Exemplo n.º 1
0
        public DataTable  ProcesAttachment(MailAtachment atachFile)
        {
            DataTable atachData = null;

            // System.Windows.Forms.MessageBox.Show(atachFile.Text);
            if (atachFile.file.Substring(atachFile.file.Length - 3, 3).ToLower() == "dbf")
            {
                Evento.SetEvento(DateTime.Now, DateTime.Now, "Parseando DBF");
                Evento.Save();
                atachData = ParseDBF.ReadDBF(atachFile.data);
                Evento.SetEvento(DateTime.Now, DateTime.Now, "Parseado Exitoso");
                Evento.Save();
                //System.Windows.Forms.MessageBox.Show(atachData.Columns.Count.ToString() + "dbf");
            }
            if (atachFile.file.Substring(atachFile.file.Length - 3, 3).ToLower() == "xls" || atachFile.file.Substring(atachFile.file.Length - 4, 4).ToLower() == "xlsx")
            {
                Evento.SetEvento(DateTime.Now, DateTime.Now, "Parseando Excel");
                Evento.Save();
                ExcelDataReader.ExcelDataReader rd;
                rd        = new ExcelDataReader.ExcelDataReader(atachFile.data);
                atachData = rd.TruColumnsTransform(rd.WorkbookData.Tables[0]);
                Evento.SetEvento(DateTime.Now, DateTime.Now, "Parseado Exitoso");
                Evento.Save();
                // System.Windows.Forms.MessageBox.Show(atachData.Columns.Count.ToString() + "Excel");
            }
            if (atachFile.file.Substring(atachFile.file.Length - 3, 3).ToLower() == "xml")
            {
                Evento.SetEvento(DateTime.Now, DateTime.Now, "Parseando Xml");
                Evento.Save();
                atachData = ParseXml(atachFile.data);
                Evento.SetEvento(DateTime.Now, DateTime.Now, "Parseado Exitoso");
                Evento.Save();
            }
            if (atachFile.file.Substring(atachFile.file.Length - 4, 4).ToLower() == "gzip")
            {
                Evento.SetEvento(DateTime.Now, DateTime.Now, "Descomprimiendo");
                Evento.Save();
                MemoryStream input = new MemoryStream();
                input.Write(atachFile.data, 0, atachFile.data.Length);
                input.Seek(0, SeekOrigin.Begin);
                GZipStream   gzip   = new GZipStream(input, CompressionMode.Decompress, true);
                MemoryStream output = new MemoryStream();

                byte[] buff = new byte[64];
                int    read = -1;
                read = gzip.Read(buff, 0, buff.Length);

                while (read > 0)
                {
                    output.Write(buff, 0, read);
                    read = gzip.Read(buff, 0, buff.Length);
                }
                gzip.Close();
                Evento.SetEvento(DateTime.Now, DateTime.Now, "Descomprimiendo Exitoso");
                Evento.Save();
                atachData = ParseXml(output.ToArray());
            }
            return(atachData);
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var dlg = new OpenFileDialog();

            if (dlg.ShowDialog().Value == true)
            {
                var dbf = ParseDBF.ReadDBF(dlg.FileName);
                table.ItemsSource = dbf.DefaultView;
            }
        }
Exemplo n.º 3
0
 private void loaddata()
 {
     try
     {
         DataTable dt = ParseDBF.ReadDBF(string.Format(@"{0}\stock_do.dbf", dsetting.Rows[0]["location"]));
     }
     catch (Exception ex)
     {
         // Do something with ex
         throw new Exception(ex.Message);
     }
 }
