using DevExpress.XtraEditors;
|
using System;
|
using System.Windows.Forms;
|
|
namespace IStation.WinFrmUI.Basic
|
{
|
public class ProjectHelper
|
{
|
/// <summary>
|
/// 加载项目
|
/// </summary>
|
public static bool LoadProject(long projectId)
|
{
|
WaitFrmHelper.ShowWaitForm("正在加载项目,请稍候...");
|
var result = new BLL.Project().GetByID(projectId);
|
WaitFrmHelper.HideWaitForm();
|
if (result == null)
|
{
|
XtraMessageBox.Show("未检测到项目!");
|
return false;
|
}
|
Settings.Project.ID = projectId;
|
Settings.Save();
|
BLL.BasicDb.InitTables(projectId);
|
return true;
|
}
|
|
/// <summary>
|
/// 导入项目
|
/// </summary>
|
public static long ImportProject(string path)
|
{
|
WaitFrmHelper.ShowWaitForm("正在导入项目,请稍候...");
|
var projectId = new BLL.Project().Import(path, out string msg);
|
WaitFrmHelper.HideWaitForm();
|
if (projectId < 1)
|
{
|
XtraMessageBox.Show($"导入失败!\r\n错误:{msg}");
|
return default;
|
}
|
return projectId;
|
}
|
|
/// <summary>
|
/// 获取打开项目路径
|
/// </summary>
|
public static string GetOpenProjectPath()
|
{
|
var dlg = new OpenFileDialog();
|
dlg.Title = "项目文件";
|
dlg.Filter = "历史数据|*" + Settings.File.ProjectSuffix;
|
dlg.AutoUpgradeEnabled = true;
|
dlg.ShowDialog();
|
return dlg.FileName;
|
}
|
|
/// <summary>
|
/// 另存为
|
/// </summary>
|
public static bool OtherSaveProject(long projectId)
|
{
|
var model = new BLL.Project().GetByID(projectId);
|
if (model == null)
|
{
|
XtraMessageBox.Show("获取项目信息失败");
|
return false;
|
}
|
var dlg = new SaveFileDialog();
|
dlg.Title = "另存为";
|
dlg.Filter = "历史数据|*" + Settings.File.ProjectSuffix;
|
dlg.AddExtension = true;
|
dlg.FileName = model.Name;
|
if (dlg.ShowDialog() == DialogResult.OK)
|
{
|
WaitFrmHelper.ShowWaitForm("正在导出......");
|
var result = new BLL.Project().Export(projectId, dlg.FileName, out string msg);
|
if (!result)
|
{
|
XtraMessageBox.Show($"另存为失败!\r\n错误:{msg}");
|
return false;
|
}
|
WaitFrmHelper.HideWaitForm();
|
return true;
|
}
|
return false;
|
}
|
|
/// <summary>
|
/// 关闭项目
|
/// </summary>
|
public static bool CloseProject()
|
{
|
if (XtraMessageBox.Show("是否关闭程序?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
|
{
|
return true;
|
}
|
var bll = new BLL.Project();
|
var project = bll.GetByID(Settings.Project.ID);
|
project.UpdateTime = DateTime.Now;
|
bll.Update(project);
|
Settings.Save();
|
return false;
|
}
|
}
|
}
|