Exemplo n.º 1
0
        private void _exportButton_Click(object sender, EventArgs e)
        {
            try
            {
                List <Schedule> schedules = new List <Schedule>();

                DialogResult result = MessageBox.Show(this,
                                                      "Hit 'Yes' to export all schedules or 'No' to only" + Environment.NewLine + "export the selected schedule(s).",
                                                      "Export", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    foreach (DataGridViewRow row in _schedulesDataGridView.Rows)
                    {
                        ScheduleSummary scheduleSummary = row.DataBoundItem as ScheduleSummary;
                        schedules.Add(Proxies.SchedulerService.GetScheduleById(scheduleSummary.ScheduleId).Result);
                    }
                }
                else if (result == DialogResult.No)
                {
                    foreach (DataGridViewRow selectedRow in _schedulesDataGridView.SelectedRows)
                    {
                        ScheduleSummary scheduleSummary = selectedRow.DataBoundItem as ScheduleSummary;
                        schedules.Add(Proxies.SchedulerService.GetScheduleById(scheduleSummary.ScheduleId).Result);
                    }
                }
                if (schedules.Count > 0)
                {
                    ExportScheduleList exportList = new ExportScheduleList(schedules);

                    _saveFileDialog.FileName = _scheduleType.ToString() + "Schedules_" + DateTime.Today.ToString("yyyyMMdd") + "_" + DateTime.Now.ToString("HHmmss") + ".xml";
                    if (_saveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        exportList.Serialize(_saveFileDialog.FileName);

                        MessageBox.Show(this, String.Format("{0} schedule(s) exported.", schedules.Count), "Export",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, null, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
0
        private void _importButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (_openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    List <ImportSchedule> schedules;

                    bool retry = false;
                    do
                    {
                        ExportScheduleList scheduleList = ExportScheduleList.Deserialize(_openFileDialog.FileName);

                        List <string> errors;
                        schedules = scheduleList.Convert(out errors);

                        if (errors.Count > 0)
                        {
                            StringBuilder errorMessage = new StringBuilder("The following errors occurred:");
                            errorMessage.AppendLine();
                            errorMessage.AppendLine();
                            foreach (string error in errors)
                            {
                                errorMessage.Append(" - ").Append(error).AppendLine();
                            }

                            DialogResult result = MessageBox.Show(this, errorMessage.ToString(), "Import",
                                                                  MessageBoxButtons.RetryCancel, MessageBoxIcon.Question);
                            retry = (result == DialogResult.Retry);
                            if (result != DialogResult.Ignore)
                            {
                                schedules.Clear();
                            }
                        }
                    }while (retry);

                    if (schedules.Count > 0)
                    {
                        bool importHistory = !ImportSchedulesHaveHistory(schedules) ||
                                             (DialogResult.Yes == MessageBox.Show(this, "Do you also want to import the previously recorded"
                                                                                  + Environment.NewLine + "history of the schedules.",
                                                                                  "Import", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2));

                        foreach (ImportSchedule schedule in schedules)
                        {
                            Schedule importedSchedule = Proxies.SchedulerService.SaveSchedule(schedule.Schedule).Result;
                            if (importHistory &&
                                schedule.History.Length > 0)
                            {
                                Proxies.ControlService.ImportPreviouslyRecordedHistory(importedSchedule.ScheduleId, schedule.History).Wait();
                            }
                        }
                        LoadAllSchedules(false);
                        MessageBox.Show(this, String.Format("{0} schedule(s) imported.", schedules.Count), "Import",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, null, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 3
0
        private void _exportButton_Click(object sender, EventArgs e)
        {
            try
            {
                List<Schedule> schedules = new List<Schedule>();

                DialogResult result = MessageBox.Show(this,
                    "Hit 'Yes' to export all schedules or 'No' to only" + Environment.NewLine + "export the selected schedule(s).",
                    "Export", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    foreach (DataGridViewRow row in _schedulesDataGridView.Rows)
                    {
                        ScheduleSummary scheduleSummary = row.DataBoundItem as ScheduleSummary;
                        schedules.Add(Proxies.SchedulerService.GetScheduleById(scheduleSummary.ScheduleId).Result);
                    }
                }
                else if (result == DialogResult.No)
                {
                    foreach (DataGridViewRow selectedRow in _schedulesDataGridView.SelectedRows)
                    {
                        ScheduleSummary scheduleSummary = selectedRow.DataBoundItem as ScheduleSummary;
                        schedules.Add(Proxies.SchedulerService.GetScheduleById(scheduleSummary.ScheduleId).Result);
                    }
                }
                if (schedules.Count > 0)
                {
                    ExportScheduleList exportList = new ExportScheduleList(schedules);

                    _saveFileDialog.FileName = _scheduleType.ToString() + "Schedules_" + DateTime.Today.ToString("yyyyMMdd") + "_" + DateTime.Now.ToString("HHmmss") + ".xml";
                    if (_saveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        exportList.Serialize(_saveFileDialog.FileName);

                        MessageBox.Show(this, String.Format("{0} schedule(s) exported.", schedules.Count), "Export",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, null, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }