Esempio n. 1
0
        /// <summary>
        /// Вызов формы для добавления изделия
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddProduction_Click(object sender, EventArgs e)
        {
            var form = new ProductionForm();

            form.ShowDialog();
            RefreshGrid();
        }
Esempio n. 2
0
        /// <summary>
        /// Контекстное меню для таблицы
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SalesMouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                ContextMenu m = new ContextMenu();
                int         currentMouseOverRow = Grid.HitTest(e.X, e.Y).RowIndex;

                if (currentMouseOverRow >= 0)
                {
                    m.MenuItems.Add(new MenuItem("Просмотр", new EventHandler(delegate(Object o, EventArgs a)
                    {
                        int id   = (int)Grid.Rows[currentMouseOverRow].Cells[0].Value;
                        var form = new ProductionForm(id, Models.EditMode.View);
                        form.ShowDialog();
                        RefreshGrid();
                    })));
                    m.MenuItems.Add(new MenuItem("Редактировать", new EventHandler(delegate(Object o, EventArgs a)
                    {
                        int id   = (int)Grid.Rows[currentMouseOverRow].Cells[0].Value;
                        var form = new ProductionForm(id, Models.EditMode.Edit);
                        form.ShowDialog();
                        RefreshGrid();
                    })));
                    m.MenuItems.Add(new MenuItem("Удалить", new EventHandler(delegate(Object o, EventArgs a)
                    {
                        int id = (int)Grid.Rows[currentMouseOverRow].Cells[0].Value;
                        if (MessageBox.Show("Вы точно хотите удалить этот элемент?", "Удалить?", MessageBoxButtons.OKCancel) == DialogResult.OK)
                        {
                            try
                            {
                                var context = new ApplicationDbContext();
                                //TODO удаление записи по ключу
                                context.Productions.Remove(context.Productions.FirstOrDefault(x => x.Id == id));
                                context.SaveChanges();
                            }catch (Exception ex)
                            {
                                MessageBox.Show("Сначала необходимо удалить все связанные данные", "Ошибка");
                            }
                        }
                        RefreshGrid();
                    })));
                }

                m.Show(Grid, new Point(e.X, e.Y));
            }
        }