private void Send_Click(object sender, EventArgs e) { emojiGroup.Visible = false; if (scanner.Text != "") { if (UserData.isClient) { SendClient(); } else { sendServer(scanner.Text); } ChatListSubItem recentSub = TurnChatToSubItem(scanner.Text); if (IsDistinct(scanner.Text)) { InfoList.CreateOrReadInstance().chatListBox_Message.Items[0].SubItems.Remove(recentSub); } else { InfoList.CreateOrReadInstance().chatListBox_Message.Items[0].SubItems.Add(recentSub); } scanner.Text = ""; } else { MessageBox.Show("消息不能为空!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void loginSignIn_Click(object sender, EventArgs e) { if (loginID.Text == "" || loginCypher.Text == "") { MessageBox.Show("账号和密码不能为空!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } con.Open(); //连接数据库查询 bool flag = false; string sql = "select * from user where id='" + loginID.Text + "' and password='******'"; MySqlCommand command = new MySqlCommand(sql, con); MySqlDataReader reader = command.ExecuteReader(); MySqlDataReader user = null; while (reader.Read()) { if ((reader.GetValue(0).ToString().Trim()) == (loginID.Text.Trim()) && (reader.GetValue(1).ToString().Trim()) == (loginCypher.Text.Trim())) { flag = true; user = reader; break; } } if (!flag) { MessageBox.Show("账号或密码错误!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { String ip = Dns.GetHostEntry(Dns.GetHostName()).AddressList.ToString(); String name = user.GetValue(2).ToString().Trim(); String sign = user.GetValue(3).ToString().Trim(); UserData.m_userData = new UserData(ip, loginID.Text, loginCypher.Text, name, sign); // InfoList m_infoList = new InfoList(m_userData); InfoList m_infoList = InfoList.CreateOrReadInstance(); if (server.Checked) { UserData.isClient = false; MyOperation.SaveIfServerToSQL(loginID.Text);//服务端初始化ip到数据库 } else { UserData.isClient = true; } m_infoList.Show(); this.Visible = false; #region 初始化好友列表 // MyOperation.ReadConnectToList(loginID.Text); MyOperation.MyId = loginID.Text; // MyOperation.LoadConnectionFromList(); #endregion } con.Close(); }
private bool IsDistinct(string changeText) { bool isSame = false; foreach (ChatListSubItem item in InfoList.CreateOrReadInstance().chatListBox_Message.Items[0].SubItems) { if (item.ID.ToString().Trim() == m_id.ToString().Trim()) { isSame = true; item.PersonalMsg = changeText; break; } } return(isSame); }
public Msg_IfAddFriend(InfoList m_infoList) { InitializeComponent(); me_info = m_infoList; Instance = this; }