Exemplo n.º 1
0
        public NewInspectionViewModel(ICustomerRepository customerRepository, IAddressRepository addressRepository, ITaskRepository taskRepository)
        {
            _taskRepository     = taskRepository;
            _customerRepository = customerRepository;
            _addressRepository  = addressRepository;
            var curDir = Directory.GetCurrentDirectory();

            WebBrowserUri   = $"file:///{curDir}/WebFiles/NewInspection.html";
            GenerateCommand = new RelayCommand <WebBrowser>(Generate);

            Customers = new ObservableCollection <Customer>(customerRepository.All());

            Regions = new ObservableCollection <string>();
            foreach (var address in addressRepository.All())
            {
                if (!Regions.Contains(address.Province))
                {
                    Regions.Add(address.Province);
                }
            }

            ChartTypes = new ObservableCollection <string>();
            ChartTypes.Add("Barchart");
            ChartTypes.Add("Piechart");
            EndDateTime = DateTime.Now.AddMonths(2);
        }
        public InspectionDurationViewModel(ITaskRepository taskRepository, IUserRepository userRepository, IAddressRepository addressRepository, ICustomerRepository customerRepository)
        {
            _customerRepository = customerRepository;
            _taskRepository     = taskRepository;
            _userRepository     = userRepository;
            _addressRepository  = addressRepository;
            BeginDateTime       = new DateTime();
            EndDateTime         = DateTime.Now;
            Regions             = new ObservableCollection <string>();
            foreach (var address in _addressRepository.All())
            {
                if (!Regions.Contains(address.Province))
                {
                    Regions.Add(address.Province);
                }
            }

            Customers          = new ObservableCollection <Customer>(customerRepository.All());
            Inspectors         = new ObservableCollection <Employee>(_userRepository.All());
            SelectedInspectors = new ObservableCollection <Employee>();

            ChartTypes = new ObservableCollection <string> {
                "Barchart", "Piechart"
            };

            var curDir = Directory.GetCurrentDirectory();

            WebBrowserUri = $"file:///{curDir}/WebFiles/InspectionDuration.html";

            GenerateCommand = new RelayCommand <WebBrowser>(Generate);
            AddCommand      = new GalaSoft.MvvmLight.CommandWpf.RelayCommand(Add);
            RemoveCommand   = new GalaSoft.MvvmLight.CommandWpf.RelayCommand(Remove);
        }
Exemplo n.º 3
0
        private void Generate(WebBrowser browser)
        {
            Regions.Clear();
            foreach (var address in _addressRepository.All())
            {
                if (!Regions.Contains(address.Province))
                {
                    Regions.Add(address.Province);
                }
            }

            _browser = browser;

            var tasks           = _taskRepository.All();
            var DataElementList = new List <NewInspectionDataElement>();

            var values = new Dictionary <string, int>();

            foreach (var item in tasks)
            {
                if (((item.Customer == SelectedCustomer) || SelectAllCustomers) && (item.DatetimeCreated != null) && (item.DateTimeEnd != null) && (item.DateTimeStart != null) && (item.ParkingLot?.Address != null))
                {
                    if ((item.DatetimeCreated < EndDateTime) && (item.DatetimeCreated > BeginDateTime) && (item.ParkingLot.Address.Province.Equals(SelectedRegion) || SelectAllRegions))
                    {
                        var month = item.DatetimeCreated.ToString("MMMMM");
                        if (!values.ContainsKey(month))
                        {
                            values.Add(month, 0);
                        }
                        values[month]++;
                    }
                }
            }

            foreach (var item in values)
            {
                DataElementList.Add(new NewInspectionDataElement
                {
                    month  = item.Key,
                    amount = item.Value.ToString()
                });
            }

            var o = JsonConvert.SerializeObject(DataElementList);

            browser.InvokeScript("go", o);

            Customers.Clear();
            _customerRepository.All().ForEach(Customers.Add);
        }
        private void Generate(WebBrowser browser)
        {
            if (SelectAllCustomers == false && SelectedCustomer == null)
            {
                return;
            }
            _browser = browser;
            var DataElementList = new List <DataElement>();
            var list            = _taskRepository.All();


            foreach (var item in list)
            {
                if (item.ParkingLot.Address != null && item.DateTimeEnd != null && item.DateTimeStart != null || item.Customer?.Name != null)
                {
                    bool region = true;
                    if (SelectedRegion != null && item.ParkingLot.Address != null && item.ParkingLot.Address.Province != null)
                    {
                        if (!item.ParkingLot.Address.Province.Equals(SelectedRegion))
                        {
                            region = false;
                        }
                    }
                    if ((region || SelectAllRegions == true) &&
                        item.DateTimeStart > BeginDateTime &&
                        item.DateTimeStart < EndDateTime &&
                        (item.Customer.Name == SelectedCustomer?.Name || SelectAllCustomers == true))
                    {
                        var inspections = item.Inspections;

                        List <Employee> employees = (from i in inspections from ii in i.InspectionInspectors select ii.Employee).ToList();

                        if (employees.Contains(SelectedEmployee) || SelectAllEmployees == true)
                        {
                            List <TimeSpan> spans = new List <TimeSpan>();
                            foreach (var i in item.Inspections)
                            {
                                TimeSpan span;
                                if (i.DateTimeDone != null)
                                {
                                    TimeSpan?tempSpan = i.DateTimeDone - i.DateTimeStarted;
                                    span = tempSpan.Value;
                                    spans.Add(span);
                                }
                            }
                            if (spans.Count > 0)
                            {
                                double duration      = spans.Average(timeSpan => timeSpan.TotalMinutes);
                                int    finalDuration = (int)duration;
                                DataElementList.Add(new DataElement
                                {
                                    inspection = item.Customer.Name,
                                    duration   = finalDuration.ToString()
                                });
                            }
                        }
                    }
                }
            }
            var o = new DataSet
            {
                data      = DataElementList,
                ChartType = SelectedChart
            };
            var test = JsonConvert.SerializeObject(o);

            browser.InvokeScript("go", test);

            Regions.Clear();
            foreach (var address in _addressRepository.All())
            {
                if (!Regions.Contains(address.Province))
                {
                    Regions.Add(address.Province);
                }
            }

            Customers.Clear();
            _customerRepository.All().ForEach(Customers.Add);
            _userRepository.All().ForEach(Inspectors.Add);
        }