/// <summary> /// 更新一条数据 /// </summary> public bool Update(KfJieDaiModel model) { bool reValue = true; int reCount = 0; StringBuilder strSql = new StringBuilder(); strSql.Append("update YYHD.dbo.KfJieDai set "); strSql.Append(" DeviceId = @DeviceId , "); strSql.Append(" UserId = @UserId , "); strSql.Append(" CreateTime = @CreateTime , "); strSql.Append(" LastTime = @LastTime , "); strSql.Append(" JieDaiStatus = @JieDaiStatus "); strSql.Append(" where KfJieDaiId=@KfJieDaiId "); SqlParameter[] parameters = { new SqlParameter("@KfJieDaiId", SqlDbType.Decimal, 9), new SqlParameter("@DeviceId", SqlDbType.VarChar, 50), new SqlParameter("@UserId", SqlDbType.VarChar, 50), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@LastTime", SqlDbType.DateTime), new SqlParameter("@JieDaiStatus", SqlDbType.Int, 4) }; parameters[0].Value = model.KfJieDaiId; parameters[1].Value = model.DeviceId; parameters[2].Value = model.UserId; parameters[3].Value = model.CreateTime; parameters[4].Value = model.LastTime; parameters[5].Value = model.JieDaiStatus; try {//异常处理 reCount = this.helper.ExecSqlReInt(strSql.ToString(), parameters); } catch (Exception ex) { this.helper.Close(); throw ex; } if (reCount <= 0) { reValue = false; } return(reValue); }
/// <summary> /// 得到一个对象实体 /// </summary> public KfJieDaiModel GetModel(decimal KfJieDaiId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select KfJieDaiId, DeviceId, UserId, CreateTime, LastTime, JieDaiStatus "); strSql.Append(" from YYHD.dbo.KfJieDai "); strSql.Append(" where KfJieDaiId=@KfJieDaiId"); SqlParameter[] parameters = { new SqlParameter("@KfJieDaiId", SqlDbType.Decimal) }; parameters[0].Value = KfJieDaiId; KfJieDaiModel model = new KfJieDaiModel(); DataSet ds = helper.ExecSqlReDs(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["KfJieDaiId"].ToString() != "") { model.KfJieDaiId = decimal.Parse(ds.Tables[0].Rows[0]["KfJieDaiId"].ToString()); } model.DeviceId = ds.Tables[0].Rows[0]["DeviceId"].ToString(); model.UserId = ds.Tables[0].Rows[0]["UserId"].ToString(); if (ds.Tables[0].Rows[0]["CreateTime"].ToString() != "") { model.CreateTime = DateTime.Parse(ds.Tables[0].Rows[0]["CreateTime"].ToString()); } if (ds.Tables[0].Rows[0]["LastTime"].ToString() != "") { model.LastTime = DateTime.Parse(ds.Tables[0].Rows[0]["LastTime"].ToString()); } if (ds.Tables[0].Rows[0]["JieDaiStatus"].ToString() != "") { model.JieDaiStatus = int.Parse(ds.Tables[0].Rows[0]["JieDaiStatus"].ToString()); } return(model); } else { return(model); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(KfJieDaiModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into YYHD.dbo.KfJieDai ("); strSql.Append("DeviceId,UserId,CreateTime,LastTime,JieDaiStatus"); strSql.Append(") values ("); strSql.Append("@DeviceId,@UserId,@CreateTime,@LastTime,@JieDaiStatus"); strSql.Append(") "); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@DeviceId", SqlDbType.VarChar, 50), new SqlParameter("@UserId", SqlDbType.VarChar, 50), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@LastTime", SqlDbType.DateTime), new SqlParameter("@JieDaiStatus", SqlDbType.Int, 4) }; parameters[0].Value = model.DeviceId; parameters[1].Value = model.UserId; parameters[2].Value = model.CreateTime; parameters[3].Value = model.LastTime; parameters[4].Value = model.JieDaiStatus; bool result = false; try { helper.ExecSqlReInt(strSql.ToString(), parameters); result = true; } catch (Exception ex) { this.helper.Close(); throw ex; } finally { } return(result); }