예제 #1
0
		/// <summary>
		/// Creates an instance of FilterBoxVmCollection to be used as a collection of guilty operators
		/// </summary>
		/// <param name="models">collection of ODR or OSR models which represent guilty operators</param>
		/// <returns></returns>
		public static FilterBoxVmCollection CreateForGuiltyOperators(dynamic models, Dal.SoheilEdmContext uow)
		{
			//find all active operators
			var operatorDs = new DataServices.OperatorDataService(uow);
			var operatorModels = operatorDs.GetActives();
			
			//create vm for all active operators
			var operatorVms = new FilterableItemVm[operatorModels.Count];
			for (int i = 0; i < operatorVms.Length; i++)
			{
				operatorVms[i] = FilterableItemVm.CreateForGuiltyOperator(operatorModels[i]);
			}

			//initiate this vm to auto-add operatorVms when a new FilterBoxVm is added to it
			var vm = new FilterBoxVmCollection();
			vm.AddCommand = new Commands.Command(o => vm.AddOperator(operatorVms));

			//add new FilterBoxVm for each of guilty operators and select the guilty operator in it
			if (models != null)
			{
				foreach (var model in models)
				{
					vm.AddOperator(operatorVms, model);
				}
			}

			return vm;
		}
예제 #2
0
		/// <summary>
		/// Adds a FilterBoxVm to this collection specialized for guilty operators
		/// </summary>
		/// <param name="operatorVms">ViewModels for operators to be added to the filterBox</param>
		/// <param name="model">Model of an existing ODR or OSR model used to create this FilterBox</param>
		private void AddOperator(FilterableItemVm[] operatorVms, object model = null)
		{
			int operId = 0;
			if (model is Model.OperatorDefectionReport)
			{
				var odr = (model as Model.OperatorDefectionReport);
				operId = odr.Operator.Id;
			}
			else if (model is Model.OperatorStoppageReport)
			{
				var osr = (model as Model.OperatorStoppageReport);
				operId = osr.Operator.Id;
			}


			var fb = FilterBoxVm.CreateForGuiltyOperators(this, operId, operatorVms);
			fb.Model = model;


			fb.FilterableItemSelected += (vm, oldOp, newOp) =>
			{
				if (newOp == null) return;
				if (newOp.Model != null)
				{
					if (OperatorSelected != null)
						OperatorSelected(vm, oldOp, newOp);
				}
			};
			fb.FilterBoxDeleted += vm =>
			{
				if (OperatorRemoved != null)
					OperatorRemoved(vm);
			};

			if (fb.SelectedItem == null) fb.SelectedItem = fb.FilteredList.FirstOrDefault();

			FilterBoxes.Add(fb);
		}
예제 #3
0
		/// <summary>
		/// Creates an instance of FilterableItemVm for cause provided by the given model
		/// <para>This constructor needs a <see cref="FilterBoxVm"/> as parent</para>
		/// </summary>
		/// <param name="model">model of cause to use in this vm</param>
		/// <returns></returns>
		public static FilterableItemVm CreateForCause(FilterBoxVm parent, Model.Cause model)
		{
			var vm = new FilterableItemVm(model.Id, model.Name, new CauseVm(model));
			vm.Parent = parent;
			return vm;
		}
예제 #4
0
		/// <summary>
		/// Creates an instance of FilterableItemVm for product defection provided by the given model
		/// <para>This constructor needs a <see cref="FilterBoxVm"/> as parent</para>
		/// </summary>
		/// <param name="model">model of product defection to use in this vm</param>
		/// <returns></returns>
		public static FilterableItemVm CreateForProductDefection(FilterBoxVm parent, Model.ProductDefection model)
		{
			var vm = new FilterableItemVm(model.Id, model.Defection.Name, new DefectionVm(model));
			vm.Parent = parent;
			return vm;
		}
예제 #5
0
		/// <summary>
		/// Creates an instance of FilterableItemVm for guilty operator provided by the given model
		/// <para>This constructor does not set the Parent so remember to set it manually</para>
		/// </summary>
		/// <param name="model">model of operator to use in this vm</param>
		/// <returns></returns>
		public static FilterableItemVm CreateForGuiltyOperator(Model.Operator model)
		{
			var vm = new FilterableItemVm(model.Id, model.Name);
			vm.Model = model;
			return vm;
		}
예제 #6
0
		/// <summary>
		/// Creates an instance of FilterBoxVm to be used as a collection of operators
		/// </summary>
		/// <param name="parent">collection of FilterBoxVm that this vm is a part of</param>
		/// <param name="selectedId">Id of defection that is selected by default</param>
		/// <param name="list">array of FilterableItemVm instances as children of this vm</param>
		/// <returns></returns>
		public static FilterBoxVm CreateForGuiltyOperators(FilterBoxVmCollection parent, int selectedId, FilterableItemVm[] list)
		{
			var vm = new FilterBoxVm();
			vm._parent = parent;
			foreach (var item in list)
			{
				item.Parent = vm;
				vm.FilteredList.Add(item);
			}

			//select the default operator
			vm.SelectedItem = vm.FilteredList.FirstOrDefault(x => x.Id == selectedId);
			return vm;
		}