private void SendMessage(string msg) { ledPanel1.Text = "发送中"; new Thread(() => { try { var client = new APIServiceClient(); client.ShowText(ClientId, msg); ledPanel1.Invoke(new Action(() => { ledPanel1.Text = msg; })); client.Close(); } catch (Exception ex) { ledPanel1.Invoke(new Action(() => { ledPanel1.Text = "发送失败"; })); MessageBox.Show("出错了\n" + ex.Message); } }).Start(); }
private void BindData() { var client = new APIServiceClient(); var json = client.DownloadConfig(ClientId); var data = JsonConvert.DeserializeObject <JObject>(json); var messages = data["messages"].ToObject <List <Model.Message> >(); var buttons = data["buttons"].ToObject <List <Model.ClientButton> >(); var window = data["window"].ToObject <Model.ClientWindow>(); var offworkTimes = data["offworktimes"].ToObject <List <Model.OffworkTime> >(); _offworkButton = buttons.FirstOrDefault(e => e.Type == Model.ClientButtonType.班); _countdownButton = buttons.FirstOrDefault(e => e.Type == Model.ClientButtonType.倒计数); this.BeginInvoke(new Action(() => { //绑定消息下拉框 cbxMessage.DataSource = messages.Select(e => e.Content).ToArray(); //绑定下班时间下拉框 cbxOffworkTime.DataSource = offworkTimes.Select(e => new TimeSpan(e.Hour, e.Minute, 0).ToString()).ToArray(); //绑定文字窗口 //ledPanel1.ChangeLedSize(300, 128); ledPanel1.Height = window.Height + 10; ledPanel1.Width = window.Width + 10; ledPanel1.TextAlign = (ContentAlignment)window.TextAlignment; ledPanel1.Font = new Font(window.FontFamily, window.FontSize); //判断下班按钮是否可见 offworkPanel.Visible = _offworkButton != null; //加载其他按钮 buttonContainer.Controls.Clear(); foreach (var btn in buttons.Where(e => e.Type != ClientButtonType.班)) { var control = new Button() { Text = btn.Type.ToString(), BackColor = Color.SteelBlue, ForeColor = Color.White, FlatStyle = FlatStyle.Flat, Width = 85, Height = 32 }; switch (btn.Type) { case ClientButtonType.故障: control.BackColor = Color.Red; break; case ClientButtonType.倒计数: control.BackColor = Color.Peru; break; } //按钮点击事件 control.Click += (sender, e) => { if (btn.Type == ClientButtonType.倒计数) { btnCountDown_Click(sender, e); } else { SendMessage(btn.Message); } }; buttonContainer.Controls.Add(control); } })); client.Close(); }
private void BindData() { var client = new APIServiceClient(); var json = client.DownloadConfig(ClientId); var data = JsonConvert.DeserializeObject<JObject>(json); var messages = data["messages"].ToObject<List<Model.Message>>(); var buttons = data["buttons"].ToObject<List<Model.ClientButton>>(); var window = data["window"].ToObject<Model.ClientWindow>(); var offworkTimes = data["offworktimes"].ToObject<List<Model.OffworkTime>>(); _offworkButton = buttons.FirstOrDefault(e => e.Type == Model.ClientButtonType.下班); _countdownButton = buttons.FirstOrDefault(e => e.Type == Model.ClientButtonType.倒计数); this.BeginInvoke(new Action(() => { //绑定消息下拉框 cbxMessage.DataSource = messages.Select(e => e.Content).ToArray(); //绑定下班时间下拉框 cbxOffworkTime.DataSource = offworkTimes.Select(e => new TimeSpan(e.Hour, e.Minute, 0).ToString()).ToArray(); //绑定文字窗口 //ledPanel1.ChangeLedSize(300, 128); ledPanel1.Height = window.Height + 10; ledPanel1.Width = window.Width + 10; ledPanel1.TextAlign = (ContentAlignment)window.TextAlignment; ledPanel1.Font = new Font(window.FontFamily, window.FontSize); //判断下班按钮是否可见 offworkPanel.Visible = _offworkButton != null; //加载其他按钮 buttonContainer.Controls.Clear(); foreach (var btn in buttons.Where(e => e.Type != ClientButtonType.下班)) { var control = new Button() { Text = btn.Type.ToString(), BackColor = Color.SteelBlue, ForeColor = Color.White, FlatStyle = FlatStyle.Flat, Width = 85, Height = 32 }; switch (btn.Type) { case ClientButtonType.故障: control.BackColor = Color.Red; break; case ClientButtonType.倒计数: control.BackColor = Color.Peru; break; } //按钮点击事件 control.Click += (sender, e) => { if (btn.Type == ClientButtonType.倒计数) { btnCountDown_Click(sender, e); } else { SendMessage(btn.Message); } }; buttonContainer.Controls.Add(control); } })); client.Close(); }