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();
        }
        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();
        }
Пример #3
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();
        }
        public void ExportCurrentPage(GridControl gridControlResults, string fileName, bool diagram, bool pics)
        {
            if (pics)
            {
                m_StatusDlg = new ProgressFormStandalone("导出本页记录", "导出 xls 文件 ...");
                m_StatusDlg.Show();
            }
            try
            {
                if (diagram)
                {
                    // 改用导出全部的数据表, 因为人工修改时的导出与显示的不一样
                    m_DTAnalyseResultsExport.Rows.Clear();

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

                    //CustomizeExportResult(gridControlResults, m_DTAnalyseResultsExport);
                    gridControlResults.DataSource = m_DTAnalyseResultsExport;

                    if (Framework.Environment.ResultExportAsXls)
                    {
                        gridControlResults.ExportToXls(fileName);
                    }
                    else
                    {
                        gridControlResults.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.2f);
                    m_StatusDlg.UpdateStatusText("开始导出图片 ...");

                    CopyImages(fullPath);
                    m_StatusDlg.Close();
                }

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

                Framework.Container.Instance.InteractionService.ShowMessageBox("导出本页记录成功");
            }
            finally
            {
                if (pics)
                {
                    m_StatusDlg.Close();
                }
            }
        }