Insert.aspx.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. namespace Com.Jpsoft.Hospital.Web.Module.jp_druginfo
  14. {
  15. public partial class Insert : Com.Jpsoft.Hospital.Web.Common.BasePage//System.Web.UI.Page
  16. {
  17. protected void Page_Load(object sender, EventArgs e)
  18. {
  19. if (!IsPostBack)
  20. {
  21. SetDDL();
  22. }
  23. }
  24. //类别回调
  25. protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
  26. {
  27. SetDDLChild(DropDownList1.SelectedValue);
  28. }
  29. //添加
  30. protected void btnAdd_Click(object sender, EventArgs e)
  31. {
  32. DateTime dt = DateTime.Now;
  33. string filename = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + ".jpg";
  34. try
  35. {
  36. if (FileUpload1.PostedFile.FileName != null && FileUpload1.PostedFile.FileName.ToString()!="")
  37. {
  38. this.UpFiles(filename);
  39. }
  40. //this.Add();
  41. Response.Write("<script>alert('添加成功!');window.navigate('List.aspx')</script>");
  42. }
  43. catch
  44. {
  45. Response.Write("<script>alert('数据添加失败!');</script>");
  46. }
  47. }
  48. #region
  49. /// <summary>
  50. /// 添加数据
  51. /// </summary>
  52. private void Add(string filename)
  53. {
  54. Com.Jpsoft.Hospital.BLL.jp_druginfo bll = new Com.Jpsoft.Hospital.BLL.jp_druginfo();
  55. Com.Jpsoft.Hospital.Model.jp_druginfo mode = new Com.Jpsoft.Hospital.Model.jp_druginfo();
  56. mode.drugname = txtdrugname.Value;
  57. mode.businessname = txtbusinessname.Value;
  58. mode.drugtype = int.Parse(DropDownList2.SelectedValue);
  59. mode.approvalnumber = txtapprovalnumber.Value;
  60. mode.standard = txtstandard.Value;
  61. mode.manufacturer = txtstandard.Value;
  62. mode.company = this.txtcompany.Value;
  63. mode.introduction = this.txtintroduction.Value;
  64. mode.goodinfo = this.txtgoodinfo.Value;
  65. mode.imgpath = filename;
  66. mode.ingredients = this.txtingredients.Value;
  67. mode.traits = this.txttraits.Value;
  68. mode.usedosage = this.txtusedosage.Value;
  69. mode.drugaffect = this.txtdrugaffect.Value;
  70. mode.functions = this.txtfunctions.Value;
  71. mode.badreaction = this.txtbadreaction.Value;
  72. mode.taboo = this.txttaboo.Value;
  73. mode.notice = this.txtnotice.Value;
  74. mode.validity = this.txtvalidity.Value;
  75. mode.py = this.txtpy.Value;
  76. bll.Add(mode);
  77. }
  78. /// <summary>
  79. /// 文件上传
  80. /// </summary>
  81. /// <param name="path">上传文件名称</param>
  82. private void UpFiles(string filename)
  83. {
  84. if (FileUpload1.PostedFile.FileName != null)
  85. {
  86. try
  87. {
  88. #region
  89. if (FileUpload1.PostedFile.ContentLength > 1024 * 1024 * 6)
  90. {
  91. Response.Write("<script>alert('文件不能超过规定大小!');</script>");
  92. }
  93. else
  94. {
  95. #region
  96. string filetype = System.IO.Path.GetExtension(FileUpload1.PostedFile.FileName).ToUpper();
  97. if (filetype == ".JPG")
  98. {
  99. string m_SavePath = Server.MapPath("../../Upload/drugimg/") + filename;
  100. FileUpload1.PostedFile.SaveAs(m_SavePath);
  101. //Response.Write("<script>alert('文件保存成功!');</script>");
  102. this.Add(filename);
  103. }
  104. else
  105. {
  106. Response.Write("<script>alert('文件格式不正确,请选择JPG文件!');</script>");
  107. }
  108. #endregion
  109. }
  110. #endregion
  111. }
  112. catch (Exception m_Ex)
  113. {
  114. Response.Write("<script>alert('文件上传失败!');</script>");
  115. }
  116. }
  117. }
  118. /// <summary>
  119. /// 绑定父类别
  120. /// </summary>
  121. private void SetDDL()
  122. {
  123. Jpsoft.Hospital.BLL.jp_drugtype bll = new Com.Jpsoft.Hospital.BLL.jp_drugtype();
  124. DataTable dt = bll.GetList(" fatherid=0 ").Tables[0];
  125. for (int i = 0; i < dt.Rows.Count; i++)
  126. {
  127. DropDownList1.Items.Add(new ListItem(dt.Rows[i]["typename"].ToString(), dt.Rows[i]["id"].ToString()));
  128. }
  129. DropDownList1.Items.Insert(0, new ListItem("--请选择一级类别--", "0"));
  130. }
  131. /// <summary>
  132. /// 绑定子类别
  133. /// </summary>
  134. private void SetDDLChild(string id)
  135. {
  136. DropDownList2.Items.Clear();
  137. if (DropDownList1.SelectedValue!="0")
  138. {
  139. Jpsoft.Hospital.BLL.jp_drugtype bll = new Com.Jpsoft.Hospital.BLL.jp_drugtype();
  140. DataTable dt = bll.GetList(" fatherid='" + id + "' ").Tables[0];
  141. for (int i = 0; i < dt.Rows.Count; i++)
  142. {
  143. DropDownList2.Items.Add(new ListItem(dt.Rows[i]["typename"].ToString(), dt.Rows[i]["id"].ToString()));
  144. }
  145. }
  146. DropDownList2.Items.Insert(0, new ListItem("--请选择一级类别--", "0"));
  147. }
  148. #endregion
  149. }
  150. }