public MainForm(loginstate lgs) { InitializeComponent(); Initializenotifyicon(); //rolelab.Text="["+ //label1.Text = lgs.Realname; username = lgs.Username; label1.Text = lgs.Realname; rolelab.Text = "[" + lgs.Usertype + "]"; baisicinfolab.Text = "未分类" + lgs.Firstfalu.ToString() + "条,已分类" + lgs.Myselffault.ToString() + "条"; //GetUserFace(); //ListenHaveNewFault(); }
public Form1(loginstate lgs) { // Windows 窗体设计器支持所必需的 //InitializeComponent1(); InitializeComponent(); //初始化托盘程序的各个要素 Initializenotifyicon(); this.username = lgs.Username.ToString(); this.realnane =lgs.Realname.ToString(); this.label1.Text = username+"欢迎使用本系统"; listener.Start(); //开始侦听端口 //Thread acceptThread = new Thread(new ThreadStart(AcceptWorkThread)); //acceptThread.Start(); //接受客户端请求 }
//private void ListenHaveNewFault() //{ // IPEndPoint iep = new IPEndPoint(IPAddress.Parse(GetIP()), 8562); // Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); // byte[] byteMessage = new byte[1024]; // //this.label1.Text = iep.ToString(); // socket.Bind(iep); // while (true) // { // try // { // socket.Listen(1); // Socket newSocket = socket.Accept(); // newSocket.Receive(byteMessage); // if (Encoding.Default.GetString(byteMessage).ToString().Length > 0) // { // MessageBox.Show("sdadasda"); // } // } // catch (SocketException ex) // { // throw ex; // } // } //} private void button1_Click(object sender, EventArgs e) { if (textBox1.Text.ToString().Trim() == "") { MessageBox.Show("用户名必填,请输入正确的用户名", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { if (textBox2.Text.ToString().Trim() == "") { MessageBox.Show("密码必填请输入正确的密码", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { button1.Enabled = false; Encryption ecry = new Encryption(); string hostname; System.Net.IPHostEntry localhost; System.Net.IPAddress localaddr; hostname = System.Net.Dns.GetHostName(); localhost = System.Net.Dns.GetHostByName(hostname); localaddr = localhost.AddressList[0]; //localaddr中就是本机ip地址 loginstate lgs = new loginstate(); //if (connectionstring == "") //{ //string recivestring = SendLoginInfor().ToString().Trim(); if (SendLoginInfor() == null) { MessageBox.Show("连接服务器失败,请与管理员联系", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); button1.Enabled = true; } else { string[] result = SendLoginInfor(); int lengths = SendLoginInfor().Length; //MessageBox.Show(result[1], "dsad"); if (lengths == 2) { MessageBox.Show("请输入正确的用户名和密码", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); textBox2.Text = ""; button1.Enabled = true; } else { Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); config.AppSettings.Settings["connectionString"].Value = ecry.Encrypto(result[0].ToString()); config.AppSettings.Settings["url"].Value = result[1]; config.Save(ConfigurationSaveMode.Full); ConfigurationManager.RefreshSection("appSettings"); XmlDocument doc = new XmlDocument(); string filestr = Application.ExecutablePath + ".config"; doc.Load(filestr); XmlNodeList nodes = doc.GetElementsByTagName("add"); for (int i = 0; i < nodes.Count; i++) { XmlAttribute att = nodes[i].Attributes["key"]; if (att.Value == "connectionString") { att = nodes[i].Attributes["value"]; att.Value = ecry.Encrypto(result[0].ToString()); //MessageBox.Show(result[0]); } if (att.Value == "url") { att = nodes[i].Attributes["value"]; att.Value = result[1]; } } doc.Save(filestr); //Properties.Settings.Default.Reload(); //doc connectionstring = result[0]; //MessageBox.Show(connectionstring); //MessageBox.Show(ConfigurationManager.AppSettings["connectionString"].ToString().Trim()); loginbyclient(textBox1.Text.ToString().Trim(), textBox2.Text.ToString().Trim(), localaddr.ToString(), connectionstring); } } //} //else //{ // MessageBox.Show(connectionstring,"xlm"); // loginbyclient(textBox1.Text.ToString().Trim(), textBox2.Text.ToString().Trim(), localaddr.ToString(),ecry.Decrypto(connectionstring)); //} } } }