using DataLoader.Model;
|
using Npgsql;
|
using System;
|
using System.Collections.Generic;
|
using System.Collections.ObjectModel;
|
using System.Data.Common;
|
using System.IO;
|
using System.Linq;
|
using System.Reflection;
|
|
namespace DataLoader.CS
|
{
|
public class Importor
|
{
|
private static PostgreHelper _ph = null;
|
|
public static PostgreHelper Helper
|
{
|
get
|
{
|
if (_ph == null) _ph = new PostgreHelper(DbEnum.langfang);
|
|
return _ph;
|
}
|
}
|
|
private static readonly string insertMeta = "insert into lf.sys_meta(name, dirid, depid, verid, type, sizes, cs, scale, resolution, gather, batch, descr, create_user) values @name, @dirid, @depid, @verid, @type, @sizes, @cs, @scale, @resolution, @gather, @batch, @descr, @create_user) returning id";
|
|
private static readonly string insertMetaFile = "insert into lf.sys_meta_file(name, metaid, fileid, guid, path, sizes, create_user) values (@name, @metaid, @fileid, @guid, @path, @sizes, @create_user)";
|
|
public static string GetFilePathByGuid(string guid)
|
{
|
string sql = "select path from lf.sys_meta_file where guid = @guid limit";
|
|
DbParameter dp = new NpgsqlParameter("@guid", guid);
|
object obj = Helper.GetScalar(sql, dp);
|
|
return obj == null ? null : obj.ToString();
|
}
|
|
public static int InsertMeta(SysMeta meta)
|
{
|
// string sql = "INSERT INTO public.data_files(mid, guid, name, ext, path, subs, remark) VALUES (@mid, @guid, @name, @ext, @path, @subs, @remark) returning id";
|
List<DbParameter> list = Tool.GetParams<SysMeta>(insertMeta, meta);
|
|
object obj = Helper.GetScalar(insertMeta, list.ToArray());
|
|
return obj == null ? 0 : Convert.ToInt32(obj);
|
}
|
|
public static int InsertMetaFile(SysMetaFile metaFile)
|
{
|
List<DbParameter> list = Tool.GetParams<SysMetaFile>(insertMetaFile, metaFile);
|
|
object obj = Helper.ExecuteNonQuery(insertMetaFile, list.ToArray());
|
|
return obj == null ? 0 : Convert.ToInt32(obj);
|
}
|
|
public static void Import(ObservableCollection<ViewData> viewDatas, string source, string target)
|
{
|
string[] files = Directory.GetFiles(source);
|
foreach (string file in files)
|
{
|
ViewData vd = new ViewData();
|
viewDatas.Add(vd);
|
|
|
}
|
|
for (int i = 0, c = files.Length; i < c; i++)
|
{
|
ViewData vd = new ViewData();
|
vd.ID = i + 1;
|
vd.FilePath = files[i];
|
vd.Status = "准备";
|
viewDatas.Add(vd);
|
|
SetSysMeta(vd);
|
}
|
}
|
|
private static void SetSysMeta(ViewData vd)
|
{
|
FileInfo fi = new FileInfo(vd.FilePath);
|
|
vd.Meta = new SysMeta();
|
vd.Meta.name = fi.Name;
|
vd.Meta.dirid = 0;
|
vd.Meta.depid = 0;
|
vd.Meta.verid = 0;
|
vd.Meta.type = "File";
|
vd.Meta.sizes = Tool.SizeToMb(fi.Length);
|
vd.Meta.cs = null;
|
vd.Meta.scale = null;
|
vd.Meta.resolution = null;
|
vd.Meta.gather = DateTime.Now;
|
vd.Meta.batch = null;
|
vd.Meta.descr = null;
|
vd.Meta.create_user = Tool.UserId;
|
}
|
}
|
}
|