Beispiel #1
0
        private void dataGridViewEvent_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e)
        {
            if (_sourceEvents.Count == 0)
            {
                return;
            }

            EventList currentEvent =
                _sourceEvents[e.RowIndex];

            switch (dataGridViewEvent.Columns[e.ColumnIndex].Name)
            {
            case "ColumnName":
                e.Value = currentEvent.EventName;
                break;

            case "ColumnDescription":
                e.Value = currentEvent.EventDescription;
                break;

            case "ColumnPoster":
                e.Value = currentEvent.EventPhoto;
                break;

            case "ColumnEdit":
                if (currentEvent.EventEditTag)
                {
                    e.Value = Resources.icoedit_disabled;
                }
                else
                {
                    e.Value = Resources.icoedit;
                }
                break;

            case "ColumnDelete":
                if (currentEvent.EventDeleteTag)
                {
                    e.Value = Resources.icodelete_disabled;
                }
                else
                {
                    e.Value = Resources.icodelete;
                }
                break;
            }
        }
Beispiel #2
0
        private void buttonDelete_Click(object sender, EventArgs e)
        {
            if (_eventCurrentIndex >= 0)
            {
                if (_sourceEvents.Count > 0)
                {
                    EventList deletedEvent =
                        _sourceEvents[_eventCurrentIndex];
                    if (deletedEvent.EventDeleteTag)
                    {
                        return;
                    }

                    SAPPackageEventMapReadWrite eventMapRW =
                        new SAPPackageEventMapReadWrite(Config._dbConnectionName);

                    if (eventMapRW.SelectByEventID(
                            deletedEvent.EventID).PackageEventMap.Rows.Count > 0)
                    {
                        Message.DisplayMessage("Unable to delete. " +
                                               "Event is currently associated with a package.");
                        return;
                    }

                    if (Message.DeleteMessage(
                            deletedEvent.EventName) == DialogResult.Yes)
                    {
                        SAPEventReadWrite eventRW =
                            new SAPEventReadWrite(Config._dbConnectionName);
                        eventRW.Delete(deletedEvent.EventID);
                        _sourceEvents.RemoveAt(_eventCurrentIndex);
                        dataGridViewEvent.RowCount = _sourceEvents.Count;
                    }
                }
            }
        }
        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();
            }
        }
Beispiel #4
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);
            }
        }