v1.0 개발 시점

This commit is contained in:
jhlee
2020-09-13 11:08:36 +09:00
parent 672b190c97
commit ad3d4abffd
12 changed files with 728 additions and 219 deletions

View File

@@ -1,8 +1,6 @@
using OCR_FILTER_JSH.DataClass;
using OCR_FILTER_JSH.Web;
using System.Collections.Generic;
using System.Drawing;
using DocumentFormat.OpenXml.Office.CoverPageProps;
namespace OCR_FILTER_JSH
{
@@ -79,5 +77,16 @@ namespace OCR_FILTER_JSH
// ini 파일 이름
public static string IniFileName = "settting.ini";
// zipCode
public static string InitZipCode = "97005";
// Default Excel 파일 경로
public static string DefaulstExcelFilePath = @"\Resource\Default.xlsx";
// 저장할 결과 Excel 파일 이름
public static string ResultExcelFileName = "ResultData.xlsx";
public static string ResultExcelSheetname = "ResultData";
}
}

View File

@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using DevExpress.XtraRichEdit.Model;
namespace OCR_FILTER_JSH.DataClass
{
@@ -19,7 +18,7 @@ namespace OCR_FILTER_JSH.DataClass
// 상품 이름
public string ProductName { get; set; }
// 상품명(한글)
public string ResultLinkNameKor { get; set; }
public string ProductNameKor { get; set; }
// 브랜드
public string BrandName { get; set; }
// 상품코드

View File

@@ -65,15 +65,19 @@
this.skinRibbonGalleryBarItem1 = new DevExpress.XtraBars.SkinRibbonGalleryBarItem();
this.barButtonItem_ExcelOutputData = new DevExpress.XtraBars.BarButtonItem();
this.barButtonItem_ExcelOutputNotProscribe = new DevExpress.XtraBars.BarButtonItem();
this.barButtonItem_MenuMode = new DevExpress.XtraBars.BarButtonItem();
this.barButtonItem_OneClickProcess = new DevExpress.XtraBars.BarButtonItem();
this.ribbonPage_InputData = new DevExpress.XtraBars.Ribbon.RibbonPage();
this.ribbonPageGroup_OneClickProcess = new DevExpress.XtraBars.Ribbon.RibbonPageGroup();
this.ribbonPageGroup_InputData = new DevExpress.XtraBars.Ribbon.RibbonPageGroup();
this.ribbonPageGroup_Execution = new DevExpress.XtraBars.Ribbon.RibbonPageGroup();
this.ribbonPageGroup_DataOutput = new DevExpress.XtraBars.Ribbon.RibbonPageGroup();
this.ribbonPageGroup_Setting = new DevExpress.XtraBars.Ribbon.RibbonPageGroup();
this.ribbonPageGroup_SkinEditor = new DevExpress.XtraBars.Ribbon.RibbonPageGroup();
this.panelControl1 = new DevExpress.XtraEditors.PanelControl();
this.ribbonPageGroup_Additionanl = new DevExpress.XtraBars.Ribbon.RibbonPageGroup();
this.barButtonItem_MenuMode = new DevExpress.XtraBars.BarButtonItem();
this.panelControl1 = new DevExpress.XtraEditors.PanelControl();
this.label_CopyRight = new System.Windows.Forms.Label();
this.label_WarningMessage = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.treeList_LinkData)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.splitContainerControl_InputDataView)).BeginInit();
this.splitContainerControl_InputDataView.SuspendLayout();
@@ -89,6 +93,7 @@
((System.ComponentModel.ISupportInitialize)(this.panelControl_ProgressBar)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.ribbonControl_MainMenu)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.panelControl1)).BeginInit();
this.panelControl1.SuspendLayout();
this.SuspendLayout();
//
// treeList_LinkData
@@ -105,7 +110,7 @@
this.treeList_LinkData.OptionsView.ShowFirstLines = false;
this.treeList_LinkData.OptionsView.ShowIndicator = false;
this.treeList_LinkData.OptionsView.ShowRoot = false;
this.treeList_LinkData.Size = new System.Drawing.Size(197, 393);
this.treeList_LinkData.Size = new System.Drawing.Size(247, 408);
this.treeList_LinkData.TabIndex = 0;
this.treeList_LinkData.RowClick += new DevExpress.XtraTreeList.RowClickEventHandler(this.treeList_LinkData_RowClick);
//
@@ -114,8 +119,6 @@
this.treeListColumn_LinkDataProductName.Caption = "상품";
this.treeListColumn_LinkDataProductName.FieldName = "ProductName";
this.treeListColumn_LinkDataProductName.Name = "treeListColumn_LinkDataProductName";
this.treeListColumn_LinkDataProductName.Visible = true;
this.treeListColumn_LinkDataProductName.VisibleIndex = 0;
this.treeListColumn_LinkDataProductName.Width = 101;
//
// treeListColumn_LinkDataLink
@@ -124,7 +127,7 @@
this.treeListColumn_LinkDataLink.FieldName = "Link";
this.treeListColumn_LinkDataLink.Name = "treeListColumn_LinkDataLink";
this.treeListColumn_LinkDataLink.Visible = true;
this.treeListColumn_LinkDataLink.VisibleIndex = 1;
this.treeListColumn_LinkDataLink.VisibleIndex = 0;
this.treeListColumn_LinkDataLink.Width = 32;
//
// splitContainerControl_InputDataView
@@ -136,7 +139,7 @@
this.splitContainerControl_InputDataView.Panel1.Text = "Panel1";
this.splitContainerControl_InputDataView.Panel2.Controls.Add(this.treeList_LinkData);
this.splitContainerControl_InputDataView.Panel2.Text = "Panel2";
this.splitContainerControl_InputDataView.Size = new System.Drawing.Size(313, 393);
this.splitContainerControl_InputDataView.Size = new System.Drawing.Size(363, 408);
this.splitContainerControl_InputDataView.SplitterPosition = 111;
this.splitContainerControl_InputDataView.TabIndex = 1;
//
@@ -153,7 +156,7 @@
this.treeList_Proscribe.OptionsView.ShowFirstLines = false;
this.treeList_Proscribe.OptionsView.ShowIndicator = false;
this.treeList_Proscribe.OptionsView.ShowRoot = false;
this.treeList_Proscribe.Size = new System.Drawing.Size(111, 393);
this.treeList_Proscribe.Size = new System.Drawing.Size(111, 408);
this.treeList_Proscribe.TabIndex = 1;
//
// treeListColumn_NAME
@@ -172,7 +175,7 @@
this.xtraTabControl_Main.Location = new System.Drawing.Point(0, 147);
this.xtraTabControl_Main.Name = "xtraTabControl_Main";
this.xtraTabControl_Main.SelectedTabPage = this.InputeDataView;
this.xtraTabControl_Main.Size = new System.Drawing.Size(940, 422);
this.xtraTabControl_Main.Size = new System.Drawing.Size(904, 437);
this.xtraTabControl_Main.TabIndex = 3;
this.xtraTabControl_Main.TabPages.AddRange(new DevExpress.XtraTab.XtraTabPage[] {
this.InputeDataView,
@@ -182,7 +185,7 @@
//
this.InputeDataView.Controls.Add(this.splitContainerControl_Main);
this.InputeDataView.Name = "InputeDataView";
this.InputeDataView.Size = new System.Drawing.Size(934, 393);
this.InputeDataView.Size = new System.Drawing.Size(898, 408);
this.InputeDataView.Text = "데이터 입력";
//
// splitContainerControl_Main
@@ -193,15 +196,15 @@
this.splitContainerControl_Main.Panel1.Controls.Add(this.splitContainerControl_InputDataView);
this.splitContainerControl_Main.Panel1.Text = "Panel1";
this.splitContainerControl_Main.Panel2.Text = "Panel2";
this.splitContainerControl_Main.Size = new System.Drawing.Size(934, 393);
this.splitContainerControl_Main.SplitterPosition = 313;
this.splitContainerControl_Main.Size = new System.Drawing.Size(898, 408);
this.splitContainerControl_Main.SplitterPosition = 363;
this.splitContainerControl_Main.TabIndex = 2;
//
// xtraTabPage_ResultDataView
//
this.xtraTabPage_ResultDataView.Controls.Add(this.treeList_ResultLink);
this.xtraTabPage_ResultDataView.Name = "xtraTabPage_ResultDataView";
this.xtraTabPage_ResultDataView.Size = new System.Drawing.Size(934, 393);
this.xtraTabPage_ResultDataView.Size = new System.Drawing.Size(898, 408);
this.xtraTabPage_ResultDataView.Text = "출력 결과";
//
// treeList_ResultLink
@@ -233,7 +236,7 @@
this.treeList_ResultLink.OptionsView.ShowRoot = false;
this.treeList_ResultLink.RepositoryItems.AddRange(new DevExpress.XtraEditors.Repository.RepositoryItem[] {
this.repositoryItemCheckEdit_ResultCheck});
this.treeList_ResultLink.Size = new System.Drawing.Size(934, 393);
this.treeList_ResultLink.Size = new System.Drawing.Size(898, 408);
this.treeList_ResultLink.TabIndex = 1;
this.treeList_ResultLink.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.treeList_ResultLink_MouseDoubleClick);
//
@@ -295,7 +298,7 @@
// treeListColumn_ResultLinkNameKor
//
this.treeListColumn_ResultLinkNameKor.Caption = "상품명(한글)";
this.treeListColumn_ResultLinkNameKor.FieldName = "ResultLinkNameKor";
this.treeListColumn_ResultLinkNameKor.FieldName = "LinkNameKor";
this.treeListColumn_ResultLinkNameKor.Name = "treeListColumn_ResultLinkNameKor";
this.treeListColumn_ResultLinkNameKor.OptionsColumn.AllowEdit = false;
this.treeListColumn_ResultLinkNameKor.Visible = true;
@@ -409,7 +412,7 @@
this.panelControl_ProgressBar.Appearance.Options.UseBackColor = true;
this.panelControl_ProgressBar.Location = new System.Drawing.Point(5, 267);
this.panelControl_ProgressBar.Name = "panelControl_ProgressBar";
this.panelControl_ProgressBar.Size = new System.Drawing.Size(927, 93);
this.panelControl_ProgressBar.Size = new System.Drawing.Size(891, 93);
this.panelControl_ProgressBar.TabIndex = 1;
//
// ribbonControl_MainMenu
@@ -425,9 +428,10 @@
this.skinRibbonGalleryBarItem1,
this.barButtonItem_ExcelOutputData,
this.barButtonItem_ExcelOutputNotProscribe,
this.barButtonItem_MenuMode});
this.barButtonItem_MenuMode,
this.barButtonItem_OneClickProcess});
this.ribbonControl_MainMenu.Location = new System.Drawing.Point(0, 0);
this.ribbonControl_MainMenu.MaxItemId = 15;
this.ribbonControl_MainMenu.MaxItemId = 18;
this.ribbonControl_MainMenu.Name = "ribbonControl_MainMenu";
this.ribbonControl_MainMenu.Pages.AddRange(new DevExpress.XtraBars.Ribbon.RibbonPage[] {
this.ribbonPage_InputData});
@@ -439,7 +443,7 @@
this.ribbonControl_MainMenu.ShowPageHeadersMode = DevExpress.XtraBars.Ribbon.ShowPageHeadersMode.Show;
this.ribbonControl_MainMenu.ShowQatLocationSelector = false;
this.ribbonControl_MainMenu.ShowToolbarCustomizeItem = false;
this.ribbonControl_MainMenu.Size = new System.Drawing.Size(940, 147);
this.ribbonControl_MainMenu.Size = new System.Drawing.Size(904, 147);
this.ribbonControl_MainMenu.Toolbar.ShowCustomizeItem = false;
this.ribbonControl_MainMenu.ToolbarLocation = DevExpress.XtraBars.Ribbon.RibbonQuickAccessToolbarLocation.Hidden;
//
@@ -487,17 +491,36 @@
this.barButtonItem_ExcelOutputData.Id = 11;
this.barButtonItem_ExcelOutputData.Name = "barButtonItem_ExcelOutputData";
this.barButtonItem_ExcelOutputData.RibbonStyle = DevExpress.XtraBars.Ribbon.RibbonItemStyles.Large;
this.barButtonItem_ExcelOutputData.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.barButtonItem_ExcelOutputData_ItemClick);
//
// barButtonItem_ExcelOutputNotProscribe
//
this.barButtonItem_ExcelOutputNotProscribe.Caption = "Excel 파일 출력 (금지항목제외)";
this.barButtonItem_ExcelOutputNotProscribe.Enabled = false;
this.barButtonItem_ExcelOutputNotProscribe.Id = 13;
this.barButtonItem_ExcelOutputNotProscribe.Name = "barButtonItem_ExcelOutputNotProscribe";
this.barButtonItem_ExcelOutputNotProscribe.RibbonStyle = DevExpress.XtraBars.Ribbon.RibbonItemStyles.Large;
//
// barButtonItem_MenuMode
//
this.barButtonItem_MenuMode.Caption = "데이터 입력/결과 숨기기";
this.barButtonItem_MenuMode.Id = 14;
this.barButtonItem_MenuMode.Name = "barButtonItem_MenuMode";
this.barButtonItem_MenuMode.RibbonStyle = DevExpress.XtraBars.Ribbon.RibbonItemStyles.Large;
this.barButtonItem_MenuMode.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.barButtonItem_MenuMode_ItemClick);
//
// barButtonItem_OneClickProcess
//
this.barButtonItem_OneClickProcess.Caption = "원클릭 프로세스";
this.barButtonItem_OneClickProcess.Id = 17;
this.barButtonItem_OneClickProcess.Name = "barButtonItem_OneClickProcess";
this.barButtonItem_OneClickProcess.RibbonStyle = DevExpress.XtraBars.Ribbon.RibbonItemStyles.Large;
this.barButtonItem_OneClickProcess.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.barButtonItem_OneClickProcess_ItemClick);
//
// ribbonPage_InputData
//
this.ribbonPage_InputData.Groups.AddRange(new DevExpress.XtraBars.Ribbon.RibbonPageGroup[] {
this.ribbonPageGroup_OneClickProcess,
this.ribbonPageGroup_InputData,
this.ribbonPageGroup_Execution,
this.ribbonPageGroup_DataOutput,
@@ -507,6 +530,12 @@
this.ribbonPage_InputData.Name = "ribbonPage_InputData";
this.ribbonPage_InputData.Text = "주요 메뉴";
//
// ribbonPageGroup_OneClickProcess
//
this.ribbonPageGroup_OneClickProcess.ItemLinks.Add(this.barButtonItem_OneClickProcess);
this.ribbonPageGroup_OneClickProcess.Name = "ribbonPageGroup_OneClickProcess";
this.ribbonPageGroup_OneClickProcess.Text = "매크로";
//
// ribbonPageGroup_InputData
//
this.ribbonPageGroup_InputData.ItemLinks.Add(this.barButtonItem_OpenExcelAmazonData);
@@ -540,14 +569,6 @@
this.ribbonPageGroup_SkinEditor.Text = "스킨 에디터";
this.ribbonPageGroup_SkinEditor.Visible = false;
//
// panelControl1
//
this.panelControl1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panelControl1.Location = new System.Drawing.Point(0, 569);
this.panelControl1.Name = "panelControl1";
this.panelControl1.Size = new System.Drawing.Size(940, 36);
this.panelControl1.TabIndex = 6;
//
// ribbonPageGroup_Additionanl
//
this.ribbonPageGroup_Additionanl.ItemLinks.Add(this.barButtonItem_MenuMode);
@@ -555,20 +576,40 @@
this.ribbonPageGroup_Additionanl.Text = "부가 기능";
this.ribbonPageGroup_Additionanl.Visible = false;
//
// barButtonItem_MenuMode
// panelControl1
//
this.barButtonItem_MenuMode.Caption = "데이터 입력/결과 숨기기";
this.barButtonItem_MenuMode.Id = 14;
this.barButtonItem_MenuMode.Name = "barButtonItem_MenuMode";
this.barButtonItem_MenuMode.RibbonStyle = DevExpress.XtraBars.Ribbon.RibbonItemStyles.Large;
this.barButtonItem_MenuMode.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.barButtonItem_MenuMode_ItemClick);
this.panelControl1.Controls.Add(this.label_CopyRight);
this.panelControl1.Controls.Add(this.label_WarningMessage);
this.panelControl1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panelControl1.Location = new System.Drawing.Point(0, 584);
this.panelControl1.Name = "panelControl1";
this.panelControl1.Size = new System.Drawing.Size(904, 21);
this.panelControl1.TabIndex = 6;
//
// label_CopyRight
//
this.label_CopyRight.AutoSize = true;
this.label_CopyRight.Location = new System.Drawing.Point(5, 3);
this.label_CopyRight.Name = "label_CopyRight";
this.label_CopyRight.Size = new System.Drawing.Size(158, 14);
this.label_CopyRight.TabIndex = 0;
this.label_CopyRight.Text = "Copyright(c) 2020 LJH v1.0";
//
// label_WarningMessage
//
this.label_WarningMessage.AutoSize = true;
this.label_WarningMessage.Location = new System.Drawing.Point(666, 3);
this.label_WarningMessage.Name = "label_WarningMessage";
this.label_WarningMessage.Size = new System.Drawing.Size(230, 14);
this.label_WarningMessage.TabIndex = 0;
this.label_WarningMessage.Text = "Illegal distribution may result in penalties.";
//
// FormMainForm
//
this.Appearance.Options.UseFont = true;
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(940, 605);
this.ClientSize = new System.Drawing.Size(904, 605);
this.Controls.Add(this.panelControl_ProgressBar);
this.Controls.Add(this.xtraTabControl_Main);
this.Controls.Add(this.panelControl1);
@@ -576,7 +617,7 @@
this.Font = new System.Drawing.Font("굴림", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(129)));
this.Name = "FormMainForm";
this.Ribbon = this.ribbonControl_MainMenu;
this.Text = "For JSH (by LJH)";
this.Text = "For JSH v1.0 (by LJH)";
((System.ComponentModel.ISupportInitialize)(this.treeList_LinkData)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.splitContainerControl_InputDataView)).EndInit();
this.splitContainerControl_InputDataView.ResumeLayout(false);
@@ -592,6 +633,8 @@
((System.ComponentModel.ISupportInitialize)(this.panelControl_ProgressBar)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.ribbonControl_MainMenu)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.panelControl1)).EndInit();
this.panelControl1.ResumeLayout(false);
this.panelControl1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
@@ -644,6 +687,10 @@
private DevExpress.XtraTreeList.Columns.TreeListColumn treeListColumn_ResultLinkGoodsCode;
private DevExpress.XtraBars.BarButtonItem barButtonItem_MenuMode;
private DevExpress.XtraBars.Ribbon.RibbonPageGroup ribbonPageGroup_Additionanl;
private DevExpress.XtraBars.BarButtonItem barButtonItem_OneClickProcess;
private DevExpress.XtraBars.Ribbon.RibbonPageGroup ribbonPageGroup_OneClickProcess;
private System.Windows.Forms.Label label_WarningMessage;
private System.Windows.Forms.Label label_CopyRight;
}
}

