protected void Page_Load(object sender, EventArgs e) { DataModel dm = new DataModel(); if (Request.Params["id"] != null && Request.Params["id"].Trim() != "") { int id = Convert.ToInt32(Request.Params["id"].Trim()); lt = dm.GetLabType(id); } }
public void ProcessRequest(HttpContext context) { DataModel dm = new DataModel(); LabType lt = new LabType(); lt.LabTypeID = Convert.ToInt32(context.Request.Params["LabTypeID"]); lt.LabTypeName = context.Request.Params["LabTypeName"]; lt.LabTypeInfo = ""; dm.SaveLabType(lt); dm.ReturnJsonMsg(context.Response, 1, "保存成功!", lt.LabTypeID); }
public LabType GetLabType(int id) { LabType lt = new LabType(); InitCommand(); cmd.CommandText = "select * from LabType_tb where LabTypeID = @id"; cmd.Parameters.AddWithValue("@id",id); dr = cmd.ExecuteReader(); if (dr.Read()) { lt.LabTypeID = Convert.ToInt32(dr["LabTypeID"]); lt.LabTypeInfo = dr["LabTypeInfo"].ToString(); lt.LabTypeName = dr["LabTypeName"].ToString(); } dr.Close(); conn.Close(); return lt; }
public List<LabType> GetLabTypes() { List<LabType> lts = new List<LabType>(); InitCommand(); cmd.CommandText = "select * from LabType_tb"; dr = cmd.ExecuteReader(); while (dr.Read()) { LabType lt = new LabType(); lt.LabTypeID = Convert.ToInt32(dr["LabTypeID"]); lt.LabTypeInfo = dr["LabTypeInfo"].ToString(); lt.LabTypeName = dr["LabTypeName"].ToString(); lts.Add(lt); } dr.Close(); conn.Close(); return lts; }
public int SaveLabType(LabType lt) { InitCommand(); if (lt.LabTypeID == 0) { //Insert new user cmd.CommandText = "INSERT INTO LabType_tb (LabTypeName,LabTypeInfo) VALUES (@LabTypeName,@LabTypeInfo)"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@LabTypeName",lt.LabTypeName); cmd.Parameters.AddWithValue("@LabTypeInfo",lt.LabTypeInfo); cmd.ExecuteNonQuery(); cmd.CommandText = "SELECT @@Identity "; lt.LabTypeID = (int)cmd.ExecuteScalar(); } else { cmd.CommandText = "UPDATE LabType_tb SET " + " LabTypeName=@LabTypeName,LabTypeInfo=@LabTypeInfo where LabTypeID=@LabTypeID"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@LabTypeName", lt.LabTypeName); cmd.Parameters.AddWithValue("@LabTypeInfo", lt.LabTypeInfo); cmd.Parameters.AddWithValue("@LabTypeID", lt.LabTypeID); cmd.ExecuteNonQuery(); } conn.Close(); return lt.LabTypeID; }