Beispiel #1
0
        private bool SaveKnxUiProject(string fileName)
        {
            Cursor = Cursors.WaitCursor;
            bool result = false;

            try
            {
                VersionStorage.Save();      // 保存项目文件的版本信息。
                this.ucdo.SaveNode();       // 保存界面到JSON文件
                GroupAddressStorage.Save(); // 保存组地址到JSON文件

                // 是否指定了项目文件名
                if (fileName == MyConst.DefaultKnxUiProjectName)
                {
                    var myDialog = new SaveFileDialog();
                    myDialog.InitialDirectory = MyCache.DefaultKnxProjectFolder;
                    myDialog.OverwritePrompt  = true;
                    myDialog.FileName         = MyConst.DefaultKnxUiProjectName;
                    myDialog.DefaultExt       = MyConst.KnxUiEditorFileExt;
                    myDialog.Filter           = KnxFilter;
                    myDialog.FilterIndex      = 1;
                    myDialog.RestoreDirectory = true;

                    var myResult = myDialog.ShowDialog(this);

                    if (DialogResult.OK == myResult)
                    {
                        ProjectFile = myDialog.FileName;
                        ZipProject(this.ProjectFile);
                        result = true;
                    }
                }
                else
                {
                    ZipProject(this.ProjectFile);
                    result = true;
                }
            }
            catch (Exception ex)
            {
                string errorMsg = ResourceMng.GetString("Message5") + " " + "exception message: " + ex.Message;
                MessageBox.Show(errorMsg, ResourceMng.GetString("Message6"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                Log.Error(errorMsg + LogHelper.Format(ex));
            }
            finally
            {
                Cursor = Cursors.Default;
            }

            if (result) // 保存成功
            {
                ProjectSaved();
            }

            return(result);
        }
Beispiel #2
0
        private void tsmiSaveAs_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter           = KnxFilter;
            saveFileDialog.FilterIndex      = 0;
            saveFileDialog.RestoreDirectory = true;

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                if (!string.IsNullOrEmpty(saveFileDialog.FileName))
                {
                    Cursor = Cursors.WaitCursor;

                    try
                    {
                        VersionStorage.Save();      // 保存项目文件的版本信息。
                        this.ucdo.SaveNode();       // 保存界面到JSON文件
                        GroupAddressStorage.Save(); // 保存组地址到JSON文件

                        ZipProject(saveFileDialog.FileName);

                        ProjectSaved();
                    }
                    catch (Exception ex)
                    {
                        string errorMsg = ResourceMng.GetString("Message5") + " " + "exception message: " + ex.Message;
                        MessageBox.Show(errorMsg, ResourceMng.GetString("Message6"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Log.Error(errorMsg + LogHelper.Format(ex));
                    }

                    finally
                    {
                        Cursor = Cursors.Default;
                    }
                }
            }
        }