Esempio n. 1
0
        public static string CreateFiles(String QueryProcedure, String QueryParameter, string ReportFormatType, string BaseDirectoryPath = null)
        {
            string queryString = QueryProcedure + " " + QueryParameter;

            DataTable Dt = new DataTable();
            var       SubReportDataList = new List <DataTable>();

            String StrSubReportProcList;
            String ReportTitle;

            try
            {
                using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString.ToString()))
                {
                    SqlDataAdapter sqlDataAapter = new SqlDataAdapter(queryString.ToString(), sqlConnection);
                    sqlDataAapter.Fill(Dt);
                }



                if (Dt.Columns.Contains("SubReportProcList"))
                {
                    StrSubReportProcList = Dt.Rows[0]["SubReportProcList"].ToString();
                }
                else
                {
                    return("SubReportProcList Not Define");
                }


                if (Dt.Columns.Contains("ReportTitle"))
                {
                    ReportTitle = Dt.Rows[0]["ReportTitle"].ToString();
                }
                else
                {
                    return("ReportTitle Not Define");
                }


                if (StrSubReportProcList != "")
                {
                    string[] SubReportProcList = StrSubReportProcList.Split(new Char[] { ',' });


                    if (SubReportProcList.Length > 0)
                    {
                        SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString.ToString());

                        foreach (var SubReportProc in SubReportProcList)
                        {
                            String    query          = "Web." + SubReportProc;
                            DataTable SubReport1Data = new DataTable();


                            SqlDataAdapter sqlDataAapter1 = new SqlDataAdapter(query.ToString(), sqlConnection);
                            sqlDataAapter1.Fill(SubReport1Data);


                            SubReportDataList.Add(SubReport1Data);

                            SubReport1Data = null;
                        }
                    }
                }


                ReportGenerateService c = new ReportGenerateService();
                string mimetype         = "";
                string Filename         = GenerateDocument(c.ReportGenerate(Dt, out mimetype, ReportFormatType, null, SubReportDataList, BaseDirectoryPath), ReportTitle + "_" + DateTime.Now.ToString("dd-MMM-yyyy-HH_mm_ss"), mimetype);



                return(Filename);
            }



            catch (Exception ex)
            {
                return(null);
            }
        }
        public ActionResult DocumentPrint(String queryString, int DocumentId = 0, string ReportFileType = ReportFileTypeConstants.PDF)
        {
            var       SubReportDataList = new List <DataTable>();
            DataTable Dt = new DataTable();
            String    StrSubReportProcList;

            using (SqlConnection sqlConnection = new SqlConnection(connectionString))
            {
                SqlDataAdapter sqlDataAapter = new SqlDataAdapter(queryString.ToString(), sqlConnection);
                dsRep.EnforceConstraints = false;
                sqlDataAapter.Fill(Dt);
            }

            if (Dt.Columns.Contains("SubReportProcList"))
            {
                StrSubReportProcList = Dt.Rows[0]["SubReportProcList"].ToString();
            }
            else
            {
                ViewBag.Message = "SubReportProcList is not define.";
                return(View("Close"));
            }


            if (StrSubReportProcList != "")
            {
                //Dim mPartyItem_UidArr As String() = Split(DtTemp.Rows(I)("PartyItem_Uid"), "|")
                string[] SubReportProcList = StrSubReportProcList.Split(new Char[] { ',' });


                if (SubReportProcList.Length > 0)
                {
                    SqlConnection sqlConnection = new SqlConnection(connectionString);

                    foreach (var SubReportProc in SubReportProcList)
                    {
                        String    query          = "Web." + SubReportProc + " " + DocumentId.ToString();
                        DataTable SubReport1Data = new DataTable();


                        SqlDataAdapter sqlDataAapter1 = new SqlDataAdapter(query.ToString(), sqlConnection);
                        dsRep.EnforceConstraints = false;
                        sqlDataAapter1.Fill(SubReport1Data);


                        SubReportDataList.Add(SubReport1Data);

                        SubReport1Data = null;
                    }
                }
            }



            string mimtype;
            ReportGenerateService c = new ReportGenerateService();

            byte[] BAR;
            //BAR = c.ReportGenerate(Dt, out mimtype, ReportFileTypeConstants.PDF);
            BAR = c.ReportGenerate(Dt, out mimtype, ReportFileType, null, SubReportDataList);
            return(File(BAR, mimtype));
        }