/// <summary> /// 插入数据 /// </summary> /// <returns></returns> public static bool insert(Trans.Db.Model.NUser_AuthSite NUser_AuthSite_obj) { SqlCommand cmd = new SqlCommand(); StringBuilder cols = new StringBuilder(); StringBuilder parameters = new StringBuilder(); string sql = "INSERT INTO NUser_AuthSite({0}) values({1})"; if (cols.Length > 0) { cols.Append(","); parameters.Append(","); } cols.Append("[UserID]"); parameters.Append("@UserID"); cmd.Parameters.AddWithValue("@UserID", NUser_AuthSite_obj.UserID); if (cols.Length > 0) { cols.Append(","); parameters.Append(","); } cols.Append("[SiteName]"); parameters.Append("@SiteName"); if (!string.IsNullOrEmpty(NUser_AuthSite_obj.SiteName)) { cmd.Parameters.AddWithValue("@SiteName", NUser_AuthSite_obj.SiteName); } else { cmd.Parameters.AddWithValue("@SiteName", ""); } if (cols.Length > 0) { cols.Append(","); parameters.Append(","); } cols.Append("[AllowList]"); parameters.Append("@AllowList"); cmd.Parameters.AddWithValue("@AllowList", NUser_AuthSite_obj.AllowList); if (cols.Length > 0) { cols.Append(","); parameters.Append(","); } cols.Append("[AllowSync]"); parameters.Append("@AllowSync"); cmd.Parameters.AddWithValue("@AllowSync", NUser_AuthSite_obj.AllowSync); if (cols.Length > 0) { cols.Append(","); parameters.Append(","); } cols.Append("[AllowRoll]"); parameters.Append("@AllowRoll"); cmd.Parameters.AddWithValue("@AllowRoll", NUser_AuthSite_obj.AllowRoll); if (cols.Length > 0) { cols.Append(","); parameters.Append(","); } cols.Append("[IsDel]"); parameters.Append("@IsDel"); cmd.Parameters.AddWithValue("@IsDel", NUser_AuthSite_obj.IsDel); if (cols.Length > 0) { cols.Append(","); parameters.Append(","); } cols.Append("[CreateTime]"); parameters.Append("@CreateTime"); if (NUser_AuthSite_obj.CreateTime == null || NUser_AuthSite_obj.CreateTime == DateTime.MinValue) { cmd.Parameters.AddWithValue("@CreateTime", DateTime.Now); } else { cmd.Parameters.AddWithValue("@CreateTime", NUser_AuthSite_obj.CreateTime); } sql = string.Format(sql, cols.ToString(), parameters.ToString()); cmd.CommandText = sql; bool b = true; try { int QueryCount = new Trans.Db.DBUtility.DBHelper(false).ExecNonQuery(cmd); if (QueryCount < 1) { b = false; } } catch { b = false; } return(b); }
/// <summary> /// 插入数据,返回自增列ID /// </summary> /// <returns></returns> public static bool Add(Trans.Db.Model.NUser_AuthSite NUser_AuthSite_obj, out Int32 ID) { ID = 0; SqlCommand cmd = new SqlCommand(); StringBuilder cols = new StringBuilder(); StringBuilder parameters = new StringBuilder(); string sql = "INSERT INTO NUser_AuthSite({0}) values({1});SELECT @@IDENTITY;"; if (cols.Length > 0) { cols.Append(","); parameters.Append(","); } cols.Append("[UserID]"); parameters.Append("@UserID"); cmd.Parameters.AddWithValue("@UserID", NUser_AuthSite_obj.UserID); if (cols.Length > 0) { cols.Append(","); parameters.Append(","); } cols.Append("[SiteName]"); parameters.Append("@SiteName"); if (!string.IsNullOrEmpty(NUser_AuthSite_obj.SiteName)) { cmd.Parameters.AddWithValue("@SiteName", NUser_AuthSite_obj.SiteName); } else { cmd.Parameters.AddWithValue("@SiteName", ""); } if (cols.Length > 0) { cols.Append(","); parameters.Append(","); } cols.Append("[AllowList]"); parameters.Append("@AllowList"); cmd.Parameters.AddWithValue("@AllowList", NUser_AuthSite_obj.AllowList); if (cols.Length > 0) { cols.Append(","); parameters.Append(","); } cols.Append("[AllowSync]"); parameters.Append("@AllowSync"); cmd.Parameters.AddWithValue("@AllowSync", NUser_AuthSite_obj.AllowSync); if (cols.Length > 0) { cols.Append(","); parameters.Append(","); } cols.Append("[AllowRoll]"); parameters.Append("@AllowRoll"); cmd.Parameters.AddWithValue("@AllowRoll", NUser_AuthSite_obj.AllowRoll); if (cols.Length > 0) { cols.Append(","); parameters.Append(","); } cols.Append("[IsDel]"); parameters.Append("@IsDel"); cmd.Parameters.AddWithValue("@IsDel", NUser_AuthSite_obj.IsDel); if (cols.Length > 0) { cols.Append(","); parameters.Append(","); } cols.Append("[CreateTime]"); parameters.Append("@CreateTime"); if (NUser_AuthSite_obj.CreateTime == null || NUser_AuthSite_obj.CreateTime == DateTime.MinValue) { cmd.Parameters.AddWithValue("@CreateTime", DateTime.Now); } else { cmd.Parameters.AddWithValue("@CreateTime", NUser_AuthSite_obj.CreateTime); } sql = string.Format(sql, cols.ToString(), parameters.ToString()); cmd.CommandText = sql; bool b = true; try { object idobj = new Trans.Db.DBUtility.DBHelper(false).ExecScalar(cmd); ID = Convert.ToInt32(idobj); if (ID == 0) { b = false; } } catch { b = false; } return(b); }
/// <summary> /// 更新数据,行级数据锁定 /// 返回:操作影响记录数,-1表示没有需要更新的列 /// </summary> /// <param name="NUser_AuthSite_obj"></param> /// <param name="IsRowLock">是否锁行</param> /// <returns></returns> public static int Update(Trans.Db.Model.NUser_AuthSite NUser_AuthSite_obj, bool IsRowLock) { if (NUser_AuthSite_obj.ModifiedColumns.Count <= 0) { return(-1); } StringBuilder sqlSet = new StringBuilder(); StringBuilder sqlWhere = new StringBuilder(); string sql = string.Empty; if (IsRowLock) { sql = "UPDATE NUser_AuthSite WITH(ROWLOCK) SET {0} WHERE {1}"; } else { sql = "UPDATE NUser_AuthSite SET {0} WHERE {1}"; } SqlCommand cmd = new SqlCommand(); cmd.Parameters.AddWithValue("@ID", NUser_AuthSite_obj.ID); cmd.Parameters["@ID"].SqlDbType = System.Data.SqlDbType.Int; if (sqlWhere.Length > 0) { sqlWhere.Append(" AND "); } sqlWhere.Append("[ID]=@ID"); if (NUser_AuthSite_obj.ModifiedColumns.Contains("[UserID]")) { if (sqlSet.Length > 0) { sqlSet.Append(","); } sqlSet.Append("[UserID]=@UserID"); cmd.Parameters.AddWithValue("@UserID", NUser_AuthSite_obj.UserID); cmd.Parameters["@UserID"].SqlDbType = System.Data.SqlDbType.Int; } if (NUser_AuthSite_obj.ModifiedColumns.Contains("[SiteName]")) { if (string.IsNullOrEmpty(NUser_AuthSite_obj.SiteName)) { NUser_AuthSite_obj.SiteName = ""; } if (sqlSet.Length > 0) { sqlSet.Append(","); } sqlSet.Append("[SiteName]=@SiteName"); cmd.Parameters.AddWithValue("@SiteName", NUser_AuthSite_obj.SiteName); cmd.Parameters["@SiteName"].SqlDbType = System.Data.SqlDbType.NVarChar; } if (NUser_AuthSite_obj.ModifiedColumns.Contains("[AllowList]")) { if (sqlSet.Length > 0) { sqlSet.Append(","); } sqlSet.Append("[AllowList]=@AllowList"); cmd.Parameters.AddWithValue("@AllowList", NUser_AuthSite_obj.AllowList); cmd.Parameters["@AllowList"].SqlDbType = System.Data.SqlDbType.Int; } if (NUser_AuthSite_obj.ModifiedColumns.Contains("[AllowSync]")) { if (sqlSet.Length > 0) { sqlSet.Append(","); } sqlSet.Append("[AllowSync]=@AllowSync"); cmd.Parameters.AddWithValue("@AllowSync", NUser_AuthSite_obj.AllowSync); cmd.Parameters["@AllowSync"].SqlDbType = System.Data.SqlDbType.Int; } if (NUser_AuthSite_obj.ModifiedColumns.Contains("[AllowRoll]")) { if (sqlSet.Length > 0) { sqlSet.Append(","); } sqlSet.Append("[AllowRoll]=@AllowRoll"); cmd.Parameters.AddWithValue("@AllowRoll", NUser_AuthSite_obj.AllowRoll); cmd.Parameters["@AllowRoll"].SqlDbType = System.Data.SqlDbType.Int; } if (NUser_AuthSite_obj.ModifiedColumns.Contains("[IsDel]")) { if (sqlSet.Length > 0) { sqlSet.Append(","); } sqlSet.Append("[IsDel]=@IsDel"); cmd.Parameters.AddWithValue("@IsDel", NUser_AuthSite_obj.IsDel); cmd.Parameters["@IsDel"].SqlDbType = System.Data.SqlDbType.Int; } if (NUser_AuthSite_obj.CreateTime != null && NUser_AuthSite_obj.CreateTime > DateTime.MinValue && NUser_AuthSite_obj.ModifiedColumns.Contains("[CreateTime]")) { if (sqlSet.Length > 0) { sqlSet.Append(","); } sqlSet.Append("[CreateTime]=@CreateTime"); cmd.Parameters.AddWithValue("@CreateTime", NUser_AuthSite_obj.CreateTime); cmd.Parameters["@CreateTime"].SqlDbType = System.Data.SqlDbType.DateTime2; } sql = string.Format(sql, sqlSet.ToString(), sqlWhere.ToString()); cmd.CommandText = sql; try { return(new Trans.Db.DBUtility.DBHelper(false).ExecNonQuery(cmd)); } catch { return(-1); } }