コード例 #1
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            errorProvider.Clear();
            bool hasNoError = true;

            _packageItem = new PackageList();
            int  packageID = _packageID;
            int  packageEventMapID;
            bool isSuccess = false;

            #region Check Image file
            string fileName  = openFileDialog.FileName;
            byte[] byteImage = null;

            if (File.Exists(fileName))
            {
                byteImage = UtilityHelper.FileToByte(fileName);
            }
            else if (_packageID > 0)
            {
                byteImage = _imageSelected;
            }
            else
            {
                byteImage = UtilityHelper.BitmapToByte(Resources.blank);
            }
            #endregion

            if (textBoxName.Text.Trim().Length == 0)
            {
                errorProvider.SetError(textBoxName, "Package name is required.");
                hasNoError = false;
            }
            if (textBoxDescription.Text.Trim().Length == 0)
            {
                errorProvider.SetError(textBoxDescription, "Package description is required.");
                hasNoError = false;
            }
            if (dataGridViewEvents.RowCount == 0)
            {
                errorProvider.SetError(dataGridViewEvents, "At least one event is required.");
                hasNoError = false;
            }
            if (byteImage == null)
            {
                errorProvider.SetError(pictureBoxPoster, "Poster is required.");
                hasNoError = false;
            }

            if (!hasNoError)
            {
                return;
            }

            using (SWPTransactionDBConnection dbTransaction =
                       new SWPTransactionDBConnection(Config._dbConnectionName))
            {
                try
                {
                    SAPPackageReadWrite packageRW =
                        new SAPPackageReadWrite(dbTransaction);
                    SAPPackageEventMapReadWrite packageEventRW =
                        new SAPPackageEventMapReadWrite(dbTransaction);
                    if (_packageID == 0)
                    {
                        packageRW.Insert(
                            textBoxName.Text,
                            textBoxDescription.Text,
                            byteImage,
                            out packageID);
                        foreach (AssociatedEventList item in _sourceEvent)
                        {
                            packageEventRW.Insert(
                                packageID,
                                item.EventID,
                                out packageEventMapID);
                        }
                    }
                    else
                    {
                        packageRW.Update(
                            _packageID,
                            textBoxName.Text,
                            textBoxDescription.Text,
                            byteImage);

                        foreach (AssociatedEventList item in _removedEvent)
                        {
                            packageEventRW.Delete(item.PackageMapID);
                        }

                        foreach (AssociatedEventList item in _sourceEvent)
                        {
                            if (item.IsNewID)
                            {
                                packageEventRW.Insert(
                                    _packageID,
                                    item.EventID,
                                    out packageEventMapID);
                            }
                        }
                    }
                    dbTransaction.Transaction.Commit();
                    isSuccess = true;
                }
                catch (Exception ex)
                {
                    dbTransaction.Transaction.Rollback();

                    ErrorForm errorForm =
                        new ErrorForm(ex.Message, ex.ToString());
                    errorForm.ShowDialog(this);
                    errorForm.Close();
                }
                finally
                {
                    dbTransaction.Transaction.Dispose();
                }
            }
            if (isSuccess)
            {
                _packageItem.PackageName        = textBoxName.Text;
                _packageItem.PackageDescription = textBoxDescription.Text;
                _packageItem.PackagePhoto       = byteImage;
                _packageItem.PackageID          = packageID;
                DialogResult = DialogResult.OK;
                Close();
            }
        }
        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;
            }
        }
