示例#1
0
        private void ButtonPeriodClose_Click(object sender, RoutedEventArgs e)
        {
            MessageDialog Msg = null;

            DomainClasses.BillPeriodsTb MyBillPeriod = null;
            MyBillPeriod = Commons.Db.BillPeriods.Find(BillPeriodId);
            if (MyBillPeriod != null)
            {
                try
                {
                    if (MyBillPeriod.IsSelected)
                    {
                        if (MyBillPeriod.IsClosed == false)
                        {
                            Msg       = new MessageDialog(Messages.CloseMessageTitleBillPeriods, Messages.PeriodsIsClosed, MessageDialogButtons.YesNo, MessageDialogType.Warning, GridHeader.Background);
                            Msg.Owner = Window.GetWindow(this);
                            if (Msg.ShowDialog() == true)
                            {
                                MyBillPeriod.IsClosed = true;
                                Commons.Db.SaveChanges();
                                Commons.SetFromEdited("BillPeriods");
                                DataGridView.ItemsSource = Commons.Db.BillPeriods.Select(x => x).Where(x => x.Year == Commons.CurrentYear).OrderBy(x => x.DateFrom).ToList();
                                DataGridView.Items.Refresh();
                                Msg       = new MessageDialog(Messages.CloseMessageTitleBillPeriods, Messages.ClosedMessageSuccessed, MessageDialogButtons.Ok, MessageDialogType.Information, GridHeader.Background);
                                Msg.Owner = Window.GetWindow(this);
                                Msg.ShowDialog();
                            }
                        }
                        else
                        {
                            Msg       = new MessageDialog(Messages.CloseMessageTitleBillPeriods, Messages.PeriodClosed, MessageDialogButtons.Ok, MessageDialogType.Information, GridHeader.Background);
                            Msg.Owner = Window.GetWindow(this);
                            Msg.ShowDialog();
                        }
                    }
                    else
                    {
                        Msg       = new MessageDialog(Messages.CloseMessageTitleBillPeriods, Messages.ImpossibleClosedMessage, MessageDialogButtons.Ok, MessageDialogType.Information, GridHeader.Background);
                        Msg.Owner = Window.GetWindow(this);
                        Msg.ShowDialog();
                    }
                }
                catch
                {
                    Msg       = new MessageDialog(Messages.CloseMessageTitleBillPeriods, Messages.ErrorSendingDataToDatabase, MessageDialogButtons.Ok, MessageDialogType.Error, GridHeader.Background);
                    Msg.Owner = Window.GetWindow(this);
                    Msg.ShowDialog();
                }
            }
            else
            {
            }
        }
