123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968 |
-
- using LYFZ.PhotoSelectSystem;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.IO;
- using System.Linq;
- using System.Runtime.Serialization.Json;
- using System.Text;
- using System.Threading;
- namespace LYFZ.Software.MainBusiness.MultipleFileImport
- {
- /// <summary>
- /// 单利线程导入文件控制
- /// </summary>
- /// <remarks>2017-3-10 杨云奕 添加</remarks>
- public class frmMultipFileImportThread
- {
- bool bRestartThread = false;
- bool bStoping = false;
- bool bStoped = false;
- public bool threadStart = false;
- static frmMultipFileImportThread singleton=null;
- /// <summary>
- /// 线程
- /// </summary>
- public Thread threadWord;
- /// <summary>
- /// 定义的线程池
- /// </summary>
- public List<frmFileImportModel> data_Pools;
- /// <summary>
- /// 剩余上传数据集合
- /// </summary>
- List<frmFileImportBaseModel> baseList;
- /// <summary>
- /// 文件上传主界面消息监控提示事件
- /// </summary>
- /// <param name="StatusCode"></param>
- /// <param name="objectData"></param>
- public delegate void SingletonThreadImportFileHandler(enumImportMultipFie StatusCode, object objectData);
- public event SingletonThreadImportFileHandler SingletonThreadImportFileEvent;
- /// <summary>
- /// 文件上传管理界面事件,销毁管理界面,线程事件需要销毁
- /// </summary>
- public delegate void SingletonThreadImportFileFormHandler(enumImportMultipFieForm StatusCode, object objectData);
- public event SingletonThreadImportFileFormHandler SingletonThreadImportFileFormEvent;
- LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
- LYFZ.BLL.BLL_ErpOrderDigital digtalBll = new LYFZ.BLL.BLL_ErpOrderDigital();
- LYFZ.BLL.BLL_ErpPieceCommissionRecords pcrsbll = new BLL.BLL_ErpPieceCommissionRecords();
- Timer timer =null;
-
- public frmMultipFileImportThread()
- {
- data_Pools = new List<frmFileImportModel>();
- baseList = new List<frmFileImportBaseModel>();
- TimerCallback timeCallBack=new TimerCallback(TimerCallback);
- timer = new Timer(timeCallBack, null, 0, 500);
-
-
- }
- void TimerCallback(object state)
- {
- if (bRestartThread && (threadWord==null||threadWord.ThreadState == ThreadState.Aborted || threadWord.ThreadState == ThreadState.Stopped))
- {
- bRestartThread = false;
- threadWord = null;
- this.StartThread();
- }
- }
- /// <summary>
- /// 实例化单利模式
- /// </summary>
- /// <returns></returns>
- public static frmMultipFileImportThread GetSingleton()
- {
- if(singleton==null)
- {
- singleton = new frmMultipFileImportThread();
- }
- return singleton;
- }
- public void DeleteFromModel(frmFileImportModel model)
- {
- }
- public bool GetAutoImportAutoUp()
- {
- return Properties.Settings.Default.bImportAutoUp;
- }
- public void ThreadStop()
- {
- if(threadWord!=null&&threadWord.ThreadState== ThreadState.Running)
- {
- threadWord.Abort();
- threadStart = false;
- }
- LYFZ.Software.MainBusiness.MultipleFileImport.frmMultipFileImportThread.GetSingleton().ImportDataLogs(DateTime.Now.ToString() + " 线程停止" );
- }
-
- public List<frmFileImportModel> GetFileImportList()
- {
- return data_Pools;
- }
- public bool CheckOrderUp(frmFileImportModel data,Model.Model_ErpOrder.DirectoryType dirType,ref string fileExitsFile)
- {
- List<frmFileImportModel> list = data_Pools.FindAll(p => p.erpOrder.Ord_Number == data.erpOrder.Ord_Number && p.directoryType == dirType&&!p.Success);
- List<frmFileImportItemModel> allItemList=new List<frmFileImportItemModel>();
- bool bCheck = true;
- foreach(var mod in list)
- {
- //if (!mod.Success&&mod.)
- allItemList.AddRange(mod.local_Path.FindAll(p=>!p.success&&p.code!=1));
- }
- foreach (var item in data.local_Path)
- {
- var tempItem = allItemList.FindAll(p => Path.GetFileName(p.local_Path) == Path.GetFileName(item.local_Path));
- if(tempItem.Count>0)
- {
- fileExitsFile += "订单:" + data.erpOrder.Ord_Number + " 的导入图片队列中存在:" + Path.GetFileName(item.local_Path) + "\r\n";
- bCheck = false;
- }
- }
- if(!bCheck)
- {
- fileExitsFile=SaveCheckFileManage(fileExitsFile);
- }
- return bCheck;
- }
- /// <summary>
- /// 添加数据如线程池
- /// </summary>
- /// <param name="data">数据</param>
- public void AddDataToDataPools(frmFileImportModel data)
- {
- //if (data_Pools.FindAll(p =>
- // p.OrdNumber == data.OrdNumber &&
- // p.directoryType == data.directoryType &&
- // p.takenName==data.takenName&&
- // !p.Success
- // ).Count > 0)
- //{
- // return;
- //}
- //!Properties.Settings.Default.bImportAutoUp &&
- if ( (threadWord == null || threadWord.ThreadState == ThreadState.Aborted || threadWord.ThreadState == ThreadState.Stopped ))
- {
- data.errorMsg = "手动上传";
- }
- data_Pools.Add(data);
- baseList.Add(data.CloneBaseData());
- ///反馈主界面数量信息
- if (SingletonThreadImportFileEvent != null)
- {
- SingletonThreadImportFileEvent(enumImportMultipFie.Number, GetProThreadNumber());
- }
- ///反馈管理界面文件上传处理
- if (SingletonThreadImportFileFormEvent!=null)
- {
-
- SingletonThreadImportFileFormEvent(enumImportMultipFieForm.AddList, data);
- }
- ///判断是否自动上传,默认手动上传
- if(Properties.Settings.Default.bImportAutoUp)
- {
- // StartThread();
- }
- ImportDataLogs(DateTime.Now.ToString() + " 数据加入队列池\r\n");
- ImportTaskFileManager(data);
-
- }
- int GetProThreadNumber()
- {
- int totalNumber = 0;
-
- for (int i = 0; i < data_Pools.Count; i++)
- {
- if(data_Pools[i].local_Path.FindAll(p => p.code == 0).Count>0)
- {
- totalNumber++;
- }
-
- }
- return ((int)(totalNumber));
- }
- static bool isShowTipsIs64BitProcess = false;
- void TipsIs64BitProcess()
- {
- if (!isShowTipsIs64BitProcess)
- {
- isShowTipsIs64BitProcess = true;
- if (!Environment.Is64BitProcess)
- {
- ExMessageBoxCustom.Show("温馨提示:当前系统不是64位系统,导片相片处理时将因内存不足导入失败\r\n建义使用64位系统8GB以上内存的电脑上进行导片");
- }
- else
- {
- int memory = LYFZ.WinAPI.CustomPublicMethod.GetPhisicalMemory() / 1024;
- if (memory <= 0)
- {
- ExMessageBoxCustom.Show("温馨提示:当前系统内存不足1GB,导片相片处理时将因内存不足导入失败\r\n建义使用64位系统8GB以上内存的电脑上进行导片");
- }
- else if (memory < 4)
- {
- ExMessageBoxCustom.Show("温馨提示:当前系统内存低于4GB的最低要求,导片相片处理时将因内存不足导入失败\r\n建义使用64位系统8GB以上内存的电脑上进行导片");
- }
- }
- }
- }
- /// <summary>
- /// 执行线程
- /// </summary>
- public void StartThread()
- {
- bRestartThread = false;
- if(threadWord==null||threadWord.ThreadState== ThreadState.Aborted || threadWord.ThreadState == ThreadState.Stopped)
- {
-
- ///线程启动处理;
- threadWord = new Thread(new ThreadStart(delegate() {
- threadStart = true;
- ImportDataLogs(DateTime.Now.ToString()+" 导片队列开始执行\r\n");
- for(int i=0;i<data_Pools.Count;i++)
- {
- var mod = data_Pools[i];
- ///原片导入方法
- if(mod.directoryType== Model.Model_ErpOrder.DirectoryType.PrimitivePicture)
- {
- ImportDataLogs(DateTime.Now.ToString() + " 原片导入,订单编号:" + mod.OrdNumber + "\r\n");
- ImportFileByPrimitivePicture(mod, i);
- }
- else if (mod.directoryType== Model.Model_ErpOrder.DirectoryType.EarlyRetouch)
- {
- ImportDataLogs(DateTime.Now.ToString() + " 初修导入,订单编号:" + mod.OrdNumber + "\r\n");
- ImportFileByEarlyRetouch(mod, i);
- }
- else if(mod.directoryType== Model.Model_ErpOrder.DirectoryType.FineRetouch)
- {
- ImportDataLogs(DateTime.Now.ToString() + " 精修导入,订单编号:" + mod.OrdNumber + "\r\n");
- ImportRefinedRepairPiece(mod, i);
- }
- else if (mod.directoryType == Model.Model_ErpOrder.DirectoryType.DesignPiece)
- {
- ImportDataLogs(DateTime.Now.ToString() + " 设计导入,订单编号:" + mod.OrdNumber + "\r\n");
- ImportDesignPiece(mod, i);
- }
- }
- bool bSuccess = true ;
- threadStart = false;
- if (SingletonThreadImportFileEvent != null)
- {
- int taskNumber = 0;
- int totalNumber = 0;
- foreach (var mod in data_Pools)
- {
- foreach(var item in mod.local_Path)
- {
- if(!item.success&&item.code==-1)
- {
- totalNumber += 1;
- bSuccess = false;
- }
- }
- if(mod.local_Path.FindAll(p=>p.code==-1).Count>0)
- {
- taskNumber++;
- }
- }
- if (bSuccess)
- {
- SingletonThreadImportFileEvent(enumImportMultipFie.Process, "success");
- }
- else
- {
- SingletonThreadImportFileEvent(enumImportMultipFie.Process, taskNumber.ToString());
- }
- }
- ImportDataLogs(DateTime.Now.ToString() + " 导片结束\r\n");
- }));
- threadWord.Start();
- }
- else if(threadWord.ThreadState== ThreadState.Stopped)
- {
- threadWord = null;
- StartThread();
- }
- }
- #region 设计导入
- public bool CheckDesignPiece(frmFileImportModel mod,ref string okActive)
- {
- TipsIs64BitProcess();
- LYFZ.WinAPI.MyDriverInfo dInfo = LYFZ.WinAPI.CustomPublicMethod.GetDiskFreeSpace(mod.service_Path);
- string Ordpg_Sights = "";
- if (mod.sPh.PhotoModel!=null)
- {
- Ordpg_Sights=mod.sPh.PhotoModel.Ordpg_Sights;
- }
- if (dInfo.G_TotalFreeBytes < 3)
- {
- ExMessageBoxCustom.Show("服务器上保存设计片的目录容量小于 3GB 所以不能导入相片,请重新设置设计片保存目录。");
- return false;
- }
- try
- {
- LYFZ.BLL.BLL_ErpSystemLogs.WriteSystemLog(EnumPublic.SystemLogsType.相片导入导出,
- "" + LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name + "导入设计片[订单号:" + mod.erpOrder.Ord_Number + "/" + mod.erpOrder.Ord_SinceOrderNumber + "(" + mod.erpDigOrder.Ordv_ViceNumber + ")]" +Ordpg_Sights ,
- LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID,
- LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name);
- }
- catch { }
-
- // this.currentDigModel.Ordv_LookDesignStatus = "0";//测试用
- bool bl = false;
- List<string> hasBeenImportedPhotoList = mod.sPh.GetSpecifyTypePhotoList(Model.Model_ErpOrder.DirectoryType.DesignPiece, BLL.SelectPhotoHandling.PhotoType.Original, sightsName: Ordpg_Sights);
- if (hasBeenImportedPhotoList.Count > 0)
- {
- if (ExMessageBoxCustom.Show("当前订单(或拍摄阶段)已导入过设计片,请确认你选择的相片是没导入过的,否则会覆盖原来设计片。\r\n是否确定要继续导入?", msgBoxButton: System.Windows.Forms.MessageBoxButtons.YesNo) != System.Windows.Forms.DialogResult.Yes)
- {
- return false;
- }
- }
- LYFZ.EnumPublic.LookDesignStatusEnum currentLookDesignStatus = EnumPublic.LookDesignStatusEnum.未看;
- try
- {
- currentLookDesignStatus = (LYFZ.EnumPublic.LookDesignStatusEnum)Convert.ToInt32(mod.erpDigOrder.Ordv_LookDesignStatus);
- }
- catch { }
- if (currentLookDesignStatus == EnumPublic.LookDesignStatusEnum.OK)
- {
- ExMessageBoxCustom.Show("当前订单(或拍摄阶段)已经确认设计版,不能再导入设计版。");
- return false;
- }
- try
- {
- LYFZ.BLL.BLL_PhotoImportRecordTable.UpdatePhotoImportRecordTable(LYFZ.Model.Model_ErpOrder.DirectoryType.DesignPiece,
- mod.CurrentCompanyInfoID, mod.erpOrder.Ord_Number, 1, PhotoImportRecordType.Import);
- }
- catch (Exception ex)
- {
- ExMessageBoxCustom.Show("更新导片记录时失败:" + ex.Message);
- return false;
- }
- try
- {
- if (hasBeenImportedPhotoList.Count <= 0 && !mod.importGenerateThumbnails)
- {
- StartGenerateThumbnails(Model.Model_ErpOrder.DirectoryType.DesignPiece, mod.erpOrder.Ord_Number);
- }
- if (currentLookDesignStatus != EnumPublic.LookDesignStatusEnum.未看)
- {
- //LYFZ.BLL.BLL_ErpOrderDigital currentOrderDigBll = new BLL.BLL_ErpOrderDigital();
- if (ExMessageBoxCustom.Show("是否所有设计版修改完成?", msgBoxButton: System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
- {
- okActive = "AllPush";
- }
- else
- {
- okActive = "NotAllPush";
- }
- }
- return true;
- }
- catch (Exception ex)
- {
- ExMessageBoxCustom.Show(ex.Message);
- return true;
- }
- }
- public void ImportDesignPiece(frmFileImportModel mod, int i)
- {
- string Ordpg_Sights = "";
- if (mod.sPh.PhotoModel != null)
- {
- Ordpg_Sights = mod.sPh.PhotoModel.Ordpg_Sights;
- }
- List<string> hasBeenImportedPhotoList = mod.sPh.GetSpecifyTypePhotoList(Model.Model_ErpOrder.DirectoryType.DesignPiece, BLL.SelectPhotoHandling.PhotoType.Original, sightsName: Ordpg_Sights);
- bool bl = false;
- try
- {
-
- //string msg = mod.sPh.ImportDesignPiece(mod.comeDirectoryPath, mod.service_Path, mod.sPh.PhotoModel.Ordpg_Sights, null, mod.importGenerateThumbnails);
- string retString = "";
- string currentShootingName = Ordpg_Sights.Trim();
- Model.Model_ErpOrder.DirectoryType dirType = Model.Model_ErpOrder.DirectoryType.DesignPiece;
- string sourceDirectory = LYFZ.WinAPI.CustomPublicMethod.GetFullDirectoryPath(mod.comeDirectoryPath);
- if (currentShootingName.Length > 0)
- {
- //选择的来源目录下的目录集合,不含子目录
- string[] tempShootingNameDirectoryNames = System.IO.Directory.GetDirectories(sourceDirectory);
- //判断要导入的源目录下的子目录名是否为当前拍摄阶段名
- bool isCurrentTakenNameInDirName = false;
- if (tempShootingNameDirectoryNames.Length > 0)
- {
- string tempDirPath = "";
- foreach (string dirPath in tempShootingNameDirectoryNames)
- {
- string tempdirName = System.IO.Path.GetFileName(dirPath);
- if (tempdirName.ToLower() == currentShootingName.ToLower())
- {
- tempDirPath = dirPath;
- isCurrentTakenNameInDirName = true;
- break;
- }
- }
- if (isCurrentTakenNameInDirName && tempShootingNameDirectoryNames.Length > 1)
- {
- sourceDirectory = LYFZ.WinAPI.CustomPublicMethod.GetFullDirectoryPath(tempDirPath);
- }
- }
- }
- if (!Directory.Exists(sourceDirectory))
- {
- ExMessageBoxCustom.Show("未找到导片相应的文件夹目录,导片失败,请核实需导片的文件夹是否存在。");
- return;
- }
- List<string> sourcFileList = mod.sPh.GetLocalPhotoList(sourceDirectory);
- if (sourcFileList.Count <= 0)
- {
- retString = "您选择的目录下没有找到要导入的相片,请检查选择的目录是否正确。";
- }
- //总计数器
- float sumCount = sourcFileList.Count;
- //当前计数器
- int currentCount = 0;
- string toSavePath = LYFZ.WinAPI.CustomPublicMethod.GetFullDirectoryPath(mod.service_Path);
- //当前拍摄景点
- string currentTakenName = "";
- if (mod.sPh.PhotoModel != null)
- {
- currentTakenName = Ordpg_Sights;
- }
- foreach (string sourcFile in sourcFileList)
- {
- currentCount++;
- frmFileImportItemModel tempItem = mod.local_Path.Find(p => p.local_Path.Equals(sourcFile) && p.code == 0);
- if (tempItem == null)
- {
- continue;
- }
- tempItem.upload_Msg = "正在上传";
- ImportTaskFileManager(mod);
- ///管理窗体显示
- if (SingletonThreadImportFileFormEvent != null)
- {
- SingletonThreadImportFileFormEvent(enumImportMultipFieForm.BackNext, mod);
- }
- //this.SetBackgroundWorker(sumCount, currentCount, "正在导入相片,请稍等...", backgroundWorker);
- if (LYFZ.BLL.SelectPhotoHandling.ImportVerificationIsExplain(sourcFile)) { continue; }
- //要导入文件要在服务器中创建的目录
- string sourceDir = (System.IO.Path.GetDirectoryName(sourcFile) + "\\").Substring(sourceDirectory.Length);
- if (currentShootingName.Length > 0)
- {
- if (sourceDir.IndexOf(currentShootingName + "\\") == 0)
- {
- sourceDir = sourceDir.Substring(currentShootingName.Length + 1);
- }
- }
- string sourcFileName = System.IO.Path.GetFileName(sourcFile);
- string toSaveNewFilePath = toSavePath + sourceDir;
- string smallImagePath = toSaveNewFilePath + LYFZ.BLL.SelectPhotoHandling.PhotoType.Small + "\\";
- //创建目录
- if (!System.IO.Directory.Exists(toSavePath))
- {
- try
- {
- System.IO.Directory.CreateDirectory(toSavePath);
- }
- catch
- {
- retString = "服务器上目录路径不正确,请配置好服务器共享目录后重试!\r\n错误目录:" + toSavePath;
- break;
- }
- }
- #region 处理如果导入相片与已导入相片存在相同产品名且相片名也相同的情况替换已存在相片
- hasBeenImportedPhotoList = mod.sPh.GetSpecifyTypePhotoList(dirType, BLL.SelectPhotoHandling.PhotoType.Original, sightsName: currentTakenName);
- string sourcPhotoName = LYFZ.BLL.SelectPhotoHandling.GetDesignConfirmName(sourcFile, currentTakenName, mod.erpOrder.Ord_Number);
- string sameProductPhoto = "";
- foreach (string photoPath in hasBeenImportedPhotoList)
- {
- string beModifiedPhotoName = LYFZ.BLL.SelectPhotoHandling.GetDesignConfirmName(photoPath, currentTakenName, mod.erpOrder.Ord_Number);
- if (sourcPhotoName.ToLower() == beModifiedPhotoName.ToLower())
- {
- sameProductPhoto = photoPath;
- break;
- }
- }
- #endregion
- try
- {
- if (sameProductPhoto.Trim().Length > 0)
- {
- if (File.Exists(sourcFile))
- {
- if (!mod.sPh.ImportPhotoFile(System.IO.Path.GetDirectoryName(sameProductPhoto), sourcFile, true, mod.importGenerateThumbnails))
- {
- retString = "相片导入失败,可能待替换的相片被占用,请重启服务器电脑后重试";
- tempItem.success = false;
- tempItem.code = -1;
- tempItem.upload_Msg = "上传失败";
- ImportTaskFileManager(mod);
- }
- else
- {
- tempItem.success = true;
- tempItem.code = 1;
- tempItem.upload_Msg = "上传成功";
- //if (SingletonThreadImportFileEvent != null)
- //{
- // SingletonThreadImportFileEvent(enumImportMultipFie.Number, GetProThreadNumber());
- //}
- ImportTaskFileManager(mod);
- }
- }
- else
- {
- tempItem.success = false;
- tempItem.code = -1;
- tempItem.upload_Msg = "上传失败-文件不存在";
- ImportDataLogs(DateTime.Now.ToString() + " 文件导入失败,路径:" + sourcFile + ",文件不存在\r\n");
- ImportTaskFileManager(mod);
- }
- if (SingletonThreadImportFileFormEvent != null)
- {
- SingletonThreadImportFileFormEvent(enumImportMultipFieForm.BackNext, mod);
- }
- }
- else
- {
- if (File.Exists(sourcFile))
- {
- if (!mod.sPh.ImportPhotoFile(toSaveNewFilePath, sourcFile, true, mod.importGenerateThumbnails))
- {
- retString = "相片导入失败,服务器相片路径设置不正确,或没有写入权限,请重新设置后重试";
- tempItem.success = false;
- tempItem.code = -1;
- tempItem.upload_Msg = "上传失败";
- ImportTaskFileManager(mod);
- }
- else
- {
- tempItem.success = true;
- tempItem.code = 1;
- tempItem.upload_Msg = "上传成功";
- //if (SingletonThreadImportFileEvent != null)
- //{
- // SingletonThreadImportFileEvent(enumImportMultipFie.Number, GetProThreadNumber());
- //}
- ImportTaskFileManager(mod);
- }
- }
- else
- {
- tempItem.success = false;
- tempItem.code = -1;
- tempItem.upload_Msg = "上传失败-文件不存在";
- ImportDataLogs(DateTime.Now.ToString() + " 文件导入失败,路径:" + sourcFile + ",文件不存在\r\n");
- ImportTaskFileManager(mod);
- }
- if (SingletonThreadImportFileFormEvent != null)
- {
- SingletonThreadImportFileFormEvent(enumImportMultipFieForm.BackNext, mod);
- }
- }
- if (bRestartThread)
- {
- // threadWord.Abort();
- SingletonThreadImportFileEvent(enumImportMultipFie.Restart, null);
- }
- }
- catch (Exception ex)
- {
- retString = "相片导入时出错:" + ex.Message;
- }
- }
- List<frmFileImportItemModel> tempItemList = mod.local_Path.FindAll(p => p.code == 0);
- foreach (frmFileImportItemModel tempItem in tempItemList)
- {
- tempItem.success = false;
- tempItem.code = -1;
- tempItem.upload_Msg = "上传失败-文件不存在";
- ImportDataLogs(DateTime.Now.ToString() + " 文件导入失败,路径:" + tempItem.local_Path + ",文件不存在\r\n");
- ImportTaskFileManager(mod);
- if (SingletonThreadImportFileFormEvent != null)
- {
- SingletonThreadImportFileFormEvent(enumImportMultipFieForm.BackNext, mod);
- }
- }
- if (retString.Trim().Length > 0)
- {
- //ExMessageBoxCustom.Show(msg);
- ///反馈主界面数量信息
- /*if (SingletonThreadImportFileEvent != null)
- {
- SingletonThreadImportFileEvent(enumImportMultipFie.MsgError, "订单" + mod.erpOrder.Ord_Number + "" + retString);
- }*/
- mod.errorMsg = retString;
- }
- else
- {
- bl = true;
- mod.Success = true;
- if (mod.okActive == "AllPush")
- {
- LYFZ.BLL.BLL_ErpOrderDigital currentOrderDigBll = new BLL.BLL_ErpOrderDigital();
- mod.erpDigOrder.Ordv_LookDesignStatus = ((int)EnumPublic.LookDesignStatusEnum.已修改).ToString();
- if (currentOrderDigBll.SetLookDesignStatus(mod.erpDigOrder.Ordv_ViceNumber, mod.erpDigOrder.Ordv_LookDesignStatus))
- {
- //ExMessageBoxCustom.Show("导入成功,辛苦了!");
- }
- else if (mod.okActive == "NotAllPush")
- {
- /*if (SingletonThreadImportFileEvent != null)
- {
- SingletonThreadImportFileEvent(enumImportMultipFie.MsgError, "订单:" + mod.erpOrder.Ord_Number + "[设计]的设计状态更新失败!" );
- }*/
- mod.errorMsg += "订单:" + mod.erpOrder.Ord_Number + "[设计]的设计状态更新失败!";
- //ExMessageBoxCustom.Show("抱歉,看设计状态更新失败!");
- }
- }
- else
- {
- //ExMessageBoxCustom.Show("导入成功,辛苦了!其它设计版请尽快修改完成。");
- //SingletonThreadImportFileEvent(enumImportMultipFie.MsgError, "订单:" + mod.erpOrder.Ord_Number + "[设计]的设计状态更新失败!");
- }
- }
- ///开始操作
- if (bl)
- {
- /*LYFZ.Model.Model_ErpOrder modelOrder = orbll.GetModel("Ord_Number", StrOrdNumber);
- modelOrder.Ord_PhotoPath = sPh.UpdatePhotoImportDirectoryPath(Model.Model_ErpOrder.DirectoryType.FineRetouch, strprht.FullName);
- modelOrder.Ord_PhotoBackupPath = "NEW";
- modelOrder.Ord_UpdateDateTime = StrTime;
- modelOrder.Ord_UpdateName = StrUserName;
- clist.Add(orbll.GetImportPhotoUpdateOrder(modelOrder));*/
- mod.erpOrder.Ord_PhotoPath = mod.sPh.UpdatePhotoImportDirectoryPath(Model.Model_ErpOrder.DirectoryType.DesignPiece, mod.service_Path);
- mod.erpOrder.Ord_PhotoBackupPath = "NEW";
- mod.erpOrder.Ord_UpdateDateTime = SDateTime.Now;
- mod.erpOrder.Ord_UpdateName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
- List<LYFZ.Helper.CommandInfo> clist = new List<Helper.CommandInfo>();
- //clist.AddRange(mod.FrmClist);
- clist.Add(orbll.GetImportPhotoUpdateOrder(mod.erpOrder));
- //LYFZ.BLL.BLL_ErpOrderDigital odbll = new BLL.BLL_ErpOrderDigital();
- //LYFZ.Model.Model_ErpOrderDigital modelDigital = odbll.GetModel("Ordv_ViceNumber", mod.OrdViceNumber);
- //if (modelDigital.Ordv_DesignerStatus.Trim() != "2")
- //{
- // modelDigital.Ordv_DesignerName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
- // modelDigital.Ordv_DesignerTime = mod.erpOrder.Ord_UpdateDateTime;
- // modelDigital.Ordv_DesignerStatus = mod.StrStatus;
- //}
- //modelDigital.Ordv_UpdateDateTime = SDateTime.Now;
- //modelDigital.Ordv_UpdateName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
- //clist.Add(odbll.GetUpdateCommandInfo(modelDigital));
- //#region 导入设计片时,完成所有外发片
- //if (mod.StrStatus.Trim() == "2")
- //{
- // LYFZ.BLL.BLL_ErpOrderOutSendDesignList outbll = new BLL.BLL_ErpOrderOutSendDesignList();
- // List<LYFZ.Model.Model_ErpOrderOutSendDesignList> mlist = outbll.GetModelList("Odlst_OrdNumber = '" + mod.OrdNumber + "' and Odlst_ViceNumber = '" + mod.OrdViceNumber + "' and Odlst_SendVendor != ''");
- // for (int iz = 0; iz < mlist.Count; iz++)
- // {
- // if (mlist[iz].Odlst_CompletedStatus != "1")
- // {
- // mlist[iz].Odlst_CompletedStatus = "1";
- // mlist[iz].Odlst_CompletedTime = mod.erpOrder.Ord_UpdateDateTime;
- // mlist[iz].Odlst_CompletedName = mod.erpOrder.Ord_UpdateName;
- // mlist[iz].Odlst_CreateDatetime = mod.erpOrder.Ord_UpdateDateTime;
- // mlist[iz].Odlst_CreateName = mod.erpOrder.Ord_UpdateName;
- // clist.Add(outbll.GetUpdateCommandInfo(mlist[iz]));
- // }
- // }
- //}
- //#endregion
- pcrsbll.SetServicePhotographCount(LYFZ.Model.Model_ErpOrder.DirectoryType.DesignPiece, mod.erpDigOrder.Ordv_Number, mod.erpDigOrder.Ordv_ViceNumber, mod.takenName, "4");
- ///开始执行数据保存
- LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist);
- if (SingletonThreadImportFileEvent != null)
- {
- SingletonThreadImportFileEvent(enumImportMultipFie.Number, GetProThreadNumber());
- }
- }
- else if (mod.errorMsg.IndexOf("暂停") == -1)
- {
- mod.Success = false;
- mod.errorMsg = "导入失败";
- }
- }
- catch (Exception ex)
- {
- //ExMessageBoxCustom.Show(ex.Message);
- if (SingletonThreadImportFileEvent != null)
- {
- SingletonThreadImportFileEvent(enumImportMultipFie.MsgError, ex.Message);
- }
- }
- }
- #endregion
- #region 精修导入
- public bool CheckRefinedRepairPiece(frmFileImportModel mod)
- {
- TipsIs64BitProcess();
- LYFZ.WinAPI.MyDriverInfo dInfo = LYFZ.WinAPI.CustomPublicMethod.GetDiskFreeSpace(mod.service_Path);
- string Ordpg_Sights = "";
- if (mod.sPh.PhotoModel != null)
- {
- Ordpg_Sights = mod.sPh.PhotoModel.Ordpg_Sights;
- }
- if (dInfo.G_TotalFreeBytes < 3)
- {
- ExMessageBoxCustom.Show("服务器上保存精修片的目录容量小于 3GB 所以不能导入相片,请重新设置精修片保存目录。");
- return false;
- }
- List<string> hasBeenImportedPhotoList = mod.sPh.GetSpecifyTypePhotoList(Model.Model_ErpOrder.DirectoryType.FineRetouch, BLL.SelectPhotoHandling.PhotoType.Original, sightsName: Ordpg_Sights);
- if (hasBeenImportedPhotoList.Count > 0)
- {
- if (ExMessageBoxCustom.Show("当前订单(或拍摄阶段)已导入过精修片,请确认你选择的相片是没导入过的,否则会覆盖原来精修片。\r\n是否确定要继续导入?", msgBoxButton: System.Windows.Forms.MessageBoxButtons.YesNo) != System.Windows.Forms.DialogResult.Yes)
- {
- return false;
- }
- }
- try
- {
- LYFZ.BLL.BLL_PhotoImportRecordTable.UpdatePhotoImportRecordTable(LYFZ.Model.Model_ErpOrder.DirectoryType.FineRetouch, mod.CurrentCompanyInfoID, mod.erpOrder.Ord_Number, 1, PhotoImportRecordType.Import);
- }
- catch (Exception ex)
- {
- ExMessageBoxCustom.Show("更新导片记录时失败:" + ex.Message);
- return false;
- }
- return true;
- }
- public void ImportRefinedRepairPiece(frmFileImportModel mod,int i)
- {
- string Ordpg_Sights = "";
- if (mod.sPh.PhotoModel != null)
- {
- Ordpg_Sights = mod.sPh.PhotoModel.Ordpg_Sights;
- }
- List<string> hasBeenImportedPhotoList = mod.sPh.GetSpecifyTypePhotoList(Model.Model_ErpOrder.DirectoryType.FineRetouch, BLL.SelectPhotoHandling.PhotoType.Original, sightsName: Ordpg_Sights);
- bool bl = false;
- try
- {
- if (hasBeenImportedPhotoList.Count <= 0 && !mod.importGenerateThumbnails)
- {
- StartGenerateThumbnails(Model.Model_ErpOrder.DirectoryType.FineRetouch, mod.erpOrder.Ord_Number);
- }
- try
- {
- LYFZ.BLL.BLL_ErpSystemLogs.WriteSystemLog(EnumPublic.SystemLogsType.相片导入导出,
- "" + LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name + "导入精修片[订单号:" + mod.erpOrder.Ord_Number + "/" + mod.erpOrder.Ord_SinceOrderNumber + "(" + mod.erpDigOrder.Ordv_ViceNumber + ")]" + Ordpg_Sights,
- LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID,
- LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name);
- }
- catch { }
- //string msg = mod.sPh.ImportDesignPiece(mod.comeDirectoryPath, mod.service_Path, mod.sPh.PhotoModel.Ordpg_Sights, null, mod.importGenerateThumbnails);
- string retString = "";
- string currentShootingName = Ordpg_Sights.Trim();
- Model.Model_ErpOrder.DirectoryType dirType = Model.Model_ErpOrder.DirectoryType.FineRetouch;
- string sourceDirectory = LYFZ.WinAPI.CustomPublicMethod.GetFullDirectoryPath(mod.comeDirectoryPath);
- if (currentShootingName.Length > 0)
- {
- //选择的来源目录下的目录集合,不含子目录
- string[] tempShootingNameDirectoryNames = System.IO.Directory.GetDirectories(sourceDirectory);
- //判断要导入的源目录下的子目录名是否为当前拍摄阶段名
- bool isCurrentTakenNameInDirName = false;
- if (tempShootingNameDirectoryNames.Length > 0)
- {
- string tempDirPath = "";
- foreach (string dirPath in tempShootingNameDirectoryNames)
- {
- string tempdirName = System.IO.Path.GetFileName(dirPath);
- if (tempdirName.ToLower() == currentShootingName.ToLower())
- {
- tempDirPath = dirPath;
- isCurrentTakenNameInDirName = true;
- break;
- }
- }
- if (isCurrentTakenNameInDirName && tempShootingNameDirectoryNames.Length > 1)
- {
- sourceDirectory = LYFZ.WinAPI.CustomPublicMethod.GetFullDirectoryPath(tempDirPath);
- }
- }
- }
- if (!Directory.Exists(sourceDirectory))
- {
- ExMessageBoxCustom.Show("未找到导片相应的文件夹目录,导片失败,请核实需导片的文件夹是否存在。");
- return ;
- }
- List<string> sourcFileList = mod.sPh.GetLocalPhotoList(sourceDirectory);
- if (sourcFileList.Count <= 0)
- {
- retString = "您选择的目录下没有找到要导入的相片,请检查选择的目录是否正确。";
- }
- //总计数器
- float sumCount = sourcFileList.Count;
- //当前计数器
- int currentCount = 0;
- string toSavePath = LYFZ.WinAPI.CustomPublicMethod.GetFullDirectoryPath(mod.service_Path);
- //当前拍摄景点
- string currentTakenName = "";
- if (mod.sPh.PhotoModel != null)
- {
- currentTakenName = Ordpg_Sights;
- }
- foreach (string sourcFile in sourcFileList)
- {
- currentCount++;
- frmFileImportItemModel tempItem = mod.local_Path.Find(p => p.local_Path.Equals(sourcFile) && p.code == 0);
- if (tempItem==null)
- {
- continue;
- }
- tempItem.upload_Msg = "正在上传";
- ImportTaskFileManager(mod);
- ///管理窗体显示
- if (SingletonThreadImportFileFormEvent != null)
- {
- SingletonThreadImportFileFormEvent(enumImportMultipFieForm.BackNext, mod);
- }
- //this.SetBackgroundWorker(sumCount, currentCount, "正在导入相片,请稍等...", backgroundWorker);
- if (LYFZ.BLL.SelectPhotoHandling.ImportVerificationIsExplain(sourcFile)) { continue; }
- //要导入文件要在服务器中创建的目录
- string sourceDir = (System.IO.Path.GetDirectoryName(sourcFile) + "\\").Substring(sourceDirectory.Length);
- if (currentShootingName.Length > 0)
- {
- if (sourceDir.IndexOf(currentShootingName + "\\") == 0)
- {
- sourceDir = sourceDir.Substring(currentShootingName.Length + 1);
- }
- }
- string sourcFileName = System.IO.Path.GetFileName(sourcFile);
- string toSaveNewFilePath = toSavePath + sourceDir;
- string smallImagePath = toSaveNewFilePath + LYFZ.BLL.SelectPhotoHandling.PhotoType.Small + "\\";
- //创建目录
- if (!System.IO.Directory.Exists(toSavePath))
- {
- try
- {
- System.IO.Directory.CreateDirectory(toSavePath);
- }
- catch
- {
- retString = "服务器上目录路径不正确,请配置好服务器共享目录后重试!\r\n错误目录:" + toSavePath;
- break;
- }
- }
- #region 处理如果导入相片与已导入相片存在相同产品名且相片名也相同的情况替换已存在相片
- hasBeenImportedPhotoList = mod.sPh.GetSpecifyTypePhotoList(dirType, BLL.SelectPhotoHandling.PhotoType.Original, sightsName: currentTakenName);
- string sourcPhotoName = LYFZ.BLL.SelectPhotoHandling.GetDesignConfirmName(sourcFile, currentTakenName, mod.erpOrder.Ord_Number);
- string sameProductPhoto = "";
- foreach (string photoPath in hasBeenImportedPhotoList)
- {
- string beModifiedPhotoName =LYFZ.BLL.SelectPhotoHandling.GetDesignConfirmName(photoPath, currentTakenName, mod.erpOrder.Ord_Number);
- if (sourcPhotoName.ToLower() == beModifiedPhotoName.ToLower())
- {
- sameProductPhoto = photoPath;
- break;
- }
- }
- #endregion
- try
- {
- if (sameProductPhoto.Trim().Length > 0)
- {
- if (File.Exists(sourcFile))
- {
- if (!mod.sPh.ImportPhotoFile(System.IO.Path.GetDirectoryName(sameProductPhoto), sourcFile, true, mod.importGenerateThumbnails))
- {
- retString = "相片导入失败,可能待替换的相片被占用,请重启服务器电脑后重试";
- tempItem.success = false;
- tempItem.code = -1;
- tempItem.upload_Msg = "上传失败";
- ImportTaskFileManager(mod);
- }
- else
- {
- tempItem.success = true;
- tempItem.code = 1;
- tempItem.upload_Msg = "上传成功";
- //if (SingletonThreadImportFileEvent != null)
- //{
- // SingletonThreadImportFileEvent(enumImportMultipFie.Number, GetProThreadNumber());
- //}
- ImportTaskFileManager(mod);
- }
- }
- else
- {
- tempItem.success = false;
- tempItem.code = -1;
- tempItem.upload_Msg = "上传失败-文件不存在";
- ImportDataLogs(DateTime.Now.ToString() + " 文件导入失败,路径:" + sourcFile + ",文件不存在\r\n");
- ImportTaskFileManager(mod);
- }
- if (SingletonThreadImportFileFormEvent != null)
- {
- SingletonThreadImportFileFormEvent(enumImportMultipFieForm.BackNext, mod);
- }
- }
- else
- {
- if (File.Exists(sourcFile))
- {
- if (!mod.sPh.ImportPhotoFile(toSaveNewFilePath, sourcFile, true, mod.importGenerateThumbnails))
- {
- retString = "相片导入失败,服务器相片路径设置不正确,或没有写入权限,请重新设置后重试";
- tempItem.success = false;
- tempItem.code = -1;
- tempItem.upload_Msg = "上传失败";
- ImportTaskFileManager(mod);
- }
- else
- {
- tempItem.success = true;
- tempItem.code = 1;
- tempItem.upload_Msg = "上传成功";
- //if (SingletonThreadImportFileEvent != null)
- //{
- // SingletonThreadImportFileEvent(enumImportMultipFie.Number, GetProThreadNumber());
- //}
- ImportTaskFileManager(mod);
- }
- }
- else
- {
- tempItem.success = false;
- tempItem.code = -1;
- tempItem.upload_Msg = "上传失败-文件不存在";
- ImportDataLogs(DateTime.Now.ToString() + " 文件导入失败,路径:" + sourcFile + ",文件不存在\r\n");
- ImportTaskFileManager(mod);
- }
- if (SingletonThreadImportFileFormEvent != null)
- {
- SingletonThreadImportFileFormEvent(enumImportMultipFieForm.BackNext, mod);
- }
- }
- if(bRestartThread)
- {
- //threadWord.Abort();
- SingletonThreadImportFileEvent(enumImportMultipFie.Restart, null);
- }
- }
- catch (Exception ex)
- {
- retString = "相片导入时出错:" + ex.Message;
- }
- }
- List<frmFileImportItemModel> tempItemList = mod.local_Path.FindAll(p => p.code == 0);
- foreach (frmFileImportItemModel tempItem in tempItemList)
- {
- tempItem.success = false;
- tempItem.code = -1;
- tempItem.upload_Msg = "上传失败-文件不存在";
- ImportDataLogs(DateTime.Now.ToString() + " 文件导入失败,路径:" + tempItem.local_Path + ",文件不存在\r\n");
- ImportTaskFileManager(mod);
- if (SingletonThreadImportFileFormEvent != null)
- {
- SingletonThreadImportFileFormEvent(enumImportMultipFieForm.BackNext, mod);
- }
- }
- if (retString.Trim().Length > 0)
- {
- //ExMessageBoxCustom.Show(msg);
- ///反馈主界面数量信息
- /*if (SingletonThreadImportFileEvent != null)
- {
- SingletonThreadImportFileEvent(enumImportMultipFie.MsgError, "订单" + mod.erpOrder.Ord_Number + "" + retString);
- }*/
- mod.errorMsg="订单" + mod.erpOrder.Ord_Number + "" + retString;
- }
- else
- {
- mod.Success = true;
- bl = true;
- }
- if (bl)
- {
- LYFZ.BLL.BLL_ErpOrderDigital odbll = new BLL.BLL_ErpOrderDigital();
- /*LYFZ.Model.Model_ErpOrder modelOrder = orbll.GetModel("Ord_Number", StrOrdNumber);
- modelOrder.Ord_PhotoPath = sPh.UpdatePhotoImportDirectoryPath(Model.Model_ErpOrder.DirectoryType.FineRetouch, strprht.FullName);
- modelOrder.Ord_PhotoBackupPath = "NEW";
- modelOrder.Ord_UpdateDateTime = StrTime;
- modelOrder.Ord_UpdateName = StrUserName;
- clist.Add(orbll.GetImportPhotoUpdateOrder(modelOrder));*/
- mod.erpOrder.Ord_PhotoPath = mod.sPh.UpdatePhotoImportDirectoryPath(Model.Model_ErpOrder.DirectoryType.FineRetouch, mod.service_Path);
- mod.erpOrder.Ord_PhotoBackupPath = "NEW";
- mod.erpOrder.Ord_UpdateDateTime = SDateTime.Now;
- mod.erpOrder.Ord_UpdateName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
- List<LYFZ.Helper.CommandInfo> clist = new List<Helper.CommandInfo>();
- //clist.AddRange(mod.FrmClist);
- clist.Add(orbll.GetImportPhotoUpdateOrder(mod.erpOrder));
- //LYFZ.Model.Model_ErpOrderDigital modelDigital = odbll.GetModel("Ordv_ViceNumber", mod.OrdViceNumber);
- //if (modelDigital.Ordv_RefinementStatus.Trim() != "2")
- //{
- // modelDigital.Ordv_RefinementName = mod.erpOrder.Ord_UpdateName;
- // modelDigital.Ordv_RefinementStatus = mod.StrStatus;
- // modelDigital.Ordv_RefinementTime = mod.erpOrder.Ord_UpdateDateTime;
- //}
- //modelDigital.Ordv_UpdateDateTime = mod.erpOrder.Ord_UpdateDateTime;
- //modelDigital.Ordv_UpdateName = mod.erpOrder.Ord_UpdateName;
- //clist.Add(odbll.GetUpdateCommandInfo(modelDigital));
- pcrsbll.SetServicePhotographCount(LYFZ.Model.Model_ErpOrder.DirectoryType.FineRetouch, mod.erpDigOrder.Ordv_Number, mod.erpDigOrder.Ordv_ViceNumber, mod.takenName, "5");
- LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist);
- if (SingletonThreadImportFileEvent != null)
- {
- SingletonThreadImportFileEvent(enumImportMultipFie.Number, GetProThreadNumber());
- }
- }
- else if (mod.errorMsg.IndexOf("暂停") == -1)
- {
- mod.Success = false;
- mod.errorMsg = "导入失败";
- }
- }
- catch (Exception ex)
- {
- //ExMessageBoxCustom.Show(ex.Message);
- if (SingletonThreadImportFileEvent != null)
- {
- SingletonThreadImportFileEvent(enumImportMultipFie.MsgError, ex.Message);
- }
- }
- }
- #endregion
- #region 修片导入
- public bool CheckImportFileByEarlyRetouch(frmFileImportModel mod)
- {
- TipsIs64BitProcess();
- LYFZ.WinAPI.MyDriverInfo dInfo = LYFZ.WinAPI.CustomPublicMethod.GetDiskFreeSpace(mod.service_Path);
- string Ordpg_Sights = "";
- if (mod.sPh.PhotoModel != null)
- {
- Ordpg_Sights = mod.sPh.PhotoModel.Ordpg_Sights;
- }
- if (dInfo.G_TotalFreeBytes < 3)
- {
- ExMessageBoxCustom.Show("服务器上保存初修片的目录容量小于 3GB 所以不能导入相片,请重新设置初修片保存目录。");
- return false;
- }
- bool bl = false;
- if(!Directory.Exists(mod.comeDirectoryPath))
- {
- ExMessageBoxCustom.Show("未找到导片相应的文件夹目录,导片失败,请核实需导片的文件夹是否存在。");
- return false;
- }
- //当前订单已导入相片集合
- List<string> importedPhotoList = mod.sPh.GetLocalPhotoList(mod.comeDirectoryPath);
- //总计数器
- float sumCount = importedPhotoList.Count;
- //当前计数器
- int currentCount = 0;
- string sightsName = "";//儿童版时的阶段
- if ((EnumPublic.OrderType)Convert.ToInt32(mod.erpOrder.Ord_Type) == EnumPublic.OrderType.儿童订单)
- {
- sightsName = Ordpg_Sights;
- }
- //当前订单已导入原片相片集合
- List<string> hasBeenImportedPhotoList = mod.sPh.GetSpecifyTypePhotoList(Model.Model_ErpOrder.DirectoryType.PrimitivePicture, BLL.SelectPhotoHandling.PhotoType.Original);
- //当前订单已导入初修片相片集合
- List<string> earlyRetouchImportedPhotoList = mod.sPh.GetSpecifyTypePhotoList(Model.Model_ErpOrder.DirectoryType.EarlyRetouch, BLL.SelectPhotoHandling.PhotoType.Original);
- bool isImport = true;//是否导入相片
- string sameNameLogsFilePath = "";
- if (!mod.sPh.CheckPhotoExist(earlyRetouchImportedPhotoList, importedPhotoList, ref sameNameLogsFilePath))
- {
- isImport = true;
- }
- else
- {
- // ImportRepairPieceWarning importWarning = new ImportRepairPieceWarning("系统检测到要导入的相片名出现重名冲突,您可以选择断续导入将替换同名相片。\r\n也可以选择取消导入本次导入操作。", sameNameLogsFilePath);
- ImportRepairPieceWarning importWarning = new ImportRepairPieceWarning("系统检测到要导入的相片名出现重名冲突,请选择取消导入本次的导入操作,删除同名相片或重命名后再导入。\r\n也可以选择继续导入替换已存在相片文件。", sameNameLogsFilePath);
- importWarning.TopMost = true;
- // importWarning.SbtnContinueImport.Visible = false;
- if (importWarning.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- isImport = true;
- }
- else
- {
- isImport = false;
- }
- }
- try
- {
- LYFZ.BLL.BLL_PhotoImportRecordTable.UpdatePhotoImportRecordTable(LYFZ.Model.Model_ErpOrder.DirectoryType.EarlyRetouch, mod.CurrentCompanyInfoID, mod.erpOrder.Ord_Number, 1, PhotoImportRecordType.Import);
- }
- catch (Exception ex)
- {
- isImport = false;
- bl = false;
- ExMessageBoxCustom.Show("更新导片记录时失败:" + ex.Message);
- }
- if (isImport)
- {
- if (hasBeenImportedPhotoList.Count <= 0 || mod.sPh.CheckEarlyRepairInOriginalPhotoExist(hasBeenImportedPhotoList, mod.comeDirectoryPath, ref sameNameLogsFilePath))
- {
- isImport = true;
- }
- else
- {
- ImportRepairPieceWarning importWarning = new ImportRepairPieceWarning("系统检测到要导入的初修片可能不是来源与已导入的原片\r\n您可以选择断续导入但系统无法保证初修片与原片的一致性\r\n也可以选择取消导入本次导入操作。", sameNameLogsFilePath);
- importWarning.TopMost = true;
- if (importWarning.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- isImport = true;
- }
- else
- {
- isImport = false;
- }
- }
- }
- return isImport;
- }
- void ImportFileByEarlyRetouch(frmFileImportModel mod, int i)
- {
- //if (!InternaNetworkAddress) { return false; }
- if (!Directory.Exists(mod.comeDirectoryPath))
- {
- ExMessageBoxCustom.Show("未找到导片相应的文件夹目录,导片失败,请核实需导片的文件夹是否存在。");
- return;
- }
- List<string> importedPhotoList = mod.sPh.GetLocalPhotoList(mod.comeDirectoryPath);
- string Ordpg_Sights = "";
- if (mod.sPh.PhotoModel != null)
- {
- Ordpg_Sights = mod.sPh.PhotoModel.Ordpg_Sights;
- }
- int currentCount = 0;
- try
- {
- LYFZ.BLL.BLL_ErpSystemLogs.WriteSystemLog(EnumPublic.SystemLogsType.相片导入导出,
- "" + LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name + "导入" + importedPhotoList.Count + "张初修片[订单号:" + mod.erpOrder.Ord_Number + "/" + mod.erpOrder.Ord_SinceOrderNumber + "(" + mod.erpDigOrder.Ordv_ViceNumber + ")]" + Ordpg_Sights,
- LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID,
- LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name);
- }
- catch { }
- bool bl = true;
- // LYFZ.PhotoSelectSystem.PhotoImportExport.StartGenerateThumbnails(Model.Model_ErpOrder.DirectoryType.EarlyRetouch, this.currentModel.Ord_Number);
- int importFailed = 0;
- foreach (string photoFile in importedPhotoList)
- {
- currentCount++;
- frmFileImportItemModel tempItem = mod.local_Path.Find(p => p.local_Path.Equals(photoFile) && p.code == 0);
- if (tempItem==null)
- {
- continue;
- }
- tempItem.upload_Msg = "正在上传";
- ImportTaskFileManager(mod);
- ///管理窗体显示
- if (SingletonThreadImportFileFormEvent != null)
- {
- SingletonThreadImportFileFormEvent(enumImportMultipFieForm.BackNext, mod);
- }
- #region 处理如果导入相片与已导入相片存在相片名相同的情况替换已存在相片
- List<string> hasBeenImportedPhotoList2 = mod.sPh.GetSpecifyTypePhotoList(Model.Model_ErpOrder.DirectoryType.EarlyRetouch, BLL.SelectPhotoHandling.PhotoType.Original);
- string sourcPhotoName = System.IO.Path.GetFileName(photoFile); //;
- string sameProductPhoto = "";//重名文件路径
- foreach (string photoPath in hasBeenImportedPhotoList2)
- {
- string beModifiedPhotoName = LYFZ.BLL.SelectPhotoHandling.ServerFileNameToOriginalName(photoPath); //GetDesignConfirmName(photoPath, currentTakenName, this.orderModel.Ord_Number);
- if (sourcPhotoName.ToLower() == beModifiedPhotoName.ToLower())
- {
- sameProductPhoto = photoPath;
- break;
- }
- }
- #endregion
- if (sameProductPhoto.Trim().Length > 0)
- {
- if (File.Exists(photoFile))
- {
- if (!mod.sPh.ImportPhotoFile(System.IO.Path.GetDirectoryName(sameProductPhoto), photoFile, true, mod.importGenerateThumbnails))
- {
- tempItem.success = false;
- tempItem.code = -1;
- tempItem.upload_Msg = "上传失败";
- ImportTaskFileManager(mod);
- importFailed++;
- }
- else
- {
- tempItem.success = true;
- tempItem.code = 1;
- tempItem.upload_Msg = "上传成功";
- //if (SingletonThreadImportFileEvent != null)
- //{
- // SingletonThreadImportFileEvent(enumImportMultipFie.Number, GetProThreadNumber());
- //}
- ImportTaskFileManager(mod);
- }
- }
- else
- {
- tempItem.success = false;
- tempItem.code = -1;
- tempItem.upload_Msg = "上传失败-文件不存在";
- ImportDataLogs(DateTime.Now.ToString() + " 文件导入失败,路径:" + photoFile + ",文件不存在\r\n");
- ImportTaskFileManager(mod);
- importFailed++;
- }
- }
- else
- {
- if (File.Exists(photoFile))
- {
- if (!mod.sPh.ImportPhotoFile(mod.service_Path, photoFile, importGenerateThumbnails: mod.importGenerateThumbnails))
- {
- tempItem.success = false;
- tempItem.code = -1;
- tempItem.upload_Msg = "上传失败";
- ImportTaskFileManager(mod);
- importFailed++;
- }
- else
- {
- tempItem.success = true;
- tempItem.code = 1;
- tempItem.upload_Msg = "上传成功";
- //if (SingletonThreadImportFileEvent != null)
- //{
- // SingletonThreadImportFileEvent(enumImportMultipFie.Number, GetProThreadNumber());
- //}
- ImportTaskFileManager(mod);
- }
- }
- else
- {
- tempItem.success = false;
- tempItem.code = -1;
- tempItem.upload_Msg = "上传失败-文件不存在";
- ImportDataLogs(DateTime.Now.ToString() + " 文件导入失败,路径:" + photoFile + ",文件不存在\r\n");
- ImportTaskFileManager(mod);
- importFailed++;
- }
- }
- ///管理窗体显示
- if (SingletonThreadImportFileFormEvent != null)
- {
- SingletonThreadImportFileFormEvent(enumImportMultipFieForm.BackNext, mod);
- }
- if (currentCount == 10 && !mod.importGenerateThumbnails)
- {
- LYFZ.PhotoSelectSystem.PhotoImportExport.StartGenerateThumbnails(Model.Model_ErpOrder.DirectoryType.EarlyRetouch, mod.erpOrder.Ord_Number);
- }
- //mod.sPh.SetBackgroundWorker(sumCount, currentCount, "正在导入相片,请稍等...", backgroundWorker);
- if (bRestartThread)
- {
- //threadWord.Abort();
- SingletonThreadImportFileEvent(enumImportMultipFie.Restart, null);
- }
- }
- List<frmFileImportItemModel> tempItemList = mod.local_Path.FindAll(p => p.code == 0);
- foreach(frmFileImportItemModel tempItem in tempItemList)
- {
- tempItem.success = false;
- tempItem.code = -1;
- tempItem.upload_Msg = "上传失败-文件不存在";
- ImportDataLogs(DateTime.Now.ToString() + " 文件导入失败,路径:" + tempItem.local_Path + ",文件不存在\r\n");
- ImportTaskFileManager(mod);
- importFailed++;
- if (SingletonThreadImportFileFormEvent != null)
- {
- SingletonThreadImportFileFormEvent(enumImportMultipFieForm.BackNext, mod);
- }
- if (currentCount == 10 && !mod.importGenerateThumbnails)
- {
- LYFZ.PhotoSelectSystem.PhotoImportExport.StartGenerateThumbnails(Model.Model_ErpOrder.DirectoryType.EarlyRetouch, mod.erpOrder.Ord_Number);
- }
- //mod.sPh.SetBackgroundWorker(sumCount, currentCount, "正在导入相片,请稍等...", backgroundWorker);
- if (bRestartThread)
- {
- //threadWord.Abort();
- SingletonThreadImportFileEvent(enumImportMultipFie.Restart, null);
- }
- }
- if (importFailed == 0)
- {
- bl = true;
- }
- else
- {
- bl = false;
- mod.errorMsg = "相片导入完成,但有 " + importFailed.ToString() + " 张导入失败。";
- //ExMessageBoxCustom.Show("相片导入完成,但有 " + importFailed.ToString() + " 张导入失败。", backgroundWorker: backgroundWorker);
- }
- if (importFailed < importedPhotoList.Count && !mod.importGenerateThumbnails)
- {
- LYFZ.PhotoSelectSystem.PhotoImportExport.StartGenerateThumbnails(Model.Model_ErpOrder.DirectoryType.EarlyRetouch, mod.erpOrder.Ord_Number);
- }
- if (bl)
- {
- LYFZ.BLL.BLL_ErpOrderDigital odbll = new BLL.BLL_ErpOrderDigital();
- LYFZ.BLL.BLL_ErpOrderDigitalStatus orsbll = new BLL.BLL_ErpOrderDigitalStatus();
- mod.Success = true;
- StartGenerateThumbnails(Model.Model_ErpOrder.DirectoryType.EarlyRetouch, mod.erpOrder.Ord_Number);
- /*#region 修改导入修片地址
- LYFZ.Model.Model_ErpOrder modelOrder = orbll.GetModel("Ord_Number", StrOrdNumber);
- modelOrder.Ord_PhotoPath = mod.sPh.UpdatePhotoImportDirectoryPath(Model.Model_ErpOrder.DirectoryType.EarlyRetouch, strprht.FullName);
- modelOrder.Ord_PhotoBackupPath = "NEW";
- modelOrder.Ord_UpdateDateTime = StrTime;
- modelOrder.Ord_UpdateName = StrUserName;
- clist.Add(orbll.GetImportPhotoUpdateOrder(modelOrder));
- #endregion*/
- mod.erpOrder.Ord_PhotoPath = mod.sPh.UpdatePhotoImportDirectoryPath(Model.Model_ErpOrder.DirectoryType.EarlyRetouch, mod.service_Path);
- mod.erpOrder.Ord_PhotoBackupPath = "NEW";
- mod.erpOrder.Ord_UpdateDateTime = SDateTime.Now;
- mod.erpOrder.Ord_UpdateName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
- List<LYFZ.Helper.CommandInfo> clist = new List<Helper.CommandInfo>();
- //clist.AddRange(mod.FrmClist);
- clist.Add(orbll.GetImportPhotoUpdateOrder(mod.erpOrder));
- //LYFZ.Model.Model_ErpOrderDigital modelDigital = odbll.GetModel("Ordv_ViceNumber", mod.OrdViceNumber);
- //if (modelDigital.Ordv_EarlyRepairStatus.Trim() != "2")
- //{
- // modelDigital.Ordv_EarlyRepairName = mod.erpOrder.Ord_UpdateName;
- // modelDigital.Ordv_EarlyRepairTime = mod.erpOrder.Ord_UpdateDateTime;
- // modelDigital.Ordv_EarlyRepairStatus = mod.StrStatus;
- //}
- //modelDigital.Ordv_UpdateDateTime = mod.erpOrder.Ord_UpdateDateTime;
- //modelDigital.Ordv_UpdateName = mod.erpOrder.Ord_UpdateName;
- //clist.Add(odbll.GetUpdateCommandInfo(modelDigital));
- //DataTable dt = orbll.GetView_Custom("tb_ErpOrderDigitalStatus", StrWhere: "Ords_OrdNumber = '" + mod.OrdNumber + "' And Ords_ViceNumber = '" + mod.OrdViceNumber + "'", ShowColumnName: "*").Tables[0];
- //LYFZ.Model.Model_ErpOrderDigitalStatus modelStatus = null;
- //if (dt.Rows.Count > 0)
- //{
- // modelStatus = orsbll.DataRowToModel(dt.Rows[0]);
- // if (modelStatus.Ords_OutSendEarlyRepairStatus.Trim() == "已发" || modelStatus.Ords_OutSendEarlyRepairStatus.Trim() == "已回")
- // {
- // modelStatus.Ords_OutSendEarlyRepairName = mod.erpOrder.Ord_UpdateName;
- // modelStatus.Ords_OutSendEarlyRepairStatus = "已回";
- // modelStatus.Ords_OutSendEarlyRepairTime = mod.erpOrder.Ord_UpdateDateTime;
- // clist.Add(orsbll.GetUpdateCommandInfo(modelStatus));
- // }
- //}
- //clist.AddRange(frm.clist);
- pcrsbll.SetServicePhotographCount(LYFZ.Model.Model_ErpOrder.DirectoryType.EarlyRetouch, mod.erpDigOrder.Ordv_Number, mod.erpDigOrder.Ordv_ViceNumber, mod.takenName, "3");
- LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist);
- if (SingletonThreadImportFileEvent != null)
- {
- SingletonThreadImportFileEvent(enumImportMultipFie.Number, GetProThreadNumber());
- }
- }
- else if (mod.errorMsg.IndexOf("暂停") == -1)
- {
- mod.Success = false;
- mod.errorMsg = "导入失败";
- }
- }
- #endregion
- /// <summary>
- /// 请求生成缩略图
- /// </summary>
- /// <param name="dirType"></param>
- /// <param name="ord_Number"></param>
- public void StartGenerateThumbnails(Model.Model_ErpOrder.DirectoryType dirType, string ord_Number)
- {
- try
- {
- // if (LYFZ.BLL.SelectPhotoHandling.CheckCurrentInternaNetworkAddress())
- // {
- LYFZ.Network.ClientRequestObject requestObj = new Network.ClientRequestObject();
- requestObj.OrdNumber = ord_Number;
- requestObj.RequestEvent = "请求生成缩略图";
- requestObj.Type = (int)dirType;
- if (LYFZ.PhotoSelectSystem.PhotoImportExport.CurrentNetworkClient != null)
- {
- LYFZ.PhotoSelectSystem.PhotoImportExport.CurrentNetworkClient.SendCommandToServer(HPSocketCS.Extended.TransferRequestCommand.GenerateThumbnails, requestObj.ToString());
- }
- else
- {
- LYFZ.BLL.BLL_FileLogs.WriteMainLogs("请求生成缩略图时网络连接断开");
- }
- // }
- }
- catch { }
- }
- #region 原片导入
-
- /// <summary>
- /// 原片导入
- /// </summary>
- /// <param name="mod"></param>
- /// <param name="i"></param>
- void ImportFileByPrimitivePicture(frmFileImportModel mod,int i)
- {
- TipsIs64BitProcess();
- // var mod = data_Pools[i];
- LYFZ.WinAPI.MyDriverInfo dInfo = LYFZ.WinAPI.CustomPublicMethod.GetDiskFreeSpace(mod.service_Path);
- if (dInfo.G_TotalFreeBytes < 3)
- {
- if (SingletonThreadImportFileEvent != null)
- {
- SingletonThreadImportFileEvent(enumImportMultipFie.MsgError, "[" + mod.directoryType.ToString() + "]服务器上保存原片的目录容量小于 3GB 所以不能导入相片,请重新设置原片保存目录。");
- }
- return;
- //ExMessageBoxCustom.Show("服务器上保存原片的目录容量小于 3GB 所以不能导入相片,请重新设置原片保存目录。");
- //return false;
- }
- LYFZ.BLL.SelectPhotoHandling sPhotoHandling = new BLL.SelectPhotoHandling(mod.erpOrder, mod.erpDigOrder);
- string currentTakenName = null;
- if (sPhotoHandling.PhotoModel != null)
- {
- currentTakenName = sPhotoHandling.PhotoModel.Ordpg_Sights;
- }
- List<string> photolist = new List<string>();
- foreach (var item in mod.local_Path)
- {
- if (item.code == 0)
- {
- photolist.Add(item.local_Path);
- }
- }
- if (photolist.Count == 0)
- {
- return;
- }
- baseList = new List<frmFileImportBaseModel>();
- for (int qz = i + 1; qz < data_Pools.Count; qz++)
- {
- baseList.Add(data_Pools[qz].CloneBaseData());
- }
- ///上传文件处理
- bool bl = ImportOriginalFilm(photolist, mod.service_Path, mod.takenName, mod.erpOrder, mod.erpDigOrder, currentTakenName, sPhotoHandling, mod, mod.importGenerateThumbnails);
- ///反馈管理界面文件上传处理
- if (SingletonThreadImportFileFormEvent != null)
- {
- SingletonThreadImportFileFormEvent(enumImportMultipFieForm.BackNext, mod);
- }
- if (bl)
- {
- mod.Success = true;
- }
- else if (mod.errorMsg.IndexOf("暂停")==-1)
- {
- mod.Success = false;
- mod.errorMsg = "导入失败";
- return;
- }
- pcrsbll.SetServicePhotographCount(LYFZ.Model.Model_ErpOrder.DirectoryType.PrimitivePicture, mod.erpDigOrder.Ordv_Number, mod.erpDigOrder.Ordv_ViceNumber, mod.takenName, "2");
- mod.erpOrder.Ord_PhotoPath = mod.sPh.UpdatePhotoImportDirectoryPath(Model.Model_ErpOrder.DirectoryType.PrimitivePicture, mod.service_Path);
- mod.erpOrder.Ord_PhotoBackupPath = "NEW";
- mod.erpOrder.Ord_UpdateDateTime = SDateTime.Now;
- mod.erpOrder.Ord_UpdateName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
- List<LYFZ.Helper.CommandInfo> clist = new List<Helper.CommandInfo>();
- clist.Add(orbll.GetImportPhotoUpdateOrder(mod.erpOrder));
- LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist);
- if (SingletonThreadImportFileEvent != null)
- {
- SingletonThreadImportFileEvent(enumImportMultipFie.Number, GetProThreadNumber());
- }
- }
- /// <summary>
- /// 导入原片
- /// </summary>
- /// <param name="photoFiles">要导入的相片路径数组</param>
- /// <param name="toDirectoryPath">要导入到的目标目录, 即服务器上的相片保存文件夹路径</param>
- /// <param name="takenName">拍摄名(即景点名不能为空)</param>
- /// <param name="backgroundWorker">线程对象</param>
- /// <returns></returns>
- public bool ImportOriginalFilm(List<string> photoFiles, string toDirectoryPath, string takenName,
- Model.Model_ErpOrder currentModel, LYFZ.Model.Model_ErpOrderDigital currentDigModel,
- string currentTakenName,LYFZ.BLL.SelectPhotoHandling sPhotoHandling ,
- frmFileImportModel groupMod,
- bool importGenerateThumbnails = false)
- {
-
- try
- {
- LYFZ.BLL.BLL_ErpSystemLogs.WriteSystemLog(EnumPublic.SystemLogsType.相片导入导出,
- "" + LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name + "导入" + photoFiles.Count + "张原片[订单号:" + currentModel.Ord_Number + "/" + currentModel.Ord_SinceOrderNumber + "(" + currentDigModel.Ordv_ViceNumber + ")]" + currentTakenName,
- LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID,
- LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name);
- }
- catch { }
- bool bl = false;
- //总计数器
- float sumCount = photoFiles.Count;
- //当前计数器
- int currentCount = 0;
- //当前订单已导入原片相片集合
- List<string> hasBeenImportedPhotoList = sPhotoHandling.GetSpecifyTypePhotoList(Model.Model_ErpOrder.DirectoryType.PrimitivePicture, BLL.SelectPhotoHandling.PhotoType.Original);
- bool isImport = true;//是否导入相片
- string sameNameLogsFilePath = "";
- if (!sPhotoHandling.CheckPhotoExist(hasBeenImportedPhotoList, photoFiles, ref sameNameLogsFilePath))
- {
- isImport = true;
- }
- else
- {
-
- bool bCheckContinue = true;
- if(!File.Exists(sameNameLogsFilePath))
- {
- FileUtil.WriteFile(sameNameLogsFilePath, "");
- }
- string txt = System.IO.File.ReadAllText(sameNameLogsFilePath);
- List<string> tempConsList = new List<string>();
- foreach(string local_txt in photoFiles)
- {
- if(txt.IndexOf(local_txt)!=-1)
- {
- var item = groupMod.local_Path.Find(p=>p.local_Path==local_txt);
- if(item!=null)
- {
- tempConsList.Add(local_txt);
- item.upload_Msg = "系统检测到要导入的相片名出现重名冲突,以取消本组图片上传,删除同名相片或重命名后再导入";
- item.success = false;
- item.code = -1;
- bCheckContinue = false;
- groupMod.Success = false;
- groupMod.errorMsg = "系统检测到要导入的相片名出现重名冲突,以取消本组图片上传,删除同名相片或重命名后再导入";
- }
- }
- }
- if(!bCheckContinue)
- {
- foreach(string temp in tempConsList)
- {
- photoFiles.Remove(temp);
- }
-
- }
- }
- try
- {
- LYFZ.BLL.BLL_PhotoImportRecordTable.UpdatePhotoImportRecordTable(LYFZ.Model.Model_ErpOrder.DirectoryType.PrimitivePicture, LYFZ.BLL.BLL_ErpCompanyInfo.CurrentCompanyInfoID, currentModel.Ord_Number, 1, PhotoImportRecordType.Import);
- }
- catch (Exception ex)
- {
- isImport = false;
- bl = false;
- ExMessageBoxCustom.Show("更新导片记录时失败:" + ex.Message);
- }
- if (isImport)
- {
- // LYFZ.PhotoSelectSystem.PhotoImportExport.StartGenerateThumbnails(Model.Model_ErpOrder.DirectoryType.PrimitivePicture, this.currentModel.Ord_Number);
- int importFailed = 0;
- foreach (string photoFile in photoFiles)
- {
- currentCount++;
- frmFileImportItemModel tempItem = groupMod.local_Path.Find(p => p.local_Path.Equals(photoFile) && p.code==0);
-
- if (tempItem==null)
- {
- continue;
- }
- tempItem.upload_Msg = "正在上传";
- ImportDataLogs(DateTime.Now.ToString() + " 正在进行文件导入,路径:" + photoFile + "\r\n");
- ImportTaskFileManager(groupMod);
-
- ///管理窗体显示
- if (SingletonThreadImportFileFormEvent != null)
- {
- SingletonThreadImportFileFormEvent(enumImportMultipFieForm.BackNext, groupMod);
- }
- if (File.Exists(photoFile))
- {
- ///图片上传
- if (!sPhotoHandling.ImportPhotoFile(toDirectoryPath, photoFile, importGenerateThumbnails: importGenerateThumbnails))
- {
- importFailed++;
- tempItem.success = false;
- tempItem.code = -1;
- tempItem.upload_Msg = "上传失败";
- ImportDataLogs(DateTime.Now.ToString() + " 文件导入失败,路径:" + photoFile + "\r\n");
- ImportTaskFileManager(groupMod);
- }
- else
- {
- tempItem.success = true;
- tempItem.code = 1;
- tempItem.upload_Msg = "上传成功";
- ImportDataLogs(DateTime.Now.ToString() + " 文件导入成功,路径:" + photoFile + "\r\n");
- ImportTaskFileManager(groupMod);
- }
- }
- else
- {
- tempItem.success = false;
- tempItem.code = -1;
- tempItem.upload_Msg = "文件不存在!!";
- ImportDataLogs(DateTime.Now.ToString() + " 文件导入失败,路径:" + photoFile + ",文件不存在\r\n");
- ImportTaskFileManager(groupMod);
- }
- ///管理窗体显示
- if (SingletonThreadImportFileFormEvent != null)
- {
- SingletonThreadImportFileFormEvent(enumImportMultipFieForm.BackNext, groupMod);
- }
- if (currentCount == 10 && !importGenerateThumbnails)
- {
- LYFZ.PhotoSelectSystem.PhotoImportExport.StartGenerateThumbnails(Model.Model_ErpOrder.DirectoryType.PrimitivePicture, currentModel.Ord_Number);
- }
- if (bRestartThread)
- {
- SingletonThreadImportFileEvent(enumImportMultipFie.Restart, null);
- }
-
- }
- List<frmFileImportItemModel> tempItemList = groupMod.local_Path.FindAll(p => p.code == 0);
- foreach (frmFileImportItemModel tempItem in tempItemList)
- {
- tempItem.success = false;
- tempItem.code = -1;
- tempItem.upload_Msg = "上传失败-文件不存在";
- ImportDataLogs(DateTime.Now.ToString() + " 文件导入失败,路径:" + tempItem.local_Path + ",文件不存在\r\n");
- ImportTaskFileManager(groupMod);
- if (SingletonThreadImportFileFormEvent != null)
- {
- SingletonThreadImportFileFormEvent(enumImportMultipFieForm.BackNext, groupMod);
- }
- }
- if (importFailed == 0)
- {
- bl = true;
- }
- else
- {
- bl = false;
- //ExMessageBoxCustom.Show("相片导入完成,但有 " + importFailed.ToString() + " 张导入失败。", backgroundWorker: backgroundWorker);
- }
- if (importFailed < photoFiles.Count)
- {
- LYFZ.PhotoSelectSystem.PhotoImportExport.StartGenerateThumbnails(Model.Model_ErpOrder.DirectoryType.PrimitivePicture, currentModel.Ord_Number);
- }
- }
- return bl;
- }
- #endregion
- #region 任务列表记录 用于退出重启动
- void ImportTaskFileManager(frmFileImportModel mod)
- {
- List<frmFileImportBaseModel> tempBaseList = new List<frmFileImportBaseModel>();
- //tempBaseList.Add(mod.CloneBaseData());
- List<frmFileImportModel> modelList = data_Pools.FindAll(p => !p.Success);
- foreach (var tempMod in modelList)
- {
- tempBaseList.Add(tempMod.CloneBaseData());
- }
- SaveFileManage(tempBaseList);
- }
- public void SaveFileManage(List<frmFileImportBaseModel> tempBaseList)
- {
- try
- {
- if (File.Exists(Environment.CurrentDirectory + "/UpFileManage/FileManage.txt"))
- {
- File.Delete(Environment.CurrentDirectory + "/UpFileManage/FileManage.txt");
- }
- FileUtil.WriteFile(Environment.CurrentDirectory + "/UpFileManage/" + HPSocketCS.Extended.CommonLibrary.ClientMarkID + "/FileManage.txt", Json.JsonTool.ObjectToJson(tempBaseList));
- }
- catch { }
- }
- public string SaveCheckFileManage(string txt)
- {
- FileUtil.WriteFile(Environment.CurrentDirectory + "/UpFileManage/CheckFileManage.txt", txt);
- return Environment.CurrentDirectory + "/UpFileManage/CheckFileManage.txt";
- }
- #endregion
- /// <summary>
- /// 启动绑定任务列表
- /// </summary>
- public void ReadNotUpFileData()
- {
- bool bThreadStart = false;
- if(BindModelListData(Environment.CurrentDirectory + "/UpFileManage/FileManage.txt"))
- {
- bThreadStart = true;
- }
- if (BindModelListData(Environment.CurrentDirectory + "/UpFileManage/" + HPSocketCS.Extended.CommonLibrary.ClientMarkID + "/FileManage.txt"))
- {
- bThreadStart = true;
- }
- if (bThreadStart)
- {
- if(this.data_Pools.Count > 0)
- {
- if (SingletonThreadImportFileEvent != null)
- {
- SingletonThreadImportFileEvent(enumImportMultipFie.Number, this.data_Pools.Count);
- }
- }
- ///判断是否自动上传,默认手动上传
- if (Properties.Settings.Default.bImportAutoUp)
- {
- if (this.data_Pools.Count > 0)
- {
- this.StartThread();
- }
- }
- }
- }
- public bool BindModelListData(string path)
- {
- string txt = FileUtil.ReadFile(path);
- if (!string.IsNullOrEmpty(txt))
- {
- List<frmFileImportBaseModel> manageBaseList = new List<frmFileImportBaseModel>();
- manageBaseList = (List<frmFileImportBaseModel>)Json.JsonTool.JsonToObject(txt, manageBaseList);
- foreach (var mod in manageBaseList)
- {
- if (mod.local_Path.Count > 0)
- {
- frmFileImportModel importModel = new frmFileImportModel();
- importModel.BindBaseDataToModel(mod);
- if (data_Pools.FindAll(p => p.OrdNumber == importModel.OrdNumber && p.directoryType == importModel.directoryType).Count > 0)
- {
- continue;
- }
- LYFZ.Model.Model_ErpOrder erpOrder = orbll.GetModel(importModel.OrdNumber);
- LYFZ.Model.Model_ErpOrderDigital orderDigital = digtalBll.GetModel(importModel.OrdViceNumber);
- importModel.erpOrder = erpOrder;
- importModel.erpDigOrder = orderDigital;
- this.data_Pools.Add(importModel);
- baseList.Add(mod);
- }
- }
- return true;
- }
- return false;
- }
- /// <summary>
- /// 清楚错误内容
- /// </summary>
- internal void SetClearErrorData()
- {
- foreach (var mod in data_Pools)
- {
- foreach(var item in mod.local_Path)
- {
- if (item.upload_Msg != "暂停上传" && !item.success && item.code==-1)
- {
- item.success = true;
- item.code = 1;
- }
- }
- if(mod.local_Path.FindAll(p=>p.code==-1||p.code==0).Count==0)
- {
- mod.Success = true;
- }
-
- }
- if (SingletonThreadImportFileEvent != null)
- {
- SingletonThreadImportFileEvent(enumImportMultipFie.Number, GetProThreadNumber());
- }
- ImportTaskFileManager(null);
- }
-
- internal void RestartThread(frmFileImportModel frmFileImportModel)
- {
- bRestartThread = true;
- }
- #region ftp控制时间对象
- System.Windows.Forms.Timer ftpMessageTime = null;
- public void BindFTPMsgTimer(System.Windows.Forms.Timer _ftpMessageTime)
- {
- ftpMessageTime = _ftpMessageTime;
- }
- public void StartFTPMsgTimer()
- {
- if(ftpMessageTime!=null)
- {
- ftpMessageTime.Start();
- }
- }
- #endregion
- internal void DeleteModel(frmFileImportModel frmFileImportModel)
- {
- //throw new NotImplementedException();
- foreach(var mod in data_Pools)
- {
- if(mod==frmFileImportModel)
- {
- data_Pools.Remove(mod);
- break;
- }
- }
- ImportTaskFileManager(null);
- if (SingletonThreadImportFileEvent != null)
- {
- SingletonThreadImportFileEvent(enumImportMultipFie.Number, GetProThreadNumber());
- }
- }
- #region 线程执行日志
- /// <summary>
- /// 写入线程日志
- /// </summary>
- /// <param name="content"></param>
- public void ImportDataLogs(string content)
- {
- try
- {
- FileUtil.WriteFileAppend(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "/Logs/ImportThread/" + DateTime.Now.ToString("yyyyMMdd") + ".txt", content);
- }
- catch { }
- }
- #endregion
- }
- }
|