Exemplo n.º 1
0
        private void BtnSaveUpdateShop_OnClick(object sender, RoutedEventArgs e)
        {
            var btn = (Button)sender;

            // Tag attribute on button is bound to Id
            int shopId = (int)btn.Tag;

            // Get Inmate object from collection
            var shop = ToolTrackerService.Shops.SingleOrDefault(i => i.Id == shopId);

            var result = NotifyUser.AskToConfirm("Are you sure you want to save?", "Confirm Update");

            if (result != System.Windows.Forms.DialogResult.Yes)
            {
                return;
            }

            if (string.IsNullOrEmpty(shop?.Name))
            {
                NotifyUser.InvalidEntry("Please enter the new shop name", "Invalid Entry");
                return;
            }

            shop.Name = ToolTrackerService.MakeEveryWordUppercase(shop.Name);
            UpdateShop(shop);
        }
Exemplo n.º 2
0
 private void OfficerLoginWindow_OnLoaded(object sender, RoutedEventArgs e)
 {
     ToolTrackerService.Officers = new ObservableCollection <Officer>();
     ToolTrackerService.LoadOfficers();
     ListBoxNames.ItemsSource       = ToolTrackerService.Officers;
     ListBoxNames.DisplayMemberPath = "Name";
 }
Exemplo n.º 3
0
        private void TestLoaderWindow_OnLoaded(object sender, RoutedEventArgs e)
        {
            ToolTrackerService.Tools = new ObservableCollection <ToolViewModel>();
            ToolTrackerService.Shops = new ObservableCollection <Shop>();

            ToolTrackerService.LoadTools();
        }
Exemplo n.º 4
0
        private void BtnImport_OnClick(object sender, RoutedEventArgs e)
        {
            TextBlockStatus.Text = "Please wait...";
            var importService = new ImportToolsService();

            importService.ImportTools(_filePath);
            ToolTrackerService.LoadTools();
            TextBlockStatus.Text = "Import Complete";
        }
Exemplo n.º 5
0
        private void AddToolWindow_OnLoaded(object sender, RoutedEventArgs e)
        {
            ToolTrackerService.UpdateShopsCombobox(ComboBoxShops);

            textBlockStatus.Foreground = CommonUISettings.StatusColor;
            textBlockStatus.FontWeight = CommonUISettings.StatusFontWeight;
            textBlockStatus.FontSize   = CommonUISettings.StatusFontSize;

            textBoxToolNo.Focus();
        }
        private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(TextBoxName.Text))
            {
                Close();
            }

            ToolTrackerService.AddOfficer(TextBoxName.Text);
            Close();
        }
Exemplo n.º 7
0
        private void BtnSave_OnClick(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(textBoxShopName.Text))
            {
                textBlockStatus.Text = "Please enter the shop name.";
                textBoxShopName.Focus();
                return;
            }

            var newShop = new Shop {
                Name = textBoxShopName.Text.Trim()
            };

            newShop.Name = ToolTrackerService.MakeEveryWordUppercase(newShop.Name);

            try
            {
                using (var db = new UnitOfWork())
                {
                    bool shopExists = db.ShopsRepo.Exists(s => s.Name == newShop.Name);
                    if (shopExists)
                    {
                        textBlockStatus.Text = "This shop already exists.";
                        return;
                    }
                    else
                    { // add to db and collection
                        db.ShopsRepo.Add(newShop);
                        db.Commit();
                    }
                }
            }
            catch (EntityException ex)
            {
                ExceptionHandler.LogAndNotifyOfException(ex, ex.Message);
            }
            catch (Exception ex)
            {
                ExceptionHandler.LogAndNotifyOfException(ex, ex.Message);
            }

            ToolTrackerService.Shops.Add(newShop);

            // change text in cancel button to "I'm Finished"
            btnCancel.Content = "I'm Finished";

            // update status
            textBlockStatus.Text = $"{newShop.Name} has been added.";

            textBoxShopName.Clear();
            textBoxShopName.Focus();

            // Updates the ShopIndex prop in view models to correct combobox selection
            ToolTrackerService.UpdateIndicesAfterShopUpdate();
        }
