Exemple #1
0
        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 buttonSave_Click(object sender, EventArgs e)
        {
            bool hasNoError = true;

            errorProvider.Clear();

            if (comboBoxCustomername.Text.Trim().Length == 0)
            {
                errorProvider.SetError(comboBoxCustomername, "Customer Name is required");
                hasNoError = false;
            }
            if (textBoxCity.Text.Trim().Length == 0)
            {
                errorProvider.SetError(textBoxCity, "City is required");
                hasNoError = false;
            }

            if (!_hasChanges)
            {
                errorProvider.SetError(dataGridViewEvent, "Not all event has flight information");
                hasNoError = false;
            }
            if (hasNoError)
            {
                #region verify item
                _itineraryList = new List <FlightConnectionList>();
                foreach (DataRow dr in dtEventFlight.Rows)
                {
                    FlightConnectionList itemList = new FlightConnectionList();
                    itemList.AgencyNumber           = dr["FlightAgency"].ToString();
                    itemList.FlightConnectionNumber = dr["FlightConnection"].ToString();
                    itemList.FlightDate             = dr["FlightDate"].ToString();
                    if (itemList.FlightDate.Length == 0)
                    {
                        errorProvider.SetError(dataGridViewEvent, "Not all event has flight information");
                        return;
                    }
                    itemList.EventID = Convert.ToInt32(dr["EventID"]);
                    _itineraryList.Add(itemList);
                }
                _country        = (string)comboBoxCountry.SelectedValue;
                _language       = (string)comboBoxLanguage.SelectedValue;
                _customerName   = comboBoxCustomername.Text.Trim();
                _customerNumber = string.Empty;

                if (comboBoxCustomername.SelectedIndex > -1 &&
                    comboBoxCustomername.SelectedIndex <
                    customerList.Count)
                {
                    if (comboBoxCustomername.SelectedValue != null)
                    {
                        _customerNumber = customerList[(string)comboBoxCustomername.SelectedValue].CUSTOMERID;
                    }
                }
                else if (comboBoxCustomername.Items.Contains(_customerName))
                {
                    comboBoxCustomername.SelectedIndex = comboBoxCustomername.Items.IndexOf(_customerName);
                    if (comboBoxCustomername.SelectedValue != null)
                    {
                        BAPISCUDAT itemSelected =
                            customerList[(string)comboBoxCustomername.SelectedValue];
                        _customerNumber = itemSelected.CUSTOMERID;
                    }
                }
                #endregion

                PseudoProgressForm progress = new PseudoProgressForm();
                progress.ProgressLabel = "Saving to SAP...";
                BackgroundWorker bgWorker = new BackgroundWorker();

                string dob =
                    string.Format("{0:yyyy-MM-dd}", dateTimePicker.Value);
                string city       = textBoxCity.Text.Trim();
                string address    = textboxAddress.Text.Trim();
                string phone      = textboxPhone.Text.Trim();
                string postalCode = textBoxPostalCode.Text.Trim();

                bgWorker.DoWork +=
                    delegate(object senderWorker, DoWorkEventArgs eWorker)
                {
                    #region savecustomer
                    SAPCustomer customer = new SAPCustomer(Config.SAPUserName, Config.SAPPassword);
                    if (_customerNumber.Length == 0)
                    {
                        if (customer.CreateFromData(
                                city,
                                _country,
                                _customerName,
                                "P",
                                "none",
                                _language,
                                address,
                                phone,
                                postalCode))
                        {
                            //get customer number of inserted customer
                            bool found = false;
                            while (!found)
                            {
                                customer.GetList();
                                if (customer._customerList.Length > 0)
                                {
                                    //search last 4
                                    for (int i = customer._customerList.Length - 1;
                                         i > (customer._customerList.Length - 5);
                                         i--)
                                    {
                                        if (customer._customerList[i].CUSTNAME.Trim() == _customerName.Trim())
                                        {
                                            _customerNumber = customer._customerList[i].CUSTOMERID;
                                            found           = true;
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            _errorCustomer = customer._bapiReturn;
                            eWorker.Cancel = true;
                        }
                    }
                    #endregion

                    #region create flight trip
                    if (_customerNumber.Length > 0)
                    {
                        SAPFlightTrip flightTrip =
                            new SAPFlightTrip(Config.SAPUserName, Config.SAPPassword);
                        for (int index = 0; index < _itineraryList.Count; index++)
                        {
                            FlightConnectionList itemList = _itineraryList[index];
                            string classType = "Y";
                            if (dictPackageType.ContainsKey(itemList.EventID))
                            {
                                classType = dictPackageType[itemList.EventID];
                            }
                            string tripNumber;
                            string travelAgencyNumber;
                            if (flightTrip.CreateTrip(
                                    itemList.AgencyNumber,
                                    classType,
                                    _customerNumber,
                                    itemList.FlightConnectionNumber,
                                    "",
                                    itemList.FlightDate,
                                    "",
                                    "none",
                                    dob,
                                    _customerName,
                                    out travelAgencyNumber,
                                    out tripNumber))
                            {
                                itemList.TripNumber   = tripNumber;
                                _itineraryList[index] = itemList;
                            }
                            else
                            {
                                _errorFlight   = flightTrip._bapiFlTripReturn;
                                eWorker.Cancel = true;
                            }
                        }
                    }
                    #endregion
                };

                bgWorker.RunWorkerCompleted +=
                    delegate(object senderWorker, RunWorkerCompletedEventArgs eWorker)
                {
                    progress.Close();

                    int eventAttendeeID = 0;
                    SAPEventAttendeeReadWrite eventAttendee =
                        new SAPEventAttendeeReadWrite(Config._dbConnectionName);
                    DateTime dateCreate;
                    eventAttendee.Insert(
                        _packageID,
                        _customerNumber,
                        dateTimePicker.Value,
                        out dateCreate,
                        out eventAttendeeID);

                    foreach (FlightConnectionList item in _itineraryList)
                    {
                        int eventAttendMapID = 0;
                        SAPEventAttendeeAgencyMapReadWrite eventMap =
                            new SAPEventAttendeeAgencyMapReadWrite(Config._dbConnectionName);
                        eventMap.Insert(
                            eventAttendeeID,
                            item.EventID,
                            item.AgencyNumber,
                            item.TripNumber,
                            out eventAttendMapID);
                    }
                    Message.DisplayInfo("Thanks for purchasing the package.");     // Total Ticket Price: " + e.Result.ToString());
                    Close();
                };

                bgWorker.RunWorkerAsync();
                progress.ShowDialog();
            }
        }
Exemple #3
0
        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();
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        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);
        }
Exemple #6
0
        private void GetSource()
        {
            List <EventList> unUsedEvent =
                new List <EventList>();
            List <EventList> usedEvent =
                new List <EventList>();

            _sourceEvents =
                new List <EventList>();

            SAPEventReadWrite eventRW =
                new SAPEventReadWrite(Config._dbConnectionName);

            SAPEventAttendeeAgencyMapReadWrite eventAttendyMapRW =
                new SAPEventAttendeeAgencyMapReadWrite(Config._dbConnectionName);

            SAPPackageEventMapReadWrite packageEventMapRW =
                new SAPPackageEventMapReadWrite(Config._dbConnectionName);

            using (SAPDataReaderEvent readerEvent =
                       eventRW.ReaderSelectAll())
            {
                if (readerEvent.DataReader != null &&
                    readerEvent.DataReader.HasRows)
                {
                    SAPDataSetEventAttendeeAgencyMap.EventAttendeeAgencyMapDataTable dtEventAttendee =
                        eventAttendyMapRW.SelectAll().EventAttendeeAgencyMap;
                    SAPDataSetPackageEventMap.PackageEventMapDataTable dtPackageEvent =
                        packageEventMapRW.SelectAll().PackageEventMap;

                    while (readerEvent.DataReader.Read())
                    {
                        EventList item = new EventList();
                        item.EventName        = readerEvent.EventName;
                        item.EventDescription = readerEvent.EventDescription;
                        item.EventPhoto       = readerEvent.EventPhoto;
                        item.EventID          = readerEvent.EventID;

                        DataRow[] rows =
                            dtEventAttendee.Select("EventID = " + item.EventID.ToString());

                        if (rows != null && rows.Length > 0)
                        {
                            item.EventEditTag   = true;
                            item.EventDeleteTag = true;
                            usedEvent.Add(item);
                        }
                        else
                        {
                            item.EventEditTag = false;

                            rows =
                                dtPackageEvent.Select("EventId = " + item.EventID.ToString());

                            item.EventDeleteTag =
                                (rows != null && rows.Length > 0);

                            unUsedEvent.Add(item);
                        }
                    }// while (readerEvent.DataReader.Read());
                    _sourceEvents.AddRange(unUsedEvent);
                    _sourceEvents.AddRange(usedEvent);
                }
            }

            if (_sourceEvents.Count > 0)
            {
                pictureBoxPoster.Image =
                    UtilityHelper.ByteToImage(_sourceEvents[0].EventPhoto);
            }
        }
        public static void CreateSeedData()
        {
            #region create random name/date of birth list
            Random        rand     = new Random((int)DateTime.Now.Ticks);
            int           index    = 0;
            List <string> names    = new List <string>();
            List <string> nameList =
                Properties.Resources.ValidNames.Split(
                    Environment.NewLine.ToCharArray(),
                    StringSplitOptions.RemoveEmptyEntries).ToList <string>();

            DateTime[] dobs = new DateTime[Config.SeedDataLimit * 4 + 1];

            int month = DateTime.Now.Month;
            int day   = DateTime.Now.Day;
            int year  = DateTime.Now.Year;

            int nameCounter = 0;
            do
            {
                if (!names.Contains(nameList[nameCounter]))
                {
                    names.Add(nameList[nameCounter]);
                    index = rand.Next(year - 40, year);
                    dobs[names.Count - 1] = new DateTime(index, month, day);
                    nameCounter++;
                }
            } while (names.Count < Config.SeedDataLimit * 4 + 1);

            #endregion

            cityCountry =
                new SortedDictionary <string, string>();

            SetCityCountry();

            #region Clear Tables
            SAPEventActorMapReadWrite eventActorMapRW =
                new SAPEventActorMapReadWrite(Config._dbConnectionName);

            SAPDataSetEventActorMap eventActorMapDataSet = eventActorMapRW.SelectAll();

            foreach (SAPDataSetEventActorMap.EventActorMapRow row in
                     eventActorMapDataSet.EventActorMap.Rows)
            {
                eventActorMapRW.Delete(row.EventActorMapID);
            }

            SAPEventAttendeeAgencyMapReadWrite eventAttendeeAgencyMapRW =
                new SAPEventAttendeeAgencyMapReadWrite(Config._dbConnectionName);

            SAPDataSetEventAttendeeAgencyMap eventAttendeeAgencyMapDataSet =
                eventAttendeeAgencyMapRW.SelectAll();

            foreach (SAPDataSetEventAttendeeAgencyMap.EventAttendeeAgencyMapRow row
                     in eventAttendeeAgencyMapDataSet.EventAttendeeAgencyMap.Rows)
            {
                eventAttendeeAgencyMapRW.Delete(row.EventAttendeeAgencyMapID);
            }


            SAPEventAttendeeReadWrite eventAttendeeRW =
                new SAPEventAttendeeReadWrite(Config._dbConnectionName);

            SAPDataSetEventAttendee eventAttendeeDataSet = eventAttendeeRW.SelectAll();

            foreach (SAPDataSetEventAttendee.EventAttendeeRow row in
                     eventAttendeeDataSet.EventAttendee.Rows)
            {
                eventAttendeeRW.Delete(row.EventAttendeeID);
            }

            SAPEventActorReadWrite eventActorRW =
                new SAPEventActorReadWrite(Config._dbConnectionName);

            SAPDataSetEventActor eventActorDataSet = eventActorRW.SelectAll();

            foreach (SAPDataSetEventActor.EventActorRow row in
                     eventActorDataSet.EventActor.Rows)
            {
                eventActorRW.Delete(row.EventActorID);
            }

            SAPPackageEventMapReadWrite packageEventMapRW =
                new SAPPackageEventMapReadWrite(Config._dbConnectionName);

            SAPDataSetPackageEventMap packageEventMapDataset = packageEventMapRW.SelectAll();

            foreach (SAPDataSetPackageEventMap.PackageEventMapRow row in
                     packageEventMapDataset.PackageEventMap.Rows)
            {
                packageEventMapRW.Delete(row.PackageEventMapID);
            }

            SAPPackageReadWrite packageRW =
                new SAPPackageReadWrite(Config._dbConnectionName);

            SAPDataSetPackage packageDataSet = packageRW.SelectAll();

            foreach (SAPDataSetPackage.PackageRow row in
                     packageDataSet.Package.Rows)
            {
                packageRW.Delete(row.PackageID);
            }

            SAPEventReadWrite eventRW =
                new SAPEventReadWrite(Config._dbConnectionName);

            SAPDataSetEvent eventDataSet = eventRW.SelectAll();

            foreach (SAPDataSetEvent.EventRow row in eventDataSet.Event.Rows)
            {
                eventRW.Delete(row.EventID);
            }


            SAPEventTypeReadWrite eventTypeRW =
                new SAPEventTypeReadWrite(Config._dbConnectionName);

            SAPDataSetEventType eventTypeDataSet = eventTypeRW.SelectAll();

            foreach (SAPDataSetEventType.EventTypeRow row in
                     eventTypeDataSet.EventType.Rows)
            {
                eventTypeRW.Delete(row.EventTypeID);
            }

            #endregion

            #region Repopulate Tables

            SAPEventTypeReadWrite seedEventTypeRW =
                new SAPEventTypeReadWrite(Config._dbSeedConnectionName);

            SAPDataSetEventType seedEventTypeDataSet =
                seedEventTypeRW.SelectAll();

            int retEventTypeID = 0;

            foreach (SAPDataSetEventType.EventTypeRow row in
                     seedEventTypeDataSet.EventType.Rows)
            {
                eventTypeRW.Insert(row.EventTypeName, row.EventTypeDescription, out retEventTypeID);
            }


            SAPEventReadWrite seedEventRW =
                new SAPEventReadWrite(Config._dbSeedConnectionName);

            SAPDataSetEvent seedEventDataSet = seedEventRW.SelectAll();

            int retEventID = 0;

            //check the difference in seed date to adjust the event dates
            long monthDiff = UtilityHelper.GetMonthDifference(
                Config.DateLastSeed,
                DateTime.Now);

            foreach (SAPDataSetEvent.EventRow row in
                     seedEventDataSet.Event.Rows)
            {
                using (SAPDataReaderEventType rdrSeedEventType =
                           eventTypeRW.ReaderSelectByEventTypeName(row.EventTypeName))
                {
                    if (rdrSeedEventType.DataReader != null &&
                        rdrSeedEventType.DataReader.HasRows)
                    {
                        DateTime newDate = new DateTime();
                        //long monthDifference =
                        //    UtilityHelper.GetMonthDifference(DateTime.Now, row.EventDate);

                        newDate = row.EventDate.AddMonths((int)monthDiff);

                        rdrSeedEventType.DataReader.Read();
                        eventRW.Insert(row.VenueID, rdrSeedEventType.EventTypeID, row.EventName,
                                       row.EventDescription, row.EventPhoto, newDate, row.GoldPackagePrice,
                                       row.SilverPackagePrice, row.BronzePackagePrice, row.GoldPackageTrueCost,
                                       row.SilverPackageTrueCost, row.BronzePackageTrueCost, row.EventTotalCost,
                                       out retEventID);
                    }
                }
            }

            SAPPackageReadWrite seedPackageRW =
                new SAPPackageReadWrite(Config._dbSeedConnectionName);

            SAPDataSetPackage seedPackageDataset =
                seedPackageRW.SelectAll();

            int retPackageID = 0;


            foreach (SAPDataSetPackage.PackageRow row in
                     seedPackageDataset.Package.Rows)
            {
                packageRW.Insert(row.PackageName, row.PackageDescription,
                                 row.PackageImage, out retPackageID);
            }

            int   retPackageEventMapID        = 0;
            int[] seedNumberOfEventPerPackage = { 4, 3, 4, 4 };
            int   packageIndex = 0;

            using (SAPDataReaderPackage rdrPackage = packageRW.ReaderSelectAll())
            {
                if (rdrPackage.DataReader != null &&
                    rdrPackage.DataReader.HasRows)
                {
                    int eventIdx = 0;

                    while (rdrPackage.DataReader.Read())
                    {
                        int eventID = 0;
                        for (int idx = 0; idx < seedNumberOfEventPerPackage[packageIndex]; idx++)
                        {
                            using (SAPDataReaderEvent rdrEvent = eventRW.ReaderSelectAll())
                            {
                                if (rdrEvent.DataReader != null &&
                                    rdrEvent.DataReader.HasRows)
                                {
                                    if (eventIdx == 0)
                                    {
                                        rdrEvent.DataReader.Read();
                                        eventID = rdrEvent.EventID;
                                    }
                                    else
                                    {
                                        for (int eidx = 0; eidx <= eventIdx; eidx++)
                                        {
                                            rdrEvent.DataReader.Read();
                                            eventID = rdrEvent.EventID;
                                        }
                                    }
                                }
                            }
                            packageEventMapRW.Insert(rdrPackage.PackageID, eventID, out retPackageEventMapID);
                            eventIdx++;
                        }
                        packageIndex++;
                    }
                }
            }

            #endregion

            int currentNameIndex = 0;

            //get the 3 package here

            SAPPackageEventReadOnly packageEvent =
                new SAPPackageEventReadOnly(Config._dbConnectionName);

            _flightConnection =
                new SAPFlightConnection(Config.SAPUserName, Config.SAPPassword);

            #region generate data
            using (SAPDataReaderPackage rdrPackage =
                       packageRW.ReaderSelectAll())
            {
                if (rdrPackage.DataReader != null &&
                    rdrPackage.DataReader.HasRows)
                {
                    while (rdrPackage.DataReader.Read())
                    {
                        if (Array.IndexOf(packages, rdrPackage.PackageName.ToUpper().Trim()) > -1)
                        {
                            List <string> location = new List <string>();

                            SeedEventDataList[] flights = GetEvent(rdrPackage.PackageID);

                            for (int i = 1; i <= Config.SeedDataLimit; i++)
                            {
                                DateTime previousDate = DateTime.MinValue;
                                string   cityFrom     = string.Empty;

                                #region iterate for each event
                                for (int idx = 0; idx < flights.Length; idx++)
                                {
                                    BAPISCODAT selectedItem  = null;
                                    string     selectedClass = string.Empty;
                                    if (_flightConnection.GetList("", Config.SeedTravelAgency, cityFrom, flights[idx].VenueCity))
                                    {
                                        List <int>   classTypeIndex = new List <int>();
                                        BAPISCODAT[] flightList     = _flightConnection._bapiConnectionList;
                                        do
                                        {
                                            #region random classtype
                                            if (classTypeIndex.Count < 3)
                                            {
                                                do
                                                {
                                                    int ridx = rand.Next(0, 3);
                                                    if (!classTypeIndex.Contains(ridx))
                                                    {
                                                        classTypeIndex.Add(ridx);
                                                        break;
                                                    }
                                                } while (true);
                                            }
                                            string classType = _classType[classTypeIndex[classTypeIndex.Count - 1]];
                                            #endregion

                                            foreach (BAPISCODAT item in flightList)
                                            {
                                                bool isAvailable = true;

                                                if (!IsValidFlightDate(item.FLIGHTDATE, flights[idx].EventDate, previousDate))
                                                {
                                                    continue;
                                                }

                                                isAvailable = IsFlightAvailable(item, classType);

                                                #region check if city to is not found on previous list
                                                //make sure that this is the startup point of the event
                                                if (isAvailable)
                                                {
                                                    if (previousDate == DateTime.MinValue)
                                                    {
                                                        if (location.Contains(item.CITYFROM))
                                                        {
                                                            //mark this in case there would be no more cityfrom on the list
                                                            if (selectedItem == null)
                                                            {
                                                                selectedItem  = item;
                                                                selectedClass = classType;
                                                            }
                                                        }
                                                        else
                                                        {
                                                            location.Add(item.CITYFROM);
                                                            selectedItem  = item;
                                                            selectedClass = classType;
                                                            classTypeIndex.Add(1);
                                                            classTypeIndex.Add(2);
                                                            classTypeIndex.Add(3);
                                                            break;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        selectedItem  = item;
                                                        selectedClass = classType;
                                                        classTypeIndex.Add(1);
                                                        classTypeIndex.Add(2);
                                                        classTypeIndex.Add(3);
                                                        break;
                                                    }
                                                }
                                                #endregion
                                            }
                                        } while (classTypeIndex.Count < 3);
                                    }
                                    previousDate = flights[idx].EventDate;
                                    if (selectedItem != null)
                                    {
                                        SeedEventDataList eventData = flights[idx];
                                        eventData.AgencyNum    = selectedItem.AGENCYNUM;
                                        eventData.FlightConnNo = selectedItem.FLIGHTCONN;
                                        eventData.CityFrom     = selectedItem.CITYFROM;
                                        eventData.FlightDate   = selectedItem.FLIGHTDATE;
                                        eventData.ClassType    = selectedClass;
                                        flights[idx]           = eventData;
                                        cityFrom = eventData.VenueCity;
                                    }
                                }
                                #endregion

                                #region verify if there's flight
                                bool isReady = true;
                                for (int idx = 0; idx < flights.Length; idx++)
                                {
                                    if (String.IsNullOrEmpty(flights[idx].FlightConnNo))
                                    {
                                        isReady = false;
                                    }
                                }
                                #endregion

                                if (isReady)
                                {
                                    string customerCity = flights[0].CityFrom;
                                    string customerName = names[currentNameIndex];
                                    string language     = string.Empty;
                                    string country      = GetCountry(customerCity, out language);
                                    string dob          =
                                        string.Format("{0:yyyy-MM-dd}", dobs[currentNameIndex]);
                                    string customerNumber = string.Empty;
                                    bool   isError        = false;

                                    #region save customer
                                    SAPCustomer customer =
                                        new SAPCustomer(Config.SAPUserName, Config.SAPPassword);

                                    if (customer.CreateFromData(
                                            customerCity,
                                            country,
                                            customerName,
                                            "P",
                                            "none",
                                            language,
                                            "N/A",
                                            "",
                                            ""))
                                    {
                                        //get customer number of inserted customer
                                        bool found = false;
                                        while (!found)
                                        {
                                            customer.GetList();
                                            if (customer._customerList.Length > 0)
                                            {
                                                //search last 3
                                                for (int j = customer._customerList.Length - 1;
                                                     j > (customer._customerList.Length - 3);
                                                     j--)
                                                {
                                                    if (customer._customerList[j].CUSTNAME.Trim() == customerName.Trim())
                                                    {
                                                        customerNumber = customer._customerList[j].CUSTOMERID;
                                                        found          = true;
                                                        break;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                break;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        isError = true;
                                    }
                                    #endregion

                                    #region create flight trip
                                    if (customerNumber.Length > 0)
                                    {
                                        SAPFlightTrip flightTrip =
                                            new SAPFlightTrip(Config.SAPUserName, Config.SAPPassword);
                                        for (int idx = 0; idx < flights.Length; idx++)
                                        {
                                            SeedEventDataList item = flights[idx];
                                            string            tripNumber;
                                            string            travelAgencyNumber;
                                            if (flightTrip.CreateTrip(
                                                    item.AgencyNum,
                                                    item.ClassType,
                                                    customerNumber,
                                                    item.FlightConnNo,
                                                    "",
                                                    item.FlightDate,
                                                    "",
                                                    "none",
                                                    dob,
                                                    customerName,
                                                    out travelAgencyNumber,
                                                    out tripNumber))
                                            {
                                                flights[idx].TripNumber = tripNumber;
                                            }
                                            else
                                            {
                                                isError = true;
                                            }
                                        }
                                    }
                                    #endregion

                                    #region save to local db
                                    if (!isError)
                                    {
                                        int eventAttendeeID = 0;
                                        SAPEventAttendeeReadWrite eventAttendee =
                                            new SAPEventAttendeeReadWrite(Config._dbConnectionName);
                                        DateTime dateCreate;
                                        eventAttendee.Insert(
                                            rdrPackage.PackageID,
                                            customerNumber,
                                            DateTime.Now,
                                            out dateCreate,
                                            out eventAttendeeID);

                                        for (int idx = 0; idx < flights.Length; idx++)
                                        {
                                            int eventAttendMapID = 0;
                                            SAPEventAttendeeAgencyMapReadWrite eventMap =
                                                new SAPEventAttendeeAgencyMapReadWrite(Config._dbConnectionName);
                                            eventMap.Insert(
                                                eventAttendeeID,
                                                flights[idx].EventID,
                                                flights[idx].AgencyNum,
                                                flights[idx].TripNumber,
                                                out eventAttendMapID);
                                        }
                                    }
                                    #endregion

                                    currentNameIndex++;
                                }
                                //reset flights
                                for (int idx = 0; idx < flights.Length; idx++)
                                {
                                    flights[idx].AgencyNum    = string.Empty;
                                    flights[idx].ClassType    = string.Empty;
                                    flights[idx].FlightConnNo = string.Empty;
                                    flights[idx].FlightDate   = string.Empty;
                                    flights[idx].TripNumber   = string.Empty;
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            Config.UpdateKey(Config._keySeedData, "true");
            Config.UpdateKey(Config._keyDateLastSeed, DateTime.Now.ToString());
        }