using DataLoader.Model; using Npgsql; using System; using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Linq; namespace DataLoader.CS { /// /// 数据库帮助类 /// public class DBHelper { // id, eventid, metaid, verid, name, type, guid, path, sizes, tab, rows, create_user, create_time, update_user, update_time, bak, geom, layer, depcode, dircode, ismeta, sensortype, acq_time, resolution, gridsize, coor_sys, epsg, h_datum, mata_type, bands, band_type, ct public static string insertMeta = "insert into lf.sys_meta (eventid, metaid, verid, name, type, guid, path, sizes, tab, rows, create_user, create_time, bak, geom, layer, depcode, dircode, ismeta, sensortype, acq_time, resolution, gridsize, coor_sys, epsg, h_datum, mata_type, bands, band_type, ct) values (@eventid, @metaid, @verid, @name, @type, @guid, @path, @sizes, @tab, @rows, @create_user, now(), @bak, @geom, @layer, @depcode, @dircode, @ismeta, @sensortype, @acq_time, @resolution, @gridsize, @coor_sys, @epsg, @h_datum, @mata_type, @bands, @band_type, @ct) returning id"; /// /// 插入元数据 /// public int InsertMeta(List list) { PostgreHelper db = Tools.DBHelper; int count = 0; foreach (SysMeta meta in list) { List args = Tools.GetParams(insertMeta, meta) ; int id = db.GetIntScalar(insertMeta, args.ToArray()); if (id > 0) count++; } return count; } /// /// 根据GUID查询路径 /// public static string GetFilePathByGuid(string guid) { string sql = "select path from lf.sys_meta where guid = @guid limit 1"; DbParameter dp = new NpgsqlParameter("@guid", guid); object obj = Tools.DBHelper.GetScalar(sql, dp); return obj == null ? null : obj.ToString(); } /// /// 文件是/否存在 /// public static bool IsFileExists(string guid) { string sql = "select count(*) from lf.sys_meta where guid = @guid"; DbParameter dp = new NpgsqlParameter("@guid", guid); object obj = Tools.DBHelper.GetScalar(sql, dp); return obj != null && Convert.ToInt32(obj) > 0; } /// /// 获取目录列表 /// public static List GetDirList() { string sql = "select a.*, fn_get_fullname(a.code, 2) fullName from lf.sys_dir a"; DataTable dt = Tools.DBHelper.GetDataTable(sql); if (null == dt || dt.Rows.Count == 0) return null; List list = ModelHandler.FillModel(dt); return list; } } }