private void ProjectConfirm_Click(object sender, EventArgs e) { if (ProjectPath.Trim() != "" && ProjectName.Trim() != "") { Directory.CreateDirectory(ProjectPath.Trim() + "\\" + ProjectName.Trim()); StreamWriter sw = new StreamWriter(ProjectPath.Trim() + "\\" + ProjectName.Trim() + "\\ProjectTestConfig.json"); Global.ResultConfig rc = new Global.ResultConfig(); rc.projectName = ProjectName.Trim(); string str = JsonHelper.SerializeObject(rc); //String str = "##ProjectName=" + ProjectName.Trim() + "\r\n"; sw.Write(str); sw.Close(); mw.SetProjectState(ProjectName); this.Close(); } else { MessageBox.Show("存储路径错误,请检查后点击新建按钮"); mw.SetProjectState("未加载"); } }
private void OpenProject_Click(object sender, EventArgs e) { if (FindProject.ShowDialog() == DialogResult.OK) { FileInfo fi = new FileInfo(FindProject.SelectedPath + "\\ProjectTestConfig.json"); if (fi.Exists) { StreamReader sr = new StreamReader(FindProject.SelectedPath + "\\ProjectTestConfig.json"); string ConfigStr = sr.ReadToEnd(); sr.Close(); ResultConfig rc = JsonHelper.DeserializeJsonToObject <ResultConfig>(ConfigStr); Project.ProjectName = rc.projectName; Project.ProjectPath = FindProject.SelectedPath.Replace("\\" + Project.ProjectName, ""); projectStatus.Text = Project.ProjectName; string CaseName = ""; string Result = ""; foreach (var item in rc.result) { CaseName = ""; Result = ""; CaseName = item.Key; Result = item.Value; if (CaseName != "") { bool flag = false; foreach (TreeNode tn in tvTestCase.Nodes) { if (tn.Nodes.Count > 0) { foreach (TreeNode tnchild in tn.Nodes) { if (tnchild.Text.Contains(CaseName)) { tnchild.ImageIndex = -1; tnchild.SelectedImageIndex = -1; tnchild.ImageIndex = Result == "PASS" ? 1 : 2; tnchild.SelectedImageIndex = Result == "PASS" ? 1 : 2; flag = true; break; } } if (flag) { break; } } } } } } else { DialogResult dr = MetroMessageBox.Show(this, "配置文件不存在,是否新建", "提示", MessageBoxButtons.YesNo); if (dr == DialogResult.Yes) { using (FileStream fs = new FileStream(FindProject.SelectedPath + "\\ProjectTestConfig.json", FileMode.Create, FileAccess.ReadWrite)) { using (StreamWriter sw = new StreamWriter(fs)) { Global.ResultConfig rc = new Global.ResultConfig(); rc.projectName = FindProject.SelectedPath.Substring(FindProject.SelectedPath.LastIndexOf("\\") + 1, FindProject.SelectedPath.Length - FindProject.SelectedPath.LastIndexOf("\\") - 1); string str = JsonHelper.SerializeObject(rc); sw.Write(str); sw.Close(); } } } } } }