View File

@@ -51,8 +51,6 @@ namespace OCR_FILTER_JSH
[Obsolete]
private void InitForm()
{
ribbonControl_MainMenu.Minimized = true;
// 프로그레스 바 미리 만들기
panelControl_ProgressBar.Visible = false;
_progressbarControl = new ProgressBarControl(this)
@@ -82,6 +80,9 @@ namespace OCR_FILTER_JSH
// 프로그램 실행 경로 가져오기
CommonProperty.SaveProgramDirecotryPath = Application.StartupPath + @"\SaveData";
// Default Excel 파일 경로
CommonProperty.DefaulstExcelFilePath = Application.StartupPath + CommonProperty.DefaulstExcelFilePath;
if (Directory.Exists(CommonProperty.SaveProgramDirecotryPath))
{
// 로컬에 저장할 파일의 경로 생성
@@ -105,7 +106,6 @@ namespace OCR_FILTER_JSH
}
else
Directory.CreateDirectory(CommonProperty.SaveProgramDirecotryPath);
}
/// <summary>
@@ -139,6 +139,10 @@ namespace OCR_FILTER_JSH
/// <param name="sender"></param>
/// <param name="e"></param>
private void barButtonItem_OpenExcelAmazonData_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
OpenExcelAmazonData();
}
public void OpenExcelAmazonData()
{
FileDownloadThread?.Abort();
@@ -147,9 +151,7 @@ namespace OCR_FILTER_JSH
// Cell Reference 만들기
var linkDataList = new Dictionary<string, string>();
linkDataList.Add("Link", "B");
linkDataList.Add("Product", "A");
linkDataList.Add("Brand", "C");
linkDataList.Add("Link", "A");
treeList_LinkData.DataSource = amazonExcelManager.GetExcelData(linkDataList);
treeList_LinkData.Caption = $@"Link : {treeList_LinkData.Nodes.Count} 개";
@@ -206,6 +208,11 @@ namespace OCR_FILTER_JSH
/// <param name="sender"></param>
/// <param name="e"></param>
private void barButtonItem_Process_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
process();
}
public void process(bool autoProgress = false)
{
// 조회할 데이터가 없으면 return
if (CommonProperty.TotalLinkCount < 1) return;
@@ -223,7 +230,7 @@ namespace OCR_FILTER_JSH
CommonProperty.ResultDataList = new List<ResultData>();
// 데이터 저장 폴더
var dialog = new FolderBrowserDialog();
var dialog = new FolderBrowserDialog() {Description = "결과데이터 저장 폴더 선택"};
var dialogResult = dialog.ShowDialog();
if (dialogResult != DialogResult.OK) return;
@@ -245,7 +252,7 @@ namespace OCR_FILTER_JSH
panelControl_ProgressBar.Visible = true;
// 프로그레스 바 초기화 및 스레드 시작
_progressbarControl.InitStartProgress();
_progressbarControl.InitStartProgress(autoProgress);
// Web Browser 폼 생성하기
for (var cnt = 0; cnt < CommonProperty.WebBrowserLimitCount; cnt++)
@@ -255,7 +262,7 @@ namespace OCR_FILTER_JSH
var linkData = (AmazonExcelData)LinkDataList[cnt];
CommonProperty.WebBrowserManagementList.Add(
new WebBrowserManagement(cnt, linkData.Link, linkData.ProductName, linkData.Brand));
new WebBrowserManagement(cnt, linkData.Link));
}
// 파일 다운로드 Thread
@@ -514,7 +521,7 @@ namespace OCR_FILTER_JSH
/// 결과 데이터 호출 함수
/// 프로그레스 바 완료 시 호출
/// </summary>
public void ShowResultData()
public void ShowResultData(object autoProcess)
{
BeginInvoke((MethodInvoker)(() =>
{
@@ -525,9 +532,14 @@ namespace OCR_FILTER_JSH
// 금지 품목을 포함하는 항목만 출력
// treeList_ResultLink.DataSource = CommonProperty.ResultDataList.FindAll(item => item.Proscribe);
treeList_ResultLink.DataSource = sortResultDataList;
CommonProperty.ResultDataList = sortResultDataList;
xtraTabControl_Main.SelectedTabPage = xtraTabPage_ResultDataView;
if ((bool)autoProcess)
{
ExceloutputData();
}
}));
}
#endregion
@@ -571,7 +583,52 @@ namespace OCR_FILTER_JSH
/// <param name="e"></param>
private void barButtonItem_MenuMode_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
//TODO 추후 구현 계획 (v1.0 이후)
}
/// <summary>
/// 한번에 처리하는 함수
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void barButtonItem_OneClickProcess_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
OpenExcelAmazonData();
process(true);
}
/// <summary>
/// 전체 Result Data 결과 Excel로 출력하기
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void barButtonItem_ExcelOutputData_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
ExceloutputData();
}
public void ExceloutputData()
{
try
{
// 저장할 결과 파일 경로
var ResultFileFullPath = CommonProperty.SaveDirecotryPath + @"\" + CommonProperty.ResultExcelFileName;
// 파일 복사
if (!File.Exists(CommonProperty.DefaulstExcelFilePath)) return;
File.Copy(CommonProperty.DefaulstExcelFilePath
, ResultFileFullPath, true);
OpenXmlExcelManager.InsertTextToExcel(ResultFileFullPath);
Process.Start(CommonProperty.SaveDirecotryPath);
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
}
}
}

