コード例 #1
0
        private void ButtonCloseYear_Click(object sender, RoutedEventArgs e)
        {
            MessageDialog Msg = null;

            try
            {
                if (ComboBoxCurrentYear.SelectedIndex < 1)
                {
                    Msg       = new MessageDialog(Messages.CloseYearTitleSettings, Messages.YearNotSelected, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                    Msg.Owner = Window.GetWindow(this);
                    ComboBoxCurrentYear.Focus();
                    Msg.ShowDialog();
                    return;
                }
                var     Ly             = Commons.Db.Years.Select(x => x).ToList();
                bool    IsAllowToClose = false;
                YearsTb SelectedYear   = null;
                foreach (YearsTb value in Ly)
                {
                    if (value.Year == Commons.CurrentYear && value.IsClosed == false)
                    {
                        IsAllowToClose = true;
                        SelectedYear   = value;
                        break;
                    }
                }
                if (IsAllowToClose == false)
                {
                    Msg       = new MessageDialog(Messages.CloseYearTitleSettings, Messages.CloseYearImpossible, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                    Msg.Owner = Window.GetWindow(this);
                    Msg.ShowDialog();
                }
                else
                {
                    Msg       = new MessageDialog(Messages.CloseYearTitleSettings, Messages.IsCloseYear, MessageDialogButtons.YesNo, MessageDialogType.Information, GridHeader.Background);
                    Msg.Owner = Window.GetWindow(this);
                    if (Msg.ShowDialog() == true)
                    {
                        SelectedYear.IsClosed       = true;
                        Commons.IsClosedCurrentYear = true;
                        Commons.Db.SaveChanges();
                        Commons.SetFromEdited("Settings");
                        Msg       = new MessageDialog(Messages.CloseYearTitleSettings, Messages.CloseYearMessageSuccess, MessageDialogButtons.Ok, MessageDialogType.Information, GridHeader.Background);
                        Msg.Owner = Window.GetWindow(this);
                        Msg.ShowDialog();
                    }
                }
            }
            catch
            {
                Msg       = new MessageDialog(Messages.CloseYearTitleSettings, Messages.ErrorSendingDataToDatabase, MessageDialogButtons.Ok, MessageDialogType.Error, GridHeader.Background);
                Msg.Owner = Window.GetWindow(this);
                Msg.ShowDialog();
            }
        }
コード例 #2
0
 public static void SetYear()
 {
     try
     {
         List <DomainClasses.SettingsTb> Tb = Commons.Db.Settings.ToList();
         if (Tb.Count > 0)
         {
             Commons.CurrentYear = Tb[0].CurrentYear;
             Commons.Address     = Tb[0].Address;
             Commons.BillMessage = Tb[0].BillMessage;
             Commons.CompanyName = Tb[0].CompanyName;
             Commons.Tel         = Tb[0].Tel;
             Commons.Vat         = Tb[0].Vat;
             Commons.WaterAndWastewaterAuthorityName = Tb[0].WaterAndWastewaterAuthorityName;
             YearsTb Ly = Commons.Db.Years.Find(Tb[0].CurrentYear);
             if (Ly != null)
             {
                 Commons.IsClosedCurrentYear = Ly.IsClosed;
             }
             else
             {
                 Commons.IsClosedCurrentYear = false;
             }
         }
         else
         {
             Commons.CurrentYear = 0;
             Commons.Address     = "";
             Commons.BillMessage = "";
             Commons.CompanyName = "";
             Commons.Tel         = "";
             Commons.Vat         = 0;
             Commons.WaterAndWastewaterAuthorityName = "";
         }
     }
     catch
     {
         Commons.CurrentYear = 0;
         Commons.Address     = "";
         Commons.BillMessage = "";
         Commons.CompanyName = "";
         Commons.Tel         = "";
         Commons.Vat         = 0;
         Commons.WaterAndWastewaterAuthorityName = "";
     }
 }
コード例 #3
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.SaveMessageTitleSettings, Vd.Value.Message, MessageDialogButtons.Ok, MessageDialogType.Warning, GridHeader.Background);
                Msg.Owner = Window.GetWindow(this);
                Msg.ShowDialog();
                Vd.Value.Control.Focus();
            }
            else
            {
                if (Commons.CurrentYear != Convert.ToInt32(ComboBoxCurrentYear.SelectedValue))
                {
                    Msg       = new MessageDialog(Messages.SaveMessageTitleSettings, Messages.CurrentYearConfilctWithThisYearSettings, MessageDialogButtons.YesNo, MessageDialogType.Warning, GridHeader.Background);
                    Msg.Owner = Window.GetWindow(this);
                    if (Msg.ShowDialog() != true)
                    {
                        return;
                    }
                }

                DomainClasses.SettingsTb MySettings = Commons.Db.Settings.FirstOrDefault();
                Msg       = new MessageDialog(Messages.SaveMessageTitleSettings, Messages.SaveMessageSettings, MessageDialogButtons.YesNo, MessageDialogType.Warning, GridHeader.Background);
                Msg.Owner = Window.GetWindow(this);
                if (Msg.ShowDialog() == true)
                {
                    if (MySettings == null)
                    {
                        try
                        {
                            Commons.Db.Settings.Add(new DomainClasses.SettingsTb
                            {
                                CurrentYear  = Convert.ToInt32(ComboBoxCurrentYear.SelectedValue),
                                Address      = TextBoxAddress.Text.Trim(),
                                BillMessage  = TextBoxMessage.Text.Trim(),
                                CompanyName  = TextBoxCompanyName.Text.Trim(),
                                Tel          = TextBoxTel.Text.Trim(),
                                Vat          = Convert.ToInt32(TextBoxVat.Text),
                                Subscription = Convert.ToInt32(TextBoxSubscription.Text),
                                WaterAndWastewaterAuthorityName = TextBoxAuthorityName.Text.Trim()
                            });
                            Commons.Db.SaveChanges();
                            Commons.SetFromEdited("Settings");

                            Commons.CurrentYear = Convert.ToInt32(ComboBoxCurrentYear.SelectedValue);
                            YearsTb Ly = Commons.Db.Years.Find(Convert.ToInt32(ComboBoxCurrentYear.SelectedValue));
                            if (Ly != null)
                            {
                                Commons.IsClosedCurrentYear = Ly.IsClosed;
                            }
                            else
                            {
                                Commons.IsClosedCurrentYear = false;
                            }
                            Commons.Address      = TextBoxAddress.Text.Trim();
                            Commons.BillMessage  = TextBoxMessage.Text.Trim();
                            Commons.CompanyName  = TextBoxCompanyName.Text.Trim();
                            Commons.Tel          = TextBoxTel.Text.Trim();
                            Commons.Vat          = Convert.ToInt32(TextBoxVat.Text);
                            Commons.Subscription = Convert.ToInt32(TextBoxSubscription.Text);
                            Commons.WaterAndWastewaterAuthorityName = TextBoxAuthorityName.Text.Trim();

                            Msg       = new MessageDialog(Messages.SaveMessageTitleSettings, Messages.SaveMessageSuccessSettings, MessageDialogButtons.Ok, MessageDialogType.Information, GridHeader.Background);
                            Msg.Owner = Window.GetWindow(this);
                            Msg.ShowDialog();
                        }
                        catch
                        {
                            Msg       = new MessageDialog(Messages.SaveMessageTitleSettings, Messages.ErrorSendingDataToDatabase, MessageDialogButtons.Ok, MessageDialogType.Error, GridHeader.Background);
                            Msg.Owner = Window.GetWindow(this);
                            Msg.ShowDialog();
                        }
                    }
                    else
                    {
                        try
                        {
                            MySettings.CurrentYear  = Convert.ToInt32(ComboBoxCurrentYear.SelectedValue);
                            MySettings.Address      = TextBoxAddress.Text.Trim();
                            MySettings.BillMessage  = TextBoxMessage.Text.Trim();
                            MySettings.CompanyName  = TextBoxCompanyName.Text.Trim();
                            MySettings.Tel          = TextBoxTel.Text.Trim();
                            MySettings.Vat          = Convert.ToInt32(TextBoxVat.Text);
                            MySettings.Subscription = Convert.ToInt32(TextBoxSubscription.Text);
                            MySettings.WaterAndWastewaterAuthorityName = TextBoxAuthorityName.Text.Trim();
                            Commons.Db.SaveChanges();
                            Commons.SetFromEdited("Settings");

                            Commons.CurrentYear = Convert.ToInt32(ComboBoxCurrentYear.SelectedValue);
                            YearsTb Ly = Commons.Db.Years.Find(Convert.ToInt32(ComboBoxCurrentYear.SelectedValue));
                            if (Ly != null)
                            {
                                Commons.IsClosedCurrentYear = Ly.IsClosed;
                            }
                            else
                            {
                                Commons.IsClosedCurrentYear = true;
                            }
                            Commons.Address      = TextBoxAddress.Text.Trim();
                            Commons.BillMessage  = TextBoxMessage.Text.Trim();
                            Commons.CompanyName  = TextBoxCompanyName.Text.Trim();
                            Commons.Tel          = TextBoxTel.Text.Trim();
                            Commons.Vat          = Convert.ToInt32(TextBoxVat.Text);
                            Commons.Subscription = Convert.ToInt32(TextBoxSubscription.Text);
                            Commons.WaterAndWastewaterAuthorityName = TextBoxAuthorityName.Text.Trim();

                            Msg       = new MessageDialog(Messages.SaveMessageTitleSettings, Messages.SaveMessageSuccessSettings, MessageDialogButtons.Ok, MessageDialogType.Information, GridHeader.Background);
                            Msg.Owner = Window.GetWindow(this);
                            Msg.ShowDialog();
                        }
                        catch
                        {
                            Msg       = new MessageDialog(Messages.SaveMessageTitleSettings, Messages.ErrorSendingDataToDatabase, MessageDialogButtons.Ok, MessageDialogType.Error, GridHeader.Background);
                            Msg.Owner = Window.GetWindow(this);
                            Msg.ShowDialog();
                        }
                    }
                }
            }
        }