示例#1
0
        public void SaveConfigTest()
        {
            if (File.Exists(this.configPath))
            {
                File.Delete(this.configPath);
            }


            var actualResult = OpenConfig();

            actualResult.IsAutoBackupOn = false;
            StockbookWindows.SaveConfig(actualResult);
            actualResult = OpenConfig();

            var expectedResult = new Config {
                IsAutoBackupOn = false
            };

            Assert.AreEqual(expectedResult.IsAutoBackupOn, actualResult.IsAutoBackupOn);

            if (File.Exists(this.configPath))
            {
                File.Delete(this.configPath);
            }
        }
示例#2
0
        /// <summary>
        /// Initialize products view by calling InitializeProductsFilter and making selected columns a read only
        /// </summary>
        public void InitializeProductsView()
        {
            var config   = StockbookWindows.OpenConfig();
            var currency = string.Empty;

            switch (config.Currency)
            {
            case "PHP - ₱":
                currency = "₱#,###,##0.00";
                break;

            case "USD - $":
                currency = "$#,###,##0.00";
                break;

            case "YEN - ¥":
                currency = "¥#,###,##0.00";
                break;
            }


            this.InitializeProducts(this.locationFilter, this.principalFilter, this.categoryFilter);
            foreach (var dc in this.DataGrid.Columns)
            {
                dc.IsReadOnly = true;

                if (dc.Header.ToString() == "Case Val" || dc.Header.ToString() == "Pack Val" || dc.Header.ToString() == "Piece Val")
                {
                    ((DataGridTextColumn)dc).Binding.StringFormat = currency;
                }
            }
        }
示例#3
0
        /// <summary>
        /// The initialize settings.
        /// </summary>
        public void InitializeSettings()
        {
            var config = StockbookWindows.OpenConfig();

            this.LastBackup.Text                = config.LastBackup.ToLongDateString();
            this.LocationTextBox.Text           = config.AutoBackupLocation;
            this.AutoBackupCheckBox.IsChecked   = config.IsAutoBackupOn;
            this.RetainBackupCheckBox.IsChecked = config.IsRetainHistoryOn;
            this.RetainCountTextBox.Text        = config.RetainHistoryCount.ToString();
            switch (config.TimeIntervalAutoBackup)
            {
            case "Weekly":
                this.WeeklyBackupRadioButton.IsChecked = true;
                break;

            case "Daily":
                this.DailyBackupRadioButton.IsChecked = true;
                break;

            case "Hourly":
                this.HourlyBackupRadioButton.IsChecked = true;
                break;
            }

            this.ProductCountTextBlock.Text     = Product.GetAllProducts().Count.ToString();
            this.TransactionCountTextBlock.Text = TransactionOrder.GetAllTransactions().Count.ToString();

            this.CompanyNameTextBox.Text = config.CompanyName;

            this.CurrencyComboBox.Items.Clear();
            this.CurrencyComboBox.Items.Add("PHP - ₱");
            this.CurrencyComboBox.Items.Add("USD - $");
            this.CurrencyComboBox.Items.Add("YEN - ¥");
            this.CurrencyComboBox.SelectedIndex = this.CurrencyComboBox.Items.IndexOf(config.Currency);
        }
