ResultViewNameRule.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. using Resources;
  2. using SmartCoalApplication.Base.CommTool;
  3. using SmartCoalApplication.Base.FunctionModel;
  4. using SmartCoalApplication.Base.MeasureModel;
  5. using SmartCoalApplication.Core.DbOpreate.DbModel;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.Data;
  10. using System.Drawing;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Text.RegularExpressions;
  14. using System.Threading.Tasks;
  15. using System.Windows.Forms;
  16. namespace SmartCoalApplication.AutomaticMeasurement
  17. {
  18. public partial class ResultViewNameRule : Form
  19. {
  20. private NameRuleListDetails nameRuleListDetails;
  21. private ResultsView resultsView;
  22. private MeasureMaintenanceType measureMaintenanceType;
  23. private FileNameRule fileNameRule = Program.instance.fileNameRule;
  24. public ResultViewNameRule(NameRuleListDetails nameRuleListDetails, ResultsView resultsView, MeasureMaintenanceType measureMaintenanceType)
  25. {
  26. this.nameRuleListDetails = nameRuleListDetails;
  27. this.resultsView = resultsView;
  28. this.measureMaintenanceType = measureMaintenanceType;
  29. InitializeComponent();
  30. setLanguege();
  31. NameRules();
  32. #region [赋值]
  33. List<NameRuleListDetails> detailList = new List<NameRuleListDetails>();
  34. foreach (var item in fileNameRule.NameRuleList)
  35. {
  36. if (item.ID.Equals(nameRuleListDetails.ID))
  37. {
  38. detailList.Add(nameRuleListDetails);
  39. }
  40. else {
  41. detailList.Add(item);
  42. }
  43. }
  44. this.comboBox2.DataSource = detailList;
  45. this.comboBox2.DisplayMember = "Name";
  46. this.comboBox2.SelectedIndex = -1;
  47. var details = fileNameRule.NameRuleList.Where(m => m.ID.Equals(nameRuleListDetails.ID)).FirstOrDefault();
  48. //var details = (NameRuleListDetails)this.comboBox2.SelectedItem;
  49. if (details != null)
  50. {
  51. this.comboBox2.SelectedIndexChanged -= this.comboBox2_SelectedIndexChanged;
  52. this.comboBox2.SelectedIndex = fileNameRule.NameRuleList.IndexOf(details);
  53. this.comboBox2.SelectedIndexChanged += this.comboBox2_SelectedIndexChanged;
  54. }
  55. this.textBox4.Text = nameRuleListDetails.Text;
  56. this.textBox2.Text = nameRuleListDetails.NameFormat;
  57. this.textBox7.Text = nameRuleListDetails.ZTextOne;
  58. this.textBox8.Text = nameRuleListDetails.ZTextTwo;
  59. this.comboBox1.SelectedIndex = nameRuleListDetails.DigitNum - 1;
  60. #endregion
  61. }
  62. private void setLanguege()
  63. {
  64. this.groupBox19.Text = PdnResources.GetString("FileNamingRules.groupBox19");
  65. this.label29.Text = PdnResources.GetString("FileNamingRules.label29"); // 名称
  66. this.groupBox1.Text = PdnResources.GetString("FileNamingRules.groupBox1"); // 预览
  67. this.label1.Text = PdnResources.GetString("FileNamingRules.label1"); // 名称
  68. this.label14.Text = PdnResources.GetString("FileNamingRules.label14"); // 名称格式
  69. this.label15.Text = PdnResources.GetString("FileNamingRules.label15"); // 数值位数
  70. }
  71. #region [命名规则]
  72. /// <summary>
  73. /// 初始化
  74. /// </summary>
  75. public void NameRules()
  76. {
  77. //
  78. // 设置comboBox1的集合和属性
  79. //
  80. comboBox1.Items.AddRange(InvariantData.numberNum);
  81. comboBox1.SelectedIndex = 0;
  82. #region [设置listView1]
  83. listView1.View = View.Details;
  84. listView1.Columns.Add("1", 0, HorizontalAlignment.Center);
  85. listView1.Columns.Add(PdnResources.GetString("Menu.Set.Generalsettings.format.text"), 60, HorizontalAlignment.Center);
  86. listView1.Columns.Add(PdnResources.GetString("Menu.instruction.text"), 316, HorizontalAlignment.Center);
  87. listView1.BeginUpdate();
  88. var dict = InvariantData.parameterList;
  89. foreach (var s in dict)
  90. {
  91. ListViewItem lvi1 = new ListViewItem();
  92. lvi1.Text = s.Key;
  93. lvi1.SubItems.Add(s.Key);
  94. lvi1.SubItems.Add(s.Value);
  95. listView1.Items.Add(lvi1);
  96. }
  97. listView1.EndUpdate();
  98. #endregion [设置listView1]
  99. }
  100. /// <summary>
  101. /// 校验名称
  102. /// </summary>
  103. /// <returns></returns>
  104. private bool Inspect()
  105. {
  106. bool check = false;
  107. if (string.IsNullOrEmpty(textBox2.Text))
  108. {
  109. MessageBox.Show(PdnResources.GetString("Menu.pleaseNameformat.text"));
  110. check = true;
  111. }
  112. else
  113. {
  114. string[] arrs = Regex.Split(textBox2.Text.Trim(), "%");
  115. List<string> strList = InvariantData.parameterList.Keys.ToList();
  116. if (arrs.Length == 1)
  117. {
  118. if (!textBox2.Text.Contains("%"))
  119. {
  120. MessageBox.Show("名稱格式不合法, 請檢查!");
  121. check = true;
  122. return check;
  123. }
  124. }
  125. foreach (string text in arrs)
  126. {
  127. if (text == "") continue;
  128. if (!strList.Contains("%" + text))
  129. {
  130. MessageBox.Show("名稱格式不合法, 請檢查!");
  131. check = true;
  132. }
  133. int index = this.textBox2.Text.IndexOf(text);
  134. if (index == 0)
  135. {
  136. string str = this.textBox2.Text.Substring(0, 1);
  137. if (str != "%")
  138. {
  139. MessageBox.Show("名稱格式不合法, 請檢查!");
  140. check = true;
  141. return check;
  142. }
  143. }
  144. else if (index == this.textBox2.Text.Length - 1)
  145. {
  146. string str = this.textBox2.Text.Substring(this.textBox2.Text.Length - 2, 1);
  147. if (str != "%")
  148. {
  149. MessageBox.Show("名稱格式不合法, 請檢查!");
  150. check = true;
  151. return check;
  152. }
  153. }
  154. else
  155. {
  156. string str = this.textBox2.Text.Substring(index - 1, 1);
  157. string str1 = this.textBox2.Text.Substring(index + 1, 1);
  158. if (str != "%" && str1 != "%")
  159. {
  160. MessageBox.Show("名稱格式不合法, 請檢查!");
  161. check = true;
  162. return check;
  163. }
  164. }
  165. }
  166. if (Islegal())
  167. {
  168. MessageBox.Show("文件名稱中不能包含 \\ / : * ? \" < > | ");
  169. check = true;
  170. }
  171. }
  172. return check;
  173. }
  174. /// <summary>
  175. /// 是否符合window命名规则不
  176. /// </summary>
  177. /// <returns></returns>
  178. public bool Islegal()
  179. {
  180. char[] charstr = { '\\', '/', ':', '*', '?', '"', '<', '>', '|' };
  181. char[] textstr = (textBox7.Text.Trim() + textBox8.Text.Trim()).ToString().Trim().ToCharArray();
  182. int count = 0;
  183. for (int i = 0; i < charstr.Length; i++)
  184. {
  185. for (int j = 0; j < textstr.Length; j++)
  186. {
  187. if (charstr[i] == textstr[j])
  188. {
  189. count++;
  190. }
  191. }
  192. }
  193. if (count > 0)
  194. return true;
  195. else
  196. return false;
  197. }
  198. #endregion
  199. /// <summary>
  200. /// 保存
  201. /// </summary>
  202. /// <param name="sender"></param>
  203. /// <param name="e"></param>
  204. private void btn_Save_Click(object sender, EventArgs e)
  205. {
  206. //if (comboBox2.SelectedIndex == -1)
  207. //{
  208. // return;
  209. //}
  210. //先校验
  211. bool pass = Inspect();
  212. if (pass)
  213. {
  214. return;
  215. }
  216. var details = (NameRuleListDetails)this.comboBox2.SelectedItem;
  217. nameRuleListDetails.ID = details.ID;
  218. nameRuleListDetails.Name = details.Name;
  219. nameRuleListDetails.Text = this.textBox4.Text;
  220. nameRuleListDetails.NameFormat = this.textBox2.Text;
  221. nameRuleListDetails.ZTextOne = this.textBox7.Text;
  222. nameRuleListDetails.ZTextTwo = this.textBox8.Text;
  223. try
  224. {
  225. nameRuleListDetails.DigitNum = Convert.ToInt32(this.comboBox1.SelectedItem);
  226. }
  227. catch (Exception ex)
  228. {
  229. nameRuleListDetails.DigitNum = 1;
  230. }
  231. MessageBox.Show("保存成功!");
  232. this.Close();
  233. this.resultsView.NameRuleCallBack(nameRuleListDetails);
  234. }
  235. /// <summary>
  236. /// 取消
  237. /// </summary>
  238. /// <param name="sender"></param>
  239. /// <param name="e"></param>
  240. private void button2_Click(object sender, EventArgs e)
  241. {
  242. this.Close();
  243. }
  244. /// <summary>
  245. /// 预览
  246. /// </summary>
  247. /// <param name="sender"></param>
  248. /// <param name="e"></param>
  249. private void textBox2_TextChanged(object sender, EventArgs e)
  250. {
  251. if (string.IsNullOrEmpty(this.textBox2.Text))
  252. {
  253. this.textBox5.Text = string.Empty;
  254. return;
  255. }
  256. //先校验
  257. bool pass = Inspect();
  258. if (pass)
  259. {
  260. return;
  261. }
  262. string ruleName = string.Empty;
  263. string ruleGain = string.Empty;
  264. if (this.measureMaintenanceType.ruleMessage != null)
  265. {
  266. ruleName = this.measureMaintenanceType.ruleMessage.ruleName;
  267. ruleGain = this.measureMaintenanceType.ruleMessage.ruleGain.ToString();
  268. }
  269. else
  270. {
  271. List<mic_rulers> list = Program.instance.mic_rulersAll;
  272. var ruler = list.Where(m => m.id.Equals(Program.instance.configModel.RulerId)).FirstOrDefault();
  273. if (ruler != null)
  274. {
  275. ruleName = ruler.ruler_name;
  276. ruleGain = ruler.gain_multiple.ToString();
  277. }
  278. }
  279. NamingRuleHelper namingRuleHelper = new NamingRuleHelper();
  280. NameRuleListDetails newNameRuleListDetails = new NameRuleListDetails();
  281. newNameRuleListDetails.Text = this.textBox4.Text;
  282. newNameRuleListDetails.NameFormat = this.textBox2.Text;
  283. newNameRuleListDetails.ZTextOne = this.textBox7.Text;
  284. newNameRuleListDetails.ZTextTwo = this.textBox8.Text;
  285. newNameRuleListDetails.isContinue = this.nameRuleListDetails.isContinue;
  286. newNameRuleListDetails.DigitNum = this.comboBox1.SelectedIndex + 1;
  287. newNameRuleListDetails.ContinueNumber = this.nameRuleListDetails.ContinueNumber;
  288. newNameRuleListDetails.NowNumber = nameRuleListDetails.NowNumber;
  289. this.textBox5.Text = namingRuleHelper.GetNameFromXml(newNameRuleListDetails, ruleName, ruleGain, this.measureMaintenanceType,"");
  290. }
  291. private void listView1_DoubleClick(object sender, EventArgs e)
  292. {
  293. if (this.listView1.FocusedItem != null && this.listView1.FocusedItem.Index != -1)
  294. {
  295. var dict = InvariantData.parameterList;
  296. int start = this.textBox2.SelectionStart;
  297. this.textBox2.Text = this.textBox2.Text.Insert(start, dict.Keys.ToList()[this.listView1.FocusedItem.Index]);
  298. this.textBox2.SelectionStart = this.textBox2.Text.Length;
  299. }
  300. }
  301. /// <summary>
  302. ///
  303. /// </summary>
  304. /// <param name="sender"></param>
  305. /// <param name="e"></param>
  306. private void text_change(object sender, EventArgs e)
  307. {
  308. if (!string.IsNullOrEmpty(textBox2.Text))
  309. {
  310. textBox2_TextChanged(null, null);
  311. }
  312. }
  313. /// <summary>
  314. ///
  315. /// </summary>
  316. /// <param name="sender"></param>
  317. /// <param name="e"></param>
  318. private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
  319. {
  320. if (comboBox2.SelectedIndex == -1)
  321. {
  322. return;
  323. }
  324. var details = (NameRuleListDetails)this.comboBox2.SelectedItem;
  325. this.textBox4.Text = details.Text;
  326. this.textBox2.Text = details.NameFormat;
  327. this.textBox7.Text = details.ZTextOne;
  328. this.textBox8.Text = details.ZTextTwo;
  329. this.comboBox1.SelectedIndex = details.DigitNum - 1;
  330. }
  331. }
  332. }