Exemple #1
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 = SalesGrid.HitTest(e.X, e.Y).RowIndex;

                if (currentMouseOverRow >= 0)
                {
                    m.MenuItems.Add(new MenuItem("Просмотр", new EventHandler(delegate(Object o, EventArgs a)
                    {
                        string id = (string)SalesGrid.Rows[currentMouseOverRow].Cells[0].Value;
                        var form  = new BuyerData(id);
                        form.ShowDialog();
                        RefreshGrid();
                    })));
                }

                m.Show(SalesGrid, new Point(e.X, e.Y));
            }
        }
Exemple #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 = SalesGrid.HitTest(e.X, e.Y).RowIndex;

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

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