コード例 #1
0
        public void UpdateDatabase(TravelAgencyDbContext db)
        {
            using (var reportsContext = new ReportsFluentModel())
            {
                var schemaHandler = reportsContext.GetSchemaHandler();
                this.EnsureDB(schemaHandler);

                var allReports = db.Excursions
                .Select(x => new Report()
                {
                    Id = x.ExcursionId,
                    Name = x.Name,
                    Duration = (int)DbFunctions.DiffDays(x.StartDate, x.EndDate),
                    Destination = x.Destination.Country,
                    ClientsCount = x.Clients,
                    TotalIncome = x.PricePerClient * x.Clients,
                    TransportCompany = x.Transport.CompanyName,
                    TransportType = x.Transport.Type.ToString(),
                    GuideName = x.Guide.Name,
                    ExpenseId = x.ExpenseId
                }).ToList();

                var reportNames = reportsContext.GetAll<Report>().Select(x => x.Name).ToList();
                foreach (var report in allReports)
                {
                    if (!reportNames.Contains(report.Name))
                    {
                        reportsContext.Add(report);
                    }
                }

                reportsContext.SaveChanges();
            }
        }
コード例 #2
0
        private void GenerateData(Document document, TravelAgencyDbContext dbContext)
        {
            var excursions = dbContext
                .Excursions
                .Select(x => new ReportExcursion()
                {
                    ExcName = x.Name,
                    Destination = x.Destination.Country,
                    Distance = x.Destination.Distance.ToString(),
                    ClientCount = x.Clients,
                    StartDate = x.StartDate,
                    EndDate = x.EndDate,
                    Guide = x.Guide.Name,
                    Experience = x.Guide.Experience
                })
                .ToList();

            PdfPTable table = new PdfPTable(5);

            int[] widths = new int[] { 20, 20, 20, 15, 11 };

            table.SetWidths(widths);

            table.AddCell(this.CreateCell(new Phrase("Excursion name"), true));
            table.AddCell(this.CreateCell(new Phrase("Destination"), true));
            table.AddCell(this.CreateCell(new Phrase("Clients count"), true));
            table.AddCell(this.CreateCell(new Phrase("Clients satisfaction"), true));
            table.AddCell(this.CreateCell(new Phrase("Duration in days"), true));

            this.InputData(excursions, table);

            document.Add(table);
        }
コード例 #3
0
        private void FillDocument(Document document, TravelAgencyDbContext dbContext)
        {
            document.Open();

            this.GenerateData(document, dbContext);

            document.Close();
        }
コード例 #4
0
        public void GeneratePdfReports(TravelAgencyDbContext dbContext)
        {
            FileStream fs = new FileStream("../../../Data files/ExcursionsReport.pdf", FileMode.Create, FileAccess.Write, FileShare.None);

            Document document = new Document(this.CreatePdfRectangle());

            PdfWriter writer = PdfWriter.GetInstance(document, fs);

            this.FillDocument(document, dbContext);
        }
コード例 #5
0
        private void FillDropbox()
        {
            TravelAgencyDbContext dbContext = new TravelAgencyDbContext();
            DropboxImport inport = new DropboxImport(dbContext);

            this.destinationsComboBox.DataSource = inport.GetDestination();
            this.guidesComboBox.DataSource = inport.GetGuides();
            this.transportsComboBox.DataSource = inport.GetTransports();
            ////this.comboBox1.AutoCompleteSource = listToInport;
        }
コード例 #6
0
        private void GenerateXmlButtonHandler(object sender, EventArgs e)
        {
            try
            {
                TravelAgencyDbContext dbContext = new TravelAgencyDbContext();
                XMLGenerator xmlGenerator = new XMLGenerator();

                var cb1Value = this.destinationsComboBox.SelectedValue.ToString();
                var cb2Value = this.guidesComboBox.SelectedValue.ToString();
                var cb3Value = this.transportsComboBox.SelectedValue.ToString();
                xmlGenerator.XmlGenerate(dbContext, cb1Value, cb2Value, cb3Value);
                MessageBox.Show("XML document was generated successfully with the data from SQL!");
            }
            catch (Exception)
            {
                MessageBox.Show("XML document couldn't be generated!");
            }
        }
コード例 #7
0
        public void XmlGenerate(TravelAgencyDbContext dbContext, string destination, string guide, string transport)
        {
            XmlTextWriter writer = new XmlTextWriter("../../../Data files/TransportReport.xml", System.Text.Encoding.UTF8);
            writer.WriteStartDocument(true);
            writer.Formatting = Formatting.Indented;
            writer.Indentation = 2;
            writer.WriteStartElement("Table");
            var dataInvoker = new DataInvoker();
            var data = dataInvoker.GetData(dbContext, destination, guide, transport);

            foreach (var report in data)
            {
                this.CreateNode(report, writer);
            }

            writer.WriteEndElement();
            writer.WriteEndDocument();
            writer.Close();
        }