示例#2
0
        private void ButtonSave_Click(object sender, RoutedEventArgs e)
        {
            ControlsValidate?Vd  = Commons.ValidateData(FirstControl, ControlsArray);
            MessageDialog    Msg = null;

            if (Vd != null)
            {
                Msg       = new MessageDialog(Messages.SaveMessageTitleBillPeriods, Vd.Value.Message, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                Msg.Owner = Window.GetWindow(this);
                Msg.ShowDialog();
                Vd.Value.Control.Focus();
            }
            else
            {
                int      Len        = Convert.ToInt32(TextBoxCountOfMonth.Text);
                int      Start      = 0;
                string[] DateFromTo = null;

                DomainClasses.BillPeriodsTb MyBillPeriod = null;
                MyBillPeriod = Commons.Db.BillPeriods.Find(BillPeriodId);
                if (MyBillPeriod == null)
                {
                    Start = IsPeriodOk(Len);
                    if (Start == -1)
                    {
                        Msg       = new MessageDialog(Messages.SaveMessageTitleBillPeriods, Messages.PeriodNotInRange, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                        Msg.Owner = Window.GetWindow(this);
                        Msg.ShowDialog();
                        TextBoxCountOfMonth.Focus();
                        TextBoxCountOfMonth.SelectAll();
                        return;
                    }
                    DateFromTo = GetDateFromAndDateTo(Start, Len);

                    if (RadioYes.IsChecked == true)
                    {
                        if (!IsPeriodSelecetedOK(-1, DateFromTo[0]))
                        {
                            Msg       = new MessageDialog(Messages.SaveMessageTitleBillPeriods, Messages.IsNotPossibeToSelect, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                            Msg.Owner = Window.GetWindow(this);
                            Msg.ShowDialog();
                            RadioYes.Focus();
                            return;
                        }
                    }
                    Msg       = new MessageDialog(Messages.SaveMessageTitleBillPeriods, Messages.SaveMessageBillPeriods, MessageDialogButtons.YesNo, MessageDialogType.Warning, GridHeader.Background);
                    Msg.Owner = Window.GetWindow(this);
                    if (Msg.ShowDialog() == true)
                    {
                        try
                        {
                            if (RadioYes.IsChecked == true)
                            {
                                var Bls = Commons.Db.BillPeriods.Select(x => x).Where(x => x.IsSelected == true && x.Year == Commons.CurrentYear);
                                foreach (BillPeriodsTb value in Bls)
                                {
                                    value.IsSelected = false;
                                }
                            }
                            Commons.Db.BillPeriods.Add(new DomainClasses.BillPeriodsTb
                            {
                                Year        = Commons.CurrentYear,
                                IsSelected  = Convert.ToBoolean(RadioYes.IsChecked),
                                IsClosed    = false,
                                Name        = TextBoxPeriodName.Text.Trim(),
                                DateFrom    = DateFromTo[0].Trim(),
                                DateTo      = DateFromTo[1].Trim(),
                                MonthPeriod = Len,
                                Description = TextBoxComments.Text.Trim()
                            });
                            Commons.Db.SaveChanges();
                            Commons.SetFromEdited("BillPeriods");
                            DataGridView.ItemsSource = Commons.Db.BillPeriods.Select(x => x).Where(x => x.Year == Commons.CurrentYear).OrderBy(x => x.DateFrom).ToList();
                            DataGridView.Items.Refresh();
                            Msg       = new MessageDialog(Messages.SaveMessageBillPeriods, Messages.SaveMessageSuccessBillPeriods, MessageDialogButtons.Ok, MessageDialogType.Information, GridHeader.Background);
                            Msg.Owner = Window.GetWindow(this);
                            Msg.ShowDialog();
                            ButtonNew_Click(null, null);
                        }
                        catch
                        {
                            Msg       = new MessageDialog(Messages.SaveMessageTitleBillPeriods, Messages.ErrorSendingDataToDatabase, MessageDialogButtons.Ok, MessageDialogType.Error, GridHeader.Background);
                            Msg.Owner = Window.GetWindow(this);
                            Msg.ShowDialog();
                        }
                    }
                }
                else
                {
                    DateFromTo    = new string[2];
                    DateFromTo[0] = MyBillPeriod.DateFrom;
                    DateFromTo[1] = MyBillPeriod.DateTo;
                    if (RadioYes.IsChecked == true)
                    {
                        if (!IsPeriodSelecetedOK(MyBillPeriod.Id, DateFromTo[0]))
                        {
                            Msg       = new MessageDialog(Messages.SaveMessageTitleBillPeriods, Messages.IsNotPossibeToSelect, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                            Msg.Owner = Window.GetWindow(this);
                            Msg.ShowDialog();
                            RadioYes.Focus();
                            return;
                        }
                    }
                    Msg       = new MessageDialog(Messages.EditMessageTitleBillPeriods, Messages.EditMessageBillPeriods, MessageDialogButtons.YesNo, MessageDialogType.Warning, GridHeader.Background);
                    Msg.Owner = Window.GetWindow(this);
                    if (Msg.ShowDialog() == true)
                    {
                        try
                        {
                            if (MyBillPeriod.IsClosed != true)
                            {
                                MyBillPeriod.Description = TextBoxComments.Text.Trim();
                                MyBillPeriod.Name        = TextBoxPeriodName.Text.Trim();
                            }
                            if (RadioYes.IsChecked == true)
                            {
                                var Bls = Commons.Db.BillPeriods.Select(x => x).Where(x => x.IsSelected == true && x.Year == Commons.CurrentYear);
                                foreach (BillPeriodsTb value in Bls)
                                {
                                    value.IsSelected = false;
                                }
                            }
                            MyBillPeriod.IsSelected = Convert.ToBoolean(RadioYes.IsChecked);
                            Commons.Db.SaveChanges();
                            Commons.SetFromEdited("BillPeriods");
                            DataGridView.ItemsSource = Commons.Db.BillPeriods.Select(x => x).Where(x => x.Year == Commons.CurrentYear).OrderBy(x => x.DateFrom).ToList();
                            DataGridView.Items.Refresh();
                            Msg       = new MessageDialog(Messages.EditMessageTitleBillPeriods, Messages.EditMessageSuccessBillPeriods, MessageDialogButtons.Ok, MessageDialogType.Information, GridHeader.Background);
                            Msg.Owner = Window.GetWindow(this);
                            Msg.ShowDialog();
                            ButtonNew_Click(null, null);
                        }
                        catch
                        {
                            Msg       = new MessageDialog(Messages.EditMessageTitleBillPeriods, Messages.ErrorSendingDataToDatabase, MessageDialogButtons.Ok, MessageDialogType.Error, GridHeader.Background);
                            Msg.Owner = Window.GetWindow(this);
                            Msg.ShowDialog();
                        }
                    }
                }
            }
        }