Exemplo n.º 4
0
 private void ReadDBF()
 {
     try
     {
         DataTable dt = ParseDBF.ReadDBF(path);
         InitTreeListControl(dt);
     }
     catch (Exception ex)
     {
         // Do something with ex
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 5
0
        private void btnLoadDBF_Click(object sender, System.EventArgs e)
        {
            try
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Filter = "dBASE files (*.dbf)|*.dbf";
                ofd.ShowDialog();

                if (ofd.FileName.Length > 0)
                {
                    DataTable dt = ParseDBF.ReadDBF(ofd.FileName);
                    grdDBF.DataSource = dt;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message + "\r\r" + ex.StackTrace, "Exception!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void search_Click(object sender, RoutedEventArgs e)
        {
            txtFile.Text = "";
            string txt = "";

            InputBox.Show("Search", "Text to search...", ref txt);

            FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();

            if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string[] files = Directory.GetFiles(folderBrowserDialog.SelectedPath, "*.dbf",
                                                    SearchOption.AllDirectories);

                foreach (var file in files)
                {
                    var dbf = ParseDBF.ReadDBF(file);

                    if (dbf != null)
                    {
                        foreach (DataColumn column in dbf.Columns)
                        {
                            foreach (DataRow row in dbf.Rows)
                            {
                                var wrt = row[column];
                                if (wrt != null && wrt.ToString().Contains(txt))
                                {
                                    txtFile.Text      = file;
                                    table.ItemsSource = dbf.DefaultView;
                                    goto finish;
                                }
                            }
                        }
                    }
                }

                txtFile.Text = "finish...";
            }

finish:
            ;
        }
Exemplo n.º 7
0
        public ShapefileReader(string filename)
        {
            // ESRI Shapefile Technical Description:
            //    http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf
            using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
            {
                // File Header:
                //
                // Position  Field         Value        Type     Byte Order
                // --------  -----         -----        ----     ----------
                // Byte 0    File Code     9994         Integer  Big
                // Byte 4    Unused        0            Integer  Big
                // Byte 8    Unused        0            Integer  Big
                // Byte 12   Unused        0            Integer  Big
                // Byte 16   Unused        0            Integer  Big
                // Byte 20   Unused        0            Integer  Big
                // Byte 24   File Length   File Length  Integer  Big
                // Byte 28   Version       1000         Integer  Little
                // Byte 32   Shape Type    Shape Type   Integer  Little
                // Byte 36   Bounding Box  Xmin         Double   Little
                // Byte 44   Bounding Box  Ymin         Double   Little
                // Byte 52   Bounding Box  Xmax         Double   Little
                // Byte 60   Bounding Box  Ymax         Double   Little
                // Byte 68*  Bounding Box  Zmin         Double   Little
                // Byte 76*  Bounding Box  Zmax         Double   Little
                // Byte 84*  Bounding Box  Mmin         Double   Little
                // Byte 92*  Bounding Box  Mmax         Double   Little
                //
                // * Unused, with value 0.0, if not Measured or Z type

                byte[] fileHeader = Read(fs, _fileHeaderLength);
                if (fileHeader == null)
                {
                    throw new InvalidDataException("Could not read shapefile header.");
                }

                _byteOrder = BitConverter.IsLittleEndian ? ByteOrder.LittleEndian : ByteOrder.BigEndian;
                int fileCode = ToInteger(fileHeader, 0, ByteOrder.BigEndian);;

                if (fileCode != _fileCode)
                {
                    throw new InvalidDataException("Could not read shapefile file code.  Is this a valid shapefile?");
                }

                int fileLengthInBytes = ToInteger(fileHeader, 24, ByteOrder.BigEndian) * 2;

                int version = ToInteger(fileHeader, 28, ByteOrder.LittleEndian);
                if (version != _version)
                {
                    throw new InvalidDataException("Shapefile version " + version + " is not supported.  Only version " + _version + " is supported.");
                }

                // If a .prj file exists, check to see if the projection is supported.
                string prjFilepath = Path.ChangeExtension(filename, "prj");
                if (File.Exists(prjFilepath))
                {
                    string prj        = System.IO.File.ReadAllText(prjFilepath);
                    string projection = @"PROJECTION";
                    string unit       = @"Degree";
                    if (Regex.IsMatch(prj, projection))
                    {
                        throw new InvalidDataException("Shapefile projection not supported.");
                    }
                    else if (!(Regex.IsMatch(prj, unit)))
                    {
                        throw new InvalidDataException("Shapefile units not supported. Only degrees is supported.");
                    }
                }

                _shapeType = (ShapeType)ToInteger(fileHeader, 32, ByteOrder.LittleEndian);

                double xMin = ToDouble(fileHeader, 36, ByteOrder.LittleEndian);
                double yMin = ToDouble(fileHeader, 44, ByteOrder.LittleEndian);
                double xMax = ToDouble(fileHeader, 52, ByteOrder.LittleEndian);
                double yMax = ToDouble(fileHeader, 60, ByteOrder.LittleEndian);

                if (fileLengthInBytes == _fileHeaderLength)
                {
                    // If the shapefile is empty (that is, has no records),
                    // the values for xMin, yMin, xMax, and yMax are unspecified.
                    //
                    // I like zero better.

                    xMin = 0.0;
                    yMin = 0.0;
                    xMax = 0.0;
                    yMax = 0.0;
                }

                _extent = new CartographicExtent(xMin, yMin, xMax, yMax);

                // Read each header...

                // Record Header:
                //
                // Position  Field           Value           Type     Byte Order
                // --------  -----           -----           ----     ----------
                // Byte 0    Record Number   Record Number   Integer  Big
                // Byte 4    Content Length  Content Length  Integer  Big

                _shapes = new List <Shape>();
                byte[] recordHeader;

                string    dBaseFilepath = Path.ChangeExtension(filename, "dbf");
                DataTable metadataTable = ParseDBF.ReadDBF(dBaseFilepath);

                while ((recordHeader = Read(fs, _recordHeaderLength)) != null)
                {
                    int    recordNumber         = ToInteger(recordHeader, 0, ByteOrder.BigEndian);
                    int    contextLengthInBytes = ToInteger(recordHeader, 4, ByteOrder.BigEndian) * 2;
                    byte[] record = Read(fs, contextLengthInBytes);
                    int    mOffset, zOffset;

                    StringDictionary metadata = new StringDictionary();
                    foreach (DataColumn column in metadataTable.Columns)
                    {
                        metadata.Add(column.ColumnName, Convert.ToString(metadataTable.Rows[recordNumber - 1][column]).Trim());
                    }

                    ShapeType recordShapeType = (ShapeType)ToInteger(record, 0, ByteOrder.LittleEndian);
                    switch (recordShapeType)
                    {
                    case ShapeType.NullShape:
                        // Filter out null shapes.  Otherwise, every client
                        // would have to deal with them.
                        break;

                    case ShapeType.Point:
                        double       x        = ToDouble(record, 4, ByteOrder.LittleEndian);
                        double       y        = ToDouble(record, 12, ByteOrder.LittleEndian);
                        Cartographic position = new Cartographic(x, y, 0.0);
                        _shapes.Add(new PointShape(recordNumber, metadata, position));
                        break;

                    case ShapeType.PointM:
                        x        = ToDouble(record, 4, ByteOrder.LittleEndian);
                        y        = ToDouble(record, 12, ByteOrder.LittleEndian);
                        position = new Cartographic(x, y, 0.0);
                        double measure = ToDouble(record, 20, ByteOrder.LittleEndian);
                        _shapes.Add(new PointMShape(recordNumber, metadata, position, measure));
                        break;

                    case ShapeType.PointZ:
                        x = ToDouble(record, 4, ByteOrder.LittleEndian);
                        y = ToDouble(record, 12, ByteOrder.LittleEndian);
                        double z = ToDouble(record, 20, ByteOrder.LittleEndian);
                        position = new Cartographic(x, y, z);
                        measure  = ToDouble(record, 28, ByteOrder.LittleEndian);
                        _shapes.Add(new PointZShape(recordNumber, metadata, position, measure));
                        break;

                    case ShapeType.MultiPoint:
                    case ShapeType.MultiPointM:
                    case ShapeType.MultiPointZ:
                        CartographicExtent extent = new CartographicExtent(
                            ToDouble(record, 4, ByteOrder.LittleEndian),
                            ToDouble(record, 12, ByteOrder.LittleEndian),
                            ToDouble(record, 20, ByteOrder.LittleEndian),
                            ToDouble(record, 28, ByteOrder.LittleEndian));

                        int            numberOfPoints = ToInteger(record, 36, ByteOrder.LittleEndian);
                        Cartographic[] points         = new Cartographic[numberOfPoints];
                        for (int i = 0; i < numberOfPoints; ++i)
                        {
                            points[i] = new Cartographic(
                                ToDouble(record, 40 + (16 * i), ByteOrder.LittleEndian),
                                ToDouble(record, 40 + (16 * i) + 8, ByteOrder.LittleEndian),
                                0.0);
                        }

                        if (recordShapeType == ShapeType.MultiPoint)
                        {
                            _shapes.Add(new MultiPointShape(recordNumber, metadata, extent, points));
                        }
                        else
                        {
                            mOffset = 40 + (16 * numberOfPoints);
                            zOffset = 40 + (16 * numberOfPoints);
                            if (recordShapeType == ShapeType.MultiPointZ)
                            {
                                mOffset = zOffset + 16 + (8 * numberOfPoints);
                            }

                            double   mMin     = ToDouble(record, mOffset, ByteOrder.LittleEndian);
                            double   mMax     = ToDouble(record, mOffset + 8, ByteOrder.LittleEndian);
                            double[] measures = new double[numberOfPoints];
                            for (int i = 0; i < numberOfPoints; i++)
                            {
                                measures[i] = ToDouble(record, mOffset + 16 + (8 * i), ByteOrder.LittleEndian);
                            }

                            if (recordShapeType == ShapeType.MultiPointM)
                            {
                                _shapes.Add(new MultiPointMShape(recordNumber, metadata, extent, points, mMin, mMax, measures));
                            }
                            else
                            {
                                double   zMin    = ToDouble(record, zOffset, ByteOrder.LittleEndian);
                                double   zMax    = ToDouble(record, zOffset + 8, ByteOrder.LittleEndian);
                                double[] zValues = new double[numberOfPoints];
                                for (int i = 0; i < numberOfPoints; i++)
                                {
                                    x         = points[i].Longitude;
                                    y         = points[i].Latitude;
                                    z         = ToDouble(record, zOffset + 16 + (8 * i), ByteOrder.LittleEndian);
                                    points[i] = new Cartographic(x, y, z);
                                }
                                _shapes.Add(new MultiPointZShape(recordNumber, metadata, extent, points, zMin, zMax, mMin, mMax, measures));
                            }
                        }

                        break;

                    case ShapeType.Polyline:
                    case ShapeType.PolylineM:
                    case ShapeType.PolylineZ:
                    case ShapeType.Polygon:
                    case ShapeType.PolygonM:
                    case ShapeType.PolygonZ:
                    case ShapeType.MultiPatch:
                        extent = new CartographicExtent(
                            ToDouble(record, 4, ByteOrder.LittleEndian),
                            ToDouble(record, 12, ByteOrder.LittleEndian),
                            ToDouble(record, 20, ByteOrder.LittleEndian),
                            ToDouble(record, 28, ByteOrder.LittleEndian));
                        int numberOfParts = ToInteger(record, 36, ByteOrder.LittleEndian);
                        numberOfPoints = ToInteger(record, 40, ByteOrder.LittleEndian);

                        int[]         parts     = new int[numberOfParts];
                        Rectangular[] positions = new Rectangular[numberOfPoints];

                        // These two loops can be optimized if the machine is little endian.
                        for (int i = 0; i < numberOfParts; ++i)
                        {
                            parts[i] = ToInteger(record, 44 + (4 * i), ByteOrder.LittleEndian);
                        }

                        int pointOffset    = 44 + (4 * numberOfParts);
                        int partTypeOffset = 44 + (4 * numberOfParts);
                        if (recordShapeType == ShapeType.MultiPatch)
                        {
                            pointOffset = partTypeOffset + (4 * numberOfParts);
                        }

                        for (int i = 0; i < numberOfPoints; ++i)
                        {
                            positions[i] = new Rectangular(
                                ToDouble(record, pointOffset + (16 * i), ByteOrder.LittleEndian),
                                ToDouble(record, pointOffset + (16 * i) + 8, ByteOrder.LittleEndian));
                        }

                        if (recordShapeType == ShapeType.Polyline)
                        {
                            _shapes.Add(new PolylineShape(recordNumber, metadata, extent, parts, positions));
                        }
                        else if (recordShapeType == ShapeType.Polygon)
                        {
                            _shapes.Add(new PolygonShape(recordNumber, metadata, extent, parts, positions));
                        }
                        else
                        {
                            mOffset = pointOffset + (16 * numberOfPoints);
                            zOffset = pointOffset + (16 * numberOfPoints);
                            if (recordShapeType == ShapeType.PolylineZ || recordShapeType == ShapeType.PolygonZ || recordShapeType == ShapeType.MultiPatch)
                            {
                                mOffset = zOffset + 16 + (8 * numberOfPoints);
                            }

                            double   mMin     = ToDouble(record, mOffset, ByteOrder.LittleEndian);
                            double   mMax     = ToDouble(record, mOffset + 8, ByteOrder.LittleEndian);
                            double[] measures = new double[numberOfPoints];
                            for (int i = 0; i < numberOfPoints; i++)
                            {
                                measures[i] = ToDouble(record, mOffset + 16 + (8 * i), ByteOrder.LittleEndian);
                            }

                            if (recordShapeType == ShapeType.PolylineM)
                            {
                                _shapes.Add(new PolylineMShape(recordNumber, metadata, extent, parts, positions, mMin, mMax, measures));
                            }
                            else if (recordShapeType == ShapeType.PolygonM)
                            {
                                _shapes.Add(new PolygonMShape(recordNumber, metadata, extent, parts, positions, mMin, mMax, measures));
                            }
                            else
                            {
                                double   zMin    = ToDouble(record, zOffset, ByteOrder.LittleEndian);
                                double   zMax    = ToDouble(record, zOffset + 8, ByteOrder.LittleEndian);
                                double[] zValues = new double[numberOfPoints];
                                for (int i = 0; i < numberOfPoints; i++)
                                {
                                    zValues[i] = ToDouble(record, zOffset + 16 + (8 * i), ByteOrder.LittleEndian);
                                }

                                if (recordShapeType == ShapeType.PolylineZ)
                                {
                                    _shapes.Add(new PolylineZShape(recordNumber, metadata, extent, parts, positions, zMin, zMax, zValues, mMin, mMax, measures));
                                }
                                else if (recordShapeType == ShapeType.PolygonZ)
                                {
                                    _shapes.Add(new PolygonZShape(recordNumber, metadata, extent, parts, positions, zMin, zMax, zValues, mMin, mMax, measures));
                                }
                                else
                                {
                                    MultiPatchPartType[] partTypes = new MultiPatchPartType[numberOfParts];
                                    for (int i = 0; i < numberOfParts; i++)
                                    {
                                        partTypes[i] = (MultiPatchPartType)ToInteger(record, partTypeOffset + (4 * i), ByteOrder.LittleEndian);
                                    }
                                    _shapes.Add(new MultiPatchShape(recordNumber, metadata, extent, parts, partTypes, positions, zMin, zMax, zValues, mMin, mMax, measures));
                                }
                            }
                        }

                        break;

                    default:
                        throw new NotImplementedException("The shapefile type is not supported.  Only null, point, polyline, and polygon are supported.");
                    }
                }
            }
        }
        /// <summary>
        /// Import information from databases contained in the DAFIF, will return Field, Runway, Nav and Comms information
        /// </summary>
        /// <param name="folderLocation">Location of the DAFIF in file system</param>
        /// <returns>Imported data</returns>
        public List <AirfieldInformation> fromDAFIF(string folderLocation)
        {
            //
            List <AirfieldInformation> importData = new List <AirfieldInformation>();

            // Set location of folders on disc
            string arptDir = folderLocation + @"\AVDAFIF\ARPT\ARPT.dbf";
            string rwyDir  = folderLocation + @"\AVDAFIF\RWY\RWY.dbf";
            string navhDir = folderLocation + @"\AVDAFIF\NAV\NAVH.dbf";
            string navlDir = folderLocation + @"\AVDAFIF\NAV\NAVL.dbf";
            string navtDir = folderLocation + @"\AVDAFIF\NAV\NAVT.dbf";
            string ilsDir  = folderLocation + @"\AVDAFIF\RWY\ILS.dbf";
            string acomDir = folderLocation + @"\AVDAFIF\ARPT\ACOM.dbf";

            // Import data from database using ParseDBF
            DataTable dtARPT = ParseDBF.ReadDBF(arptDir);
            DataTable dtRWY  = ParseDBF.ReadDBF(rwyDir);
            DataTable dtNAVH = ParseDBF.ReadDBF(navhDir);
            DataTable dtNAVL = ParseDBF.ReadDBF(navlDir);
            DataTable dtNAVT = ParseDBF.ReadDBF(navtDir);
            DataTable dtILS  = ParseDBF.ReadDBF(ilsDir);
            DataTable dtACOM = ParseDBF.ReadDBF(acomDir);

            // Import data
            foreach (DataRow rowL1 in dtARPT.Rows)
            {
                // Get field data
                Field fieldData = new Field(rowL1, dtARPT.Columns);

                // Create lists to store multiple data
                List <Runway>        runwaysData = new List <Runway>();
                List <NavigationAid> navData     = new List <NavigationAid>();
                List <Communication> commsData   = new List <Communication>();

                List <DataRow> foundRows = new List <DataRow>();

                // Get runway info for current field
                foundRows.Clear();
                foundRows.AddRange(dtRWY.Select("ARPT_IDENT = '" + fieldData.Ident + "'"));
                foreach (DataRow rowL2 in foundRows)
                {
                    runwaysData.Add(new Runway(rowL2, dtRWY.Columns));
                }

                // Nav
                foundRows.Clear();
                foundRows.AddRange(dtNAVH.Select("ARPT_ICAO = '" + fieldData.ICAO + "'"));
                foundRows.AddRange(dtNAVL.Select("ARPT_ICAO = '" + fieldData.ICAO + "'"));
                foundRows.AddRange(dtNAVT.Select("ARPT_ICAO = '" + fieldData.ICAO + "'"));
                foreach (DataRow rowL2 in foundRows)
                {
                    navData.Add(new NavigationAid(rowL2, dtNAVH.Columns, "NAV"));
                    if (fieldData.Country == null)
                    {
                        fieldData.Country = rowL2.ItemArray[dtNAVH.Columns.IndexOf("CTRY")].ToString().Trim();
                    }
                }
                // ILS
                foundRows.Clear();
                foundRows.AddRange(dtILS.Select("ARPT_IDENT = '" + fieldData.Ident + "'"));
                foreach (DataRow rowL2 in foundRows)
                {
                    navData.Add(new NavigationAid(rowL2, dtILS.Columns, "ILS"));
                }
                //Tidy nav list
                List <NavigationAid> navToRemove = new List <NavigationAid>();
                for (int i = 0; i < navData.Count - 1; i++)
                {
                    for (int j = i + 1; j < navData.Count; j++)
                    {
                        if (i == j)
                        {
                            continue;
                        }
                        if (navData[i].Ident == navData[j].Ident && navData[i].Type == navData[j].Type)
                        {
                            navToRemove.Add(navData[i]);
                        }
                        if (navData[i].Type == "GLIDE" && navData[j].Type == "LOC" && navData[i].Runway == navData[j].Runway)
                        {
                            navData[j].Type = "ILS"; navToRemove.Add(navData[i]);
                        }
                    }
                }
                foreach (NavigationAid n in navToRemove)
                {
                    navData.Remove(n);
                }

                // Comms
                foundRows.Clear();
                foundRows.AddRange(dtACOM.Select("ARPT_IDENT = '" + fieldData.Ident + "'"));
                foreach (DataRow rowL2 in foundRows)
                {
                    commsData.Add(new Communication(rowL2, dtACOM.Columns));
                }
                //Tidy Comms list
                List <Communication> commsToRemove = new List <Communication>();
                for (int i = 0; i < commsData.Count - 1; i++)
                {
                    for (int j = i + 1; j < commsData.Count; j++)
                    {
                        if (i == j)
                        {
                            continue;
                        }
                        if (commsData[i].Name == commsData[j].Name && commsData[i].Frequency_Pri == commsData[j].Frequency_Pri)
                        {
                            commsToRemove.Add(commsData[i]);
                        }
                    }
                }
                foreach (Communication c in commsToRemove)
                {
                    commsData.Remove(c);
                }
                commsData.Sort((x, y) => x.Name.CompareTo(y.Name));

                // Add current airfield to complete list of airfields
                importData.Add(new AirfieldInformation(fieldData, runwaysData, navData, commsData));
            }

            return(importData);
        }
Exemplo n.º 9
0
        public void openPartBase()
        {
            using (var context = new CCSpecialEntities())
            {
                DataTable dt = ParseDBF.ReadDBF(partbasepath);
                //grdDBF.DataSource = dt;
                JobNumber    = dt.Rows.OfType <DataRow>().Select(k => k[0].ToString()).ToArray();
                Unit         = dt.Rows.OfType <DataRow>().Select(k => k[1].ToString()).ToArray();
                PartNumber   = dt.Rows.OfType <DataRow>().Select(k => k[2].ToString().Trim()).ToArray();
                Desc         = dt.Rows.OfType <DataRow>().Select(k => k[3].ToString()).ToArray();
                Price        = dt.Rows.OfType <DataRow>().Select(k => k[4].ToString()).ToArray();
                PartsOnShelf = dt.Rows.OfType <DataRow>().Select(k => k[5].ToString()).ToArray();
                PartBin      = dt.Rows.OfType <DataRow>().Select(k => k[6].ToString()).ToArray();

                int Max = JobNumber.Length;

                int   OnShelf_ = 0;
                float Float_   = 0;

                var partbaserecords = context.PARTBASEs.ToList();

                //List<PARTBASE> NewRecordList = new List<PARTBASE>();
                PARTBASE row = new PARTBASE();

                for (int i = 1; i < Max; i++)
                {
                    row = partbaserecords.FirstOrDefault(x => PartNumber[i] == x.PartNumber.Trim());
                    if (row != null)
                    {
                        Int32.TryParse(PartsOnShelf[i], out OnShelf_);
                        row.OnShelf   = OnShelf_;
                        row.BoxNumber = PartBin[i];
                    }
                    else
                    {
                        PARTBASE NewRow = new PARTBASE();

                        float.TryParse(JobNumber[i], out Float_);
                        NewRow.JobNumber = (decimal)Float_;

                        NewRow.Unit = Unit[i];

                        NewRow.PartNumber  = PartNumber[i];
                        NewRow.Description = Desc[i];

                        float.TryParse(Price[i], out Float_);
                        NewRow.Price = (decimal)Float_;

                        Int32.TryParse(PartsOnShelf[i], out OnShelf_);
                        NewRow.OnShelf = OnShelf_;

                        NewRow.PartBaseID = Guid.NewGuid();

                        NewRow.BoxNumber = PartBin[i];

                        context.AddToPARTBASEs(NewRow);
                    }
                }
                // Update changes to PARTBASE SQL Table
                context.SaveChanges();
            }
        }