List.aspx.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using System.Collections;
  3. using System.Configuration;
  4. using System.Data;
  5. //using System.Linq;
  6. using System.Web;
  7. using System.Web.Security;
  8. using System.Web.UI;
  9. using System.Web.UI.HtmlControls;
  10. using System.Web.UI.WebControls;
  11. using System.Web.UI.WebControls.WebParts;
  12. //using System.Xml.Linq;
  13. using System.Text;
  14. namespace Com.Jpsoft.Hospital.Web.Module.jp_druginfo
  15. {
  16. //public partial class List : System.Web.UI.Page
  17. public partial class List : Com.Jpsoft.Hospital.Web.Common.BasePage
  18. {
  19. protected void Page_Load(object sender, EventArgs e)
  20. {
  21. if (!IsPostBack)
  22. {
  23. int id = 0;
  24. if (Request.QueryString["id"]!=null)
  25. {
  26. id = int.Parse(Request.QueryString["id"].ToString());
  27. this.Delete(id);
  28. }
  29. }
  30. BindData();
  31. }
  32. protected void btnselect_Click(object sender, EventArgs e)
  33. {
  34. string drugname = txtdrugname.Value.Trim();// GetSafeSql(txtdrugname.Value.Trim());
  35. StringBuilder strWhere = new StringBuilder();
  36. strWhere.Append(" where 1=1 ");
  37. if (drugname.Length != 0)
  38. {
  39. strWhere.Append(" and drugname like '%" + drugname + "%'");
  40. }
  41. ViewState["SearchTerms"] = strWhere.ToString();
  42. BindData();
  43. }
  44. protected void AspNetPager1_PageChanged(object sender, EventArgs e)
  45. {
  46. BindData();
  47. }
  48. #region
  49. /// <summary>
  50. /// 获得数据列表
  51. /// </summary>
  52. private void BindData()
  53. {
  54. int RecordCount = 0;
  55. string strWhere = " where 1=1 ";
  56. if (ViewState["SearchTerms"] != null)
  57. {
  58. strWhere = ViewState["SearchTerms"].ToString();
  59. }
  60. string strOrder = " order by id DESC";
  61. using (IDataReader idr = Com.Jpsoft.Hospital.DAL.jp_druginfoEx.SelectPage(AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, strWhere, strOrder))
  62. {
  63. if (idr.Read())
  64. {
  65. RecordCount = Convert.ToInt32(idr["RecordCount"]);
  66. }
  67. idr.NextResult();
  68. GridView1.DataSource = idr;
  69. GridView1.DataBind();
  70. }
  71. this.AspNetPager1.RecordCount = RecordCount;
  72. }
  73. /// <summary>
  74. /// 删除数据
  75. /// </summary>
  76. /// <param name="id"></param>
  77. private void Delete(int id)
  78. {
  79. Com.Jpsoft.Hospital.BLL.jp_druginfoEx bll = new Com.Jpsoft.Hospital.BLL.jp_druginfoEx();
  80. bll.Delete(id);
  81. Response.Write("<script>alert('删除成功!');window.navigate('List.aspx');</script>");
  82. }
  83. #endregion
  84. }
  85. }