Beispiel #1
0
 private void addSeriesCatalog()
 {
     //call stored procedure spUpdateSeriesCatalog
     db.createSeriesCatalog();
 }
Beispiel #2
0
        public void saveFiles2012()
        {
            //db = new clsDatabase(HucNumber);
            string dirpath = Properties.Settings.Default.filePath + "\\2012 data";

            DirectoryInfo di = new DirectoryInfo(dirpath);

            //Dim txtFile As System.IO.File
            StreamReader txtStreamReader;
            string       strLine;

            string[] arrSplitLine;
            //int i = 0;
            List <int> hucs = new List <int>();

            double   DataValue;
            DateTime LocalDateTime;
            int      UTCOffset;
            DateTime DateTimeUTC;
            int      SiteID;
            int      VariableID;
            int      MethodID = 1;
            int      SourceID = 1;
            int      QualityControlLevelID = 1;


            //Get the Sites from the database
            string strError;

            // Loop through the .gz files in the directory, decompress them and then load them into
            // the SQL Server Database.

            foreach (FileInfo file in di.GetFiles("*.txt"))
            {
                int HucNumber = 0;
                if (file.Name.StartsWith("h8"))
                {
                    HucNumber = 8;
                }
                else if (file.Name.StartsWith("h0"))
                {
                    HucNumber = 10;
                }
                else if (file.Name.StartsWith("h2"))
                {
                    HucNumber = 12;
                }


                //#if DEBUG
                //                    db = new clsDatabase(8);
                //#else
                if (HucNumber == 10)
                {
                    db = new clsDatabase(HucNumber);
                    //#endif
                    // int ValueID = db.getValueID() + 1;
                    //i = 0;
                    txtStreamReader = File.OpenText(file.FullName);

                    //Figure out what kind of file it is (eg., snow, SWE, snow depth)
                    // and Set the VariableID baseed on variabletype
                    if (file.Name.Contains("HP001_s"))
                    {
                        //The file contains Percent snow Cover
                        VariableID = 8;
                    }
                    else if (file.Name.Contains("11036tS_"))
                    {
                        //The file contains snow depth data
                        VariableID = 2;
                    }
                    else
                    {
                        //The file contains snow water equivalent
                        VariableID = 1;
                    }



                    //Read the file and load each line as a new record into the ODM database
                    while ((strLine = txtStreamReader.ReadLine()) != null)
                    {
                        //Increment the line number counter
                        //i = i + 1;
                        //Read a line of the file and split it
                        arrSplitLine = strLine.Split('|');

                        //Construct the DataValues record to insert into the database
                        if (arrSplitLine.Length >= 3)
                        {
                            if (Information.IsNumeric(arrSplitLine[3]))
                            {
                                try
                                {
                                    //Get the SiteID for the site
                                    int siteID = db.getSite(arrSplitLine[0]);

                                    if (siteID > 0)
                                    {
                                        SiteID        = siteID;
                                        DataValue     = Convert.ToDouble(arrSplitLine[3]);
                                        LocalDateTime = Convert.ToDateTime(arrSplitLine[2].Split(' ')[0] + " 06:00");
                                        UTCOffset     = 0;
                                        DateTimeUTC   = LocalDateTime;
                                        values.Rows.Add(SqlInt32.Null, DataValue, SqlDouble.Null, LocalDateTime, UTCOffset /*utcoffset*/, DateTimeUTC, SiteID, VariableID, SqlDouble.Null, SqlInt32.Null, "nc", SqlInt32.Null, MethodID, SourceID, SqlInt32.Null, SqlInt32.Null, QualityControlLevelID);

                                        //ValueID += 1;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    strError = ex.ToString();
                                }
                            }
                        }
                    }
#if DEBUG
                    //Console.WriteLine(values.Rows[0][0]);
                    //HucNumber = 8;
                    if (HucNumber == 8)
                    {
                        db.insertBulk(values);
                    }
#else
                    db.insertBulk(values);
#endif
                    values.Clear();
                    txtStreamReader.Close();
                    //Delete the .txt file
                }
                foreach (int huc in hucs)
                {
                    db = new clsDatabase(huc);
                    db.createSeriesCatalog();
                }
            }
        }