コード例 #1
0
        private void StartSAPEnvironment()
        {
            PseudoProgressForm progress = new PseudoProgressForm(Config.SeedDataLimit / 2);

            progress.ProgressLabel = "Setting the SAP Environment...";
            BackgroundWorker backgroundWorker = new BackgroundWorker();

            Process[] processes = Process.GetProcessesByName(Config.SAPProcess);

            if (processes == null || processes.Length == 0)
            {
                backgroundWorker.DoWork +=
                    delegate(object obj, DoWorkEventArgs eventArgs)
                {
                    Process sapProcess = new Process();

                    ProcessStartInfo sapInfo = new ProcessStartInfo(Config.SAPProcessFile);

                    sapInfo.WindowStyle  = ProcessWindowStyle.Normal;
                    sapProcess.StartInfo = sapInfo;
                    sapProcess.Start();
                    sapProcess.WaitForExit();
                };

                backgroundWorker.RunWorkerCompleted +=
                    delegate(object obj, RunWorkerCompletedEventArgs eventArgs)
                {
                    progress.Close();
                };

                backgroundWorker.RunWorkerAsync();
                progress.ShowDialog();
            }
        }
コード例 #2
0
        private void linkLabelSeedDatabase_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Visible = false;

            Config.UpdateKey(Config._keyShowReseedDataForm, "false");

            PseudoProgressForm progress = new PseudoProgressForm(Config.SeedDataLimit / 2);

            progress.ProgressLabel = "Creating seed data...";
            BackgroundWorker backgroundWorker = new BackgroundWorker();

            backgroundWorker.DoWork +=
                delegate(object obj, DoWorkEventArgs eventArgs)
            {
                SeedDataHelper.CreateSeedData();
            };

            backgroundWorker.RunWorkerCompleted +=
                delegate(object obj, RunWorkerCompletedEventArgs eventArgs)
            {
                progress.Close();
                Close();
            };

            backgroundWorker.RunWorkerAsync();
            progress.ShowDialog(this);
        }
コード例 #3
0
        private void buttonFlightList_Click(object sender, RibbonControlEventArgs e)
        {
            PseudoProgressForm progress = new PseudoProgressForm();

            progress.ProgressLabel = "Querying SAP...";
            BackgroundWorker backgroundWorker = new BackgroundWorker();

            Flights flightDataset = new Flights();

            backgroundWorker.DoWork +=
                delegate(object workSender, DoWorkEventArgs eventArg)
            {
                SAPFlight flightHelper =
                    new SAPFlight(Config.SAPUserName, Config.SAPPassword);

                flightHelper.GetList();

                Flights.FlightDataTable flightTable = flightDataset.Flight;

                foreach (SAPServices.SAP_FLIGHTLIST.BAPISFLDAT flight in flightHelper._flightList)
                {
                    DateTime flDate = Convert.ToDateTime(flight.FLIGHTDATE);
                    if (flDate > DateTime.Today)
                    {
                        flightHelper.CheckAvailability(flight.AIRLINEID, flight.CONNECTID, flight.FLIGHTDATE);
                        flight.FLIGHTDATE = flDate.ToShortDateString();

                        flightTable.AddFlightRow(
                            flight.AIRLINE,
                            flight.CITYFROM,
                            flight.CITYTO,
                            flight.AIRPORTFR,
                            flight.AIRPORTTO,
                            flight.FLIGHTDATE,
                            flight.DEPTIME,
                            flight.ARRDATE,
                            flight.ARRTIME,
                            flightHelper._availability.FIRSTFREE,
                            flightHelper._availability.BUSINFREE,
                            flightHelper._availability.ECONOFREE);
                    }
                }
            };

            backgroundWorker.RunWorkerCompleted +=
                delegate(object workSender, RunWorkerCompletedEventArgs eventArg)
            {
                progress.Close();
                ExcelHelper.LoadExcelSheet("ListOfFlights", Resources.ListOfFlights, flightDataset);
            };

            backgroundWorker.RunWorkerAsync();
            progress.ShowDialog();
        }
