Example #1
0
        // function generates list of anchoring ships in Ashdod port
        private static List <Common.Anchoring> generateTableForAshdodPort(DataSet dataSet)
        {
            string newLineStr = Environment.NewLine;

            string[] stringSeparators = new string[] { newLineStr };
            string   dateParseFormat  = "yyyy-MM-ddHH:mm";
            string   value            = string.Empty;

            string[] tmpArr = { };

            List <Common.Anchoring> anchoringPortList = new List <Common.Anchoring>();

            // there might be several tables, we assume that they have same format
            foreach (DataTable dt in dataSet.Tables)
            {
                // add all the records from a given table into AnchoringPortList
                // use Trim() only in case of splits, since all atomic variables are already trimmed
                foreach (DataRow row in dt.Rows)
                {
                    Common.Anchoring anchoringShip = new Common.Anchoring();

                    // col[0] last port
                    anchoringShip.lastPort = row[0].ToString();

                    // col[1] flag
                    anchoringShip.flag = row[1].ToString();

                    // col[2] arrival date
                    value = row[2].ToString().Replace(newLineStr, string.Empty);
                    if (string.IsNullOrEmpty(value) == false)
                    {
                        anchoringShip.arrivalDate = DateTime.ParseExact(value, dateParseFormat, CultureInfo.InvariantCulture);
                    }

                    // col[3] manifest
                    tmpArr = row[3].ToString().Split(stringSeparators, StringSplitOptions.None);
                    if (tmpArr.Length == 2)
                    {
                        anchoringShip.importManifest = Convert.ToInt32(tmpArr[0].Trim());
                        anchoringShip.exportManifest = Convert.ToInt32(tmpArr[1].Trim());
                    }

                    // col[4] cargo type
                    tmpArr = row[4].ToString().Split(stringSeparators, StringSplitOptions.None);
                    if (tmpArr.Length == 2)
                    {
                        anchoringShip.importCargo = tmpArr[0].Trim();
                        anchoringShip.exportCargo = tmpArr[1].Trim();
                    }

                    // col[5] place code
                    anchoringShip.status = row[5].ToString().Trim();

                    // col[6] yard status
                    anchoringShip.yardStatus = row[6].ToString().Trim();

                    // col[7] agent
                    anchoringShip.operatingAgent = row[7].ToString().Replace(newLineStr, string.Empty).Trim();

                    // col[8] scheduled
                    anchoringShip.bScheduled = false;
                    if (row[8].ToString().ToLower() == "yes")
                    {
                        anchoringShip.bScheduled = true;
                    }

                    // col[9] ship name
                    anchoringShip.shipName = row[9].ToString().Replace(newLineStr, string.Empty).Trim();

                    // row is ready, add to list
                    anchoringPortList.Add(anchoringShip);
                    anchoringShip = null;
                }
            }

            return(anchoringPortList);
        }
Example #2
0
        // function generates list of anchoring ships in Haifa port
        private static List <Common.Anchoring> generateTableForHaifaPort(DataSet dataSet)
        {
            string newLineStr = Environment.NewLine;

            string[] stringSeparators = new string[] { newLineStr };
            string   dateParseFormat  = "dd/MM/yy HH:mm";

            string[] tmpArr = { };

            List <Common.Anchoring> anchoringPortList = new List <Common.Anchoring>();

            // we assume only one table in the page - take the first one
            DataTable dt = dataSet.Tables[0];

            // add all the records from a given table into AnchoringPortList
            // use Trim() only in case of splits, since all atomic variables are already trimmed
            foreach (DataRow row in dt.Rows)
            {
                Common.Anchoring anchoringShip = new Common.Anchoring();

                // col[0] manifests
                // import and export manifests are in same column separated by new line
                // need to remove the '/' from manifest to cast into int
                string val = row[0].ToString().Replace("/", string.Empty);
                tmpArr = val.Split(stringSeparators, StringSplitOptions.None);
                if (tmpArr.Length == 2)
                {
                    // input validation - there might be cases of empty manifest
                    // in such case, manifest will remain 0
                    if (string.IsNullOrEmpty(tmpArr[0]) == false)
                    {
                        anchoringShip.importManifest = Convert.ToInt32(tmpArr[0].Trim());
                    }
                    if (string.IsNullOrEmpty(tmpArr[0]) == false)
                    {
                        anchoringShip.exportManifest = Convert.ToInt32(tmpArr[1].Trim());
                    }
                }

                // col[1] ship name
                anchoringShip.shipName = row[1].ToString().Replace(newLineStr, string.Empty);

                // col[2] cargo
                // import and export cargo are in same column separated by new line
                tmpArr = row[2].ToString().Split(stringSeparators, StringSplitOptions.None);
                if (tmpArr.Length == 2)
                {
                    anchoringShip.importCargo = tmpArr[0].Trim();
                    anchoringShip.exportCargo = tmpArr[1].Trim();
                }

                // col[3] status
                anchoringShip.status = row[3].ToString();

                // col[4] platform
                anchoringShip.platform = row[4].ToString();

                // col[5] operator
                anchoringShip.operatingAgent = row[5].ToString().Replace(newLineStr, string.Empty);

                // col[6] line
                anchoringShip.serviceLinePorts = row[6].ToString().Replace(newLineStr, string.Empty);

                // col[7] partners
                anchoringShip.partners = row[7].ToString().Replace(newLineStr, string.Empty);

                // col[8] export start time
                if (string.IsNullOrEmpty(row[8].ToString()) == false)
                {
                    anchoringShip.exportStartTime = DateTime.ParseExact(row[8].ToString(), dateParseFormat, CultureInfo.InvariantCulture);
                }

                // col[9] export end time
                if (string.IsNullOrEmpty(row[9].ToString()) == false)
                {
                    anchoringShip.exportEndTime = DateTime.ParseExact(row[9].ToString(), dateParseFormat, CultureInfo.InvariantCulture);
                }

                // col[10] arrival date
                if (string.IsNullOrEmpty(row[10].ToString()) == false)
                {
                    anchoringShip.arrivalDate = DateTime.ParseExact(row[10].ToString(), dateParseFormat, CultureInfo.InvariantCulture);
                }

                // row is ready, add to list
                anchoringPortList.Add(anchoringShip);
                anchoringShip = null;
            }

            return(anchoringPortList);
        }