public static void StockRequestsToExcel(string filename = "stockRequests.xlsx") { string sheetName = "StockRequests"; List <StockRequest> requests = StockRequest.GetAllShelfRestockRequests(); var workbook = new XLWorkbook(); workbook.AddWorksheet(sheetName); var ws = workbook.Worksheet(sheetName); int row = 1; ws.Cell("A" + row.ToString()).Value = "Name"; ws.Cell("B" + row.ToString()).Value = "Description"; ws.Cell("C" + row.ToString()).Value = "Quantity"; ws.Cell("D" + row.ToString()).Value = "QuantityInDepot"; ws.Cell("E" + row.ToString()).Value = "QuantityInStore"; row++; foreach (StockRequest item in requests) { ws.Cell("A" + row.ToString()).Value = item.Name; ws.Cell("B" + row.ToString()).Value = item.Description; ws.Cell("C" + row.ToString()).Value = item.Quantity; ws.Cell("D" + row.ToString()).Value = item.QuantityInDepot; ws.Cell("E" + row.ToString()).Value = item.QuantityInStore; row++; } workbook.SaveAs(filename); }
public static List <StockRequest> GetAllShelfRestockRequests() { MySqlConnection conn = Utils.GetConnection(); List <StockRequest> requests = new List <StockRequest>(); List <Stock> stocks = new List <Stock>(); try { string sql = "SELECT name, description, quantity_in_depo, quantity_in_store, price, department_id, needed_quantity FROM stock INNER JOIN stockrequests ON stock_id = id;"; MySqlCommand cmd = new MySqlCommand(sql, conn); conn.Open(); MySqlDataReader row = cmd.ExecuteReader(); while (row.Read()) { StockRequest request = new StockRequest(row[0].ToString(), row[1].ToString(), Convert.ToInt32(row[2].ToString()), Convert.ToInt32(row[3]), Convert.ToInt32(row[4]), Convert.ToInt32(row[5]), Convert.ToInt32(row[6])); requests.Add(request); } } catch (Exception) { // TODO: add it to error log in the future } finally { conn.Close(); } return(requests); }
public ShelfRestockRequests() { InitializeComponent(); List <StockRequest> requests = StockRequest.GetAllShelfRestockRequests(); shelfRestockView.Items.Clear(); foreach (StockRequest request in requests) { shelfRestockView.Items.Add(new ListViewItem(new[] { "[WIP, in later phase]", request.Name, request.Description, request.Quantity.ToString() })); } }
private void requestStockBttn_Click(object sender, EventArgs e) { if (requestStockQtty.Value < 1) { MessageBox.Show("Enter quantity"); return; } if (requestStockStocksCmbbx.SelectedIndex == -1) { MessageBox.Show("Select stock"); return; } int quantity = (int)requestStockQtty.Value; int stock_id = ((StocksComboBoxItem)requestStockStocksCmbbx.SelectedItem).Id; StockRequest.CreateStockRequest(stock_id, quantity); this.Hide(); }
private void requestStockBttn_Click(object sender, EventArgs e) { if (MessageBox.Show("Do you really want to send this stock request?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { if (requestStockQtty.Value < 1) { MessageBox.Show("Enter quantity"); return; } if (requestStockStocksCmbbx.SelectedIndex == -1) { MessageBox.Show("Select stock"); return; } int quantity = (int)requestStockQtty.Value; int stock_id = ((StocksComboBoxItem)requestStockStocksCmbbx.SelectedItem).Id; StockRequest.CreateStockRequest(stock_id, quantity); MessageBox.Show("Stock has been requested."); this.Hide(); } }