View File

@@ -191,6 +191,9 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<None Include="Resource\default.xlsx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />

View File

@@ -4,25 +4,35 @@ using DocumentFormat.OpenXml.Spreadsheet;
using OCR_FILTER_JSH.DataClass;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using DevExpress.DataProcessing;
using DocumentFormat.OpenXml;
namespace OCR_FILTER_JSH.Parser
{
/// <summary>
/// OpenXML Excel 매니저 클래스
/// </summary>
public class OpenXmlExcelManager
{
private CommonProperty.ExcelFileType _ExcelFileType;
// File명과 확장자
string _fileName ;
private string _fileName ;
// File 경로
string _filePath;
private string _filePath;
// File 경로와 File명
public string FileFullName { get; set; }
/// <summary>
/// 생성자
/// </summary>
/// <param name="excelFileType"></param>
public OpenXmlExcelManager(CommonProperty.ExcelFileType excelFileType)
{
_ExcelFileType = excelFileType;
@@ -77,130 +87,141 @@ namespace OCR_FILTER_JSH.Parser
/// </summary>
public BindingList<object> GetExcelData(Dictionary<string,string> cellReferenceList)
{
using (var spreadsheetDocument =
SpreadsheetDocument.Open(FileFullName, false))
try
{
var workbookPart = spreadsheetDocument.WorkbookPart;
Dictionary<string,List<Cell>> cellsList = new Dictionary<string, List<Cell>>();
foreach (var workSheetPart in workbookPart.WorksheetParts)
using (var spreadsheetDocument =
SpreadsheetDocument.Open(FileFullName, false))
{
foreach (var cellReference in cellReferenceList)
{
var cells = workSheetPart.Worksheet.Descendants<Cell>()
.Where(c => c.CellReference.Value.Contains(cellReference.Value)).ToList();
var workbookPart = spreadsheetDocument.WorkbookPart;
if (cells.Count > 1)
Dictionary<string, List<Cell>> cellsList = new Dictionary<string, List<Cell>>();
foreach (var workSheetPart in workbookPart.WorksheetParts)
{
foreach (var cellReference in cellReferenceList)
{
// Cell 리스트에 추가
cellsList.Add(cellReference.Value, cells);
var cells = workSheetPart.Worksheet.Descendants<Cell>()
.Where(c => c.CellReference.Value.Contains(cellReference.Value)).ToList();
if (cells.Count > 1)
{
// Cell 리스트에 추가
cellsList.Add(cellReference.Value, cells);
}
}
}
}
if (cellsList.Count < 1) return null;
if (cellsList.Count < 1) return null;
var sharedStringPart = workbookPart.SharedStringTablePart;
var values = sharedStringPart.SharedStringTable.Elements<SharedStringItem>().ToList();
var sharedStringPart = workbookPart.SharedStringTablePart;
var values = sharedStringPart.SharedStringTable.Elements<SharedStringItem>().ToList();
var returnBindingList = new BindingList<object>();
var returnBindingList = new BindingList<object>();
var rowIndex = 0;
var rowIndex = 0;
// Excel File 종류에 따른 구분
switch (_ExcelFileType)
{
case CommonProperty.ExcelFileType.Amazondata:
// Excel File 종류에 따른 구분
switch (_ExcelFileType)
{
case CommonProperty.ExcelFileType.Amazondata:
// 원본 데이터 따로 보관
CommonProperty.OriAmazonExcelDatas = null;
CommonProperty.OriAmazonExcelDatas = new List<AmazonExcelData>();
// 원본 데이터 따로 보관
CommonProperty.OriAmazonExcelDatas = null;
CommonProperty.OriAmazonExcelDatas = new List<AmazonExcelData>();
if (!cellsList.ContainsKey(cellReferenceList["Link"])) return null;
if (!cellsList.ContainsKey(cellReferenceList["Link"])) return null;
foreach (var linkCell in cellsList[cellReferenceList["Link"]])
{
if (linkCell.CellValue == null)
foreach (var linkCell in cellsList[cellReferenceList["Link"]])
{
if (linkCell.CellValue == null)
{
rowIndex++;
// 다른 열도 진행할 이유가 없음
continue;
}
var link = getCellText(linkCell, values);
// Cell Reference의 First인 Link 데이터 이면
if (!link.Contains("http"))
{
// 다른 열도 진행할 이유가 없음
rowIndex++;
continue;
}
string productName = null;
string brand = null;
// 같은 거 다른 리스트에 넣어도 되는 지 테스트
// TODO 현재는 데이터가 정확하게 맞지 않으면 컬럼수가 맞지 않음
try
{
productName = getCellText(cellsList[cellReferenceList["Product"]]?[rowIndex], values);
}
catch { }
try
{
brand = getCellText(cellsList[cellReferenceList["Brand"]]?[rowIndex], values);
}
catch { }
var amazonExcelData = new AmazonExcelData
{
Link = link,
ProductName = productName,
Brand = brand
};
var amazonExcelDataOrg = new AmazonExcelData
{
Link = link,
ProductName = productName,
Brand = brand
};
returnBindingList.Add(amazonExcelData);
// 원본 데이터 보관
CommonProperty.OriAmazonExcelDatas.Add(amazonExcelDataOrg);
rowIndex++;
// 다른 열도 진행할 이유가 없음
continue;
}
break;
case CommonProperty.ExcelFileType.Proscribe:
var link = getCellText(linkCell, values);
// 원본 데이터 따로 보관
CommonProperty.ProscribeDatas = new List<ProscribeData>();
// Cell Reference의 First인 Link 데이터 이면
if (!link.Contains("http"))
foreach (var cell in cellsList[cellReferenceList.First().Value])
{
// 다른 열도 진행할 이유가 없음
var index = int.Parse(cell.CellValue.Text);
var dataText = values[index].InnerText.Replace(",", "");
var proscribeData = new ProscribeData { Name = dataText };
returnBindingList.Add(proscribeData);
// 원본 데이터 보관
CommonProperty.ProscribeDatas.Add(proscribeData);
rowIndex++;
continue;
}
break;
}
string productName = null;
string brand = null;
// 같은 거 다른 리스트에 넣어도 되는 지 테스트
// TODO 현재는 데이터가 정확하게 맞지 않으면 컬럼수가 맞지 않음
try
{
productName = getCellText(cellsList[cellReferenceList["Product"]]?[rowIndex], values);
}
catch { }
try
{
brand = getCellText(cellsList[cellReferenceList["Brand"]]?[rowIndex], values);
}
catch { }
var amazonExcelData = new AmazonExcelData
{
Link = link,
ProductName = productName,
Brand = brand
};
var amazonExcelDataOrg = new AmazonExcelData
{
Link = link,
ProductName = productName,
Brand = brand
};
returnBindingList.Add(amazonExcelData);
// 원본 데이터 보관
CommonProperty.OriAmazonExcelDatas.Add(amazonExcelDataOrg);
rowIndex++;
}
break;
case CommonProperty.ExcelFileType.Proscribe:
// 원본 데이터 따로 보관
CommonProperty.ProscribeDatas = new List<ProscribeData>();
foreach (var cell in cellsList[cellReferenceList.First().Value])
{
var index = int.Parse(cell.CellValue.Text);
var dataText = values[index].InnerText.Replace(",", "");
var proscribeData = new ProscribeData { Name = dataText };
returnBindingList.Add(proscribeData);
// 원본 데이터 보관
CommonProperty.ProscribeDatas.Add(proscribeData);
rowIndex++;
}
break;
return returnBindingList;
}
return returnBindingList;
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return null;
}
}
/// <summary>
/// Cell 에서 Text 가져오기
/// </summary>
/// <param name="cell"></param>
/// <param name="values"></param>
/// <returns></returns>
private string getCellText(Cell cell, List<SharedStringItem> values)
{
var index = int.Parse(cell.CellValue.Text);
@@ -209,5 +230,241 @@ namespace OCR_FILTER_JSH.Parser
return dataText;
}
/// <summary>
/// 결과 Excel 데이터에 데이터 기록하기
/// </summary>
/// <param name="docName"></param>
/// <param name="text"></param>
public static void InsertTextToExcel(string docName, List<ResultData> resultDataList = null)
{
// 결과 데이터가 없으면 Return
//if (CommonProperty.ResultDataList == null || CommonProperty.ResultDataList.Count < 1) return;
// Open the document for editing.
using (SpreadsheetDocument spreadSheet = SpreadsheetDocument.Open(docName, true))
{
// Get the SharedStringTablePart. If it does not exist, create a new one.
SharedStringTablePart shareStringPart;
if (spreadSheet.WorkbookPart.GetPartsOfType<SharedStringTablePart>().Count() > 0)
{
shareStringPart = spreadSheet.WorkbookPart.GetPartsOfType<SharedStringTablePart>().First();
}
else
{
shareStringPart = spreadSheet.WorkbookPart.AddNewPart<SharedStringTablePart>();
}
var ascii = (int)'A';
// Insert a new worksheet.
// WorksheetPart worksheetPart = InsertWorksheet(spreadSheet.WorkbookPart);
var relId = spreadSheet.WorkbookPart.Workbook.Descendants<Sheet>()
.First(s => CommonProperty.ResultExcelSheetname.Equals(s.Name)).Id;
var worksheetPart = (WorksheetPart) spreadSheet.WorkbookPart.GetPartById(relId);
#region Excel 컬럼
// Excel 컬럼 만들기
var outputResultDataList = new List<string>();
//outputResultDataList.Add("다운로드 실패");
outputResultDataList.Add("금지품목포함");
outputResultDataList.Add("프라임");
outputResultDataList.Add("팬트리");
outputResultDataList.Add("상품번호");
outputResultDataList.Add("브랜드");
outputResultDataList.Add("상품명");
outputResultDataList.Add("상품명(한글)");
outputResultDataList.Add("가격");
outputResultDataList.Add("무게");
outputResultDataList.Add("부피");
outputResultDataList.Add("이미지 갯수");
outputResultDataList.Add("금지성분");
outputResultDataList.Add("URL");
outputResultDataList.Add("폴더 경로");
#endregion
// Excel Column 만들기
for (var cIndex = 0; cIndex < outputResultDataList.Count; cIndex++)
{
var text = string.Format("{0}", (char)(ascii + cIndex));
// TODO 추후 효율적으로 수정
// Insert cells into the new worksheet.
var cell = InsertCellInWorksheet(text, 1, worksheetPart);
// Insert the text into the SharedStringTablePart.
var index = InsertSharedStringItem(outputResultDataList[cIndex], shareStringPart);
// Set the value of cell A1.
cell.CellValue = new CellValue(index.ToString());
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
}
// TODO 추후 효율적으로 수정
#region Excel 데이터 만들기
for (var rIndex = 0; rIndex < CommonProperty.ResultDataList.Count; rIndex++)
{
// Insert cells into the new worksheet.
/*
var cell = InsertCellInWorksheet("A", (uint)rIndex+2, worksheetPart);
// Insert the text into the SharedStringTablePart.
var index = InsertSharedStringItem(CommonProperty.ResultDataList[rIndex].DownloadFailStr, shareStringPart);
// Set the value of cell A1.
cell.CellValue = new CellValue(index.ToString());
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);*/
var cell = InsertCellInWorksheet("A", (uint)rIndex + 2, worksheetPart);
var index = InsertSharedStringItem(CommonProperty.ResultDataList[rIndex].Proscribe.ToString(), shareStringPart);
cell.CellValue = new CellValue(index.ToString());
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
cell = InsertCellInWorksheet("B", (uint)rIndex + 2, worksheetPart);
index = InsertSharedStringItem(CommonProperty.ResultDataList[rIndex].Prime.ToString(), shareStringPart);
cell.CellValue = new CellValue(index.ToString());
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
cell = InsertCellInWorksheet("C", (uint)rIndex + 2, worksheetPart);
index = InsertSharedStringItem(CommonProperty.ResultDataList[rIndex].Pantry.ToString(), shareStringPart);
cell.CellValue = new CellValue(index.ToString());
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
cell = InsertCellInWorksheet("D", (uint)rIndex + 2, worksheetPart);
index = InsertSharedStringItem(CommonProperty.ResultDataList[rIndex].Index.ToString(), shareStringPart);
cell.CellValue = new CellValue(index.ToString());
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
cell = InsertCellInWorksheet("E", (uint)rIndex + 2, worksheetPart);
index = InsertSharedStringItem(CommonProperty.ResultDataList[rIndex].BrandName, shareStringPart);
cell.CellValue = new CellValue(index.ToString());
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
cell = InsertCellInWorksheet("F", (uint)rIndex + 2, worksheetPart);
index = InsertSharedStringItem(CommonProperty.ResultDataList[rIndex].ProductName, shareStringPart);
cell.CellValue = new CellValue(index.ToString());
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
cell = InsertCellInWorksheet("G", (uint)rIndex + 2, worksheetPart);
index = InsertSharedStringItem(CommonProperty.ResultDataList[rIndex].ProductNameKor, shareStringPart);
cell.CellValue = new CellValue(index.ToString());
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
cell = InsertCellInWorksheet("H", (uint)rIndex + 2, worksheetPart);
index = InsertSharedStringItem(CommonProperty.ResultDataList[rIndex].GoodsPrice, shareStringPart);
cell.CellValue = new CellValue(index.ToString());
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
cell = InsertCellInWorksheet("I", (uint)rIndex + 2, worksheetPart);
index = InsertSharedStringItem(CommonProperty.ResultDataList[rIndex].GoodsWeight, shareStringPart);
cell.CellValue = new CellValue(index.ToString());
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
cell = InsertCellInWorksheet("J", (uint)rIndex + 2, worksheetPart);
index = InsertSharedStringItem(CommonProperty.ResultDataList[rIndex].GoodsVolume, shareStringPart);
cell.CellValue = new CellValue(index.ToString());
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
cell = InsertCellInWorksheet("K", (uint)rIndex + 2, worksheetPart);
index = InsertSharedStringItem(CommonProperty.ResultDataList[rIndex].ImageCount, shareStringPart);
cell.CellValue = new CellValue(index.ToString());
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
cell = InsertCellInWorksheet("L", (uint)rIndex + 2, worksheetPart);
index = InsertSharedStringItem(CommonProperty.ResultDataList[rIndex].Proscribes, shareStringPart);
cell.CellValue = new CellValue(index.ToString());
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
cell = InsertCellInWorksheet("M", (uint)rIndex + 2, worksheetPart);
index = InsertSharedStringItem(CommonProperty.ResultDataList[rIndex].Link, shareStringPart);
cell.CellValue = new CellValue(index.ToString());
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
cell = InsertCellInWorksheet("N", (uint)rIndex + 2, worksheetPart);
index = InsertSharedStringItem(CommonProperty.ResultDataList[rIndex].HtmlFilePath, shareStringPart);
cell.CellValue = new CellValue(index.ToString());
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
}
#endregion
// Save the new worksheet.
worksheetPart.Worksheet.Save();
}
}
// Given text and a SharedStringTablePart, creates a SharedStringItem with the specified text
// and inserts it into the SharedStringTablePart. If the item already exists, returns its index.
private static int InsertSharedStringItem(string text, SharedStringTablePart shareStringPart)
{
// If the part does not contain a SharedStringTable, create one.
if (shareStringPart.SharedStringTable == null)
{
shareStringPart.SharedStringTable = new SharedStringTable();
}
var i = 0;
// Iterate through all the items in the SharedStringTable. If the text already exists, return its index.
foreach (SharedStringItem item in shareStringPart.SharedStringTable.Elements<SharedStringItem>())
{
if (item.InnerText == text)
{
return i;
}
i++;
}
// The text does not exist in the part. Create the SharedStringItem and return its index.
shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new DocumentFormat.OpenXml.Spreadsheet.Text(text)));
shareStringPart.SharedStringTable.Save();
return i;
}
// Given a column name, a row index, and a WorksheetPart, inserts a cell into the worksheet.
// If the cell already exists, returns it.
private static Cell InsertCellInWorksheet(string columnName, uint rowIndex, WorksheetPart worksheetPart)
{
Worksheet worksheet = worksheetPart.Worksheet;
SheetData sheetData = worksheet.GetFirstChild<SheetData>();
string cellReference = columnName + rowIndex;
// If the worksheet does not contain a row with the specified row index, insert one.
Row row;
if (sheetData.Elements<Row>().Where(r => r.RowIndex == rowIndex).Count() != 0)
{
row = sheetData.Elements<Row>().Where(r => r.RowIndex == rowIndex).First();
}
else
{
row = new Row() { RowIndex = rowIndex };
sheetData.Append(row);
}
// If there is not a cell with the specified column name, insert one.
if (row.Elements<Cell>().Where(c => c.CellReference.Value == columnName + rowIndex).Count() > 0)
{
return row.Elements<Cell>().Where(c => c.CellReference.Value == cellReference).First();
}
else
{
// Cells must be in sequential order according to CellReference. Determine where to insert the new cell.
Cell refCell = null;
foreach (Cell cell in row.Elements<Cell>())
{
if (string.Compare(cell.CellReference.Value, cellReference, true) > 0)
{
refCell = cell;
break;
}
}
Cell newCell = new Cell() { CellReference = cellReference };
row.InsertBefore(newCell, refCell);
worksheet.Save();
return newCell;
}
}
}
}

