T
TechStackInc
Guest
I want to manage the stock level(To reduce the product quantity availability) in the database once purchases are made. and alert the user when the quantity is less than 2. or have a read-only input box to show the quantity available for each product. my Datacontext includes Products, Sales, Customers, Categories and SalesDetails
In the saleButton, I am adding each product to list then sum multiply the quantity and price then get the sum of the product price added to list. which has an ID for each list of purchases
Then in the submit sales button, I want it to process payment and grab the list and save in the db, then deduct the quantity of each item from stock. This where the issue is. I am trying to get the stock level and total product using LINQ but I have been getting errors. How do I change stock level after payment is processed?
Thanks
This is "add item" to list of product by a customer
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();
}
}
This is submitting sales to DB and processing stock level
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.
}
Continue reading...
In the saleButton, I am adding each product to list then sum multiply the quantity and price then get the sum of the product price added to list. which has an ID for each list of purchases
Then in the submit sales button, I want it to process payment and grab the list and save in the db, then deduct the quantity of each item from stock. This where the issue is. I am trying to get the stock level and total product using LINQ but I have been getting errors. How do I change stock level after payment is processed?
Thanks
This is "add item" to list of product by a customer
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();
}
}
This is submitting sales to DB and processing stock level
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.
}
Continue reading...