Example #1
0
        private void Delete_Click(object sender, RoutedEventArgs e)
        {
            Errands errandSelected = lv_Errand.SelectedItem as Errands;

            string jsonFromFile;

            using (var reader = new StreamReader(mechpath))
            {
                jsonFromFile = reader.ReadToEnd();
            }
            var readFromJson = JsonConvert.DeserializeObject <List <Mechanic> >(jsonFromFile);

            mechanics = readFromJson;

            Mechanic mechanic  = readFromJson.FirstOrDefault(x => x.ErrandIDArray[0] == errandSelected.ErrandID);
            Mechanic mechanic2 = readFromJson.FirstOrDefault(x => x.ErrandIDArray[1] == errandSelected.ErrandID);

            if (mechanic != null)
            {
                mechanic.ErrandIDArray[0] = Guid.Empty;
            }
            if (mechanic2 != null)
            {
                mechanic2.ErrandIDArray[1] = Guid.Empty;
            }

            if (errandSelected != null)
            {
                errands.Remove(errandSelected);
            }
            DeleteTheErrand();
            Overrite <Mechanic>(mechpath, mechanics);
            ErrandViewer.Children.Clear();
            ErrandViewer.Children.Add(new UserControlNewErrand());
        }
        public ErandMechanicDetail()
        {
            InitializeComponent();

            string jsonFromFile;

            using (var reader = new StreamReader(mechpath))
            {
                jsonFromFile = reader.ReadToEnd();
            }
            var readFromJson = JsonConvert.DeserializeObject <List <Mechanic> >(jsonFromFile);

            DataContext = readFromJson;

            Errands errands1 = _selectedErrand;

            Mechanic mechanic  = readFromJson.FirstOrDefault(x => x.FirstName == errands1.FirstName);
            Mechanic mechanic1 = readFromJson.FirstOrDefault(x => x.SurName == errands1.LastName);

            Guid currentMechID = mechanic.MechID;

            tboldFirst.Text     = mechanic.FirstName;
            tboldSur.Text       = mechanic1.SurName;
            tboldBirth.Text     = mechanic.DateOfBirth;
            tboldEmploy.Text    = mechanic.DateOfEmployment;
            tboldEmployEnd.Text = mechanic.EndDate;
            tboldMechID.Text    = currentMechID.ToString();
            tboldCFE.Text       = mechanic.CanFixEngines;
            tboldCFT.Text       = mechanic.CanFixTires;
            tboldCFB.Text       = mechanic.CanFixBrakes;
            tboldCFWS.Text      = mechanic.CanFixWindshields;
            tboldCFVB.Text      = mechanic.CanFixVehicleBody;
        }
Example #3
0
 /// <summary>
 /// Method that fetches errand detail from database
 /// </summary>
 /// <param name="id">Id of the requested errand</param>
 /// <returns>errandDetail model object</returns>
 public Task <Errand> GetErrandDetail(int id)
 {
     return(Task.Run(() =>
     {
         var errandDetail = Errands.First(td => td.ErrandId == id);
         return errandDetail;
     }));
 }
Example #4
0
        public Task <IQueryable <Errand> > GetErrandByInvestigatorAsync()
        {
            // hämtar inloggad användare
            var userName = contextAcc.HttpContext.User.Identity.Name;

            return(Task.Run(() => Errands
                            .Where(td => td.EmployeeId == userName)

                            ));
        }
Example #5
0
        private void AssignMechanicToErrand_Click(object sender, RoutedEventArgs e)
        {
            Errands errands = lv_Errand.SelectedItem as Errands;

            _selectedErrand = errands;
            if (errands != null)
            {
                errands.ErrandStatus = "OnGoing";
                ErrandViewer.Children.Clear();
                ErrandViewer.Children.Add(new ChooseMechanicToErrand());
            }
        }
Example #6
0
        private void Edit_Click(object sender, RoutedEventArgs e)
        {
            Errands selectedErrand = lv_Errand.SelectedItem as Errands;

            _newSelectedErrandTest = selectedErrand;
            //selectedErrand.FirstName = null;
            ErrandViewer.Children.Clear();
            var child = new EditErrand();

            child.DataContext = selectedErrand;
            ErrandViewer.Children.Add(child);
        }
