c# - 如何使用 LINQ-to-Entities 将客户订单详细信息插入我的账单表
问题描述
请帮我解决这个问题。
我正在使用窗口窗体创建一个商店管理应用程序来管理一家婴儿用品店。除了将客户订单详细信息添加到数据库之外,所有方面都有效。
到目前为止,我使用下面的 ode 添加了包含他或她想要购买的所有物品的客户账单。
private void btuAddBill_Click(object sender, EventArgs e)
{
if (txtProName.Text != "" && txtProPrice.Text != "")
{
if (ComboSelectCustID.Text != "NONE")
{
if (txtQuantity.Text != "")
{
decimal Total = Convert.ToDecimal(txtProPrice.Text) * Convert.ToDecimal(txtQuantity.Text);
DataGridViewRow newRow = new DataGridViewRow();
newRow.CreateCells(DataGribBills);
newRow.Cells[0].Value = n + 1;
newRow.Cells[1].Value = txtProName.Text;
newRow.Cells[2].Value = txtProPrice.Text;
newRow.Cells[3].Value = txtQuantity.Text;
newRow.Cells[4].Value = Convert.ToDecimal(txtProPrice.Text) * Convert.ToDecimal(txtQuantity.Text);
DataGribBills.Rows.Add(newRow);
n++;
GrdTotal = GrdTotal + Total;
txtTotalAmt.Text = Convert.ToString(GrdTotal);
}
else
{
MessageBox.Show("Kindly Input Quantity to Proceed");
}
}
else
{
MessageBox.Show("Kindly Select Customer ID");
}
}
else
{
MessageBox.Show("Kindly Select Product");
}
}
当客户准备好付款时,会处理交易并将总账单金额连同有关交易的一些详细信息发送到数据库。
下面是我用来将交易发布到我的数据库的代码。此交易仅包含所购商品清单的总价以及总数量。
private void btuAddTransaction_Click(object sender, EventArgs e)
{
TotaPurchaseAmt = Convert.ToDecimal(txtQuantity.Text) * Convert.ToDecimal(txtPurchaseCost.Text);
decimal profit = GrdTotal - TotaPurchaseAmt;
DBS = new BabyHubEntities();
ProductTB del = new ProductTB();
decimal proID = Convert.ToDecimal(txtTbale_ID.Text);
cusQua = Convert.ToDecimal(txtQuantity.Text);
var IDpro = (from s in DBS.ProductTBs where s.t_ID == proID select s).FirstOrDefault();
IDpro.ProdQty = IDpro.ProdQty - Convert.ToDecimal(txtQuantity.Text);
if (cusQua > IDpro.ProdQty)
{
MessageBox.Show("Qunatity is not in stock");
}
else
{
DBS.SaveChanges();
if (txtBill_ID.Text == "")
{
MessageBox.Show("Missing Transaction Details");
}
else
{
try
{
DBS = new BabyHubEntities();
BillingTB acc = new BillingTB();
ProfitTB PS = new ProfitTB();
acc.bill_ID = Convert.ToDecimal(hidetxtHideID.Text);
acc.Biiling_ID = txtBill_ID.Text;
acc.billDate = DateTime.Now;
acc.customerID = ComboSelectCustID.Text;
acc.customerName = txtCustName.Text;
acc.EmplName = MainLogin.TBH_Login.Username;
acc.Amt = Convert.ToDecimal(txtTotalAmt.Text);
string message = "Are you sure you want to add this Transaction?";
string title = "Adding Record...";
MessageBoxButtons but = MessageBoxButtons.YesNo;
DialogResult result = MessageBox.Show(message, title, but);
if (result == DialogResult.Yes)
{
acc.SellerName = MainLogin.TBH_Login.Username;
DBS.BillingTBs.Add(acc);
DBS.SaveChanges();
MessageBox.Show("Transaction Added Successfully");
}
else
{
MessageBox.Show("Transaction Not Added");
}
PS.BillID = txtBill_ID.Text;
PS.SoldBy = MainLogin.TBH_Login.Username;
PS.SalAmt = GrdTotal;
PS.ProfitAmt = profit;
PS.SoldQty = Convert.ToDecimal(txtQuantity.Text);
PS.SaleDT = DateTime.Now;
PS.UnitPrice = Convert.ToDecimal(txtProPrice.Text);
PS.ProdPurcCost = Convert.ToDecimal(txtPurchaseCost.Text);
DBS.ProfitTBs.Add(PS);
DBS.SaveChanges();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
DisplayTransaction();
}
现在,我想将订单详细信息发送到另一张表,其中包括客户购买的商品列表以及他们的单价和数量,所有这些都在一个带有订单日期的 OrderID 下。这让我好几天没睡。
请协助我。
解决方案
推荐阅读
- python - markdown2 模块 - 如何从 Python 脚本中转换一个 markdown 文件?
- ios - 在 react-native 中动态地需要 json 文件(来自数千个文件)
- javascript - 如何将 if 条件放入 JS / JQuery 中,如电子邮件所需的属性?
- php - foreach 遗漏了第一个值
- reactjs - 如何将 apollo 查询数据放入受控输入?
- c# - 无法使用 for 循环反转字符串
- c# - SqlException:'1' 附近的语法不正确
- php - 如何通过 id 的 Laravel 数组获取列表的记录
- bash - sed 在处理大文件时不适用于 psexec 和重定向
- docker - 未找到 Docker 网络