コード例 #3
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            string eventName   = comboBoxEventType.Text.Trim();
            int    eventTypeID = 0;
            int    eventID     = _eventID;
            bool   hasNoError  = true;
            bool   isSuccess   = false;

            errorProvider.Clear();


            #region get price/cost

            DateTime eventSchedule =
                new DateTime(
                    monthCalendarSchedule.SelectionEnd.Year,
                    monthCalendarSchedule.SelectionEnd.Month,
                    monthCalendarSchedule.SelectionEnd.Day,
                    dateTimePickerSchedule.Value.Hour,
                    dateTimePickerSchedule.Value.Minute,
                    dateTimePickerSchedule.Value.Second);

            decimal goldPackageCost =
                Convert.ToDecimal(_packageTypeList[0].PackageCost);
            decimal silverPackageCost =
                Convert.ToDecimal(_packageTypeList[1].PackageCost);
            decimal bronzePackageCost =
                Convert.ToDecimal(_packageTypeList[2].PackageCost);

            decimal totalPackageCost =
                goldPackageCost + silverPackageCost + bronzePackageCost;
            #endregion

            _eventList = new EventList();

            #region check image file
            string fileName  = openFileDialog.FileName;
            byte[] byteImage = null;

            if (File.Exists(fileName))
            {
                FileInfo imageFile = new FileInfo(fileName);

                using (FileStream fs = new FileStream(
                           fileName,
                           FileMode.Open,
                           FileAccess.Read,
                           FileShare.Read))
                {
                    int fileSize = Convert.ToInt32(imageFile.Length);
                    byteImage = new byte[fileSize];
                    int bytesRead = fs.Read(
                        byteImage,
                        0,
                        fileSize);
                    fs.Close();
                }
            }
            else if (_eventID > 0)
            {
                byteImage = _previousImage;
            }
            else
            {
                byteImage = UtilityHelper.BitmapToByte(Resources.blank);
            }

            #endregion

            if (byteImage == null)
            {
                errorProvider.SetError(pictureBoxPoster, "Poster is required.");
                hasNoError = false;
            }

            if (eventName.Length == 0)
            {
                errorProvider.SetError(comboBoxEventType, "Event Type is required.");
                hasNoError = false;
            }

            if (textBoxName.Text.Trim().Length == 0)
            {
                errorProvider.SetError(textBoxName, "Event name is required.");
                hasNoError = false;
            }

            if (textBoxDescription.Text.Trim().Length == 0)
            {
                errorProvider.SetError(textBoxDescription, "Event description is required.");
                hasNoError = false;
            }

            if (!hasNoError)
            {
                return;
            }

            try
            {
                SAPEventTypeReadWrite eventType =
                    new SAPEventTypeReadWrite(Config._dbConnectionName);
                SAPDataSetEventType.EventTypeDataTable dtEventType
                    = eventType.SelectByEventTypeName(eventName).EventType;
                if (dtEventType.Rows.Count > 0)
                {
                    eventTypeID =
                        ((SAPDataSetEventType.EventTypeRow)dtEventType.Rows[0]).EventTypeID;
                }

                if (eventTypeID == 0)
                {
                    eventType.Insert(
                        eventName,
                        eventName,
                        out eventTypeID);
                }

                using (SWPTransactionDBConnection dbTransaction =
                           new SWPTransactionDBConnection(Config._dbConnectionName))
                {
                    try
                    {
                        SAPEventReadWrite mEvent =
                            new SAPEventReadWrite(dbTransaction);
                        SAPEventActorReadWrite eventActor =
                            new SAPEventActorReadWrite(dbTransaction);
                        SAPEventActorMapReadWrite eventActorMap =
                            new SAPEventActorMapReadWrite(dbTransaction);
                        if (_eventID == 0)
                        {
                            mEvent.Insert(
                                Convert.ToInt32(comboBoxVenue.SelectedValue),
                                eventTypeID,
                                textBoxName.Text,
                                textBoxDescription.Text,
                                byteImage,
                                eventSchedule,
                                _packageTypeList[0].PackagePrice,
                                _packageTypeList[1].PackagePrice,
                                _packageTypeList[2].PackagePrice,
                                goldPackageCost,
                                silverPackageCost,
                                bronzePackageCost,
                                totalPackageCost,
                                out eventID);
                        }
                        else
                        {
                            mEvent.Update(
                                _eventID,
                                Convert.ToInt32(comboBoxVenue.SelectedValue),
                                eventTypeID,
                                textBoxName.Text,
                                textBoxDescription.Text,
                                byteImage,
                                eventSchedule,
                                _packageTypeList[0].PackagePrice,
                                _packageTypeList[1].PackagePrice,
                                _packageTypeList[2].PackagePrice,
                                goldPackageCost,
                                silverPackageCost,
                                bronzePackageCost,
                                totalPackageCost);
                        }
                        if (dsEventActor.Tables[0].Rows.Count == 0)
                        {
                            eventActorMap.DeleteByEventID(eventID);
                        }

                        DataTable dtAdded         = dsEventActor.Tables[0].GetChanges(DataRowState.Added);
                        DataTable dtDeleted       = dsEventActor.Tables[0].GetChanges(DataRowState.Deleted);
                        int       eventActorMapID = 0;
                        if (dtAdded != null)
                        {
                            foreach (DataRow dr in dtAdded.Rows)
                            {
                                int eventActorID = Convert.ToInt32(dr[1]);
                                if (eventActorID == 0)
                                {
                                    eventActor.Insert(
                                        (string)dr[0],
                                        out eventActorID);
                                }
                                eventActorMap.Insert(
                                    eventID,
                                    eventActorID,
                                    out eventActorMapID);
                            }
                        }
                        if (dtDeleted != null)
                        {
                            foreach (DataRow dr in dtDeleted.Rows)
                            {
                                int eventActorID = (int)dr[1];
                                if (eventActorID != 0)
                                {
                                    eventActorMap.DeleteByEventActorID(eventActorID);
                                }
                            }
                        }
                        dbTransaction.Transaction.Commit();
                        isSuccess = true;
                    }
                    catch (Exception ex)
                    {
                        dbTransaction.Transaction.Rollback();

                        ErrorForm errorForm =
                            new ErrorForm(ex.Message, ex.ToString());
                        errorForm.ShowDialog(this);
                        errorForm.Close();
                    }
                    finally
                    {
                        dbTransaction.Transaction.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorForm errorForm =
                    new ErrorForm(ex.Message, ex.ToString());
                errorForm.ShowDialog(this);
                errorForm.Close();
            }
            if (isSuccess)
            {
                _eventList.EventName        = textBoxName.Text;
                _eventList.EventDescription = textBoxDescription.Text;
                _eventList.EventPhoto       = byteImage;
                _eventList.EventID          = eventID;
                DialogResult = DialogResult.OK;
                Close();
            }
        }