private void saveBtn_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (receiptsList.Any(r => r.Checked))
            {
                if (MessageBox.Show("Сохранить изменения?", "Сохранение", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    int curOrderId = 0;

                    ordersService             = Program.kernel.Get <IOrdersService>();
                    receiptsService           = Program.kernel.Get <IReceiptsService>();
                    receiptAcceptancesService = Program.kernel.Get <IReceiptAcceptancesService>();

                    foreach (var checkReceipt in receiptsList.Where(r => r.Checked))
                    {
                        if (curOrderId != checkReceipt.OrderId)
                        {
                            curOrderId = checkReceipt.OrderId;
                            var orderItem = ordersService.GetOrderById(curOrderId);
                            orderItem.StatusId = 2;
                            ordersService.OrderUpdate(orderItem);
                        }

                        var receiptItem = receiptsService.GetReceiptById(checkReceipt.ReceiptId);
                        receiptItem.StatusId = 6;
                        receiptsService.ReceiptUpdate(receiptItem);

                        var curReceiptAcceptancesList = receiptAcceptancesService.GetReceiptAcceptanceByReceiptId(checkReceipt.ReceiptId).Select(ra => { ra.StatusId = 6; return(ra); }).ToList();
                        receiptAcceptancesService.UpdateRange(curReceiptAcceptancesList);
                    }

                    receiptsGridView.BeginDataUpdate();
                    LoadReceiptsData((int)statusItem.EditValue);
                    receiptsGridView.EndDataUpdate();

                    if (receiptsBS.Count > 0)
                    {
                        receiptsGridView.FocusedRowHandle = 0;
                        receiptsGridView.ExpandAllGroups();
                    }
                }
            }
            else
            {
                MessageBox.Show("Не выбраны данные для принятия!", "Принятие прихода", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private void cancelAcceptanceBtn_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            receiptAcceptancesService = Program.kernel.Get <IReceiptAcceptancesService>();
            receiptsService           = Program.kernel.Get <IReceiptsService>();
            ordersService             = Program.kernel.Get <IOrdersService>();

            if (receiptsBS.List.Count == 0)
            {
                return;
            }

            var currentReceipt = (ReceiptsForAcceptanceDTO)receiptsBS.Current;

            if ((currentReceipt.StatusId == 6) && (!receiptAcceptancesList.Any(ra => ra.StatusId > 6))) // отменить прием можно если статус Принят и нет не одной записи в receiptAcceptances со статусом Выше (хранение, частично обработан или отгружен)
            {
                if (MessageBox.Show("Отменить прием выбранной номенклатуры?", "Сохранение", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    if (receiptsService.GetReceiptsForAcceptance().Any(m => m.OrderId == currentReceipt.OrderId && m.StatusId == 6 && m.ReceiptId != currentReceipt.ReceiptId))
                    {
                        var orderItem = ordersService.GetOrderById(currentReceipt.OrderId);
                        orderItem.StatusId = 1;
                        ordersService.OrderUpdate(orderItem);
                    }

                    var receiptItem = receiptsService.GetReceiptById(currentReceipt.ReceiptId);
                    receiptItem.StatusId = 5;
                    receiptsService.ReceiptUpdate(receiptItem);

                    receiptAcceptancesService.UpdateRange(receiptAcceptancesList.Select(ra => { ra.StatusId = 5; return(ra); }).ToList());

                    receiptsGridView.BeginDataUpdate();

                    LoadReceiptsData((int)statusItem.EditValue);

                    receiptsGridView.EndDataUpdate();

                    int handle = receiptsGridView.LocateByValue("ReceiptId", currentReceipt.ReceiptId);
                    receiptsGridView.FocusedRowHandle = handle;
                }
            }
            else
            {
                MessageBox.Show("Нельзя отменить принятие, поскольку один или несколько комплектов находятся на хранении.", "Отменить принятие прихода", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemplo n.º 3
0
        private void SaveOrder()
        {
            this.Item.EndEdit();

            if (this.operation == Utils.Operation.Add)
            {
                ((OrdersDTO)Item).StatusId = 1; //К поступлению
                ((OrdersDTO)Item).OrderId  = ordersService.OrderCreate((OrdersDTO)Item);

                List <ReceiptsDTO> receiptsDTO = (List <ReceiptsDTO>)receiptsBS.DataSource;
                receiptsDTO.Select(c => { c.OrderId = ((OrdersDTO)Item).OrderId; return(c); }).ToList();

                for (int i = 0; i <= receiptsDTO.Count - 1; i++)
                {
                    int pId = receiptsService.ReceiptCreate(receiptsDTO[i]);
                }
            }
            else
            {
                ordersService.OrderUpdate((OrdersDTO)Item);

                receiptsBS.DataSource = receiptsByOrder;

                List <ReceiptsDTO> receiptsDTO = (List <ReceiptsDTO>)receiptsBS.DataSource;

                for (int i = 0; i <= receiptsDTO.Count - 1; i++)
                {
                    switch (receiptsDTO[i].Changes)
                    {
                    case 1:     //добавлена запись
                    {
                        int pId = receiptsService.ReceiptCreate(receiptsDTO[i]);
                        break;
                    }

                    case 2:    //отредактирована запись
                    {
                        receiptsService.ReceiptUpdate(receiptsDTO[i]);
                        break;
                    }

                    case 3:    //удалена запись
                    {
                        Error.ErrorCRUD result = receiptsService.ReceiptDelete(receiptsDTO[i]);
                        switch (result)
                        {
                        case Error.ErrorCRUD.RelationError:
                            MessageBox.Show("Приход нельзя удалить. Есть связанные данные!", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            break;

                        case Error.ErrorCRUD.DatabaseError:
                            MessageBox.Show("Ошибка Базы данных!", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            break;

                        default:
                            break;
                        }
                        break;
                    }

                    default:
                        break;
                    }
                }
            }
        }