Esempio n. 1
0
        public AccessRulePositionsVM(AccessRuleVM accessRule, AccessType access)
            : base(access)
        {
            UnitOfWork = new SoheilEdmContext();
            CurrentAccessRule = accessRule;
            AccessRuleDataService = new AccessRuleDataService(UnitOfWork);
            AccessRuleDataService.PositionAdded += OnPositionAdded;
            AccessRuleDataService.PositionRemoved += OnPositionRemoved;
            PositionDataService = new PositionDataService(UnitOfWork);

            var selectedVms = new ObservableCollection<PositionAccessRuleVM>();
            foreach (var accessRulePosition in AccessRuleDataService.GetPositions(accessRule.Id))
            {
                selectedVms.Add(new PositionAccessRuleVM(accessRulePosition, Access, RelationDirection.Reverse));
            }
            SelectedItems = new ListCollectionView(selectedVms);

            var allVms = new ObservableCollection<PositionVM>();
            foreach (var position in PositionDataService.GetActives())
            {
                allVms.Add(new PositionVM(position, Access,PositionDataService));
            }
            AllItems = new ListCollectionView(allVms);

            IncludeCommand = new Command(Include,CanInclude);
            ExcludeCommand = new Command(Exclude,CanExclude);
        }
Esempio n. 2
0
		public MachineStationsVM(MachineVM machine, AccessType access)
			: base(access)
		{
            UnitOfWork = new SoheilEdmContext();
			CurrentMachine = machine;
            MachineDataService = new MachineDataService(UnitOfWork);
			MachineDataService.StationAdded += OnStationAdded;
			MachineDataService.StationRemoved += OnStationRemoved;
            StationDataService = new StationDataService(UnitOfWork);

			var selectedVms = new ObservableCollection<StationMachineVM>();
			foreach (var stationMachine in MachineDataService.GetStations(machine.Id))
			{
				selectedVms.Add(new StationMachineVM(stationMachine, Access, StationMachineDataService, RelationDirection.Reverse));
			}
			SelectedItems = new ListCollectionView(selectedVms);

            var allVms = new ObservableCollection<StationVM>();
            foreach (var station in StationDataService.GetActives(SoheilEntityType.Machines, CurrentMachine.Id))
            {
                allVms.Add(new StationVM(station, Access, StationDataService));
            }
            AllItems = new ListCollectionView(allVms);

			IncludeCommand = new Command(Include, CanInclude);
			ExcludeCommand = new Command(Exclude, CanExclude);
		}
Esempio n. 3
0
        public AccessRuleUsersVM(AccessRuleVM accessRule, AccessType access)
            : base(access)
        {
            UnitOfWork = new SoheilEdmContext();
            CurrentAccessRule = accessRule;
            AccessRuleDataService = new AccessRuleDataService(UnitOfWork);
            AccessRuleDataService.UserAdded += OnUserAdded;
            AccessRuleDataService.UserRemoved += OnUserRemoved;
            UserDataService = new UserDataService(UnitOfWork);

            var selectedVms = new ObservableCollection<UserAccessRuleVM>();
            foreach (var accessRuleUser in AccessRuleDataService.GetUsers(accessRule.Id))
            {
                selectedVms.Add(new UserAccessRuleVM(accessRuleUser, Access, RelationDirection.Reverse));
            }
            SelectedItems = new ListCollectionView(selectedVms);

            var allVms = new ObservableCollection<UserVM>();
            foreach (var user in UserDataService.GetActives())
            {
                allVms.Add(new UserVM(user, Access, UserDataService));
            }
            AllItems = new ListCollectionView(allVms);

            IncludeCommand = new Command(Include,CanInclude);
            ExcludeCommand = new Command(Exclude, CanExclude);
        }
Esempio n. 4
0
		internal static void CorrectStates()
		{
			int c = 0;
			Console.ForegroundColor = ConsoleColor.Yellow;
			Console.WriteLine("4. Fix all missing mainProduct refs in all states in db");
			Console.ForegroundColor = ConsoleColor.DarkGray;

			//actual db shit
			using (var ctx = new SoheilEdmContext())
			{
				var repo = new Repository<FPC>(ctx);
				var all = repo.GetAll();
				foreach (var fpc in all)
				{
					foreach (var state in fpc.States.Where(x => x.StateType == Soheil.Common.StateType.Mid))
					{
						if (state.OnProductRework == null)
						{
							state.OnProductRework = fpc.Product.MainProductRework;
							c++;
							Console.WriteLine(string.Format("FPC with ID {0} : State with ID {1} corrected.", fpc.Id, state.Id));
						}
					}
				}
				ctx.Commit();
			}

			//result
			Console.ForegroundColor = ConsoleColor.Green;
			Console.WriteLine(string.Format("{0} States corrected successfully.", c));
		}
        public FishboneNodeActionPlansVM(FishboneNodeVM defection, AccessType access)
            : base(access)
        {
            UnitOfWork = new SoheilEdmContext();
            CurrentFishboneNode = defection;
            FishboneNodeDataService = new FishboneNodeDataService(UnitOfWork);
            FishboneNodeDataService.ActionPlanAdded += OnActionPlanAdded;
            FishboneNodeDataService.ActionPlanRemoved += OnActionPlanRemoved;
            ActionPlanDataService = new ActionPlanDataService(UnitOfWork);

            var selectedVms = new ObservableCollection<ActionPlanFishboneVM>();
            foreach (var productFishboneNode in FishboneNodeDataService.GetActionPlans(defection.Id))
            {
                selectedVms.Add(new ActionPlanFishboneVM(productFishboneNode, Access, RelationDirection.Reverse));
            }
            SelectedItems = new ListCollectionView(selectedVms);

            var allVms = new ObservableCollection<ActionPlanVM>();
            foreach (var actionPlan in ActionPlanDataService.GetActives())
            {
                allVms.Add(new ActionPlanVM(actionPlan, Access, ActionPlanDataService));
            }
            AllItems = new ListCollectionView(allVms);

            IncludeCommand = new Command(Include, CanInclude);
            ExcludeCommand = new Command(Exclude, CanExclude);
        }
