问题描述
我使用以下代码计算平均购买奖。我有两个类PurchaseAccountBLL和StockpageBLL。 unit_prize,Quantity,Item_discount从购买数据库和Stock_Item_Quantity,Stock_ItemUnit_Prize绑定,Profit来自Stock数据库表。所以我想计算以下等式:Profit =(unit_prize * Quantity) - (Stock_Item_Quantity * Stock_ItemUnit_Prize)并将更新的数据更新到库存数据库表中。我怎么能做到这一点。
谢谢你推荐
这是我的代码:
我在列表中检索数据库表数据
public List< purchaseaccountbll> PurchaseAccountSelection()
{
DataTable dt = prl.SelectPurchaseAccount();
List< purchaseaccountbll> purchase = new List< purchaseaccountbll>();
foreach(dt.Rows中的DataRow行)
{
PurchaseAccountBLL a = new PurchaseAccountBLL( );
a.Itemname = row [item_name]。ToString();
a.Id = Convert.ToInt32(row [purchase_id]);
a.Unit_Prize = Convert.ToDecimal(row [unit_prize]);
a.Quantity = Convert.ToDecimal(row [数量]);
a.Item_Discount = Convert.ToDecimal(row [discount]);
purchase.Add(a);
}
退货购买;
}
public List< stockpagebll> StockSelection()
{
DataTable dt = prl.StockSelection();
List< stockpagebll> stock = new List< stockpagebll>();
decimal total_prize = 0;
foreach(dt.Rows中的DataRow行)
{
StockpageBLL add = new StockpageBLL();
add.Id = Convert.ToInt32(row [item_id]);
add.Itemname = Convert.ToString(row [itemname]);
add.Stock_Item_Quantity = Convert.ToDecimal(row [quantity]);
add.Stock_Barcode = Convert .ToString(row [barcode]);
add.Stock_ItemUnit_Prize = Convert.ToDecimal(row [unitPrize]);
add.Profit = Convert.ToDecimal (row [profit]);
total_prize + = Convert.ToDecimal(row [unit_prize]);
// StockpageDLL stk = new StockpageDLL(Profit,Id);
stock.Add(add);
}
十进制平均值= total_prize / dt.Rows.Count;
StockpageDLL stk = new StockpageDLL(平均,条形码);
退货;
}
I m using the following code to calculate average purchase prize.I have two classes PurchaseAccountBLL and StockpageBLL. The unit_prize,Quantity, Item_discount is binding from purchase database and Stock_Item_Quantity ,Stock_ItemUnit_Prize,Profit is coming from Stock database table. So I want to calculate the following equation: Profit= (unit_prize*Quantity)-(Stock_Item_Quantity*Stock_ItemUnit_Prize) and update the updated data into stock database table. How I can achieve this.
Thanks in advace
This is my code:
I m retrieve database table data in a list
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.Unit_Prize = Convert.ToDecimal(row["unit_prize"]);
a.Quantity = Convert.ToDecimal(row["quantity"]);
a.Item_Discount = Convert.ToDecimal(row["discount"]);
purchase.Add(a);
}
return purchase;
}
public List<stockpagebll> StockSelection()
{
DataTable dt = prl.StockSelection();
List<stockpagebll> stock = new List<stockpagebll>();
decimal total_prize = 0;
foreach (DataRow row in dt.Rows)
{
StockpageBLL add = new StockpageBLL();
add.Id = Convert.ToInt32(row["item_id"]);
add.Itemname = Convert.ToString(row["itemname"]);
add.Stock_Item_Quantity = Convert.ToDecimal(row["quantity"]);
add.Stock_Barcode = Convert.ToString(row["barcode"]);
add.Stock_ItemUnit_Prize = Convert.ToDecimal(row["unitPrize"]);
add.Profit = Convert.ToDecimal(row["profit"]);
total_prize += Convert.ToDecimal(row["unit_prize"]);
// StockpageDLL stk = new StockpageDLL(Profit,Id);
stock.Add(add);
}
decimal avg = total_prize / dt.Rows.Count;
StockpageDLL stk = new StockpageDLL(avg, barcode);
return stock;
}
推荐答案
decimal purchaseTotal = 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.Unit_Prize = Convert.ToDecimal(row["unit_prize"]);
a.Quantity = Convert.ToDecimal(row["quantity"]);
a.Item_Discount = Convert.ToDecimal(row["discount"]);
purchase.Add(a);
purchaseTotal += (Convert.ToDecimal(row["unit_prize"]) * Convert.ToDecimal(row["quantity"]));
}
decimal stockTotal = 0;
foreach (DataRow row in dt.Rows)
{
StockpageBLL add = new StockpageBLL();
add.Id = Convert.ToInt32(row["item_id"]);
add.Itemname = Convert.ToString(row["itemname"]);
add.Stock_Item_Quantity = Convert.ToDecimal(row["quantity"]);
add.Stock_Barcode = Convert.ToString(row["barcode"]);
add.Stock_ItemUnit_Prize = Convert.ToDecimal(row["unitPrize"]);
add.Profit = Convert.ToDecimal(row["profit"]);
stockTotal += (Convert.ToDecimal(row["quantity"]) * Convert.ToDecimal(row["unit_prize"]));
total_prize += Convert.ToDecimal(row["unit_prize"]);
// StockpageDLL stk = new StockpageDLL(Profit,Id);
stock.Add(add);
}
decimal profit = purchaseTotal - stockTotal;
-KR
-KR
这篇关于我需要如何计算平均购买奖金的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!