示例#1
0
        protected void btnCalculate_Click(object sender, EventArgs e)
        {
            const string METHOD_NAME = "btnCalculate_Click";

            try {
                Decimal qcBeetPaymentPerTon = 0, oldNorthBeetPaymentPerTon = 0, oldSouthBeetPaymentPerTon = 0;
                string  sugarContent, slmPct, netReturn;
                int     cropYear = Convert.ToInt32(ddlCropYear.SelectedItem.Text);

                sugarContent = txtSugarContent.Text;
                if (sugarContent.Length == 0)
                {
                    Common.CWarning warn = new Common.CWarning("Please enter a Sugar Content.");
                    throw (warn);
                }
                if (!Common.CodeLib.IsNumeric(sugarContent))
                {
                    Common.CWarning warn = new Common.CWarning("Please enter a number for Sugar Content, like 16.54.");
                    throw (warn);
                }
                slmPct = txtSLM.Text;
                if (slmPct.Length == 0)
                {
                    Common.CWarning warn = new Common.CWarning("Please enter a SLM value.");
                    throw (warn);
                }
                if (!Common.CodeLib.IsNumeric(slmPct))
                {
                    Common.CWarning warn = new Common.CWarning("Please enter a number for SLM, like 1.60.");
                    throw (warn);
                }
                netReturn = txtNetReturn.Text;
                if (netReturn.Length == 0)
                {
                    Common.CWarning warn = new Common.CWarning("Please enter a Net Return.");
                    throw (warn);
                }
                if (!Common.CodeLib.IsNumeric(netReturn))
                {
                    Common.CWarning warn = new Common.CWarning("Please enter a number for Net Return, like 24.55.");
                    throw (warn);
                }

                using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["BeetConn"].ToString())) {
                    WSCPayment.CalculatePayment(conn, Convert.ToDecimal(sugarContent),
                                                Convert.ToDecimal(slmPct),
                                                Convert.ToDecimal(netReturn), cropYear, ref qcBeetPaymentPerTon,
                                                ref oldNorthBeetPaymentPerTon, ref oldSouthBeetPaymentPerTon);

                    lblQCPayment.Text = "$" + qcBeetPaymentPerTon.ToString();
                }
            }
            catch (System.Exception ex) {
                Common.CException wex = new Common.CException(MOD_NAME + METHOD_NAME, ex);
                ((PrimaryTemplate)Page.Master).ShowWarning(ex);
            }
        }