DCL 3.7.4
Loading...
Searching...
No Matches
PageWriteForm Class Reference

#include <Page.h>

Inheritance diagram for PageWriteForm:
FormView HtmlView TextTemplate Object

Public Member Functions

 PageWriteForm (HtmlPage *pPage)
virtual void init (SQLFields &fields) __DCL_THROWS1(Exception *)
virtual void onPrint (Session &session) __DCL_THROWS1(Exception *)
virtual void onPost (Session &session) __DCL_THROWS1(Exception *)
Public Member Functions inherited from HtmlView
const HtmlPagepage () const
String SELF () const
String VNO () const
virtual void onGet (Session &session) __DCL_THROWS1(Exception *)
Public Member Functions inherited from Object
virtual String toString () const
virtual void destroy ()
String className () const
bool isInstanceOf (const std::type_info &typeinfo) const
virtual const std::type_info & typeInfo () const

Additional Inherited Members

Static Public Member Functions inherited from HtmlView
static HtmlViewcreateObject (HtmlPage *pPage, int nClassID, int nIndex)
Protected Member Functions inherited from HtmlView
 HtmlView (HtmlPage *pPage)
Protected Member Functions inherited from TextTemplate
virtual String onSQLFieldValue (_CONST SQLField &_field, const String &_fieldIsNullValue)
void parseHelper (const char_t *_begin, const char_t *_end)
void parse (const char_t *_begin, const char_t *_end)
int append (const char_t *_name, const String &_value, bool _clearExists)
int append (const char_t *_name, const TextTemplate &_template, bool _clearExists)
int append (const StringStringArray &_nameToValues, bool _clearExists)
int append (_CONST SQLFields &_fields, const String &_fieldIsNullValue, bool _clearExists)
Protected Member Functions inherited from Object
virtual ~Object ()
 Object ()
Static Protected Member Functions inherited from HtmlView
static size_t split (const String &str, StringStringArray &v)
static void dump (Session &session)
static String getDefault (ListedStringToStringArrayMap &map, const String &strKey)
static size_t getShortString (SQLField &field, size_t _len, String &strLong, String &strShort)
Protected Attributes inherited from HtmlView
HtmlPage__pPage
int __nIndex
int __nClassID
StringToStringMap __mapParams
Protected Attributes inherited from TextTemplate
void * __textList
void * __subTemplateMap

Detailed Description

Definition at line 54 of file Page.h.

Constructor & Destructor Documentation

◆ PageWriteForm()

PageWriteForm::PageWriteForm ( HtmlPage * pPage)

Member Function Documentation

◆ init()

void PageWriteForm::init ( SQLFields & fields)
virtual

Reimplemented from HtmlView.

Definition at line 344 of file Page.cpp.

346{
347 FormView::init(fields);
348
349 __mapParams.lookup(L"DETAIL", __strDetailPage);
350 __mapParams.lookup(L"LIST", __strListPage);
351}
StringToStringMap __mapParams
Definition HtmlView.h:112
virtual void init(SQLFields &fields) __DCL_THROWS1(Exception *)
Definition HtmlView.cpp:298

◆ onPost()

void PageWriteForm::onPost ( Session & session)
virtual

Reimplemented from FormView.

Definition at line 458 of file Page.cpp.

