|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using static DefectItemsTool.Form1;
-
- namespace DefectItemsTool
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
-
- #region 尺寸
- List<SizeItemParam> sizeItemParams = new List<SizeItemParam>();
-
- public class SizeItemParam
- {
- /// <summary>
- /// 名称
- /// </summary>
- public string Name { get; set; }
- /// <summary>
- /// 代码
- /// </summary>
- public string Code { get; set; }
- /// <summary>
- /// 测试点数
- /// </summary>
- public int PointCnt { get; set; }
- /// <summary>
- /// 处理代码
- /// </summary>
- public int[] DefectIndex { get; set; }
- /// <summary>
- /// RGB颜色代码
- /// </summary>
- public int[] RGBcolor { get; set; }
-
- }
-
- private void button1_Click(object sender, EventArgs e)
- {
- SizeItemParam sizeItem = new SizeItemParam();
- sizeItem.Name = textBox1.Text;
- sizeItem.Code = textBox2.Text;
- sizeItem.PointCnt = (int)numericUpDown1.Value;
- try
- {
- sizeItem.DefectIndex = Array.ConvertAll<string, int>(textBox3.Text.Split(','), s => int.Parse(s));
- if (sizeItem.DefectIndex.Length > sizeItem.PointCnt)
- {
- MessageBox.Show("处理代码数据错误,长度大于测试点数!", "警告");
- return;
- }
- }
- catch {
- MessageBox.Show("处理代码格式错误!", "警告");
- return;
- }
- try
- {
- sizeItem.RGBcolor = Array.ConvertAll<string, int>(textBox4.Text.Split(','), s => int.Parse(s));
- if (sizeItem.RGBcolor.Length > 3)
- {
- MessageBox.Show("RGB颜色代码数据错误,长度大于3!", "警告");
- return;
- }
- for (int i = 0; i< sizeItem.RGBcolor.Length; i++)
- {
- if(sizeItem.RGBcolor[i] >256)
- {
- MessageBox.Show("RGB颜色代码数据错误,不能大于255!", "警告");
- return;
- }
- }
- }
- catch
- {
- MessageBox.Show("RGB颜色代码格式错误!", "警告");
- return;
- }
- if(sizeItemParams.Count >0)
- {
- for (int i = 0; i < sizeItemParams.Count; i++)
- {
- if (sizeItemParams[i].Name == sizeItem.Name)
- {
- MessageBox.Show("名称已存在!", "警告");
- return;
- }
- if (sizeItemParams[i].Code == sizeItem.Code)
- {
- MessageBox.Show("代码已存在!", "警告");
- return;
- }
- if (Enumerable.SequenceEqual(sizeItemParams[i].DefectIndex , sizeItem.DefectIndex))
- {
- MessageBox.Show("处理代码已存在!", "警告");
- return;
- }
- if (Enumerable.SequenceEqual(sizeItemParams[i].RGBcolor, sizeItem.RGBcolor))
- {
- MessageBox.Show("RGB颜色代码已存在!", "警告");
- return;
- }
- }
- }
- sizeItemParams.Add(sizeItem);
- //listBox1.Items.Clear();
- listBox1.Items.Add(sizeItem.Name);
- this.Refresh();
- }
- private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
- {
- int index = this.listBox1.SelectedIndex;
- textBox5.Text = JsonConvert.SerializeObject(sizeItemParams[index]);
- }
-
- private void button2_Click(object sender, EventArgs e)
- {
- SaveFileDialog dialog = new SaveFileDialog();
- dialog.Filter = "Json文件(*.json)|*.json"; //设置文件类型
- dialog.FileName = "尺寸测试项"; //设置默认文件名
- dialog.DefaultExt = "json"; //设置默认格式(可以不设)
- //dialog.AddExtension = true; //设置自动在文件名中添加扩展名
- if (dialog.ShowDialog() == DialogResult.OK)
- {
- File.WriteAllText(dialog.FileName.ToString(), JsonConvert.SerializeObject(sizeItemParams));
- }
- }
-
- private void button3_Click(object sender, EventArgs e)
- {
- OpenFileDialog openFileDialog1 = new OpenFileDialog();
- openFileDialog1.Filter = "Json文件(*.json)|*.json"; //设置文件类型
- DialogResult result = openFileDialog1.ShowDialog();
- if (result == DialogResult.OK)
- {
- string str = File.ReadAllText(openFileDialog1.FileName);
- sizeItemParams = JsonConvert.DeserializeObject<List<SizeItemParam>>(str);
- listBox1.Items.Clear();
- for (int i = 0; i < sizeItemParams.Count; i++)
- listBox1.Items.Add(sizeItemParams[i].Name);
- this.Refresh();
- }
- }
- #endregion
-
-
- }
- }
|