예제 #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["userid"] == null)
     {
         this.Response.Write("<script language=\"javascript\">");
         this.Response.Write("alert('您未正常登录,请登录后再使用,谢谢!')");
         this.Response.Write("</script>");
         this.Response.Redirect("index.htm");
     }
     string[] strsqls = (this.Request.QueryString["sql"] == null) ? null : this.Request.QueryString["sql"].Split(';');
     string prnname = this.Request.QueryString["prn"];
     string prntype = this.Request.QueryString["prntype"];
     string prnpms = this.Request.QueryString["pms"];
     string relation = this.Request.QueryString["relation"];
     NameObjectList paramlist = new NameObjectList();
     string[] parammacro = { "10", "0", "", "", "", "", "", "", "" };
     if (prnpms != null)
     {
         paramlist = createParam(prnpms);
         parammacro = createMacro(prnpms);
     }
     string[] prndatasrcs = null;
     if (this.Request.QueryString["datasrc"] != null)
         prndatasrcs = this.Request.QueryString["datasrc"].Split(';');
     if (prntype == null) prntype = "excel";
     if (prndatasrcs == null) prndatasrcs = new String[] { "table" };
     string strCn = DataAccRes.DefaultDataConnInfo.Value;
     DataSet ds = new DataSet();
     //初始化连接字符串
     if (strsqls != null && strsqls.Length > 0)
     {
         SqlConnection CN = new SqlConnection();
         try
         {
             CN.ConnectionString = strCn;
             CN.Open();
             for (int i = 0; i < strsqls.Length; i++)
             {
                 if (strsqls[i] == "") continue;
                 SqlDataAdapter adp = new SqlDataAdapter(strsqls[i], CN);
                 adp.Fill(ds, prndatasrcs[i]);
             }
             CN.Close();
         }
         catch (Exception ex)
         {
             if (CN.State == ConnectionState.Open) CN.Close();
             this.Response.Write("");
             return;
         }
     }
     else if (null != prndatasrcs && prndatasrcs.Length > 0)
     {
         QueryDataRes query = null;
         for (int i = 0; i < prndatasrcs.Length; i++)
         {
             if (string.IsNullOrEmpty(prndatasrcs[i]))
                 continue;
             string[] src = prndatasrcs[i].Split(".".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
             if (src.Length < 2)
                 continue;
             query = new QueryDataRes(src[0]);
             query.FillDataSet(src[1], paramlist, parammacro, ds);
         }
     }
     if (!ds.Tables.Contains("参数表"))
     {
         User user = new User(Convert.ToString(Session["userid"]));
         string[,] colmap = { { "公司名称", user.Company }, { "部门代码", user.DeptmentCode }, { "部门名称", user.DeptmentName }, 
                              { "上级部门", user.DeptSup }, { "单位名称", user.UnitName }, { "用户名称", user.UserName } };
         for (int i = 0; i < colmap.GetLength(0); i++)
         {
             if (null == paramlist[colmap[i, 0]])
                 paramlist[colmap[i, 0]] = colmap[i, 1];
         }
         DataTable tabm = new DataTable("参数表");
         foreach (string key in paramlist.AllKeys)
             tabm.Columns.Add(key);
         DataRow drm = tabm.NewRow();
         foreach (string key in paramlist.AllKeys)
             drm[key] = Convert.ToString(paramlist[key]);
         tabm.Rows.Add(drm);
         ds.Tables.Add(tabm);
     }
     //表关系:master.col~child.col;
     if (!string.IsNullOrEmpty(relation))
     {
         string[] relts = relation.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
         for (int i = 0; i < relts.Length; i++)
         {
             string[] rlt = relts[i].Split("~".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
             if (rlt.Length < 2) continue;
             string[] rltm = rlt[0].Split(".".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
             string[] rltd = rlt[1].Split(".".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
             if (!ds.Tables.Contains(rltm[0]) || !ds.Tables.Contains(rltd[0]))
                 continue;
             if (!ds.Tables[rltm[0]].Columns.Contains(rltm[1]) || !ds.Tables[rltd[0]].Columns.Contains(rltd[1]))
                 continue;
             DataTable tabm = ds.Tables[rltm[0]];
             DataTable tabd = ds.Tables[rltd[0]];
             tabm.ChildRelations.Add(tabm.Columns[rltm[1]], tabd.Columns[rltd[1]]);
         }
     }
     string SourceFile = prnname;
     string TemplatePath = this.Server.MapPath(DataAccRes.AppSettings("TpFilePath"));    //存放源文件的文件夹路径。
     string SrcFile = TemplatePath + SourceFile; //源文件名称
     string DestFile = "print.XLS";
     if (!string.IsNullOrEmpty(SourceFile) && !File.Exists(SrcFile))
     {
         string strMSG = "打印模板 [" + SourceFile + "] 不存在,请联系系统管理员建立打印模板!";
         this.Response.Write("<script language=\"javascript\">");
         this.Response.Write("alert('" + strMSG + "')");
         this.Response.Write("</script>");
         return;
     }
     switch (prntype)
     {
         case "word":
             PrintWord printdoc = new PrintWord();
             printdoc.TemplateFileName = SrcFile;
             printdoc.DataSource = ds;
             printdoc.DataBind();
             printdoc.RemoveXmlLable();
             csPrint.outXML2Word(printdoc.PrintXmlDoc, "print.doc");
             break;
         case "excel":
             //DataTable tab = (ds.Tables.Count == 0) ? null : ds.Tables[0];
             //XmlDocument xmlPrintDoc = csPrintData.makeprint(null, null, SourceFile, DestFile, tab, tab, 0, this.Session["userid"].ToString(), paramlist);
             if (string.IsNullOrEmpty(SourceFile) || !File.Exists(SrcFile))
             {
                 SrcFile = "";
                 ds.Tables.Remove("参数表");
             }
             PrintExcel printexcel = new PrintExcel();
             printexcel.DataSource = ds;
             printexcel.TemplateFileName = SrcFile;
             printexcel.DataBind();
             csPrintData.outXML2Excel(printexcel.PrintXmlDoc, DestFile);
             break;
         case "html":
             break;
     }
 }
예제 #2
0
        /// <summary>
        /// 打印报表项
        /// </summary>
        /// <param name="appendItem"></param>
        private void printReport(string appendItemName)
        {
            string TemplatePath = this.Server.MapPath(DataAccRes.AppSettings("TpFilePath"));    //存放源文件的文件夹路径。

            //需要知道itemName
            AppendItem appendItem = this.PgUnitItem.GetAppendItem(appendItemName);
            if (null == appendItem) return;
            string printname = appendItem.PrintTpName;
            if (printname == "" || printname == null) 
                printname = appendItem.ItemName;

            string SourceFile = printname + ".XML"; //源文件名称
            string SrcFile = TemplatePath + "\\" + SourceFile; //源文件名称
            string DestFile = printname + Session["userid"] + ".XLS";
            if (System.IO.File.Exists(SrcFile) == true)
            {
                //获取模板中的原始SQL
                QueryDataRes query = this.PgQuery;
                NameObjectList paramlist = BuildParamList.BuildParams(this.PgParamXmlDoc);
                DataSet ds = new DataSet(appendItem.ItemName);
                string schemaFile = TemplatePath + "\\" + printname + ".xsd";
                UnitItem appendUnit = this.PgUnitItem;
                if (!string.IsNullOrEmpty(appendItem.UnitName))
                {
                    appendUnit = new UnitItem(this.Server.MapPath(DataAccRes.AppSettings("WorkConfig")), appendItem.UnitName);
                    if (null == appendUnit) return;
                    query = new QueryDataRes(appendUnit.DataSrcFile);
                }
                if (File.Exists(schemaFile))
                {
                    ds.ReadXmlSchema(schemaFile);
                    for (int i = 0; i < ds.Tables.Count; i++)
                    {
                        WorkItem tabItem = null;
                        for (int j = 0; j < appendUnit.WorkItemList.Length; j++)
                            if (ds.Tables[i].TableName == appendUnit.WorkItemList[j].DataSrc)
                            {
                                tabItem = appendUnit.WorkItemList[j];
                                break;
                            }
                        if (null == tabItem)
                            query.FillDataSet(ds.Tables[i].TableName, paramlist, ds);
                        else
                        {
                            query.FillDataSet(ds.Tables[i].TableName, paramlist, this.getStrParams(this.PgParamXmlDoc,tabItem), ds);
                            if (null != ds.Tables[i] && !string.IsNullOrEmpty(tabItem.printcountmin))
                                ds.Tables[i].ExtendedProperties[PrintWord.ExProMinRowCountName] = tabItem.printcountmin;
                        }
                    }///for (int i = 0; i < ds.Tables.Count; i++)
                }
                else
                {
                    if (string.IsNullOrEmpty(appendItem.UnitName))
                    {
                        query.FillDataSet(appendItem.DataSrc, paramlist, ds);
                        if (null != ds.Tables[appendItem.DataSrc] && !string.IsNullOrEmpty(appendItem.PrintCountMin))
                            ds.Tables[appendItem.DataSrc].ExtendedProperties[PrintWord.ExProMinRowCountName] = appendItem.PrintCountMin;
                    }
                    else if (null != appendUnit)
                    {
                        for (int i = 0; i < appendUnit.WorkItemList.Length; i++)
                        {
                            WorkItem    workitem=appendUnit.WorkItemList[i];
                            query.FillDataSet(workitem.DataSrc, paramlist, this.getStrParams(this.PgParamXmlDoc,appendUnit.WorkItemList[i]), ds);
                            if (null != ds.Tables[workitem.DataSrc] && !string.IsNullOrEmpty(workitem.printcountmin))
                                ds.Tables[workitem.DataSrc].ExtendedProperties[PrintWord.ExProMinRowCountName] = workitem.printcountmin;
                        }
                    }
                }
                if (ds == null) return;
                if (ds.Tables[0] == null) return;
                if (ds.Tables[0].Rows.Count < 1) return;

                if (appendItem.PrintType == PrintType.Word)
                {
                    PrintWord printdoc = new PrintWord();
                    printdoc.TemplateFileName = SrcFile;
                    printdoc.DataSource = ds;
                    printdoc.DataBind();
                    printdoc.RemoveXmlLable();
                    csPrint.outXML2Word(printdoc.PrintXmlDoc, "print.doc");
                }
                else
                {
                    XmlDocument xmldoc = csPrintData.makeprint(null,null,SourceFile, DestFile, ds.Tables[0], ds.Tables[0], 0, Session["userid"].ToString(), paramlist);
                    csPrintData.outXML2Excel(xmldoc, "print.xls");
                }
            }
            else
            {
                string strMSG = "打印模板 [" + SourceFile + "] 不存在,请联系系统管理员建立打印模板!";
                this.Response.Write("<script language=\"javascript\">");
                this.Response.Write("alert('" + strMSG + "')");
                this.Response.Write("</script>");
            }
        }
예제 #3
0
		//为什么是PgWorkItemList[1].ItemType ?
		private void printword(string mrowIndex,WorkItem workitem)
		{
            string TemplatePath = this.Server.MapPath(DataAccRes.AppSettings("TpFilePath"));    //存放源文件的文件夹路径。

			string printname = "", itemname="";
			printname = workitem.printname;
			itemname  = workitem.ItemName;
			if(string.IsNullOrEmpty(printname))
                printname= itemname;
			string SourceFile	= printname + ".XML"; //源文件名称
			string SrcFile		= TemplatePath +"\\"+ SourceFile; //源文件名称
			string DestFile		= printname + Session["userid"] + ".XLS";
            string schemaFile = TemplatePath + "\\" + printname + ".xsd";
            if (!File.Exists(SrcFile))
            {
                string strMSG = "打印模板 [" + SourceFile + "] 不存在,请联系系统管理员建立打印模板!";
                this.Response.Write("<script language=\"javascript\">");
                this.Response.Write("alert('" + strMSG + "')");
                this.Response.Write("</script>");
                return;
            }
            QueryDataRes query = this.PgQuery;
            NameObjectList paramlist = BuildParamList.BuildParams(this.PgParamXmlDoc);
            DataSet ds = new DataSet(this.PgUnitItem.UnitName);
            if (File.Exists(schemaFile))
            {
                ds.ReadXmlSchema(schemaFile);
                for (int i = 0; i < ds.Tables.Count; i++)
                {
                    WorkItem tabItem = null;
                    for (int j = 0; j < this.PgUnitItem.WorkItemList.Length; j++)
                        if (ds.Tables[i].TableName == this.PgUnitItem.WorkItemList[j].DataSrc)
                        {
                            tabItem = this.PgUnitItem.WorkItemList[j];
                            break;
                        }
                    if (null == tabItem)
                        query.FillDataSet(ds.Tables[i].TableName, paramlist, ds);
                    else
                    {
                        query.FillDataSet(ds.Tables[i].TableName, paramlist, this.getStrParams(this.PgParamXmlDoc,tabItem), ds);
                        if (!string.IsNullOrEmpty(tabItem.printcountmin))
                            ds.Tables[i].ExtendedProperties[PrintWord.ExProMinRowCountName] = tabItem.printcountmin;
                    }
                }///for (int i = 0; i < ds.Tables.Count; i++)
            }
            else
            {
                query.FillDataSet(workitem.DataSrc, paramlist, this.getStrParams(this.PgParamXmlDoc,workitem), ds);
                if (null != ds.Tables[workitem.DataSrc] && !string.IsNullOrEmpty(workitem.printcountmin))
                    ds.Tables[workitem.DataSrc].ExtendedProperties[PrintWord.ExProMinRowCountName] = workitem.printcountmin;
            }
            if (ds == null) return;
            if (ds.Tables[0] == null) return;
            if (ds.Tables[0].Rows.Count < 1) return;

            PrintWord printdoc = new PrintWord();
            printdoc.TemplateFileName = SrcFile;
            printdoc.DataSource = ds;
            printdoc.DataBind();
            printdoc.RemoveXmlLable();
            csPrint.outXML2Word(printdoc.PrintXmlDoc, printname + ".doc");
        }
예제 #4
0
		private void printword(string mrowIndex)
		{
            string TemplatePath = this.Server.MapPath(DataAccRes.AppSettings("TpFilePath"));    //存放源文件的文件夹路径。

			//需要知道itemName
			string printname = this.PgWorkItemList[0].printname;
			if(printname=="" || printname==null) printname = this.PgWorkItemList[0].ItemName;

			string SourceFile	= printname + ".XML"; //源文件名称
			string SrcFile		= TemplatePath +"\\"+ SourceFile; //源文件名称
			string DestFile		= printname + Session["userid"] + ".XLS";

			if(System.IO.File.Exists(SrcFile)==true)
			{				
				QueryDataRes query	=this.PgQuery;
                NameObjectList paramlist = BuildParamList.BuildParams(this.PgParamXmlDoc);
            
				//获取模板中的原始SQL
				DataSet			ds=new DataSet(this.PgUnitName);
				WorkItem	workItem=this.PgWorkItemList[0];
				string  strRowCount=this.getRecordCountParam(workItem);
				query.FillDataSet(this.PgWorkItemList[0].DataSrc,paramlist,getStrParams(this.PgParamXmlDoc,this.PgWorkItemList[0]),ds);

				PrintWord	printdoc=new PrintWord();
                printdoc.TemplateFileName = this.Server.MapPath(DataAccRes.AppSettings("TpFilePath") + "\\" + workItem.printname + ".xml");
				printdoc.DataSource=ds;
				printdoc.DataBind();
				printdoc.RemoveXmlLable();
				csPrint.outXML2Word(printdoc.PrintXmlDoc,"print.doc");
			}
			else
			{
				string strMSG = "打印模板 ["+SourceFile+"] 不存在,请联系系统管理员建立打印模板!";
				this.Response.Write("<script language=\"javascript\">");
				this.Response.Write("alert('"+ strMSG +"')");
				this.Response.Write("</script>");
			}
		}