예제 #1
0
        /// <summary>
        /// Импорт доставок в таблицу
        /// </summary>
        /// <param name="deliveries"></param>
        public void ImportDeliveryes(List <Delivery> deliveries)
        {
            int iRow = NextRow;

            //DateTime dateMax = DateTime.Today;
            //dateMax = dateMax.AddDays(-(double)dateMax.DayOfWeek);

            Forms.ProcessBar pb = Forms.ProcessBar.Init("Экспорт в Shipments", deliveries.Count, 1, "Экспорт");
            if (pb == null)
            {
                return;
            }
            pb.Show();
            int i = 0;

            foreach (Delivery delivery in deliveries)
            {
                if (pb == null)
                {
                    return;
                }
                i++;
                if (pb.Cancel)
                {
                    break;
                }
                pb.Action($"Доставка {i} из {pb.Count}");

                //if (DateTime.Parse(delivery.DateDelivery) > dateMax) continue;
                TableSheet.Cells[iRow, ColumnPriceDelivery].Value = delivery.Cost;

                foreach (Order order in delivery.Orders)
                {
                    TableSheet.Cells[iRow, ColumnId].Value       = delivery.Driver.Id;
                    TableSheet.Cells[iRow, ColumnProvider].Value = delivery.Truck.ProviderCompany.Name;
                    TableSheet.Cells[iRow, ColumnCarType].Value  = delivery.Truck.Tonnage;
                    TableSheet.Cells[iRow, ColumnDriver].Value   = delivery.Driver.Name;

                    TableSheet.Cells[iRow, ColumnDriverOrgan].Value      = delivery.Driver.Organization;
                    TableSheet.Cells[iRow, ColumnDriverAddress].Value    = delivery.Driver.Address;
                    TableSheet.Cells[iRow, ColumnDriverINN].Value        = delivery.Driver.INN;
                    TableSheet.Cells[iRow, ColumnDriverPhoneOrgan].Value = delivery.Driver.PhoneOrganization;
                    TableSheet.Cells[iRow, ColumnDriverOwnType].Value    = delivery.Driver.TypeOwn;



                    TableSheet.Cells[iRow, ColumnDriverPhone].Value = delivery.Driver.Phone;
                    TableSheet.Cells[iRow, ColumnCarNumber].Value   = delivery.Driver.CarNumber;

                    TableSheet.Cells[iRow, ColumnDate].Value           = delivery.DateDelivery;
                    TableSheet.Cells[iRow, ColumnTime].Value           = delivery.Time;
                    TableSheet.Cells[iRow, ColumnDeliveryNumber].Value = order.DeliveryNumber;
                    TableSheet.Cells[iRow, ColumnSity].Value           = order.DeliveryPoint.City;
                    TableSheet.Cells[iRow, ColumnRoute].Value          = order.RouteCity;
                    TableSheet.Cells[iRow, ColumnPoint].Value          = order.PointNumber;
                    TableSheet.Cells[iRow, ColumnClientId].Value       = order.Customer.Id;
                    TableSheet.Cells[iRow, ColumnTTN].Value            = order.TransportationUnit;
                    TableSheet.Cells[iRow, ColumnOrderNumber].Value    = order.Id;
                    TableSheet.Cells[iRow, ColumnClient].Value         = order.Customer.Name;

                    TableSheet.Cells[iRow, ColumnWeightBrutto].Value = order.WeightBrutto;
                    TableSheet.Cells[iRow, ColumnWeightNetto].Value  = order.WeightNetto;
                    TableSheet.Cells[iRow, ColumnPalleteCount].Value = order.PalletsCount;
                    TableSheet.Cells[iRow, ColumnPriceOrder].Value   = order.Cost;
                    iRow++;
                }
            }
            pb.Close();
        }
        /// <summary>
        /// Импорт данных из архива
        /// </summary>
        /// <param name="deliveries"></param>
        public void ImportDeliveryes(List <Delivery> deliveries)
        {
            int      iRow       = NextRow;
            int      iRowDeline = NextRowDeline;
            DateTime dateMax    = DateTime.Today;

            dateMax = dateMax.AddDays(-(double)dateMax.DayOfWeek);

            Forms.ProcessBar pb = Forms.ProcessBar.Init("Экспорт в Transport Table", deliveries.Count, 1, "Экспорт");
            if (pb == null)
            {
                return;
            }
            pb.Show();
            int i = 0;

            foreach (Delivery delivery in deliveries)
            {
                if (pb == null)
                {
                    return;
                }
                i++;
                if (pb.Cancel)
                {
                    break;
                }
                pb.Action($"Доставка {i} из {pb.Count}");
                List <string> sityes  = new List <string>();
                List <string> routes  = new List <string>();
                List <string> ttns    = new List <string>();
                List <string> clients = new List <string>();

                double weightNetto  = 0;
                double weightBrutto = 0;
                double palletCount  = 0;
                double priceOrder   = 0;

                if (DateTime.Parse(delivery.DateDelivery) > dateMax)
                {
                    continue;
                }

                foreach (Order order in delivery.Orders)
                {
                    weightNetto  += order.WeightNetto;
                    weightBrutto += order.WeightBrutto;
                    palletCount  += order.PalletsCount;
                    priceOrder   += order.Cost;


                    sityes.Add(order.DeliveryPoint.City);
                    routes.Add(order.RouteCity);
                    ttns.Add(order.TransportationUnit);

                    string client = order.Customer.Name;
                    if (client.IndexOf('/') != -1)
                    {
                        client = client.Substring(0, client.IndexOf('/'));
                    }
                    client = client.Replace(",", "");
                    client = client + "-" + order.Customer.Id;
                    clients.Add(client);
                }

                sityes  = sityes.Distinct().ToList();
                routes  = routes.Distinct().ToList();
                ttns    = ttns.Distinct().ToList();
                clients = clients.Distinct().ToList();

                Worksheet worksheet;
                int       row;
                if (delivery.Truck.ProviderCompany.Name == "Деловые линии")
                {
                    worksheet = TableSheetDeline;
                    row       = iRowDeline;
                }
                else
                {
                    worksheet = TableSheet;
                    row       = iRow;
                }

                worksheet.Cells[row, ColumnId].Value        = delivery.Driver.Id;
                worksheet.Cells[row, ColumnProvider].Value  = delivery.Truck.ProviderCompany.Name;
                worksheet.Cells[row, ColumnCarType].Value   = delivery.Truck.Tonnage;
                worksheet.Cells[row, ColumnDate].Value      = delivery.DateDelivery;
                worksheet.Cells[row, ColumnCarNumber].Value = delivery.Driver.CarNumber;
                worksheet.Cells[row, ColumnCarDriver].Value = delivery.Driver.Name;

                worksheet.Cells[row, ColumnSity].Value  = string.Join(", ", sityes.Select(x => x.ToString()));
                worksheet.Cells[row, ColumnRoute].Value = string.Join(", ", routes.Select(x => x.ToString()));

                worksheet.Cells[row, ColumnPointCount].Value = clients.Count;
                worksheet.Cells[row, ColumnTTNs].Value       = string.Join(", ", ttns.Select(x => x.ToString()));
                worksheet.Cells[row, ColumnClients].Value    = string.Join(", ", clients.Select(x => x.ToString()));

                worksheet.Cells[row, ColumnWeightBrutto].Value  = weightBrutto;
                worksheet.Cells[row, ColumnWeightNetto].Value   = weightNetto;
                worksheet.Cells[row, ColumnPalleteCount].Value  = palletCount;
                worksheet.Cells[row, ColumnPriceOrder].Value    = priceOrder;
                worksheet.Cells[row, ColumnPriceDelivery].Value = delivery.Cost;

                if (worksheet == TableSheet)
                {
                    iRow++;
                }
                else
                {
                    iRowDeline++;
                }
            }
            pb.Close();
        }