コード例 #4
0
        private void buttonListofCustomers_Click(object sender, RibbonControlEventArgs e)
        {
            PseudoProgressForm progress = new PseudoProgressForm();

            progress.ProgressLabel = "Querying SAP...";
            BackgroundWorker backgroundWorker = new BackgroundWorker();

            Customers customerDataset = new Customers();

            backgroundWorker.DoWork +=
                delegate(object workSender, DoWorkEventArgs eventArg)
            {
                SAPEventAttendeeReadWrite attendee     = new SAPEventAttendeeReadWrite(Config._dbConnectionName);
                SAPDataSetEventAttendee   attendeeData = attendee.SelectAll();

                SAPCustomer sapCustomer =
                    new SAPCustomer(Config.SAPUserName, Config.SAPPassword);

                sapCustomer.GetList();

                Customers.CustomerDataTable customerData = customerDataset.Customer;

                foreach (SAPServices.SAP_FLIGHTCUSTOMERLIST.BAPISCUDAT customer in sapCustomer._customerList)
                {
                    DataRow[] dr =
                        attendeeData.EventAttendee.Select("CustomerNumber = " + customer.CUSTOMERID.Trim());

                    int IsContosoCustomer = dr.Length > 0 ? 1 : 0;

                    customerData.AddCustomerRow(
                        customer.CUSTNAME,
                        customer.STREET,
                        customer.POBOX,
                        customer.POSTCODE,
                        customer.CITY,
                        customer.COUNTR,
                        customer.PHONE,
                        IsContosoCustomer);
                }
            };

            backgroundWorker.RunWorkerCompleted +=
                delegate(object workSender, RunWorkerCompletedEventArgs eventArg)
            {
                progress.Close();
                ExcelHelper.LoadExcelSheet("ListOfCustomer", Resources.ListOfCustomers, customerDataset);
            };

            backgroundWorker.RunWorkerAsync();
            progress.ShowDialog();
        }
コード例 #5
0
        private void buttonPackageSales_Click(object sender, RibbonControlEventArgs e)
        {
            PseudoProgressForm progress = new PseudoProgressForm();

            progress.ProgressLabel = "Querying SAP...";
            BackgroundWorker backgroundWorker    = new BackgroundWorker();
            PackageSales     packageSalesDataset = new PackageSales();

            backgroundWorker.DoWork +=
                delegate(object workSender, DoWorkEventArgs eventArg)
            {
                PackageSales.PackageSaleDataTable packageSalesTable =
                    packageSalesDataset.PackageSale;

                Sales sales = DataHelper.GetSalesData();

                foreach (Sales.PackageRow packageRow in sales.Package.Rows)
                {
                    PackageSales.PackageSaleRow packageSaleRow = packageSalesTable.NewPackageSaleRow();
                    packageSaleRow.PackageName   = packageRow.PackageName;
                    packageSaleRow.NumberOfSales = 0;
                    packageSaleRow.PriceOfSales  = 0;
                    foreach (DataRow row in packageRow.GetChildRows("Package_PackageSale"))
                    {
                        Sales.PackageSaleRow salesPackageSaleRow = row as Sales.PackageSaleRow;
                        packageSaleRow.NumberOfSales += 1;
                        packageSaleRow.PriceOfSales  += salesPackageSaleRow.Price;
                    }
                    packageSalesTable.AddPackageSaleRow(packageSaleRow);
                }
            };

            backgroundWorker.RunWorkerCompleted +=
                delegate(object workSender, RunWorkerCompletedEventArgs eventArg)
            {
                progress.Close();
                progress.Dispose();

                ExcelHelper.LoadExcelSheet(
                    "PackageSalesDistribution",
                    Resources.PackageSalesDistribution,
                    packageSalesDataset);
            };

            backgroundWorker.RunWorkerAsync();
            progress.ShowDialog();
        }
コード例 #6
0
        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();
            }
        }
