private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { if (listBox1.SelectedIndex > -1) { Konke.MiniK k = listBox1.SelectedItem as Konke.MiniK; if (k != null) { openOrClose = k.state == "开"; button2.Text = button4.Text = openOrClose ? "关闭" : "开启"; if (k.device_type == "2代") { string state; if (control.GetKLightInfo(k.kid, out state)) { label10.Text = state; button13.Text = state == "open" ? "关" : "开"; } } else { label10.Text = "[未知状态]"; } } else { label10.Text = "[未知状态]"; } } }
private void button9_Click(object sender, EventArgs e) { string access_token = textBox2.Text; string userid = control.UserID; if (userid != "") { label5.Text = userid; this.Cursor = Cursors.WaitCursor; try { if (listBox1.SelectedItems.Count > 0) { openOrClose = !openOrClose; bool someOneFalse = false; foreach (object o in listBox1.SelectedItems) { Konke.MiniK k = o as Konke.MiniK; if (k != null) { bool f = control.Turn(k.kid, openOrClose); if (!f) { someOneFalse = true; } } } if (someOneFalse) { MessageBox.Show("选定的设备中,至少有一个开关控制失败!"); } else { MessageBox.Show("选定的设备全部" + (openOrClose ? "开启" : "关闭") + "成功!"); } RefreshDeviceList2(); button2.Text = button4.Text = openOrClose ? "关闭" : "开启"; } else { MessageBox.Show("请先选定要操作的设备!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { this.Cursor = Cursors.Default; } } else { MessageBox.Show("获取不到userid!"); } }
private void listBox2_SelectedIndexChanged(object sender, EventArgs e) { if (listBox2.SelectedIndex > -1) { Konke.MiniK k = listBox2.SelectedItem as Konke.MiniK; if (k != null) { openOrClose = k.state == "开"; button8.Text = openOrClose ? "关闭" : "开启"; } } }
private void button13_Click(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; try { if (listBox1.SelectedItems.Count > 0) { bool state = label10.Text == "关"; bool someOneFalse = false; foreach (object o in listBox1.SelectedItems) { Konke.MiniK k = o as Konke.MiniK; if (k != null) { bool f = control.DoSwitchKLight(k.kid, state ? 1 : 0); if (f) { label10.Text = state ? "开" : "关"; button13.Text = state ? "关" : "开"; } else { someOneFalse = true; } } } if (someOneFalse) { MessageBox.Show("选定的设备中,至少有一个小夜灯控制失败!"); } else { MessageBox.Show("选定的设备全部小夜灯" + (state ? "开启" : "关闭") + "成功!"); } } else { MessageBox.Show("请先选定要操作的设备!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { this.Cursor = Cursors.Default; } }
private void button12_Click(object sender, EventArgs e) { if (listBox1.SelectedIndex > -1) { Konke.MiniK device = listBox1.SelectedItem as Konke.MiniK; if (device != null) { if (device.device_type == "2代")//支持插件的设备类型 { GetPlugins(device.kid); } else { MessageBox.Show("请先选定一个小K二代的设备!"); } } } else { MessageBox.Show("请先选定一个设备!"); } }