Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        private ChatListSubItem TurnChatToSubItem(string msg)
        {
            ChatListSubItem sub = new ChatListSubItem();
            MySqlConnection con = new MySqlConnection(UserData.conStr);

            con.Open();
            string          sql = "select * from user where id='" + this.m_id + "'";
            MySqlCommand    cmd = new MySqlCommand(sql, con);
            MySqlDataReader mdr = cmd.ExecuteReader();

            while (mdr.Read())
            {
                sub.DisplayName = mdr.GetString("name");
                sub.ID          = Convert.ToUInt32(mdr.GetString("id"));
                sub.HeadImage   = MyOperation.LoadImage(mdr.GetString("photoPath").ToString());
                sub.PersonalMsg = msg;//这里显示最近聊天内容
                sub.IsTwinkle   = true;
            }
            con.Close();
            cmd.Dispose();
            return(sub);
        }
Exemplo n.º 3
0
 public Chat(string id)
 {
     if (MyOperation.JudgeIfServer(MyOperation.MyId))
     {
         if (!MyOperation.JudgeIfServer2(id))
         {
             goServer();
             // UserData.isClient = true;
         }
     }
     else
     {
         if (MyOperation.JudgeIfServer2(id))
         {
             goClient();
             // UserData.isClient = true;
         }
     }
     m_id = id;
     InitializeComponent();
     scanner.Focus();
     #region 数据库读取信息
     MySqlConnection con = new MySqlConnection(UserData.conStr);
     con.Open();
     string          sql = "select * from user where id='" + id + "'";
     MySqlCommand    cmd = new MySqlCommand(sql, con);
     MySqlDataReader mdr = cmd.ExecuteReader();
     while (mdr.Read())
     {
         lab_Name.Text  = mdr.GetString("name");
         this.Text      = "与" + mdr.GetString("name") + "的聊天";
         picture.Image  = MyOperation.LoadImage(mdr.GetString("photoPath").ToString());
         lab_sign.Text += mdr.GetString("sign");
     }
     con.Close();
     cmd.Dispose();
     #endregion
 }