- 중간 커밋

This commit is contained in:
2017-01-26 15:41:25 +09:00
parent df0ee31d18
commit 16733892b7
20 changed files with 171 additions and 148 deletions

1
.gitignore vendored
View File

@@ -2,3 +2,4 @@ bin/
obj/ obj/
log/ log/
publish/ publish/
.vs/

View File

@@ -501,6 +501,9 @@ namespace NewsCrawler
public void ReadDartAPI(bool bInitial = false) public void ReadDartAPI(bool bInitial = false)
{ {
if (Util.IsDebugging() == true)
return;
if(m_iDartAPIRetry <= 0) if(m_iDartAPIRetry <= 0)
return; return;

View File

@@ -1,119 +1,119 @@
using System; //using System;
using System.Collections.Generic; //using System.Collections.Generic;
using System.IO; //using System.IO;
using System.Linq; //using System.Linq;
using System.Runtime.InteropServices; //using System.Runtime.InteropServices;
using System.Text; //using System.Text;
using System.Threading.Tasks; //using System.Threading.Tasks;
using Excel = Microsoft.Office.Interop.Excel; //using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection; //using System.Reflection;
namespace NewsCrawler //namespace NewsCrawler
{ //{
public class ExcelHandler // public class ExcelHandler
{ // {
bool m_bAvailable = true; // bool m_bAvailable = true;
string m_strFileName = ""; // string m_strFileName = "";
string m_strToday = DateTime.Now.ToString("yyyy-MM-dd"); // string m_strToday = DateTime.Now.ToString("yyyy-MM-dd");
public ExcelHandler(string strFileName) // public ExcelHandler(string strFileName)
{ // {
m_strFileName = strFileName; // m_strFileName = strFileName;
} // }
public bool IsAvailable() // public bool IsAvailable()
{ // {
return m_bAvailable; // return m_bAvailable;
} // }
private void Create() // private void Create()
{ // {
try // try
{ // {
Excel.Application App = new Excel.Application(); // Excel.Application App = new Excel.Application();
if(App == null) // if(App == null)
{ // {
Util.Log(Util.LOG_TYPE.ERROR, "엑셀이 설치되지 않음"); // Util.Log(Util.LOG_TYPE.ERROR, "엑셀이 설치되지 않음");
m_bAvailable = false; // m_bAvailable = false;
return; // return;
} // }
Excel._Workbook Workbook = App.Workbooks.Add(Missing.Value); // Excel._Workbook Workbook = App.Workbooks.Add(Missing.Value);
Excel._Worksheet Worksheet = Workbook.ActiveSheet; // Excel._Worksheet Worksheet = Workbook.ActiveSheet;
Worksheet.Cells[1, 1] = "날짜"; // Worksheet.Cells[1, 1] = "날짜";
Worksheet.Cells[1, 2] = "기사 시간"; // Worksheet.Cells[1, 2] = "기사 시간";
Worksheet.Cells[1, 3] = "받은 시간"; // Worksheet.Cells[1, 3] = "받은 시간";
Worksheet.Cells[1, 4] = "출처"; // Worksheet.Cells[1, 4] = "출처";
Worksheet.Cells[1, 5] = "제목"; // Worksheet.Cells[1, 5] = "제목";
Worksheet.Cells[1, 6] = "요청 시간"; // Worksheet.Cells[1, 6] = "요청 시간";
Worksheet.Cells[1, 7] = "시가"; // Worksheet.Cells[1, 7] = "시가";
Worksheet.Cells[1, 8] = "저가"; // Worksheet.Cells[1, 8] = "저가";
Worksheet.Cells[1, 9] = "대비"; // Worksheet.Cells[1, 9] = "대비";
Worksheet.Cells[1, 10] = "고가"; // Worksheet.Cells[1, 10] = "고가";
Worksheet.Cells[1, 11] = "대비"; // Worksheet.Cells[1, 11] = "대비";
Worksheet.Cells[1, 12] = "링크"; // Worksheet.Cells[1, 12] = "링크";
Workbook.SaveAs(m_strFileName, Excel.XlFileFormat.xlOpenXMLWorkbook, Missing.Value, // Workbook.SaveAs(m_strFileName, Excel.XlFileFormat.xlOpenXMLWorkbook, Missing.Value,
Missing.Value, false, false, Excel.XlSaveAsAccessMode.xlNoChange, // Missing.Value, false, false, Excel.XlSaveAsAccessMode.xlNoChange,
Excel.XlSaveConflictResolution.xlUserResolution, true, // Excel.XlSaveConflictResolution.xlUserResolution, true,
Missing.Value, Missing.Value, Missing.Value); // Missing.Value, Missing.Value, Missing.Value);
Workbook.Close(); // Workbook.Close();
} // }
catch(Exception ex) // catch(Exception ex)
{ // {
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace); // Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
} // }
} // }
public bool AddRow(string strNewsTime, string strResTime, string strRef, string strTitle, float fReqTime, int iPriceS, int iPriceLow, float fPriceLowP, int iPriceHigh, float fPriceHighP, string strLink) // public bool AddRow(string strNewsTime, string strResTime, string strRef, string strTitle, float fReqTime, int iPriceS, int iPriceLow, float fPriceLowP, int iPriceHigh, float fPriceHighP, string strLink)
{ // {
lock(this) // lock(this)
{ // {
if(m_bAvailable == false) // if(m_bAvailable == false)
return false; // return false;
if(File.Exists(m_strFileName) == false) // if(File.Exists(m_strFileName) == false)
Create(); // Create();
try // try
{ // {
Excel.Application App = new Excel.Application(); // Excel.Application App = new Excel.Application();
if(App == null) // if(App == null)
{ // {
Util.Log(Util.LOG_TYPE.ERROR, "엑셀이 설치되지 않음"); // Util.Log(Util.LOG_TYPE.ERROR, "엑셀이 설치되지 않음");
m_bAvailable = false; // m_bAvailable = false;
return false; // return false;
} // }
App.DisplayAlerts = false; // App.DisplayAlerts = false;
Excel._Workbook Workbook = App.Workbooks.Open(m_strFileName); // Excel._Workbook Workbook = App.Workbooks.Open(m_strFileName);
Excel._Worksheet Worksheet = Workbook.ActiveSheet; // Excel._Worksheet Worksheet = Workbook.ActiveSheet;
int iRow = Worksheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell, Type.Missing).Row+1; // int iRow = Worksheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell, Type.Missing).Row+1;
Worksheet.Cells[iRow, 1] = m_strToday; // Worksheet.Cells[iRow, 1] = m_strToday;
Worksheet.Cells[iRow, 2] = strNewsTime; // Worksheet.Cells[iRow, 2] = strNewsTime;
Worksheet.Cells[iRow, 3] = strResTime; // Worksheet.Cells[iRow, 3] = strResTime;
Worksheet.Cells[iRow, 4] = strRef; // Worksheet.Cells[iRow, 4] = strRef;
Worksheet.Cells[iRow, 5] = strTitle; // Worksheet.Cells[iRow, 5] = strTitle;
Worksheet.Cells[iRow, 6] = fReqTime; // Worksheet.Cells[iRow, 6] = fReqTime;
Worksheet.Cells[iRow, 7] = iPriceS; // Worksheet.Cells[iRow, 7] = iPriceS;
Worksheet.Cells[iRow, 8] = iPriceLow; // Worksheet.Cells[iRow, 8] = iPriceLow;
Worksheet.Cells[iRow, 9] = fPriceLowP; // Worksheet.Cells[iRow, 9] = fPriceLowP;
Worksheet.Cells[iRow, 10] = iPriceHigh; // Worksheet.Cells[iRow, 10] = iPriceHigh;
Worksheet.Cells[iRow, 11] = fPriceHighP; // Worksheet.Cells[iRow, 11] = fPriceHighP;
Worksheet.Cells[iRow, 12] = strLink; // Worksheet.Cells[iRow, 12] = strLink;
Workbook.Save(); // Workbook.Save();
Workbook.Close(); // Workbook.Close();
} // }
catch(Exception ex) // catch(Exception ex)
{ // {
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace); // Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
return false; // return false;
} // }
} // }
return true; // return true;
} // }
} // }
} //}

