/// <summary> /// 得到一个对象实体 /// </summary> public JMP.MDL.jmp_goods GetModel(int g_id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select g_id, g_app_id, g_name, g_saletype_id, g_price, g_state "); strSql.Append(" from jmp_goods "); strSql.Append(" where g_id=@g_id"); SqlParameter[] parameters = { new SqlParameter("@g_id", SqlDbType.Int, 4) }; parameters[0].Value = g_id; JMP.MDL.jmp_goods model = new JMP.MDL.jmp_goods(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["g_id"].ToString() != "") { model.g_id = int.Parse(ds.Tables[0].Rows[0]["g_id"].ToString()); } if (ds.Tables[0].Rows[0]["g_app_id"].ToString() != "") { model.g_app_id = int.Parse(ds.Tables[0].Rows[0]["g_app_id"].ToString()); } model.g_name = ds.Tables[0].Rows[0]["g_name"].ToString(); if (ds.Tables[0].Rows[0]["g_saletype_id"].ToString() != "") { model.g_saletype_id = int.Parse(ds.Tables[0].Rows[0]["g_saletype_id"].ToString()); } if (ds.Tables[0].Rows[0]["g_price"].ToString() != "") { model.g_price = decimal.Parse(ds.Tables[0].Rows[0]["g_price"].ToString()); } if (ds.Tables[0].Rows[0]["g_state"].ToString() != "") { model.g_state = int.Parse(ds.Tables[0].Rows[0]["g_state"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(JMP.MDL.jmp_goods model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update jmp_goods set "); strSql.Append(" g_app_id = @g_app_id , "); strSql.Append(" g_name = @g_name , "); strSql.Append(" g_saletype_id = @g_saletype_id , "); strSql.Append(" g_price = @g_price , "); strSql.Append(" g_state = @g_state "); strSql.Append(" where g_id=@g_id "); SqlParameter[] parameters = { new SqlParameter("@g_id", SqlDbType.Int, 4), new SqlParameter("@g_app_id", SqlDbType.Int, 4), new SqlParameter("@g_name", SqlDbType.NVarChar, -1), new SqlParameter("@g_saletype_id", SqlDbType.Int, 4), new SqlParameter("@g_price", SqlDbType.Money, 8), new SqlParameter("@g_state", SqlDbType.Int, 4) }; parameters[0].Value = model.g_id; parameters[1].Value = model.g_app_id; parameters[2].Value = model.g_name; parameters[3].Value = model.g_saletype_id; parameters[4].Value = model.g_price; parameters[5].Value = model.g_state; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(JMP.MDL.jmp_goods model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into jmp_goods("); strSql.Append("g_app_id,g_name,g_saletype_id,g_price,g_state"); strSql.Append(") values ("); strSql.Append("@g_app_id,@g_name,@g_saletype_id,@g_price,@g_state"); strSql.Append(") "); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@g_app_id", SqlDbType.Int, 4), new SqlParameter("@g_name", SqlDbType.NVarChar, -1), new SqlParameter("@g_saletype_id", SqlDbType.Int, 4), new SqlParameter("@g_price", SqlDbType.Money, 8), new SqlParameter("@g_state", SqlDbType.Int, 4) }; parameters[0].Value = model.g_app_id; parameters[1].Value = model.g_name; parameters[2].Value = model.g_saletype_id; parameters[3].Value = model.g_price; parameters[4].Value = model.g_state; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }