//保存配置文件 private void btnSaveGroupSet_Click(object sender, EventArgs e) { if (allData.Count() == 0) { MessageBox.Show("没有组配置文件需要保存,请检查组配置文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Title = "保存文件"; saveFileDialog.Filter = "文本文件(*.txt)|*.txt"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { FileListOperate fo = new FileListOperate(); fo.SavePath = saveFileDialog.FileName; fo.Dicts_Content = allData; try { fo.WriteConfigFile(); MessageBox.Show("保存组配置文件成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void btnNextStep_Click(object sender, EventArgs e) { FileListOperate fo = new FileListOperate(); fo.Dicts_Content = allData; bool isflag = fo.isFileExists(); if (isflag == true && allData.Count != 0) { Frm_Params fmParams = new Frm_Params(allData); fmParams.ShowDialog(); this.Close(); } else { MessageBox.Show("部分文件不存在,请重新选择!"); } }
//读取配置文件 private void btnOpenGroupSet_Click(object sender, EventArgs e) { OpenFileDialog openDialog = new OpenFileDialog(); openDialog.Title = "打开文件"; openDialog.Filter = "文本文件(*.txt)|*.txt"; if (openDialog.ShowDialog() == DialogResult.OK) { FileListOperate fo = new FileListOperate(); fo.SavePath = openDialog.FileName; fo.Dicts_Content = new List <string>(); try { if (allData.Count == 0) { lstBx1.Items.Clear(); lstBxGroup.Items.Clear(); allData = fo.ReadConfigFile(); //foreach (string dic in allData) //{ // lstBxGroup.Items.Add("第 " + (dic.Key) + " 组"); // if (dic.Key == lstBxGroup.SelectedIndex + 1) // { // for (int i = 0; i < 8; i++) // { // lstBx1.Items.Add(dic.Value[i]); // } // } //} for (int i = 0; i < allData.Count; i = i + 8) { lstBxGroup.Items.Add("第 " + (i / 8 + 1) + " 组"); } lstBxGroup.SelectedIndex = 0; } else { int count = allData.Count; List <string> dicts = fo.ReadConfigFile(); //foreach (KeyValuePair<int, List<string>> dic in dicts) //{ // allDataList.Add(dic.Key +count , dic.Value); //} //for (int i = count; i < allDataList.Count; i++) //{ // KeyValuePair<int, List<string>> dic = allDataList.ElementAt(i); // lstBxGroup.Items.Add("第 " + (dic.Key) + " 组"); // if (dic.Key== lstBxGroup.SelectedIndex + 1) // { // for (int j = 0; j < 8; j++) // { // lstBx1.Items.Add(dic.Value[j]); // } // } // lstBxGroup.SelectedIndex = 0; //} for (int i = 0; i < dicts.Count; i = i + 8) { lstBxGroup.Items.Add("第 " + ((i + count) / 8 + 1) + " 组"); } allData.AddRange(dicts); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }