using Api.Framework; using Api.Framework.Enums; using Api.Framework.Tools; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using UI.Framework.Forms; using VideoFission.Entitys; using VideoFission.Properties; namespace VideoFission { public partial class MainForm : BaseForm { public MainForm() { InitializeComponent(); this.Text = Resources.MainFormTitle; } public void CloseForm() { try { if (!this.IsDisposed) { this.Invoke(new Action(delegate { this.Close(); this.Dispose(); })); } } catch (Exception ex) { ShowError(ex); } } private void MainForm_Load(object sender, EventArgs e) { try { this.settingControl1.Bind(Class1.Config); buttonCheck1.Checked = Class1.Config.OnOff; _RefreshData(); buttonCheck2.Checked = Class1.Config.Custom_OnOff; textEdit1.Text = Class1.Config.Custom_SearchCMD; textEdit2.Text = Class1.Config.Custom_SearchUrl; memoEdit1.Text = Class1.Config.Custom_SearchMess; #region 增加缩短类型 this.comboBoxEdit1.Properties.Items.Clear(); var objqqList = Enum.GetNames(typeof(DwzType)).ToList(); this.comboBoxEdit1.Properties.Items.AddRange(objqqList); if (comboBoxEdit1.Properties.Items.Count != 0) comboBoxEdit1.SelectedIndex = objqqList.IndexOf(Class1.Config.Custom_SearchShortLinkWay.ToString()); #endregion } catch (Exception ex) { ShowError(ex); } } private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { Class1.Config.Custom_OnOff = buttonCheck2.Checked; Class1.Config.Custom_SearchCMD = textEdit1.Text; Class1.Config.Custom_SearchUrl = textEdit2.Text; Class1.Config.Custom_SearchMess = memoEdit1.Text; Class1.Config.Custom_SearchShortLinkWay = (DwzType)Enum.Parse(typeof(DwzType), comboBoxEdit1.Text); Util.Save(Class1.Config); } /// /// 按钮状态 /// /// private void _ButtonEnabled(bool flag) { simpleButton2.Enabled = simpleButton3.Enabled = flag; } private void xtraTabControl2_SelectedPageChanging(object sender, DevExpress.XtraTab.TabPageChangingEventArgs e) { _RefreshData(e.Page.TabIndex); } /// /// 数显数据 /// private void _RefreshData(int index = 0) { try { listView1.Tag = null; if (groupControl4.Tag == null) _ButtonEnabled(false); var session = ApiClient.GetSession(); var ruleInfoS = session.Find("select * from fl_plugin_videofission_rule_info where ruletype = @ruletype order by amount asc", new { ruletype = index }); listView1.Items.Clear(); foreach (var rule in ruleInfoS) { var item = new ListViewItem(); item.Text = rule.id.ToString(); item.SubItems.Add(rule.amount.ToString()); item.SubItems.Add(rule.num.ToString()); listView1.Items.Add(item); } listView1.Tag = ruleInfoS; session.FindSignInfos((RuleType)index, true); } catch (Exception ex) { ShowError(ex); } } private void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) { try { if (listView1.SelectedItems.Count == 0) { _ButtonEnabled(false); return; } else { var id = long.Parse(listView1.SelectedItems[0].SubItems[0].Text); var session = ApiClient.GetSession(); List signInfoS = null; if (listView1.Tag != null) signInfoS = listView1.Tag as List; else signInfoS = session.Find("select * from fl_plugin_videofission_rule_info where ruletype = @ruletype order by amount asc", new { signtype = xtraTabControl1.TabIndex }); if (signInfoS != null && signInfoS.Count != 0) { var signInfo = signInfoS.FirstOrDefault(f => f.id == id); if (signInfo == null) return; _FillDate(signInfo); _ButtonEnabled(true); } } } catch (Exception ex) { ShowError(ex); } } /// /// 填充数据到控件中 /// private void _FillDate(fl_plugin_videofission_rule_info fuleInfo) { radioGroup1.SelectedIndex = (int)fuleInfo.ruletype; textEdit5.Text = xtraTabControl2.SelectedTabPage.Text; numericUpDown1.Value = (decimal)fuleInfo.amount; textEdit4.Text = fuleInfo.num.ToString(); groupControl4.Tag = fuleInfo; } /// /// 增加 /// /// /// private void simpleButton1_Click(object sender, EventArgs e) { try { var session = ApiClient.GetSession(); List signInfoS = null; if (listView1.Tag != null) signInfoS = listView1.Tag as List; else signInfoS = session.Find("select * from fl_plugin_videofission_rule_info where ruletype = @ruletype order by amount asc", new { ruletype = xtraTabControl1.TabIndex }); var signInfo = new fl_plugin_videofission_rule_info(); signInfo.id = 0; signInfo.ruletype = (RuleType)radioGroup1.SelectedIndex; signInfo.amount = (long)numericUpDown1.Value; if (signInfoS != null && signInfoS.Count != 0) { var _signInfo = signInfoS.FirstOrDefault(f => f.ruletype == signInfo.ruletype && f.amount == signInfo.amount); if (_signInfo != null) throw new Exception("该条件已经存在,无法增加"); } signInfo.num = long.Parse(textEdit4.Text.Trim()); session.Insertable(signInfo).ExecuteCommand(); _RefreshData((int)signInfo.ruletype); } catch (Exception ex) { ShowError(ex); } } /// /// 修改 /// /// /// private void simpleButton2_Click(object sender, EventArgs e) { try { fl_plugin_videofission_rule_info signInfo = null; if (groupControl4.Tag != null) { signInfo = groupControl4.Tag as fl_plugin_videofission_rule_info; signInfo.ruletype = (RuleType)radioGroup1.SelectedIndex; signInfo.amount = (long)numericUpDown1.Value; signInfo.num = long.Parse(textEdit4.Text.Trim()); var session = ApiClient.GetSession(); List signInfoS = null; if (listView1.Tag != null) signInfoS = listView1.Tag as List; else signInfoS = session.Find("select * from fl_plugin_videofission_rule_info where ruletype = @ruletype order by amount asc", new { ruletype = xtraTabControl1.TabIndex }); if (signInfoS != null && signInfoS.Count != 0) { var _signInfo = signInfoS.FirstOrDefault(f => f.ruletype == signInfo.ruletype && f.amount == signInfo.amount); //if (_signInfo != null) throw new Exception("该条件已经存在,无法增加"); } session.Updateable(signInfo).ExecuteCommand(); _RefreshData((int)signInfo.ruletype); } } catch (Exception ex) { ShowError(ex); } } /// /// 删除 /// /// /// private void simpleButton3_Click(object sender, EventArgs e) { try { var session = ApiClient.GetSession(); fl_plugin_videofission_rule_info signInfo = null; if (groupControl4.Tag != null) { signInfo = groupControl4.Tag as fl_plugin_videofission_rule_info; session.Deleteable(signInfo).ExecuteCommand(); _RefreshData((int)signInfo.ruletype); } } catch (Exception ex) { ShowError(ex); } } private void buttonCheck1_Click(object sender, EventArgs e) { Class1.Config.OnOff = buttonCheck1.Checked; } private void radioGroup1_SelectedIndexChanged(object sender, EventArgs e) { try { xtraTabControl2.SelectedTabPageIndex = radioGroup1.SelectedIndex; textEdit5.Text = xtraTabControl2.SelectedTabPage.Text; } catch (Exception ex) { ShowError(ex); } } } }