public void SeedItemTypes() { ItemTypes.Add(new ItemType { ItemTypeId = 1, ItemTypeName = "Knight" }); ItemTypes.Add(new ItemType { ItemTypeId = 2, ItemTypeName = "Potion" }); SaveChanges(); }
public void CreatedEditedItemType(ItemType itemType, bool wasCreated) { if (itemType.IsDefault) { foreach (var type in ItemTypes) { type.IsDefault = type.ID == itemType.ID; } } if (wasCreated) { ItemTypes.Add(itemType); } RefreshCanDelete(); }
private void CreateItemTypes() { if (_itemTypes == null) { _itemTypes = new FullyObservableCollection <LItem>(); } var itemTypes = new List <TrinityItemType>((TrinityItemType[])Enum.GetValues(typeof(TrinityItemType))); var itemTypeImages = itemTypes.ToDictionary(k => k, v => string.Empty); foreach (var item in _TrinityItems) { itemTypeImages[item.TrinityItemType] = item.IconUrl; } var existingItemTypes = ItemTypes.ToDictionary(k => k.Id, v => v); foreach (var itemType in AllowedTrinityItemTypes) { LItem item; if (!existingItemTypes.TryGetValue((int)itemType, out item)) { item = new LItem { Name = itemType.ToString(), Id = (int)itemType, Type = LItem.ILType.Slot, TrinityItemType = itemType, ItemSelectionType = itemType.ToItemSelectionType(), IconUrl = itemTypeImages[itemType] }; item.LoadCommands(); ItemTypes.Add(item); continue; } item.Name = itemType.ToString(); item.Type = LItem.ILType.Slot; item.TrinityItemType = itemType; item.ItemSelectionType = itemType.ToItemSelectionType(); item.IconUrl = itemTypeImages[itemType]; item.LoadCommands(); } ItemTypes.Sort(itr => itr.Name); }
private void PopulateLists() { ItemTypes.Clear(); foreach (string iType in Enum.GetNames(typeof(ItemType))) { ItemTypes.Add(iType); } LocationTypes.Clear(); foreach (string lType in Enum.GetNames(typeof(LocationType))) { LocationTypes.Add(lType); } Mediums = new ObservableCollection <string>(); }
public Project(ViewModels.Project viewModel) { foreach (var itemType in viewModel.ItemTypes) { ItemTypes.Add(new ItemType { Name = itemType.Name, IsRelationship = itemType.IsRelationship, Properties = itemType.Properties.Select(property => new ItemTypeProperty { Name = property.Name, DataSource = property.DataSourceType?.Name, }).ToList(), Relationships = itemType.Relationships.Select(relationship => relationship.Name).ToList(), }); } var itemIndexes = new Dictionary <ViewModels.Item, int>(); foreach (var item in viewModel.Items) { var itemXml = new Item { ItemType = item.ItemType.Name, Left = item.Left, Top = item.Top, Properties = item.Properties.Select(propertyValue => new ItemProperty(propertyValue.Name, propertyValue.Value)).ToList(), }; itemIndexes[item] = Items.Count; Items.Add(itemXml); } foreach (var item in viewModel.Items) { foreach (var relationship in item.Relationships) { Relationships.Add(new Relationship { SourceIndex = itemIndexes[item], RelatedIndex = itemIndexes[relationship], }); } } }
public void AddTest() { var three = one.Add(two); Assert.Equal(3, (int)three); }
public ItemDimensionSearchViewModel() { Client.AccWithConfigAndSizeCompleted += (s, sv) => { bool isSearchItem = false; var itemSearchModel = SearchResultList.FirstOrDefault(i => i.ItemId == sv.Result.Iserial && i.ItemType == sv.Result.ItemGroup); CRUDManagerService.ItemsDto item; if (itemSearchModel != null) { item = itemSearchModel.ItemPerRow ?? (itemSearchModel.ItemPerRow = new CRUDManagerService.ItemsDto()); isSearchItem = true; } else { item = ItemPerRow; } item.AccConfigList = sv.Result.AccConfigList; item.SizesList = new ObservableCollection <string>(); item.CombinationList = sv.Result.CombinationList; var tblAccessoryAttributesDetails = sv.Result.CombinationList.FirstOrDefault(); if (tblAccessoryAttributesDetails != null) { item.SizesList.Add(tblAccessoryAttributesDetails.Size); } if (item.CombinationList != null) { item.SizesList = new ObservableCollection <string>(); } if (isSearchItem) { if (item.AccConfigList == null) { item.AccConfigList = new ObservableCollection <CRUDManagerService.TblColor>(); } itemSearchModel.ColorPerRow = item.AccConfigList.FirstOrDefault(c => c.Iserial == itemSearchModel.ColorToId); } }; Client.InspectionRouteCompleted += (o, e) => { foreach (var batchNo in e.Result.Select(x => x.RollBatch)) { if (!BatchNoList.Contains(batchNo)) { BatchNoList.Add(batchNo); } } }; // Client.SearchF WarehouseClient.GetAccWarehouseRowsCompleted += (s, e) => { if (e.Result.Count <= 0) { MessageBox.Show(strings.NoDataFound); } foreach (var iR in e.Result) { // هشوف لو موجود مش هحطه if (!SearchResultList.Any(sr => sr.ItemDimFromIserial == iR.ItemDimFromIserial)) { var qtemp = iR.AvailableQuantity; iR.AvailableQuantity = 0; // iR.CountedQuantity = 0; iR.AvailableQuantity = qtemp; if (iR.PendingQuantity > 0) { iR.TransferredQuantity = iR.AvailableQuantity; } else { iR.TransferredQuantity = iR.AvailableQuantity + iR.PendingQuantity; } ItemDimensionSearchModel item = new ItemDimensionSearchModel(); item.InjectFrom(iR); if (item.ItemPerRow == null) { item.ItemPerRow = new CRUDManagerService.ItemsDto(); } if (ItemPerRow.Iserial > 0) { item.ItemPerRow.InjectFrom(ItemPerRow); } //else // Client.AccWithConfigAndSizeAsync(new CRUDManagerService.ItemsDto() // { // Iserial = item.ItemId, // ItemGroup = item.ItemType, // Code=item.ItemCode, // }); if (item.ItemPerRow.AccConfigList == null) { item.ItemPerRow.AccConfigList = new ObservableCollection <CRUDManagerService.TblColor>(); } var colorRow = item.ItemPerRow.AccConfigList.FirstOrDefault(c => c.Iserial == iR.ColorPerRow.Iserial); if (colorRow == null) { colorRow = new CRUDManagerService.TblColor() { Iserial = item.ColorFromId, Code = item.ColorFromCode }; } item.ColorPerRow = colorRow; SearchResultList.Add(item); } } Loading = false; }; WarehouseClient.GetItemDimensionsOrCreteForTransferCompleted += (s, e) => { SelectedSearchResultList.Clear(); foreach (var item in e.Result) { ItemDimensionSearchModel temp = new ItemDimensionSearchModel(); temp.InjectFrom(item); temp.ItemPerRow = ItemPerRow; temp.ColorPerRow.InjectFrom(item.ColorPerRow); SelectedSearchResultList.Add(temp); } IsWorking = false; }; CancelCommand = new RelayCommand((o) => // هقفل وارجع فولس يعرف انه كنسل { var view = (o as ChildWindowsOverride); if (view != null) { view.DialogResult = false; view.Close(); } }); ApplyCommand = new RelayCommand((o) => { var view = (o as ItemDimensionSearchChildWindow); if (view != null) { //هنا هاخد الى مختاره فى الجريد للشاشة الاصلية ApplySelectedItem(view); } }); OkCommand = new RelayCommand((o) => { var view = (o as ItemDimensionSearchChildWindow); if (view != null) { //هنا هاخد الى مختاره فى الجريد للشاشة الاصلية لو مكانش راح //وهقفل الشاشة فى الاخر ApplySelectedItem(view); view.DialogResult = true; view.Close(); } }); LoadingRow = new GalaSoft.MvvmLight.Command.RelayCommand <object>((o) => { var e = o as System.Windows.Controls.DataGridRowEventArgs; if (SearchResultList.Count < PageSize) { return; } if (SearchResultList.Count - 2 < e.Row.GetIndex() && !Loading) { GetInspectionWarehouseRows(); } }); DetailSelectionChanged = new GalaSoft.MvvmLight.Command.RelayCommand <object>( (o) => { var e = o as System.Windows.Controls.SelectionChangedEventArgs; var temp = new Web.DataLayer.ItemDimensionSearchModel(); if (e.AddedItems != null && e.AddedItems.Count > 0) { temp.InjectFrom(e.AddedItems[0]); WarehouseClient.GetItemToQuantitiesAsync(temp, WarehouseToCode); } }); WarehouseClient.GetItemToQuantitiesCompleted += (s, e) => { var item = SearchResultList.FirstOrDefault(rl => rl.ItemId == e.Result.ItemId && rl.ItemType == e.Result.ItemType && rl.ItemDimFromIserial == e.Result.ItemDimFromIserial && rl.ColorFromId == e.Result.ColorFromId && rl.SizeFrom == e.Result.SizeFrom && rl.BatchNoFrom == e.Result.BatchNoFrom && rl.ColorToId == e.Result.ColorToId && rl.SizeTo == e.Result.SizeTo && rl.BatchNoTo == e.Result.BatchNoTo); if (item != null) { item.ItemDimToIserial = e.Result.ItemDimToIserial; item.AvailableToQuantity = e.Result.AvailableToQuantity; item.PendingToQuantity = e.Result.PendingToQuantity; } else { //item.AvailableToQuantity = 0; //item.PendingToQuantity = 0; } }; WarehouseClient.GetItemGroupCompleted += (s, e) => { foreach (var item in e.Result) { ItemTypes.Add(item); } }; WarehouseClient.GetItemGroupAsync(); }
// update constants in User database to current version defined in EntityConstants public bool VersionConstants(string me) { try { bool updateDB = false; if (Versions.Any(v => v.VersionType == DatabaseVersion.Constants && v.VersionString == UserConstants.ConstantsVersion) == false) { // no database - create and lock the new version entry TraceLog.TraceInfo(String.Format("User database version {0} not found", UserConstants.ConstantsVersion)); // remove an existing database version (there should never be more than one) foreach (var existingVersion in Versions.Where(v => v.VersionType == DatabaseVersion.Constants).ToList()) { Versions.Remove(existingVersion); } SaveChanges(); // create the new version entry DatabaseVersion ver = new DatabaseVersion() { VersionType = DatabaseVersion.Constants, VersionString = UserConstants.ConstantsVersion, Status = me }; Versions.Add(ver); SaveChanges(); updateDB = true; } else { var dbVersion = Versions.Single(v => v.VersionType == DatabaseVersion.Constants && v.VersionString == UserConstants.ConstantsVersion); if (dbVersion.Status == DatabaseVersion.Corrupted) { // try to update the database again - take a lock TraceLog.TraceInfo("User database corrupted"); dbVersion.Status = me; SaveChanges(); updateDB = true; } } if (updateDB == false) { TraceLog.TraceInfo(String.Format("User database version {0} is up to date", UserConstants.ConstantsVersion)); return(true); } } catch (Exception ex) { TraceLog.TraceException("Could not find database version", ex); return(false); } // update the default database values DatabaseVersion version = null; UserStorageContext versionContext = Storage.NewUserContext; try { // verify that this unit of execution owns the update lock for the database version version = versionContext.Versions.Single(v => v.VersionType == DatabaseVersion.Constants && v.VersionString == UserConstants.ConstantsVersion); if (version.Status != me) { return(true); } TraceLog.TraceInfo(String.Format("{0} updating User datatbase to version {1}", me, UserConstants.ConstantsVersion)); // update existing action types, add new action types foreach (var entity in UserConstants.DefaultActionTypes()) { if (ActionTypes.Any(e => e.ActionTypeID == entity.ActionTypeID)) { ActionTypes.Single(e => e.ActionTypeID == entity.ActionTypeID).Copy(entity); } else { ActionTypes.Add(entity); } } SaveChanges(); TraceLog.TraceInfo("Replaced action types"); // update existing colors, add new colors foreach (var entity in UserConstants.DefaultColors()) { if (Colors.Any(e => e.ColorID == entity.ColorID)) { Colors.Single(e => e.ColorID == entity.ColorID).Copy(entity); } else { Colors.Add(entity); } } SaveChanges(); TraceLog.TraceInfo("Replaced colors"); // update existing permissions, add new permissions foreach (var entity in UserConstants.DefaultPermissions()) { if (Permissions.Any(e => e.PermissionID == entity.PermissionID)) { Permissions.Single(e => e.PermissionID == entity.PermissionID).Copy(entity); } else { Permissions.Add(entity); } } SaveChanges(); TraceLog.TraceInfo("Replaced permissions"); // update existing priorities, add new priorities foreach (var entity in UserConstants.DefaultPriorities()) { if (Priorities.Any(e => e.PriorityID == entity.PriorityID)) { Priorities.Single(e => e.PriorityID == entity.PriorityID).Copy(entity); } else { Priorities.Add(entity); } } SaveChanges(); TraceLog.TraceInfo("Replaced priorities"); // update existing or add new built-in users foreach (var user in UserConstants.DefaultUsers()) { if (Users.Any(u => u.ID == user.ID)) { var existing = Users.Single(u => u.ID == user.ID); existing.Name = user.Name; existing.Email = user.Email; existing.CreateDate = user.CreateDate; } else { Users.Add(user); } } SaveChanges(); TraceLog.TraceInfo("Replaced users"); // update existing or add new built-in itemtypes and fields foreach (var itemType in UserConstants.DefaultItemTypes()) { if (ItemTypes.Any(it => it.ID == itemType.ID)) { var existing = ItemTypes.Include("Fields").Single(it => it.ID == itemType.ID); existing.Copy(itemType); if (itemType.Fields == null) { continue; } foreach (var field in itemType.Fields) { if (existing.Fields.Any(f => f.ID == field.ID)) { var existingField = existing.Fields.Single(f => f.ID == field.ID); existingField.Copy(field); } else { existing.Fields.Add(field); } } } else { ItemTypes.Add(itemType); } } SaveChanges(); TraceLog.TraceInfo("Replaced item types and fields"); // save the new version number version.Status = DatabaseVersion.OK; versionContext.SaveChanges(); return(true); } catch (Exception ex) { TraceLog.TraceException("VersionConstants failed", ex); // mark the version as corrupted version.Status = DatabaseVersion.Corrupted; versionContext.SaveChanges(); return(false); } }