public bool Update(QPS.NEW.Model.Trends model) { bool res = false; string[] filedName = new string[50]; string[] paramName = new string[50]; SqlParameter[] sqlParams = new SqlParameter[50]; int Count = 0; if (model.Id == -999) return false; if (model.Id != -999) { filedName[Count] = "Id"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Id); Count++; } if (model.Title != null) { filedName[Count] = "Title"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Title); Count++; } if (model.Content != null) { filedName[Count] = "Content"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Content); Count++; } if (model.Time != null) { filedName[Count] = "time"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Time); Count++; } StringBuilder strSql = new StringBuilder(); strSql.Append("update Trends set "); for (int i = 1; i < Count; i++) { strSql.Append(filedName[i]); strSql.Append("="); strSql.Append(paramName[i]); if (i != Count - 1) { strSql.Append(","); } } strSql.Append(" where "); strSql.Append(filedName[0] + "=" + paramName[0]); int num = Convert.ToInt32(sqlHelper_.ExecuteCommand( strSql.ToString(), CommandType.Text, sqlParams )); if (num != 1) { res = false; } else { res = true; } return res; }
public int Add(QPS.NEW.Model.Trends model) { string[] filedName = new string[50]; string[] paramName = new string[50]; SqlParameter[] sqlParams = new SqlParameter[50]; int Count = 0; if (model.Title != null) { filedName[Count] = "Title"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Title); Count++; } if (model.Content != null) { filedName[Count] = "Content"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Content); Count++; } if (model.Time != null) { filedName[Count] = "time"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Time); Count++; } StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Trends("); for (int i = 0; i < Count; i++) { strSql.Append(filedName[i]); if (i != Count - 1) { strSql.Append(","); } } strSql.Append(")values("); for (int i = 0; i < Count; i++) { strSql.Append(paramName[i]); if (i != Count - 1) { strSql.Append(","); } } strSql.Append(")"); int res = -1; res = sqlHelper_.ExecuteCommand( strSql.ToString(), CommandType.Text, sqlParams ); if (res != 1) { return 0; } return 1; }
public bool Update(QPS.NEW.Model.Enterprise model) { bool res = false; string[] filedName = new string[50]; string[] paramName = new string[50]; SqlParameter[] sqlParams = new SqlParameter[50]; int Count = 0; if (model.Id == -999) return false; if (model.Id != -999) { filedName[Count] = "Id"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Id); Count++; } if (model.Username != null) { filedName[Count] = "Username"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Username); Count++; } if (model.Password != null) { filedName[Count] = "Password"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Password); Count++; } if (model.Nickname != null) { filedName[Count] = "Nickname"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Nickname); Count++; } if (model.Phone != null) { filedName[Count] = "Phone"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Phone); Count++; } if (model.Address != null) { filedName[Count] = "Address"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Address); Count++; } if (model.Mail != null) { filedName[Count] = "Mail"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Mail); Count++; } if (model.IfChecked != -999) { filedName[Count] = "IfChecked"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.IfChecked); Count++; } StringBuilder strSql = new StringBuilder(); strSql.Append("update Enterprise set "); for (int i = 1; i < Count; i++) // i begin with 0 !!! { strSql.Append(filedName[i]); strSql.Append("="); strSql.Append(paramName[i]); if (i != Count - 1) { strSql.Append(","); } } strSql.Append(" where "); strSql.Append(filedName[0] + "=" + paramName[0]); int num = Convert.ToInt32(sqlHelper_.ExecuteCommand( strSql.ToString(), CommandType.Text, sqlParams )); if (num != 1) { res = false; } else { res = true; } return res; }
public int Add(QPS.NEW.Model.Enterprise model) { int checkUsername = -1; enterprise_ = model; checkUsername = Convert.ToInt32( sqlHelper_.GetSingle("select count(*) from Enterprise where Username=@username", CommandType.Text, new System.Data.SqlClient.SqlParameter[]{ new System.Data.SqlClient.SqlParameter("@username",enterprise_.Username) } ) ); if (checkUsername != 0) { throw new Exception("Error:用户名已经存在"); } else { string[] filedName = new string[50]; string[] paramName = new string[50]; SqlParameter[] sqlParams = new SqlParameter[50]; int Count = 0; if (model.Username != null) { filedName[Count] = "Username"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Username); Count++; } if (model.Password != null) { filedName[Count] = "Password"; paramName[Count] = "@" + filedName[Count]; string md5Pwd = MD5Helper.Encode(model.Password); sqlParams[Count] = new SqlParameter(paramName[Count], md5Pwd); Count++; } if (model.Nickname != null) { filedName[Count] = "Nickname"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Nickname); Count++; } if (model.Phone != null) { filedName[Count] = "Phone"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Phone); Count++; } if (model.Address != null) { filedName[Count] = "Address"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Address); Count++; } if (model.Mail != null) { filedName[Count] = "Mail"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Mail); Count++; } if (model.IfChecked != -999) { filedName[Count] = "IfChecked"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.IfChecked); Count++; } StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Enterprise("); for (int i = 0; i < Count; i++) { strSql.Append(filedName[i]); if (i != Count - 1) { strSql.Append(","); } } strSql.Append(")values("); for (int i = 0; i < Count; i++) { strSql.Append(paramName[i]); if (i != Count - 1) { strSql.Append(","); } } strSql.Append(")"); int res = -1; res = sqlHelper_.ExecuteCommand( strSql.ToString(), CommandType.Text, sqlParams ); if (res != 1) { throw new Exception("Error:写入数据库失败"); } } return 1; }
public bool UpdateContent(QPS.NEW.Model.Integral model) { return Update(model); }
public bool Update(QPS.NEW.Model.Integral model) { bool res = false; string[] filedName = new string[50]; string[] paramName = new string[50]; SqlParameter[] sqlParams = new SqlParameter[50]; int Count = 0; if (model.UserID == -999 && model.TotalMoney!=-999) return false; if (model.UserID != -999) { filedName[Count] = "UserID"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.UserID); Count++; } int newWalletMoney, newBankMoney; int bankMoney = GetBankMoney(model.UserID); int walletMoney = GetWalletMoney(model.UserID); if (bankMoney + walletMoney < model.TotalMoney) //增加积分,直接写增加金额到Bank { newWalletMoney = walletMoney; newBankMoney = model.TotalMoney - walletMoney; } else // 减少积分 { int reducedMoney = model.TotalMoney - (bankMoney + walletMoney); if (bankMoney >= reducedMoney) // 优先操作Bank { newBankMoney = bankMoney - reducedMoney; newWalletMoney = walletMoney; } else { newBankMoney = 0; newWalletMoney = walletMoney + bankMoney - reducedMoney; } } filedName[Count] = "WalletMoney"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], newWalletMoney); Count++; filedName[Count] = "BankMoney"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], newBankMoney); Count++; StringBuilder strSql = new StringBuilder(); strSql.Append("update TUserInfo set "); for (int i = 1; i < Count; i++) { strSql.Append(filedName[i]); strSql.Append("="); strSql.Append(paramName[i]); if (i != Count - 1) { strSql.Append(","); } } strSql.Append(" where "); strSql.Append(filedName[0] + "=" + paramName[0]); int num = Convert.ToInt32(sqlHelper_.ExecuteCommand( strSql.ToString(), CommandType.Text, sqlParams )); if (num != 1) { res = false; } else { res = true; } return res; }
public bool Update(QPS.NEW.Model.Orderform model) { bool res = false; string[] filedName = new string[50]; string[] paramName = new string[50]; SqlParameter[] sqlParams = new SqlParameter[50]; int Count = 0; if (model.Id == -999) return false; if (model.Id != -999) { filedName[Count] = "Id"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Id); Count++; } if (model.OrderNumber != null) { filedName[Count] = "OrderNumber"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.OrderNumber); Count++; } if (model.StartTime != null) { filedName[Count] = "StartTime"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.StartTime); Count++; } if (model.endTime != null) { filedName[Count] = "endTime"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.endTime); Count++; } if (model.Userid != -999) { filedName[Count] = "Userid"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Userid); Count++; } if (model.Roomid != -999) { filedName[Count] = "Roomid"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Roomid); Count++; } if (model.RoomType != null) { filedName[Count] = "RoomType"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.RoomType); Count++; } if (model.Beveragecost != null) { filedName[Count] = "Beveragecost"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Beveragecost); Count++; } if (model.IsDelete != -999) { filedName[Count] = "IsDelete"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.IsDelete); Count++; } if (model.IsValidity != null) { filedName[Count] = "IsValidity"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.IsValidity); Count++; } StringBuilder strSql = new StringBuilder(); strSql.Append("update Orderform set "); for (int i = 1; i < Count; i++) // i begin with 0 !!! { strSql.Append(filedName[i]); strSql.Append("="); strSql.Append(paramName[i]); if (i != Count - 1) { strSql.Append(","); } } strSql.Append(" where "); strSql.Append(filedName[0] + "=" + paramName[0]); int num = Convert.ToInt32(sqlHelper_.ExecuteCommand( strSql.ToString(), CommandType.Text, sqlParams )); if (num != 1) { res = false; } else { res = true; } return res; }
public int Add(QPS.NEW.Model.Integral model) { int bankMoney = GetBankMoney(model.UserID) + model.BankMoney; int num = sqlHelper_.ExecuteCommand( "update TUserInfo set BankMoney=@bankmoney", CommandType.Text, new SqlParameter("@bankmoney",bankMoney) ); if (num==1) return 1; else return 0; }
public bool Update(QPS.NEW.Model.ad model) { bool res = false; string[] filedName = new string[50]; string[] paramName = new string[50]; SqlParameter[] sqlParams = new SqlParameter[50]; int Count = 0; if (model.Id == -999) return false; if (model.Id != -999) { filedName[Count] = "Id"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Id); Count++; } if (model.Catid != null) { filedName[Count] = "catid"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Catid); Count++; } if (model.AdImg != null) { filedName[Count] = "adImg"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.AdImg); Count++; } if (model.AdUrl != null) { filedName[Count] = "adUrl"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.AdUrl); Count++; } if (model.AdType != null) { filedName[Count] = "adType"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.AdType); Count++; } if (model.AdName != null) { filedName[Count] = "adName"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.AdName); Count++; } if (model.AdDate != null) { filedName[Count] = "adDate"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.AdDate); Count++; } StringBuilder strSql = new StringBuilder(); strSql.Append("update ad set "); for (int i = 1; i < Count; i++) // i begin with 0 !!! { strSql.Append(filedName[i]); strSql.Append("="); strSql.Append(paramName[i]); if (i != Count - 1) { strSql.Append(","); } } strSql.Append(" where "); strSql.Append(filedName[0] + "=" + paramName[0]); int num = Convert.ToInt32(sqlHelper_.ExecuteCommand( strSql.ToString(), CommandType.Text, sqlParams )); if (num != 1) { res = false; } else { res = true; } return res; }
public int Add(QPS.NEW.Model.Orderform model) { int res = 0; bool isOrdered = false; string strSql = "select count(*) from Orderform where Roomid=@roomid and IsDelete=0 and IsValidity=1"; int num =Convert.ToInt32( sqlHelper_.GetSingle( strSql, CommandType.Text, new System.Data.SqlClient.SqlParameter[] { new System.Data.SqlClient.SqlParameter("@roomid",model.Roomid) } ) ); if (num > 0) { isOrdered = true; } if (num < 0) { res = -1; throw new Exception("Error:查询数据库失败"); } if (isOrdered) { res = -1; throw new Exception("Error:房间已被预定"); } else { string[] filedName = new string[50]; string[] paramName = new string[50]; SqlParameter[] sqlParams = new SqlParameter[50]; int Count = 0; if (model.OrderNumber != null) { filedName[Count] = "OrderNumber"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.OrderNumber); Count++; } if (model.StartTime != null) { filedName[Count] = "StartTime"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.StartTime); Count++; } if (model.endTime != null) { filedName[Count] = "endTime"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.endTime); Count++; } if (model.Userid != -999) { filedName[Count] = "Userid"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Userid); Count++; } if (model.Roomid != -999) { filedName[Count] = "Roomid"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Roomid); Count++; } if (model.RoomType != null) { filedName[Count] = "RoomType"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.RoomType); Count++; } if (model.Beveragecost != null) { filedName[Count] = "Beveragecost"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Beveragecost); Count++; } if (model.IsDelete != -999) { filedName[Count] = "IsDelete"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.IsDelete); Count++; } if (model.IsValidity != null) { filedName[Count] = "IsValidity"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.IsValidity); Count++; } StringBuilder strSql_bs = new StringBuilder(); strSql_bs.Append("insert into Orderform("); for (int i = 0; i < Count; i++) { strSql_bs.Append(filedName[i]); if (i != Count - 1) { strSql_bs.Append(","); } } strSql_bs.Append(")values("); for (int i = 0; i < Count; i++) { strSql_bs.Append(paramName[i]); if (i != Count - 1) { strSql_bs.Append(","); } } strSql_bs.Append(")"); num = sqlHelper_.ExecuteCommand( strSql_bs.ToString(), CommandType.Text, sqlParams ); if (num != 1) { res = -1; throw new Exception("Error:写入数据库失败"); } else { res = 1; } } return res; }
public bool Update(QPS.NEW.Model.Room model) { bool res = false; string[] filedName = new string[50]; string[] paramName = new string[50]; SqlParameter[] sqlParams = new SqlParameter[50]; int Count = 0; if (model.Id == -999) return false; if (model.Id != -999) { filedName[Count] = "Id"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Id); Count++; } if (model.Name != null) { filedName[Count] = "Name"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Name); Count++; } if (model.RoomType != null) { filedName[Count] = "RoomType"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.RoomType); Count++; } if (model.RoomPrice != -999) { filedName[Count] = "RoomPrice"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.RoomPrice); Count++; } if (model.Are != null) { filedName[Count] = "Are"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Are); Count++; } if (model.Address != null) { filedName[Count] = "Address"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Address); Count++; } if (model.ImagePath != null) { filedName[Count] = "ImagePath"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.ImagePath); Count++; } if (model.Content != null) { filedName[Count] = "Content"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Content); Count++; } if (model.RoomState != -999) { filedName[Count] = "RoomState"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.RoomState); Count++; } if (model.OwnerID != -999) { filedName[Count] = "OwnerID"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.OwnerID); Count++; } if (model.IfRecommend != -999) { filedName[Count] = "IfRecommend"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.IfRecommend); Count++; } if (model.Examine != -999) { filedName[Count] = "IfExamine"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Examine); Count++; } if (model.RecommendTime != null) { filedName[Count] = "RecommendTime"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.RecommendTime); Count++; } StringBuilder strSql = new StringBuilder(); strSql.Append("update Room set "); for (int i = 1; i < Count; i++) { strSql.Append(filedName[i]); strSql.Append("="); strSql.Append(paramName[i]); if (i != Count - 1) { strSql.Append(","); } } strSql.Append(" where "); strSql.Append(filedName[0] + "=" + paramName[0]); int num = Convert.ToInt32(sqlHelper_.ExecuteCommand( strSql.ToString(), CommandType.Text, sqlParams )); if (num != 1) { res = false; } else { res = true; } return res; }
public int Add(QPS.NEW.Model.Room model) { string[] filedName = new string[50]; string[] paramName = new string[50]; SqlParameter[] sqlParams = new SqlParameter[50]; int Count = 0; if (model.Name != null) { filedName[Count] = "Name"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Name); Count++; } if (model.RoomType != null) { filedName[Count] = "RoomType"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.RoomType); Count++; } if (model.RoomPrice != -999) { filedName[Count] = "RoomPrice"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.RoomPrice); Count++; } if (model.Are != null) { filedName[Count] = "Are"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Are); Count++; } if (model.Address != null) { filedName[Count] = "Address"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Address); Count++; } if (model.ImagePath != null) { filedName[Count] = "ImagePath"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.ImagePath); Count++; } if (model.Content != null) { filedName[Count] = "Content"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Content); Count++; } if (model.RoomState != -999) { filedName[Count] = "RoomState"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.RoomState); Count++; } if (model.OwnerID != -999) { filedName[Count] = "OwnerID"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.OwnerID); Count++; } if (model.IfRecommend != -999) { filedName[Count] = "IfRecommend"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.IfRecommend); Count++; } if (model.Examine != -999) { filedName[Count] = "IfExamine"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Examine); Count++; } if (model.RecommendTime != null) { filedName[Count] = "RecommendTime"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.RecommendTime); Count++; } StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Room("); for (int i = 0; i < Count; i++) { strSql.Append(filedName[i]); if (i != Count - 1) { strSql.Append(","); } } strSql.Append(")values("); for (int i = 0; i < Count; i++) { strSql.Append(paramName[i]); if (i != Count - 1) { strSql.Append(","); } } strSql.Append(")"); int res = -1; res = sqlHelper_.ExecuteCommand( strSql.ToString(), CommandType.Text, sqlParams ); if (res != 1) { return 0; } return 1; }
public bool UpdateUs(QPS.NEW.Model.Users us) { return Update(us); }
public bool Update(QPS.NEW.Model.Users model) { string[] filedName = new string[50]; string[] paramName = new string[50]; SqlParameter[] sqlParams = new SqlParameter[50]; int Count = 0; if (model.Id == -999) return false; if (model.Id != -999) { filedName[Count] = "UserID"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Id); Count++; } if (model.Username != null) { filedName[Count] = "UserName"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Username); Count++; } if (model.Password != null) { filedName[Count] = "Pass"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Password); Count++; } if (model.Nickname != null) { filedName[Count] = "NickName"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Nickname); Count++; } StringBuilder strSql = new StringBuilder(); strSql.Append("update TUsers set "); for (int i = 1; i < Count; i++) // i begin with 0 !!! { strSql.Append(filedName[i]); strSql.Append("="); strSql.Append(paramName[i]); if (i != Count - 1) { strSql.Append(","); } } strSql.Append(" where "); strSql.Append(filedName[0] + "=" + paramName[0]); int num = Convert.ToInt32(sqlHelper_.ExecuteCommand( strSql.ToString(), CommandType.Text, sqlParams )); if (num != 1) { return false; } strSql = new StringBuilder(); for (int i = 0; i < 50; i++) { filedName[i] = null; paramName[i] = null; sqlParams[i] = null; } Count = 0; filedName[Count] = "UserID"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Id); Count++; if (model.Phone != null) { filedName[Count] = "PhoneNum"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Phone); Count++; } if (model.Usertype != -999) { filedName[Count] = "Usertype"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Usertype); Count++; } strSql.Append("update TUserinfo set "); for (int i = 1; i < Count; i++) // i begin with 0 !!! { strSql.Append(filedName[i]); strSql.Append("="); strSql.Append(paramName[i]); if (i != Count - 1) { strSql.Append(","); } } strSql.Append(" where "); strSql.Append(filedName[0] + "=" + paramName[0]); num = Convert.ToInt32(sqlHelper_.ExecuteCommand( strSql.ToString(), CommandType.Text, sqlParams )); if (num != 1) return false; strSql = new StringBuilder(); for (int i = 0; i < 50; i++) { filedName[i] = null; paramName[i] = null; sqlParams[i] = null; } Count = 0; filedName[Count] = "UserID"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Id); Count++; if (model.Phone != null) { filedName[Count] = "Phone"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Phone); Count++; } if (model.Address != null) { filedName[Count] = "Address"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Address); Count++; } if (model.Mail != null) { filedName[Count] = "Email"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Mail); Count++; } strSql.Append("update Web_Users set "); for (int i = 1; i < Count; i++) // i begin with 0 !!! { strSql.Append(filedName[i]); strSql.Append("="); strSql.Append(paramName[i]); if (i != Count - 1) { strSql.Append(","); } } strSql.Append(" where "); strSql.Append(filedName[0] + "=" + paramName[0]); num = Convert.ToInt32(sqlHelper_.ExecuteCommand( strSql.ToString(), CommandType.Text, sqlParams )); if (num != 1) { return false; } return true; }
public int Add(QPS.NEW.Model.Users model) { int checkUsername = -1; int res = -1; user_ = model; checkUsername = Convert.ToInt32( sqlHelper_.GetSingle("select count(*) from TUsers where UserName=@username", CommandType.Text, new System.Data.SqlClient.SqlParameter[]{ new System.Data.SqlClient.SqlParameter("@username",user_.Username) } ) ); if (checkUsername != 0) { return -1; } else { string[] filedName = new string[50]; string[] paramName = new string[50]; SqlParameter[] sqlParams = new SqlParameter[50]; int Count = 0; int userId = Convert.ToInt32(sqlHelper_.GetSingle( "select Max(UserID) from TUsers", CommandType.Text, new SqlParameter[] { new SqlParameter("@username",model.Username) } )) + 1; filedName[Count] = "UserID"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], userId); Count++; if (model.Username != null) { filedName[Count] = "UserName"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Username); Count++; } if (model.Password != null) { filedName[Count] = "Pass"; paramName[Count] = "@" + filedName[Count]; string md5Pwd = MD5Helper.Encode(model.Password); sqlParams[Count] = new SqlParameter(paramName[Count], md5Pwd); Count++; } if (model.Nickname != null) { filedName[Count] = "NickName"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Nickname); Count++; } StringBuilder strSql = new StringBuilder(); strSql.Append("insert into TUsers("); for (int i = 0; i < Count; i++) { strSql.Append(filedName[i]); if (i != Count - 1) { strSql.Append(","); } } strSql.Append(")values("); for (int i = 0; i < Count; i++) { strSql.Append(paramName[i]); if (i != Count - 1) { strSql.Append(","); } } strSql.Append(")"); res = sqlHelper_.ExecuteCommand( strSql.ToString(), CommandType.Text, sqlParams ); if (res != 1) { return -2; } else { // 初始化数组 for (int i = 0; i < 50; i++) { filedName[i] = null; paramName[i] = null; sqlParams[i] = null; } Count = 0; filedName[Count] = "UserID"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], userId); Count++; if (model.Phone != null) { filedName[Count] = "PhoneNum"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Phone); Count++; } if (model.Usertype != -999) { filedName[Count] = "UserType"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Usertype); Count++; } strSql = new StringBuilder(); strSql.Append("insert into TUserInfo("); for (int i = 0; i < Count; i++) { strSql.Append(filedName[i]); if (i != Count - 1) { strSql.Append(","); } } strSql.Append(")values("); for (int i = 0; i < Count; i++) { strSql.Append(paramName[i]); if (i != Count - 1) { strSql.Append(","); } } strSql.Append(")"); res = -1; res = sqlHelper_.ExecuteCommand( strSql.ToString(), CommandType.Text, sqlParams ); if (res != 1) { return -2; } if (model.Mail != null) { res = -1; res = sqlHelper_.ExecuteCommand( "insert into Web_Users(UserID,Email,Phone,Address)values(@userid,@email,@phone,@address)", CommandType.Text, new SqlParameter[] { new SqlParameter("@userid",userId), new SqlParameter("@email",model.Mail), new SqlParameter("@phone",model.Phone), new SqlParameter("@address",model.Address) } ); if (res != 1) { return -2; } } } } return 1; }