protected void Page_Load(object sender, EventArgs e)
        {
            string sAgentNo   = "";
            string sAgentName = "";
            string sError;

            string sFN = WebConfigurationManager.AppSettings["SavePDFPath"].ToString() + "AgentDashboard.pdf";


            string sYearFrom = Request.QueryString["YearFrom"].ToString();
            string sYearTo   = Request.QueryString["YearTo"].ToString();

            if (Convert.ToInt32(Session["Internal"]) != 1)
            {
                sAgentNo   = Agent.GetAgentCode(Agent.GetMGMAgentNo(Session["RepName"].ToString()), Session["RepName"].ToString());
                sAgentName = Session["RepName"].ToString();
            }
            else
            {
                sAgentNo   = Request.QueryString["AgentNo"].ToString();
                sAgentName = Request.QueryString["AgentName"].ToString().Replace("88", "&");
            }


            string sAgentCode = Agent.GetAgentCode(Convert.ToInt32(sAgentNo), sAgentName);

            AgentDashboardPDF adPDF = new AgentDashboardPDF(new DateTime(Convert.ToInt32(sYearFrom), 1, 1),
                                                            new DateTime(Convert.ToInt32(sYearTo), 12, 31), sAgentName == "All Agents" ? "All Agents" : sAgentCode, sAgentName, sAgentNo, sFN);


            if (!adPDF.CreatePDF(out sError))
            {
                System.Web.HttpContext.Current.Response.Write("<h1>No Data Found</h1>");
            }
            else
            {
                System.Web.HttpContext.Current.Response.ClearContent();
                System.Web.HttpContext.Current.Response.ClearHeaders();
                System.Web.HttpContext.Current.Response.ContentType = "application/pdf";
                System.Web.HttpContext.Current.Response.WriteFile(sFN);
            }
        }
