public void ExportAll(GridControl gridControl, string fileName, bool diagram, bool pics)
        {
            m_StatusDlg = new ProgressFormStandalone("导出全部记录", "获取全部结果记录 ...");
            m_StatusDlg.Show();

            List <AnalyseRecord> records = Framework.Container.Instance.TaskManager.GetDetailResults(this.m_Records);

            m_StatusDlg.UpdateProgress(0.3f);

            if (records != null && records.Count > 0)
            {
                m_DTAnalyseResultsExport.Clear();

                foreach (AnalyseRecord record in records)
                {
                    AddResultRow(m_DTAnalyseResultsExport, record);
                }

                //CustomizeExportResult(gridControl, m_DTAnalyseResultsExport);

                if (diagram)
                {
                    m_StatusDlg.UpdateStatusText("导出 xls 文件 ...");
                    gridControl.DataSource = m_DTAnalyseResultsExport;

                    if (Framework.Environment.ResultExportAsXls)
                    {
                        gridControl.ExportToXls(fileName);
                    }
                    else
                    {
                        gridControl.ExportToCsv(fileName);
                    }
                }

                if (pics)
                {
                    string fullPath = fileName;
                    if (diagram)
                    {
                        string folder = Path.GetFileNameWithoutExtension(fileName);
                        string path   = Path.GetDirectoryName(fileName);
                        folder = string.Concat(folder, "全部结果导出图片");

                        fullPath = Path.Combine(path, folder);
                        if (!Directory.Exists(fullPath))
                        {
                            Directory.CreateDirectory(fullPath);
                        }
                    }

                    m_StatusDlg.UpdateProgress(0.4f);
                    m_StatusDlg.UpdateStatusText("开始导出图片 ...");
                    CopyImages(records, fullPath);
                }
                m_DTAnalyseResultsExport.Rows.Clear();
            }

            m_StatusDlg.Close();
        }
        private void CopyImages(List <AnalyseRecord> records, string fullPath)
        {
            string fileName;
            Image  image;

            float progressPerFile = 0.6f / (float)records.Count;
            int   i = 0;

            foreach (AnalyseRecord record in records)
            {
                i++;
                if (record != null)
                {
                    m_StatusDlg.UpdateStatusText(string.Format("保存图片 {0} ...", record.PicPath));
                    m_StatusDlg.UpdateProgress(0.4f + progressPerFile * i);
                    try
                    {
                        fileName = Path.GetFileName(record.PicPath);
                        fileName = Path.Combine(fullPath, fileName);
                        image    = AppUtil.Common.Utils.GetImage(record.PicPath, Framework.Environment.URLEncodingType);
                        CopyImage(image, fileName);
                    }
                    catch (Exception ex)
                    {
                        MyLog4Net.Container.Instance.Log.Error(string.Format("导出文件 {0} 出错", record.PicPath), ex);
                    }
                }
            }
        }
        private void CopyImages(string fullPath)
        {
            if (m_DTAnalyseResults != null && m_DTAnalyseResults.Rows != null)
            {
                string fileName;
                Image  image;

                float progressPerFile = 0.8f / (float)m_DTAnalyseResults.Rows.Count;
                int   i = 0;

                foreach (DataRow row in m_DTAnalyseResults.Rows)
                {
                    i++;
                    AnalyseRecord record = row["AnalyseRecord"] as AnalyseRecord;

                    if (record != null)
                    {
                        m_StatusDlg.UpdateStatusText(string.Format("保存图片 {0} ...", record.PicPath));
                        m_StatusDlg.UpdateProgress(0.2f + progressPerFile * i);
                        try
                        {
                            fileName = m_FileAccess.GetFileName(record.PicPath);
                            fileName = Path.Combine(fullPath, fileName);

                            if (m_FileAccess is LocalFileAccess)
                            {
                                File.Copy(record.PicPath, fileName);
                            }
                            else
                            {
                                image = AppUtil.Common.Utils.GetImage(record.PicPath, Framework.Environment.URLEncodingType);
                                CopyImage(image, fileName);
                            }
                        }
                        catch (Exception ex)
                        {
                            MyLog4Net.Container.Instance.Log.Error(string.Format("导出文件 {0} 出错", record.PicPath), ex);
                        }
                    }
                }
            }
        }
        public void ExportAll(string fileName)
        {
            m_StatusDlg = new ProgressFormStandalone("导出全部记录", "获取全部结果记录 ...");
            m_StatusDlg.Show();

            List <AnalyseRecord> records = this.m_Records;

            m_StatusDlg.UpdateProgress(0.3f);

            if (records != null && records.Count > 0)
            {
                string fullPath = fileName;

                m_StatusDlg.UpdateProgress(0.4f);
                m_StatusDlg.UpdateStatusText("开始导出图片 ...");
                CopyImages(records, fullPath);
            }

            m_StatusDlg.Close();
        }
