zoukankan      html  css  js  c++  java
  • 动态查询后绑定数据到水晶报表(这是收藏版,有待自个完善)

    protected void getData()
        {
            string workid = this.gonghaoTxt.Text;
            if (!workid.Equals(String.Empty))
            {
                //先查询人事资料
                string sql1 = "select top 1 EMPID,NAME,SEX,DEPNAME,SEGNAME,EMPSIZE,convert(varchar(10),ENT_DATE,23)as ENT_DATE from";
                if (RadioButton3.Checked) sql1 = sql1 + " kqempe";
                else sql1 = sql1 + " kqdime";
                sql1 = sql1 + " kqempe where empid='" + workid + "'";
                DataTable dt1 = new DataTable("kqEMPE");
                ConnectSQL sqlconn = new ConnectSQL();
                dt1 = sqlconn.SearchHRS(sql1);
                //查询培训记录
                string sql2 = "select * FROM PXVIEW where workid='" + workid + "' order by workdate asc";
                DataTable dt2 = new DataTable("PXVIEW");
                dt2 = sqlconn.SearchHRS(sql2);
                if (dt2.Rows.Count > 0)
                {
                    this.result.Text = "";
                    this.CrystalReportViewer1.Visible = true;
                    string fact = Session["Factory"].ToString();//所在厂区
                    string serverName = "";//服务器地址
                    string DBname = "";//数据库
                    string username = "";//帐号
                    string userpwd = "";//密码
                    switch (fact)
                    {
                        case "SMD": serverName = "192.168.2.12"; DBname = "HRSD"; username = "fkqe"; userpwd = "kqef"; break;
                        case "XFE": serverName = "192.168.2.12"; DBname = "HRSF"; username = "fkqe"; userpwd = "kqef"; break;
                        case "XTE": serverName = "192.168.2.12"; DBname = "HRSZ"; username = "fkqe"; userpwd = "kqef"; break;
                        case "SMX": serverName = "192.168.50.31"; DBname = "HRSX"; username = "fkqe"; userpwd = "kqef"; break;
                    }
                    string strPath = Server.MapPath("EachTrainReport.rpt");
                    ReportDocument rd = new ReportDocument();
                    rd.Load(strPath);
                    rd.SetDataSource(dt2);
                    TextObject nameTxt = rd.ReportDefinition.ReportObjects["nameTxt"] as TextObject;
                    TextObject gonghaoTxt = rd.ReportDefinition.ReportObjects["gonghaoTxt"] as TextObject;
                    TextObject entdateTxt = rd.ReportDefinition.ReportObjects["entdateTxt"] as TextObject;
                    TextObject empsizeTxt = rd.ReportDefinition.ReportObjects["empsizeTxt"] as TextObject;
                    TextObject depnameTxt = rd.ReportDefinition.ReportObjects["depnameTxt"] as TextObject;
                    TextObject sextxt = rd.ReportDefinition.ReportObjects["sextxt"] as TextObject;
                    TextObject segnameTxt = rd.ReportDefinition.ReportObjects["segnameTxt"] as TextObject;
                    //将员工资料显示到报表中的文本框
                    if (dt1.Rows.Count > 0)
                    {
                        nameTxt.Text = dt1.Rows[0]["NAME"].ToString(); gonghaoTxt.Text = dt1.Rows[0]["EMPID"].ToString(); entdateTxt.Text = dt1.Rows[0]["ENT_DATE"].ToString();
                        empsizeTxt.Text = dt1.Rows[0]["EMPSIZE"].ToString(); depnameTxt.Text = dt1.Rows[0]["DEPNAME"].ToString(); sextxt.Text = dt1.Rows[0]["SEX"].ToString();
                        segnameTxt.Text = dt1.Rows[0]["SEGNAME"].ToString();
                    }
                    rd.Refresh();
                    TableLogOnInfo logOnInfo = new TableLogOnInfo();
                    // 对报表中的每个表依次循环。 
                    for (int i = 0; i < rd.Database.Tables.Count; i++)
                    {
                        logOnInfo.ConnectionInfo.ServerName = serverName;
                        logOnInfo.ConnectionInfo.DatabaseName = DBname;
                        logOnInfo.ConnectionInfo.UserID = username;
                        logOnInfo.ConnectionInfo.Password = userpwd;
                        rd.Database.Tables[i].ApplyLogOnInfo(logOnInfo);
                    }
                    this.CrystalReportViewer1.ReportSource = rd;
                }
                else
                {
                    this.result.Text = "该员工暂无培训记录";
                    this.CrystalReportViewer1.Visible = false;
                }
            }
        }
  • 相关阅读:
    第一次实习项目总结
    javascript整理笔记(一)-----写项目的小技巧
    Vue(项目踩坑)_These dependencies were not found: * !!vue-style-loader!css-loader?{"sourceMap":true}!../../../node_modules/vue-loader/lib/style-compiler/index?{"vue"
    JS(递归-记一次面试题)-写一个get函数,get({a:1}, 'a')输出1,get({a : {b:2}},‘a.b’)输出2,按照此规律写一个函数
    html5_音视频的兼容性写法
    canvas_画出图片的马赛克
    项目(踩坑)_移动端在使用touch滑动事件的时候会出现抖动现象
    vue+mongoose+node.js项目总结第七篇_express框架中使用socket.io插件实现在线聊天功能(前端消息发送-后端接收逻辑)
    网址
    RAII Theory && auto_ptr
  • 原文地址:https://www.cnblogs.com/lvk618/p/3339231.html
Copyright © 2011-2022 走看看