Binary file not shown.

View File

@@ -38,7 +38,7 @@ namespace OCR_FILTER_JSH.SubForm
_formMainForm = formMainForm;
}
public void InitStartProgress()
public void InitStartProgress(bool autoProgress)
{
// 프로그레스 바를 초기화 함
progressBarControl_Time.Properties.Maximum = CommonProperty.TotalLinkCount;
@@ -50,15 +50,15 @@ namespace OCR_FILTER_JSH.SubForm
_beforeCommandTime = new TimeSpan(0);
// 프로그레스 바 관리 스레드
ProgressbarTrThread = new Thread(ProgressManagement);
ProgressbarTrThread.Start();
ProgressbarTrThread = new Thread(new ParameterizedThreadStart(ProgressManagement));
ProgressbarTrThread.Start(autoProgress);
}
/// <summary>
/// 프로그레스바 관리 스레드 함수
/// </summary>
public void ProgressManagement()
public void ProgressManagement(object autoProcess)
{
var pastTime = new TimeSpan(0, 0, 1);
@@ -103,7 +103,7 @@ namespace OCR_FILTER_JSH.SubForm
_formMainForm.WebBrowserManagementThread.Abort();
// Resut 결과 띄우기
_formMainForm.ShowResultData();
_formMainForm.ShowResultData(autoProcess);
// 프로그레스 바 종료
ProgressbarTrThread.Abort();
@@ -116,6 +116,8 @@ namespace OCR_FILTER_JSH.SubForm
_beforeCommandTime += pastTime;
}
}
/// <summary>

