private void grdList_CellContentClick_1(object sender, DataGridViewCellEventArgs e) { try { if (e.RowIndex < 0) { return; } string columnName = grdList.Columns[e.ColumnIndex].Name; try { if (columnName.Equals("Edit")) { clearData(); //string btnText = btnSave.Text; btnSave.Text = "update"; prevag = new accountgroup(); prevag.GroupCode = grdList.Rows[e.RowIndex].Cells["GroupCode"].Value.ToString(); prevag.GroupDescription = grdList.Rows[e.RowIndex].Cells["GroupDescription"].Value.ToString(); prevag.GroupLevel = Convert.ToInt32(cmbSelectLevel.SelectedItem.ToString().Trim()); txtGroupCode.Text = prevag.GroupCode; txtGroupDescription.Text = prevag.GroupDescription; pnlAddNew.Visible = true; txtGroupCode.ReadOnly = true; } } catch (Exception) { } } catch (Exception ex) { } }
public void clearData() { try { txtGroupCode.Text = ""; txtGroupDescription.Text = ""; prevag = new accountgroup(); } catch (Exception ex) { } }
private void btnSave_Click(object sender, EventArgs e) { Boolean status = true; try { AccountGroupDB agdb = new AccountGroupDB(); accountgroup ag = new accountgroup(); System.Windows.Forms.Button btn = sender as System.Windows.Forms.Button; string btnText = btnSave.Text; try { if (!System.Text.RegularExpressions.Regex.IsMatch(txtGroupCode.Text, @"^[0-9]+$")) { MessageBox.Show("Group Code accepts only numeric characters"); return; } else { ag.GroupCode = txtGroupCode.Text; } if (!System.Text.RegularExpressions.Regex.IsMatch(txtGroupDescription.Text, @"^[\sa-zA-Z0-9]+$")) { MessageBox.Show("GroupDescription accepts only alphanumeric characters"); return; } else { ag.GroupDescription = txtGroupDescription.Text; } ag.GroupLevel = Convert.ToInt32(cmbSelectLevel.SelectedItem.ToString().Trim()); } catch (Exception ex) { MessageBox.Show("Validation failed"); return; } if (btnText.Equals("Save")) { if (agdb.validateCustomerGroup(ag)) { if (agdb.insertAccountGroup(ag)) { MessageBox.Show("Account Code Added"); closeAllPanels(); listAccountGroup(lvl); pnlAddNew.Visible = false; pnlBottomButtons.Visible = true; } else { status = false; } } else { MessageBox.Show("Validation failed"); } if (!status) { MessageBox.Show("Failed to Insert Customer Code"); } } else if (btnText.Equals("update")) { if (agdb.validateCustomerGroup(ag)) { if (agdb.updateCustomerGroup(ag)) { MessageBox.Show("Account Code Added"); closeAllPanels(); listAccountGroup(lvl); pnlAddNew.Visible = false; pnlBottomButtons.Visible = true; } else { status = false; } } else { MessageBox.Show("Validation failed"); } if (!status) { MessageBox.Show("Failed to Insert Stock Code"); } } else { MessageBox.Show("btnSave error."); } } catch (Exception ex) { MessageBox.Show("Errorr in saving"); } }