コード例 #1
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(tbTitle.Text))
            {
                MessageBox.Show("Название работы не может быть пустым!");
                return;
            }
            if (string.IsNullOrEmpty(tbCopy.Text))
            {
                MessageBox.Show("Укажите копию работы!");
                return;
            }
            if (string.IsNullOrEmpty(cbArtist.Text))
            {
                MessageBox.Show("Укажите автора работы!");
                return;
            }
            if (string.IsNullOrEmpty(dpAcuired.Text))
            {
                MessageBox.Show("Укажите дату приобретения работы!");
                return;
            }
            if (string.IsNullOrEmpty(tbAcquisitionPrice.Text))
            {
                MessageBox.Show("Укажите цену приобретения работы!");
                return;
            }
            WorkDto work = new WorkDto
            {
                Title       = tbTitle.Text,
                Copy        = tbCopy.Text,
                Description = tbDescription.Text,
                Artist      = (ArtistDto)this.cbArtist.SelectedItem
            };
            TransactionDto transaction = new TransactionDto
            {
                AcquisitionPrice = Convert.ToDecimal(tbAcquisitionPrice.Text),
                DateAcquired     = Convert.ToDateTime(this.dpAcuired.Text)
            };
            IWorkProcess        workProcess  = ProcessFactory.GetWorkProcess();
            ITransactionProcess transProcess = ProcessFactory.GetTransactionProcess();

            if (_id == 0)
            {
                workProcess.Add(work);
                FreeForSale      = ProcessFactory.GetWorkProcess().GetList();
                transaction.Work = FreeForSale.Last();
                transProcess.Add(transaction);
            }
            else
            {
                work.Id = _id;
                workProcess.Update(work);
            }
            this.Close();
        }
コード例 #2
0
 public TranMainProgram(ITransactionProcess obj)
 {
     this._Obj = obj;
 }
コード例 #3
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (status == "sale")
            {
                if (this.cbCustomer.SelectedIndex < 0)
                {
                    MessageBox.Show("Укажите клиента, которому продается картина!"); return;
                }
            }
            TransactionDto transaction  = new TransactionDto();
            WorkDto        SelectedWork = selectWork();

            if (SelectedWork == null)
            {
                MessageBox.Show("Картина должна быть выбрана!"); return;
            }
            if (status == "sale")
            {
                if (!workAtGalery(SelectedWork))
                {
                    MessageBox.Show("Запрашиваемая работа уже продана!"); return;
                }
            }
            if (status == "purchase")
            {
                if (workAtGalery(SelectedWork))
                {
                    MessageBox.Show("Запрашиваемая работа уже находится в галерее!"); return;
                }
            }
            transaction.Work = SelectedWork;
            if (!string.IsNullOrEmpty(tbAcquisitionPrice.Text))
            {
                try
                {
                    transaction.AcquisitionPrice = Convert.ToDecimal(tbAcquisitionPrice.Text);
                }
                catch (Exception)
                {
                    MessageBox.Show("Введите корректную цену приобретения"); return;
                }
            }
            if (!string.IsNullOrEmpty(tbAskingPrice.Text))
            {
                try
                {
                    transaction.AskingPrice = Convert.ToDecimal(tbAskingPrice.Text);
                }
                catch (Exception)
                {
                    MessageBox.Show("Введите корректную запрашиваемую цену"); return;
                }
            }
            if (!string.IsNullOrEmpty(this.dpAcuired.Text))
            {
                transaction.DateAcquired = Convert.ToDateTime(this.dpAcuired.Text);
            }
            else
            {
                MessageBox.Show("Дата приобретения должна быть указана!"); return;
            }
            if (!string.IsNullOrEmpty(this.dpPurchase.Text))
            {
                if (Convert.ToDateTime(dpPurchase.Text) > Convert.ToDateTime(dpAcuired.Text))
                {
                    transaction.PurchaseDate = Convert.ToDateTime(this.dpPurchase.Text);
                }
                else
                {
                    MessageBox.Show("Нельзя продать работу раньше, чем её купила галерея! Проверьте правильность ввода данных.");
                    return;
                }

                if (dpPurchase.Text == "")
                {
                    transaction.PurchaseDate = null;
                }
            }
            if (!string.IsNullOrEmpty(cbCustomer.Text))
            {
                CustomerDto SelectedCustomer = (CustomerDto)this.cbCustomer.SelectedItem;
                transaction.Customer = SelectedCustomer;
            }
            if (!string.IsNullOrEmpty(tbSalesPrice.Text))
            {
                try
                {
                    if (Convert.ToDecimal(tbSalesPrice.Text) >= 30000 && Convert.ToDecimal(tbSalesPrice.Text) <= 1500000)
                    {
                        transaction.SalesPrice = Convert.ToDecimal(tbSalesPrice.Text);
                    }
                    else
                    {
                        MessageBox.Show("Продажа может проходить только в пределах от 30 тыс.у.е.до 1, 5 млн.у.е.");
                        return;
                    }
                    if (tbSalesPrice.Text == "")
                    {
                        transaction.SalesPrice = null;
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Неверный формат данных при операции с ценой продажи"); return;
                }
            }
            ITransactionProcess transProcess = ProcessFactory.GetTransactionProcess();

            if (id == 0)
            {
                transProcess.Add(transaction);
            }
            else
            {
                transaction.Id = id;
                transProcess.Update(transaction);
            }
            this.Close();
        }