public List <SavedSearch> GetSavedSearch(string itemTypeName) { List <SavedSearch> resultList; if (!cachedSavedSearches.TryGetValue(itemTypeName, out resultList)) { resultList = new List <SavedSearch>(); dynamic savedSearches = innovatorInstance.newItem(); savedSearches.loadAML(string.Format(@" <AML> <Item type=""SavedSearch"" action=""get""> <itname>{0}</itname> <auto_saved>0</auto_saved> </Item> </AML>" , itemTypeName)); savedSearches = savedSearches.apply(); var searchesCount = savedSearches.getItemCount(); for (int i = 0; i < searchesCount; i++) { var search = new SavedSearch(); var savedSearch = savedSearches.getItemByIndex(i); search.SearchId = savedSearch.getID(); search.SearchName = savedSearch.getProperty("label"); search.ItemName = itemTypeName; string criteria = savedSearch.getProperty("criteria"); if (!string.IsNullOrEmpty(criteria)) { XmlDocument doc = new XmlDocument(); doc.LoadXml(criteria); var properties = doc.FirstChild.ChildNodes; foreach (XmlNode prop in properties) { var propertyInfo = new ItemSearchPropertyInfo(); propertyInfo.PropertyName = prop.Name; propertyInfo.PropertyValue = prop.InnerText; search.SavedSearchProperties.Add(propertyInfo); } } resultList.Add(search); } cachedSavedSearches.Add(itemTypeName, resultList); } return(resultList); }
public DataGridViewColumn GetColumn(ItemSearchPropertyInfo property) { DataGridViewColumn column = null; if (property.PropertyName == "locked_by_id") { var colImage = new DataGridViewImageColumn() { ImageLayout = DataGridViewImageCellLayout.Normal, Image = null, }; property.Label = string.Empty; colImage.DefaultCellStyle.NullValue = null; column = colImage; } else if (property.DataType == PropertyDataType.Boolean) { column = new DataGridViewCheckBoxColumn(true) { FalseValue = 0, TrueValue = 1 }; } else if (property.DataType == PropertyDataType.List) { var source = (property as ListPropertyInfo).ItemsSource; column = new DataGridViewComboBoxColumn() { DataSource = source, DisplayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton, FlatStyle = FlatStyle.Flat }; } else if (property.DataType == PropertyDataType.ColorList) { var source = (property as ColorListPropertyInfo).ColorSource; var template = new DataGridViewComboBoxCellLable() { DataSource = new BindingSource(source, null), DisplayMember = "Value", ValueMember = "Key", DisplayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton, FlatStyle = FlatStyle.Flat, }; column = new DataGridViewComboBoxColumn() { CellTemplate = template, Tag = "color list" }; } else { column = new DataGridViewTextBoxColumn(); if (property.DataType == PropertyDataType.Date && !string.IsNullOrEmpty(property.Pattern)) { DataGridViewCalendarCell cell = new DataGridViewCalendarCell(Utilities.Utils.dateFormatDictionary[property.Pattern], false); column.CellTemplate = cell; } } if (property.DataType == PropertyDataType.Color) { column.Tag = "color"; } column.HeaderText = property.Label; column.Name = property.PropertyName; column.Width = property.Width; //TODO: change to enum. if (!string.IsNullOrEmpty(property.Alignment)) { switch (property.Alignment) { case "left": column.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft; break; case "center": column.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; break; case "right": column.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; break; } } //TODO: check to get readonly from property.IsReadonly column.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; column.ReadOnly = true; column.SortMode = DataGridViewColumnSortMode.Programmatic; return(column); }
public DataGridViewCell GetCell(ItemSearchPropertyInfo property) { var lockProperInfo = property as LockedByPropertyInfo; if (lockProperInfo != null) { var cell = new DataGridViewImageCell(); if (lockProperInfo.IsLocked) { cell.Value = Resources.img_locked; } if (!lockProperInfo.IsLockedByMe) { cell.Value = Resources.img_locked_else; } if (!lockProperInfo.IsLocked) { cell.Value = null; } return(cell); } if (property.DataType == PropertyDataType.Boolean) { var cell = new DataGridViewCheckBoxCell(); cell.Value = property.PropertyValue == "1"; return(cell); } if (property.DataType == PropertyDataType.Color) { var cell = new DataGridViewTextBoxCell(); var color = string.IsNullOrEmpty(property.PropertyValue) ? Color.White : System.Drawing.ColorTranslator.FromHtml(property.PropertyValue); cell.Style.BackColor = color; return(cell); } if (property.DataType == PropertyDataType.ColorList) { var colors = (property as ColorListPropertyInfo).ColorSource; var cell = new DataGridViewTextBoxCell(); string value = property.PropertyValue ?? string.Empty; string label; if (!colors.TryGetValue(value, out label)) { label = value; } var color = string.IsNullOrEmpty(value) ? Color.White : ColorTranslator.FromHtml(value); cell.Value = label; cell.Style.BackColor = color; return(cell); } if (property.DataType == PropertyDataType.Date) { var cell = new DataGridViewCalendarCell(); DateTime dt; if (DateTime.TryParse(property.PropertyValue, out dt)) { cell.Value = dt; } else { cell.Value = property.PropertyValue; } return(cell); } if (property.DataType == PropertyDataType.Item) { var cell = new DataGridViewTextBoxCell(); cell.Value = property.Label; return(cell); } var defaultCell = new DataGridViewTextBoxCell(); defaultCell.Value = property.PropertyValue; return(defaultCell); }
public virtual List <ItemSearchPropertyInfo> GetPropertiesForSearch(string itemType) { List <ItemSearchPropertyInfo> notSortedList = new List <ItemSearchPropertyInfo>(); List <dynamic> properties = Utils.GetItemTypeProperties(innovatorInstance, itemType); foreach (dynamic property in properties) { //TODO: check this if statesment if (string.Equals("1", property.getProperty("is_hidden")) && !string.Equals("locked_by_id", property.getProperty("name"))) { continue; } var dataType = PropertyDataTypeParser.ParseDataType(property.getProperty("data_type")); ItemSearchPropertyInfo propertyInfo; if (dataType == PropertyDataType.List) { var pinfo = new ListPropertyInfo(); var affectedItem = property.node.GetXmlNodePropertyAttribute("data_source", "keyed_name"); pinfo.ItemsSource = new List <string>() { string.Empty }; //TODO: should show lable not a value List <dynamic> listValueItems = Utilities.Utils.GetValueListByName(innovatorInstance, affectedItem); List <string> listValues = listValueItems.Select(x => x.getProperty("value") as string).ToList(); pinfo.ItemsSource.AddRange(listValues); propertyInfo = pinfo; } else if (dataType == PropertyDataType.ColorList) { var pinfo = new ColorListPropertyInfo(); var affectedItem = property.node.GetXmlNodePropertyAttribute("data_source", "keyed_name"); List <dynamic> items = Utilities.Utils.GetValueListByName(innovatorInstance, affectedItem); var colors = new Dictionary <string, string>() { { string.Empty, string.Empty } }; string value; string label; foreach (dynamic item in items) { value = item.getProperty("value", string.Empty); label = item.getProperty("label", value); if (!colors.ContainsKey(value)) { colors.Add(value, label); } } pinfo.ColorSource = colors; propertyInfo = pinfo; } else { propertyInfo = new ItemSearchPropertyInfo(); } propertyInfo.PropertyName = property.getProperty("name"); propertyInfo.Label = property.getProperty("label"); if (string.IsNullOrEmpty(propertyInfo.Label)) { propertyInfo.Label = property.getProperty("keyed_name"); } propertyInfo.DataType = dataType; propertyInfo.Id = property.getID(); propertyInfo.Pattern = property.getProperty("pattern"); string widthString; if (propertyInfo.PropertyName == "locked_by_id") { widthString = property.getProperty("column_width", "24"); } else { widthString = property.getProperty("column_width", "100"); } propertyInfo.Width = int.Parse(widthString); propertyInfo.DataSource = property.getProperty("data_source"); propertyInfo.Alignment = property.getProperty("column_alignment"); notSortedList.Add(propertyInfo); } notSortedList.Add(new ItemSearchPropertyInfo() { PropertyName = "id", IsHidden = true }); UpdatePropertiesForSearch(notSortedList); List <ItemSearchPropertyInfo> resultList = new List <ItemSearchPropertyInfo>(); var layout = preferencesProvider.GetItemGridLayout(itemType); if (layout != null) { for (int i = 0; i < layout.ColumnOrderList.Count; i++) { var foundedProperty = notSortedList.FirstOrDefault(p => p.PropertyName == layout.ColumnOrderList[i]); if (foundedProperty != null) { int width; if (int.TryParse(layout.ColumnWidthsList[i], out width)) { foundedProperty.Width = width; } resultList.Add(foundedProperty); } } } //Add properties which is not in layoutsettings foreach (var item in notSortedList) { if (!resultList.Contains(item)) { if (item.PropertyName == "locked_by_id") { resultList.Insert(0, item); } else { resultList.Add(item); } } } return(resultList); }
public List <ItemSearchResult> RunSearch(string itemType, SavedSearch search) { var itemForSearch = innovatorInstance.newItem(itemType, "get"); foreach (var prop in search.SavedSearchProperties) { if (!string.IsNullOrEmpty(prop.PropertyValue) && !string.Equals(prop.PropertyValue, "Indeterminate")) { if (prop.DataType == PropertyDataType.Item) { itemForSearch.setProperty(prop.PropertyName, CreateItemSearchProperty(prop.DataSource, prop.PropertyValue)); } else if (prop.DataType == PropertyDataType.Date) { DateTime date; if (DateTime.TryParse(prop.PropertyValue, out date)) { string value = date.ToString("yyyy-MM-dd"); itemForSearch.setProperty(prop.PropertyName, $"{value}T00:00:00 and {value}T23:59:59"); itemForSearch.setPropertyAttribute(prop.PropertyName, "condition", "between"); } } else { itemForSearch.setProperty(prop.PropertyName, prop.PropertyValue); if (prop.PropertyValue.Contains("*") || prop.PropertyValue.Contains("%")) { itemForSearch.setPropertyAttribute(prop.PropertyName, "condition", "like"); } } } } itemForSearch.setAttribute("page", search.Page.ToString()); if (!string.IsNullOrEmpty(search.PageSize)) { itemForSearch.setAttribute("pagesize", search.PageSize.ToString()); } var codes = new Dictionary <string, string>() { { ">", ">" }, { "<", "<" }, }; string parsedString = itemForSearch.ToString(); parsedString = codes.Aggregate(parsedString, (current, code) => current.Replace(code.Key, code.Value)); itemForSearch.loadAML(parsedString); UpdateSearch(itemForSearch, itemType, search.SavedSearchProperties); itemForSearch = itemForSearch.apply(); //itemForSearch.IsErrorItem(true); List <dynamic> itemForSearchList = new List <dynamic>(); var itemsCount = itemForSearch.getItemCount(); for (int i = 0; i < itemsCount; i++) { var currentItem = itemForSearch.getItemByIndex(i); itemForSearchList.Add(currentItem); } UpdateFoundedItems(itemForSearchList); var resultSearchList = new List <ItemSearchResult>(); for (int i = 0; i < itemForSearchList.Count; i++) { var currentItem = itemForSearchList[i]; ItemSearchResult searchResult = new ItemSearchResult(); foreach (var item in search.SavedSearchProperties) { var value = currentItem.getProperty(item.PropertyName); ItemSearchPropertyInfo foundedPropertyInfo; if (item.PropertyName == "locked_by_id") { var lockedPropertyInfo = new LockedByPropertyInfo(); lockedPropertyInfo.IsLocked = !string.IsNullOrEmpty(value); lockedPropertyInfo.IsLockedByMe = string.Equals(value, innovatorInstance.getUserID()); lockedPropertyInfo.PropertyName = item.PropertyName; foundedPropertyInfo = lockedPropertyInfo; } else if (item.DataType == PropertyDataType.ColorList) { var colorProp = item as ColorListPropertyInfo; foundedPropertyInfo = new ColorListPropertyInfo() { PropertyName = item.PropertyName, PropertyValue = value, DataType = item.DataType, ColorSource = colorProp.ColorSource }; } else if (item.DataType == PropertyDataType.Item) { var label = currentItem.getPropertyAttribute(item.PropertyName, "keyed_name", string.Empty); foundedPropertyInfo = new ItemSearchPropertyInfo() { PropertyName = item.PropertyName, PropertyValue = value, Label = label, DataType = item.DataType }; } else { foundedPropertyInfo = new ItemSearchPropertyInfo() { PropertyName = item.PropertyName, PropertyValue = value, DataType = item.DataType }; } searchResult.FoundedItems.Add(foundedPropertyInfo); } resultSearchList.Add(searchResult); } if (resultSearchList.Count > 0) { var firstItem = itemForSearch.getItemByIndex(0); var page = firstItem.getAttribute("page", "1"); var pageMax = firstItem.getAttribute("pagemax", "1"); int value; search.Page = int.TryParse(page, out value) ? value : 1; search.PageMax = int.TryParse(pageMax, out value) ? value : 1; } else { search.Page = 1; search.PageMax = 1; } return(resultSearchList); }