BIN
ExcelLibrary.dll Normal file

Binary file not shown.

26
ListViewNF.cs Normal file
View File

@@ -0,0 +1,26 @@
using System.Windows.Forms;
namespace NewsCrawler
{
class ListViewNF : System.Windows.Forms.ListView
{
public ListViewNF()
{
//Activate double buffering
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
//Enable the OnNotifyMessage event so we get a chance to filter out
// Windows messages before they get to the form's WndProc
this.SetStyle(ControlStyles.EnableNotifyMessage, true);
}
protected override void OnNotifyMessage(Message m)
{
//Filter out the WM_ERASEBKGND message
if (m.Msg != 0x14)
{
base.OnNotifyMessage(m);
}
}
}
}

View File

@@ -38,6 +38,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
@@ -89,6 +90,9 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="ListViewNF.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="CodeList.cs" /> <Compile Include="CodeList.cs" />
<Compile Include="Config.cs" /> <Compile Include="Config.cs" />
<Compile Include="ConfigForm.cs"> <Compile Include="ConfigForm.cs">
@@ -213,33 +217,6 @@
<Isolated>False</Isolated> <Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes> <EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference> </COMReference>
<COMReference Include="Microsoft.Office.Core">
<Guid>{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}</Guid>
<VersionMajor>2</VersionMajor>
<VersionMinor>4</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>primary</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
<COMReference Include="Microsoft.Office.Interop.Excel">
<Guid>{00020813-0000-0000-C000-000000000046}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>6</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>primary</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
<COMReference Include="VBIDE">
<Guid>{0002E157-0000-0000-C000-000000000046}</Guid>
<VersionMajor>5</VersionMajor>
<VersionMinor>3</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>primary</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.5.2"> <BootstrapperPackage Include=".NETFramework,Version=v4.5.2">

