private void btnOK_Click(object sender, EventArgs e) { TBL_MP_Master_State model = null; ServiceMASTERS _service = new ServiceMASTERS(); try { if (this.StateID == 0) { model = new TBL_MP_Master_State(); } else { model = _service.GetStateDBRecordByStateID(this.StateID); } // gather data into model from controls model.StateName = txtStateName.Text.Trim(); model.FK_CountryId = ((SelectListItem)cboCountries.SelectedItem).ID; model.IsActive = chkIsActive.Checked; model.FK_CompanyID = Program.CURR_USER.CompanyID; model.FK_BranchID = Program.CURR_USER.BranchID; if (StateID == 0) { this.StateID = _service.AddNewState(model); } else { _service.EditState(model); } this.DialogResult = DialogResult.OK; } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "frmAddEditState::btnOK_Click", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void ScatterData() { try { TBL_MP_Master_State model = (new ServiceMASTERS()).GetStateDBRecordByStateID(this.StateID); if (model != null) { txtStateName.Text = model.StateName; SelectListItem item = ((List <SelectListItem>)cboCountries.DataSource).Where(x => x.ID == model.FK_CountryId).FirstOrDefault(); cboCountries.SelectedItem = item; chkIsActive.Checked = model.IsActive; } } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(ex.Message, "frmAddEditState::ScatterData", MessageBoxButtons.OK, MessageBoxIcon.Error); } }