private Invoice SaveInvoice()
    {
        financialManager = new FinancialManager(this);
        Invoice original_invoice = new Invoice();
        Invoice invoice = new Invoice();

        if (Page.ViewState["InvoiceId"] != null)
        {
            original_invoice = financialManager.GetInvoice(Company.CompanyId, Convert.ToInt32(Page.ViewState["InvoiceId"]));
            invoice.CopyPropertiesFrom(original_invoice);
        }

        invoice.Description = txtSource.Text;
        invoice.CompanyId = Company.CompanyId;
        invoice.CostCenterId = Convert.ToInt32(cboCostCenter.SelectedValue);

        if (Page.ViewState["CustomerId"] != null)
            invoice.CustomerId = Convert.ToInt32(Page.ViewState["CustomerId"]);

        //accountPlan
        if (!String.IsNullOrEmpty(cboAccountPlan.SelectedValue))
            invoice.AccountingPlanId = Convert.ToInt32(cboAccountPlan.SelectedValue);

        if (Page.ViewState["InvoiceId"] != null)
        {
            invoice.ModifiedByUser = User.Identity.UserName;
            financialManager.Update(original_invoice, invoice, ucParcels.DataSource);
        }
        else
        {
            invoice.CreatedByUser = User.Identity.UserName;
            financialManager.Insert(invoice, ucParcels.DataSource);
        }


        if (Page.ViewState["InvoiceId"] != null)
            return original_invoice;
        else
            return invoice;
    }
Esempio n. 2
0
    private void SaveBill(object sender)
    {
        var bill = new Bill();

        bill.CopyPropertiesFrom(OriginalBill);

        bill.CompanyId = Company.CompanyId;
        // Numero da Nota fiscal do fornecedor
        bill.DocumentNumber = txtDocumentNumber.Text;
       
        bill.Description = txtDescription.Text;
        bill.CostCenterId = Convert.ToInt32(cboCostCenter.SelectedValue);
        bill.EntryDate = DateTime.Now;



        //supplier
        if (Page.ViewState["SupplierId"] != null)
            bill.SupplierId = Convert.ToInt32(Page.ViewState["SupplierId"]);
        else
            bill.SupplierId = null;

        //accountPlan
        if (!String.IsNullOrEmpty(cboAccountPlan.SelectedValue))
            bill.AccountingPlanId = Convert.ToInt32(cboAccountPlan.SelectedValue);

        //documentType
        if (rbtGuia.Checked)
            bill.DocumentType = (Int32)DocumentType.Guia;
        else if (rbtReceipt.Checked)
            bill.DocumentType = (Int32)DocumentType.receipt;
        else if (rbtOthers.Checked)
            bill.DocumentType = (Int32)DocumentType.others;

        var billManager = new FinancialManager(this);

        //bill.Parcels = ucParcels.DataSource;

        if (Page.ViewState["BillId"] != null)
        {
            bill.ModifiedByUser = User.Identity.UserName;
            billManager.Update(OriginalBill, bill, ucParcels.DataSource);
        }
        else
        {
            bill.CreatedByUser = User.Identity.UserName;
            billManager.Insert(bill, ucParcels.DataSource);
            Context.Items["PostBack"] = Context.Items["BillId"] = bill.BillId;
        }
        ucParcels.Clear();

        if ((sender as Button).ID == "btnNew")
            Response.Redirect("Bill.aspx");
        else
            Response.Redirect("Bills.aspx");
    }