工作单的基础界面布局好了,而对Gridview的Layout布局如下:
进入工作单默认加载的是“我创建的”数据,这里定义了一个变量btnMode,当btnMode为1时是“我创建的”的数据,btnMode为2时是“我审批的”数据;这里楼楼定义了一个Bind方法用来绑定数据,再在load事件中加载Bind方法。现在gridview便可展示“我创建的”数据,那么当数据较多的情况时,客户端加载速度就变慢了,在这种情况下数据需要进行分批加载,用到了UpSlippling(Gridview数据上拉事件)。
<span style="font-size:14px;">/// <summary> /// bind方法 /// </summary> /// <remarks></remarks> private void Bind() { try { switch (btnMode) { case 1: //我创建的 this.btnWorkDCreate.ForeColor = Drawing.Color.DeepSkyBlue; this.btnWorkDCheck.ForeColor = Drawing.Color.Gray; break; case 2: //我审批的 this.btnWorkDCreate.ForeColor = Drawing.Color.Gray; this.btnWorkDCheck.ForeColor = Drawing.Color.DeepSkyBlue; break; } pagesCount = GetNumber(); //获取我创建或我审批工作单的总条数 DataTable table = GetData(pageIndex); //我创建的或我审批的数据 if (table.Rows.Count > 0) { this.GridView1.DataSource = table; this.GridView1.DataBind(); } else { this.GridView1.Rows.Clear(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } </span>
<span style="font-size:14px;">/// <summary> /// GridView下拉事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <remarks></remarks> private void GridView1_UpSlippling(object sender, EventArgs e) { try { pageIndex += 1; if (pageIndex < pagesCount) { DataTable table = GetData(pageIndex); //分批工作单数据 if (table.Rows.Count > 0) { this.GridView1.AddData(table); } } else { MessageBox.Show("数据已加载完成!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } </span>
<span style="font-size:14px;">/// <summary> /// GridView点击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <remarks></remarks> private void GridView1_CellClick(object sender, GridViewCellEventArgs e) { try { string WDOC_NO = e.Cell.Items("lblNOTE").Value; //获取工作单编号 switch (btnMode) { case 1: frmWorkDocumentDetail frm = new frmWorkDocumentDetail(); frm.WDOC_NO = WDOC_NO; this.Redirect(frm); break; case 2: frmWorkDocumentDetail1 frm = new frmWorkDocumentDetail1(); frm.WDOC_NO = WDOC_NO; this.Redirect(frm, () => { if (frm.ShowResult == Smobiler.Core.ShowResult.Yes) { Bind(); } }); break; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } </span>
<span style="font-size:14px;">/// <summary> /// 工作单我创建的按钮事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <remarks></remarks> private void btnWorkDCreate_Click(object sender, EventArgs e) { btnMode = 1; Bind(); } /// <summary> /// 工作单我待审批的按钮事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <remarks></remarks> private void btnWorkDCheck_Click(object sender, EventArgs e) { btnMode = 2; Bind(); } </span>