Exemplo n.º 1
0
    /// <summary>
    /// 登录后执行
    /// </summary>
    /// <param name="UserID">用户标识</param>
    public void LoginRegister(string UserID)
    {
        Log.log   a       = new Log.log();
        Hashtable hOnline = (Hashtable)System.Web.HttpContext.Current.Application["Online"];

        if (hOnline != null)
        {
            IDictionaryEnumerator idE = hOnline.GetEnumerator();
            string strKey             = "";
            while (idE.MoveNext())
            {
                if (idE.Value != null && idE.Value.ToString().Equals(UserID))
                {
                    //already login
                    //strKey = idE.Key.ToString();
                    //hOnline[strKey] = UserID;

                    break;
                }
            }
        }
        else
        {
            hOnline = new Hashtable();
        }

        hOnline[System.Web.HttpContext.Current.Session.SessionID] = UserID;
        System.Web.HttpContext.Current.Application.Lock();
        System.Web.HttpContext.Current.Application["Online"] = hOnline;
        System.Web.HttpContext.Current.Application.UnLock();
    }
Exemplo n.º 2
0
    /// <summary>
    /// Global文件的SessionEnd事件中增加此代码
    /// </summary>
    public static void GlobalSessionEnd()
    {
        Log.log   a       = new Log.log();
        Hashtable hOnline = (Hashtable)System.Web.HttpContext.Current.Application["Online"];

        if (hOnline != null)
        {
            if (hOnline[System.Web.HttpContext.Current.Session.SessionID] != null)
            {
                a.Log(System.Web.HttpContext.Current.Session.SessionID);
                hOnline.Remove(System.Web.HttpContext.Current.Session.SessionID);
                System.Web.HttpContext.Current.Application.Lock();
                System.Web.HttpContext.Current.Application["Online"] = hOnline;
                System.Web.HttpContext.Current.Application.UnLock();
            }
        }
    }
