Beispiel #1
0
        static void Main(string[] args)
        {
            //args = new string[] { "{\"LST\":\"2017/03/17 00:59:00\",\"Type\":\"BC\"}", "{\"ConnectionString\":\"Data Source=211.144.122.59,3433;Initial Catalog=SEMCShare;Persist Security Info=True;User ID=sa;Password=diting\",\"TableName\":\"T_SuperStation1\",\"FilePath\":\"C:/Users/ZhangXiaoyi/Desktop/初始浓度.csv\",\"CreateTaskType\":\"MosaicLidar1\"}", "{}" }; //数据更换
            //args = new string[] { "{\"LST\":\"2017/01/03 00:59:00\",\"Type\":\"BC\"}", "{\"ConnectionString\":\"Data Source=10.1.14.62;Initial Catalog=SEMCShare;Persist Security Info=True;User ID=sa;Password=Diting2017\",\"FilePath\":\"E:/SMMCDatabase/SourceData/BC/\"}", "{}" };
            //args = new string[] { "{\"LST\":\"2016/06/11 22:00:00\"}", "{\"Type\":\"ScatCo\",\"ConnectionString\":\"Data Source=10.1.14.62;Initial Catalog=SEMCShare;Persist Security Info=True;User ID=sa;Password=Diting2017\",\"FilePath\":\"E:/SMMCDatabase/SourceData/Zhuoduyi/\"}", "{}" };
            //args = new string[] { "{\"LST\":\"2018/03/29 02:00:00\"}", "{\"Type\":\"OCEC\",\"ConnectionString\":\"Data Source=10.1.14.62;Initial Catalog=SEMCShare;Persist Security Info=True;User ID=sa;Password=Diting2017\",\"FilePath\":\"E:/SMMCDatabase/SourceData/OCEC/\"}", "{}" };
            //args = new string[] { "{\"LST\":\"2018/03/13 00:59:00\"}", "{\"Type\":\"Spectra\",\"ConnectionString\":\"Data Source=10.1.14.62;Initial Catalog=SEMCShare;Persist Security Info=True;User ID=sa;Password=Diting2017\",\"FilePath\":\"E:/SMMCDatabase/SourceData/SPAMS/\"}", "{}" };
            //args = new string[] { "{\"LST\":\"2018/03/13 16:59:00\"}", "{\"Type\":\"Spectra\",\"ConnectionString\":\"Data Source=localhost;Initial Catalog=SEMCShare;Persist Security Info=True;User ID=sa;Password=diting\",\"FilePath\":\"E:/1Readearth/S四川环科院/超级站/tempdata/单颗粒质谱\"}", "{}" };
            //args = new string[] { "{\"LST\":\"2018/03/29 02:00:00\"}", "{\"Type\":\"OCEC\",\"ConnectionString\":\"Data Source=localhost;Initial Catalog=SEMCShare;Persist Security Info=True;User ID=sa;Password=diting\",\"FilePath\":\"E:/1Readearth/S四川环科院/超级站/tempdata/OCEC/\"}", "{}" };

            ResolvePar resolvePar        = new ResolvePar(args);
            string     ConnectionStrings = resolvePar.TryGetValue("ConnectionString");
            DateTime   LST      = Convert.ToDateTime(resolvePar.TryGetValue("LST"));
            string     filepath = resolvePar.TryGetValue("FilePath");
            string     type     = resolvePar.TryGetValue("Type");
            //string tablename = resolvePar.TryGetValue("TableName");
            SuperStation super = new SuperStation(ConnectionStrings);

            super.Station = "环科院站";
            super.City    = "四川";
            super.Type    = type;
            if (super.Type == "Hmetal")
            {
                super.InsertToDBHmetal(LST, filepath);
            }
            else if (super.Type == "BC" || super.Type == "ScatCo")
            {
                super.InsertToDBMin(LST, filepath);
            }
            else if (super.Type == "OCEC" || super.Type == "Spectra")
            {
                super.InsertToDBHour(LST, filepath);
            }
            else
            {
                super.InsertToDB(filepath);
            }
        }
