What's new
  • Welcome to PHCorner Forums. Take a moment to Sign up and gain unlimited access and extra privileges that guests are not entitled to, such as: All that and more! Registration is quick, simple and absolutely free. Join our community today!

C# Program Classes and Database

FourBytes

Addict
Joined
Feb 26, 2018
Messages
385
Reaction
37
I badly needed some suggestions to get my programming skills become better.

Language I can read:

  • c# (.net framework)
  • java
------- I want this to be an open forum -- open for expert programmers and students like me. -------------
------- I'm not a bright student but I really want to learn about these things and I mean it. -------------
To get this started,
I know the basics about programming. Alam ko narin yung tungkol sa classes na inheritance, polymorphism ... at higit sa lahat gumagamit na rin kami ng database. Nakakagawa na kami ng ibat ibatng system sa c# gaya ng library management.

Last na pinagawa samin ay sarili naming program from scratch. Fast food ordering system yung samin. The problem is gusto kong matuto magcreate ng organized na code. What Im meaning to say is gusto kong gumawa ng classes para maging object oriented ang approach ng progarm. Hindi ko alng alam kung pano ko to gagawin. For example wala akong idea kung anong ilalagay ko sa Account class, Order Class, or Item class . hindi ko rin alam kung anong mga class ba dapat ang gamitin ko. Please help.



Sana mapansin.
 

mrHazan

Eternal Poster
Well kung class lang naman. Isipin mo ang class as isang object pwede din na machine.
Example: Account
Ano ba meron sa class na Account?
-ID
-Username
-Password
Depende sa system meron din
-Type
-Salary
Etc.

Now ang basic methods sa mga class is yung getter and setter.
SetUsername, SetPassword, GetSalary, GetType, etc.

Now, meron din type ng class that serves as machine. Magbibigay ka ng input may output.

Example AccountManager
Possible methods.
DeleteAccount, SuspendAccount, LoginAccount, RegisterAccount, etc etc.
 
Comment

FourBytes

Addict
, Last edited:
Well kung class lang naman. Isipin mo ang class as isang object pwede din na machine.
Example: Account
Ano ba meron sa class na Account?
-ID
-Username
-Password
Depende sa system meron din
-Type
-Salary
Etc.

Now ang basic methods sa mga class is yung getter and setter.
SetUsername, SetPassword, GetSalary, GetType, etc.

Now, meron din type ng class that serves as machine. Magbibigay ka ng input may output.

Example AccountManager
Possible methods.
DeleteAccount, SuspendAccount, LoginAccount, RegisterAccount, etc etc.
about sa getter and setter sir? tama po ba ang pagkakaintindi ko na ang purpose lang nyan ay ihold muna ang data bago ipasok sa database? yun lang po ba ang purpose nya?
at saka ginagamit ang gantong technique para di paulit ulit ang declare ng variable kung maraming form ang paggagamitan? form1,form2 ...?
 
Comment

mrHazan

Eternal Poster
Hindi ko magets yung idea mo.
Pero ang setter and getter is the proper way to get data saka mag set ng data to an object or class.
For security purposes, kailangan ihide yugn mga data(private) at ang only ways to get these or retreive data are through setter and getter.
For example may class ako Bank. Syempre napaka unappropriate kung yung mga data like balance ko is nakapublic. Dapat makukuha ko lang yun through Bank Class's Getter class.
Its a good practice din for OOP Object-Oriented Programming.
 
Comment

FourBytes

Addict
Hindi ko magets yung idea mo.
Pero ang setter and getter is the proper way to get data saka mag set ng data to an object or class.
For security purposes, kailangan ihide yugn mga data(private) at ang only ways to get these or retreive data are through setter and getter.
For example may class ako Bank. Syempre napaka unappropriate kung yung mga data like balance ko is nakapublic. Dapat makukuha ko lang yun through Bank Class's Getter class.
Its a good practice din for OOP Object-Oriented Programming.
for example po ganito. may dalwa po akong form at isang class na Order pangalan. tapos sa form 1 naggawa po ako ng object ng order . tas nilagyan ko ng value yung property na nasa order class halimbawa sir ito ang laman ng order class:
private string _orderT,_orderP,_orderQ;
public string Type{
get { return _orderT; }
set { _orderT = value; }
}
public string Price
{
get { return _orderP; }
set { _orderP = value; }
}
public string Quantity
{
get { return _orderQ; }
set { _orderQ = value; }
}

tas sa form1
Order ord = new Order();
ord.Price = "109";
ord.Quantity = "10";


tapos sa form 2 gusto kong mapass yung mga value. Kaya lang pag nagdeclare ako ng bagong object ng Order null na yung mga value nung variables. So the point is bakit pa natin kelangang gumawa ng Order class kung pede naman na sa form na natin ideclare yung mga variables na maghohold ng data?
 
Comment

FourBytes

Addict
mrHazan meron po ba kayong system na nagawa sa c# na nagaaccess sa database o gumagamit ng maraming classes pede po ba patingin para makita ko kung pano ginagamit ng tama yung mga class na ginawa?
 
Comment

mrHazan

Eternal Poster
PWede naman magpass.
You do not have permission to view the full content of this post. Log in or register now.


Kung possible sa taas. PWede mo din ipass yung class object na initialized mo sa form1 para maaccess sa form2.
Magcreate ka lang ng another constructor ng form2 mo. For examle.

Code:
 public Form2(Order ord)
    {
        InitializeComponent();
        currentOrder = ord

    }
Tatawagin mo sa form1 mo ang form2 mo in this way:

Code:
private void button1_Click(object sender, EventArgs e)
{
        Order ord = new Order();
        ord.Price = "109";
        ord.Quantity = "10";

        Form2 frm2 = new Form2(ord);
        frm2.Show();  
}
 
Comment

mrHazan

Eternal Poster
Sorry hindi ako makakapagpakita ng code kasi kahit ako ngayon lang din natututo ng tamang way ng pagcode.
 
Comment

mrHazan

Eternal Poster
, Last edited:
Pwede ka din gumawa ng Singleton Manager mo. Para maaccess ng kahit anong form mo.
Example

Code:
//Singleton Manager Example
public static class OrderManager
{

    public static Order currentOrder;

    public static void SetOrder(int price, int qty)
    {
        currentOrder = new Order();
        currentOrder.Price = price;
        currentOrder.Quantity = qty;
    }

    public static Order GetCurrentOrder()
    {
        return currentOrder;
    }

}

Sa form1...
private void button1_Click(object sender, EventArgs e)
{
    OrderManager.SetOrder(108, 11);
}

Sa form2...
private void button1_Click(object sender, EventArgs e)
{
    Order order = new Order();
    order = OrderManager.GetOrder();
     
     // Do whatever you want sa order

}
Hindi ako 100% sure magwowork ang code above kasi tinype ko lang yan without compiling and running. Basta nasa ganyan ang idea.
 
Comment

jxychrist

Addict
for DBMS, I suggest MySQL.
tapos isama mo yung joining ng at optimization ng tables, at user permission.
 
Comment

Like us on facebook

Online statistics

Members online
1,458
Guests online
953
Total visitors
2,411

Forum statistics

Threads
765,252
Messages
15,147,688
Members
1,409,082
Top