Exemplo n.º 1
0
        private bool CheckData()
        {
            float dblPaymentAmount = 0;
            float dblTotalSplit    = 0;
            float dblTotalBalance  = 0;
            float dblSplitPayments = 0;
            float dblTemp;

            if (float.TryParse(txtAmount.Text.Trim().Replace("$", ""), out dblPaymentAmount))
            {
            }

            // adding total splits
            foreach (DataRow dr in _dtFeePayments.Rows)
            {
                if (float.TryParse(dr["apply"].ToString(), out dblTemp))
                {
                    dblTotalSplit += dblTemp;
                }
            }

            // do the splits equal the total
            if (dblTotalSplit != dblPaymentAmount)
            {
                MessageBox.Show(this, "Payment amount does not equal sum of splits.", "Payment Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            string strError = "";
            string strReportToCountyClerk = "";
            string strOtherCounty         = "";

            LocalUser usr = new LocalUser();


            foreach (Plan plan in ((Defendant)((BindingSource)((BindingSource)bindingPayments.DataSource).DataSource).Current).Plans)
            {
                dblTotalBalance  = 0;
                dblSplitPayments = 0;

                DataRow[] drs = _dtFeePayments.Select("planid = " + plan.ID);

                // calculating remaining balance
                foreach (DataRow dr in drs)
                {
                    if (float.TryParse(dr["remaining"].ToString(), out dblTemp))
                    {
                        dblTotalBalance += dblTemp;
                    }

                    if (float.TryParse(dr["apply"].ToString(), out dblTemp))
                    {
                        dblSplitPayments += dblTemp;
                    }
                }

                // has the defendant paid more than owed.
                if ((dblTotalBalance - dblSplitPayments) < 0)
                {
                    strError += plan.PlanName + ":  Payment made is greater than what the defendant owes.\n";
                }

                // is this the last payment made.
                if (string.IsNullOrEmpty(strError) && (dblTotalBalance - dblSplitPayments) == 0)
                {
                    strReportToCountyClerk += plan.PlanName + "\n";
                }

                // is a payment being posted to a plan with cases in other counties
                if (dblSplitPayments > 0)
                {
                    var lnq = from cs in plan.Cases where cs.CountyId != usr.HomeCountyId select cs;
                    if (lnq.Count() > 0)
                    {
                        strOtherCounty += plan.PlanName + "\n";
                    }
                }
            }

            if (!string.IsNullOrEmpty(strError))
            {
                MessageBox.Show(this, strError, "Payment Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            else
            {
                string msg = "";

                // is this the last payment made.
                if (!string.IsNullOrEmpty(strReportToCountyClerk))
                {
                    msg += "Report to Clerk Needed:\n\n " + strReportToCountyClerk;
                }

                // is this payment out of county.
                if (!string.IsNullOrEmpty(strOtherCounty))
                {
                    msg += (msg.Length > 0) ? "\n" : "";
                    msg += "A payment is being made to a plan or plans with at least one case in another county:\n\n " + strOtherCounty;
                }

                if (!string.IsNullOrEmpty(msg))
                {
                    this.Hide();
                    MessageBox.Show(this, msg, "Reminder", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }

            return(true);
        }