FrmSmsUserF.cpp 8.8 KB

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