Exemplo n.º 1
0
        private void выборкаНаПроверкуToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var frm = new frmGetDate();

            frm.ShowDialog();
        }
Exemplo n.º 2
0
        private void btnChecked_Click(object sender, EventArgs e)
        {
            if (grid.SelectedRows.Count == 0)
            {
                MessageBox.Show("Выберите запись!", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            Guid id = Guid.Parse(grid.SelectedRows[0].Cells["colId"].Value.ToString());

            using (var context = new Context())
            {
                var item = context.Items.First(x => x.Id == id);

                string s = string.Format(m[item.CheckDate.Month - 1] + " " + DateTime.Now.AddYears(1).Year + " г");

                string mes = string.Format(
                    $"Иструмент проверен, новая дата проверки {s}.\nЕсли вы нажмете \"Да\", эта дата будет применена к записи в БД." +
                    $"\nДля указания даты следующей проверки вручную нажмите \"Нет\"\n\nПрименить дату {s}?");

                DialogResult d = MessageBox.Show(mes, "Предупреждение", MessageBoxButtons.YesNoCancel,
                                                 MessageBoxIcon.Question);
                switch (d)
                {
                case DialogResult.Yes:
                    item.CheckDate = DateTime.Now.AddYears(1);

                    try
                    {
                        var history = new History(History.Action.Checked);
                        context.Histories.Add(history);
                        history.Item = item;
                        context.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message + Environment.NewLine + ex.InnerException + Environment.NewLine +
                                        ex.StackTrace);
                    }
                    RefreshGrid();
                    break;

                case DialogResult.No:
                    var frm = new frmGetDate(true);
                    frm.ShowDialog();
                    item.CheckDate = frm.Date;
                    try
                    {
                        var history = new History(History.Action.Checked);
                        history.Item = item;
                        context.Histories.Add(history);
                        context.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message + Environment.NewLine + ex.InnerException + Environment.NewLine +
                                        ex.StackTrace);
                    }
                    RefreshGrid();
                    break;
                }
            }
        }