public void Add(TransDto trans)
        {
            int max = Transactions.Keys.Count == 0 ? 1 : Transactions.Keys.Max(p => p) + 1;

            trans.TransactionID = max;
            Transactions.Add(max, trans);
        }
 public void Update(TransDto trans)
 {
     if (Transactions.ContainsKey(trans.TransactionID))
     {
         Transactions[trans.TransactionID] = trans;
     }
 }
 public void PutTransferencia(TransDto op)
 {
     ExecuteProcedure("TraConta");
     AddParameter("@Num_ContaOri", op.Conta1.Conta);
     AddParameter("@Num_ContaDes", op.Conta2.Conta);
     AddParameter("@Num_Valor", op.Valor);
     ExecuteNonQuery();
 }
        private void loadTransaction(int transId)
        {
            TransDto trans = ProcessFactory.GetTransProcess().Get(transId);

            this.dpAcuired.Text               = trans.DateAcquired.ToString();
            this.dpAcuired.IsEnabled          = false;
            this.tbAcquisitionPrice.Text      = trans.AcquisitionPrice.ToString();
            this.tbAcquisitionPrice.IsEnabled = false;
            this.tbAskingPrice.Text           = trans.AskingPrice.ToString();
            this.tbAskingPrice.IsEnabled      = false;
        }
        //
        // TRANS
        //
        public static TransDto Convert(Trans trans)
        {
            if (trans == null)
            {
                return(null);
            }
            TransDto transDto = new TransDto();

            transDto.TransactionID    = trans.TransactionID;
            transDto.Customer         = Convert(DaoFactory.GetCustomerDao().Get(trans.CustomerID.Value));
            transDto.DateAcquired     = trans.DateAcquired;
            transDto.AcquisitionPrice = trans.AcquisitionPrice;
            transDto.PurchaseDate     = trans.PurchaseDate;
            transDto.SalesPrice       = trans.SalesPrice;
            transDto.AskingPrice      = trans.AskingPrice;
            transDto.Work             = Convert(DaoFactory.GetWorkDao().Get(trans.WorkID));;
            return(transDto);
        }
 public void Load(TransDto trans)
 {
     _transactionid = trans.TransactionID;
     this.Title     = "Транзакция: Редактирование";
     if (trans.Customer != null)
     {
         this.cbCustomer.Text = trans.Customer.Name;
     }
     if (trans.Work.Copy != null)
     {
         this.cbCopy.Text = trans.Work.Copy;
         this.cbWork.Text = trans.Work.Title;
     }
     this.tbAcquisitionPrice.Text = trans.AcquisitionPrice.ToString();
     this.tbAskingPrice.Text      = trans.AskingPrice.ToString();
     this.tbSalesPrice.Text       = trans.SalesPrice.ToString();
     this.dpAcuired.Text          = trans.DateAcquired.ToString();
     this.dpPurchase.Text         = trans.PurchaseDate.ToString();
     this.LoadWork(trans.Work.Title);
 }
        private void btnEditT_Click(object sender, RoutedEventArgs e)
        {
            //Получаем выделенную строку с объектом клиента
            TransDto item = dgTrans.SelectedItem as TransDto;

            //если там не клиент или пользователь ничего не выбрал сообщаем об этом
            if (item == null)
            {
                MessageBox.Show("Выберите запись для редактирования", "Редактирование");
                return;
            }
            //Создаем окно
            AddTransWindow window = new AddTransWindow();

            //Передаем объект на редактирование
            window.Load(item);
            //Отображаем окно с данными
            window.ShowDialog();
            //Перезагружаем список объектов
            btnRefresh_Click(sender, e);
        }
        public static Trans Convert(TransDto transDto)
        {
            if (transDto == null)
            {
                return(null);
            }
            Trans trans = new Trans();

            trans.TransactionID = transDto.TransactionID;
            if (transDto.Customer.CustomerID.HasValue)
            {
                trans.CustomerID = transDto.Customer.CustomerID.Value;
            }
            trans.DateAcquired     = transDto.DateAcquired;
            trans.AcquisitionPrice = transDto.AcquisitionPrice;
            trans.PurchaseDate     = transDto.PurchaseDate;
            trans.SalesPrice       = transDto.SalesPrice;
            trans.AskingPrice      = transDto.AskingPrice;
            trans.WorkID           = transDto.Work.WorkID;
            return(trans);
        }
        private void btnDeleteT_Click(object sender, RoutedEventArgs e)
        {
            //Получаем выделенную строку с объектом художника
            TransDto item = dgTrans.SelectedItem as TransDto;

            //если там не художник или пользователь ничего не выбрал сообщаем об этом
            if (item == null)
            {
                MessageBox.Show("Выберите запись для удаления", "Удаление художника");
                return;
            }
            //Просим подтвердить удаление
            MessageBoxResult result = MessageBox.Show("Удалить художника " + item.TransactionID + "?", "Удаление художника", MessageBoxButton.YesNo, MessageBoxImage.Warning);

            //Если пользователь не подтвердил, выходим
            if (result != MessageBoxResult.Yes)
            {
                return;
            }
            //Если все проверки пройдены и подтверждение получено, удаляем художника
            ProcessFactory.GetTransProcess().Delete(item.TransactionID);
            //И перезагружаем список художников
            btnRefresh_Click(sender, e);
        }
 public IHttpActionResult Put(TransDto op)
 {
     _ContasRepository.PutTransferencia(op);
     return(Ok());
 }
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (status == "sale")
            {
                if (this.cbCustomer.SelectedIndex < 0)
                {
                    MessageBox.Show("Укажите клиента, которому продается картина!");
                    return;
                }
            }
            TransDto transaction  = new TransDto();
            WorkDto  SelectedWork = selectWork();

            if (SelectedWork == null)
            {
                MessageBox.Show("Картина должна быть выбрана!");
                return;
            }
            if (status == "purchase")
            {
                if (workAtGalery(SelectedWork))
                {
                    MessageBox.Show("Запрашиваемая работа уже находится в галерее!");
                    return;
                }
            }
            if (status == "sale")
            {
                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.AcquisitionPrice = Convert.ToDecimal(tbAcquisitionPrice.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 (!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;
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Неверный формат данных при операции с ценой продажи"); return;
                }
            }
            ITransProcess transProcess = ProcessFactory.GetTransProcess();

            if (_transactionid == 0)
            {
                transProcess.Add(transaction);
            }
            else
            {
                transaction.TransactionID = _transactionid;
                transProcess.Update(transaction);
            }
            this.Close();
        }
