private void LoadProjects() { ResetSelectionTextBox(lblSelectedProjects); var allProjects = _currentDB.Projects.AsQueryable(); //if (CurrentUserID != default(Guid)) //{ // allProjects = allProjects.Where(p => p.UserProjects.Any(up => up.UserID == CurrentUserID && up.GroupID == Group.RoleManagerGroup)); //} List <object> existingProjects; Version currentVersion = Program.GetCurrrentCodeVersion(); if (AryaTools.Instance.InstanceData.CurrentUser.IsAdmin) { existingProjects = _currentDB.ExecuteQuery <Project>("SELECT * FROM Project p INNER JOIN sys.databases sd ON sd.Name = p.DatabaseName").Where(p => p.AryaCodeBaseVersion == "4.5").Select( p => new { ProjectID = p.ID, ProjectName = p.ClientDescription + " " + p.SetName + " " + "[" + p.AryaCodeBaseVersion + "]" }).OrderBy( p => p.ProjectName).Cast <object>().ToList(); } else { existingProjects = allProjects.Where(p => p.UserProjects.Any(up => up.UserID == CurrentUserID && up.GroupID == Group.RoleManagerGroup && up.Project.AryaCodeBaseVersion == "4.5")).Select( p => new { ProjectID = p.ID, ProjectName = p.ClientDescription + " " + p.SetName + " " + "[" + p.AryaCodeBaseVersion + "]" }).OrderBy( p => p.ProjectName).Cast <object>().ToList(); } if (!existingProjects.Any()) { return; } clbProjects.BeginUpdate(); clbProjects.DataSource = existingProjects; clbProjects.DisplayMember = "ProjectName"; clbProjects.ValueMember = "ProjectID"; clbProjects.CheckedIndices.OfType <int>().ForEach(a => clbProjects.SetItemChecked(a, false)); clbProjects.EndUpdate(); }
public void Run(Guid currentUserID, bool isAdmin, Guid currentProjectIDValue = default(Guid)) { if (currentDb != null) { currentDb.Dispose(); } currentDb = new SkuDataDbDataContext(); Version currentVersion = Program.GetCurrrentCodeVersion(); var allUserProjects = !isAdmin ? currentDb.ExecuteQuery <Project>( @"SELECT * FROM Project WHERE ID IN ( SELECT DISTINCT p.ID FROM UserProject up INNER JOIN Project p ON up.ProjectID = p.ID WHERE up.UserID = {0} and up.GroupID = {1} AND EXISTS ( SELECT database_id FROM sys.databases sd WHERE sd.Name = p.DatabaseName and p.AryaCodeBaseVersion ={2} ) ) ", currentUserID, Group.PermissionsManagerGroup, currentVersion.Major + "." + currentVersion.Minor).ToList().Select( p => new { p.ProjectDescription, ProjectID = p.ID }).Distinct().ToList() : currentDb.ExecuteQuery <Project>(@"SELECT * FROM Project p INNER JOIN sys.databases sd ON sd.Name = p.DatabaseName WHERE p.AryaCodeBaseVersion={0}", currentVersion.Major + "." + currentVersion.Minor).ToList().Select( p => new { p.ProjectDescription, ProjectID = p.ID }).Distinct().ToList(); if (allUserProjects.Count == 0) { MessageBox.Show("You are not Permission Manager in any project!!"); return; } tscbProjects.SelectedIndexChanged -= tscbProjects_SelectedIndexChanged; tscbProjects.ComboBox.DataSource = allUserProjects; tscbProjects.ComboBox.DisplayMember = "ProjectDescription"; tscbProjects.ComboBox.ValueMember = "ProjectID"; //resizes the combobox to show the longest string using (Graphics graphics = CreateGraphics()) { int maxWidth = 0; foreach (object obj in tscbProjects.ComboBox.Items) { var currentString = ((dynamic)obj).ProjectDescription; var area = graphics.MeasureString(currentString, tscbProjects.ComboBox.Font); maxWidth = Math.Max((int)area.Width, maxWidth); } tscbProjects.ComboBox.Width = maxWidth + 15; if (maxWidth + 50 > tlpPermissionsManager.ColumnStyles[0].Width) { tlpPermissionsManager.ColumnStyles[0].Width = maxWidth + 70; } } tscbProjects.SelectedIndex = currentProjectIDValue != default(Guid) ? allUserProjects.IndexOf( allUserProjects.Single(p => p.ProjectID == currentProjectIDValue)) :0; // if (tscbProjects.SelectedIndex == 0) // { // currentDb.ExecuteQuery<Project>( // @"SELECT * // FROM Project // WHERE ID IN ( // SELECT DISTINCT p.ID // FROM UserProject up // INNER JOIN Project p ON up.ProjectID = p.ID // WHERE up.UserID = {0} // AND EXISTS ( // SELECT database_id FROM sys.databases sd WHERE sd.Name = p.DatabaseName // ) // ) // ", // currentUserID) // } tscbProjects.SelectedIndexChanged += tscbProjects_SelectedIndexChanged; tscbProjects_SelectedIndexChanged(tscbProjects, EventArgs.Empty); LoadPermissions(); }
public void FillTaxonomyAttributesCacheForImagingGapFill(TaxonomyInfo rootTaxonomy) { var allChilds = rootTaxonomy.AllLeafChildren.ToList(); //include the root allChilds.Add(rootTaxonomy); var maxAttrCount = _currentDb.ExecuteQuery <int>(@"SELECT MAX(A.CT) AS MaxAttrCount FROM ( SELECT TaxonomyID,COUNT(DISTINCT AttributeName)AS CT FROM SchemaAttributes WHERE InSchema = 1 AND T2 = 'Representational' AND T3 = 'Skus' AND (DisplayOrder <= 49 AND DisplayOrder >= 1) GROUP BY TaxonomyID ) A").Single(); //Data Combination var dCSchema = allChilds.SelectMany( child => child.SchemaInfos.Where( si => si.SchemaDatas.Any(sd => sd.Active && sd.InSchema) && si.Attribute.AttributeName == "Data Combination")).FirstOrDefault(); var dCSchemaAttribute = dCSchema == null ? new Attribute { AttributeName = "Data Combination" } : dCSchema.Attribute; var blankAttribute = new Attribute { AttributeName = string.Empty }; foreach (var child in allChilds) { if (_taxonomyAttributesCache.ContainsKey(child.ID)) { continue; } var atts = child.SchemaInfos.Where(p => p.SchemaData != null && p.SchemaData.InSchema) .Select(p => new { p.Attribute, p.SchemaData }) .ToList(); var attributes = (from att in atts let rank = GetRank(att.SchemaData, OrderAttributesBy) orderby rank, att.Attribute.AttributeName select new Tuple <Attribute, decimal, decimal>(att.Attribute, att.SchemaData == null ? 0 : att.SchemaData.NavigationOrder, att.SchemaData == null ? 0 : att.SchemaData.DisplayOrder)).ToList(); var finalList = new List <Tuple <Attribute, decimal, decimal> >(); var lessThan50DisplayAttributes = attributes.Where(p => p.Item3 < 50); //add all the left attributes finalList.AddRange(lessThan50DisplayAttributes); if (finalList.Count != maxAttrCount) { var misCount = maxAttrCount - finalList.Count; finalList.AddRange( Enumerable.Repeat(new Tuple <Attribute, decimal, decimal>(blankAttribute, 0, int.MaxValue), misCount)); } //add DC attribute finalList.Add(new Tuple <Attribute, decimal, decimal>(dCSchemaAttribute, 0, int.MaxValue)); finalList.AddRange(attributes.Where(p => p.Item3 > 50)); _taxonomyAttributesCache.Add(child.ID, finalList); } }