Ejemplo n.º 5
0
        public void ExportCurrentGroup(List <AnalyseRecord> records, string fileName)
        {
            m_StatusDlg = new ProgressFormStandalone("导出本组记录", "获取本组结果记录 ...");
            m_StatusDlg.Show();
            try
            {
                string fullPath = fileName;

                m_StatusDlg.UpdateProgress(0.2f);
                m_StatusDlg.UpdateStatusText("开始导出图片 ...");

                CopyImages(records, fullPath);
                m_StatusDlg.Close();

                Framework.Container.Instance.EvtAggregator.GetEvent <AnalyseMessageEvent>().Publish(
                    new Tuple <uint, string>(10, string.Format("导出本组记录到 {0} 成功", fileName)));

                Framework.Container.Instance.InteractionService.ShowMessageBox("导出本组记录成功");
            }
            finally
            {
                m_StatusDlg.Close();
            }
        }
        public void ExportAllPics(bool originalPic)
        {
            string path = Framework.Environment.PictureSavePath;

            using (FolderBrowserDialog dialog = new FolderBrowserDialog())
            {
                dialog.ShowNewFolderButton = true;
                dialog.Description         = "设置需要批量导出的文件夹";
                dialog.SelectedPath        = path;
                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                path = dialog.SelectedPath;
            }

            ProgressFormStandalone pf = new ProgressFormStandalone("图片批量导出", "正在请求图片。。。");

            pf.Show();
            int index = 0;

            if (m_ResultSummary != null && m_ResultSummary.SearchResultList != null && m_ResultSummary.SearchResultList.Count > 0)
            {
                int    count     = m_ResultSummary.SearchResultList.Count;
                float  unit      = 1.0f / (3f * count);
                float  progress  = 0.0f;
                string operation = originalPic ? "请求原始图" : "请求缩略图";
                foreach (SearchResultRecord record in m_ResultSummary.SearchResultList)
                {
                    index++;

                    progress += unit * 2;

                    if (originalPic)
                    {
                        if (record.OriginalPic == null)
                        {
                            pf.UpdateStatusText(string.Format("正在获取 {0} / {1} 图片 ...", index, count));
                            pf.UpdateProgress(progress);
                            try
                            {
                                record.OriginalPic = Framework.Container.Instance.VideoSearchService.RequestImage(m_searchSessionID, record, originalPic);
                            }
                            catch (SDKCallException ex)
                            {
                                Common.SDKCallExceptionHandler.Handle(ex, operation);
                            }
                        }
                    }
                    else
                    {
                        if (record.ThumbNailPic == null)
                        {
                            pf.UpdateStatusText(string.Format("正在获取 {0} / {1} 图片 ...", index, count));
                            pf.UpdateProgress(progress);
                            try
                            {
                                record.ThumbNailPic = Framework.Container.Instance.VideoSearchService.RequestImage(m_searchSessionID, record, originalPic);
                            }
                            catch (SDKCallException ex)
                            {
                                Common.SDKCallExceptionHandler.Handle(ex, operation);
                            }
                        }
                    }
                }
                progress = 0.67f;
                pf.UpdateStatusText("开始导出图片。。。");
                pf.UpdateProgress(progress);

                // string path = Framework.Environment.PictureSavePath + "\\" + DateTime.Now.ToString("MMddHHmmss") + "\\";

                if (!System.IO.Directory.Exists(path))
                {
                    System.IO.Directory.CreateDirectory(path);
                }
                if (!path.EndsWith("\\"))
                {
                    path = path + "\\";
                }

                string resourcename = GetResourceNameByTaskUnitID(m_ResultSummary.TaskUnitID);

                string fileName;
                Image  img;
                foreach (SearchResultRecord record in m_ResultSummary.SearchResultList)
                {
                    img = originalPic ? record.OriginalPic : record.ThumbNailPic;
                    if (img != null)
                    {
                        string type = (originalPic) ? "原始图" : "缩略图";

                        // string FileName = "原始图" + index + ".jpg";
                        fileName = resourcename.Replace(".", "_") + type + record.ID.ToString() + ".jpg";

                        using (Image imgTmp = new Bitmap(img))
                        {
                            try
                            {
                                pf.UpdateStatusText(string.Format("正在保存图片 ‘{0}’ ...", fileName));
                                progress += unit;
                                pf.UpdateProgress(progress);

                                imgTmp.Save(Path.Combine(path, fileName));

                                if (originalPic)
                                {
                                    // 需要清除, 避免内存占用过大
                                    if (!Framework.Container.Instance.CacheMgr.HasItem(record))
                                    {
                                        record.Clear();
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                string msg = string.Format("保存图片出错: {0}", ex.Message);
                                Framework.Container.Instance.InteractionService.ShowMessageBox(msg, Framework.Environment.PROGRAM_NAME,
                                                                                               System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                                msg = msg = string.Format("保存图片 '{0}' 出错", fileName);
                                MyLog4Net.Container.Instance.Log.Error(msg, ex);
                            }
                        }
                    }
                }
            }

            pf.UpdateStatusText("导出图片完成");
            pf.Close();
        }