/// <summary> /// 第i项从json删除 /// </summary> /// <param name="lv"></param> /// <param name="list_Format"></param> /// <param name="list"></param> /// <param name="i"></param> /// <returns></returns> private static List_format white_check_value(ListView lv, List_format list_Format, List <string> list, int i) { list[i - 1] = null; list_Format = new List_format { one = list[0], two = list[1], three = list[2], four = list[3], five = list[4], six = list[5], seven = list[6], eight = list[7], nine = list[8], ten = list[9] }; return(list_Format); }
/// <summary> /// 颜色选择水绿色后把校验项写入json /// </summary> /// <param name="i"></param> private void Json_write_check_value(int i) { My_config my_Config = ReadFile(); var config = new My_config(); var checkCode_value = new List_format(); checkCode_value = Add_check_value(this.listView1, checkCode_value, listview_check_value, i); //赋值config config = new My_config { Command_config = my_Config.Command_config, Serial_config = my_Config.Serial_config, Command_Name = my_Config.Command_Name, List_Name = my_Config.List_Name, List_Value = my_Config.List_Value, CheckCode_value = checkCode_value }; //把config烧写进json文件 WriteFile(config); //调用WriteFile方法把配置写入json文件中 }
/// <summary> /// 删除最新的1列数据并保存在json中 /// </summary> private void Json_clean() { My_config my_Config = ReadFile(); var config = new My_config(); var list_Name = new List_format(); var list_Value = new List_format(); var checkCode_value = new List_format(); //listview 列表表头 list_Name = Clean_config_Columns_listView(this.listView1, list_Name, listview_name); //listview 列表表值 list_Value = Clean_config_Value_listView(this.listView1, list_Value, listview_value); //校验内容 checkCode_value = Clean_check_value(this.listView1, checkCode_value, listview_check_value); //赋值config config = new My_config { Command_config = my_Config.Command_config, Serial_config = my_Config.Serial_config, Command_Name = my_Config.Command_Name, List_Name = list_Name, List_Value = list_Value, CheckCode_value = checkCode_value }; //把config烧写进json文件 WriteFile(config); //调用WriteFile方法把配置写入json文件中 for (int i = 0; i < listview_check_value.Count; i++) { if (listview_check_value[i] != null) { this.listView1.Items[0].SubItems[i + 1].BackColor = Color.Aqua; } } }
/// <summary> /// 把新配置写入json文件中 /// </summary> private void Json_write() { My_config my_Config = ReadFile(); var config = new My_config(); var command_config = new Command_config(); var FrameHead = new General_format(); var FrameTail = new General_format(); var FrameData = new General_format(); var FrameCommand = new General_format(); var FrameOne = new General_format(); var FramTwo = new General_format(); var FramThree = new General_format(); var command_name = new General_format(); var list_Name = new List_format(); var list_Value = new List_format(); //listview 列表表头 list_Name = Add_config_Columns_listView(this.listView1, list_Name, listview_name, this.comboBox1); //listview 列表表值 list_Value = Add_config_Value_listView(this.listView1, list_Value, listview_value, this.comboBox2); //选项名 //根据实际个数来写入配置:选项名称 中 switch (comboBox1.SelectedIndex) { //选择“帧头”选项时 case 1: FrameHead = Add_config_cmb(comboBox2, FrameHead, list_FrameHead); command_config = new Command_config { strFrameHead = FrameHead, strFrameTail = my_Config.Command_config.strFrameTail, strFrameCheckCode = my_Config.Command_config.strFrameCheckCode, intFrameSequential = my_Config.Command_config.intFrameSequential, strFrameData = my_Config.Command_config.strFrameData, strFrameCommand = my_Config.Command_config.strFrameCommand, strFrameOne = my_Config.Command_config.strFrameOne, strFramTwo = my_Config.Command_config.strFramTwo, strFramThree = my_Config.Command_config.strFramThree }; break; //选择“时序”的时候,显示框内容就是时序位 case 2: command_config = new Command_config { strFrameHead = my_Config.Command_config.strFrameHead, strFrameTail = my_Config.Command_config.strFrameTail, strFrameCheckCode = my_Config.Command_config.strFrameCheckCode, intFrameSequential = this.comboBox2.Text, strFrameData = my_Config.Command_config.strFrameData, strFrameCommand = my_Config.Command_config.strFrameCommand, strFrameOne = my_Config.Command_config.strFrameOne, strFramTwo = my_Config.Command_config.strFramTwo, strFramThree = my_Config.Command_config.strFramThree }; break; //选择“命令码”的时候 case 3: FrameCommand = Add_config_cmb(comboBox2, FrameCommand, list_FrameCommand); command_config = new Command_config { strFrameHead = my_Config.Command_config.strFrameHead, strFrameTail = my_Config.Command_config.strFrameTail, strFrameCheckCode = my_Config.Command_config.strFrameCheckCode, intFrameSequential = my_Config.Command_config.intFrameSequential, strFrameData = my_Config.Command_config.strFrameData, strFrameCommand = FrameCommand, strFrameOne = my_Config.Command_config.strFrameOne, strFramTwo = my_Config.Command_config.strFramTwo, strFramThree = my_Config.Command_config.strFramThree }; break; //选择“数据”的时候 case 4: FrameData = Add_config_cmb(comboBox2, FrameData, list_FrameData); command_config = new Command_config { strFrameHead = my_Config.Command_config.strFrameHead, strFrameTail = my_Config.Command_config.strFrameTail, strFrameCheckCode = my_Config.Command_config.strFrameCheckCode, intFrameSequential = my_Config.Command_config.intFrameSequential, strFrameData = FrameData, strFrameCommand = my_Config.Command_config.strFrameCommand, strFrameOne = my_Config.Command_config.strFrameOne, strFramTwo = my_Config.Command_config.strFramTwo, strFramThree = my_Config.Command_config.strFramThree }; break; //选择“校验”的时候 case 5: command_config = new Command_config { strFrameHead = my_Config.Command_config.strFrameHead, strFrameTail = my_Config.Command_config.strFrameTail, strFrameCheckCode = comboBox2.Text, intFrameSequential = my_Config.Command_config.intFrameSequential, strFrameData = my_Config.Command_config.strFrameData, strFrameCommand = my_Config.Command_config.strFrameCommand, strFrameOne = my_Config.Command_config.strFrameOne, strFramTwo = my_Config.Command_config.strFramTwo, strFramThree = my_Config.Command_config.strFramThree }; break; //选择“帧尾”的时候 case 6: FrameTail = Add_config_cmb(comboBox2, FrameTail, list_FrameTail); command_config = new Command_config { strFrameHead = my_Config.Command_config.strFrameHead, strFrameTail = FrameTail, strFrameCheckCode = my_Config.Command_config.strFrameCheckCode, intFrameSequential = my_Config.Command_config.intFrameSequential, strFrameData = my_Config.Command_config.strFrameData, strFrameCommand = my_Config.Command_config.strFrameCommand, strFrameOne = my_Config.Command_config.strFrameOne, strFramTwo = my_Config.Command_config.strFramTwo, strFramThree = my_Config.Command_config.strFramThree }; break; //选择“预留1”的时候 case 7: FrameOne = Add_config_cmb(comboBox2, FrameOne, list_FrameOne); command_config = new Command_config { strFrameHead = my_Config.Command_config.strFrameHead, strFrameTail = my_Config.Command_config.strFrameTail, strFrameCheckCode = my_Config.Command_config.strFrameCheckCode, intFrameSequential = my_Config.Command_config.intFrameSequential, strFrameData = my_Config.Command_config.strFrameData, strFrameCommand = my_Config.Command_config.strFrameCommand, strFrameOne = FrameOne, strFramTwo = my_Config.Command_config.strFramTwo, strFramThree = my_Config.Command_config.strFramThree }; break; //选择“预留2”的时候 case 8: FramTwo = Add_config_cmb(comboBox2, FramTwo, list_FrameTwo); command_config = new Command_config { strFrameHead = my_Config.Command_config.strFrameHead, strFrameTail = my_Config.Command_config.strFrameTail, strFrameCheckCode = my_Config.Command_config.strFrameCheckCode, intFrameSequential = my_Config.Command_config.intFrameSequential, strFrameData = my_Config.Command_config.strFrameData, strFrameCommand = my_Config.Command_config.strFrameCommand, strFrameOne = my_Config.Command_config.strFrameOne, strFramTwo = FramTwo, strFramThree = my_Config.Command_config.strFramThree }; break; //选择“预留3”的时候 case 9: FramThree = Add_config_cmb(comboBox2, FramThree, list_FramThree); command_config = new Command_config { strFrameHead = my_Config.Command_config.strFrameHead, strFrameTail = my_Config.Command_config.strFrameTail, strFrameCheckCode = my_Config.Command_config.strFrameCheckCode, intFrameSequential = my_Config.Command_config.intFrameSequential, strFrameData = my_Config.Command_config.strFrameData, strFrameCommand = my_Config.Command_config.strFrameCommand, strFrameOne = my_Config.Command_config.strFrameOne, strFramTwo = my_Config.Command_config.strFramTwo, strFramThree = FramThree }; break; } //选项名称 command_name = Add_config_cmb(comboBox1, command_name, list_name, 6); //赋值config config = new My_config { Command_config = command_config, Serial_config = my_Config.Serial_config, Command_Name = command_name, List_Name = list_Name, List_Value = list_Value, CheckCode_value = my_Config.CheckCode_value }; //把config烧写进json文件 if (!WriteFile(config)) //调用WriteFile方法把配置写入json文件中 { MessageBox.Show("保存失败", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } //写完数据后显示已经标记的颜色 for (int i = 0; i < listview_check_value.Count; i++) { if (listview_check_value[i] != null) { this.listView1.Items[0].SubItems[i + 1].BackColor = Color.Aqua; } } }
/// <summary> /// 返回删除校验项的List_format,并且listview显示选择的颜色 /// </summary> /// <param name="lv"></param> /// <param name="list_Format"></param> /// <param name="list"></param> /// <returns></returns> private static List_format Clean_check_value(ListView lv, List_format list_Format, List <string> list) { switch (lv.Columns.Count) { case 10: list[9] = null; break; case 9: list[8] = null; break; case 8: list[7] = null; break; case 7: list[6] = null; break; case 6: list[5] = null; break; case 5: list[4] = null; break; case 4: list[3] = null; break; case 3: list[2] = null; break; case 2: list[1] = null; break; case 1: list[0] = null; break; case 0: break; } list_Format = new List_format { one = list[0], two = list[1], three = list[2], four = list[3], five = list[4], six = list[5], seven = list[6], eight = list[7], nine = list[8], ten = list[9] }; return(list_Format); }
/// <summary> /// 返回添加表值后的List_format,并且listview显示表值 /// </summary> /// <param name="lv">要处理的listview</param> /// <param name="list_Format">被返回的数据结构</param> /// <param name="list">被添加的list</param> /// <param name="box">被处理的combox</param> /// <returns></returns> private static List_format Add_config_Value_listView(ListView lv, List_format list_Format, List <string> list, ComboBox box) { switch (lv.Columns.Count) { case 1: list[0] = box.Text; break; case 2: list[1] = box.Text; break; case 3: list[2] = box.Text; break; case 4: list[3] = box.Text; break; case 5: list[4] = box.Text; break; case 6: list[5] = box.Text; break; case 7: list[6] = box.Text; break; case 8: list[7] = box.Text; break; case 9: list[8] = box.Text; break; case 10: list[9] = box.Text; break; case 11: list[10] = box.Text; break; } Listview_value_add(lv, list); list_Format = new List_format { one = list[1], two = list[2], three = list[3], four = list[4], five = list[5], six = list[6], seven = list[7], eight = list[8], nine = list[9], ten = list[10] }; return(list_Format); }