Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        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);
            }
        }