private void buttonCheck_Click(object sender, EventArgs e) { if (button_onindex == ButtonIndex.ButtonCheck) { return; } button_onindex = ButtonIndex.ButtonCheck; button_refrush(); //host主机参数 格式“password@ip:port” string[] host = { serverpara.RedisPassword + '@' + serverpara.RedisIP + ':' + serverpara.RedisPort }; try { //从连接池获得只读连接客户端 long initialDB = 0; RedisClient Client = (RedisClient)redismanager.GetReadOnlyClient(ref (initialDB), ref (host)); if (Client == null || !Client.Ping()) { throw new Exception("连接服务器失败,请设置服务器参数!"); } //连接成功 serverpara.connectvalid = true; redismanager.DisposeClient(ref (Client)); //dispose客户端 Properties.Settings.Default.Save(); // 存储上一次成功连接的IP地址和端口号\ firsttimerun = true; //第一次运行完成 //测试连接 MessageBox.Show(Client.Db.ToString()); //db index MessageBox.Show(Client.DbSize.ToString()); //属性设置 machinestate.Dock = DockStyle.Fill; machinestate.Height = this.panel1.Height; machinestate.Width = this.panel1.Width; this.panel1.Controls.Add(machinestate); //机床状态监测画面初始化 ListViewInitial(); //机床状态监测画面刷新 t = new System.Timers.Timer(1000); //实例化Timer类,设置间隔时间为10000毫秒; t.Elapsed += new System.Timers.ElapsedEventHandler(ListViewRefrush); //到达时间的时候执行事件; t.AutoReset = true; //设置是执行一次(false)还是一直执行(true); t.Enabled = true; //是否执行System.Timers.Timer.Elapsed事件; } catch (Exception ex) { MessageBox.Show("ERROR:" + ex.Message, "ERROR"); if (machinestate != null) { machinestate.Visible = false; machinestate = null; } redismanager.dispose(); //redispara.dispose(); } }
private void buttonHome_Click(object sender, EventArgs e) { if (button_onindex == ButtonIndex.ButtonHome) { return; } button_onindex = ButtonIndex.ButtonHome; button_refrush(); button2_Click(sender, e); //redispara = redisparasetting.redisparaName; //服务器连接ip,por,password设置 for (int i = 1; i <= 4; ++i) { //检验输入是否为数字,数字是否介于0~255之间 int tmp = -1; TextBox objText = (TextBox)this.panel2.Controls["textBox" + i.ToString()]; if (int.TryParse(objText.Text, out tmp) != true) { MessageBox.Show("错误:服务器IP地址输入错误,请重新输入!", "ERROR"); return; } else if (!(tmp >= 0 && tmp <= 255)) { MessageBox.Show("错误:服务器IP地址输入错误,请重新输入!", "ERROR"); return; } } String IP = textBox1.Text + '.' + textBox2.Text + '.' + textBox3.Text + '.' + textBox4.Text; int port = 0; if (int.TryParse(textBox5.Text, out port) != true) { MessageBox.Show("错误:服务器端口号输入错误,请重新输入!", "ERROR"); return; } serverpara.RedisIP = IP; serverpara.RedisPort = textBox5.Text; serverpara.RedisPassword = textBox6.Text; serverpara.connectvalid = false; //host主机参数 格式“password@ip:port” string[] host = { serverpara.RedisPassword + '@' + serverpara.RedisIP + ':' + serverpara.RedisPort }; try { //从连接池获得只读连接客户端 long initialDB = 0; RedisClient Client = (RedisClient)redismanager.GetReadOnlyClient(ref (initialDB), ref (host)); //byte[] ConnectTimeout = System.BitConverter.GetBytes(3); //Client.ConfigSet("repl-ping-slave-period", ConnectTimeout); if (Client == null || !Client.Ping()) { throw new Exception("连接服务器失败!"); } //连接成功 serverpara.connectvalid = true; redismanager.DisposeClient(ref (Client)); //dispose客户端 Properties.Settings.Default.Save(); // 存储上一次成功连接的IP地址和端口号\ firsttimerun = true; //第一次运行完成 //测试连接 MessageBox.Show(Client.Db.ToString()); //db index MessageBox.Show(Client.DbSize.ToString()); //绘制用户界面 if (machinestate == null) { machinestate = new UserControlMachineState(); } machinestate.Visible = true; machinestate.listView1.Visible = true; machinestate.Dock = DockStyle.Fill; //绘制标题 machinestate.Height = this.panel1.Height; machinestate.Width = this.panel1.Width; if (!machinestate.ListViewTitleDraw(ref (LineNo))) { throw new Exception(); } this.panel1.Controls.Add(machinestate); //机床状态监测画面初始化 ListViewInitial(); //机床状态监测画面刷新 t = new System.Timers.Timer(1000); //实例化Timer类,设置间隔时间为10000毫秒; t.Elapsed += new System.Timers.ElapsedEventHandler(ListViewRefrush); //到达时间的时候执行事件; t.AutoReset = true; //设置是执行一次(false)还是一直执行(true); t.Enabled = true; //是否执行System.Timers.Timer.Elapsed事件; } catch (Exception ex) { MessageBox.Show("ERROR:" + ex.Message, "ERROR"); if (machinestate != null) { machinestate.Visible = false; machinestate = null; } redismanager.dispose(); //redispara.dispose(); } }