Exemplo n.º 8
0
        private void BtnSave_OnClick(object sender, RoutedEventArgs e)
        {
            TextBlockStatus.Text = "";

            // Validate tool
            if (ValidateToolData())
            {
                return;
            }

            // Persist update to db
            using (var db = new UnitOfWork())
            {
                try
                {
                    var newTool = new Tool
                    {
                        ToolNumber  = textBoxToolNo.Text.Trim(),
                        Description = ToolTrackerService.MakeEveryWordUppercase(textBoxToolDesc.Text.Trim())
                    };

                    var toolNoExists = db.ToolsRepo.Exists(t => t.ToolNumber.Equals(newTool.ToolNumber));
                    if (toolNoExists)
                    {
                        TextBlockStatus.Text = "Tool number already exists.";
                        textBoxToolNo.Focus();
                        return;
                    }

                    var shop = (Shop)ComboBoxShops.SelectedItem;
                    newTool.ShopId = shop.Id;

                    db.ToolsRepo.Add(newTool);
                    db.Commit();

                    // Update observable collection
                    ToolTrackerService.MapToolToViewModel(newTool);
                    ToolTrackerService.SortTools();

                    TextBlockStatus.Text = $"{newTool.ToolNumber} added successfully.";
                }
                catch (EntityException ex)
                {
                    ExceptionHandler.LogAndNotifyOfException(ex, ex.Message);
                }
                catch (Exception ex)
                {
                    ExceptionHandler.LogAndNotifyOfException(ex, ex.Message);
                }

                btnCancel.Content = "I'm Finished";
                ResetForm();
            }
        }
Exemplo n.º 9
0
        private void LoadToolsIssued(Shop shop)
        {
            ToolTrackerService.ToolsIssued.Clear();
            var date = DatePickerDate.SelectedDate ?? DateTime.Today;

            if (shop.Name.Equals("All Shops"))
            {
                ListBoxToolsIssued.ItemsSource = ToolTrackerService.LoadAllToolsIssued(date);
                return;
            }

            ListBoxToolsIssued.ItemsSource = ToolTrackerService.LoadToolsIssued(shop, date);
        }
Exemplo n.º 10
0
        private void BtnSave_OnClick(object sender, RoutedEventArgs e)
        {
            var assignedShop = (Shop)comboBoxShops.SelectedItem;

            // create inmate object from data entered
            var newInmate = CreateInmateObject(assignedShop);

            string statusMsg = ToolTrackerService.ValidateInmateData(newInmate);

            if (AlertUserIfNotValidated(statusMsg))
            {
                return;
            }

            newInmate.FirstName = ToolTrackerService.MakeFirstLetterUppercase(newInmate.FirstName);
            newInmate.LastName  = ToolTrackerService.MakeFirstLetterUppercase(newInmate.LastName);

            // update database and collection
            try
            {
                using (var db = new UnitOfWork())
                {
                    // Used for validation but not needed here. Avoids re-adding the shop.
                    newInmate.AssignedShop = null;

                    db.InmatesRepo.Add(newInmate);
                    db.Commit();
                }
            }
            catch (EntityException ex)
            {
                ExceptionHandler.LogAndNotifyOfException(ex, ex.Message);
            }
            catch (Exception ex)
            {
                ExceptionHandler.LogAndNotifyOfException(ex, ex.Message);
            }

            ToolTrackerService.MapInmateToViewModel(newInmate);
            ToolTrackerService.SortInmates();

            // change text in cancel button to "I'm Finished"
            btnCancel.Content = "I'm Finished";

            // update status
            textBlockStatus.Text = $"{newInmate.FirstName} {newInmate.LastName} has been added.";

            ResetForm();
        }