6
NewsForm.Designer.cs generated
View File

@@ -28,7 +28,7 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.lvList = new System.Windows.Forms.ListView(); this.lvList = new NewsCrawler.ListViewNF();
this.chId = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chId = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chTime = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chTime = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chResT = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chResT = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
@@ -279,7 +279,7 @@
// //
this.chBuy.Appearance = System.Windows.Forms.Appearance.Button; this.chBuy.Appearance = System.Windows.Forms.Appearance.Button;
this.chBuy.AutoSize = true; this.chBuy.AutoSize = true;
this.chBuy.Location = new System.Drawing.Point(356, 1); this.chBuy.Location = new System.Drawing.Point(359, 1);
this.chBuy.Name = "chBuy"; this.chBuy.Name = "chBuy";
this.chBuy.Size = new System.Drawing.Size(39, 22); this.chBuy.Size = new System.Drawing.Size(39, 22);
this.chBuy.TabIndex = 9; this.chBuy.TabIndex = 9;
@@ -329,7 +329,7 @@
#endregion #endregion
private System.Windows.Forms.ListView lvList; private ListViewNF lvList;
private System.Windows.Forms.ColumnHeader chTime; private System.Windows.Forms.ColumnHeader chTime;
private System.Windows.Forms.ColumnHeader chTitle; private System.Windows.Forms.ColumnHeader chTitle;
private System.Windows.Forms.ColumnHeader chReference; private System.Windows.Forms.ColumnHeader chReference;

View File

