Ejemplo n.º 1
0
 public void GetCmpByCapId()
 {
     try
     {
         CmpFaceList = thirft.QueryCmpByCapIdWidthImgH(cCViewModel.Id, cCViewModel.Day);
         List <FaceObj> ListFaceObj = new List <FaceObj>();
         int            i           = 0;
         foreach (var cmpFaceLogWidthImg in CmpFaceList)
         {
             List <FaceObj> listFaceObj = thirft.QueryFaceObj(cmpFaceLogWidthImg.TcUuid);
             foreach (var faceObj in listFaceObj)
             {
                 ListFaceObj.Add(faceObj);
             }
         }
         foreach (FaceObj cmpFace in ListFaceObj)
         {
             for (int j = 0; j < cmpFace.Tmplate.Count; j++)
             {
                 MyFaceObj myFaceObj = new MyFaceObj();
                 //读入MemoryStream对象
                 BitmapImage myBitmapImage = new BitmapImage();
                 myBitmapImage.BeginInit();
                 myBitmapImage.StreamSource = new System.IO.MemoryStream(cmpFace.Tmplate[j].Img);
                 myFaceObj.img = myBitmapImage;
                 myBitmapImage.EndInit();
                 myBitmapImage          = null;
                 myFaceObj.fa_ob_tcUuid = cmpFace.TcUuid;
                 myFaceObj.tcName       = cmpFace.TcName;
                 myFaceObj.nAge         = CmpFaceList[i].Score;
                 MyFaceObjListTemp.Add(myFaceObj);
                 i++;
             }
         }
         ShowFaceObject();
     }
     catch (Exception ex)
     {
         Logger <OperaExcel> .Log.Error("GetCmpByCapId", ex);
     }
 }
        /// <summary>
        /// 查询模版的具体实现
        /// </summary>
        /// <param name="page"></param>
        private void GetAllInfo(int page)
        {
            currPage = page;
            //page = page - 1;
            tMViewModel.LoadingVisiblity = "Visible";
            List <MyCapFaceLogWithImg> listMyCapFaceLogWithImg = new List <MyCapFaceLogWithImg>();

            tMViewModel.MaxCount = thirft.QueryFaceObjTotalCount(tMViewModel.templateManagerValue);
            tMViewModel.MaxPage  = tMViewModel.MaxCount % tMViewModel.templateManagerValue.PageRowValue != 0 ? tMViewModel.MaxCount / tMViewModel.templateManagerValue.PageRowValue + 1 : tMViewModel.MaxCount / tMViewModel.templateManagerValue.PageRowValue;
            tMViewModel.templateManagerValue.MaxCount = tMViewModel.MaxCount;
            if (page > 1)
            {
                tMViewModel.templateManagerValue.StartRowValue = tMViewModel.MaxCount - (page * tMViewModel.templateManagerValue.PageRowValue);
                if (tMViewModel.templateManagerValue.StartRowValue < 0)
                {
                    tMViewModel.templateManagerValue.StartRowValue = 0;
                }
            }
            else
            {
                tMViewModel.templateManagerValue.StartRowValue = tMViewModel.MaxCount - (tMViewModel.templateManagerValue.PageRowValue);
                if (tMViewModel.templateManagerValue.StartRowValue < 0)
                {
                    tMViewModel.templateManagerValue.StartRowValue = 0;
                }
            }
            tMViewModel.CurrPage         = page;
            tMViewModel.ListMyFaceObj    = thirft.QueryFaceObj(tMViewModel.templateManagerValue);
            tMViewModel.LoadingVisiblity = "Hidden";
            this.Dispatcher.BeginInvoke(
                new Action(() =>
            {
                if (listViewTemplate.Items.Count > 0)
                {
                    listViewTemplate.ScrollIntoView(listViewTemplate.Items[0]);
                }
            }));
        }
