Update.aspx.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 Update : 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. if (Request.Params["id"] != null || Request.Params["id"].Trim() != "")
  23. {
  24. string id = Request.Params["id"];
  25. ShowInfo(int.Parse(id));
  26. }
  27. }
  28. }
  29. protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
  30. {
  31. SetDDLChild(DropDownList1.SelectedValue);
  32. }
  33. //更新
  34. protected void btnAdd_Click(object sender, EventArgs e)
  35. {
  36. DateTime dt = DateTime.Now;
  37. string filename = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + ".jpg";
  38. try
  39. {
  40. //如果有上传的文件则更新上传,没有则不修改
  41. if (FileUpload1.PostedFile.FileName != null && FileUpload1.PostedFile.FileName.ToString() != "")
  42. {
  43. this.UpFiles(filename);
  44. }
  45. if (Request.Params["id"] != null || Request.Params["id"].Trim() != "")
  46. {
  47. string id = Request.Params["id"];
  48. UpData(int.Parse(id), filename);
  49. }
  50. //this.Add();
  51. Response.Write("<script>alert('更新成功!');window.navigate('List.aspx')</script>");
  52. }
  53. catch
  54. {
  55. Response.Write("<script>alert('数据更新失败!');</script>");
  56. }
  57. }
  58. #region
  59. /// <summary>
  60. /// 显示药品详情
  61. /// </summary>
  62. /// <param name="id"></param>
  63. private void ShowInfo(int id)
  64. {
  65. Com.Jpsoft.Hospital.BLL.jp_druginfo bll = new Com.Jpsoft.Hospital.BLL.jp_druginfo();
  66. Com.Jpsoft.Hospital.Model.jp_druginfo model = bll.GetModel(id);
  67. this.txtdrugname.Value = model.drugname;
  68. this.txtbusinessname.Value = model.businessname;
  69. Com.Jpsoft.Hospital.BLL.jp_drugtype tpbll = new Com.Jpsoft.Hospital.BLL.jp_drugtype();
  70. Com.Jpsoft.Hospital.Model.jp_drugtype tpmode = tpbll.GetModel(model.drugtype);
  71. DropDownList1.SelectedValue = tpmode.fatherid.ToString();
  72. SetDDLChild(tpmode.fatherid.ToString());
  73. this.DropDownList2.SelectedValue = model.drugtype.ToString();
  74. this.txtapprovalnumber.Value = model.approvalnumber;
  75. this.txtstandard.Value = model.standard;
  76. this.txtmanufacturer.Value = model.manufacturer;
  77. this.txtcompany.Value = model.company;
  78. this.txtintroduction.Value = model.introduction;
  79. this.txtgoodinfo.Value = model.goodinfo;
  80. //this.txtimgpath.Value = model.imgpath;
  81. this.txtingredients.Value = model.ingredients;
  82. this.txttraits.Value = model.traits;
  83. this.txtusedosage.Value = model.usedosage;
  84. this.txtdrugaffect.Value = model.drugaffect;
  85. this.txtfunctions.Value = model.functions;
  86. this.txtbadreaction.Value = model.badreaction;
  87. this.txttaboo.Value = model.taboo;
  88. this.txtnotice.Value = model.notice;
  89. this.txtvalidity.Value = model.validity;
  90. this.txtpy.Value = model.py;
  91. }
  92. private void UpData(int id,string filename)
  93. {
  94. Com.Jpsoft.Hospital.BLL.jp_druginfo bll = new Com.Jpsoft.Hospital.BLL.jp_druginfo();
  95. Com.Jpsoft.Hospital.Model.jp_druginfo mode = new Com.Jpsoft.Hospital.Model.jp_druginfo();
  96. mode.drugname = txtdrugname.Value;
  97. mode.businessname = txtbusinessname.Value;
  98. mode.drugtype = int.Parse(DropDownList2.SelectedValue);
  99. mode.approvalnumber = txtapprovalnumber.Value;
  100. mode.standard = txtstandard.Value;
  101. mode.manufacturer = txtstandard.Value;
  102. mode.company = this.txtcompany.Value;
  103. mode.introduction = this.txtintroduction.Value;
  104. mode.goodinfo = this.txtgoodinfo.Value;
  105. //mode.imgpath = this.FileUpload1.FileName;
  106. mode.ingredients = this.txtingredients.Value;
  107. mode.traits = this.txttraits.Value;
  108. mode.usedosage = this.txtusedosage.Value;
  109. mode.drugaffect = this.txtdrugaffect.Value;
  110. mode.functions = this.txtfunctions.Value;
  111. mode.badreaction = this.txtbadreaction.Value;
  112. mode.taboo = this.txttaboo.Value;
  113. mode.notice = this.txtnotice.Value;
  114. mode.validity = this.txtvalidity.Value;
  115. mode.py = this.txtpy.Value;
  116. mode.id = id;
  117. if (FileUpload1.PostedFile.FileName != null && FileUpload1.PostedFile.FileName.ToString() != "")
  118. {
  119. mode.imgpath = filename;
  120. }
  121. else
  122. {
  123. Com.Jpsoft.Hospital.Model.jp_druginfo model = bll.GetModel(id);
  124. mode.imgpath = model.imgpath;
  125. }
  126. bll.Update(mode);
  127. }
  128. /// <summary>
  129. /// 文件上传
  130. /// </summary>
  131. /// <param name="path">上传文件名称</param>
  132. private void UpFiles(string filename)
  133. {
  134. if (FileUpload1.PostedFile.FileName != null)
  135. {
  136. try
  137. {
  138. #region
  139. if (FileUpload1.PostedFile.ContentLength > 1024 * 1024 * 6)
  140. {
  141. Response.Write("<script>alert('文件不能超过规定大小!');</script>");
  142. }
  143. else
  144. {
  145. #region
  146. string filetype = System.IO.Path.GetExtension(FileUpload1.PostedFile.FileName).ToUpper();
  147. if (filetype == ".JPG")
  148. {
  149. string m_SavePath = Server.MapPath("../../Upload/drugimg/") + filename;
  150. FileUpload1.PostedFile.SaveAs(m_SavePath);
  151. //Response.Write("<script>alert('文件保存成功!');</script>");
  152. }
  153. else
  154. {
  155. Response.Write("<script>alert('文件格式不正确,请选择JPG文件!');</script>");
  156. }
  157. #endregion
  158. }
  159. #endregion
  160. }
  161. catch (Exception m_Ex)
  162. {
  163. Response.Write("<script>alert('文件上传失败!');</script>");
  164. }
  165. }
  166. }
  167. /// <summary>
  168. /// 绑定父类别
  169. /// </summary>
  170. private void SetDDL()
  171. {
  172. Jpsoft.Hospital.BLL.jp_drugtype bll = new Com.Jpsoft.Hospital.BLL.jp_drugtype();
  173. DataTable dt = bll.GetList(" fatherid=0 ").Tables[0];
  174. for (int i = 0; i < dt.Rows.Count; i++)
  175. {
  176. DropDownList1.Items.Add(new ListItem(dt.Rows[i]["typename"].ToString(), dt.Rows[i]["id"].ToString()));
  177. }
  178. DropDownList1.Items.Insert(0, new ListItem("--请选择一级类别--", "0"));
  179. }
  180. /// <summary>
  181. /// 绑定子类别
  182. /// </summary>
  183. private void SetDDLChild(string id)
  184. {
  185. string where = string.Empty;
  186. if (id != "" )
  187. {
  188. where = " fatherid='" + id + "' ";
  189. }
  190. DropDownList2.Items.Clear();
  191. if (DropDownList1.SelectedValue != "0")
  192. {
  193. Jpsoft.Hospital.BLL.jp_drugtype bll = new Com.Jpsoft.Hospital.BLL.jp_drugtype();
  194. DataTable dt = bll.GetList(where).Tables[0];
  195. for (int i = 0; i < dt.Rows.Count; i++)
  196. {
  197. DropDownList2.Items.Add(new ListItem(dt.Rows[i]["typename"].ToString(), dt.Rows[i]["id"].ToString()));
  198. }
  199. }
  200. DropDownList2.Items.Insert(0, new ListItem("--请选择一级类别--", "0"));
  201. }
  202. #endregion
  203. }
  204. }