/// <summary> /// 更新一条数据 /// </summary> public bool Update(Leadin.Model.Workers model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tb_Workers set "); strSql.Append("NumId=@NumId,"); strSql.Append("Account=@Account,"); strSql.Append("Pwd=@Pwd,"); strSql.Append("NameInfo=@NameInfo,"); strSql.Append("Phone=@Phone,"); strSql.Append("Email=@Email,"); strSql.Append("HeaderImg=@HeaderImg,"); strSql.Append("TypeId=@TypeId,"); strSql.Append("StateInfo=@StateInfo,"); strSql.Append("AddTime=@AddTime"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@NumId", SqlDbType.NVarChar, 100), new SqlParameter("@Account", SqlDbType.NVarChar, 100), new SqlParameter("@Pwd", SqlDbType.NVarChar, 200), new SqlParameter("@NameInfo", SqlDbType.NVarChar, 200), new SqlParameter("@Phone", SqlDbType.NVarChar, 100), new SqlParameter("@Email", SqlDbType.NVarChar, 100), new SqlParameter("@HeaderImg", SqlDbType.NVarChar, 200), new SqlParameter("@TypeId", SqlDbType.Int, 4), new SqlParameter("@StateInfo", SqlDbType.Int, 4), new SqlParameter("@AddTime", SqlDbType.DateTime), new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = model.NumId; parameters[1].Value = model.Account; parameters[2].Value = model.Pwd; parameters[3].Value = model.NameInfo; parameters[4].Value = model.Phone; parameters[5].Value = model.Email; parameters[6].Value = model.HeaderImg; parameters[7].Value = model.TypeId; parameters[8].Value = model.StateInfo; parameters[9].Value = model.AddTime; parameters[10].Value = model.Id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Leadin.Model.Workers DataRowToModel(DataRow row) { Leadin.Model.Workers model = new Leadin.Model.Workers(); if (row != null) { if (row["Id"] != null && row["Id"].ToString() != "") { model.Id = int.Parse(row["Id"].ToString()); } if (row["NumId"] != null) { model.NumId = row["NumId"].ToString(); } if (row["Account"] != null) { model.Account = row["Account"].ToString(); } if (row["Pwd"] != null) { model.Pwd = row["Pwd"].ToString(); } if (row["NameInfo"] != null) { model.NameInfo = row["NameInfo"].ToString(); } if (row["Phone"] != null) { model.Phone = row["Phone"].ToString(); } if (row["Email"] != null) { model.Email = row["Email"].ToString(); } if (row["HeaderImg"] != null) { model.HeaderImg = row["HeaderImg"].ToString(); } if (row["TypeId"] != null && row["TypeId"].ToString() != "") { model.TypeId = int.Parse(row["TypeId"].ToString()); } if (row["StateInfo"] != null && row["StateInfo"].ToString() != "") { model.StateInfo = int.Parse(row["StateInfo"].ToString()); } if (row["AddTime"] != null && row["AddTime"].ToString() != "") { model.AddTime = DateTime.Parse(row["AddTime"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Leadin.Model.Workers model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tb_Workers("); strSql.Append("NumId,Account,Pwd,NameInfo,Phone,Email,HeaderImg,TypeId,StateInfo,AddTime)"); strSql.Append(" values ("); strSql.Append("@NumId,@Account,@Pwd,@NameInfo,@Phone,@Email,@HeaderImg,@TypeId,@StateInfo,@AddTime)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@NumId", SqlDbType.NVarChar, 100), new SqlParameter("@Account", SqlDbType.NVarChar, 100), new SqlParameter("@Pwd", SqlDbType.NVarChar, 200), new SqlParameter("@NameInfo", SqlDbType.NVarChar, 200), new SqlParameter("@Phone", SqlDbType.NVarChar, 100), new SqlParameter("@Email", SqlDbType.NVarChar, 100), new SqlParameter("@HeaderImg", SqlDbType.NVarChar, 200), new SqlParameter("@TypeId", SqlDbType.Int, 4), new SqlParameter("@StateInfo", SqlDbType.Int, 4), new SqlParameter("@AddTime", SqlDbType.DateTime) }; parameters[0].Value = model.NumId; parameters[1].Value = model.Account; parameters[2].Value = model.Pwd; parameters[3].Value = model.NameInfo; parameters[4].Value = model.Phone; parameters[5].Value = model.Email; parameters[6].Value = model.HeaderImg; parameters[7].Value = model.TypeId; parameters[8].Value = model.StateInfo; parameters[9].Value = model.AddTime; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Leadin.Model.Workers GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,NumId,Account,Pwd,NameInfo,Phone,Email,HeaderImg,TypeId,StateInfo,AddTime from tb_Workers "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; Leadin.Model.Workers model = new Leadin.Model.Workers(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }