Пример #1
0
        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();
        }
Пример #2
0
        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();
        }