using Resources; using SmartCoalApplication.Base.CommTool; using SmartCoalApplication.Base.FunctionModel; using SmartCoalApplication.Base.MeasureModel; using SmartCoalApplication.Core.DbOpreate.DbModel; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Forms; namespace SmartCoalApplication.AutomaticMeasurement { public partial class ResultViewNameRule : Form { private NameRuleListDetails nameRuleListDetails; private ResultsView resultsView; private MeasureMaintenanceType measureMaintenanceType; private FileNameRule fileNameRule = Program.instance.fileNameRule; public ResultViewNameRule(NameRuleListDetails nameRuleListDetails, ResultsView resultsView, MeasureMaintenanceType measureMaintenanceType) { this.nameRuleListDetails = nameRuleListDetails; this.resultsView = resultsView; this.measureMaintenanceType = measureMaintenanceType; InitializeComponent(); setLanguege(); NameRules(); #region [赋值] List detailList = new List(); foreach (var item in fileNameRule.NameRuleList) { if (item.ID.Equals(nameRuleListDetails.ID)) { detailList.Add(nameRuleListDetails); } else { detailList.Add(item); } } this.comboBox2.DataSource = detailList; this.comboBox2.DisplayMember = "Name"; this.comboBox2.SelectedIndex = -1; var details = fileNameRule.NameRuleList.Where(m => m.ID.Equals(nameRuleListDetails.ID)).FirstOrDefault(); //var details = (NameRuleListDetails)this.comboBox2.SelectedItem; if (details != null) { this.comboBox2.SelectedIndexChanged -= this.comboBox2_SelectedIndexChanged; this.comboBox2.SelectedIndex = fileNameRule.NameRuleList.IndexOf(details); this.comboBox2.SelectedIndexChanged += this.comboBox2_SelectedIndexChanged; } this.textBox4.Text = nameRuleListDetails.Text; this.textBox2.Text = nameRuleListDetails.NameFormat; this.textBox7.Text = nameRuleListDetails.ZTextOne; this.textBox8.Text = nameRuleListDetails.ZTextTwo; this.comboBox1.SelectedIndex = nameRuleListDetails.DigitNum - 1; #endregion } private void setLanguege() { this.groupBox19.Text = PdnResources.GetString("FileNamingRules.groupBox19"); this.label29.Text = PdnResources.GetString("FileNamingRules.label29"); // 名称 this.groupBox1.Text = PdnResources.GetString("FileNamingRules.groupBox1"); // 预览 this.label1.Text = PdnResources.GetString("FileNamingRules.label1"); // 名称 this.label14.Text = PdnResources.GetString("FileNamingRules.label14"); // 名称格式 this.label15.Text = PdnResources.GetString("FileNamingRules.label15"); // 数值位数 } #region [命名规则] /// /// 初始化 /// public void NameRules() { // // 设置comboBox1的集合和属性 // comboBox1.Items.AddRange(InvariantData.numberNum); comboBox1.SelectedIndex = 0; #region [设置listView1] listView1.View = View.Details; listView1.Columns.Add("1", 0, HorizontalAlignment.Center); listView1.Columns.Add(PdnResources.GetString("Menu.Set.Generalsettings.format.text"), 60, HorizontalAlignment.Center); listView1.Columns.Add(PdnResources.GetString("Menu.instruction.text"), 316, HorizontalAlignment.Center); listView1.BeginUpdate(); var dict = InvariantData.parameterList; foreach (var s in dict) { ListViewItem lvi1 = new ListViewItem(); lvi1.Text = s.Key; lvi1.SubItems.Add(s.Key); lvi1.SubItems.Add(s.Value); listView1.Items.Add(lvi1); } listView1.EndUpdate(); #endregion [设置listView1] } /// /// 校验名称 /// /// private bool Inspect() { bool check = false; if (string.IsNullOrEmpty(textBox2.Text)) { MessageBox.Show(PdnResources.GetString("Menu.pleaseNameformat.text")); check = true; } else { string[] arrs = Regex.Split(textBox2.Text.Trim(), "%"); List strList = InvariantData.parameterList.Keys.ToList(); if (arrs.Length == 1) { if (!textBox2.Text.Contains("%")) { MessageBox.Show("名稱格式不合法, 請檢查!"); check = true; return check; } } foreach (string text in arrs) { if (text == "") continue; if (!strList.Contains("%" + text)) { MessageBox.Show("名稱格式不合法, 請檢查!"); check = true; } int index = this.textBox2.Text.IndexOf(text); if (index == 0) { string str = this.textBox2.Text.Substring(0, 1); if (str != "%") { MessageBox.Show("名稱格式不合法, 請檢查!"); check = true; return check; } } else if (index == this.textBox2.Text.Length - 1) { string str = this.textBox2.Text.Substring(this.textBox2.Text.Length - 2, 1); if (str != "%") { MessageBox.Show("名稱格式不合法, 請檢查!"); check = true; return check; } } else { string str = this.textBox2.Text.Substring(index - 1, 1); string str1 = this.textBox2.Text.Substring(index + 1, 1); if (str != "%" && str1 != "%") { MessageBox.Show("名稱格式不合法, 請檢查!"); check = true; return check; } } } if (Islegal()) { MessageBox.Show("文件名稱中不能包含 \\ / : * ? \" < > | "); check = true; } } return check; } /// /// 是否符合window命名规则不 /// /// public bool Islegal() { char[] charstr = { '\\', '/', ':', '*', '?', '"', '<', '>', '|' }; char[] textstr = (textBox7.Text.Trim() + textBox8.Text.Trim()).ToString().Trim().ToCharArray(); int count = 0; for (int i = 0; i < charstr.Length; i++) { for (int j = 0; j < textstr.Length; j++) { if (charstr[i] == textstr[j]) { count++; } } } if (count > 0) return true; else return false; } #endregion /// /// 保存 /// /// /// private void btn_Save_Click(object sender, EventArgs e) { //if (comboBox2.SelectedIndex == -1) //{ // return; //} //先校验 bool pass = Inspect(); if (pass) { return; } var details = (NameRuleListDetails)this.comboBox2.SelectedItem; nameRuleListDetails.ID = details.ID; nameRuleListDetails.Name = details.Name; nameRuleListDetails.Text = this.textBox4.Text; nameRuleListDetails.NameFormat = this.textBox2.Text; nameRuleListDetails.ZTextOne = this.textBox7.Text; nameRuleListDetails.ZTextTwo = this.textBox8.Text; try { nameRuleListDetails.DigitNum = Convert.ToInt32(this.comboBox1.SelectedItem); } catch (Exception ex) { nameRuleListDetails.DigitNum = 1; } MessageBox.Show("保存成功!"); this.Close(); this.resultsView.NameRuleCallBack(nameRuleListDetails); } /// /// 取消 /// /// /// private void button2_Click(object sender, EventArgs e) { this.Close(); } /// /// 预览 /// /// /// private void textBox2_TextChanged(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.textBox2.Text)) { this.textBox5.Text = string.Empty; return; } //先校验 bool pass = Inspect(); if (pass) { return; } string ruleName = string.Empty; string ruleGain = string.Empty; if (this.measureMaintenanceType.ruleMessage != null) { ruleName = this.measureMaintenanceType.ruleMessage.ruleName; ruleGain = this.measureMaintenanceType.ruleMessage.ruleGain.ToString(); } else { List list = Program.instance.mic_rulersAll; var ruler = list.Where(m => m.id.Equals(Program.instance.configModel.RulerId)).FirstOrDefault(); if (ruler != null) { ruleName = ruler.ruler_name; ruleGain = ruler.gain_multiple.ToString(); } } NamingRuleHelper namingRuleHelper = new NamingRuleHelper(); NameRuleListDetails newNameRuleListDetails = new NameRuleListDetails(); newNameRuleListDetails.Text = this.textBox4.Text; newNameRuleListDetails.NameFormat = this.textBox2.Text; newNameRuleListDetails.ZTextOne = this.textBox7.Text; newNameRuleListDetails.ZTextTwo = this.textBox8.Text; newNameRuleListDetails.isContinue = this.nameRuleListDetails.isContinue; newNameRuleListDetails.DigitNum = this.comboBox1.SelectedIndex + 1; newNameRuleListDetails.ContinueNumber = this.nameRuleListDetails.ContinueNumber; newNameRuleListDetails.NowNumber = nameRuleListDetails.NowNumber; this.textBox5.Text = namingRuleHelper.GetNameFromXml(newNameRuleListDetails, ruleName, ruleGain, this.measureMaintenanceType,""); } private void listView1_DoubleClick(object sender, EventArgs e) { if (this.listView1.FocusedItem != null && this.listView1.FocusedItem.Index != -1) { var dict = InvariantData.parameterList; int start = this.textBox2.SelectionStart; this.textBox2.Text = this.textBox2.Text.Insert(start, dict.Keys.ToList()[this.listView1.FocusedItem.Index]); this.textBox2.SelectionStart = this.textBox2.Text.Length; } } /// /// /// /// /// private void text_change(object sender, EventArgs e) { if (!string.IsNullOrEmpty(textBox2.Text)) { textBox2_TextChanged(null, null); } } /// /// /// /// /// private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox2.SelectedIndex == -1) { return; } var details = (NameRuleListDetails)this.comboBox2.SelectedItem; this.textBox4.Text = details.Text; this.textBox2.Text = details.NameFormat; this.textBox7.Text = details.ZTextOne; this.textBox8.Text = details.ZTextTwo; this.comboBox1.SelectedIndex = details.DigitNum - 1; } } }