Beispiel #1
0
        public CUSTOMRP.Model.SOURCEVIEW GetModelByQueryName(int UserID, string TBLVIEWNAME, int DATABASEID)
        {
            CUSTOMRP.Model.SOURCEVIEW result = null;
            StringBuilder             strSql = new StringBuilder();

            strSql.Append("select top 1 ID,SOURCEVIEWNAME,DATABASEID,SOURCETYPE,TBLVIEWNAME,AUDODATE,VIEWLEVEL,[DESC],FORMATTYPE from SOURCEVIEW ");
            strSql.Append(" where TBLVIEWNAME = @TBLVIEWNAME AND DATABASEID = @DATABASEID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@TBLVIEWNAME", TBLVIEWNAME),
                new SqlParameter("@DATABASEID",  DATABASEID),
            };

            CUSTOMRP.Model.SOURCEVIEW model = new CUSTOMRP.Model.SOURCEVIEW();
            DataSet ds = DbHelperSQL.Query(UserID, strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                result = DataRowToModel(ds.Tables[0].Rows[0]);
            }

            if (result != null)
            {
                DAL.WORDTEMPLATE dalWT = new DAL.WORDTEMPLATE();
                result.WordTemplate = dalWT.GetModelBySVID(UserID, result.ID, -1);
            }

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(int UserID, CUSTOMRP.Model.SOURCEVIEW model)
        {
            Model.SOURCEVIEW original = GetModel(UserID, model.ID);

            StringBuilder strSql = new StringBuilder();

            strSql.Append("update SOURCEVIEW set ");
            strSql.Append("SOURCEVIEWNAME=@SOURCEVIEWNAME,");
            strSql.Append("DATABASEID=@DATABASEID,");
            strSql.Append("SOURCETYPE=@SOURCETYPE,");
            strSql.Append("TBLVIEWNAME=@TBLVIEWNAME,");
            strSql.Append("AUDODATE=@AUDODATE,");
            strSql.Append("VIEWLEVEL=@VIEWLEVEL,");
            strSql.Append("[DESC]=@DESC,");
            strSql.Append("FORMATTYPE=@FORMATTYPE");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@SOURCEVIEWNAME", SqlDbType.NVarChar,   50),
                new SqlParameter("@DATABASEID",     SqlDbType.Int,         4),
                new SqlParameter("@SOURCETYPE",     SqlDbType.Int,         4),
                new SqlParameter("@TBLVIEWNAME",    SqlDbType.NVarChar,  128),
                new SqlParameter("@AUDODATE",       SqlDbType.DateTime),
                new SqlParameter("@VIEWLEVEL",      SqlDbType.Decimal,     9),
                new SqlParameter("@DESC",           SqlDbType.NVarChar,   50),
                new SqlParameter("@FORMATTYPE",     SqlDbType.Int,         4),
                new SqlParameter("@ID",             SqlDbType.Int, 4)
            };
            parameters[0].Value = model.SOURCEVIEWNAME;
            parameters[1].Value = model.DATABASEID;
            parameters[2].Value = model.SOURCETYPE;
            parameters[3].Value = model.TBLVIEWNAME;
            parameters[4].Value = model.AUDODATE;
            parameters[5].Value = model.VIEWLEVEL;
            parameters[6].Value = model.DESC;
            parameters[7].Value = model.FORMATTYPE;
            parameters[8].Value = model.ID;

            int rows = DbHelperSQL.ExecuteSql(UserID, strSql.ToString(), parameters);

            if (rows > 0)
            {
                Model.AUDITLOG auditobj = model.GetAuditLogObject(original);
                auditobj.UserID      = UserID;
                auditobj.CreateDate  = DateTime.Now;
                auditobj.MessageType = Model.AUDITLOG.Severity.Audit;
                auditobj.ModuleName  = "DAL.SOURCEVIEW.Update";
                auditobj.Message     = String.Format(AppNum.AuditMessage.SourceViewUpdateSuccess, model.ID);

                AUDITLOG.Add(auditobj);

                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(int UserID, CUSTOMRP.Model.SOURCEVIEW model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into SOURCEVIEW(");
            strSql.Append("SOURCEVIEWNAME,DATABASEID,SOURCETYPE,TBLVIEWNAME,AUDODATE,VIEWLEVEL,[DESC],FORMATTYPE)");
            strSql.Append(" values (");
            strSql.Append("@SOURCEVIEWNAME,@DATABASEID,@SOURCETYPE,@TBLVIEWNAME,@AUDODATE,@VIEWLEVEL,@DESC,@FORMATTYPE)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@SOURCEVIEWNAME", SqlDbType.NVarChar,   50),
                new SqlParameter("@DATABASEID",     SqlDbType.Int,         4),
                new SqlParameter("@SOURCETYPE",     SqlDbType.Int,         4),
                new SqlParameter("@TBLVIEWNAME",    SqlDbType.NVarChar,  128),
                new SqlParameter("@AUDODATE",       SqlDbType.DateTime),
                new SqlParameter("@VIEWLEVEL",      SqlDbType.Decimal,     9),
                new SqlParameter("@DESC",           SqlDbType.NVarChar,   50),
                new SqlParameter("@FORMATTYPE",     SqlDbType.Int, 4)
            };
            parameters[0].Value = model.SOURCEVIEWNAME;
            parameters[1].Value = model.DATABASEID;
            parameters[2].Value = model.SOURCETYPE;
            parameters[3].Value = model.TBLVIEWNAME;
            parameters[4].Value = model.AUDODATE;
            parameters[5].Value = model.VIEWLEVEL;
            parameters[6].Value = model.DESC;
            parameters[7].Value = model.FORMATTYPE;

            object obj = DbHelperSQL.GetSingle(UserID, strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                model.ID = Convert.ToInt32(obj);

                Model.AUDITLOG auditobj = model.GetAuditLogObject(null);
                auditobj.UserID      = UserID;
                auditobj.CreateDate  = DateTime.Now;
                auditobj.MessageType = Model.AUDITLOG.Severity.Audit;
                auditobj.ModuleName  = "DAL.SOURCEVIEW.Add";
                auditobj.Message     = String.Format(AppNum.AuditMessage.SourceViewInsertSuccess, model.ID);

                AUDITLOG.Add(auditobj);

                return(model.ID);
            }
        }
Beispiel #4
0
        private void FillPageHeaderUI()
        {
            this.FillddlQueryNames();

            DataTable mydtCategory = WebHelper.bllcategory.GetList(me.ID, 100000, "DATABASEID='" + me.DatabaseID + "'", "NAME").Tables[0];

            this.ddlCategory.DataSource     = mydtCategory;
            this.ddlCategory.DataTextField  = "NAME";
            this.ddlCategory.DataValueField = "ID";
            this.ddlCategory.DataBind();

            //v1.2.0 - Cheong - 2016/06/23 - Do not allow people to select report groups that they can't see
            //DataTable mydtRPGROUP = WebHelper.bllrpGroup.GetList(100000, "DATABASEID='" + me.DatabaseID + "'", "NAME").Tables[0];
            DataTable mydtRPGROUP = WebHelper.bllrpGroup.GetList(me.ID, 100000, "DATABASEID='" + me.DatabaseID + "' AND ID IN (" + me.ReportGroup + ")", "NAME").Tables[0];

            this.ddlReportGroup.DataSource     = mydtRPGROUP;
            this.ddlReportGroup.DataTextField  = "NAME";
            this.ddlReportGroup.DataValueField = "ID";
            this.ddlReportGroup.DataBind();

            CUSTOMRP.BLL.SOURCEVIEW   bllsv = new CUSTOMRP.BLL.SOURCEVIEW();
            CUSTOMRP.Model.SOURCEVIEW sv    = null;
            if (myReport != null)
            {
                sv = bllsv.GetModel(me.ID, myReport.SVID);
                this.txtReportName.Text         = myReport.REPORTNAME;
                this.txtReportTitle.Text        = myReport.RPTITLE;
                this.ddlFormat.SelectedValue    = myReport.DEFAULTFORMAT.ToString();
                this.ddlQueryName.SelectedValue = myReport.SVID.ToString();
                //v1.2.0 - Cheong - 2016/07/04 - Add option to hide duplicate items
                this.chkHideDuplicate.Checked     = myReport.fHideDuplicate;
                this.ddlCategory.SelectedValue    = myReport.CATEGORY.ToString();
                this.ddlReportGroup.SelectedValue = myReport.REPORTGROUPLIST.ToString();
                //this.ddlPrintType.SelectedValue = myReport.EXTENDFIELD.ToString().Split(',')[0].ToString();
            }

            if (this.ddlQueryName.SelectedItem != null)
            {
                int svid = this.ddlQueryNameChange();
                sv = WebHelper.bllSOURCEVIEW.GetModel(me.ID, svid);
            }
            else
            {
                this.ddlQueryName.Items.Add(new ListItem("N/A", ""));
            }
        }
Beispiel #5
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public CUSTOMRP.Model.SOURCEVIEW DataRowToModel(DataRow row)
 {
     CUSTOMRP.Model.SOURCEVIEW model = new CUSTOMRP.Model.SOURCEVIEW();
     if (row != null)
     {
         if (row["ID"] != null && row["ID"].ToString() != "")
         {
             model.ID = Int32.Parse(row["ID"].ToString());
         }
         if (row["SOURCEVIEWNAME"] != null)
         {
             model.SOURCEVIEWNAME = row["SOURCEVIEWNAME"].ToString();
         }
         if (row["DATABASEID"] != null && row["DATABASEID"].ToString() != "")
         {
             model.DATABASEID = Int32.Parse(row["DATABASEID"].ToString());
         }
         if (row["SOURCETYPE"] != null && row["SOURCETYPE"].ToString() != "")
         {
             model.SOURCETYPE = Int32.Parse(row["SOURCETYPE"].ToString());
         }
         if (row["TBLVIEWNAME"] != null)
         {
             model.TBLVIEWNAME = row["TBLVIEWNAME"].ToString();
         }
         if (row["AUDODATE"] != null && row["AUDODATE"].ToString() != "")
         {
             model.AUDODATE = DateTime.Parse(row["AUDODATE"].ToString());
         }
         if (row["VIEWLEVEL"] != null && row["VIEWLEVEL"].ToString() != "")
         {
             model.VIEWLEVEL = Decimal.Parse(row["VIEWLEVEL"].ToString());
         }
         if (row["DESC"] != null)
         {
             model.DESC = row["DESC"].ToString();
         }
         if (row["FORMATTYPE"] != null && row["FORMATTYPE"].ToString() != "")
         {
             model.FORMATTYPE = Int32.Parse(row["FORMATTYPE"].ToString());
         }
     }
     return(model);
 }
Beispiel #6
0
        private bool p_fSuppressRender = false;     // Whether to render page contents

        #region Event Handlers

        protected void Page_Init(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Request.QueryString["id"]) == false)
            {
                if (me.checkUserGroupRight(CUSTOMRP.Model.APPModuleID.usergroupright_query, "Modify", me.LoginID) == false)
                {
                    Common.JScript.AlertAndRedirect(AppNum.ErrorMsg.accesserror, "ViewList.aspx");
                    Response.End();
                }

                if (me.checkUserGroupRight(CUSTOMRP.Model.APPModuleID.usergroupright_query, "Delete", me.LoginID))
                {
                    this.btnDelete.Visible = true;
                }

                if (!IsPostBack)
                {
                    int id = 0;

                    if (Request.QueryString["id"] != null)
                    {
                        if (!Int32.TryParse(Request.QueryString["id"], out id))
                        {
                            Common.JScript.AlertAndRedirect(AppNum.ErrorMsg.parameter_error, "ViewList.aspx");
                            Response.End();
                            return;
                        }

                        myView = WebHelper.bllSOURCEVIEW.GetModel(me.ID, id);
                        if (myView == null)
                        {
                            Session.Remove(strSessionViewNew_myView);
                            Session.Remove(strSessionViewNew_myColumns);
                            Common.JScript.AlertAndRedirect(AppNum.ErrorMsg.parameter_error, "ViewList.aspx");
                            Response.End();
                        }
                        else
                        {
                            Session[strSessionViewNew_myView] = myView;

                            myColumns = WebHelper.bllSOURCEVIEWCOLUMN.GetModelsForSourceView(me.ID, id, true).OrderBy(x => x.COLUMNNAME).ToList();
                            Session[strSessionViewNew_myColumns] = myColumns;
                        }
                    }
                }
                else
                {
                    myView = (CUSTOMRP.Model.SOURCEVIEW)Session[strSessionViewNew_myView];
                }
            }
            else
            {
                if (!IsPostBack)
                {
                    Session.Remove(strSessionViewNew_myView);
                    Session.Remove(strSessionViewNew_myColumns);
                    Session.Remove(strSessionViewNew_strAllColumns);
                }

                if (me.checkUserGroupRight(CUSTOMRP.Model.APPModuleID.usergroupright_query, "Add", me.LoginID) == false)
                {
                    Common.JScript.AlertAndRedirect(AppNum.ErrorMsg.accesserror, "ViewList.aspx");
                    Response.End();
                }
            }

            //?????
            //v1.8.2 Ben 2018.02.22 - Add to store actual columns name from DB - Begin
            if (!IsPostBack)
            {
                Session.Remove(strSessionViewNew_strAllColumns);
            }
            //v1.8.2 Ben 2018.02.22 - Add to store actual columns name from DB - End

            myColumns  = (List <CUSTOMRP.Model.SOURCEVIEWCOLUMN>)Session[strSessionViewNew_myColumns] ?? new List <CUSTOMRP.Model.SOURCEVIEWCOLUMN>();
            dbViewList = (List <TblView>)Session[strSessionViewNew_dbViewList] ?? new List <TblView>();
        }
