コード例 #1
0
        public override Order UpdateOrder(Order order)
        {
            if (order == null)
            {
                return(null);
            }

            // Get start params about excel file
            int sheetsAllCount = excel.GetSheetsCount();
            int sheetsVisCount = excel.GetSheetsCount(false);

            // Open sheet with order & parse them into orderBO
            int orderIndex = 0;

            for (var i = 1; i < sheetsAllCount + 1; i++)
            {
                excel.SetSheetByIndex(i);

                if (excel.CheckSheetVisibility())
                {
                    orderIndex = i;
                    break;
                }
            }

            if (excel.IsSheetOpened())
            {
                order.Initiator = excel.GetLabelValue("Полное наименование Заказчика");

                var brokerCode = excel.GetLabelValue("Код Брокера Заказчика");
                brokerCode = brokerCode.ToUpper().Replace("К", "K").Replace("А", "A");

                switch (brokerCode.ToLower().Substring(0, 4))
                {
                case "altk": order.Auction.Broker = new Broker(brokerCode, "ТОО «Альта и К», Андреев В.И., Директор Казахстан, 050064, г.Алматы, мкрн.Думан - 2, дом 18, кв. 55 тел.: +7(727) 390 - 43 - 02 e - mail: info @altaik.kz"); break;

                case "alta": order.Auction.Broker = new Broker("ALTA", "ТОО «Альтаир Нур»"); break;
                }

                order.Auction.ExchangeProvisionSize = excel.GetLabelValue("Размер Гарантийного обеспечения");
                var regex = new Regex(@"[^\d,\.]*");
                order.Auction.ExchangeProvisionSize = regex.Replace(order.Auction.ExchangeProvisionSize, "").Replace(".", ",");

                lotName = Regex.Replace(excel.GetLabelValue("Наименование товара"), @"[Лл]от\s*№\d*:\s*", "");
            }

            // Open sheet(-s) with tech spec & parse them into orderBO
            int lotCount    = sheetsVisCount - 2;
            int lotTechSpec = orderIndex + 1;

            for (var i = 1; i < lotCount + 1; i++)
            {
                for (var iLot = lotTechSpec; iLot < sheetsAllCount + 1; iLot++)
                {
                    excel.SetSheetByIndex(iLot);

                    if (excel.CheckSheetVisibility())
                    {
                        lotTechSpec = iLot + 1;
                        break;
                    }
                }

                if (excel.IsSheetOpened())
                {
                    // Change title
                    var titleTechRowWord = excel.FindRow(DocumentTypeEnum.TechSpecs.GetName() + " к Ло");

                    if (titleTechRowWord != 0)
                    {
                        excel.SetCells(titleTechRowWord, "A", "Техническая спецификация к Лоту №" + i);
                    }

                    // Delete not needed header rows
                    if (string.IsNullOrEmpty(excel.GetCell(1, 1)))
                    {
                        for (var iRow = 1; iRow < 5; iRow++)
                        {
                            excel.DeleteRow(1);
                        }
                    }

                    // Delete not needed footer rows and find sum
                    var rowsCount = excel.GetRowsCount();
                    var row       = 0;

                    if (string.IsNullOrEmpty(excel.GetCell(excel.GetRowsCount(), "F")))
                    {
                        for (var iRow = rowsCount; iRow > 0; iRow--)
                        {
                            if (!string.IsNullOrEmpty(excel.GetCell(iRow, "F")))
                            {
                                row           = iRow;
                                lotStartPrice = excel.GetCell(iRow, "F");

                                try {
                                    if (!string.IsNullOrEmpty(excel.GetCell(iRow - 1, "K")))
                                    {
                                        lotMinRequerments = excel.GetCell(iRow - 1, "K");
                                    }
                                    else
                                    {
                                        lotMinRequerments = excel.GetCell(iRow - 2, "K");
                                    }
                                } catch { lotMinRequerments = excel.GetCell(iRow - 2, "K"); }
                                break;
                            }
                        }

                        for (var iRow = row + 1; iRow < rowsCount + 1; iRow++)
                        {
                            excel.DeleteRow(row + 1);
                        }
                    }
                    else
                    {
                        lotStartPrice = excel.GetCell(excel.GetRowsCount(), "F");
                    }

                    // Create lot item
                    var lot = new Lot {
                        Number         = i.ToString(),
                        Name           = lotName,
                        MinRequerments = lotMinRequerments,
                        StartPrice     = lotStartPrice
                    };

                    if (order.Auction.Lots == null)
                    {
                        order.Auction.Lots = new ObservableCollection <Lot>();
                    }
                    order.Auction.Lots.Add(lot);

                    // For Creating LotsExtended
                    var  iRowNum = excel.FindRow("Наименование");
                    bool isBusy  = true;
                    int  iCount  = 1;

                    if (order.Auction.Lots[i - 1].LotsExtended == null)
                    {
                        order.Auction.Lots[i - 1].LotsExtended = new ObservableCollection <LotsExtended>();
                    }

                    while (isBusy)
                    {
                        if (!string.IsNullOrEmpty(excel.GetCell(iRowNum + iCount, 1)))
                        {
                            LotsExtended lotEx = new LotsExtended();

                            lotEx.serialnumber = iCount;
                            lotEx.name         = excel.GetCell(iRowNum + iCount, 2);
                            lotEx.unit         = excel.GetCell(iRowNum + iCount, 3);
                            lotEx.quantity     = Convert.ToDecimal(excel.GetCell(iRowNum + iCount, 4).Replace(".", ","));
                            lotEx.price        = Convert.ToDecimal(excel.GetCell(iRowNum + iCount, 5).Replace(".", ","));
                            lotEx.sum          = Convert.ToDecimal(excel.GetCell(iRowNum + iCount, 6).Replace(".", ","));
                            lotEx.country      = excel.GetCell(iRowNum + iCount, 7);
                            lotEx.techspec     = excel.GetCell(iRowNum + iCount, 8);
                            lotEx.terms        = excel.GetCell(iRowNum + iCount, 9);
                            lotEx.paymentterm  = excel.GetCell(iRowNum + iCount, 10);

                            try {
                                lotEx.dks = Convert.ToInt32(Regex.Replace(excel.GetCell(iRowNum + iCount, 11).Replace("%", ""), "[^0-9]", ""));
                            } catch (Exception) { lotEx.dks = 0; }

                            lotEx.contractnumber = excel.GetCell(iRowNum + iCount, 12);
                            order.Auction.Lots[i - 1].LotsExtended.Add(lotEx);
                        }
                        else
                        {
                            isBusy = false;
                        }

                        iCount++;
                    }
                }
            }

            order.Warranty = WARRANTY_LETER;

            return(order);
        }