コード例 #1
0
ファイル: Plans.cs プロジェクト: hprog/exchange
        private void EventProcessing(int colIndex, int rowIndex, BindingSource actualEvents, BindingSource actualActions)
        {
            try
            {
                //запомнить положение скроллбара
                int saveRow = 0;
                if (dgv1.Rows.Count > 0)
                    saveRow = dgv1.FirstDisplayedCell.RowIndex;

                int currEvent = 0;

                //проверка пересечения мероприятий
                string cellTag = Convert.ToString(dgv1[colIndex, rowIndex].Tag);

                if (Int32.TryParse(cellTag, out currEvent))
                {

                    if ((dgv1.collapseEvents.Keys.Contains(currEvent)) && (dgv1[colIndex, rowIndex].Style.BackColor == event_error_bg))
                    {
                        string filter = String.Format("[{0}] IN ({1}, {2})", currEventField, currEvent, dgv1.collapseEvents[currEvent]);
                        CollapseSelect cs = new CollapseSelect(filter, eCategory);

                        if (cs.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            currEvent = cs.ReturnEventID();
                        }
                        else
                            return;
                    }

                    actualEvents.Position = actualEvents.Find(currEventField, currEvent);

                    DataRowView curr = (DataRowView)actualEvents.Current;
                    DateTime ebegin = Convert.ToDateTime(Convert.ToString(curr["BeginTime"]));
                    DateTime eend = Convert.ToDateTime(Convert.ToString(curr["EndTime"]));
                    //if (this.EditCurrentEvent(actualEvents, this.eventlistBindingSource, ebegin, eend))
                    //выбираем кейсом eCategory и создаем IEditable;

                    IEditable editEventForm = null;
                    IEditable editActionForm = null;

                    switch (eCategory)
                    {
                        case eventCategory.CurrentEvent:
                            {
                                editEventForm = new EditEventItem(actualEvents, this.eventlistBindingSource, ebegin, eend);
                                editActionForm = new EditActionItem(actualActions, actualEvents, facility_tracksBindingSource,
            groupsBindingSource, group_headersBindingSource);
                            }
                            break;
                        case eventCategory.CalendarEvent:
                            {
                                editEventForm = new EditCalendarEventItem(actualEvents, this.eventlistBindingSource);
                                editActionForm = new EditCalendarActionItem(actualActions, actualEvents, facility_tracksBindingSource,
            groupsBindingSource, group_headersBindingSource);
                            }
                            break;
                        default:
                            editEventForm = null;
                            editActionForm = null;
                            break;
                    }

                    if (this.GenericEditEvent(editEventForm, actualEvents))
                    {
                        SaveChanges();
                        actualActions.MoveFirst();
                        //если есть записи
                        bool isNew = (actualActions.Current == null) ? true : false;

                //        if (this.EditCurrentAction(this.actionsBindingSource, eventsBindingSource, facility_tracksBindingSource,
                //groupsBindingSource, group_headersBindingSource, isNew))
                            if (this.GenericEditAction(editActionForm, this.actionsBindingSource, group_headersBindingSource, isNew))
                            SaveChanges();

                        PrepareSelected();
                        //восстановить положение скроллбара
                        if (saveRow != 0 && saveRow < dgv1.Rows.Count)
                            dgv1.FirstDisplayedScrollingRowIndex = saveRow;
                    }
                }
                else if (cellTag.Equals("new"))
                {
                    DateTime newEventDate = GetCurrentDate(colIndex, dt1.Value);
                    DateTime begin;
                    DateTime end;
                    string btime = String.Format("{0} {1}", currDate.ToShortDateString(), dgv1.Rows[rowIndex].HeaderCell.Value);
                    begin = Convert.ToDateTime(btime);
                    end = begin.AddMinutes(90);

                    Properties.Settings.Default.lastEditEventBeginTime = begin.ToShortTimeString();
                    Properties.Settings.Default.lastEditEventEndTime = end.ToShortTimeString();

                    //if (this.EditCurrentEvent(actualEvents, this.eventlistBindingSource, newEventDate, new DateTime(), true, false))
                    //выбираем кейсом eCategory и создаем IEditable;

                    IEditable editEventForm = null;
                    IEditable editActionForm = null;

                    switch (eCategory)
                    {
                        case eventCategory.CurrentEvent:
                            {
                                editEventForm = new EditEventItem(actualEvents, this.eventlistBindingSource, newEventDate, new DateTime(), false);
                                editActionForm = new EditActionItem(actualActions, actualEvents, facility_tracksBindingSource,
            groupsBindingSource, group_headersBindingSource);
                            }
                            break;
                        case eventCategory.CalendarEvent:
                            {
                                editEventForm = new EditCalendarEventItem(actualEvents, this.eventlistBindingSource);
                                editActionForm = new EditCalendarActionItem(actualActions, actualEvents, facility_tracksBindingSource,
            groupsBindingSource, group_headersBindingSource);
                            }
                            break;
                        default:
                            editEventForm = null;
                            editActionForm = null;
                            break;
                    }

                    if (this.GenericEditEvent(editEventForm, actualEvents,true))
                    {
                        SaveChanges();
                        actualActions.MoveFirst();

                 //       if (this.EditCurrentAction(this.actionsBindingSource, eventsBindingSource, facility_tracksBindingSource,
                 //groupsBindingSource, group_headersBindingSource, true))
                        if (this.GenericEditAction(editActionForm, actualActions, group_headersBindingSource, true))
                            SaveChanges();

                        PrepareSelected();

                        if (saveRow != 0 && saveRow < dgv1.Rows.Count)
                            dgv1.FirstDisplayedScrollingRowIndex = saveRow;
                    }
                }
            }
            catch (Exception ex) { ulog.Message(ex.Message, UserLogMessageLevel.Error); }
        }
コード例 #2
0
ファイル: Plans.cs プロジェクト: hprog/exchange
        private void DeleteEvent(int colIndex, int rowIndex, BindingSource actualEvents)
        {
            //запомнить положение скроллбара
            int saveRow = 0;
            if (dgv1.Rows.Count > 0)
                saveRow = dgv1.FirstDisplayedCell.RowIndex;

            int currEvent = 0;

            string cellTag = Convert.ToString(dgv1[colIndex, rowIndex].Tag);

            if (Int32.TryParse(cellTag, out currEvent))
            {
                if ((dgv1.collapseEvents.Keys.Contains(currEvent)) && (dgv1[colIndex, rowIndex].Style.BackColor == event_error_bg))
                {
                    string filter = String.Format("[{0}] IN ({1}, {2})", currEventField, currEvent, dgv1.collapseEvents[currEvent]);
                    CollapseSelect cs = new CollapseSelect(filter, eCategory);

                    if (cs.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        currEvent = cs.ReturnEventID();
                    }
                    else
                        return;
                }
            }
            else
            {
                ulog.Message("Не удается определить мероприятие.", UserLogMessageLevel.Error);
                return;
            }

            actualEvents.Position = actualEvents.Find(currEventField , currEvent);

            if (ConfirmDeletion("Мероприятие"))
                try
                {
                    actualEvents.RemoveCurrent();
                    ulog.Message("Запись мероприятия удалена.");
                    SaveChanges();

                    PrepareSelected();
                    //восстановить положение скроллбара
                    if (saveRow != 0 && saveRow < dgv1.Rows.Count)
                        dgv1.FirstDisplayedScrollingRowIndex = saveRow;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
        }