Пример #1
0
        private void cleanToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SelectDateForm selectDateForm = new SelectDateForm();

            selectDateForm.SelectionRange.Start = monthCalendar1.SelectionStart.AddDays(-1);
            selectDateForm.SelectionRange.End   = selectDateForm.SelectionRange.Start;

            if (selectDateForm.ShowDialog(this) == DialogResult.OK)
            {
                Cursor.Current = Cursors.WaitCursor;

                try
                {
                    ScheduleTableAdapter scheduleAdapter = new ScheduleTableAdapter();
                    scheduleAdapter.Connection.Open();

                    SqlCommand cmd = scheduleAdapter.Connection.CreateCommand();
                    cmd.CommandText = "update [Schedule] set [IsActive]='false' where [Date] < @Date";
                    cmd.Parameters.Add("@Date", SqlDbType.DateTime);
                    cmd.Parameters[0].Value = DateTime.Now.Date;
                    cmd.ExecuteNonQuery();

                    scheduleAdapter.Connection.Close();
                }
                catch (Exception ex)
                {
                    ReportError(ex);
                }

                Cursor.Current = Cursors.Default;

                LoadDataSet();
            }
        }
Пример #2
0
        private void copyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SelectDateForm selectDateForm = new SelectDateForm();

            if (selectDateForm.ShowDialog(this) == DialogResult.OK)
            {
                for (DateTime copyToDate = selectDateForm.SelectionRange.Start;
                     copyToDate.CompareTo(selectDateForm.SelectionRange.End) <= 0;
                     copyToDate = copyToDate.AddDays(1))
                {
                    Cursor.Current = Cursors.WaitCursor;
                    ADAScheduleDataSet dataSet = new ADAScheduleDataSet();

                    try
                    {
                        LoadDataSet(dataSet, copyToDate, false);

                        DataRow[] scheduleRows = dataSet.Schedule.Select("Type <= " + 1);

                        foreach (ADAScheduleDataSet.ScheduleRow scheduleRow in scheduleRows)
                        {
                            scheduleRow.Delete();
                        }

                        ScheduleTableAdapter scheduleAdapter = new ScheduleTableAdapter();
                        ActivityTableAdapter activityAdapter = new ActivityTableAdapter();

                        activityAdapter.Update(dataSet);
                        scheduleAdapter.Update(dataSet);

                        scheduleRows = adaScheduleDataSet1.Schedule.Select("Type <= " + 1);

                        foreach (ADAScheduleDataSet.ScheduleRow scheduleRow in scheduleRows)
                        {
                            ADAScheduleDataSet.ScheduleRow newScheduleRow;
                            newScheduleRow          = dataSet.Schedule.NewScheduleRow();
                            newScheduleRow.Date     = copyToDate;
                            newScheduleRow.UserId   = scheduleRow.UserId;
                            newScheduleRow.Type     = scheduleRow.Type;
                            newScheduleRow.IsActive = true;
                            dataSet.Schedule.AddScheduleRow(newScheduleRow);

                            scheduleAdapter.Update(dataSet);

                            foreach (ADAScheduleDataSet.ActivityRow activityRow in scheduleRow.GetActivityRowsByFK_Activity_Schedule())
                            {
                                ADAScheduleDataSet.ActivityRow newActivityRow;

                                newActivityRow            = dataSet.Activity.NewActivityRow();
                                newActivityRow.ScheduleId = newScheduleRow.ScheduleId;

                                if (!activityRow.IsStartTimeNull())
                                {
                                    TimeSpan timeSpan = copyToDate.Subtract(activityRow.StartTime.Date);
                                    newActivityRow.StartTime = activityRow.StartTime.AddDays(timeSpan.Days);
                                }

                                if (!activityRow.IsEndTimeNull())
                                {
                                    TimeSpan timeSpan = copyToDate.Subtract(activityRow.EndTime.Date);
                                    newActivityRow.EndTime = activityRow.EndTime.AddDays(timeSpan.Days);
                                }

                                if (!activityRow.IsSymbolIdNull())
                                {
                                    newActivityRow.SymbolId = activityRow.SymbolId;
                                }

                                if (!activityRow.IsNameNull())
                                {
                                    newActivityRow.Name = activityRow.Name;
                                }

                                if (!activityRow.IsSequenceNull())
                                {
                                    newActivityRow.Sequence = activityRow.Sequence;
                                }

                                dataSet.Activity.AddActivityRow(newActivityRow);
                                activityAdapter.Update(dataSet);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ReportError(ex);
                    }
                }

                Cursor.Current = Cursors.Default;

                monthCalendar1.SetDate(selectDateForm.SelectionRange.Start);
                LoadDataSet();
            }
        }