private void AddProjectButton_Click(object sender, EventArgs e) { ProjectDialogue dialogue = new ProjectDialogue(true); if (dialogue.ShowDialog(this) == DialogResult.OK && dialogue.NewInfo != null) { StreamReader sr = null; StreamWriter sw = null; string content = null; string line; try { sr = File.OpenText("projects.dat"); while ((line = sr.ReadLine()) != null) content += (line + "\r\n"); content += "#\r\n"; content += dialogue.NewInfo.Info["number"] + "\r\n"; content += dialogue.NewInfo.Info["name"] + "\r\n"; content += dialogue.NewInfo.Info["beginTime"] + "\r\n"; content += dialogue.NewInfo.Info["endTime"] + "\r\n"; content += dialogue.NewInfo.Info["manager"] + "\r\n"; content += dialogue.NewInfo.Info["members"] + "\r\n\r\n"; } catch (FileNotFoundException fe) { Console.WriteLine(fe.StackTrace); MessageBox.Show("读取项目数据信息失败!", "提示"); return; } finally { if (sr != null) sr.Close(); } try { sw = File.CreateText("projects.dat"); sw.Write(content); } catch (FileNotFoundException fe) { Console.WriteLine(fe.StackTrace); MessageBox.Show("写入项目数据信息失败!", "提示"); return; } finally { if (sw != null) sw.Close(); } projectInfoList.Add(dialogue.NewInfo); bs.ResetBindings(true); content = ""; try { sr = File.OpenText("plans.dat"); while ((line = sr.ReadLine()) != null) content += (line + "\r\n"); content += ("#" + dialogue.NewInfo.Info["name"] + "\r\n"); foreach(string member in dialogue.NewInfo.Info["members"].Split(new char[] { '|' })) content += (member + "\r\n" + dialogue.NewInfo.Info["beginTime"] + "\r\n" + dialogue.NewInfo.Info["endTime"] + "\r\n" + "0" + "\r\n" + "-" + "\r\n"); content += "\r\n"; } catch (FileNotFoundException fe) { Console.WriteLine(fe.StackTrace); MessageBox.Show("读取项目数据信息失败!", "提示"); return; } finally { if (sr != null) sr.Close(); } try { sw = File.CreateText("plans.dat"); sw.Write(content); } catch (FileNotFoundException fe) { Console.WriteLine(fe.StackTrace); MessageBox.Show("写入项目数据信息失败!", "提示"); return; } finally { if (sw != null) sw.Close(); } content = ""; try { sr = File.OpenText("states.dat"); while ((line = sr.ReadLine()) != null) content += (line + "\r\n"); content += ("#" + dialogue.NewInfo.Info["name"] + "\r\n"); foreach (string member in dialogue.NewInfo.Info["members"].Split(new char[] { '|' })) content += (member + "\r\n" + "-" + "\r\n" + "0" + "\r\n" + "0" + "\r\n" + "0" + "\r\n"); content += "\r\n"; } catch (FileNotFoundException fe) { Console.WriteLine(fe.StackTrace); MessageBox.Show("读取项目数据信息失败!", "提示"); return; } finally { if (sr != null) sr.Close(); } try { sw = File.CreateText("states.dat"); sw.Write(content); } catch (FileNotFoundException fe) { Console.WriteLine(fe.StackTrace); MessageBox.Show("写入项目数据信息失败!", "提示"); return; } finally { if (sw != null) sw.Close(); } content = ""; try { sr = File.OpenText("reports.dat"); while ((line = sr.ReadLine()) != null) content += (line + "\r\n"); content += ("#" + dialogue.NewInfo.Info["name"] + "\r\n\r\n"); } catch (FileNotFoundException fe) { Console.WriteLine(fe.StackTrace); MessageBox.Show("读取项目数据信息失败!", "提示"); return; } finally { if (sr != null) sr.Close(); } try { sw = File.CreateText("reports.dat"); sw.Write(content); } catch (FileNotFoundException fe) { Console.WriteLine(fe.StackTrace); MessageBox.Show("写入项目数据信息失败!", "提示"); return; } finally { if (sw != null) sw.Close(); } content = ""; try { sr = File.OpenText("warning.dat"); while ((line = sr.ReadLine()) != null) content += (line + "\r\n"); content += ("#" + dialogue.NewInfo.Info["name"] + "\r\n\r\n"); } catch (FileNotFoundException fe) { Console.WriteLine(fe.StackTrace); MessageBox.Show("读取项目数据信息失败!", "提示"); return; } finally { if (sr != null) sr.Close(); } try { sw = File.CreateText("warning.dat"); sw.Write(content); } catch (FileNotFoundException fe) { Console.WriteLine(fe.StackTrace); MessageBox.Show("写入项目数据信息失败!", "提示"); return; } finally { if (sw != null) sw.Close(); } } }
private void EditInfoButton_Click(object sender, EventArgs e) { if (projectsListBox.SelectedItem == null) { MessageBox.Show("请选择要编辑的项目!", "提示"); } else { ProjectDialogue dialogue = new ProjectDialogue(false); if (dialogue.ShowDialog(this) == DialogResult.OK) { ProjectInfo project = (ProjectInfo)projectsListBox.SelectedItem; StreamReader sr = null; StreamWriter sw = null; string content = null; string tmp; string tmp2; string line; try { sr = File.OpenText("projects.dat"); while ((line = sr.ReadLine()) != null) { content += (line + "\r\n"); if (line.StartsWith("#")) { tmp = sr.ReadLine() + "\r\n"; if((tmp2 = sr.ReadLine()).Equals(project.Name)) { content += project.Info["number"] + "\r\n" + project.Info["name"] + "\r\n" + project.Info["beginTime"] + "\r\n" + project.Info["endTime"] + "\r\n" + project.Info["manager"] + "\r\n" + project.Info["members"] + "\r\n"; for (int i = 0; i < 4; i++) sr.ReadLine(); } else { content += (tmp + tmp2 + "\r\n" + sr.ReadLine() + "\r\n" + sr.ReadLine() + "\r\n" + sr.ReadLine() + "\r\n" + sr.ReadLine() + "\r\n"); } } } } catch (FileNotFoundException fe) { Console.WriteLine(fe.StackTrace); MessageBox.Show("读取项目数据信息失败!", "提示"); return; } finally { if (sr != null) sr.Close(); } try { sw = File.CreateText("projects.dat"); sw.Write(content); } catch (FileNotFoundException fe) { Console.WriteLine(fe.StackTrace); MessageBox.Show("写入项目数据信息失败!", "提示"); return; } finally { if (sw != null) sw.Close(); } bs.ResetBindings(true); ProjectsListBox_SelectedIndexChanged(null, null); content = ""; tmp = ""; string[] members = project.Info["members"].Split(new char[] {'|'}); bool[] flag = new bool[members.Length]; bool isVisited; try { sr = File.OpenText("plans.dat"); while ((line = sr.ReadLine()) != null) { content += (line + "\r\n"); if (line.StartsWith("#") && line.Split(new char[] { '#' })[1].Equals(project.Name)) { while ((tmp = sr.ReadLine()) != null && !tmp.Equals("")) { isVisited = false; for(int i = 0; i < members.Length; i++) if (members[i].Equals(tmp)) { content += (tmp + "\r\n" + sr.ReadLine() + "\r\n" + sr.ReadLine() + "\r\n" + sr.ReadLine() + "\r\n" + sr.ReadLine() + "\r\n"); flag[i] = true; isVisited = true; break; } if (isVisited == false) for (int i = 0; i < 4; i++) sr.ReadLine(); } for (int i = 0; i < members.Length; i++) { if(flag[i] == false) { content += (members[i] + "\r\n" + project.Info["beginTime"] + "\r\n" + project.Info["endTime"] + "\r\n" + "0" + "\r\n" + "-" + "\r\n"); } } content += "\r\n"; } } } catch (FileNotFoundException fe) { Console.WriteLine(fe.StackTrace); MessageBox.Show("读取项目数据信息失败!", "提示"); return; } finally { if (sr != null) sr.Close(); } try { sw = File.CreateText("plans.dat"); sw.Write(content); } catch (FileNotFoundException fe) { Console.WriteLine(fe.StackTrace); MessageBox.Show("写入项目数据信息失败!", "提示"); return; } finally { if (sw != null) sw.Close(); } content = ""; tmp = ""; for (int i = 0; i < flag.Length; i++) flag[i] = false; try { sr = File.OpenText("states.dat"); while ((line = sr.ReadLine()) != null) { content += (line + "\r\n"); if (line.StartsWith("#") && line.Split(new char[] { '#' })[1].Equals(project.Name)) { while ((tmp = sr.ReadLine()) != null && !tmp.Equals("")) { isVisited = false; for (int i = 0; i < members.Length; i++) if (members[i].Equals(tmp)) { content += (tmp + "\r\n" + sr.ReadLine() + "\r\n" + sr.ReadLine() + "\r\n" + sr.ReadLine() + "\r\n" + sr.ReadLine() + "\r\n"); flag[i] = true; isVisited = true; break; } if (isVisited == false) for (int i = 0; i < 4; i++) sr.ReadLine(); } for (int i = 0; i < members.Length; i++) { if (flag[i] == false) { content += (members[i] + "\r\n" + "-" + "\r\n" + "0" + "\r\n" + "0" + "\r\n" + "0" + "\r\n"); } } content += "\r\n"; } } } catch (FileNotFoundException fe) { Console.WriteLine(fe.StackTrace); MessageBox.Show("读取项目数据信息失败!", "提示"); return; } finally { if (sr != null) sr.Close(); } try { sw = File.CreateText("states.dat"); sw.Write(content); } catch (FileNotFoundException fe) { Console.WriteLine(fe.StackTrace); MessageBox.Show("写入项目数据信息失败!", "提示"); return; } finally { if (sw != null) sw.Close(); } content = ""; tmp = ""; try { sr = File.OpenText("warning.dat"); while ((line = sr.ReadLine()) != null) { content += (line + "\r\n"); if (line.StartsWith("#") && line.Split(new char[] { '#' })[1].Equals(project.Name)) { while ((tmp = sr.ReadLine()) != null && !tmp.Equals("")) { for (int i = 0; i < members.Length; i++) if (members[i].Equals(tmp)) { content += tmp; break; } } content += "\r\n"; } } } catch (FileNotFoundException fe) { Console.WriteLine(fe.StackTrace); MessageBox.Show("读取项目数据信息失败!", "提示"); return; } finally { if (sr != null) sr.Close(); } try { sw = File.CreateText("warning.dat"); sw.Write(content); } catch (FileNotFoundException fe) { Console.WriteLine(fe.StackTrace); MessageBox.Show("写入项目数据信息失败!", "提示"); return; } finally { if (sw != null) sw.Close(); } // bs.ResetBindings(true); } } }