/// <summary> /// Создать новый заказ /// </summary> private void CreateNewOrder() { string ordName = CreateOrderName(); var usId = AppState.CurrentUser.UserId; var receiptData = new ReceiptData(); receiptData.UserName = AppState.CurrentUser.userName; receiptData.TimeOfPurchase = DateTime.Now.ToString(); receiptData.PurchasedOrders = new List <Product>(); for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { DataGridViewRow row = dataGridView1.Rows[i]; Int32.TryParse(row.Cells[0].Value.ToString(), out int prId); string prod = row.Cells[1].Value.ToString(); string price = row.Cells[2].Value.ToString(); Int32.TryParse(row.Cells[3].Value.ToString(), out int prQuantity); receiptData.PurchasedOrders.Add(new Product() { productName = prod, productPrice = float.Parse(price) }); // Добавить в таблицу Order заказ AddNewOrderRow(ordName, usId, prId, prQuantity); } receiptData.Summ = TotalCostLabel.Text; MessageBox.Show("Заказик принят."); CreateReceipt(receiptData); }
public void CreateReceipt(ReceiptData receiptData) { string receipt = string.Empty; receipt += $"Покупатель: {receiptData.UserName} Дата покупки: {receiptData.TimeOfPurchase} {Environment.NewLine}"; foreach (var product in receiptData.PurchasedOrders) { receipt += $"Товар: {product.productName} Стоимость: {product.productPrice} грн {Environment.NewLine}"; } receipt += $"{receiptData.Summ}"; if (!Directory.Exists("Temp")) { Directory.CreateDirectory("Temp"); } File.WriteAllText(FilePath, receipt); Process.Start("notepad.exe", FilePath); }
/// <summary> /// Создать чек /// </summary> private void CreateReceipt(ReceiptData data) { var receipt = new Receipt(); receipt.CreateReceipt(data); }