public byte[] GetPDFFileByteArray(string formOrdKy, string formObjCaption, string formObjKy, string ReptNo)
        {
            List <paramClass> listParam = new List <paramClass>();

            string CKy   = HTNSession.CKy.ToString();
            string UsrKy = HTNSession.UsrKy.ToString();

            string UsrNm           = HTNSession.UsrId.ToString();
            string CNm             = HTNSession.CNm.ToString();
            string ServerName      = ConfigurationManager.AppSettings["ReportServerName"].ToString();
            string EnvironmentName = HTNSession.Environment;

            string ReportServerUrl = WebConfigurationManager.AppSettings["ReportpathforServer"];
            string _userName       = ConfigurationManager.AppSettings["ReportServerUserName"];
            string _pasword        = ConfigurationManager.AppSettings["ReportServerPwd"];

            ApiOperation apiOpr = new ApiOperation();

            List <ObjMasModel> selectedReportProp = apiOpr.UsrObjPrp_SelectWeb(
                EnvironmentName, Convert.ToInt32(CKy), Convert.ToInt32(UsrKy), formObjKy, "ReportWeb", null);

            ObjMasModel selectedReportPropObj = new ObjMasModel();

            if (ReptNo == "1")
            {
                selectedReportPropObj = selectedReportProp.Where(obj => obj.ObjNm == "SourceReport").SingleOrDefault();
            }
            else
            {
                string dynmicObjNm = "SourceReport_" + ReptNo;
                selectedReportPropObj = selectedReportProp.Where(obj => obj.ObjNm == dynmicObjNm).SingleOrDefault();
            }

            List <ObjMasModel> selectedReportParamProp = apiOpr.UsrObjPrp_SelectWeb(
                EnvironmentName, Convert.ToInt32(CKy), Convert.ToInt32(UsrKy),
                selectedReportPropObj.ObjKy.ToString(), "ReportParameter", null);

            List <ObjMasModel> selectedReportPrameter = apiOpr.UsrObjPrp_SelectWeb(
                EnvironmentName, Convert.ToInt32(CKy), Convert.ToInt32(UsrKy),
                selectedReportParamProp[0].ObjKy.ToString(), null, null);

            string paramString = "";

            foreach (ObjMasModel dynobj in selectedReportPrameter)
            {
                paramClass param = new paramClass();

                string ObjNm = dynobj.ObjNm.ToString();

                param.Paramname = ObjNm;

                if (string.Equals(ObjNm, "CKy", StringComparison.CurrentCultureIgnoreCase))
                {
                    //paramList.Add(new ReportParameter(ObjNm, CKy));
                    paramString      = paramString + "&" + ObjNm + "=" + CKy;
                    param.ParamValue = CKy;
                }
                else if (string.Equals(ObjNm, "UsrKy", StringComparison.CurrentCultureIgnoreCase))
                {
                    //paramList.Add(new ReportParameter(ObjNm, UsrKy));
                    paramString      = paramString + "&" + ObjNm + "=" + UsrKy;
                    param.ParamValue = UsrKy;
                }
                else if (ObjNm == "ObjKy")
                {
                    //paramList.Add(new ReportParameter("ObjKy", selectedReportPropObj.ObjKy.ToString()));
                    paramString      = paramString + "&ObjKy=" + selectedReportPropObj.ObjKy.ToString();
                    param.ParamValue = selectedReportPropObj.ObjKy.ToString();
                }

                else if (string.Equals(ObjNm, "CNm", StringComparison.CurrentCultureIgnoreCase))
                {
                    //paramList.Add(new ReportParameter(ObjNm, CNm));
                    paramString      = paramString + "&" + ObjNm + "=" + CNm;
                    param.ParamValue = CNm;
                }
                else if (string.Equals(ObjNm, "UsrID", StringComparison.CurrentCultureIgnoreCase))
                {
                    //paramList.Add(new ReportParameter(ObjNm, UsrNm));
                    paramString      = paramString + "&" + ObjNm + "=" + UsrNm;
                    param.ParamValue = UsrNm;
                }

                else if (string.Equals(ObjNm, "RtpTitle", StringComparison.CurrentCultureIgnoreCase))
                {
                    //paramList.Add(new ReportParameter(ObjNm, selectedReportPropObj.ObjCaptn));
                    paramString      = paramString + "&" + ObjNm + "=" + selectedReportPropObj.ObjCaptn;
                    param.ParamValue = selectedReportPropObj.ObjCaptn;
                }
                else if (string.Equals(ObjNm, "RptTitle", StringComparison.CurrentCultureIgnoreCase))
                {
                    //paramList.Add(new ReportParameter(ObjNm, selectedReportPropObj.ObjCaptn));
                    paramString      = paramString + "&" + ObjNm + "=" + selectedReportPropObj.ObjCaptn;
                    param.ParamValue = selectedReportPropObj.ObjCaptn;
                }

                else if (ObjNm == "ServerName")
                {
                    //paramList.Add(new ReportParameter("ServerName", ServerName));
                    paramString      = paramString + "&ServerName=" + ServerName;
                    param.ParamValue = ServerName;
                }
                else if (ObjNm == "EnvironmentName")
                {
                    //paramList.Add(new ReportParameter("EnvironmentName", EnvironmentName));
                    paramString      = paramString + "&EnvironmentName=" + EnvironmentName;
                    param.ParamValue = EnvironmentName;
                }

                else if (ObjNm == "TrnKy")
                {
                    //paramList.Add(new ReportParameter(ObjNm, formOrdKy));
                    paramString      = paramString + "&" + ObjNm + "=" + formOrdKy;
                    param.ParamValue = formOrdKy;
                }
                else if (ObjNm == "OdrKy")
                {
                    //paramList.Add(new ReportParameter(ObjNm, formOrdKy));
                    paramString      = paramString + "&" + ObjNm + "=" + formOrdKy;
                    param.ParamValue = formOrdKy;
                }
                else if (ObjNm == "OrdKy")
                {
                    //paramList.Add(new ReportParameter(ObjNm, formOrdKy));
                    paramString      = paramString + "&" + ObjNm + "=" + formOrdKy;
                    param.ParamValue = formOrdKy;
                }
                else if (ObjNm == "FromTrnKy")
                {
                    //paramList.Add(new ReportParameter(ObjNm, formOrdKy));
                    paramString      = paramString + "&" + ObjNm + "=" + formOrdKy;
                    param.ParamValue = formOrdKy;
                }

                else if (ObjNm == "RptNm")
                {
                    //paramList.Add(new ReportParameter(ObjNm, selectedReportPropObj.ObjCaptn));
                    paramString      = paramString + "&" + ObjNm + "=" + selectedReportPropObj.ObjCaptn;
                    param.ParamValue = selectedReportPropObj.ObjCaptn;
                }

                else
                {
                    //if (ObjNm.EndsWith("Ky") || ObjNm.EndsWith("ky"))
                    //{
                    //    if (varNeededObjVal[ObjNm] == "")
                    //        varNeededObjVal[ObjNm] = 1;
                    //}
                    //else if (
                    //    ObjNm.EndsWith("Cd") ||
                    //    ObjNm.EndsWith("cd") ||
                    //    ObjNm.EndsWith("CD") ||
                    //    ObjNm.EndsWith("Nm") ||
                    //    ObjNm.EndsWith("nm") ||
                    //    ObjNm.EndsWith("NM"))
                    //{
                    //    if (varNeededObjVal[ObjNm] == "")
                    //        varNeededObjVal[ObjNm] = 1;
                    //}

                    //if (varNeededObjVal.ContainsKey(ObjNm))
                    //{
                    //    string paramObjNm = ObjNm;
                    //    if (ObjNm.StartsWith("datPic"))
                    //    {
                    //        paramObjNm = ObjNm.Replace("datPic", "");

                    //        string joinstring = "/";
                    //        string[] tempsplit = varNeededObjVal[ObjNm].ToString().Split('/');
                    //        varNeededObjVal[ObjNm] = tempsplit[2] + joinstring + tempsplit[1] + joinstring + tempsplit[0];
                    //    }
                    //    if (ObjNm.StartsWith("cmb"))
                    //        paramObjNm = ObjNm.Replace("cmb", "");
                    //    if (ObjNm.StartsWith("chckBox"))
                    //        paramObjNm = ObjNm.Replace("chckBox", "");

                    //    paramList.Add(new ReportParameter(paramObjNm, varNeededObjVal[ObjNm].ToString()));
                    //}
                }

                listParam.Add(param);
            }

            List <paramClass> listParamTemp = new List <paramClass>();

            listParamTemp = listParam;

            string sTargetURL = ReportServerUrl + "?" + selectedReportPropObj.ReportPath + "&rs:Command=Render&rs:format=PDF";

            sTargetURL = sTargetURL + paramString;

            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(sTargetURL);

            req.Credentials = new System.Net.NetworkCredential(
                _userName,
                _pasword);
            req.PreAuthenticate = true;

            HttpWebResponse HttpWResp = (HttpWebResponse)req.GetResponse();

            Stream str = HttpWResp.GetResponseStream();

            byte[] fileBytes = ReadFully(str);

            // Working code commentexd by VGSan
            //FileStream fs = new FileStream(@"C:\Invoice.pdf", FileMode.Create);
            //fs.Write(fileBytes, 0, fileBytes.Length);
            //fs.Close();

            HttpWResp.Close();

            return(fileBytes);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string formObjKy      = Request.QueryString["formObjKy"];
            string formOrdKy      = Request.QueryString["formOrdKy"];
            string ReptNo         = Request.QueryString["ReptNo"];
            string formObjCaption = Request.QueryString["formObjCaption"];

            if (!Page.IsPostBack)
            {
                List <paramClass> listParam = new List <paramClass>();
                try
                {
                    MyReportViewer.Visible = true;

                    string CKy   = HTNSession.CKy.ToString();
                    string UsrKy = HTNSession.UsrKy.ToString();

                    string UsrNm           = HTNSession.UsrId.ToString();
                    string CNm             = HTNSession.CNm.ToString();
                    string ServerName      = ConfigurationManager.AppSettings["ReportServerName"].ToString();
                    string EnvironmentName = HTNSession.Environment;

                    string ReportServerUrl = WebConfigurationManager.AppSettings["ReportpathforServer"];
                    string _userName       = ConfigurationManager.AppSettings["ReportServerUserName"];
                    string _pasword        = ConfigurationManager.AppSettings["ReportServerPwd"];

                    ApiOperation apiOpr = new ApiOperation();

                    List <ObjMasModel> selectedReportProp = apiOpr.UsrObjPrp_SelectWeb(
                        EnvironmentName, Convert.ToInt32(CKy), Convert.ToInt32(UsrKy), formObjKy, "ReportWeb", null);

                    ObjMasModel selectedReportPropObj = new ObjMasModel();

                    if (ReptNo == "1")
                    {
                        selectedReportPropObj = selectedReportProp.Where(obj => obj.ObjNm == "SourceReport").SingleOrDefault();
                    }
                    else
                    {
                        string dynmicObjNm = "SourceReport_" + ReptNo;
                        selectedReportPropObj = selectedReportProp.Where(obj => obj.ObjNm == dynmicObjNm).SingleOrDefault();
                    }

                    List <ObjMasModel> selectedReportParamProp = apiOpr.UsrObjPrp_SelectWeb(
                        EnvironmentName, Convert.ToInt32(CKy), Convert.ToInt32(UsrKy),
                        selectedReportPropObj.ObjKy.ToString(), "ReportParameter", null);

                    List <ObjMasModel> selectedReportPrameter = apiOpr.UsrObjPrp_SelectWeb(
                        EnvironmentName, Convert.ToInt32(CKy), Convert.ToInt32(UsrKy),
                        selectedReportParamProp[0].ObjKy.ToString(), null, null);


                    List <ReportParameter> paramList = new List <ReportParameter>();

                    foreach (ObjMasModel dynobj in selectedReportPrameter)
                    {
                        paramClass param = new paramClass();

                        string ObjNm = dynobj.ObjNm.ToString();

                        param.Paramname = ObjNm;

                        if (string.Equals(ObjNm, "CKy", StringComparison.CurrentCultureIgnoreCase))
                        {
                            paramList.Add(new ReportParameter(ObjNm, CKy));
                            param.ParamValue = CKy;
                        }
                        else if (string.Equals(ObjNm, "UsrKy", StringComparison.CurrentCultureIgnoreCase))
                        {
                            paramList.Add(new ReportParameter(ObjNm, UsrKy));
                            param.ParamValue = UsrKy;
                        }
                        else if (ObjNm == "ObjKy")
                        {
                            paramList.Add(new ReportParameter("ObjKy", selectedReportPropObj.ObjKy.ToString()));
                            param.ParamValue = selectedReportPropObj.ObjKy.ToString();
                        }

                        else if (string.Equals(ObjNm, "CNm", StringComparison.CurrentCultureIgnoreCase))
                        {
                            paramList.Add(new ReportParameter(ObjNm, CNm));
                            param.ParamValue = CNm;
                        }
                        else if (string.Equals(ObjNm, "UsrID", StringComparison.CurrentCultureIgnoreCase))
                        {
                            paramList.Add(new ReportParameter(ObjNm, UsrNm));
                            param.ParamValue = UsrNm;
                        }

                        else if (string.Equals(ObjNm, "RtpTitle", StringComparison.CurrentCultureIgnoreCase))
                        {
                            paramList.Add(new ReportParameter(ObjNm, selectedReportPropObj.ObjCaptn));
                            param.ParamValue = selectedReportPropObj.ObjCaptn;
                        }
                        else if (string.Equals(ObjNm, "RptTitle", StringComparison.CurrentCultureIgnoreCase))
                        {
                            paramList.Add(new ReportParameter(ObjNm, selectedReportPropObj.ObjCaptn));
                            param.ParamValue = selectedReportPropObj.ObjCaptn;
                        }

                        else if (ObjNm == "ServerName")
                        {
                            paramList.Add(new ReportParameter("ServerName", ServerName));
                            param.ParamValue = ServerName;
                        }
                        else if (ObjNm == "EnvironmentName")
                        {
                            paramList.Add(new ReportParameter("EnvironmentName", EnvironmentName));
                            param.ParamValue = EnvironmentName;
                        }

                        else if (ObjNm == "TrnKy")
                        {
                            paramList.Add(new ReportParameter(ObjNm, formOrdKy));
                            param.ParamValue = formOrdKy;
                        }
                        else if (ObjNm == "OdrKy")
                        {
                            paramList.Add(new ReportParameter(ObjNm, formOrdKy));
                            param.ParamValue = formOrdKy;
                        }
                        else if (ObjNm == "OrdKy")
                        {
                            paramList.Add(new ReportParameter(ObjNm, formOrdKy));
                            param.ParamValue = formOrdKy;
                        }
                        else if (ObjNm == "FromTrnKy")
                        {
                            paramList.Add(new ReportParameter(ObjNm, formOrdKy));
                            param.ParamValue = formOrdKy;
                        }

                        else if (ObjNm == "RptNm")
                        {
                            paramList.Add(new ReportParameter(ObjNm, selectedReportPropObj.ObjCaptn));
                            param.ParamValue = selectedReportPropObj.ObjCaptn;
                        }

                        else
                        {
                        }

                        listParam.Add(param);
                    }

                    List <paramClass> listParamTemp = new List <paramClass>();
                    listParamTemp = listParam;

                    MyReportViewer.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
                    MyReportViewer.ServerReport.ReportServerUrl         = new Uri(ReportServerUrl);
                    MyReportViewer.ServerReport.ReportServerCredentials = new ReportViewerCredentials(_userName, _pasword);
                    MyReportViewer.ServerReport.ReportPath = selectedReportPropObj.ReportPath;
                    MyReportViewer.ShowParameterPrompts    = false;
                    MyReportViewer.ServerReport.SetParameters(paramList);
                    MyReportViewer.ServerReport.Refresh();
                }
                catch (Exception ex)
                {
                    string errMsg = ex.Message.ToString();
                    throw new Exception(ex.Message.ToString());
                }
            }
        }
