private void LoadCategories()
 {
     try
     {
         foreach (Category category in this.UnitOfWork.CategoryRepository.GetAll())
         {
             this.Categories.Add(category);
         }
         if (this.Categories.Count <= 0)
         {
             return;
         }
         int min = this.Categories.Min <Category>((Func <Category, int>)(o => o.Order));
         this.SelectedCategory = this.Categories.FirstOrDefault <Category>((Func <Category, bool>)(c => c.Order == min));
     }
     catch (SqlException ex)
     {
         SplashScreenHelper.CloseInstant();
         int num = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
         NewTicketViewModel.logger.Error("Database error: {0}", ex.Message);
     }
     catch (DataException ex)
     {
         SplashScreenHelper.CloseInstant();
         int num = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
         NewTicketViewModel.logger.Error("Database error: {0}", ex.Message);
     }
 }
 public NewTicketViewModel()
 {
     NewTicketViewModel.logger.Debug("VIEWMODEL LOADING: NewTicketViewModel");
     AuthenticationService.Instance.SuspendService = false;
     this.OpenTickets = new ObservableCollection <TicketViewModel>();
     this.Categories  = new ObservableCollection <Category>();
     this.UnitOfWork  = new UnitOfWork();
     this.LoadCategories();
     SplashScreenHelper.ShowText(Resources.SplashScreenLoadingProducts);
     SplashScreenHelper.Close();
     if (AuthenticationService.Instance.AuthenticatedMember == null)
     {
         LockScreenHelper.Show();
     }
     this.CurrentTicket = new TicketViewModel()
     {
         Ticket              = new Ticket(),
         Visibility          = Visibility.Collapsed,
         NewTicket           = true,
         ItemSelectedCommand = (ICommand) new RelayCommand(new Action(this.SelectedItemChanged))
     };
     this.OpenTickets.Add(this.CurrentTicket);
     this.OpenCheckoutSheet = this.UnitOfWork.CheckoutSheetRepository.GetLastOpenSheet();
     if (this.OpenCheckoutSheet == null)
     {
         if (NavigatorHelper.NavigationService == null)
         {
             return;
         }
         NavigatorHelper.NavigationService.Navigate(new Uri("Views/NewTicket/NewCheckoutSheetPageView.xaml", UriKind.Relative));
         NavigatorHelper.NavigationService.RemoveBackEntry();
     }
     else
     {
         try
         {
             foreach (Ticket ticket in this.UnitOfWork.TicketRepository.GetOpenTicketsNoTracking())
             {
                 this.OpenTickets.Add(new TicketViewModel()
                 {
                     Ticket = ticket,
                     TicketControlClicked = (ICommand) new RelayCommand <TicketViewModel>(new Action <TicketViewModel>(this.TicketSelected))
                 });
             }
         }
         catch (SqlException ex)
         {
             SplashScreenHelper.CloseInstant();
             int num = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
             NewTicketViewModel.logger.Error("Database error: {0}", ex.Message);
         }
         catch (DataException ex)
         {
             SplashScreenHelper.CloseInstant();
             int num = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
             NewTicketViewModel.logger.Error("Database error: {0}", ex.Message);
         }
         NewTicketViewModel.logger.Debug("VIEWMODEL LOADED: NewTicketViewModel");
     }
 }
 private void ConfirmTicketCommandExec()
 {
     if (this.CurrentTicket == null || this.CurrentTicket.Ticket == null || this.CurrentTicket.Ticket.TicketLines.Count < 1)
     {
         int num1 = (int)WPFMessageBox.Show(Resources.MessageEmptyTicket, Resources.MessageEmptyTicketTitle, MessageBoxButton.OK, MessageBoxImage.Exclamation);
     }
     else
     {
         this.CurrentTicket.Ticket.CreationTime = DateTime.Now;
         this.OpenCheckoutSheet = this.UnitOfWork.CheckoutSheetRepository.GetLastOpenSheet();
         if (this.OpenCheckoutSheet == null)
         {
             if (NavigatorHelper.NavigationService == null)
             {
                 return;
             }
             NavigatorHelper.NavigationService.Navigate(new Uri("Views/NewTicket/NewCheckoutSheetPageView.xaml", UriKind.Relative));
             NavigatorHelper.NavigationService.RemoveBackEntry();
         }
         else
         {
             this.CurrentTicket.Ticket.CheckoutSheet = this.OpenCheckoutSheet;
             try
             {
                 this.UnitOfWork.TicketRepository.Add(this.CurrentTicket.Ticket);
                 this.UnitOfWork.Save();
                 NewTicketViewModel.logger.Info("New order created: " + (object)this.currentTicket.Ticket.Id);
                 if (NavigatorHelper.NavigationService == null)
                 {
                     return;
                 }
                 NavigatorHelper.NavigationService.Refresh();
                 NavigatorHelper.NavigationService.RemoveBackEntry();
             }
             catch (SqlException ex)
             {
                 int num2 = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
                 NewTicketViewModel.logger.Error("Database error: {0}", ex.Message);
                 if (NavigatorHelper.NavigationService == null)
                 {
                     return;
                 }
                 NavigatorHelper.NavigationService.Refresh();
                 NavigatorHelper.NavigationService.RemoveBackEntry();
             }
             catch (DataException ex)
             {
                 SplashScreenHelper.CloseInstant();
                 int num2 = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
                 NewTicketViewModel.logger.Error("Database error: {0}", ex.Message);
                 if (NavigatorHelper.NavigationService == null)
                 {
                     return;
                 }
                 NavigatorHelper.NavigationService.Refresh();
                 NavigatorHelper.NavigationService.RemoveBackEntry();
             }
         }
     }
 }
 private void LoadUsers()
 {
     try
     {
         this.MemberFilterList.Add(new Member()
         {
             FirstName = "*"
         });
         foreach (Member member in this.UnitOfWork.MemberRepository.GetAll())
         {
             this.MemberFilterList.Add(member);
         }
     }
     catch (SqlException ex)
     {
         SplashScreenHelper.CloseInstant();
         int num = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
         ReportsViewModel.logger.Error("Database error: {0}", ex.Message);
     }
     catch (DataException ex)
     {
         SplashScreenHelper.CloseInstant();
         int num = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
         ReportsViewModel.logger.Error("Database error: {0}", ex.Message);
     }
 }