Beispiel #7
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string  name        = this.txtuid.Text.Trim();
            string  description = this.txtp1.Text.Trim();
            string  tblviewname = this.ddlTblViewName.SelectedValue;
            int     sourcetype  = dbViewList.Where(x => x.TblViewName == tblviewname).First().SourceType;
            decimal level       = Decimal.Parse(this.ddlLevel.SelectedValue);

            List <int> kv = new List <int>();

            if (this.cbExcel.Checked)
            {
                kv.Add(0);
            }
            if (this.cbWord.Checked)
            {
                kv.Add(1);
            }
            long kvs = Common.Utils.getSum2N(kv.ToArray());

            if (myView != null)
            {
                myView.SOURCEVIEWNAME = name;
                myView.SOURCETYPE     = sourcetype;
                myView.TBLVIEWNAME    = tblviewname;
                myView.VIEWLEVEL      = level;
                myView.DESC           = description;
                myView.FORMATTYPE     = (int)kvs;
                WebHelper.bllSOURCEVIEW.Update(me.ID, myView);

                //v1.8.2 Ben 2018.02.22 - Remove columns not in actual - Begin

                /*
                 * //temp not delete
                 * if (Session[strSessionViewNew_strAllColumns] != null)
                 * {
                 *  var strAllColumns = (string[])Session[strSessionViewNew_strAllColumns];
                 *  //var delColumns= myColumns.Except(myColumns.Where(x => strAllColumns.Contains(x.COLUMNNAME))).ToArray();
                 *  //WebHelper.bllSOURCEVIEWCOLUMN.DeleteModelList(me.ID, delColumns);
                 *  //myColumns = myColumns.Where(x => strAllColumns.Contains(x.COLUMNNAME)).ToList();
                 *  / *
                 *  for (int i = 0; i < strAllColumns.Length; i++)
                 *  {
                 *      //Handle different same content but different case
                 *      if (myColumns.Any(x => x.COLUMNNAME.ToUpper() == strAllColumns[i].ToUpper() && x.COLUMNNAME != strAllColumns[i]))
                 *      {
                 *          myColumns.Where(x => x.COLUMNNAME.ToUpper() == strAllColumns[i].ToUpper()).ToList().ForEach(x => x.COLUMNNAME = strAllColumns[i]);
                 *      }
                 *  }
                 * /
                 * }
                 */
                //v1.8.2 Ben 2018.02.22 - Remove columns not in actual - End

                //v1.8.2 Ben 2018.02.26 - Handle same name but different case - Begin
                //Same name but different case is only because once saved but modified column name later
                //and hence 2 records: 1. column in DB having ID. 2. new row not having ID and your modified in UI is in here
                //so update the latest 1. by 2. and remove 2. here
                var PossibleDuplicatedColumns = myColumns.Where(x => x.ID == 0).ToList();
                myColumns = myColumns.Except(PossibleDuplicatedColumns).ToList();
                for (var i = 0; i < PossibleDuplicatedColumns.Count(); i++)
                {
                    var modColumns = myColumns.Where(x => x.COLUMNNAME.ToUpper() == PossibleDuplicatedColumns[i].COLUMNNAME.ToUpper());
                    if (modColumns.Any())
                    {
                        var modColumn = myColumns.Where(x => x.COLUMNNAME.ToUpper() == PossibleDuplicatedColumns[i].COLUMNNAME.ToUpper()).OrderByDescending(x => x.ID).FirstOrDefault();
                        modColumn.HIDDEN      = PossibleDuplicatedColumns[i].HIDDEN;
                        modColumn.COLUMNNAME  = PossibleDuplicatedColumns[i].COLUMNNAME;
                        modColumn.DISPLAYNAME = PossibleDuplicatedColumns[i].DISPLAYNAME;
                    }
                    else
                    {
                        myColumns.Add(PossibleDuplicatedColumns[i]);
                    }
                }

                //v1.8.2 Ben 2018.02.26 - Handle same name but different case - End

                foreach (CUSTOMRP.Model.SOURCEVIEWCOLUMN item in myColumns)
                {
                    item.SVID = myView.ID;
                }
                //WebHelper.bllSOURCEVIEWCOLUMN.DeleteForSourceView(myView.ID);
                //v1.7.0 Ben 2017.08.21 - Below will not update Hidden columns so new function to update
                //WebHelper.bllSOURCEVIEWCOLUMN.UpdateModelList(me.ID, myColumns.ToArray());
                WebHelper.bllSOURCEVIEWCOLUMN.UpdateModelList(me.ID, myColumns.ToArray(), true);
            }
            else
            {
                myView = new CUSTOMRP.Model.SOURCEVIEW();
                myView.SOURCEVIEWNAME = name;
                myView.DATABASEID     = Convert.ToInt32(me.DatabaseID);
                myView.SOURCETYPE     = sourcetype;
                myView.TBLVIEWNAME    = tblviewname;
                myView.AUDODATE       = DateTime.Now;
                myView.VIEWLEVEL      = level;
                myView.DESC           = description;
                myView.FORMATTYPE     = (int)kvs;
                myView.ID             = WebHelper.bllSOURCEVIEW.Add(me.ID, myView);
                foreach (CUSTOMRP.Model.SOURCEVIEWCOLUMN item in myColumns)
                {
                    item.SVID = myView.ID;
                }
                //WebHelper.bllSOURCEVIEWCOLUMN.DeleteForSourceView(myView.ID);
                //WebHelper.bllSOURCEVIEWCOLUMN.AddColList(myView.ID, selected_arr);
                //v1.7.0 Ben 2017.08.21 - Below will not update Hidden columns so new function to update
                //WebHelper.bllSOURCEVIEWCOLUMN.UpdateModelList(me.ID, myColumns.ToArray());
                WebHelper.bllSOURCEVIEWCOLUMN.UpdateModelList(me.ID, myColumns.ToArray(), true);
            }

            Session.Remove(strSessionViewNew_myView); //work done
            //v1.7.0 Ben 2017.08.21 - this session will store columns before update
            //temp ignore it
            //Session.Remove(strSessionViewNew_myColumns);
            Common.JScript.AlertAndRedirect(AppNum.ErrorMsg.success, "viewlist.aspx");
            Response.End();
        }
