/// <summary> /// 增加一条数据 /// </summary> public decimal Add(Maticsoft.Model.Operation_log model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tb_Operation_log("); strSql.Append("UserName,Operation,Remarks,DateTime)"); strSql.Append(" values ("); strSql.Append("@UserName,@Operation,@Remarks,@DateTime)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@UserName", SqlDbType.VarChar, 50), new SqlParameter("@Operation", SqlDbType.NVarChar, 50), new SqlParameter("@Remarks", SqlDbType.Text), new SqlParameter("@DateTime", SqlDbType.DateTime) }; parameters[0].Value = model.UserName; parameters[1].Value = model.Operation; parameters[2].Value = model.Remarks; parameters[3].Value = model.DateTime; object obj = dbs.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToDecimal(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.Operation_log model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tb_Operation_log set "); strSql.Append("UserName=@UserName,"); strSql.Append("Operation=@Operation,"); strSql.Append("Remarks=@Remarks,"); strSql.Append("DateTime=@DateTime"); strSql.Append(" where R_ID=@R_ID"); SqlParameter[] parameters = { new SqlParameter("@UserName", SqlDbType.VarChar, 50), new SqlParameter("@Operation", SqlDbType.NVarChar, 50), new SqlParameter("@Remarks", SqlDbType.Text), new SqlParameter("@DateTime", SqlDbType.DateTime), new SqlParameter("@R_ID", SqlDbType.Decimal, 9) }; parameters[0].Value = model.UserName; parameters[1].Value = model.Operation; parameters[2].Value = model.Remarks; parameters[3].Value = model.DateTime; parameters[4].Value = model.R_ID; int rows = dbs.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.Operation_log GetModel(decimal R_ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 R_ID,UserName,Operation,Remarks,DateTime from tb_Operation_log "); strSql.Append(" where R_ID=@R_ID"); SqlParameter[] parameters = { new SqlParameter("@R_ID", SqlDbType.Decimal) }; parameters[0].Value = R_ID; Maticsoft.Model.Operation_log model = new Maticsoft.Model.Operation_log(); DataSet ds = dbs.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["R_ID"] != null && ds.Tables[0].Rows[0]["R_ID"].ToString() != "") { model.R_ID = decimal.Parse(ds.Tables[0].Rows[0]["R_ID"].ToString()); } if (ds.Tables[0].Rows[0]["UserName"] != null && ds.Tables[0].Rows[0]["UserName"].ToString() != "") { model.UserName = ds.Tables[0].Rows[0]["UserName"].ToString(); } if (ds.Tables[0].Rows[0]["Operation"] != null && ds.Tables[0].Rows[0]["Operation"].ToString() != "") { model.Operation = ds.Tables[0].Rows[0]["Operation"].ToString(); } if (ds.Tables[0].Rows[0]["Remarks"] != null && ds.Tables[0].Rows[0]["Remarks"].ToString() != "") { model.Remarks = ds.Tables[0].Rows[0]["Remarks"].ToString(); } if (ds.Tables[0].Rows[0]["DateTime"] != null && ds.Tables[0].Rows[0]["DateTime"].ToString() != "") { model.DateTime = DateTime.Parse(ds.Tables[0].Rows[0]["DateTime"].ToString()); } return(model); } else { return(null); } }