Пример #1
0
        private void pbBricksAdd_Click(object sender, EventArgs e)
        {
            using (var frm = new BricksInOrderAddEditFrom(new OrderedBrick()))
            {
                frm.Theme = this.Theme;
                frm.Style = this.Style;
                if (mcbClient.SelectedIndex < 0)
                {
                    frm.ClientId = 0;
                }
                else
                {
                    frm.ClientId = (clientBindingSource.Current as Client).Id;
                }

                if (frm.ShowDialog(this) == DialogResult.OK)
                {
                    if (OrderInfo.Id > 0)
                    {
                        Order ord = db.Orders.FirstOrDefault(o => o.Id == OrderInfo.Id);
                        if (ord != null)
                        {
                            ord.OrderedBricks.Add(frm.OrderedBrickInfo);
                            db.SaveChanges();
                            LoadBricks();
                        }
                    }
                    else
                    {
                        OrderInfo.OrderedBricks.Add(frm.OrderedBrickInfo);
                        string brickMark = db.Bricks.FirstOrDefault(b => b.Id == frm.OrderedBrickInfo.BrickId).Mark;
                        bricksInOrderViewBindingSource.Add(new BricksInOrderView
                        {
                            Id        = frm.OrderedBrickInfo.Id,
                            BrickId   = frm.OrderedBrickInfo.BrickId,
                            OrderId   = frm.OrderedBrickInfo.OrderId,
                            BrickMark = brickMark,
                            OrderDate = OrderInfo.OrderedDate,
                            Quantity  = frm.OrderedBrickInfo.Quantity
                        });
                        orderBindingSource.EndEdit();
                    }
                }
            }
        }
Пример #2
0
        private void bricksGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 4 || e.ColumnIndex == 5)
            {
                var boundItem    = ((BricksInOrderView)bricksGrid.Rows[e.RowIndex].DataBoundItem);
                var oBricks      = db.OrderedBricks.FirstOrDefault(ob => ob.Id == boundItem.Id);
                var oBricks_edit = new OrderedBrick
                {
                    Id       = oBricks.Id,
                    OrderId  = oBricks.OrderId,
                    Quantity = oBricks.Quantity,
                    BrickId  = oBricks.BrickId
                };

                switch (e.ColumnIndex)
                {
                //bricks edit
                case 4:
                    using (var frm = new BricksInOrderAddEditFrom(oBricks_edit))
                    {
                        frm.Theme = this.Theme;
                        frm.Style = this.Style;
                        if (mcbClient.SelectedIndex < 0)
                        {
                            frm.ClientId = 0;
                        }
                        else
                        {
                            frm.ClientId = (clientBindingSource.Current as Client).Id;
                        }
                        if (frm.ShowDialog(this) == DialogResult.OK)
                        {
                            if (oBricks != null)
                            {
                                oBricks.Id       = oBricks_edit.Id;
                                oBricks.OrderId  = oBricks_edit.OrderId;
                                oBricks.Quantity = oBricks_edit.Quantity;
                                oBricks.BrickId  = oBricks_edit.BrickId;
                                db.SaveChanges();
                            }
                            LoadBricks();
                        }
                    }
                    break;

                //bricks delete
                case 5:
                    if (oBricks != null)
                    {
                        if (OrderInfo.Id > 0)
                        {
                            db.OrderedBricks.Remove(oBricks);
                            db.SaveChanges();
                        }
                    }
                    bricksInOrderViewBindingSource.Remove(boundItem);
                    LoadBricks();
                    break;

                default:
                    break;
                }
            }
        }