示例#1
0
文件: MainForm.cs 项目: nakijun/adasg
        private void copyToAntherUserToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Data.DataRowView userRowView = this.BindingContext[adaScheduleDataSet1, "User"].Current as System.Data.DataRowView;
            if (userRowView != null)
            {
                ADAScheduleDataSet.UserRow currentUserRow = userRowView.Row as ADAScheduleDataSet.UserRow;
                SelectUserForm             f = new SelectUserForm();

                f.ScheduleDataSet.Merge(adaScheduleDataSet1);
                DataRow[] rows = f.ScheduleDataSet.User.Select("UserId=" + currentUserRow.UserId);
                if (rows.Length > 0)
                {
                    rows[0].Delete();
                }

                if (f.ShowDialog(this) == DialogResult.OK)
                {
                    DataRow[] scheduleRows = adaScheduleDataSet1.Schedule.Select("UserId=" + f.SelectedUser.UserId);
                    ADAScheduleDataSet.ScheduleRow currentScheduleRow = null;
                    foreach (ADAScheduleDataSet.ScheduleRow scheduleRow in scheduleRows)
                    {
                        if (scheduleRow.Type == (int)ScheduleType.Normal)
                        {
                            currentScheduleRow = scheduleRow;
                            break;
                        }
                    }

                    if (currentScheduleRow == null)
                    {
                        currentScheduleRow          = adaScheduleDataSet1.Schedule.NewScheduleRow();
                        currentScheduleRow.UserId   = f.SelectedUser.UserId;
                        currentScheduleRow.Type     = (int)ScheduleType.Normal;
                        currentScheduleRow.Date     = monthCalendar1.SelectionStart;
                        currentScheduleRow.IsActive = true;
                        adaScheduleDataSet1.Schedule.AddScheduleRow(currentScheduleRow);
                    }
                    else
                    {
                        foreach (ADAScheduleDataSet.ActivityRow activityRow in currentScheduleRow.GetActivityRowsByFK_Activity_Schedule())
                        {
                            ADAScheduleDataSet.Activity_ReminderRow[] remiderRows = activityRow.GetActivity_ReminderRows();
                            foreach (ADAScheduleDataSet.Activity_ReminderRow reminderRow in remiderRows)
                            {
                                reminderRow.Delete();
                            }

                            activityRow.Delete();
                        }
                    }

                    int count = this.BindingContext[adaScheduleDataSet1, "User.FK_Schedule_User.FK_Activity_Schedule"].Count;
                    for (int i = 0; i < count; i++)
                    {
                        this.BindingContext[adaScheduleDataSet1, "User.FK_Schedule_User.FK_Activity_Schedule"].Position = i;

                        DataRowView activityRowView = this.BindingContext[adaScheduleDataSet1, "User.FK_Schedule_User.FK_Activity_Schedule"].Current as DataRowView;
                        ADAScheduleDataSet.ActivityRow currentActivityRow = activityRowView.Row as ADAScheduleDataSet.ActivityRow;

                        ADAScheduleDataSet.ActivityRow newActivityRow = adaScheduleDataSet1.Activity.NewActivityRow();
                        newActivityRow.ScheduleId = currentScheduleRow.ScheduleId;
                        newActivityRow.Sequence   = currentActivityRow.Sequence;
                        newActivityRow.StartTime  = currentActivityRow.StartTime;
                        newActivityRow.EndTime    = currentActivityRow.EndTime;
                        newActivityRow.Name       = currentActivityRow.Name;
                        newActivityRow.SymbolId   = currentActivityRow.SymbolId;
                        newActivityRow.Image      = currentActivityRow.Image;

                        adaScheduleDataSet1.Activity.AddActivityRow(newActivityRow);

                        ADAScheduleDataSet.Activity_ReminderRow[] remiderRows = currentActivityRow.GetActivity_ReminderRows();
                        foreach (ADAScheduleDataSet.Activity_ReminderRow reminderRow in remiderRows)
                        {
                            ADAScheduleDataSet.Activity_ReminderRow activityReminderRow = adaScheduleDataSet1.Activity_Reminder.NewActivity_ReminderRow();
                            activityReminderRow.ActivityId = newActivityRow.ActivityId;
                            activityReminderRow.ReminderId = ADADataAccess.Constants.ALARM_REMINDER_ID;
                            activityReminderRow.Time       = reminderRow.Time;
                            adaScheduleDataSet1.Activity_Reminder.AddActivity_ReminderRow(activityReminderRow);
                        }
                    }

                    count = this.BindingContext[adaScheduleDataSet1, "User"].Count;
                    for (int i = 0; i < count; i++)
                    {
                        this.BindingContext[adaScheduleDataSet1, "User"].Position = i;
                        userRowView    = this.BindingContext[adaScheduleDataSet1, "User"].Current as System.Data.DataRowView;
                        currentUserRow = userRowView.Row as ADAScheduleDataSet.UserRow;
                        if (currentUserRow.UserId == f.SelectedUser.UserId)
                        {
                            break;
                        }
                    }
                }
            }
        }
