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) { if (!ValidateEntry()) { return; } Layer.LedgerBL BL = new Layer.LedgerBL(); if (this._IsAdd) { BL.LedgerId = DateTime.Now.ToString("yyyyMMddHHmmss"); } else { BL.LedgerId = this.sLedgerId; } BL.CompanyCode = LocalAccess.l_CompanyCode; BL.LedgerDate = Convert.ToDateTime(txtDate.Text); BL.LedgerDocu = txtDocu.Text.Trim(); BL.LedgerDesc = txtDesc.Text.Trim(); BL.LedgerRef = txtRef.Text.Trim(); BL.dtls = new List <Layer.LedgerDtlBL>(); foreach (DataGridViewRow dr in grdDetail.Rows) { if (dr.IsNewRow) { continue; } Layer.LedgerDtlBL dtl = new Layer.LedgerDtlBL(); dtl.LedgerId = BL.LedgerId; dtl.AccountCode = "" + dr.Cells["cAccount"].Value; dtl.LedgerDescription = "" + dr.Cells["cDescription"].Value; dtl.LedgerDebit = 0; dtl.LedgerCredit = 0; dtl.LedgerAmount = 0; try { dtl.LedgerDebit = Convert.ToDouble(dr.Cells["cDebit"].Value); } catch { } try { dtl.LedgerCredit = Convert.ToDouble(dr.Cells["cCredit"].Value); } catch { } try { dtl.LedgerAmount = Convert.ToDouble(dr.Cells["cAmount"].Value); } catch { } BL.dtls.Add(dtl); } if (this._IsAdd) { if (BL.Exist()) { MessageBox.Show("Document already exist.", "Add Ledger"); return; } BL.Insert(); frmList.LoadEntry(); //FormNew(); txtDate.Focus(); LoadDescriptionList(); MessageBox.Show("Record Saved"); } else { BL.UpdateByPK(); this.Close(); frmList.LoadEntry(); } }