Example #7
0
        private void MechDetail_Click(object sender, RoutedEventArgs e)
        {
            Errands errands = lv_Errand.SelectedItem as Errands;

            _selectedErrand = errands;
            if (errands != null)
            {
                ErrandViewer.Children.Clear();
                var child = new ErandMechanicDetail();
                child.DataContext = errands;
                //child.DataContext = selectedMechanic;
                ErrandViewer.Children.Add(child);
            }
        }
        private void ChangeStatus_Click(object sender, RoutedEventArgs e)
        {
            Errands errand = MechListView.SelectedItem as Errands;

            errand.Finished = true;

            errand.ErrandStatus = errand.Finished ? "Finished" : "OnGoing";


            Overrite <Errands>(pathforErrand, errands);
            MessageBox.Show("Errand Finished!");

            ErrandMechanic.Children.Clear();
            ErrandMechanic.Children.Add(new UCErrandsMech());
        }
        public UCErrandsMech()
        {
            InitializeComponent();

            string jsonFromFile;

            using (var reader = new StreamReader(pathforErrand))
            {
                jsonFromFile = reader.ReadToEnd();
            }
            var readFromJson = JsonConvert.DeserializeObject <List <Errands> >(jsonFromFile);

            errands = readFromJson;

            string jsonFromFile2;

            using (var reader = new StreamReader(mechpath))
            {
                jsonFromFile2 = reader.ReadToEnd();
            }

            var readFromJson2 = JsonConvert.DeserializeObject <List <Mechanic> >(jsonFromFile2);

            mechanics = readFromJson2;

            Mechanic mechanic = readFromJson2.FirstOrDefault(x => x.UserID == LoggedInUserService.LoggedInUser.UserID);

            List <Errands> errandsOfMech = new List <Errands>();

            foreach (var id in mechanic.ErrandIDArray)
            {
                Errands errand = readFromJson.FirstOrDefault(e => e.ErrandID == id);

                if (errand != null)
                {
                    errandsOfMech.Add(errand);
                }
            }



            DataContext = errandsOfMech;
            MechListView.ItemsSource = errandsOfMech;
        }
Example #10
0
        // sparar filnamn i databasen, i tabellerna Pictures resp Samples
        public void SaveFileToDb(string FileName, bool isImage, string errandId)
        {
            var errand = Errands.Where(td => td.RefNumber == errandId).First();

            // kollar om bild är med
            if (isImage)
            {
                Picture picture = new Picture {
                    PictureName = FileName, ErrandId = errand.ErrandID
                };
                _context.Pictures.Add(picture);
            }
            // om ej bild är det en fil
            else if (!isImage)
            {
                Sample sample = new Sample {
                    SampleName = FileName, ErrandId = errand.ErrandID
                };
                _context.Samples.Add(sample);
            }
            _context.SaveChanges();
        }
Example #11
0
        public async void CreateErrand_Click(object sender, RoutedEventArgs e)
        {
            if (!Regex.IsMatch(tbRegistrationDate.Text, @"^\d{4}-((0\d)|(1[012]))-(([012]\d)|3[01])$"))
            {
                MessageBox.Show("Enter a valid date for Registration Date. YYYY-MM-DD");
            }

            if (!Regex.IsMatch(tbErrandStart.Text, @"^\d{4}-((0\d)|(1[012]))-(([012]\d)|3[01])$"))
            {
                MessageBox.Show("Enter a valid date for Errand Start. YYYY-MM-DD");
                return;
            }

            if (!Regex.IsMatch(tbErrandEnd.Text, @"^\d{4}-((0\d)|(1[012]))-(([012]\d)|3[01])$"))
            {
                MessageBox.Show("Enter a valid date for Errand End. YYYY-MM-DD");
                return;
            }

            if (!Regex.IsMatch(tbRegistrationNumber.Text, @"^[A-Z0-9]*$"))
            {
                MessageBox.Show("Invalid Registration number. The letters must be in capitals A-Z");
                return;
            }



            StockChange();
            //ChooseVehicle();


            string errandName     = this.tbErrandName.Text;
            string errandStart    = this.tbErrandStart.Text;
            string errandEnd      = this.tbErrandEnd.Text;
            string componentsNeed = this.InvComboBox.Text;

            string vehicleType = this.VehicleComboBox.Text;
            string carType     = this.TypeCarComboBox.Text;

            string   modelType        = this.tbModel.Text;
            string   regNr            = this.tbRegistrationNumber.Text;
            int      odoMeterm        = int.Parse(this.tbOdometer.Text);
            DateTime regDate          = DateTime.Parse(this.tbRegistrationDate.Text);
            string   typePropellant   = this.TypePropellantComboBox.Text;
            string   hasTow           = this.tbHasTowbar.Text;
            int      maxPass          = int.Parse(this.tbMaxNrPass.Text);
            int      loadMax          = int.Parse(this.tbMaxLoad.Text);
            string   writeDescription = this.tbDescription.Text;
            int      amountOfComp     = int.Parse(this.tbAmount.Text);


            Errands errand = new Errands
            {
                ErrandName         = errandName,
                ErrandStartDate    = errandStart,
                ErrandEndDate      = errandEnd,
                ErrandID           = Guid.NewGuid(),
                ErrandStatus       = "New",
                ComponentsNeeded   = componentsNeed,
                TypeOfVehicle      = vehicleType,
                TypOfCar           = carType,
                ModelName          = modelType,
                RegistrationNumber = regNr,
                Odometer           = odoMeterm,
                RegistrationDate   = regDate,
                Propellant         = typePropellant,
                HasTowbar          = hasTow,
                MaxNrPassengers    = maxPass,
                MaxLoad            = loadMax,
                Description        = writeDescription,
                Amount             = amountOfComp,
                FirstName          = null,
                LastName           = null,
                Competence         = null
            };



            if (errands.Count >= 1)
            {
                string jsonFile;

                using (var reader = new StreamReader(pathforErrand))
                {
                    jsonFile = reader.ReadToEnd();
                }

                var jsonRead = JsonConvert.DeserializeObject <List <Errands> >(jsonFile);
                errands.Add(errand);
                var jsonWrite = JsonConvert.SerializeObject(errands, Formatting.Indented);
                var fs        = File.OpenWrite(pathforErrand);
                using (var jsonWriter = new StreamWriter(fs))
                {
                    await jsonWriter.WriteAsync(jsonWrite);
                }
            }

            else
            {
                errands.Add(errand);
                var jsonWrite = JsonConvert.SerializeObject(errands, Formatting.Indented);
                var fs        = File.OpenWrite(pathforErrand);
                using (var jsonWriter = new StreamWriter(fs))
                {
                    await jsonWriter.WriteAsync(jsonWrite);
                }
            }
            ErrandViewer.Children.Clear();
            ErrandViewer.Children.Add(new UserControlNewErrand());
        }
