private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { string insNo = _gridTools.getCurrentRowValue(ViewInsuranceInfoData.insuranceNumber_FIELD).ToString(); int id = (int)_gridTools.getCurrentRowValue(ViewInsuranceInfoData.id_FIELD); InsuranceInfoForm1 insFrm = new InsuranceInfoForm1(); _currentInsuranceNumber = insNo; insFrm._id = id; insFrm.ShowDialog(); if (insFrm.isDeleted) { MainForm.MainFormInstance.fillGrid(); } }
private void btnUpdate_Click(object sender, EventArgs e) { string check = checkData(); if (check != null) { MessageBox.Show(check); return; } if (dataGridView1.RowCount <= 0) { dataMode = NEW_MODE; } UsersBS isb = new UsersBS(); UsersData inData = new UsersData(); DataRow dr = inData.Tables[UsersData.users_TABLE].NewRow(); dr[UsersData.name_FIELD] = txtName.Text; dr[UsersData.family_FIELD] = txtFamily.Text; dr[UsersData.userName_FIELD] = txtUserName.Text; dr[UsersData.password_FIELD] = txtPassword.Text; dr[UsersData.userType_FIELD] = cmbUserType.SelectedIndex; if (!dataMode.Equals(NEW_MODE)) { dr[UsersData.id_FIELD] = _gridTools.getCurrentRowValue(UsersData.id_FIELD); } object id = _gridTools.getCurrentRowValue(UsersData.id_FIELD); inData.Tables[UsersData.users_TABLE].Rows.Add(dr); int count; if (dataMode.Equals(NEW_MODE)) { count = isb.add(inData); } else if (dataMode.Equals(EDIT_MODE)) { count = isb.update(inData); } dataMode = EDIT_MODE; btnRefresh_Click(null, null); fillGrid(); }
private void btnUpdate_Click(object sender, EventArgs e) { int id = -1; if (dataGridView1.RowCount <= 0) { dataMode = NEW_MODE; } if (!dataMode.Equals(NEW_MODE)) { id = int.Parse(_gridTools.getCurrentRowValue(InsuranceTypeData.InsuranceId_FIELD) + ""); } string caption = _gridTools.getCurrentRowValue(InsuranceTypeData.InsuranceCaption_FIELD) + ""; InsuranceTypeBS isb = new InsuranceTypeBS(); string strCaption = this.txtInsuranceType.Text; if (strCaption.Trim().Length <= 0) { txtInsuranceType.Focus(); MessageBox.Show("لطفا یک مقدار برای نوع بیمه وارد کنید"); return; } string str = this.cmbDaysBeforExp.Text; int d = 0; if (str.Trim().Length <= 0) { cmbDaysBeforExp.Focus(); MessageBox.Show("لطفا یک مقدار برای نوع بیمه وارد کنید"); return; } try { d = int.Parse(str); } catch (Exception ex) { cmbDaysBeforExp.Focus(); MessageBox.Show("عدد وارد شده برای روز صحیح نیست"); return; } string colorStr = ColorTranslator.ToHtml(pnlColor.BackColor); InsuranceTypeData inData = new InsuranceTypeData(); DataRow dr = inData.Tables[InsuranceTypeData.InsuranceType_TABLE].NewRow(); dr[InsuranceTypeData.InsuranceCaption_FIELD] = strCaption; dr[InsuranceTypeData.DAYSBEFOREXP_FIELD] = d; dr[InsuranceTypeData.InsuranceId_FIELD] = id; dr[InsuranceTypeData.INSURANCETYPECOLOR_FIELD] = colorStr; inData.Tables[InsuranceTypeData.InsuranceType_TABLE].Rows.Add(dr); if (dataMode.Equals(NEW_MODE)) { isb.add(inData); } else if (dataMode.Equals(EDIT_MODE)) { isb.update(inData); } dataMode = EDIT_MODE; btnRefresh_Click(null, null); 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 (dataGridView1.RowCount <= 0) { dataMode = NEW_MODE; } UsersEntity entity = new UsersEntity(); DataRow dr = null; dr = entity.Tables[entity.TableName].NewRow(); entity.FilledTableName = entity.TableName; dr[UsersEntity.FIELD_NAME] = txtName.Text; dr[UsersEntity.FIELD_FAMILY] = txtFamily.Text; dr[UsersEntity.FIELD_USERNAME] = txtUserName.Text; dr[UsersEntity.FIELD_PASSWORD] = txtPassword.Text; dr[UsersEntity.FIELD_USER_TYPE] = (cmbUserType.SelectedIndex + 1); dr[UsersEntity.FIELD_ACTIVE] = (cbActive.Checked ? 1 : 0); if (cmbLetterPattern.SelectedIndex >= 0) { ComboBoxItem item = (ComboBoxItem)cmbLetterPattern.Items[cmbLetterPattern.SelectedIndex]; dr[UsersEntity.FIELD_LETTER_PATTERN_ID] = item.Value; } if (!dataMode.Equals(NEW_MODE)) { dr[entity.IndexFieldName] = _gridTools.getCurrentRowValue(dataGridView1, entity.IndexFieldName); } object id = _gridTools.getCurrentRowValue(dataGridView1, entity.IndexFieldName); entity.Tables[entity.TableName].Rows.Add(dr); int count; if (dataMode.Equals(NEW_MODE)) { UsersEntity en = _usersBs.get(UsersEntity.FIELD_USERNAME + "='" + txtUserName.Text + "'"); if (en.Tables[en.FilledTableName].Rows.Count > 0) { MessageBox.Show("نام کاربری تعیین شده قبلا تعریف شده است، لطفا نام دیگری را انتخاب نمایید"); return; } count = _usersBs.add(entity); } else if (dataMode.Equals(EDIT_MODE)) { count = _usersBs.update(entity); } dataMode = EDIT_MODE; btnRefresh_Click(null, null); fillGrid(); }
private void dataGridView1_SelectionChanged(object sender, EventArgs e) { IConverter converter = new DateConverter(); IConverter booleanConverter = new RMX_TOOLS.converter.BooleanConverter(); if (_gridTools.getCurrentRowValue(ViewInsuranceInfoData.name_FIELD) != null) { txtName.Text = _gridTools.getCurrentRowValue(ViewInsuranceInfoData.name_FIELD).ToString().Trim(); } if (_gridTools.getCurrentRowValue(ViewInsuranceInfoData.family_FIELD) != null) { txtFamily.Text = _gridTools.getCurrentRowValue(ViewInsuranceInfoData.family_FIELD).ToString().Trim(); } if (_gridTools.getCurrentRowValue(ViewInsuranceInfoData.phoneNumber_FIELD) != null) { txtPhoneNumber.Text = _gridTools.getCurrentRowValue(ViewInsuranceInfoData.phoneNumber_FIELD).ToString().Trim(); } if (_gridTools.getCurrentRowValue(ViewInsuranceInfoData.insuranceNumber_FIELD) != null) { txtInsuranceNumber.Text = _gridTools.getCurrentRowValue(ViewInsuranceInfoData.insuranceNumber_FIELD).ToString().Trim(); } if (_gridTools.getCurrentRowValue(ViewInsuranceInfoData.caption_FIELD) != null) { cmbInsuranceType.SelectedText = _gridTools.getCurrentRowValue(ViewInsuranceInfoData.caption_FIELD).ToString().Trim(); } if (_gridTools.getCurrentRowValue(ViewInsuranceInfoData.insuranceType_FIELD) != null) { cmbInsuranceType.SelectedValue = _gridTools.getCurrentRowValue(ViewInsuranceInfoData.insuranceType_FIELD); } if (_gridTools.getCurrentRowValue(InsuranceInfoData.beginDate_FIELD) != null) { //txtBeginDate.Text = converter.valueToString(_gridTools.getCurrentRowValue(InsuranceInfoData.beginDate_FIELD)); txtBeginDate.Text = _gridTools.getCurrentRowValue(InsuranceInfoData.beginDate_FIELD).ToString().Trim(); } if (_gridTools.getCurrentRowValue(InsuranceInfoData.endDate_FIELD) != null) { //txtEndDate.Text = converter.valueToString(_gridTools.getCurrentRowValue(InsuranceInfoData.endDate_FIELD)); txtEndDate.Text = _gridTools.getCurrentRowValue(InsuranceInfoData.endDate_FIELD).ToString().Trim(); } if (_gridTools.getCurrentRowValue(ViewInsuranceInfoData.haveDid_FIELD) != null) { Boolean b = Boolean.Parse(booleanConverter.valueToString(_gridTools.getCurrentRowValue(ViewInsuranceInfoData.haveDid_FIELD))); if (b) { cmbHaveDid.SelectedIndex = 1; } else { cmbHaveDid.SelectedIndex = 2; } } if (_gridTools.getCurrentRowValue(ViewInsuranceInfoData.address_FIELD) != null) { txtAddress.Text = _gridTools.getCurrentRowValue(ViewInsuranceInfoData.address_FIELD).ToString().Trim(); } if (_gridTools.getCurrentRowValue(ViewInsuranceInfoData.description_FIELD) != null) { txtDescription.Text = _gridTools.getCurrentRowValue(ViewInsuranceInfoData.description_FIELD).ToString().Trim(); } }
private void dataGridView1_SelectionChanged(object sender, EventArgs e) { IConverter converter = new DateConverter(); IConverter booleanConverter = new RMX_TOOLS.converter.BooleanConverter(); cmbHaveDid.SelectedIndex = -1; if (_gridTools.getCurrentRowValue(ViewHaveDidLogData.INSURANCEINFO_NAME_FIELD) != null) { txtName.Text = _gridTools.getCurrentRowValue(ViewHaveDidLogData.INSURANCEINFO_NAME_FIELD).ToString().Trim(); } if (_gridTools.getCurrentRowValue(ViewHaveDidLogData.INSURANCEINFO_FAMILY_FIELD) != null) { txtFamily.Text = _gridTools.getCurrentRowValue(ViewHaveDidLogData.INSURANCEINFO_FAMILY_FIELD).ToString().Trim(); } if (_gridTools.getCurrentRowValue(ViewHaveDidLogData.PhoneNumber_FIELD) != null) { txtPhoneNumber.Text = _gridTools.getCurrentRowValue(ViewHaveDidLogData.PhoneNumber_FIELD).ToString().Trim(); } if (_gridTools.getCurrentRowValue(ViewHaveDidLogData.InsuranceNumber_FIELD) != null) { txtInsuranceNumber.Text = _gridTools.getCurrentRowValue(ViewHaveDidLogData.InsuranceNumber_FIELD).ToString().Trim(); } if (_gridTools.getCurrentRowValue(ViewHaveDidLogData.InsuranceType_Caption_FIELD) != null) { cmbInsuranceType.SelectedText = _gridTools.getCurrentRowValue(ViewHaveDidLogData.InsuranceType_Caption_FIELD).ToString().Trim(); } if (_gridTools.getCurrentRowValue(ViewHaveDidLogData.InsuranceType_FIELD) != null) { cmbInsuranceType.SelectedValue = _gridTools.getCurrentRowValue(ViewHaveDidLogData.InsuranceType_FIELD); } if (_gridTools.getCurrentRowValue(ViewHaveDidLogData.BeginDate_FIELD) != null) { //txtBeginDate.Text = converter.valueToString(_gridTools.getCurrentRowValue(ViewHaveDidLogData.BeginDate_FIELD)); txtBeginDate.Text = _gridTools.getCurrentRowValue(ViewHaveDidLogData.BeginDate_FIELD).ToString().Trim(); } if (_gridTools.getCurrentRowValue(ViewHaveDidLogData.EndDate_FIELD) != null) { //txtEndDate.Text = converter.valueToString(_gridTools.getCurrentRowValue(ViewHaveDidLogData.EndDate_FIELD)); txtEndDate.Text = _gridTools.getCurrentRowValue(ViewHaveDidLogData.EndDate_FIELD).ToString().Trim(); } if (_gridTools.getCurrentRowValue(ViewHaveDidLogData.haveDid_FIELD) != null) { Boolean b = Boolean.Parse(booleanConverter.valueToString(_gridTools.getCurrentRowValue(ViewHaveDidLogData.haveDid_FIELD))); if (b) { cmbHaveDid.SelectedIndex = 1; } //else // cmbHaveDid.SelectedIndex = 2; } if (_gridTools.getCurrentRowValue(ViewHaveDidLogData.address_FIELD) != null) { txtAddress.Text = _gridTools.getCurrentRowValue(ViewHaveDidLogData.address_FIELD).ToString().Trim(); } if (_gridTools.getCurrentRowValue(ViewHaveDidLogData.description_FIELD) != null) { txtDescription.Text = _gridTools.getCurrentRowValue(ViewHaveDidLogData.description_FIELD).ToString().Trim(); } }