Esempio n. 6
0
        public ActionPlanFishbonesVM(ActionPlanVM actionPlan, AccessType access)
            : base(access)
        {
            UnitOfWork = new SoheilEdmContext();
            CurrentActionPlan = actionPlan;
            ActionPlanDataService = new ActionPlanDataService(UnitOfWork);
            ActionPlanDataService.FishboneNodeAdded += OnFishboneNodeAdded;
            ActionPlanDataService.FishboneNodeRemoved += OnFishboneNodeRemoved;
            FishboneActionPlanDataService = new FishboneActionPlanDataService(UnitOfWork);
            FishboneNodeDataService = new FishboneNodeDataService(UnitOfWork);

            var selectedVms = new ObservableCollection<ActionPlanFishboneVM>();
            foreach (var fishboneNodeActionPlan in ActionPlanDataService.GetFishboneNodes(actionPlan.Id))
            {
                selectedVms.Add(new ActionPlanFishboneVM(fishboneNodeActionPlan,access,RelationDirection.Straight));
            }
            SelectedItems = new ListCollectionView(selectedVms);

            var allVms = new ObservableCollection<FishboneNodeVM>();
            foreach (var fishboneNode in FishboneNodeDataService.GetActives())
            {
                allVms.Add(new FishboneNodeVM(fishboneNode, Access, FishboneNodeDataService));
            }
            AllItems = new ListCollectionView(allVms);

            IncludeCommand = new Command(Include, CanInclude);
            ExcludeCommand = new Command(Exclude, CanExclude);
        }
Esempio n. 7
0
        public OperatorActivitiesVM(OperatorVM opr, AccessType access) : base(access)
        {
            UnitOfWork = new SoheilEdmContext();
            CurrentOperator = opr;
            OperatorDataService = new OperatorDataService(UnitOfWork);
            OperatorDataService.ActivityAdded += OnActivityAdded;
            OperatorDataService.ActivityRemoved += OnActivityRemoved;
            ActivityDataService = new ActivityDataService(UnitOfWork);
            ActivityOperatorDataService = new ActivitySkillDataService(UnitOfWork);
            ActivityGroupDataService = new ActivityGroupDataService(UnitOfWork);

            var selectedVms = new ObservableCollection<ActivityOperatorVM>();
            foreach (var generalActivitySkill in OperatorDataService.GetActivities(opr.Id))
            {
                selectedVms.Add(new ActivityOperatorVM(generalActivitySkill, Access, ActivityOperatorDataService, RelationDirection.Reverse));
            }
            SelectedItems = new ListCollectionView(selectedVms);

            var allVms = new ObservableCollection<ActivityVM>();
            foreach (var activity in ActivityDataService.GetActives()
				.Where(activity => !selectedVms.Any(activityOperator => activityOperator.ActivityId == activity.Id)))
            {
                allVms.Add(new ActivityVM(activity, Access, ActivityDataService, ActivityGroupDataService));
            }
            AllItems = new ListCollectionView(allVms);

            IncludeCommand = new Command(Include, CanInclude);
            ExcludeCommand = new Command(Exclude, CanExclude);
            
        }
Esempio n. 8
0
        public PositionUsersVM(PositionVM position, AccessType access)
            : base(access)
        {
            UnitOfWork = new SoheilEdmContext();
            CurrentPosition = position;
            PositionDataService = new PositionDataService(UnitOfWork);
            PositionDataService.UserAdded += OnUserAdded;
            PositionDataService.UserRemoved += OnUserRemoved;
            UserDataService = new UserDataService(UnitOfWork);

            var selectedVms = new ObservableCollection<UserPositionVM>();
            foreach (var positionUser in PositionDataService.GetUsers(position.Id))
            {
                selectedVms.Add(new UserPositionVM(positionUser, Access, RelationDirection.Reverse));
            }
            SelectedItems = new ListCollectionView(selectedVms);

            var allVms = new ObservableCollection<UserVM>();
            foreach (var user in UserDataService.GetActives(SoheilEntityType.Positions, CurrentPosition.Id))
            {
                allVms.Add(new UserVM(user, Access, UserDataService));
            }
            AllItems = new ListCollectionView(allVms);

            IncludeCommand = new Command(Include, CanInclude);
            ExcludeCommand = new Command(Exclude, CanExclude);
            
        }
Esempio n. 9
0
        public UserPositionsVM(UserVM user, AccessType access)
            : base(access)
        {
            UnitOfWork = new SoheilEdmContext();
            CurrentUser = user;
            UserDataService = new UserDataService(UnitOfWork);
            PositionDataService = new PositionDataService(UnitOfWork);
            AccessRuleDataService = new AccessRuleDataService(UnitOfWork);
            UserDataService.PositionAdded += OnPositionAdded;
            UserDataService.PositionRemoved += OnPositionRemoved;


            var selectedVms = new ObservableCollection<UserPositionVM>();
            foreach (var userPosition in UserDataService.GetPositions(user.Id))
            {
                selectedVms.Add(new UserPositionVM(userPosition, Access, RelationDirection.Straight));
            }
            SelectedItems = new ListCollectionView(selectedVms);

            var allVms = new ObservableCollection<PositionVM>();
            foreach (var position in PositionDataService.GetActives(SoheilEntityType.Users, CurrentUser.Id))
            {
                allVms.Add(new PositionVM(position, Access, PositionDataService));
            }
            AllItems = new ListCollectionView(allVms);

            //AllItems = new ListCollectionView(PositionDataService.GetActives());
            IncludeCommand = new Command(Include, CanInclude);
            ExcludeCommand = new Command(Exclude, CanExclude);
        }
