Beispiel #1
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        btnSave.Focus();
        var receipt = new Receipt();
        var lstSavingReceiptItem = new List <ReceiptItem>();

        if (!ReceiptItems.Any())
        {
            ShowError(Exception.UnselectedItem);
            return;
        }

        UpdateReceiptValue();

        if (IsLoaded)
        {
            receipt.CopyPropertiesFrom(Original_Receipt);
        }

        receipt.SubstitutionICMSBase  = ucCurrFieldSubstituionICMSBase.CurrencyValue;
        receipt.SubstitutionICMSValue = ucCurrFieldSubstituionICMSValue.CurrencyValue;
        receipt.FreightValue          = ucCurrFieldFreightValue.CurrencyValue;
        receipt.InsuranceValue        = ucCurrFieldInsuranceValue.CurrencyValue;
        receipt.OthersChargesValue    = ucCurrFieldOthersChargesValue.CurrencyValue;


        if (!String.IsNullOrEmpty(lblReceiptValue.Text))
        {
            receipt.ReceiptValue = Convert.ToDecimal(lblReceiptValue.Text.Replace("_", ""));
        }

        receipt.CompanyId = Company.CompanyId;

        if (Page.ViewState["customerId"] != null)
        {
            receipt.SupplierId = null;
            receipt.CustomerId = Convert.ToInt32(Page.ViewState["customerId"]);
        }
        else
        {
            receipt.CustomerId = null;
            receipt.SupplierId = Convert.ToInt32(Page.ViewState["SupplierId"]);
        }
        if (Page.ViewState["TransporterId"] != null)
        {
            receipt.TransporterId = Convert.ToInt32(Page.ViewState["TransporterId"]);
        }

        receipt.DeliveryDate = null;
        receipt.EntryDate    = null;

        if (ucEntrydate.DateTime.HasValue)
        {
            receipt.EntryDate = ucEntrydate.DateTime;
        }
        else
        {
            receipt.DeliveryDate = ucDeliveryDate.DateTime;
        }

        if (ucIssueDate.DateTime.HasValue)
        {
            receipt.IssueDate = ucIssueDate.DateTime.Value;
        }

        receipt.CfopId = Convert.ToInt32(cboCFOP.SelectedValue);

        receipt.ReceiptNumber = ucCurrFieldReceiptNumber.IntValue;

        foreach (ReceiptItem item in ReceiptItems)
        {
            item.ReceiptId = receipt.ReceiptId;
            lstSavingReceiptItem.Add(item);
        }

        try
        {
            ///update ReceiptValue
            ReceiptManager.SaveReceipt(Original_Receipt, receipt, lstSavingReceiptItem, LstServiceOrder, LstSale);
        }
        catch (InvalidOperationException)
        {
            ShowError(Exception.InvalidReceiptNumber);
            return;
        }
        Server.Transfer("Receipts.aspx");
    }