コード例 #7
0
        private void BookEvent_Load(object sender, EventArgs e)
        {
            #region populate combobox country
            SAPRefCountryReadWrite country =
                new SAPRefCountryReadWrite(Config._dbConnectionName);
            comboBoxCountry.DataSource    = country.SelectAll().RefCountry;
            comboBoxCountry.DisplayMember = SAPRefCountryReadWrite._countryNameColumnName;
            comboBoxCountry.ValueMember   = SAPRefCountryReadWrite._countryCodeColumnName;
            #endregion

            #region populate combobox language
            SAPRefLanguageReadWrite language =
                new SAPRefLanguageReadWrite(Config._dbConnectionName);
            comboBoxLanguage.DataSource    = language.SelectAll().RefLanguage;
            comboBoxLanguage.DisplayMember = SAPRefLanguageReadWrite._languageColumnName;
            comboBoxLanguage.ValueMember   = SAPRefLanguageReadWrite._languageCodeColumnName;
            #endregion

            #region create grid
            SAPPackageEventReadOnly packageEvent =
                new SAPPackageEventReadOnly(Config._dbConnectionName);
            dtEventFlight = new DataTable();
            dtEventFlight.Columns.Add("EventName", typeof(string));
            dtEventFlight.Columns.Add("EventVenue", typeof(string));
            dtEventFlight.Columns.Add("EventDate", typeof(DateTime));
            dtEventFlight.Columns.Add("FlightDate", typeof(string));
            dtEventFlight.Columns.Add("FlightTime", typeof(string));
            dtEventFlight.Columns.Add("FlightAirport", typeof(string));
            dtEventFlight.Columns.Add("FlightConnection", typeof(string));
            dtEventFlight.Columns.Add("FlightAgency", typeof(string));
            dtEventFlight.Columns.Add("VenueCity", typeof(string));
            dtEventFlight.Columns.Add("EventID", typeof(int));

            using (SAPDataReaderPackageEvent rdrEvent =
                       packageEvent.ReaderSelectByPackageID(_packageID))
            {
                if (rdrEvent.DataReader != null &&
                    rdrEvent.DataReader.HasRows)
                {
                    while (rdrEvent.DataReader.Read())
                    {
                        dtEventFlight.Rows.Add(
                            rdrEvent.EventName,
                            rdrEvent.VenueName,
                            rdrEvent.EventDate,
                            string.Empty,
                            string.Empty,
                            string.Empty,
                            string.Empty,
                            string.Empty,
                            rdrEvent.VenueCity,
                            rdrEvent.EventID);
                    } //while (rdrEvent.DataReader.Read());
                }
            }
            dataGridViewEvent.DataSource = dtEventFlight;
            GridHelper.HideColumns(
                dataGridViewEvent,
                "FlightConnection",
                "FlightAgency",
                "VenueCity",
                "EventID");

            #endregion

            #region get customer from SAP
            dtCustomer = new DataTable();
            dtCustomer.Columns.Add("customername", typeof(string));
            dtCustomer.Columns.Add("customerid", typeof(string));

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

            addCustomerItem = new AddCustomerItem(AddCustomer);

            bgWorker.DoWork +=
                delegate(object senderWorker, DoWorkEventArgs eWorker)
            {
                SAPCustomer sapCustomer = new SAPCustomer(Config.SAPUserName, Config.SAPPassword);
                if (sapCustomer.GetList() && sapCustomer._customerList.Length > 0)
                {
                    //customerList = sapCustomer._customerList;
                    customerList = new SortedList <string, BAPISCUDAT>();
                    foreach (BAPISCUDAT item in
                             sapCustomer._customerList)
                    {
                        if (!customerList.ContainsKey(item.CUSTOMERID))
                        {
                            customerList.Add(item.CUSTOMERID, item);
                            dtCustomer.Rows.Add(item.CUSTNAME, item.CUSTOMERID);
                        }
                    }
                }
            };

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

            bgWorker.RunWorkerAsync();
            progress.ShowDialog();
            dtCustomer.DefaultView.Sort        = "customername";
            comboBoxCustomername.DataSource    = dtCustomer.DefaultView;
            comboBoxCustomername.DisplayMember = "customername";
            comboBoxCustomername.ValueMember   = "customerid";

            comboBoxCustomername.Text = string.Empty;
            #endregion
        }
        private void buttonSearch_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor = Cursors.WaitCursor;
                listViewFlight.Items.Clear();
                addListItem = new AddListItem(AddListItemMethod);

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

                string airlineID    = string.Empty;
                string travelAgency = string.Empty;

                if (comboBoxAirline.SelectedIndex > -1)
                {
                    airlineID = (string)comboBoxAirline.SelectedValue;
                }
                if (comboBoxTravelAgency.SelectedIndex > -1)
                {
                    travelAgency = (string)comboBoxTravelAgency.SelectedValue;
                }

                PseudoProgressForm progress = new PseudoProgressForm();
                progress.ProgressLabel = "Querying SAP...";
                BackgroundWorker bgWorker        = new BackgroundWorker();
                string           destinationTo   = comboBoxTo.Text;
                string           destinationFrom = textBoxCity.Text;

                bgWorker.DoWork +=
                    delegate(object senderWorker, DoWorkEventArgs eWorker)
                {
                    if (_flightConnection.GetList(
                            airlineID,
                            travelAgency,
                            destinationFrom,
                            destinationTo))
                    {
                        _flConn = _flightConnection._bapiConnectionList;

                        _connectionList = new List <FlightConnectionList>();

                        foreach (BAPISCODAT item
                                 in _flConn)
                        {
                            Invoke(addListItem, item);
                        }
                    }
                };
                bgWorker.RunWorkerCompleted +=
                    delegate(object senderWorker, RunWorkerCompletedEventArgs eWorker)
                {
                    progress.Close();
                    progress.Dispose();

                    if (listViewFlight.Items.Count == 0)
                    {
                        Message.DisplayMessage("No records found.");
                    }
                };

                bgWorker.RunWorkerAsync();
                progress.ShowDialog();
            }
            catch (Exception ex)
            {
                ErrorForm errorForm =
                    new ErrorForm(ex.Message, ex.ToString());
                errorForm.ShowDialog(this);
                errorForm.Close();
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
コード例 #9
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();
        }
