old_flsystem/应用/ProductClient/MainForm.cs

213 lines
7.9 KiB
C#

using Api.Framework;
using Api.Framework.Cps;
using Api.Framework.Enums;
using Api.Framework.Tools;
using DevExpress.XtraEditors;
using ProductClient.Properties;
using System;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using UI.Framework.Forms;
using static Api.Framework.ApiClient;
namespace ProductClient
{
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.Message);
}
}
private void MainForm_Load(object sender, EventArgs e)
{
textEdit1.Text = Class1.Config.tbPid;
textEdit2.Text = Class1.Config.pddPid;
textEdit3.Text = Class1.Config.jdPid;
textEdit4.Text = Class1.Config.actionLink;
numericUpDown1.Value = Class1.Config.Monitor_Interval;
checkBox1.Checked = Class1.Config.isPyTkl;
checkBox2.Checked = Class1.Config.isPl;
this.comboBoxEdit2.Properties.Items.AddRange(Enum.GetNames(typeof(DwzType)));
comboBoxEdit2.SelectedIndex = (int)Class1.Config.dwzType;
comboBoxEdit1.SelectedIndex = (int)Class1.Config.qrImageType;
memoEdit1.Text = Class1.Config.appendComment;
}
private void hyperlinkLabelControl_Click(object sender, EventArgs e)
{
try
{
var label = sender as HyperlinkLabelControl;
if (label == null) return;
var session = ApiClient.GetSession();
var cps = (CpsType)Enum.ToObject(typeof(CpsType), int.Parse(label.Name.ToLower().Replace("hyperlinklabelcontrol", "")));
switch (cps)
{
case CpsType.:
{
var tgwObj = CpsClient.SelectTuiguangwei(CpsType.);
if (tgwObj != null)
{
var tgw = tgwObj as Tuiguangwei;
textEdit1.Text = tgw.Pid;
Class1.Config.tbPid = tgw.Pid;
}
}
break;
case CpsType.:
{
var tgwObj = CpsClient.SelectTuiguangwei(CpsType.);
if (tgwObj != null)
{
var tgw = tgwObj as Tuiguangwei;
textEdit2.Text = tgw.Pid;
Class1.Config.pddPid = tgw.Pid;
}
}
break;
case CpsType.:
{
var tgwObj = CpsClient.SelectTuiguangwei(CpsType.);
if (tgwObj != null)
{
var tgw = tgwObj as Tuiguangwei;
textEdit3.Text = tgw.Pid + "_" + tgw.Member.username;
Class1.Config.jdPid = textEdit3.Text;
}
}
break;
default:
break;
}
}
catch (Exception ex)
{
ShowError(ex);
}
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
comboBoxEdit1.Focus();
Class1.Config.qrImageType = (QrImageType)comboBoxEdit1.SelectedIndex;
Class1.Config.Monitor_Interval = (int)numericUpDown1.Value;
Class1.Config.dwzType = (DwzType)comboBoxEdit2.SelectedIndex;
Class1.Config.isPyTkl = checkBox1.Checked;
Class1.Config.isPl = checkBox2.Checked;
Class1.Config.appendComment = memoEdit1.Text;
Class1.Config.actionLink = textEdit4.Text;
Util.Save(Class1.Config);
}
private void textEdit_Leave(object sender, EventArgs e)
{
try
{
var text = sender as TextEdit;
if (text == null) return;
var session = ApiClient.GetSession();
var cps = (CpsType)Enum.ToObject(typeof(CpsType), int.Parse(text.Name.ToLower().Replace("textedit", "")));
switch (cps)
{
case CpsType.:
{
//mm_28592081_118450408_105567700447
var pidstr = text.Text.Trim();
if (!string.IsNullOrWhiteSpace(pidstr))
{
var reg = Regex.Match(pidstr, @"mm_(?<cpsname>\d+)_(?<pid1>\d+)_(?<pid2>\d+)");
if (reg.Success)
Class1.Config.tbPid = pidstr;
}
}
break;
case CpsType.:
{
//1929015_26838864
var pidstr = text.Text.Trim();
if (!string.IsNullOrWhiteSpace(pidstr))
{
var reg = Regex.Match(pidstr, @"(?<cpsname>\d+)_(\d+)");
if (reg.Success)
Class1.Config.pddPid = pidstr;
}
}
break;
case CpsType.:
{
//1000858402_0_1843753459_xxxxxxxxxxxxxxxxxxxxxxxxx
var pidstr = text.Text.Trim();
if (!string.IsNullOrWhiteSpace(pidstr))
{
var reg = Regex.Match(pidstr, @"(?<pid>(?<cpsname>\d+)_\d+_\d+)_(?<key>.+)");
if (reg.Success)
Class1.Config.jdPid = pidstr;
}
}
break;
default:
break;
}
}
catch (Exception ex)
{
ShowError(ex);
}
}
private void hyperlinkLabelControl_Click_1(object sender, EventArgs e)
{
try
{
var label = sender as HyperlinkLabelControl;
if (label == null) return;
var cps = (CpsType)Enum.ToObject(typeof(CpsType), int.Parse(label.Name.ToLower().Replace("hyperlinklabelcontrol_", "")));
switch (cps)
{
case CpsType.:
{
textEdit1.Text = Class1.Config.tbPid = string.Empty;
}
break;
case CpsType.:
textEdit2.Text = Class1.Config.pddPid = string.Empty;
break;
case CpsType.:
textEdit3.Text = Class1.Config.jdPid = string.Empty;
break;
default:
break;
}
}
catch (Exception ex)
{
ShowError(ex);
}
}
}
}