Example #5
0
 private void HideProductCommandExec()
 {
     if (WPFMessageBox.Show(Resources.PageConfigurationProductsProductConfirmHide, Resources.PageConfigurationProductsProductConfirmHideTitle, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Cancel) == MessageBoxResult.No)
     {
         return;
     }
     try
     {
         this.SelectedProduct.IsHidden = true;
         this.UnitOfWork.ProductRepository.Update(this.SelectedProduct);
         this.UnitOfWork.Save();
         if (NavigatorHelper.NavigationService == null)
         {
             return;
         }
         NavigatorHelper.NavigationService.Refresh();
     }
     catch (SqlException ex)
     {
         SplashScreenHelper.CloseInstant();
         int num = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
         ConfigurationViewModel.logger.Error("Database error: {0}", ex.Message);
     }
     catch (DataException ex)
     {
         SplashScreenHelper.CloseInstant();
         int num = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
         ConfigurationViewModel.logger.Error("Database error: {0}", ex.Message);
     }
 }
Example #6
0
 private void AddMemberCard(MemberCard memberCard)
 {
     try
     {
         if (AuthenticationService.Instance.AuthenticatedMember == null)
         {
             return;
         }
         Member byId = this.UnitOfWork.MemberRepository.GetById(AuthenticationService.Instance.AuthenticatedMember.Id);
         if (byId != null)
         {
             this.NewMemberCard.CreatedBy = byId;
         }
         this.UnitOfWork.MemberCardRepository.Add(memberCard);
         this.UnitOfWork.Save();
         int num = (int)WPFMessageBox.Show(Resources.PageNewMembercardUpdateSuccess, Resources.PageNewMembercardUpdateSuccessTitle, MessageBoxButton.OK, MessageBoxImage.Asterisk);
         NewMembercardViewModel.logger.Info("MemberCard added successfully to existing member, card id: " + (object)memberCard.Id + ", member: " + (object)memberCard.Member.Id);
         NavigatorHelper.NavigationService.Refresh();
     }
     catch (SqlException ex)
     {
         SplashScreenHelper.CloseInstant();
         int num = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
         NewMembercardViewModel.logger.Error("Database error: {0}", ex.Message);
         if (NavigatorHelper.NavigationService == null)
         {
             return;
         }
         NavigatorHelper.NavigationService.Refresh();
     }
 }
 private void CloseCheckoutSheetCommandExec()
 {
     this.CheckoutSheet.CloseTime = new DateTime?(DateTime.Now);
     if (AuthenticationService.Instance.AuthenticatedMember != null)
     {
         this.AuthenticatedMember     = this.UnitOfWork.MemberRepository.GetById(AuthenticationService.Instance.AuthenticatedMember.Id);
         this.CheckoutSheet.ClosedBy  = this.AuthenticatedMember;
         this.CheckoutSheet.CloseTime = new DateTime?(DateTime.Now);
     }
     try
     {
         this.UnitOfWork.CheckoutSheetRepository.Update(this.CheckoutSheet);
         this.UnitOfWork.Save();
     }
     catch (SqlException ex)
     {
         SplashScreenHelper.CloseInstant();
         int num = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
         CheckoutSheetViewModel.logger.Error("Database error: {0}", ex.Message);
         if (NavigatorHelper.NavigationService != null)
         {
             NavigatorHelper.NavigationService.Refresh();
             NavigatorHelper.NavigationService.RemoveBackEntry();
         }
     }
     catch (DataException ex)
     {
         SplashScreenHelper.CloseInstant();
         int num = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
         CheckoutSheetViewModel.logger.Error("Database error: {0}", ex.Message);
         if (NavigatorHelper.NavigationService != null)
         {
             NavigatorHelper.NavigationService.Refresh();
             NavigatorHelper.NavigationService.RemoveBackEntry();
         }
     }
     catch (FormattedDbEntityValidationException ex)
     {
         SplashScreenHelper.CloseInstant();
         int num = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
         CheckoutSheetViewModel.logger.Error("Database error: {0}", ex.Message);
         if (NavigatorHelper.NavigationService != null)
         {
             NavigatorHelper.NavigationService.Refresh();
             NavigatorHelper.NavigationService.RemoveBackEntry();
         }
     }
     new Thread(new ThreadStart(this.GenerateReport)).Start();
     if (NavigatorHelper.NavigationService == null)
     {
         return;
     }
     NavigatorHelper.NavigationService.Navigate(new Uri("Views/NewTicket/NewTicketPageView.xaml", UriKind.Relative));
     NavigatorHelper.NavigationService.RemoveBackEntry();
 }