Beispiel #8
0
        protected void btnNext_Click(object sender, EventArgs e)
        {
            if (!this.ValidateParameters())
            {
                return;
            }

            CUSTOMRP.Model.REPORT            myReport    = null;
            List <CUSTOMRP.Model.ColumnInfo> columninfos = null;

            string path          = g_Config["WordTemplatePath"];
            string savedFileName = String.Empty;

            try
            {
                savedFileName = this.SaveTemplateFile();
            }
            catch
            {
                this.lblJavascript.Text = String.Format("<script type=\"text/javascript\">alert(\"{0}\");</script>", AppNum.ErrorMsg.uploadFailed);
                return;
            }

            string strReportName = this.txtReportName.Text.Trim();
            int    svID          = Convert.ToInt32(this.ddlQueryName.SelectedValue);

            #region Read CustomProps from file

            System.Collections.Specialized.NameValueCollection nvc = QueryReport.Code.MailMerge.ReadCustomPropsFromFile(path + savedFileName);
            if (String.IsNullOrWhiteSpace(strReportName))
            {
                strReportName = nvc["RptName"];
                if (strReportName != null)
                {
                    strReportName = strReportName.Trim();
                }
            }
            string strQueryName = nvc["QueryName"];
            if (!String.IsNullOrWhiteSpace(strQueryName))
            {
                CUSTOMRP.Model.SOURCEVIEW svFromFile = WebHelper.bllSOURCEVIEW.GetModelByQueryName(me.ID, strQueryName.Trim(), me.DatabaseID);
                svID = (svFromFile != null) ? svFromFile.ID : -1;
            }

            #endregion

            if (String.IsNullOrWhiteSpace(strReportName))
            {
                this.lblJavascript.Text = String.Format("<script type=\"text/javascript\">alert(\"{0}\");</script>",
                                                        String.Format(AppNum.ErrorMsg.fieldcannotbeempty, "Report Name"));
                return;
            }

            if (svID == -1)
            {
                this.lblJavascript.Text = String.Format("<script type=\"text/javascript\">alert(\"{0}\");</script>",
                                                        String.Format(AppNum.ErrorMsg.pleaseselectvalidvaluefrom, "Query Name"));
                return;
            }

            CUSTOMRP.Model.RPCATEGORY  rpcat = WebHelper.bllcategory.GetModelList(me.ID, "DATABASEID='" + me.DatabaseID + "'").FirstOrDefault();
            CUSTOMRP.Model.REPORTGROUP rpgrp = WebHelper.bllrpGroup.GetModelList(me.ID, "DATABASEID='" + me.DatabaseID + "'").FirstOrDefault();

            #region Save columninfos

            CUSTOMRP.Model.SOURCEVIEW sv = WebHelper.bllSOURCEVIEW.GetModel(me.ID, svID);
            List <CUSTOMRP.Model.SOURCEVIEWCOLUMN> svclist = WebHelper.bllSOURCEVIEWCOLUMN.GetModelsForSourceView(me.ID, sv.ID).OrderBy(x => x.DisplayName).ToList();
            string[] colnames = svclist.Select(x => x.DisplayName).ToArray();

            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 (colnames == null)
                {
                    colnames = CUSTOMRP.BLL.AppHelper.GetColumnNamesForTblView(me.ID, me.DatabaseNAME, sv.TBLVIEWNAME);
                }
            }
            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 (colnames == null)
                {
                    colnames = CUSTOMRP.BLL.AppHelper.GetColumnNamesForStoredProc(me.ID, me.DatabaseNAME, sv.TBLVIEWNAME);
                }
            }
            break;
            }
            // Filter result to only columns that is requested
            columninfos = columninfos.Where(x => colnames.Contains(x.ColName)).ToList();

            #endregion Save columninfos

            #region myReport
            DateTime currTime = DateTime.Now;
            int      UserID   = me.ID;

            myReport                 = new CUSTOMRP.Model.REPORT();
            myReport.REPORTNAME      = strReportName;
            myReport.RPTITLE         = myReport.REPORTNAME;
            myReport.DATABASEID      = me.DatabaseID;
            myReport.SVID            = svID;
            myReport.CATEGORY        = rpcat != null ? rpcat.ID : -1;
            myReport.REPORTGROUPLIST = rpgrp != null ? rpgrp.ID : -1;
            myReport.DEFAULTFORMAT   = 0;
            myReport.ADDUSER         = UserID;
            myReport.AUDODATE        = currTime;
            myReport.ADDUSER         = UserID;

            myReport.ReportColumns = new List <CUSTOMRP.Model.REPORTCOLUMN>();
            foreach (CUSTOMRP.Model.ColumnInfo c in columninfos)
            {
                CUSTOMRP.Model.SOURCEVIEWCOLUMN svc = svclist.Where(x => x.COLUMNNAME == c.ColName).First();
                myReport.ReportColumns.Add(new CUSTOMRP.Model.REPORTCOLUMN()
                {
                    COLUMNNAME         = c.ColName,
                    COLUMNFUNC         = (int)CUSTOMRP.Model.REPORTCOLUMN.ColumnFuncs.Content,
                    CRITERIA1          = String.Empty,
                    CRITERIA2          = String.Empty,
                    CRITERIA3          = String.Empty,
                    CRITERIA4          = String.Empty,
                    AUDODATE           = currTime,
                    SOURCEVIEWCOLUMNID = svc.ID,
                    DISPLAYNAME        = svc.DISPLAYNAME,
                    COLUMNTYPE         = (int)CUSTOMRP.Model.REPORTCOLUMN.ColumnTypes.Normal,
                    COLUMNCOMMENT      = String.Empty,
                    HIDDEN             = false,
                });
            }

            myReport.WordFile              = new CUSTOMRP.Model.WORDFILE();
            myReport.WordFile.Description  = String.Format("Word file for {0}", myReport.RPTITLE);
            myReport.WordFile.OrigFileName = Path.GetFileName(fUploadTemplate.PostedFile.FileName).Replace(' ', '_');
            myReport.WordFile.WordFileName = savedFileName;
            myReport.WordFile.CreateDate   = currTime;
            myReport.WordFile.CreateUser   = UserID;
            myReport.WordFile.ModifyDate   = currTime;
            myReport.WordFile.ModifyUser   = UserID;

            #endregion myReport

            Session[rpexcel.strSessionKeyMyReport]   = myReport;
            Session[rpexcel.strSessionKeyColumnInfo] = columninfos;

            Response.Redirect("rpworddetail.aspx");
        }
