private void BtnCreate_Click(object sender, EventArgs e) { if (ListTemplate.FocusedItem == null) { MessageBox.Show("��ѡ��ģ��", "Ӧ�ó�����ʾ", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string path = CmbLocation.Text; if (!path.EndsWith("\\")) path += "\\"; string projectName = TxtProjectName.Text; if (path == string.Empty) { MessageBox.Show("��������Ŀ����·��", "Ӧ�ó�����ʾ", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string tmp = Path.Combine(path, projectName); if (Directory.Exists(tmp)) { MessageBox.Show(string.Format("�������ļ��С�{0}�����Ѵ�����һ����Ŀ���������������Ŀ", tmp), "Ӧ�ó�����ʾ", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } projectInfo = new ProjectInfo(); projectInfo.CreateDate = DateTime.Now; projectInfo.Name = projectName; projectInfo.SolutionName = TxtSolutionName.Text; projectInfo.SolutionPath = path; projectInfo.TemplatePath = Path.Combine(TEMPLATE_PATH, ListTemplate.FocusedItem.Text); this.DialogResult = DialogResult.OK; this.Close(); }
/// <summary> /// 新建项目 /// </summary> private void NewMenuItem_Click(object sender, EventArgs e) { CreateProject createProject = new CreateProject(); DialogResult dr = createProject.ShowDialog(); if (dr == DialogResult.Cancel) return; CurrentProject = createProject.Projct; ProjectInfo.Save(CurrentProject); }
private void OpenMenuItem_Click(object sender, EventArgs e) { DialogResult dr = openFileDialog.ShowDialog(); if (dr == DialogResult.Cancel) return; string file = openFileDialog.FileName; try { ProjectInfo info = XmlSerialization.DeSerializeObject(file, typeof(ProjectInfo)) as ProjectInfo; if (info != null) { CurrentProject = info; projectfrm.CurrentProject = CurrentProject; projectfrm.Initi(CurrentProject.Name); try { CurrentConnection.ServerAddress = CurrentProject.ServerAddress; CurrentConnection.UserName = CurrentProject.UserName; CurrentConnection.Password = CurrentProject.Password; CurrentConnection.IsWindowAuth = CurrentProject.WindowsAudhority; databasefrm.CheckSavedPassword(); } catch { } string path = Path.Combine(CurrentProject.SolutionPath, CurrentProject.Name); path = Path.Combine(path, CurrentProject.Name); string[] dirs = Directory.GetDirectories(path); foreach (string dir in dirs) { string[] files = Directory.GetFiles(dir, "*.cs"); List<CodeInfo> codeInfoList = new List<CodeInfo>(); string dirName = Path.GetFileName(dir); foreach (string tmp in files) { CodeInfo tmpInfo = new CodeInfo(); tmpInfo.Code = File.ReadAllText(tmp, Encoding.UTF8); tmpInfo.FileName = Path.GetFileName(tmp).Replace(".cs", ""); tmpInfo.Template = dirName; codeInfoList.Add(tmpInfo); } projectfrm.AddCodeFiles(dirName, codeInfoList); } } } catch { MessageBox.Show("文件打开失败", "应用程序提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static bool Save(ProjectInfo info) { string file = Path.Combine(info.solutionPath, info.name); if (!Directory.Exists(file)) { Directory.CreateDirectory(file); } file = Path.Combine(file, info.name + ".cgp"); try { XmlSerialization.SerializeObject(file, info); return true; } catch { return false; } }