-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSelExcelDlg.cpp
305 lines (255 loc) · 10.2 KB
/
SelExcelDlg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
// SelExcelDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ColorEyeI.h"
#include "SelExcelDlg.h"
#include "MainFrm.h"
#include "ColorEyeIDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSelExcelDlg dialog
CSelExcelDlg::CSelExcelDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSelExcelDlg::IDD, pParent)
{
EnableAutomation(); //為什麼要有這個呀?
//{{AFX_DATA_INIT(CSelExcelDlg)
m_xlsDescrip = _T("");
//}}AFX_DATA_INIT
}
void CSelExcelDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSelExcelDlg)
DDX_Control(pDX, IDOK, m_tran2Xls);
DDX_Control(pDX, IDC_LIST_SELFILELIST, m_lstSelOmdFileList);
DDX_Control(pDX, IDC_STATIC_HDFILELIST, m_stcHDFileList);
DDX_Control(pDX, IDC_RADIO_HDFILE, m_rdoChooseHDFile);
DDX_Control(pDX, IDC_COMBO_EXCELSELER, m_cbxExcelSelor);
DDX_Control(pDX, IDC_RADIO_NOWFILE, m_rdoChooseNowFile);
DDX_Control(pDX, IDC_BUTTON_FINDFILE, m_btnFindFile);
DDX_Text(pDX, IDC_STATIC_XLSDESCRIP, m_xlsDescrip);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSelExcelDlg, CDialog)
//{{AFX_MSG_MAP(CSelExcelDlg)
ON_CBN_SELCHANGE(IDC_COMBO_EXCELSELER, OnSelectXlsForm)
ON_BN_CLICKED(IDC_BUTTON_FINDFILE, OnFindOmdFile)
ON_BN_CLICKED(IDC_RADIO_NOWFILE, OnRadioNowfile)
ON_BN_CLICKED(IDC_RADIO_HDFILE, OnRadioHdfile)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSelExcelDlg message handlers
BOOL CSelExcelDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
setOmdComeFrom(ThisFile);
initSelXlsCbx("xls");
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
const CString CSelExcelDlg::reconstructSearchXlsPath(const CString& XlsNameExt)
{
CColorEyeIApp* pApp = dynamic_cast<CColorEyeIApp*>(AfxGetApp());
ASSERT_VALID(pApp);
//抓取程式目錄下的.xls表格
return pApp->GetPath() + "\\*." + XlsNameExt; //目前執行檔所在路徑/*.xls
}
void CSelExcelDlg::initSelXlsCbx(const CString& XlsNameExt)
{
//找第一個檔案
WIN32_FIND_DATA FindFileData; //一個結構,找到的檔案
HANDLE hListFile;
hListFile = FindFirstFile(reconstructSearchXlsPath(XlsNameExt), &FindFileData);
//找xls檔案的動作
//設定下拉式選單的可選表格
//內建表格
m_cbxExcelSelor.ResetContent();
m_cbxExcelSelor.AddString("RA Form"); //0
m_cbxExcelSelor.AddString("SEC Form"); //1
//外加表格
if(hListFile != INVALID_HANDLE_VALUE)
{
//填上選擇Excel下拉式選單的資料
do m_cbxExcelSelor.AddString(FindFileData.cFileName);
while(FindNextFile(hListFile, &FindFileData));
}
m_cbxExcelSelor.SetCurSel(0);
OnSelectXlsForm();
}
void CSelExcelDlg::OnRadioNowfile()
{
// TODO: Add your control notification handler code here
setOmdComeFrom(ThisFile);
}
void CSelExcelDlg::OnRadioHdfile()
{
// TODO: Add your control notification handler code here
setOmdComeFrom(OtherFile);
}
void CSelExcelDlg::setOmdComeFrom(WhereFileComeFrom WFCF)
{
//用Radio選擇誰要enable,誰不要
m_rdoChooseNowFile.SetCheck(!WFCF);
m_rdoChooseHDFile.SetCheck(WFCF);
m_lstSelOmdFileList.EnableWindow(WFCF);
m_btnFindFile.EnableWindow(WFCF);
m_stcHDFileList.EnableWindow(WFCF);
}
void CSelExcelDlg::setSelXlsDetail(const LPCTSTR& _S, const int& _I, const FormType& _F, const BOOL& _B)
{
m_xlsDescrip.Format(_S);
m_omdOpenLimit = _I;
m_omdFromType = _F;
m_tran2Xls.EnableWindow(_B);
}
void CSelExcelDlg::OnSelectXlsForm()
{
// TODO: Add your control notification handler code here
//下拉式選單選擇時的動作
CString str;
m_lstSelOmdFileList.ResetContent();
m_cbxExcelSelor.GetLBText(m_cbxExcelSelor.GetCurSel(), str);
const CString W9_1over6("白色9點_離邊1/6\n");
const CString D9_0("黑色9點\n");
const CString WRGBD("WRGBD中心點\n");
const CString Nits5sub("Nits5↓\n");
const CString NitsLvValue("灰階階數\n");
const CString FlickerValue("Flicker\n");
const CString CaChannelIndex("Channel Number\n");
const CString CaProbeSerNo("Probe Number\n");
const CString D25side10_0("黑色25點\n");
const CString D21_0("黑色21點\n");
const CString CrossTalk_1over4("CrossTalk\n");
const CString ColorGamut("Color Gamut\n");
const CString WRGB_Gamma("WRGB Gamma Curve");
const CString dscrptRA(W9_1over6 + CaChannelIndex + CaProbeSerNo);
const CString dscrptOQCmass("2013年量產表格\n" + W9_1over6 + WRGBD + Nits5sub + FlickerValue + NitsLvValue + CaChannelIndex + D25side10_0 + D21_0 + CrossTalk_1over4 + ColorGamut);
const CString dscrptOQCtest("2013年試產表格\n" + W9_1over6 + WRGBD + Nits5sub + FlickerValue + NitsLvValue + CaChannelIndex + D25side10_0 + D21_0 + CrossTalk_1over4 + ColorGamut);
const CString dscrptGamma(WRGB_Gamma);
const CString dscrptSEC(W9_1over6 + D9_0 + WRGBD + Nits5sub + NitsLvValue + CaChannelIndex + FlickerValue + CrossTalk_1over4);
if (str.Find("RA") != -1) setSelXlsDetail(dscrptRA , 100, FM_RA );
else if (str.Find("Y2013") != -1) setSelXlsDetail(dscrptOQCmass, 10 , FM_OQCY2013_Volume);
else if (str.Find("OQC") != -1) setSelXlsDetail(dscrptOQCtest, 10 , FM_OQC_Test );
else if (str.Find("Gamma") != -1) setSelXlsDetail(dscrptGamma , 5 , FM_Gamma );
else if (str.Find("SEC") != -1) setSelXlsDetail(dscrptSEC , 1 , FM_SEC );
else setSelXlsDetail("(無法識別)" , 1 , FM_Nothing, FALSE );
UpdateData(FALSE);
}
void CSelExcelDlg::findOtherOmdFile(std::vector<CString>& fileList)
{
CString fOmdFilter("OrigMsrData Files (*.omd)|*.omd|Text File(*.txt)|*.txt|All Files (*.*)|*.* ||");//檔案過濾條件
CFileDlg aFileDialog (TRUE, NULL, NULL, \
( m_omdOpenLimit > 1 ) ? OFN_ALLOWMULTISELECT | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT \
: OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, fOmdFilter);
aFileDialog.SetSelMultiFileTotal(m_omdOpenLimit); //設定可以選幾個檔案。
if (aFileDialog.DoModal() == IDOK)
aFileDialog.GetSelFileList(fileList);
if(CommDlgExtendedError() == FNERR_BUFFERTOOSMALL)
AfxMessageBox("Sel Excel Dialog緩衝區不夠大\n剪下畫面,並且找程式設計師解決這問題。", MB_OK | MB_ICONERROR);
else
m_lstSelOmdFileList.ResetContent();
}
void CSelExcelDlg::showOtherOmdList(std::vector<CString>& fileList)
{
for (std::vector<CString>::iterator itStr = fileList.begin(); itStr != fileList.end(); ++itStr)
{
//顯示時會依表格適用幾筆Omd檔的數量,做限制。
if (itStr - fileList.begin() < m_omdOpenLimit)
m_lstSelOmdFileList.AddString(itStr->Right(itStr->GetLength() - itStr->ReverseFind('\\') - 1));
else
{
fileList.erase(itStr, fileList.end()); //超過表格可以裝載數量,就刪掉。
break;
}
}
}
void CSelExcelDlg::OnFindOmdFile()
{
// TODO: Add your control notification handler code here
findOtherOmdFile(m_omdList); //找omd檔案的動作
showOtherOmdList(m_omdList); //檔案列表裝在控制項上
}
void CSelExcelDlg::OnOK()
{
BeginWaitCursor();
XLSPTR pXls;
pXls = 0;
initXlsObj(pXls);
out2xls(pXls);
if (pXls != 0)
delete pXls;
EndWaitCursor();
CDialog::OnOK();
}
void CSelExcelDlg::initXlsObj(XLSPTR& pXls)
{
switch(m_omdFromType)
{
case FM_SEC: pXls = new CXlsSEC1 (); pXls->New()->SetSheetName(1,"SEC Report"); break;
case FM_RA: pXls = new CXlsRA1 (); pXls->New()->SetSheetName(1,"RA Report"); break;
case FM_OQC_Test: pXls = new CXlsOQCtest(); pXls->Open(getCurSelXlsPath())/*->SetSheetName(1, "光學")*/; break;
case FM_OQCY2013_Volume: pXls = new CXlsOQCmass(); pXls->Open(getCurSelXlsPath())/*->SetSheetName(1, "光學")*/; break;
case FM_Gamma: pXls = new CXlsGamma (); pXls->Open(getCurSelXlsPath())/*->SetSheetName(1, "Color Data")*/; break;
case FM_Nothing:
default: AfxMessageBox("怎麼會選這一個輸出?");
}
}
const CString CSelExcelDlg::getCurSelXlsPath() const
{
CColorEyeIApp* pApp = dynamic_cast<CColorEyeIApp*>(AfxGetApp());
ASSERT_VALID(pApp);
CString xlsSelNamePath;
m_cbxExcelSelor.GetLBText(m_cbxExcelSelor.GetCurSel(), xlsSelNamePath); //ComboBox -> file name
return pApp->GetPath() + "\\" + xlsSelNamePath;
}
void CSelExcelDlg::out2xls(XLSPTR& pXls)
{
if ( m_rdoChooseHDFile.GetCheck() == OtherFile )
otherOmd2xls(pXls);
else
thisOmd2xls(pXls);
}
void CSelExcelDlg::otherOmd2xls(XLSPTR& hdXls)
{
hdXls->InitForm();
COmdFile0 fOmd;
for (std::vector<CString>::iterator itfPaths = m_omdList.begin(); itfPaths != m_omdList.end(); ++itfPaths)
{
//在此,等同於Doc的開啟舊檔As omd
if(!fOmd.Open(*itfPaths))
AfxMessageBox("路徑有問題");
else
{
// CString str;
// str.Format("%s, %s, %s, %s", fOmd.GetFileHead().oCHID(), fOmd.GetFileHead().oPnlID(), fOmd.GetFileHead().oPrb(), fOmd.GetFileHead().oNitsLv());
// AfxMessageBox(str);
hdXls->iCellNO (abs(itfPaths - m_omdList.begin()));
hdXls->iData (fOmd.oOmdData()); //先給這個,才可以給head(doc 的open也是一樣)
hdXls->iChannel(fOmd.GetFileHead().oCHID());
hdXls->iPanelID(fOmd.GetFileHead().oPnlID());
hdXls->iProb (fOmd.GetFileHead().oPrb());
hdXls->iNitsLv (fOmd.GetFileHead().oNitsLv());
fOmd.Close();
}
}
}
void CSelExcelDlg::thisOmd2xls(XLSPTR& docXls)
{
docXls->InitForm();
CMainFrame* m_pMainFrm = dynamic_cast<CMainFrame*>(AfxGetMainWnd());
CColorEyeIDoc* m_pDoc = dynamic_cast<CColorEyeIDoc*>(m_pMainFrm->GetActiveDocument());
ASSERT_VALID(m_pMainFrm);
ASSERT_VALID(m_pDoc);
docXls->iCellNO (0);
docXls->iChannel(m_pDoc->GetFileHead().oCHID());
docXls->iPanelID(m_pDoc->GetFileHead().oPnlID());
docXls->iProb (m_pDoc->GetFileHead().oPrb());
docXls->iNitsLv (m_pDoc->GetFileHead().oNitsLv());
docXls->iData (m_pDoc->GetDocRNA());
}