Beispiel #2
0
        static int Main(string[] args)
        {
            try
            {
                args = new string[] { "{\"LST\":\"2017/03/17 00:59:00\",\"Type\":\"外表入库\"}", "{\"ConnectionString\":\"Data Source=211.144.122.59,3433;Initial Catalog=SEMCShare;Persist Security Info=True;User ID=sa;Password=diting\",\"TableName\":\"T_SourceAclevel\",\"FilePath\":\"D:/SMMCDatabase/ModuleTest/DataSource/OMI/2017/20170201_104_DWD-MOHP.csv\",\"CreateTaskType\":\"MosaicLidar1\"}", "{}" };

                ResolvePar resolvePar = new ResolvePar(args);
                ConnectionStrings = resolvePar.TryGetValue("ConnectionString");
                m_Database        = new Database(ConnectionStrings);
                string       type           = resolvePar.TryGetValue("Type");
                DateTime     LST            = Convert.ToDateTime(resolvePar.TryGetValue("LST"));
                string       tablename      = resolvePar.TryGetValue("TableName");
                string       filename       = resolvePar.TryGetValue("FilePath");
                string       station        = "环科院站";
                string       city           = "上海";
                ScheduleTask m_ScheduleTask = new ScheduleTask(ConnectionStrings);
                if (type == "颗粒")
                {
                    DataTable Table = ToCSV(filename, ',');
                    foreach (DataRow row in Table.Rows)
                    {
                        DateTime starttime = Convert.ToDateTime(row[0]);
                        UpdateVarDb(row, station, type, city);
                    }
                }
                else if (type == "Hmetal")
                {
                    string csvpath = resolvePar.TryGetValue("DataBasePath") + "SourceData/Hmetal/" + LST.ToString("yyyy") + "/" + LST.ToString("yyyyMMdd") + "/" + LST.ToString("yyyyMMddHHmm") + ".txt";
                    if (File.Exists(csvpath))
                    {
                        if (LST.Minute > 30)
                        {
                            LST = Convert.ToDateTime(LST.ToString("yyyy-MM-dd HH:00:00")).AddHours(1);
                        }
                        else
                        {
                            LST = Convert.ToDateTime(LST.ToString("yyyy-MM-dd HH:00:00"));
                        }
                        UpdateDb(ToCSV(csvpath, ','), type, LST, city, station);
                    }
                }
                else if (type == "OMI")
                {
                    ExternalData.m_Database = m_Database;
                    DataTable sources = ExternalData.MonthColumnO3toDb(filename, type, station, city);
                    foreach (DataRow row in sources.Rows)
                    {
                        DateTime starttime = Convert.ToDateTime(row[0]);
                        UpdateVarDb(row, station, type, city);
                    }
                }
                else if (type == "外表入库")
                {
                    foreach (int itemid in Enum.GetValues(typeof(ITEM)))
                    {
                        string   temptype       = ((ITEM)itemid).ToString();
                        DateTime minmaxtime     = Convert.ToDateTime(m_Database.GetFirstValue("select max(lst) from  [ssta].[dbo].[" + temptype + "1]"));
                        string   strminlasttime = m_Database.GetFirstValue("select max(StartTime) from  T_SuperStationmin where  Type='" + temptype + "'");
                        if (temptype == "O3Leida")
                        {
                            strminlasttime = m_Database.GetFirstValue("select max(LST) from  T_Lidar where  Type like '" + temptype + "%'");
                        }
                        string   strlasttime = m_Database.GetFirstValue("select max(StartTime) from  T_SuperStation where  Type='" + temptype + "'");
                        DateTime minlasttime = minmaxtime.AddHours(-72);
                        DateTime lasttime    = Convert.ToDateTime(minmaxtime.AddHours(-72).ToString("yyyy-MM-dd HH:00:00"));
                        if (strminlasttime != "")
                        {
                            minlasttime = Convert.ToDateTime(strminlasttime);
                        }
                        if (strlasttime != "")
                        {
                            lasttime = Convert.ToDateTime(strlasttime);
                        }

                        ///////////
                        minlasttime = Convert.ToDateTime("2017/01/01 00:00:00");
                        minmaxtime  = Convert.ToDateTime("2017/01/31 00:00:00");
                        DataTable timelist = m_Database.GetDataset(string.Format("select distinct lst  from [ssta].[dbo].[{0}1] where  lst between '{1}' and  '{2}' order by  lst", temptype, minlasttime, minmaxtime)).Tables[0];
                        for (int i = 1; i < timelist.Rows.Count; i++)
                        {
                            DateTime  time    = Convert.ToDateTime(timelist.Rows[i][0]);
                            DataTable sources = m_Database.GetDataset(string.Format("select [parameterid] ,[value]  ,[opcode]  from [ssta].[dbo].[{0}1] where  lst='{1}'", temptype, time)).Tables[0];
                            try
                            {
                                if (temptype == "O3Leida")
                                {
                                    time    = CorrectTime(time, 20);
                                    sources = ExternalData.O3Lidar(sources, time, temptype);
                                    InsertLidarToDB(sources, temptype, time);
                                    string CreateTaskType = resolvePar.TryGetValue("CreateTaskType");

                                    if (CreateTaskType != null && time.Minute == 0)
                                    {
                                        var taskPro = m_ScheduleTask.taskPros.FirstOrDefault(p => p.Name == CreateTaskType);
                                        CreateTask.InsertTask(time, taskPro);
                                    }
                                }
                                else
                                {
                                    UpdateVarDb(sources, station, temptype, time, "T_SuperStationmin");
                                    if (temptype == "Sun")
                                    {
                                        double v        = 121.43561;
                                        double latitude = 31.17599;
                                        ExternalData.m_Database = m_Database;
                                        sources = ExternalData.CalAOD(v, latitude, time, sources);
                                        UpdateVarDb(sources, station, temptype, time, "T_SuperStation");
                                    }
                                }
                            }
                            catch { }
                            if (temptype == "Zhuoduji" || temptype == "Capsalb" || temptype == "Jvalues")
                            {
                                for (DateTime dtime = lasttime.AddHours(1); dtime < Convert.ToDateTime(time.ToString("yyyy-MM-dd HH:00:00")); dtime = dtime.AddHours(1))
                                {
                                    string Str_SQL = "select '" + dtime + "' as [StartTime]  ,'" + dtime.AddHours(1) + "' as [EndTime]  ,[City]  ,[Station]  ,[Item] ,avg([Value]) as [Value]  ,'' as [Quality]  ,[Type]  ,avg([DValue]) as [DValue]  ,'' as [OPCode] ,'' as [LMark]  ,'' as [HMark] ,'' as [State] from T_SuperStationmin where convert(varchar(13),StartTime,120)+':00:00'='" + dtime.ToString("yyyy-MM-dd HH:00:00") + "'  and   Type='" + temptype + "'  and  [DValue] !=-99 and  [Value]!=-99 group by  [City]  ,[Station], [Type],[Item] ";

                                    DataTable Table_Data = m_Database.GetDataset(Str_SQL).Tables[0];
                                    if (Table_Data.Rows.Count != 0)
                                    {
                                        UpdateDb(Table_Data, type, dtime, city, station);
                                    }
                                    lasttime = dtime;
                                }
                            }
                        }
                    }
                }
                else
                {
                    try
                    {
                        //string filename = resolvePar.TryGetValue("FilePath");
                        string    insertsql = "insert into " + tablename + " ([Year]  ,[Code]  ,[ParameterID]  ,[TypeCode]   ,[CLType]  ,[EcoCode]  ,[Value]) values ";
                        DataTable Table     = ToCSV(filename, ',');
                        int       typecode  = (int)Enum.Parse(typeof(TypeCode), type);
                        int       i         = 0;
                        foreach (DataRow row in Table.Rows)
                        {
                            int year = Convert.ToInt32(row[0]);
                            city = row[1].ToString();
                            string province = row[2].ToString();
                            int    code     = GetCode(city, province);
                            int    cltype   = -1;
                            int    ecocode  = -1;
                            for (int j = 3; j < Table.Columns.Count; j++)
                            {
                                if (Table.Columns[j].ColumnName.Contains("Column"))
                                {
                                    continue;
                                }
                                double value = 0;
                                try
                                {
                                    value = Convert.ToDouble(row[j]);
                                }
                                catch { }
                                int parameterid = GetParameterID(Table.Columns[j].ColumnName);
                                insertsql += string.Format("({0},{1},{2},{3},{4},{5},{6}),", year, code, parameterid, typecode, cltype, ecocode, value);
                                i++;
                                if (i > 900)
                                {
                                    m_Database.Execute(insertsql.Remove(insertsql.Length - 1));
                                    insertsql = "insert into " + tablename + " ([Year]  ,[Code]  ,[ParameterID]  ,[TypeCode]   ,[CLType]  ,[EcoCode]  ,[Value]) values ";
                                    i         = 0;
                                }
                            }
                        }
                        m_Database.Execute(insertsql.Remove(insertsql.Length - 1));
                    }
                    catch { }
                }
                return(2);
            }
            catch { return(-1); }
        }