Example #12
0
 public void Update(TransDto trans)
 {
     transDao.Update(DtoConverter.Convert(trans));
 }
Example #13
0
 public void Add(TransDto customer)
 {
     transDao.Add(DtoConverter.Convert(customer));
 }
        public void fillExcelTableByType(IEnumerable <object> grid, string status, FileInfo xlsxFile)
        {
            if (grid != null)
            {
                ExcelPackage pck   = new ExcelPackage(xlsxFile);
                var          excel = pck.Workbook.Worksheets.Add(status);
                int          x     = 1;
                int          y     = 1;
                // Устанавливает фиксированный десятичный разделитель (нужно для верногораспознавания типа данных Excel'ем).
                CultureInfo cultureInfo = new CultureInfo(Thread.CurrentThread.CurrentCulture.Name);
                Thread.CurrentThread.CurrentCulture             = cultureInfo;
                cultureInfo.NumberFormat.NumberDecimalSeparator = ".";
                // Первая строка (шапка таблицы) – жирным стилем.
                excel.Cells["A1: Z1"].Style.Font.Bold = true;
                // Выравнивание текста в ячейках – по левому краю.
                excel.Cells.Style.HorizontalAlignment = ExcelHorizontalAlignment.Left;
                // Устанавливает формат ячеек.
                excel.Cells.Style.Numberformat.Format = "General";

                // Пустой объект для получения списка property.
                Object dtObj = new Object();
                switch (status)
                {
                case "Customer":
                    dtObj = new CustomerDto();
                    break;

                case "Artist":
                    dtObj = new ArtistDto();
                    break;

                case "Work":
                    dtObj = new WorkDto();
                    break;

                case "Trans":
                    dtObj = new TransDto();
                    break;

                case "Interests":
                    dtObj = new CustomerArtistIntDto();
                    break;

                case "Nations":
                    dtObj = new NationDto();
                    break;
                }
                // Генерация шапки таблицы.
                foreach (var prop in dtObj.GetType().GetProperties())
                {
                    excel.Cells[y, x].Value = prop.Name.Trim();
                    x++;
                }
                // Генерация строк-записей таблицы.
                foreach (var item in grid)
                {
                    y++;
                    // Объект-контейнер для текущего читаемого элемента.
                    Object itemObj = item;
                    x = 1;
                    foreach (var prop in itemObj.GetType().GetProperties())
                    {
                        object t = prop.GetValue(itemObj, null);
                        object val;
                        if (t == null)
                        {
                            val = "";
                        }
                        else
                        {
                            val = t.ToString();
                            // Если тип сложный, то вытаскиваем нужное поле.
                            if (t is NationDto)
                            {
                                val = ((NationDto)t).Nationality;
                            }
                            if (t is ArtistDto)
                            {
                                val = ((ArtistDto)t).Name;
                            }
                            if (t is CustomerDto)
                            {
                                val = ((CustomerDto)t).Name;
                            }
                            if (t is WorkDto)
                            {
                                val = ((WorkDto)t).Title;
                            }
                        }
                        excel.Cells[y, x].Value = val;
                        x++;
                    }
                }
                // Устанавливаем размер колонок по ширине содержимого.
                excel.Cells.AutoFitColumns();
                // Сохраняем файл.
                pck.Save();
            }
            else
            {
                MessageBox.Show("Данные не загружены!");
            }
        }