460{
461// dump(session);
462// return;
463
464 ListedStringToStringArrayMap& mapQuery = session.__ctx.__queryMap;
465 ListedStringToStringArrayMap& mapForm = session.__ctx.__formMap;
466
467 int nOldPageID = Integer::parse(
468 getDefault(mapQuery, L"_page"),
469 10,
470 -1
471 );
472 int nPageID = Integer::parse(
473 getDefault(mapForm, L"PAGE_ID"),
474 10,
475 -1
476 );
477 int nCategoryID = Integer::parse(getDefault(mapForm, L"CATEGORY_ID"), 10, 0);
478 int nPermID = Integer::parse(getDefault(mapForm, L"PERM_ID"), 10, 1);
479 String strType = getDefault(mapForm, L"TYPE");
480 String strCharset = getDefault(mapForm, L"CHARSET");
481 String strLanguage = getDefault(mapForm, L"LANGUAGE");
482 String strTitle = getDefault(mapForm, L"TITLE");
483 String strDesc = getDefault(mapForm, L"COMMENT");
484
485 if (strType.isEmpty())
486 strType = L"text/html";
487
488 if (nPageID <= 0 ) {
489 // data error
490 return;
491 }
492
493 int nCM = CM_INSERT;
494 if (nOldPageID > 0)
495 nCM = CM_UPDATE;
496
497 SQLQuery& q = session.__query;
498 if (nCM == CM_INSERT) {
499 // insert
500 q.prepare(L""
501 "INSERT INTO DCL_PAGE (PAGE_ID, PERM_ID, CATEGORY_ID,"
502 " TYPE, CHARSET, LANGUAGE, TITLE,"
503 " COMMENT, UPDATE_TIME)\n"
504 "\n VALUES (:PAGE_ID, :PERM_ID, :CATEGORY_ID,"
505 " :TYPE, :CHARSET, :LANGUAGE, :TITLE,"
506 " :COMMENT, CURRENT_TIMESTAMP)"
507 );
508 }
509 else {
510 q.execute(L""
511 "DELETE FROM DCL_VIEW WHERE PAGE_ID = " + String::valueOf(nOldPageID)
512 );
513
514 q.prepare(L""
515 "UPDATE DCL_PAGE SET "
516 "\n PAGE_ID = :PAGE_ID,"
517 " PERM_ID = :PERM_ID,"
518 " CATEGORY_ID = :CATEGORY_ID,"
519 " TYPE = :TYPE, CHARSET = :CHARSET,"
520 " LANGUAGE = :LANGUAGE, TITLE = :TITLE,"
521 " COMMENT = :COMMENT,"
522 " UPDATE_TIME = CURRENT_TIMESTAMP"
523 "\n WHERE PAGE_ID = :OLD_PAGE_ID"
524 );
525 }
526
527 SQLParams& params = q.params();
528 params.byName(L"PAGE_ID").setValue(nPageID);
529 params.byName(L"PERM_ID").setValue(nPermID);
530 params.byName(L"CATEGORY_ID").setValue(nCategoryID);
531 params.byName(L"TYPE").setValue(strType);
532 if (strCharset.isEmpty())
533 params.byName(L"CHARSET").setNull();
534 else
535 params.byName(L"CHARSET").setValue(strCharset);
536
537 if (strLanguage.isEmpty())
538 params.byName(L"LANGUAGE").setNull();
539 else
540 params.byName(L"LANGUAGE").setValue(strLanguage);
541
542 if (strTitle.isEmpty())
543 params.byName(L"TITLE").setNull();
544 else
545 params.byName(L"TITLE").setValue(strTitle);
546
547 if (strDesc.isEmpty())
548 params.byName(L"COMMENT").setNull();
549 else
550 params.byName(L"COMMENT").setValue(strDesc);
551
552 if (nCM == CM_UPDATE)
553 params.byName(L"OLD_PAGE_ID").setValue(nOldPageID);
554
555 q.execute();
556
557 /*
558 try {
559 q.execute();
560 }
561 catch(SQLException* e) {
562 // insert 때 중복값이 발생하거나... 또는, ..
563 e->destroy();
564 return false;
565 }
566 */
567
568 StringArray& vCLASS = mapForm[L"CLASS_ID"];
569 StringArray& vUSER = mapForm[L"USER_ID"];
570 StringArray& vDS = mapForm[L"DS_ID"];
571 StringArray& vSKIN = mapForm[L"SKIN_FILE"];
572 StringArray& vPARAMS = mapForm[L"PARAMETERS"];
573
574 q.prepare(L""
575 "INSERT INTO DCL_VIEW "
576 "\n VALUES(:PAGE_ID, :NO, :CLASS_ID, :USER_ID, :DS_ID, :SKIN_FILE, :PARAMETERS)"
577 );
578 for(size_t i = 0; i < vCLASS.size(); i++) {
579 int nClassID = Integer::parse(vCLASS[i], 10, -1);
580 if (nClassID < 0) {
581 // error
582 break;
583 }
584 q.params().byName(L"PAGE_ID").setValue(nPageID);
585 q.params().byName(L"NO").setValue((int)(i + 1));
586 q.params().byName(L"CLASS_ID").setValue(nClassID);
587 q.params().byName(L"USER_ID").setValue(Integer::parse(vUSER[i], 10, -1));
588 q.params().byName(L"DS_ID").setValue(Integer::parse(vDS[i], 10, -1));
589 if (vSKIN[i].isEmpty())
590 q.params().byName(L"SKIN_FILE").setNull();
591 else
592 q.params().byName(L"SKIN_FILE").setValue(vSKIN[i]);
593
594 if (vPARAMS[i].isEmpty())
595 q.params().byName(L"PARAMETERS").setNull();
596 else
597 q.params().byName(L"PARAMETERS").setValue(vPARAMS[i]);
598
599 q.execute();
600 }
601
602 StringBuilder strNext = getDefault(mapQuery, L"next");
603 if (strNext.isEmpty()) {
604 strNext = __strDetailPage;
605 strNext += L"&_page=" + String::valueOf(nPageID);
606 }
607
608 String strListPage = getDefault(mapQuery, L"list");
609 if (!strListPage.isEmpty())
610 strNext += L"&list=" + URLEncoder::encode(strListPage);
611
612 __pPage->refresh(session, L"?page=" + strNext.toString());
613}
#define CM_UPDATE
#define CM_INSERT
static String getDefault(ListedStringToStringArrayMap &map, const String &strKey)
Definition HtmlView.cpp:256
HtmlPage * __pPage
Definition HtmlView.h:108
static int parse(const wchar_t *_number, unsigned _base=10) __DCL_THROWS1(NumericConvertException *)
Definition Numeric.inl:36
SQLParam & byName(const wchar_t *_name) _CONST __DCL_THROWS1(InvalidIndexException *)
Definition SQLQuery.cpp:157
void prepare(const String &_sql) __DCL_THROWS1(SQLException *)
Definition SQLQuery.cpp:282
_CONST SQLParams & params() _CONST
Definition SQL.inl:106
void execute() __DCL_THROWS1(SQLException *)
Definition SQLQuery.cpp:316
HttpServletContextEx & __ctx
Definition Session.h:41
SQLQuery & __query
Definition Session.h:42
static ByteString encode(const ByteString &_str)
Definition URI.cpp:82