Example #8
0
 private void DeleteProductCommandExec()
 {
     if (WPFMessageBox.Show(Resources.PageConfigurationProductsProductConfirmDeletion, Resources.PageConfigurationProductsProductConfirmDeletionTitle, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Cancel) == MessageBoxResult.No)
     {
         return;
     }
     try
     {
         if (this.SelectedProduct != null)
         {
             if (!string.IsNullOrWhiteSpace(this.SelectedProduct.PicturePath))
             {
                 File.Delete(Directory.GetCurrentDirectory() + "\\Images\\" + this.selectedProduct.PicturePath);
             }
         }
     }
     catch (Exception ex)
     {
         ConfigurationViewModel.logger.Warn("Could not delete product image file:", ex.Message + ex.InnerException?.ToString());
     }
     try
     {
         this.UnitOfWork.ProductRepository.Delete(this.SelectedProduct);
         this.UnitOfWork.Save();
         if (NavigatorHelper.NavigationService == null)
         {
             return;
         }
         NavigatorHelper.NavigationService.Refresh();
     }
     catch (SqlException ex)
     {
         SplashScreenHelper.CloseInstant();
         int num = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
         ConfigurationViewModel.logger.Error("Database error: {0}", ex.Message);
     }
     catch (DataException ex)
     {
         SplashScreenHelper.CloseInstant();
         int num = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
         ConfigurationViewModel.logger.Error("Database error: {0}", ex.Message);
     }
 }
