private bool CheckPervRowIsExist(BillPeriodsTb RowDeleted) { List <BillPeriodsTb> Lb = Commons.Db.BillPeriods.Select(x => x).Where(x => x.Year == Commons.CurrentYear).OrderBy(x => x.DateFrom).ToList(); if (Lb.Count == 1 || Lb[Lb.Count - 1].Id == RowDeleted.Id) { return(false); } else { return(true); } }
private bool CheckPeriodIsUsed(BillPeriodsTb RowDeleted) { List <BillsTb> Lb = Commons.Db.Bills.Select(x => x).Where(x => (x.CurrentPeriod == RowDeleted.Id || x.CurrentPeriod == (RowDeleted.Id) * -1) && x.Year == Commons.CurrentYear).Take(1).ToList(); if (Lb.Count == 0) { return(false); } else { return(true); } }
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(); } }
public int LoadFirst() { CurrentBillPeriod = null; int Cy = Commons.GetCurrentYear(); CurrentBillPeriod = Commons.Db.BillPeriods.Local.Select(x => x).Where(x => x.Year == Cy && x.IsSelected == true && x.IsClosed == false).FirstOrDefault(); if (CurrentBillPeriod != null) { CurentPeriodNotSelectedOrNotCreated = false; TextBlockNewDateRead.Text = CurrentBillPeriod.DateTo; TextBlockPeriod.Text = CurrentBillPeriod.Name; DoNext(); LoadBills(); } else { CurentPeriodNotSelectedOrNotCreated = true; return(-1); } return(0); }
private void ButtonDelete_Click(object sender, RoutedEventArgs e) { MessageDialog Msg = null; 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 RowDeleted = Commons.Db.BillPeriods.Find(Convert.ToInt32(id)); if (RowDeleted != null) { if (CheckPervRowIsExist(RowDeleted) == true) { Msg = new MessageDialog(Messages.DeleteMessageTitleBillPeriods, Messages.PrevRowExits, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); DataGridView.Focus(); } else { if (CheckPeriodIsUsed(RowDeleted) == true) { Msg = new MessageDialog(Messages.DeleteMessageTitleBillPeriods, Messages.PeriodInUseDelete, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); DataGridView.Focus(); } else { if (RowDeleted.IsClosed == true) { Msg = new MessageDialog(Messages.DeleteMessageTitleBillPeriods, Messages.DeletePeriodIsClosedBillPeriods, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); DataGridView.Focus(); } else { Msg = new MessageDialog(Messages.DeleteMessageTitleBillPeriods, Messages.DeleteMessageBillPeriods, MessageDialogButtons.YesNo, MessageDialogType.Warning, GridHeader.Background); Msg.Owner = Window.GetWindow(this); if (Msg.ShowDialog() == true) { Commons.Db.BillPeriods.Remove(RowDeleted); 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.DeleteMessageTitleBillPeriods, Messages.DeleteMessageSuccessBillPeriods, MessageDialogButtons.Ok, MessageDialogType.Error, GridHeader.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); DataGridView.Focus(); } } } } } } catch { Msg = new MessageDialog(Messages.DeleteMessageTitleBillPeriods, Messages.ErrorSendingDataToDatabase, MessageDialogButtons.Ok, MessageDialogType.Error, GridHeader.Background); Msg.Owner = Window.GetWindow(this); Msg.ShowDialog(); DataGridView.Focus(); } }