Exemplo n.º 1
0
        /// <summary>
        /// Creates PDF reports and saves them as a PDF file
        /// </summary>
        public static void GeneratePdfReport()
        {
            File.Delete(PdfPath + PdfFileName);
            var repo = new MSSqlRepository();
            var pdfData = repo.GetDataForPdfExport();
            var doc = new Document();

            PdfWriter.GetInstance(doc, new FileStream(PdfPath + PdfFileName, FileMode.Create));

            doc.Open();

            PdfPTable table = new PdfPTable(RowCountInPdfExport);
            table.DefaultCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
            table.DefaultCell.VerticalAlignment = PdfPCell.ALIGN_MIDDLE;

            var headerBackground = new BaseColor(204, 204, 204);
            PdfPCell headerCell = new PdfPCell(new Phrase("Sample PDF Export From the Football Manager"));
            headerCell.Colspan = RowCountInPdfExport;
            headerCell.Padding = 10f;
            headerCell.HorizontalAlignment = 1;
            headerCell.BackgroundColor = headerBackground;
            table.AddCell(headerCell);

            string[] col = { "Date", "Staduim", "Home Team", "Away Team", "Result" };

            for (int i = 0; i < col.Length; ++i)
            {
                PdfPCell columnCell = new PdfPCell(new Phrase(col[i]));
                columnCell.VerticalAlignment = PdfPCell.ALIGN_MIDDLE;
                columnCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                columnCell.BackgroundColor = headerBackground;
                table.AddCell(columnCell);
            }

            foreach (var item in pdfData)
            {
                PdfPCell townCell = new PdfPCell(new Phrase(item.Key));
                townCell.Colspan = RowCountInPdfExport;
                townCell.Padding = 10f;
                table.AddCell(townCell);

                foreach (var match in item.Value)
                {
                    table.AddCell(match.Date.Day + "." + match.Date.Month + "." + match.Date.Year);
                    table.AddCell(match.Stadium);
                    table.AddCell(match.HomeTeam);
                    table.AddCell(match.AwayTeam);
                    table.AddCell(match.Result);
                }
            }

            doc.Add(table);
            doc.Close();
            Process.Start(PdfPath);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates all JSON reports and save them in text file
        /// </summary>
        public static void JsonCreateReports()
        {
            var repo = new MSSqlRepository();

            var teamReports = repo.GetTeamReport();

            foreach (var report in teamReports)
            {
                SaveReport(report, report.Name);
            }

            Process.Start(SaveFilePath);
        }
 private async void CreateSqlServerDb_Click(object sender, EventArgs e)
 {
     var repo = new MSSqlRepository();
     try
     {
         await repo.CreateDb();
         MessageBox.Show(
             "The db is created",
             "Db creation",
             MessageBoxButtons.OK,
             MessageBoxIcon.Information);
     }
     catch (Exception ex)
     {
         // Find appropriate exception
         var exmes = ex.Message;
     }
 }
        private void FillDatFromZip_Click(object sender, EventArgs e)
        {
            var openFileDialog = new OpenFileDialog();
            var repo = new MSSqlRepository();
            try
            {
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    var filePath = openFileDialog.FileName;
                    var zip = ZipFile.Open(filePath, ZipArchiveMode.Read);
                    using (zip)
                    {
                        var teams = Utilities.ExcelUtils.GetAllPlayers(zip);
                        repo.FillPlayersFromZip(teams);
                    }
                }

                MessageBox.Show(
                    "The players are inserted",
                    "Players insert",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
            }
            catch (IOException)
            {
                MessageBox.Show(
                    "Error reading file!",
                    "Players insert",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }
        }
 private void GenerateXmlReport_btn_Click(object sender, EventArgs e)
 {
     try
     {
         var repo = new MSSqlRepository();
         XmlUtils.XmlCreateReports(repo.GetStadiumReport());
         // Write logic here
         MessageBox.Show(
            "The XML report for stadiums",
            "Stadiums report generated!",
            MessageBoxButtons.OK,
            MessageBoxIcon.Information);
     }
     catch (Exception)
     {
         // Find appropriate exception
         MessageBox.Show(
             "Something bad happened",
             "Fatal Error",
             MessageBoxButtons.OKCancel,
             MessageBoxIcon.Information);
     }
 }
        private void FillFromXml_btn_Click(object sender, EventArgs e)
        {
            var repo = new MSSqlRepository();
            var ctx = new FootballContext();
            var xmlToDtoConverter = new XmlToDtoMatchConverter(XmlMatchesPath);
            var dtoToMatchModelConverter = new DtoMatchToDbMatchConverter(xmlToDtoConverter, ctx);
            var matches = dtoToMatchModelConverter.GetAllMatches();

            try
            {
                repo.FillMatchesFromXml(matches);

                MessageBox.Show(
                    "The matches are inserted",
                    "Matches insert",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
            }
            catch (Exception)
            {
                // Find appropriate exception
                MessageBox.Show(
                    "Something bad happened",
                    "Fatal Error",
                    MessageBoxButtons.OKCancel,
                    MessageBoxIcon.Information);
            }
        }