Beispiel #1
0
        //注册的时候 对比信息 是否已有账号 已经存在就返回true  不存在返回false
        private bool IsExistID(List <Object> info)
        {
            string selectstr = String.Format("select * from IDInfo where ip='{0}' and port = {1}",
                                             info[1].ToString(),
                                             Convert.ToInt32(info[2].ToString()));
            DBDeal dbDeal2 = new DBDeal();

            return(dbDeal2.SqlSelectHas(selectstr));                //已经存在账号则返回客户端
        }
Beispiel #2
0
        //------------------------------------------------------------------------------------------

        //判断是登陆还是注册 用户列表 退出 用户信息
        private string IsLoginOrRegister(List <Object> info)
        {
            ShowInfoOnView(info, info[0].ToString());
            switch (info[0].ToString())
            {
            case "1":
                //是注册的话先判断是否存在   不存在则新建并进行数据存储
                if (IsExistID(info) == false)
                {
                    string insertStr = String.Format("insert into IDInfo(ip,port,pwd,name,sex,lastlogindate,islogin) values('{0}',{1},'{2}','{3}','{4}','{5}',{6})",
                                                     info[1].ToString(),
                                                     Convert.ToInt32(info[2].ToString()),
                                                     info[3].ToString(),
                                                     info[4].ToString(),
                                                     info[5].ToString(),
                                                     DateTime.Now.ToString(),
                                                     0); //0 代表下线  1 代表上线
                    DBDeal dbDeal = new DBDeal();
                    int    i      = dbDeal.SqlAction(insertStr);
                    if (i > 0)
                    {
                        //更新服务器的显示信息
                        dataGridView1.Invoke((MethodInvoker)(() =>
                        {
                            ShowClientInfo();
                        }));
                        //在注册时候会出现错误  会直接进入下一线程    交给ui线程 在等ui线程?? 都在等(死锁)
                        //MessageBox.Show("注册成功!!!", "提示",
                        //    MessageBoxButtons.OK,
                        //    MessageBoxIcon.Information);
                    }
                    return("2");
                }
                else
                {
                    return("23");
                }

            case "3":
                //是登陆的话进行数据对比
                string selectstr = String.Format("select * from IDInfo where ip='{0}' and port = {1} and pwd='{2}'",
                                                 info[1].ToString(),
                                                 Convert.ToInt32(info[2].ToString()),
                                                 info[3], ToString());
                DBDeal dbDeal2 = new DBDeal();
                if (dbDeal2.SqlSelectHas(selectstr))                    //有账号则返回客户端  "4"
                {
                    UpdateLoginStateAndTime_Close(info, 1, 1);          //修改该账号的登陆状态到数据库

                    dataGridView1.Invoke((MethodInvoker)(() =>          //更新服务器的显示信息
                    {
                        ShowClientInfo();
                    }));
                    return("4");
                }
                return("gg");                                           //无账号则返回客户端  "gg"

            case "7":
                //进行客户端好友列表更新
                return("7");

            case "12":                                                  //代表下线
                //是退出的话进行数据更新
                UpdateLoginStateAndTime_Close(info, 1, 0);              //修改该账号的登陆状态到数据库

                dataGridView1.Invoke((MethodInvoker)(() =>              //更新服务器的显示信息
                {
                    ShowClientInfo();
                }));
                return("12");

            case "22":                                                  //代表给客户端发送ip port对应的用户信息
                //代表给客户端发送ip port对应的用户信息
                temp = new List <object>();
                temp.Add(info[1].ToString());
                temp.Add(info[2].ToString());
                return("22");

            default:
                return("0");                                            //代表不存在
            }
        }