private void loadLCSettlement(BEXPORT_LC_DOCS_SETTLEMENT ExLCDocSettlement)
 {
     loadLCDoc(dbEntities.findExportLCDoc(ExLCDocSettlement.DocsCode));
     //
     txtInvoiceAmount.Value = ExLCDocSettlement.InvoiceAmount;
     txtReceiveAmount.Value = ExLCDocSettlement.ReceiveAmount;
     if (ExLCDocSettlement.DeductedAmount.HasValue)
         lblDeductedAmount.Text = ExLCDocSettlement.DeductedAmount.ToString();
     txtValueDate.SelectedDate = ExLCDocSettlement.ValueDate;
     //
     //
     rcbWaiveCharges.SelectedValue = ExLCDocSettlement.WaiveCharges;
     rcbWaiveCharges_OnSelectedIndexChanged(null, null);
     txtChargeRemarks.Text = ExLCDocSettlement.ChargeRemarks;
     txtVATNo.Text = ExLCDocSettlement.VATNo;
     if (ExLCDocSettlement.WaiveCharges.Equals(bd.YesNo.NO)) loadCharges();
 }
 private void saveSettlement(ref BEXPORT_LC_DOCS_SETTLEMENT ExLCDocSettlement)
 {
     ExLCDocSettlement.PaymentCode = tbLCCode.Text.Trim();
     int i = ExLCDocSettlement.PaymentCode.LastIndexOf(".");
     ExLCDocSettlement.DocsCode = ExLCDocSettlement.PaymentCode.Substring(0, i);
     ExLCDocSettlement.InvoiceAmount = txtInvoiceAmount.Value;
     ExLCDocSettlement.ReceiveAmount = txtReceiveAmount.Value;
     if (txtInvoiceAmount.Value.HasValue || txtReceiveAmount.Value.HasValue)
     {
         if (txtInvoiceAmount.Value.HasValue)
         {
             ExLCDocSettlement.DeductedAmount = txtInvoiceAmount.Value;
             if (txtReceiveAmount.Value.HasValue) ExLCDocSettlement.DeductedAmount = txtInvoiceAmount.Value - txtReceiveAmount.Value;
         }
         else ExLCDocSettlement.DeductedAmount = -txtReceiveAmount.Value;
     }
     ExLCDocSettlement.ValueDate = txtValueDate.SelectedDate;
     ExLCDocSettlement.WaiveCharges = rcbWaiveCharges.SelectedValue;
     ExLCDocSettlement.ChargeRemarks = txtChargeRemarks.Text;
     ExLCDocSettlement.VATNo = txtVATNo.Text;
 }
 protected void RadToolBar1_ButtonClick(object sender, RadToolBarEventArgs e)
 {
     var toolBarButton = e.Item as RadToolBarButton;
     var commandName = toolBarButton.CommandName.ToLower();
     //
     string paymentCode = tbLCCode.Text.Trim();
     var ExLCDocSettlement = dbEntities.findExportLCDocSettlement(paymentCode);
     //
     switch (commandName)
     {
         case bc.Commands.Commit:
             if (ExLCDocSettlement == null)
             {
                 ExLCDocSettlement = new BEXPORT_LC_DOCS_SETTLEMENT();
                 ExLCDocSettlement.Status = bd.TransactionStatus.UNA;
                 ExLCDocSettlement.CreateDate = DateTime.Now;
                 ExLCDocSettlement.CreateBy = this.UserInfo.Username;
                 saveSettlement(ref ExLCDocSettlement);
                 dbEntities.BEXPORT_LC_DOCS_SETTLEMENT.Add(ExLCDocSettlement);
             }
             else
             {
                 ExLCDocSettlement.Status = bd.TransactionStatus.UNA;
                 ExLCDocSettlement.UpdateDate = DateTime.Now;
                 ExLCDocSettlement.UpdatedBy = this.UserInfo.Username;
                 saveSettlement(ref ExLCDocSettlement);
                 //Xoa di insert lai
                 var ExLCDocCharge = dbEntities.BEXPORT_LC_DOCS_SETTLEMENT_CHARGES.Where(p => p.PaymentCode.Trim().ToLower().Equals(paymentCode.ToLower()));
                 if (ExLCDocCharge != null)
                 {
                     foreach (BEXPORT_LC_DOCS_SETTLEMENT_CHARGES ch in ExLCDocCharge)
                         dbEntities.BEXPORT_LC_DOCS_SETTLEMENT_CHARGES.Remove(ch);
                 }
             }
             if (ExLCDocSettlement.WaiveCharges.Equals(bd.YesNo.NO))
             {
                 BEXPORT_LC_DOCS_SETTLEMENT_CHARGES ExLCCharge;
                 if (tbChargeAmt1.Value.HasValue)
                 {
                     ExLCCharge = new BEXPORT_LC_DOCS_SETTLEMENT_CHARGES();
                     saveCharge(txtChargeCode1, rcbChargeCcy1, rcbChargeAcct1, tbChargeAmt1, rcbPartyCharged1, rcbAmortCharge1, rcbChargeStatus1, lblTaxCode1, lblTaxAmt1, ref ExLCCharge);
                     dbEntities.BEXPORT_LC_DOCS_SETTLEMENT_CHARGES.Add(ExLCCharge);
                 }
                 if (tbChargeAmt2.Value.HasValue)
                 {
                     ExLCCharge = new BEXPORT_LC_DOCS_SETTLEMENT_CHARGES();
                     saveCharge(txtChargeCode2, rcbChargeCcy2, rcbChargeAcct2, tbChargeAmt2, rcbPartyCharged2, rcbAmortCharge2, rcbChargeStatus2, lblTaxCode2, lblTaxAmt2, ref ExLCCharge);
                     dbEntities.BEXPORT_LC_DOCS_SETTLEMENT_CHARGES.Add(ExLCCharge);
                 }
                 if (tbChargeAmt3.Value.HasValue)
                 {
                     ExLCCharge = new BEXPORT_LC_DOCS_SETTLEMENT_CHARGES();
                     saveCharge(txtChargeCode3, rcbChargeCcy3, rcbChargeAcct3, tbChargeAmt3, rcbPartyCharged3, rcbAmortCharge3, rcbChargeStatus3, lblTaxCode3, lblTaxAmt3, ref ExLCCharge);
                     dbEntities.BEXPORT_LC_DOCS_SETTLEMENT_CHARGES.Add(ExLCCharge);
                 }
             }
             //
             dbEntities.SaveChanges();
             //
             Response.Redirect("Default.aspx?tabid=" + this.TabId);
             break;
         case bc.Commands.Authorize:
         case bc.Commands.Reverse:
             if (ExLCDocSettlement != null)
             {
                 if (commandName.Equals(bc.Commands.Authorize))
                 {
                     ExLCDocSettlement.Status = bd.TransactionStatus.AUT;
                     ExLCDocSettlement.AuthorizedBy = this.UserInfo.Username;
                     ExLCDocSettlement.AuthorizedDate = DateTime.Now;
                     /*
                     if (ExLCDoc.PaymentAmount.HasValue)
                         ExLCDoc.PaymentAmount += ExLCDoc.Amount;
                     else
                         ExLCDoc.PaymentAmount = ExLCDoc.Amount;
                     ExLCDoc.PaymentFull = (ExLC.PaymentAmount == ExLC.Amount);
                     */
                     dbEntities.SaveChanges();
                     Response.Redirect("Default.aspx?tabid=" + this.TabId);
                 }
                 else
                 {
                     ExLCDocSettlement.Status = bd.TransactionStatus.REV;
                     dbEntities.SaveChanges();
                     Response.Redirect("Default.aspx?tabid=" + this.TabId + "&code=" + tbLCCode.Text);
                 }
             }
             break;
     }
 }