示例#2
0
文件: MainForm.cs 项目: nakijun/adasg
        private void buttonAddActivity_Click(object sender, EventArgs e)
        {
            ActivityDetailForm f = new ActivityDetailForm();

            f.ScheduleDataSet.Merge(adaScheduleDataSet1);

            DataRowView view = this.BindingContext[adaScheduleDataSet1, "User"].Current as DataRowView;

            ADAScheduleDataSet.UserRow userRow = view.Row as ADAScheduleDataSet.UserRow;

            DataRow[] scheduleRows = f.ScheduleDataSet.Schedule.Select("UserId=" + userRow.UserId);
            ADAScheduleDataSet.ScheduleRow currentScheduleRow = null;
            foreach (ADAScheduleDataSet.ScheduleRow scheduleRow in scheduleRows)
            {
                if (scheduleRow.Type == (int)ScheduleType.Normal)
                {
                    currentScheduleRow = scheduleRow;
                    break;
                }
            }

            if (currentScheduleRow == null)
            {
                currentScheduleRow          = f.ScheduleDataSet.Schedule.NewScheduleRow();
                currentScheduleRow.UserId   = userRow.UserId;
                currentScheduleRow.Type     = (int)ScheduleType.Normal;
                currentScheduleRow.Date     = monthCalendar1.SelectionStart;
                currentScheduleRow.IsActive = true;
                f.ScheduleDataSet.Schedule.AddScheduleRow(currentScheduleRow);
            }

            int      sequenceMax  = 0;
            DateTime startTimeMax = currentScheduleRow.Date;
            DateTime endTimeMax   = currentScheduleRow.Date;

            ADAScheduleDataSet.ActivityRow lastActivityRow = null;

            foreach (ADAScheduleDataSet.ActivityRow activityRow in
                     currentScheduleRow.GetActivityRowsByFK_Activity_Schedule())
            {
                if (sequenceMax < activityRow.Sequence)
                {
                    sequenceMax     = activityRow.Sequence;
                    lastActivityRow = activityRow;

                    if (!activityRow.IsStartTimeNull() && startTimeMax.CompareTo(activityRow.StartTime) < 0)
                    {
                        startTimeMax = activityRow.StartTime;
                    }

                    if (!activityRow.IsEndTimeNull() && endTimeMax.CompareTo(activityRow.EndTime) < 0)
                    {
                        endTimeMax = activityRow.EndTime;
                    }
                }
            }

            ADAScheduleDataSet.ActivityRow currentActivityRow = f.ScheduleDataSet.Activity.NewActivityRow();
            currentActivityRow.ScheduleId = currentScheduleRow.ScheduleId;
            currentActivityRow.Sequence   = sequenceMax + 1;
            currentActivityRow.StartTime  = endTimeMax;
            currentActivityRow.EndTime    = endTimeMax + endTimeMax.Subtract(startTimeMax);

            if (currentActivityRow.EndTime == currentActivityRow.StartTime)
            {
                currentActivityRow.EndTime = currentActivityRow.StartTime.Add(new TimeSpan(1, 0, 0));
            }

            currentActivityRow.Name = string.Format("Step {0}", currentActivityRow.Sequence);

            if (lastActivityRow != null)
            {
                currentActivityRow.SymbolId = lastActivityRow.SymbolId;
                currentActivityRow.Image    = lastActivityRow.Image;
            }

            f.ScheduleDataSet.Activity.AddActivityRow(currentActivityRow);

            ADAScheduleDataSet.Activity_ReminderRow activityReminderRow = f.ScheduleDataSet.Activity_Reminder.NewActivity_ReminderRow();
            activityReminderRow.ActivityId = currentActivityRow.ActivityId;
            activityReminderRow.ReminderId = ADADataAccess.Constants.ALARM_REMINDER_ID;
            activityReminderRow.Time       = currentActivityRow.EndTime.Subtract(new TimeSpan(0, 15, 0));
            f.ScheduleDataSet.Activity_Reminder.AddActivity_ReminderRow(activityReminderRow);

            f.ScheduleDataSet.DefaultViewManager.DataViewSettings["Activity"].RowFilter = "ActivityId=" + currentActivityRow.ActivityId;

            if (f.ShowDialog() == DialogResult.OK)
            {
                adaScheduleDataSet1.Merge(f.ScheduleDataSet);
            }
        }