using Api.Framework; using Api.Framework.Model; using Api.Framework.Tools; using MessageSupervises.Properties; using System; using System.Collections.Generic; using System.ComponentModel; using System.Windows.Forms; using UI.Framework.Forms; namespace MessageSupervises { public partial class MainForm : BaseForm { public MainForm() { InitializeComponent(); this.Text = Resources.MainFormTitle; } public void CloseForm() { if (!this.IsDisposed) { this.Invoke(new Action(delegate { this.Close(); this.Dispose(); })); } } private void MainForm_Load(object sender, EventArgs e) { try { var session = ApiClient.GetSession(); var apis = session.FindNoticeapiRobots().ToArray(); var rst = new List(); rst.Add("请选择(钉钉/微信群机器人API名称)"); foreach (var item in apis) rst.Add(item.name); comboBox1.DataSource = rst; this.buttonCheck2.Checked = numericUpDown1.Enabled = numericUpDown2.Enabled = Class1.Config.FrequencySwitch; this.buttonCheck3.Checked = Class1.Config.FrequencyCloudBlack; this.buttonCheck1.Checked = Class1.Config.WhiteListSwitch; this.memoEdit1.Enabled = !Class1.Config.WhiteListSwitch; this.numericUpDown1.Value = Class1.Config.FrequencyIntervalSecs; this.numericUpDown2.Value = Class1.Config.FrequencyIntervalSendNum; this.memoEdit2.Text = Class1.Config.FrequencyDetentionTip; this.memoEdit5.Text = Class1.Config.WhiteListWords; this.checkEdit1.Checked = Class1.Config.ProhibitSL; this.checkEdit2.Checked = Class1.Config.ProhibitQL; this.comboBox2.SelectedIndex = Class1.Config.GroupResponseType ? 0 : 1; this.memoEdit1.Text = string.Join(",", Class1.Config.GroupWhiteList); this.buttonCheck4.Checked = this.memoEdit3.Enabled = Class1.Config.ProhibitNick; this.memoEdit3.Text = string.Join(",", Class1.Config.ProhibitNickList); this.buttonCheck5.Checked = this.memoEdit4.Enabled = Class1.Config.ProhibitWxid; this.memoEdit4.Text = string.Join(",", Class1.Config.ProhibitWxidList); this.checkEdit4.Checked = Class1.Config.auth_delete_black; this.textBox3.Text = Class1.Config.auto_black_day.ToString(); this.textBox4.Text = Class1.Config.auto_black_order.ToString(); this.textBox5.Text = Class1.Config.auto_black_chat.ToString(); this.textBox2.Text = Class1.Config.auto_black_message; this.comboBox1.SelectedIndex = rst.IndexOf(Class1.Config.notice_robotname) == -1 ? 0 : rst.IndexOf(Class1.Config.notice_robotname); this.buttonCheck6.Checked = Class1.Config.auth_black_swich; this.buttonCheck7.Checked = Class1.Config.auth_dingding_swich; } catch (Exception ex) { ShowError(ex); } } private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { try { Class1.Config.FrequencySwitch = buttonCheck2.Checked; Class1.Config.WhiteListSwitch = buttonCheck1.Checked; Class1.Config.FrequencyIntervalSecs = (int)numericUpDown1.Value; Class1.Config.FrequencyIntervalSendNum = (int)numericUpDown2.Value; Class1.Config.FrequencyDetentionTip = memoEdit2.Text; Class1.Config.WhiteListWords = memoEdit5.Text; Class1.Config.ProhibitSL = checkEdit1.Checked; Class1.Config.ProhibitQL = checkEdit2.Checked; Class1.Config.GroupResponseType = comboBox2.SelectedIndex == 0; Class1.Config.GroupWhiteList = memoEdit1.Text.Replace(",", ",").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); Class1.Config.ProhibitNick = buttonCheck4.Checked; Class1.Config.ProhibitNickList = memoEdit3.Text.Replace(",", ",").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); Class1.Config.ProhibitWxid = buttonCheck5.Checked; Class1.Config.ProhibitWxidList = memoEdit4.Text.Replace(",", ",").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); Class1.Config.auth_delete_black = this.checkEdit4.Checked; Class1.Config.auto_black_day = int.Parse(this.textBox3.Text); Class1.Config.auto_black_order = int.Parse(this.textBox4.Text); Class1.Config.auto_black_chat = int.Parse(this.textBox5.Text); Class1.Config.auto_black_message = this.textBox2.Text; Class1.Config.notice_robotname = this.comboBox1.SelectedValue.ToString(); Class1.Config.auth_black_swich = this.buttonCheck6.Checked; Class1.Config.auth_dingding_swich = this.buttonCheck7.Checked; Class1.Config.FrequencyCloudBlack = this.buttonCheck3.Checked; groupControl2.Enabled = buttonCheck6.Checked; groupControl3.Enabled = buttonCheck7.Checked; Util.Save(Class1.Config); } catch (Exception ex) { ShowError(ex.Message); } } private void 移除ToolStripMenuItem_Click(object sender, EventArgs e) { //try //{ // int[] selectRows = gridView1.GetSelectedRows();//获取选中的列 // if (selectRows.Length != 0) // { // string id = this.gridView1.GetRowCellValue(selectRows[0], "id").ToString();//获取列的数据 // var session = ApiClient.GetSession(); // session.ExcuteSQL("update fl_member_info set status = 0 where id=@id", new { id = id }); // pageControl1.GotoPage(); // label1.Visible = gridView1.RowCount == 0; // pageControl2.GotoPage(); // label2.Visible = gridView2.RowCount == 0; // } //} //catch (Exception ex) //{ // ShowError(ex); //} } private void contextMenuStrip2_Opening(object sender, CancelEventArgs e) { //try //{ // int[] selectRows = gridView2.GetSelectedRows();//获取选中的列 // if (selectRows.Length != 0) // { // if (selectRows.Length == 0) // contextMenuStrip2.Items[0].Enabled = false; // else // contextMenuStrip2.Items[0].Enabled = true; // } //} //catch (Exception ex) //{ // ShowError(ex); //} } private void contextMenuStrip1_Opening(object sender, CancelEventArgs e) { //try //{ // int[] selectRows = gridView1.GetSelectedRows();//获取选中的列 // if (selectRows.Length == 0) // contextMenuStrip1.Items[0].Enabled = false; // else // contextMenuStrip1.Items[0].Enabled = true; //} //catch (Exception ex) //{ // ShowError(ex); //} } private void buttonCheck1_Click(object sender, EventArgs e) { memoEdit1.Enabled = !buttonCheck1.Checked; } private void buttonCheck2_Click(object sender, EventArgs e) { numericUpDown1.Enabled = numericUpDown2.Enabled = buttonCheck2.Checked; } private void buttonCheck4_Click(object sender, EventArgs e) { memoEdit3.Enabled = buttonCheck4.Checked; } private void buttonCheck5_Click(object sender, EventArgs e) { memoEdit4.Enabled = buttonCheck5.Checked; } private void buttonCheck6_Click(object sender, EventArgs e) { groupControl2.Enabled = this.buttonCheck6.Checked; } private void buttonCheck7_Click(object sender, EventArgs e) { groupControl3.Enabled = this.buttonCheck7.Checked; } } }