Esempio n. 10
0
        private void InitializeData()
        {
            UnitOfWork = new SoheilEdmContext();
            PartWarehouseGroupDataService = new PartWarehouseGroupDataService(UnitOfWork);
            PartWarehouseDataService = new PartWarehouseDataService(UnitOfWork);
            PartWarehouseDataService.PartWarehouseAdded += OnPartWarehouseAdded;
            PartWarehouseGroupDataService.PartWarehouseGroupAdded += OnPartWarehouseGroupAdded;


            ColumnHeaders = new List<ColumnInfo> 
            { 
                new ColumnInfo("Code",0), 
                new ColumnInfo("Name",1), 
                new ColumnInfo("Quantity","txtQuantity",2,true), 
                new ColumnInfo("TotalCost","txtCost",3,true),
                new ColumnInfo("Status",4) ,
                new ColumnInfo("Mode",5,true) 
            };

            AddCommand = new Command(Add, CanAdd);RefreshCommand = new Command(CreateItems);
            AddGroupCommand = new Command(AddGroup);
            ViewCommand = new Command(View, CanView);

            CreateItems(null);
        }
        public PositionOrganizationChartsVM(PositionVM position, AccessType access)
            : base(access)
        {
            UnitOfWork = new SoheilEdmContext();
            CurrentPosition = position;
            PositionDataService = new PositionDataService(UnitOfWork);
            PositionDataService.OrganizationChartAdded += OnOrganizationChartAdded;
            PositionDataService.OrganizationChartRemoved += OnOrganizationChartRemoved;
            OrganizationChartDataService = new OrganizationChartDataService(UnitOfWork);
            OrganizationChartPositionDataService = new OrganizationChartPositionDataService(UnitOfWork);

            var selectedVms = new ObservableCollection<OrganizationChartPositionVM>();
            foreach (var positionOrganizationChart in PositionDataService.GetOrganizationCharts(position.Id))
            {
                selectedVms.Add(new OrganizationChartPositionVM(positionOrganizationChart, Access, OrganizationChartPositionDataService));
            }
            SelectedItems = new ListCollectionView(selectedVms);

            var allVms = new ObservableCollection<OrganizationChartVM>();
            foreach (var organizationChart in OrganizationChartDataService.GetActives())
            {
                allVms.Add(new OrganizationChartVM(organizationChart, Access, OrganizationChartDataService));
            }
            AllItems = new ListCollectionView(allVms);

            IncludeCommand = new Command(Include, CanInclude);
            ExcludeCommand = new Command(Exclude, CanExclude);
            
        }
Esempio n. 12
0
        public DefectionProductsVM(DefectionVM defection, AccessType access)
            : base(access)
        {
            UnitOfWork = new SoheilEdmContext();
            CurrentDefection = defection;
            DefectionDataService = new DefectionDataService(UnitOfWork);
            DefectionDataService.ProductAdded += OnProductAdded;
            DefectionDataService.ProductRemoved += OnProductRemoved;
            ProductDataService = new ProductDataService(UnitOfWork);
            ProductGroupDataService = new ProductGroupDataService(UnitOfWork);
            ProductDefectionDataService = new ProductDefectionDataService(UnitOfWork);

            var selectedVms = new ObservableCollection<ProductDefectionVM>();
            foreach (var productDefection in DefectionDataService.GetProducts(defection.Id))
            {
                selectedVms.Add(new ProductDefectionVM(productDefection, Access, ProductDefectionDataService, RelationDirection.Reverse));
            }
            SelectedItems = new ListCollectionView(selectedVms);

            var allVms = new ObservableCollection<ProductVM>();
            foreach (var product in ProductDataService.GetActives(SoheilEntityType.Defections, CurrentDefection.Id))
            {
                allVms.Add(new ProductVM(product, Access, ProductDataService, ProductGroupDataService));
            }
            AllItems = new ListCollectionView(allVms);

            IncludeCommand = new Command(Include, CanInclude);
            ExcludeCommand = new Command(Exclude, CanExclude);
        }
Esempio n. 13
0
        public ProductDefectionsVM(ProductVM product, AccessType access):base(access)
        {
            UnitOfWork = new SoheilEdmContext();
            CurrentProduct = product;
            ProductDataService = new ProductDataService(UnitOfWork);
            ProductDataService.DefectionAdded += OnDefectionAdded;
            ProductDataService.DefectionRemoved += OnDefectionRemoved;
            DefectionDataService = new DefectionDataService(UnitOfWork);
            ProductDefectionDataService = new ProductDefectionDataService(UnitOfWork);

            var selectedVms = new ObservableCollection<ProductDefectionVM>();
            foreach (var productDefection in ProductDataService.GetDefections(product.Id))
            {
                selectedVms.Add(new ProductDefectionVM(productDefection, Access, ProductDefectionDataService, RelationDirection.Straight));
            }
            SelectedItems = new ListCollectionView(selectedVms);

            var allVms = new ObservableCollection<DefectionVM>();
            foreach (var defection in DefectionDataService.GetActives(SoheilEntityType.Products, CurrentProduct.Id))
            {
                allVms.Add(new DefectionVM(defection, Access, DefectionDataService));
            }
            AllItems = new ListCollectionView(allVms);

            IncludeCommand = new Command(Include, CanInclude);
            ExcludeCommand = new Command(Exclude, CanExclude);
            IncludeRangeCommand = new Command(IncludeRange, CanIncludeRange);
            ExcludeRangeCommand = new Command(ExcludeRange, CanExcludeRange);
        }
Esempio n. 14
0
        public ActivityOperatorsVM(ActivityVM activity, AccessType access)
            : base(access)
        {
            UnitOfWork = new SoheilEdmContext();
            CurrentActivity = activity;
            ActivityDataService = new ActivityDataService(UnitOfWork);
            ActivityDataService.OperatorAdded += OnOperatorAdded;
            ActivityDataService.OperatorRemoved += OnOperatorRemoved;
            OperatorDataService = new OperatorDataService(UnitOfWork);
            ActivityOperatorDataService = new ActivitySkillDataService(UnitOfWork);

            var selectedVms = new ObservableCollection<ActivityOperatorVM>();
            foreach (var activityOperator in ActivityDataService.GetOperators(activity.Id))
            {
                selectedVms.Add(new ActivityOperatorVM(activityOperator, Access, ActivityOperatorDataService, RelationDirection.Straight));
            }
            SelectedItems = new ListCollectionView(selectedVms);

            var allVms = new ObservableCollection<OperatorVM>();
            foreach (var opr in OperatorDataService.GetActives(SoheilEntityType.Activities, CurrentActivity.Id))
            {
                allVms.Add(new OperatorVM(opr, Access, OperatorDataService));
            }
            AllItems = new ListCollectionView(allVms);

            IncludeCommand = new Command(Include, CanInclude);
            ExcludeCommand = new Command(Exclude, CanExclude);
        }
 public int GetProductCount()
 {
     int count;
     using (var context = new SoheilEdmContext())
     {
         var repository = new Repository<Product>(context);
         count = repository.GetAll().Count();
     }
     return count;
 }