View File

@@ -34,10 +34,14 @@
this.textEdit_ImageWhiteSpaceSize = new DevExpress.XtraEditors.TextEdit();
this.panelControl1 = new DevExpress.XtraEditors.PanelControl();
this.simpleButton_SettingSave = new DevExpress.XtraEditors.SimpleButton();
this.label_SetLocation = new System.Windows.Forms.Label();
this.textEdit_setZipCode = new DevExpress.XtraEditors.TextEdit();
this.simpleButton_SetZipCode = new DevExpress.XtraEditors.SimpleButton();
((System.ComponentModel.ISupportInitialize)(this.textEdit_DownloadWebCount.Properties)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.textEdit_ImageWhiteSpaceSize.Properties)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.panelControl1)).BeginInit();
this.panelControl1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.textEdit_setZipCode.Properties)).BeginInit();
this.SuspendLayout();
//
// label_WebBrowserCount
@@ -76,28 +80,56 @@
//
this.panelControl1.Controls.Add(this.simpleButton_SettingSave);
this.panelControl1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panelControl1.Location = new System.Drawing.Point(0, 92);
this.panelControl1.Location = new System.Drawing.Point(0, 131);
this.panelControl1.Name = "panelControl1";
this.panelControl1.Size = new System.Drawing.Size(289, 28);
this.panelControl1.Size = new System.Drawing.Size(273, 28);
this.panelControl1.TabIndex = 2;
//
// simpleButton_SettingSave
//
this.simpleButton_SettingSave.Location = new System.Drawing.Point(201, 3);
this.simpleButton_SettingSave.Location = new System.Drawing.Point(181, 5);
this.simpleButton_SettingSave.Name = "simpleButton_SettingSave";
this.simpleButton_SettingSave.Size = new System.Drawing.Size(75, 23);
this.simpleButton_SettingSave.Size = new System.Drawing.Size(75, 20);
this.simpleButton_SettingSave.TabIndex = 0;
this.simpleButton_SettingSave.Text = "설정 저장";
this.simpleButton_SettingSave.Click += new System.EventHandler(this.simpleButton_SettingSave_Click);
//
// label_SetLocation
//
this.label_SetLocation.AutoSize = true;
this.label_SetLocation.Location = new System.Drawing.Point(21, 93);
this.label_SetLocation.Name = "label_SetLocation";
this.label_SetLocation.Size = new System.Drawing.Size(92, 14);
this.label_SetLocation.TabIndex = 0;
this.label_SetLocation.Text = "ZIPCODE 설정 : ";
//
// textEdit_setZipCode
//
this.textEdit_setZipCode.Location = new System.Drawing.Point(119, 90);
this.textEdit_setZipCode.Name = "textEdit_setZipCode";
this.textEdit_setZipCode.Size = new System.Drawing.Size(83, 20);
this.textEdit_setZipCode.TabIndex = 3;
//
// simpleButton_SetZipCode
//
this.simpleButton_SetZipCode.Location = new System.Drawing.Point(208, 89);
this.simpleButton_SetZipCode.Name = "simpleButton_SetZipCode";
this.simpleButton_SetZipCode.Size = new System.Drawing.Size(48, 23);
this.simpleButton_SetZipCode.TabIndex = 0;
this.simpleButton_SetZipCode.Text = "설정";
this.simpleButton_SetZipCode.Click += new System.EventHandler(this.simpleButton_SetZipCode_Click);
//
// SettingForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 14F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(289, 120);
this.ClientSize = new System.Drawing.Size(273, 159);
this.Controls.Add(this.simpleButton_SetZipCode);
this.Controls.Add(this.panelControl1);
this.Controls.Add(this.textEdit_setZipCode);
this.Controls.Add(this.textEdit_ImageWhiteSpaceSize);
this.Controls.Add(this.textEdit_DownloadWebCount);
this.Controls.Add(this.label_SetLocation);
this.Controls.Add(this.label_ImageWhiteSpaceSize);
this.Controls.Add(this.label_WebBrowserCount);
this.FormBorderEffect = DevExpress.XtraEditors.FormBorderEffect.None;
@@ -109,6 +141,7 @@
((System.ComponentModel.ISupportInitialize)(this.textEdit_ImageWhiteSpaceSize.Properties)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.panelControl1)).EndInit();
this.panelControl1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.textEdit_setZipCode.Properties)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@@ -122,5 +155,8 @@
private DevExpress.XtraEditors.TextEdit textEdit_ImageWhiteSpaceSize;
private DevExpress.XtraEditors.PanelControl panelControl1;
private DevExpress.XtraEditors.SimpleButton simpleButton_SettingSave;
private System.Windows.Forms.Label label_SetLocation;
private DevExpress.XtraEditors.TextEdit textEdit_setZipCode;
private DevExpress.XtraEditors.SimpleButton simpleButton_SetZipCode;
}
}

