private void clientIdTxtBox_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { string clientId = this.clientIdTxtBox.Text; var dataTable = PopulateColums(); switch (selectedMenu) { case 'B': { try { string result = orderRaports.GetOrderAmountPerClient(clientId).ToString(); resultLabel.Text = $"Ilość zamówień dla klienta z id {clientId} wynosi: {result}"; } catch (ArgumentNullException exception) { MessageBox.Show(exception.Message); } break; } case 'D': { try { string result = orderRaports.GetTotalPriceOfOrdersPerClient(clientId).ToString(); resultLabel.Text = $"Łączna kwota zamówień dla klienta z id: {clientId} wynosi: " + result; } catch (ArgumentNullException exception) { MessageBox.Show(exception.Message); } break; } case 'F': { try { foreach (var val in orderRaports.GetTotalListOfOrdersPerClient(clientId)) { dataTable.Rows.Add(val.ClientId, val.RequestId, val.Name, val.Quantity, val.Price); } } catch (ArgumentNullException exception) { MessageBox.Show(exception.Message); } break; } case 'J': { dataTable = new DataTable(); dataTable.Columns.Add("Name"); dataTable.Columns.Add("Quantity"); try { foreach (var val in orderRaports.GetAmountOfOrdersGroupedByNamePerClient(clientId)) { dataTable.Rows.Add(val.Key, val.Value); } } catch (ArgumentNullException exception) { MessageBox.Show(exception.Message); } break; } } this.dataGridView.DataSource = dataTable; } }
public void SaveFile(string path, char selectedMenu, string clientId, double min, double max) { using (StreamWriter streamWriter = new StreamWriter(path)) { StringBuilder stringBuilder = new StringBuilder(); switch (selectedMenu) { case 'A': { var result = _orderRaports.GetOrderAmount(); stringBuilder.AppendLine($"Order amount:, {result}"); break; } case 'B': { var result = _orderRaports.GetOrderAmountPerClient(clientId); stringBuilder.AppendLine($"Order amount for client with id '{clientId}':, {result}"); break; } case 'C': { var result = _orderRaports.GetTotalPriceOfOrders(); stringBuilder.AppendLine($"Total Price of orders':, {result}"); break; } case 'D': { var result = _orderRaports.GetTotalPriceOfOrdersPerClient(clientId); stringBuilder.AppendLine($"Total price of orders for client with id '{clientId}':, {result}"); break; } case 'E': { stringBuilder.AppendLine("ClientId,RequestId,Name,Quantity,Price"); foreach (var val in _orderRaports.GetTotalListOfOrders()) { stringBuilder.AppendLine(string.Format("{0},{1},{2},{3},{4}", val.ClientId, val.RequestId, val.Name, val.Quantity, val.Price)); } break; } case 'F': { stringBuilder.AppendLine("ClientId,RequestId,Name,Quantity,Price"); foreach (var val in _orderRaports.GetTotalListOfOrdersPerClient(clientId)) { stringBuilder.AppendLine(string.Format("{0},{1},{2},{3},{4}", val.ClientId, val.RequestId, val.Name, val.Quantity, val.Price)); } break; } case 'I': { stringBuilder.AppendLine("Name,AmountOfOrders"); foreach (var val in _orderRaports.GetAmountOfOrdersGroupedByName()) { stringBuilder.AppendLine(string.Format("{0},{1}", val.Key, val.Value)); } break; } case 'J': { stringBuilder.AppendLine("Name,AmountOfOrders"); foreach (var val in _orderRaports.GetAmountOfOrdersGroupedByNamePerClient(clientId)) { stringBuilder.AppendLine(string.Format("{0},{1}", val.Key, val.Value)); } break; } case 'K': { stringBuilder.AppendLine("ClientId,RequestId,Name,Quantity,Price"); foreach (var val in _orderRaports.GetOrdersInPriceRange(min, max)) { stringBuilder.AppendLine(string.Format("{0},{1},{2},{3},{4}", val.ClientId, val.RequestId, val.Name, val.Quantity, val.Price)); } break; } } streamWriter.Write(stringBuilder.ToString()); } }
public void GetTotalPriceOfOrdersPerClientTest() { orderRaports.GetTotalPriceOfOrdersPerClient("1").Should().Be(115.0); }