コード例 #8
0
        public override IEnumerable<ReportTransport> ProcessRequest(TravelAgencyDbContext dbContext, string destination, string guide, string transport)
        {
            if (destination == "*" && guide == "*" && transport == "*")
            {
                var excursions = dbContext
                .Excursions
                .Select(x => new ReportTransport()
                {
                    ExcName = x.Name,
                    StartDate = x.StartDate,
                    EndDate = x.EndDate,
                    CompanyName = x.Transport.CompanyName,
                    TransportType = x.Transport.Type,
                    County = x.Destination.Country
                })
                .ToList();

                return excursions;
            }
            else
            {
                return this.Successor.ProcessRequest(dbContext, destination, guide, transport);
            }
        }
コード例 #9
0
        public string[,] GenerateReports(TravelAgencyDbContext db)
        {
            using (var reportsContext = new ReportsFluentModel())
            {
                var schemaHandler = reportsContext.GetSchemaHandler();

                var sqliteReports = this.sqliteReader.GetData();

                var currentReports = reportsContext.GetAll<Report>().Select(x => new
                {
                    Name = x.Name,
                    ExpenseId = x.ExpenseId,
                    Income = x.TotalIncome
                }).ToList();

                var finalReportsLength = currentReports.Count;

                string[,] finalReports = new string[finalReportsLength, 2];

                for (int i = 0; i < finalReportsLength; i++)
                {
                    var currentReport = currentReports[i];
                    foreach (var sqliteReport in sqliteReports)
                    {
                        if (sqliteReport.Key == currentReport.ExpenseId)
                        {
                            var expenseToAdd = currentReport.Income - sqliteReport.Value;
                            finalReports[i, 0] = currentReport.Name;
                            finalReports[i, 1] = sqliteReport.Value.ToString();
                        }
                    }
                }

                return finalReports;
            }
        }
コード例 #10
0
 private void ReadFromXML(object sender, System.EventArgs e)
 {
     TravelAgencyDbContext dbContext = new TravelAgencyDbContext();
     ReadFromXml xmlReader = new ReadFromXml();
     this.guides = xmlReader.ImportFromXmlIntoSql("../../../Data files/Guides.xml");
     this.HideLoadDataButtons();
     importFormXmlToSqlButton.Show();
     loadFromXmlToMongoDbButton.Show();
     this.backButton.Visible = true;
 }
コード例 #11
0
 private void ImportFromSqlToXml(object sender, EventArgs e)
 {
     TravelAgencyDbContext dbContext = new TravelAgencyDbContext();
     XMLGenerator xmlGenerator = new XMLGenerator();
     this.GenerateXmlButtonHandler(sender, e);
 }
コード例 #12
0
 private void ImportFromSqlToPdf(object sender, EventArgs e)
 {
     try
     {
         TravelAgencyDbContext dbContext = new TravelAgencyDbContext();
         PdfGenerator pdfGenerator = new PdfGenerator();
         pdfGenerator.GeneratePdfReports(dbContext);
         MessageBox.Show("PDF report  was successfully generated with the data from SQL!");
     }
     catch (Exception)
     {
         MessageBox.Show("PDF report couldn't be generated!");
     }
 }
コード例 #13
0
 private void ImportFromMySqlAndSqliteToExcel(object sender, EventArgs e)
 {
     try
     {
         var db = new TravelAgencyDbContext();
         var reader = new ReadFromSQLite();
         var excelReportsToAdd = new ExcelReport(reader);
         var reports = excelReportsToAdd.GenerateReports(db);
         var excelWriter = new WritteDataToExcel();
         excelWriter.WritteDestinationInExcel(reports);
         MessageBox.Show("Excel report was succesfully generated with the data from MySQL and SQLite1");
     }
     catch (Exception)
     {
         MessageBox.Show("Excel report couldn't be generated!");
     }
 }
コード例 #14
0
 private void ImportFromMongoToSQL(object sender, EventArgs e)
 {
     try
     {
         var travelAgency = new TravelAgencyDbContext();
         var transports = new MongoDBImporter();
         transports.ImportData(travelAgency);
         MessageBox.Show("The data from MongoDb was successfully loaded to SQL!");
     }
     catch (Exception)
     {
         MessageBox.Show("The data from MongoDb couldn't be loaded to SQL!");
     }
 }