Пример #1
0
        public int Replace(CUSTOMRP.Model.WORDTEMPLATE model)
        {
            int result = 0;

            if ((model.WordTemplateID != 0) && (dal.GetModel(model.ModifyUser, model.WordTemplateID, model.ModifyUser) != null))
            {
                if (dal.Update(model))
                {
                    result = model.WordTemplateID;
                }
            }
            else
            {
                result = dal.Add(model);
            }

            return(result);
        }
Пример #2
0
        protected void Word(int rpid, ReportCriteria[] rpParam = null, CUSTOMRP.BLL.AppHelper.QueryParamsObject[] qpParam = null)
        {
            CUSTOMRP.Model.REPORT myReport = WebHelper.bllReport.GetModel(me.ID, rpid);
            string WordFilePath            = null;

            if ((myReport.WordFile != null) && (File.Exists(g_Config["WordTemplatePath"] + myReport.WordFile.WordFileName)))
            {
                WordFilePath = myReport.WordFile.WordFileName;
            }
            else
            {
                CUSTOMRP.Model.WORDTEMPLATE template = WebHelper.bllWORDTEMPLATE.GetModelByReportID(me.ID, myReport.ID, me.ID);
                if (File.Exists(g_Config["WordTemplatePath"] + template.TemplateFileName))
                {
                    WordFilePath = template.TemplateFileName;
                }
                else
                {
                    Context.Response.Write(String.Format("<script type=\"text/javascript\">alert(\"{0}\");</script>",
                                                         AppNum.ErrorMsg.filenotfounderror));
                    Context.Response.End();
                    return;
                }
            }

            CUSTOMRP.Model.SOURCEVIEW mySV = WebHelper.bllSOURCEVIEW.GetModel(me.ID, myReport.SVID);
            string[] colnames;

            switch (mySV.SourceType)
            {
            case CUSTOMRP.Model.SOURCEVIEW.SourceViewType.StoredProc:
            {
                colnames = CUSTOMRP.BLL.AppHelper.GetColumnNamesForStoredProc(me.ID, me.DatabaseNAME, mySV.TBLVIEWNAME);
            }
            break;

            default:
            {
                colnames = CUSTOMRP.BLL.AppHelper.GetColumnNamesForTblView(me.ID, me.DatabaseNAME, mySV.TBLVIEWNAME);
            }
            break;
            }

            //just print .no need save to database.
            List <string> rpcr     = new List <string>();
            List <string> comments = new List <string>();
            List <string> avgs     = new List <string>();
            List <string> sums     = new List <string>();
            List <string> groups   = new List <string>();
            List <string> subtotal = new List <string>();
            List <string> subavg   = new List <string>();
            List <string> subcount = new List <string>();
            List <string> count    = new List <string>();

            //v1.2.0 - Cheong - 2016/07/04 - Add option to hide duplicate items
            //DataTable dt = CUSTOMRP.BLL.AppHelper.getDataForReport(ref comments, ref avgs, ref sums, ref groups, ref subtotal, ref subavg, ref subcount, ref count, me, rpid, true, rpParam);
            DataTable dt = CUSTOMRP.BLL.AppHelper.getDataForReport(me.ID, ref comments, ref avgs, ref sums, ref groups, ref subtotal, ref subavg, ref subcount, ref count, me,
                                                                   rpid, myReport.fHideDuplicate, rpParam, QueryParamsToSqlParams(qpParam));

            this.p_fSuppressRender = true;

            string path             = g_Config["WordTemplatePath"] + WordFilePath;
            string downloadFilename = myReport.REPORTNAME.Replace(' ', '_') + ".docx";

            // Not calling downloadfile because this function need not write on disk
            using (MemoryStream filestream = MailMerge.PerformMailMergeFromTemplate(path, dt, colnames))
            {
                Context.Response.ContentType = "application/octet-stream";
                //Context.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + downloadFilename + "\"");
                Context.Response.AddHeader("Content-Disposition", String.Format("attachment; filename=\"{0}\"; filename*=utf-8''{1}", downloadFilename, HttpUtility.UrlPathEncode(downloadFilename)));
                Context.Response.AddHeader("Content-Length", filestream.Length.ToString());
                byte[] fileBuffer = new byte[filestream.Length];
                filestream.Read(fileBuffer, 0, (int)filestream.Length);
                //CA2202
                //filestream.Close();
                Context.Response.BinaryWrite(fileBuffer);
                Context.Response.End();
            }
        }
