Example #1
0
    protected void OnButtonInvoicePrintSelectionClicked(object sender, EventArgs e)
    {
        List<InvoicingFile> fileList = new List<InvoicingFile>();
        GridItemCollection col = gridInvoice.SelectedItems;
        foreach (GridDataItem item in col)
        {
            TableCell cell = item["InvoiceIdPK"];
            if (!string.IsNullOrEmpty(cell.Text))
            {
                string[] key = cell.Text.Split('-');
                int idFactNumber = int.Parse(key[0]);
                string type = key[1];
                int idYear = int.Parse(key[2]);
                Invoices invoice = new InvoicesRepository().GetInvoiceByID(idFactNumber, type, idYear);
                string fileName = Common.ExportInvoices(invoice, WebConfig.AddressFillInInvoice,
                    WebConfig.AbsoluteExportDirectory);

                InvoicingFile file = new InvoicingFile();
                file.InvoiceIdPK = invoice.InvoiceIdPK;
                file.FilePath = fileName;
                fileList.Add(file);
            }
        }
        InvoicingMView.ActiveViewIndex = 1;
        ProcessPrintedFiles(fileList);

        /*string message = ResourceManager.GetString("messageExportSuccessfully");
        string script1 = "<script type=\"text/javascript\">";
        script1 += " alert(\"" + message + "\")";
        script1 += " </script>";

        if (!ClientScript.IsClientScriptBlockRegistered("redirectUser"))
            ClientScript.RegisterStartupScript(this.GetType(), "redirectUser", script1);*/
    }
