public BricksInOrderAddEditFrom(OrderedBrick obj) { InitializeComponent(); OrderedBrickInfo = obj; db = new BrickWorksModel(); if (OrderedBrickInfo.Id == 0) { OrderedBrickInfo.BrickId = db.Bricks.First().Id; } orderedBrickBindingSource.DataSource = OrderedBrickInfo; brickBindingSource.DataSource = db.Bricks.ToList(); CalcRemaindedBricks(); }
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; } } }