/// <summary> /// 另存新檔 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSaveAs_Click(object sender, EventArgs e) { //取得使用者輸入路徑 Filepath = GetUserInputFilePath(); //若路徑為空白則跳出 if (string.IsNullOrEmpty(Filepath)) return; #region 讓使用者輸入密碼確認存檔 frmPasspordInput PasswordInput = new frmPasspordInput(Password, "請設定排課檔案開啟密碼",true); if (PasswordInput.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Password = PasswordInput.Password; schLocal.SaveByBase64(Filepath, Password); } #endregion }
/// <summary> /// 儲存檔案 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, EventArgs e) { //若預設儲存路徑不存在,則讓使用者選取路徑 if (string.IsNullOrEmpty(Filepath)) { Filepath = GetUserInputFilePath(); if (string.IsNullOrEmpty(Filepath)) return; } //若密碼不存在,則讓使用者輸入密碼;若密碼沒有值,則將路徑清空 if (string.IsNullOrEmpty(Password)) { frmPasspordInput PasswordInput = new frmPasspordInput(Password, "請設定排課檔案開啟密碼",true); if (PasswordInput.ShowDialog() == System.Windows.Forms.DialogResult.OK) Password = PasswordInput.Password; else Filepath = string.Empty; } //若路徑及密碼不為空白才儲存檔案 if (!string.IsNullOrEmpty(Filepath) && !string.IsNullOrEmpty(Password)) schLocal.SaveByBase64(Filepath, Password); }
/// <summary> /// 開啟舊檔 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnOpen_Click(object sender, EventArgs e) { string vFilepath = string.Empty; #region 開啟檔案 OpenFileDialog dlgCommonDialog = new OpenFileDialog(); dlgCommonDialog.InitialDirectory = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); dlgCommonDialog.Filter = "(*.sch)|*.sch"; DialogResult userClickedOK = dlgCommonDialog.ShowDialog(); #endregion #region 判斷使用者是否按取消,或檔案長度為0則離開 if (userClickedOK == System.Windows.Forms.DialogResult.Cancel) return; if (dlgCommonDialog.FileName.Length == 0) return; #endregion #region 實際開啟排課資料 vFilepath = dlgCommonDialog.FileName; try { frmPasspordInput PasswordInput = new frmPasspordInput(string.Empty, "請輸入排課檔案開啟密碼",false); if (PasswordInput.ShowDialog() == System.Windows.Forms.DialogResult.OK) { //開啟時將使用者的路徑及密碼儲存 Password = PasswordInput.Password; Filepath = vFilepath; schLocal.OpenByBase64(vFilepath,Password); LoadResourceList(); } } catch (Exception ve) { MessageBox.Show(ve.Message); } #endregion }