Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
1.29/5 (4 votes)
See more:
C#
public List<purchaseaccountbll> PurchaseAccountSelection()
        {
            DataTable dt = prl.SelectPurchaseAccount();
            List<purchaseaccountbll> purchase = new List<purchaseaccountbll>();
            foreach (DataRow row in dt.Rows)
            {
                PurchaseAccountBLL a = new PurchaseAccountBLL();
                a.Itemname = row["item_name"].ToString();
                a.Id = Convert.ToInt32(row["purchase_id"]);

                a.Purchase_Unit_Prize = Convert.ToDecimal(row["unit_prize"]);
                a.Purchase_Item_Quantity1 = Convert.ToDecimal(row["quantity"]);
                a.Purchase_Item_Discount1 = Convert.ToDecimal(row["discount"]);
                a.Purchase_Item_Total1 = Convert.ToDecimal(row["item_total"]);

               
                purchase.Add(a);
             }
            return purchase;
             }
       
        
        public List<stockpagebll> StockSelection()
        {
            DataTable dt = prl.StockSelection();
            List<stockpagebll> stock = new List<stockpagebll>();
            foreach (DataRow row in dt.Rows)
            {
                StockpageBLL add = new StockpageBLL();
                add.Id = Convert.ToInt32(row["item_id"]);
               add.Itemname = Convert.ToString(row["itemname"]);
                add.Item_Quantity1 = Convert.ToDecimal(row["quantity"]);
                add.Barcode = Convert.ToString(row["barcode"]);
                add.Category = Convert.ToString(row["category"]);

                add.ItemUnit_Prize1 = Convert.ToDecimal(row["unitPrize"]);
                add.Profit = Convert.ToDecimal(row["profit"]);

                
                StockpageDLL stk = new StockpageDLL(Profit,Id);
                stock.Add(add);

            }

            return stock;
            

        }
Posted
Updated 4-Nov-15 3:22am
v2
Comments
Tomas Takac 4-Nov-15 9:27am    
Can you be a more specific and describe the problem in more detail?
Geethus 4-Nov-15 10:16am    
Im using two classes one is stockBLL and one is PurchaseAccountBLL. so I try to calculate avarage purchase prize in the two classess like
Profit=(purchae_unit_prize*purchase_Item_Quantity)

The profit is the field of stockBLL class and 'purchae_unit_prize,purchase_Item_Quantity' is the field of purchaeAccountBLL
and the updated values store in stockBLL database field


how can I get the values ?
Plese help
Thanks in advance
Suvendu Shekhar Giri 4-Nov-15 9:43am    
A question and some code dump doesn't help us understanding your question and so we can't help you. Try to add description to the question body.
Geethus 4-Nov-15 10:26am    
Sir,
Im using two classes one is stockBLL and one is PurchaseAccountBLL. so I try to calculate avarage purchase prize in the two classess like
Profit=(purchae_unit_prize*purchase_Item_Quantity)

The profit is the field of stockBLL class and 'purchae_unit_prize,purchase_Item_Quantity' is the field of purchaeAccountBLL
and the updated values store in stockBLL database field


how can I get the values ?
Plese help
Thanks in advance
ZurdoDev 4-Nov-15 10:12am    
Average is total/count.

1 solution

If I understood your question correctly,
C#
decimal total_prize = 0;
foreach (DataRow row in dt.Rows)
{
    PurchaseAccountBLL a = new PurchaseAccountBLL();
    a.Itemname = row["item_name"].ToString();
    a.Id = Convert.ToInt32(row["purchase_id"]);
    
    a.Purchase_Unit_Prize = Convert.ToDecimal(row["unit_prize"]);
    a.Purchase_Item_Quantity1 = Convert.ToDecimal(row["quantity"]);
    a.Purchase_Item_Discount1 = Convert.ToDecimal(row["discount"]);
    a.Purchase_Item_Total1 = Convert.ToDecimal(row["item_total"]);

    total_prize +=   Convert.ToDecimal(row["unit_prize"]);

    purchase.Add(a);
}
decimal avg = total_prize/dt.Rows.Count;   // this is your average

// user the avg value later...


-KR
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900