@@ -86,7 +86,7 @@ namespace NewsCrawler
Crawler m_Crawler = null; Crawler m_Crawler = null;
ExcelHandler m_Excel = null; //ExcelHandler m_Excel = null;
float m_fSupplyContractRate; float m_fSupplyContractRate;
@@ -148,13 +148,13 @@ namespace NewsCrawler
lvList.SelectedItems[0].EnsureVisible(); lvList.SelectedItems[0].EnsureVisible();
} }
foreach(ColumnHeader col in lvList.Columns) //foreach(ColumnHeader col in lvList.Columns)
{ //{
if(!(col == chPriceS || col == chPriceLow || col == chPriceHigh)) // if(!(col == chPriceS || col == chPriceLow || col == chPriceHigh))
col.Width = -2; // col.Width = -2;
} //}
m_Excel = new ExcelHandler(Util.GetLogPath()+"/PriceCheck"+DateTime.Now.ToString("yyyy-MM-dd")+".xlsx"); //m_Excel = new ExcelHandler(Util.GetLogPath()+"/PriceCheck"+DateTime.Now.ToString("yyyy-MM-dd")+".xlsx");
m_CrawlTimer.Elapsed+=CrawlTimer_Tick; m_CrawlTimer.Elapsed+=CrawlTimer_Tick;
m_CrawlTimer.Interval = m_iCrawlInterval; m_CrawlTimer.Interval = m_iCrawlInterval;
@@ -387,6 +387,15 @@ namespace NewsCrawler
"", "",
strURL })); strURL }));
if(lvList.Items.Count == 0)
{
foreach (ColumnHeader col in lvList.Columns)
{
if (!(col == chPriceS || col == chPriceLow || col == chPriceHigh))
col.Width = -2;
}
}
lock(m_URLs) lock(m_URLs)
m_URLs.Add(strURL); m_URLs.Add(strURL);
@@ -548,11 +557,11 @@ namespace NewsCrawler
if(Data.m_bLog == false) if(Data.m_bLog == false)
{ {
Data.m_bLog = m_Excel.AddRow(Data.m_NewsItem.m_NewsTime.ToString("HH:mm:ss:fff"), Data.m_NewsItem.m_ResTime.ToString("HH:mm:ss:fff"), Data.m_NewsItem.m_strRef, Data.m_NewsItem.m_strTitle, Data.m_NewsItem.m_fElapseT, //Data.m_bLog = m_Excel.AddRow(Data.m_NewsItem.m_NewsTime.ToString("HH:mm:ss:fff"), Data.m_NewsItem.m_ResTime.ToString("HH:mm:ss:fff"), Data.m_NewsItem.m_strRef, Data.m_NewsItem.m_strTitle, Data.m_NewsItem.m_fElapseT,
Data.m_iPriceStart, // Data.m_iPriceStart,
Data.m_iPriceLow, (Data.m_iPriceLow-Data.m_iPriceStart)*100/(float)Data.m_iPriceStart, // Data.m_iPriceLow, (Data.m_iPriceLow-Data.m_iPriceStart)*100/(float)Data.m_iPriceStart,
Data.m_iPriceHigh, (Data.m_iPriceHigh-Data.m_iPriceStart)*100/(float)Data.m_iPriceStart, // Data.m_iPriceHigh, (Data.m_iPriceHigh-Data.m_iPriceStart)*100/(float)Data.m_iPriceStart,
Data.m_NewsItem.m_strURL); // Data.m_NewsItem.m_strURL);
} }
if(Data.m_bLog == false) if(Data.m_bLog == false)

View File

@@ -113,7 +113,11 @@ namespace NewsCrawler
public static bool IsDebugging() public static bool IsDebugging()
{ {
#if DEBUG
return Debugger.IsAttached; return Debugger.IsAttached;
#else
return false;
#endif
} }
public static string GetConfigPath() public static string GetConfigPath()

View File

@@ -76,3 +76,5 @@ KODEX 단기채권
강스템바이오텍 강스템바이오텍
금호타이어 금호타이어
아이진 아이진
바른전자
솔고바이오

View File

@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="Microsoft.Office.Interop.Excel" version="15.0.4795.1000" targetFramework="net452" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" /> <package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
</packages> </packages>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.