예제 #1
0
        private void SaveCurrentDb()
        {
            var messageID = FrmWaitScreen.ShowMessage("Saving Changes ....");

            _currentDB.SubmitChanges();
            FrmWaitScreen.HideMessage(messageID);
        }
예제 #2
0
        private void CheckDeletes()
        {
            var deletedGroupsIDs =
                (from row in
                 dgvGroups.Rows.Cast <DataGridViewRow>().Where(
                     p => p.Cells[0].Value != null && (Guid)p.Cells[0].Value != Guid.Empty)
                 let deleteCheckboxCell = row.Cells[1] as DataGridViewCheckBoxCell
                                          where deleteCheckboxCell != null && deleteCheckboxCell.Value != null && (bool)deleteCheckboxCell.Value
                                          select(Guid) row.Cells[0].Value).ToList();

            if (deletedGroupsIDs.Count == 0)
            {
                return;
            }

            if (deletedGroupsIDs.Count > 0 && MessageBox.Show("Group(s) will be deleted from all of its dependant Role(s) & Project(s)", "Warning - Group Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Cancel)
            {
                return;
            }

            var deletedGroups =
                dbContext.Groups.Where(p => deletedGroupsIDs.Contains(p.ID)).ToList();
            var currentDatabase = dbContext.Connection.Database;
            var otherDbs        =
                deletedGroups.SelectMany(p => p.UserProjects).Select(p => p.Project.DatabaseName).Where(p => p != currentDatabase).Distinct().ToList();

            dbContext.Groups.DeleteAllOnSubmit(deletedGroups);
            dbContext.SubmitChanges();
            //AryaTools.Instance.SaveChangesIfNecessary(false, true);

            if (otherDbs.Count == 0)
            {
                return;
            }

            var waitKey = FrmWaitScreen.ShowMessage("Cascading changes to Dependent Database(s) ...");

            foreach (var otherDb in otherDbs)
            {
                dbContext.Connection.ChangeDatabase(otherDb);
                dbContext.Groups.DeleteAllOnSubmit(dbContext.Groups.Where(p => deletedGroupsIDs.Contains(p.ID)));
            }

            AryaTools.Instance.InstanceData.Dc.Connection.ChangeDatabase(currentDatabase);

            FrmWaitScreen.HideMessage(waitKey);
        }
예제 #3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            bool errors = false;

            var       allTextBoxControls = GetControls(this).Where(p => p.Name.StartsWith("tb")).ToList();
            MetaTable projectMeta        = currentDb.Mapping.GetTable(typeof(Project));
            var       dataMembers        = projectMeta.RowType.PersistentDataMembers.Where(p => !p.CanBeNull && p.Type == typeof(string)).ToList();

            foreach (var requiredMember in dataMembers)
            {
                var requiredValue = currentProject.GetPropertyValue(requiredMember.Name);
                if (requiredValue == null || string.IsNullOrWhiteSpace(requiredValue.ToString()))
                {
                    MetaDataMember member = requiredMember;
                    epUser.SetError(allTextBoxControls.Single(p => p.Name == "tb" + member.Name), "Invalid Input");
                    errors = true;
                }
            }

            if (errors)
            {
                return;
            }

            currentProject.ProjectPreferences = projPreferences;
            currentDb.SubmitChanges();

            if (newProject)
            {
                var backupFileName = @"E:\TemporarySpace\" + Guid.NewGuid();
                BackupDatabase(backupFileName);
                RestoreDatabase(currentProject.DatabaseName, backupFileName);

                using (var targetDb = new SkuDataDbDataContext())
                {
                    targetDb.Connection.Open();
                    targetDb.Connection.ChangeDatabase(currentProject.DatabaseName);
                    //targetDb.Projects.InsertOnSubmit(currentProject.CloneEntity());

                    targetDb.Attributes.ForEach(att => att.ProjectID    = currentProject.ID);
                    targetDb.TaxonomyInfos.ForEach(tax => tax.ProjectID = currentProject.ID);
                    targetDb.Projects.DeleteAllOnSubmit(targetDb.Projects.Where(prj => prj.ID != currentProject.ID));
                    targetDb.SubmitChanges();
                }
            }
            else
            {
                using (var targetDb = new SkuDataDbDataContext())
                {
                    targetDb.Connection.Open();
                    targetDb.Connection.ChangeDatabase(currentProject.DatabaseName);
                    var targetProject = targetDb.Projects.Single(p => p.ID == currentProject.ID);
                    targetProject.InjectFrom <ProjectInjection>(currentProject);
                    targetDb.SubmitChanges();
                }
            }

            MessageBox.Show("Project Created.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
예제 #4
0
파일: FrmNewUser.cs 프로젝트: ewin66/Arya
        private void btnCreateUser_Click(object sender, EventArgs e)
        {
            epNewUser.Clear();

            var errors = false;

            if (!ValidateEmailAddress())
            {
                epNewUser.SetError(tbEmailAddress, "Valid Email Address required");
                errors = true;
            }

            if (string.IsNullOrWhiteSpace(tbFullName.Text))
            {
                epNewUser.SetError(tbFullName, "Valid Full Name required");
                errors = true;
            }

            if (errors)
            {
                return;
            }

            using (var db = new SkuDataDbDataContext())
            {
                var ssoID   = db.Users.Max(p => p.SingleSignOnId) + 1;
                var newUser = new User
                {
                    ID             = Guid.NewGuid(),
                    EmailAddress   = tbEmailAddress.Text.Trim(),
                    FullName       = tbFullName.Text.Trim(),
                    SingleSignOnId = ssoID,
                    CreatedOn      = DateTime.Now,
                    Active         = true
                };
                db.Users.InsertOnSubmit(newUser);
                db.SubmitChanges();

                MessageBox.Show(@"New User Created", @"New User", MessageBoxButtons.OK, MessageBoxIcon.Information);
                btnClear.PerformClick();
            }
        }
예제 #5
0
        private void btnDeleteUPG_Click(object sender, EventArgs e)
        {
            List <Guid> deletedUPGIDs =
                (from row in
                 dgvUserProjectGroups.Rows.Cast <DataGridViewRow>().Where(
                     p => p.Cells[0].Value != null)
                 let deleteCheckboxCell = row.Cells[1] as DataGridViewCheckBoxCell
                                          where deleteCheckboxCell != null && deleteCheckboxCell.Value != null && (bool)deleteCheckboxCell.Value
                                          select(Guid) row.Cells[0].Value).ToList();

            _currentDB.UserProjects.DeleteAllOnSubmit(
                _currentDB.UserProjects.Where(p => deletedUPGIDs.Contains(p.ID)));

            var dbList =
                _currentDB.UserProjects.Where(p => deletedUPGIDs.Contains(p.ID)).Select(
                    p => p.Project.DatabaseName).Distinct().ToList();

            foreach (var db in dbList)
            {
                using (var admindb = new SkuDataDbDataContext())
                {
                    admindb.Connection.Open();
                    admindb.Connection.ChangeDatabase(db);
                    admindb.UserProjects.DeleteAllOnSubmit(
                        admindb.UserProjects.Where(p => deletedUPGIDs.Contains(p.ID)));
                    admindb.SubmitChanges();
                }
            }

            //AryaTools.Instance.SaveChangesIfNecessary(false, true);

            SaveCurrentDb();

            LoadUPGs();

            ToggleDeleteUPGButton();
        }
예제 #6
0
        private void btnAddUPG_Click(object sender, EventArgs e)
        {
            List <Guid> selectedUsers = (from object currentItem in clbUsers.CheckedItems
                                         select currentItem.GetType().GetProperty("UserID").GetValue(currentItem, null)).
                                        OfType <Guid>().ToList();
            List <Guid> selectedGroups = (from object currentItem in clbGroups.CheckedItems
                                          select currentItem.GetType().GetProperty("GroupID").GetValue(currentItem, null))
                                         .OfType <Guid>().ToList();
            List <Guid> selectedProjects = (from object currentItem in clbProjects.CheckedItems
                                            select
                                            currentItem.GetType().GetProperty("ProjectID").GetValue(currentItem, null))
                                           .OfType <Guid>().ToList();

            var userLists = _currentDB.Users.Where(p => selectedUsers.Contains(p.ID)).ToList();
            var groupList = _currentDB.Groups.Where(p => selectedGroups.Contains(p.ID)).ToList();
            var dbLists   = _currentDB.Projects.Where(p => selectedProjects.Contains(p.ID)).Select(d => d.DatabaseName).Distinct().ToList();

            foreach (var db in dbLists)
            {
                using (var admindb = new SkuDataDbDataContext())
                {
                    admindb.Connection.Open();
                    admindb.Connection.ChangeDatabase(db);

                    var missingUsers = selectedUsers.Except(admindb.Users.Select(p => p.ID));

                    foreach (var usr in missingUsers)
                    {
                        var currentMissingUser = usr;
                        admindb.Users.InsertOnSubmit(userLists.Single(p => p.ID == currentMissingUser).CloneEntity());
                    }

                    var missingGroups = selectedGroups.Except(admindb.Groups.Select(p => p.ID));

                    foreach (var grp in missingGroups)
                    {
                        var currentMissingGrp = grp;
                        admindb.Groups.InsertOnSubmit(groupList.Single(p => p.ID == currentMissingGrp).CloneEntity());
                    }

                    admindb.SubmitChanges();
                }
            }

            var newUPGs = selectedUsers.SelectMany(
                selectedUserID =>
                selectedProjects.SelectMany(selectedProjectID => (from selectedGroupID in selectedGroups
                                                                  let userID = selectedUserID
                                                                               let projectID = selectedProjectID
                                                                                               let groupID = selectedGroupID
                                                                                                             let newUPG =
                                                                      _currentDB.UserProjects.SingleOrDefault(p => p.UserID == userID &&
                                                                                                              p.ProjectID == projectID &&
                                                                                                              p.GroupID == groupID)
                                                                      where newUPG == null
                                                                      select new UserProject
            {
                ID = Guid.NewGuid(),
                ProjectID = selectedProjectID,
                UserID = selectedUserID,
                GroupID = selectedGroupID
            }))).ToList();

            foreach (UserProject newUPG in newUPGs)
            {
                _currentDB.UserProjects.InsertOnSubmit(newUPG);
            }

            foreach (var db in dbLists)
            {
                using (var admindb = new SkuDataDbDataContext())
                {
                    admindb.Connection.Open();
                    admindb.Connection.ChangeDatabase(db);
                    var currentDbProjects = admindb.Projects.Select(p => p.ID).ToList();

                    foreach (var newUPG in newUPGs.Where(p => currentDbProjects.Contains(p.ProjectID)))
                    {
                        var currentNewUPG = newUPG;
                        admindb.UserProjects.InsertOnSubmit(currentNewUPG.CloneEntity());
                    }

                    admindb.SubmitChanges();
                }
            }

            //AryaTools.Instance.SaveChangesIfNecessary(false, true);
            SaveCurrentDb();

            LoadUPGs();
        }
예제 #7
0
        private void tsbtnSave_Click(object sender, EventArgs e)
        {
            var currentGroup = (Group)lbUserGroups.SelectedValue;

            if (currentGroup == null)
            {
                MessageBox.Show("The project has no group(s)");
                return;
            }

            if (MessageBox.Show(@"Do you want to save the current changes?", @"Save", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }

            //gather taxonomy exclusions
            var changedTaxonomyExclusions = taxonomyPermissions.GetAllCheckedTaxonomies();
            var currentTaxonomyExclusions = currentGroup.TaxonomyExlusions.ToList();

            var toBeDeletedTaxonomyExclusions = currentTaxonomyExclusions.Except(changedTaxonomyExclusions).ToList();
            var toBeAddedTaxonomyExclusions   = changedTaxonomyExclusions.Except(currentTaxonomyExclusions).ToList();

            foreach (var addedTaxonomyExclusion in toBeAddedTaxonomyExclusions)
            {
                currentGroup.Roles.Add(new Role {
                    GroupID = currentGroup.ID, ID = Guid.NewGuid(), ObjectID = addedTaxonomyExclusion, ObjectType = Role.TaskObjectType.TaxonomyInfo.ToString(), Permission = false
                });
            }

            foreach (var deletedTaxonomyExclusion in toBeDeletedTaxonomyExclusions)
            {
                Guid exclusion   = deletedTaxonomyExclusion;
                var  deletedRole = currentGroup.Roles.Single(p => p.ObjectID == exclusion);
                currentDb.Roles.DeleteOnSubmit(deletedRole);
            }

            //gather attribute exclusions
            var changedAttributeExclusions = attributeExclusionsControl.CheckedAttributes;
            var currentAttributeExclusions = currentGroup.AttributeExlusions.ToList();

            var toBeDeletedAttributeExclusions = currentAttributeExclusions.Except(changedAttributeExclusions).ToList();
            var toBeAddedAttributeExclusions   = changedAttributeExclusions.Except(currentAttributeExclusions);

            foreach (var addedAttributeExclusion in toBeAddedAttributeExclusions)
            {
                currentGroup.Roles.Add(new Role {
                    GroupID = currentGroup.ID, ID = Guid.NewGuid(), ObjectID = addedAttributeExclusion, ObjectType = Role.TaskObjectType.Attribute.ToString(), Permission = false
                });
            }

            foreach (var deletedAttributeExclusion in toBeDeletedAttributeExclusions)
            {
                Guid exclusion   = deletedAttributeExclusion;
                var  deletedRole = currentGroup.Roles.Single(p => p.ObjectID == exclusion);
                currentDb.Roles.DeleteOnSubmit(deletedRole);
            }

            //gather UI exclusions
            var changedUIExclusions = cilbUIObjects.CheckedItems.Select(p => (Guid)((dynamic)p).ID).ToList();
            var currentUIExclusions = currentGroup.UIExclusions.ToList();

            var toBeDeletedUIExclusions = currentUIExclusions.Except(changedUIExclusions).ToList();
            var toBeAddedUIExclusions   = changedUIExclusions.Except(currentUIExclusions).ToList();

            foreach (var addedUIExclusion in toBeAddedUIExclusions)
            {
                currentGroup.Roles.Add(new Role {
                    GroupID = currentGroup.ID, ID = Guid.NewGuid(), ObjectID = addedUIExclusion, ObjectType = Role.TaskObjectType.UIObject.ToString(), Permission = false
                });
            }

            foreach (var deletedUIExclusion in toBeDeletedUIExclusions)
            {
                Guid exclusion   = deletedUIExclusion;
                var  deletedRole = currentGroup.Roles.Single(p => p.ObjectID == exclusion);
                currentDb.Roles.DeleteOnSubmit(deletedRole);
            }

            currentDb.SubmitChanges();
        }