日期:2014-05-20 浏览次数:21037 次
//crs为数据源ReportDataSource protected void Button1_Click(object sender, EventArgs e) { try { TableLogOnInfo loginfo = new TableLogOnInfo(); loginfo.ConnectionInfo.ServerName = "10.8.2.31"; loginfo.ConnectionInfo.UserID = "sa"; loginfo.ConnectionInfo.Password = "moringstra"; DataTable repdt = new DataTable(); SetDateUserid(); GetSpdt(ref repdt, txtUserid, beginDate, enddate); crs.Report.FileName = "日报"; crs.ReportDocument.Load(Server.MapPath("Report/usp_DalayReoprt.rpt")); crs.ReportDocument.Database.Tables[0].ApplyLogOnInfo(loginfo); crs.ReportDocument.SetDataSource(repdt); crs.DataBind(); CrystalReportViewer1.ReportSource = crs; CrystalReportViewer1.DataBind(); } catch (Exception ex) { MessageBoxShow(ex.Message.ToString()); } } private DataTable GetSpdt(ref DataTable spdt,string seUserid,string BeginDate,string Enddate) { try { string Userid = (string)(Session["LoginUser"]); string UserAuthority = (string)(Session["Authority"]); UserAuthority = UserAuthority.Substring(1, UserAuthority.Length - 2); getscnstr(scn); OpenConn(scn); string sqlstr2 = "SELECT * FROM uvw_IsPrincipal WHERE FnAME='" + Userid + "' AND IsPrincipal=1 "; DataTable dt2 = acc.GetSereachData(scn, sqlstr2); if (dt2.Rows.Count == 0) { seUserid = Userid; } getscnstr(scn); OpenConn(scn); SqlCommand cmd = new SqlCommand(); cmd.CommandText = "usp_DalayReoprt"; cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = scn; cmd.Parameters.Add("@PositionCode", SqlDbType.VarChar); cmd.Parameters["@PositionCode"].Value = UserAuthority; cmd.Parameters.Add("@Code", SqlDbType.VarChar); cmd.Parameters["@Code"].Value = seUserid+"%"; cmd.Parameters.Add("@BeginDate", SqlDbType.VarChar); cmd.Parameters["@BeginDate"].Value = BeginDate; cmd.Parameters.Add("@EndDate", SqlDbType.VarChar); cmd.Parameters["@EndDate"].Value = Enddate; crs.ReportDocument.SetParameterValue("PositionCode", UserAuthority); crs.ReportDocument.SetParameterValue("BeginDate", BeginDate); crs.ReportDocument.SetParameterValue("EndDate", Enddate); SqlDataAdapter sda = new SqlDataAdapter(cmd); sda.Fill(spdt); return spdt; } catch (Exception ex) { MessageBoxShow(ex.ToString()); spdt = null; return spdt; } }