コード例 #1
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 (!(CBxSklad.SelectedItem is Sklad))
            {
                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);
            }
            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 (_cgt == null)
                {
                    GetTovara getTovar = new GetTovara()
                    {
                        GetId     = AppData.Context.GetTovara.Max(p => p.GetId) + 1,
                        Tovares   = CBxTovar.SelectedItem as Tovares,
                        Sklad     = CBxSklad.SelectedItem as Sklad,
                        Count     = count,
                        Price     = price,
                        Users     = CBxManager.SelectedItem as Users,
                        DateOfGet = (DateTime)DPDateOfGet.SelectedDate
                    };
                    getTovar.Tovares.Count = getTovar.Tovares.Count + count;
                    AppData.Context.GetTovara.Add(getTovar);
                    System.Windows.MessageBox.Show(Properties.Resources.MessageSuccessfullAdd, Properties.Resources.CaptionSuccessfully,
                                                   MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    _cgt.Tovares   = CBxTovar.SelectedItem as Tovares;
                    _cgt.Sklad     = CBxSklad.SelectedItem as Sklad;
                    _cgt.Count     = count;
                    _cgt.Price     = price;
                    _cgt.Users     = CBxManager.SelectedItem as Users;
                    _cgt.DateOfGet = (DateTime)DPDateOfGet.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);
            }
        }
コード例 #2
0
 public PagePrihodnaya(GetTovara currentGetTovara)
 {
     InitializeComponent();
     _cgt           = currentGetTovara;
     BtnAdd.Content = Properties.Resources.BtnEdit;
 }