public void clearData() { try { ////dtDate.Value = DateTime.Now; pnlForwarder.Visible = false; cmbGroup1Select.SelectedIndex = -1; cmbGroup2Select.SelectedIndex = -1; cmbGroup3Select.SelectedIndex = -1; cmbGroup4Select.SelectedIndex = -1; cmbGroup5Select.SelectedIndex = -1; txtAccCode.Text = ""; txtName.Text = ""; isTempEditCLick = false; //foreach (ComboBox cmb in pnlCVINRInner.Controls.OfType<ComboBox>()) //{ // cmb.Enabled = true; //} //txtName.Enabled = true; cmbStatus.Visible = false; lblStatus.Visible = false; prevaccode = new accountcode(); } catch (Exception) { } }
//private void btnSave_Click(object sender, EventArgs e) //{ //} private void grdList_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { // pnlActionButtons.Visible = false; lblActionHeader.Visible = false; if (e.RowIndex < 0) { return; } string columnName = grdList.Columns[e.ColumnIndex].Name; if (columnName.Equals("Edit") || columnName.Equals("TempEdit") || columnName.Equals("Approve") || columnName.Equals("LoadDocument") || columnName.Equals("View") || columnName.Equals("ViewDocument")) { clearData(); setButtonVisibility(columnName); prevaccode = new accountcode(); int rowID = e.RowIndex; try { prevaccode.AccountCode = grdList.Rows[e.RowIndex].Cells["AccCode"].Value.ToString(); prevaccode.Name = grdList.Rows[e.RowIndex].Cells["AccName"].Value.ToString(); prevaccode.documentStatus = Convert.ToInt32(grdList.Rows[e.RowIndex].Cells["DocumentStatus"].Value.ToString()); prevaccode.CreateUser = grdList.Rows[e.RowIndex].Cells["CreateUser"].Value.ToString(); prevaccode.ForwarderList = grdList.Rows[e.RowIndex].Cells["ForwarderLists"].Value.ToString(); } catch (Exception ez) { } //--------Load Documents if (columnName.Equals("LoadDocument")) { string hdrString = "Account NO" + prevaccode.AccountCode + "\n" + "Account name:" + prevaccode.Name; string dicDir = Main.documentDirectory + "\\" + docID; string subDir = prevaccode.AccountCode + "-" + prevaccode.Name; FileManager.LoadDocuments load = new FileManager.LoadDocuments(dicDir, subDir, docID, hdrString); load.ShowDialog(); this.RemoveOwnedForm(load); btnCancel_Click_1(null, null); return; } //-------- if (columnName.Equals("ViewDocument")) { return; } if (columnName.Equals("TempEdit")) { cmbStatus.Visible = true; lblStatus.Visible = true; isTempEditCLick = true; } else { isTempEditCLick = false; cmbStatus.Visible = false; lblStatus.Visible = false; } btnSave.Text = "Update"; //dtDate.Value = DateTime.Parse(grdList.Rows[e.RowIndex].Cells[0].Value.ToString()); txtAccCode.Text = grdList.Rows[e.RowIndex].Cells[0].Value.ToString(); txtName.Text = grdList.Rows[e.RowIndex].Cells[1].Value.ToString(); string grp1 = grdList.Rows[e.RowIndex].Cells["GroupLevel1"].Value.ToString(); cmbGroup1Select.SelectedIndex = grp1.Length == 0 ? -1 : cmbGroup1Select.FindString(grp1); string grp2 = grdList.Rows[e.RowIndex].Cells["GroupLevel2"].Value.ToString(); cmbGroup2Select.SelectedIndex = grp2.Length == 0 ? -1 : cmbGroup2Select.FindString(grp2); string grp3 = grdList.Rows[e.RowIndex].Cells["GroupLevel3"].Value.ToString(); cmbGroup3Select.SelectedIndex = grp3.Length == 0 ? -1 : cmbGroup3Select.FindString(grp3); string grp4 = grdList.Rows[e.RowIndex].Cells["GroupLevel4"].Value.ToString(); cmbGroup4Select.SelectedIndex = grp4.Length == 0 ? -1 : cmbGroup4Select.FindString(grp4); string grp5 = grdList.Rows[e.RowIndex].Cells["GroupLevel5"].Value.ToString(); cmbGroup5Select.SelectedIndex = grp5.Length == 0 ? -1 : cmbGroup5Select.FindString(grp5); cmbStatus.SelectedIndex = cmbStatus.FindString(getstatusString(Convert.ToInt32(grdList.Rows[e.RowIndex].Cells["Status"].Value))); if (columnName.Equals("Approve")) { string gd1 = cmbGroup1Select.SelectedItem.ToString().Trim().Substring(0, cmbGroup1Select.SelectedItem.ToString().Trim().IndexOf('-')); string gd2 = cmbGroup2Select.SelectedItem.ToString().Trim().Substring(0, cmbGroup2Select.SelectedItem.ToString().Trim().IndexOf('-')); string gd3 = cmbGroup3Select.SelectedItem.ToString().Trim().Substring(0, cmbGroup3Select.SelectedItem.ToString().Trim().IndexOf('-')); string gd4 = cmbGroup4Select.SelectedItem.ToString().Trim().Substring(0, cmbGroup4Select.SelectedItem.ToString().Trim().IndexOf('-')); string gd5 = cmbGroup5Select.SelectedItem.ToString().Trim().Substring(0, cmbGroup5Select.SelectedItem.ToString().Trim().IndexOf('-')); string itc = gd1 + gd2 + gd3 + gd4 + gd5; id = CreateAccountID(itc); } pnlCVINRInner.Visible = true; pnlCVINROuter.Visible = true; pnlList.Visible = false; } else { return; } ////pnlCVINRInner.Visible = true; ////pnlCVINROuter.Visible = true; ////pnlList.Visible = false; } catch (Exception ex) { setButtonVisibility("init"); } }
private void btnSave_Click_1(object sender, EventArgs e) { Boolean status = true; try { accountcode acc = new accountcode(); AccountCodeDB accDB = new AccountCodeDB(); //cvi.ConversionDate = dtDate.Value; try { acc.GroupLevel1 = cmbGroup1Select.SelectedItem.ToString().Trim().Substring(0, cmbGroup1Select.SelectedItem.ToString().Trim().IndexOf('-')); acc.GroupLevel1Description = cmbGroup1Select.SelectedItem.ToString().Trim().Substring(cmbGroup1Select.SelectedItem.ToString().Trim().IndexOf('-') + 1); } catch (Exception) { acc.GroupLevel1 = ""; acc.GroupLevel1Description = ""; } try { acc.GroupLevel2 = cmbGroup2Select.SelectedItem.ToString().Trim().Substring(0, cmbGroup2Select.SelectedItem.ToString().Trim().IndexOf('-')); acc.GroupLevel2eDescription = cmbGroup2Select.SelectedItem.ToString().Trim().Substring(cmbGroup2Select.SelectedItem.ToString().Trim().IndexOf('-') + 1); } catch (Exception) { acc.GroupLevel2 = ""; acc.GroupLevel2eDescription = ""; } try { acc.GroupLevel3 = cmbGroup3Select.SelectedItem.ToString().Trim().Substring(0, cmbGroup3Select.SelectedItem.ToString().Trim().IndexOf('-')); acc.GroupLevel3Description = cmbGroup3Select.SelectedItem.ToString().Trim().Substring(cmbGroup3Select.SelectedItem.ToString().Trim().IndexOf('-') + 1); } catch (Exception) { acc.GroupLevel3 = ""; acc.GroupLevel3Description = ""; } try { acc.GroupLevel4 = cmbGroup4Select.SelectedItem.ToString().Trim().Substring(0, cmbGroup4Select.SelectedItem.ToString().Trim().IndexOf('-')); acc.GroupLevel4Description = cmbGroup4Select.SelectedItem.ToString().Trim().Substring(cmbGroup4Select.SelectedItem.ToString().Trim().IndexOf('-') + 1); } catch (Exception) { acc.GroupLevel4 = ""; acc.GroupLevel4Description = ""; } try { acc.GroupLevel5 = cmbGroup5Select.SelectedItem.ToString().Trim().Substring(0, cmbGroup5Select.SelectedItem.ToString().Trim().IndexOf('-')); acc.GroupLevel5Description = cmbGroup5Select.SelectedItem.ToString().Trim().Substring(cmbGroup5Select.SelectedItem.ToString().Trim().IndexOf('-') + 1); } catch (Exception ex) { acc.GroupLevel5 = ""; acc.GroupLevel5Description = ""; } acc.Name = txtName.Text.Replace("'", "''"); acc.ForwarderList = prevaccode.ForwarderList; System.Windows.Forms.Button btn = sender as System.Windows.Forms.Button; string btnText = btn.Text; if (accDB.validateAccountCodeDetail(acc)) { if (btnText.Equals("Update")) { if (isTempEditCLick) { acc.status = getstatuscode(cmbStatus.SelectedItem.ToString().Trim()); } else { acc.status = 0; } if (accDB.updateAccountCodeDetails(acc, prevaccode)) { MessageBox.Show("Account Code updated"); closeAllPanels(); listOption = 1; ListAccountDetail(listOption); } else { status = false; MessageBox.Show("Failed to Update Account Code"); } } else if (btnText.Equals("Save")) { acc.documentStatus = 1;//created if (accDB.insertAccountCodeDetails(acc)) { MessageBox.Show("Account Code Added"); closeAllPanels(); listOption = 1; ListAccountDetail(listOption); } else { status = false; MessageBox.Show("Failed to Insert Account Code"); } } } else { MessageBox.Show("Account Code Data Validation failed"); return; } } catch (Exception ex) { MessageBox.Show("Failed Adding / Editing Account Code"); return; } if (status) { setButtonVisibility("btnEditPanel"); //activites are same for cancel, forward,approve, reverse and save } }