Exemplo n.º 1
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Inits report table.
        /// </summary>
        private void _InitReportTable()
        {
            ReportsGenerator generator = App.Current.ReportGenerator;

            if (null != generator)
            {
                Debug.Assert(null != _viewSourceReports);

                List <ReportDataWrapper> reportsWrap = new List <ReportDataWrapper>();
                foreach (string name in generator.GetPresentedNames(false))
                {
                    reportsWrap.Add(new ReportDataWrapper(name));
                }

                _viewSourceReports.Source = reportsWrap;
            }
        }
        /// <summary>
        /// Method for populating the Charts
        /// </summary>
        public void populateCharts()
        {
            if (DbConnector.OpenSQLConnection()) // Open connection to the database
            {
                ReportsGenerator      reportGen     = new ReportsGenerator();
                List <StatusAnalysis> statusAnalyis = reportGen.StatusAnalysis();

                barChart.DataSource = statusAnalyis.OrderBy(i => i.Status);
                barChart.Series["Defect Count"].XValueMember  = "Status";
                barChart.Series["Defect Count"].YValueMembers = "Count";
                barChart.Series["Defect Count"].YValueType    = ChartValueType.Int32;

                doughnutChart.DataSource = statusAnalyis.OrderBy(i => i.Status);
                doughnutChart.Series["Count"].XValueMember  = "Status";
                doughnutChart.Series["Count"].YValueMembers = "Count";
                doughnutChart.Series["Count"].YValueType    = ChartValueType.Int32;

                DefectDataAccess defect = new DefectDataAccess();
                var defects             = defect.GetAllDefects();
                drePointChart.DataSource = defect.GetAllDefects();
                drePointChart.Series["DRE"].XValueMember  = "DefectId";
                drePointChart.Series["DRE"].YValueMembers = "DRE";
                drePointChart.Series["DRE"].YValueType    = ChartValueType.Int32;

                List <AgeAnalysis> ageAnalysis = new List <AgeAnalysis>();
                foreach (var d in defects.Zip(reportGen.calculateAge(defects), Tuple.Create))
                {
                    ageAnalysis.Add(new AgeAnalysis
                    {
                        DefectId = d.Item1.DefectId,
                        Age      = d.Item2
                    });
                }
                agePointChart.DataSource = ageAnalysis;
                agePointChart.Series["Age"].XValueMember  = "DefectId";
                agePointChart.Series["Age"].YValueMembers = "Age";
                agePointChart.Series["Age"].YValueType    = ChartValueType.Int32;
            }
            else
            {
                // Connection could not be opened
                MessageBox.Show("Connection to the database could not be established", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            DbConnector.CloseSQLConnection(); // Close connection to the database
        }
        private void analyzeButton_Click(object sender, RoutedEventArgs e)
        {
            // TODO  make a function using the code below
            var urlValidator = new UrlValidator();

            if (urlValidator.IsValid(UrlTextBox.Text))
            {
                var analyzer = new Analyzer(UrlTextBox.Text, KeywordTextBox.Text);
                analyzer.Analyze();
                ReportsGenerator.GenerateReport(analyzer, ref ReportDataGrid);
            }
            else
            {
                MessageBox.Show(this, "Please enter valid url/keyword!", "Error", MessageBoxButton.OK,
                                MessageBoxImage.Warning);
            }
        }
        /// <summary>
        /// Method for populating the DataDridViews
        /// </summary>
        public void populateDataGridDRRAnalysis()
        {
            if (DbConnector.OpenSQLConnection()) // Open connection to the database
            {
                // Connection opened
                ReportsGenerator reportGen = new ReportsGenerator();
                dgvDRRAnalysis.AutoGenerateColumns = false; // To only show the columns needed
                dgvDRRAnalysis.DataSource          = reportGen.DrrAnalysis();
                txtSearchDRE.Text = "";
            }
            else
            {
                // Connection could not be opened
                MessageBox.Show("Connection to the database could not be established", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            DbConnector.CloseSQLConnection(); // Close connection to the database
        }
Exemplo n.º 5
0
        private int _GetSubReportsCount(SelectReportWrapper reportWrapper)
        {
            ReportsGenerator generator = App.Current.ReportGenerator;

            Debug.Assert(null != App.Current.ReportGenerator);
            Debug.Assert(generator.GetPresentedNames(false).Contains(reportWrapper.Name.Name));

            ReportInfo report = generator.GetReportInfo(reportWrapper.Name.Name);

            int result = 0;

            if ((null != report) && (null != report.SubReports))
            {
                result = report.SubReports.Count;
            }

            return(result);
        }
Exemplo n.º 6
0
        public void Test2Orders()
        {
            // arrange
            List <string> data = new List <string>();

            data.Add("[email protected] 2021-02-11 10:00 P01 1");
            data.Add("[email protected] 11-02-2021 15:00");
            data.Add("P02b 2");
            int ordersQnty = 1;

            IData fileData = new DataStub(data);

            // act
            var orders = ReportsGenerator.ReadOrders(fileData);
            int items  = orders.Sum(o => o.Items.Count);

            // assert
            ordersQnty.Should().Be(items);
        }
        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (DbConnector.OpenSQLConnection()) // Open connection to the database
            {
                // Connection opened
                DefectDataAccess defect = new DefectDataAccess();
                dgvAgeAnalysis.AutoGenerateColumns = false; // To only show the columns needed
                var defects = defect.SearchDefectsAnalysis(txtSearchDefects.Text.Trim());
                dgvAgeAnalysis.DataSource = defects;
                ReportsGenerator reportGen = new ReportsGenerator();
                reportGen.calculateAge(defects);
            }
            else
            {
                // Connection could not be opened
                MessageBox.Show("Connection to the database could not be established", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            DbConnector.CloseSQLConnection(); // Close connection to the database
        }
Exemplo n.º 8
0
        public void TestDiscount()
        {
            // arrange
            List <string> data = new List <string>();

            data.Add("[email protected] 2021-02-11 10:00 !SALE1102 P01 1");
            data.Add("[email protected] 2021-02-11 15:00 P02b 2");
            data.Add("[email protected] 2021-02-11 12:30 !SALE1102");
            data.Add("P01");
            data.Add("P42 5");
            IData fileData = new DataStub(data);
            ITime time     = new TimeStub(new DateTime(2021, 02, 11));

            // act
            ReportsGenerator.TodaysOrdersReport(fileData, time);
            bool isError = ReportsGenerator.isError;

            // assert
            isError.Should().BeFalse();
        }
Exemplo n.º 9
0
        /// <summary>
        /// Gets template dublicate unique name.
        /// </summary>
        /// <param name="oldName">Source template name.</param>
        /// <returns>Dublicate unique name.</returns>
        private string _GetNameForDublicate(string sourceName)
        {
            ReportsGenerator     generator  = App.Current.ReportGenerator;
            ICollection <string> collection = generator.GetPresentedNames(true);

            int k = 2;

            string newName = string.Format((string)App.Current.FindResource("ItemCopyShortName"), sourceName);

            if (collection.Contains(newName))
            {
                newName = string.Format((string)App.Current.FindResource("ItemCopyLongName"), k, sourceName);
                while (collection.Contains(newName))
                {
                    ++k;
                    newName = string.Format((string)App.Current.FindResource("ItemCopyLongName"), k, sourceName);
                }
            }

            return(newName);
        }
Exemplo n.º 10
0
        public PreviewForm(Form parentForm, ReportStateDescription description, bool disposeResponsible)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            this.MdiParent = parentForm;
            if (null == description.Report)
            {
                ReportsGenerator generator = App.Current.ReportGenerator;
                generator.RunReport(description);
            }
            description.IsLocked = true;

            arvMain.Document = description.Report.Document;
            this.Text        = description.Report.Document.Name;

            _description        = description;
            _disposeResponsible = disposeResponsible;
        }
Exemplo n.º 11
0
        public void TestErrorLineNumber()
        {
            // arrange
            List <string> data = new List <string>();

            data.Add("[email protected] 2021-02-11 10:00 P01 1");
            data.Add("[email protected] 2021-02-11 15:00 P02b 2");
            data.Add("[email protected] 21-02-2011 12:30");
            data.Add("P01");
            data.Add("P42 5");
            IData fileData  = new DataStub(data);
            ITime time      = new TimeStub(new DateTime(2021, 02, 11));
            int   errorLine = 3;

            // act
            ReportsGenerator.TodaysOrdersReport(fileData, time);
            int line = ReportsGenerator.lineNumber;

            // assert
            errorLine.Should().Be(line);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Delete button click handler.
        /// </summary>
        private void _DeleteTemplate_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ReportInfo selectedInfo = _GetSelectedInfo();
                if (null != selectedInfo)
                {
                    bool doProcess = true;
                    if (Settings.Default.IsAllwaysAskBeforeDeletingEnabled)
                    {
                        // show warning dialog
                        doProcess = DeletingWarningHelper.Execute(selectedInfo.Name, "ReportTemplate", "ReportTemplate");
                    }

                    if (doProcess)
                    {
                        App.Current.ReportGenerator.DeleteReportInfo(selectedInfo.Name);
                        _itemIndexToSelection = xceedGridReports.SelectedIndex;

                        // remove template file
                        string reportTemplatePath = ReportsGenerator.GetTemplateAbsolutelyPath(selectedInfo.TemplatePath);
                        _DeleteFileSafe(reportTemplatePath);

                        // remove sub report templates
                        foreach (SubReportInfo subReport in selectedInfo.SubReports)
                        {
                            reportTemplatePath = ReportsGenerator.GetTemplateAbsolutelyPath(subReport.TemplatePath);
                            _DeleteFileSafe(reportTemplatePath);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }

            _InitReportTable();
        }
Exemplo n.º 13
0
        private static void SortedReport_I_J(IEnumerable<Request> requests, string userSort, bool cId, string clientId = "0")
        {
            switch (userSort)
            {
                case "n":
                    break;
                case "t":
                    SortMenuMini();
                    if (Int32.TryParse(Console.ReadLine(), out int sortChoice))
                    {
                        if (sortChoice != 1 && sortChoice != 2)
                        {
                            Console.WriteLine("\nWprowadzono nieprawidłowy znak. Może uda się następnym razem... ;)");
                            break;
                        }

                        if (cId)
                        {
                            Console.WriteLine($"\nPosortowana ilość zamówień pogrupowanych po nazwie dla klienta o ID = {clientId}:\n");
                            ReportsGenerator.RequestsAmountGroupedByName(requests, clientId, sortChoice);
                        }
                        else
                        {
                            Console.WriteLine("\nPosortowana ilość zamówień pogrupowanych po nazwie:\n");
                            ReportsGenerator.RequestsAmountGroupedByName(requests, sortChoice);
                        }

                    }
                    else
                    {
                        Console.WriteLine("\nWprowadzono nieprawidłowy znak. Może uda się następnym razem... ;)");
                    }
                    break;
                default:
                    Console.WriteLine("\nWprowadzono nieprawidłowy znak. Może uda się następnym razem... ;)");
                    break;
            }
        }
Exemplo n.º 14
0
        private static void SortedReport_E_F(IEnumerable<Request> requests, string userSort, bool cId, string clientId = "0")
        {
            switch (userSort)
            {
                case "n":
                    break;
                case "t":
                    SortMenuFull();
                    if (Int32.TryParse(Console.ReadLine(), out int sortChoice))
                    {
                        if (sortChoice != 1 && sortChoice != 2 && sortChoice != 3 && sortChoice != 4 && sortChoice != 5)
                        {
                            Console.WriteLine("\nWprowadzono nieprawidłowy znak. Może uda się następnym razem... ;)");
                            break;
                        }

                        if (cId)
                        {
                            Console.WriteLine($"\nPosortowana lista wszystkich zamówień dla klienta o ID = {clientId}:\n");
                            ReportsGenerator.ListOfAllRequests(requests, clientId, sortChoice);
                        }
                        else
                        {
                            Console.WriteLine("\nPosortowana lista wszystkich zamówień:\n");
                            ReportsGenerator.ListOfAllRequests(requests, sortChoice);
                        }

                    }
                    else
                    {
                        Console.WriteLine("\nWprowadzono nieprawidłowy znak. Może uda się następnym razem... ;)");
                    }
                    break;
                default:
                    Console.WriteLine("\nWprowadzono nieprawidłowy znak. Może uda się następnym razem... ;)");
                    break;
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (null != components)
                {
                    components.Dispose();
                }
            }

            base.Dispose(disposing);

            if (_disposeResponsible)
            {
                ReportsGenerator generator = App.Current.ReportGenerator;
                generator.DisposeReport(_description);
            }

            if (null != _description)
            {
                _description.IsLocked = false;
            }
        }
        /// <summary>
        /// Method for populating the DataDridViews
        /// </summary>
        public void populateDataGridAgeAnalysis()
        {
            if (DbConnector.OpenSQLConnection()) // Open connection to the database
            {
                // Connection opened
                DefectDataAccess defect = new DefectDataAccess();
                var defects             = defect.GetAllDefects();
                dgvAgeAnalysis.AutoGenerateColumns = false; // To only show the columns needed
                dgvAgeAnalysis.DataSource          = defects;
                txtSearchDefects.Text = "";
                for (int i = 0; i < defects.Count; i++)
                {
                    ReportsGenerator reportGen = new ReportsGenerator();
                    dgvAgeAnalysis.Rows[i].Cells[7].Value = reportGen.calculateAge(defects)[i];
                }
            }
            else
            {
                // Connection could not be opened
                MessageBox.Show("Connection to the database could not be established", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            DbConnector.CloseSQLConnection(); // Close connection to the database
        }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            Console.WriteLine("Podaj pełną ścieżkę do katalogu z plikami wejściowymi:");

            string path = Console.ReadLine();

            List<Request> requests = DataLoader.PopulateDbWithData(path);

            bool exitFlag = false;

            while (!exitFlag)
            {
                MainMenu();
                string userChoice = Console.ReadLine();
                string clientId;

                switch (userChoice)
                {
                    case "a":
                        Console.WriteLine($"\nCałkowita liczba zamówień: {ReportsGenerator.TotalNumberOfRequests(requests)}");
                        break;
                    case "b":
                        Console.Write("\nPodaj ID klienta: ");
                        clientId = Console.ReadLine();
                        Console.WriteLine($"\nCałkowita liczba zamówień dla klienta o ID = {clientId}: {ReportsGenerator.TotalNumberOfRequests(requests, clientId)}");
                        break;
                    case "c":
                        Console.WriteLine($"\nŁączna kwota zamówień: {ReportsGenerator.TotalValueOfRequests(requests)}");
                        break;
                    case "d":
                        Console.Write("\nPodaj ID klienta: ");
                        clientId = Console.ReadLine();
                        Console.WriteLine($"\nŁączna kwota zamówień dla klienta o ID = {clientId}: {ReportsGenerator.TotalValueOfRequests(requests, clientId)}");
                        break;
                    case "e":
                        Console.WriteLine("\nLista wszystkich zamówień:\n");
                        ReportsGenerator.ListOfAllRequests(requests);
                        Console.Write("Chcesz posortować raport? (t/n): ");
                        string userSort = Console.ReadLine();
                        SortedReport_E_F(requests, userSort, false);
                        break;
                    case "f":
                        Console.Write("\nPodaj ID klienta: ");
                        clientId = Console.ReadLine();
                        if (requests.Count(x => x.ClientId == clientId) == 0)
                        {
                            Console.WriteLine("\nBrak klienta o wskazanym ID...");
                            break;
                        }
                        Console.WriteLine($"\nLista wszystkich zamówień dla klienta o ID = {clientId}:\n");
                        ReportsGenerator.ListOfAllRequests(requests, clientId);
                        Console.Write("Chcesz posortować raport? (t/n): ");
                        userSort = Console.ReadLine();
                        SortedReport_E_F(requests, userSort, true, clientId);
                        break;
                    case "g":
                        double averRequest = ReportsGenerator.TotalValueOfRequests(requests) / ReportsGenerator.TotalNumberOfRequests(requests);
                        Console.WriteLine($"\nŚrednia wartość zamówienia: {averRequest.ToString("F", CultureInfo.InvariantCulture)}");
                        break;
                    case "h":
                        Console.Write("\nPodaj ID klienta: ");
                        clientId = Console.ReadLine();
                        double averRequestClientId = ReportsGenerator.TotalValueOfRequests(requests, clientId) / ReportsGenerator.TotalNumberOfRequests(requests, clientId);
                        if (double.IsNaN(averRequestClientId))
                        {
                            Console.WriteLine("\nBrak klienta o wskazanym ID...");
                            break;
                        }
                        Console.WriteLine($"\nŚrednia wartość zamówienia dla klienta o ID = {clientId}: " +
                                          $"{averRequestClientId.ToString("F", CultureInfo.InvariantCulture)}");
                        break;
                    case "i":
                        Console.WriteLine("\nIlość zamówień pogrupowanych po nazwie:\n");
                        ReportsGenerator.RequestsAmountGroupedByName(requests);
                        Console.Write("Chcesz posortować raport? (t/n): ");
                        userSort = Console.ReadLine();
                        SortedReport_I_J(requests, userSort, false);
                        break;
                    case "j":
                        Console.Write("\nPodaj ID klienta: ");
                        clientId = Console.ReadLine();
                        if (requests.Count(x => x.ClientId == clientId) == 0)
                        {
                            Console.WriteLine("\nBrak klienta o wskazanym ID...");
                            break;
                        }
                        Console.WriteLine($"\nIlość zamówień pogrupowanych po nazwie dla klienta dla klienta o ID = {clientId}:\n");
                        ReportsGenerator.RequestsAmountGroupedByName(requests, clientId);
                        Console.Write("Chcesz posortować raport? (t/n): ");
                        userSort = Console.ReadLine();
                        SortedReport_I_J(requests, userSort, true, clientId);
                        break;
                    case "k":
                        double priceFrom;
                        double priceTo;
                        Console.Write("\nPodaj dolny przedział cen: ");
                        if (Double.TryParse(Console.ReadLine(), out double price1))
                            priceFrom = price1;
                        else
                        {
                            Console.WriteLine("\nWprowadzono nieprawidłowy znak. Może uda się następnym razem... ;)");
                            break;
                        }
                        Console.Write("Podaj górny przedział cen: ");
                        if (Double.TryParse(Console.ReadLine(), out double price2))
                        {
                            priceTo = price2;
                            if (priceTo < priceFrom)
                            {
                                Console.WriteLine("\nPodano złą cenę. Górny przedział cen nie może być niższy od dolnego...");
                                break;
                            }
                        }
                        else
                        {
                            Console.WriteLine("\nWprowadzono nieprawidłowy znak. Może uda się następnym razem... ;)");
                            break;
                        }
                        if (requests.Count(c => c.Price >= priceFrom && c.Price <= priceTo) == 0)
                        {
                            Console.WriteLine("\nBrak zamówień w podanym przedziale cenowym...");
                            break;
                        }
                        Console.WriteLine($"\nZamówienia w przedziale cenowym od {priceFrom} do {priceTo}:\n");
                        ReportsGenerator.RequestsInPriceRange(requests, priceFrom, priceTo);
                        Console.Write("Chcesz posortować raport? (t/n): ");
                        userSort = Console.ReadLine();
                        SortedReport_K(requests, userSort, priceFrom, priceTo);
                        break;
                    case "z":
                        exitFlag = true;
                        break;
                    default:
                        Console.WriteLine("\nWprowadzono nieprawidłowy znak. Może uda się następnym razem... ;)");
                        break;
                }
            }
        }
Exemplo n.º 18
0
        public override ValidationResult Validate(object value, CultureInfo culture, CellValidationContext context)
        {
            // not empty check
            bool isObjectEmpty = true;

            if (null != value)
            {
                isObjectEmpty = string.IsNullOrEmpty(value.ToString().Trim());
            }
            if (isObjectEmpty)
            {
                return(new ValidationResult(false, (string)Application.Current.FindResource("ReportTemplateEmptyName")));
            }

            // unique name check
            string name = value.ToString();

            if (!string.IsNullOrEmpty(ReportDataWrapper.StartTemplateName))
            {
                if (0 == string.Compare(ReportDataWrapper.StartTemplateName, name, true))
                {
                    return(ValidationResult.ValidResult);
                }
            }

            ReportsGenerator     generator      = App.Current.ReportGenerator;
            ICollection <string> presentedNames = generator.GetPresentedNames(true);

            foreach (string nameTemplate in presentedNames)
            {
                if (0 == string.Compare(nameTemplate, name, true))
                {
                    return(new ValidationResult(false, (string)Application.Current.FindResource("ReportTemplateNotUniqueName")));
                }
            }

            // normal length check
            bool   isLong       = false;
            string templatePath = ReportsGenerator.GetNewTemplatePath(name, ReportDataWrapper.StartTemplatePath);
            string fileName     = null;

            try
            {
                fileName = ReportsGenerator.GetTemplateAbsolutelyPath(templatePath);
                new FileInfo(fileName);
            }
            catch (PathTooLongException)
            {
                isLong = true;
            }
            catch (Exception)
            {
            }

            if (isLong)
            {
                return(new ValidationResult(false, (string)Application.Current.FindResource("ReportTemplateLongName")));
            }

            // valid name check
            if (!FileHelpers.ValidateFilepath(fileName))
            {
                return(new ValidationResult(false, (string)Application.Current.FindResource("ReportTemplateInvalidName")));
            }

            return(ValidationResult.ValidResult);
        }
Exemplo n.º 19
0
        public void RequestAverageValueClientId()
        {
            double expectedValue = 200;
            double actualValue   = ReportsGenerator.TotalValueOfRequests(_requestList, "1") / ReportsGenerator.TotalNumberOfRequests(_requestList, "1");

            Assert.Equal(expectedValue, actualValue);
        }
Exemplo n.º 20
0
        public void RequestAverageValue()
        {
            double expectedValue = 150;
            double actualValue   = ReportsGenerator.TotalValueOfRequests(_requestList) / ReportsGenerator.TotalNumberOfRequests(_requestList);

            Assert.Equal(expectedValue, actualValue);
        }