Ejemplo n.º 3
0
        ///// <summary>
        ///// 清除时间
        ///// </summary>
        ///// <param name="sender"></param>
        ///// <param name="e"></param>
        //private void ClearDatePickerTime(object sender, MouseButtonEventArgs e)
        //{
        //    DatePicker dp = sender as DatePicker;
        //    dp.Text = "";
        //}

        /// <summary>
        /// 导出excel
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void ExportExcelFile_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string saveExcelPath = ConfigurationManager.AppSettings["Excel保存地址"];
                if (string.IsNullOrEmpty(saveExcelPath))
                {
                    saveExcelPath = System.Windows.Forms.Application.StartupPath + @"\比对记录导出";
                }
                else
                {
                    saveExcelPath += @"\比对记录导出";
                }
                await Task.Run(
                    () =>
                {
                    XSSFWorkbook workbook    = new XSSFWorkbook();
                    XSSFCellStyle style      = (XSSFCellStyle)workbook.CreateCellStyle();
                    style.Alignment          = NPOI.SS.UserModel.HorizontalAlignment.Center;
                    style.VerticalAlignment  = NPOI.SS.UserModel.VerticalAlignment.Center;
                    style.BorderBottom       = BorderStyle.Thin;
                    style.BorderLeft         = BorderStyle.Thin;
                    style.BorderRight        = BorderStyle.Thin;
                    style.BorderTop          = BorderStyle.Thin;
                    XSSFCellStyle style2     = (XSSFCellStyle)workbook.CreateCellStyle();
                    style2.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                    style2.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                    style2.BorderBottom      = BorderStyle.Thin;
                    style2.BorderLeft        = BorderStyle.Thin;
                    style2.BorderRight       = BorderStyle.Thin;
                    style2.BorderTop         = BorderStyle.Thin;
                    XSSFFont font            = (XSSFFont)workbook.CreateFont();
                    font.Boldweight          = (short)NPOI.SS.UserModel.FontBoldWeight.Bold;
                    style2.SetFont(font);
                    XSSFCellStyle style0     = (XSSFCellStyle)workbook.CreateCellStyle();
                    style0.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                    style0.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                    style0.BorderBottom      = BorderStyle.Thin;
                    style0.BorderLeft        = BorderStyle.Thin;
                    style0.BorderRight       = BorderStyle.Thin;
                    style0.BorderTop         = BorderStyle.Thin;
                    IDataFormat dataformat   = workbook.CreateDataFormat();
                    style0.DataFormat        = dataformat.GetFormat("yyyy年MM月dd日 h:mm:ss 上午/下午");
                    XSSFSheet sheet          = (XSSFSheet)workbook.CreateSheet("比对记录");
                    int row = 0;
                    List <MyCmpFaceLogWidthImgModel> allCmpInfo = new List <MyCmpFaceLogWidthImgModel>();
                    allCmpInfo = GetCmpFaceLogByPage(1);
                    foreach (var item in allCmpInfo)
                    {
                        if (row == 0)
                        {
                            sheet.CreateRow(row).CreateCell(0).SetCellValue("序号");
                            sheet.GetRow(row).CreateCell(1).SetCellValue("抓拍通道");
                            sheet.GetRow(row).CreateCell(2).SetCellValue("抓拍时间");
                            sheet.GetRow(row).CreateCell(3).SetCellValue("模版姓名");
                            sheet.GetRow(row).CreateCell(4).SetCellValue("注册类型");
                            sheet.GetRow(row).CreateCell(5).SetCellValue("相似度");
                            sheet.GetRow(row).CreateCell(6).SetCellValue("抓拍照片");
                            sheet.GetRow(row).CreateCell(7).SetCellValue("模版照片");
                            sheet.GetRow(row).GetCell(0).CellStyle = style2;
                            sheet.GetRow(row).GetCell(1).CellStyle = style2;
                            sheet.GetRow(row).GetCell(2).CellStyle = style2;
                            sheet.GetRow(row).GetCell(3).CellStyle = style2;
                            sheet.GetRow(row).GetCell(4).CellStyle = style2;
                            sheet.GetRow(row).GetCell(5).CellStyle = style2;
                            sheet.GetRow(row).GetCell(6).CellStyle = style2;
                            sheet.GetRow(row).GetCell(7).CellStyle = style2;
                            sheet.SetColumnWidth(2, 30 * 256);
                            sheet.SetColumnWidth(6, 30 * 256);
                            sheet.SetColumnWidth(7, 30 * 256);
                            row++;
                        }
                        sheet.CreateRow(row).CreateCell(0).SetCellValue(row);
                        sheet.GetRow(row).Height = 100 * 40;
                        sheet.GetRow(row).CreateCell(1).SetCellValue(item.channelName);
                        sheet.GetRow(row).CreateCell(2).SetCellValue(item.time);
                        sheet.GetRow(row).CreateCell(3).SetCellValue(item.name);
                        sheet.GetRow(row).CreateCell(4).SetCellValue(item.type);
                        sheet.GetRow(row).CreateCell(5).SetCellValue(item.score);
                        sheet.GetRow(row).CreateCell(6).SetCellValue("");
                        sheet.GetRow(row).CreateCell(7).SetCellValue("");
                        sheet.GetRow(row).GetCell(0).CellStyle = style;
                        sheet.GetRow(row).GetCell(1).CellStyle = style;
                        sheet.GetRow(row).GetCell(2).CellStyle = style0;
                        sheet.GetRow(row).GetCell(3).CellStyle = style;
                        sheet.GetRow(row).GetCell(4).CellStyle = style;
                        sheet.GetRow(row).GetCell(5).CellStyle = style;
                        sheet.GetRow(row).GetCell(6).CellStyle = style;
                        sheet.GetRow(row).GetCell(7).CellStyle = style;
                        if (true)
                        {
                            XSSFDrawing patriarch  = (XSSFDrawing)sheet.CreateDrawingPatriarch();
                            List <byte[]> capImage = new List <byte[]>();
                            capImage = thirft.QueryCmpLogImageH(item.ID, exportCurrDay);
                            if (capImage.Count > 0)
                            {
                                byte[] bytes            = capImage[0];
                                int pictureIdx          = workbook.AddPicture(bytes, PictureType.JPEG);
                                XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, 6, row, 7, row + 1);
                                XSSFPicture pict        = (XSSFPicture)patriarch.CreatePicture(anchor, pictureIdx);
                            }
                            var faceObject = thirft.QueryFaceObj(item.tcUuid);
                            if (faceObject.Count > 0 && faceObject[0].Tmplate.Count > 0)
                            {
                                byte[] bytes2            = faceObject[0].Tmplate[0].Img;
                                int pictureIdx2          = workbook.AddPicture(bytes2, PictureType.JPEG);
                                XSSFClientAnchor anchor2 = new XSSFClientAnchor(0, 0, 0, 0, 7, row, 8, row + 1);
                                XSSFPicture pict2        = (XSSFPicture)patriarch.CreatePicture(anchor2, pictureIdx2);
                            }
                        }
                        row++;
                        Thread.Sleep(1);
                    }
                    FileStream fs = new FileStream(saveExcelPath + ".xlsx", FileMode.Create, FileAccess.Write);
                    workbook.Write(fs);
                    workbook = null;
                });

                MB_MODULES.Views.MyMessage.showYes("导出完成!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }