frmMultipFileImportThread.cs 92 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968
  1. 
  2. using LYFZ.PhotoSelectSystem;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Runtime.Serialization.Json;
  9. using System.Text;
  10. using System.Threading;
  11. namespace LYFZ.Software.MainBusiness.MultipleFileImport
  12. {
  13. /// <summary>
  14. /// 单利线程导入文件控制
  15. /// </summary>
  16. /// <remarks>2017-3-10 杨云奕 添加</remarks>
  17. public class frmMultipFileImportThread
  18. {
  19. bool bRestartThread = false;
  20. bool bStoping = false;
  21. bool bStoped = false;
  22. public bool threadStart = false;
  23. static frmMultipFileImportThread singleton=null;
  24. /// <summary>
  25. /// 线程
  26. /// </summary>
  27. public Thread threadWord;
  28. /// <summary>
  29. /// 定义的线程池
  30. /// </summary>
  31. public List<frmFileImportModel> data_Pools;
  32. /// <summary>
  33. /// 剩余上传数据集合
  34. /// </summary>
  35. List<frmFileImportBaseModel> baseList;
  36. /// <summary>
  37. /// 文件上传主界面消息监控提示事件
  38. /// </summary>
  39. /// <param name="StatusCode"></param>
  40. /// <param name="objectData"></param>
  41. public delegate void SingletonThreadImportFileHandler(enumImportMultipFie StatusCode, object objectData);
  42. public event SingletonThreadImportFileHandler SingletonThreadImportFileEvent;
  43. /// <summary>
  44. /// 文件上传管理界面事件,销毁管理界面,线程事件需要销毁
  45. /// </summary>
  46. public delegate void SingletonThreadImportFileFormHandler(enumImportMultipFieForm StatusCode, object objectData);
  47. public event SingletonThreadImportFileFormHandler SingletonThreadImportFileFormEvent;
  48. LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
  49. LYFZ.BLL.BLL_ErpOrderDigital digtalBll = new LYFZ.BLL.BLL_ErpOrderDigital();
  50. LYFZ.BLL.BLL_ErpPieceCommissionRecords pcrsbll = new BLL.BLL_ErpPieceCommissionRecords();
  51. Timer timer =null;
  52. public frmMultipFileImportThread()
  53. {
  54. data_Pools = new List<frmFileImportModel>();
  55. baseList = new List<frmFileImportBaseModel>();
  56. TimerCallback timeCallBack=new TimerCallback(TimerCallback);
  57. timer = new Timer(timeCallBack, null, 0, 500);
  58. }
  59. void TimerCallback(object state)
  60. {
  61. if (bRestartThread && (threadWord==null||threadWord.ThreadState == ThreadState.Aborted || threadWord.ThreadState == ThreadState.Stopped))
  62. {
  63. bRestartThread = false;
  64. threadWord = null;
  65. this.StartThread();
  66. }
  67. }
  68. /// <summary>
  69. /// 实例化单利模式
  70. /// </summary>
  71. /// <returns></returns>
  72. public static frmMultipFileImportThread GetSingleton()
  73. {
  74. if(singleton==null)
  75. {
  76. singleton = new frmMultipFileImportThread();
  77. }
  78. return singleton;
  79. }
  80. public void DeleteFromModel(frmFileImportModel model)
  81. {
  82. }
  83. public bool GetAutoImportAutoUp()
  84. {
  85. return Properties.Settings.Default.bImportAutoUp;
  86. }
  87. public void ThreadStop()
  88. {
  89. if(threadWord!=null&&threadWord.ThreadState== ThreadState.Running)
  90. {
  91. threadWord.Abort();
  92. threadStart = false;
  93. }
  94. LYFZ.Software.MainBusiness.MultipleFileImport.frmMultipFileImportThread.GetSingleton().ImportDataLogs(DateTime.Now.ToString() + " 线程停止" );
  95. }
  96. public List<frmFileImportModel> GetFileImportList()
  97. {
  98. return data_Pools;
  99. }
  100. public bool CheckOrderUp(frmFileImportModel data,Model.Model_ErpOrder.DirectoryType dirType,ref string fileExitsFile)
  101. {
  102. List<frmFileImportModel> list = data_Pools.FindAll(p => p.erpOrder.Ord_Number == data.erpOrder.Ord_Number && p.directoryType == dirType&&!p.Success);
  103. List<frmFileImportItemModel> allItemList=new List<frmFileImportItemModel>();
  104. bool bCheck = true;
  105. foreach(var mod in list)
  106. {
  107. //if (!mod.Success&&mod.)
  108. allItemList.AddRange(mod.local_Path.FindAll(p=>!p.success&&p.code!=1));
  109. }
  110. foreach (var item in data.local_Path)
  111. {
  112. var tempItem = allItemList.FindAll(p => Path.GetFileName(p.local_Path) == Path.GetFileName(item.local_Path));
  113. if(tempItem.Count>0)
  114. {
  115. fileExitsFile += "订单:" + data.erpOrder.Ord_Number + " 的导入图片队列中存在:" + Path.GetFileName(item.local_Path) + "\r\n";
  116. bCheck = false;
  117. }
  118. }
  119. if(!bCheck)
  120. {
  121. fileExitsFile=SaveCheckFileManage(fileExitsFile);
  122. }
  123. return bCheck;
  124. }
  125. /// <summary>
  126. /// 添加数据如线程池
  127. /// </summary>
  128. /// <param name="data">数据</param>
  129. public void AddDataToDataPools(frmFileImportModel data)
  130. {
  131. //if (data_Pools.FindAll(p =>
  132. // p.OrdNumber == data.OrdNumber &&
  133. // p.directoryType == data.directoryType &&
  134. // p.takenName==data.takenName&&
  135. // !p.Success
  136. // ).Count > 0)
  137. //{
  138. // return;
  139. //}
  140. //!Properties.Settings.Default.bImportAutoUp &&
  141. if ( (threadWord == null || threadWord.ThreadState == ThreadState.Aborted || threadWord.ThreadState == ThreadState.Stopped ))
  142. {
  143. data.errorMsg = "手动上传";
  144. }
  145. data_Pools.Add(data);
  146. baseList.Add(data.CloneBaseData());
  147. ///反馈主界面数量信息
  148. if (SingletonThreadImportFileEvent != null)
  149. {
  150. SingletonThreadImportFileEvent(enumImportMultipFie.Number, GetProThreadNumber());
  151. }
  152. ///反馈管理界面文件上传处理
  153. if (SingletonThreadImportFileFormEvent!=null)
  154. {
  155. SingletonThreadImportFileFormEvent(enumImportMultipFieForm.AddList, data);
  156. }
  157. ///判断是否自动上传,默认手动上传
  158. if(Properties.Settings.Default.bImportAutoUp)
  159. {
  160. // StartThread();
  161. }
  162. ImportDataLogs(DateTime.Now.ToString() + " 数据加入队列池\r\n");
  163. ImportTaskFileManager(data);
  164. }
  165. int GetProThreadNumber()
  166. {
  167. int totalNumber = 0;
  168. for (int i = 0; i < data_Pools.Count; i++)
  169. {
  170. if(data_Pools[i].local_Path.FindAll(p => p.code == 0).Count>0)
  171. {
  172. totalNumber++;
  173. }
  174. }
  175. return ((int)(totalNumber));
  176. }
  177. static bool isShowTipsIs64BitProcess = false;
  178. void TipsIs64BitProcess()
  179. {
  180. if (!isShowTipsIs64BitProcess)
  181. {
  182. isShowTipsIs64BitProcess = true;
  183. if (!Environment.Is64BitProcess)
  184. {
  185. ExMessageBoxCustom.Show("温馨提示:当前系统不是64位系统,导片相片处理时将因内存不足导入失败\r\n建义使用64位系统8GB以上内存的电脑上进行导片");
  186. }
  187. else
  188. {
  189. int memory = LYFZ.WinAPI.CustomPublicMethod.GetPhisicalMemory() / 1024;
  190. if (memory <= 0)
  191. {
  192. ExMessageBoxCustom.Show("温馨提示:当前系统内存不足1GB,导片相片处理时将因内存不足导入失败\r\n建义使用64位系统8GB以上内存的电脑上进行导片");
  193. }
  194. else if (memory < 4)
  195. {
  196. ExMessageBoxCustom.Show("温馨提示:当前系统内存低于4GB的最低要求,导片相片处理时将因内存不足导入失败\r\n建义使用64位系统8GB以上内存的电脑上进行导片");
  197. }
  198. }
  199. }
  200. }
  201. /// <summary>
  202. /// 执行线程
  203. /// </summary>
  204. public void StartThread()
  205. {
  206. bRestartThread = false;
  207. if(threadWord==null||threadWord.ThreadState== ThreadState.Aborted || threadWord.ThreadState == ThreadState.Stopped)
  208. {
  209. ///线程启动处理;
  210. threadWord = new Thread(new ThreadStart(delegate() {
  211. threadStart = true;
  212. ImportDataLogs(DateTime.Now.ToString()+" 导片队列开始执行\r\n");
  213. for(int i=0;i<data_Pools.Count;i++)
  214. {
  215. var mod = data_Pools[i];
  216. ///原片导入方法
  217. if(mod.directoryType== Model.Model_ErpOrder.DirectoryType.PrimitivePicture)
  218. {
  219. ImportDataLogs(DateTime.Now.ToString() + " 原片导入,订单编号:" + mod.OrdNumber + "\r\n");
  220. ImportFileByPrimitivePicture(mod, i);
  221. }
  222. else if (mod.directoryType== Model.Model_ErpOrder.DirectoryType.EarlyRetouch)
  223. {
  224. ImportDataLogs(DateTime.Now.ToString() + " 初修导入,订单编号:" + mod.OrdNumber + "\r\n");
  225. ImportFileByEarlyRetouch(mod, i);
  226. }
  227. else if(mod.directoryType== Model.Model_ErpOrder.DirectoryType.FineRetouch)
  228. {
  229. ImportDataLogs(DateTime.Now.ToString() + " 精修导入,订单编号:" + mod.OrdNumber + "\r\n");
  230. ImportRefinedRepairPiece(mod, i);
  231. }
  232. else if (mod.directoryType == Model.Model_ErpOrder.DirectoryType.DesignPiece)
  233. {
  234. ImportDataLogs(DateTime.Now.ToString() + " 设计导入,订单编号:" + mod.OrdNumber + "\r\n");
  235. ImportDesignPiece(mod, i);
  236. }
  237. }
  238. bool bSuccess = true ;
  239. threadStart = false;
  240. if (SingletonThreadImportFileEvent != null)
  241. {
  242. int taskNumber = 0;
  243. int totalNumber = 0;
  244. foreach (var mod in data_Pools)
  245. {
  246. foreach(var item in mod.local_Path)
  247. {
  248. if(!item.success&&item.code==-1)
  249. {
  250. totalNumber += 1;
  251. bSuccess = false;
  252. }
  253. }
  254. if(mod.local_Path.FindAll(p=>p.code==-1).Count>0)
  255. {
  256. taskNumber++;
  257. }
  258. }
  259. if (bSuccess)
  260. {
  261. SingletonThreadImportFileEvent(enumImportMultipFie.Process, "success");
  262. }
  263. else
  264. {
  265. SingletonThreadImportFileEvent(enumImportMultipFie.Process, taskNumber.ToString());
  266. }
  267. }
  268. ImportDataLogs(DateTime.Now.ToString() + " 导片结束\r\n");
  269. }));
  270. threadWord.Start();
  271. }
  272. else if(threadWord.ThreadState== ThreadState.Stopped)
  273. {
  274. threadWord = null;
  275. StartThread();
  276. }
  277. }
  278. #region 设计导入
  279. public bool CheckDesignPiece(frmFileImportModel mod,ref string okActive)
  280. {
  281. TipsIs64BitProcess();
  282. LYFZ.WinAPI.MyDriverInfo dInfo = LYFZ.WinAPI.CustomPublicMethod.GetDiskFreeSpace(mod.service_Path);
  283. string Ordpg_Sights = "";
  284. if (mod.sPh.PhotoModel!=null)
  285. {
  286. Ordpg_Sights=mod.sPh.PhotoModel.Ordpg_Sights;
  287. }
  288. if (dInfo.G_TotalFreeBytes < 3)
  289. {
  290. ExMessageBoxCustom.Show("服务器上保存设计片的目录容量小于 3GB 所以不能导入相片,请重新设置设计片保存目录。");
  291. return false;
  292. }
  293. try
  294. {
  295. LYFZ.BLL.BLL_ErpSystemLogs.WriteSystemLog(EnumPublic.SystemLogsType.相片导入导出,
  296. "" + LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name + "导入设计片[订单号:" + mod.erpOrder.Ord_Number + "/" + mod.erpOrder.Ord_SinceOrderNumber + "(" + mod.erpDigOrder.Ordv_ViceNumber + ")]" +Ordpg_Sights ,
  297. LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID,
  298. LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name);
  299. }
  300. catch { }
  301. // this.currentDigModel.Ordv_LookDesignStatus = "0";//测试用
  302. bool bl = false;
  303. List<string> hasBeenImportedPhotoList = mod.sPh.GetSpecifyTypePhotoList(Model.Model_ErpOrder.DirectoryType.DesignPiece, BLL.SelectPhotoHandling.PhotoType.Original, sightsName: Ordpg_Sights);
  304. if (hasBeenImportedPhotoList.Count > 0)
  305. {
  306. if (ExMessageBoxCustom.Show("当前订单(或拍摄阶段)已导入过设计片,请确认你选择的相片是没导入过的,否则会覆盖原来设计片。\r\n是否确定要继续导入?", msgBoxButton: System.Windows.Forms.MessageBoxButtons.YesNo) != System.Windows.Forms.DialogResult.Yes)
  307. {
  308. return false;
  309. }
  310. }
  311. LYFZ.EnumPublic.LookDesignStatusEnum currentLookDesignStatus = EnumPublic.LookDesignStatusEnum.未看;
  312. try
  313. {
  314. currentLookDesignStatus = (LYFZ.EnumPublic.LookDesignStatusEnum)Convert.ToInt32(mod.erpDigOrder.Ordv_LookDesignStatus);
  315. }
  316. catch { }
  317. if (currentLookDesignStatus == EnumPublic.LookDesignStatusEnum.OK)
  318. {
  319. ExMessageBoxCustom.Show("当前订单(或拍摄阶段)已经确认设计版,不能再导入设计版。");
  320. return false;
  321. }
  322. try
  323. {
  324. LYFZ.BLL.BLL_PhotoImportRecordTable.UpdatePhotoImportRecordTable(LYFZ.Model.Model_ErpOrder.DirectoryType.DesignPiece,
  325. mod.CurrentCompanyInfoID, mod.erpOrder.Ord_Number, 1, PhotoImportRecordType.Import);
  326. }
  327. catch (Exception ex)
  328. {
  329. ExMessageBoxCustom.Show("更新导片记录时失败:" + ex.Message);
  330. return false;
  331. }
  332. try
  333. {
  334. if (hasBeenImportedPhotoList.Count <= 0 && !mod.importGenerateThumbnails)
  335. {
  336. StartGenerateThumbnails(Model.Model_ErpOrder.DirectoryType.DesignPiece, mod.erpOrder.Ord_Number);
  337. }
  338. if (currentLookDesignStatus != EnumPublic.LookDesignStatusEnum.未看)
  339. {
  340. //LYFZ.BLL.BLL_ErpOrderDigital currentOrderDigBll = new BLL.BLL_ErpOrderDigital();
  341. if (ExMessageBoxCustom.Show("是否所有设计版修改完成?", msgBoxButton: System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
  342. {
  343. okActive = "AllPush";
  344. }
  345. else
  346. {
  347. okActive = "NotAllPush";
  348. }
  349. }
  350. return true;
  351. }
  352. catch (Exception ex)
  353. {
  354. ExMessageBoxCustom.Show(ex.Message);
  355. return true;
  356. }
  357. }
  358. public void ImportDesignPiece(frmFileImportModel mod, int i)
  359. {
  360. string Ordpg_Sights = "";
  361. if (mod.sPh.PhotoModel != null)
  362. {
  363. Ordpg_Sights = mod.sPh.PhotoModel.Ordpg_Sights;
  364. }
  365. List<string> hasBeenImportedPhotoList = mod.sPh.GetSpecifyTypePhotoList(Model.Model_ErpOrder.DirectoryType.DesignPiece, BLL.SelectPhotoHandling.PhotoType.Original, sightsName: Ordpg_Sights);
  366. bool bl = false;
  367. try
  368. {
  369. //string msg = mod.sPh.ImportDesignPiece(mod.comeDirectoryPath, mod.service_Path, mod.sPh.PhotoModel.Ordpg_Sights, null, mod.importGenerateThumbnails);
  370. string retString = "";
  371. string currentShootingName = Ordpg_Sights.Trim();
  372. Model.Model_ErpOrder.DirectoryType dirType = Model.Model_ErpOrder.DirectoryType.DesignPiece;
  373. string sourceDirectory = LYFZ.WinAPI.CustomPublicMethod.GetFullDirectoryPath(mod.comeDirectoryPath);
  374. if (currentShootingName.Length > 0)
  375. {
  376. //选择的来源目录下的目录集合,不含子目录
  377. string[] tempShootingNameDirectoryNames = System.IO.Directory.GetDirectories(sourceDirectory);
  378. //判断要导入的源目录下的子目录名是否为当前拍摄阶段名
  379. bool isCurrentTakenNameInDirName = false;
  380. if (tempShootingNameDirectoryNames.Length > 0)
  381. {
  382. string tempDirPath = "";
  383. foreach (string dirPath in tempShootingNameDirectoryNames)
  384. {
  385. string tempdirName = System.IO.Path.GetFileName(dirPath);
  386. if (tempdirName.ToLower() == currentShootingName.ToLower())
  387. {
  388. tempDirPath = dirPath;
  389. isCurrentTakenNameInDirName = true;
  390. break;
  391. }
  392. }
  393. if (isCurrentTakenNameInDirName && tempShootingNameDirectoryNames.Length > 1)
  394. {
  395. sourceDirectory = LYFZ.WinAPI.CustomPublicMethod.GetFullDirectoryPath(tempDirPath);
  396. }
  397. }
  398. }
  399. if (!Directory.Exists(sourceDirectory))
  400. {
  401. ExMessageBoxCustom.Show("未找到导片相应的文件夹目录,导片失败,请核实需导片的文件夹是否存在。");
  402. return;
  403. }
  404. List<string> sourcFileList = mod.sPh.GetLocalPhotoList(sourceDirectory);
  405. if (sourcFileList.Count <= 0)
  406. {
  407. retString = "您选择的目录下没有找到要导入的相片,请检查选择的目录是否正确。";
  408. }
  409. //总计数器
  410. float sumCount = sourcFileList.Count;
  411. //当前计数器
  412. int currentCount = 0;
  413. string toSavePath = LYFZ.WinAPI.CustomPublicMethod.GetFullDirectoryPath(mod.service_Path);
  414. //当前拍摄景点
  415. string currentTakenName = "";
  416. if (mod.sPh.PhotoModel != null)
  417. {
  418. currentTakenName = Ordpg_Sights;
  419. }
  420. foreach (string sourcFile in sourcFileList)
  421. {
  422. currentCount++;
  423. frmFileImportItemModel tempItem = mod.local_Path.Find(p => p.local_Path.Equals(sourcFile) && p.code == 0);
  424. if (tempItem == null)
  425. {
  426. continue;
  427. }
  428. tempItem.upload_Msg = "正在上传";
  429. ImportTaskFileManager(mod);
  430. ///管理窗体显示
  431. if (SingletonThreadImportFileFormEvent != null)
  432. {
  433. SingletonThreadImportFileFormEvent(enumImportMultipFieForm.BackNext, mod);
  434. }
  435. //this.SetBackgroundWorker(sumCount, currentCount, "正在导入相片,请稍等...", backgroundWorker);
  436. if (LYFZ.BLL.SelectPhotoHandling.ImportVerificationIsExplain(sourcFile)) { continue; }
  437. //要导入文件要在服务器中创建的目录
  438. string sourceDir = (System.IO.Path.GetDirectoryName(sourcFile) + "\\").Substring(sourceDirectory.Length);
  439. if (currentShootingName.Length > 0)
  440. {
  441. if (sourceDir.IndexOf(currentShootingName + "\\") == 0)
  442. {
  443. sourceDir = sourceDir.Substring(currentShootingName.Length + 1);
  444. }
  445. }
  446. string sourcFileName = System.IO.Path.GetFileName(sourcFile);
  447. string toSaveNewFilePath = toSavePath + sourceDir;
  448. string smallImagePath = toSaveNewFilePath + LYFZ.BLL.SelectPhotoHandling.PhotoType.Small + "\\";
  449. //创建目录
  450. if (!System.IO.Directory.Exists(toSavePath))
  451. {
  452. try
  453. {
  454. System.IO.Directory.CreateDirectory(toSavePath);
  455. }
  456. catch
  457. {
  458. retString = "服务器上目录路径不正确,请配置好服务器共享目录后重试!\r\n错误目录:" + toSavePath;
  459. break;
  460. }
  461. }
  462. #region 处理如果导入相片与已导入相片存在相同产品名且相片名也相同的情况替换已存在相片
  463. hasBeenImportedPhotoList = mod.sPh.GetSpecifyTypePhotoList(dirType, BLL.SelectPhotoHandling.PhotoType.Original, sightsName: currentTakenName);
  464. string sourcPhotoName = LYFZ.BLL.SelectPhotoHandling.GetDesignConfirmName(sourcFile, currentTakenName, mod.erpOrder.Ord_Number);
  465. string sameProductPhoto = "";
  466. foreach (string photoPath in hasBeenImportedPhotoList)
  467. {
  468. string beModifiedPhotoName = LYFZ.BLL.SelectPhotoHandling.GetDesignConfirmName(photoPath, currentTakenName, mod.erpOrder.Ord_Number);
  469. if (sourcPhotoName.ToLower() == beModifiedPhotoName.ToLower())
  470. {
  471. sameProductPhoto = photoPath;
  472. break;
  473. }
  474. }
  475. #endregion
  476. try
  477. {
  478. if (sameProductPhoto.Trim().Length > 0)
  479. {
  480. if (File.Exists(sourcFile))
  481. {
  482. if (!mod.sPh.ImportPhotoFile(System.IO.Path.GetDirectoryName(sameProductPhoto), sourcFile, true, mod.importGenerateThumbnails))
  483. {
  484. retString = "相片导入失败,可能待替换的相片被占用,请重启服务器电脑后重试";
  485. tempItem.success = false;
  486. tempItem.code = -1;
  487. tempItem.upload_Msg = "上传失败";
  488. ImportTaskFileManager(mod);
  489. }
  490. else
  491. {
  492. tempItem.success = true;
  493. tempItem.code = 1;
  494. tempItem.upload_Msg = "上传成功";
  495. //if (SingletonThreadImportFileEvent != null)
  496. //{
  497. // SingletonThreadImportFileEvent(enumImportMultipFie.Number, GetProThreadNumber());
  498. //}
  499. ImportTaskFileManager(mod);
  500. }
  501. }
  502. else
  503. {
  504. tempItem.success = false;
  505. tempItem.code = -1;
  506. tempItem.upload_Msg = "上传失败-文件不存在";
  507. ImportDataLogs(DateTime.Now.ToString() + " 文件导入失败,路径:" + sourcFile + ",文件不存在\r\n");
  508. ImportTaskFileManager(mod);
  509. }
  510. if (SingletonThreadImportFileFormEvent != null)
  511. {
  512. SingletonThreadImportFileFormEvent(enumImportMultipFieForm.BackNext, mod);
  513. }
  514. }
  515. else
  516. {
  517. if (File.Exists(sourcFile))
  518. {
  519. if (!mod.sPh.ImportPhotoFile(toSaveNewFilePath, sourcFile, true, mod.importGenerateThumbnails))
  520. {
  521. retString = "相片导入失败,服务器相片路径设置不正确,或没有写入权限,请重新设置后重试";
  522. tempItem.success = false;
  523. tempItem.code = -1;
  524. tempItem.upload_Msg = "上传失败";
  525. ImportTaskFileManager(mod);
  526. }
  527. else
  528. {
  529. tempItem.success = true;
  530. tempItem.code = 1;
  531. tempItem.upload_Msg = "上传成功";
  532. //if (SingletonThreadImportFileEvent != null)
  533. //{
  534. // SingletonThreadImportFileEvent(enumImportMultipFie.Number, GetProThreadNumber());
  535. //}
  536. ImportTaskFileManager(mod);
  537. }
  538. }
  539. else
  540. {
  541. tempItem.success = false;
  542. tempItem.code = -1;
  543. tempItem.upload_Msg = "上传失败-文件不存在";
  544. ImportDataLogs(DateTime.Now.ToString() + " 文件导入失败,路径:" + sourcFile + ",文件不存在\r\n");
  545. ImportTaskFileManager(mod);
  546. }
  547. if (SingletonThreadImportFileFormEvent != null)
  548. {
  549. SingletonThreadImportFileFormEvent(enumImportMultipFieForm.BackNext, mod);
  550. }
  551. }
  552. if (bRestartThread)
  553. {
  554. // threadWord.Abort();
  555. SingletonThreadImportFileEvent(enumImportMultipFie.Restart, null);
  556. }
  557. }
  558. catch (Exception ex)
  559. {
  560. retString = "相片导入时出错:" + ex.Message;
  561. }
  562. }
  563. List<frmFileImportItemModel> tempItemList = mod.local_Path.FindAll(p => p.code == 0);
  564. foreach (frmFileImportItemModel tempItem in tempItemList)
  565. {
  566. tempItem.success = false;
  567. tempItem.code = -1;
  568. tempItem.upload_Msg = "上传失败-文件不存在";
  569. ImportDataLogs(DateTime.Now.ToString() + " 文件导入失败,路径:" + tempItem.local_Path + ",文件不存在\r\n");
  570. ImportTaskFileManager(mod);
  571. if (SingletonThreadImportFileFormEvent != null)
  572. {
  573. SingletonThreadImportFileFormEvent(enumImportMultipFieForm.BackNext, mod);
  574. }
  575. }
  576. if (retString.Trim().Length > 0)
  577. {
  578. //ExMessageBoxCustom.Show(msg);
  579. ///反馈主界面数量信息
  580. /*if (SingletonThreadImportFileEvent != null)
  581. {
  582. SingletonThreadImportFileEvent(enumImportMultipFie.MsgError, "订单" + mod.erpOrder.Ord_Number + "" + retString);
  583. }*/
  584. mod.errorMsg = retString;
  585. }
  586. else
  587. {
  588. bl = true;
  589. mod.Success = true;
  590. if (mod.okActive == "AllPush")
  591. {
  592. LYFZ.BLL.BLL_ErpOrderDigital currentOrderDigBll = new BLL.BLL_ErpOrderDigital();
  593. mod.erpDigOrder.Ordv_LookDesignStatus = ((int)EnumPublic.LookDesignStatusEnum.已修改).ToString();
  594. if (currentOrderDigBll.SetLookDesignStatus(mod.erpDigOrder.Ordv_ViceNumber, mod.erpDigOrder.Ordv_LookDesignStatus))
  595. {
  596. //ExMessageBoxCustom.Show("导入成功,辛苦了!");
  597. }
  598. else if (mod.okActive == "NotAllPush")
  599. {
  600. /*if (SingletonThreadImportFileEvent != null)
  601. {
  602. SingletonThreadImportFileEvent(enumImportMultipFie.MsgError, "订单:" + mod.erpOrder.Ord_Number + "[设计]的设计状态更新失败!" );
  603. }*/
  604. mod.errorMsg += "订单:" + mod.erpOrder.Ord_Number + "[设计]的设计状态更新失败!";
  605. //ExMessageBoxCustom.Show("抱歉,看设计状态更新失败!");
  606. }
  607. }
  608. else
  609. {
  610. //ExMessageBoxCustom.Show("导入成功,辛苦了!其它设计版请尽快修改完成。");
  611. //SingletonThreadImportFileEvent(enumImportMultipFie.MsgError, "订单:" + mod.erpOrder.Ord_Number + "[设计]的设计状态更新失败!");
  612. }
  613. }
  614. ///开始操作
  615. if (bl)
  616. {
  617. /*LYFZ.Model.Model_ErpOrder modelOrder = orbll.GetModel("Ord_Number", StrOrdNumber);
  618. modelOrder.Ord_PhotoPath = sPh.UpdatePhotoImportDirectoryPath(Model.Model_ErpOrder.DirectoryType.FineRetouch, strprht.FullName);
  619. modelOrder.Ord_PhotoBackupPath = "NEW";
  620. modelOrder.Ord_UpdateDateTime = StrTime;
  621. modelOrder.Ord_UpdateName = StrUserName;
  622. clist.Add(orbll.GetImportPhotoUpdateOrder(modelOrder));*/
  623. mod.erpOrder.Ord_PhotoPath = mod.sPh.UpdatePhotoImportDirectoryPath(Model.Model_ErpOrder.DirectoryType.DesignPiece, mod.service_Path);
  624. mod.erpOrder.Ord_PhotoBackupPath = "NEW";
  625. mod.erpOrder.Ord_UpdateDateTime = SDateTime.Now;
  626. mod.erpOrder.Ord_UpdateName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
  627. List<LYFZ.Helper.CommandInfo> clist = new List<Helper.CommandInfo>();
  628. //clist.AddRange(mod.FrmClist);
  629. clist.Add(orbll.GetImportPhotoUpdateOrder(mod.erpOrder));
  630. //LYFZ.BLL.BLL_ErpOrderDigital odbll = new BLL.BLL_ErpOrderDigital();
  631. //LYFZ.Model.Model_ErpOrderDigital modelDigital = odbll.GetModel("Ordv_ViceNumber", mod.OrdViceNumber);
  632. //if (modelDigital.Ordv_DesignerStatus.Trim() != "2")
  633. //{
  634. // modelDigital.Ordv_DesignerName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
  635. // modelDigital.Ordv_DesignerTime = mod.erpOrder.Ord_UpdateDateTime;
  636. // modelDigital.Ordv_DesignerStatus = mod.StrStatus;
  637. //}
  638. //modelDigital.Ordv_UpdateDateTime = SDateTime.Now;
  639. //modelDigital.Ordv_UpdateName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
  640. //clist.Add(odbll.GetUpdateCommandInfo(modelDigital));
  641. //#region 导入设计片时,完成所有外发片
  642. //if (mod.StrStatus.Trim() == "2")
  643. //{
  644. // LYFZ.BLL.BLL_ErpOrderOutSendDesignList outbll = new BLL.BLL_ErpOrderOutSendDesignList();
  645. // List<LYFZ.Model.Model_ErpOrderOutSendDesignList> mlist = outbll.GetModelList("Odlst_OrdNumber = '" + mod.OrdNumber + "' and Odlst_ViceNumber = '" + mod.OrdViceNumber + "' and Odlst_SendVendor != ''");
  646. // for (int iz = 0; iz < mlist.Count; iz++)
  647. // {
  648. // if (mlist[iz].Odlst_CompletedStatus != "1")
  649. // {
  650. // mlist[iz].Odlst_CompletedStatus = "1";
  651. // mlist[iz].Odlst_CompletedTime = mod.erpOrder.Ord_UpdateDateTime;
  652. // mlist[iz].Odlst_CompletedName = mod.erpOrder.Ord_UpdateName;
  653. // mlist[iz].Odlst_CreateDatetime = mod.erpOrder.Ord_UpdateDateTime;
  654. // mlist[iz].Odlst_CreateName = mod.erpOrder.Ord_UpdateName;
  655. // clist.Add(outbll.GetUpdateCommandInfo(mlist[iz]));
  656. // }
  657. // }
  658. //}
  659. //#endregion
  660. pcrsbll.SetServicePhotographCount(LYFZ.Model.Model_ErpOrder.DirectoryType.DesignPiece, mod.erpDigOrder.Ordv_Number, mod.erpDigOrder.Ordv_ViceNumber, mod.takenName, "4");
  661. ///开始执行数据保存
  662. LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist);
  663. if (SingletonThreadImportFileEvent != null)
  664. {
  665. SingletonThreadImportFileEvent(enumImportMultipFie.Number, GetProThreadNumber());
  666. }
  667. }
  668. else if (mod.errorMsg.IndexOf("暂停") == -1)
  669. {
  670. mod.Success = false;
  671. mod.errorMsg = "导入失败";
  672. }
  673. }
  674. catch (Exception ex)
  675. {
  676. //ExMessageBoxCustom.Show(ex.Message);
  677. if (SingletonThreadImportFileEvent != null)
  678. {
  679. SingletonThreadImportFileEvent(enumImportMultipFie.MsgError, ex.Message);
  680. }
  681. }
  682. }
  683. #endregion
  684. #region 精修导入
  685. public bool CheckRefinedRepairPiece(frmFileImportModel mod)
  686. {
  687. TipsIs64BitProcess();
  688. LYFZ.WinAPI.MyDriverInfo dInfo = LYFZ.WinAPI.CustomPublicMethod.GetDiskFreeSpace(mod.service_Path);
  689. string Ordpg_Sights = "";
  690. if (mod.sPh.PhotoModel != null)
  691. {
  692. Ordpg_Sights = mod.sPh.PhotoModel.Ordpg_Sights;
  693. }
  694. if (dInfo.G_TotalFreeBytes < 3)
  695. {
  696. ExMessageBoxCustom.Show("服务器上保存精修片的目录容量小于 3GB 所以不能导入相片,请重新设置精修片保存目录。");
  697. return false;
  698. }
  699. List<string> hasBeenImportedPhotoList = mod.sPh.GetSpecifyTypePhotoList(Model.Model_ErpOrder.DirectoryType.FineRetouch, BLL.SelectPhotoHandling.PhotoType.Original, sightsName: Ordpg_Sights);
  700. if (hasBeenImportedPhotoList.Count > 0)
  701. {
  702. if (ExMessageBoxCustom.Show("当前订单(或拍摄阶段)已导入过精修片,请确认你选择的相片是没导入过的,否则会覆盖原来精修片。\r\n是否确定要继续导入?", msgBoxButton: System.Windows.Forms.MessageBoxButtons.YesNo) != System.Windows.Forms.DialogResult.Yes)
  703. {
  704. return false;
  705. }
  706. }
  707. try
  708. {
  709. LYFZ.BLL.BLL_PhotoImportRecordTable.UpdatePhotoImportRecordTable(LYFZ.Model.Model_ErpOrder.DirectoryType.FineRetouch, mod.CurrentCompanyInfoID, mod.erpOrder.Ord_Number, 1, PhotoImportRecordType.Import);
  710. }
  711. catch (Exception ex)
  712. {
  713. ExMessageBoxCustom.Show("更新导片记录时失败:" + ex.Message);
  714. return false;
  715. }
  716. return true;
  717. }
  718. public void ImportRefinedRepairPiece(frmFileImportModel mod,int i)
  719. {
  720. string Ordpg_Sights = "";
  721. if (mod.sPh.PhotoModel != null)
  722. {
  723. Ordpg_Sights = mod.sPh.PhotoModel.Ordpg_Sights;
  724. }
  725. List<string> hasBeenImportedPhotoList = mod.sPh.GetSpecifyTypePhotoList(Model.Model_ErpOrder.DirectoryType.FineRetouch, BLL.SelectPhotoHandling.PhotoType.Original, sightsName: Ordpg_Sights);
  726. bool bl = false;
  727. try
  728. {
  729. if (hasBeenImportedPhotoList.Count <= 0 && !mod.importGenerateThumbnails)
  730. {
  731. StartGenerateThumbnails(Model.Model_ErpOrder.DirectoryType.FineRetouch, mod.erpOrder.Ord_Number);
  732. }
  733. try
  734. {
  735. LYFZ.BLL.BLL_ErpSystemLogs.WriteSystemLog(EnumPublic.SystemLogsType.相片导入导出,
  736. "" + LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name + "导入精修片[订单号:" + mod.erpOrder.Ord_Number + "/" + mod.erpOrder.Ord_SinceOrderNumber + "(" + mod.erpDigOrder.Ordv_ViceNumber + ")]" + Ordpg_Sights,
  737. LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID,
  738. LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name);
  739. }
  740. catch { }
  741. //string msg = mod.sPh.ImportDesignPiece(mod.comeDirectoryPath, mod.service_Path, mod.sPh.PhotoModel.Ordpg_Sights, null, mod.importGenerateThumbnails);
  742. string retString = "";
  743. string currentShootingName = Ordpg_Sights.Trim();
  744. Model.Model_ErpOrder.DirectoryType dirType = Model.Model_ErpOrder.DirectoryType.FineRetouch;
  745. string sourceDirectory = LYFZ.WinAPI.CustomPublicMethod.GetFullDirectoryPath(mod.comeDirectoryPath);
  746. if (currentShootingName.Length > 0)
  747. {
  748. //选择的来源目录下的目录集合,不含子目录
  749. string[] tempShootingNameDirectoryNames = System.IO.Directory.GetDirectories(sourceDirectory);
  750. //判断要导入的源目录下的子目录名是否为当前拍摄阶段名
  751. bool isCurrentTakenNameInDirName = false;
  752. if (tempShootingNameDirectoryNames.Length > 0)
  753. {
  754. string tempDirPath = "";
  755. foreach (string dirPath in tempShootingNameDirectoryNames)
  756. {
  757. string tempdirName = System.IO.Path.GetFileName(dirPath);
  758. if (tempdirName.ToLower() == currentShootingName.ToLower())
  759. {
  760. tempDirPath = dirPath;
  761. isCurrentTakenNameInDirName = true;
  762. break;
  763. }
  764. }
  765. if (isCurrentTakenNameInDirName && tempShootingNameDirectoryNames.Length > 1)
  766. {
  767. sourceDirectory = LYFZ.WinAPI.CustomPublicMethod.GetFullDirectoryPath(tempDirPath);
  768. }
  769. }
  770. }
  771. if (!Directory.Exists(sourceDirectory))
  772. {
  773. ExMessageBoxCustom.Show("未找到导片相应的文件夹目录,导片失败,请核实需导片的文件夹是否存在。");
  774. return ;
  775. }
  776. List<string> sourcFileList = mod.sPh.GetLocalPhotoList(sourceDirectory);
  777. if (sourcFileList.Count <= 0)
  778. {
  779. retString = "您选择的目录下没有找到要导入的相片,请检查选择的目录是否正确。";
  780. }
  781. //总计数器
  782. float sumCount = sourcFileList.Count;
  783. //当前计数器
  784. int currentCount = 0;
  785. string toSavePath = LYFZ.WinAPI.CustomPublicMethod.GetFullDirectoryPath(mod.service_Path);
  786. //当前拍摄景点
  787. string currentTakenName = "";
  788. if (mod.sPh.PhotoModel != null)
  789. {
  790. currentTakenName = Ordpg_Sights;
  791. }
  792. foreach (string sourcFile in sourcFileList)
  793. {
  794. currentCount++;
  795. frmFileImportItemModel tempItem = mod.local_Path.Find(p => p.local_Path.Equals(sourcFile) && p.code == 0);
  796. if (tempItem==null)
  797. {
  798. continue;
  799. }
  800. tempItem.upload_Msg = "正在上传";
  801. ImportTaskFileManager(mod);
  802. ///管理窗体显示
  803. if (SingletonThreadImportFileFormEvent != null)
  804. {
  805. SingletonThreadImportFileFormEvent(enumImportMultipFieForm.BackNext, mod);
  806. }
  807. //this.SetBackgroundWorker(sumCount, currentCount, "正在导入相片,请稍等...", backgroundWorker);
  808. if (LYFZ.BLL.SelectPhotoHandling.ImportVerificationIsExplain(sourcFile)) { continue; }
  809. //要导入文件要在服务器中创建的目录
  810. string sourceDir = (System.IO.Path.GetDirectoryName(sourcFile) + "\\").Substring(sourceDirectory.Length);
  811. if (currentShootingName.Length > 0)
  812. {
  813. if (sourceDir.IndexOf(currentShootingName + "\\") == 0)
  814. {
  815. sourceDir = sourceDir.Substring(currentShootingName.Length + 1);
  816. }
  817. }
  818. string sourcFileName = System.IO.Path.GetFileName(sourcFile);
  819. string toSaveNewFilePath = toSavePath + sourceDir;
  820. string smallImagePath = toSaveNewFilePath + LYFZ.BLL.SelectPhotoHandling.PhotoType.Small + "\\";
  821. //创建目录
  822. if (!System.IO.Directory.Exists(toSavePath))
  823. {
  824. try
  825. {
  826. System.IO.Directory.CreateDirectory(toSavePath);
  827. }
  828. catch
  829. {
  830. retString = "服务器上目录路径不正确,请配置好服务器共享目录后重试!\r\n错误目录:" + toSavePath;
  831. break;
  832. }
  833. }
  834. #region 处理如果导入相片与已导入相片存在相同产品名且相片名也相同的情况替换已存在相片
  835. hasBeenImportedPhotoList = mod.sPh.GetSpecifyTypePhotoList(dirType, BLL.SelectPhotoHandling.PhotoType.Original, sightsName: currentTakenName);
  836. string sourcPhotoName = LYFZ.BLL.SelectPhotoHandling.GetDesignConfirmName(sourcFile, currentTakenName, mod.erpOrder.Ord_Number);
  837. string sameProductPhoto = "";
  838. foreach (string photoPath in hasBeenImportedPhotoList)
  839. {
  840. string beModifiedPhotoName =LYFZ.BLL.SelectPhotoHandling.GetDesignConfirmName(photoPath, currentTakenName, mod.erpOrder.Ord_Number);
  841. if (sourcPhotoName.ToLower() == beModifiedPhotoName.ToLower())
  842. {
  843. sameProductPhoto = photoPath;
  844. break;
  845. }
  846. }
  847. #endregion
  848. try
  849. {
  850. if (sameProductPhoto.Trim().Length > 0)
  851. {
  852. if (File.Exists(sourcFile))
  853. {
  854. if (!mod.sPh.ImportPhotoFile(System.IO.Path.GetDirectoryName(sameProductPhoto), sourcFile, true, mod.importGenerateThumbnails))
  855. {
  856. retString = "相片导入失败,可能待替换的相片被占用,请重启服务器电脑后重试";
  857. tempItem.success = false;
  858. tempItem.code = -1;
  859. tempItem.upload_Msg = "上传失败";
  860. ImportTaskFileManager(mod);
  861. }
  862. else
  863. {
  864. tempItem.success = true;
  865. tempItem.code = 1;
  866. tempItem.upload_Msg = "上传成功";
  867. //if (SingletonThreadImportFileEvent != null)
  868. //{
  869. // SingletonThreadImportFileEvent(enumImportMultipFie.Number, GetProThreadNumber());
  870. //}
  871. ImportTaskFileManager(mod);
  872. }
  873. }
  874. else
  875. {
  876. tempItem.success = false;
  877. tempItem.code = -1;
  878. tempItem.upload_Msg = "上传失败-文件不存在";
  879. ImportDataLogs(DateTime.Now.ToString() + " 文件导入失败,路径:" + sourcFile + ",文件不存在\r\n");
  880. ImportTaskFileManager(mod);
  881. }
  882. if (SingletonThreadImportFileFormEvent != null)
  883. {
  884. SingletonThreadImportFileFormEvent(enumImportMultipFieForm.BackNext, mod);
  885. }
  886. }
  887. else
  888. {
  889. if (File.Exists(sourcFile))
  890. {
  891. if (!mod.sPh.ImportPhotoFile(toSaveNewFilePath, sourcFile, true, mod.importGenerateThumbnails))
  892. {
  893. retString = "相片导入失败,服务器相片路径设置不正确,或没有写入权限,请重新设置后重试";
  894. tempItem.success = false;
  895. tempItem.code = -1;
  896. tempItem.upload_Msg = "上传失败";
  897. ImportTaskFileManager(mod);
  898. }
  899. else
  900. {
  901. tempItem.success = true;
  902. tempItem.code = 1;
  903. tempItem.upload_Msg = "上传成功";
  904. //if (SingletonThreadImportFileEvent != null)
  905. //{
  906. // SingletonThreadImportFileEvent(enumImportMultipFie.Number, GetProThreadNumber());
  907. //}
  908. ImportTaskFileManager(mod);
  909. }
  910. }
  911. else
  912. {
  913. tempItem.success = false;
  914. tempItem.code = -1;
  915. tempItem.upload_Msg = "上传失败-文件不存在";
  916. ImportDataLogs(DateTime.Now.ToString() + " 文件导入失败,路径:" + sourcFile + ",文件不存在\r\n");
  917. ImportTaskFileManager(mod);
  918. }
  919. if (SingletonThreadImportFileFormEvent != null)
  920. {
  921. SingletonThreadImportFileFormEvent(enumImportMultipFieForm.BackNext, mod);
  922. }
  923. }
  924. if(bRestartThread)
  925. {
  926. //threadWord.Abort();
  927. SingletonThreadImportFileEvent(enumImportMultipFie.Restart, null);
  928. }
  929. }
  930. catch (Exception ex)
  931. {
  932. retString = "相片导入时出错:" + ex.Message;
  933. }
  934. }
  935. List<frmFileImportItemModel> tempItemList = mod.local_Path.FindAll(p => p.code == 0);
  936. foreach (frmFileImportItemModel tempItem in tempItemList)
  937. {
  938. tempItem.success = false;
  939. tempItem.code = -1;
  940. tempItem.upload_Msg = "上传失败-文件不存在";
  941. ImportDataLogs(DateTime.Now.ToString() + " 文件导入失败,路径:" + tempItem.local_Path + ",文件不存在\r\n");
  942. ImportTaskFileManager(mod);
  943. if (SingletonThreadImportFileFormEvent != null)
  944. {
  945. SingletonThreadImportFileFormEvent(enumImportMultipFieForm.BackNext, mod);
  946. }
  947. }
  948. if (retString.Trim().Length > 0)
  949. {
  950. //ExMessageBoxCustom.Show(msg);
  951. ///反馈主界面数量信息
  952. /*if (SingletonThreadImportFileEvent != null)
  953. {
  954. SingletonThreadImportFileEvent(enumImportMultipFie.MsgError, "订单" + mod.erpOrder.Ord_Number + "" + retString);
  955. }*/
  956. mod.errorMsg="订单" + mod.erpOrder.Ord_Number + "" + retString;
  957. }
  958. else
  959. {
  960. mod.Success = true;
  961. bl = true;
  962. }
  963. if (bl)
  964. {
  965. LYFZ.BLL.BLL_ErpOrderDigital odbll = new BLL.BLL_ErpOrderDigital();
  966. /*LYFZ.Model.Model_ErpOrder modelOrder = orbll.GetModel("Ord_Number", StrOrdNumber);
  967. modelOrder.Ord_PhotoPath = sPh.UpdatePhotoImportDirectoryPath(Model.Model_ErpOrder.DirectoryType.FineRetouch, strprht.FullName);
  968. modelOrder.Ord_PhotoBackupPath = "NEW";
  969. modelOrder.Ord_UpdateDateTime = StrTime;
  970. modelOrder.Ord_UpdateName = StrUserName;
  971. clist.Add(orbll.GetImportPhotoUpdateOrder(modelOrder));*/
  972. mod.erpOrder.Ord_PhotoPath = mod.sPh.UpdatePhotoImportDirectoryPath(Model.Model_ErpOrder.DirectoryType.FineRetouch, mod.service_Path);
  973. mod.erpOrder.Ord_PhotoBackupPath = "NEW";
  974. mod.erpOrder.Ord_UpdateDateTime = SDateTime.Now;
  975. mod.erpOrder.Ord_UpdateName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
  976. List<LYFZ.Helper.CommandInfo> clist = new List<Helper.CommandInfo>();
  977. //clist.AddRange(mod.FrmClist);
  978. clist.Add(orbll.GetImportPhotoUpdateOrder(mod.erpOrder));
  979. //LYFZ.Model.Model_ErpOrderDigital modelDigital = odbll.GetModel("Ordv_ViceNumber", mod.OrdViceNumber);
  980. //if (modelDigital.Ordv_RefinementStatus.Trim() != "2")
  981. //{
  982. // modelDigital.Ordv_RefinementName = mod.erpOrder.Ord_UpdateName;
  983. // modelDigital.Ordv_RefinementStatus = mod.StrStatus;
  984. // modelDigital.Ordv_RefinementTime = mod.erpOrder.Ord_UpdateDateTime;
  985. //}
  986. //modelDigital.Ordv_UpdateDateTime = mod.erpOrder.Ord_UpdateDateTime;
  987. //modelDigital.Ordv_UpdateName = mod.erpOrder.Ord_UpdateName;
  988. //clist.Add(odbll.GetUpdateCommandInfo(modelDigital));
  989. pcrsbll.SetServicePhotographCount(LYFZ.Model.Model_ErpOrder.DirectoryType.FineRetouch, mod.erpDigOrder.Ordv_Number, mod.erpDigOrder.Ordv_ViceNumber, mod.takenName, "5");
  990. LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist);
  991. if (SingletonThreadImportFileEvent != null)
  992. {
  993. SingletonThreadImportFileEvent(enumImportMultipFie.Number, GetProThreadNumber());
  994. }
  995. }
  996. else if (mod.errorMsg.IndexOf("暂停") == -1)
  997. {
  998. mod.Success = false;
  999. mod.errorMsg = "导入失败";
  1000. }
  1001. }
  1002. catch (Exception ex)
  1003. {
  1004. //ExMessageBoxCustom.Show(ex.Message);
  1005. if (SingletonThreadImportFileEvent != null)
  1006. {
  1007. SingletonThreadImportFileEvent(enumImportMultipFie.MsgError, ex.Message);
  1008. }
  1009. }
  1010. }
  1011. #endregion
  1012. #region 修片导入
  1013. public bool CheckImportFileByEarlyRetouch(frmFileImportModel mod)
  1014. {
  1015. TipsIs64BitProcess();
  1016. LYFZ.WinAPI.MyDriverInfo dInfo = LYFZ.WinAPI.CustomPublicMethod.GetDiskFreeSpace(mod.service_Path);
  1017. string Ordpg_Sights = "";
  1018. if (mod.sPh.PhotoModel != null)
  1019. {
  1020. Ordpg_Sights = mod.sPh.PhotoModel.Ordpg_Sights;
  1021. }
  1022. if (dInfo.G_TotalFreeBytes < 3)
  1023. {
  1024. ExMessageBoxCustom.Show("服务器上保存初修片的目录容量小于 3GB 所以不能导入相片,请重新设置初修片保存目录。");
  1025. return false;
  1026. }
  1027. bool bl = false;
  1028. if(!Directory.Exists(mod.comeDirectoryPath))
  1029. {
  1030. ExMessageBoxCustom.Show("未找到导片相应的文件夹目录,导片失败,请核实需导片的文件夹是否存在。");
  1031. return false;
  1032. }
  1033. //当前订单已导入相片集合
  1034. List<string> importedPhotoList = mod.sPh.GetLocalPhotoList(mod.comeDirectoryPath);
  1035. //总计数器
  1036. float sumCount = importedPhotoList.Count;
  1037. //当前计数器
  1038. int currentCount = 0;
  1039. string sightsName = "";//儿童版时的阶段
  1040. if ((EnumPublic.OrderType)Convert.ToInt32(mod.erpOrder.Ord_Type) == EnumPublic.OrderType.儿童订单)
  1041. {
  1042. sightsName = Ordpg_Sights;
  1043. }
  1044. //当前订单已导入原片相片集合
  1045. List<string> hasBeenImportedPhotoList = mod.sPh.GetSpecifyTypePhotoList(Model.Model_ErpOrder.DirectoryType.PrimitivePicture, BLL.SelectPhotoHandling.PhotoType.Original);
  1046. //当前订单已导入初修片相片集合
  1047. List<string> earlyRetouchImportedPhotoList = mod.sPh.GetSpecifyTypePhotoList(Model.Model_ErpOrder.DirectoryType.EarlyRetouch, BLL.SelectPhotoHandling.PhotoType.Original);
  1048. bool isImport = true;//是否导入相片
  1049. string sameNameLogsFilePath = "";
  1050. if (!mod.sPh.CheckPhotoExist(earlyRetouchImportedPhotoList, importedPhotoList, ref sameNameLogsFilePath))
  1051. {
  1052. isImport = true;
  1053. }
  1054. else
  1055. {
  1056. // ImportRepairPieceWarning importWarning = new ImportRepairPieceWarning("系统检测到要导入的相片名出现重名冲突,您可以选择断续导入将替换同名相片。\r\n也可以选择取消导入本次导入操作。", sameNameLogsFilePath);
  1057. ImportRepairPieceWarning importWarning = new ImportRepairPieceWarning("系统检测到要导入的相片名出现重名冲突,请选择取消导入本次的导入操作,删除同名相片或重命名后再导入。\r\n也可以选择继续导入替换已存在相片文件。", sameNameLogsFilePath);
  1058. importWarning.TopMost = true;
  1059. // importWarning.SbtnContinueImport.Visible = false;
  1060. if (importWarning.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  1061. {
  1062. isImport = true;
  1063. }
  1064. else
  1065. {
  1066. isImport = false;
  1067. }
  1068. }
  1069. try
  1070. {
  1071. LYFZ.BLL.BLL_PhotoImportRecordTable.UpdatePhotoImportRecordTable(LYFZ.Model.Model_ErpOrder.DirectoryType.EarlyRetouch, mod.CurrentCompanyInfoID, mod.erpOrder.Ord_Number, 1, PhotoImportRecordType.Import);
  1072. }
  1073. catch (Exception ex)
  1074. {
  1075. isImport = false;
  1076. bl = false;
  1077. ExMessageBoxCustom.Show("更新导片记录时失败:" + ex.Message);
  1078. }
  1079. if (isImport)
  1080. {
  1081. if (hasBeenImportedPhotoList.Count <= 0 || mod.sPh.CheckEarlyRepairInOriginalPhotoExist(hasBeenImportedPhotoList, mod.comeDirectoryPath, ref sameNameLogsFilePath))
  1082. {
  1083. isImport = true;
  1084. }
  1085. else
  1086. {
  1087. ImportRepairPieceWarning importWarning = new ImportRepairPieceWarning("系统检测到要导入的初修片可能不是来源与已导入的原片\r\n您可以选择断续导入但系统无法保证初修片与原片的一致性\r\n也可以选择取消导入本次导入操作。", sameNameLogsFilePath);
  1088. importWarning.TopMost = true;
  1089. if (importWarning.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  1090. {
  1091. isImport = true;
  1092. }
  1093. else
  1094. {
  1095. isImport = false;
  1096. }
  1097. }
  1098. }
  1099. return isImport;
  1100. }
  1101. void ImportFileByEarlyRetouch(frmFileImportModel mod, int i)
  1102. {
  1103. //if (!InternaNetworkAddress) { return false; }
  1104. if (!Directory.Exists(mod.comeDirectoryPath))
  1105. {
  1106. ExMessageBoxCustom.Show("未找到导片相应的文件夹目录,导片失败,请核实需导片的文件夹是否存在。");
  1107. return;
  1108. }
  1109. List<string> importedPhotoList = mod.sPh.GetLocalPhotoList(mod.comeDirectoryPath);
  1110. string Ordpg_Sights = "";
  1111. if (mod.sPh.PhotoModel != null)
  1112. {
  1113. Ordpg_Sights = mod.sPh.PhotoModel.Ordpg_Sights;
  1114. }
  1115. int currentCount = 0;
  1116. try
  1117. {
  1118. LYFZ.BLL.BLL_ErpSystemLogs.WriteSystemLog(EnumPublic.SystemLogsType.相片导入导出,
  1119. "" + LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name + "导入" + importedPhotoList.Count + "张初修片[订单号:" + mod.erpOrder.Ord_Number + "/" + mod.erpOrder.Ord_SinceOrderNumber + "(" + mod.erpDigOrder.Ordv_ViceNumber + ")]" + Ordpg_Sights,
  1120. LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID,
  1121. LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name);
  1122. }
  1123. catch { }
  1124. bool bl = true;
  1125. // LYFZ.PhotoSelectSystem.PhotoImportExport.StartGenerateThumbnails(Model.Model_ErpOrder.DirectoryType.EarlyRetouch, this.currentModel.Ord_Number);
  1126. int importFailed = 0;
  1127. foreach (string photoFile in importedPhotoList)
  1128. {
  1129. currentCount++;
  1130. frmFileImportItemModel tempItem = mod.local_Path.Find(p => p.local_Path.Equals(photoFile) && p.code == 0);
  1131. if (tempItem==null)
  1132. {
  1133. continue;
  1134. }
  1135. tempItem.upload_Msg = "正在上传";
  1136. ImportTaskFileManager(mod);
  1137. ///管理窗体显示
  1138. if (SingletonThreadImportFileFormEvent != null)
  1139. {
  1140. SingletonThreadImportFileFormEvent(enumImportMultipFieForm.BackNext, mod);
  1141. }
  1142. #region 处理如果导入相片与已导入相片存在相片名相同的情况替换已存在相片
  1143. List<string> hasBeenImportedPhotoList2 = mod.sPh.GetSpecifyTypePhotoList(Model.Model_ErpOrder.DirectoryType.EarlyRetouch, BLL.SelectPhotoHandling.PhotoType.Original);
  1144. string sourcPhotoName = System.IO.Path.GetFileName(photoFile); //;
  1145. string sameProductPhoto = "";//重名文件路径
  1146. foreach (string photoPath in hasBeenImportedPhotoList2)
  1147. {
  1148. string beModifiedPhotoName = LYFZ.BLL.SelectPhotoHandling.ServerFileNameToOriginalName(photoPath); //GetDesignConfirmName(photoPath, currentTakenName, this.orderModel.Ord_Number);
  1149. if (sourcPhotoName.ToLower() == beModifiedPhotoName.ToLower())
  1150. {
  1151. sameProductPhoto = photoPath;
  1152. break;
  1153. }
  1154. }
  1155. #endregion
  1156. if (sameProductPhoto.Trim().Length > 0)
  1157. {
  1158. if (File.Exists(photoFile))
  1159. {
  1160. if (!mod.sPh.ImportPhotoFile(System.IO.Path.GetDirectoryName(sameProductPhoto), photoFile, true, mod.importGenerateThumbnails))
  1161. {
  1162. tempItem.success = false;
  1163. tempItem.code = -1;
  1164. tempItem.upload_Msg = "上传失败";
  1165. ImportTaskFileManager(mod);
  1166. importFailed++;
  1167. }
  1168. else
  1169. {
  1170. tempItem.success = true;
  1171. tempItem.code = 1;
  1172. tempItem.upload_Msg = "上传成功";
  1173. //if (SingletonThreadImportFileEvent != null)
  1174. //{
  1175. // SingletonThreadImportFileEvent(enumImportMultipFie.Number, GetProThreadNumber());
  1176. //}
  1177. ImportTaskFileManager(mod);
  1178. }
  1179. }
  1180. else
  1181. {
  1182. tempItem.success = false;
  1183. tempItem.code = -1;
  1184. tempItem.upload_Msg = "上传失败-文件不存在";
  1185. ImportDataLogs(DateTime.Now.ToString() + " 文件导入失败,路径:" + photoFile + ",文件不存在\r\n");
  1186. ImportTaskFileManager(mod);
  1187. importFailed++;
  1188. }
  1189. }
  1190. else
  1191. {
  1192. if (File.Exists(photoFile))
  1193. {
  1194. if (!mod.sPh.ImportPhotoFile(mod.service_Path, photoFile, importGenerateThumbnails: mod.importGenerateThumbnails))
  1195. {
  1196. tempItem.success = false;
  1197. tempItem.code = -1;
  1198. tempItem.upload_Msg = "上传失败";
  1199. ImportTaskFileManager(mod);
  1200. importFailed++;
  1201. }
  1202. else
  1203. {
  1204. tempItem.success = true;
  1205. tempItem.code = 1;
  1206. tempItem.upload_Msg = "上传成功";
  1207. //if (SingletonThreadImportFileEvent != null)
  1208. //{
  1209. // SingletonThreadImportFileEvent(enumImportMultipFie.Number, GetProThreadNumber());
  1210. //}
  1211. ImportTaskFileManager(mod);
  1212. }
  1213. }
  1214. else
  1215. {
  1216. tempItem.success = false;
  1217. tempItem.code = -1;
  1218. tempItem.upload_Msg = "上传失败-文件不存在";
  1219. ImportDataLogs(DateTime.Now.ToString() + " 文件导入失败,路径:" + photoFile + ",文件不存在\r\n");
  1220. ImportTaskFileManager(mod);
  1221. importFailed++;
  1222. }
  1223. }
  1224. ///管理窗体显示
  1225. if (SingletonThreadImportFileFormEvent != null)
  1226. {
  1227. SingletonThreadImportFileFormEvent(enumImportMultipFieForm.BackNext, mod);
  1228. }
  1229. if (currentCount == 10 && !mod.importGenerateThumbnails)
  1230. {
  1231. LYFZ.PhotoSelectSystem.PhotoImportExport.StartGenerateThumbnails(Model.Model_ErpOrder.DirectoryType.EarlyRetouch, mod.erpOrder.Ord_Number);
  1232. }
  1233. //mod.sPh.SetBackgroundWorker(sumCount, currentCount, "正在导入相片,请稍等...", backgroundWorker);
  1234. if (bRestartThread)
  1235. {
  1236. //threadWord.Abort();
  1237. SingletonThreadImportFileEvent(enumImportMultipFie.Restart, null);
  1238. }
  1239. }
  1240. List<frmFileImportItemModel> tempItemList = mod.local_Path.FindAll(p => p.code == 0);
  1241. foreach(frmFileImportItemModel tempItem in tempItemList)
  1242. {
  1243. tempItem.success = false;
  1244. tempItem.code = -1;
  1245. tempItem.upload_Msg = "上传失败-文件不存在";
  1246. ImportDataLogs(DateTime.Now.ToString() + " 文件导入失败,路径:" + tempItem.local_Path + ",文件不存在\r\n");
  1247. ImportTaskFileManager(mod);
  1248. importFailed++;
  1249. if (SingletonThreadImportFileFormEvent != null)
  1250. {
  1251. SingletonThreadImportFileFormEvent(enumImportMultipFieForm.BackNext, mod);
  1252. }
  1253. if (currentCount == 10 && !mod.importGenerateThumbnails)
  1254. {
  1255. LYFZ.PhotoSelectSystem.PhotoImportExport.StartGenerateThumbnails(Model.Model_ErpOrder.DirectoryType.EarlyRetouch, mod.erpOrder.Ord_Number);
  1256. }
  1257. //mod.sPh.SetBackgroundWorker(sumCount, currentCount, "正在导入相片,请稍等...", backgroundWorker);
  1258. if (bRestartThread)
  1259. {
  1260. //threadWord.Abort();
  1261. SingletonThreadImportFileEvent(enumImportMultipFie.Restart, null);
  1262. }
  1263. }
  1264. if (importFailed == 0)
  1265. {
  1266. bl = true;
  1267. }
  1268. else
  1269. {
  1270. bl = false;
  1271. mod.errorMsg = "相片导入完成,但有 " + importFailed.ToString() + " 张导入失败。";
  1272. //ExMessageBoxCustom.Show("相片导入完成,但有 " + importFailed.ToString() + " 张导入失败。", backgroundWorker: backgroundWorker);
  1273. }
  1274. if (importFailed < importedPhotoList.Count && !mod.importGenerateThumbnails)
  1275. {
  1276. LYFZ.PhotoSelectSystem.PhotoImportExport.StartGenerateThumbnails(Model.Model_ErpOrder.DirectoryType.EarlyRetouch, mod.erpOrder.Ord_Number);
  1277. }
  1278. if (bl)
  1279. {
  1280. LYFZ.BLL.BLL_ErpOrderDigital odbll = new BLL.BLL_ErpOrderDigital();
  1281. LYFZ.BLL.BLL_ErpOrderDigitalStatus orsbll = new BLL.BLL_ErpOrderDigitalStatus();
  1282. mod.Success = true;
  1283. StartGenerateThumbnails(Model.Model_ErpOrder.DirectoryType.EarlyRetouch, mod.erpOrder.Ord_Number);
  1284. /*#region 修改导入修片地址
  1285. LYFZ.Model.Model_ErpOrder modelOrder = orbll.GetModel("Ord_Number", StrOrdNumber);
  1286. modelOrder.Ord_PhotoPath = mod.sPh.UpdatePhotoImportDirectoryPath(Model.Model_ErpOrder.DirectoryType.EarlyRetouch, strprht.FullName);
  1287. modelOrder.Ord_PhotoBackupPath = "NEW";
  1288. modelOrder.Ord_UpdateDateTime = StrTime;
  1289. modelOrder.Ord_UpdateName = StrUserName;
  1290. clist.Add(orbll.GetImportPhotoUpdateOrder(modelOrder));
  1291. #endregion*/
  1292. mod.erpOrder.Ord_PhotoPath = mod.sPh.UpdatePhotoImportDirectoryPath(Model.Model_ErpOrder.DirectoryType.EarlyRetouch, mod.service_Path);
  1293. mod.erpOrder.Ord_PhotoBackupPath = "NEW";
  1294. mod.erpOrder.Ord_UpdateDateTime = SDateTime.Now;
  1295. mod.erpOrder.Ord_UpdateName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
  1296. List<LYFZ.Helper.CommandInfo> clist = new List<Helper.CommandInfo>();
  1297. //clist.AddRange(mod.FrmClist);
  1298. clist.Add(orbll.GetImportPhotoUpdateOrder(mod.erpOrder));
  1299. //LYFZ.Model.Model_ErpOrderDigital modelDigital = odbll.GetModel("Ordv_ViceNumber", mod.OrdViceNumber);
  1300. //if (modelDigital.Ordv_EarlyRepairStatus.Trim() != "2")
  1301. //{
  1302. // modelDigital.Ordv_EarlyRepairName = mod.erpOrder.Ord_UpdateName;
  1303. // modelDigital.Ordv_EarlyRepairTime = mod.erpOrder.Ord_UpdateDateTime;
  1304. // modelDigital.Ordv_EarlyRepairStatus = mod.StrStatus;
  1305. //}
  1306. //modelDigital.Ordv_UpdateDateTime = mod.erpOrder.Ord_UpdateDateTime;
  1307. //modelDigital.Ordv_UpdateName = mod.erpOrder.Ord_UpdateName;
  1308. //clist.Add(odbll.GetUpdateCommandInfo(modelDigital));
  1309. //DataTable dt = orbll.GetView_Custom("tb_ErpOrderDigitalStatus", StrWhere: "Ords_OrdNumber = '" + mod.OrdNumber + "' And Ords_ViceNumber = '" + mod.OrdViceNumber + "'", ShowColumnName: "*").Tables[0];
  1310. //LYFZ.Model.Model_ErpOrderDigitalStatus modelStatus = null;
  1311. //if (dt.Rows.Count > 0)
  1312. //{
  1313. // modelStatus = orsbll.DataRowToModel(dt.Rows[0]);
  1314. // if (modelStatus.Ords_OutSendEarlyRepairStatus.Trim() == "已发" || modelStatus.Ords_OutSendEarlyRepairStatus.Trim() == "已回")
  1315. // {
  1316. // modelStatus.Ords_OutSendEarlyRepairName = mod.erpOrder.Ord_UpdateName;
  1317. // modelStatus.Ords_OutSendEarlyRepairStatus = "已回";
  1318. // modelStatus.Ords_OutSendEarlyRepairTime = mod.erpOrder.Ord_UpdateDateTime;
  1319. // clist.Add(orsbll.GetUpdateCommandInfo(modelStatus));
  1320. // }
  1321. //}
  1322. //clist.AddRange(frm.clist);
  1323. pcrsbll.SetServicePhotographCount(LYFZ.Model.Model_ErpOrder.DirectoryType.EarlyRetouch, mod.erpDigOrder.Ordv_Number, mod.erpDigOrder.Ordv_ViceNumber, mod.takenName, "3");
  1324. LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist);
  1325. if (SingletonThreadImportFileEvent != null)
  1326. {
  1327. SingletonThreadImportFileEvent(enumImportMultipFie.Number, GetProThreadNumber());
  1328. }
  1329. }
  1330. else if (mod.errorMsg.IndexOf("暂停") == -1)
  1331. {
  1332. mod.Success = false;
  1333. mod.errorMsg = "导入失败";
  1334. }
  1335. }
  1336. #endregion
  1337. /// <summary>
  1338. /// 请求生成缩略图
  1339. /// </summary>
  1340. /// <param name="dirType"></param>
  1341. /// <param name="ord_Number"></param>
  1342. public void StartGenerateThumbnails(Model.Model_ErpOrder.DirectoryType dirType, string ord_Number)
  1343. {
  1344. try
  1345. {
  1346. // if (LYFZ.BLL.SelectPhotoHandling.CheckCurrentInternaNetworkAddress())
  1347. // {
  1348. LYFZ.Network.ClientRequestObject requestObj = new Network.ClientRequestObject();
  1349. requestObj.OrdNumber = ord_Number;
  1350. requestObj.RequestEvent = "请求生成缩略图";
  1351. requestObj.Type = (int)dirType;
  1352. if (LYFZ.PhotoSelectSystem.PhotoImportExport.CurrentNetworkClient != null)
  1353. {
  1354. LYFZ.PhotoSelectSystem.PhotoImportExport.CurrentNetworkClient.SendCommandToServer(HPSocketCS.Extended.TransferRequestCommand.GenerateThumbnails, requestObj.ToString());
  1355. }
  1356. else
  1357. {
  1358. LYFZ.BLL.BLL_FileLogs.WriteMainLogs("请求生成缩略图时网络连接断开");
  1359. }
  1360. // }
  1361. }
  1362. catch { }
  1363. }
  1364. #region 原片导入
  1365. /// <summary>
  1366. /// 原片导入
  1367. /// </summary>
  1368. /// <param name="mod"></param>
  1369. /// <param name="i"></param>
  1370. void ImportFileByPrimitivePicture(frmFileImportModel mod,int i)
  1371. {
  1372. TipsIs64BitProcess();
  1373. // var mod = data_Pools[i];
  1374. LYFZ.WinAPI.MyDriverInfo dInfo = LYFZ.WinAPI.CustomPublicMethod.GetDiskFreeSpace(mod.service_Path);
  1375. if (dInfo.G_TotalFreeBytes < 3)
  1376. {
  1377. if (SingletonThreadImportFileEvent != null)
  1378. {
  1379. SingletonThreadImportFileEvent(enumImportMultipFie.MsgError, "[" + mod.directoryType.ToString() + "]服务器上保存原片的目录容量小于 3GB 所以不能导入相片,请重新设置原片保存目录。");
  1380. }
  1381. return;
  1382. //ExMessageBoxCustom.Show("服务器上保存原片的目录容量小于 3GB 所以不能导入相片,请重新设置原片保存目录。");
  1383. //return false;
  1384. }
  1385. LYFZ.BLL.SelectPhotoHandling sPhotoHandling = new BLL.SelectPhotoHandling(mod.erpOrder, mod.erpDigOrder);
  1386. string currentTakenName = null;
  1387. if (sPhotoHandling.PhotoModel != null)
  1388. {
  1389. currentTakenName = sPhotoHandling.PhotoModel.Ordpg_Sights;
  1390. }
  1391. List<string> photolist = new List<string>();
  1392. foreach (var item in mod.local_Path)
  1393. {
  1394. if (item.code == 0)
  1395. {
  1396. photolist.Add(item.local_Path);
  1397. }
  1398. }
  1399. if (photolist.Count == 0)
  1400. {
  1401. return;
  1402. }
  1403. baseList = new List<frmFileImportBaseModel>();
  1404. for (int qz = i + 1; qz < data_Pools.Count; qz++)
  1405. {
  1406. baseList.Add(data_Pools[qz].CloneBaseData());
  1407. }
  1408. ///上传文件处理
  1409. bool bl = ImportOriginalFilm(photolist, mod.service_Path, mod.takenName, mod.erpOrder, mod.erpDigOrder, currentTakenName, sPhotoHandling, mod, mod.importGenerateThumbnails);
  1410. ///反馈管理界面文件上传处理
  1411. if (SingletonThreadImportFileFormEvent != null)
  1412. {
  1413. SingletonThreadImportFileFormEvent(enumImportMultipFieForm.BackNext, mod);
  1414. }
  1415. if (bl)
  1416. {
  1417. mod.Success = true;
  1418. }
  1419. else if (mod.errorMsg.IndexOf("暂停")==-1)
  1420. {
  1421. mod.Success = false;
  1422. mod.errorMsg = "导入失败";
  1423. return;
  1424. }
  1425. pcrsbll.SetServicePhotographCount(LYFZ.Model.Model_ErpOrder.DirectoryType.PrimitivePicture, mod.erpDigOrder.Ordv_Number, mod.erpDigOrder.Ordv_ViceNumber, mod.takenName, "2");
  1426. mod.erpOrder.Ord_PhotoPath = mod.sPh.UpdatePhotoImportDirectoryPath(Model.Model_ErpOrder.DirectoryType.PrimitivePicture, mod.service_Path);
  1427. mod.erpOrder.Ord_PhotoBackupPath = "NEW";
  1428. mod.erpOrder.Ord_UpdateDateTime = SDateTime.Now;
  1429. mod.erpOrder.Ord_UpdateName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
  1430. List<LYFZ.Helper.CommandInfo> clist = new List<Helper.CommandInfo>();
  1431. clist.Add(orbll.GetImportPhotoUpdateOrder(mod.erpOrder));
  1432. LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist);
  1433. if (SingletonThreadImportFileEvent != null)
  1434. {
  1435. SingletonThreadImportFileEvent(enumImportMultipFie.Number, GetProThreadNumber());
  1436. }
  1437. }
  1438. /// <summary>
  1439. /// 导入原片
  1440. /// </summary>
  1441. /// <param name="photoFiles">要导入的相片路径数组</param>
  1442. /// <param name="toDirectoryPath">要导入到的目标目录, 即服务器上的相片保存文件夹路径</param>
  1443. /// <param name="takenName">拍摄名(即景点名不能为空)</param>
  1444. /// <param name="backgroundWorker">线程对象</param>
  1445. /// <returns></returns>
  1446. public bool ImportOriginalFilm(List<string> photoFiles, string toDirectoryPath, string takenName,
  1447. Model.Model_ErpOrder currentModel, LYFZ.Model.Model_ErpOrderDigital currentDigModel,
  1448. string currentTakenName,LYFZ.BLL.SelectPhotoHandling sPhotoHandling ,
  1449. frmFileImportModel groupMod,
  1450. bool importGenerateThumbnails = false)
  1451. {
  1452. try
  1453. {
  1454. LYFZ.BLL.BLL_ErpSystemLogs.WriteSystemLog(EnumPublic.SystemLogsType.相片导入导出,
  1455. "" + LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name + "导入" + photoFiles.Count + "张原片[订单号:" + currentModel.Ord_Number + "/" + currentModel.Ord_SinceOrderNumber + "(" + currentDigModel.Ordv_ViceNumber + ")]" + currentTakenName,
  1456. LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID,
  1457. LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name);
  1458. }
  1459. catch { }
  1460. bool bl = false;
  1461. //总计数器
  1462. float sumCount = photoFiles.Count;
  1463. //当前计数器
  1464. int currentCount = 0;
  1465. //当前订单已导入原片相片集合
  1466. List<string> hasBeenImportedPhotoList = sPhotoHandling.GetSpecifyTypePhotoList(Model.Model_ErpOrder.DirectoryType.PrimitivePicture, BLL.SelectPhotoHandling.PhotoType.Original);
  1467. bool isImport = true;//是否导入相片
  1468. string sameNameLogsFilePath = "";
  1469. if (!sPhotoHandling.CheckPhotoExist(hasBeenImportedPhotoList, photoFiles, ref sameNameLogsFilePath))
  1470. {
  1471. isImport = true;
  1472. }
  1473. else
  1474. {
  1475. bool bCheckContinue = true;
  1476. if(!File.Exists(sameNameLogsFilePath))
  1477. {
  1478. FileUtil.WriteFile(sameNameLogsFilePath, "");
  1479. }
  1480. string txt = System.IO.File.ReadAllText(sameNameLogsFilePath);
  1481. List<string> tempConsList = new List<string>();
  1482. foreach(string local_txt in photoFiles)
  1483. {
  1484. if(txt.IndexOf(local_txt)!=-1)
  1485. {
  1486. var item = groupMod.local_Path.Find(p=>p.local_Path==local_txt);
  1487. if(item!=null)
  1488. {
  1489. tempConsList.Add(local_txt);
  1490. item.upload_Msg = "系统检测到要导入的相片名出现重名冲突,以取消本组图片上传,删除同名相片或重命名后再导入";
  1491. item.success = false;
  1492. item.code = -1;
  1493. bCheckContinue = false;
  1494. groupMod.Success = false;
  1495. groupMod.errorMsg = "系统检测到要导入的相片名出现重名冲突,以取消本组图片上传,删除同名相片或重命名后再导入";
  1496. }
  1497. }
  1498. }
  1499. if(!bCheckContinue)
  1500. {
  1501. foreach(string temp in tempConsList)
  1502. {
  1503. photoFiles.Remove(temp);
  1504. }
  1505. }
  1506. }
  1507. try
  1508. {
  1509. LYFZ.BLL.BLL_PhotoImportRecordTable.UpdatePhotoImportRecordTable(LYFZ.Model.Model_ErpOrder.DirectoryType.PrimitivePicture, LYFZ.BLL.BLL_ErpCompanyInfo.CurrentCompanyInfoID, currentModel.Ord_Number, 1, PhotoImportRecordType.Import);
  1510. }
  1511. catch (Exception ex)
  1512. {
  1513. isImport = false;
  1514. bl = false;
  1515. ExMessageBoxCustom.Show("更新导片记录时失败:" + ex.Message);
  1516. }
  1517. if (isImport)
  1518. {
  1519. // LYFZ.PhotoSelectSystem.PhotoImportExport.StartGenerateThumbnails(Model.Model_ErpOrder.DirectoryType.PrimitivePicture, this.currentModel.Ord_Number);
  1520. int importFailed = 0;
  1521. foreach (string photoFile in photoFiles)
  1522. {
  1523. currentCount++;
  1524. frmFileImportItemModel tempItem = groupMod.local_Path.Find(p => p.local_Path.Equals(photoFile) && p.code==0);
  1525. if (tempItem==null)
  1526. {
  1527. continue;
  1528. }
  1529. tempItem.upload_Msg = "正在上传";
  1530. ImportDataLogs(DateTime.Now.ToString() + " 正在进行文件导入,路径:" + photoFile + "\r\n");
  1531. ImportTaskFileManager(groupMod);
  1532. ///管理窗体显示
  1533. if (SingletonThreadImportFileFormEvent != null)
  1534. {
  1535. SingletonThreadImportFileFormEvent(enumImportMultipFieForm.BackNext, groupMod);
  1536. }
  1537. if (File.Exists(photoFile))
  1538. {
  1539. ///图片上传
  1540. if (!sPhotoHandling.ImportPhotoFile(toDirectoryPath, photoFile, importGenerateThumbnails: importGenerateThumbnails))
  1541. {
  1542. importFailed++;
  1543. tempItem.success = false;
  1544. tempItem.code = -1;
  1545. tempItem.upload_Msg = "上传失败";
  1546. ImportDataLogs(DateTime.Now.ToString() + " 文件导入失败,路径:" + photoFile + "\r\n");
  1547. ImportTaskFileManager(groupMod);
  1548. }
  1549. else
  1550. {
  1551. tempItem.success = true;
  1552. tempItem.code = 1;
  1553. tempItem.upload_Msg = "上传成功";
  1554. ImportDataLogs(DateTime.Now.ToString() + " 文件导入成功,路径:" + photoFile + "\r\n");
  1555. ImportTaskFileManager(groupMod);
  1556. }
  1557. }
  1558. else
  1559. {
  1560. tempItem.success = false;
  1561. tempItem.code = -1;
  1562. tempItem.upload_Msg = "文件不存在!!";
  1563. ImportDataLogs(DateTime.Now.ToString() + " 文件导入失败,路径:" + photoFile + ",文件不存在\r\n");
  1564. ImportTaskFileManager(groupMod);
  1565. }
  1566. ///管理窗体显示
  1567. if (SingletonThreadImportFileFormEvent != null)
  1568. {
  1569. SingletonThreadImportFileFormEvent(enumImportMultipFieForm.BackNext, groupMod);
  1570. }
  1571. if (currentCount == 10 && !importGenerateThumbnails)
  1572. {
  1573. LYFZ.PhotoSelectSystem.PhotoImportExport.StartGenerateThumbnails(Model.Model_ErpOrder.DirectoryType.PrimitivePicture, currentModel.Ord_Number);
  1574. }
  1575. if (bRestartThread)
  1576. {
  1577. SingletonThreadImportFileEvent(enumImportMultipFie.Restart, null);
  1578. }
  1579. }
  1580. List<frmFileImportItemModel> tempItemList = groupMod.local_Path.FindAll(p => p.code == 0);
  1581. foreach (frmFileImportItemModel tempItem in tempItemList)
  1582. {
  1583. tempItem.success = false;
  1584. tempItem.code = -1;
  1585. tempItem.upload_Msg = "上传失败-文件不存在";
  1586. ImportDataLogs(DateTime.Now.ToString() + " 文件导入失败,路径:" + tempItem.local_Path + ",文件不存在\r\n");
  1587. ImportTaskFileManager(groupMod);
  1588. if (SingletonThreadImportFileFormEvent != null)
  1589. {
  1590. SingletonThreadImportFileFormEvent(enumImportMultipFieForm.BackNext, groupMod);
  1591. }
  1592. }
  1593. if (importFailed == 0)
  1594. {
  1595. bl = true;
  1596. }
  1597. else
  1598. {
  1599. bl = false;
  1600. //ExMessageBoxCustom.Show("相片导入完成,但有 " + importFailed.ToString() + " 张导入失败。", backgroundWorker: backgroundWorker);
  1601. }
  1602. if (importFailed < photoFiles.Count)
  1603. {
  1604. LYFZ.PhotoSelectSystem.PhotoImportExport.StartGenerateThumbnails(Model.Model_ErpOrder.DirectoryType.PrimitivePicture, currentModel.Ord_Number);
  1605. }
  1606. }
  1607. return bl;
  1608. }
  1609. #endregion
  1610. #region 任务列表记录 用于退出重启动
  1611. void ImportTaskFileManager(frmFileImportModel mod)
  1612. {
  1613. List<frmFileImportBaseModel> tempBaseList = new List<frmFileImportBaseModel>();
  1614. //tempBaseList.Add(mod.CloneBaseData());
  1615. List<frmFileImportModel> modelList = data_Pools.FindAll(p => !p.Success);
  1616. foreach (var tempMod in modelList)
  1617. {
  1618. tempBaseList.Add(tempMod.CloneBaseData());
  1619. }
  1620. SaveFileManage(tempBaseList);
  1621. }
  1622. public void SaveFileManage(List<frmFileImportBaseModel> tempBaseList)
  1623. {
  1624. try
  1625. {
  1626. if (File.Exists(Environment.CurrentDirectory + "/UpFileManage/FileManage.txt"))
  1627. {
  1628. File.Delete(Environment.CurrentDirectory + "/UpFileManage/FileManage.txt");
  1629. }
  1630. FileUtil.WriteFile(Environment.CurrentDirectory + "/UpFileManage/" + HPSocketCS.Extended.CommonLibrary.ClientMarkID + "/FileManage.txt", Json.JsonTool.ObjectToJson(tempBaseList));
  1631. }
  1632. catch { }
  1633. }
  1634. public string SaveCheckFileManage(string txt)
  1635. {
  1636. FileUtil.WriteFile(Environment.CurrentDirectory + "/UpFileManage/CheckFileManage.txt", txt);
  1637. return Environment.CurrentDirectory + "/UpFileManage/CheckFileManage.txt";
  1638. }
  1639. #endregion
  1640. /// <summary>
  1641. /// 启动绑定任务列表
  1642. /// </summary>
  1643. public void ReadNotUpFileData()
  1644. {
  1645. bool bThreadStart = false;
  1646. if(BindModelListData(Environment.CurrentDirectory + "/UpFileManage/FileManage.txt"))
  1647. {
  1648. bThreadStart = true;
  1649. }
  1650. if (BindModelListData(Environment.CurrentDirectory + "/UpFileManage/" + HPSocketCS.Extended.CommonLibrary.ClientMarkID + "/FileManage.txt"))
  1651. {
  1652. bThreadStart = true;
  1653. }
  1654. if (bThreadStart)
  1655. {
  1656. if(this.data_Pools.Count > 0)
  1657. {
  1658. if (SingletonThreadImportFileEvent != null)
  1659. {
  1660. SingletonThreadImportFileEvent(enumImportMultipFie.Number, this.data_Pools.Count);
  1661. }
  1662. }
  1663. ///判断是否自动上传,默认手动上传
  1664. if (Properties.Settings.Default.bImportAutoUp)
  1665. {
  1666. if (this.data_Pools.Count > 0)
  1667. {
  1668. this.StartThread();
  1669. }
  1670. }
  1671. }
  1672. }
  1673. public bool BindModelListData(string path)
  1674. {
  1675. string txt = FileUtil.ReadFile(path);
  1676. if (!string.IsNullOrEmpty(txt))
  1677. {
  1678. List<frmFileImportBaseModel> manageBaseList = new List<frmFileImportBaseModel>();
  1679. manageBaseList = (List<frmFileImportBaseModel>)Json.JsonTool.JsonToObject(txt, manageBaseList);
  1680. foreach (var mod in manageBaseList)
  1681. {
  1682. if (mod.local_Path.Count > 0)
  1683. {
  1684. frmFileImportModel importModel = new frmFileImportModel();
  1685. importModel.BindBaseDataToModel(mod);
  1686. if (data_Pools.FindAll(p => p.OrdNumber == importModel.OrdNumber && p.directoryType == importModel.directoryType).Count > 0)
  1687. {
  1688. continue;
  1689. }
  1690. LYFZ.Model.Model_ErpOrder erpOrder = orbll.GetModel(importModel.OrdNumber);
  1691. LYFZ.Model.Model_ErpOrderDigital orderDigital = digtalBll.GetModel(importModel.OrdViceNumber);
  1692. importModel.erpOrder = erpOrder;
  1693. importModel.erpDigOrder = orderDigital;
  1694. this.data_Pools.Add(importModel);
  1695. baseList.Add(mod);
  1696. }
  1697. }
  1698. return true;
  1699. }
  1700. return false;
  1701. }
  1702. /// <summary>
  1703. /// 清楚错误内容
  1704. /// </summary>
  1705. internal void SetClearErrorData()
  1706. {
  1707. foreach (var mod in data_Pools)
  1708. {
  1709. foreach(var item in mod.local_Path)
  1710. {
  1711. if (item.upload_Msg != "暂停上传" && !item.success && item.code==-1)
  1712. {
  1713. item.success = true;
  1714. item.code = 1;
  1715. }
  1716. }
  1717. if(mod.local_Path.FindAll(p=>p.code==-1||p.code==0).Count==0)
  1718. {
  1719. mod.Success = true;
  1720. }
  1721. }
  1722. if (SingletonThreadImportFileEvent != null)
  1723. {
  1724. SingletonThreadImportFileEvent(enumImportMultipFie.Number, GetProThreadNumber());
  1725. }
  1726. ImportTaskFileManager(null);
  1727. }
  1728. internal void RestartThread(frmFileImportModel frmFileImportModel)
  1729. {
  1730. bRestartThread = true;
  1731. }
  1732. #region ftp控制时间对象
  1733. System.Windows.Forms.Timer ftpMessageTime = null;
  1734. public void BindFTPMsgTimer(System.Windows.Forms.Timer _ftpMessageTime)
  1735. {
  1736. ftpMessageTime = _ftpMessageTime;
  1737. }
  1738. public void StartFTPMsgTimer()
  1739. {
  1740. if(ftpMessageTime!=null)
  1741. {
  1742. ftpMessageTime.Start();
  1743. }
  1744. }
  1745. #endregion
  1746. internal void DeleteModel(frmFileImportModel frmFileImportModel)
  1747. {
  1748. //throw new NotImplementedException();
  1749. foreach(var mod in data_Pools)
  1750. {
  1751. if(mod==frmFileImportModel)
  1752. {
  1753. data_Pools.Remove(mod);
  1754. break;
  1755. }
  1756. }
  1757. ImportTaskFileManager(null);
  1758. if (SingletonThreadImportFileEvent != null)
  1759. {
  1760. SingletonThreadImportFileEvent(enumImportMultipFie.Number, GetProThreadNumber());
  1761. }
  1762. }
  1763. #region 线程执行日志
  1764. /// <summary>
  1765. /// 写入线程日志
  1766. /// </summary>
  1767. /// <param name="content"></param>
  1768. public void ImportDataLogs(string content)
  1769. {
  1770. try
  1771. {
  1772. FileUtil.WriteFileAppend(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "/Logs/ImportThread/" + DateTime.Now.ToString("yyyyMMdd") + ".txt", content);
  1773. }
  1774. catch { }
  1775. }
  1776. #endregion
  1777. }
  1778. }