private bool ValidateEntry() { try { DateTime dtDate = Convert.ToDateTime(txtDate.Text); } catch { MessageBox.Show("Invalid Date", "Entry"); return(false); } if (this._IsAdd) { Layer.LedgerBL BL = new Layer.LedgerBL(); BL.Exist(LocalAccess.l_CompanyCode, txtDocu.Text.Trim()); } double nDebit = 0; double nCredit = 0; foreach (DataGridViewRow dr in grdDetail.Rows) { if (dr.IsNewRow) { continue; } string sAccount = "" + dr.Cells["cAccount"].Value; Layer.AccountBL BL = new Layer.AccountBL(); if (!BL.Exist(sAccount)) { MessageBox.Show("Account Code does not exist.", "Entry"); return(false); } try { nDebit += Convert.ToDouble(dr.Cells["cDebit"].Value); } catch { } try { nCredit += Convert.ToDouble(dr.Cells["cCredit"].Value); } catch { } //nBalance = Math.Round(nBalance + nDebit - nCredit); } if (Math.Round(nDebit, 2) != Math.Round(nCredit, 2)) { MessageBox.Show("Ledger Not Balance" + Environment.NewLine + "Debit: " + nDebit.ToString("#,##0.00") + Environment.NewLine + "Credit: " + nCredit.ToString("#,##0.00"), "Entry"); return(false); } return(true); }
private void btnAdd_Click(object sender, EventArgs e) { Layer.AccountBL BL = new Layer.AccountBL(); BL.AccountCode = txtCode.Text.Trim(); BL.AccountType = txtType.Text.Trim(); BL.AccountName = txtName.Text.Trim(); if (BL.AccountCode == "" || BL.AccountType == "" || BL.AccountName == "") { MessageBox.Show("Account Code/Type/Name cannot be blank", "Add Account"); return; } //if (BL.AccountType == "BS" || BL.AccountType == "PL" || BL.AccountType == "TD" || BL.AccountType == "TC") //{} //else //{ // MessageBox.Show("Invalid Account Type", "Add Account"); // return; //} if (this._IsAdd) { if (BL.Exist()) { MessageBox.Show("Account Code already exist.", "Add Account"); return; } BL.Insert(); } else { BL.UpdateByPK(); } this.DialogResult = DialogResult.OK; this.Close(); }