public TempleteImportPop()
 {
     InitializeComponent();
     tIPViewModel       = new TempleteImportPopViewModel();
     this.DataContext   = tIPViewModel;
     AddFaceObjDelegate = new ThreadImportPicIntoDbDelegate(delegate(FaceObj _FaceObj) {
         return(thirft.AddFaceObj(_FaceObj));;
     });
     this.MouseLeftButtonDown += TempleteImportPop_MouseLeftButtonDown;
     InitTempleteCol();
 }
Пример #2
0
        /// <summary>
        /// 将人脸对象批量上传的回调函数(错误的保存)
        /// </summary>
        /// <param name="ar"></param>
        private void PicHandle(IAsyncResult ar)
        {
            lock (tIPViewModel)
            {
                try
                {
                    upedCount++;
                    FaceObj     _FaceObj = ar.AsyncState as FaceObj;
                    AsyncResult a        = (AsyncResult)ar;
                    ThreadImportPicIntoDbDelegate trys = (ThreadImportPicIntoDbDelegate)a.AsyncDelegate;
                    List <ErrorInfo> ListErrorInfo     = trys.EndInvoke(ar);
                    if (ListErrorInfo.Count > 0)
                    {
                        for (int l = 0; l < ListErrorInfo.Count; l++)
                        {
                            Console.WriteLine(ListErrorInfo[l].ErrCode + "");
                            if (ListErrorInfo[l].ErrCode == -1)//小于0,注册失败
                            {
                                byte[]               photo  = _FaceObj.Tmplate[0].Img;
                                MemoryStream         stream = new MemoryStream(photo);
                                System.Drawing.Image img    = System.Drawing.Image.FromStream(stream);
                                //判断文件夹存在
                                DirectoryInfo directory = new DirectoryInfo(tIPViewModel.ErrorAddress);
                                if (!directory.Exists)
                                {
                                    //重新生成文件夹
                                    Directory.CreateDirectory(tIPViewModel.ErrorAddress);
                                }

                                string strPath = "";

                                strPath = tIPViewModel.ErrorAddress + @"\" + _FaceObj.TcName + @".jpg";
                                img.Save(strPath, img.RawFormat);
                                tIPViewModel.ErrorCount++;
                            }
                            if (ListErrorInfo[l].ErrCode == -3 || ListErrorInfo[l].ErrCode == -2)//图片不存在
                            {
                                tIPViewModel.ErrorCount++;
                                string message = "第" + upedCount + "行注册失败";
                            }
                        }
                    }
                    else
                    {
                        ++tIPViewModel.SuccessCount;
                    }
                }
                catch (Exception ex)
                {
                    Logger <OperaExcel> .Log.Error("PicHandle", ex);

                    tIPViewModel.ErrorCount++;
                    //System.Windows.MessageBox.Show("PicHandle" + ex.Message);
                }
                finally
                {
                    ++tIPViewModel.CurrentLength;
                    tIPViewModel.ImportInfo = "总数量:" + tIPViewModel.MaxLength + "  上传数量:" + tIPViewModel.CurrentLength + "成功数量:" + tIPViewModel.SuccessCount + "";
                    //Console.WriteLine("总数量:" + tIPViewModel.MaxLength + "  上传数量:" + tIPViewModel.CurrentLength + "成功数量:" + tIPViewModel.SuccessCount + "");
                    upingCount--;
                    if (tIPViewModel.MaxLength == tIPViewModel.CurrentLength)
                    {
                        this.Dispatcher.BeginInvoke(new Action(() =>
                        {
                            MB_MODULES.Views.MyMessage.showYes("模版已全部导入完成!");
                        }));
                    }
                }
            }
        }