private void AddButton_Click(object sender, EventArgs e)
        {
            using (PharmacyEntities db = new PharmacyEntities())
            {
                Manufactures buff = new Manufactures();

                try
                {
                    buff.id = Convert.ToInt32(idTextBox.Text);
                    buff.NameManufacture = nameTextBox.Text;
                }
                catch (FormatException)
                {
                    MessageBox.Show("Неверно введённые данные!");
                    return;
                }

                db.Manufactures.Add(buff);

                try
                {
                    db.SaveChanges();
                }
                catch (DbUpdateException)
                {
                    MessageBox.Show("ID не должен повторяться!");
                    return;
                }
            }

            this.Close();
        }
Example #2
0
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            using (PharmacyEntities db = new PharmacyEntities())
            {
                db.ProductList.RemoveRange(db.ProductList.Where(items => items.shelfLife < DateTime.Now));
                db.SaveChanges();

                InitializeRows();
            }
        }
Example #3
0
        private void DeleteToolStripButton_Click(object sender, EventArgs e)
        {
            switch (tablesToolStripComboBox.SelectedIndex)
            {
            case 0:
                foreach (var item in dataGridView.Rows)
                {
                    if ((item as DataGridViewRow).Selected)
                    {
                        using (PharmacyEntities db = new PharmacyEntities())
                        {
                            var buff = db.Manufactures.Find((int)(item as DataGridViewRow).Cells[0].Value);
                            db.Manufactures.Remove(buff);

                            try
                            {
                                db.SaveChanges();
                            }
                            catch (DbUpdateException)
                            {
                                MessageBox.Show("Ошибка");
                                return;
                            }
                        }

                        break;
                    }
                }

                InitializeRows();
                break;

            case 1:
                foreach (var item in dataGridView.Rows)
                {
                    if ((item as DataGridViewRow).Selected)
                    {
                        using (PharmacyEntities db = new PharmacyEntities())
                        {
                            var buff = db.MedicalPreparations.Find((int)(item as DataGridViewRow).Cells[0].Value);
                            db.MedicalPreparations.Remove(buff);

                            try
                            {
                                db.SaveChanges();
                            }
                            catch (DbUpdateException)
                            {
                                MessageBox.Show("Ошибка");
                                return;
                            }
                        }

                        break;
                    }
                }

                InitializeRows();
                break;

            case 2:
                foreach (var item in dataGridView.Rows)
                {
                    if ((item as DataGridViewRow).Selected)
                    {
                        using (PharmacyEntities db = new PharmacyEntities())
                        {
                            var buff = db.PointsOfSale.Find((int)(item as DataGridViewRow).Cells[0].Value);
                            db.PointsOfSale.Remove(buff);

                            try
                            {
                                db.SaveChanges();
                            }
                            catch (DbUpdateException)
                            {
                                MessageBox.Show("Ошибка");
                                return;
                            }
                        }

                        break;
                    }
                }

                InitializeRows();
                break;

            case 3:
                foreach (var item in dataGridView.Rows)
                {
                    if ((item as DataGridViewRow).Selected)
                    {
                        using (PharmacyEntities db = new PharmacyEntities())
                        {
                            var buff = db.ProductList.Find((int)(item as DataGridViewRow).Cells[0].Value);
                            db.ProductList.Remove(buff);

                            try
                            {
                                db.SaveChanges();
                            }
                            catch (DbUpdateException)
                            {
                                MessageBox.Show("Ошибка");
                                return;
                            }
                        }

                        break;
                    }
                }

                InitializeRows();
                break;
            }
        }