Example #1
0
        protected void gvInvoice_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            string erroMsg = string.Empty;

            GridViewRow row           = gvInvoice.Rows[e.RowIndex];
            int         billingItemId = (int)gvInvoice.DataKeys[e.RowIndex].Value;
            int         bookingId     = DataUtil.GetBookingIdFromGiffiId(double.Parse(lblGiffiRef.Text));

            BillingItem bi = null;

            try
            {
                bi = new BillingItem
                {
                    Id            = billingItemId,
                    BookingId     = bookingId,
                    CodeId        = int.Parse((row.FindControl("txtCodeId") as TextBox).Text.Trim()),
                    Description   = (row.FindControl("txtDescription") as TextBox).Text.Trim(),
                    BillingAmount = decimal.Parse((row.FindControl("txtBillingAmount") as TextBox).Text.Trim()),
                    PayoutAmount  = decimal.Parse((row.FindControl("txtPayoutAmount") as TextBox).Text.Trim())
                };

                BillingRepository repo = new BillingRepository();
                if (repo.UpdateBillingItem(bi))
                {
                    gvInvoice.EditIndex  = -1;
                    gvInvoice.DataSource = DataUtil.GetBillingItems(bookingId);
                    gvInvoice.DataBind();
                }
            }
            catch (SqlException se)
            {
                erroMsg = string.Format("Unable to insert freight to database. SQLException={0}", bookingId, se.Message);
                AlertMessage(erroMsg);
            }
            catch (Exception ex)
            {
                erroMsg = string.Format("Unable to insert freight due to an invalid entry. Exception={0}", bookingId, ex.Message);
                AlertMessage(erroMsg);
            }
        }