private void BindGrid(string staffname,int positionid,string mobile,string email,string gender,int[] displayfiledsid) { SqlDataReader dr; UDS.Components.Staff staff = new UDS.Components.Staff(); dr = staff.Find(staffname,positionid,mobile,email,gender,bound); DataTable dt = UDS.Components.Tools.ConvertDataReaderToDataTable(dr); if(ViewState["sortfield"]!=null) dt.DefaultView.Sort = ViewState["sortfield"] + " " + ViewState["sortdirect"]; dgrd_StaffList.DataSource = dt.DefaultView; //������ٻ����б��ڴ�ӡ Cache["StaffList"] = dt; for(int i=0;i<displayfieldsid.Length;i++) { dgrd_StaffList.Columns[displayfiledsid[i]].Visible = true; } dgrd_StaffList.DataBind(); }
private void BindGrid(string staffname, int positionid, string mobile, string email, string gender, int[] displayfiledsid) { SqlDataReader dr; UDS.Components.Staff staff = new UDS.Components.Staff(); dr = staff.Find(staffname, positionid, mobile, email, gender, bound); DataTable dt = UDS.Components.Tools.ConvertDataReaderToDataTable(dr); if (ViewState["sortfield"] != null) { dt.DefaultView.Sort = ViewState["sortfield"] + " " + ViewState["sortdirect"]; } dgrd_StaffList.DataSource = dt.DefaultView; //放入高速缓存中便于打印 Cache["StaffList"] = dt; for (int i = 0; i < displayfieldsid.Length; i++) { dgrd_StaffList.Columns[displayfiledsid[i]].Visible = true; } dgrd_StaffList.DataBind(); }
private void Page_Load(object sender, System.EventArgs e) { ds = new StaffDataSet(); DataTable dt =(DataTable)Cache["StaffList"]; if(!Page.IsPostBack) { staffname = Session["staffname"].ToString(); positionid = Int32.Parse(Session["positionid"].ToString()); mobile = Session["mobile"].ToString(); email = Session["email"].ToString(); gender = Session["gender"].ToString(); dept = Session["dept"].ToString(); bound = Session["bound"].ToString(); displayfields = (string[])Session["displayfieldsname"]; ViewState["staffname"] = staffname; ViewState["positionid"] = positionid.ToString(); ViewState["mobile"] = mobile.ToString(); ViewState["email"] = email.ToString(); ViewState["gender"] = gender.ToString(); ViewState["dept"] = dept.ToString(); ViewState["bound"] = bound.ToString(); ViewState["displayfields"] = displayfields; Session["staffname"] = null; Session["positionid"] = null; Session["mobile"] = null; Session["gender"] = null; Session["dept"] = null; Session["displayfieldsname"] = null; Session["bound"] = null; } else { staffname = ViewState["staffname"].ToString(); positionid = Int32.Parse(ViewState["positionid"].ToString()); mobile = ViewState["mobile"].ToString(); email = ViewState["email"].ToString(); gender = ViewState["gender"].ToString(); dept = ViewState["dept"].ToString(); bound = ViewState["bound"].ToString(); displayfields = (string[])ViewState["displayfields"]; } if(dt==null) { //�ò�����������ݣ����»�ȡ SqlDataReader dr; UDS.Components.Staff staff = new UDS.Components.Staff(); dr = staff.Find(staffname, positionid, mobile, email, gender, dept,bound); dt = UDS.Components.Tools.ConvertDataReaderToDataTable(dr); Cache["StaffList"] = dt; } //���datatable�е����� foreach(DataRow row in dt.Rows) { DataRow staffviewrow = ds.StaffView.NewRow(); staffviewrow["Staff_Name"] = row["Staff_Name"].ToString(); staffviewrow["RealName"] = row["RealName"].ToString(); staffviewrow["Mobile"] = row["Mobile"].ToString(); staffviewrow["SexName"] = row["SexName"].ToString(); staffviewrow["Email"] = row["Email"].ToString(); staffviewrow["Position_Name"] = row["Position_Name"].ToString(); ds.StaffView.AddStaffViewRow((StaffDataSet.StaffViewRow)staffviewrow); } stafflistreport = new StaffList(); stafflistreport.SetDataSource(ds); crv_StaffList.ReportSource = stafflistreport; //�����û�ѡ�������ֶ� foreach(string fieldname in displayfields) { stafflistreport.ReportDefinition.ReportObjects["ttl"+fieldname].ObjectFormat.EnableSuppress = false; stafflistreport.ReportDefinition.ReportObjects[fieldname].ObjectFormat.EnableSuppress = false; } crv_StaffList.DataBind(); }
private void Page_Load(object sender, System.EventArgs e) { ds = new StaffDataSet(); DataTable dt = (DataTable)Cache["StaffList"]; if (!Page.IsPostBack) { staffname = Session["staffname"].ToString(); positionid = Int32.Parse(Session["positionid"].ToString()); mobile = Session["mobile"].ToString(); email = Session["email"].ToString(); gender = Session["gender"].ToString(); bound = Session["bound"].ToString(); displayfields = (string[])Session["displayfieldsname"]; ViewState["staffname"] = staffname; ViewState["positionid"] = positionid.ToString(); ViewState["mobile"] = mobile.ToString(); ViewState["email"] = email.ToString(); ViewState["gender"] = gender.ToString(); ViewState["bound"] = bound.ToString(); ViewState["displayfields"] = displayfields; Session["staffname"] = null; Session["positionid"] = null; Session["mobile"] = null; Session["gender"] = null; Session["displayfieldsname"] = null; Session["bound"] = null; } else { staffname = ViewState["staffname"].ToString(); positionid = Int32.Parse(ViewState["positionid"].ToString()); mobile = ViewState["mobile"].ToString(); email = ViewState["email"].ToString(); gender = ViewState["gender"].ToString(); bound = ViewState["bound"].ToString(); displayfields = (string[])ViewState["displayfields"]; } if (dt == null) { //得不到缓存的内容,重新获取 SqlDataReader dr; UDS.Components.Staff staff = new UDS.Components.Staff(); dr = staff.Find(staffname, positionid, mobile, email, gender, bound); dt = UDS.Components.Tools.ConvertDataReaderToDataTable(dr); Cache["StaffList"] = dt; } //添加datatable中的数据 foreach (DataRow row in dt.Rows) { DataRow staffviewrow = ds.StaffView.NewRow(); staffviewrow["Staff_Name"] = row["Staff_Name"].ToString(); staffviewrow["RealName"] = row["RealName"].ToString(); staffviewrow["Mobile"] = row["Mobile"].ToString(); staffviewrow["SexName"] = row["SexName"].ToString(); staffviewrow["Email"] = row["Email"].ToString(); staffviewrow["Position_Name"] = row["Position_Name"].ToString(); ds.StaffView.AddStaffViewRow((StaffDataSet.StaffViewRow)staffviewrow); } stafflistreport = new StaffList(); stafflistreport.SetDataSource(ds); crv_StaffList.ReportSource = stafflistreport; //根据用户选择隐藏字段 foreach (string fieldname in displayfields) { stafflistreport.ReportDefinition.ReportObjects["ttl" + fieldname].ObjectFormat.EnableSuppress = false; stafflistreport.ReportDefinition.ReportObjects[fieldname].ObjectFormat.EnableSuppress = false; } crv_StaffList.DataBind(); }