public int Register() { if (m_username.Length >= Variable.MinLength.UserName && m_password.Length >= Variable.MinLength.Password && new Regex(Variable.Regix.Email).IsMatch(m_email.ToLower())) { string salt = Guid.NewGuid().ToString(); object uid = MariaDBHelper.ExecuteScalar( "RegisterUser", CommandType.StoredProcedure, new MySqlParameter("UserName", m_username), new MySqlParameter("Salt", salt), new MySqlParameter("UserNameHash", MariaDBHelper.GetHashCode(m_username + salt)), new MySqlParameter("PasswordHash", MariaDBHelper.GetHashCode(m_password + salt)), new MySqlParameter("UserRole", Variable.UserRole.user), new MySqlParameter("Status", Variable.State.User.inActived), new MySqlParameter("Email", m_email), new MySqlParameter("RegisterTime", DateTime.Now) ); return(Convert.ToInt32(uid)); } else { return(-1); } }
public static int GetCount() { object count = MariaDBHelper.ExecuteScalar( "GetMessagesCount", CommandType.StoredProcedure); return Convert.ToInt32(count); }
public static void GetMsgListByPage(int page, out List<Message> msgs) { List<Message> buff = new List<Message>(); MariaDBHelper.ExecuteReader( "GetMessageByPage", CommandType.StoredProcedure, (MySqlDataReader dataReader) => { while (dataReader.Read()) { long id = Convert.ToInt64(MariaDBHelper.GetData(dataReader, "Id")); string composer = MariaDBHelper.GetData(dataReader, "Composer"); string content = MariaDBHelper.GetData(dataReader, "Content"); DateTime post_time = Convert.ToDateTime(MariaDBHelper.GetData(dataReader, "PostTime")); int support = Convert.ToInt32(MariaDBHelper.GetData(dataReader, "Support")); int oppose = Convert.ToInt32(MariaDBHelper.GetData(dataReader, "Oppose")); int reply_num = Convert.ToInt32(MariaDBHelper.GetData(dataReader, "ReplyNum")); int report = Convert.ToInt32(MariaDBHelper.GetData(dataReader, "Report")); long reply_msgid = Convert.ToInt32(MariaDBHelper.GetData(dataReader, "ReplyMsgID")); buff.Add(new Message(id, composer, content, post_time, support, oppose, reply_num, report, reply_msgid)); } }, new MySqlParameter("@Page", page) ); msgs = new List<Message>(buff.ToArray()); }
public int Remove() { return MariaDBHelper.ExecuteNonQuery( "RemoveMessage", CommandType.StoredProcedure, new MySqlParameter("Id", m_id) ); }
public int Reply(CommentEntity cmt) { return(MariaDBHelper.ExecuteNonQuery( "ReplyCommentById", CommandType.StoredProcedure, new MySqlParameter("SourceId", cmt.m_id), new MySqlParameter("Content", m_content), new MySqlParameter("Now", m_postTime), new MySqlParameter("Composer", m_composer), new MySqlParameter("PostIP", m_postIP) )); }
public int Reply(MessageEntity msg) { return MariaDBHelper.ExecuteNonQuery( "ReplyMessageById", CommandType.StoredProcedure, new MySqlParameter("Content", m_content), new MySqlParameter("Now", m_postTime), new MySqlParameter("Composer", m_composer), new MySqlParameter("PostIP", m_postIP), new MySqlParameter("SourceID", msg.m_id) ); }
public int Post() { object id = MariaDBHelper.ExecuteScalar( "PostMessage", CommandType.StoredProcedure, new MySqlParameter("Content", m_content), new MySqlParameter("Composer", m_composer), new MySqlParameter("PostIP", m_postIP), new MySqlParameter("PostTime", m_postTime) ); return Convert.ToInt32(id); }
public int Add() { return(MariaDBHelper.ExecuteNonQuery( "AddResource", CommandType.StoredProcedure, new MySqlParameter("Parent", m_parentFolder), new MySqlParameter("Name", m_name), new MySqlParameter("Type", m_type), new MySqlParameter("Format", m_format), new MySqlParameter("Composer", m_composer), new MySqlParameter("Description", m_description) )); }
public int Remove(string path) { if (m_type.ToLower() == "folder" && Directory.Exists(path)) { Directory.Delete(path, true); } else if (File.Exists(path)) { File.Delete(path); } return(MariaDBHelper.ExecuteNonQuery( "RemoveResource", CommandType.StoredProcedure, new MySqlParameter("@ResourceId", m_id) )); }
public int React(string react) { switch (react.ToLower()) { case "support": case "oppose": case "report": return(MariaDBHelper.ExecuteNonQuery( string.Format("UPDATE T_Comment SET {0} = {0} + 1, F_ReactLastIP = @Ip WHERE F_Id = @Id", "F_" + react), CommandType.Text, new MySqlParameter("Id", m_id), new MySqlParameter("Ip", m_postIP) )); default: return(-1); } }
public List <int> GetChildren() { List <int> children = new List <int>(); MariaDBHelper.ExecuteReader( "GetResourceChildren", CommandType.StoredProcedure, (MySqlDataReader dataReader) => { while (dataReader.Read()) { children.Add(Convert.ToInt32(MariaDBHelper.GetData(dataReader, "Id"))); } }, new MySqlParameter("@Id", m_id) ); return(children); }
public static List <int> GetListByResourceAndPage(int id, int page) { List <int> list = new List <int>(); MariaDBHelper.ExecuteReader( "GetCommentsByResourceID", CommandType.StoredProcedure, (MySqlDataReader dataReader) => { while (dataReader.Read()) { list.Add(Convert.ToInt32(MariaDBHelper.GetData(dataReader, "ID"))); } }, new MySqlParameter("ResourceID", id) ); return(list); }
public int LoginByWeibo(string code) { int loginStatus = 0; int uid = 0;// new Weibo(code).Login(); MariaDBHelper.ExecuteReader( "GetUserByWeibo", CommandType.StoredProcedure, (MySqlDataReader dataReader) => { if (dataReader.Read()) { m_username = MariaDBHelper.GetData(dataReader, "Username"); m_role = MariaDBHelper.GetData(dataReader, "UserRole"); loginStatus = 1; } }, new MySqlParameter("@WeiboUserId", uid) ); return(loginStatus); }
public int Login() { string salt = string.Empty, passwordHash = string.Empty; MariaDBHelper.ExecuteReader( "GetUserByUsername", CommandType.StoredProcedure, (MySqlDataReader dataReader) => { if (dataReader.Read()) { salt = MariaDBHelper.GetData(dataReader, "Salt"); passwordHash = MariaDBHelper.GetData(dataReader, "PasswordHash"); } }, new MySqlParameter("UserName", m_username) ); if (m_username.Length <= Variable.MinLength.UserName && m_password.Length <= Variable.MinLength.Password) { return(-1); } else if (MariaDBHelper.GetHashCode(m_password + salt) == passwordHash) { object loginId = MariaDBHelper.ExecuteScalar( "LoginUser", CommandType.StoredProcedure, new MySqlParameter("Ticket", m_ticket), new MySqlParameter("UserName", m_username), new MySqlParameter("LoginIP", m_loginIp), new MySqlParameter("LoginTime", DateTime.Now), new MySqlParameter("Status", Variable.State.Login.valid) ); return(Convert.ToInt32(loginId)); } else { return(0); } }
public void GetUserInfo() { MariaDBHelper.ExecuteReader( "GetUserByUsername", CommandType.StoredProcedure, (MySqlDataReader dataReader) => { if (dataReader.Read()) { m_id = Convert.ToInt32(MariaDBHelper.GetData(dataReader, "Id")); m_salt = Convert.ToString(MariaDBHelper.GetData(dataReader, "Salt")); m_status = Convert.ToString(MariaDBHelper.GetData(dataReader, "Status")); m_gender = Convert.ToString(MariaDBHelper.GetData(dataReader, "Gender")); m_realName = Convert.ToString(MariaDBHelper.GetData(dataReader, "RealName")); m_phoneNumber = Convert.ToString(MariaDBHelper.GetData(dataReader, "PhoneNumber")); m_role = Convert.ToString(MariaDBHelper.GetData(dataReader, "UserRole")); m_registerTime = Convert.ToString(MariaDBHelper.GetData(dataReader, "RegisterTime")); m_email = Convert.ToString(MariaDBHelper.GetData(dataReader, "Email")); } }, new MySqlParameter("@UserName", m_username) ); }
public ResourceEntity(int id) { MariaDBHelper.ExecuteReader( "GetResourceById", CommandType.StoredProcedure, (MySqlDataReader dataReader) => { if (dataReader.Read()) { m_id = id; m_parentFolder = Convert.ToInt32(MariaDBHelper.GetData(dataReader, "ParentFolder")); m_name = MariaDBHelper.GetData(dataReader, "Name"); m_uri = MariaDBHelper.GetData(dataReader, "Uri"); m_cover = MariaDBHelper.GetData(dataReader, "Cover"); m_type = MariaDBHelper.GetData(dataReader, "Type"); m_format = MariaDBHelper.GetData(dataReader, "Format"); m_composer = MariaDBHelper.GetData(dataReader, "Composer"); m_description = MariaDBHelper.GetData(dataReader, "Description"); } }, new MySqlParameter("@Id", id) ); }
public CommentEntity(int id) { MariaDBHelper.ExecuteReader( "GetCommentByID", CommandType.StoredProcedure, (MySqlDataReader dataReader) => { if (dataReader.Read()) { m_id = id; m_resourceId = Convert.ToInt32(MariaDBHelper.GetData(dataReader, "ResourceId")); m_composer = MariaDBHelper.GetData(dataReader, "Composer"); m_content = MariaDBHelper.GetData(dataReader, "Content"); m_postTime = Convert.ToDateTime(MariaDBHelper.GetData(dataReader, "PostTime")); m_support = Convert.ToInt32(MariaDBHelper.GetData(dataReader, "Support")); m_oppose = Convert.ToInt32(MariaDBHelper.GetData(dataReader, "Oppose")); m_replyNum = Convert.ToInt32(MariaDBHelper.GetData(dataReader, "ReplyNum")); m_report = Convert.ToInt32(MariaDBHelper.GetData(dataReader, "Report")); m_replyMsgID = Convert.ToInt32(MariaDBHelper.GetData(dataReader, "ReplyMsgID")); } }, new MySqlParameter("@Id", id) ); }