◆ onPrint()

void PageWriteForm::onPrint ( Session & session)
virtual

Reimplemented from FormView.

Definition at line 353 of file Page.cpp.

355{
356 SQLQuery& q = session.__query;
357
358 TextTemplate& CATEGORY = (*this)[L"CATEGORY"];
359 q.execute(L""
360 "SELECT CATEGORY_ID, CATEGORY_NAME FROM DCL_PAGE_CATEGORY"
361 "\n ORDER BY CATEGORY_ID"
362 );
363 q.fetch();
364 while(!q.eof()) {
365 CATEGORY.assign(q.fields(), L"");
366 append(L"CATEGORY", CATEGORY);
367 q.fetch();
368 }
369
370 TextTemplate& ROLE = (*this)[L"ROLE"];
371 q.execute(L""
372 "SELECT ROLE_ID, ROLE_NAME FROM DCL_ROLE"
373 "\n WHERE ROLE_ID > 0"
374 "\n ORDER BY ROLE_ID"
375 );
376 q.fetch();
377 while(!q.eof()) {
378 ROLE.assign(q.fields(), L"");
379 append(L"ROLE", ROLE);
380 q.fetch();
381 }
382
383 ListedStringToStringArrayMap& mapQuery = session.__ctx.__queryMap;
384
385 String strListPage = getDefault(mapQuery, L"list");
386 if (!strListPage.isEmpty()) {
387 String strListPageEnc = URLEncoder::encode(strListPage);
388 assign(L"_LIST", strListPageEnc);
389 }
390 else
391 strListPage = __strListPage;
392
393 assign(L"LIST", strListPage);
394
395 String strPageID = getDefault(mapQuery, L"_page");
396 if (strPageID.isEmpty())
397 strPageID = L"-1";
398
399 q.execute(L""
400 "SELECT * FROM DCL_PAGE WHERE PAGE_ID = " + strPageID
401 );
402 q.fetch();
403 if (q.eof()) {
404 // insert NEW
405 q.execute(L"SELECT MAX(PAGE_ID) AS PAGE_ID FROM DCL_PAGE");
406 q.fetch();
407 if (q.eof() || q.fields()[0].isNull())
408 strPageID = L"1";
409 else {
410 int nPageID = q.fields()[0].asInteger();
411 if (nPageID < 201)
412 nPageID = 201;
413 else
414 nPageID++;
415
416 strPageID = String::valueOf(nPageID);
417 }
418 assign(L"PAGE_ID", strPageID);
419 }
420 else {
421 // modify
422 assign(q.fields(), L"");
423 assign(L"ACTION", L"&_page=" + strPageID);
424
425 q.execute(L""
426 "SELECT V.NO, V.CLASS_ID, V.USER_ID, V.DS_ID, V.SKIN_FILE"
427 ", V.PARAMETERS, D.DS_TYPE, D.DS_NAME"
428 "\n FROM DCL_VIEW AS V"
429 "\n INNER JOIN DCL_DATA_SOURCE AS D"
430 "\n ON(V.USER_ID = D.USER_ID AND V.DS_ID = D.DS_ID)"
431 "\n WHERE V.PAGE_ID = " + strPageID + L""
432 "\n ORDER BY V.NO"
433 );
434 q.fetch();
435 TextTemplate& VIEW = (*this)[L"VIEW"];
436 while(!q.eof()) {
437 VIEW.assign(q.fields(), L"");
438 const HtmlView::CLASS_INFO* pInfo =
439 HtmlView::getClassInfo(q.fields().byName(L"CLASS_ID").asInteger());
440 if (pInfo) {
441 VIEW.assign(L"CLASS_NAME", pInfo->className());
442 VIEW.assign(L"CLASS_DS_TYPE", String::valueOf(pInfo->nDsType));
443 }
444 else {
445 VIEW.assign(L"CLASS_NAME", L"Invalid ClassID");
446 VIEW.assign(L"CLASS_DS_TYPE", L"0");
447 }
448
449 VIEW.assign(L"VNO", VNO());
450 append(L"VIEW", VIEW);
451 q.fetch();
452 }
453 }
454
455 FormView::onPrint(session);
456}
String VNO() const
Definition HtmlView.cpp:293
_CONST SQLField & byName(const wchar_t *_name) _CONST __DCL_THROWS1(InvalidIndexException *)
Definition SQLQuery.cpp:77
_CONST SQLFields & fields() _CONST
Definition SQL.inl:101
bool eof() const
Definition SQL.inl:91
void fetch() __DCL_THROWS1(SQLException *)
Definition SQLQuery.cpp:336

The documentation for this class was generated from the following files: