Example #1
0
        private bool ValidateCalculation(Freight f, out string outMsg)
        {
            outMsg = string.Empty;

            if (f.PC == "P")
            {
                if (Math.Round(f.AmtPPD, 2, MidpointRounding.AwayFromZero) != Math.Round(f.Units * f.Rate, 2, MidpointRounding.AwayFromZero))
                {
                    outMsg = string.Format("ERROR!!! AmtPPD={0:0.00}, and Units * Rate= {1:0.00} * {2:0.00}= {3:0.00} are not equal)", f.AmtPPD, f.Units, f.Rate, f.Units * f.Rate);
                    return(false);
                }

                if (Math.Round(f.BrkAmt, 2, MidpointRounding.AwayFromZero) != Math.Round(f.AmtPPD * f.BrkRate, 2, MidpointRounding.AwayFromZero))
                {
                    outMsg = string.Format("ERROR!!! BrkAmt= {0:0.00} and AmtPPD * BrkRate= {1:0.00} * {2:0.00}= {3:0.00} are not equal!!!", f.BrkAmt, f.AmtPPD, f.BrkRate, f.AmtPPD * f.BrkRate);
                    return(false);
                }
            }
            else if (f.PC == "C")
            {
                if (f.AmtPPD != 0 || f.BrkRate != 0 || f.BrkAmt != 0)
                {
                    outMsg = string.Format("ERROR!! if PC=C, then AmtPPD={0:0.00}, BrkRate={1:0.00} and BrkAmt= {2:0.00} should be zero", f.AmtPPD, f.BrkRate, f.BrkAmt);
                    return(false);
                }
            }
            else
            {
                outMsg = string.Format("SYSTEM ERRROR!!! P/C field should be P or C value");
                return(false);
            }
            return(true);
        }
Example #2
0
        protected void AddNewFreight_Click(object sender, EventArgs e)
        {
            string  outMsg    = string.Empty;
            Freight fr        = null;
            int     bookingId = DataUtil.GetBookingIdFromGiffiId(double.Parse(txtGiffRef.Text));

            if (bookingId < Constants.InitBookingId)
            {
                this.Page.AlertMessage(GetType(), string.Format("Invalid bookingId={0}", bookingId));
                return;
            }

            try
            {
                fr = new Freight
                {
                    BookingId = bookingId,
                    Code      = ddlNewCode.SelectedValue,
                    BS        = txtNewBS.Text.Trim(),
                    PC        = ddlNewPC.SelectedValue,
                    Units     = int.Parse(txtNewUnits.Text.Trim()),
                    Rate      = decimal.Parse(txtNewRate.Text.Trim(), NumberStyles.Currency),
                    AmtPPD    = decimal.Parse(txtNewAmtPPD.Text.Trim(), NumberStyles.Currency),
                    AmtCOL    = decimal.Parse(txtNewAmtCOL.Text.Trim(), NumberStyles.Currency),
                    BrkRate   = decimal.Parse(txtNewBrkRate.Text.Trim(), NumberStyles.Currency),
                    BrkAmt    = decimal.Parse(txtNewBrkAmt.Text.Trim(), NumberStyles.Currency)
                };


                if (!ValidateCalculation(fr, out outMsg))
                {
                    this.Page.AlertMessage(GetType(), outMsg);

                    return;
                }

                FreightRepository repo = new FreightRepository();
                if (repo.InsertFreight(fr))
                {
                    ClearFreightTextFields();

                    List <Freight> results = GetFreightByBookingId(bookingId);
                    gvFreight.DataSource = results;
                    gvFreight.DataBind();
                }
            }
            catch (SqlException se)
            {
                outMsg = string.Format("Unable to insert freight to database. BookingId={0}, SQLException={1}'", bookingId, se.Message);
                this.Page.AlertMessage(GetType(), outMsg);
            }
            catch (Exception ex)
            {
                outMsg = string.Format("Unable to insert freight due to an invalid entry. Bookinging={0}, Exception={1}", bookingId, ex.Message);
                this.Page.AlertMessage(GetType(), outMsg);
            }
        }
Example #3
0
        protected void gvFreight_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            GridViewRow row       = gvFreight.Rows[e.RowIndex];
            int         freightId = (int)gvFreight.DataKeys[e.RowIndex].Value;

            int     bookingId = DataUtil.GetBookingIdFromGiffiId(double.Parse(txtGiffRef.Text));
            Freight fr        = null;

            try
            {
                fr = new Freight
                {
                    Id        = freightId,
                    BookingId = bookingId,
                    Code      = (row.FindControl("txtCode") as TextBox).Text.Trim(),
                    BS        = (row.FindControl("txtBS") as TextBox).Text.Trim(),
                    PC        = (row.FindControl("txtPC") as TextBox).Text.Trim(),
                    Units     = int.Parse((row.FindControl("txtUnits") as TextBox).Text.Trim()),
                    Rate      = decimal.Parse((row.FindControl("txtRate") as TextBox).Text.Trim()),
                    AmtPPD    = decimal.Parse((row.FindControl("txtAmtPPD") as TextBox).Text.Trim()),
                    AmtCOL    = decimal.Parse((row.FindControl("txtAmtCOL") as TextBox).Text.Trim()),
                    BrkRate   = decimal.Parse((row.FindControl("txtBrkRate") as TextBox).Text.Trim()),
                    BrkAmt    = decimal.Parse((row.FindControl("txtBrkAmt") as TextBox).Text.Trim())
                };
                FreightRepository repo = new FreightRepository();
                repo.UpdateFreight(fr);

                gvFreight.EditIndex  = -1;
                gvFreight.DataSource = GetFreightByBookingId(bookingId);
                gvFreight.DataBind();
            }
            catch (SqlException se)
            {
                this.Page.AlertMessage(GetType(), string.Format("Unable to insert freight to database. SQLException={0}", bookingId, se.Message));
            }
            catch (Exception ex)
            {
                this.Page.AlertMessage(GetType(), string.Format("Unable to insert freight due to an invalid entry. Exception={0}", bookingId, ex.Message));
            }
        }