Files
easySif/mainProgram/NewProjectWindow.cs

165 lines
5.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Threading;
namespace mainProgram
{
//子窗口向父窗口传递参数https://www.cnblogs.com/xcong/p/3386085.html
public delegate void transferProjectManagerDelegate(ProjectManager value);//申明委托
public partial class NewProjectWindow : Form
{
public NewProjectWindow()
{
InitializeComponent();
}
public event transferProjectManagerDelegate TransferEvent;//申明事件
private void CreateProjectBtn_Click(object sender, EventArgs e)
{
//获取数据
//string currPath = Application.StartupPath;
string dataPath = DataPathTextBox.Text;
string projectPath = ProjectPathTextBox.Text;
string calFilePath = CalFilePathTextBox.Text;
//当创建工程时,工程文件夹必须为空
DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(projectPath));
FileSystemInfo[] fileinfo = dir.GetFileSystemInfos();
if (fileinfo.Length != 0)
{
MessageBox.Show(this, "工程文件夹中有内容", "提示");
return;
}
if (dataPath != null && dataPath.Length == 0)
{
MessageBox.Show(this, "数据文件夹路径不能为空", "提示");
return;
}
if (projectPath != null && projectPath.Length == 0)
{
MessageBox.Show(this, "工程路径不能为空", "提示");
return;
}
if (calFilePath != null && calFilePath.Length == 0)
{
MessageBox.Show(this, "定标路径不能为空", "提示");
return;
}
//创建工程
ProjectManager projectManager = new ProjectManager(projectPath);
int value = projectManager.CreateProject(calFilePath, dataPath);
switch (value)
{
case 0:
TransferEvent(projectManager);//触发事件
MessageBox.Show(this, "工程创建成功!", "提示");
this.DialogResult = DialogResult.OK;
Close();//创建工程完成后,关闭窗口
break;
case 1:
MessageBox.Show(this, "定标文件夹有错!", "提示");
break;
case 2:
MessageBox.Show(this, "数据文件夹有错!", "提示");
break;
case 3:
MessageBox.Show(this, "工程路径有错!", "提示");
break;
default: /* 可选的 */
break;
}
}
private void SelectDataPathBtn_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.Description = "请选择数据所在文件夹";
if (dialog.ShowDialog() == DialogResult.OK)
{
if (string.IsNullOrEmpty(dialog.SelectedPath))
{
MessageBox.Show(this, "文件夹路径不能为空", "提示");
return;
}
string savePath = dialog.SelectedPath;
DataPathTextBox.Text = savePath;
}
}
private void SelectProjectPathBtn_Click(object sender, EventArgs e)
{
//FolderBrowserDialog dialog = new FolderBrowserDialog();
//dialog.Description = "请选择工程文件夹";
//if (dialog.ShowDialog() == DialogResult.OK)
//{
// if (string.IsNullOrEmpty(dialog.SelectedPath))
// {
// MessageBox.Show(this, "文件夹路径不能为空", "提示");
// return;
// }
// string savePath = dialog.SelectedPath;
// ProjectPathTextBox.Text = savePath;
//}
OpenFileDialog dialog = new OpenFileDialog();
dialog.CheckFileExists = false; //设置不弹出警告
//dialog.Multiselect = true;//该值确定是否可以选择多个文件
dialog.Title = "请输入工程名";
dialog.Filter = "所有文件(*.*)|*.*";
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string filePath = dialog.FileName;
filePath = filePath + ".EasySif";
ProjectPathTextBox.Text = filePath;
}
}
private void Cancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
Close();
}
private void SelectCalFilePathBtn_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.Description = "请选择定标文件夹";
if (dialog.ShowDialog() == DialogResult.OK)
{
if (string.IsNullOrEmpty(dialog.SelectedPath))
{
MessageBox.Show(this, "文件夹路径不能为空", "提示");
return;
}
string savePath = dialog.SelectedPath;
CalFilePathTextBox.Text = savePath;
}
}
}
}