private bool CheckDistributions() { double sumDR = 0; //Validating content of each GL Transaction foreach (GLDistribution d in Trx.Distributions) { if (d.GL == null) { MessageBox.Show("Missing Account:\n" + d.ToString()); return(false); } if (d.DR != 0 && d.CR != 0) { MessageBox.Show("Only a debit or credit should be entered for each distribution:\n" + d.ToString()); return(false); } if (d.DR < 0 || d.CR < 0) { MessageBox.Show("Debits and Credits should be no less than zero:\n" + d.ToString()); return(false); } if (!d.GL.IsActive) { MessageBox.Show("Inactive Account Selected: " + d.GL.ToString()); return(false); } if (!d.GL.CanPstDrct) { MessageBox.Show("Direct Posting Disabled: " + d.GL.ToString()); return(false); } d.ActIndx = d.GL.ActIndx; if (string.IsNullOrEmpty(d.TrxDscr)) { MessageBox.Show("Missing GJ Distribution Description:\n" + d.ToString()); return(false); } sumDR += d.DR; d.GL = repo.Find(d.ActNmbr); } if (sumDR <= 0) { MessageBox.Show("Distributions must positive have amounts."); return(false); } double var = Trx.DistributionVariance(); if (var == 0) { return(true); } MessageBox.Show(String.Format("Sum of Debits must equal sum of Credits\n[Variance = {0:C}].", var)); return(false); }
private void BtSave_Click(object sender, RoutedEventArgs e) { GLAccount tempGL; GLAccounts = repo.GetAll(); GLAccount findGL = GLAccounts.FirstOrDefault(i => i.ActNmbr == tbActNmbr.Text); bool isNew = false; if (tbActDscr.Text.Trim() == "" || tbActNmbr.Text.Trim() == "") { MessageBox.Show("Account Number and Account Descriptions are required fields."); return; } if (findGL == null) { tempGL = new GLAccount(); isNew = true; } else { tempGL = findGL; } tempGL.ActNmbr = tbActNmbr.Text; tempGL.ActDscr = tbActDscr.Text; tempGL.IsActive = (bool)ckIsActive.IsChecked; tempGL.CanPstDrct = (bool)ckCanDirPst.IsChecked; tempGL.HasDRBal = (bool)ckHasDRBal.IsChecked; tempGL = repo.Save(tempGL); if (isNew) { GLAccounts.Add(repo.Save(tempGL)); count++; } index = GLAccounts.IndexOf(tempGL); MessageBox.Show("Account Saved."); DataContext = repo.Find(tempGL.ActNmbr); }