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

            try
            {
                ContentPresenter fe        = (ContentPresenter)DataGridView.Columns[7].GetCellContent(DataGridView.SelectedItem);
                StackPanel       S         = (StackPanel)fe.ContentTemplate.FindName("StackEditDelete", fe);
                string           id        = ((TextBlock)S.FindName("Id")).Text;
                BillPeriodsTb    RowEdited = Commons.Db.BillPeriods.Find(Convert.ToInt32(id));
                if (RowEdited != null)
                {
                    TextBoxPeriodName.IsEnabled   = true;
                    TextBoxComments.IsEnabled     = true;
                    TextBoxCountOfMonth.IsEnabled = true;

                    BillPeriodId = Convert.ToInt32(id);
                    if (RowEdited.IsSelected)
                    {
                        RadioYes.IsChecked = true;
                    }
                    else
                    {
                        RadioNo.IsChecked = true;
                    }
                    TextBoxPeriodName.Text        = RowEdited.Name.Trim();
                    TextBoxCountOfMonth.Text      = RowEdited.MonthPeriod.ToString();
                    TextBoxCountOfMonth.IsEnabled = false;
                    TextBlockMonths.Text          = GetNameOFMonthsInPeriod(RowEdited.DateFrom, RowEdited.DateTo);
                    TextBoxComments.Text          = RowEdited.Description.Trim();
                    if (RowEdited.IsClosed)
                    {
                        TextBoxPeriodName.IsEnabled = false;
                        TextBoxComments.IsEnabled   = false;
                        RadioYes.Focus();
                    }
                    else
                    {
                        FirstControl.Focus();
                    }
                }
            }
            catch
            {
                Msg       = new MessageDialog(Messages.EditMessageTitleBillPeriods, Messages.ErrorSendingDataToDatabase, MessageDialogButtons.Ok, MessageDialogType.Error, GridHeader.Background);
                Msg.Owner = Window.GetWindow(this);
                Msg.ShowDialog();
            }
        }
示例#2
0
 private void UserControlBillPeriods_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
 {
     if (((bool)e.NewValue))
     {
         DataGridView.ItemsSource = Commons.Db.BillPeriods.Select(x => x).Where(x => x.Year == Commons.CurrentYear).OrderBy(x => x.DateFrom).ToList();
         if (FirstControl.IsEnabled == true)
         {
             FirstControl.Focus();
         }
         else
         {
             RadioYes.Focus();
         }
     }
 }
示例#3
0
 private void DataGridView_PreviewKeyDown(object sender, KeyEventArgs e)
 {
     if ((Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) && e.Key == Key.D)
     {
         ButtonDelete_Click(null, null);
     }
     if ((Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) && e.Key == Key.E)
     {
         ButtonShowEdit_Click(null, null);
     }
     Commons.GridViewKeyDown(DataGridView, ref e, TextBoxPeriodName, "نام دوره قبض", "عملیات", "توضیحات", 7);
     if (TextBoxPeriodName.IsEnabled == false)
     {
         RadioYes.Focus();
     }
 }
示例#4
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();
                        }
                    }
                }
            }
        }