Пример #3
0
        //run
        protected void btnPrint_Click(object sender, EventArgs e)
        {
            string WordFilePath     = null;
            string downloadFilename = null;

            if ((myReport != null) && (myReport.WordFile != null) && (File.Exists(g_Config["WordTemplatePath"] + myReport.WordFile.WordFileName)))
            {
                WordFilePath     = myReport.WordFile.WordFileName;
                downloadFilename = myReport.WordFile.OrigFileName;
            }
            else
            {
                CUSTOMRP.Model.WORDTEMPLATE template = WebHelper.bllWORDTEMPLATE.GetModelByReportID(me.ID, myReport.ID, me.ID);
                if (template != null)
                {
                    if (File.Exists(g_Config["WordTemplatePath"] + template.TemplateFileName))
                    {
                        WordFilePath     = template.TemplateFileName;
                        downloadFilename = myReport.RPTITLE + ".docx";
                    }
                }
            }

            if (WordFilePath == null)
            {
                Response.Write(String.Format("<script type=\"text/javascript\">alert(\"{0}\")</script>",
                                             AppNum.ErrorMsg.filenotfounderror));
                return;
            }

            string strSqlColumn, strSqlPlus, strSqlCriteria, strSqlSortOn;

            getSql(ref rpcr, out strSqlColumn, out strSqlCriteria, out strSqlPlus, out strSqlSortOn);

            if (String.IsNullOrWhiteSpace(strSqlColumn))
            {
                #region Get Column Names

                string[] colnames            = null;
                CUSTOMRP.Model.SOURCEVIEW sv = WebHelper.bllSOURCEVIEW.GetModel(me.ID, myReport.SVID);
                List <CUSTOMRP.Model.SOURCEVIEWCOLUMN> svc = WebHelper.bllSOURCEVIEWCOLUMN.GetModelsForSourceView(me.ID, sv.ID, true).OrderBy(x => x.DisplayName).ToList();

                switch (sv.SourceType)
                {
                case CUSTOMRP.Model.SOURCEVIEW.SourceViewType.View:
                case CUSTOMRP.Model.SOURCEVIEW.SourceViewType.Table:
                {
                    try
                    {
                        columninfos = CUSTOMRP.BLL.AppHelper.GetColumnInfoForTblView(me.ID, me.DatabaseNAME, sv.TBLVIEWNAME);
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex.ToString());
                        columninfos             = new List <CUSTOMRP.Model.ColumnInfo>();
                        this.lblJavascript.Text = String.Format("<script type=\"text/javascript\">alert('Error in retrieving columns for [{0}]. Please check view defination.');</script>", sv.TBLVIEWNAME);
                    }
                    if (svc == null)
                    {
                        colnames = CUSTOMRP.BLL.AppHelper.GetColumnNamesForTblView(me.ID, me.DatabaseNAME, sv.TBLVIEWNAME);
                        // Filter result to only columns that is requested
                        columninfos = columninfos.Where(x => colnames.Contains(x.ColName)).ToList();
                    }
                }
                break;

                case CUSTOMRP.Model.SOURCEVIEW.SourceViewType.StoredProc:
                {
                    try
                    {
                        columninfos = CUSTOMRP.BLL.AppHelper.GetColumnInfoForStoredProc(me.ID, me.DatabaseNAME, sv.ID);
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex.ToString());
                        columninfos             = new List <CUSTOMRP.Model.ColumnInfo>();
                        this.lblJavascript.Text = String.Format("<script type=\"text/javascript\">alert('Error in retrieving columns for [{0}]. Please check stored proc defination.');</script>", sv.TBLVIEWNAME);
                    }
                    if (svc == null)
                    {
                        colnames = CUSTOMRP.BLL.AppHelper.GetColumnNamesForStoredProc(me.ID, me.DatabaseNAME, sv.TBLVIEWNAME);
                        // Filter result to only columns that is requested
                        columninfos = columninfos.Where(x => colnames.Contains(x.ColName)).ToList();
                    }
                }
                break;
                }

                if (svc.Count == 0)
                {
                    // do sorting
                    columninfos = columninfos.OrderBy(p => p.ColName).ToList();
                }
                else
                {
                    columninfos = (from c in columninfos
                                   join s in svc.Where(x => x.ColumnType == CUSTOMRP.Model.SOURCEVIEWCOLUMN.ColumnTypes.Normal) on c.ColName equals s.COLUMNNAME into lefts
                                   from s in lefts.DefaultIfEmpty()
                                   where (s == null || !s.HIDDEN)
                                   orderby s.DisplayName, c.ColName
                                   select new CUSTOMRP.Model.ColumnInfo()
                    {
                        ColName = c.ColName,
                        DisplayName = (s == null || String.IsNullOrEmpty(s.DISPLAYNAME)) ? c.ColName : s.DISPLAYNAME,                // no need to show actual column name here if DisplayName is supplied
                        DataType = c.DataType,
                    }).ToList();
                }

                strSqlColumn = String.Join(",", columninfos.Select(x => "[" + x.ColName + "]").ToArray());

                #endregion
            }

            if (strSqlColumn != "")
            {
                var sqlParams_queryParams = new List <SqlParameter>();
                foreach (var x in container.queryParams)
                {
                    switch (x.SqlType)
                    {
                    case "bit":
                        sqlParams_queryParams.Add(new SqlParameter()
                        {
                            ParameterName = "@QueryParam_" + x.ParamName, SqlDbType = SqlDbType.Bit, Value = int.Parse(x.Value)
                        });
                        break;

                    case "int":
                        sqlParams_queryParams.Add(new SqlParameter()
                        {
                            ParameterName = "@QueryParam_" + x.ParamName, SqlDbType = SqlDbType.Int, Value = int.Parse(x.Value)
                        });
                        break;

                    case "date":
                        sqlParams_queryParams.Add(new SqlParameter()
                        {
                            ParameterName = "@QueryParam_" + x.ParamName, SqlDbType = SqlDbType.Date, Value = x.Value
                        });
                        break;

                    case "datetime":
                        sqlParams_queryParams.Add(new SqlParameter()
                        {
                            ParameterName = "@QueryParam_" + x.ParamName, SqlDbType = SqlDbType.DateTime, Value = x.Value
                        });
                        break;

                    case "varchar":
                        sqlParams_queryParams.Add(new SqlParameter()
                        {
                            ParameterName = "@QueryParam_" + x.ParamName, Size = -1, SqlDbType = SqlDbType.VarChar, Value = x.Value
                        });
                        break;

                    case "nvarchar":
                        sqlParams_queryParams.Add(new SqlParameter()
                        {
                            ParameterName = "@QueryParam_" + x.ParamName, Size = -1, SqlDbType = SqlDbType.NVarChar, Value = x.Value
                        });
                        break;
                    }
                }

                this.rpdt = CUSTOMRP.BLL.AppHelper.getDataForReport(me.ID, myReport.SVID, me.DatabaseNAME, strSqlColumn, strSqlPlus, strSqlCriteria, strSqlSortOn, myReport.fHideDuplicate, sqlParams_queryParams);

                if (rpdt != null)
                {
                    if (container.Format == 1)
                    {
                        Server.Transfer("htmlexport.aspx?active=html", true);
                    }
                    else if (container.Format == 0)
                    {
                        string path     = g_Config["WordTemplatePath"] + WordFilePath;
                        string fileName = container.ReportName + ".docx";

                        using (MemoryStream filestream = MailMerge.PerformMailMergeFromTemplate(path, rpdt, columninfos.Select(x => x.DisplayName).ToArray()))
                        {
                            Context.Response.ContentType = "application/octet-stream";
                            //Context.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + downloadFilename + "\"");
                            Context.Response.AddHeader("Content-Disposition", String.Format("attachment; filename=\"{0}\"; filename*=utf-8''{1}", downloadFilename, HttpUtility.UrlPathEncode(downloadFilename)));
                            Context.Response.AddHeader("Content-Length", filestream.Length.ToString());
                            byte[] fileBuffer = new byte[filestream.Length];
                            filestream.Read(fileBuffer, 0, (int)filestream.Length);
                            //CA2202
                            //filestream.Close();
                            Context.Response.BinaryWrite(fileBuffer);
                            Context.Response.End();
                        }
                    }
                }
                else
                {
                    this.lblJavascript.Text = String.Format("<script type=\"text/javascript\">alert(\"{0}\");</script>", "Empty data!");
                }
            }
            else
            {
                this.lblJavascript.Text = String.Format("<script type=\"text/javascript\">alert(\"{0}\");</script>", "Zero Column,please check!");
            }
        }