private void btnAdd_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txtFlavourName.Text)) { ClsCommon.ShowErrorToolTip(txtFlavourName, "Please Enter The Flavour Name"); } else { var model = new FlavourModel { FlavourId = _flavourId, FlavourName = txtFlavourName.Text, Description = txtRemarks.Text }; if (_isNewMode) { _flavourId = _flavourService.Save(model); if (_flavourId <= 0) { return; } MessageBox.Show(@"Data Saved Successfully", @"Save", MessageBoxButtons.OK, MessageBoxIcon.Information); var frm = (FrmFlavour)_frmForm; frm.grdData.Rows.Add(_flavourId, model.FlavourName, model.Description); frm.grdData.Rows[frm.grdData.Rows.Count - 1].IsSelected = true; txtFlavourName.Focus(); txtFlavourName.Text = ""; txtRemarks.Text = ""; notify(); } else { var success = _flavourService.Update(model); if (!success) { return; } MessageBox.Show(@"Data Updated Successfully", @"Update", MessageBoxButtons.OK, MessageBoxIcon.Information); var frm = (FrmFlavour)_frmForm; frm.grdData.CurrentRow.Cells["FlavourName"].Value = model.FlavourName; frm.grdData.CurrentRow.Cells["Description"].Value = model.Description; notify(); Close(); } } }
private void btnEdit_Click(object sender, EventArgs e) { if (Convert.ToInt32(lblID.Text) <= 0) { return; } var model = new FlavourModel() { FlavourId = Convert.ToInt32(lblID.Text), FlavourName = lblName.Text, Description = lblRemarks.Text }; var frm = new FrmFlavourEntry(model, this); frm.ShowDialog(this); }
public FrmFlavourEntry(FlavourModel model, Form frmForm) { InitializeComponent(); _frmForm = frmForm; _flavourService = new FlavourService(); if (model != null) { _isNewMode = false; _flavourId = model.FlavourId; txtFlavourName.Text = model.FlavourName; txtRemarks.Text = model.Description; btnAdd.Text = @"Update"; } else { _isNewMode = true; btnAdd.Text = @"Save"; } }