예제 #1
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);
        }
        public void DeleteAllTransactionTest()
        {
            for (var i = 0; i < 5; i++)
            {
                var actualResult = new TransactionOrder
                {
                    TransactionType = "Sales",
                    DateTransaction = DateTime.Now,
                    RefNo           = "TestRef"
                };
                TransactionOrder.CreateTransaction(actualResult);
            }

            var trans          = TransactionOrder.GetAllTransactions();
            var expectedResult = TransactionOrder.DeleteAllTransactions();

            Assert.AreEqual(expectedResult, trans.Count);
        }
예제 #3
0
        /// <summary>
        /// The initialize transaction filter determines the products that will be printed in View depending on the current filter parameters
        /// </summary>
        /// <param name="newValueTransaction">
        /// The parameter for a new transaction value or default empty if user did not put any
        /// </param>
        /// <param name="newValueParticular">
        /// The parameter for a new particular value or default empty if user did not put any
        /// </param>
        /// <param name="newValuePrincipal">
        /// The parameter for a new principal value or default empty if user did not put any
        /// </param>
        /// <param name="newValueSalesman">
        /// The parameter for a new salesman value or default empty if user did not put any
        /// </param>
        public void InitializeTransFilter(
            string newValueTransaction = "",
            string newValueParticular  = "",
            string newValuePrincipal   = "",
            string newValueSalesman    = "")
        {
            var listTrans = TransactionOrder.GetAllTransactions();

            this.ParticularFilterTrans.ItemsSource = null;
            this.ParticularFilterTrans.Items.Clear();
            this.ParticularFilterTrans.Items.Add("All Particular");
            this.PrincipalFilterTrans.ItemsSource = null;
            this.PrincipalFilterTrans.Items.Clear();
            this.PrincipalFilterTrans.Items.Add("All Principal");
            this.SalesmanFilterTrans.ItemsSource = null;
            this.SalesmanFilterTrans.Items.Clear();
            this.SalesmanFilterTrans.Items.Add("All Salesman");

            if (newValueTransaction != "All Transactions")
            {
                listTrans = listTrans.Where(q => q.TransactionType == newValueTransaction).ToList();
            }

            foreach (var prod in listTrans.Select(q => q.Particular).Distinct())
            {
                this.ParticularFilterTrans.Items.Add(prod);
            }

            if (newValueParticular != "All Particular")
            {
                listTrans = listTrans.Where(q => q.Particular == newValueParticular).ToList();
            }

            foreach (var prod in listTrans.SelectMany(q => q.Transactions).Select(s => s.Product.Principal).Distinct())
            {
                this.PrincipalFilterTrans.Items.Add(prod);
            }

            if (newValuePrincipal != "All Principal")
            {
                listTrans =
                    listTrans.Where(q => q.Transactions.Exists(s => s.Product.Principal == newValuePrincipal)).ToList();
            }

            foreach (var prod in listTrans.Select(q => q.SalesmanName).Distinct())
            {
                this.SalesmanFilterTrans.Items.Add(prod);
            }

            if (newValueSalesman != "All Salesman")
            {
                listTrans =
                    listTrans.Where(q => q.SalesmanName == newValueSalesman).ToList();
            }

            if (!string.IsNullOrWhiteSpace(this.startDate.Text))
            {
                listTrans = listTrans.Where(q => q.DateTransaction >= this.startDate.SelectedDate).ToList();
            }

            if (!string.IsNullOrWhiteSpace(this.endDate.Text))
            {
                listTrans = listTrans.Where(q => q.DateTransaction <= this.endDate.SelectedDate).ToList();
            }

            var transView = new List <TransactionView>();

            foreach (var tran in listTrans)
            {
                var temp = new TransactionView
                {
                    Id = tran.Id,
                    TransactionType = tran.TransactionType,
                    DateTransaction = tran.DateTransaction,
                    Particular      = tran.Particular,
                    PrincipalList   =
                        string.Join(
                            ",",
                            tran.Transactions.Select(q => q.Product)
                            .ToList()
                            .Select(q => q.Principal)
                            .Distinct()
                            .ToList()),
                    RefNo        = tran.RefNo,
                    ItemCount    = tran.Transactions.Count,
                    SalesmanName = tran.SalesmanName,
                    Transactions = tran.Transactions
                };
                transView.Add(temp);
            }

            this.TransactionDataGrid.ItemsSource      = transView;
            this.transactionFilterTrans               = newValueTransaction;
            this.particularFilterTrans                = newValueParticular;
            this.principalFilterTrans                 = newValuePrincipal;
            this.salesmanFilterTrans                  = newValueSalesman;
            this.TransactionFilterTrans.SelectedIndex = this.TransactionFilterTrans.Items.IndexOf(newValueTransaction);
            this.ParticularFilterTrans.SelectedIndex  = this.ParticularFilterTrans.Items.IndexOf(newValueParticular);
            this.PrincipalFilterTrans.SelectedIndex   = this.PrincipalFilterTrans.Items.IndexOf(newValuePrincipal);
            this.SalesmanFilterTrans.SelectedIndex    = this.SalesmanFilterTrans.Items.IndexOf(newValueSalesman);
        }