コード例 #10
0
        private void buttonPackageType_Click(object sender, RibbonControlEventArgs e)
        {
            PseudoProgressForm progress = new PseudoProgressForm();

            progress.ProgressLabel = "Querying SAP...";
            BackgroundWorker    backgroundWorker           = new BackgroundWorker();
            PackagePerPromoType packageSalesPerTypeDataset =
                new PackagePerPromoType();

            backgroundWorker.DoWork +=
                delegate(object workSender, DoWorkEventArgs eventArg)
            {
                PackagePerPromoType.PackageDataTable packageSalesTable =
                    packageSalesPerTypeDataset.Package;

                Sales sales = DataHelper.GetSalesData();

                foreach (Sales.PackageRow packageRow in sales.Package.Rows)
                {
                    PackagePerPromoType.PackageRow packageSaleRow = packageSalesTable.NewPackageRow();
                    packageSaleRow.PackageID               = packageRow.PackageID;
                    packageSaleRow.PackageName             = packageRow.PackageName;
                    packageSaleRow.GoldPackageCount        = 0;
                    packageSaleRow.SilverPackageCount      = 0;
                    packageSaleRow.BronzePackageCount      = 0;
                    packageSaleRow.GoldPackageTotalSales   = 0;
                    packageSaleRow.SilverPackageTotalSales = 0;
                    packageSaleRow.BronzePackageTotalSales = 0;
                    foreach (DataRow saleRow in packageRow.GetChildRows("Package_PackageSale"))
                    {
                        Sales.PackageSaleRow salesPackageSaleRow = saleRow as Sales.PackageSaleRow;
                        foreach (DataRow eventRow in salesPackageSaleRow.GetChildRows("PackageSale_EventSale"))
                        {
                            Sales.EventSaleRow salesEventSaleRow = eventRow as Sales.EventSaleRow;

                            switch (salesEventSaleRow.PackageType)
                            {
                            case "Gold":
                                packageSaleRow.GoldPackageCount      += 1;
                                packageSaleRow.GoldPackageTotalSales += salesEventSaleRow.Price;
                                break;

                            case "Silver":
                                packageSaleRow.SilverPackageCount      += 1;
                                packageSaleRow.SilverPackageTotalSales += salesEventSaleRow.Price;
                                break;

                            case "Bronze":
                                packageSaleRow.BronzePackageCount      += 1;
                                packageSaleRow.BronzePackageTotalSales += salesEventSaleRow.Price;
                                break;
                            }
                        }
                    }
                    packageSalesTable.AddPackageRow(packageSaleRow);
                }
            };

            backgroundWorker.RunWorkerCompleted +=
                delegate(object workSender, RunWorkerCompletedEventArgs eventArg)
            {
                progress.Close();
                progress.Dispose();

                ExcelHelper.LoadExcelSheet(
                    "PackageSalesPerPromoType",
                    Resources.PackageSalesPerPromoType,
                    packageSalesPerTypeDataset);
            };

            backgroundWorker.RunWorkerAsync();
            progress.ShowDialog();
        }
