コード例 #1
0
    protected void OnBtnSaveClicked(object sender, EventArgs e)
    {
        InvoiceDetailsRepository repo = new InvoiceDetailsRepository();
        InvoicesRepository repoInv = new InvoicesRepository();
        if (!string.IsNullOrEmpty(Request.QueryString["InvoiceDetailId"]))
        {
            string[] key = Request.QueryString["InvoiceDetailId"].Split('-');
            int idFactNumber = int.Parse(key[0]);
            string type = key[1];
            int idYear = int.Parse(key[2]);
            int idLigneNumber = int.Parse(key[3]);
            IList<InvoiceDetails> invDetailList = repo.GetInvoiceDetailsOfInvoice(
                idFactNumber, type, idYear, idLigneNumber);
            if (invDetailList.Count == 1)
            {
                InvoiceDetails invDetail = invDetailList[0];
                invDetail.Description = txtDescription.Text;
                invDetail.Quantity = txtQuantity.Value;
                invDetail.UnitPriceEuro = txtUnitPrice.Value;
                invDetail.AmountEuro = (invDetail.Quantity.HasValue ? invDetail.Quantity.Value : 0) *
                    (invDetail.UnitPriceEuro.HasValue ? invDetail.UnitPriceEuro.Value : 0);
                invDetail.VatCode = int.Parse(ddlVAT.SelectedValue);
                repo.UpdateInvoiceDetails(invDetail);
                repoInv.ReComputeAmountOfInvoice(idFactNumber, type, idYear);
            }
        }
        else if (!string.IsNullOrEmpty(Request.QueryString["InvoiceIdPK"]))
        {
            string[] key = Request.QueryString["InvoiceIdPK"].Split('-');
            int idFactNumber = int.Parse(key[0]);
            string type = key[1];
            int idYear = int.Parse(key[2]);
            int? idLigneNumber = repo.GetMaxInvoiceDetailOrderNumber(idFactNumber, type, idYear);
            if (!idLigneNumber.HasValue)
                idLigneNumber = 1;
            else
                idLigneNumber += 1;
            InvoiceDetails invDetail = new InvoiceDetails();
            invDetail.IdFactNumber = idFactNumber;
            invDetail.IdTypeInvoice = type;
            invDetail.IdYear = idYear;
            invDetail.IdLigneNumber = idLigneNumber.Value;

            invDetail.Description = txtDescription.Text;
            invDetail.Quantity = txtQuantity.Value;
            invDetail.UnitPriceEuro = txtUnitPrice.Value;
            invDetail.AmountEuro = (invDetail.Quantity.HasValue ? invDetail.Quantity.Value : 0) *
                    (invDetail.UnitPriceEuro.HasValue ? invDetail.UnitPriceEuro.Value : 0);
            invDetail.VatCode = int.Parse(ddlVAT.SelectedValue);
            repo.InserNewInvoiceDetails(invDetail);
            repoInv.ReComputeAmountOfInvoice(idFactNumber, type, idYear);
        }

        string script = "<script type=\"text/javascript\">";
        script += " OnBtnSaveClientClicked();";
        script += " </script>";

        if (!ClientScript.IsClientScriptBlockRegistered("saveAndCloseWindow"))
            ClientScript.RegisterStartupScript(this.GetType(), "saveAndCloseWindow", script);
    }
