示例#1
0
        public static DataTable LoadDataStructureList(string shortName, string version)
        {
            WebClient wc        = new WebClient();
            string    ds_string = wc.DownloadString(@"https://ndar.nih.gov/api/datadictionary/v2/datastructure/");

            NDAR.NDAR_DataStructure ds = JsonConvert.DeserializeObject <NDAR.NDAR_DataStructure>(ds_string, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            });

            //Create the data table for the dataElements
            DataTable dt = NDAR.NDAR_dataElements();

            foreach (NDAR.NDAR_DataElement de in ds.dataElements)
            {
                DataRow row = dt.NewRow();

                row["shortName"]     = shortName;
                row["id"]            = de.id;
                row["dataElementId"] = de.dataElementId;
                row["name"]          = de.name;
                row["description"]   = de.description;
                row["type"]          = de.type;

                row["required"]   = de.required;
                row["position"]   = de.position;
                row["valueRange"] = de.valueRange;

                dt.Rows.Add(row);
            }

            return(dt);
        }
示例#2
0
        public static string SaveToDB(string shortname)
        {
            NDAR.NDAR_DataStructure ds = NDAR.GetNDARDataStructure(shortname);

            DataTable dse = NDAR.NDARDataStructureElements_to_DataTable(ds);



            string results = "";
            //lblInfo.Text = "nrow = {" + dse.Rows.Count.ToString() + "}";
            SQL_utils sql = new SQL_utils();

            //Check is NDAR_DS exists
            int n_ds = sql.IntScalar_from_SQLstring(
                String.Format("select count(*) from NDAR_DS where shortname='{0}'", shortname));

            if (n_ds == 0)
            {
                // then insert DSE
                string code = String.Format("insert into ndar_ds (shortname, title, datatype, status ) values ('{0}', '{1}','{2}','{3}')"
                                            , ds.shortName, ds.title, ds.dataType, ds.status);

                sql.NonQuery_from_SQLstring(code);
            }

            //Check is NDAR_DS exists
            int n_dse = sql.IntScalar_from_SQLstring(
                String.Format("select count(*) from NDAR_DSE where shortname='{0}'", shortname));

            if (n_dse > 0)
            {
                sql.NonQuery_from_SQLstring(String.Format("delete from NDAR_DSE where shortname='{0}'", shortname));
            }

            SqlParameter p = sql.CreateParam("NDAR_DSE", dse);

            try
            {
                sql.NonQuery_from_ProcName("spNDAR_Insert_DSE", p);
                results = "Successfully imported " + shortname;
            }
            catch (Exception ex)
            {
                results = "Error: " + ex.Message;
            }

            sql.Close();
            return(results);
        }