⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 operationcenter.cs

📁 .Net实现的局域网完整IM,含完整的设计远隔
💻 CS
📖 第 1 页 / 共 5 页
字号:
                                    //FLD_UID,FLD_ACCOUNT,FLD_PASSWORD
                                    //FLD_NICKNAME,FLD_HEADPIC,FLD_MYSHOW
                                    //FLD_SEX,FLD_BIRTHDAY,FLD_BEWRITE
                                    //FLD_OPENTIME,FLD_LASTTIME
                                    //FLD_LASTIP,FLD_LASTPORT,FLD_STATE
                                    //Out:
                                    //HeadPic,NickName,UID,Sex,Bewrite
                                    t_CRow = t_Rows[t_n];
                                    if ((int)t_CRow[0] != t_SUID &&
                                        (string)t_CRow[3] == t_SKeyNN &&
                                          Convert.ToChar(t_CRow[13]) == USER_STATE_HOT)
                                    {
                                        t_bWriter.Write((int)t_CRow[4]);
                                        t_bWriter.Write((string)t_CRow[3]);
                                        t_bWriter.Write((int)t_CRow[0]);
                                        t_bWriter.Write((int)t_CRow[6]);
                                        t_bWriter.Write((string)t_CRow[8]);
                                        t_bWriter.Write((int)t_CRow[5]);
                                        t_bWriter.Flush();
                                    }
                                }
                            }
                            else
                            {
                                t_bWriter.Write(0);
                                t_bWriter.Flush();
                            }
                        }
                    }
                    else if (t_MType == MESSAGE_TYPE_REQUESTFRIEND)
                    {
                        int t_FUID;
                        string t_FNName;

                        t_FUID = t_bReader.ReadInt32();
                        t_FNName = t_bReader.ReadString();
                        RequestBeFriend(t_Session._uID, t_Session._uNName, t_FUID, t_FNName);
                    }
                    else if (t_MType == MESSAGE_TYPE_AGEEBEFRIEND)
                    {
                        int t_FUID;
                        string t_FNName;

                        t_FUID = t_bReader.ReadInt32();
                        t_FNName = t_bReader.ReadString();
                        BeFriend(t_Session._uID, t_Session._uNName, t_FUID, t_FNName);
                    }
                    else if (t_MType == MESSAGE_TYPE_DELETEFRIEND)
                    {
                        int t_FUID;
                        string t_FNName;

                        t_FUID = t_bReader.ReadInt32();
                        t_FNName = t_bReader.ReadString();

                        if (DeleteFriend(t_Session._uID, t_Session._uNName, t_FUID, t_FNName) == true)
                        {
                            t_bWriter.Write('t');
                        }
                        else
                        {
                            t_bWriter.Write('f');
                        }
                        t_bWriter.Flush();
                    }
                    else if (t_MType == MESSAGE_TYPE_NEWUSERINFO)
                    {
                        icUser t_User = new icUser();

                        t_User._uID = t_Session._uID;
                        t_User._account = t_bReader.ReadString().Replace("'", "''");
                        t_User._password = t_bReader.ReadString().Replace("'", "''");
                        t_User._nickName = t_bReader.ReadString().Replace("'", "''");
                        t_User._headPic = t_bReader.ReadInt32();
                        t_User._myShow = t_bReader.ReadInt32();
                        t_User._sex = t_bReader.ReadInt32();
                        t_User._birthDay = t_bReader.ReadString().Replace("'", "''");
                        t_User._bewrite = t_bReader.ReadString();
                        if (t_User._bewrite != null)
                        {
                            t_User._bewrite = t_User._bewrite.Replace("'", "''");
                        }

                        if (NewUserInfo(t_User) == true)
                        {
                            t_bWriter.Write('t');
                        }
                        else
                        {
                            t_bWriter.Write('f');
                        }
                        t_bWriter.Flush();
                    }
                    else if (t_MType == MESSAGE_TYPE_MESSAGE)
                    {
                        int t_FUID;
                        string t_Message;

                        t_FUID = t_bReader.ReadInt32();
                        t_Message = t_bReader.ReadString();

                        SendMessage(t_Session._uID, t_FUID, t_Message);
                    }
                    else if (t_MType == MESSAGE_TYPE_EXIT)
                    {
                        t_JE = new NewControl.JPM_List_Entity();

                        UserLeave(t_Session._uID);

                        t_JE.Add(global::JPMLab_LanTalker_Server.Properties.Resources.BMP_CLIENTCLOSE);
                        t_JE.Add(Convert.ToString(t_UID));
                        t_JE.Add(System.DateTime.Now.ToString());
                        t_JE.Add(global::JPMLab_LanTalker_Server.Properties.Resources.STR_MSGTYPE_USER);
                        t_JE.Add(t_Acc + global::JPMLab_LanTalker_Server.Properties.Resources.STR_MSGCONTENT_CLIENTCLOSE + MESSAGE_TYPE_EXIT);
                        _MessageList.AddAnEntity(t_JE);

                        break;
                    }
                }

                t_bReader.Close();
                t_bWriter.Close();
                t_NStream.Close();
                t_NowSocket.Close();
            }
            catch (Exception e)
            {
                t_JE = new NewControl.JPM_List_Entity();

                UserLeave(t_Session._uID);

                t_JE.Add(global::JPMLab_LanTalker_Server.Properties.Resources.BMP_CLIENTCLOSE);
                t_JE.Add(Convert.ToString(t_UID));
                t_JE.Add(System.DateTime.Now.ToString());
                t_JE.Add(global::JPMLab_LanTalker_Server.Properties.Resources.STR_MSGTYPE_USER);
                t_JE.Add(t_Acc + global::JPMLab_LanTalker_Server.Properties.Resources.STR_MSGCONTENT_CLIENTCLOSE + e.Message);
                _MessageList.AddAnEntity(t_JE);

                System.Console.WriteLine(e.Message);
            }


            _icSessionList.Remove(t_Session);
            if (_SessionList.IsDisposed == false)
            {
                _SessionList.RemoveItem(t_SJE);
            }
        }

        static void thdfunMsgListener()
        {
            try
            {
                _socMsgListener = new TcpListener(_serverPort);

                _socMsgListener.Start();

                while (_keepListen == true)
                {
                    if (_socMsgListener.Pending() == true)
                    {
                        Thread t_thdSession = new Thread(new ThreadStart(thdfunSession));
                        t_thdSession.Start();
                    }
                }

                _socMsgListener.Stop();
                _thdMsgListener = null;
            }
            catch (Exception e)
            {
                if (_MessageList != null)
                {
                    NewControl.JPM_List_Entity t_JE = new NewControl.JPM_List_Entity();

                    t_JE.Add(global::JPMLab_LanTalker_Server.Properties.Resources.BMP_SERVERERROR);
                    t_JE.Add(Convert.ToString(SERVER_UID));
                    t_JE.Add(System.DateTime.Now.ToString());
                    t_JE.Add(global::JPMLab_LanTalker_Server.Properties.Resources.STR_MSGTYPE_SYSTEM);
                    t_JE.Add(global::JPMLab_LanTalker_Server.Properties.Resources.STR_SERVER_FAILSTARTNETWORK);

                    _MessageList.AddAnEntity(t_JE);
                }

                Console.Write(e.Message);
            }
        }

        ///<summary>
        /// Data operation
        ///</summary>

        public static bool LoadData()
        {
            if (_dataConnection != null)
            {
                return true;
            }

            try
            {
                //FLD_UID,FLD_ACCOUNT,FLD_PASSWORD
                //FLD_NICKNAME,FLD_HEADPIC,FLD_MYSHOW
                //FLD_SEX,FLD_BIRTHDAY,FLD_BEWRITE
                //FLD_OPENTIME,FLD_LASTTIME
                //FLD_LASTIP,FLD_LASTPORT,FLD_STATE

                _dataConnection = new SqlConnection();
                NewControl.JPM_List_Entity t_JE;

                _dataConnection.ConnectionString = "SERVER=Localhost;DATABASE=LabLT;UID=mda_LabLT;PWD=1133";
                _dataConnection.Open();
                _dataAdpter = new SqlDataAdapter("SELECT FLD_UID,FLD_ACCOUNT,FLD_PASSWORD,FLD_NICKNAME,FLD_HEADPIC,FLD_MYSHOW,FLD_SEX,FLD_BIRTHDAY,FLD_BEWRITE,FLD_OPENTIME,FLD_LASTTIME,FLD_LASTIP,FLD_LASTPORT,FLD_STATE FROM TBL_Account", _dataConnection);
                _dataAdpter.Fill(_dsetUsers, DATASET_TABLE_USERS);

                if (_UserList != null)
                {
                    int t_c;

                    t_c = _dsetUsers.Tables[0].Rows.Count;
                    _UserList.Clear();
                    if (t_c > 0)
                    {
                        int t_n;
                        System.Data.DataRowCollection t_Rows;
                        System.Data.DataRow t_CRow;

                        t_Rows = _dsetUsers.Tables[0].Rows;
                        for (t_n = 0; t_n < t_c; t_n++)
                        {
                            t_CRow = t_Rows[t_n];
                            t_JE = new NewControl.JPM_List_Entity();

                            t_JE.Add(_HeadImagesList.Images[(int)t_CRow[4]]);
                            t_JE.Add(Convert.ToString(t_CRow[0]));
                            t_JE.Add((string)t_CRow[3]);
                            t_JE.Add((string)t_CRow[1]);
                            t_JE.Add((string)t_CRow[8]);
                            t_JE.Add(Convert.ToString(t_CRow[13]));

                            _UserList.AddAnEntity(t_JE);
                        }
                    }
                }

                t_JE = new NewControl.JPM_List_Entity();

                t_JE.Add(global::JPMLab_LanTalker_Server.Properties.Resources.BMP_SERVERDATA);
                t_JE.Add(Convert.ToString(SERVER_UID));
                t_JE.Add(System.DateTime.Now.ToString());
                t_JE.Add(global::JPMLab_LanTalker_Server.Properties.Resources.STR_MSGTYPE_SYSTEM);
                t_JE.Add(global::JPMLab_LanTalker_Server.Properties.Resources.STR_MSGCONTENT_COMLOADDATA);

                _MessageList.AddAnEntity(t_JE);
                return true;
            }
            catch (Exception e)
            {
                _dataConnection = null;

                NewControl.JPM_List_Entity t_JE = new NewControl.JPM_List_Entity();

                t_JE.Add(global::JPMLab_LanTalker_Server.Properties.Resources.BMP_DATAERR);
                t_JE.Add(Convert.ToString(SERVER_UID));
                t_JE.Add(System.DateTime.Now.ToString());
                t_JE.Add(global::JPMLab_LanTalker_Server.Properties.Resources.STR_MSGTYPE_DATA);
                t_JE.Add(global::JPMLab_LanTalker_Server.Properties.Resources.STR_SERVER_FAILLOADDATA + e.Message);

                _MessageList.AddAnEntity(t_JE);
            }

            return false;
        }

        public static void CloseDataSource()
        {
            try
            {
                NewControl.JPM_List_Entity t_JE = new NewControl.JPM_List_Entity();
                t_JE.Add(global::JPMLab_LanTalker_Server.Properties.Resources.BMP_CLOSEDATA);
                t_JE.Add(Convert.ToString(SERVER_UID));
                t_JE.Add(System.DateTime.Now.ToString());
                t_JE.Add(global::JPMLab_LanTalker_Server.Properties.Resources.STR_MSGTYPE_SYSTEM);

                if (_dataConnection != null && _dataConnection.State == System.Data.ConnectionState.Open)
                {
                    _dataConnection.Close();
                    _dataConnection.Dispose();
                    _dataConnection = null;
                    t_JE.Add(global::JPMLab_LanTalker_Server.Properties.Resources.STR_MSGCONTENT_COMCLOSEDATA);
                }
                else
                {
                    t_JE.Add(global::JPMLab_LanTalker_Server.Properties.Resources.STR_MSGCONTENT_NULLCLOSEDATA);
                }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -