示例#1
0
        protected void btnAddBillingItem_Click(object sender, EventArgs e)
        {
            int bookingId = DataUtil.GetBookingIdFromGiffiId(double.Parse(lblGiffiRef.Text));

            BillingRepository repo = new BillingRepository();
            var     arrCodeMap     = ddlAddCode.SelectedValue.Split(',');
            decimal billingAmount  = 0;
            decimal payoutAmount   = 0;

            string errorMsg = string.Empty;

            int codeId = 0;

            if (bookingId < Constants.InitBookingId)
            {
                errorMsg = string.Format("ERROR!!! Invalid bookingId={0}.", bookingId);
                AlertMessage(errorMsg);
            }
            else if (arrCodeMap == null || arrCodeMap.Count() == 0 || !int.TryParse(arrCodeMap[0], out codeId))
            {
                errorMsg = string.Format("ERROR!!! Parsing AccountingCode from input.");
                AlertMessage(errorMsg);
            }
            else if (!decimal.TryParse(txtAddBillingAmount.Text, out billingAmount) ||
                     !decimal.TryParse(txtAddPayoutAmount.Text, out payoutAmount))
            {
                errorMsg = string.Format("ERROR!!! INVALID Billing={0} or Payout={1}.", txtAddBillingAmount.Text, txtAddPayoutAmount.Text);
                AlertMessage(errorMsg);
            }
            else if (payoutAmount > billingAmount)
            {
                errorMsg = string.Format("ERROR!!! Payout={1} cannot greater than Billing={0} amount.", txtAddBillingAmount.Text, txtAddPayoutAmount.Text);
                AlertMessage(errorMsg);
            }
            else if (billingAmount <= 0 || payoutAmount < 0)
            {
                errorMsg = string.Format("ERROR!!! Billing={0} or Payout={1} invalid amount.", txtAddBillingAmount.Text, txtAddPayoutAmount.Text);
                AlertMessage(errorMsg);
            }
            else if (ddlAddVendor.SelectedValue == "0")
            {
                errorMsg = string.Format("ERROR!!! Need to choose a vendor.");
                AlertMessage(errorMsg);
            }
            else
            {
                if (repo.InsertBillingItem(bookingId, int.Parse(arrCodeMap[0]), 1, txtAddDescription.Text, billingAmount, payoutAmount, int.Parse(ddlAddVendor.SelectedValue.ToString())))
                {
                    gvInvoice.DataSource = DataUtil.GetBillingItems(bookingId);
                    gvInvoice.DataBind();

                    ddlAddCode.SelectedIndex    = -1;
                    txtAddDescription.Text      = "";
                    txtAddBillingAmount.Text    = "";
                    txtAddBillingAmount.Enabled = true;
                    txtAddPayoutAmount.Text     = "";
                    txtAddPayoutAmount.Enabled  = true;
                }
            }
        }