예제 #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string formObjKy      = Request.QueryString["formObjKy"];
            string formOrdKy      = Request.QueryString["formOrdKy"];
            string ReptNo         = Request.QueryString["ReptNo"];
            string formObjCaption = Request.QueryString["formObjCaption"];

            if (!Page.IsPostBack)
            {
                List <paramClass> listParam = new List <paramClass>();
                try
                {
                    ReportViewer1.Visible = true;


                    string CKy   = HTNSession.CKy.ToString();
                    string UsrKy = HTNSession.UsrKy.ToString();

                    string UsrNm           = HTNSession.UsrId.ToString();
                    string CNm             = HTNSession.CNm.ToString();
                    string EnvironmentName = HTNSession.Environment;


                    ApiOperation apiOpr = new ApiOperation();

                    List <ObjMasModel> selectedReportProp = apiOpr.UsrObjPrp_SelectWeb(EnvironmentName, Convert.ToInt32(CKy), Convert.ToInt32(UsrKy), formObjKy, "ReportWeb", null);

                    ObjMasModel selectedReportPropObj = new ObjMasModel();

                    if (ReptNo == "1")
                    {
                        selectedReportPropObj = selectedReportProp.Where(obj => obj.ObjNm == "SourceReport").SingleOrDefault();
                    }
                    else
                    {
                        string dynmicObjNm = "SourceReport_" + ReptNo;
                        selectedReportPropObj = selectedReportProp.Where(obj => obj.ObjNm == dynmicObjNm).SingleOrDefault();
                    }

                    List <ObjMasModel> selectedReportParamProp = apiOpr.UsrObjPrp_SelectWeb(EnvironmentName, Convert.ToInt32(CKy), Convert.ToInt32(UsrKy), selectedReportPropObj.ObjKy.ToString(), "ReportParameter", null);

                    List <ObjMasModel> selectedReportPrameter = apiOpr.UsrObjPrp_SelectWeb(EnvironmentName, Convert.ToInt32(CKy), Convert.ToInt32(UsrKy), selectedReportParamProp[0].ObjKy.ToString(), null, null);

                    var    uriReportSource = new Telerik.Reporting.UriReportSource();
                    string URL             = AppDomain.CurrentDomain.BaseDirectory + @"\Reports\TelericcSample\" + selectedReportProp[0].ReportPath;
                    foreach (ObjMasModel dynobj in selectedReportPrameter)
                    {
                        paramClass param = new paramClass();

                        string ObjNm = dynobj.ObjNm.ToString();

                        param.Paramname = ObjNm;

                        if (string.Equals(ObjNm, "CKy", StringComparison.CurrentCultureIgnoreCase))
                        {
                            uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter(ObjNm, Convert.ToInt32(CKy)));
                        }
                        else if (string.Equals(ObjNm, "UsrKy", StringComparison.CurrentCultureIgnoreCase))
                        {
                            uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter(ObjNm, Convert.ToInt32(UsrKy)));
                        }
                        else if (ObjNm == "ObjKy")
                        {
                            uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter(ObjNm, selectedReportPropObj.ObjKy.ToString()));
                        }

                        else if (string.Equals(ObjNm, "CNm", StringComparison.CurrentCultureIgnoreCase))
                        {
                            uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter(ObjNm, CNm));
                        }
                        else if (string.Equals(ObjNm, "UsrID", StringComparison.CurrentCultureIgnoreCase))
                        {
                            uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter(ObjNm, UsrNm));
                        }

                        else if (string.Equals(ObjNm, "RtpTitle", StringComparison.CurrentCultureIgnoreCase))
                        {
                            uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter(ObjNm, selectedReportPropObj.ObjCaptn));
                        }
                        else if (string.Equals(ObjNm, "RptTitle", StringComparison.CurrentCultureIgnoreCase))
                        {
                            uriReportSource.Parameters.Add(ObjNm, selectedReportPropObj.ObjCaptn);
                        }


                        else if (ObjNm == "EnvironmentName")
                        {
                            uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter(ObjNm, EnvironmentName));
                        }

                        else if (ObjNm == "TrnKy")
                        {
                            uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter(ObjNm, Convert.ToInt32(formOrdKy)));
                        }
                        else if (ObjNm == "OdrKy")
                        {
                            uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter(ObjNm, formOrdKy));
                        }
                        else if (ObjNm == "OrdKy")
                        {
                            uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter(ObjNm, formOrdKy));
                        }
                        else if (ObjNm == "FromTrnKy")
                        {
                            uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter(ObjNm, formOrdKy));
                        }

                        else if (ObjNm == "RptNm")
                        {
                            uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter(ObjNm, selectedReportPropObj.ObjCaptn));
                        }

                        else
                        {
                        }
                    }

                    uriReportSource.Uri                 = URL;
                    ReportViewer1.ReportSource          = uriReportSource;
                    ReportViewer1.ParametersAreaVisible = false;
                    ReportViewer1.ShowHistoryButtons    = false;
                    ReportViewer1.ShowParametersButton  = false;
                    ReportViewer1.RefreshReport();
                }
                catch (Exception ex)
                {
                    string errMsg = ex.Message.ToString();
                    throw new Exception(ex.Message.ToString());
                }
            }
        }