public PageAddTovar(Tovares currentTovares)
 {
     InitializeComponent();
     _ct = currentTovares;
     BtnAddEdit.Content = Properties.Resources.BtnEdit;
 }
        private void BtnAddEdit_Click(object sender, RoutedEventArgs e)
        {
            StringBuilder error   = new StringBuilder();
            int           article = 0;

            if (string.IsNullOrWhiteSpace(TBxTovarName.Text))
            {
                error.AppendLine(Properties.Resources.ErrorTovarName);
            }
            if (string.IsNullOrWhiteSpace(TBxArticle.Text))
            {
                error.AppendLine(Properties.Resources.ErrorArticleEmpty);
            }
            else
            if (!int.TryParse(TBxArticle.Text, out article))
            {
                error.AppendLine(Properties.Resources.ErrorArcticleFormat);
            }
            if (!(CBxCountry.SelectedItem is Country))
            {
                error.AppendLine(Properties.Resources.ErrorCountry);
            }
            if (!(CBxColor.SelectedItem is TovarColor))
            {
                error.AppendLine(Properties.Resources.ErrorColor);
            }
            if (!error.ToString().Equals(""))
            {
                System.Windows.MessageBox.Show(Properties.Resources.ErrorSomethingWrong + "\n\n" + error, Properties.Resources.CaptionError,
                                               MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            try
            {
                if (_ct == null)
                {
                    Tovares tovar = new Tovares()
                    {
                        TovarId      = AppData.Context.Tovares.Max(p => p.TovarId) + 1,
                        TovarName    = TBxTovarName.Text,
                        TovarArticle = article,
                        Country      = CBxCountry.SelectedItem as Country,
                        TovarColor   = CBxColor.SelectedItem as TovarColor,
                        Count        = 0,
                    };
                    AppData.Context.Tovares.Add(tovar);
                    System.Windows.MessageBox.Show(Properties.Resources.MessageSuccessfullAdd, Properties.Resources.CaptionSuccessfully,
                                                   MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    _ct.TovarName    = TBxTovarName.Text;
                    _ct.TovarArticle = article;
                    _ct.Country      = CBxCountry.SelectedItem as Country;
                    _ct.TovarColor   = CBxColor.SelectedItem as TovarColor;
                    _ct.Count        = 0;
                    System.Windows.MessageBox.Show(Properties.Resources.MessageSuccessfullEdit, Properties.Resources.CaptionSuccessfully,
                                                   MessageBoxButton.OK, MessageBoxImage.Information);
                }
                AppData.Context.SaveChanges();
                AppData.WindowAddEdit.CloseDialog();
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(Properties.Resources.ErrorUnspecified + ex.Message, Properties.Resources.CaptionError,
                                               MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }