FrmSmsUserF.cpp 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /****************************************************************************
  2. * @source :
  3. * @description :
  4. ****************************************************************************
  5. * DATE AUTHOR DESCRIPTION
  6. * --------------------------------------------------------------------------
  7. * 2011/12/24 정승호 최초작성
  8. *
  9. ****************************************************************************/
  10. //---------------------------------------------------------------------------
  11. #include <vcl.h>
  12. #include "ITSSkinF.h"
  13. #include "ITSUtilF.h"
  14. #include "ITSDbF.h"
  15. #include "AppGlobalF.h"
  16. #pragma hdrstop
  17. #include "FrmSmsUserF.h"
  18. //---------------------------------------------------------------------------
  19. #pragma package(smart_init)
  20. #pragma link "cxButtons"
  21. #pragma link "cxContainer"
  22. #pragma link "cxControls"
  23. #pragma link "cxEdit"
  24. #pragma link "cxGraphics"
  25. #pragma link "cxGroupBox"
  26. #pragma link "cxLookAndFeelPainters"
  27. #pragma link "cxLookAndFeels"
  28. #pragma link "dxSkinBlack"
  29. #pragma link "dxSkinBlue"
  30. #pragma link "dxSkinCaramel"
  31. #pragma link "dxSkinCoffee"
  32. #pragma link "dxSkinDarkRoom"
  33. #pragma link "dxSkinDarkSide"
  34. #pragma link "dxSkinFoggy"
  35. #pragma link "dxSkinGlassOceans"
  36. #pragma link "dxSkiniMaginary"
  37. #pragma link "dxSkinLilian"
  38. #pragma link "dxSkinLiquidSky"
  39. #pragma link "dxSkinLondonLiquidSky"
  40. #pragma link "dxSkinMcSkin"
  41. #pragma link "dxSkinMoneyTwins"
  42. #pragma link "dxSkinOffice2007Black"
  43. #pragma link "dxSkinOffice2007Blue"
  44. #pragma link "dxSkinOffice2007Green"
  45. #pragma link "dxSkinOffice2007Pink"
  46. #pragma link "dxSkinOffice2007Silver"
  47. #pragma link "dxSkinOffice2010Black"
  48. #pragma link "dxSkinOffice2010Blue"
  49. #pragma link "dxSkinOffice2010Silver"
  50. #pragma link "dxSkinsCore"
  51. #pragma link "dxSkinSeven"
  52. #pragma link "dxSkinSharp"
  53. #pragma link "dxSkinSilver"
  54. #pragma link "dxSkinStardust"
  55. #pragma link "FRAME_NodeListF"
  56. #pragma link "cxTextEdit"
  57. #pragma resource "*.dfm"
  58. TFrmSmsUser *FrmSmsUser = NULL;
  59. //---------------------------------------------------------------------------
  60. __fastcall TFrmSmsUser::TFrmSmsUser(TComponent* Owner)
  61. : TForm(Owner)
  62. {
  63. ITSSkin_Load(this);
  64. //CMM_LoadForm(g_sFormsDir, this);
  65. FUpdated = false;
  66. }
  67. //---------------------------------------------------------------------------
  68. /*
  69. * 닫기버튼 이나 x버튼 클릭시 공통으로 처리하는 로직이들어간다..
  70. * Form과 DataModule class를 delete시킨다.
  71. * arguments
  72. *
  73. * return
  74. * void
  75. */
  76. void __fastcall TFrmSmsUser::CommClose()
  77. {
  78. try
  79. {
  80. //CMM_SaveForm(g_sFormsDir, this);
  81. }
  82. catch(...)
  83. {
  84. }
  85. }
  86. //---------------------------------------------------------------------------
  87. /*
  88. * Form을 보여줄때 호출되는 event 메서드이다.
  89. * arguments
  90. * Sender : event handler 객체
  91. * return
  92. * void
  93. */
  94. void __fastcall TFrmSmsUser::FormShow(TObject *Sender)
  95. {
  96. Refresh();
  97. }
  98. //---------------------------------------------------------------------------
  99. /*
  100. * Close 버튼 클릭 이벤트 핸들러
  101. * arguments
  102. * Sender : event handler 객체
  103. * return
  104. * void
  105. */
  106. void __fastcall TFrmSmsUser::BtnCloseClick(TObject *Sender)
  107. {
  108. FUpdated = false;
  109. Close();
  110. }
  111. //---------------------------------------------------------------------------
  112. void __fastcall TFrmSmsUser::FormClose(TObject *Sender, TCloseAction &Action)
  113. {
  114. CommClose();
  115. FrmSmsUser = NULL;
  116. //Action = caFree;
  117. }
  118. //---------------------------------------------------------------------------
  119. bool __fastcall TFrmSmsUser::CheckField()
  120. {
  121. String sId = EdId->Text.Trim();
  122. String sName = EdName->Text.Trim();
  123. String sCallTel = EdCallTel->Text.Trim();
  124. String sBackTel = EdBackTel->Text.Trim();
  125. String sDesc = EdDesc->Text.Trim();
  126. if (sId == "")
  127. {
  128. Application->MessageBox(L"ID를 확인 하세요.", Caption.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
  129. return false;
  130. }
  131. if (sName == "")
  132. {
  133. Application->MessageBox(L"사용자명을 확인 하세요.", Caption.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
  134. return false;
  135. }
  136. if (sCallTel == "")
  137. {
  138. Application->MessageBox(L"전화번호를 확인 하세요.", Caption.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
  139. return false;
  140. }
  141. if (sBackTel == "")
  142. {
  143. Application->MessageBox(L"회신 전화번호를 확인 하세요.", Caption.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
  144. return false;
  145. }
  146. return true;
  147. }
  148. //---------------------------------------------------------------------------
  149. void __fastcall TFrmSmsUser::BtnSaveClick(TObject *Sender)
  150. {
  151. String sMsg;
  152. String sId = EdId->Text.Trim();
  153. String sName = EdName->Text.Trim();
  154. String sCallTel = EdCallTel->Text.Trim();
  155. String sBackTel = EdBackTel->Text.Trim();
  156. String sDesc = EdDesc->Text.Trim();
  157. String sRegDt = Now().FormatString("yyyymmddhhnnss");//EdRegDt->Text.Trim();
  158. EdRegDt->Text = sRegDt;
  159. if (!CheckField()) return;
  160. if (FDbMode == enJobSave)
  161. sMsg = "SMS 연락처 정보를 등록 하시겠습까?";
  162. else
  163. sMsg = "SMS 연락처 정보를 수정 하시겠습까?";
  164. if (Application->MessageBox(sMsg.c_str(), Caption.c_str(), MB_YESNO|MB_ICONQUESTION|MB_APPLMODAL) != IDYES) return;
  165. String sQry;
  166. TADOQuery *pADO = NULL;
  167. sQry = "MERGE INTO TB_SMS_USER L \r\n"
  168. "USING (SELECT :p01 AS SMS_USER_ID, \r\n"
  169. " :p02 AS SMS_USER_NM, \r\n"
  170. " :p03 AS SMS_USER_TEL, \r\n"
  171. " :p04 AS SMS_RPLY_TEL, \r\n"
  172. " :p05 AS SMS_USER_EXPL, \r\n"
  173. " :p06 AS RGST_DT \r\n"
  174. " FROM DUAL \r\n"
  175. " ) M \r\n"
  176. "ON (L.SMS_USER_ID = M.SMS_USER_ID) \r\n"
  177. "WHEN MATCHED THEN \r\n"
  178. " UPDATE SET L.SMS_USER_NM = M.SMS_USER_NM, \r\n"
  179. " L.SMS_USER_TEL = M.SMS_USER_TEL, \r\n"
  180. " L.SMS_RPLY_TEL = M.SMS_RPLY_TEL, \r\n"
  181. " L.SMS_USER_EXPL = M.SMS_USER_EXPL, \r\n"
  182. " L.RGST_DT = M.RGST_DT \r\n"
  183. "WHEN NOT MATCHED THEN \r\n"
  184. " INSERT (L.SMS_USER_ID, \r\n"
  185. " L.SMS_USER_NM, \r\n"
  186. " L.SMS_USER_TEL, \r\n"
  187. " L.SMS_RPLY_TEL, \r\n"
  188. " L.SMS_USER_EXPL, \r\n"
  189. " L.RGST_DT) \r\n"
  190. " VALUES (M.SMS_USER_ID, \r\n"
  191. " M.SMS_USER_NM, \r\n"
  192. " M.SMS_USER_TEL, \r\n"
  193. " M.SMS_RPLY_TEL, \r\n"
  194. " M.SMS_USER_EXPL, \r\n"
  195. " M.RGST_DT) \r\n";
  196. try
  197. {
  198. try
  199. {
  200. pADO = new TADOQuery(NULL);
  201. pADO->Close();
  202. pADO->Connection = ITSDb_GetConnection();
  203. ITSDb_SQLText(pADO, sQry);
  204. ITSDb_SQLBind(pADO, "p01", sId);
  205. ITSDb_SQLBind(pADO, "p02", sName);
  206. ITSDb_SQLBind(pADO, "p03", sCallTel);
  207. ITSDb_SQLBind(pADO, "p04", sBackTel);
  208. ITSDb_SQLBind(pADO, "p05", sDesc);
  209. ITSDb_SQLBind(pADO, "p06", sRegDt);
  210. EdRegDt->Text = sRegDt;
  211. ITSDb_GetConnection()->BeginTrans();
  212. ITSDb_SQLExec(pADO);
  213. ITSDb_GetConnection()->CommitTrans();
  214. }
  215. catch(EDatabaseError &E)
  216. {
  217. ITSDb_GetConnection()->RollbackTrans();
  218. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  219. ShowMessage(String(E.ClassName()) + E.Message);
  220. return;
  221. }
  222. catch(Exception &exception)
  223. {
  224. ITSDb_GetConnection()->RollbackTrans();
  225. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  226. ShowMessage(String(exception.ClassName()) + exception.Message);
  227. return;
  228. }
  229. catch(...)
  230. {
  231. ITSDb_GetConnection()->RollbackTrans();
  232. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  233. ShowMessage("데이터 저장 중에 알수없는 DB 오류가 발생하였습니다.");
  234. return;
  235. }
  236. }
  237. __finally
  238. {
  239. if (pADO)
  240. {
  241. pADO->Close();
  242. delete pADO;
  243. }
  244. }
  245. if (FDbMode == enJobSave)
  246. sMsg = "SMS 연락처 정보를 등록 하였습니다.";
  247. else
  248. sMsg = "SMS 연락처 정보를 수정 하였습니다.";
  249. Application->MessageBox(sMsg.c_str(), Caption.c_str(), MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
  250. FUpdated = true;
  251. Close();
  252. }
  253. //---------------------------------------------------------------------------
  254. void __fastcall TFrmSmsUser::EdCallTelKeyPress(TObject *Sender, wchar_t &Key)
  255. {
  256. if (Key > '9' || Key < '0')
  257. {
  258. if (Key != VK_BACK && Key != VK_TAB && Key != '-')
  259. Key = 0;
  260. }
  261. }
  262. //---------------------------------------------------------------------------