Example #12
0
 // i min kod är RefNumber id-parameter och inte integern id i pocoklassen.
 // Annars kan jag inte få detaljvyn att se exakt likadan ut som er iom
 // att jag har en view component som hämtar all data. RefNumber skrivs ut innan
 // denna komponent i vyn och därför kan jag enbart komma åt den om jag har med den som
 // asp-route-id
 public Task <Errand> GetErrand(string id)
 {
     return(Task.Run(() => Errands
                     .Where(td => td.RefNumber == id)
                     .First()));
 }
Example #13
0
 private void ErrandView_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     Errands errands = (Errands)lv_Errand.SelectedItem;
 }
        private async void EditErrandButton_Click(object sender, RoutedEventArgs e)
        {
            if (tbAmountNeed.Text == "" || tbAmountNeed.Text == null)
            {
                MessageBox.Show("Ange antal komponenter du behöver.");
                return;
            }
            if (!Regex.IsMatch(tbRegistrationDate.Text, @"^\d{4}-((0\d)|(1[012]))-(([012]\d)|3[01])$"))
            {
                MessageBox.Show("Enter a valid date for Registration Date. YYYY-MM-DD");
                return;
            }

            if (!Regex.IsMatch(tbStartDate.Text, @"^\d{4}-((0\d)|(1[012]))-(([012]\d)|3[01])$"))
            {
                MessageBox.Show("Enter a valid date for Errand Start. YYYY-MM-DD");
                return;
            }

            if (!Regex.IsMatch(tbEndDate.Text, @"^\d{4}-((0\d)|(1[012]))-(([012]\d)|3[01])$"))
            {
                MessageBox.Show("Enter a valid date for Errand End. YYYY-MM-DD");
                return;
            }

            if (!Regex.IsMatch(tbRegistrationNumber.Text, @"^[A-Z0-9]*$"))
            {
                MessageBox.Show("Invalid Registration number. The letters must be in capitals A-Z");
                return;
            }


            if (InvComboBoxNeed.SelectedItem == null)
            {
                MessageBox.Show("Välj en komponent.");
                return;
            }

            if (InvComboBoxReturned.SelectedItem == null)
            {
                MessageBox.Show("Välj en komponent.");
                return;
            }

            if (VehicleComboBox.SelectedItem == null)
            {
                MessageBox.Show("Välj en fordonstyp.");
                return;
            }

            if (TypeCarComboBox.SelectedItem == null)
            {
                MessageBox.Show("Välj en bilmodell.");
                return;
            }

            if (TypePropellantComboBox.SelectedItem == null)
            {
                MessageBox.Show("Välj en bränsletyp.");
                return;
            }



            if (tbAmount.Text == "" || tbAmount.Text == null)
            {
                //tbAmount.Text = "0";
                //int.Parse(this.tbAmount.Text);
                MessageBox.Show("Ange antal komponenter du vill lämna tillbaka.");
                return;
            }


            Errands selectedErrand = _newSelectedErrandTest;

            var currentMechanic = selectedErrand.FirstName;

            var currentMechanic1 = selectedErrand.LastName;

            Guid CurrentErrandID = selectedErrand.ErrandID;

            var findIndexOfErrand = errands.FindIndex(x => x.ErrandID == selectedErrand.ErrandID);

            errands[findIndexOfErrand] = selectedErrand;

            errands.Remove(selectedErrand);

            Overrite <Errands>(pathforErrand, errands);

            string jsonFile4;

            using (var reader = new StreamReader(pathforErrand))
            {
                jsonFile4 = reader.ReadToEnd();
            }

            var jsonRead4 = JsonConvert.DeserializeObject <List <Errands> >(jsonFile4);

            errands = jsonRead4;

            StockChangeNeed();
            StockChangeAdd();

            string errandName         = this.tbErrandName.Text;
            string errandStart        = this.tbStartDate.Text;
            string errandEnd          = this.tbEndDate.Text;
            string componentsNeed     = this.InvComboBoxNeed.Text;
            string componentsReturned = this.InvComboBoxReturned.Text;
            int    amountOfComp       = int.Parse(this.tbAmountNeed.Text);

            string vehicleType = this.VehicleComboBox.Text;
            string carType     = this.TypeCarComboBox.Text;

            string modelType = this.tbModel.Text;
            string regNr     = this.tbRegistrationNumber.Text;
            int    odoMeterm = int.Parse(this.tbOdometer.Text);
            //DateTime regDate = DateTime.Parse(this.tbRegistrationDate.Text);
            string regDate          = this.tbRegistrationDate.Text;
            string typePropellant   = this.TypePropellantComboBox.Text;
            string hasTow           = this.tbHasTowbar.Text;
            int    maxPass          = int.Parse(this.tbMaxNrPass.Text);
            int    loadMax          = int.Parse(this.tbMaxLoad.Text);
            string writeDescription = this.tbDescription.Text;



            string finished = ((bool)cbStatusFinished.IsChecked) ? "Finished" : "OnGoing";



            Errands errand = new Errands
            {
                ErrandName         = errandName,
                ErrandStartDate    = errandStart,
                ErrandEndDate      = errandEnd,
                ErrandID           = CurrentErrandID,
                ErrandStatus       = finished,
                ComponentsNeeded   = componentsNeed,
                TypeOfVehicle      = vehicleType,
                TypOfCar           = carType,
                ModelName          = modelType,
                RegistrationNumber = regNr,
                Odometer           = odoMeterm,
                RegistrationDate   = regDate,
                Propellant         = typePropellant,
                HasTowbar          = hasTow,
                MaxNrPassengers    = maxPass,
                MaxLoad            = loadMax,
                Description        = writeDescription,
                Amount             = amountOfComp,
                FirstName          = currentMechanic,
                LastName           = currentMechanic1
            };

            if (errand.ErrandStatus == "Finished")
            {
                string jsonFromFile;
                using (var reader = new StreamReader(mechpath))
                {
                    jsonFromFile = reader.ReadToEnd();
                }
                var readFromJson = JsonConvert.DeserializeObject <List <Mechanic> >(jsonFromFile);
                mechanics = readFromJson;

                Mechanic ArrayFirstElement  = readFromJson.FirstOrDefault(x => x.ErrandIDArray[0] == errand.ErrandID);
                Mechanic ArraySecondElement = readFromJson.FirstOrDefault(x => x.ErrandIDArray[1] == errand.ErrandID);

                if (ArrayFirstElement != null)
                {
                    if (ArrayFirstElement.ErrandIDArray[0] == errand.ErrandID)
                    {
                        ArrayFirstElement.ErrandIDArray[0] = Guid.Empty;
                    }
                }

                if (ArraySecondElement != null)
                {
                    if (ArraySecondElement.ErrandIDArray[1] == errand.ErrandID)
                    {
                        ArraySecondElement.ErrandIDArray[1] = Guid.Empty;
                    }
                }
            }
            var jsonWrite = JsonConvert.SerializeObject(mechanics, Formatting.Indented);
            var fs        = File.OpenWrite(mechpath);

            using (var jsonWriter = new StreamWriter(fs))
            {
                await jsonWriter.WriteAsync(jsonWrite);
            }

            errands.Add(errand);
            var jsonWrite2 = JsonConvert.SerializeObject(errands, Formatting.Indented);
            var fs2        = File.OpenWrite(pathforErrand);

            using (var jsonWriter = new StreamWriter(fs2))
            {
                await jsonWriter.WriteAsync(jsonWrite2);
            }


            EditErrandView.Children.Clear();
            EditErrandView.Children.Add(new UserControlNewErrand());
        }
        private async void AssignMechanicToErrand_Click(object sender, RoutedEventArgs e)
        {
            Errands errands1 = _selectedErrand;

            var mechanic = MechanicChoose.SelectedItem as Mechanic;

            mechanic.ErrandIDMech = errands1.ErrandID;

            var indexOfMechanic = mechanics.FindIndex(x => x.ErrandIDMech == errands1.ErrandID);

            mechanics[indexOfMechanic] = mechanic;

            errands1.FirstName = mechanic.FirstName;
            errands1.LastName  = mechanic.SurName;
            string CFB      = mechanic.CanFixBrakes;
            string CFE      = mechanic.CanFixEngines;
            string CFT      = mechanic.CanFixTires;
            string CFV      = mechanic.CanFixVehicleBody;
            string CFW      = mechanic.CanFixWindshields;
            string compNeed = errands1.ComponentsNeeded;

            //=========================================================================================
            _mechanic = mechanic;

            var totalElementsInArray = mechanic.ErrandIDArray;

            var numberOfElements = (bool)mechanic.HasErrands ? totalElementsInArray.Count() : 0;



            if (mechanic.ErrandIDArray[0].Equals(Guid.Empty))
            {
                _index = 0;
                mechanic.ErrandIDArray[_index] = errands1.ErrandID;
                var SetValueToMechanic = mechanics.FindIndex(x => x.ErrandIDArray[_index] == errands1.ErrandID);
                mechanics[SetValueToMechanic] = mechanic;
                _index++;
            }
            else if ((mechanic.ErrandIDArray[1].Equals(Guid.Empty)))
            {
                _index = 1;
                mechanic.ErrandIDArray[_index] = errands1.ErrandID;
                var SetValueToMechanic = mechanics.FindIndex(x => x.ErrandIDArray[_index] == errands1.ErrandID);
                mechanics[SetValueToMechanic] = mechanic;
                _index++;
            }
            else
            {
                MessageBox.Show("This mechanic has 2 errands already.", "Choose another mechanic.",
                                MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            //=========================================================================================

            if ((totalElementsInArray[0].Equals(Guid.Empty)) && (totalElementsInArray[1].Equals(Guid.Empty)))
            {
                mechanic.ErrandAmount = 0;
            }
            else if ((totalElementsInArray[0] != (Guid.Empty)) && (totalElementsInArray[1] != (Guid.Empty)))
            {
                mechanic.ErrandAmount = 2;
            }
            else if ((totalElementsInArray[0] != (Guid.Empty)) || (totalElementsInArray[1] != (Guid.Empty)))
            {
                mechanic.ErrandAmount = 1;
            }

            //=========================================================================================

            if (mechanics.Count >= 1)
            {
                string jsonFromFile;
                using (var reader = new StreamReader(mechpath))
                {
                    jsonFromFile = reader.ReadToEnd();
                }
                var readFromJson = JsonConvert.DeserializeObject <List <Mechanic> >(jsonFromFile);
                //mechanics.Clear();
                //mechanics.Add(mechanic);
                var jsonToWrite = JsonConvert.SerializeObject(mechanics, Formatting.Indented);
                using (var writer = new StreamWriter(mechpath))
                {
                    await writer.WriteAsync(jsonToWrite);
                }
            }
            //ADD

            errands.Remove(_selectedErrand);



            if (((compNeed == "CarTires" || compNeed == "MCTires" || compNeed == "BusTires" || compNeed == "TruckTires") && CFT == "Yes") ||
                ((compNeed == "CarBrakes" || compNeed == "MCBrakes" || compNeed == "BusBrakes" || compNeed == "TruckBrakes") && CFB == "Yes") ||
                ((compNeed == "CarMotors" || compNeed == "MCMotors" || compNeed == "BusMotors" || compNeed == "TruckMotors") && CFE == "Yes") ||
                ((compNeed == "CarWindshields" || compNeed == "MCWindshields" || compNeed == "BusWindshields" || compNeed == "TruckWindshields") && CFW == "Yes") ||
                ((compNeed == "CarVehicleBodies" || compNeed == "MCVehicleBodies" || compNeed == "BusVehicleBodies" || compNeed == "TruckVehicleBodies") && CFV == "Yes"))
            {
                if (errands.Count >= 1)
                {
                    string jsonFromFile;
                    using (var reader = new StreamReader(pathforErrand))
                    {
                        jsonFromFile = reader.ReadToEnd();
                    }
                    var readFromJson = JsonConvert.DeserializeObject <List <Mechanic> >(jsonFromFile);
                    errands.Add(errands1);
                    var jsonToWrite = JsonConvert.SerializeObject(errands, Formatting.Indented);
                    using (var writer = new StreamWriter(pathforErrand))
                    {
                        await writer.WriteAsync(jsonToWrite);
                    }
                }

                else
                {
                    errands.Add(errands1);
                    var jsonToWrite = JsonConvert.SerializeObject(errands, Formatting.Indented);
                    var fs          = File.OpenWrite(pathforErrand);
                    using (var writer = new StreamWriter(fs))
                    {
                        await writer.WriteAsync(jsonToWrite);
                    }
                }
                ChooseMechanic.Children.Clear();
                ChooseMechanic.Children.Add(new UserControlNewErrand());
            }
            else
            {
                MessageBox.Show("Does not have the competence, choose another mechanic!");
            }
        }
        private async void EditErrandButton_Click(object sender, RoutedEventArgs e)
        {
            Errands selectedErrand = _newSelectedErrandTest;

            var currentMechanic = selectedErrand.FirstName;

            var currentMechanic1 = selectedErrand.LastName;

            Guid CurrentErrandID = selectedErrand.ErrandID;

            var findIndexOfErrand = errands.FindIndex(x => x.ErrandID == selectedErrand.ErrandID);

            errands[findIndexOfErrand] = selectedErrand;

            errands.Remove(selectedErrand);

            Overrite <Errands>(pathforErrand, errands);

            string jsonFile4;

            using (var reader = new StreamReader(pathforErrand))
            {
                jsonFile4 = reader.ReadToEnd();
            }

            var jsonRead4 = JsonConvert.DeserializeObject <List <Errands> >(jsonFile4);

            errands = jsonRead4;

            StockChangeNeed();
            StockChangeAdd();

            string errandName         = this.tbErrandName.Text;
            string errandStart        = this.tbStartDate.Text;
            string errandEnd          = this.tbEndDate.Text;
            string componentsNeed     = this.InvComboBoxNeed.Text;
            string componentsReturned = this.InvComboBoxReturned.Text;
            int    amountOfComp       = int.Parse(this.tbAmountNeed.Text);

            string vehicleType = this.VehicleComboBox.Text;
            string carType     = this.TypeCarComboBox.Text;

            string   modelType        = this.tbModel.Text;
            string   regNr            = this.tbRegistrationNumber.Text;
            int      odoMeterm        = int.Parse(this.tbOdometer.Text);
            DateTime regDate          = DateTime.Parse(this.tbRegistrationDate.Text);
            string   typePropellant   = this.TypePropellantComboBox.Text;
            string   hasTow           = this.tbHasTowbar.Text;
            int      maxPass          = int.Parse(this.tbMaxNrPass.Text);
            int      loadMax          = int.Parse(this.tbMaxLoad.Text);
            string   writeDescription = this.tbDescription.Text;



            string finished = ((bool)cbStatusFinished.IsChecked) ? "Finished" : "OnGoing";



            Errands errand = new Errands
            {
                ErrandName         = errandName,
                ErrandStartDate    = errandStart,
                ErrandEndDate      = errandEnd,
                ErrandID           = CurrentErrandID,
                ErrandStatus       = finished,
                ComponentsNeeded   = componentsNeed,
                TypeOfVehicle      = vehicleType,
                TypOfCar           = carType,
                ModelName          = modelType,
                RegistrationNumber = regNr,
                Odometer           = odoMeterm,
                RegistrationDate   = regDate,
                Propellant         = typePropellant,
                HasTowbar          = hasTow,
                MaxNrPassengers    = maxPass,
                MaxLoad            = loadMax,
                Description        = writeDescription,
                Amount             = amountOfComp,
                FirstName          = currentMechanic,
                LastName           = currentMechanic1
            };

            if (errand.ErrandStatus == "Finished")
            {
                string jsonFromFile;
                using (var reader = new StreamReader(mechpath))
                {
                    jsonFromFile = reader.ReadToEnd();
                }
                var readFromJson = JsonConvert.DeserializeObject <List <Mechanic> >(jsonFromFile);
                mechanics = readFromJson;

                Mechanic ArrayFirstElement  = readFromJson.FirstOrDefault(x => x.ErrandIDArray[0] == errand.ErrandID);
                Mechanic ArraySecondElement = readFromJson.FirstOrDefault(x => x.ErrandIDArray[1] == errand.ErrandID);

                if (ArrayFirstElement != null)
                {
                    if (ArrayFirstElement.ErrandIDArray[0] == errand.ErrandID)
                    {
                        ArrayFirstElement.ErrandIDArray[0] = Guid.Empty;
                    }
                }

                if (ArraySecondElement != null)
                {
                    if (ArraySecondElement.ErrandIDArray[1] == errand.ErrandID)
                    {
                        ArraySecondElement.ErrandIDArray[1] = Guid.Empty;
                    }
                }
            }
            var jsonWrite = JsonConvert.SerializeObject(mechanics, Formatting.Indented);
            var fs        = File.OpenWrite(mechpath);

            using (var jsonWriter = new StreamWriter(fs))
            {
                await jsonWriter.WriteAsync(jsonWrite);
            }

            errands.Add(errand);
            var jsonWrite2 = JsonConvert.SerializeObject(errands, Formatting.Indented);
            var fs2        = File.OpenWrite(pathforErrand);

            using (var jsonWriter = new StreamWriter(fs2))
            {
                await jsonWriter.WriteAsync(jsonWrite2);
            }


            EditErrandView.Children.Clear();
            EditErrandView.Children.Add(new UserControlNewErrand());
        }
Example #17
0
        public async void CreateErrand_Click(object sender, RoutedEventArgs e)
        {
            if (!Regex.IsMatch(tbRegistrationDate.Text, @"^\d{4}-((0\d)|(1[012]))-(([012]\d)|3[01])$"))
            {
                MessageBox.Show("Ange gilltigt datum för registrering. YYYY-MM-DD");
                return;
            }

            if (!Regex.IsMatch(tbErrandStart.Text, @"^\d{4}-((0\d)|(1[012]))-(([012]\d)|3[01])$"))
            {
                MessageBox.Show("Ange gilltigt datum för ärende start. YYYY-MM-DD");
                return;
            }

            if (!Regex.IsMatch(tbErrandEnd.Text, @"^\d{4}-((0\d)|(1[012]))-(([012]\d)|3[01])$"))
            {
                MessageBox.Show("Ange gilltigt datum för ärende s**t. YYYY-MM-DD");
                return;
            }
            if (tbRegistrationNumber.Text == null || tbRegistrationNumber.Text == "")
            {
                MessageBox.Show("Ange registreringsnummer.");
                return;
            }

            if (!Regex.IsMatch(tbRegistrationNumber.Text, @"^[A-Z0-9]*$"))
            {
                MessageBox.Show("Ogilltigt registreringsnummer. Måste innehålla stora bokstäver A-Z");
                return;
            }


            if (InvComboBox.SelectedItem == null)
            {
                MessageBox.Show("Välj en komponent.");
                return;
            }

            if (VehicleComboBox.SelectedItem == null)
            {
                MessageBox.Show("Välj en fordonstyp.");
                return;
            }

            if (TypeCarComboBox.SelectedItem == null)
            {
                MessageBox.Show("Välj en bilmodell.");
                return;
            }

            if (TypePropellantComboBox.SelectedItem == null)
            {
                MessageBox.Show("Välj en bränsletyp.");
                return;
            }


            if (tbOdometer.Text == "" || tbOdometer.Text == null)
            {
                MessageBox.Show("Ange miltal.");
                return;
            }

            if (tbMaxNrPass.Text == "" || tbMaxNrPass.Text == null)
            {
                MessageBox.Show("Ange antal passagerare.");
                return;
            }

            if (tbMaxLoad.Text == "" || tbMaxLoad.Text == null)
            {
                MessageBox.Show("Ange maxbelastning.");
                return;
            }

            if (tbAmount.Text == "" || tbAmount.Text == null)
            {
                //tbAmount.Text = "0";
                //int.Parse(this.tbAmount.Text);
                MessageBox.Show("Ange antal komponenter.");
                return;
            }

            if (string.IsNullOrEmpty(tbErrandName.Text) || string.IsNullOrEmpty(tbModel.Text) || string.IsNullOrEmpty(tbHasTowbar.Text) || string.IsNullOrEmpty(tbDescription.Text))
            {
                MessageBox.Show("Ange namn, model, dragkrok och beskrivning.");
                return;
            }


            StockChange();
            //ChooseVehicle();


            string errandName     = this.tbErrandName.Text;
            string errandStart    = this.tbErrandStart.Text;
            string errandEnd      = this.tbErrandEnd.Text;
            string componentsNeed = this.InvComboBox.Text;

            string vehicleType = this.VehicleComboBox.Text;
            string carType     = this.TypeCarComboBox.Text;

            string modelType        = this.tbModel.Text;
            string regNr            = this.tbRegistrationNumber.Text;
            int    odoMeterm        = int.Parse(this.tbOdometer.Text);
            string regDate          = this.tbRegistrationDate.Text;
            string typePropellant   = this.TypePropellantComboBox.Text;
            string hasTow           = this.tbHasTowbar.Text;
            int    maxPass          = int.Parse(this.tbMaxNrPass.Text);
            int    loadMax          = int.Parse(this.tbMaxLoad.Text);
            string writeDescription = this.tbDescription.Text;
            int    amountOfComp     = int.Parse(this.tbAmount.Text);



            Errands errand = new Errands
            {
                ErrandName         = errandName,
                ErrandStartDate    = errandStart,
                ErrandEndDate      = errandEnd,
                ErrandID           = Guid.NewGuid(),
                ErrandStatus       = "New",
                ComponentsNeeded   = componentsNeed,
                TypeOfVehicle      = vehicleType,
                TypOfCar           = carType,
                ModelName          = modelType,
                RegistrationNumber = regNr,
                Odometer           = odoMeterm,
                RegistrationDate   = regDate,
                Propellant         = typePropellant,
                HasTowbar          = hasTow,
                MaxNrPassengers    = maxPass,
                MaxLoad            = loadMax,
                Description        = writeDescription,
                Amount             = amountOfComp,
                FirstName          = null,
                LastName           = null,
                Competence         = null
            };



            if (errands.Count >= 1)
            {
                string jsonFile;

                using (var reader = new StreamReader(pathforErrand))
                {
                    jsonFile = reader.ReadToEnd();
                }

                var jsonRead = JsonConvert.DeserializeObject <List <Errands> >(jsonFile);
                errands.Add(errand);
                var jsonWrite = JsonConvert.SerializeObject(errands, Formatting.Indented);
                var fs        = File.OpenWrite(pathforErrand);
                using (var jsonWriter = new StreamWriter(fs))
                {
                    await jsonWriter.WriteAsync(jsonWrite);
                }
            }

            else
            {
                errands.Add(errand);
                var jsonWrite = JsonConvert.SerializeObject(errands, Formatting.Indented);
                var fs        = File.OpenWrite(pathforErrand);
                using (var jsonWriter = new StreamWriter(fs))
                {
                    await jsonWriter.WriteAsync(jsonWrite);
                }
            }
            ErrandViewer.Children.Clear();
            ErrandViewer.Children.Add(new UserControlNewErrand());
        }
Example #18
0
        /// <summary>
        /// Method to fetch list of data, filtered by request.
        /// </summary>
        /// <param name="request">Object of <c>InvokeRequest</c> that holds filter information to fetch data from the database</param>
        /// <returns>returns the generated list.</returns>
        public IQueryable <ErrandTableItem> GetErrandList(InvokeRequest request)
        {
            var tempList = Errands;
            //No matter what, get the employee ID first
            var userId = contextAccessor.HttpContext.User.Identity.Name;

            var employee = Employees.Where(em => em.EmployeeId == userId).First();

            //Filtering data first according to employee's role.
            if (employee.RoleTitle == "Coordinator")
            {
                tempList = Errands; //Create initial List for the specific employee role.

                if (request.RefNumber != null)
                {
                    tempList = tempList.Where(err => err.RefNumber.Contains(request.RefNumber)); // search input doesn't need to be exact.
                    //tempList = tempList.Where(err => err.RefNumber == request.RefNumber);
                }
                if (request.StatusId != null)
                {
                    tempList = tempList.Where(err => err.StatusId == request.StatusId);
                }
                if (request.DepartmentId != null)
                {
                    tempList = tempList.Where(err => err.DepartmentId == request.DepartmentId);
                }
            }
            if (employee.RoleTitle == "Manager")
            {
                tempList = Errands.Where(err => err.DepartmentId == employee.DepartmentId);

                if (request.RefNumber != null)
                {
                    tempList = tempList.Where(err => err.RefNumber.Contains(request.RefNumber));
                }
                if (request.StatusId != null)
                {
                    tempList = tempList.Where(err => err.StatusId == request.StatusId);
                }
                if (request.EmployeeId != null)
                {
                    tempList = tempList.Where(err => err.EmployeeId == request.EmployeeId);
                }
            }
            if (employee.RoleTitle == "Investigator")
            {
                tempList = Errands.Where(err => err.EmployeeId == employee.EmployeeId);

                if (request.RefNumber != null)
                {
                    tempList = tempList.Where(err => err.RefNumber.Contains(request.RefNumber));
                }
                if (request.StatusId != null)
                {
                    tempList = tempList.Where(err => err.StatusId == request.StatusId);
                }
            }

            //Joining tables with the resulting list. This is to show some information in a more user-friendly manner:example: Status name. department name.
            var errandList = from err in tempList
                             join stat in ErrandStatuses on err.StatusId equals stat.StatusId
                             join dep in Departments on err.DepartmentId equals dep.DepartmentId
                             into departmentErrand
                             from deptE in departmentErrand.DefaultIfEmpty()
                             join em in Employees on err.EmployeeId equals em.EmployeeId
                             into employeeErrand
                             from empE in employeeErrand.DefaultIfEmpty()
                             orderby err.RefNumber descending
                             select new ErrandTableItem

            {
                DateOfObservation = err.DateOfObservation,
                ErrandId          = err.ErrandId,
                RefNumber         = err.RefNumber,
                TypeOfCrime       = err.TypeOfCrime,
                StatusName        = stat.StatusName,
                DepartmentName    =
                    (err.DepartmentId == null ? "ej tillsatt" : deptE.DepartmentName),          //show "ej tillsatt" if no data available in this field.
                EmployeeName =
                    (err.EmployeeId == null ? "ej tillsatt" : empE.EmployeeName)
            };


            return(errandList);
        }