private void ChangeRecordBTN_Click(object sender, EventArgs e) { List <Form> changeForm = new List <Form>(); if (_currentTable.Equals(db.Orders.GetType()) && !db.Orders.Find(MainGrid.CurrentRow.Cells[0].Value).State) { AddOrder ChangeOrderForm = new AddOrder(db.Orders.Find(MainGrid.CurrentRow.Cells[0].Value), this); changeForm.Add(ChangeOrderForm); ChangeOrderForm.ShowDialog(); if (ChangeOrderForm.flag) { db.Orders.ToList().Find(item => item.Id == (int)MainGrid.CurrentRow.Cells[0].Value).DishID = ChangeOrderForm.DishID; db.Orders.ToList().Find(item => item.Id == (int)MainGrid.CurrentRow.Cells[0].Value).ChefId = ChangeOrderForm.Chef; db.Orders.ToList().Find(item => item.Id == (int)MainGrid.CurrentRow.Cells[0].Value).State = ChangeOrderForm.state; } } if (_currentTable.Equals(db.Chefs.GetType())) { AddChef ChangeChefForm = new AddChef(db.Chefs.ToList().Find(item => item.Id == (int)MainGrid.CurrentRow.Cells[0].Value)); changeForm.Add(ChangeChefForm); ChangeChefForm.ShowDialog(); if (ChangeChefForm.flag) { db.Chefs.ToList().Find(item => item.Id == (int)MainGrid.CurrentRow.Cells[0].Value).Name = ChangeChefForm.name; db.Chefs.ToList().Find(item => item.Id == (int)MainGrid.CurrentRow.Cells[0].Value).Surname = ChangeChefForm.surname; db.Chefs.ToList().Find(item => item.Id == (int)MainGrid.CurrentRow.Cells[0].Value).Salary = ChangeChefForm.salary; db.Chefs.ToList().Find(item => item.Id == (int)MainGrid.CurrentRow.Cells[0].Value).Birthday = ChangeChefForm.birthday; db.Chefs.ToList().Find(item => item.Id == (int)MainGrid.CurrentRow.Cells[0].Value).Pozition_name = ChangeChefForm.pozition; } } if (_currentTable.Equals(db.Products.GetType())) { AddProducts ChangeProductForm = new AddProducts(db.Products.ToList().Find(item => item.Id == (int)MainGrid.CurrentRow.Cells[0].Value)); changeForm.Add(ChangeProductForm); ChangeProductForm.ShowDialog(); if (ChangeProductForm.flag) { db.Products.ToList().Find(item => item.Id == (int)MainGrid.CurrentRow.Cells[0].Value).ProductName = ChangeProductForm.ProdName; db.Products.ToList().Find(item => item.Id == (int)MainGrid.CurrentRow.Cells[0].Value).Type = ChangeProductForm.Type; db.Products.ToList().Find(item => item.Id == (int)MainGrid.CurrentRow.Cells[0].Value).Count = ChangeProductForm.Count; } } if (_currentTable.Equals(db.Menu.GetType())) { AddMenuPoint ChangeMenuPointForm = new AddMenuPoint(db.Menu.ToList().Find(item => item.Id == (int)MainGrid.CurrentRow.Cells[0].Value), this); ChangeMenuPointForm.ShowDialog(); if (ChangeMenuPointForm.flag) { db.Menu.ToList().Find(item => item.Id == (int)MainGrid.CurrentRow.Cells[0].Value).DishName = ChangeMenuPointForm.DishName; db.Menu.ToList().Find(item => item.Id == (int)MainGrid.CurrentRow.Cells[0].Value).Cost = ChangeMenuPointForm.Cost; db.Menu.ToList().Find(item => item.Id == (int)MainGrid.CurrentRow.Cells[0].Value).ReceptionID = ChangeMenuPointForm.ReceptionID; db.Menu.ToList().Find(item => item.Id == (int)MainGrid.CurrentRow.Cells[0].Value).WaitingTime_Min = ChangeMenuPointForm.WTime; } } if (_currentTable.Equals(db.Receptions.GetType())) { int no = Int32.Parse(MainGrid.CurrentRow.Cells[0].Value.ToString()); AddReception ChangeReceptionForm = new AddReception( db.Receptions.Where (recept => recept.No == no).ToList() , this); changeForm.Add(ChangeReceptionForm); ChangeReceptionForm.ShowDialog(); if (ChangeReceptionForm.flag) { db.Receptions.RemoveRange(db.Receptions.Where(recept => recept.No == no).ToList()); db.SaveChanges(); db.Receptions.AddRange(ChangeReceptionForm.ReceptionList); } } if (_currentTable.Equals(db.Cheks.GetType())) { int no = Int32.Parse(MainGrid.CurrentRow.Cells[0].Value.ToString()); AddChek ChangeCheckFrom = new AddChek(this, db.Cheks.Where(item => item.Id == no).ToList()); changeForm.Add(ChangeCheckFrom); ChangeCheckFrom.ShowDialog(); if (ChangeCheckFrom.flag && ChangeCheckFrom.ChekList != null) { db.Cheks.AddRange(ChangeCheckFrom.ChekList); } } try { db.SaveChanges(); foreach (Form item in changeForm) { item.Dispose(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } Refresh_Grid(); }
private void AddBtn_Click(object sender, EventArgs e) { if (_currentTable.Equals(db.Orders.GetType())) { AddOrder AddOrderForm = new AddOrder(this); AddOrderForm.ShowDialog(); if (AddOrderForm.flag) { try { Orders new_order = new Orders { DishID = AddOrderForm.DishID, ChefId = AddOrderForm.Chef, Time = AddOrderForm.time, State = AddOrderForm.state }; db.Orders.Add(new_order); db.SaveChanges(); AddOrderForm.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } if (_currentTable.Equals(db.Chefs.GetType())) { AddChef AddChefForm = new AddChef(); AddChefForm.ShowDialog(); if (AddChefForm.flag) { try { Chef new_chef = new Chef { Name = AddChefForm.name, Surname = AddChefForm.surname, Salary = AddChefForm.salary, Birthday = AddChefForm.birthday, Pozition_name = AddChefForm.pozition }; db.Chefs.Add(new_chef); db.SaveChanges(); AddChefForm.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } if (_currentTable.Equals(db.Products.GetType())) { AddProducts AddProductForm = new AddProducts(); AddProductForm.ShowDialog(); if (AddProductForm.flag) { try { Products new_product = new Products { ProductName = AddProductForm.ProdName, Count = AddProductForm.Count, Type = AddProductForm.Type }; db.Products.Add(new_product); db.SaveChanges(); AddProductForm.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } if (_currentTable.Equals(db.Menu.GetType())) { AddMenuPoint AddMenuPointForm = new AddMenuPoint(this); AddMenuPointForm.ShowDialog(); if (AddMenuPointForm.flag) { try { Classes.Menu new_menu = new Classes.Menu { DishName = AddMenuPointForm.DishName, ReceptionID = AddMenuPointForm.ReceptionID, Cost = AddMenuPointForm.Cost, WaitingTime_Min = AddMenuPointForm.WTime }; db.Menu.Add(new_menu); db.SaveChanges(); AddMenuPointForm.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } if (_currentTable.Equals(db.Receptions.GetType())) { AddReception AddReceptionForm = new AddReception(this); AddReceptionForm.ShowDialog(); if (AddReceptionForm.flag) { try { db.Receptions.AddRange(AddReceptionForm.ReceptionList); db.SaveChanges(); AddReceptionForm.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } if (_currentTable.Equals(db.Cheks.GetType())) { AddChek AddCheckForm = new AddChek(this); AddCheckForm.ShowDialog(); if (AddCheckForm.flag) { db.Cheks.AddRange(AddCheckForm.ChekList); foreach (var CurrentOrder in AddCheckForm.ChosenOrder) { db.Orders.Find(CurrentOrder.Id).State = true; } foreach (var CurrentDish in AddCheckForm.ChosenDish) { foreach (var CurrentReception in db.Receptions.Where(item => item.No == CurrentDish.ReceptionID).ToList()) { db.Products.ToList().Find(item => item.Id == CurrentReception.ProductId).Count -= CurrentReception.Count; } } db.SaveChanges(); AddCheckForm.Dispose(); } } Refresh_Grid(); }
private void addProductsToolStripMenuItem_Click(object sender, EventArgs e) { var form = new AddProducts(UpdateDataGridWiew); form.ShowDialog(); }
private void btnProducts_Click(object sender, RoutedEventArgs e) { AddProducts addProd = new AddProducts(this, lstProductModel, ifEdit); addProd.ShowDialog(); }
//private void loadProductOnCombo() //{ // conDB = new ConnectionDB(); // ProductModel prod = new ProductModel(); // string queryString = "SELECT ID, productname, description FROM dbfh.tblproducts WHERE isDeleted = 0"; // MySqlDataReader reader = conDB.getSelectConnection(queryString, null); // comboProduct.Items.Clear(); // searchProduct.Items.Clear(); // while (reader.Read()) // { // prod.ID = reader["ID"].ToString(); // prod.ProductName = reader["productname"].ToString(); // prod.Description = reader["description"].ToString(); // comboProduct.Items.Add(prod); // searchProduct.Items.Add(prod); // prod = new ProductModel(); // } // conDB.closeConnection(); //} //private List<DrugstoresSalesModel> loadDataGridDetails() //{ // conDB = new ConnectionDB(); // List<DrugstoresSalesModel> lstSales = new List<DrugstoresSalesModel>(); // DrugstoresSalesModel sales = new DrugstoresSalesModel(); // string queryString = "SELECT dbfh.tblsales.ID, dbfh.tblsales.deliverydate, dbfh.tblsales.quantity, dbfh.tblsales.drugstoreID, " // + "dbfh.tbldrugstores.drugstore, dbfh.tblproducts.description AS product, dbfh.tblsales.productID as prodID " // + "FROM((dbfh.tblsales INNER JOIN dbfh.tbldrugstores ON dbfh.tblsales.drugstoreID = dbfh.tbldrugstores.ID) " + // "INNER JOIN dbfh.tblproducts ON dbfh.tblsales.productID = dbfh.tblproducts.ID) " + // "WHERE dbfh.tblsales.isDeleted = 0 ORDER BY dbfh.tblsales.deliverydate DESC"; // MySqlDataReader reader = conDB.getSelectConnection(queryString, null); // while (reader.Read()) // { // sales.ID = reader["ID"].ToString(); // DateTime dte = DateTime.Parse(reader["deliveryDate"].ToString()); // sales.DeliveryDate = dte.ToShortDateString(); // sales.Quantity = Convert.ToInt32(reader["quantity"].ToString()); // sales.DrugstoreID = reader["drugstoreID"].ToString(); // sales.DrugstoreName = reader["drugstore"].ToString(); // sales.ProductName = reader["product"].ToString(); // sales.ProductID = reader["prodID"].ToString(); // lstSales.Add(sales); // sales = new DrugstoresSalesModel(); // } // conDB.closeConnection(); // return lstSales; //} //private void loadDrugstoreOnCombo() //{ // conDB = new ConnectionDB(); // string queryString = "SELECT ID, drugstore, description FROM dbfh.tbldrugstores WHERE isDeleted = 0"; // MySqlDataReader reader = conDB.getSelectConnection(queryString, null); // comboDrugstore.Items.Clear(); // searchDrugstore.Items.Clear(); // while (reader.Read()) // { // DrugstoreModel drg = new DrugstoreModel(); // drg.ID = reader["ID"].ToString(); // drg.DrugstoreName = reader["drugstore"].ToString(); // drg.Description = reader["description"].ToString(); // comboDrugstore.Items.Add(drg); // searchDrugstore.Items.Add(drg); // } // conDB.closeConnection(); //} //private void updateRecord(DrugstoresSalesModel dsm) //{ // conDB = new ConnectionDB(); // string queryString = "UPDATE dbfh.tblsales SET deliverydate = ?, quantity = ?, drugstoreID = ?, productID = ? WHERE ID = ?"; // List<string> parameters = new List<string>(); // DateTime date = DateTime.Parse(deliveryDate.Text); // parameters.Add(date.Year + "/" + date.Month + "/" + date.Day); // parameters.Add(txtQuantity.Text); // parameters.Add(comboDrugstore.SelectedValue.ToString()); // parameters.Add(comboProduct.SelectedValue.ToString()); // parameters.Add(dsm.ID); // conDB.AddRecordToDatabase(queryString, parameters); // conDB.closeConnection(); //} //private void saveRecord() //{ // conDB = new ConnectionDB(); // string queryString = "INSERT INTO dbfh.tblsales (deliverydate, quantity, drugstoreID, productID, isDeleted) VALUES " + // "(?,?,?,?,0)"; // List<string> parameters = new List<string>(); // DateTime date = DateTime.Parse(deliveryDate.Text); // parameters.Add(date.Year + "/" + date.Month + "/" + date.Day); // parameters.Add(txtQuantity.Text); // parameters.Add(comboDrugstore.SelectedValue.ToString()); // parameters.Add(comboProduct.SelectedValue.ToString()); // conDB.AddRecordToDatabase(queryString, parameters); // conDB.closeConnection(); //} //private List<DrugstoresSalesModel> search() //{ // List<DrugstoresSalesModel> lstDrugstores = new List<DrugstoresSalesModel>(); // DrugstoresSalesModel sales = new DrugstoresSalesModel(); // conDB = new ConnectionDB(); // string queryString = "SELECT dbfh.tblsales.ID, dbfh.tblsales.deliverydate, dbfh.tblsales.quantity, dbfh.tblsales.drugstoreID, " // + "dbfh.tbldrugstores.drugstore, dbfh.tblproducts.description AS product, dbfh.tblsales.productID as prodID " // + "FROM((dbfh.tblsales INNER JOIN dbfh.tbldrugstores ON dbfh.tblsales.drugstoreID = dbfh.tbldrugstores.ID) " + // "INNER JOIN dbfh.tblproducts ON dbfh.tblsales.productID = dbfh.tblproducts.ID) " + // "WHERE dbfh.tblsales.isDeleted = 0"; // List<string> parameters = new List<string>(); // if (checkDate.IsChecked == true) // { // queryString += " AND (deliverydate BETWEEN ? AND ?)"; // DateTime sdate = DateTime.Parse(searchDateFrom.Text); // parameters.Add(sdate.Year + "/" + sdate.Month + "/" + sdate.Day); // sdate = DateTime.Parse(searchDateTo.Text); // parameters.Add(sdate.Year + "/" + sdate.Month + "/" + sdate.Day); // } // if (checkCategory.IsChecked == true) // { // queryString += " AND (dbfh.tblsales.productID = ?)"; // parameters.Add(searchProduct.SelectedValue.ToString()); // } // if (checkDrugstore.IsChecked == true) // { // queryString += " AND (dbfh.tblsales.drugstoreID = ?)"; // parameters.Add(searchDrugstore.SelectedValue.ToString()); // } // queryString += " ORDER BY dbfh.tblsales.deliverydate DESC"; // MySqlDataReader reader = conDB.getSelectConnection(queryString, parameters); // while (reader.Read()) // { // sales.ID = reader["ID"].ToString(); // DateTime dte = DateTime.Parse(reader["deliveryDate"].ToString()); // sales.DeliveryDate = dte.ToShortDateString(); // sales.Quantity = Convert.ToInt32(reader["quantity"].ToString()); // sales.DrugstoreID = reader["drugstoreID"].ToString(); // sales.DrugstoreName = reader["drugstore"].ToString(); // sales.ProductName = reader["product"].ToString(); // sales.ProductID = reader["prodID"].ToString(); // lstDrugstores.Add(sales); // sales = new DrugstoresSalesModel(); // } // conDB.closeConnection(); // return lstDrugstores; //} #endregion private void btnAdd_Click(object sender, RoutedEventArgs e) { AddProducts addProducts = new AddProducts(this, lstProductsOrdered, lstPayments); addProducts.ShowDialog(); }
//add a new product through form private void btnAddProducts_Click(object sender, EventArgs e) { var addProductForm = new AddProducts(this); addProductForm.ShowDialog(); }