public AccountInfo AccountInfoReader(int user_id) { try { con.Open(); sql = "SELECT* FROM users_information WHERE user_id = " + user_id; MySQLCommand com = new MySQLCommand(sql, con); DbDataReader reader = com.ExecuteReader(); if(reader.Read()) { AccountInfo accountInfo = new AccountInfo(); accountInfo.Sex = short.Parse(reader["user_sex"].ToString()); accountInfo.Birthday = DateTime.Parse(reader["user_birthday"].ToString()); accountInfo.Phone = reader["uesr_phome"].ToString(); return accountInfo; } return null; } catch { return null; } finally { con.Close(); } }
public ReadUserInfo(DataPackage data) { AccountInfoConvet convert = new AccountInfoConvet(); accountInfo = convert.ConvertToClass(data.Data); SQLService sql = new SQLService(); accountInfo = sql.AccountInfoReader(accountInfo.User_id); dataSend.Client = data.Client; dataSend.Data = convert.ConvertToBytes(accountInfo); }
public EditAccountInfo(DataPackage data) { AccountInfoConvet convert = new AccountInfoConvet(); accountInfo = convert.ConvertToClass(data.Data); dataSend.Client = data.Client; }
public AccountInfo ConvertToClass(byte[] data) { AccountInfo dataResult = new AccountInfo(); byte[] bUid = new byte[4]; byte[] bUser_id = new byte[4]; byte[] bUser_sex = new byte[2]; byte[] bUser_birthday = new byte[4]; byte[] bUser_phone = new byte[24]; for (int i = 0; i < 4; i++) bUid[i] = data[i + 2]; for (int i = 0; i < 4; i++) bUser_id[i] = data[i + 6]; for (int i = 0; i < 2; i++) bUser_sex[i] = data[i + 10]; for (int i = 0; i < 4; i++) bUser_birthday[i] = data[i + 12]; for (int i = 0; i < 24; i++) bUser_phone[i] = data[i + 16]; return null; }
public byte[] ConvertToBytes(AccountInfo data) { //4+2+4+24 byte[] bResult = new byte[42]; byte[] bMessageType = BitConverter.GetBytes(data.MessageType); byte[] bUid = BitConverter.GetBytes(data.Uid); byte[] bUser_id = BitConverter.GetBytes(data.User_id); byte[] bUser_sex = BitConverter.GetBytes(data.Sex); byte[] bUser_birthdat = BitConverter.GetBytes(data.Birthday.Ticks); byte[] bUser_phone = Encoding.Default.GetBytes(data.Phone); for (int i = 0; i < bMessageType.Length; i++) bResult[i + 0] = bMessageType[i]; for (int i = 0; i < bUid.Length; i++) bResult[i + 2] = bUid[i]; for (int i = 0; i < bUser_id.Length; i++) bResult[i + 6] = bUser_id[i]; for (int i = 0; i < bUser_sex.Length; i++) bResult[i + 10] = bUser_sex[i]; for (int i = 0; i < bUser_birthdat.Length; i++) bResult[i + 12] = bUser_birthdat[i]; for (int i = 0; i < bUser_phone.Length; i++) bResult[i + 16] = bUser_phone[i]; return bResult; }
public bool AccountInfoEditor(AccountInfo accountInfo) { try { con.Open(); sql = "UPDATE user_sex = " + accountInfo.Sex + ", user_birthday = " + accountInfo.Birthday + ", user_phone = " + accountInfo.Phone + " FROM users_information WHERE user_id = " + accountInfo.User_id; MySQLCommand com = new MySQLCommand(sql, con); com.ExecuteNonQuery(); return true; } catch { return false; } finally { con.Close(); } }
public ArrayList SearchAccount(SelectAccount selAccount) { try { //AccountInfo accountInfo = new AccountInfo(); //accountInfo.Sex = short.Parse(reader["user_sex"].ToString()); //accountInfo.Birthday = DateTime.Parse(reader["user_birthday"].ToString()); //accountInfo.Phone = reader["uesr_phome"].ToString(); //return accountInfo; con.Open(); sql = "INNER JOIN users_information ON users_information.user_name LIKE '%" + selAccount.Sel_info + "%'"; MySQLCommand com = new MySQLCommand(sql, con); MySQLDataAdapter adp = new MySQLDataAdapter(com); DataSet ds = new DataSet(); adp.Fill(ds); ArrayList arr = new ArrayList(); foreach (DataRow dr in ds.Tables[0].Rows) { AccountInfo accountInfo = new AccountInfo(); accountInfo.User_id = Int32.Parse(dr["user_id"].ToString()); accountInfo.User_name = dr["user_name"].ToString(); accountInfo.Sex = short.Parse(dr["user_sex"].ToString()); accountInfo.Birthday = DateTime.Parse(dr["user_birthday"].ToString()); accountInfo.Phone = dr["uesr_phome"].ToString(); arr.Add(accountInfo); } try { sql = "SELECT * FROM users INNER JOIN users_information ON users.user_id = " + Int32.Parse(selAccount.Sel_info); com = new MySQLCommand(sql, con); DbDataReader reader = com.ExecuteReader(); if(reader.Read()) { AccountInfo accountInfo = new AccountInfo(); accountInfo.User_id = Int32.Parse(reader["user_id"].ToString()); accountInfo.User_name = reader["user_name"].ToString(); accountInfo.Sex = short.Parse(reader["user_sex"].ToString()); accountInfo.Birthday = DateTime.Parse(reader["user_birthday"].ToString()); accountInfo.Phone = reader["uesr_phome"].ToString(); arr.Add(accountInfo); } } catch { } return arr; } catch(Exception ex) { throw ex; } finally { con.Close(); } }