Exemplo n.º 3
0
    protected void btn_print_Click(object sender, EventArgs e)
    {
        try
        {
            RemoveFiles(Server.MapPath(".") + "\\");
        }
        catch (Exception exp)
        {
            Log.log alog = new Log.log();
            alog.Log(exp.Message.ToString() + DateTime.Now.ToString());
        }

        Random rd  = new Random();
        int    oid = rd.Next(10000);

        Word.Application app     = new Word.Application();
        Word.Document    doc     = new Word.Document();
        object           missing = System.Reflection.Missing.Value;
        object           IsSave  = true;

        try
        {
            DataSet ds_depart = new MyDataOp("select * from t_企业信息 inner join t_M_ClientInfo on 所属镇街道=t_M_ClientInfo.id inner join t_行业信息 on t_行业信息.id=行业类别 inner join t_生产状态 on t_生产状态.id=生产状态 where t_企业信息.id='" + Editid + "'").CreateDataSet();
            depart  departobj = new depart();
            if (ds_depart.Tables[0].Rows.Count > 0)
            {
                departobj.departid   = ds_depart.Tables[0].Rows[0]["id"].ToString().Trim();
                departobj.departname = ds_depart.Tables[0].Rows[0]["单位全称"].ToString().Trim();
                departobj.address    = ds_depart.Tables[0].Rows[0]["单位详细地址"].ToString().Trim();
                departobj.fddb       = ds_depart.Tables[0].Rows[0]["法定代表人"].ToString().Trim();
                departobj.frdm       = ds_depart.Tables[0].Rows[0]["单位法人代码"].ToString().Trim();
                departobj.frdh       = ds_depart.Tables[0].Rows[0]["tel1"].ToString().Trim();
                departobj.frsj       = ds_depart.Tables[0].Rows[0]["mobile1"].ToString().Trim();
                departobj.fzrsfw     = ds_depart.Tables[0].Rows[0]["市府网1"].ToString().Trim();

                departobj.fgr    = ds_depart.Tables[0].Rows[0]["环保分管人"].ToString().Trim();
                departobj.fgdh   = ds_depart.Tables[0].Rows[0]["tel2"].ToString().Trim();
                departobj.fgsj   = ds_depart.Tables[0].Rows[0]["mobile2"].ToString().Trim();
                departobj.fgsfw  = ds_depart.Tables[0].Rows[0]["市府网2"].ToString().Trim();
                departobj.fzr    = ds_depart.Tables[0].Rows[0]["环保负责人"].ToString().Trim();
                departobj.fzdh   = ds_depart.Tables[0].Rows[0]["tel3"].ToString().Trim();
                departobj.fzrsj  = ds_depart.Tables[0].Rows[0]["mobile3"].ToString().Trim();
                departobj.fzrsfw = ds_depart.Tables[0].Rows[0]["市府网3"].ToString().Trim();
                departobj.sczt   = ds_depart.Tables[0].Rows[0]["des2"].ToString().Trim();
                departobj.ssjd   = ds_depart.Tables[0].Rows[0]["des"].ToString().Trim();
                departobj.yzbm   = ds_depart.Tables[0].Rows[0]["邮政编码"].ToString().Trim();
                departobj.dzyx   = ds_depart.Tables[0].Rows[0]["电子邮箱"].ToString().Trim();
                departobj.czhm   = ds_depart.Tables[0].Rows[0]["传真号码"].ToString().Trim();
                departobj.hy     = ds_depart.Tables[0].Rows[0]["des1"].ToString().Trim();
                if (ds_depart.Tables[0].Rows[0]["污水是否入网"].ToString().Trim() == "1")
                {
                    departobj.wsrw = "是";
                }
                else
                {
                    departobj.wsrw = "否";
                }
                if (ds_depart.Tables[0].Rows[0]["污水入网时间"].ToString() != "1900-1-1 0:00:00" && ds_depart.Tables[0].Rows[0]["污水入网时间"].ToString() != "")
                {
                    departobj.rwsj = ds_depart.Tables[0].Rows[0]["污水入网时间"].ToString().Trim();
                }
                else
                {
                    departobj.rwsj = "";
                }
                if (ds_depart.Tables[0].Rows[0]["集中供热是否入网"].ToString().Trim() == "1")
                {
                    departobj.jzgr = "是";
                }
                else
                {
                    departobj.jzgr = "否";
                }
                if (ds_depart.Tables[0].Rows[0]["集中供热入网时间"].ToString() != "1900-1-1 0:00:00" && ds_depart.Tables[0].Rows[0]["集中供热入网时间"].ToString() != "")
                {
                    departobj.grsj = ds_depart.Tables[0].Rows[0]["集中供热入网时间"].ToString().Trim();
                }
                else
                {
                    departobj.grsj = "";
                }
                departobj.yyzzfw = ds_depart.Tables[0].Rows[0]["工商营业执照经营范围"].ToString().Trim();
                if (ds_depart.Tables[0].Rows[0]["单位设立时间"].ToString() != "1900-1-1 0:00:00" && ds_depart.Tables[0].Rows[0]["单位设立时间"].ToString() != "")
                {
                    departobj.jcsj = DateTime.Parse(ds_depart.Tables[0].Rows[0]["单位设立时间"].ToString().Trim()).ToString("yyyy-mm-dd");
                }
                else
                {
                    departobj.jcsj = "";
                }
                departobj.jncp = ds_depart.Tables[0].Rows[0]["企业近年产品产量"].ToString().Trim();
                departobj.cym  = ds_depart.Tables[0].Rows[0]["单位曾用名全称"].ToString().Trim();



                int j = 0;

                //string DocPath = ConfigurationManager.AppSettings["DocPath"].ToString();
                string DocPath = Server.MapPath("../");



                string TemplateFile = "";
                //if (hpxs == "环评书")
                TemplateFile = DocPath + "BaseData\\template\\qydjtemplate.doc";
                //else if (hpxs == "环评表")
                //    TemplateFile = DocPath + "\\template\\template_pf_nocs.doc";

                //生成的具有模板样式的新文件
                string FileName = DocPath + "BaseData\\" + oid.ToString() + ".doc";

                File.Copy(TemplateFile, FileName);


                object Obj_FileName = FileName;

                object Visible = false;

                object ReadOnly = false;

                //PageSetupDialog dlgPageSetup = new PageSetupDialog();

                //打开文件
                //WORD程序不可见
                app.Visible = false;
                //不弹出警告框
                app.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;

                //先保存默认的打印机
                string defaultPrinter = app.ActivePrinter;



                doc = app.Documents.Open(ref Obj_FileName,

                                         ref missing, ref ReadOnly, ref missing,

                                         ref missing, ref missing, ref missing, ref missing,

                                         ref missing, ref missing, ref missing, ref Visible,

                                         ref missing, ref missing, ref missing,

                                         ref missing);

                doc.Activate();
                // 单位全称,企业地址,法人代表,机构代码,试用类型,COD,废水排放量,
                //string[] sqArr = { "departname", "address", "frdb", "jgdm", "sytype", "infectant1", "water", "infectant1nd", "infectant2", "infectant2nd", "remark" };


                foreach (Word.Bookmark bm in doc.Bookmarks)
                {
                    switch (bm.Name)
                    {
                    case "c_dwmc": bm.Select(); bm.Range.Text = departobj.departname.ToString(); break;

                    case "c_xxdz": bm.Select(); bm.Range.Text = departobj.address.ToString(); break;

                    case "c_frdm": bm.Select(); bm.Range.Text = departobj.frdm.ToString(); break;

                    case "c_ssjd": bm.Select(); bm.Range.Text = departobj.ssjd.ToString(); break;

                    case "c_yzbm": bm.Select(); bm.Range.Text = departobj.yzbm.ToString(); break;

                    case "c_czhm": bm.Select(); bm.Range.Text = departobj.czhm.ToString(); break;

                    case "c_dzyx": bm.Select(); bm.Range.Text = departobj.dzyx.ToString(); break;

                    case "c_sczt": bm.Select(); bm.Range.Text = departobj.sczt.ToString(); break;

                    case "c_hy": bm.Select(); bm.Range.Text = departobj.hy.ToString(); break;

                    case "c_frdb": bm.Select(); bm.Range.Text = departobj.fddb.ToString(); break;

                    case "c_frdh": bm.Select(); bm.Range.Text = departobj.frdh.ToString(); break;

                    case "c_frsj": bm.Select(); bm.Range.Text = departobj.frsj.ToString(); break;

                    case "c_frsfw": bm.Select(); bm.Range.Text = departobj.frsfw.ToString(); break;

                    case "c_fgr": bm.Select(); bm.Range.Text = departobj.fgr.ToString(); break;

                    case "c_fgrdh": bm.Select(); bm.Range.Text = departobj.fgdh.ToString(); break;

                    case "c_fgrsj": bm.Select(); bm.Range.Text = departobj.fgsj.ToString(); break;

                    case "c_fgrsfw": bm.Select(); bm.Range.Text = departobj.fgsfw.ToString(); break;

                    case "c_zrr": bm.Select(); bm.Range.Text = departobj.fzr.ToString(); break;

                    case "c_zrrdh": bm.Select(); bm.Range.Text = departobj.fzdh.ToString(); break;

                    case "c_zrrsj": bm.Select(); bm.Range.Text = departobj.fzrsj.ToString(); break;

                    case "c_zrrsfw": bm.Select(); bm.Range.Text = departobj.fzrsfw.ToString(); break;

                    case "c_wsrw": bm.Select(); bm.Range.Text = departobj.wsrw.ToString(); break;

                    case "c_wsrwsj": bm.Select(); bm.Range.Text = departobj.rwsj.ToString(); break;

                    case "c_jzgr": bm.Select(); bm.Range.Text = departobj.jzgr.ToString(); break;

                    case "c_jzgrsj": bm.Select(); bm.Range.Text = departobj.grsj.ToString(); break;

                    case "c_yyzzfw": bm.Select(); bm.Range.Text = departobj.yyzzfw.ToString(); break;

                    case "c_jncp": bm.Select(); bm.Range.Text = departobj.jncp.ToString(); break;

                    case "c_jcsj": bm.Select(); bm.Range.Text = departobj.jcsj.ToString(); break;

                    case "c_cym": bm.Select(); bm.Range.Text = departobj.cym.ToString(); break;
                    }
                }



                doc.Save();



                object Background = true;
                //doc.PrintPreview();
                //doc.PrintOut(ref Background, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);



                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "", "window.open('" + oid.ToString() + ".doc','theNewWindow',' left=0,top=0,width='+ (screen.availWidth - 10) +',height='+ (screen.availHeight-50) +',scrollbars,resizable=yes,toolbar=no')", true);
            }
        }
        catch (Exception mes)
        {
            //ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "", "alert('打印机连接失败!请先测试打印机连接状态!')", true);



            Log.log alog = new Log.log();
            alog.Log(mes.Message.ToString() + DateTime.Now.ToString());
        }
        finally
        {
            doc.Close(ref IsSave, ref missing, ref missing);
            app.Application.Quit(ref missing, ref missing, ref missing);
            doc = null;
            app = null;
        }
    }
    private void print(List <Entity.Sample> samplelist, int num)
    {
        try
        {
            RemoveFiles(Server.MapPath(".") + "\\temp\\");
        }
        catch (Exception e)
        {
            Log.log alog = new Log.log();
            alog.Log(e.Message.ToString() + DateTime.Now.ToString());
        }

        try
        {
            Random           rd      = new Random();
            int              oid     = rd.Next(10000);
            Word.Application app     = new Word.Application();
            Word.Document    doc     = new Document();
            object           missing = System.Reflection.Missing.Value;


            object IsSave = true;
            try
            {
                string DocPath = Server.MapPath("../");



                string TemplateFile = "";

                TemplateFile = DocPath + "Sample\\template\\SampleTemplate0.doc";


                //生成的具有模板样式的新文件
                string FileName = DocPath + "Sample\\temp\\" + oid.ToString() + ".doc";

                File.Copy(TemplateFile, FileName);


                object Obj_FileName = FileName;

                object Visible = false;

                object ReadOnly = false;



                //打开文件

                doc = app.Documents.Open(ref Obj_FileName,

                                         ref missing, ref ReadOnly, ref missing,

                                         ref missing, ref missing, ref missing, ref missing,

                                         ref missing, ref missing, ref missing, ref Visible,

                                         ref missing, ref missing, ref missing,

                                         ref missing);

                doc.Activate();

                for (int j = 1; j <= samplelist.Count; j++)
                {
                    //找书签,赋值
                    //    //样品编号
                    object name = "SampleID1_" + (j + num);
                    if (doc.Bookmarks.Exists(name.ToString()) == true)
                    {
                        Word.Bookmark itemstr = doc.Bookmarks.get_Item(ref name);
                        itemstr.Select();
                        itemstr.Range.Text = samplelist[j - 1].SampleID;
                    }

                    //项目名称
                    object ProjectName = "ProjectName1_" + (j + num);
                    if (doc.Bookmarks.Exists(ProjectName.ToString()) == true)
                    {
                        Word.Bookmark itemstr = doc.Bookmarks.get_Item(ref ProjectName);
                        itemstr.Select();
                        itemstr.Range.Text = samplelist[j - 1].projectname;
                        // break;
                    }
                    //样品性状
                    object Profile = "Profile1_" + (j + num);
                    if (doc.Bookmarks.Exists(Profile.ToString()) == true)
                    {
                        Word.Bookmark itemstr = doc.Bookmarks.get_Item(ref Profile);
                        itemstr.Select();
                        itemstr.Range.Text = samplelist[j - 1].SampleProperty;
                        //break;
                    }
                    //样品性状
                    object SampleDate = "SampleDate1_" + (j + num);
                    if (doc.Bookmarks.Exists(SampleDate.ToString()) == true)
                    {
                        Word.Bookmark itemstr = doc.Bookmarks.get_Item(ref SampleDate);
                        itemstr.Select();
                        itemstr.Range.Text = samplelist[j - 1].SampleDate.ToString("yyyy-MM-dd");
                        // break;
                    }
                    //for (int p = 1; p <= samplelist[j - 1].SampleItemList.Count; p++)
                    //{
                    object Item = "ListItem" + (j + num);
                    if (doc.Bookmarks.Exists(Item.ToString()) == true)
                    {
                        Word.Bookmark itemstr = doc.Bookmarks.get_Item(ref Item);
                        itemstr.Select();
                        object type     = @"Excel.Sheet.8";
                        object filename = @DocPath + "Sample\\template\\SampleTemplate.xls";;
                        // TemplateFile = DocPath + "Sample\\template\\SampleTemplate.doc";
                        //app.Selection.InlineShapes[1].OLEFormat.Edit();
                        //object Mychart = app.Selection.InlineShapes[1].OLEFormat.Object;
                        object range = itemstr.Range;

                        app.Selection.InlineShapes.AddOLEObject(ref type, ref filename, ref missing, ref missing, ref missing, ref missing, ref missing, ref range);
                    }
                    //}
                }
                doc.Save();

                doc.Close(ref IsSave, ref missing, ref missing);
                app.Application.Quit(ref missing, ref missing, ref missing);

                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "", "window.open('temp/" + oid.ToString() + ".doc','theNewWindow',' left=0,top=0,width='+ (screen.availWidth - 10) +',height='+ (screen.availHeight-50) +',scrollbars,resizable=yes,toolbar=no')", true);
            }
            catch (Exception mes)
            {
                doc.Close(ref IsSave, ref missing, ref missing);
                app.Application.Quit(ref missing, ref missing, ref missing);
                Log.log alog = new Log.log();
                alog.Log(mes.Message.ToString() + DateTime.Now.ToString());
            }
        }
        catch (Exception mes)
        {
            Log.log alog = new Log.log();
            alog.Log(mes.Message.ToString() + DateTime.Now.ToString());
        }
    }