示例#4
0
        /// <summary>
        /// The update settings button_ click.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void UpdateSettingsButtonClick(object sender, RoutedEventArgs e)
        {
            var config    = StockbookWindows.OpenConfig();
            var isChecked = this.AutoBackupCheckBox.IsChecked;

            if (isChecked != null)
            {
                config.IsAutoBackupOn = isChecked.Value;
            }

            if (!string.IsNullOrWhiteSpace(this.LocationTextBox.Text))
            {
                config.AutoBackupLocation = this.LocationTextBox.Text;
            }

            int retainCount;

            if (!string.IsNullOrWhiteSpace(this.RetainCountTextBox.Text) && int.TryParse(this.RetainCountTextBox.Text, out retainCount))
            {
                config.RetainHistoryCount = retainCount;
            }

            isChecked = this.RetainBackupCheckBox.IsChecked;
            if (isChecked != null)
            {
                config.IsRetainHistoryOn = isChecked.Value;
            }

            if (this.WeeklyBackupRadioButton.IsChecked.Value)
            {
                config.TimeIntervalAutoBackup = "Weekly";
            }
            else if (this.DailyBackupRadioButton.IsChecked.Value)
            {
                config.TimeIntervalAutoBackup = "Daily";
            }
            else if (this.HourlyBackupRadioButton.IsChecked.Value)
            {
                config.TimeIntervalAutoBackup = "Hourly";
            }

            if (!string.IsNullOrWhiteSpace(this.CompanyNameTextBox.Text))
            {
                config.CompanyName = this.CompanyNameTextBox.Text;
            }

            if (!string.IsNullOrWhiteSpace(this.CurrencyComboBox.SelectedValue.ToString()))
            {
                config.Currency = this.CurrencyComboBox.SelectedValue.ToString();
            }

            StockbookWindows.SaveConfig(config);
            this.Close();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MainMetro"/> class and initialize Product and Transaction views
        /// </summary>
        public MainMetro()
        {
            this.InitializeComponent();
            this.InitializeProductsView();
            this.InitializeTransView();
            StockbookWindows.AutoBackup();


            System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
            dispatcherTimer.Tick    += new EventHandler(this.DispatcherTimerTick);
            dispatcherTimer.Interval = new TimeSpan(0, 5, 0);
            dispatcherTimer.Start();
        }
示例#6
0
 /// <summary>
 /// The delete products click.
 /// </summary>
 /// <param name="sender">
 /// The sender.
 /// </param>
 /// <param name="e">
 /// The e.
 /// </param>
 private void DeleteProductsClick(object sender, RoutedEventArgs e)
 {
     if (MessageBox.Show("Are you sure you want to delete all products in database?", "Confirm", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
     {
         var deleteCount = Product.DeleteAllProducts();
         MessageBox.Show(
             "Successfully Deleted Products: " + deleteCount,
             string.Empty,
             MessageBoxButton.OK,
             MessageBoxImage.Asterisk);
     }
     StockbookWindows.RefreshMainWindow();
     InitializeSettings();
 }
示例#7
0
        public void DatabaseBackupTest()
        {
            var testPath = Environment.CurrentDirectory + @"\SettingsTest\";

            StockbookWindows.DatabaseBackup(location: testPath);

            var actualResult = Directory.GetFiles(testPath, "*.stockbook").ToList().Count;

            var expectedResult = 1;

            Assert.AreEqual(expectedResult, actualResult);

            DirectoryInfo di = new DirectoryInfo(testPath);

            di.Delete(true);
        }
        /// <summary>
        /// Initialize products view by calling InitializeProductsFilter and making selected columns a read only
        /// </summary>
        public void InitializeProductsView()
        {
            this.InitializeProductsFilter(
                this.locationFilterProduct,
                this.principalFilterProduct,
                this.categoryFilterProduct);

            var config   = StockbookWindows.OpenConfig();
            var currency = string.Empty;

            switch (config.Currency)
            {
            case "PHP - ₱":
                currency = "₱#,###,##0.00";
                break;

            case "USD - $":
                currency = "$#,###,##0.00";
                break;

            case "YEN - ¥":
                currency = "¥#,###,##0.00";
                break;
            }
            try
            {
                foreach (var dc in this.DataGrid.Columns)
                {
                    if (dc.Header.ToString() == "Case Bal" || dc.Header.ToString() == "Pack Bal" || dc.Header.ToString() == "Piece Bal" ||
                        dc.Header.ToString() == "Case To Packs" || dc.Header.ToString() == "Pack To Pieces")
                    {
                        var firstOrDefault = this.DataGrid.Columns.FirstOrDefault(q => q.Header == dc.Header);
                        if (firstOrDefault != null)
                        {
                            firstOrDefault.IsReadOnly = true;
                        }
                    }
                    if (dc.Header.ToString() == "Case Val" || dc.Header.ToString() == "Pack Val" || dc.Header.ToString() == "Piece Val")
                    {
                        ((DataGridTextColumn)dc).Binding.StringFormat = currency;
                    }
                }
            }
            catch (Exception)
            {
            }
        }
 /// <summary>
 /// The dispatcher timer tick.
 /// </summary>
 /// <param name="sender">
 /// The sender.
 /// </param>
 /// <param name="e">
 /// The e.
 /// </param>
 private void DispatcherTimerTick(object sender, EventArgs e)
 {
     StockbookWindows.AutoBackup();
 }
        /// <summary>
        /// The submit create click will add product and store it in database
        /// </summary>
        /// <param name="sender">
        /// The sender is the parent object of the button, which is the Grid
        /// </param>
        /// <param name="e">
        /// The event argument which contains the product that has been updated or will be updated
        /// </param>
        private void SubmitCreateClick(object sender, RoutedEventArgs e)
        {
            decimal Case, pack, piece, casePacks, packPieces;

            if (decimal.TryParse(this.CaseInput.Text.Trim(), out Case) && decimal.TryParse(this.CaseToPack.Text.Trim(), out casePacks) &&
                decimal.TryParse(this.PackToPiece.Text.Trim(), out packPieces) && decimal.TryParse(this.PackInput.Text.Trim(), out pack) &&
                decimal.TryParse(this.PieceInput.Text.Trim(), out piece) && !string.IsNullOrWhiteSpace(this.LocationInput.Text) &&
                !string.IsNullOrWhiteSpace(this.PrincipalInput.Text) && !string.IsNullOrWhiteSpace(this.CategoryInput.Text) &&
                !string.IsNullOrWhiteSpace(this.NameInput.Text) && !string.IsNullOrWhiteSpace(this.CodeInput.Text))
            {
                var prod = new Product
                {
                    Id           = string.Empty,
                    Location     = this.LocationInput.Text.Trim(),
                    Category     = this.CategoryInput.Text.Trim(),
                    Principal    = this.PrincipalInput.Text.Trim(),
                    Name         = this.NameInput.Text.Trim(),
                    ProdCode     = this.CodeInput.Text.Trim(),
                    CaseValue    = Case,
                    PackValue    = pack,
                    PieceValue   = piece,
                    CaseBalance  = 0,
                    PackBalance  = 0,
                    PieceBalance = 0,
                    PackToPieces = packPieces,
                    CaseToPacks  = casePacks
                };
                Product.CreateProduct(prod);
                StockbookWindows.RefreshMainWindow();
                this.Close();
            }
            else
            {
                var errorMessage = string.Empty;
                if (!decimal.TryParse(this.CaseInput.Text.Trim(), out Case))
                {
                    errorMessage = "Case Input has invalid characters or no value was given";
                }
                else if (!decimal.TryParse(this.PackInput.Text.Trim(), out pack))
                {
                    errorMessage = "Pack Input has invalid characters or no value was given";
                }
                else if (!decimal.TryParse(this.PieceInput.Text.Trim(), out piece))
                {
                    errorMessage = "Piece Input has invalid characters or no value was given";
                }
                else if (!decimal.TryParse(this.PackToPiece.Text.Trim(), out piece))
                {
                    errorMessage = "Pack To Piece Input has invalid characters or no value was given";
                }
                else if (!decimal.TryParse(this.CaseToPack.Text.Trim(), out piece))
                {
                    errorMessage = "Case To Pack Input has invalid characters or no value was given";
                }
                else if (string.IsNullOrWhiteSpace(this.LocationInput.Text))
                {
                    errorMessage = "No value was given in Location Input";
                }
                else if (string.IsNullOrWhiteSpace(this.PrincipalInput.Text))
                {
                    errorMessage = "No value was given in Principal Input";
                }
                else if (string.IsNullOrWhiteSpace(this.CategoryInput.Text))
                {
                    errorMessage = "No value was given in Category Input";
                }
                else if (string.IsNullOrWhiteSpace(this.NameInput.Text))
                {
                    errorMessage = "No value was given in Name Input";
                }
                else if (string.IsNullOrWhiteSpace(this.CodeInput.Text))
                {
                    errorMessage = "No value was given in Code Input";
                }

                MessageBox.Show(
                    "Error: " + errorMessage,
                    "Error in Creating Transaction",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);
            }
        }
示例#11
0
 /// <summary>
 /// The restore database_ click.
 /// </summary>
 /// <param name="sender">
 /// The sender.
 /// </param>
 /// <param name="e">
 /// The e.
 /// </param>
 private void RestoreDatabaseClick(object sender, RoutedEventArgs e)
 {
     StockbookWindows.RestoreBackup();
     StockbookWindows.RefreshMainWindow();
     InitializeSettings();
 }
示例#12
0
 /// <summary>
 /// The backup database_ click.
 /// </summary>
 /// <param name="sender">
 /// The sender.
 /// </param>
 /// <param name="e">
 /// The e.
 /// </param>
 private void BackupDatabaseClick(object sender, RoutedEventArgs e)
 {
     StockbookWindows.DatabaseBackup(true);
 }