예제 #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            EmployeeScheduleDatabaseDataSetTableAdapters.ShiftTableTableAdapter sAdapter =
                new EmployeeScheduleDatabaseDataSetTableAdapters.ShiftTableTableAdapter();

            EmployeeScheduleDatabaseDataSet.ShiftTableDataTable shiftData = sAdapter.GetData();
            if (StartTimePicker.Value > EndTimePicker.Value)
            {
                System.Windows.MessageBox.Show("Start time must be before end time.");
                return;
            }

            if (updateShift != null)
            {
                EmployeeScheduleDatabaseDataSet.ShiftTableRow editRow =
                    shiftData.FindByShiftId(updateShift.ShiftId);


                editRow.ShiftName = ShiftNameTextBox.Text;
                editRow.StartTime = DateTime.Parse(StartTimePicker.Value.ToString()).ToString(@"hh\:mm\:ss tt");
                editRow.EndTime   = DateTime.Parse(EndTimePicker.Value.ToString()).ToString(@"hh\:mm\:ss tt");



                try
                {
                    sAdapter.Update(editRow);

                    Shifts shiftWindow = new Shifts();
                    shiftWindow.Show();
                    this.Close();
                }
                catch
                {
                    System.Windows.MessageBox.Show("whoops");
                }
            }
            else
            {
                EmployeeScheduleDatabaseDataSet.ShiftTableRow newRow =
                    shiftData.NewShiftTableRow();

                newRow.ShiftId   = shiftData.Last().ShiftId + 1;
                newRow.ShiftName = ShiftNameTextBox.Text;
                newRow.StartTime = DateTime.Parse(StartTimePicker.Value.ToString()).ToString(@"hh\:mm\:ss tt");
                newRow.EndTime   = DateTime.Parse(EndTimePicker.Value.ToString()).ToString(@"hh\:mm\:ss tt");


                try
                {
                    sAdapter.Insert(newRow.ShiftId, newRow.ShiftName, newRow.StartTime, newRow.EndTime);

                    Shifts shiftWindow = new Shifts();
                    shiftWindow.Show();
                    this.Close();
                }
                catch
                {
                    System.Windows.MessageBox.Show("whoops");
                }
            }
        }
        private void viewshifts_Click(object sender, RoutedEventArgs e)
        {
            Shifts SP = new Shifts();

            SP.Show();
        }