版博士V2.0程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

162 wiersze
5.9 KiB

  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using static DefectItemsTool.Form1;
  13. namespace DefectItemsTool
  14. {
  15. public partial class Form1 : Form
  16. {
  17. public Form1()
  18. {
  19. InitializeComponent();
  20. }
  21. #region 尺寸
  22. List<SizeItemParam> sizeItemParams = new List<SizeItemParam>();
  23. public class SizeItemParam
  24. {
  25. /// <summary>
  26. /// 名称
  27. /// </summary>
  28. public string Name { get; set; }
  29. /// <summary>
  30. /// 代码
  31. /// </summary>
  32. public string Code { get; set; }
  33. /// <summary>
  34. /// 测试点数
  35. /// </summary>
  36. public int PointCnt { get; set; }
  37. /// <summary>
  38. /// 处理代码
  39. /// </summary>
  40. public int[] DefectIndex { get; set; }
  41. /// <summary>
  42. /// RGB颜色代码
  43. /// </summary>
  44. public int[] RGBcolor { get; set; }
  45. }
  46. private void button1_Click(object sender, EventArgs e)
  47. {
  48. SizeItemParam sizeItem = new SizeItemParam();
  49. sizeItem.Name = textBox1.Text;
  50. sizeItem.Code = textBox2.Text;
  51. sizeItem.PointCnt = (int)numericUpDown1.Value;
  52. try
  53. {
  54. sizeItem.DefectIndex = Array.ConvertAll<string, int>(textBox3.Text.Split(','), s => int.Parse(s));
  55. if (sizeItem.DefectIndex.Length > sizeItem.PointCnt)
  56. {
  57. MessageBox.Show("处理代码数据错误,长度大于测试点数!", "警告");
  58. return;
  59. }
  60. }
  61. catch {
  62. MessageBox.Show("处理代码格式错误!", "警告");
  63. return;
  64. }
  65. try
  66. {
  67. sizeItem.RGBcolor = Array.ConvertAll<string, int>(textBox4.Text.Split(','), s => int.Parse(s));
  68. if (sizeItem.RGBcolor.Length > 3)
  69. {
  70. MessageBox.Show("RGB颜色代码数据错误,长度大于3!", "警告");
  71. return;
  72. }
  73. for (int i = 0; i< sizeItem.RGBcolor.Length; i++)
  74. {
  75. if(sizeItem.RGBcolor[i] >256)
  76. {
  77. MessageBox.Show("RGB颜色代码数据错误,不能大于255!", "警告");
  78. return;
  79. }
  80. }
  81. }
  82. catch
  83. {
  84. MessageBox.Show("RGB颜色代码格式错误!", "警告");
  85. return;
  86. }
  87. if(sizeItemParams.Count >0)
  88. {
  89. for (int i = 0; i < sizeItemParams.Count; i++)
  90. {
  91. if (sizeItemParams[i].Name == sizeItem.Name)
  92. {
  93. MessageBox.Show("名称已存在!", "警告");
  94. return;
  95. }
  96. if (sizeItemParams[i].Code == sizeItem.Code)
  97. {
  98. MessageBox.Show("代码已存在!", "警告");
  99. return;
  100. }
  101. if (Enumerable.SequenceEqual(sizeItemParams[i].DefectIndex , sizeItem.DefectIndex))
  102. {
  103. MessageBox.Show("处理代码已存在!", "警告");
  104. return;
  105. }
  106. if (Enumerable.SequenceEqual(sizeItemParams[i].RGBcolor, sizeItem.RGBcolor))
  107. {
  108. MessageBox.Show("RGB颜色代码已存在!", "警告");
  109. return;
  110. }
  111. }
  112. }
  113. sizeItemParams.Add(sizeItem);
  114. //listBox1.Items.Clear();
  115. listBox1.Items.Add(sizeItem.Name);
  116. this.Refresh();
  117. }
  118. private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
  119. {
  120. int index = this.listBox1.SelectedIndex;
  121. textBox5.Text = JsonConvert.SerializeObject(sizeItemParams[index]);
  122. }
  123. private void button2_Click(object sender, EventArgs e)
  124. {
  125. SaveFileDialog dialog = new SaveFileDialog();
  126. dialog.Filter = "Json文件(*.json)|*.json"; //设置文件类型
  127. dialog.FileName = "尺寸测试项"; //设置默认文件名
  128. dialog.DefaultExt = "json"; //设置默认格式(可以不设)
  129. //dialog.AddExtension = true; //设置自动在文件名中添加扩展名
  130. if (dialog.ShowDialog() == DialogResult.OK)
  131. {
  132. File.WriteAllText(dialog.FileName.ToString(), JsonConvert.SerializeObject(sizeItemParams));
  133. }
  134. }
  135. private void button3_Click(object sender, EventArgs e)
  136. {
  137. OpenFileDialog openFileDialog1 = new OpenFileDialog();
  138. openFileDialog1.Filter = "Json文件(*.json)|*.json"; //设置文件类型
  139. DialogResult result = openFileDialog1.ShowDialog();
  140. if (result == DialogResult.OK)
  141. {
  142. string str = File.ReadAllText(openFileDialog1.FileName);
  143. sizeItemParams = JsonConvert.DeserializeObject<List<SizeItemParam>>(str);
  144. listBox1.Items.Clear();
  145. for (int i = 0; i < sizeItemParams.Count; i++)
  146. listBox1.Items.Add(sizeItemParams[i].Name);
  147. this.Refresh();
  148. }
  149. }
  150. #endregion
  151. }
  152. }