public static int CreateThread(int bid, byte type, int uid, string uname, string uip, string name, string story) { return(DBH.GetInt32(QA.DBCS_MAIN, CommandType.StoredProcedure, "usp_thread_create", new SqlParameter("@bid", bid), new SqlParameter("@type", type), new SqlParameter("@uid", uid), new SqlParameter("@uname", uname), new SqlParameter("@uip", uip), new SqlParameter("@name", name), new SqlParameter("@story", story))); }
internal static bool CanApplyFriend(int uid, int tid) { if (IsFriend(uid, tid)) { return(false); //已经是朋友了 } int eid = DBH.GetInt32(QA.DBCS_MAIN, CommandType.Text, "SELECT id FROM event WHERE uid=@uid AND touid=@tid AND tmplname='apply_friend'", new SqlParameter("@uid", uid), new SqlParameter("@tid", tid)); if (eid > 0) //发送过邀请 { bool hasEventIndex = DBH.GetBoolean(QA.DBCS_MAIN, CommandType.Text, "SELECT COUNT(*) event_index WHERE uid=@tid AND eid=@eid", new SqlParameter("@tid", tid), new SqlParameter("@eid", eid)); if (hasEventIndex) { return(false); //对方还没处理 } } return(true); }
public static int Operate(int mid, NameValueCollection collection) { int rtn = 0; //get reposity_meta ReposityMeta rm = GetMeta(mid); string sql = null; IList <SqlParameter> spList = new List <SqlParameter>(); if (rm.OP == 0) { rtn = DBH.GetInt32(QA.DBCS_MAIN, CommandType.Text, sql, spList.ToArray <SqlParameter>()); } else if (rm.OP == 2) { rtn = DBH.ExecuteText(QA.DBCS_MAIN, sql, spList.ToArray <SqlParameter>()); } return(rtn); }
/// <summary> /// 创建用户 /// </summary> /// <param name="connectingString">数据库链接串</param> /// <param name="entity">实体对象</param> /// <returns>如果创建成功返回对应的实体对象。</returns> public static int Create(string connectingString, T entity, string tableName = null) { int ret = -1; try { Type t = entity.GetType(); if (string.IsNullOrEmpty(tableName)) { object[] tables = t.GetCustomAttributes(typeof(TableAttribute), false); if (tables != null && tables.Length == 1) { tableName = (tables[0] as TableAttribute).Name; } } if (tableName != null) { string sql = "INSERT INTO " + tableName + "("; string keys = string.Empty; string values = string.Empty; List <SqlParameter> parameters = new List <SqlParameter>(); //遍历字段 FieldInfo[] fields = t.GetFields(); foreach (FieldInfo f in fields) { object[] attrs = f.GetCustomAttributes(typeof(FieldAttribute), false); if (attrs.Length == 1) { FieldAttribute fa = attrs[0] as FieldAttribute; object o = f.GetValue(entity); if (!fa.AutoCreated) { if (fa.AllowNulls && o == null) { continue; } if (!string.IsNullOrEmpty(keys)) { keys += ","; values += ","; } keys += fa.Name; values += "@" + fa.Name; parameters.Add(new SqlParameter("@" + fa.Name, o)); } } } //遍历属性 PropertyInfo[] properties = t.GetProperties(); foreach (PropertyInfo f in properties) { object[] attrs = f.GetCustomAttributes(typeof(FieldAttribute), false); if (attrs.Length == 1) { FieldAttribute fa = attrs[0] as FieldAttribute; object o = f.GetValue(entity, null); if (!fa.AutoCreated && !fa.Identity) { if (fa.AllowNulls && o == null) { continue; } if (!string.IsNullOrEmpty(keys)) { keys += ","; values += ","; } keys += fa.Name; values += "@" + fa.Name; parameters.Add(new SqlParameter("@" + fa.Name, o)); } } } sql = sql + keys + ") VALUES(" + values + ");SELECT SCOPE_IDENTITY();"; ret = DBH.GetInt32(connectingString, CommandType.Text, sql, parameters.ToArray()); } } catch { /*TODO:LOG*/ } return(ret); }
private static int GetUserCategoryPid(int id, string categoryTable) { return(DBH.GetInt32(QA.DBCS_CMS, CommandType.Text, "SELECT pid FROM " + categoryTable + " WHERE id=@id", new SqlParameter("@id", id))); }