| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Globalization;
- using System.IO;
- using System.Linq;
- using System.Media;
- using System.Security.Principal;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using UAS_Tools_HY;
- using UAS_Tools_HY.PublicMethods;
- namespace UAS_MES_Tools
- {
- public partial class Main : Form
- {
- string _Account, _Password, _UserName;
- DataTable dt;
- Timer loadTime;
- string minTime, maxTime;
- string curRule, curRuleLeng;
- public Main(string account, string password)
- {
- _Account = account;
- _Password = password;
- InitializeComponent();
- }
- private void Main_Load(object sender, EventArgs e)
- {
- currUser.Text = "当前账户: " + _Account;
- dt = ConnectDB.ExecuteSelect($"select * from employee where em_code = '{_Account}'");
- if (dt.Rows.Count > 0)
- {
- _UserName = dt.Rows[0]["em_name"].ToString();
- }
- loadTime_Tick(null, null);
- loadTime = new Timer();
- loadTime.Interval = 1000;
- loadTime.Tick += loadTime_Tick;
- loadTime.Start();
- SN.SelectAll();
- SN.Focus();
- settingLeftInput1.Text = BaseUtil.GetCacheData("SettingCount").ToString();
- settingLeftInput2.Text = BaseUtil.GetCacheData("SettingVolume").ToString();
- settingRightInput1.Text = BaseUtil.GetCacheData("SettingNGPath").ToString();
- settingRightInput2.Text = BaseUtil.GetCacheData("SettingExportPath").ToString();
-
- QDcheckbox1.Checked = true;
- QDdtp1.Value = QDdtp2.Value.AddDays(-1);
- rulesQuery_Click(null, null);
- }
- private void SN_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode != Keys.Enter) return;
- if (CheckEnter()) return;
- bool checkRes = true;
- ShowMsg.Text = "Pass";
- ShowMsg.BackColor = Color.LawnGreen;
- if (radio1.Checked)
- {
- dt = ConnectDB.ExecuteSelect($@"SELECT COUNT(1) sum FROM dcrlogexcel WHERE item = '{SN.Text.Trim()}'");
- if (dt.Rows[0]["sum"].ToString() == "0")
- {
- PlaySound("NG");
- ShowMsg.Text = "Fail";
- ShowMsg.BackColor = Color.Red;
- MessageBox.Show($"{SN.Text.Trim()},没有DCR测试数据", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- checkRes = false;
- return;
- }
- }
- if (FormMethods.IsCheckSNRules(curRule, SN.Text.Trim(), curRuleLeng))
- {
- PlaySound("NG");
- ShowMsg.Text = "Fail";
- ShowMsg.BackColor = Color.Red;
- MessageBox.Show($"{SN.Text.Trim()},不符合条码规则", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- checkRes = false;
- return;
- }
- if (Datas.Rows.Count > 0)
- {
- foreach (DataGridViewRow item in Datas.Rows)
- {
- if (SN.Text.Trim() == item.Cells[0].Value.ToString())
- {
- int iCou = Convert.ToInt32(item.Cells[2].Value);
- iCou += 1;
- item.Cells[3].Value = currTime.Text;
- item.Cells[6].Value = checkRes ? "OK" : "NG";
- }
- }
- }
- DataGridViewRow row = new DataGridViewRow();
- row.CreateCells(Datas);
- row.Cells[0].Value = SN.Text.Trim();
- row.Cells[1].Value = BoxNo.Text.Trim();
- row.Cells[2].Value = 1;
- row.Cells[3].Value = currTime.Text;
- row.Cells[4].Value = _UserName;
- row.Cells[5].Value = radio1.Checked ? "是" : "否";
- row.Cells[6].Value = checkRes ? "OK": "NG";
- Datas.Rows.Add(row);
- PlaySound("OK");
- Datas.FirstDisplayedScrollingRowIndex = Datas.Rows.Count - 1;
- }
- private void BoxNo_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode != Keys.Enter) return;
- if (CheckEnter()) return;
- if (Datas.Rows.Count > 0)
- {
- foreach(DataGridViewRow item in Datas.Rows)
- {
- item.Cells[1].Value = BoxNo.Text.Trim();
- }
- }
- BoxNo.Enabled = false;
- SN.SelectAll();
- SN.Focus();
- }
- private bool CheckEnter()
- {
- if (string.IsNullOrEmpty(settingLeftInput1.Text))
- {
- MessageBox.Show("请维护列表记录数", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return true;
- }
- if (string.IsNullOrEmpty(settingLeftInput2.Text))
- {
- MessageBox.Show("请维护箱内容量", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return true;
- }
- if (string.IsNullOrEmpty(dRules.Text))
- {
- MessageBox.Show("请选择条码规则", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return true;
- }
- if (dRules.Enabled)
- {
- MessageBox.Show("请选择确认条码规则", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return true;
- }
- return false;
- }
-
- private void settingLeftSubmit_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(settingLeftInput1.Text))
- {
- MessageBox.Show("请输入列表记录数", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- if (string.IsNullOrEmpty(settingLeftInput2.Text))
- {
- MessageBox.Show("请输入箱内容量", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- BaseUtil.SetCacheData("SettingCount", settingLeftInput1.Text);
- BaseUtil.SetCacheData("SettingVolume", settingLeftInput2.Text);
- MessageBox.Show("已提交扫描设置", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- private void settingRightSubmit_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(settingRightInput2.Text))
- {
- MessageBox.Show("请选择导出文件目录", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- if(!string.IsNullOrEmpty(settingRightInput1.Text)) BaseUtil.SetCacheData("SettingNGPath", settingRightInput1.Text);
- BaseUtil.SetCacheData("SettingExportPath", settingRightInput2.Text);
- MessageBox.Show("已提交文件设置", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- private void QDquery_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(QDInput1.Text) && string.IsNullOrEmpty(QDInput2.Text) && !QDcheckbox1.Checked)
- {
- MessageBox.Show("请添加筛选条件", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- if (QDcheckbox1.Checked)
- {
- }
- }
- private void QDexport_Click(object sender, EventArgs e)
- {
- if(QDDatas.Rows.Count == 0)
- {
- MessageBox.Show("请筛选数据", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- }
- private void rulesAdd_Click(object sender, EventArgs e)
- {
- StringBuilder filterStr = new StringBuilder();
- if (!string.IsNullOrEmpty(rulesInput1.Text))
- {
- filterStr.Append($"WHERE instr(RULE_NAME,'{rulesInput1.Text}') > 0");
- }
- if (!string.IsNullOrEmpty(rulesInput2.Text))
- {
- if(filterStr.Length == 0)
- {
- filterStr.Append($"WHERE instr(RULE_VALUE,'{rulesInput2.Text}') > 0");
- }
- else
- {
- filterStr.Append($" and instr(RULE_VALUE, '{rulesInput2.Text}') > 0");
- }
- }
- Form rulesList = new RulesList("Add",_UserName);
- if (rulesList.ShowDialog() == DialogResult.OK)
- {
- MessageBox.Show("新增规则成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- dt = ConnectDB.ExecuteSelect($@"SELECT RULE_ID ruleId,RULE_NAME RulesCol1, RULE_VALUE RulesCol2, RELE_REMARK RulesCol3,
- RULE_LENGTH RulesCol4,to_char(UPDATE_TIME, 'YYYY-MM-DD HH:Mi:SS') RulesCol5,UPDATE_USER RulesCol6 FROM g_packing_rules {filterStr.ToString()} order by UPDATE_TIME desc");
- RulesDatas.DataSource = dt;
- }
- }
- private void rulesQuery_Click(object sender, EventArgs e)
- {
- StringBuilder filterStr = new StringBuilder();
- if (!string.IsNullOrEmpty(rulesInput1.Text))
- {
- filterStr.Append($"WHERE instr(RULE_NAME,'{rulesInput1.Text}') > 0");
- }
- if (!string.IsNullOrEmpty(rulesInput2.Text))
- {
- if (filterStr.Length == 0)
- {
- filterStr.Append($"WHERE instr(RULE_VALUE,'{rulesInput2.Text}') > 0");
- }
- else
- {
- filterStr.Append($" and instr(RULE_VALUE, '{rulesInput2.Text}') > 0");
- }
- }
- dt = ConnectDB.ExecuteSelect($@"SELECT RULE_ID ruleId,RULE_NAME RulesCol1, RULE_VALUE RulesCol2, RELE_REMARK RulesCol3,
- RULE_LENGTH RulesCol4,to_char(UPDATE_TIME, 'YYYY-MM-DD HH:Mi:SS') RulesCol5,UPDATE_USER RulesCol6 FROM g_packing_rules {filterStr.ToString()} order by UPDATE_TIME desc");
- RulesDatas.DataSource = dt;
- }
- private void RulesDatas_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
- {
- if (e.RowIndex >= 0 && !RulesDatas.Rows[e.RowIndex].IsNewRow)
- {
- DataGridView dgv = sender as DataGridView;
- if (dgv != null)
- {
- DataGridViewRow selectedRow = dgv.Rows[e.RowIndex];
- string RULE_ID = selectedRow.Cells[0].Value.ToString();
- StringBuilder filterStr = new StringBuilder();
- if (!string.IsNullOrEmpty(rulesInput1.Text))
- {
- filterStr.Append($"WHERE instr(RULE_NAME,'{rulesInput1.Text}') > 0");
- }
- if (!string.IsNullOrEmpty(rulesInput2.Text))
- {
- if (filterStr.Length == 0)
- {
- filterStr.Append($"WHERE instr(RULE_VALUE,'{rulesInput2.Text}') > 0");
- }
- else
- {
- filterStr.Append($" and instr(RULE_VALUE, '{rulesInput2.Text}') > 0");
- }
- }
- Form rulesList = new RulesList("Modify",RULE_ID, _UserName);
- if (rulesList.ShowDialog() == DialogResult.OK)
- {
- MessageBox.Show("修改规则成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- dt = ConnectDB.ExecuteSelect($@"SELECT RULE_ID ruleId,RULE_NAME RulesCol1, RULE_VALUE RulesCol2, RELE_REMARK RulesCol3,
- RULE_LENGTH RulesCol4,to_char(UPDATE_TIME, 'YYYY-MM-DD HH:Mi:SS') RulesCol5,UPDATE_USER RulesCol6 FROM g_packing_rules {filterStr.ToString()} order by UPDATE_TIME desc");
- RulesDatas.DataSource = dt;
- }
- }
- }
- }
- private void RulesDatas_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
- {
- if (e.RowIndex >= 0 && !RulesDatas.Rows[e.RowIndex].IsNewRow)
- {
- DataGridView dgv = sender as DataGridView;
- if (dgv != null)
- {
- DataGridViewRow selectedRow = dgv.Rows[e.RowIndex];
- if (dRules.Enabled)
- {
- dRules.Text = selectedRow.Cells[1].Value.ToString();
- curRule = selectedRow.Cells[2].Value.ToString();
- curRuleLeng = selectedRow.Cells[4].Value.ToString();
- }
- }
- }
- }
- private void boxBtn_Click(object sender, EventArgs e)
- {
- BoxNo.Enabled = true;
- BoxNo.Focus();
- BoxNo.SelectAll();
- }
- private void settingRightInput1_Click(object sender, EventArgs e)
- {
- using (OpenFileDialog openFileDialog = new OpenFileDialog())
- {
- openFileDialog.Title = "请选择告警文件";
- openFileDialog.Filter = "可执行文件 (*.wav)|*.wav|所有文件 (*.*)|*.*";
- openFileDialog.FilterIndex = 1;
- openFileDialog.RestoreDirectory = true;
- if (!string.IsNullOrEmpty(settingRightInput1.Text) && System.IO.File.Exists(settingRightInput1.Text))
- {
- openFileDialog.InitialDirectory = System.IO.Path.GetDirectoryName(settingRightInput1.Text);
- }
- else
- {
- openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
- }
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
- settingRightInput1.Text = openFileDialog.FileName;
- }
- }
- }
- private void settingRightInput2_Click(object sender, EventArgs e)
- {
- using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
- {
- folderBrowserDialog.Description = "请选择导出文件夹";
- if (!string.IsNullOrEmpty(settingRightInput2.Text) && System.IO.Directory.Exists(settingRightInput2.Text))
- {
- folderBrowserDialog.SelectedPath = settingRightInput2.Text;
- }
- else
- {
- folderBrowserDialog.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); // folderBrowserDialog.SelectedPath = "";
- }
- if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
- {
- settingRightInput2.Text = folderBrowserDialog.SelectedPath;
- }
- }
- }
- private void QDdtp1_ValueChanged(object sender, EventArgs e)
- {
- if (QDdtp1.Value > QDdtp2.Value)
- {
- QDdtp1.Value = QDdtp2.Value.AddDays(-1);
- MessageBox.Show("时间不得大于最大时间", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- minTime = QDdtp1.Value.ToString("yyyy-mm-dd hh:mm:ss");
- }
- private void DRulesBtn_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(dRules.Text))
- {
- MessageBox.Show("请选择条码规则", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- dRules.Enabled = false;
- }
- private void DRulesBtn1_Click(object sender, EventArgs e)
- {
- dRules.Enabled = true;
- }
- private void QDdtp2_ValueChanged(object sender, EventArgs e)
- {
- if (QDdtp2.Value < QDdtp1.Value)
- {
- QDdtp2.Value = QDdtp1.Value.AddDays(1);
- MessageBox.Show("时间不得小于最小时间", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- maxTime = QDdtp2.Value.ToString("yyyy-mm-dd hh:mm:ss");
- }
- private void PlaySound(string type)
- {
- Task.Run(() => {
- if (type == "OK")
- {
- using (var stream = UAS_Tools_HY.Properties.Resources.OK)
- {
- SoundPlayer player = new SoundPlayer(stream);
- player.Play();
- }
- }
- else
- {
- if (string.IsNullOrEmpty(settingRightInput1.Text))
- {
- using (var stream = UAS_Tools_HY.Properties.Resources.NG)
- {
- SoundPlayer player = new SoundPlayer(stream);
- player.Play();
- }
- }
- else
- {
- string customPath = settingRightInput1.Text.Trim();
- if (File.Exists(customPath))
- {
- SoundPlayer player = new SoundPlayer(customPath);
- player.Play();
- }
- }
- }
- });
- }
- public void loadTime_Tick(object sender, EventArgs e)
- {
- string currentDate = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
- currTime.Text = currentDate;
- }
- }
- }
|