private void buttonEdit_Click(object sender, EventArgs e) { DataRowView view = this.BindingContext[adaScheduleDataSet1, "User.FK_Schedule_User.FK_Activity_Schedule"].Current as DataRowView; ADAScheduleDataSet.ActivityRow row = view.Row as ADAScheduleDataSet.ActivityRow; ActivityDetailForm f = new ActivityDetailForm(); f.ScheduleDataSet.Merge(adaScheduleDataSet1); f.ScheduleDataSet.DefaultViewManager.DataViewSettings["Activity"].RowFilter = "ActivityId=" + row.ActivityId; if (f.ShowDialog() == DialogResult.OK) { adaScheduleDataSet1.Merge(f.ScheduleDataSet); } }
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); } }