public bool Update(MODEL.WareHouseModel model) { try { using (_context = new HSSNInventoryEntities()) { var editModel = _context.WareHouses.FirstOrDefault(a => a.WareHouseId == model.WareHouseId); if (editModel != null) { editModel.WareHouseName = model.WareHouseName; editModel.WareHouseType = model.WareHouseType; editModel.Description = model.Description; } _context.Entry(editModel).State = EntityState.Modified; _context.SaveChanges(); return(true); } } catch (Exception e) { Console.WriteLine(e); return(false); } }
private void btnAdd_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txtWareHouseName.Text)||string.IsNullOrWhiteSpace(cmbType.Text)) { ClsCommon.ShowErrorToolTip(txtWareHouseName,"Please Enter The WareHouse Name"); } else { var model = new WareHouseModel { WareHouseId = _wareHouseId, WareHouseName = txtWareHouseName.Text, WareHouseType = cmbType.Text, Description = txtRemarks.Text }; if (_isNewMode) { _wareHouseId = _wareHouseService.Save(model); if (_wareHouseId<=0) return; MessageBox.Show(@"Data Saved Successfully", @"Save", MessageBoxButtons.OK, MessageBoxIcon.Information); var frm = (FrmWareHouse)_frmForm; frm.grdData.Rows.Add(_wareHouseId, model.WareHouseName,model.WareHouseType, model.Description); frm.grdData.Rows[frm.grdData.Rows.Count - 1].IsSelected = true; txtWareHouseName.Focus(); txtWareHouseName.Text = ""; txtRemarks.Text = ""; Notify(); } else { var success = _wareHouseService.Update(model); if (!success) return; MessageBox.Show(@"Data Updated Successfully", @"Update", MessageBoxButtons.OK, MessageBoxIcon.Information); var frm = (FrmWareHouse)_frmForm; frm.grdData.CurrentRow.Cells["WareHouseName"].Value = model.WareHouseName; frm.grdData.CurrentRow.Cells["WareHouseType"].Value = model.WareHouseType; frm.grdData.CurrentRow.Cells["Description"].Value = model.Description; Close(); Notify(); } } }
public FrmWareHouseEntry(WareHouseModel model, Form frmForm) { InitializeComponent(); _frmForm = frmForm; _wareHouseService = new WareHouseService(); if (model != null) { _isNewMode = false; _wareHouseId = model.WareHouseId; txtWareHouseName.Text = model.WareHouseName; cmbType.Text = model.WareHouseType; txtRemarks.Text = model.Description; btnAdd.Text = @"Update"; } else { _isNewMode = true; btnAdd.Text = @"Save"; } }
public int Save(MODEL.WareHouseModel model) { try { using (_context = new HSSNInventoryEntities()) { var addModel = new WareHouse() { WareHouseName = model.WareHouseName, WareHouseType = model.WareHouseType, Description = model.Description }; _context.Entry(addModel).State = EntityState.Added; _context.SaveChanges(); return(addModel.WareHouseId); } } catch (Exception e) { //Console.WriteLine(e); return(0); } }
private void btnEdit_Click(object sender, EventArgs e) { if (Convert.ToInt32(lblID.Text) <= 0) return; var model = new WareHouseModel() { WareHouseId = Convert.ToInt32(lblID.Text), WareHouseName = lblName.Text, WareHouseType = lblType.Text, Description = lblRemarks.Text }; var frm = new FrmWareHouseEntry(model, this); frm.ShowDialog(this); }