예제 #4
0
        /// <summary>
        /// The method initialize the transactions and filter it with the input of the user
        /// </summary>
        /// <param name="newValueLocation">
        /// The new value location filter if user changed it.
        /// </param>
        /// <param name="newValuePrincipal">
        /// The new value principal filter if user changed it.
        /// </param>
        /// <param name="newValueCategory">
        /// The new value category filter if user changed it.
        /// </param>
        /// <param name="newValueName">
        /// The new value name filter if user changed it.
        /// </param>
        /// <param name="newValueType">
        /// The new value type filter if user changed it.
        /// </param>
        /// <param name="newValueParticular">
        /// The new value particular filter if user changed it.
        /// </param>
        /// <param name="newValueSalesman">
        /// The new value salesman filter if user changed it.
        /// </param>
        private void InitializeTransactions(string newValueLocation, string newValuePrincipal, string newValueCategory, string newValueName, string newValueType, string newValueParticular, string newValueSalesman)
        {
            var listTrans = TransactionOrder.GetAllTransactions();

            this.PrincipalInputTrans.Items.Clear();
            this.PrincipalInputTrans.Items.Add("All Principal");
            this.CategoryInputTrans.Items.Clear();
            this.CategoryInputTrans.Items.Add("All Category");
            this.LocationInputTrans.Items.Clear();
            this.LocationInputTrans.Items.Add("All Location");
            this.TypeInputTrans.Items.Clear();
            this.TypeInputTrans.Items.Add("All Transactions");
            this.TypeInputTrans.Items.Add("Sales");
            this.TypeInputTrans.Items.Add("Purchased");
            this.ParticularInputTrans.Items.Clear();
            this.ParticularInputTrans.Items.Add("All Particular");
            this.SalesmanInputTrans.Items.Clear();
            this.SalesmanInputTrans.Items.Add("All Salesman");
            this.NameInputTrans.Items.Clear();
            this.NameInputTrans.Items.Add("All Product");

            // Remove This
            foreach (var prod in listTrans.Select(q => q.TransactionType).Distinct())
            {
                this.TypeInputTrans.Items.Add(prod);
            }

            if (newValueType != "All Transactions")
            {
                listTrans = listTrans.Where(q => q.TransactionType == newValueType).ToList();
            }

            foreach (var prod in listTrans.Select(q => q.Particular).Distinct())
            {
                this.ParticularInputTrans.Items.Add(prod);
            }

            if (newValueParticular != "All Particular")
            {
                listTrans = listTrans.Where(q => q.Particular == newValueParticular).ToList();
            }

            foreach (var prod in listTrans.Select(q => q.SalesmanName).Distinct())
            {
                this.SalesmanInputTrans.Items.Add(prod);
            }

            if (newValueSalesman != "All Salesman")
            {
                listTrans = listTrans.Where(q => q.SalesmanName == newValueSalesman).ToList();
            }

            if (this.locationTransFilter != newValueLocation)
            {
                this.principalTransFilter = "All Principal";
                newValuePrincipal         = this.principalTransFilter;
                this.categoryTransFilter  = "All Category";
                newValueCategory          = this.categoryTransFilter;
                this.nameTransFilter      = "All Product";
                newValueName = this.nameTransFilter;
            }

            if (this.principalTransFilter != newValuePrincipal)
            {
                this.categoryTransFilter = "All Category";
                newValueCategory         = this.categoryTransFilter;
                this.nameTransFilter     = "All Product";
                newValueName             = this.nameTransFilter;
            }

            if (this.categoryTransFilter != newValueCategory)
            {
                this.nameTransFilter = "All Product";
                newValueName         = this.nameTransFilter;
            }

            foreach (var prod in listTrans.SelectMany(q => q.Transactions).Select(s => s.Product.Location).Distinct())
            {
                this.LocationInputTrans.Items.Add(prod);
            }

            if (newValueLocation != "All Location")
            {
                listTrans = listTrans.Where(q => q.Transactions.Exists(s => s.Product.Location == newValueLocation)).ToList();
            }

            foreach (var prod in listTrans.SelectMany(q => q.Transactions).Select(s => s.Product.Principal).Distinct())
            {
                this.PrincipalInputTrans.Items.Add(prod);
            }

            if (newValuePrincipal != "All Principal")
            {
                listTrans = listTrans.Where(q => q.Transactions.Exists(s => s.Product.Principal == newValuePrincipal)).ToList();
            }

            foreach (var prod in listTrans.SelectMany(q => q.Transactions).Select(s => s.Product.Category).Distinct())
            {
                this.CategoryInputTrans.Items.Add(prod);
            }

            if (newValueCategory != "All Category")
            {
                listTrans = listTrans.Where(q => q.Transactions.Exists(s => s.Product.Category == newValueCategory)).ToList();
            }

            foreach (var prod in listTrans.SelectMany(q => q.Transactions).Select(s => s.Product.Name).Distinct())
            {
                this.NameInputTrans.Items.Add(prod);
            }

            if (newValueName != "All Product")
            {
                listTrans = listTrans.Where(q => q.Transactions.Exists(s => s.Product.Name == newValueName)).ToList();
            }

            if (!string.IsNullOrWhiteSpace(this.DateFrom.Text))
            {
                listTrans = listTrans.Where(q => q.DateTransaction.Date >= this.DateFrom.SelectedDate).ToList();
            }

            if (!string.IsNullOrWhiteSpace(this.DateTo.Text))
            {
                listTrans = listTrans.Where(q => q.DateTransaction.Date <= this.DateTo.SelectedDate).ToList();
            }

            var transView = new List <TransactionView>();

            foreach (var tran in listTrans)
            {
                var temp = new TransactionView
                {
                    Id = tran.Id,
                    TransactionType = tran.TransactionType,
                    DateTransaction = tran.DateTransaction,
                    Particular      = tran.Particular,
                    PrincipalList   = string.Join(",", tran.Transactions.Select(q => q.Product).ToList().Select(q => q.Principal).Distinct().ToList()),
                    RefNo           = tran.RefNo,
                    ItemCount       = tran.Transactions.Count,
                    SalesmanName    = tran.SalesmanName,
                    Transactions    = tran.Transactions
                };
                transView.Add(temp);
            }

            this.typeTransFilter                    = newValueType;
            this.locationTransFilter                = newValueLocation;
            this.principalTransFilter               = newValuePrincipal;
            this.categoryTransFilter                = newValueCategory;
            this.particularTransFilter              = newValueParticular;
            this.salesmanTransFilter                = newValueSalesman;
            this.nameTransFilter                    = newValueName;
            this.TypeInputTrans.SelectedIndex       = this.TypeInputTrans.Items.IndexOf(newValueType);
            this.LocationInputTrans.SelectedIndex   = this.LocationInputTrans.Items.IndexOf(newValueLocation);
            this.PrincipalInputTrans.SelectedIndex  = this.PrincipalInputTrans.Items.IndexOf(newValuePrincipal);
            this.CategoryInputTrans.SelectedIndex   = this.CategoryInputTrans.Items.IndexOf(newValueCategory);
            this.ParticularInputTrans.SelectedIndex = this.ParticularInputTrans.Items.IndexOf(newValueParticular);
            this.SalesmanInputTrans.SelectedIndex   = this.SalesmanInputTrans.Items.IndexOf(newValueSalesman);
            this.NameInputTrans.SelectedIndex       = this.NameInputTrans.Items.IndexOf(newValueName);
            this.listTransactions                   = listTrans;
            this.TransactionDataGrid.ItemsSource    = transView;
        }