View File

@@ -1,7 +1,6 @@
using DevExpress.XtraEditors;
using System;
using System.IO;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace OCR_FILTER_JSH.SubForm
@@ -9,12 +8,12 @@ namespace OCR_FILTER_JSH.SubForm
public partial class SettingForm : XtraForm
{
private string _iniFileFullPath;
private string _preWebBrowserLimitCount;
private string _preImageWhiteSpaceSize;
IniFile _iniFile = new IniFile();
readonly IniFile _iniFile = new IniFile();
/// <summary>
/// 환경설정 폼
/// </summary>
public SettingForm()
{
InitializeComponent();
@@ -22,11 +21,16 @@ namespace OCR_FILTER_JSH.SubForm
InitForm();
}
/// <summary>
/// 폼 초기 설정
/// </summary>
public void InitForm()
{
// 초기 데이터 설정
textEdit_DownloadWebCount.Text = CommonProperty.WebBrowserLimitCount.ToString();
textEdit_ImageWhiteSpaceSize.Text = CommonProperty.ImageWhiteSpaceSize.ToString();
textEdit_setZipCode.Text = CommonProperty.InitZipCode;
// Ini 저장된 데이터 불러오기
// SaveData 폴더는 프로그램 시작 시 미리 생성됨
CommonProperty.SaveProgramDirecotryPath = Application.StartupPath + @"\SaveData";
@@ -38,10 +42,24 @@ namespace OCR_FILTER_JSH.SubForm
// ini 파일 내용 불러오기
if (!_iniFile.Load(_iniFileFullPath)) return;
CommonProperty.WebBrowserLimitCount =
int.Parse(_iniFile["iniSetting"]["WebBrowserLimitCount"].ToString());
CommonProperty.ImageWhiteSpaceSize =
int.Parse(_iniFile["iniSetting"]["ImageWhiteSpaceSize"].ToString());
if (!_iniFile.Keys.Contains("iniSetting")) return;
if (_iniFile["iniSetting"].ContainsKey("WebBrowserLimitCount"))
{
CommonProperty.WebBrowserLimitCount =
int.Parse(_iniFile["iniSetting"]["WebBrowserLimitCount"].ToString());
}
if (_iniFile["iniSetting"].ContainsKey("ImageWhiteSpaceSize"))
{
CommonProperty.ImageWhiteSpaceSize =
int.Parse(_iniFile["iniSetting"]["ImageWhiteSpaceSize"].ToString());
}
if (_iniFile["iniSetting"].ContainsKey("ZipCode"))
{
CommonProperty.ImageWhiteSpaceSize =
int.Parse(_iniFile["iniSetting"]["ZipCode"].ToString());
}
}
/// <summary>
@@ -53,20 +71,58 @@ namespace OCR_FILTER_JSH.SubForm
{
//TODO 추후 예외처리 추가
// 숫자 검사
var returnVal = 0;
if (!int.TryParse(textEdit_DownloadWebCount.Text, out returnVal)
&& !int.TryParse(textEdit_DownloadWebCount.Text, out returnVal))
if (!int.TryParse(textEdit_DownloadWebCount.Text, out _)
&& !int.TryParse(textEdit_ImageWhiteSpaceSize.Text, out _)
&& !int.TryParse(textEdit_setZipCode.Text, out _))
{
MessageBox.Show("숫자만 입력 가능");
MessageBox.Show(@"숫자만 입력 가능");
return;
}
// ini 파일 저장하기
_iniFile["iniSetting"]["WebBrowserLimitCount"] = textEdit_DownloadWebCount.Text;
_iniFile["iniSetting"]["ImageWhiteSpaceSize"] = textEdit_ImageWhiteSpaceSize.Text;
_iniFile["iniSetting"]["ZipCode"] = textEdit_setZipCode.Text;
_iniFile.Save(_iniFileFullPath);
this.Close();
}
/// <summary>
/// Excel 문설로드 > 작업진행 > Excel Export를 원클릭으로 처리하는 버튼 클릭 이벤트
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void simpleButton_SetZipCode_Click(object sender, EventArgs e)
{
// 숫자 검사
if (!int.TryParse(textEdit_setZipCode.Text, out _))
{
MessageBox.Show(@"숫자만 입력 가능");
return;
}
// Web Browser 생성
var webBrowser = new WebBrowser { ScriptErrorsSuppressed = true };
// 미국 ZIP코드로 변경
var strPostData =
$"https://www.amazon.com/gp/delivery/ajax/address-change.html?locationType=LOCATION_INPUT&zipCode={textEdit_setZipCode.Text}&storeContext=hpc&deviceType=web&pageType=Detail&actionSource=glow&almBrandId=undefined";
webBrowser.Navigate(strPostData);
webBrowser.DocumentCompleted += WebControl_DocumentComplete;
}
/// <summary>
/// 위치 지정 WebBrowser의 문서 로드 종료 시 이벤트
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private static void WebControl_DocumentComplete(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (!(sender is WebBrowser browser)) return;
// 문서로드 후 브라우저 종료
browser.Dispose();
}
}
}

