Example #1
0
        private void Create_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new SaveFileDialog {
                FileName     = "profile.db",
                Filter       = "db ファイル|*.db",
                FilterIndex  = 0,
                AddExtension = true
            };

            if (true != dialog.ShowDialog())
            {
                return;
            }
            var profile = new FileOperator(dialog.FileName);

            if (this.IsRegisterProfile(profile.FilePath))
            {
                return;
            }
            profile.Delete();
            using (var database = new ProfileDatabase(profile.FilePath)) {
                try {
                    database.SetPassWord(ProfileDatabase.Password);
                    database.Open();
                    database.BeginTrans();
                    if (database.ExecuteNonQuery(CategoriesTable.CreateTable()) < 0)
                    {
                        AppCommon.ShowErrorMsg(string.Format(ErrorMsg.FailToCreate, "categories table"));
                        return;
                    }
                    if (database.ExecuteNonQuery(ItemsTable.CreateTable()) < 0)
                    {
                        AppCommon.ShowErrorMsg(string.Format(ErrorMsg.FailToCreate, "items table"));
                        return;
                    }
                    database.CommitTrans();
                } catch (Exception ex) {
                    AppCommon.ShowErrorMsg(ex.Message);
                } finally {
                    database.RollbackTrans();
                }
            }
            if (this.InsertProfile(profile))
            {
                this.cProfileList.DataContext = this._model;
            }
        }