コード例 #11
0
        private void buttonRevenueForecast_Click(object sender, RibbonControlEventArgs e)
        {
            SelectYearForm selectYearForm = new SelectYearForm();

            selectYearForm.ShowDialog();
            int year = selectYearForm.SelectedYear;

            selectYearForm.Dispose();

            if (year == 0)
            {
                return;
            }

            PseudoProgressForm progress = new PseudoProgressForm();

            progress.ProgressLabel = "Querying SAP...";
            BackgroundWorker backgroundWorker = new BackgroundWorker();
            PackagesRevenue  revenueDataset   = new PackagesRevenue();

            backgroundWorker.DoWork +=
                delegate(object workSender, DoWorkEventArgs eventArg)
            {
                PackagesRevenue.PackageRevenueDataTable revenueTable =
                    revenueDataset.PackageRevenue;

                Dictionary <string, ArrayList> allSales =
                    new Dictionary <string, ArrayList>();

                allSales.Add("Gold", new ArrayList());
                allSales.Add("Silver", new ArrayList());
                allSales.Add("Bronze", new ArrayList());

                allSales["Gold"].Add("Gold");
                allSales["Silver"].Add("Silver");
                allSales["Bronze"].Add("Bronze");

                Sales[] aSales = new Sales[12];
                for (int month = 0; month < aSales.Length; month++)
                {
                    aSales[month] = DataHelper.GetSalesData(month + 1, year);

                    allSales["Gold"].Add(0);
                    allSales["Silver"].Add(0);
                    allSales["Bronze"].Add(0);

                    foreach (Sales.EventSaleRow eventSaleRow in aSales[month].EventSale.Rows)
                    {
                        allSales[eventSaleRow.PackageType][month + 1] =
                            Convert.ToDecimal(allSales[eventSaleRow.PackageType][month + 1]) +
                            (eventSaleRow.Price - eventSaleRow.Cost);
                    }
                }

                allSales["Gold"].Add(year);
                allSales["Silver"].Add(year);
                allSales["Bronze"].Add(year);

                revenueTable.LoadDataRow(allSales["Gold"].ToArray(), true);
                revenueTable.LoadDataRow(allSales["Silver"].ToArray(), true);
                revenueTable.LoadDataRow(allSales["Bronze"].ToArray(), true);
            };

            backgroundWorker.RunWorkerCompleted +=
                delegate(object workSender, RunWorkerCompletedEventArgs eventArg)
            {
                progress.Close();
                progress.Dispose();

                ExcelHelper.LoadExcelSheet(
                    "RevenueForecast",
                    Resources.RevenueForecast,
                    revenueDataset);
            };

            backgroundWorker.RunWorkerAsync();
            progress.ShowDialog();
        }