示例#1
0
 public Register()
 {
     InitializeComponent();
     client_socket = Server_Connection.Connect_Server();
     connection    = My_Database.Connect_Database();
     //connection.Open();
 }
示例#2
0
 static void Main()
 {
     My_Database.Connect_Database();
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     //AllocConsole();
     Application.Run(new Login());
 }
示例#3
0
        public Main_Window(string username, Socket s)
        {
            InitializeComponent();
            //数据库连接
            connection          = My_Database.Connect_Database();
            label_username.Text = username;
            user_name           = username;
            client_socket       = s;
            int listen_port;

            listen_port = Convert.ToInt32(username.Substring(6)) + 50000;
            //开始监听
            P2P_Communication.Begin_Listening(listen_port, user_name, this);
            string search_text = "Select friend_list from friend_table where username=" + user_name;
            object friend_all  = My_Database.SQLite_Select(search_text, connection).ToString();

            //string[] friend_array;
            //friend_list = friend_all.ToString().Split('.');
            if (friend_all.ToString().Length > 10)
            {
                friend_list = friend_all.ToString().Substring(11);
            }
            get_friend_list(true);
            get_group_list();
            //创建进程刷新好友在线状态
            threadstart_query         = new ThreadStart(query_friend_state);
            thread_query              = new Thread(threadstart_query);
            thread_query.IsBackground = true;
            thread_query.Start();
            chat_select = 0;
            unread_num  = 0;
            listView_unread.Hide();
            listView_group.Hide();
            button_approve.Hide();
            button_refuse.Hide();
            label1.Hide();
            label2.Hide();
            button_refuse.Enabled  = false;
            button_approve.Enabled = false;
            //unread_msg = null;
        }
示例#4
0
        public Chat_Window(List <string> recv_msg, List <Socket> s, int num, int con_num)
        {
            InitializeComponent();
            connection       = My_Database.Connect_Database();
            socket_to_server = Server_Connection.Connect_Server();
            user_name        = recv_msg[0].Substring(5).Split('.').ToList();
            List <string> unconnect_name = new List <string>(user_name);

            unconnect_name.RemoveAt(0);
            chat_num = num;
            datapath = ".\\data\\" + user_name[0] + "\\";
            if (!Directory.Exists(datapath))
            {
                Directory.CreateDirectory(datapath);
            }
            //读入聊天记录
            recordpath = ".\\data\\" + user_name[0] + "\\";
            for (int i = 0; i < chat_num; i++)
            {
                recordpath = recordpath + user_name[i + 1];
            }
            recordpath = recordpath + ".txt";

            StreamReader sr = new StreamReader(new FileStream(recordpath, FileMode.OpenOrCreate));
            string       exist_record;

            while ((exist_record = sr.ReadLine()) != null)
            {
                string[] record_split = exist_record.Split('.');
                if (record_split.Length >= 3)
                {
                    if (record_split[0] == user_name[0])
                    {
                        richTextBox1.SelectionAlignment = HorizontalAlignment.Left;
                    }
                    else
                    {
                        richTextBox1.SelectionAlignment = HorizontalAlignment.Right;
                    }
                    string show_msg = record_split[0] + " " + record_split[1] + "\n" + record_split[2] + "\n";
                    richTextBox1.AppendText(show_msg);
                }
                else
                {
                    richTextBox1.AppendText(exist_record);
                }
            }
            sr.Close();
            //如果为接收消息方 显示消息
            for (int i = 0; i < recv_msg.Count(); i++)
            {
                string[] info = recv_msg[i].Split('.');
                if (info[0] == "info")
                {
                    //string recv_msg = fri_name + recv_str.Split('.')[2];
                    string show_msg = info[2] + " " + info[info.Length - 1];
                    richTextBox1.SelectionAlignment = HorizontalAlignment.Right;
                    richTextBox1.AppendText(show_msg);
                    new_msg.Add(show_msg);
                    if (i == 0)
                    {
                        unconnect_name.Remove(info[2]);
                        user_name.RemoveAt(user_name.Count() - 1);
                    }
                }
            }

            if (s.Count() != 0)
            {
                socket_to_friend = s;
                //已连接用户
                for (int j = 0; j < con_num; j++)
                {
                    string send_message = "onchat." + user_name[0];
                    P2P_Communication.Connect_Send(socket_to_friend[j], send_message);
                }
                for (int i = con_num; i < chat_num; i++)
                {
                    socket_to_friend.Add(P2P_Communication.Commun_Friend(unconnect_name[i - con_num], socket_to_server));

                    string send_message = "chat.";
                    for (int j = 0; j <= chat_num; j++)
                    {
                        send_message = send_message + user_name[j] + ".";
                    }
                    P2P_Communication.Connect_Send(socket_to_friend[i], send_message);
                }
            }
            else
            {
                for (int i = con_num; i < chat_num; i++)
                {
                    socket_to_friend.Add(P2P_Communication.Commun_Friend(unconnect_name[i - con_num], socket_to_server));
                    string send_message = "chat.";
                    for (int j = 0; j <= chat_num; j++)
                    {
                        send_message = send_message + user_name[j] + ".";
                    }
                    P2P_Communication.Connect_Send(socket_to_friend[i], send_message);
                }
            }
            //开始接受消息
            for (int i = 0; i < chat_num; i++)
            {
                P2P_Communication.Chat_Receive(socket_to_friend[i], this, true);
            }
            //控件初始化
            //如果为群聊
            if (chat_num > 1)
            {
                textBox_name.Text = findGroup(user_name);
            }
            string others = null;

            for (int i = 0; i < chat_num; i++)
            {
                others = others + user_name[i + 1] + "\n";
            }
            label3.Text = user_name[0];
            label4.Text = others;
            label5.Hide();
            button_fileaccept.Hide();
            button_filerefuse.Hide();
            button_voicerefuse.Hide();
            if (chat_num > 1)
            {
                button_voicechat.Enabled = false;
            }
            waveProvider   = new BufferedWaveProvider(new WaveFormat(8000, 16, WaveIn.GetCapabilities(0).Channels));
            recievedStream = new WaveOut();
            recievedStream.Init(waveProvider);
        }
示例#5
0
文件: Login.cs 项目: Zhikaiiii/eChat
 public Login()
 {
     InitializeComponent();
     connection = My_Database.Connect_Database();
 }