Beispiel #9
0
        protected void btnSampleDataFile_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(this.txtReportName.Text))
            {
                this.lblJavascript.Text = String.Format("<script type=\"text/javascript\">alert(\"{0}\");</script>",
                                                        String.Format(AppNum.ErrorMsg.fieldcannotbeempty, "Report Name"));
                return;
            }

            #region Get ColumnInfo
            CUSTOMRP.Model.SOURCEVIEW sv = WebHelper.bllSOURCEVIEW.GetModel(me.ID, Int32.Parse(this.ddlQueryName.SelectedValue));
            List <CUSTOMRP.Model.SOURCEVIEWCOLUMN> svclist = WebHelper.bllSOURCEVIEWCOLUMN.GetModelsForSourceView(me.ID, sv.ID).OrderBy(x => x.DisplayName).ToList();
            string[] colnames = svclist.Select(x => x.DisplayName).ToArray();

            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 (colnames == null)
                {
                    colnames = CUSTOMRP.BLL.AppHelper.GetColumnNamesForTblView(me.ID, me.DatabaseNAME, sv.TBLVIEWNAME);
                }
            }
            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 (colnames == null)
                {
                    colnames = CUSTOMRP.BLL.AppHelper.GetColumnNamesForStoredProc(me.ID, me.DatabaseNAME, sv.TBLVIEWNAME);
                }
            }
            break;
            }
            // Filter result to only columns that is requested
            columninfos = columninfos.Where(x => colnames.Contains(x.ColName)).ToList();
            #endregion Get ColumnInfo

            StringBuilder selectclause = new StringBuilder(" TOP 5 ");
            selectclause.Append(String.Join(",", columninfos.Select(x => "[" + x.DisplayName + "]").ToArray()));
            //v1.2.0 - Cheong - 2016/07/04 - Add option to hide duplicate items - do not get duplicate data when getting sample
            DataTable dt = CUSTOMRP.BLL.AppHelper.getDataForReport(me.ID, sv.ID, me.DatabaseNAME, selectclause.ToString(), CUSTOMRP.BLL.AppHelper.sql_plus(sv.ID, me), "", "", true);

            NPOI.XSSF.UserModel.XSSFWorkbook XSSFworkbook = NPOIHelper.GetWorkbookAsMailMergeDataSource(dt);

            string downloadFilename = this.txtReportName.Text.Trim().Replace(' ', '_') + ".xlsx";

            string folder = PathHelper.getTempFolderName();
            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }

            string filePath = folder + PathHelper.getSafePath(downloadFilename);
            try
            {
                using (FileStream outFs = new FileStream(filePath, FileMode.Create))
                {
                    XSSFworkbook.Write(outFs);
                    //outFs.Close();
                }

                FileInfo file = new System.IO.FileInfo(filePath);

                Response.ContentType = "application/octet-stream";
                //Response.AddHeader("Content-Disposition", "attachment; filename=\"" + downloadFilename + "\"");
                Response.AddHeader("Content-Disposition", String.Format("attachment; filename=\"{0}\"; filename*=utf-8''{1}", downloadFilename, HttpUtility.UrlPathEncode(downloadFilename)));
                Response.AddHeader("Content-Length", file.Length.ToString());
                Response.WriteFile(file.FullName);
                Response.Flush();
                p_fSuppressRender = true;
                HttpContext.Current.ApplicationInstance.CompleteRequest();
            }
            finally
            {
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
            }
        }