View File

@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace OCR_FILTER_JSH.Web
@@ -14,25 +15,19 @@ namespace OCR_FILTER_JSH.Web
// Result Data에 들어간 Index
private int _index;
private string _goodsName;
// private BrowserForm browserForm = null;
private string _link;
private string _brandName;
public WebBrowserManagement(int index, string link, string goodsName = null, string brandName = null)
public WebBrowserManagement(int index, string link)
{
_goodsName = goodsName;
_brandName = brandName;
// Web Browser 생성
WebBrowser = new WebBrowser {ScriptErrorsSuppressed = true};
// 아마존 사이트의 위치 변경
// ChangeNavigatePost();
// Web Browser 이벤트 등록
WebBrowser.DocumentCompleted +=
new WebBrowserDocumentCompletedEventHandler(WebControl_DocumentComplete);
WebBrowser.Navigated += new WebBrowserNavigatedEventHandler(WebBrowserNavigatedEventHandler);
ChangeNavigate(index, link);
}
@@ -44,17 +39,31 @@ namespace OCR_FILTER_JSH.Web
// Web Browser Status 설정
WebBrowserStatus = CommonProperty.WebBrowserStatus.Create;
// 주소로 이동
WebBrowser.Navigate(_link);
}
private void WebBrowserNavigatedEventHandler(object sender, WebBrowserNavigatedEventArgs eventArgs)
public static List<HtmlElement> GetElementsByTagAndClassName(HtmlDocument doc, string tag = "", string className = "")
{
//var webBrowser = (WebBrowser)sender;
//var text = webBrowser.Document.Body.OuterHtml;
var lst = new List<HtmlElement>();
var emptyTag = string.IsNullOrEmpty(tag);
var emptyCn = string.IsNullOrEmpty(className);
if (emptyTag && emptyCn) return lst;
var elmts = emptyTag ? doc.All : doc.GetElementsByTagName(tag);
if (emptyCn)
{
lst.AddRange(elmts.Cast<HtmlElement>());
return lst;
}
for (int i = 0; i < elmts.Count; i++)
{
if (elmts[i].GetAttribute("className") == className)
{
lst.Add(elmts[i]);
}
}
return lst;
}
private void WebControl_DocumentComplete(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (!(sender is WebBrowser browser)) return;
@@ -62,24 +71,19 @@ namespace OCR_FILTER_JSH.Web
// HTML 가져오기
var outerHtml = WebBrowser?.Document?.Body?.OuterHtml;
var innerHtml = WebBrowser?.Document?.Body?.InnerHtml;
var allHtml = WebBrowser?.Document?.Body?.All;
var innerText = WebBrowser?.Document?.Body?.InnerText;
//WebBrowser?.Document?.get
// HTML의 NULL or 빈값 체크
if (string.IsNullOrEmpty(outerHtml)) return;
// 다음과 같은 영역이 존재해야 한다
if (!outerHtml.Contains("imageBlockVariations_feature_div") &&
!outerHtml.Contains("feature-bullets")) return;
if (!outerHtml.Contains("a-unordered-list a-nostyle a-vertical a-spacing-none detail-bullet-list")) return;
//!outerHtml.Contains("feature-bullets")) return;
// TODO HTML 내 내용만 확인하면 되기에 WebBrowser가 아닌 HTMLailityPack 사용
var suppliesPage = new HtmlAgilityPack.HtmlDocument();
suppliesPage.LoadHtml(outerHtml);
// 내부에 포함된 문장 비교
var compareText = suppliesPage.GetElementbyId("feature-bullets").InnerText.Trim();
var scriptSource = suppliesPage.GetElementbyId("imageBlockVariations_feature_div")?.ChildNodes?.ToList().Find(item => item.Name == "script");
// json string 뽑아내기
//var jsonStr = scriptSource.InnerHtml;
// 이미지 찾아내기
@@ -94,42 +98,85 @@ namespace OCR_FILTER_JSH.Web
var imageUrlListSub = ((Dictionary<string, object>)imageUrlList).First().Value;
var imageUrlListDic = (List<object>)((Dictionary<string, object>)imageUrlListSub).First().Value;
var searchPriceStr = "priceBlockBuyingPriceString";
string price = "";
string Volume = "";
string Weight = "";
string productNameKor = "";
string productName = "";
string brand = "";
var prime = false;
var pantry = false;
var noBlankInnerText = innerText.Replace(" ", "").Replace(" ", "");
var searchStr = "";
//TODO 나중에 소스코드 정리하기
/*
var detailBulletsWrapper_feature_div = suppliesPage.GetElementbyId("detailBulletsWrapper_feature_div");
var price_div = suppliesPage.GetElementbyId("price");
var productTitle_span = suppliesPage.GetElementbyId("productTitle");
*/
// 가격 찾기
jsonStr = outerHtml.Remove(
outerHtml.IndexOf(searchPriceStr) + searchPriceStr.Length + 2);
// 무게 찾기
// 부피 찾기
if (noBlankInnerText.Contains("Price:"))
{
searchStr = "Price:";
var removedStr = noBlankInnerText.Remove(0, noBlankInnerText.IndexOf(searchStr) + searchStr.Length);
removedStr = removedStr.Remove(removedStr.IndexOf('\r'));
price = removedStr.Replace("&FREEShipping.Details", "");
}
// 무게/부피 찾기
if (noBlankInnerText.Contains("Dimensions:")) {
searchStr = "Dimensions:";
var removedStr = noBlankInnerText.Remove(0, noBlankInnerText.IndexOf(searchStr) + searchStr.Length);
removedStr = removedStr.Remove(removedStr.IndexOf('\r'));
if (removedStr.Contains(';'))
{
var volumeWeight = removedStr.Split(';');
Volume = volumeWeight[0];
Weight = volumeWeight[1];
}
}
// Brand 찾기
if (innerText.Contains("\nManufacturer :"))
{
searchStr = "\nManufacturer :";
var removedStr = innerText.Remove(0, innerText.IndexOf(searchStr) + searchStr.Length);
removedStr = removedStr.Remove(removedStr.IndexOf('\r'));
brand = removedStr.Trim();
}
// 상품명 찾기
productName = suppliesPage.GetElementbyId("productTitle").InnerText;
// TODO Pantry 찾기
// TODO 프라임 구분하기 추가 구현
var noBlankInnerTextToLower = noBlankInnerText.ToLower();
if (noBlankInnerTextToLower.Contains("shipsfromandsoldbyamazon".ToLower()) ||
noBlankInnerTextToLower.Contains("shipsFrombyAmazon".ToLower()) || noBlankInnerTextToLower.Contains("shipsFromAmazon".ToLower()))
prime = true;
// Link 주소 1개에서 이벤트에 여러번 들어옴
var test = suppliesPage.GetElementbyId("priceblock_ourprice").OuterHtml.Trim();
//var node = DocumentNode.SelectSingleNode("//span[@id='foo']");
var resultData =
CommonProperty.ResultDataList.Find(
item => item.Index == _index);
if (resultData != null) return;
// Result Data 생성
CommonProperty.ResultDataList.Add(
new ResultData()
// Result Data 생성
CommonProperty.ResultDataList.Add(
new ResultData
{
Index = _index,
ProductName = _goodsName,
ProductName = productName,
ProductNameKor = "",
Link = _link,
BrandName = _brandName,
BrandName = brand,
GoodsCode = _link.Split('/').Last(),
WorkDirectoryPath = CommonProperty.SaveDirecotryPath,
ImageUrlList = imageUrlListDic,
GoodsVolume = Volume,
GoodsWeight = Weight,
GoodsPrice = price,
Prime = prime
});
// 더 이상 진행할 필요 없음

View File

@@ -6,8 +6,6 @@ using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Threading.Tasks;
using DevExpress.XtraRichEdit.Model;
using DocumentFormat.OpenXml.Wordprocessing;
namespace OCR_FILTER_JSH.Web
{
@@ -49,7 +47,7 @@ namespace OCR_FILTER_JSH.Web
return true;
}
catch (Exception e) { return false; }
catch { return false; }
}
return false;
@@ -138,13 +136,12 @@ namespace OCR_FILTER_JSH.Web
/// <summary>
/// OCR Text를 HTML stirng 으로 변환
/// </summary>
/// <param name="ocrText"></param>
/// <returns></returns>
public static string ConvertOcrStrToHtmlStr(ResultImageData resultImageData, bool containImage = false)
{
if (!string.IsNullOrEmpty(resultImageData.OcrOutputHtml)) return resultImageData.OcrOutputHtml;
var htmlStr = "";
string htmlStr;
// html
var startHtml = "<p style=\"max-width:1000px\">";
@@ -166,7 +163,6 @@ namespace OCR_FILTER_JSH.Web
// 이미지 사용 / 미사용
var changeStr = fontColorHtmlStart + proscribeData.Name + fontColorHtmlEnd;
ocrStr.Replace(proscribeData.Name, changeStr);
}
if (containImage)