예제 #1
0
 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="sender"></param>
        /// <param name="e"></param>
        private void btnDetermineAddTemplate_Click(object sender, RoutedEventArgs e)
        {
            List <ErrorInfo> ListErrorInfo;

            ThriftServiceNameSpace.ThriftService thirft = new ThriftServiceNameSpace.ThriftService();

            try
            {
                /**
                 * 姓名
                 * 性别
                 * 年龄
                 * 类型:普通、黑名单
                 * 备注
                 * 1张主照片
                 * 4张附属照片 均为模板照片,指向一个人
                 * **/

                #region 验证
                if (string.IsNullOrEmpty(txtName.Text.Trim()))
                {
                    MyMessage.showYes("名称必填!");
                    return;
                }
                if (string.IsNullOrEmpty(txtAge.Text.Trim()))
                {
                    MyMessage.showYes("年龄必填!");
                    return;
                }
                #endregion

                #region 添加输入项

                tIPViewModel._FaceObj.TcUuid = guid;
                tIPViewModel._FaceObj.TcName = txtName.Text.Trim();
                string message = _validationRule.intValidationRule(this.txtAge.Text.Trim());
                if (message != "")
                {
                    MyMessage.showYes(message);
                    return;
                }
                tIPViewModel._FaceObj.NAge = int.Parse(txtAge.Text.Trim());
                tIPViewModel._FaceObj.NSex = combSex.SelectedIndex;
                //暂时没确定
                tIPViewModel._FaceObj.NType =
                    (GlobalCache.FaceTypeList.Cast <STypeInfo>().FirstOrDefault(x => x.Description == tIPViewModel.Type[combType.SelectedIndex]) ?? new STypeInfo()).Type;
                tIPViewModel._FaceObj.TcRemarks = txtRemarks.Text.Trim();
                #endregion

                tIPViewModel._FaceObj.Tmplate = new List <FaceObjTemplate>();
                //遍历照片存放数组,必须添加至少一张照片
                var isExistPhoto = templateData.FirstOrDefault(x => x != null) ?? null;
                if (isExistPhoto == null)
                {
                    MyMessage.showYes("至少要一张照片才能注册成功!");
                    return;
                }

                int nj = -1;

                for (int i = 0; i < 5; i++)
                {
                    if (templateData[i] != null)
                    {
                        FaceObjTemplate templateObj = new FaceObjTemplate();
                        templateObj.TcUuid  = System.Guid.NewGuid().ToString().Replace("-", "");;
                        templateObj.TcObjid = tIPViewModel._FaceObj.TcUuid;

                        //判断前面是不是有空位置,有那么排到前面去
                        for (int j = 0; j < i; j++)
                        {
                            if (templateData[j] == null)
                            {
                                templateObj.NIndex = j;
                                nj = j;
                                break;
                            }
                        }
                        if (templateObj.NIndex == 0)
                        {
                            if (nj == -1)
                            {
                                templateObj.NIndex = i;
                            }
                            else
                            {
                                templateObj.NIndex = nj;
                            }
                        }
                        //时间
                        long addDateTime =
                            DateTimeConvert.ToLongFromSubstract(DateTime.Now, new DateTime(1970, 1, 1));

                        templateObj.DTm = addDateTime;//模板时间
                        if (tIPViewModel._FaceObj.DTm == 0)
                        {
                            tIPViewModel._FaceObj.DTm = addDateTime;
                        }

                        if (_mainTemplateStream != null)
                        {
                            if (_mainTemplateStream.Equals(templateData[i]))
                            {
                                tIPViewModel._FaceObj.NMain_ftID = i;//主照片ID
                            }
                            else if (i == tIPViewModel._FaceObj.NMain_ftID)
                            {
                                tIPViewModel._FaceObj.NMain_ftID = templateObj.NIndex;//主照片ID
                            }
                        }
                        else
                        {
                            tIPViewModel._FaceObj.NMain_ftID = 0;//主模板ID为 0
                        }
                        templateObj.Img = templateData[i];
                        tIPViewModel._FaceObj.Tmplate.Add(templateObj);//Add Template to db.face_template/db.face_object

                        if (nj != -1)
                        {
                            templateData[nj] = templateData[i];
                            templateData[i]  = null;
                            nj = -1;
                        }
                    }
                }
                //具体的操作(添加,修改)
                if (tIPViewModel.Title.Contains("添加"))
                {
                    ListErrorInfo = thirft.AddFaceObj(tIPViewModel._FaceObj);
                }
                else
                {
                    ListErrorInfo = thirft.ModifyFaceObj(tIPViewModel.Id, tIPViewModel._FaceObj);
                }
                //判断是否成功
                if (ListErrorInfo.Count == 0)//判断成功,提示成功
                {
                    MyMessage.showYes("成功!");
                    this.Close();
                }
                else//添加不成功,显示错误
                {
                    if ("Add Face To Compare Server Failed, Because img repeat".Equals(ListErrorInfo[0].ID))
                    {
                        MyMessage.Show("模板照片已存在,请取消并重新添加模板");
                        return;
                    }
                    else
                    {
                        MyMessage.showYes("添加模板ID:" + ListErrorInfo[0].ID + "失败,\n失败信息:" + ListErrorInfo[0].ErrCode);
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger <TempleteInfoPop> .Log.Error("AddTemplate:btnRemove_Click", ex);
            }
        }