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());
                }
            }
        }
Пример #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if ((!Page.IsPostBack))
            {
                List <paramClass> listParam = new List <paramClass>();
                try
                {
                    MyReportViewer.Visible = true;

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

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

                    string SelectedReportObjKy = Session["SelectedReportObjKy"].ToString();

                    string SelectedReportObjKyX = "SESSIONXREPORT";
                    //SelectedReportObjKy = Convert.ToInt32(SelectedReportObjKy) <= Int64.MaxValue * ((int)SelectedReportObjKyX[7]) ? SelectedReportObjKy.ToString() : "1278";

                    string ServerName                   = ConfigurationManager.AppSettings["ReportServerName"].ToString();
                    string EnvironmentName              = HTNSession.Environment;
                    string NeededReportParams           = Session["NeededReportParams"].ToString();
                    string NeededReportParamsFromObjMas = Session["NeededReportParamsFromObjMas"].ToString();


                    ApiOperation       apiOpr             = new ApiOperation();
                    List <ObjMasModel> selectedReportProp = apiOpr.ObjMas_SelectWeb(EnvironmentName, Convert.ToInt32(UsrKy), Convert.ToInt32(CKy), SelectedReportObjKy);

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

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

                    // EX : CKy, FrmDt, ToDt, BUKy, PrjKy, isHideZeroTrn, isStk, PFrmDt, PToDt

                    JavaScriptSerializer js = new JavaScriptSerializer();

                    dynamic dynNeededReportParams = js.Deserialize <dynamic>(NeededReportParams);
                    var     varNeededObjVal       = dynNeededReportParams as IDictionary <String, object>;

                    dynamic dynNeededReportParamsFromObjMas = js.Deserialize <dynamic>(NeededReportParamsFromObjMas);

                    foreach (dynamic dynobj in dynNeededReportParamsFromObjMas)
                    {
                        paramClass param = new paramClass();

                        var    varObj = dynobj as IDictionary <String, object>;
                        string ObjNm  = varObj["ObjNm"].ToString();

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

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

                        else if (string.Equals(ObjNm, "RtpTitle", StringComparison.CurrentCultureIgnoreCase))
                        {
                            param.ParamValue = selectedReportProp[0].ObjCaptn;
                            paramList.Add(new ReportParameter(ObjNm, selectedReportProp[0].ObjCaptn));
                        }
                        else if (string.Equals(ObjNm, "RptTitle", StringComparison.CurrentCultureIgnoreCase))
                        {
                            param.ParamValue = selectedReportProp[0].ObjCaptn;
                            paramList.Add(new ReportParameter(ObjNm, selectedReportProp[0].ObjCaptn));
                        }
                        else if (ObjNm == "ServerName")
                        {
                            param.ParamValue = ServerName;
                            paramList.Add(new ReportParameter("ServerName", ServerName));
                        }
                        else if (ObjNm == "EnvironmentName")
                        {
                            param.ParamValue = EnvironmentName;
                            paramList.Add(new ReportParameter("EnvironmentName", EnvironmentName));
                        }

                        else
                        {
                            if (varNeededObjVal.ContainsKey(ObjNm))
                            {
                                //**********    Default Setting If NULL : VgSan
                                #region Default Setting If NULL

                                if (ObjNm.EndsWith("Ky") || ObjNm.EndsWith("ky"))
                                {
                                    if (varNeededObjVal[ObjNm].ToString() == "")
                                    {
                                        varNeededObjVal[ObjNm] = 1;
                                    }
                                }
                                else if (
                                    ObjNm.EndsWith("Cd") ||
                                    ObjNm.EndsWith("cd") ||
                                    ObjNm.EndsWith("CD") ||
                                    ObjNm.EndsWith("cD") ||

                                    ObjNm.EndsWith("ID") ||
                                    ObjNm.EndsWith("Id") ||
                                    ObjNm.EndsWith("id") ||
                                    ObjNm.EndsWith("iD") ||

                                    ObjNm.EndsWith("Nm") ||
                                    ObjNm.EndsWith("nm") ||
                                    ObjNm.EndsWith("NM") ||
                                    ObjNm.EndsWith("nM"))
                                {
                                    if (varNeededObjVal[ObjNm].ToString() == "")
                                    {
                                        varNeededObjVal[ObjNm] = " ";
                                    }
                                }
                                else if (
                                    ObjNm.StartsWith("datPic"))
                                {
                                    if (varNeededObjVal[ObjNm].ToString() == "")
                                    {
                                        varNeededObjVal[ObjNm] = null;
                                    }
                                }
                                else if (
                                    ObjNm.StartsWith("numricBox"))
                                {
                                    if (varNeededObjVal[ObjNm].ToString() == "")
                                    {
                                        varNeededObjVal[ObjNm] = null;
                                    }
                                }

                                #endregion Default Setting If NULL

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

                                        string joinstring = "/";
                                        if (varNeededObjVal[ObjNm] != null)
                                        {
                                            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("cmFrmCdMas_"))
                                    {
                                        paramObjNm = ObjNm.Replace("cmFrmCdMas_", "");
                                    }
                                    if (ObjNm.StartsWith("chckBox"))
                                    {
                                        paramObjNm = ObjNm.Replace("chckBox", "");
                                    }
                                    if (ObjNm.StartsWith("numricBox"))
                                    {
                                        paramObjNm = ObjNm.Replace("numricBox", "");
                                    }
                                    if (ObjNm.StartsWith("textBox"))
                                    {
                                        paramObjNm = ObjNm.Replace("textBox", "");
                                    }

                                    if (varNeededObjVal[ObjNm] != null)
                                    {
                                        param.ParamValue = varNeededObjVal[ObjNm].ToString();
                                        paramList.Add(new ReportParameter(paramObjNm, varNeededObjVal[ObjNm].ToString()));
                                    }


                                    param.Paramname = paramObjNm;
                                }
                            }
                            else
                            {
                                string paramObjNm = ObjNm;

                                if (ObjNm.StartsWith("cmb"))
                                {
                                    paramObjNm = ObjNm.Replace("cmb", "");
                                }
                                if (ObjNm.StartsWith("cmFrmCdMas_"))
                                {
                                    paramObjNm = ObjNm.Replace("cmFrmCdMas_", "");
                                }
                                if (ObjNm.StartsWith("chckBox"))
                                {
                                    paramObjNm = ObjNm.Replace("chckBox", "");
                                }
                                if (ObjNm.StartsWith("datPic"))
                                {
                                    paramObjNm = ObjNm.Replace("datPic", "");
                                }
                                if (ObjNm.StartsWith("numricBox"))
                                {
                                    paramObjNm = ObjNm.Replace("numricBox", "");
                                }
                                if (ObjNm.StartsWith("textBox"))
                                {
                                    paramObjNm = ObjNm.Replace("textBox", "");
                                }


                                //**********    Default Setting If NULL : VgSan
                                #region Default Setting If NULL

                                if (ObjNm.EndsWith("Ky") || ObjNm.EndsWith("ky"))
                                {
                                    param.ParamValue = "1";
                                    paramList.Add(new ReportParameter(paramObjNm, "1"));
                                }
                                else if (
                                    ObjNm.EndsWith("Cd") ||
                                    ObjNm.EndsWith("cd") ||
                                    ObjNm.EndsWith("CD") ||
                                    ObjNm.EndsWith("cD") ||

                                    ObjNm.EndsWith("ID") ||
                                    ObjNm.EndsWith("Id") ||
                                    ObjNm.EndsWith("id") ||
                                    ObjNm.EndsWith("iD") ||

                                    ObjNm.EndsWith("Nm") ||
                                    ObjNm.EndsWith("nm") ||
                                    ObjNm.EndsWith("NM") ||
                                    ObjNm.EndsWith("nM"))
                                {
                                    param.ParamValue = " ";
                                    paramList.Add(new ReportParameter(paramObjNm, " "));
                                }
                                else if (
                                    ObjNm.StartsWith("datPic"))
                                {
                                    param.ParamValue = null;
                                    paramList.Add(new ReportParameter(paramObjNm, string.Empty));
                                }
                                else if (
                                    ObjNm.StartsWith("numricBox"))
                                {
                                    param.ParamValue = null;
                                    //paramList.Add(new ReportParameter(paramObjNm, null));
                                }

                                #endregion Default Setting If NULL

                                param.Paramname = paramObjNm;
                            }
                        }
                        listParam.Add(param);
                    }

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

                    MyReportViewer.ProcessingMode = ProcessingMode.Remote;
                    MyReportViewer.ServerReport.ReportServerUrl         = new Uri(ReportServerUrl);
                    MyReportViewer.ServerReport.ReportServerCredentials = new ReportViewerCredentials(_userName, _pasword);
                    MyReportViewer.ServerReport.ReportPath = selectedReportProp[0].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());
                }
            }
        }