Example #9
0
 private void LoadRoles()
 {
     try
     {
         foreach (Role role in this.UnitOfWork.RoleRepository.GetAll())
         {
             this.UserRolesList.Add(role);
         }
     }
     catch (SqlException ex)
     {
         SplashScreenHelper.CloseInstant();
         int num = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
         ConfigurationViewModel.logger.Error("Database error: {0}", ex.Message);
     }
     catch (DataException ex)
     {
         SplashScreenHelper.CloseInstant();
         int num = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
         ConfigurationViewModel.logger.Error("Database error: {0}", ex.Message);
     }
 }
Example #10
0
 private void LoadHiddenProducts()
 {
     try
     {
         foreach (Product product in this.UnitOfWork.ProductRepository.GetHidden())
         {
             this.HiddenProducts.Add(product);
         }
     }
     catch (SqlException ex)
     {
         SplashScreenHelper.CloseInstant();
         int num = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
         ConfigurationViewModel.logger.Error("Database error: {0}", ex.Message);
     }
     catch (DataException ex)
     {
         SplashScreenHelper.CloseInstant();
         int num = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
         ConfigurationViewModel.logger.Error("Database error: {0}", ex.Message);
     }
 }
Example #11
0
 private void UpdateMemberCard(MemberCard mc)
 {
     try
     {
         this.UnitOfWork.MemberCardRepository.Update(mc);
         this.UnitOfWork.Save();
         int num = (int)WPFMessageBox.Show(Resources.PageNewMembercardUpdateSuccess, Resources.PageNewMembercardUpdateSuccessTitle, MessageBoxButton.OK, MessageBoxImage.Asterisk);
         NewMembercardViewModel.logger.Info("MemberCard updated successfully: " + (object)mc.Id);
         NavigatorHelper.NavigationService.Refresh();
     }
     catch (SqlException ex)
     {
         SplashScreenHelper.CloseInstant();
         int num = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
         NewMembercardViewModel.logger.Error("Database error: {0}", ex.Message);
         if (NavigatorHelper.NavigationService == null)
         {
             return;
         }
         NavigatorHelper.NavigationService.Refresh();
     }
 }