Beispiel #10
0
        protected void btnDownloadRawTemplate_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(this.txtReportName.Text))
            {
                this.lblJavascript.Text = String.Format("<script type=\"text/javascript\">alert(\"{0}\");</script>",
                                                        String.Format(AppNum.ErrorMsg.fieldcannotbeempty, "Report Name"));
                return;
            }

            #region Get ColumnInfo
            CUSTOMRP.Model.SOURCEVIEW sv = WebHelper.bllSOURCEVIEW.GetModel(me.ID, Int32.Parse(this.ddlQueryName.SelectedValue));
            List <CUSTOMRP.Model.SOURCEVIEWCOLUMN> svclist = WebHelper.bllSOURCEVIEWCOLUMN.GetModelsForSourceView(me.ID, sv.ID).OrderBy(x => x.DisplayName).ToList();
            string[] colnames = svclist.Select(x => x.DisplayName).ToArray();

            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 (colnames == null)
                {
                    colnames = CUSTOMRP.BLL.AppHelper.GetColumnNamesForTblView(me.ID, me.DatabaseNAME, sv.TBLVIEWNAME);
                }
            }
            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 (colnames == null)
                {
                    colnames = CUSTOMRP.BLL.AppHelper.GetColumnNamesForStoredProc(me.ID, me.DatabaseNAME, sv.TBLVIEWNAME);
                }
            }
            break;
            }
            // Filter result to only columns that is requested
            columninfos = columninfos.Where(x => colnames.Contains(x.ColName)).ToList();
            #endregion Get ColumnInfo

            string srcfile          = Server.MapPath("~/File/blank.docx");
            string downloadFilename = this.txtReportName.Text.Trim().Replace(' ', '_') + ".docx";
            using (MemoryStream filestream = QueryReport.Code.MailMerge.CreateBlankMailMergeTemplate(srcfile, this.txtReportName.Text.Trim(),
                                                                                                     sv.TBLVIEWNAME, 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);
                p_fSuppressRender = true;
                HttpContext.Current.ApplicationInstance.CompleteRequest();
            }
        }