Example #2
0
    protected void OnMyAjaxManagerAjaxRequest(object sender, AjaxRequestEventArgs e)
    {
        if (e.Argument.IndexOf("RebindInvoiceDetailGrid") != -1)
        {
            InvoiceAjaxManager.AjaxSettings.AddAjaxSetting(InvoiceAjaxManager, gridInvoiceDetails);
            //InvoiceAjaxManager.AjaxSettings.AddAjaxSetting(InvoiceAjaxManager, btnPrintSelection);
            string[] args = e.Argument.Split('/');
            if (args.Length == 3)
            {
                try
                {
                    //string userID = args[1];
                    int rowIndex = Int32.Parse(args[2]);
                    gridInvoice.MasterTableView.ClearSelectedItems();
                    gridInvoice.MasterTableView.Items[rowIndex - 1].Selected = true;
                }
                catch (System.Exception ex) { throw ex; }
                gridInvoiceDetails.Rebind();
                //btnPrintSelection.Enabled = true;
            }
        }
        else if (e.Argument.IndexOf("InvoiceGridMultiSelected") != -1)
        {
            //InvoiceAjaxManager.AjaxSettings.AddAjaxSetting(InvoiceAjaxManager, btnPrintSelection);
            //btnPrintSelection.Enabled = true;

            bool isSameReceiptionEmail = true;
            string email = "";
            string[] args = e.Argument.Split('/');
            if (args.Length == 2)
            {
                List<string> invoices = new List<string>(args[1].TrimEnd(';').Split(';'));
                foreach (string invoiceId in invoices)
                {
                    if (!string.IsNullOrEmpty(invoiceId))
                    {
                        string[] key = invoiceId.Split('-');
                        int idFactNumber = int.Parse(key[0]);
                        string type = key[1];
                        int idYear = int.Parse(key[2]);
                        Invoices invoice = new InvoicesRepository().GetInvoiceByID(idFactNumber, type, idYear);
                        if (string.IsNullOrEmpty(email))
                        {
                            email = GetEmailOfCompany(invoice.CompanyId.Value);
                        }
                        else
                            if (email.CompareTo(GetEmailOfCompany(invoice.CompanyId.Value)) != 0)
                            {
                                isSameReceiptionEmail = false;
                                break;
                            }
                        //InvoiceAjaxManager.ResponseScripts.Add(string.Format("alert('{0}: {1}')", invoice.InvoiceIdPK, GetEmailOfCompany(invoice.CompanyId.Value)));
                    }
                }
            }
            if (isSameReceiptionEmail)
            {
                InvoiceAjaxManager.ResponseScripts.Add("processInvoiceToolBar(\"InvoiceGridSelectedSameReceiptionEmail\")");
            }
            else
                InvoiceAjaxManager.ResponseScripts.Add("processInvoiceToolBar(\"InvoiceGridMultiSelected\")");

        }
        else if (e.Argument.IndexOf("RebindInvoiceGrid") != -1)
        {
            InvoiceAjaxManager.AjaxSettings.AddAjaxSetting(InvoiceAjaxManager, gridInvoice);
            InvoiceAjaxManager.AjaxSettings.AddAjaxSetting(InvoiceAjaxManager, gridInvoiceDetails);
            gridInvoice.Rebind();
            gridInvoiceDetails.Rebind();
        }
        else
        {
            switch (e.Argument)
            {
                case "OpenSelectedInvoice":
                    Response.Redirect(string.Format("~/InvoiceProfile.aspx?InvoiceIdPK={0}&mode=edit&backurl=visible", GetSelectedInvoiceIdPK()), true);
                    break;
                case "DeleteSelectedInvoice":
                    InvoiceAjaxManager.AjaxSettings.AddAjaxSetting(InvoiceAjaxManager, gridInvoice);
                    InvoiceAjaxManager.AjaxSettings.AddAjaxSetting(InvoiceAjaxManager, gridInvoiceDetails);
                    foreach (GridDataItem selectedItem in gridInvoice.SelectedItems)
                    {
                        TableCell invoiceIDCell = selectedItem["InvoiceIdPK"];
                        string invoiceID = selectedItem["InvoiceIdPK"].Text;
                        if (!string.IsNullOrEmpty(invoiceID))
                        {
                            string[] key = invoiceID.Split('-');
                            int idFactNumber = int.Parse(key[0]);
                            string type = key[1];
                            int idYear = int.Parse(key[2]);
                            //Delete Invoice's payments first.
                            InvoicePaymentsRepository payRepo = new InvoicePaymentsRepository();
                            payRepo.DeleteInvoicePaymentsOfInvoice(idFactNumber, type, idYear);

                            //Delete invoice's details
                            InvoiceDetailsRepository detailRepo = new InvoiceDetailsRepository();
                            detailRepo.DeleteInvoiceDetails(idFactNumber, type, idYear, null);

                            //Delete Invoice
                            InvoicesRepository invoiceRepo = new InvoicesRepository();
                            invoiceRepo.DeleteInvoice(idFactNumber, type, idYear);
                        }
                    }
                    BindGridData(null);
                    gridInvoice.DataBind();
                    break;
                case "PrintInvoice":

                    List<InvoicingFile> fileList = new List<InvoicingFile>();
                    GridItemCollection col = gridInvoice.SelectedItems;
                    foreach (GridDataItem item in col)
                    {
                        TableCell cell = item["InvoiceIdPK"];
                        if (!string.IsNullOrEmpty(cell.Text))
                        {
                            string[] key = cell.Text.Split('-');
                            int idFactNumber = int.Parse(key[0]);
                            string type = key[1];
                            int idYear = int.Parse(key[2]);
                            Invoices invoice = new InvoicesRepository().GetInvoiceByID(idFactNumber, type, idYear);
                            string fileName = Common.ExportInvoices(invoice, WebConfig.AddressFillInInvoice,
                                WebConfig.AbsoluteExportDirectory);

                            InvoicingFile file = new InvoicingFile();
                            file.InvoiceIdPK = invoice.InvoiceIdPK;
                            file.FilePath = fileName;
                            fileList.Add(file);
                        }
                    }
                    InvoicingMView.ActiveViewIndex = 1;
                    ProcessPrintedFiles(fileList);

                    break;
                case "EmailInvoice":
                    string selectedInvoiceIDs = "";
                    foreach (GridDataItem selectedItem in gridInvoice.SelectedItems)
                    {
                        TableCell invoiceIDCell = selectedItem["InvoiceIdPK"];
                        string invoiceID = selectedItem["InvoiceIdPK"].Text;
                        if (!string.IsNullOrEmpty(invoiceID))
                        {
                            selectedInvoiceIDs += invoiceID + ";";
                        }
                    }
                    selectedInvoiceIDs = selectedInvoiceIDs.TrimEnd(';');
                    string url = "SendEmail.aspx?type=invoice&ids=" + selectedInvoiceIDs;
                    InvoiceAjaxManager.ResponseScripts.Add(string.Format("OnSendInvoiceByEmail('{0}')", url));

                    break;
                case "CopyInvoice":
                    Response.Redirect(string.Format("~/InvoiceProfile.aspx?type=copy&from={0}&mode=edit", GetSelectedInvoiceIdPK()));
                    break;
            }
        }
    }