Exemplo n.º 11
0
        private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
        {
            //StartLoaderAnimation();

            if (ToolTrackerService.Officer == null)
            {
                NotifyUser.Inform("An officer must be logged in.", "Officer Not Logged In");
                Environment.Exit(0);
            }

            #region Seed database
            //var seeder = new TestDataSeeder();

            //seeder.WipeOutData();
            //seeder.SeedShops();
            //seeder.SeedInmates();
            #endregion

            _toolsCheckedOutNext = new Queue <int>();
            _toolsCheckedOutBack = new Queue <int>();

            UpdateCheckedOutTotal(ToolTrackerService.GetCheckedOutTotal());

            TextBlockLoggedInName.Text = ToolTrackerService.Officer.Name;

            ToolTrackerService.Inmates         = new ObservableCollection <InmateViewModel>();
            ToolTrackerService.Shops           = new ObservableCollection <Shop>();
            ToolTrackerService.Tools           = new ObservableCollection <ToolViewModel>();
            ToolTrackerService.CheckOutInTools = new ObservableCollection <CheckToolOutInViewModel>();
            ToolTrackerService.ToolsIssued     = new ObservableCollection <ToolIssuedViewModel>();


            ToolTrackerService.UpdateShopsCombobox(comboBoxShops);
            ToolTrackerService.UpdateShopsCombobox(comboBoxShopsToolsIssued);
            UpdateToolsListBox();

            backgroundWorkerLoad                     = new BackgroundWorker();
            backgroundWorkerLoad.DoWork             += BackgroundWorkerLoad_DoWork;
            backgroundWorkerLoad.RunWorkerCompleted += BackgroundWorkerLoad_RunWorkerCompleted;

            _busyIndicator.IsBusy = true;
            backgroundWorkerLoad.RunWorkerAsync();

            DatePickerDate.SelectedDate = DateTime.Today;

            SettingsService.ReadXmlSettings();
            //StopLoaderAnimation();
        }
Exemplo n.º 12
0
        private void UpdateToolsCheckedOutIn()
        {
            if (comboBoxInmates.SelectedIndex < 1)
            {
                return;
            }
            var inmate = (Inmate)comboBoxInmates.SelectedItem;

            ToolTrackerService.SelectedInmateId = inmate.Id;
            ToolTrackerService.LoadCheckOutInTools();
            listBoxToolsCheckOutIn.ItemsSource = ToolTrackerService.CheckOutInTools;

            UpdateCheckedOutTotal();

            StackPanelNextPrevButtons.Visibility = Visibility.Visible;
            LoadCheckedOutQueues();
        }
Exemplo n.º 13
0
        private void BtnSaveUpdateTool_OnClick(object sender, RoutedEventArgs e)
        {
            var btn = (Button)sender;

            // Tag attribute on button is bound to Id
            int toolId = (int)btn.Tag;

            // Get tool obj from collection
            var tool = ToolTrackerService.Tools.SingleOrDefault(t => t.Id == toolId);

            // Ensure description is uppercase
            if (tool != null)
            {
                tool.Description = ToolTrackerService.MakeEveryWordUppercase(tool.Description);
            }

            // update/save tool
            UpdateTool(tool);
        }
Exemplo n.º 14
0
        private void TabControl_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //_counter++;
            //Console.WriteLine("counter: " + _counter);

            if (!TabItemToolsIssued.IsSelected)
            {
                comboBoxShopsToolsIssued.SelectedIndex = 0;
                ToolTrackerService.ToolsIssued?.Clear();
            }

            if (TabItemCheckOutInTools.IsSelected)
            {
                TextBlockTabHeader.Text = "CHECK OUT/IN TOOLS";
            }
            if (!TabItemCheckOutInTools.IsSelected)
            {
                comboBoxShops.SelectedIndex   = 0;
                comboBoxInmates.SelectedIndex = 0;
                ToolTrackerService.CheckOutInTools.Clear();
                TextBlockCheckOutTotal.Text          = ToolTrackerService.GetCheckedOutTotal();
                StackPanelNextPrevButtons.Visibility = Visibility.Hidden;
            }

            if (TabItemToolsIssued.IsSelected)
            {
                TextBlockTabHeader.Text = "TOOLS ISSUED";
            }
            if (TabItemInmates.IsSelected)
            {
                TextBlockTabHeader.Text = "UPDATE INMATES";
            }
            if (TabItemTools.IsSelected)
            {
                TextBlockTabHeader.Text = "UPDATE TOOLS";
            }

            if (TabItemShops.IsSelected)
            {
                TextBlockTabHeader.Text = "UPDATE SHOPS";
            }
        }