Esempio n. 16
0
 public int GetMachineCount()
 {
     int machineCount;
     using (var context = new SoheilEdmContext())
     {
         var machineRepository = new Repository<Machine>(context);
         machineCount = machineRepository.GetAll().Count();
     }
     return machineCount;
 }
 public int GetCostsCount(int costCenterId)
 {
     int count;
     using (var context = new SoheilEdmContext())
     {
         var repository = new Repository<Cost>(context);
         count = repository.Find(item=>item.CostCenter != null && item.CostCenter.Id == costCenterId).Count();
     }
     return count;
 }
 public int GetCostCentersCount()
 {
     int count;
     using (var context = new SoheilEdmContext())
     {
         var repository = new Repository<CostCenter>(context);
         count = repository.GetAll().Count();
     }
     return count;
 }
Esempio n. 19
0
        private void InitializeData()
        {
            UnitOfWork = new SoheilEdmContext();
            CauseDataService = new CauseDataService(UnitOfWork);
            CauseDataService.CauseAdded += OnCauseAdded;
            CauseDataService.CauseUpdated += OnCauseUpdated;

            AddCommand = new Command(Add, CanAdd);RefreshCommand = new Command(CreateItems);
            AddGroupCommand = new Command(Add, CanAddGroup);
            ViewCommand = new Command(View, CanView);

            CreateItems(null);
        }
Esempio n. 20
0
        private IList<Record> GetCostsByDate(DateTimeIntervals intervalType, CostType type, int startIdx, int count)
        {
            IList<Record> records = new List<Record>();
            int currentYear = DateTime.Now.Year;
            var startDate = new DateTime(currentYear, 1, 1);
            startDate = AddInterval(startDate, startIdx, intervalType);
            var currentInterval = startDate;

            using (var context = new SoheilEdmContext())
            {
                var costRepository = new Repository<Cost>(context);

                var costList = costRepository.GetAll();

                var indexList = new List<KeyValuePair<int, double>>();

                for (int i = startIdx; i < count; i++)
                {
                    indexList.AddRange(from cost in costList
                                      where cost.Date >= currentInterval
                                      && cost.Date < AddInterval(currentInterval, 1, intervalType)
                                      && (type == CostType.All || cost.CostType == (decimal) type)
                                      select new KeyValuePair<int, double>(i, cost.CostValue?? 0));
                    indexList.Add(new KeyValuePair<int, double>(i, 0));
                    currentInterval = AddInterval(currentInterval, 1, intervalType);
                }

                var query = from index in indexList
                            group index by index.Key into g
                            let total = g.Sum(item => item.Value)
                            select new { interval = g.Key, value = total};

                for (int i = startIdx; i < count; i++)
                {
                    var newRecord = new Record { Header = i.ToString(CultureInfo.InvariantCulture) };
                    foreach (var line in query)
                    {
                        if (line.interval == i)
                        {
                            newRecord.Id = line.interval;
                            newRecord.Value = line.value;
                            newRecord.StartDate = AddInterval(startDate, i - startIdx, intervalType);
                            newRecord.EndDate = AddInterval(startDate, i - startIdx + 1, intervalType);
                        }
                    }
                    records.Add(newRecord);
                }
            }
            return records;
        }
Esempio n. 21
0
        private void InitializeData()
        {
            UnitOfWork = new SoheilEdmContext();
            AccessRuleDataService = new AccessRuleDataService(UnitOfWork);
            AccessRuleDataService.AccessRuleAdded += OnAccessRuleAdded;

            AddCommand = new Command(Add, CanAdd);RefreshCommand = new Command(CreateItems);
            AddGroupCommand = new Command(Add, CanAddGroup);
            ViewCommand = new Command(View, CanView);

            //var viewModels = AccessRuleDataService.GetAll();
            CreateItems(null);

            //CurrentNode = (ISplitNodeContent) CurrentContent;
        }
Esempio n. 22
0
        private void InitializeData()
        {
            UnitOfWork = new SoheilEdmContext();
            ActionPlanDataService = new ActionPlanDataService(UnitOfWork);
            ActionPlanDataService.ActionPlanAdded += OnActionPlanAdded;

            ColumnHeaders = new List<ColumnInfo> 
            { 
                new ColumnInfo("Code",0), 
                new ColumnInfo("Name",1), 
                new ColumnInfo("Status",2),
                new ColumnInfo("Mode",3,true) 
            };
            AddCommand = new Command(Add, CanAdd);RefreshCommand = new Command(CreateItems);
            AddGroupCommand = new Command(Add, CanAddGroup);
            CreateItems(null);
        }
Esempio n. 23
0
        private void InitializeData()
        {
            UnitOfWork = new SoheilEdmContext();
            OrganizationChartDataService = new OrganizationChartDataService(UnitOfWork);
            OrganizationChartDataService.OrganizationChartAdded += OnOrganizationChartAdded;

            ColumnHeaders = new List<ColumnInfo> 
            { 
                new ColumnInfo("Name",0), 
                new ColumnInfo("Status",1) ,
                new ColumnInfo("Mode",2,true) 
            };

            AddCommand = new Command(Add, CanAdd);RefreshCommand = new Command(CreateItems);
            AddGroupCommand = new Command(Add, CanAddGroup);
            ViewCommand = new Command(View, CanView);
            CreateItems(null);
        }
