public static StatisticList GetStatistics(int packageID) { StatisticList statList = new StatisticList(); SortedDictionary <string, string> customerList = new SortedDictionary <string, string>(); SAPEventAttendeeAgencyMapReadWrite eventTrip = new SAPEventAttendeeAgencyMapReadWrite(Config._dbConnectionName); #region get statistic using (SAPDataReaderEventAttendeeAgencyMap rdrTrip = eventTrip.ReaderSelectByPackageID(packageID)) { if (rdrTrip.DataReader != null && rdrTrip.DataReader.HasRows) { SAPFlightTrip flightTrip = new SAPFlightTrip(Config.SAPUserName, Config.SAPPassword); while (rdrTrip.DataReader.Read()) { if (flightTrip.GetList( rdrTrip.CustomerNumber.Trim(), rdrTrip.AgencyNumber.Trim())) { BAPISTRDAT[] _bapiFlightTripList = flightTrip._bapiFlightTripList; foreach (BAPISTRDAT _bapiFlightTrip in _bapiFlightTripList) { if (_bapiFlightTrip.TRIPNUMBER != rdrTrip.TripNumber.Trim()) { continue; } statList.AdultAgeStat += _bapiFlightTrip.NUMADULT; statList.ChildAgeStat += _bapiFlightTrip.NUMCHILD; statList.InfantAgeStat += _bapiFlightTrip.NUMINFANT; switch (_bapiFlightTrip.CLASS) { case "Y": statList.FirstClassStat++; break; case "C": statList.BusinessClassStat++; break; case "F": statList.EconomyClassStat++; break; } } } }// while (rdrTrip.DataReader.Read()); } } #endregion return(statList); }
private void buttonTicket_Click(object sender, RibbonControlEventArgs e) { PseudoProgressForm progress = new PseudoProgressForm(); progress.ProgressLabel = "Querying SAP..."; BackgroundWorker backgroundWorker = new BackgroundWorker(); TicketSales ticketDataset = new TicketSales(); backgroundWorker.DoWork += delegate(object workSender, DoWorkEventArgs eventArg) { TicketSales.TicketSaleDataTable ticketSaleDataTable = ticketDataset.TicketSale; SAPEventAttendeeAgencyMapReadWrite attendeeAgency = new SAPEventAttendeeAgencyMapReadWrite(Config._dbConnectionName); SAPRefTravelAgencyReadWrite travelAgency = new SAPRefTravelAgencyReadWrite(Config._dbConnectionName); //get all agencies where client booked flights to Dictionary <string, string> agencyList = new Dictionary <string, string>(); using (SAPDataReaderEventAttendeeAgencyMap reader = attendeeAgency.ReaderSelectAll()) { if (reader.DataReader.HasRows) { while (reader.DataReader.Read()) { if (!agencyList.ContainsKey(reader.AgencyNumber)) { string agencyName = string.Empty; using (SAPDataReaderRefTravelAgency travelReader = travelAgency.ReaderSelectByAgencyNumber(reader.AgencyNumber)) { travelReader.DataReader.Read(); agencyName = travelReader.AgencyName; } agencyList.Add( reader.AgencyNumber, agencyName); } } } } SAPFlightTrip flightTripHelper = new SAPFlightTrip(Config.SAPUserName, Config.SAPPassword); SAPFlightConnection flightConnectionHelper = new SAPFlightConnection(Config.SAPUserName, Config.SAPPassword); foreach (KeyValuePair <string, string> agency in agencyList) { TicketSales.TicketSaleRow ticketSaleRow = ticketSaleDataTable.NewTicketSaleRow(); ticketSaleRow.AgencyName = agency.Value; ticketSaleRow.TicketsSold = 0; ticketSaleRow.TotalTicketPrice = 0; flightTripHelper.GetList(string.Empty, agency.Key); foreach (SAPServices.SAP_FLIGHTTRIPLIST.BAPISTRDAT flightTrip in flightTripHelper._bapiFlightTripList) { flightConnectionHelper.GetDetail( flightTrip.FLCONN1, flightTrip.FLDATE1, string.Empty, flightTrip.AGENCYNUM); ticketSaleRow.TicketsSold += 1; ticketSaleRow.TotalTicketPrice += flightConnectionHelper._bapiPrice.PRICE_BUS1; } ticketSaleDataTable.AddTicketSaleRow(ticketSaleRow); } }; backgroundWorker.RunWorkerCompleted += delegate(object workSender, RunWorkerCompletedEventArgs eventArg) { progress.Close(); progress.Dispose(); ExcelHelper.LoadExcelSheet( "TicketSalesDistribution", Resources.TicketSalesDistribution, ticketDataset); }; backgroundWorker.RunWorkerAsync(); progress.ShowDialog(); }
public static StatisticList GetStatistics(int packageID) { StatisticList statList = new StatisticList(); SortedDictionary <string, int> locationCount = new SortedDictionary <string, int>(); SortedDictionary <string, string> customerList = new SortedDictionary <string, string>(); SAPEventAttendeeAgencyMapReadWrite eventTrip = new SAPEventAttendeeAgencyMapReadWrite(Config._dbConnectionName); SAPEventAttendeeReadWrite eventAttendee = new SAPEventAttendeeReadWrite(Config._dbConnectionName); #region get customer list first SAPCustomer sapCustomer = new SAPCustomer(Config.SAPUserName, Config.SAPPassword); if (sapCustomer.GetList()) { foreach (SAPServices.SAP_FLIGHTCUSTOMERLIST.BAPISCUDAT customerItem in sapCustomer._customerList) { if (!customerList.ContainsKey(customerItem.CUSTOMERID)) { customerList.Add( customerItem.CUSTOMERID, customerItem.CITY); } } } #endregion #region get statistic using (SAPDataReaderEventAttendeeAgencyMap rdrTrip = eventTrip.ReaderSelectByPackageID(packageID)) { if (rdrTrip.DataReader != null && rdrTrip.DataReader.HasRows) { SAPFlightTrip flightTrip = new SAPFlightTrip(Config.SAPUserName, Config.SAPPassword); while (rdrTrip.DataReader.Read()) { if (flightTrip.GetList( rdrTrip.CustomerNumber.Trim(), rdrTrip.AgencyNumber.Trim())) { SAPServices.SAP_FLIGHTTRIPLIST.BAPISTRDAT[] _bapiFlightTripList = flightTrip._bapiFlightTripList; foreach (SAPServices.SAP_FLIGHTTRIPLIST.BAPISTRDAT _bapiFlightTrip in _bapiFlightTripList) { if (_bapiFlightTrip.TRIPNUMBER != rdrTrip.TripNumber.Trim()) { continue; } statList.AdultAgeStat += _bapiFlightTrip.NUMADULT; statList.ChildAgeStat += _bapiFlightTrip.NUMCHILD; statList.InfantAgeStat += _bapiFlightTrip.NUMINFANT; switch (_bapiFlightTrip.CLASS) { case "Y": statList.FirstClassStat++; break; case "C": statList.BusinessClassStat++; break; case "F": statList.EconomyClassStat++; break; } } } } //while (rdrTrip.DataReader.Read()); } } #endregion using (SAPDataReaderEventAttendee rdrEventAttendee = eventAttendee.ReaderSelectByPackageID(packageID)) { if (rdrEventAttendee.DataReader != null && rdrEventAttendee.DataReader.HasRows) { while (rdrEventAttendee.DataReader.Read()) { //location demographics if (customerList.ContainsKey(rdrEventAttendee.CustomerNumber.Trim())) { string location = customerList[rdrEventAttendee.CustomerNumber.Trim()].ToUpper(); if (locationCount.ContainsKey(location)) { locationCount[location]++; } else { locationCount.Add(location, 1); } } } //while (rdrEventAttendee.DataReader.Read()); } } Population populate = null; if (locationCount.Count > 0) { populate = new Population(); Population.PopulationTableDataTable dt = populate.PopulationTable; foreach (KeyValuePair <string, int> kvp in locationCount) { dt.AddPopulationTableRow( kvp.Key, kvp.Value); } } statList.LocationStat = populate; return(statList); }
public static Sales GetSalesData(int month, int year) { Sales salesDataset = new Sales(); Sales.PackageDataTable salesPackageDataTable = salesDataset.Package; Sales.PackageSaleDataTable salesPackageSaleDataTable = salesDataset.PackageSale; Sales.EventDataTable salesEventDataTable = salesDataset.Event; Sales.EventSaleDataTable salesEventSaleDataTable = salesDataset.EventSale; Sales.FlightDataTable salesFlightDataTable = salesDataset.Flight; SAPPackageReadWrite package = new SAPPackageReadWrite(Config._dbConnectionName); SAPEventAttendeeReadWrite attendee = new SAPEventAttendeeReadWrite(Config._dbConnectionName); SAPEventAttendeeAgencyMapReadWrite eventAttendeeAgencyMap = new SAPEventAttendeeAgencyMapReadWrite(Config._dbConnectionName); SAPPackageEventMapReadWrite packageEventMap = new SAPPackageEventMapReadWrite(Config._dbConnectionName); SAPEventReadWrite events = new SAPEventReadWrite(Config._dbConnectionName); SAPFlightTrip flightTripHelper = new SAPFlightTrip(Config.SAPUserName, Config.SAPPassword); SAPFlightConnection flightConnectionHelper = new SAPFlightConnection(Config.SAPUserName, Config.SAPPassword); //fetch all packages SAPDataSetPackage packageDataset = package.SelectAll(); //iterate through the packages foreach (SAPDataSetPackage.PackageRow packageRow in packageDataset.Package.Rows) { Sales.PackageRow salesPackageRow = salesPackageDataTable.AddPackageRow(packageRow.PackageID, packageRow.PackageName); SAPDataSetEventAttendee attendeeDataset = attendee.SelectByPackageID(packageRow.PackageID); SAPDataSetPackageEventMap packageEventMapDataset = packageEventMap.SelectByPackageID(packageRow.PackageID); foreach (SAPDataSetEventAttendee.EventAttendeeRow eventAttendeeRow in attendeeDataset.EventAttendee.Rows) { if ((eventAttendeeRow.Created.Month == month || month == 0) && (eventAttendeeRow.Created.Year == year || year == 0)) { //build temp package table Sales.PackageSaleRow salesPackageSaleRow = salesPackageSaleDataTable.AddPackageSaleRow( salesPackageRow, eventAttendeeRow.EventAttendeeID, eventAttendeeRow.Created, eventAttendeeRow.DateOfBirth, eventAttendeeRow.CustomerNumber, 0, 0); SAPDataSetEventAttendeeAgencyMap eventAttendeeAgencyMapDataset = eventAttendeeAgencyMap.SelectByEventAttendeeID(eventAttendeeRow.EventAttendeeID); for (int i = 0; i < packageEventMapDataset.PackageEventMap.Rows.Count; i++) { SAPDataSetPackageEventMap.PackageEventMapRow packageEventMapRow = packageEventMapDataset.PackageEventMap.Rows[i] as SAPDataSetPackageEventMap.PackageEventMapRow; SAPDataSetEvent eventDataset = events.SelectByEventID(packageEventMapRow.EventID); SAPDataSetEvent.EventRow eventRow = eventDataset.Event[0]; //assumes same record position as to event, need to revise!!! //SAPDataSetEventAttendeeAgencyMap.EventAttendeeAgencyMapRow eventAttendeeAgencyMapRow = // eventAttendeeAgencyMapDataset.EventAttendeeAgencyMap.Rows[i] as // SAPDataSetEventAttendeeAgencyMap.EventAttendeeAgencyMapRow; DataRow[] eventAttendeeAgencyMapDataRow = eventAttendeeAgencyMapDataset.EventAttendeeAgencyMap.Select("EventID = " + packageEventMapRow.EventID); SAPDataSetEventAttendeeAgencyMap.EventAttendeeAgencyMapRow eventAttendeeAgencyMapRow = eventAttendeeAgencyMapDataRow[0] as SAPDataSetEventAttendeeAgencyMap.EventAttendeeAgencyMapRow; Sales.EventRow salesEventRow = salesEventDataTable.FindByEventID(eventRow.EventID); if (salesEventRow == null) { salesEventRow = salesEventDataTable.AddEventRow( eventRow.EventID, eventRow.EventName, eventRow.GoldPackagePrice, eventRow.SilverPackagePrice, eventRow.BronzePackagePrice, eventRow.GoldPackageTrueCost, eventRow.SilverPackageTrueCost, eventRow.BronzePackageTrueCost); } salesEventSaleDataTable.AddEventSaleRow( salesEventRow, packageRow.PackageID, eventAttendeeRow.EventAttendeeID, eventAttendeeAgencyMapRow.AgencyNumber, eventAttendeeAgencyMapRow.TripNumber, string.Empty, 0, 0); } } } } foreach (Sales.PackageSaleRow salesPackageSalesRow in salesPackageSaleDataTable.Rows) { foreach (DataRow row in salesPackageSalesRow.GetChildRows("PackageSale_EventSale")) { Sales.EventSaleRow salesEventSaleRow = row as Sales.EventSaleRow; flightTripHelper.GetList( salesPackageSalesRow.CustomerNumber.Trim(), salesEventSaleRow.AgencyNumber); foreach (SAPServices.SAP_FLIGHTTRIPLIST.BAPISTRDAT trip in flightTripHelper._bapiFlightTripList) { if (salesEventSaleRow.TripNumber == trip.TRIPNUMBER) { flightConnectionHelper.GetDetail( trip.FLCONN1, trip.FLDATE1, string.Empty, salesEventSaleRow.AgencyNumber); Sales.EventRow salesEventRow = salesEventDataTable.FindByEventID(salesEventSaleRow.EventID); decimal ticketPrice = 0; switch (trip.CLASS) { case "F": salesEventSaleRow.Cost = salesEventRow.GoldPackageCost; salesEventSaleRow.Price = salesEventRow.GoldPackagePrice; salesEventSaleRow.PackageType = "Gold"; ticketPrice = trip.NUMADULT == 1 ? flightConnectionHelper._bapiPrice.PRICE_FST1 : trip.NUMCHILD == 1 ? flightConnectionHelper._bapiPrice.PRICE_FST2 : trip.NUMINFANT == 1 ? flightConnectionHelper._bapiPrice.PRICE_FST3 : 0; break; case "C": salesEventSaleRow.Cost = salesEventRow.SilverPackageCost; salesEventSaleRow.Price = salesEventRow.SilverPackagePrice; salesEventSaleRow.PackageType = "Silver"; ticketPrice = trip.NUMADULT == 1 ? flightConnectionHelper._bapiPrice.PRICE_BUS1 : trip.NUMCHILD == 1 ? flightConnectionHelper._bapiPrice.PRICE_BUS2 : trip.NUMINFANT == 1 ? flightConnectionHelper._bapiPrice.PRICE_BUS3 : 0; break; case "Y": salesEventSaleRow.Cost = salesEventRow.BronzePackageCost; salesEventSaleRow.Price = salesEventRow.BronzePackagePrice; salesEventSaleRow.PackageType = "Bronze"; ticketPrice = trip.NUMADULT == 1 ? flightConnectionHelper._bapiPrice.PRICE_ECO1 : trip.NUMCHILD == 1 ? flightConnectionHelper._bapiPrice.PRICE_ECO2 : trip.NUMINFANT == 1 ? flightConnectionHelper._bapiPrice.PRICE_ECO3 : 0; break; } salesPackageSalesRow.Cost += salesEventSaleRow.Cost; salesPackageSalesRow.Price += salesEventSaleRow.Price; salesFlightDataTable.AddFlightRow( salesEventSaleRow, trip.FLCONN1, trip.FLDATE1, trip.CLASS, ticketPrice, trip.NUMADULT, trip.NUMCHILD, trip.NUMINFANT); } } } } return(salesDataset); }