Beispiel #11
0
        /// <summary>
        /// Update ListBox values
        /// </summary>
        /// <returns>SVID of selected query</returns>
        private int ddlQueryNameChange()
        {
            string[] colnames            = null;
            CUSTOMRP.Model.SOURCEVIEW sv = WebHelper.bllSOURCEVIEW.GetModel(me.ID, Int32.Parse(this.ddlQueryName.SelectedValue));
            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;
            }

            //v1.0.0 - Cheong - 2015/05/29 - Removed this line to hide unwanted columns from users
            // ad-hoc add all columns to SOURCEVIEWCOLUMN
            //WebHelper.bllSOURCEVIEWCOLUMN.AddColList(sv.ID, colnames);

            this.lbAllColumns.Items.Clear();
            this.lbAllColumns_master.Items.Clear();

            // changing query will make the formula useless, so purge them.
            //this.lbFormula.Items.Clear();
            this.formulaFields.Clear();
            Session.Remove(rpexcel.strSessionKeyFormulaFields);

            //v1.0.0 Fai 2015.03.19 - Order by Column Name
            if (svc.Count == 0)
            {
                // do sorting
                columninfos = columninfos.OrderBy(p => p.ColName).ToList();
            }
            else
            {
                // patch displayname and do sorting
                //v1.1.0 - Cheong - 2016/05/20 - Allow new columns be displayed in report
                //columninfos = (from c in columninfos
                //               join s in svc.Where(x => x.ColumnType == CUSTOMRP.Model.SOURCEVIEWCOLUMN.ColumnTypes.Normal) on c.ColName equals s.COLUMNNAME
                //               orderby s.DisplayName
                //               select new CUSTOMRP.Model.ColumnInfo()
                //               {
                //                   ColName = c.ColName,
                //                   DisplayName = String.IsNullOrEmpty(s.DISPLAYNAME) ? c.ColName : s.DISPLAYNAME, // no need to show actual column name here if DisplayName is supplied
                //                   DataType = c.DataType,
                //               }).ToList();

                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 c.ColName //s.DisplayName,
                               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();
            }

            foreach (CUSTOMRP.Model.ColumnInfo col in columninfos)
            {
                ListItem option = new ListItem(col.DisplayName, col.ColName);
                option.Attributes.Add("data-datatype", col.DataType);
                this.lbAllColumns.Items.Add(option);
                //v1.6.8 - Cheong - 2016/05/26 - Add a master select box to hold values
                this.lbAllColumns_master.Items.Add(option);
            }

            // cache column type data in session
            Session[rpexcel.strSessionKeyColumnInfo] = columninfos;

            this.lbcontents.Items.Clear();
            this.lbcriteria.Items.Clear();
            this.lbsorton.Items.Clear();

            return(sv.ID);
        }
