Пример #1
0
        /// <summary>
        /// 登录函数
        /// </summary>
        private void login_()
        {
            string hostname = string.Empty;
            string serID = string.Empty;

            User.user.UserName = Username_textbox.Text;
            User.user.PassWord1 = Password_textbox.Text;
            //string[] sMessage = { "", "" };
            //bSuccess = User.Login(User.user.UserName, User.user.PassWord1, ref sMessage);
            //if (bSuccess)
            //{
            #region 发送登录消息
            //向服务器发送登录消息
            hostname = Dns.GetHostName();
            //IPAddress[] ip = Dns.GetHostAddresses(hostname);
            LoginMsg loginmsg = new LoginMsg();
            //RegisterMsg registmsg = new RegisterMsg();
            ClassMsg msg = new ClassMsg();
            //registmsg.UserName = Username_textbox.Text;
            //registmsg.PassWord = Password_textbox.Text;
            loginmsg.UserName = Username_textbox.Text;
            loginmsg.PassWord = Password_textbox.Text;
            byte[] logindata = new ClassSerializers().SerializeBinary(loginmsg).ToArray();
            msg.sendKind = SendKind.SendCommand;
            msg.msgCommand = MsgCommand.Logining;
            msg.Data = logindata;
            serID = "192.168.1.187";                 //服务器IP
            udpSocket1.Send(IPAddress.Parse(serID), 11001, new ClassSerializers().SerializeBinary(msg).ToArray());
            #endregion

            //}
            //else
            //{
            //    if (!string.IsNullOrEmpty(sMessage[0]))
            //        MessageBox.Show(sMessage[0]);
            //    else
            //        MessageBox.Show(sMessage[1]);
            //}
        }
Пример #2
0
 private void main_Load(object sender, EventArgs e)
 {
     UserBLL udb = new UserBLL();
     ClassMsg msg = new ClassMsg();
     LoginMsg loginmsg = new LoginMsg();
     msg.sendKind = SendKind.SendCommand;
     msg.msgCommand = MsgCommand.GetFriendList;
     msg.SID = udb.user.UserID.ToString();
     loginmsg.UserName = udb.user.UserName;
     byte[] loginbyte = new ClassSerializers().SerializeBinary(loginmsg).ToArray();
     msg.Data = loginbyte;
     udpSocket1.Send(IPAddress.Parse(serIP),10001,new ClassSerializers().SerializeBinary(msg).ToArray());
     ////用户信息表
     //DataTable dt = new DataTable();
     ////好友表
     //DataTable dt1 = new DataTable();
     ////分组信息表
     //DataTable dt2 = new DataTable();
     ////好友详细信息表
     //DataTable dt3 = new DataTable();
     //dt = udb.Userinfo(udb.user.UserID);
     //Name_skinLable.Text = udb.user.UserNickName;
     //PersonalMessage.Text = udb.user.UserPersonalMessage;
     //chatListBox1.Items.Clear();
     //dt2 = udb.DB.GetData(string.Format("select * from friendgroup where userID={0}", udb.user.UserID));
     //if (string.IsNullOrEmpty(dt.Rows[0]["HeadPicture"].ToString()))
     //{
     //    headpicture.ImageLocation = s + "\\search_teacher.jpg";
     //}
     //else
     //{
     //    headpicture.ImageLocation = dt.Rows[0]["HeadPicture"].ToString();
     //}
     //for (int i = 0; i < dt2.Rows.Count; i++)
     //{
     //    ChatListItem chatlist1 = new ChatListItem();
     //    chatlist1.Bounds = new System.Drawing.Rectangle(0, 53, 363, 25);
     //    chatlist1.IsTwinkleHide = false;
     //    chatlist1.OwnerChatListBox = this.chatListBox1;
     //    chatlist1.Text = dt2.Rows[i]["GrouName"].ToString();
     //    chatlist1.TwinkleSubItemNumber = 0;
     //    chatListBox1.Items.AddRange(new ChatListItem[] { chatlist1 });
     //    dt1 = udb.GetFriendList(udb.user.UserName, dt2.Rows[i]["GrouID"].ToString());
     //    for (int l = 0; l < dt1.Rows.Count; l++)
     //    {
     //        dt3 = udb.DB.GetData(string.Format("select * from user where UserID={0}", dt1.Rows[l]["Use_UserID"]));
     //        ChatListSubItem chatListSubItem1 = new ChatListSubItem();
     //        chatListSubItem1.Bounds = new System.Drawing.Rectangle(0, 0, 0, 0);
     //        chatListSubItem1.DisplayName = dt1.Rows[l]["Alternatename"].ToString();
     //        chatListSubItem1.HeadImage = null;
     //        chatListSubItem1.HeadRect = new System.Drawing.Rectangle(0, 0, 0, 0);
     //        chatListSubItem1.ID = Convert.ToInt32(dt1.Rows[l]["Use_UserID"]);
     //        chatListSubItem1.IpAddress = null;
     //        chatListSubItem1.IsTwinkle = false;
     //        chatListSubItem1.IsTwinkleHide = false;
     //        chatListSubItem1.NicName = dt3.Rows[0]["UserNickName"].ToString();
     //        chatListSubItem1.OwnerListItem = chatlist1;
     //        chatListSubItem1.PersonalMsg = dt3.Rows[0]["UserPersonalMessage"].ToString();
     //        chatListSubItem1.Status = ChatListSubItem.UserStatus.Online;
     //        chatListSubItem1.Tag = null;
     //        chatListSubItem1.TcpPort = 0;
     //        chatListSubItem1.UpdPort = 0;
     //        chatlist1.SubItems.AddRange(new ChatListSubItem[] {chatListSubItem1});
     //    }
     //}
 }