-
Notifications
You must be signed in to change notification settings - Fork 2
/
COmdFileFactor.cpp
117 lines (99 loc) · 2.61 KB
/
COmdFileFactor.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
// OmdFile1.cpp: implementation of the COmdFile0 class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "COmdFile0.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////////
//輸出輸入文件格式
//oForm() output form
//iForm() input form
//////////////////////////////////////////////////////////////////////////
COmdFileFactor::COmdFileFactor(){};
COmdFileFactor::~COmdFileFactor()
{
m_omdRNA.Empty();
m_dTxt.clear();
};
BOOL COmdFileFactor::Open(LPCTSTR path, CFileException& fx)
{
if (m_fTxt.Open(path, fx))
return TRUE;
else
{
ErrorMsg(fx);
return FALSE;
}
}
BOOL COmdFileFactor::Save(LPCTSTR path, CFileException& fx)
{
if (m_fTxt.Save(path, fx))
{
return TRUE;
}
else
{
ErrorMsg(fx);
m_fTxt.Close();
return FALSE;
}
}
const CString COmdFileFactor::GetLine(const int& lineIndex) const//OK
{
if (lineIndex <= 0)
return "出現錯誤: 參數 < 1";
else if (lineIndex > m_dTxt.size())
return "超出範圍";
else
return m_dTxt.at((std::vector<CString>::size_type)lineIndex - 1);
}
const CString COmdFileFactor::GetCell(const int& Word, const int& line) const
{
CString strBuf1;
CString strBuf2;
strBuf1 = GetLine(line) + '\t';
if (!strBuf1.IsEmpty())
{
int wBegin = 0, wLength = 0;
for (int i = 0; i < Word; ++i)
{
wLength = strBuf1.Right(strBuf1.GetLength() - wBegin).Find('\t');
strBuf2.Format("%s", strBuf1.Mid(wBegin, wLength));
wBegin += wLength + 1;
}
}
if (strBuf2.IsEmpty())
strBuf2.Format("");//(內容空白)
return strBuf2;
}
const CString COmdFileFactor::GetCell(const TCHAR& c, const int& n) const
{
int x;
x = c - 'A'+1;
return GetCell(x, n);
}
const CString COmdFileFactor::GetCell(const PTCHAR& c, const int& n) const
{
CString str;
str.Format("%s", c);
TCHAR c1;
TCHAR c2;
c1 = *(str.Left(1).GetBuffer(str.Left(1).GetLength()));
c2 = *(str.Right(1).GetBuffer(str.Left(1).GetLength()));
int x;
x = (c1 - 'A'+1) + (c2 - 'A'+1) + 'Z'+1;//+25是因為這個部份是從AA開始算,所以要跳過A~Z
return GetCell(x, n);
}
void COmdFileFactor::ErrorMsg(CFileException& fx) const
{
//例外處理
TCHAR buf[255];
fx.GetErrorMessage(buf, 255);
CString strPrompt;
strPrompt.Format("COmdFileFactor::LoadData()\n%s", buf);
AfxMessageBox(strPrompt);
}