123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- using System;
- using System.Collections;
- using System.Configuration;
- using System.Data;
- //using System.Linq;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.HtmlControls;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- //using System.Xml.Linq;
- namespace Com.Jpsoft.Hospital.Web.Module.jp_druginfo
- {
- public partial class Insert : Com.Jpsoft.Hospital.Web.Common.BasePage//System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- SetDDL();
- }
- }
- //类别回调
- protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
- {
- SetDDLChild(DropDownList1.SelectedValue);
- }
- //添加
- protected void btnAdd_Click(object sender, EventArgs e)
- {
- DateTime dt = DateTime.Now;
- string filename = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + ".jpg";
- try
- {
- if (FileUpload1.PostedFile.FileName != null && FileUpload1.PostedFile.FileName.ToString()!="")
- {
- this.UpFiles(filename);
- }
- //this.Add();
- Response.Write("<script>alert('添加成功!');window.navigate('List.aspx')</script>");
- }
- catch
- {
- Response.Write("<script>alert('数据添加失败!');</script>");
- }
- }
- #region
- /// <summary>
- /// 添加数据
- /// </summary>
- private void Add(string filename)
- {
- Com.Jpsoft.Hospital.BLL.jp_druginfo bll = new Com.Jpsoft.Hospital.BLL.jp_druginfo();
- Com.Jpsoft.Hospital.Model.jp_druginfo mode = new Com.Jpsoft.Hospital.Model.jp_druginfo();
- mode.drugname = txtdrugname.Value;
- mode.businessname = txtbusinessname.Value;
- mode.drugtype = int.Parse(DropDownList2.SelectedValue);
- mode.approvalnumber = txtapprovalnumber.Value;
- mode.standard = txtstandard.Value;
- mode.manufacturer = txtstandard.Value;
- mode.company = this.txtcompany.Value;
- mode.introduction = this.txtintroduction.Value;
- mode.goodinfo = this.txtgoodinfo.Value;
- mode.imgpath = filename;
- mode.ingredients = this.txtingredients.Value;
- mode.traits = this.txttraits.Value;
- mode.usedosage = this.txtusedosage.Value;
- mode.drugaffect = this.txtdrugaffect.Value;
- mode.functions = this.txtfunctions.Value;
- mode.badreaction = this.txtbadreaction.Value;
- mode.taboo = this.txttaboo.Value;
- mode.notice = this.txtnotice.Value;
- mode.validity = this.txtvalidity.Value;
- mode.py = this.txtpy.Value;
- bll.Add(mode);
- }
- /// <summary>
- /// 文件上传
- /// </summary>
- /// <param name="path">上传文件名称</param>
- private void UpFiles(string filename)
- {
- if (FileUpload1.PostedFile.FileName != null)
- {
- try
- {
- #region
- if (FileUpload1.PostedFile.ContentLength > 1024 * 1024 * 6)
- {
- Response.Write("<script>alert('文件不能超过规定大小!');</script>");
- }
- else
- {
- #region
- string filetype = System.IO.Path.GetExtension(FileUpload1.PostedFile.FileName).ToUpper();
- if (filetype == ".JPG")
- {
- string m_SavePath = Server.MapPath("../../Upload/drugimg/") + filename;
- FileUpload1.PostedFile.SaveAs(m_SavePath);
- //Response.Write("<script>alert('文件保存成功!');</script>");
- this.Add(filename);
- }
- else
- {
- Response.Write("<script>alert('文件格式不正确,请选择JPG文件!');</script>");
- }
- #endregion
- }
- #endregion
- }
- catch (Exception m_Ex)
- {
- Response.Write("<script>alert('文件上传失败!');</script>");
- }
- }
- }
- /// <summary>
- /// 绑定父类别
- /// </summary>
- private void SetDDL()
- {
- Jpsoft.Hospital.BLL.jp_drugtype bll = new Com.Jpsoft.Hospital.BLL.jp_drugtype();
- DataTable dt = bll.GetList(" fatherid=0 ").Tables[0];
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- DropDownList1.Items.Add(new ListItem(dt.Rows[i]["typename"].ToString(), dt.Rows[i]["id"].ToString()));
- }
- DropDownList1.Items.Insert(0, new ListItem("--请选择一级类别--", "0"));
- }
- /// <summary>
- /// 绑定子类别
- /// </summary>
- private void SetDDLChild(string id)
- {
- DropDownList2.Items.Clear();
- if (DropDownList1.SelectedValue!="0")
- {
- Jpsoft.Hospital.BLL.jp_drugtype bll = new Com.Jpsoft.Hospital.BLL.jp_drugtype();
- DataTable dt = bll.GetList(" fatherid='" + id + "' ").Tables[0];
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- DropDownList2.Items.Add(new ListItem(dt.Rows[i]["typename"].ToString(), dt.Rows[i]["id"].ToString()));
- }
- }
- DropDownList2.Items.Insert(0, new ListItem("--请选择一级类别--", "0"));
- }
- #endregion
-
-
-
- }
- }
|