Beispiel #1
0
        public void OpenEditReports()
        {
            var window = new EditReportWindow();

            window.DataContext = new EditReportViewModel(_user);
            window.Show();
        }
        private async void ButtonAddReport_OnClick(object sender, RoutedEventArgs e)
        {
            var select = (ReportsLVModel)ListViewReports.SelectedItem;

            if (select == null)
            {
                return;
            }
            if (select.ReportId != -1)
            {
                return;
            }
            using (var context = new PlanReportEntities())
            {
                var newReport = new Report
                {
                    PlanId = select.Id,
                };
                EditReportWindow window = new EditReportWindow
                {
                    Report   = newReport,
                    PlanText = select.PlanText,
                    Title    = "Добавление нового отчета",
                };
                window.ShowDialog();
                if (window.DialogResult.HasValue && window.DialogResult.Value)
                {
                    try
                    {
                        context.Reports.Add(newReport);
                        await context.SaveChangesAsync();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Ошибка!\n" + ex.InnerException?.Message);
                    }
                }
            }
            await ViewDataListViewReportsAsync();
        }