1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| private void uiSySearch_Click(object sender, EventArgs e) { string txtSerach = this.txtSerach.Text.ToString().Trim();
if (txtSerach.Length > 0) { string strWhere = " GDGSI like '%" + txtSerach + "%' Or BDZHANG like '%" + txtSerach + "%'"; DataTable dt_Search = CreateNewDataTable(dt_Excele, strWhere);
DataTable dt_New = dt_Search.DefaultView.ToTable(false, new string[] { "XHAO", "GDGSI", "BDZHANG", "YXBHAO", "SBXHAO", "CHPTHAO", "CHPXHAO", "RLIANG", "EDDYA", "EDDLIU", "DLZKANG-H-M", "DLZKANG-H-L", "DLZKANG-M-L", "BYQXSHU", "PLV", "TXZHSHU" });
if (dt_New.Rows.Count > 0) { for (int i = 0; i < dt_New.Rows.Count; i++) { if (dt_New.Rows[i]["EDDLIU"].ToString().Trim().Length > 0) { dt_New.Rows[i]["EDDLIU"] = float.Parse(dt_New.Rows[i]["EDDLIU"].ToString()).ToString("F2"); } } this.gvShow.DataSource = dt_New; } else { DataTable table = dt_Excele.Clone(); table.NewRow(); table = table.DefaultView.ToTable(false, new string[] { "XHAO", "GDGSI", "BDZHANG", "YXBHAO", "SBXHAO", "CHPTHAO", "CHPXHAO", "RLIANG", "EDDYA", "EDDLIU", "DLZKANG-H-M", "DLZKANG-H-L", "DLZKANG-M-L", "BYQXSHU", "PLV", "TXZHSHU" }); gvShow.DataSource = table; } } else { DataBind(); } }
private void DataBind() { if (dt_Excele.Rows.Count > 0) { DataTable dt_New = dt_Excele.DefaultView.ToTable(false, new string[] { "XHAO", "GDGSI", "BDZHANG", "YXBHAO", "SBXHAO", "CHPTHAO", "CHPXHAO", "RLIANG", "EDDYA", "EDDLIU", "DLZKANG-H-M", "DLZKANG-H-L", "DLZKANG-M-L", "BYQXSHU", "PLV", "TXZHSHU" });
if (dt_New.Rows.Count > 0) { for (int i = 0; i < dt_New.Rows.Count; i++) { if (dt_New.Rows[i]["EDDLIU"].ToString().Trim().Length > 0) { dt_New.Rows[i]["EDDLIU"] = float.Parse(dt_New.Rows[i]["EDDLIU"].ToString()).ToString("F2"); } } this.gvShow.DataSource = dt_New; } else { this.gvShow.DataSource = null; } } }
|