Example #15
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (cbArtist == null)
            {
                MessageBox.Show("Необходимо выбрать художника", "Проверка");
                return;
            }
            if (string.IsNullOrEmpty(tbCopy.Text))
            {
                MessageBox.Show("Информация о копии не должна быть пустой", "Проверка");
                return;
            }
            if (string.IsNullOrEmpty(tbDescription.Text))
            {
                MessageBox.Show("Описание не должно быть пустым", "Проверка");
                return;
            }
            if (string.IsNullOrEmpty(tbTitle.Text))
            {
                MessageBox.Show("Название картины не должно быть пустым", "Проверка");
                return;
            }
            WorkDto work = new WorkDto
            {
                Title       = tbTitle.Text,
                Copy        = tbCopy.Text,
                Description = tbDescription.Text,
                Artist      = (ArtistDto)this.cbArtist.SelectedItem
            };
            TransDto trans = new TransDto
            {
                AcquisitionPrice = Convert.ToDecimal(tbAcquisitionPrice.Text),
                DateAcquired     = Convert.ToDateTime(this.dpAquired.Text)
            };
            IWorkProcess  workProcess  = ProcessFactory.GetWorkProcess();
            ITransProcess transProcess = ProcessFactory.GetTransProcess();

            if (_workid == 0)
            {
                workProcess.Add(work);
                FreeForSale = ProcessFactory.GetWorkProcess().GetList();
                trans.Work  = FreeForSale.Last();
                transProcess.Add(trans);
            }
            else
            {
                work.WorkID = _workid;
                workProcess.Update(work);
            }

            /*WorkDto work = new WorkDto();
             * work.Artist = cbArtist.SelectedItem as ArtistDto;
             * work.Title = tbTitle.Text;
             * work.Copy = tbCopy.Text;
             * work.Description = tbDescription.Text;
             * IWorkProcess workProcess = ProcessFactory.GetWorkProcess();
             * if(_workid==0)
             * {
             *  workProcess.Add(work);
             * }
             * else
             * {
             *  work.WorkID = _workid;
             *  workProcess.Update(work);
             * }*/
            Close();
        }