Beispiel #12
0
        protected void btnDownloadDatafile_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(this.txtReportName.Text))
            {
                this.lblJavascript.Text = String.Format("<script type=\"text/javascript\">alert(\"{0}\");</script>",
                                                        String.Format(AppNum.ErrorMsg.fieldcannotbeempty, "Report Name"));
                return;
            }

            #region Get ColumnInfo
            CUSTOMRP.Model.SOURCEVIEW sv = WebHelper.bllSOURCEVIEW.GetModel(me.ID, Int32.Parse(this.ddlQueryName.SelectedValue));
            List <CUSTOMRP.Model.SOURCEVIEWCOLUMN> svclist = WebHelper.bllSOURCEVIEWCOLUMN.GetModelsForSourceView(me.ID, sv.ID).OrderBy(x => x.DisplayName).ToList();
            string[] colnames = svclist.Select(x => x.DisplayName).ToArray();

            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 (colnames == null)
                {
                    colnames = CUSTOMRP.BLL.AppHelper.GetColumnNamesForTblView(me.ID, me.DatabaseNAME, sv.TBLVIEWNAME);
                }
            }
            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 (colnames == null)
                {
                    colnames = CUSTOMRP.BLL.AppHelper.GetColumnNamesForStoredProc(me.ID, me.DatabaseNAME, sv.TBLVIEWNAME);
                }
            }
            break;
            }
            // Filter result to only columns that is requested
            columninfos = columninfos.Where(x => colnames.Contains(x.ColName)).ToList();
            #endregion Get ColumnInfo

            StringBuilder selectclause = new StringBuilder("TOP 5 ");

            //v1.2.0 Fai 2017.01.11 - Avoid to throw Exception if columninfos have no any items - Begin
            //selectclause.Append(String.Join(",", columninfos.Select(x => "[" + x.DisplayName + "]").ToArray()));
            if (columninfos.Select(x => "[" + x.DisplayName + "]").ToArray().Length > 0)
            {
                selectclause.Append(String.Join(",", columninfos.Select(x => "[" + x.DisplayName + "]").ToArray()));
            }
            else
            {
                selectclause.Append("*");
            }
            //v1.2.0 Fai 2017.01.11 - Avoid to throw Exception if columninfos have no any items - End

            //v1.2.0 - Cheong - 2016/07/04 - Add option to hide duplicate items
            //DataTable dt = CUSTOMRP.BLL.AppHelper.getDataForReport(sv.ID, me.DatabaseNAME, selectclause.ToString(), CUSTOMRP.BLL.AppHelper.sql_plus(sv.ID, me), "", "", true);
            DataTable dt = CUSTOMRP.BLL.AppHelper.getDataForReport(me.ID, sv.ID, me.DatabaseNAME, selectclause.ToString(), CUSTOMRP.BLL.AppHelper.sql_plus(sv.ID, me), "", "", myReport.fHideDuplicate);

            NPOI.XSSF.UserModel.XSSFWorkbook XSSFworkbook = NPOIHelper.GetWorkbookAsMailMergeDataSource(dt);

            string path = g_Config["WordTemplatePath"];
            string filenamewithoutextension = null;
            string datafilename             = null;
            if ((myReport.WordFile != null) && File.Exists(path + myReport.WordFile.WordFileName))
            {
                filenamewithoutextension = Path.GetFileNameWithoutExtension(myReport.WordFile.WordFileName);
                if (filenamewithoutextension.LastIndexOf('.') > 0)
                {
                    filenamewithoutextension = filenamewithoutextension.Substring(0, filenamewithoutextension.LastIndexOf('.'));
                }
                datafilename = filenamewithoutextension + ".xlsx";
            }
            else
            {
                CUSTOMRP.Model.WORDTEMPLATE wordtemplate = WebHelper.bllWORDTEMPLATE.GetModelBySVID(me.ID, sv.ID, me.ID);
                if (wordtemplate != null)
                {
                    filenamewithoutextension = Path.GetFileNameWithoutExtension(wordtemplate.TemplateFileName);
                    datafilename             = wordtemplate.DataFileName;
                }
            }

            if (datafilename == null)
            {
                this.lblJavascript.Text = String.Format("<script type=\"text/javascript\">alert(\"{0}\");</script>", AppNum.ErrorMsg.parameter_error);
                return;
            }

            string folder = PathHelper.getTempFolderName();
            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }

            string filePath = folder + PathHelper.getSafePath(datafilename);
            try
            {
                using (FileStream outFs = new FileStream(filePath, FileMode.Create))
                {
                    XSSFworkbook.Write(outFs);
                    //CA2202
                    //outFs.Close();
                }

                FileInfo file = new System.IO.FileInfo(filePath);

                Response.ContentType = "application/octet-stream";
                //Encode filename according to RFC5987
                //Response.AddHeader("Content-Disposition", "attachment; filename=\"" + datafilename + "\"");
                Context.Response.AddHeader("Content-Disposition", String.Format("attachment; filename=\"{0}\"; filename*=utf-8''{1}", datafilename, HttpUtility.UrlPathEncode(datafilename)));
                Response.AddHeader("Content-Length", file.Length.ToString());
                Response.WriteFile(file.FullName);
                Response.Flush();
                p_fSuppressRender = true;
                HttpContext.Current.ApplicationInstance.CompleteRequest();
            }
            finally
            {
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
            }
        }
Beispiel #13
0
        private bool p_fSuppressRender = false;     // Whether to render page contents

        #region Event Handlers

        protected void Page_Init(object sender, EventArgs e)
        {
            if (Session[rpexcel.strSessionKeyColumnInfo] != null)
            {
                columninfos = (List <CUSTOMRP.Model.ColumnInfo>)Session[rpexcel.strSessionKeyColumnInfo];
            }

            if (Session[rpexcel.strSessionKeyFormulaFields] != null)
            {
                formulaFields = (List <CUSTOMRP.Model.REPORTCOLUMN>)Session[rpexcel.strSessionKeyFormulaFields];
            }
            else
            {
                formulaFields = new List <CUSTOMRP.Model.REPORTCOLUMN>();
                Session[rpexcel.strSessionKeyFormulaFields] = formulaFields;
            }

            if ((myReport == null) && (Session[rpexcel.strSessionKeyMyReport] != null))
            {
                myReport = (CUSTOMRP.Model.REPORT)Session[rpexcel.strSessionKeyMyReport];
            }

            if (!this.IsPostBack)
            {
                if (!String.IsNullOrEmpty(Request.QueryString["id"]))
                {
                    int id = Int32.Parse(Request.QueryString["id"]);
                    myReport = WebHelper.bllReport.GetModel(me.ID, id);

                    this.btnDelete.Visible = true;
                    if (myReport == null)
                    {
                        Common.JScript.AlertAndRedirect(AppNum.ErrorMsg.parameter_error, "rplist.aspx");
                        Response.End();
                    }
                    else
                    {
                        Session[rpexcel.strSessionKeyMyReport] = myReport;
                        CUSTOMRP.BLL.SOURCEVIEW svBLL = new CUSTOMRP.BLL.SOURCEVIEW();
                        mySV = svBLL.GetModel(me.ID, myReport.SVID);
                    }
                }
                else
                {
                    // creating new report
                    myReport    = (CUSTOMRP.Model.REPORT)Session[rpexcel.strSessionKeyMyReport];
                    columninfos = (List <CUSTOMRP.Model.ColumnInfo>)Session[rpexcel.strSessionKeyColumnInfo];
                }
            }
            else
            {
                // v1.2.0 Kim 2016.11.22 do this both IsPostBack or not
                //if ((myReport == null) && (Session[rpexcel.strSessionKeyMyReport] != null))
                //{
                //    myReport = (CUSTOMRP.Model.REPORT)Session[rpexcel.strSessionKeyMyReport];
                //}

                if (!String.IsNullOrEmpty(Request.QueryString["id"]))
                {
                    int id = Int32.Parse(Request.QueryString["id"]);

                    if (Session[rpexcel.strSessionKeyReportParameterContainer] != null)
                    {
                        ReportParameterContainer container        = (ReportParameterContainer)Session[rpexcel.strSessionKeyReportParameterContainer];
                        CUSTOMRP.Model.REPORT    rptFromContainer = container.GetReportModel(me, columninfos, id);

                        //v1.7.0 - Cheong - 2016/07/04 - Since we also need to receive setting data from rpword.aspx, instead of directly assigning
                        // report object decoded, we try to merge settings here instead.
                        #region Merge myReport data

                        if (myReport == null)
                        {
                            myReport = rptFromContainer;
                        }
                        else
                        {
                            myReport.REPORTNAME      = rptFromContainer.REPORTNAME;
                            myReport.CATEGORY        = rptFromContainer.CATEGORY;
                            myReport.REPORTGROUPLIST = rptFromContainer.REPORTGROUPLIST;
                            myReport.RPTITLE         = rptFromContainer.RPTITLE;
                            myReport.EXTENDFIELD     = rptFromContainer.EXTENDFIELD;
                        }

                        #endregion Merge myReport data
                    }
                }
            }

            if (!IsPostBack)
            {
                if (myReport != null)
                {
                    selectedColumns = myReport.ReportColumns;
                }
                else
                {
                    selectedColumns = new List <CUSTOMRP.Model.REPORTCOLUMN>();
                }
            }
        }
