Exemple #1
0
        private void ParseAmphoeChangwatName(String line, AmphoeComData data)
        {
            Int32 pos1 = line.IndexOf(EntityTypeHelper.EntityNames[EntityType.Amphoe]) + EntityTypeHelper.EntityNames[EntityType.Amphoe].Length;
            Int32 pos2 = line.IndexOf(" ");

            data.AmphoeName = line.Substring(pos1, pos2 - pos1);
            Int32 pos3 = line.IndexOf(EntityTypeHelper.EntityNames[EntityType.Changwat]) + EntityTypeHelper.EntityNames[EntityType.Changwat].Length;
            Int32 pos4 = line.IndexOf(SearchStringAmphoeChangwatEnd);

            data.ChangwatName = line.Substring(pos3, pos4 - pos3);
        }
Exemple #2
0
        private AmphoeComData Parse(Stream stream)
        {
            AmphoeComData retval      = new AmphoeComData();
            var           reader      = new StreamReader(stream, TambonHelper.ThaiEncoding);
            String        currentLine = String.Empty;
            StringBuilder entryData   = new StringBuilder();
            Int32         dataState   = 0;

            while ((currentLine = reader.ReadLine()) != null)
            {
                if (currentLine.Contains(SearchStringAmphoeChangwat))
                {
                    ParseAmphoeChangwatName(currentLine, retval);
                }
                else if (currentLine.Contains(SearchStringDataCaptionTop))
                {
                    if (currentLine.Contains(SearchStringChangwatSlogan))
                    {
                        dataState = 1;
                    }
                    else if (currentLine.Contains(SearchStringAmphoeSlogan))
                    {
                        dataState = 2;
                    }
                    else if (currentLine.Contains(SearchStringDistrictOffice))
                    {
                        dataState = 3;
                    }
                    else if (currentLine.Contains(SearchStringTelephone))
                    {
                        dataState = 4;
                    }
                    else if (currentLine.Contains(SearchStringFax))
                    {
                        dataState = 5;
                    }
                    else if (currentLine.Contains(SearchStringWebsite))
                    {
                        dataState = 6;
                    }
                }
                else if (currentLine.Contains(SearchStringHistory))
                {
                    dataState = 7;
                }
                else if (currentLine.Contains(SearchStringArea))
                {
                    dataState = 8;
                }
                else if (currentLine.Contains(SearchStringClimate))
                {
                    dataState = 9;
                }
                else if (currentLine.Contains(SearchStringTambon))
                {
                    retval.Tambon = ParseSubEntityNumber(currentLine);
                }
                else if (currentLine.Contains(SearchStringMuban))
                {
                    retval.Muban = ParseSubEntityNumber(currentLine);
                }
                else if (currentLine.Contains(SearchStringThesaban))
                {
                    retval.Thesaban = ParseSubEntityNumber(currentLine);
                }
                else if (currentLine.Contains(SearchStringTAO))
                {
                    retval.TAO = ParseSubEntityNumber(currentLine);
                }
                else if (currentLine.Contains(SearchStringDataLineEndTop))
                {
                    String tempString = ParseTopTableData(currentLine);
                    switch (dataState)
                    {
                    case 1:
                        retval.ChangwatSlogan = tempString;
                        break;

                    case 2:
                        retval.AmphoeSlogan = tempString;
                        break;

                    case 3:
                        retval.DistrictOffice = tempString;
                        break;

                    case 4:
                        retval.Telephone = tempString;
                        break;

                    case 5:
                        retval.Fax = tempString;
                        break;

                    case 6:
                        retval.Website = tempString;
                        break;
                    }
                }
                else if (currentLine.Contains(SearchStringDataBottom))
                {
                    String tempString = currentLine;

                    while (!tempString.Contains(SearchStringDataLineEnd))
                    {
                        if ((currentLine = reader.ReadLine()) == null)
                        {
                            break;
                        }
                        tempString = tempString + currentLine;
                    }
                    tempString = ParseSecondDataTable(tempString).Trim();
                    tempString = TrimMultiLine(tempString);
                    switch (dataState)
                    {
                    case 7:
                        retval.History = tempString;
                        dataState      = 0;
                        break;

                    case 8:
                        retval.Area = tempString;
                        dataState   = 0;
                        break;

                    case 9:
                        retval.Climate = tempString;
                        dataState      = 0;
                        break;
                    }
                }
            }
            return(retval);
        }
 private void ParseAmphoeChangwatName(String line, AmphoeComData data)
 {
     Int32 pos1 = line.IndexOf(EntityTypeHelper.EntityNames[EntityType.Amphoe]) + EntityTypeHelper.EntityNames[EntityType.Amphoe].Length;
     Int32 pos2 = line.IndexOf(" ");
     data.AmphoeName = line.Substring(pos1, pos2 - pos1);
     Int32 pos3 = line.IndexOf(EntityTypeHelper.EntityNames[EntityType.Changwat]) + EntityTypeHelper.EntityNames[EntityType.Changwat].Length;
     Int32 pos4 = line.IndexOf(SearchStringAmphoeChangwatEnd);
     data.ChangwatName = line.Substring(pos3, pos4 - pos3);
 }
        private AmphoeComData Parse(Stream stream)
        {
            AmphoeComData retval = new AmphoeComData();
            var reader = new StreamReader(stream, TambonHelper.ThaiEncoding);
            String currentLine = String.Empty;
            StringBuilder entryData = new StringBuilder();
            Int32 dataState = 0;
            while ( (currentLine = reader.ReadLine()) != null )
            {
                if ( currentLine.Contains(SearchStringAmphoeChangwat) )
                {
                    ParseAmphoeChangwatName(currentLine, retval);
                }
                else if ( currentLine.Contains(SearchStringDataCaptionTop) )
                {
                    if ( currentLine.Contains(SearchStringChangwatSlogan) )
                    {
                        dataState = 1;
                    }
                    else if ( currentLine.Contains(SearchStringAmphoeSlogan) )
                    {
                        dataState = 2;
                    }
                    else if ( currentLine.Contains(SearchStringDistrictOffice) )
                    {
                        dataState = 3;
                    }
                    else if ( currentLine.Contains(SearchStringTelephone) )
                    {
                        dataState = 4;
                    }
                    else if ( currentLine.Contains(SearchStringFax) )
                    {
                        dataState = 5;
                    }
                    else if ( currentLine.Contains(SearchStringWebsite) )
                    {
                        dataState = 6;
                    }
                }
                else if ( currentLine.Contains(SearchStringHistory) )
                {
                    dataState = 7;
                }
                else if ( currentLine.Contains(SearchStringArea) )
                {
                    dataState = 8;
                }
                else if ( currentLine.Contains(SearchStringClimate) )
                {
                    dataState = 9;
                }
                else if ( currentLine.Contains(SearchStringTambon) )
                {
                    retval.Tambon = ParseSubEntityNumber(currentLine);
                }
                else if ( currentLine.Contains(SearchStringMuban) )
                {
                    retval.Muban = ParseSubEntityNumber(currentLine);
                }
                else if ( currentLine.Contains(SearchStringThesaban) )
                {
                    retval.Thesaban = ParseSubEntityNumber(currentLine);
                }
                else if ( currentLine.Contains(SearchStringTAO) )
                {
                    retval.TAO = ParseSubEntityNumber(currentLine);
                }
                else if ( currentLine.Contains(SearchStringDataLineEndTop) )
                {
                    String tempString = ParseTopTableData(currentLine);
                    switch ( dataState )
                    {
                        case 1:
                            retval.ChangwatSlogan = tempString;
                            break;
                        case 2:
                            retval.AmphoeSlogan = tempString;
                            break;
                        case 3:
                            retval.DistrictOffice = tempString;
                            break;
                        case 4:
                            retval.Telephone = tempString;
                            break;
                        case 5:
                            retval.Fax = tempString;
                            break;
                        case 6:
                            retval.Website = tempString;
                            break;
                    }
                }
                else if ( currentLine.Contains(SearchStringDataBottom) )
                {
                    String tempString = currentLine;

                    while ( !tempString.Contains(SearchStringDataLineEnd) )
                    {
                        if ( (currentLine = reader.ReadLine()) == null )
                        {
                            break;
                        }
                        tempString = tempString + currentLine;
                    }
                    tempString = ParseSecondDataTable(tempString).Trim();
                    tempString = TrimMultiLine(tempString);
                    switch ( dataState )
                    {
                        case 7:
                            retval.History = tempString;
                            dataState = 0;
                            break;
                        case 8:
                            retval.Area = tempString;
                            dataState = 0;
                            break;
                        case 9:
                            retval.Climate = tempString;
                            dataState = 0;
                            break;
                    }
                }
            }
            return retval;
        }