Exemplo n.º 15
0
        private void BtnSaveUpdateInmate_OnClick(object sender, RoutedEventArgs e)
        {
            var btn = (Button)sender;

            // Tag attribute on button is bound to Id
            int inmateId = (int)btn.Tag;

            // Get Inmate object from collection
            var inmate = ToolTrackerService.Inmates.SingleOrDefault(i => i.Id == inmateId);

            var result = NotifyUser.AskToConfirm("Are you sure you want to save?", "Confirm Update");

            if (result != System.Windows.Forms.DialogResult.Yes)
            {
                return;
            }

            if (inmate != null && inmate.AssignedShop == null)
            {
                inmate.AssignedShop = ToolTrackerService.Shops.FirstOrDefault(s => s.Id == inmate.ShopId);
            }

            string statusMsg = ToolTrackerService.ValidateInmateData(inmate);

            if (statusMsg != null)
            {
                NotifyUser.InvalidEntry(statusMsg, "Invalid Entry");
                return;
            }


            // Ensure first letter is uppercase
            if (inmate != null)
            {
                inmate.FirstName = ToolTrackerService.MakeFirstLetterUppercase(inmate.FirstName);
                inmate.LastName  = ToolTrackerService.MakeFirstLetterUppercase(inmate.LastName);
            }


            UpdateInmate(inmate);
        }
Exemplo n.º 16
0
 private void BackgroundWorkerLoad_DoWork(object sender, DoWorkEventArgs e)
 {
     ToolTrackerService.LoadInmates();
     ToolTrackerService.LoadShops();
     ToolTrackerService.LoadTools();
 }
Exemplo n.º 17
0
        private void BtnDeleteShop_OnClick(object sender, RoutedEventArgs e)
        {
            var btn    = (Button)sender;
            int shopId = (int)btn.Tag;

            var shopToDel = ToolTrackerService.Shops.FirstOrDefault(s => s.Id == shopId);

            var result =
                NotifyUser.AskToConfirm(
                    $"Are you absolutely positive you want to delete {shopToDel?.Name}? Inmates assigned to this shop will be un-assigned.",
                    "Confirm Delete");

            if (result != System.Windows.Forms.DialogResult.Yes)
            {
                return;
            }

            // Remove from db
            using (var db = new UnitOfWork())
            {
                var shop = db.ShopsRepo.FindById(shopId);

                if (shop == null)
                {
                    NotifyUser.SomethingIsMissing("Sorry, this shop was not found.", "Shop No Found");
                    return;
                }

                if (shop.Name.Equals(ToolTrackerService.AllShopsName))
                {
                    NotifyUser.Forbidden("'All Shops' cannot be removed.", "Not Allowed");
                    return;
                }

                // Check if any inmates assigned to the shop.
                // If so, un-assign inmates. Otherwise get a FK restraint exception.
                bool inmatesAssigned = db.InmatesRepo.Exists(i => i.ShopId == shop.Id);
                if (inmatesAssigned)
                {
                    var inmates = db.InmatesRepo.FindAll(i => i.ShopId == shop.Id);
                    foreach (var inmate in inmates)
                    {
                        inmate.ShopId = null;
                        db.InmatesRepo.Update(inmate);
                    }
                }

                try
                {
                    db.ShopsRepo.Delete(shop);
                    db.Commit();
                }
                catch (EntityException ex)
                {
                    ExceptionHandler.LogAndNotifyOfException(ex, ex.Message);
                }
                catch (Exception ex)
                {
                    ExceptionHandler.LogAndNotifyOfException(ex, ex.Message);
                }

                // Remove from collection
                var shopElement = ToolTrackerService.Shops.SingleOrDefault(s => s.Id == shop.Id);
                ToolTrackerService.Shops.Remove(shopElement);

                // Updates the ShopIndex prop in view models to correct combobox selection
                ToolTrackerService.UpdateIndicesAfterShopUpdate();
            }
        }