Beispiel #14
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (ProcessAjaxRequestParameters())
            {
                return;
            }                                               // stop further process if it's Ajax event

            this.lblJavascript.Text = String.Empty;

            if (!IsPostBack)
            {
                this.FillPageHeaderUI();
            }

            #region get column names

            string[] colnames = null;
            if (mySV == null)
            {
                mySV = WebHelper.bllSOURCEVIEW.GetModel(me.ID, Int32.Parse(this.ddlQueryName.SelectedValue));
            }
            colnames = WebHelper.bllSOURCEVIEWCOLUMN.GetModelsForSourceView(me.ID, mySV.ID).OrderBy(x => x.DisplayName).Select(x => x.DisplayName).ToArray();
            if (colnames == null)
            {
                switch (mySV.SourceType)
                {
                case CUSTOMRP.Model.SOURCEVIEW.SourceViewType.View:
                case CUSTOMRP.Model.SOURCEVIEW.SourceViewType.Table:
                {
                    colnames = CUSTOMRP.BLL.AppHelper.GetColumnNamesForTblView(me.ID, me.DatabaseNAME, mySV.TBLVIEWNAME);
                }
                break;

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

            #endregion

            if (selectedColumns != null)
            {
                foreach (CUSTOMRP.Model.REPORTCOLUMN dr in selectedColumns)
                {
                    if (dr.ColumnType == CUSTOMRP.Model.REPORTCOLUMN.ColumnTypes.Formula)
                    {
                        this.formulaFields.Add(dr);
                        //this.lbFormula.Items.Add(new ListItem(dr.DisplayName));

                        switch (dr.ColumnFunc)
                        {
                        case CUSTOMRP.Model.REPORTCOLUMN.ColumnFuncs.Content:
                        {
                            this.lbcontents.Items.Add(new ListItem(dr.DisplayName));
                        }
                        break;

                        case CUSTOMRP.Model.REPORTCOLUMN.ColumnFuncs.Criteria:
                        {
                            this.lbcriteria.Items.Add(new ListItem(dr.DisplayName));
                        }
                        break;

                        case CUSTOMRP.Model.REPORTCOLUMN.ColumnFuncs.SortOn:
                        {
                            this.lbsorton.Items.Add(new ListItem(dr.DisplayName));
                        }
                        break;
                        }
                    }
                    else
                    {
                        //v1.0.0 - Cheong - 2015/03/31 - Filter missing columns from list when running reports
                        if (colnames.Contains(dr.COLUMNNAME))
                        {
                            switch (dr.ColumnFunc)
                            {
                            case CUSTOMRP.Model.REPORTCOLUMN.ColumnFuncs.Content:
                            {
                                if ((dr.ColumnType == CUSTOMRP.Model.REPORTCOLUMN.ColumnTypes.Normal) && (!dr.COLUMNNAME.Equals(dr.DISPLAYNAME)))
                                {
                                    this.lbcontents.Items.Add(new ListItem(String.Format("{0} = [{1}]", dr.DisplayName, dr.COLUMNNAME), dr.COLUMNNAME));
                                }
                                else
                                {
                                    this.lbcontents.Items.Add(new ListItem(dr.DisplayName, dr.COLUMNNAME));
                                }
                            }
                            break;

                            case CUSTOMRP.Model.REPORTCOLUMN.ColumnFuncs.Criteria:
                            {
                                this.lbcriteria.Items.Add(new ListItem(dr.DisplayName, dr.COLUMNNAME));
                            }
                            break;

                            case CUSTOMRP.Model.REPORTCOLUMN.ColumnFuncs.SortOn:
                            {
                                this.lbsorton.Items.Add(new ListItem(dr.DisplayName, dr.COLUMNNAME));
                            }
                            break;
                            }
                        }
                    }
                }

                // After formula fields are loaded, save it to session
                Session[rpexcel.strSessionKeyFormulaFields] = formulaFields;
            }

            //v1.0.0 - Cheong - 2015/03/31 if no right to modify, go directly to rpwordsave.aspx
            if ((!me.rp_modify) || (Request.Params["cmd"] == "run"))
            {
                //v1.2.0 Kim 2016.12.08 clear Container session to force rpwordsave.aspx load from report setting if go directly
                Session[rpexcel.strSessionKeyReportParameterContainer] = null;
                Server.Transfer("rpwordsave.aspx", true);
            }
        }