示例#2
0
        /// <summary>
        /// Preview the selected report with the selected options.
        /// </summary>
        /// <param name="sTarget"></param>
        protected void Preview(string sTarget)
        {
            string sRptName   = "";
            string sUserName  = Session["UserName"].ToString();
            string sAgentName = "";
            int    iInternal  = Convert.ToInt32(Session["Internal"]);
            string sAgent     = "";
            string sAgentCode = "";
            string sError;

            if (sTarget == "Performance")
            {
                sRptName = "PerformancePDF";
            }
            else if (sTarget == "Gift Card")
            {
                sRptName = "GiftCardPromotionPDF";
            }
            else if (sTarget == "Agent Stock Prices")
            {
                sRptName = "AgentStockPricesPDF";
            }
            else if (sTarget == "Pending Approvals")
            {
                sRptName = "AdminPendingApprovals";
            }
            else if (sTarget == "M1 Customer Sales")
            {
                sRptName = "M1CustSales";
            }

            else if (sTarget == "Quote Status")
            {
                sRptName = "QuoteStatusPDF";
            }
            else if (sTarget == "Inventory")
            {
                sRptName = "InventoryPDF";
            }
            else if (sTarget == "Agent Dashboard")
            {
                sRptName = "AgentDashboard";
            }
            else
            {
                return;
            }

            string sRedirect = "";

            if (pnlCriteria.Visible == true)
            {
                if (ValidateDateRange() == true)
                {
                    string sRepID = "";
                    // 0 = Current Rep - Always this choice if not Admin.
                    if (rblAll.SelectedValue == "0" || rblAll.Visible == false)
                    {
                        sRepID = Session["RepID"].ToString();
                    }
                    // 1 = All Reps.
                    else
                    {
                        sRepID = "0";
                    }

                    string sDateFrom = txtFrom.Text.ToString();
                    string sDateTo   = txtTo.Text.ToString();

                    if (sTarget == "M1 Customer Sales")
                    {
                        string sProductCat = rblProductCat.SelectedValue;

                        if (ddlAgents.Visible == true)
                        {
                            sRepID = ddlAgents.SelectedValue;
                        }
                        else
                        {
                            sRepID = Session["MGMAgentNo"].ToString();
                        }

                        sRepID = string.IsNullOrEmpty(sRepID) ? "-1" : sRepID;
                        lblAgentReqd.Visible = false;

                        // If no rep selected, show Agent required and exit.
                        if (sRepID == "-1")
                        {
                            lblAgentReqd.Visible = true;
                            return;
                        }

                        sRedirect = "~/" + sRptName + ".aspx?AgentNo=" + sRepID + "&DateFrom=" + sDateFrom +
                                    "&DateTo=" + sDateTo + "&ProductCat=" + sProductCat;
                    }
                    else if (sTarget == "Performance")
                    {
                        sRedirect = "~/" + sRptName + ".aspx?DateFrom=" + sDateFrom +
                                    "&DateTo=" + sDateTo + "&RepID=" + sRepID + "&UserName="******"Quote Status")
                    {
                        sRedirect = "~/" + sRptName + ".aspx?DateFrom=" + sDateFrom +
                                    "&DateTo=" + sDateTo + "&UserName="******"Inventory")
                    {
                        if (ddlAgentsWithWarehouse.Visible == true)
                        {
                            sRepID = ddlAgentsWithWarehouse.SelectedValue;
                        }
                        else
                        {
                            sRepID = "-1";// Session["MGMAgentNo"].ToString();
                        }


                        if (rbSelectAgentInventory.Checked)
                        {
                            sRepID = string.IsNullOrEmpty(sRepID) ? "-1" : sRepID;
                            lblAgentReqd.Visible = false;

                            // If no rep selected, show Agent required and exit.
                            if (sRepID == "-1")
                            {
                                lblAgentReqd.Visible = true;
                                return;
                            }
                        }

                        sAgentName = ddlAgentsWithWarehouse.Items[ddlAgentsWithWarehouse.SelectedIndex].ToString();


                        sRedirect = "~/" + sRptName + ".aspx?Agent=" + sRepID + "&Name=" + Server.UrlEncode(sAgentName) + "&All=" +
                                    (rbAllAgentInventory.Checked ? "true" : "false") + "&KVA=0&VoltageCat=ALL&VoltageDisp=&Windings=&Searching=false";


                        if (rbSearchAvailability.Checked)
                        {
                            sRedirect = "~/" + sRptName + ".aspx?Agent=" + sRepID + "&Name=" + Server.UrlEncode(sAgentName) +
                                        "&All=true&KVA=" + (ddKVA.SelectedItem.Text == "ALL" ? "0" : ddKVA.SelectedItem.Text) +
                                        "&VoltageCat=" + StockVoltages.GetCategory(ddVoltage.SelectedItem.Text, rblWindings.SelectedItem.Text) +
                                        "&VoltageDisp=" + ddVoltage.SelectedItem.Text +
                                        "&Windings=" + (rblWindings.SelectedItem.Text == "Aluminum" ? "Al" : "Cu") +
                                        "&Searching=true";
                        }
                    }
                    else if (sTarget == "Agent Dashboard")
                    {
                        int _iStartDate = Convert.ToInt32(ddlDistributorDashboardFromYear.SelectedItem.ToString());
                        int _iEndDate   = Convert.ToInt32(ddlDistributorDashboardToYear.SelectedItem.ToString());

                        if (_iEndDate - _iStartDate + 1 > 6)
                        {
                            lblNotEnoughDataDashboard.Text = "Maximum 6 Years Time Span.";
                            return;
                        }

                        if (Convert.ToInt32(Session["Internal"]) == 1)
                        {
                            sAgent = Agent.GetAgentCode(Convert.ToInt32(ddlAgents.SelectedItem.Value), ddlAgents.SelectedItem.Text);
                        }
                        else
                        {
                            sAgent = Agent.GetAgentCode(Agent.GetMGMAgentNo(Session["RepName"].ToString()), Session["RepName"].ToString());
                        }

                        if (sAgent == "")
                        {
                            lblNotEnoughDataDashboard.Text = "Agent information not found.";
                            return;
                        }


                        sAgentName = Session["RepName"].ToString();

                        if (ddlAgents.Visible)
                        {
                            if ((ddlAgents.SelectedItem.Value == "-1") && (iInternal == 1))
                            {
                                lblInventoryExternal.ForeColor = System.Drawing.Color.Red;
                                lblInventoryExternal.Text      = "Agent Required";
                                lblInventoryExternal.Visible   = true;
                                return;
                            }

                            sAgent     = ddlAgents.SelectedItem.Value;
                            sAgentName = ddlAgents.SelectedItem.Text;
                        }

                        if (Convert.ToInt32(Session["Internal"]) == 1)
                        {
                            sAgentCode = Agent.GetAgentCode(Convert.ToInt32(sAgent), ddlAgents.SelectedItem.Text);
                        }
                        else
                        {
                            sAgentCode = Agent.GetAgentCode(Convert.ToInt32(sAgent), sAgentName);
                        }


                        AgentDashboardPDF adPDF = new AgentDashboardPDF(new DateTime(Convert.ToInt32(ddlDistributorDashboardFromYear.SelectedItem.ToString()), 1, 1),
                                                                        new DateTime(Convert.ToInt32(ddlDistributorDashboardToYear.SelectedItem.ToString()), 12, 31),
                                                                        sAgentName == "All Agents" ? "All Agents" : sAgentCode, sAgentName, sAgent, "");

                        if (!adPDF.IsThereData)
                        {
                            lblNotEnoughDataDashboard.Text = "Not enough Data to generate Dashboard";
                            return;
                        }
                        else
                        {
                            if (WebConfigurationManager.AppSettings["SaveAgentDashboard"] != null &&
                                WebConfigurationManager.AppSettings["SaveAgentDashboard"].ToString() == "1")
                            {
                                string sURL = "Agent Dashboard - [" + sAgentName.Replace("&", "and") + "," + ddlDistributorDashboardFromYear.SelectedItem.ToString() + "," +
                                              ddlDistributorDashboardToYear.SelectedItem.ToString() + "]" + ".pdf";
                                sURL = sURL.Replace("&", "and");

                                if (WebConfigurationManager.AppSettings["LocalMachine"] != null &&
                                    Convert.ToBoolean(WebConfigurationManager.AppSettings["LocalMachine"]) == true)
                                {
                                    if (WebConfigurationManager.AppSettings["LocalMachinePath"] == null)
                                    {
                                        lblDSRNoResults.Text = "No Path Setting";
                                        return;
                                    }

                                    adPDF.FileName = WebConfigurationManager.AppSettings["LocalMachinePath"] + sURL;
                                    adPDF.CreatePDF(out sError);


                                    if (WebConfigurationManager.AppSettings["LocalWebSiteURL"] == null)
                                    {
                                        lblDSRNoResults.Text = "Redirect Failed.";
                                        return;
                                    }
                                    ResponseHelper.Redirect(WebConfigurationManager.AppSettings["LocalWebSiteURL"] + sURL, "_blank", "");
                                }
                                else
                                {
                                    adPDF.FileName = "C:\\MGMQuotation\\pdfs\\" + sURL;
                                    adPDF.CreatePDF(out sError);
                                    ResponseHelper.Redirect("https://MGMQuotation.MGMTransformer.com//MGMQuotation//pdfs//" + sURL, "_blank", "");
                                }
                            }
                            else
                            {
                                sRedirect = "~/" + sRptName + ".aspx?YearFrom=" + ddlDistributorDashboardFromYear.SelectedItem.ToString() +
                                            "&YearTo=" + ddlDistributorDashboardToYear.SelectedItem.ToString() + "&AgentNo=" + sAgent +
                                            "&AgentName=" + sAgentName.Replace("&", "88");
                            }
                        }
                    }
                    else
                    {
                        sRedirect = "~/" + sRptName + ".aspx?DateFrom=" + sDateFrom +
                                    "&DateTo=" + sDateTo + "&RepID=" + sRepID;
                    }
                }
            }
            else
            {
                sRedirect = "~/" + sRptName + ".aspx";
            }

            // open PDF.
            ResponseHelper.Redirect(sRedirect, "_blank", "");
        }