private bool DeleteCatalog(AccountCatalog catalogItem)
        {
            if (catalogItem != null)
            {
                var tmpMessageBoxTitle = SafePassResource.DeletePermanentlySelectedCatalogTitle;

                var tmpCatalogService = new HuiruiSoft.Safe.Service.CatalogService();
                if (tmpCatalogService.GetChildCatalogCount(catalogItem.CatalogId) > 0)
                {
                    MessageBox.Show(string.Format(SafePassResource.DeleteSelectedCatalogErrorForNotEmpty, catalogItem.Name), tmpMessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }

                var tmpAccountService = new HuiruiSoft.Safe.Service.AccountService();
                if (tmpAccountService.GetBelongAccountCount(catalogItem.CatalogId) > 0)
                {
                    MessageBox.Show(string.Format(SafePassResource.DeleteSelectedCatalogErrorForNotEmpty, catalogItem.Name), tmpMessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
                else
                {
                    var tmpMessageBoxPrompt = SafePassResource.DeletePermanentlySelectedCatalogQuestion;
                    if (MessageBox.Show(string.Format(tmpMessageBoxPrompt, catalogItem.Name), tmpMessageBoxTitle, MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) == DialogResult.OK)
                    {
                        return(tmpCatalogService.Delete(catalogItem));
                    }
                }
            }

            return(false);
        }
        private void buttonOK_Click(object sender, System.EventArgs args)
        {
            var tmpInputErrorCaption = SafePassResource.MessageBoxCaptionInputError;

            var tmpOldPassword = this.textOldPassword.Text.Trim();
            var tmpNewPassword = this.textNewPassword.Text.Trim();

            if (tmpOldPassword != Account.CurrentAccount.Password)
            {
                this.textOldPassword.Focus();
                MessageBox.Show(SafePassResource.ChangePasswordWindowPromptPasswordIncorrect, tmpInputErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (string.IsNullOrEmpty(tmpNewPassword))
            {
                this.textNewPassword.Focus();
                MessageBox.Show(SafePassResource.ChangePasswordWindowPromptPasswordIsEmpty, tmpInputErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else if (!string.Equals(tmpNewPassword, this.textRepeatPassword.Text))
            {
                this.textRepeatPassword.Focus();
                MessageBox.Show(SafePassResource.PasswordRepeatFailed, tmpInputErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (string.Equals(tmpOldPassword, tmpNewPassword, System.StringComparison.OrdinalIgnoreCase))
            {
                this.textNewPassword.Focus();
                MessageBox.Show(SafePassResource.ChangePasswordWindowPromptSameAsOldPassword, tmpInputErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                var tmpPasswordMd5 = Md5DigestHelper.Md5Salt(tmpNewPassword, Account.CurrentAccount.UserName);

                var tmpAccountService = new HuiruiSoft.Safe.Service.AccountService();
                var tmpChangeResult   = tmpAccountService.ChangePassword(tmpPasswordMd5);
                if (tmpChangeResult)
                {
                    DataBaseConfig.Password               = tmpPasswordMd5;
                    Account.CurrentAccount.Password       = tmpNewPassword;
                    Account.CurrentAccount.PasswordStored = EncryptorHelper.DESEncrypt(Account.CurrentAccount.SecretKey, tmpPasswordMd5);

                    ApplicationConfigSerializer.SaveApplicationConfig(Program.Config);
                    MessageBox.Show(SafePassResource.ChangePasswordWindowMessageChangeSuccess, SafePassResource.Success, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.DialogResult = DialogResult.OK;
                }
            }
            catch (System.SystemException exception)
            {
                loger.Error(exception);
                MessageBox.Show(SafePassResource.ChangePasswordWindowMessageChangeFailed, SafePassResource.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 3
0
        protected override void buttonOK_Click(object sender, System.EventArgs args)
        {
            if (base.CheckInputValidity())
            {
                var tmpInputErrorCaption = SafePassResource.MessageBoxCaptionInputError;

                string tmpAccountName = this.textName.Text.Trim();
                if (string.IsNullOrEmpty(tmpAccountName))
                {
                    this.textName.Focus();
                    MessageBox.Show(SafePassResource.AccountEditorPromptNameIsEmpty, tmpInputErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else if (tmpAccountName.Length > 30)      // if(HuiruiSoft.Shared.StringHelper.GetStringByteCount(tmpAccountName) > 30)
                {
                    this.textName.Focus();
                    MessageBox.Show(SafePassResource.AccountEditorPromptNameTooLong, tmpInputErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                string tmpComment = this.textComment.Text.Trim();
                var    tmpEmail   = this.textEmail.Text.Trim();
                var    tmpMobile  = this.textMobile.Text.Trim();
                var    tmpHttpUrl = this.textURL.Text.Trim();

                var tmpPassword = this.textPassword.Text.Trim();
                if (!string.Equals(tmpPassword, this.textPwdRepeat.Text))
                {
                    this.textPwdRepeat.Focus();
                    MessageBox.Show(SafePassResource.PasswordRepeatFailed, tmpInputErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                this.currentAccount.Name       = tmpAccountName;
                this.currentAccount.URL        = this.textURL.Text.Trim();
                this.currentAccount.LoginName  = this.textLoginName.Text.Trim();
                this.currentAccount.Password   = tmpPassword;
                this.currentAccount.Email      = string.IsNullOrEmpty(tmpEmail) ? null : tmpEmail;
                this.currentAccount.URL        = string.IsNullOrEmpty(tmpHttpUrl) ? null : tmpHttpUrl;
                this.currentAccount.Mobile     = string.IsNullOrEmpty(tmpMobile) ? null : tmpMobile;
                this.currentAccount.UpdateTime = System.DateTime.Now;
                this.currentAccount.Comment    = string.IsNullOrEmpty(tmpComment) ? null : tmpComment;

                if (this.radioSecretRank0.Checked)
                {
                    currentAccount.SecretRank = SecretRank.公开;
                }
                else if (this.radioSecretRank1.Checked)
                {
                    currentAccount.SecretRank = SecretRank.秘密;
                }
                else if (this.radioSecretRank2.Checked)
                {
                    currentAccount.SecretRank = SecretRank.机密;
                }
                else if (this.radioSecretRank3.Checked)
                {
                    currentAccount.SecretRank = SecretRank.绝密;
                }
                else
                {
                    currentAccount.SecretRank = SecretRank.绝密;
                }

                this.currentAccount.Attributes.Clear();

                short order = 0;
                foreach (System.Data.DataRow tmpCurrentRow in accountDataTable.Rows)
                {
                    string attributeName  = string.Format("{0}", tmpCurrentRow[Account_Column_Name]);
                    string attributeValue = string.Format("{0}", tmpCurrentRow[Account_Column_Value]);

                    if (!string.IsNullOrEmpty(attributeName) && !string.IsNullOrEmpty(attributeValue))
                    {
                        order++;

                        var tmpAttribute = new AccountAttribute();
                        tmpAttribute.AccountId = this.currentAccount.AccountId;

                        int tmpAttributeId = -1;
                        if (tmpCurrentRow[Account_Column_Id] != System.DBNull.Value)
                        {
                            int.TryParse(string.Format("{0}", tmpCurrentRow[Account_Column_Id]), out tmpAttributeId);
                        }
                        tmpAttribute.AttributeId = tmpAttributeId;

                        tmpAttribute.Order = order;
                        tmpAttribute.Name  = attributeName;
                        tmpAttribute.Value = attributeValue;

                        if (tmpCurrentRow[Account_Column_Encrypt] != System.DBNull.Value)
                        {
                            tmpAttribute.Encrypted = System.Convert.ToBoolean(tmpCurrentRow[Account_Column_Encrypt]);
                        }

                        this.currentAccount.Attributes.Add(tmpAttribute);
                    }
                }

                try
                {
                    Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

                    var  tmpAccountService = new HuiruiSoft.Safe.Service.AccountService();
                    bool tmpUpdateResult   = tmpAccountService.UpdateAccount(this.currentAccount);
                    tmpAccountService = null;

                    Cursor.Current    = System.Windows.Forms.Cursors.Default;
                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                }
                catch (System.Exception exception)
                {
                    loger.Error(exception);
                    Cursor.Current = System.Windows.Forms.Cursors.Default;
                    MessageBox.Show(string.Format(SafePassResource.AccountEditorDialogMessageUpdateFailed, System.Environment.NewLine, exception.Message), SafePassResource.AccountEditorDialogTitleUpdateFailed, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
        }
Ejemplo n.º 4
0
        protected override void OnLoad(System.EventArgs args)
        {
            base.OnLoad(args);

            if (!base.DesignMode)
            {
                this.Visible = false;

                this.MinimizeBox          = true;
                this.MaximizeBox          = true;
                this.ShowInTaskbar        = true;
                this.StartPosition        = FormStartPosition.Manual;
                this.splitControls.Dock   = System.Windows.Forms.DockStyle.Fill;
                this.treeViewCatalog.Dock = System.Windows.Forms.DockStyle.Fill;
                this.dataGridAccount.Dock = System.Windows.Forms.DockStyle.Fill;

                var tmpScreenBounds = Screen.PrimaryScreen.Bounds;

                int tmpMinLocationX = -1 * (tmpScreenBounds.Width * 80 / 100);
                int tmpMinLocationY = -1 * (tmpScreenBounds.Height * 80 / 100);

                int tmpMinimumWidth  = tmpScreenBounds.Width * 40 / 100;
                int tmpMinimumHeight = tmpScreenBounds.Height * 40 / 100;

                var tmpAppConfig = HuiruiSoft.Safe.Program.Config;
                if (tmpAppConfig.MainWindow.X < tmpMinLocationX)
                {
                    tmpAppConfig.MainWindow.X = 0;
                }

                if (tmpAppConfig.MainWindow.X > tmpScreenBounds.Width * 90 / 100)
                {
                    tmpAppConfig.MainWindow.X = tmpScreenBounds.Width * 90 / 100;
                }

                if (tmpAppConfig.MainWindow.Y < tmpMinLocationY)
                {
                    tmpAppConfig.MainWindow.Y = 0;
                }

                if (tmpAppConfig.MainWindow.Y > tmpScreenBounds.Height * 90 / 100)
                {
                    tmpAppConfig.MainWindow.Y = tmpScreenBounds.Height * 90 / 100;
                }

                if (tmpAppConfig.MainWindow.Width < tmpMinimumWidth)
                {
                    tmpAppConfig.MainWindow.Width = tmpMinimumWidth;
                }

                if (tmpAppConfig.MainWindow.Width > tmpScreenBounds.Width)
                {
                    tmpAppConfig.MainWindow.Width = tmpScreenBounds.Width;
                }

                if (tmpAppConfig.MainWindow.Height < tmpMinimumHeight)
                {
                    tmpAppConfig.MainWindow.Height = tmpMinimumHeight;
                }

                if (tmpAppConfig.MainWindow.Height > tmpScreenBounds.Height)
                {
                    tmpAppConfig.MainWindow.Height = tmpScreenBounds.Height;
                }

                this.TopMost     = tmpAppConfig.MainWindow.TopMost;
                this.MinimumSize = new System.Drawing.Size(tmpMinimumWidth, tmpMinimumHeight);
                this.Location    = new System.Drawing.Point(tmpAppConfig.MainWindow.X, tmpAppConfig.MainWindow.Y);
                this.ClientSize  = new System.Drawing.Size(tmpAppConfig.MainWindow.Width, tmpAppConfig.MainWindow.Height);

                if (Program.Config.MainWindow.Maximized)
                {
                    this.WindowState           = FormWindowState.Maximized;
                    this.lastNotMinimizedState = this.WindowState;
                }
                else if (Program.Config.MainWindow.Minimized)
                {
                    this.WindowState = FormWindowState.Minimized;
                }
                else
                {
                    this.WindowState = FormWindowState.Normal;
                }

                this.splitControls.Panel1MinSize = 150;
                this.splitControls.Panel2MinSize = 200;
                if (tmpAppConfig.MainWindow.SplitPosition >= 8)
                {
                    this.splitControls.SplitterDistance = (int)(this.splitControls.Width * tmpAppConfig.MainWindow.SplitPosition / 100);
                }

                this.accountService = new HuiruiSoft.Safe.Service.AccountService( );

                this.CreateSpecialTreeNode( );
                this.InitializeToolBar( );
                this.InitializeTreeView( );
                this.InitializeAccountDataGrid( );

                this.toolComboBoxQuickFind.AutoCompleteMode   = AutoCompleteMode.Suggest;
                this.toolComboBoxQuickFind.AutoCompleteSource = AutoCompleteSource.ListItems;

                this.idleTickTimer          = new System.Windows.Forms.Timer( );
                this.idleTickTimer.Tick    += this.OnIdleTickTimerElapsed;
                this.idleTickTimer.Interval = 1 * 1000;
                this.idleTickTimer.Start( );

                this.initialized           = true;
                this.Visible               = true;
                this.Icon                  = WindowsUtils.DefaultAppIcon;
                this.lockTimerMaximum      = (int)Program.Config.Application.Security.LockWorkspace.LockAfterTime;
                this.lockGlobalMaximum     = (int)Program.Config.Application.Security.LockWorkspace.LockGlobalTime;
                this.clearClipboardMaximum = (int)Program.Config.Application.Security.Clipboard.ClipboardClearAfterSeconds;

                this.NotifyUserActivity( );

                this.treeViewCatalog.ContextMenuStrip = this.menuStripTreeView;
                this.dataGridAccount.ContextMenuStrip = this.menuStripDataGrid;

                this.GetCatalogChildAccounts(true);

                this.statusPartProgress.Visible  = false;
                this.statusPartClipboard.Visible = false;
                this.UpdateClipboardStatus();

                System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(OnFormLoadParallelAsync));
            }
        }
        private void buttonOK_Click(object sender, System.EventArgs args)
        {
            var tmpFileName = this.textExportFile.Text;

            if (!string.IsNullOrEmpty(tmpFileName))
            {
                var tmpFileInfo = new System.IO.FileInfo(tmpFileName);
                if (tmpFileInfo.Exists)
                {
                    if (MessageBox.Show(string.Format(SafePassResource.ExportOverwriteDialogPrompt, tmpFileInfo.Name, System.Environment.NewLine),
                                        SafePassResource.ExportOverwriteDialogCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.No)
                    {
                        return;
                    }
                }
                else if (!tmpFileInfo.Directory.Exists)
                {
                    MessageBox.Show(string.Format(SafePassResource.ExportInvalidPathDialogPrompt, tmpFileInfo.Directory, System.Environment.NewLine),
                                    SafePassResource.ExportInvalidPathDialogCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                FileFormatProvider tmpExportProvider;
                if (this.radioExportExcel.Checked)
                {
                    tmpExportProvider = new OfficeExcel()
                    {
                        FileName = tmpFileInfo.FullName
                    };
                }
                else
                {
                    tmpExportProvider = new SafePassXml1x()
                    {
                        FileName = tmpFileInfo.FullName
                    };
                }

                var tmpAccountService = new HuiruiSoft.Safe.Service.AccountService();
                var tmpAccountModels  = tmpAccountService.GetAccountInfosWithAttributes();
                if (tmpAccountModels != null)
                {
                    bool tmpExportResult = false;
                    if (tmpExportProvider is OfficeExcel)
                    {
                        tmpExportResult = ExportAccountHelper.ExportExcel(this.treeViewNodes, tmpAccountModels, tmpExportProvider.FileName);
                    }
                    else if (tmpExportProvider is SafePassXml1x)
                    {
                        tmpExportResult = ExportAccountHelper.ExportSafePassXml(this.treeViewNodes, tmpAccountModels, tmpExportProvider.FileName);
                    }

                    var tmpDialogTitle = tmpExportResult ? SafePassResource.ExportWindowDialogTitleSuccess : SafePassResource.ExportWindowDialogTitleFailed;
                    if (!tmpExportResult)
                    {
                        MessageBox.Show(SafePassResource.ExportWindowDialogMessageFailed, tmpDialogTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show(string.Format(SafePassResource.ExportWindowDialogMessageSuccess, System.Environment.NewLine, tmpFileInfo.FullName), tmpDialogTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.DialogResult = DialogResult.OK;
                    }
                }
            }
        }
Ejemplo n.º 6
0
        protected override void buttonOK_Click(object sender, System.EventArgs args)
        {
            if (this.CheckInputValidity( ))
            {
                var tmpComment = this.textComment.Text.Trim( );
                var tmpEmail   = this.textEmail.Text.Trim( );
                var tmpMobile  = this.textMobile.Text.Trim( );
                var tmpHttpUrl = this.textURL.Text.Trim();

                var tmpInputErrorCaption = SafePassResource.MessageBoxCaptionInputError;

                var tmpPassword = this.textPassword.Text.Trim();
                if (!string.Equals(tmpPassword, this.textPwdRepeat.Text))
                {
                    this.textPwdRepeat.Focus();
                    MessageBox.Show(SafePassResource.PasswordRepeatFailed, tmpInputErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                var tmpAccountInfo = new AccountModel( );
                tmpAccountInfo.AccountGuid = System.Guid.NewGuid( ).ToString("N");
                tmpAccountInfo.Name        = this.textName.Text.Trim();
                tmpAccountInfo.LoginName   = this.textLoginName.Text.Trim();
                tmpAccountInfo.Password    = tmpPassword;
                tmpAccountInfo.Email       = string.IsNullOrEmpty(tmpEmail) ? null : tmpEmail;
                tmpAccountInfo.URL         = string.IsNullOrEmpty(tmpHttpUrl) ? null : tmpHttpUrl;
                tmpAccountInfo.Mobile      = string.IsNullOrEmpty(tmpMobile) ? null : tmpMobile;
                tmpAccountInfo.Comment     = string.IsNullOrEmpty(tmpComment) ? null : tmpComment;
                tmpAccountInfo.CreateTime  = System.DateTime.Now;
                tmpAccountInfo.UpdateTime  = System.DateTime.Now;

                if (this.radioSecretRank0.Checked)
                {
                    tmpAccountInfo.SecretRank = SecretRank.公开;
                }
                else if (this.radioSecretRank1.Checked)
                {
                    tmpAccountInfo.SecretRank = SecretRank.秘密;
                }
                else if (this.radioSecretRank2.Checked)
                {
                    tmpAccountInfo.SecretRank = SecretRank.机密;
                }
                else if (this.radioSecretRank3.Checked)
                {
                    tmpAccountInfo.SecretRank = SecretRank.绝密;
                }
                else
                {
                    tmpAccountInfo.SecretRank = SecretRank.绝密;
                }

                if (this.currentCatalog != null)
                {
                    tmpAccountInfo.CatalogId = this.currentCatalog.CatalogId;
                }

                short order = 0;
                foreach (System.Data.DataRow tmpCurrentRow in this.accountDataTable.Rows)
                {
                    var attributeName  = string.Format("{0}", tmpCurrentRow[Account_Column_Name]);
                    var attributeValue = string.Format("{0}", tmpCurrentRow[Account_Column_Value]);

                    if (!string.IsNullOrEmpty(attributeName) && !string.IsNullOrEmpty(attributeValue))
                    {
                        var tmpAttribute = new AccountAttribute( );
                        tmpAttribute.AccountId = tmpAccountInfo.AccountId;
                        tmpAttribute.Order     = ++order;
                        tmpAttribute.Name      = attributeName;
                        tmpAttribute.Value     = attributeValue;

                        if (tmpCurrentRow[Account_Column_Encrypt] != System.DBNull.Value)
                        {
                            tmpAttribute.Encrypted = System.Convert.ToBoolean(tmpCurrentRow[Account_Column_Encrypt]);
                        }

                        tmpAccountInfo.Attributes.Add(tmpAttribute);
                    }
                }

                try
                {
                    Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

                    var  tmpAccountService = new HuiruiSoft.Safe.Service.AccountService( );
                    bool tmpCreateResult   = tmpAccountService.CreateAccount(tmpAccountInfo);
                    tmpAccountService = null;

                    if (tmpCreateResult)
                    {
                        this.textName.Text      = "";
                        this.textLoginName.Text = "";
                        this.textMobile.Text    = "";
                        this.textURL.Text       = "";
                        this.textPassword.Text  = "";
                        this.textEmail.Text     = "";
                        this.textComment.Text   = "";
                        this.accountDataTable.Rows.Clear( );
                    }

                    Cursor.Current    = System.Windows.Forms.Cursors.Default;
                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                }
                catch (System.Exception exception)
                {
                    loger.Error(exception);
                    Cursor.Current = System.Windows.Forms.Cursors.Default;
                    MessageBox.Show(string.Format(SafePassResource.AccountEditorDialogMessageCreateFailed, System.Environment.NewLine, exception.Message), SafePassResource.AccountEditorDialogTitleCreateFailed, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
        }