3b55f5017538ffd4ac11114954a70a0cb5eea2d8.svn-base 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. namespace IControls_FireManager
  10. {
  11. public partial class Form_System_UserEdit : Form
  12. {
  13. // GridEx 컬럼값
  14. string[] ColumnNames_Headers = _Convert.String_to_ArrayString(_Text.UI_USER_LIST_COLUMNNAME);
  15. // 대화 팝업용 (모두 삭제 여부)
  16. Form DialogPopup_User_AllDelete = new Form();
  17. // 대화 팝업용 (삭제 여부)
  18. Form DialogPopup_User_Delete = new Form();
  19. // 대화 팝업용 (저장 여부)
  20. Form DialogPopup_User_Save = new Form();
  21. // 선택한 사용자
  22. string gridEX_Selected_User_ID = null;
  23. public Form_System_UserEdit()
  24. {
  25. ///
  26. /// 초기화
  27. ///
  28. InitializeComponent();
  29. Initialize_Defalut(false);
  30. ///
  31. /// DB 열기
  32. ///
  33. GET_DB_USER_INFO();
  34. ///
  35. /// 이벤트
  36. ///
  37. // 폼닫기 이벤트를 등록 (이벤트 핸들러 해제용)
  38. this.FormClosing += new FormClosingEventHandler(CreateForm_FormClosing);
  39. // 윈도우 스타일 변경 이벤트 핸들러 등록
  40. _Event.WindowStyleSet_SendMessage_Event += new _Event.WindowStyleSet_SendMessage_Handler(_Event_WindowStyleSet_SendMessage_Event);
  41. ///
  42. /// UI 셋팅
  43. ///
  44. UI_GridEx_Initialize();
  45. ///
  46. /// 스타일 변경
  47. ///
  48. UI_Style_Initialize();
  49. }
  50. // 윈도우 스타일 변경 이벤트
  51. public void _Event_WindowStyleSet_SendMessage_Event()
  52. {
  53. UI_Style_Initialize();
  54. }
  55. // 스타일 초기화 함수
  56. private void UI_Style_Initialize()
  57. {
  58. this.uiGroupBox.VisualStyle = _Data.Style_PanelVisualStyle;
  59. this.uiButton_New.VisualStyle = _Data.Style_VisualStyle;
  60. this.GridEx_UserList.VisualStyle = _Style.Get_GridEXVisualStyle(_Data.Style_VisualStyle.ToString());
  61. this.editBox_ID.VisualStyle = _Style.Get_GridEXVisualStyle(_Data.Style_VisualStyle.ToString());
  62. this.editBox_PW.VisualStyle = _Style.Get_GridEXVisualStyle(_Data.Style_VisualStyle.ToString());
  63. this.editBox_RePW.VisualStyle = _Style.Get_GridEXVisualStyle(_Data.Style_VisualStyle.ToString());
  64. this.editBox_Name.VisualStyle = _Style.Get_GridEXVisualStyle(_Data.Style_VisualStyle.ToString());
  65. this.editBox_CompanyName.VisualStyle = _Style.Get_GridEXVisualStyle(_Data.Style_VisualStyle.ToString());
  66. this.editBox_CompanyPosition.VisualStyle = _Style.Get_GridEXVisualStyle(_Data.Style_VisualStyle.ToString());
  67. this.editBox_Phone.VisualStyle = _Style.Get_GridEXVisualStyle(_Data.Style_VisualStyle.ToString());
  68. this.uiButton_Save.VisualStyle = _Data.Style_VisualStyle;
  69. this.UiButton_SameIdChk.VisualStyle = _Data.Style_VisualStyle;
  70. }
  71. // 폼닫기 이벤트를 등록 (이벤트 핸들러 해제용)
  72. public void CreateForm_FormClosing(object sender, FormClosingEventArgs e)
  73. {
  74. // 윈도우 스타일 변경 이벤트 핸들러 해제
  75. _Event.WindowStyleSet_SendMessage_Event -= new _Event.WindowStyleSet_SendMessage_Handler(_Event_WindowStyleSet_SendMessage_Event);
  76. }
  77. // 기본값 초기화
  78. public void Initialize_Defalut(bool Enable)
  79. {
  80. // 중복 체크를 누르기 전까지는 모두 비활성화
  81. this.editBox_ID.Enabled = !Enable;
  82. this.UiButton_SameIdChk.Enabled = !Enable;
  83. this.editBox_PW.Enabled = Enable;
  84. this.editBox_RePW.Enabled = Enable;
  85. this.editBox_Name.Enabled = Enable;
  86. this.editBox_CompanyName.Enabled = Enable;
  87. this.editBox_CompanyPosition.Enabled = Enable;
  88. this.editBox_Phone.Enabled = Enable;
  89. this.uiButton_Save.Enabled = Enable;
  90. }
  91. public void UI_EditBox_Clear()
  92. {
  93. // 중복 체크를 누르기 전까지는 모두 비활성화
  94. this.editBox_ID.Text = null;
  95. this.editBox_PW.Text = null;
  96. this.editBox_RePW.Text = null;
  97. this.editBox_Name.Text = null;
  98. this.editBox_CompanyName.Text = null;
  99. this.editBox_CompanyPosition.Text = null;
  100. this.editBox_Phone.Text = null;
  101. }
  102. // 데이타베이스에서 USER 정보 가져오기 (DEVICE CONFIG 혹은 CARD REG 용인지 내부에서 구분해서 리스트 생성됨)
  103. public static bool GET_DB_USER_INFO()
  104. {
  105. try
  106. {
  107. // 초기화
  108. _Data.HASH_USER.Clear();
  109. _Data.LIST_USER_KEY.Clear();
  110. ///
  111. /// DB -> 해쉬에 저장
  112. ///
  113. DataRowCollection DB_TABLE_USER = null;
  114. DB_TABLE_USER = _Db.ExecuteRead_SqlDataAdapter(_Sql.SearchAll_Table_Value("TB_USERS", null));
  115. if (DB_TABLE_USER != null)
  116. {
  117. foreach (DataRow dr in DB_TABLE_USER)
  118. {
  119. _USER USER = new _USER();
  120. USER.USER_NO = dr["USER_NO"].ToString();
  121. USER.USER_NAME = dr["USER_NAME"].ToString();
  122. USER.USER_ID = dr["USER_ID"].ToString();
  123. USER.USER_PW = dr["USER_PW"].ToString();
  124. USER.USER_COMPANY = dr["USER_COMPANY"].ToString();
  125. USER.USER_POSITION = dr["USER_POSITION"].ToString();
  126. USER.USER_PHONE = dr["USER_PHONE"].ToString();
  127. // 해쉬에 추가 (키값은 항상 String 으로 접근)
  128. if (_Hash.Add(_Data.HASH_USER, USER.USER_ID, USER) == true)
  129. {
  130. // 키리스트에 추가
  131. _Data.LIST_USER_KEY.Add(USER.USER_ID);
  132. }
  133. }
  134. }
  135. return true;
  136. }
  137. catch (Exception e)
  138. {
  139. // LOG
  140. _Event.DebugView_SendMessage_Write(e.ToString());
  141. return false;
  142. }
  143. }
  144. // 사용자 정보 리스트 초기화
  145. public void UI_GridEx_Initialize()
  146. {
  147. // 초기화
  148. this.GridEx_UserList.ClearItems();
  149. int i = 0;
  150. foreach (string USER_KEY in _Data.LIST_USER_KEY)
  151. {
  152. // 접근하려는 USER 정보 추출
  153. _USER USER = ((_USER)_Data.HASH_USER[USER_KEY]);
  154. // 기본 출력될 컬럼
  155. string GridexAddItem = null;
  156. // 생성된 컬럼명에 맞게 데이타를 추가한다
  157. GridexAddItem =
  158. // NO
  159. ColumnNames_Headers[0] + _Text.Equal + (++i).ToString() + _Text.SemiColon +
  160. // ID
  161. ColumnNames_Headers[1] + _Text.Equal + USER.USER_ID + _Text.SemiColon +
  162. // PW
  163. ColumnNames_Headers[2] + _Text.Equal + USER.USER_PW + _Text.SemiColon +
  164. // Name
  165. ColumnNames_Headers[3] + _Text.Equal + USER.USER_NAME + _Text.SemiColon +
  166. // Company_Name
  167. ColumnNames_Headers[4] + _Text.Equal + USER.USER_COMPANY + _Text.SemiColon +
  168. // Company_Positon
  169. ColumnNames_Headers[5] + _Text.Equal + USER.USER_POSITION + _Text.SemiColon +
  170. // Phone
  171. ColumnNames_Headers[6] + _Text.Equal + USER.USER_PHONE;
  172. // 컬럼추가
  173. _Gridex.Column_Data_Add(this.GridEx_UserList, false, GridexAddItem);
  174. }
  175. }
  176. // 중복체크 버튼 누름
  177. private void UiButton_SameIdChk_Click(object sender, EventArgs e)
  178. {
  179. // 자동으로 공백처리
  180. this.editBox_ID.Text = this.editBox_ID.Text.Trim();
  181. // 예외처리
  182. string TempError = _Error.Data_Confirm_NotDefineString(this.editBox_ID.Text);
  183. if (TempError != null)
  184. {
  185. // 입력부 비활성화
  186. Initialize_Defalut(false);
  187. // 경고 문구
  188. _Popup.Create(Popup_Type.Confirm, Popup_Style.Normal, _Text.OK, 250, 150, TempError, 0); // 에러 문구
  189. }
  190. // 그룹명을 지정해야만 한다
  191. else if (this.editBox_ID.Text == null || this.editBox_ID.Text.Trim().Length == 0)
  192. {
  193. // 입력부 비활성화
  194. Initialize_Defalut(false);
  195. // 경고 문구
  196. _Popup.Create(Popup_Type.Confirm, Popup_Style.Normal, _Text.OK, 250, 150, _Text.NameNotInput, 0); // 이름을 입력해 주세요
  197. }
  198. // 현재 등록하려는 아이디가 포함되는지 알아본다
  199. else if (_Data.LIST_USER_KEY.Contains(this.editBox_ID.Text) == true)
  200. {
  201. // 입력부 비활성화
  202. Initialize_Defalut(false);
  203. // 경고 문구
  204. _Popup.Create(Popup_Type.Confirm, Popup_Style.Normal, _Text.OK, 400, 150, _Text.UserIDUsingFail, 0);
  205. }
  206. else
  207. {
  208. // 입력부 활성화
  209. Initialize_Defalut(true);
  210. // 확인 문구
  211. _Popup.Create(Popup_Type.Confirm, Popup_Style.Normal, _Text.OK, 400, 150, _Text.UserIDUsingSuccess, 0);
  212. }
  213. }
  214. // 저장버튼 누름
  215. private void uiButton_Save_Click(object sender, EventArgs e)
  216. {
  217. // 패스워드 정보 체크
  218. if (this.editBox_PW.Text != this.editBox_RePW.Text || this.editBox_PW.Text == null || this.editBox_PW.Text.Trim().Length == 0)
  219. {
  220. _Popup.Create(Popup_Type.Confirm, Popup_Style.Normal, _Text.OK, 250, 150, _Text.UserPWUsingFail, 0);
  221. return;
  222. }
  223. // 모든 입력 체크
  224. if (this.editBox_Name.Text == null || this.editBox_Name.Text.Trim().Length == 0
  225. || this.editBox_CompanyName.Text == null || this.editBox_CompanyName.Text.Trim().Length == 0
  226. || this.editBox_Phone.Text == null || this.editBox_Phone.Text.Trim().Length == 0
  227. || this.editBox_CompanyPosition.Text == null || this.editBox_CompanyPosition.Text.Trim().Length == 0
  228. )
  229. {
  230. _Popup.Create(Popup_Type.Confirm, Popup_Style.Normal, _Text.OK, 250, 150, _Text.UserInfoNot, 0);
  231. return;
  232. }
  233. // 사용자 저장합니다. 진행하시겠습니까?
  234. DialogPopup_User_Save = _PopupDialog.Create(Popup_Type.Dialog, Popup_Style.Normal, _Text.OK, 450, 150, _Text.UserSave_Continue, _Event_DialogPopup_User_Save_SendMessage_Event);
  235. }
  236. // 리스트에서 아이템 마우스 클릭
  237. private void GridEx_UserList_MouseClick(object sender, MouseEventArgs e)
  238. {
  239. // 선택한 아이템이 없으면
  240. if (this.GridEx_UserList.CurrentRow == null ||
  241. this.GridEx_UserList.CurrentRow.Cells["ID"] == null ||
  242. this.GridEx_UserList.CurrentRow.Cells["ID"].Value == null)
  243. return;
  244. // 오른쪽 마우스를 선택할 경우
  245. if (e.Button == System.Windows.Forms.MouseButtons.Right)
  246. {
  247. //if (this.GridEx_UserList.CurrentRow.Cells["ID"].Value.ToString() != _Data.Super_User_ID)
  248. {
  249. _Contextmenustrip.Create(this.GridEx_UserList, e.Location,
  250. _Text.Delete + ";" +
  251. _Text.ContextStripSeparator + ";" +
  252. _Text.AllDelete,
  253. Selected_Menustrip_ItemClicked);
  254. }
  255. }
  256. // 선택한 그룹이름을 저장한다
  257. gridEX_Selected_User_ID = this.GridEx_UserList.CurrentRow.Cells["ID"].Value.ToString();
  258. // UI 표시
  259. this.editBox_ID.Text = ((_USER)_Data.HASH_USER[gridEX_Selected_User_ID]).USER_ID;
  260. this.editBox_PW.Text = ((_USER)_Data.HASH_USER[gridEX_Selected_User_ID]).USER_PW;
  261. this.editBox_RePW.Text = ((_USER)_Data.HASH_USER[gridEX_Selected_User_ID]).USER_PW;
  262. this.editBox_Name.Text = ((_USER)_Data.HASH_USER[gridEX_Selected_User_ID]).USER_NAME;
  263. this.editBox_CompanyName.Text = ((_USER)_Data.HASH_USER[gridEX_Selected_User_ID]).USER_COMPANY;
  264. this.editBox_CompanyPosition.Text = ((_USER)_Data.HASH_USER[gridEX_Selected_User_ID]).USER_POSITION;
  265. this.editBox_Phone.Text = ((_USER)_Data.HASH_USER[gridEX_Selected_User_ID]).USER_PHONE;
  266. Initialize_Defalut(true);
  267. }
  268. ///
  269. /// 팝업 메뉴 선택
  270. ///
  271. public void Selected_Menustrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  272. {
  273. // 리스트에서 팝업창 메뉴중 전체 삭제를 선택
  274. if (e.ClickedItem.Text == _Text.AllDelete)
  275. {
  276. // 시스템 사용자 모두 삭제됩니다. 계속 진행하시겠습니까?"
  277. DialogPopup_User_AllDelete = _PopupDialog.Create(Popup_Type.Dialog, Popup_Style.Normal, _Text.OK, 450, 150, _Text.UserAllDelete_Continue, _Event_DialogPopup_User_AllDelete_SendMessage_Event);
  278. }
  279. // 리스트에서 팝업창 메뉴중 삭제를 선택
  280. else if (e.ClickedItem.Text == _Text.Delete)
  281. {
  282. // 시스템 사용자 삭제됩니다. 계속 진행하시겠습니까?"
  283. DialogPopup_User_Delete = _PopupDialog.Create(Popup_Type.Dialog, Popup_Style.Normal, _Text.OK, 450, 150, _Text.UserDelete_Continue, _Event_DialogPopup_User_Delete_SendMessage_Event);
  284. }
  285. }
  286. // 전체 삭제 여부
  287. public void _Event_DialogPopup_User_AllDelete_SendMessage_Event(object sender, object etc)
  288. {
  289. // 대화 팝업 주체
  290. Form popup = (Form)sender;
  291. if (DialogPopup_User_AllDelete.Name == popup.Name && etc.ToString() == _Text.OK)
  292. {
  293. // DB 삭제
  294. _Db.Execute("DELETE FROM TB_USERS");
  295. // DB 로 부터 해쉬 테이블 및 리스트 정리
  296. GET_DB_USER_INFO();
  297. // 선택한 아이디를 초기화
  298. gridEX_Selected_User_ID = null;
  299. // UI 초기화
  300. Initialize_Defalut(false);
  301. UI_EditBox_Clear();
  302. // UI 갱신
  303. UI_GridEx_Initialize();
  304. }
  305. }
  306. // 삭제 여부
  307. public void _Event_DialogPopup_User_Delete_SendMessage_Event(object sender, object etc)
  308. {
  309. // 대화 팝업 주체
  310. Form popup = (Form)sender;
  311. if (DialogPopup_User_Delete.Name == popup.Name && etc.ToString() == _Text.OK)
  312. {
  313. // DB 삭제
  314. string sql = string.Format("DELETE FROM TB_USERS WHERE USER_ID = '{0}'", gridEX_Selected_User_ID);
  315. _Db.Execute(sql);
  316. // DB 로 부터 해쉬 테이블 및 리스트 정리
  317. GET_DB_USER_INFO();
  318. // 선택한 아이디를 초기화
  319. gridEX_Selected_User_ID = null;
  320. // UI 초기화
  321. Initialize_Defalut(false);
  322. UI_EditBox_Clear();
  323. // UI 갱신
  324. UI_GridEx_Initialize();
  325. }
  326. }
  327. // 저장 여부
  328. public void _Event_DialogPopup_User_Save_SendMessage_Event(object sender, object etc)
  329. {
  330. // 대화 팝업 주체
  331. Form popup = (Form)sender;
  332. if (DialogPopup_User_Save.Name == popup.Name && etc.ToString() == _Text.OK)
  333. {
  334. // 데이타 저장하자
  335. _USER USER = new _USER();
  336. USER.USER_ID = this.editBox_ID.Text;
  337. USER.USER_PW = this.editBox_PW.Text;
  338. USER.USER_NAME = this.editBox_Name.Text;
  339. USER.USER_COMPANY = this.editBox_CompanyName.Text;
  340. USER.USER_POSITION = this.editBox_CompanyPosition.Text;
  341. USER.USER_PHONE = this.editBox_Phone.Text;
  342. // 새로 추가인지 편집인지 구분해서 루틴을 타도록 한다
  343. if (_Data.LIST_USER_KEY.Contains(USER.USER_ID) == false)
  344. {
  345. // 해쉬에 추가
  346. if (_Hash.Add(_Data.HASH_USER, USER.USER_ID, USER) == true)
  347. {
  348. // 키리스트에 추가
  349. _Data.LIST_USER_KEY.Add(USER.USER_ID);
  350. }
  351. // UI 표시
  352. UI_GridEx_Initialize();
  353. // DB 저장
  354. string sql = string.Format("insert into TB_USERS(USER_NO,USER_ID,USER_PW,USER_NAME,USER_COMPANY,USER_POSITION,USER_PHONE,REG_TIME) values ({0},'{1}','{2}','{3}','{4}','{5}','{6}',current_timestamp)",
  355. _Data.LIST_USER_KEY.IndexOf(USER.USER_ID),
  356. USER.USER_ID,
  357. USER.USER_PW,
  358. USER.USER_NAME,
  359. USER.USER_COMPANY,
  360. USER.USER_POSITION,
  361. USER.USER_PHONE
  362. );
  363. _Db.Execute(sql);
  364. }
  365. // 편집
  366. else
  367. {
  368. // 해쉬에 내용 변경
  369. ((_USER)_Data.HASH_USER[USER.USER_ID]).USER_PW = USER.USER_PW;
  370. ((_USER)_Data.HASH_USER[USER.USER_ID]).USER_NAME = USER.USER_NAME;
  371. ((_USER)_Data.HASH_USER[USER.USER_ID]).USER_COMPANY = USER.USER_COMPANY;
  372. ((_USER)_Data.HASH_USER[USER.USER_ID]).USER_POSITION = USER.USER_POSITION;
  373. ((_USER)_Data.HASH_USER[USER.USER_ID]).USER_PHONE = USER.USER_PHONE;
  374. // UI 표시
  375. _Gridex.Column_Data_Edit(this.GridEx_UserList, ColumnNames_Headers[1] + _Text.Equal + USER.USER_ID,
  376. // PW
  377. ColumnNames_Headers[2] + _Text.Equal + USER.USER_PW + _Text.SemiColon +
  378. // Name
  379. ColumnNames_Headers[3] + _Text.Equal + USER.USER_NAME + _Text.SemiColon +
  380. // Company_Name
  381. ColumnNames_Headers[4] + _Text.Equal + USER.USER_COMPANY + _Text.SemiColon +
  382. // Company_Postion
  383. ColumnNames_Headers[5] + _Text.Equal + USER.USER_POSITION + _Text.SemiColon +
  384. // Phone
  385. ColumnNames_Headers[6] + _Text.Equal + USER.USER_PHONE);
  386. // DB 저장
  387. string sql = string.Format("update TB_USERS set USER_PW='{1}',USER_NAME='{2}',USER_PHONE='{3}',USER_COMPANY='{4}',USER_POSITION='{5}',REG_TIME=current_timestamp where USER_ID='{0}'",
  388. USER.USER_ID,
  389. USER.USER_PW,
  390. USER.USER_NAME,
  391. USER.USER_PHONE,
  392. USER.USER_COMPANY,
  393. USER.USER_POSITION);
  394. _Db.Execute(sql);
  395. }
  396. // 선택한 아이디 초기화
  397. gridEX_Selected_User_ID = null;
  398. // UI 초기화
  399. Initialize_Defalut(false);
  400. UI_EditBox_Clear();
  401. }
  402. // 팝업창 이벤트 처리 해제
  403. //_Event.PopupClose_SendMessage_Event -= new _Event.PopupClose_SendMessage_Handler(_Event_DialogPopup_User_Save_SendMessage_Event);
  404. }
  405. // 새로 만들기 버튼
  406. private void uiButton_New_Click(object sender, EventArgs e)
  407. {
  408. // 선택한 아이디 초기화
  409. gridEX_Selected_User_ID = null;
  410. // UI 초기화
  411. Initialize_Defalut(false);
  412. UI_EditBox_Clear();
  413. }
  414. }
  415. }