Ejemplo n.º 1
0
 public PageRashodnaya(PostTovara postTovara)
 {
     InitializeComponent();
     _cpt           = postTovara;
     BtnAdd.Content = Properties.Resources.BtnEdit;
 }
Ejemplo n.º 2
0
        private void BtnAdd_Click(object sender, RoutedEventArgs e)
        {
            StringBuilder error = new StringBuilder();
            int           count = 0;
            decimal       price = 0;

            if (!(CBxTovar.SelectedItem is Tovares))
            {
                error.AppendLine(Properties.Resources.ErrorTovar);
            }
            if (!(CBxKontragent.SelectedItem is Kontragent))
            {
                error.AppendLine(Properties.Resources.ErrorSklad);
            }
            if (!(CBxManager.SelectedItem is Users))
            {
                error.AppendLine(Properties.Resources.ErrorManager);
            }
            if (string.IsNullOrWhiteSpace(TBxCount.Text))
            {
                error.AppendLine(Properties.Resources.ErrorCountEmpty);
            }
            else
            if (!int.TryParse(TBxCount.Text, out count))
            {
                error.AppendLine(Properties.Resources.ErrorCountFormat);
            }
            else if (count > ((Tovares)CBxTovar.SelectedItem).Count)
            {
                error.AppendLine(Properties.Resources.ErrorCountFormat);
            }
            if (string.IsNullOrWhiteSpace(TBxPrice.Text))
            {
                error.AppendLine(Properties.Resources.ErrorPriceEmpty);
            }
            else
            if (!decimal.TryParse(TBxPrice.Text, out price))
            {
                error.AppendLine(Properties.Resources.ErrorPriceFormat);
            }
            if (!error.ToString().Equals(""))
            {
                System.Windows.MessageBox.Show(Properties.Resources.ErrorSomethingWrong + "\n\n" + error, Properties.Resources.CaptionError,
                                               MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            try
            {
                if (_cpt == null)
                {
                    PostTovara postTovara = new PostTovara()
                    {
                        PostId     = AppData.Context.PostTovara.Max(p => p.PostId) + 1,
                        Tovares    = CBxTovar.SelectedItem as Tovares,
                        Kontragent = CBxKontragent.SelectedItem as Kontragent,
                        Count      = count,
                        Price      = price,
                        Users      = CBxManager.SelectedItem as Users,
                        DateOfPost = (DateTime)DPDateOfSale.SelectedDate
                    };
                    postTovara.Tovares.Count = postTovara.Tovares.Count - count;
                    AppData.Context.PostTovara.Add(postTovara);
                    System.Windows.MessageBox.Show(Properties.Resources.MessageSuccessfullAdd, Properties.Resources.CaptionSuccessfully,
                                                   MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    _cpt.Tovares    = CBxTovar.SelectedItem as Tovares;
                    _cpt.Kontragent = CBxKontragent.SelectedItem as Kontragent;
                    _cpt.Count      = count;
                    _cpt.Price      = price;
                    _cpt.Users      = CBxManager.SelectedItem as Users;
                    _cpt.DateOfPost = (DateTime)DPDateOfSale.SelectedDate;
                    System.Windows.MessageBox.Show(Properties.Resources.MessageSuccessfullEdit, Properties.Resources.CaptionSuccessfully,
                                                   MessageBoxButton.OK, MessageBoxImage.Information);
                }
                AppData.WindowAddEdit.CloseDialog();
                AppData.Context.SaveChanges();
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(Properties.Resources.ErrorUnspecified + ex.Message, Properties.Resources.CaptionError,
                                               MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }