Shuxia Ning
2025-02-13 2f1cbec203dcff25df7a5c2b51b13ec558f2c3db
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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;
        }
    }
}