コード例 #2
0
    protected void OnButtonInvoiceEditSaveClicked(object sender, EventArgs e)
    {
        if (btnEditSave.Text == ResourceManager.GetString("editText"))
        {
            //Change mode to Edit mode.
            //btnEditSave.Text = ResourceManager.GetString("saveText");
            //EnableInvoiceControls(true);
            //lnkAddInvoiceDetail.OnClientClick = "return OnAddNewInvoiceDetailClientClicked('"
            //    + SessionManager.CurrentInvoice.InvoiceIdPK + "')";
            //lnkAddNewPayment.OnClientClick = "return OnAddNewInvoicePaymentClientClicked('"
            //    + SessionManager.CurrentInvoice.InvoiceIdPK + "')";
            //btnExport.Visible = false;
            string url = Request.Url.PathAndQuery;

            if (!string.IsNullOrEmpty(Request.QueryString["mode"]))
                url = url.Replace(Request.QueryString["mode"], "edit");
            else
                url += "&mode=edit";
            Response.Redirect(url, true);
        }
        else if (Request.QueryString["type"] == "copy")
        {
            string message;
            SessionManager.CurrentInvoice = null;
            Invoices saveItem = GetInvoice(out message);
            if (!string.IsNullOrEmpty(message))
            {
                string script = "<script type=\"text/javascript\">";
                script += " alert(\"" + message + "\")";
                script += " </script>";

                if (!ClientScript.IsClientScriptBlockRegistered("redirectUser"))
                    ClientScript.RegisterStartupScript(this.GetType(), "redirectUser", script);
                return;
            }
            InvoicesRepository repo = new InvoicesRepository();
            repo.InserNewInvoices(saveItem);
            //insert invoice details
            if (!string.IsNullOrEmpty(Request.QueryString["from"]))
            {
                string invoideIDPK = Request.QueryString["from"];
                string[] key = invoideIDPK.Split('-');
                int idFactNumber = int.Parse(key[0]);
                string type = key[1];
                int idYear = int.Parse(key[2]);

                InvoiceDetailsRepository detailRepo = new InvoiceDetailsRepository();
                IList<InvoiceDetails> detailList = detailRepo.GetInvoiceDetailsOfInvoice(idFactNumber, type, idYear, null);
                foreach (InvoiceDetails detail in detailList)
                {
                    detail.IdFactNumber = saveItem.IdFactNumber;
                    detail.IdTypeInvoice = saveItem.IdTypeInvoice;
                    detail.IdYear = saveItem.IdYear;

                    detailRepo.InserNewInvoiceDetails(detail);
                }
            }

            Response.Redirect("~/InvoiceProfile.aspx?InvoiceIdPK=" + saveItem.InvoiceIdPK + "&mode=edit", true);
        }
        else
        {
            string message;
            //Save data.
            Invoices saveItem = GetInvoice(out message);
            if (!string.IsNullOrEmpty(message))
            {
                string script = "<script type=\"text/javascript\">";
                script += " alert(\"" + message + "\")";
                script += " </script>";

                if (!ClientScript.IsClientScriptBlockRegistered("redirectUser"))
                    ClientScript.RegisterStartupScript(this.GetType(), "redirectUser", script);
                return;
            }
            InvoicesRepository repo = new InvoicesRepository();

            //if (SessionManager.CurrentInvoice != null)
            if (!string.IsNullOrEmpty(Request.QueryString["InvoiceIdPK"]))
            {
                repo.UpdateInvoices(saveItem);
            }
            else
            {
                repo.InserNewInvoices(saveItem);
            }

            if (saveItem.IdFactNumberNew.HasValue)
                SessionManager.CurrentInvoice = repo.GetInvoiceByID(saveItem.IdFactNumberNew.Value, saveItem.IdTypeInvoice, saveItem.IdYear);
            else
                SessionManager.CurrentInvoice = repo.GetInvoiceByID(saveItem.IdFactNumber, saveItem.IdTypeInvoice, saveItem.IdYear);

            if (SessionManager.CurrentInvoice.CompanyId.HasValue)
            {
                txtIdCustomer.Text = SessionManager.CurrentInvoice.CompanyId.ToString();
                txtCustomerName.Text = SessionManager.CurrentInvoice.CompanyName.Trim();
            }
            txtInvoiceNumber.Text = SessionManager.CurrentInvoice.IdFactNumber.ToString();
            //    //Change mode to View mode

            string addBackUrl = string.Empty;
            if (!string.IsNullOrEmpty(Request.QueryString["backurl"]) && Request.QueryString["backurl"] == "visible")
            {
                addBackUrl = "&backurl=visible";
            }
            Response.Redirect(string.Format("~/InvoiceProfile.aspx?InvoiceIdPK={0}&mode=view" + addBackUrl, SessionManager.CurrentInvoice.InvoiceIdPK), true);
        }
    }