购买后,我想管理数据库中的库存水平(以减少产品数量可用性)。并在数量少于 2 时提醒用户。或者有一个只读输入框来显示每个产品的可用数量。我的 Datacontext 包括 Products、Sales、Customers、Categories 和 SalesDetails
在 saleButton 中,我将每个产品添加到列表中,然后将数量和价格相乘,然后得到添加到列表中的产品价格的总和。每个购买列表都有一个 ID
然后在提交销售按钮中,我希望它处理付款并获取列表并保存在数据库中,然后从库存中扣除每件商品的数量。这就是问题所在。我正在尝试使用 LINQ 获取库存水平和总产品,但我遇到了错误。付款处理后如何更改库存水平?
谢谢
这是客户向产品列表中“添加项目”
private void SalesButton_Click(object sender, RoutedEventArgs e)
{
SaleId += 1;
var newDate = date.ToString("F");
if (AddSalesProductNameComboBox.Text != "" && AddSalesCustomerNameComboBox.Text != "" &&
ProductSalesPrice.Text != "" && ProductQuantityBought.Text != "")
{
var sale = new Sale
{
SalesID = SaleId,
ProductName = AddSalesProductNameComboBox.Text,
CustomerName = AddSalesCustomerNameComboBox.Text,
ProductPrice = Convert.ToDecimal(ProductSalesPrice.Text),
QuantityPurchased = Convert.ToInt32(ProductQuantityBought.Text),
Date = DateTime.Parse(newDate),
Total = Convert.ToDecimal(ProductSalesPrice.Text) * Convert.ToInt32(ProductQuantityBought.Text)
};
posManager.AddSales(sale);
var NewAmount = posManager.Sales.Sum(c => c.Total);
AmountDueDisplay.Text = NewAmount.ToString();
}
}
这是向数据库提交销售并处理库存级别
private void SubmitSalesButton_Click(object sender, RoutedEventArgs e)
{
decimal Balance = 0;
//Check if inputs are empty
if (AmountPaidInput.Text != "" && AmountDueDisplay.Text != "")
{
//Calculating the Amount due and amouunt paid
decimal AmtDue = Convert.ToDecimal(AmountDueDisplay.Text);
decimal AmtPaid = Convert.ToDecimal(AmountPaidInput.Text);
DisplayBalance.Text = (AmtDue - AmtPaid).ToString();
}
//pass the calculated balance to the balance variable
Balance = Convert.ToDecimal(DisplayBalance.Text);
//SaleDetailsID += 1;
var newSalesDate = date.ToString("F");
var salesDetails = new SalesDetail
{
SalesDetailsID = SaleDetailsID,
SalesID = SaleId,
SalesDetailsCustomerName = AddSalesCustomerNameComboBox.Text,
SalesProductName = AddSalesProductNameComboBox.Text,
AmountPaid = Convert.ToDecimal(AmountPaidInput.Text),
Balance = Balance,
Total = TotalQtyPurchased,
SalesDetailsDate = Convert.ToDateTime(newSalesDate),
//QuantityPuchased = Convert.ToInt32(ProductQuantityBought.Text)
//QuantityPuchased = quan
//SalesDetailsDate =
};
posDBcontext.GetSalesDetails.Add(salesDetails);
posDBcontext.SaveChanges();
var q = SubmitSalesButton.Content as Product;
var s = posDBcontext.Sales.Where(a => a.QuantityPurchased == q.QuantityAvailableInStock);
AmountPaidInput.Clear();
AmountDueDisplay.Clear();
SalesDatagrid.ItemsSource = null;
SalesDatagrid.Items.Clear();
//var s = posDBContext.GetSalesDetails.Where(c => c.SalesID == c.SalesID);
//var DetailSales = posManager.Sales.Where(c=> c.)
//posManager.CreateSales(s);
//TotalQtyPurchased = posDBContext.Sales.Sum(c => c.QuantityPurchased);
//posDBContext.Products.
}
我试着这样做
var TotalQtyBought = posDBcontext.Sales.Where(c => c.Total == c.Total);
var StockLevel = posDBcontext.Products.Where(c => c.ProductPrice == c.ProductPrice);
foreach (var item in StockLevel) { var newStock = item - TotalQtyBought; }
我收到了这个错误
But I got this error cannot apply operands to type Product and iQueryable<sale> ```