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