Пример #1
0
        // function updates arrivals data grid with data taken from port websites
        // function should be called when data reading from all ports is complete
        // and the following lists are filled with data:
        // Common.ashdodAnchoringList
        // Common.haifaAnchoringList
        // function colors rows according to arrival status and adds tooltips with additional data
        public void arrivalsDataGrid_WebSyncComplete()
        {
            // get columns based on Common.ArrivalsReport
            PortService.PortName portName = PortService.PortName.Unknown;
            int    toPlaceIndex           = arrivalsDataGrid.Columns["toPlace"].Index;
            int    vesselIndex            = arrivalsDataGrid.Columns["vessel"].Index;
            string portNameStr            = string.Empty;
            string toolTipStr             = string.Empty;

            // go over each rows
            foreach (DataGridViewRow row in arrivalsDataGrid.Rows)
            {
                string vesselName = string.Empty;
                portNameStr = row.Cells[toPlaceIndex].Value.ToString();

                if (portNameStr.ToLower() == "ashdod")
                {
                    portName = PortService.PortName.Ashdod;
                }

                if (portNameStr.ToLower() == "haifa")
                {
                    portName = PortService.PortName.Haifa;
                }

                vesselName = row.Cells[vesselIndex].Value.ToString();

                if (string.IsNullOrEmpty(vesselName) == false)
                {
                    // colorize according to arrival status
                    // get tool tip as well during parsing
                    switch (PortService.shipStatusInPort(vesselName, portName, out toolTipStr))
                    {
                    case PortService.ShipStatus.Arrived:
                        row.DefaultCellStyle.BackColor = Color.LightGreen;
                        break;

                    case PortService.ShipStatus.Expected:
                        row.DefaultCellStyle.BackColor = Color.LightPink;
                        break;

                    case PortService.ShipStatus.Unknown:
                        row.DefaultCellStyle.BackColor = Color.LightYellow;
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    // vessel name is empty, this can happen if excel has not been updated yet
                    // in such case, mark as unknown
                    row.DefaultCellStyle.BackColor = Color.LightYellow;
                    toolTipStr = "Vessel not found";
                }

                // add tool tip with additional data about this ship
                foreach (DataGridViewCell cell in row.Cells)
                {
                    cell.ToolTipText = toolTipStr;
                }
            }

            //sailsDataGrid.DefaultCellStyle.Font = new Font(new FontFamily("Calibri"), 10f);
            arrivalsDataGrid.AutoGenerateColumns = true;
            arrivalsDataGrid.AutoResizeColumns();
            arrivalsDataGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;

            arrivalsDataGrid.Invoke(new MethodInvoker(delegate
            {
                arrivalsDataGrid.Refresh();
            }));

            initCompleteCB();
        }
Пример #2
0
        // function updates today's arrivals data grid
        private void updateArrivalsGrid()
        {
            List <Common.Order> resultList = new List <Common.Order>();
            DateTime            now        = DateTime.Now;
            string str = string.Empty;

            // filter only needed customer (all the customers in the list)
            foreach (Common.Customer customer in Common.customerList)
            {
                resultList.AddRange(Outlook.filterCustomersByName(customer.name, customer.alias));
            }

#if OFFLINE
            // for testing purposes, since there might be no arrivals today, take several random arrivals
            resultList = resultList.Where(x => x.arrivalDate.Date >= DateTime.Now.Date)
                         .Take(6)
                         .OrderBy(x => x.consignee)
                         .Distinct()
                         .ToList();
#else
            // filter only today's arrival dates
            // filter only loadings sent from the country of the agent
            // order by consignee
            resultList = resultList.Where(x => x.arrivalDate.Date == DateTime.Now.Date)
                         .OrderBy(x => x.consignee)
                         .Distinct()
                         .ToList();
#endif

            // check if customer has orders
            if (resultList.Count == 0)
            {
                str = "No new arrivals today";
                log(str);
                updateLabel(arrivals_lbl, str);
                initCompleteCB();
                return;
            }

            str = string.Format("{0} new arrivals today", resultList.Count);
            log(str);
            updateLabel(arrivals_lbl, str);

            // start async thread to get data from ports web
            // optimization: downloading data from web takes time, so do not do it
            // in case there are no arrivals today to this specific port
            if (Utils.bArrivalsToPort(resultList, PortService.PortName.Ashdod) == true)
            {
                PortService.getShipsFromPort(PortService.PortName.Ashdod);
            }

            if (Utils.bArrivalsToPort(resultList, PortService.PortName.Haifa) == true)
            {
                PortService.getShipsFromPort(PortService.PortName.Haifa);
            }

            // not all the columns are needed in the report - remove some
            List <Common.ArrivalsReport> targetResList = resultList.ConvertAll(x => new Common.ArrivalsReport
            {
                jobNo       = x.jobNo,
                consignee   = x.consignee,
                toPlace     = x.toPlace,
                vessel      = x.vessel,
                arrivalDate = x.arrivalDate,
            });

            // prepare DataTable to fill the grid
            DataTable table = Utils.generateDataTableFromList <Common.ArrivalsReport>(targetResList);

            arrivalsDataGrid.Invoke(new MethodInvoker(delegate
            {
                arrivalsDataGrid.AutoGenerateColumns = true;
                arrivalsDataGrid.DataSource          = table;
                arrivalsDataGrid.AutoResizeColumns();
                arrivalsDataGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
                arrivalsDataGrid.Refresh();
            }));
        }