Esempio n. 24
0
        public UserAccessRulesVM(UserVM user, AccessType access):base(access)
        {
            UnitOfWork = new SoheilEdmContext();
            CurrentUser = user;
            UserDataService = new UserDataService(UnitOfWork);
            UserDataService.AccessRuleChanged += OnAccessRuleChanged;
            AccessRuleDataService = new AccessRuleDataService(UnitOfWork);
            UserAccessRuleDataService = new UserAccessRuleDataService(UnitOfWork);
            PositionAccessRuleDataService = new PositionAccessRuleDataService(UnitOfWork);

            RootNode = new UserAccessNodeVM(Access) { Title = string.Empty, Id = -1, ParentId = -2 };

            var selectedVms = new ObservableCollection<UserAccessNodeVM>();

            var ruleAccessList = AccessRuleDataService.GetPositionsAccessOfUser(user.Id);

            foreach (var accessRule in AccessRuleDataService.GetActives())
            {
                selectedVms.Add(new UserAccessNodeVM(accessRule.Id, user.Id, AccessRuleDataService, UserAccessRuleDataService, ruleAccessList, Access));
            }

            var allVms = new ObservableCollection<AccessRuleVM>();
            foreach (var accessRule in AccessRuleDataService.GetActives())
            {
                allVms.Add(new AccessRuleVM(AccessRuleDataService, accessRule, Access));
            }
            AllItems = new ListCollectionView(allVms);

            IncludeCommand = new Command(Include, CanInclude);
            ExcludeTreeCommand = new Command(ExcludeTree, CanExcludeTree);

            foreach (UserAccessNodeVM item in selectedVms)
            {
                if (item.ParentId == RootNode.Id)
                {
                    RootNode.ChildNodes.Add(item);
                    break;
                }
            }

            CurrentNode = RootNode;
        }
Esempio n. 25
0
        private void InitializeData()
        {
            UnitOfWork = new SoheilEdmContext();
            UserDataService = new UserDataService(UnitOfWork);
            UserDataService.UserAdded += OnUserAdded;

            ColumnHeaders = new List<ColumnInfo> 
            { 
                new ColumnInfo("Code",0), 
                new ColumnInfo("Name",1), 
                new ColumnInfo("Username",2), 
                new ColumnInfo("Status",3) ,
                new ColumnInfo("Mode",4,true) 
            };

            AddCommand = new Command(Add, CanAdd);RefreshCommand = new Command(CreateItems);
            AddGroupCommand = new Command(Add ,CanAddGroup);
            ViewCommand = new Command(View, CanView);
            CreateItems(null);
        }
Esempio n. 26
0
        private void InitializeData()
        {
            UnitOfWork = new SoheilEdmContext();
			FpcDataService = new FPCDataService();
            ProductDataService = new ProductDataService(UnitOfWork);
            ProductGroupDataService = new ProductGroupDataService(UnitOfWork);
			FpcDataService.FpcAdded += OnFpcAdded;

            ColumnHeaders = new List<ColumnInfo> 
            { 
                new ColumnInfo("Code",0), 
                new ColumnInfo("Name",1), 
                new ColumnInfo("Status",2) ,
                new ColumnInfo("Mode",3,true) 
            };

            AddCommand = new Command(Add, CanAdd);
			RefreshCommand = new Command(CreateItems);
            AddGroupCommand = new Command(Add, () => false);
            CreateItems(null);
        }
        public OrganizationChartPositionsVM(OrganizationChartVM organizationChart, AccessType access):base(access)
        {
            UnitOfWork = new SoheilEdmContext();
            CurrentOrganizationChart = organizationChart;
            OrganizationChartDataService = new OrganizationChartDataService(UnitOfWork);
            OrganizationChartDataService.PositionAdded += OnPositionAdded;
            OrganizationChartDataService.PositionRemoved += OnPositionRemoved;
            PositionDataService = new PositionDataService(UnitOfWork);
            OrganizationChartPositionDataService = new OrganizationChartPositionDataService(UnitOfWork);

            RootNode = new OrganizationChartPositionVM(Access, OrganizationChartPositionDataService) { Title = string.Empty, Id = -1, ParentId = -2 };

            var selectedVms = new ObservableCollection<OrganizationChartPositionVM>();
            foreach (var organizationChartPosition in OrganizationChartDataService.GetPositions(organizationChart.Id))
            {
                selectedVms.Add(new OrganizationChartPositionVM(organizationChartPosition, Access, OrganizationChartPositionDataService));
            }

            var allVms = new ObservableCollection<PositionVM>();
            foreach (var position in PositionDataService.GetActives(SoheilEntityType.OrganizationCharts, CurrentOrganizationChart.Id))
            {
                allVms.Add(new PositionVM(position, Access, PositionDataService));
            }
            AllItems = new ListCollectionView(allVms);

            IncludeCommand = new Command(Include, CanInclude);
            ExcludeTreeCommand = new Command(ExcludeTree, CanExcludeTree);


            foreach (OrganizationChartPositionVM item in selectedVms)
            {
                if (item.ParentId == RootNode.Id)
                {
                    RootNode.ChildNodes.Add(item);
                    break;
                }
            }

            CurrentNode = RootNode;
        }
