DCL 3.7.4
Loading...
Searching...
No Matches
ZipCode.cpp
Go to the documentation of this file.
1#include <dcl/Config.h>
2
3#ifdef __WINNT__
4#include <windows.h>
5#endif
6
7#include <dcl/URI.h>
8
9#include "HtmlPage.h"
10#include "LinkUtility.h"
11#include "HtmlView.h"
12
13#if __DCL_HAVE_THIS_FILE__
14#undef __THIS_FILE__
15static const char_t __THIS_FILE__[] = __T("fastpage/ZipCode.cpp");
16#endif
17
18__DCL_BEGIN_NAMESPACE
19
21
22ZipCodeListView::ZipCodeListView(HtmlPage* pPage)
23 : HtmlView(pPage)
24{
25 __nParts = 5;
26 __nRows = 10;
27}
28
29void ZipCodeListView::init(SQLFields& fields)
31{
32 HtmlView::init(fields);
33
34 String rValue;
35 if (__mapParams.lookup(L"PARTS", rValue) && !rValue.isEmpty()) {
36 int n = Integer::parse(rValue, 10, 0);
37 if (5 <= n && n <= 20)
38 __nParts = n;
39 }
40
41 if (__mapParams.lookup(L"ROWS", rValue) && !rValue.isEmpty()) {
42 int n = Integer::parse(rValue, 10, 0);
43 if (n > 0)
44 __nRows = n;
45 }
46}
47
48void ZipCodeListView::onPrint(Session& session)
50{
51 SQLQuery& q = session.__query;
52 ListedStringToStringArrayMap& mapQuery = session.__ctx.__queryMap;
53
54 int nCurrentPart = Integer::parse(getDefault(mapQuery, L"part"), 10, 1);
55 int nRows = __nRows;
56
57 StringBuilder strThisPage = __pPage->__strPageID;
58 String strThisPageEnc;
59
60 String strSido = getDefault(mapQuery, L"sido");
61 String strGugun = getDefault(mapQuery, L"gugun");
62 String strDong = getDefault(mapQuery, L"dong");
63
64 StringBuilder strWhere;
65
66 if (!strSido.isEmpty()) {
67 strWhere = L"SIDO LIKE \'" + strSido + L"%\'";
68 strThisPage += L"&sido=" + strSido;
69 }
70 if (!strGugun.isEmpty()) {
71 if (!strWhere.isEmpty())
72 strWhere += L" AND ";
73 strWhere += L"GUGUN LIKE \'" + strGugun + L"%\'";
74 strThisPage += L"&gugun=" + strGugun;
75 }
76 if (!strDong.isEmpty()) {
77 if (!strWhere.isEmpty())
78 strWhere += L" AND ";
79 strWhere += L"DONG LIKE \'" + strDong + L"%\'";
80 strThisPage += L"&dong=" + strDong;
81 }
82
83 if (strWhere.isEmpty()) {
84 assign(L"DEFAULT", (*this)[L"DEFAULT"]);
85 HtmlView::onPrint(session);
86 return;
87 }
88
89 assign(L"SIDO", strSido);
90 assign(L"GUGUN", strGugun);
91 assign(L"DONG", strDong);
92
93 int nUsingRecord = nRows;
94 int nTotalRecord = nUsingRecord;
95 int nTotalPart = 1;
96
97 StringBuilder strSQL = L""
98 "SELECT COUNT(*)"
99 "\n FROM DCL_ZIPCODE";
100 if (!strWhere.isEmpty())
101 strSQL += L"\n WHERE " + strWhere.toString();
102
103 q.execute(strSQL);
104 q.fetch();
105 nTotalRecord = q.fields()[0].asInteger();
106 if (nTotalRecord == 0) {
107 assign(L"EMPTY", (*this)[L"EMPTY"]);
108 HtmlView::onPrint(session);
109 return;
110 }
111
112 __DCL_VERIFY(nTotalRecord > 0);
113
114 nTotalPart = nTotalRecord / nUsingRecord;
115 if (nTotalRecord % nUsingRecord)
116 nTotalPart++;
117
118 if (nCurrentPart <= 0 || nCurrentPart > nTotalPart)
119 nCurrentPart = nTotalPart;
120
121 StringBuilder strThisPageEx = strThisPage;
122 if (nCurrentPart > 1)
123 strThisPageEx += L"&part=" + String::valueOf(nCurrentPart);
124 strThisPageEnc = URLEncoder::encode(strThisPageEx);
125 assign(L"_THIS", strThisPageEnc);
126
127 int nOffset = (nCurrentPart - 1) * nUsingRecord;
128 int nNo = nTotalRecord - ((nCurrentPart - 1) * nUsingRecord);
129 int nRow = 1;
130
131 TextTemplate& ROW = (*this)[L"ROW"];
132
133 strSQL = L""
134 "SELECT ZIPCODE"
135 ", CONCAT(SIDO, ' ', GUGUN, ' ', DONG) AS ADDRESS"
136 ", BUNJI"
137 "\n FROM DCL_ZIPCODE";
138
139 if (!strWhere.isEmpty())
140 strSQL += L"\n WHERE " + strWhere.toString();
141
142 strSQL += L"\n ORDER BY ZIPCODE"
143 "\n LIMIT " + String::valueOf(nUsingRecord) + L""
144 "\n OFFSET " + String::valueOf(nOffset);
145
146 q.execute(strSQL);
147 q.fetch();
148 if (q.eof())
149 assign(L"EMPTY", (*this)[L"EMPTY"]);
150 else {
151// if (__bNoAsc)
152// nNo = nOffset;
153
154 TextTemplate& ROW = (*this)[L"ROW"];
155 do {
156 ROW.assign(q.fields(), L"&nbsp;");
157 ROW.assign(L"VNO", VNO());
158 append(L"ROW", ROW);
159 q.fetch();
160 } while(!q.eof());
161
162 TextTemplate* pPART_LINK = atP(L"PART_LINK");
163 if (pPART_LINK && nTotalPart > 1) {
164 PartLink pl(pPART_LINK, strThisPage, String());
165 pl.assign(this, nTotalPart, nCurrentPart, __nParts);
166 }
167 }
168
169 HtmlView::onPrint(session);
170}
171
172__DCL_END_NAMESPACE
#define __THIS_FILE__
Definition _trace.h:14
wchar_t char_t
Definition Config.h:247
#define __DCL_THROWS1(e)
Definition Config.h:152
#define IMPLEMENT_CLASSINFO_EX(class_name, base_class_name)
Definition HtmlView.h:37
#define __DCL_VERIFY(expr)
Definition Object.h:396
#define __T(str)
Definition Object.h:60
virtual void onPrint(Session &session) __DCL_THROWS1(Exception *)
Definition HtmlView.cpp:349
virtual void init(SQLFields &fields) __DCL_THROWS1(Exception *)
Definition HtmlView.cpp:298
static int parse(const wchar_t *_number, unsigned _base=10) __DCL_THROWS1(NumericConvertException *)
Definition Numeric.inl:36
virtual String toString() const
Definition Object.cpp:187
_CONST SQLFields & fields() _CONST
Definition SQL.inl:101
void execute() __DCL_THROWS1(SQLException *)
Definition SQLQuery.cpp:316
bool eof() const
Definition SQL.inl:91
void fetch() __DCL_THROWS1(SQLException *)
Definition SQLQuery.cpp:336
static ByteString encode(const ByteString &_str)
Definition URI.cpp:82