Example #12
0
        public App()
        {
            this.InitializeComponent();
            MediaTypeNames.Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;
            if (Pos.Properties.Settings.Default.UpdateSettings)
            {
                Pos.Properties.Settings.Default.Upgrade();
                Pos.Properties.Settings.Default.UpdateSettings = false;
                Pos.Properties.Settings.Default.Save();
            }
            Dal.Settings.ConnectionString = new SqlConnectionStringBuilder()
            {
                Password       = Pos.Properties.Settings.Default.DbPassword,
                UserID         = Pos.Properties.Settings.Default.DbUser,
                InitialCatalog = Pos.Properties.Settings.Default.DbCatalog,
                DataSource     = Pos.Properties.Settings.Default.DbInstance
            }.ToString();
            MainWindowView      mainWindowView      = new MainWindowView();
            MainWindowViewModel mainWindowViewModel = new MainWindowViewModel();

            mainWindowView.DataContext = (object)mainWindowViewModel;
            MediaTypeNames.Application.Current.MainWindow = (Window)mainWindowView;
            NavigatorHelper.NavigationService             = mainWindowView.MainFrame.NavigationService;
            mainWindowView.Show();
            mainWindowView.Visibility = Visibility.Hidden;
            if (!string.IsNullOrEmpty(Pos.Properties.Settings.Default.SerialPortCashDrawer))
            {
                CashDrawerService.ComPortName = Pos.Properties.Settings.Default.SerialPortCashDrawer;
                if (!CashDrawerService.Connect())
                {
                    int num = (int)WPFMessageBox.Show(Resources.ExceptionSerial, Resources.ExceptionSerialTitle, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }
            }
            try
            {
                new UnitOfWork().CategoryRepository.GetAll();
            }
            catch (SqlException ex)
            {
                SplashScreenHelper.CloseInstant();
                int num = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
                App.logger.Error("Database error: {0}", ex.Message);
                NavigatorHelper.NavigationService.Navigate(new Uri("Views/Settings/SettingsPageView.xaml", UriKind.Relative));
                NavigatorHelper.NavigationService.RemoveBackEntry();
                return;
            }
            catch (DataException ex)
            {
                SplashScreenHelper.CloseInstant();
                int num = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
                App.logger.Error("Database error: {0}", ex.Message);
                NavigatorHelper.NavigationService.Navigate(new Uri("Views/Settings/SettingsPageView.xaml", UriKind.Relative));
                NavigatorHelper.NavigationService.RemoveBackEntry();
                return;
            }
            catch (InvalidOperationException ex)
            {
                SplashScreenHelper.CloseInstant();
                int num = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
                App.logger.Error("Database error: {0}", ex.Message);
                NavigatorHelper.NavigationService.Navigate(new Uri("Views/Settings/SettingsPageView.xaml", UriKind.Relative));
                NavigatorHelper.NavigationService.RemoveBackEntry();
                return;
            }
            if (string.IsNullOrEmpty(Pos.Properties.Settings.Default.NfcReaderName))
            {
                LockScreenHelper.Hide();
                NavigatorHelper.NavigationService.Navigate(new Uri("Views/Settings/SettingsPageView.xaml", UriKind.Relative));
                NavigatorHelper.NavigationService.RemoveBackEntry();
            }
            else
            {
                AuthenticationService.Instance.Inititialize(new PcscService(Pos.Properties.Settings.Default.NfcReaderName), Pos.Properties.Settings.Default.AuthenticationTimeout);
                AuthenticationService.Instance.MemberAuthenticated += (AuthenticationService.AuthenticationEventHandler)((o, e) =>
                {
                    if (!e.AuthenticatedMember.Roles.Any <Role>())
                    {
                        return;
                    }
                    LockScreenHelper.Hide();
                });
                AuthenticationService.Instance.MemberDeauthenticated += (AuthenticationService.AuthenticationEventHandler) delegate
                {
                    LockScreenHelper.Show();
                };
                NavigatorHelper.NavigationService.Navigate(new Uri("Views/NewTicket/NewTicketPageView.xaml", UriKind.Relative));
                NavigatorHelper.NavigationService.RemoveBackEntry();
            }
        }
Example #13
0
 private void SaveCommandExec()
 {
     if (this.SelectedMenuItem == "AddCategoryControlView")
     {
         this.NewCategory.Order = this.CategoryX;
         if (string.IsNullOrWhiteSpace(this.NewCategory.Name))
         {
             int num = (int)WPFMessageBox.Show(Resources.ValidationGeneral, Resources.ValidationGeneralTitle, MessageBoxButton.OK, MessageBoxImage.Exclamation);
             return;
         }
         if (this.UnitOfWork.CategoryRepository.GetByName(this.NewCategory.Name) != null)
         {
             int num = (int)WPFMessageBox.Show(Resources.ValidationCategorytNameUnique, Resources.ValidationCategoryNameUniqueTitle, MessageBoxButton.OK, MessageBoxImage.Exclamation);
             return;
         }
         if (!string.IsNullOrWhiteSpace(this.NewCategory.ImagePath))
         {
             try
             {
                 string str = Guid.NewGuid().ToString();
                 using (Bitmap bitmap = new Bitmap(this.NewCategory.ImagePath))
                 {
                     double num    = Math.Min(100.0 / (double)bitmap.Width, 100.0 / (double)bitmap.Height);
                     int    width  = (int)((double)bitmap.Width * num);
                     int    height = (int)((double)bitmap.Height * num);
                     using (Image image = (Image) new Bitmap(width, height))
                     {
                         using (Graphics graphics = Graphics.FromImage(image))
                         {
                             graphics.SmoothingMode     = SmoothingMode.AntiAlias;
                             graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                             graphics.DrawImage((Image)bitmap, 0, 0, width, height);
                         }
                         string filename = Directory.GetCurrentDirectory() + "\\Images\\" + str + ".png";
                         image.Save(filename, ImageFormat.Png);
                     }
                 }
                 this.NewCategory.ImagePath = str + ".png";
             }
             catch (Exception ex)
             {
                 int num = (int)WPFMessageBox.Show(ex.Message, "", MessageBoxButton.OK, MessageBoxImage.Hand);
                 ConfigurationViewModel.logger.Error("Error while resizing image: {0}", ex.Message);
                 return;
             }
         }
         this.UnitOfWork.CategoryRepository.Add(this.NewCategory);
     }
     else if (this.SelectedMenuItem == "AddProductControlView")
     {
         if (this.SelectedHiddenProduct != null)
         {
             this.SelectedHiddenProduct.Xpos     = this.ProductX;
             this.SelectedHiddenProduct.YPos     = this.ProductY;
             this.SelectedHiddenProduct.Category = this.SelectedCategory;
             this.SelectedHiddenProduct.IsHidden = false;
             this.UnitOfWork.ProductRepository.Update(this.SelectedHiddenProduct);
         }
         else
         {
             this.NewProduct.IsHidden    = false;
             this.NewProduct.Xpos        = this.ProductX;
             this.NewProduct.YPos        = this.ProductY;
             this.NewProduct.DateAdded   = DateTime.Now;
             this.NewProduct.Category    = this.SelectedCategory;
             this.NewProduct.TaxCategory = this.UnitOfWork.TaxCategoryRepository.GetById(1);
             if (AuthenticationService.Instance.AuthenticatedMember != null)
             {
                 this.NewProduct.AddedBy = this.UnitOfWork.MemberRepository.GetById(AuthenticationService.Instance.AuthenticatedMember.Id);
             }
             if (string.IsNullOrWhiteSpace(this.NewProduct.Name) || this.NewProduct.Price <= 0.0 || this.NewProduct.PriceCoin <= 0)
             {
                 int num = (int)WPFMessageBox.Show(Resources.ValidationGeneral, Resources.ValidationGeneralTitle, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                 return;
             }
             if (this.UnitOfWork.ProductRepository.GetByName(this.NewProduct.Name) != null)
             {
                 int num = (int)WPFMessageBox.Show(Resources.ValidationProductNameUnique, Resources.ValidationProductNameUniqueTitle, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                 return;
             }
             if (!string.IsNullOrWhiteSpace(this.NewProduct.PicturePath))
             {
                 try
                 {
                     string str = Guid.NewGuid().ToString();
                     using (Bitmap bitmap = new Bitmap(this.NewProduct.PicturePath))
                     {
                         double num    = Math.Min(100.0 / (double)bitmap.Width, 100.0 / (double)bitmap.Height);
                         int    width  = (int)((double)bitmap.Width * num);
                         int    height = (int)((double)bitmap.Height * num);
                         using (Image image = (Image) new Bitmap(width, height))
                         {
                             using (Graphics graphics = Graphics.FromImage(image))
                             {
                                 graphics.SmoothingMode     = SmoothingMode.AntiAlias;
                                 graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                                 graphics.DrawImage((Image)bitmap, 0, 0, width, height);
                             }
                             string filename = Directory.GetCurrentDirectory() + "\\Images\\" + str + ".png";
                             image.Save(filename, ImageFormat.Png);
                         }
                     }
                     this.NewProduct.PicturePath = str + ".png";
                 }
                 catch (Exception ex)
                 {
                     int num = (int)WPFMessageBox.Show(ex.Message, "", MessageBoxButton.OK, MessageBoxImage.Hand);
                     ConfigurationViewModel.logger.Error("Error while resizing image: {0}", ex.Message);
                     return;
                 }
             }
             this.UnitOfWork.ProductRepository.Add(this.NewProduct);
         }
     }
     else if (this.SelectedMenuItem == "EditProductControlView")
     {
         if (this.SelectedProduct == null)
         {
             return;
         }
         if (string.IsNullOrWhiteSpace(this.SelectedProduct.Name) || this.SelectedProduct.Price <= 0.0 || this.SelectedProduct.PriceCoin <= 0)
         {
             int num = (int)WPFMessageBox.Show(Resources.ValidationGeneral, Resources.ValidationGeneralTitle, MessageBoxButton.OK, MessageBoxImage.Exclamation);
             return;
         }
         if (!string.IsNullOrWhiteSpace(this.NewProductImagePath))
         {
             try
             {
                 string str = Guid.NewGuid().ToString();
                 using (Bitmap bitmap = new Bitmap(this.NewProductImagePath))
                 {
                     double num    = Math.Min(100.0 / (double)bitmap.Width, 100.0 / (double)bitmap.Height);
                     int    width  = (int)((double)bitmap.Width * num);
                     int    height = (int)((double)bitmap.Height * num);
                     using (Image image = (Image) new Bitmap(width, height))
                     {
                         using (Graphics graphics = Graphics.FromImage(image))
                         {
                             graphics.SmoothingMode     = SmoothingMode.AntiAlias;
                             graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                             graphics.DrawImage((Image)bitmap, 0, 0, width, height);
                         }
                         string filename = Directory.GetCurrentDirectory() + "\\Images\\" + str + ".png";
                         image.Save(filename, ImageFormat.Png);
                     }
                 }
                 this.SelectedProduct.PicturePath = str + ".png";
             }
             catch (Exception ex)
             {
                 int num = (int)WPFMessageBox.Show(ex.Message, "", MessageBoxButton.OK, MessageBoxImage.Hand);
                 ConfigurationViewModel.logger.Error("Error while resizing image: {0}", ex.Message);
                 return;
             }
         }
         this.UnitOfWork.ProductRepository.Update(this.SelectedProduct);
     }
     else if (this.SelectedMenuItem == "EditCategoryControlView")
     {
         if (string.IsNullOrWhiteSpace(this.SelectedCategory.Name))
         {
             int num = (int)WPFMessageBox.Show(Resources.ValidationGeneral, Resources.ValidationGeneralTitle, MessageBoxButton.OK, MessageBoxImage.Exclamation);
             return;
         }
         if (this.UnitOfWork.CategoryRepository.GetByName(this.SelectedCategory.Name) != null)
         {
             int num = (int)WPFMessageBox.Show(Resources.ValidationCategorytNameUnique, Resources.ValidationCategoryNameUniqueTitle, MessageBoxButton.OK, MessageBoxImage.Exclamation);
             return;
         }
         if (!string.IsNullOrWhiteSpace(this.NewCategoryImagePath))
         {
             try
             {
                 string str = Guid.NewGuid().ToString();
                 using (Bitmap bitmap = new Bitmap(this.NewCategoryImagePath))
                 {
                     double num    = Math.Min(100.0 / (double)bitmap.Width, 100.0 / (double)bitmap.Height);
                     int    width  = (int)((double)bitmap.Width * num);
                     int    height = (int)((double)bitmap.Height * num);
                     using (Image image = (Image) new Bitmap(width, height))
                     {
                         using (Graphics graphics = Graphics.FromImage(image))
                         {
                             graphics.SmoothingMode     = SmoothingMode.AntiAlias;
                             graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                             graphics.DrawImage((Image)bitmap, 0, 0, width, height);
                         }
                         string filename = Directory.GetCurrentDirectory() + "\\Images\\" + str + ".png";
                         image.Save(filename, ImageFormat.Png);
                     }
                 }
                 this.SelectedCategory.ImagePath = str + ".png";
             }
             catch (Exception ex)
             {
                 int num = (int)WPFMessageBox.Show(ex.Message, "", MessageBoxButton.OK, MessageBoxImage.Hand);
                 ConfigurationViewModel.logger.Error("Error while resizing image: {0}", ex.Message);
                 return;
             }
         }
         this.UnitOfWork.CategoryRepository.Update(this.SelectedCategory);
     }
     else if (this.SelectedMenuItem == Resources.PageConfigurationMenuUserRights)
     {
         this.SelectedUser.Roles = this.SelectedRoles;
         this.UnitOfWork.MemberRepository.Update(this.SelectedUser);
     }
     try
     {
         this.UnitOfWork.Save();
         if (NavigatorHelper.NavigationService == null)
         {
             return;
         }
         NavigatorHelper.NavigationService.Refresh();
     }
     catch (SqlException ex)
     {
         SplashScreenHelper.CloseInstant();
         int num = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
         ConfigurationViewModel.logger.Error("Database error: {0}", ex.Message);
     }
     catch (DataException ex)
     {
         SplashScreenHelper.CloseInstant();
         int num = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
         ConfigurationViewModel.logger.Error("Database error: {0}", ex.Message);
     }
 }
Example #14
0
 private void DeleteCategoryCommandExec()
 {
     if (WPFMessageBox.Show(Resources.PageConfigurationProductsCategoryConfirmDeletion, Resources.PageConfigurationProductsCategoryConfirmDeletionTitle, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Cancel) == MessageBoxResult.No)
     {
         return;
     }
     if (this.SelectedCategory != null && this.SelectedCategory.Products != null && this.SelectedCategory.Products.Count > 0)
     {
         if (WPFMessageBox.Show(Resources.PageConfigurationProductsCategoryContainsProducts, Resources.PageConfigurationProductsCategoryContainsProductsTitle, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Cancel) == MessageBoxResult.No)
         {
             return;
         }
         foreach (Product product in (Collection <Product>) this.SelectedCategory.Products)
         {
             product.Category = (Category)null;
             product.IsHidden = true;
         }
         try
         {
             this.UnitOfWork.CategoryRepository.Update(this.SelectedCategory);
             this.UnitOfWork.Save();
         }
         catch (SqlException ex)
         {
             SplashScreenHelper.CloseInstant();
             int num = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
             ConfigurationViewModel.logger.Error("Database error: {0}", ex.Message);
         }
         catch (DataException ex)
         {
             SplashScreenHelper.CloseInstant();
             int num = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
             ConfigurationViewModel.logger.Error("Database error: {0}", ex.Message);
         }
     }
     try
     {
         if (this.SelectedCategory != null)
         {
             if (!string.IsNullOrWhiteSpace(this.SelectedCategory.ImagePath))
             {
                 File.Delete(Directory.GetCurrentDirectory() + "\\Images\\" + this.selectedCategory.ImagePath);
             }
         }
     }
     catch (Exception ex)
     {
         ConfigurationViewModel.logger.Warn("Could not delete category image file:", ex.Message + ex.InnerException?.ToString());
     }
     try
     {
         this.UnitOfWork.CategoryRepository.Delete(this.SelectedCategory);
         this.UnitOfWork.Save();
     }
     catch (SqlException ex)
     {
         SplashScreenHelper.CloseInstant();
         int num = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
         ConfigurationViewModel.logger.Error("Database error: {0}", ex.Message);
     }
     catch (DataException ex)
     {
         SplashScreenHelper.CloseInstant();
         int num = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
         ConfigurationViewModel.logger.Error("Database error: {0}", ex.Message);
     }
     if (NavigatorHelper.NavigationService == null)
     {
         return;
     }
     NavigatorHelper.NavigationService.Refresh();
 }