/// <summary> /// 以文件为单位导入 /// </summary> /// <param name="cat"></param> /// <param name="files"></param> /// <returns>成功导入的数量</returns> private int ImportImg(DocDto cat, string[] files) { if (files == null) { return(0); } var qty = 0; var docDao = new DocImgDao(); var keyDao = new KeyDao(); foreach (var srcFile in files) { var docDto = ImportImg(docDao, keyDao, cat, srcFile); if (docDto == null) { continue; } _Docs.Add(docDto); qty += 1; } return(qty); }
/// <summary> /// 以目录为单位导入 /// </summary> /// <param name="dto"></param> /// <param name="path"></param> private int ImportCat(DocDto dto, string path) { var qty = 0; var dirs = Directory.GetDirectories(path); if (dirs != null) { var docDao = new DocDao(); foreach (var dir in dirs) { var catDto = new CatImgDto(); catDto.path = dir; catDto.names = Path.GetFileName(dir); catDto.pid = dto.id; docDao.Save(catDto); qty += ImportCat(catDto, path); } } var files = System.IO.Directory.GetFiles(path); qty += ImportImg(dto, files); return(qty); }
public void Init(MainWindow main, UserCfg cfg) { _Main = main; _Cfg = cfg; MyView.ItemsSource = _Docs; //MyView.SetBinding(ItemsControl.ItemsSourceProperty, _Docs); BindingOperations.EnableCollectionSynchronization(_Docs, _LockObj); var path = Path.Combine(cfg.RootDir, "img"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } _RootCat = new CatImgDto(); _RootCat.names = "我的照片"; _RootCat.path = path; _RootCat.id = CatDto.TYPE_60_CODE; _RootCat.Init(cfg); _CurrCat = _RootCat; MyCat.ItemsSource = _RootCat.CatList; }
/// <summary> /// 删除文件 /// </summary> /// <param name="doc"></param> private void DeleteImg(DocDto doc) { if (doc == null) { return; } new DocDao().Delete(doc.id); new KeyDao().Change(doc.key, -1); }
public IEnumerable <DocImgDto> ListDir(DocDto dto, Orderby orderby = null) { if (orderby == null) { orderby = new Orderby(); } var sql = @"SELECT a.[id], a.[pid], a.[key], a.[types], a.[modes], a.[names], a.[path], a.[remark], a.[update_time], a.[create_time] FROM[doc] a WHERE a.[pid] = @id AND a.[types] = @types"; sql += " AND a.[modes] = " + DocDto.MODE_10_CODE; sql += orderby.GenerateOrderBy("a."); return(Query <DocImgDto>(sql, dto)); }
/// <summary> /// 执行文件导入 /// </summary> /// <param name="docDao"></param> /// <param name="keyDao"></param> /// <param name="cat"></param> /// <param name="srcFile"></param> /// <returns></returns> private DocDto ImportImg(DocDao docDao, KeyDao keyDao, DocDto cat, string srcFile) { var name = Path.GetFileName(srcFile); var dstFile = DocDto.Combine(cat.FullRelativeFile, name); var docDto = new DocImgDto(); docDto.names = cat.GenDocName(name); docDto.path = dstFile; docDto.pid = cat.id; docDto.Init(_Cfg); var key = DocImgDto.GetFileHash(srcFile); if (string.IsNullOrEmpty(key)) { if (!docDto.ImportFile(srcFile, false)) { return(null); } } var keyDto = keyDao.Read(key); if (keyDto == null) { keyDto = new KeyDto(); keyDto.names = name; keyDto.key = key; keyDto.qty = 1; keyDto.file = dstFile; keyDao.Save(keyDto); if (!docDto.ImportFile(srcFile, false)) { return(null); } } else { keyDto.qty += 1; keyDao.Change(keyDto.id, 1); } docDto.key = keyDto.id; docDao.Save(docDto); return(docDto); }
private void MyCat_SelectedItemChanged(object sender, System.Windows.RoutedPropertyChangedEventArgs <object> e) { var doc = MyCat.SelectedItem as DocDto; if (doc == null) { return; } _CurrCat = doc; _Main.ShowUri(doc.FullRelativeFile); ListImgAsync(); }
public void ListTag(DocDto dto) { _Doc = dto; if (_Doc == null) { return; } var list = new TagDao().List(dto); TagList.Children.Clear(); foreach (var item in list) { ShowTag(item); _Tags.Add(item); } }
/// <summary> /// 创建目录 /// </summary> /// <param name="parent"></param> public void CreateCat(DocDto parent) { if (parent == null) { return; } parent.BuildCatKeys(); var dialog = new InputDialog(); var result = dialog.ShowDialog(_Main, (input, error) => { input = (input ?? "").Trim(); if (input == null) { error.Text = "请输入一个有效的目录名称:"; return(false); } if (parent.CatNameExist(input)) { error.Text = $"已存在名为 {input} 的目录!"; return(false); } var cat = new CatImgDto(); cat.names = input; cat.path = parent.FullRelativeFile + "/" + input; cat.pid = parent.id; cat.Init(_Cfg); parent.AppendCatItem(cat); new DocDao().Save(cat); if (!Directory.Exists(cat.FullPhysicalFile)) { Directory.CreateDirectory(cat.FullPhysicalFile); } return(true); }); }
private void ListDoc(DocDto doc) { _Docs.Clear(); var list = new DocImgDao().ListDoc(doc); var keyDao = new KeyDao(); foreach (var item in list) { item.Init(_Cfg); doc.AppendDocItem(item); var key = keyDao.Read <KeyDto>(item.key); if (key != null) { item.path = key.file; } item.Prepare(); _Docs.Add(item); } }
/// <summary> /// 删除目录 /// </summary> /// <param name="doc"></param> private void DeleteCat(DocDto doc) { var parent = doc.Parent; if (parent == null) { return; } var docDao = new DocDao(); var items = docDao.List <DocDto>(doc); if (items != null && items.GetEnumerator().MoveNext()) { MessageBox.Show("目录不为空,不能删除!"); return; } docDao.Delete(doc.id); parent.CatList.Remove(doc); }
/// <summary> /// 修改文件 /// </summary> /// <param name="doc"></param> private void UpdateImg(DocDto doc) { var parent = doc.Parent; if (parent == null) { return; } parent.BuildDocKeys(); var dialog = new InputDialog(); dialog.Text = doc.names; var result = dialog.ShowDialog(_Main, (input, error) => { input = (input ?? "").Trim(); if (input == null) { error.Text = "请输入一个有效的文件名称:"; return(false); } if (input.ToUpper() != doc.names.ToUpper()) { if (parent.CatNameExist(input)) { error.Text = $"已存在名为 {input} 的文件!"; return(false); } } doc.names = input; new DocDao().Save(doc); return(true); }); }
/// <summary> /// 更新目录 /// </summary> /// <param name="node"></param> /// <param name="doc"></param> public void UpdateCat(DocDto doc) { var parent = doc.Parent; if (parent == null) { return; } parent.BuildCatKeys(); var dialog = new InputDialog(); dialog.Text = doc.names; var result = dialog.ShowDialog(_Main, (input, error) => { input = (input ?? "").Trim(); if (input == null) { error.Text = "请输入一个有效的目录名称:"; return(false); } if (input.ToUpper() != doc.names.ToUpper()) { if (parent.CatNameExist(input)) { error.Text = $"已存在名为 {input} 的目录!"; return(false); } } doc.path = parent.FullRelativeFile + "/" + input; doc.names = input; new DocDao().Save(doc); return(true); }); }
public static DocDpo GetInstance(DocDto dto) { return(null); }
public IEnumerable <TagDto> List(DocDto dto) { var sql = $"SELECT b.[id],b.[qty],b.[names],a.[update_time],a.[create_time] FROM [tag_doc] a,[tag] b WHERE a.[tag_id] = b.[id] AND a.[doc_id] = {dto.id} ORDER BY b.[qty] desc"; return(Query <TagDto>(sql)); }