public UInt64 InsertVote(VoteItem item) { MySqlCommand command = new MySqlCommand(); command.CommandText = insertVoteStr; command.CommandType = System.Data.CommandType.Text; command.Connection = conn; command.Parameters.Add(new MySqlParameter("@userId", item.UserBelong)); command.Parameters.Add(new MySqlParameter("@topic", item.Topic)); command.Parameters.Add(new MySqlParameter("@desc", item.Desc)); command.Parameters.Add(new MySqlParameter("@voteAble", item.VoteAble)); command.Parameters.Add(new MySqlParameter("@createTime", item.CreateTime)); command.Parameters.Add(new MySqlParameter("@overdueTime", item.OverdueTime)); command.Parameters.Add(new MySqlParameter("@multiNum", item.MultiNum)); conn.Open(); try { int res = command.ExecuteNonQuery(); if (res <= 0) { conn.Close(); return(0); } } catch { conn.Close(); return(0); } MySqlCommand command1 = new MySqlCommand(); command1.CommandText = getLastInsertId; command1.CommandType = System.Data.CommandType.Text; command1.Connection = conn; try { UInt64 res = (UInt64)command1.ExecuteScalar(); return(res); } catch { return(0); } finally { conn.Close(); } }
public bool GetVoteFromNThToMTh(ref SplitPageRes list, uint n, uint m, int size, uint userId) { if (m - n != size || n > m) { return(false); } MySqlCommand command = new MySqlCommand(); command.CommandText = getUserVoteFromNThToMThStr; command.CommandType = System.Data.CommandType.Text; command.Connection = conn; command.Parameters.Add(new MySqlParameter("@nTh", n)); command.Parameters.Add(new MySqlParameter("@mTh", m)); command.Parameters.Add(new MySqlParameter("@userId", userId)); conn.Open(); try { var res = command.ExecuteReader(); int i = 0; List <VoteItem> b = new List <VoteItem>(); while (res.Read() && i < size) { VoteItem temp = new VoteItem(); temp.VoteId = (uint)res[0]; temp.UserBelong = (uint)res[1]; temp.Topic = (string)res[2]; temp.Desc = (string)res[3]; temp.VoteAble = (Byte)res[4]; temp.CreateTime = (uint)res[5]; temp.OverdueTime = (uint)res[6]; temp.MultiNum = (uint)res[7]; ++i; b.Add(temp); } list.items = b.ToArray(); } catch { return(false); } finally { conn.Close(); } return(true); }
public bool GetVoteFromNThToMTh(ref SplitPageRes list, uint n, uint m, int size) { //private string getVoteFromNThToMThStr = "SELECT `vote`.`id`, `vote`.`user_belong`,`vote`.`topic`,`vote`.`desc`,`vote`.`vote_able`,`vote`.`create_time`,`vote`.`overdue_time`,`vote`.`multi_num`" + // " from vote limit @nTh, @mTh"; if (m - n != size || n > m) { return(false); } MySqlCommand command = new MySqlCommand(); command.CommandText = getVoteFromNThToMThStr; command.CommandType = System.Data.CommandType.Text; command.Connection = conn; command.Parameters.Add(new MySqlParameter("@nTh", n)); command.Parameters.Add(new MySqlParameter("@mTh", m)); conn.Open(); try { var res = command.ExecuteReader(); int i = 0; List <VoteItem> b = new List <VoteItem>(); while (res.Read() && i < size) { VoteItem temp = new VoteItem(); temp.VoteId = (uint)res[0]; temp.UserBelong = (uint)res[1]; temp.Topic = (string)res[2]; temp.Desc = (string)res[3]; temp.VoteAble = (Byte)res[4]; temp.CreateTime = (uint)res[5]; temp.OverdueTime = (uint)res[6]; temp.MultiNum = (uint)res[7]; ++i; b.Add(temp); } list.items = b.ToArray(); } catch { return(false); } finally { conn.Close(); } return(true); }
public bool getItemsInVote(uint voteId, ref VoteItem item) { MySqlCommand command = new MySqlCommand(); command.CommandText = getItemsInVoteStr; command.CommandType = System.Data.CommandType.Text; command.Connection = conn; command.Parameters.Add(new MySqlParameter("@voteId", voteId)); conn.Open(); var res = command.ExecuteReader(); List <uint> b = new List <uint>(); while (res.Read()) { b.Add((uint)res[0]); } item.ItemIds = b.ToArray(); return(true); }
public bool UpdateVoteItem(VoteItem item) { //private string updateVoteItemStr = "UPDATE `voters`.`vote` SET `topic`=@topic, `desc`=@desc, `vote_able`=@voteAble, `overdue_time`=@overDueTime, `multi_num`=@multiNum WHERE `id`=@voteId"; MySqlCommand command = new MySqlCommand(); command.CommandText = updateVoteItemStr; command.CommandType = System.Data.CommandType.Text; command.Connection = conn; command.Parameters.Add(new MySqlParameter("@topic", item.Topic)); command.Parameters.Add(new MySqlParameter("@desc", item.Desc)); command.Parameters.Add(new MySqlParameter("@voteAble", item.VoteAble)); command.Parameters.Add(new MySqlParameter("@overDueTime", item.OverdueTime)); command.Parameters.Add(new MySqlParameter("@multiNum", item.MultiNum)); command.Parameters.Add(new MySqlParameter("@voteId", item.VoteId)); conn.Open(); try { int res = command.ExecuteNonQuery(); if (res <= 0) { return(false); } } catch { return(false); } finally { conn.Close(); } return(true); }
public bool GetVoteItem(uint voteId, ref VoteItem item) { MySqlCommand command = new MySqlCommand(); command.CommandText = getVoteItemStr; command.CommandType = System.Data.CommandType.Text; command.Connection = conn; command.Parameters.Add(new MySqlParameter("@voteId", voteId)); conn.Open(); try { var res = command.ExecuteReader(); if (res.Read()) { item.VoteId = (uint)res[0]; item.UserBelong = (uint)res[1]; item.Topic = (string)res[2]; item.Desc = (string)res[3]; item.VoteAble = (Byte)res[4]; item.OverdueTime = (uint)res[5]; item.CreateTime = (uint)res[6]; item.MultiNum = (uint)res[7]; return(true); } } catch { return(false); } finally { conn.Close(); } return(false); }