private TotalSales GetTX() { decimal salesTotal = 0; var ordersNY = (from oNY in _context.OrdenesTexas join od in _context.DetalleOrden on oNY.IdOrden equals od.IdOrden where oNY.EstadoOrden == 4 select new { IdOrden = oNY.IdOrden, EstadoOrden = oNY.EstadoOrden, PrecioVenta = od.PrecioVenta }).ToList(); foreach (var orders in ordersNY) { salesTotal += orders.PrecioVenta; } TotalSales total = new TotalSales { totalSales = salesTotal }; return(total); }
/// <summary> /// Method checks if the value input for monthly sales is a valid number. If is is the number /// is converted to a dollar figure else a message is shown that the information /// is not valid and the field is cleared. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TotalMonthlySalesTextBox_Leave(object sender, EventArgs e) { double TotalSales; if (TotalMonthlySalesTextBox.Text != "") { try { TotalSales = Convert.ToDouble(TotalMonthlySalesTextBox.Text); TotalMonthlySalesTextBox.Text = TotalSales.ToString("C2"); } catch (Exception exception) { try { TotalSales = double.Parse(TotalMonthlySalesTextBox.Text, NumberStyles.Currency); TotalMonthlySalesTextBox.Text = TotalSales.ToString("C2"); } catch { MessageBox.Show("Invalid Data Entered", "Input Error"); Debug.WriteLine(exception.Message); TotalMonthlySalesTextBox.Focus(); TotalMonthlySalesTextBox.Text = ""; TotalMonthlySalesTextBox.SelectAll(); } } } }
static void Main() { /* Create an object of class "TotalSales", providing "5" and "3" as parameters for the class's constructor. Using them * the constructor is creating an object, which private two-dimentional field "sales[]" would have 5 rows with 3 columns. */ TotalSales salesTable = new TotalSales(5, 3); // Print a welcome message. Console.WriteLine("The app calculates total sales for 3 salespersons and 5 product types.\n" + "In order to fill the resulting summary sales table, you need to provide a list of slips,\n" + "where every slip contains: number of a salesperson, numeber of a product\n" + "and total dollar value of the product sold that day by the salesperson."); // Declare a local variable "toContinue" to use it in while loop continuation test. bool toContinue = true; // While user answers "y" for the "ToContinue()" method's question. while (toContinue) { Console.WriteLine(); Console.WriteLine("Entering data for the next slip."); Console.Write("Please enter a salesperson number: "); /* Create an object of class "Slip", providing "5" and "3" as parameters for the class's constructor. Using them * the constructor is creating a "slip" object which wouldn't allow to set product or salesperson greater than these values. * Notice that new object is created during every iteration of while loop. * Old objects are deleted from memory by the C# garbage collector. * https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/ */ Slip slip = new Slip(5, 3); // Write the next number of a salesperson to "SalesmanNumber" - the property of "slip" object. slip.SalesmanNumber = int.Parse(Console.ReadLine()); Console.Write("Please enter a product number: "); // Write the next number of a product to "ProductNumber" - the property of "slip" object. slip.ProductNumber = int.Parse(Console.ReadLine()); Console.Write("Please enter the total dollar value of the product sold that day: "); // Write the next dollar value to "DollarValue" - the property of "slip" object. slip.DollarValue = decimal.Parse(Console.ReadLine()); /* Call a "salesTable" class's method "AddSalesDataFromSlip()" providing a "slip" object as a parameter. * The method would add data stored in the object to a "sales" field stored in its class. */ salesTable.AddSalesDataFromSlip(slip); // Ask user whether he/she wants to enter data for the next slip. toContinue = ToContinue(); } Console.WriteLine(); Console.WriteLine("The total sales table:"); // Call a "salesTable" class's method "PrintTotalSalesTable()" which prints a resulting table. salesTable.PrintTotalSalesTable(); Console.WriteLine(); Console.WriteLine(); Console.Write("Press any key to exit."); /* The method "ReadKey()" of class "Console" is similar to "ReadLine()" method, but reads not a string of characters, * followed by "Enter" key, but in contrast reads a single character pressed by a user. * It is useful when you need a console window to left opened after an application finishes its work. */ Console.ReadKey(); }
public TotalSales Get() { Console.WriteLine(Environment.GetEnvironmentVariable("CITY")); switch (Environment.GetEnvironmentVariable("CITY")) { case "NY": return(GetNY()); case "CA": return(GetCal()); case "TX": return(GetTX()); default: TotalSales total = new TotalSales(); total.totalSales = -1; return(total); } }
public ActionResult Home() { var currentstock = _productService.GetProducts(); var paymenttypes = _paymentDetailService.GetPaymentTypes(); var orders = _orderService.GetOrders(); List <TotalSales> totalSales = new List <TotalSales>(); TotalSales sale = new TotalSales(); foreach (var p in paymenttypes) { sale = new TotalSales() { PaymentDesc = p.PaymtType, TotalAmount = _paymentDetailService.GetSalesByType(p.PaymtId) }; totalSales.Add(sale); } ViewData["canssold"] = orders; ViewData["currentstock"] = currentstock; ViewData["totalsales"] = totalSales; return(View()); }
public ActionResult Restock() { _paymentDetailService.RefreshPayments(); _orderService.ResetOrders(); var currentstock = _productService.GetProducts(); var stockToBeAdded = (from product in currentstock select new Product { ProdId = product.ProdId, ProdQty = 5 }).ToList(); _productService.AddNewProductStock(stockToBeAdded); var paymenttypes = _paymentDetailService.GetPaymentTypes(); List <TotalSales> totalSales = new List <TotalSales>(); TotalSales sale = new TotalSales(); foreach (var p in paymenttypes) { sale = new TotalSales() { PaymentDesc = p.PaymtType, TotalAmount = _paymentDetailService.GetSalesByType(p.PaymtId) }; totalSales.Add(sale); } var newStock = _productService.GetProducts(); var orders = _orderService.GetOrders(); ViewData["canssold"] = orders; ViewData["currentstock"] = newStock; ViewData["totalsales"] = totalSales; return(View()); }
/// <summary> /// reads in present sales report, if exists, then updates /// sales report dictionary values, adding previous total sales /// to total sales after each user transaction /// finally, writes new updated values to the sales report /// by overwriting existing data /// </summary> private void GenerateSalesReport() { if (File.Exists(_reportPath)) { using (StreamReader sr = new StreamReader(_reportPath)) { while (!sr.EndOfStream) { string line = sr.ReadLine(); if (line.Contains("$")) { string[] totalLine = line.Split('$'); TotalSales += decimal.Parse(totalLine[1]); } else if (line != "") { string[] dictString = line.Split('|'); string itemName = dictString[0]; int lastQtySold = int.Parse(dictString[1]); foreach (Item item in _itemList) { if (item.Name == itemName) { _salesReport[itemName] = lastQtySold + item.QtySold; } } } } } using (StreamWriter sw = new StreamWriter(_reportPath, false)) { foreach (KeyValuePair <string, int> entry in _salesReport) { sw.WriteLine($"{entry.Key}|{entry.Value}"); } sw.WriteLine(); sw.WriteLine($"**TOTAL SALES** {TotalSales.ToString("C")}"); TotalSales = 0; } } else { using (StreamWriter sw = new StreamWriter(_reportPath, false)) { foreach (KeyValuePair <string, int> line in _salesReport) { string key = line.Key; int qtySold = 0; foreach (Item item in _itemList) { if (item.Name == key) { qtySold = item.QtySold; } } sw.WriteLine($"{line.Key}|{line.Value + qtySold}"); } sw.WriteLine(); sw.WriteLine($"**TOTAL SALES** {TotalSales.ToString("C")}"); } } }