public MODEL.ProductionMaterialModel Update(MODEL.ProductionMaterialModel model) { try { using (_context = new HSSNInventoryEntities()) { var editModel = _context.ProductionMaterials.FirstOrDefault(a => a.ProductionMaterialId == model.ProductionMaterialId); if (editModel != null) { editModel.MaterialName = model.MaterialName; editModel.Description = model.Description; editModel.UnitOfMeasurementId = model.UnitOfMeasurementId; editModel.Description = model.Description; } _context.Entry(editModel).State = EntityState.Modified; _context.SaveChanges(); return(model); } } catch (Exception e) { Console.WriteLine(e); return(new ProductionMaterialModel()); } }
private void btnAdd_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txtName.Text)||string.IsNullOrWhiteSpace(txtType.Text)||string.IsNullOrWhiteSpace(cmbUnit.Text)) { ClsCommon.ShowErrorToolTip(txtName,"Please Enter The ProductionMaterial Name"); } else { var model = new ProductionMaterialModel { ProductionMaterialId = _productionMaterialId, MaterialName = txtName.Text, MaterialType = txtType.Text, Description = txtDesc.Text, UnitOfMeasurementId = (int)cmbUnit.SelectedValue }; if (_isNewMode) { _productionMaterialId = _productionMaterialService.Save(model).ProductionMaterialId; if (_productionMaterialId<=0) return; MessageBox.Show(@"Data Saved Successfully", @"Save", MessageBoxButtons.OK, MessageBoxIcon.Information); var frm = (FrmProductionMaterial)_frmForm; frm.grdData.Rows.Add(_productionMaterialId, model.MaterialName,model.UnitOfMeasurementId,cmbUnit.Text, model.MaterialType,model.Description); frm.grdData.Rows[frm.grdData.Rows.Count - 1].IsSelected = true; txtName.Focus(); txtName.Text = ""; Notify(); } else { var success = _productionMaterialService.Update(model).ProductionMaterialId; if (success<=0) return; MessageBox.Show(@"Data Updated Successfully", @"Update", MessageBoxButtons.OK, MessageBoxIcon.Information); var frm = (FrmProductionMaterial)_frmForm; frm.grdData.CurrentRow.Cells["MaterialName"].Value = model.MaterialName; frm.grdData.CurrentRow.Cells["MaterialType"].Value = model.MaterialType; frm.grdData.CurrentRow.Cells["UnitOfMeasurementId"].Value = model.UnitOfMeasurementId; frm.grdData.CurrentRow.Cells["UnitName"].Value = cmbUnit.Text; frm.grdData.CurrentRow.Cells["Description"].Value = model.Description; Close(); Notify(); } } }
public FrmProductionMaterialEntry(ProductionMaterialModel model, Form frmForm) { InitializeComponent(); _unitService = new UnitService(); _frmForm = frmForm; _productionMaterialService = new ProductionMaterialService(); LoadUnits(); if (model != null) { _isNewMode = false; _productionMaterialId = model.ProductionMaterialId; txtName.Text = model.MaterialName; txtType.Text = model.MaterialType; txtDesc.Text = model.Description; cmbUnit.SelectedValue = model.UnitOfMeasurementId; btnAdd.Text = @"Update"; } else { _isNewMode = true; btnAdd.Text = @"Save"; } }
public MODEL.ProductionMaterialModel Save(MODEL.ProductionMaterialModel model) { try { using (_context = new HSSNInventoryEntities()) { var addmodel = new ProductionMaterial() { MaterialName = model.MaterialName, Description = model.Description, MaterialType = model.MaterialType, UnitOfMeasurementId = model.UnitOfMeasurementId }; _context.Entry(addmodel).State = EntityState.Added; _context.SaveChanges(); model.ProductionMaterialId = addmodel.ProductionMaterialId; return(model); } } catch (Exception aException) { return(new ProductionMaterialModel()); } }
private void btnEdit_Click(object sender, EventArgs e) { if (Convert.ToInt32(lblID.Text) <= 0) return; var model = new ProductionMaterialModel() { ProductionMaterialId = Convert.ToInt32(lblID.Text), MaterialName = lblName.Text, UnitOfMeasurementId = _unitId, MaterialType = lblType.Text, Description = lblDesc.Text }; var frm = new FrmProductionMaterialEntry(model, this); frm.ShowDialog(this); }