Exemplo n.º 5
0
    protected void btn_print_Click(object sender, EventArgs e)
    {
        try
        {
            RemoveFiles(Server.MapPath(".") + "\\");
        }
        catch { }

        Random rd  = new Random();
        int    oid = rd.Next(10000);

        string id      = strReportId;
        string sql_sel = "SELECT hanNO,hContent,hcreatedate,wtdepart 单位全称,Projectname,hfwdw,hcs  FROM t_Y_FlowInfo  where  t_Y_FlowInfo.id= '" + id + "'";

        // string sql_sel = "SELECT hanNO,hContent,hcreatedate,单位全称,Projectname,hfwdw,hcs  FROM t_Y_FlowInfo inner join t_委托单位 on t_委托单位.type=0 and t_委托单位.id=wtdepart where  t_Y_FlowInfo.id= '" + id + "'";
        DataSet ds_sel = new MyDataOp(sql_sel).CreateDataSet();

        if (ds_sel.Tables[0].Rows.Count > 0)
        {
            int    i           = ds_sel.Tables[0].Rows[0]["hanNO"].ToString().LastIndexOf('〕');
            string xmbh_1      = ds_sel.Tables[0].Rows[0]["hanNO"].ToString().Substring(i - 4, 4);
            string xmbh_2      = ds_sel.Tables[0].Rows[0]["hanNO"].ToString().Substring(i + 1);
            string zgyj        = ds_sel.Tables[0].Rows[0]["hContent"].ToString();
            string xmmc        = ds_sel.Tables[0].Rows[0]["Projectname"].ToString();
            string dwmc        = ds_sel.Tables[0].Rows[0]["单位全称"].ToString();
            string fwrq        = string.Empty;
            string fwrqChinese = string.Empty;
            if (ds_sel.Tables[0].Rows[0][2].ToString().Trim() != null && ds_sel.Tables[0].Rows[0][2].ToString().Trim() != "")
            {
                fwrq        = DateTime.Parse(ds_sel.Tables[0].Rows[0][2].ToString()).ToString("yyyy年MM月dd日");
                fwrqChinese = DateConvert(DateTime.Parse(ds_sel.Tables[0].Rows[0][2].ToString()).ToString("yyyy-M-d"));
            }
            string fwr = ds_sel.Tables[0].Rows[0]["hfwdw"].ToString();
            string cs  = ds_sel.Tables[0].Rows[0]["hcs"].ToString();
            //string ztc = ds_sel.Tables[0].Rows[0][7].ToString();
            //string fwjg = ds_sel.Tables[0].Rows[0][8].ToString();
            //string fsdx = ds_sel.Tables[0].Rows[0][9].ToString();

            try
            {
                string DocPath = Server.MapPath("./");// ConfigurationManager.AppSettings["DocPath"].ToString();
                //string DocPath = "E:\\桐乡环保审批\\WebApp\\txsp\\Query\\";

                Word.Application app          = new Word.Application();
                string           TemplateFile = DocPath + "\\template\\template_zg.doc";

                //生成的具有模板样式的新文件
                string FileName = DocPath + "\\temp\\" + oid.ToString() + ".doc";

                File.Copy(TemplateFile, FileName);

                Word.Document doc = new Word.Document();

                object Obj_FileName = FileName;

                object Visible = false;

                object ReadOnly = false;

                object missing = System.Reflection.Missing.Value;

                //打开文件
                object IsSave = true;
                try
                {
                    doc = app.Documents.Open(ref Obj_FileName,

                                             ref missing, ref ReadOnly, ref missing,

                                             ref missing, ref missing, ref missing, ref missing,

                                             ref missing, ref missing, ref missing, ref Visible,

                                             ref missing, ref missing, ref missing,

                                             ref missing);

                    doc.Activate();
                    // throw new Exception("test");
                }
                catch (Exception exp)
                {
                    Log.log a = new Log.log();
                    a.Log("文档打开" + exp.ToString());
                    doc.Close(ref IsSave, ref missing, ref missing);
                    app.Application.Quit(ref missing, ref missing, ref missing);
                    NAR(doc);
                    NAR(app);
                    return;
                }

                string[] sqArr      = { "sq_xmbh_1", "sq_xmbh_2", "sq_xmmc", "sq_zgyj", "sq_date", "sq_cs", "sq_fsdx", "sq_fwdw" };
                string[] replaceArr = { xmbh_1, xmbh_2, xmmc, zgyj, fwrq, cs, dwmc, fwr };


                foreach (Word.Bookmark bm in doc.Bookmarks)
                {
                    switch (bm.Name)
                    {
                    case "sq_xmbh_1": bm.Select(); bm.Range.Text = replaceArr[0].ToString(); break;

                    case "sq_xmbh_2": bm.Select(); bm.Range.Text = replaceArr[1].ToString(); break;

                    case "sq_xmmc": bm.Select(); bm.Range.Text = replaceArr[2].ToString(); break;

                    case "sq_zgyj": bm.Select(); bm.Range.Text = replaceArr[3].ToString(); break;

                    case "sq_date": bm.Select(); bm.Range.Text = replaceArr[4].ToString(); break;

                    case "sq_cs": bm.Select(); bm.Range.Text = replaceArr[5].ToString(); break;

                    case "sq_fsdx": bm.Select(); bm.Range.Text = replaceArr[6].ToString(); break;

                    case "sq_fwdw": bm.Select(); bm.Range.Text = replaceArr[7].ToString(); break;
                    }
                }


                doc.Close(ref IsSave, ref missing, ref missing);
                app.Application.Quit(ref missing, ref missing, ref missing);
                NAR(doc);
                NAR(app);
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "", "window.open('temp/" + oid.ToString() + ".doc','theNewWindow',' left=0,top=0,width='+ (screen.availWidth - 10) +',height='+ (screen.availHeight-50) +',scrollbars,resizable=yes,toolbar=no')", true);
                // ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "", "window.open('" + oid.ToString() + ".doc','theNewWindow',' left=0,top=0,width='+ (screen.availWidth - 10) +',height='+ (screen.availHeight-50) +',scrollbars,resizable=yes,toolbar=no')", true);
            }
            catch (Exception exp)
            {
                Log.log a = new Log.log();
                a.Log("标签替换" + exp.ToString());
            }
        }
    }