Esempio n. 28
0
        public StationMachinesVM(StationVM station, AccessType access):base(access)
        {
            UnitOfWork = new SoheilEdmContext();
            CurrentStation = station;
            StationDataService = new StationDataService(UnitOfWork);
            StationDataService.MachineAdded += OnMachineAdded;
            StationDataService.MachineRemoved += OnMachineRemoved;
            MachineDataService = new MachineDataService(UnitOfWork);
            StationMachineDataService = new StationMachineDataService(UnitOfWork);
            MachineFamilyDataService = new MachineFamilyDataService(UnitOfWork);

            var selectedVms = new ObservableCollection<StationMachineVM>();
            foreach (var stationMachine in StationDataService.GetMachines(station.Id))
            {
                selectedVms.Add(new StationMachineVM(stationMachine, Access, StationMachineDataService, RelationDirection.Straight));
            }
            SelectedItems = new ListCollectionView(selectedVms);

            var allVms = new ObservableCollection<MachineVM>();
            foreach (var machine in MachineDataService.GetActives()
				.Where(machine => !selectedVms.Any(stationMachine => stationMachine.MachineId == machine.Id)))
            {
                allVms.Add(new MachineVM(machine, Access, MachineDataService, MachineFamilyDataService));
            }
            AllItems = new ListCollectionView(allVms);

            IncludeCommand = new Command(Include, CanInclude);
            ExcludeCommand = new Command(Exclude, CanExclude);
			IncludeAllCommand = new Command(o =>
			{
				foreach (var vm in allVms.ToArray())
				{
					StationDataService.AddMachine(CurrentStation.Id, ((IEntityItem)vm).Id);
				}
			}, () => allVms.Any());
        }
        private double GetMaxCostByCostCenters(CostBarInfo indexInfo, CostType type, int count)
        {
            using (var context = new SoheilEdmContext())
            {
                var costRepository = new Repository<Cost>(context);
                var costCenterRepository = new Repository<CostCenter>(context);

                var costList = costRepository.GetAll().ToList();
                var costCenterList = costCenterRepository.GetAll().ToList();

                var indexList = costCenterList.Select((cc, index) => new { interval = index, cc.Id, cc.Name });

                var ccQuery = from index in indexList
                              from cost in costList.Where(c => c.CostCenter != null && c.CostCenter.Id == index.Id
                                  && c.Date >= indexInfo.StartDate && c.Date < indexInfo.EndDate
                                  && (type == (decimal)CostType.All || c.CostType == (decimal)type)).DefaultIfEmpty()
                              select new { index.interval, index.Id, index.Name, Value = cost == null ? 0 : cost.CostValue ?? 0 };

                var query = from costCenter in ccQuery
                            group costCenter by new { costCenter.interval, costCenter.Id, costCenter.Name } into g
                            let total = g.Sum(item => item.Value)
                            select new { g.Key.interval, g.Key.Id, g.Key.Name, value = total };

                return query.Max(item => item.value);
            }
        }
        private IList<Record> GetCostsByDate(DateTimeIntervals intervalType, CostBarInfo barInfo, int startIdx, int count)
        {
            IList<Record> records = new List<Record>();
            int currentYear = DateTime.Now.Year;
            var startDate = new DateTime(currentYear, 1, 1);
            startDate = AddInterval(startDate, startIdx, intervalType);
            var currentInterval = startDate;

            using (var context = new SoheilEdmContext())
            {
                var costRepository = new Repository<Cost>(context);
                var costCenterRepository = new Repository<CostCenter>(context);
                var ssamRepository = new Repository<StateStationActivityMachine>(context);
                var ssaRepository = new Repository<StateStationActivity>(context);
                var processRepository = new Repository<Process>(context);
                var processReportRepository = new Repository<ProcessReport>(context);
                var taskReportRepository = new Repository<TaskReport>(context);
                var processOperatortRepository = new Repository<ProcessOperator>(context);
                var stateStationRepository = new Repository<StateStation>(context);
                var stateRepository = new Repository<State>(context);
                var fpcRepository = new Repository<FPC>(context);
                var productRepository = new Repository<Product>(context);

                var costList = costRepository.GetAll().ToList();
                var costCenterList = costCenterRepository.GetAll().ToList();
                var ssamList = ssamRepository.GetAll().ToList();
                var processList = processRepository.GetAll().ToList();
                var processReportList = processReportRepository.GetAll().ToList();
                var taskReportList = taskReportRepository.GetAll().ToList();
                var processOperatortList = processOperatortRepository.GetAll().ToList();
                var ssaList = ssaRepository.GetAll().ToList();
                var stateStationList = stateStationRepository.GetAll().ToList();
                var stateList = stateRepository.GetAll().ToList();
                var fpcList = fpcRepository.GetAll().ToList();
                var productList = productRepository.GetAll().ToList();

                // List of all products in range
                var indexList = new List<KeyValuePair<int, int>>();

                for (int i = startIdx; i < count; i++)
                {
                    indexList.AddRange(from taskReport in taskReportList
                                       where taskReport.ReportStartDateTime >= currentInterval
                                       && taskReport.ReportStartDateTime < AddInterval(currentInterval, 1, intervalType)
                                       select new KeyValuePair<int, int>(i, taskReport.Id));
                    indexList.Add(new KeyValuePair<int, int>(i, -1));
                    currentInterval = AddInterval(currentInterval, 1, intervalType);
                }

                // Products duration
                var productDurationQuery = from index in indexList
                                           from taskReport in taskReportList.Where(tr => tr.Id == index.Value).DefaultIfEmpty()
                                           from processReport in processReportList.Where(pr => pr.TaskReport != null && taskReport != null && pr.TaskReport.Id == taskReport.Id).DefaultIfEmpty()
                                           from process in processList.Where(p => processReport != null && processReport.Process != null && p.Id == processReport.Process.Id).DefaultIfEmpty()
                                           from processOpr in processOperatortList.Where(po => process != null && po.Process != null && po.Process.Id == process.Id).DefaultIfEmpty()
                                           from ssActivity in ssaList.Where(ssa => process != null && process.StateStationActivity != null && ssa.Id == process.StateStationActivity.Id).DefaultIfEmpty()
                                           from ssaMachine in ssamList.Where(ssam => ssActivity != null && ssam.StateStationActivity != null && ssActivity.Id == ssam.StateStationActivity.Id).DefaultIfEmpty()
                                           from stateStation in stateStationList.Where(ss => ssActivity != null && ssActivity.StateStation != null && ss.Id == ssActivity.StateStation.Id).DefaultIfEmpty()
                                           from state in stateList.Where(s => stateStation != null && stateStation.State != null && s.Id == stateStation.State.Id).DefaultIfEmpty()
                                           from fpc in fpcList.Where(f => state != null && state.FPC != null && state.FPC.Id == f.Id).DefaultIfEmpty()
                                           from product in productList.Where(p => fpc != null && fpc.Product != null && p.Id == fpc.Product.Id).DefaultIfEmpty()
                                           let productId = product == null ? -1 : product.Id
                                           let stationId = stateStation == null ? -1 : (stateStation.Station == null ? -1 : stateStation.Station.Id)
                                           let machineId = ssaMachine == null ? -1 : (ssaMachine.Machine == null ? -1 : ssaMachine.Machine.Id)
                                           let activityId = ssActivity == null ? -1 : (ssActivity.Activity == null ? -1 : ssActivity.Activity.Id)
                                           let operatorId = processOpr == null ? -1 : (processOpr.Operator == null ? -1 : processOpr.Operator.Id)
                                           let start = taskReport == null ? DateTime.MinValue : taskReport.ReportStartDateTime
                                           let end = taskReport == null ? DateTime.MinValue : taskReport.ReportEndDateTime
                                           let duration = taskReport == null ? 0 : taskReport.ReportDurationSeconds
                                           select new { interval = index.Key, productId, stationId, machineId, activityId, operatorId, start, end, duration };

                // Cost centers totals
                var productDurationList = productDurationQuery.ToList();
                var productCostByStationQuery = from product in productDurationList
                                                from cost in costList.Where(c => c.Station != null && c.Station.Id == product.stationId
                                                    && c.Date >= product.start && c.Date < product.end).DefaultIfEmpty()
                                                let productId = product == null ? -1 : product.productId
                                                let stationId = product == null ? -1 : product.stationId
                                                let productDuration = product == null ? 0 : product.duration
                                                let stationCost = cost == null ? 0 : cost.CostValue
                                                select new { product.interval, productId, stationId, productDuration, stationCost };

                var costByStationList = productCostByStationQuery.ToList();
                var sTotalByProductQuery = from station in costByStationList
                                           group station by station.stationId into g
                                           select new { g.Key, stationTotal = g.Sum(item => item.stationCost) };

                var stationCostByProductQuery = from product in costByStationList
                                                from station in sTotalByProductQuery.Where(s => s.Key == product.stationId).DefaultIfEmpty()
                                                let productId = product == null ? -1 : product.productId
                                                let stationId = product == null ? -1 : product.stationId
                                                let productDuration = product == null ? 0 : product.productDuration
                                                let stationCost = station == null ? 0 : station.stationTotal
                                                select new { product.interval, productId, stationId, productDuration, stationCost };

                var productCostByMachineQuery = from product in productDurationList
                                                from cost in costList.Where(c => c.Machine != null && c.Machine.Id == product.machineId
                                                                            && c.Date >= product.start && c.Date < product.end).DefaultIfEmpty()
                                                let productId = product == null ? -1 : product.productId
                                                let machineId = product == null ? -1 : product.machineId
                                                let productDuration = product == null ? 0 : product.duration
                                                let machineCost = cost == null ? 0 : cost.CostValue
                                                select new { product.interval, productId, machineId, productDuration, machineCost };

                var costByMachineList = productCostByMachineQuery.ToList();
                var mTotalByProductQuery = from machine in costByMachineList
                                           group machine by machine.machineId into g
                                           select new { g.Key, machineTotal = g.Sum(item => item.machineCost) };

                var machineCostByProductQuery = from product in costByMachineList
                                                from machine in mTotalByProductQuery.Where(s => s.Key == product.machineId).DefaultIfEmpty()
                                                let productId = product == null ? -1 : product.productId
                                                let machineId = product == null ? -1 : product.machineId
                                                let productDuration = product == null ? 0 : product.productDuration
                                                let machineCost = machine == null ? 0 : machine.machineTotal
                                                select new { product.interval, productId, machineId, productDuration, machineCost };

                var productCostByActivityQuery = from product in productDurationList
                                                 from cost in costList.Where(c => c.Activity != null && c.Activity.Id == product.activityId
                                                                            && c.Date >= product.start && c.Date < product.end).DefaultIfEmpty()
                                                 let productId = product == null ? -1 : product.productId
                                                 let activityId = product == null ? -1 : product.activityId
                                                 let productDuration = product == null ? 0 : product.duration
                                                 let activityCost = cost == null ? 0 : cost.CostValue
                                                 select new { product.interval, productId, activityId, productDuration, activityCost };

                var costByActivityList = productCostByActivityQuery.ToList();
                var aTotalByProductQuery = from activity in costByActivityList
                                           group activity by activity.activityId into g
                                           select new { g.Key, activityTotal = g.Sum(item => item.activityCost) };

                var activityCostByProductQuery = from product in costByActivityList
                                                 from activity in aTotalByProductQuery.Where(s => s.Key == product.activityId).DefaultIfEmpty()
                                                 let productId = product == null ? -1 : product.productId
                                                 let activityId = product == null ? -1 : product.activityId
                                                 let productDuration = product == null ? 0 : product.productDuration
                                                 let activityCost = activity == null ? 0 : activity.activityTotal
                                                 select new { product.interval, productId, activityId, productDuration, activityCost };

                var productCostByOperatorQuery = from product in productDurationList
                                                 from cost in costList.Where(c => c.Operator != null && c.Operator.Id == product.operatorId
                                                                            && c.Date >= product.start && c.Date < product.end).DefaultIfEmpty()
                                                 let productId = product == null ? -1 : product.productId
                                                 let operatorId = product == null ? -1 : product.operatorId
                                                 let productDuration = product == null ? 0 : product.duration
                                                 let operatorCost = cost == null ? 0 : cost.CostValue
                                                 select new { product.interval, productId, operatorId, productDuration, operatorCost };

                var costByOperatorList = productCostByOperatorQuery.ToList();
                var oTotalByProductQuery = from opr in costByOperatorList
                                           group opr by opr.operatorId into g
                                           select new { g.Key, operatorTotal = g.Sum(item => item.operatorCost) };

                var operatorCostByProductQuery = from product in costByOperatorList
                                                 from opr in oTotalByProductQuery.Where(s => s.Key == product.operatorId).DefaultIfEmpty()
                                                 let productId = product == null ? -1 : product.productId
                                                 let operatorId = product == null ? -1 : product.operatorId
                                                 let productDuration = product == null ? 0 : product.productDuration
                                                 let operatorCost = opr == null ? 0 : opr.operatorTotal
                                                 select new { product.interval, productId, operatorId, productDuration, operatorCost };

                var productCostByMiscQuery = from product in productDurationList
                                             from costCenter in costCenterList.Where(cc=> cc.SourceType == (decimal) CostSourceType.Other).DefaultIfEmpty()
                                                 from cost in costList.Where(c=> c.CostCenter.Id == costCenter.Id && c.CostCenter != null && costCenter != null
                                                     && c.Date >= product.start && c.Date < product.end).DefaultIfEmpty()
                                                 let productId = product == null ? -1 : product.productId
                                                 let productDuration = product == null ? 0 : product.duration
                                                 let miscCost = cost == null ? 0 : cost.CostValue
                                             select new { product.interval, productId, productDuration, miscCost };

                // Cost centers durations
                var stationCostByProductList = stationCostByProductQuery.ToList();
                var stationDurationQuery = from product in stationCostByProductList
                                           group product by new { product.interval, product.stationId } into g
                                           let stationDuration = g.Sum(item => item.productDuration)
                                           select new { g.Key.interval, g.Key.stationId, stationDuration };

                var machineCostByProductList = machineCostByProductQuery.ToList();
                var machineDurationQuery = from product in machineCostByProductList
                                           group product by new { product.interval, product.machineId } into g
                                           let machineDuration = g.Sum(item => item.productDuration)
                                           select new { g.Key.interval, g.Key.machineId, machineDuration };

                var activityCostByProductList = activityCostByProductQuery.ToList();
                var activityDurationQuery = from product in activityCostByProductList
                                            group product by new { product.interval, product.activityId } into g
                                            let activityDuration = g.Sum(item => item.productDuration)
                                            select new { g.Key.interval, g.Key.activityId, activityDuration };

                var operatorCostByProductList = operatorCostByProductQuery.ToList();
                var operatorDurationQuery = from product in operatorCostByProductList
                                            group product by new { product.interval, product.operatorId } into g
                                            let operatorDuration = g.Sum(item => item.productDuration)
                                            select new { g.Key.interval, g.Key.operatorId, operatorDuration };

                var productCostByMiscList = productCostByMiscQuery.ToList();
                var productSumDurationQuery = from product in productCostByMiscList
                                            group product by new { product.interval, product.productId } into g
                                            let productDuration = g.Sum(item => item.productDuration)
                                            select new { g.Key.interval, g.Key.productId, productDuration };

                // Products costs
                var productStationCostQuery = from station in stationDurationQuery
                                              from product in stationCostByProductList.Where(p => station != null && p.stationId == station.stationId && p.interval == station.interval).DefaultIfEmpty()
                                              let stationDuration = station == null ? 0 : station.stationDuration
                                              let productDuration = product == null ? 0 : product.productDuration
                                              let totalCost = product == null ? 0 : product.stationCost
                                              let reletiveCost = stationDuration == 0 ? 0 : totalCost * (productDuration / stationDuration)
                                              select new { product.interval, product.productId, reletiveCost };

                var productMachineCostQuery = from machine in machineDurationQuery
                                              from product in machineCostByProductList.Where(p => machine != null && p.machineId == machine.machineId && p.interval == machine.interval).DefaultIfEmpty()
                                              let machineDuration = machine == null ? 0 : machine.machineDuration
                                              let productDuration = product == null ? 0 : product.productDuration
                                              let totalCost = product == null ? 0 : product.machineCost
                                              let reletiveCost = machineDuration == 0 ? 0 : totalCost * (productDuration / machineDuration)
                                              select new { product.interval, product.productId, reletiveCost };

                var productActivityCostQuery = from activity in activityDurationQuery
                                               from product in activityCostByProductList.Where(p => activity != null && p.activityId == activity.activityId && p.interval == activity.interval).DefaultIfEmpty()
                                               let activityDuration = activity == null ? 0 : activity.activityDuration
                                               let productDuration = product == null ? 0 : product.productDuration
                                               let totalCost = product == null ? 0 : product.activityCost
                                               let reletiveCost = activityDuration == 0 ? 0 : totalCost * (productDuration / activityDuration)
                                               select new { product.interval, product.productId, reletiveCost };

                var productOperatorCostQuery = from opr in operatorDurationQuery
                                               from product in operatorCostByProductList.Where(p => opr != null && p.operatorId == opr.operatorId && p.interval == opr.interval).DefaultIfEmpty()
                                               let operatorDuration = opr == null ? 0 : opr.operatorDuration
                                               let productDuration = product == null ? 0 : product.productDuration
                                               let totalCost = product == null ? 0 : product.operatorCost
                                               let reletiveCost = operatorDuration == 0 ? 0 : totalCost * (productDuration / operatorDuration)
                                               select new { product.interval, product.productId, reletiveCost };

                var intervalSumDurationQuery = from product in productCostByMiscList
                                               group product by product.interval into g
                                               let intervalDuration = g.Sum(item => item.productDuration)
                                               let intervalCost = g.Sum(item => item.miscCost)
                                               select new { interval = g.Key, intervalDuration, intervalCost };

                var productMiscCostQuery = from product in productSumDurationQuery
                         from interval in intervalSumDurationQuery.Where(i => i.interval == product.interval).DefaultIfEmpty()
                         let miscCost = interval.intervalDuration == 0 ? 0 : interval.intervalCost * (product.productDuration / interval.intervalDuration)
                         select new { interval.interval, product.productId, miscCost };

                // Interval total cost
                var intervalTotalCost = from index in indexList
                                        from sCost in productStationCostQuery.Where(s => s.productId == barInfo.Id && s.interval == index.Key).DefaultIfEmpty()
                                        from mCost in productMachineCostQuery.Where(m => m.productId == barInfo.Id && m.interval == index.Key).DefaultIfEmpty()
                                        from aCost in productActivityCostQuery.Where(a => a.productId == barInfo.Id && a.interval == index.Key).DefaultIfEmpty()
                                        from oCost in productOperatorCostQuery.Where(o => o.productId == barInfo.Id && o.interval == index.Key).DefaultIfEmpty()
                                        from iCost in productMiscCostQuery.Where(i=> i.productId == barInfo.Id && i.interval == index.Key).DefaultIfEmpty()
                                        let psCost = sCost == null ? 0 : sCost.reletiveCost
                                        let pmCost = mCost == null ? 0 : sCost.reletiveCost
                                        let paCost = aCost == null ? 0 : sCost.reletiveCost
                                        let poCost = oCost == null ? 0 : sCost.reletiveCost
                                        let inCost = iCost == null ? 0 : iCost.miscCost
                                        select new { index.Key, psCost, pmCost, paCost, poCost, inCost };

                var query = from interval in intervalTotalCost
                            group interval by interval.Key into g
                            let productCost = g.Sum(item => item == null ? 0 : item.psCost + item.pmCost + item.poCost + item.paCost + item.inCost)
                            select new { interval = g.Key, value = productCost??0 };

                var results = query.ToList();

                for (int i = startIdx; i < count; i++)
                {
                    var newRecord = new Record { Header = i.ToString(CultureInfo.InvariantCulture) };
                    foreach (var line in results)
                    {
                        if (line.interval == i)
                        {
                            newRecord.Id = barInfo.Id;
                            newRecord.Value = line.value;
                            newRecord.StartDate = barInfo.StartDate;
                            newRecord.EndDate = barInfo.EndDate;
                        }
                    }
                    records.Add(newRecord);
                }
            }
            return records;
        }