private void btnUpdate_Click(object sender, EventArgs e) { string check = checkData(); if (check != null) { MessageBox.Show(check); return; } InsuranceInfoData inData = new InsuranceInfoData(); DataRow dr = inData.Tables[InsuranceInfoData.insuranceInfo_TABLE].NewRow(); dr[InsuranceInfoData.id_FIELD] = _id; dr[InsuranceInfoData.name_FIELD] = txtName.Text.Trim(); dr[InsuranceInfoData.family_FIELD] = txtFamily.Text.Trim(); dr[InsuranceInfoData.phoneNumber_FIELD] = txtPhoneNumber.Text.Trim(); dr[InsuranceInfoData.insuranceNumber_FIELD] = txtInsuranceNumber.Text.Trim(); dr[InsuranceInfoData.haveDid_FIELD] = cbxHaveDid.Checked; dr[InsuranceInfoData.address_FIELD] = txtAddress.Text.Trim(); dr[InsuranceInfoData.description_FIELD] = txtDescription.Text.Trim(); dr[InsuranceInfoData.mobileNumber_FIELD] = txtMobilePhone.Text.Trim(); dr[InsuranceInfoData.CustomerType_FIELD] = cmbCustomerType.SelectedIndex; #region dateValidation GregorianCalendar gcal = new GregorianCalendar(); int d = 12; int m = 0; int y = 0; CheckDate.checkDate(txtBeginDate.Text, ref y, ref m, ref d); DateTime persianDateTime = new DateTime(y, m, d, new PersianCalendar()); DateTime greorianDateTime = new DateTime(gcal.GetYear(persianDateTime), gcal.GetMonth(persianDateTime), gcal.GetDayOfMonth(persianDateTime), new GregorianCalendar()); dr[InsuranceInfoData.beginDate_FIELD] = greorianDateTime; // CheckDate.checkDate(txtEndDate.Text, ref y, ref m, ref d); persianDateTime = new DateTime(y, m, d, new PersianCalendar()); greorianDateTime = new DateTime(gcal.GetYear(persianDateTime), gcal.GetMonth(persianDateTime), gcal.GetDayOfMonth(persianDateTime), new GregorianCalendar()); dr[InsuranceInfoData.endDate_FIELD] = greorianDateTime; // //Creation Date String todayShamsi; String[] dateArr; CheckDate.checkDate(txtCreationDate.Text, ref y, ref m, ref d); persianDateTime = new DateTime(y, m, d, new PersianCalendar()); greorianDateTime = new DateTime(gcal.GetYear(persianDateTime), gcal.GetMonth(persianDateTime), gcal.GetDayOfMonth(persianDateTime), new GregorianCalendar()); dr[InsuranceInfoData.creationDate_FIELD] = greorianDateTime; // //Last update date todayShamsi = RMX_TOOLS.date.DateXFormer.gregorianToPersianString(DateTime.Now); dateArr = todayShamsi.Split('/'); persianDateTime = new DateTime(int.Parse(dateArr[0]), int.Parse(dateArr[1]), int.Parse(dateArr[2]), new PersianCalendar()); greorianDateTime = new DateTime(gcal.GetYear(persianDateTime), gcal.GetMonth(persianDateTime), gcal.GetDayOfMonth(persianDateTime), new GregorianCalendar()); dr[InsuranceInfoData.lastUpdateDate_FIELD] = greorianDateTime; // //Birth date if (txtBirthDate.Text.Trim() != DateConstants.NULL_Date.Trim()) { CheckDate.checkDate(txtBirthDate.Text, ref y, ref m, ref d); persianDateTime = new DateTime(y, m, d, new PersianCalendar()); greorianDateTime = new DateTime(gcal.GetYear(persianDateTime), gcal.GetMonth(persianDateTime), gcal.GetDayOfMonth(persianDateTime), new GregorianCalendar()); dr[InsuranceInfoData.BirthDate_FIELD] = greorianDateTime; } #endregion //fetch id from comboBox int insuranceTypeId = int.Parse(cmbInsuranceType.SelectedValue + ""); dr[InsuranceInfoData.insuranceType_FIELD] = insuranceTypeId; string insuranceNumber = txtInsuranceNumber.Text.Trim(); inData.Tables[InsuranceInfoData.insuranceInfo_TABLE].Rows.Add(dr); try { if (insuranceInfoBs.checkInsuranceNumberExists(txtInsuranceNumber.Text.Trim(), _id)) { MessageBox.Show("امکان اضافه کردن این رکورد وجود ندارد ، شماره بیمه تکراری است"); txtInsuranceNumber.Focus(); return; } if (cbxHaveDid.Checked) { string endDate = insuranceInfoBs.getEndDateByInsuranceNumer(txtInsuranceNumber.Text.Trim()); checkForLogging(_id, endDate); } if (_id > 0) { insuranceInfoBs.update(inData); } else { insuranceInfoBs.add(inData); } this.Close(); } catch (Exception ex) { string s = ex.ToString(); if (s.IndexOf("duplicate") >= 0) { MessageBox.Show("امکان اضافه کردن این رکورد وجود ندارد ، شماره بیمه تکراری است"); txtInsuranceNumber.Focus(); } else { MessageBox.Show(ex.ToString()); } return; } // MainForm.MainFormInstance.fillGrid(); }
private void btnUpdate_Click(object sender, EventArgs e) { string check = checkData(); if (check != null) { MessageBox.Show(check); return; } if (dataMode == EDIT_MODE) { if (dataGridView1.CurrentRow.Selected) { if (cbxHaveDid.Checked) { cbxHaveDid.Checked = Boolean.Parse(_gridTools.getCurrentRowValue(InsuranceInfoData.haveDid_FIELD).ToString()); } } } if (dataMode == NEW_MODE) { cbxHaveDid.Checked = false; } if (dataGridView1.RowCount <= 0) { dataMode = NEW_MODE; } InsuranceInfoBS isb = new InsuranceInfoBS(); InsuranceInfoData inData = new InsuranceInfoData(); DataRow dr = inData.Tables[InsuranceInfoData.insuranceInfo_TABLE].NewRow(); dr[InsuranceInfoData.name_FIELD] = txtName.Text.Trim(); dr[InsuranceInfoData.family_FIELD] = txtFamily.Text.Trim(); dr[InsuranceInfoData.phoneNumber_FIELD] = txtPhoneNumber.Text.Trim(); dr[InsuranceInfoData.insuranceNumber_FIELD] = txtInsuranceNumber.Text.Trim(); dr[InsuranceInfoData.haveDid_FIELD] = cbxHaveDid.Checked; dr[InsuranceInfoData.address_FIELD] = txtAddress.Text.Trim(); dr[InsuranceInfoData.description_FIELD] = txtDescription.Text.Trim(); dr[InsuranceInfoData.mobileNumber_FIELD] = txtMobilePhone.Text.Trim(); dr[InsuranceInfoData.CustomerType_FIELD] = cmbCustomerType.SelectedIndex; if (!dataMode.Equals(NEW_MODE)) { dr[InsuranceInfoData.id_FIELD] = _gridTools.getCurrentRowValue(InsuranceInfoData.id_FIELD); } // Date validation and converion #region dateValidation GregorianCalendar gcal = new GregorianCalendar(); int d = 12; int m = 0; int y = 0; CheckDate.checkDate(txtBeginDate.Text, ref y, ref m, ref d); DateTime persianDateDime = new DateTime(y, m, d, new PersianCalendar()); DateTime greorianDateTime = new DateTime(gcal.GetYear(persianDateDime), gcal.GetMonth(persianDateDime), gcal.GetDayOfMonth(persianDateDime), new GregorianCalendar()); dr[InsuranceInfoData.beginDate_FIELD] = greorianDateTime; // CheckDate.checkDate(txtEndDate.Text, ref y, ref m, ref d); persianDateDime = new DateTime(y, m, d, new PersianCalendar()); greorianDateTime = new DateTime(gcal.GetYear(persianDateDime), gcal.GetMonth(persianDateDime), gcal.GetDayOfMonth(persianDateDime), new GregorianCalendar()); dr[InsuranceInfoData.endDate_FIELD] = greorianDateTime; // //Creation Date String todayShamsi; String[] dateArr; CheckDate.checkDate(txtCreationDate.Text, ref y, ref m, ref d); if (dataMode.Equals(NEW_MODE)) { todayShamsi = RMX_TOOLS.date.DateXFormer.gregorianToPersianString(DateTime.Now); dateArr = todayShamsi.Split('/'); persianDateDime = new DateTime(int.Parse(dateArr[0]), int.Parse(dateArr[1]), int.Parse(dateArr[2]), new PersianCalendar()); } else { persianDateDime = new DateTime(y, m, d, new PersianCalendar()); } greorianDateTime = new DateTime(gcal.GetYear(persianDateDime), gcal.GetMonth(persianDateDime), gcal.GetDayOfMonth(persianDateDime), new GregorianCalendar()); dr[InsuranceInfoData.creationDate_FIELD] = greorianDateTime; // //Last update date todayShamsi = RMX_TOOLS.date.DateXFormer.gregorianToPersianString(DateTime.Now); dateArr = todayShamsi.Split('/'); persianDateDime = new DateTime(int.Parse(dateArr[0]), int.Parse(dateArr[1]), int.Parse(dateArr[2]), new PersianCalendar()); greorianDateTime = new DateTime(gcal.GetYear(persianDateDime), gcal.GetMonth(persianDateDime), gcal.GetDayOfMonth(persianDateDime), new GregorianCalendar()); dr[InsuranceInfoData.lastUpdateDate_FIELD] = greorianDateTime; // //Birth date if (txtBirthDate.Text.Trim() != DateConstants.NULL_Date.Trim()) { CheckDate.checkDate(txtBirthDate.Text, ref y, ref m, ref d); persianDateDime = new DateTime(y, m, d, new PersianCalendar()); greorianDateTime = new DateTime(gcal.GetYear(persianDateDime), gcal.GetMonth(persianDateDime), gcal.GetDayOfMonth(persianDateDime), new GregorianCalendar()); dr[InsuranceInfoData.BirthDate_FIELD] = greorianDateTime; } #endregion //fetch id from comboBox int id = int.Parse(cmbInsuranceType.SelectedValue + ""); dr[InsuranceInfoData.insuranceType_FIELD] = id; string insuranceNumber = txtInsuranceNumber.Text.Trim(); inData.Tables[InsuranceInfoData.insuranceInfo_TABLE].Rows.Add(dr); try { int index; if (dataMode == NEW_MODE) { index = -1; } else { index = int.Parse(_gridTools.getCurrentRowValue(InsuranceInfoData.id_FIELD).ToString()); } if (isb.checkInsuranceNumberExists(txtInsuranceNumber.Text.Trim(), index)) { MessageBox.Show("امکان اضافه کردن این رکورد وجود ندارد ، شماره بیمه تکراری است"); txtInsuranceNumber.Focus(); return; } if (dataMode.Equals(NEW_MODE)) { isb.add(inData); InsuranceInfoData iData = isb.getByInsuranceNumer(txtInsuranceNumber.Text.Trim()); if (iData.Tables[0].Rows.Count > 0) { addlog(cbxHaveDid.Checked, int.Parse(iData.Tables[0].Rows[0][InsuranceInfoData.id_FIELD].ToString()), iData.Tables[0].Rows[0][InsuranceInfoData.endDate_FIELD].ToString()); } } else if (dataMode.Equals(EDIT_MODE)) { if (cbxHaveDid.Checked) { checkForLogging(int.Parse(_gridTools.getCurrentRowValue(InsuranceInfoData.id_FIELD).ToString()), _gridTools.getCurrentRowValue(InsuranceInfoData.endDate_FIELD).ToString()); } isb.update(inData); } } catch (Exception ex) { string s = ex.ToString(); if (s.IndexOf("duplicate") >= 0) { MessageBox.Show("امکان اضافه کردن این رکورد وجود ندارد ، شماره بیمه تکراری است"); txtInsuranceNumber.Focus(); } else { MessageBox.Show(ex.ToString()); } return; } btnRefresh_Click(null, null); MainForm.MainFormInstance.fillGrid(); int addedRow = searcInGrid(insuranceNumber); if (addedRow == -1) { dataGridView1.CurrentCell = dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[0]; } else { dataGridView1.CurrentCell = dataGridView1.Rows[addedRow].Cells[0]; } dataGridView1_SelectionChanged(null, null); dataMode = EDIT_MODE; fillSearchMap(); MainForm.MainFormInstance.msDoAgantsJobDirectly(); //frmMain.msDoAgantsJobDirectly(); }
private void btnUpdate_Click(object sender, EventArgs e) { string check = checkData(); if (check != null) { MessageBox.Show(check); return; } if (_gridTools.getCurrentRowValue(InsuranceInfoData.id_FIELD) == null) { return; } InsuranceInfoBS isb = new InsuranceInfoBS(); InsuranceInfoData inData = new InsuranceInfoData(); DataRow dr = inData.Tables[InsuranceInfoData.insuranceInfo_TABLE].NewRow(); // if (cmbHaveDid.SelectedIndex == 1) // dr[InsuranceInfoData.haveDid_FIELD] = true; // if (cmbHaveDid.SelectedIndex == 2) // dr[InsuranceInfoData.haveDid_FIELD] = false; dr[InsuranceInfoData.name_FIELD] = txtName.Text; dr[InsuranceInfoData.family_FIELD] = txtFamily.Text; dr[InsuranceInfoData.phoneNumber_FIELD] = txtPhoneNumber.Text; dr[InsuranceInfoData.insuranceNumber_FIELD] = txtInsuranceNumber.Text; dr[InsuranceInfoData.id_FIELD] = _gridTools.getCurrentRowValue(InsuranceInfoData.id_FIELD); dr[InsuranceInfoData.address_FIELD] = _gridTools.getCurrentRowValue(InsuranceInfoData.address_FIELD); dr[InsuranceInfoData.haveDid_FIELD] = _gridTools.getCurrentRowValue(InsuranceInfoData.haveDid_FIELD); dr[InsuranceInfoData.cancel_FIELD] = _gridTools.getCurrentRowValue(InsuranceInfoData.cancel_FIELD); dr[InsuranceInfoData.address_FIELD] = txtAddress.Text.Trim(); dr[InsuranceInfoData.description_FIELD] = txtDescription.Text.Trim(); // Date validation and converion #region dateValidation GregorianCalendar gcal = new GregorianCalendar(); int d = 0; int m = 0; int y = 0; CheckDate.checkDate(txtBeginDate.Text, ref y, ref m, ref d); DateTime persianDateDime = new DateTime(y, m, d, new PersianCalendar()); DateTime greorianDateTime = new DateTime(gcal.GetYear(persianDateDime), gcal.GetMonth(persianDateDime), gcal.GetDayOfMonth(persianDateDime), new GregorianCalendar()); dr[InsuranceInfoData.beginDate_FIELD] = greorianDateTime; CheckDate.checkDate(txtEndDate.Text, ref y, ref m, ref d); persianDateDime = new DateTime(y, m, d, new PersianCalendar()); greorianDateTime = new DateTime(gcal.GetYear(persianDateDime), gcal.GetMonth(persianDateDime), gcal.GetDayOfMonth(persianDateDime), new GregorianCalendar()); dr[InsuranceInfoData.endDate_FIELD] = greorianDateTime; #endregion //fetch id from comboBox int id = int.Parse(cmbInsuranceType.SelectedValue + ""); dr[InsuranceInfoData.insuranceType_FIELD] = id; inData.Tables[InsuranceInfoData.insuranceInfo_TABLE].Rows.Add(dr); isb.update(inData); string insuranceNumber = txtInsuranceNumber.Text.Trim(); fillGrid(_condition); int addedRow = searcInGrid(insuranceNumber); if (addedRow == -1) { dataGridView1.Rows[dataGridView1.RowCount - 1].Selected = true; } else { dataGridView1.Rows[addedRow].Selected = true; } MainForm.MainFormInstance.fillGrid(); MessageBox.Show("به روز رسانی انجام شد"); }