Example #3
0
    protected void OnButtonInvoicePrintAllClicked(object sender, EventArgs e)
    {
        List<InvoicingFile> fileList = new List<InvoicingFile>();

        if (!string.IsNullOrEmpty(Request.QueryString["type"]) && Request.QueryString["type"] == "search")
        {
            InvoicesSearchCriteria criteria = new InvoicesSearchCriteria();
            string sortExpress = "IdFactNumber DESC, IdTypeInvoice ASC, IdYear DESC";
            string sortExpressInvert = "IdFactNumber ASC, IdTypeInvoice DESC, IdYear ASC";

            if (!string.IsNullOrEmpty(Request.QueryString["invoiceNumberFrom"]))
                criteria.InvoiceNumberFrom = int.Parse(Request.QueryString["invoiceNumberFrom"]);
            if (!string.IsNullOrEmpty(Request.QueryString["invoiceNumberTo"]))
                criteria.InvoiceNumberTo = int.Parse(Request.QueryString["invoiceNumberTo"]);

            if (!string.IsNullOrEmpty(Request.QueryString["fiscalYear"]))
                criteria.FiscalYear = int.Parse(Request.QueryString["fiscalYear"]);

            if (!string.IsNullOrEmpty(Request.QueryString["dateFrom"]))
                criteria.InvoiceDateFrom = DateTime.ParseExact(Request.QueryString["dateFrom"], "dd/MM/yyyy",
                    System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat);
            if (!string.IsNullOrEmpty(Request.QueryString["dateTo"]))
                criteria.InvoiceDateTo = DateTime.ParseExact(Request.QueryString["dateTo"], "dd/MM/yyyy",
                    System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat);

            if (!string.IsNullOrEmpty(Request.QueryString["invoiceType"]))
                criteria.InvoiceType = Request.QueryString["invoiceType"];

            if (!string.IsNullOrEmpty(Request.QueryString["customer"]))
                criteria.Customer = int.Parse(Request.QueryString["customer"]);

            InvoicesRepository repo = new InvoicesRepository();
            gridInvoice.VirtualItemCount = repo.CountInvoices(criteria, 10, 1, sortExpress, sortExpressInvert);
            IList<Invoices> list = repo.SearchInvoices(criteria, gridInvoice.VirtualItemCount,
                1, sortExpress, sortExpressInvert);
            foreach (Invoices item in list)
            {
                string filePath = Common.ExportInvoices(item, WebConfig.AddressFillInInvoice,
                    WebConfig.AbsoluteExportDirectory);

                InvoicingFile file = new InvoicingFile();
                file.InvoiceIdPK = item.InvoiceIdPK;
                file.FilePath = filePath;

                fileList.Add(file);
            }
            InvoicingMView.ActiveViewIndex = 1;
            ProcessPrintedFiles(fileList);

            /*string message = ResourceManager.GetString("messageExportSuccessfully");
            string script1 = "<script type=\"text/javascript\">";
            script1 += " alert(\"" + message + "\")";
            script1 += " </script>";

            if (!ClientScript.IsClientScriptBlockRegistered("redirectUser"))
                ClientScript.RegisterStartupScript(this.GetType(), "redirectUser", script1);*/
        }
    }