123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace IControls_FireManager
- {
- public partial class Form_System_UserEdit : Form
- {
- // GridEx 컬럼값
- string[] ColumnNames_Headers = _Convert.String_to_ArrayString(_Text.UI_USER_LIST_COLUMNNAME);
- // 대화 팝업용 (모두 삭제 여부)
- Form DialogPopup_User_AllDelete = new Form();
- // 대화 팝업용 (삭제 여부)
- Form DialogPopup_User_Delete = new Form();
- // 대화 팝업용 (저장 여부)
- Form DialogPopup_User_Save = new Form();
- // 선택한 사용자
- string gridEX_Selected_User_ID = null;
- public Form_System_UserEdit()
- {
- ///
- /// 초기화
- ///
- InitializeComponent();
- Initialize_Defalut(false);
- ///
- /// DB 열기
- ///
- GET_DB_USER_INFO();
-
- ///
- /// 이벤트
- ///
- // 폼닫기 이벤트를 등록 (이벤트 핸들러 해제용)
- this.FormClosing += new FormClosingEventHandler(CreateForm_FormClosing);
- // 윈도우 스타일 변경 이벤트 핸들러 등록
- _Event.WindowStyleSet_SendMessage_Event += new _Event.WindowStyleSet_SendMessage_Handler(_Event_WindowStyleSet_SendMessage_Event);
- ///
- /// UI 셋팅
- ///
- UI_GridEx_Initialize();
- ///
- /// 스타일 변경
- ///
- UI_Style_Initialize();
- }
-
- // 윈도우 스타일 변경 이벤트
- public void _Event_WindowStyleSet_SendMessage_Event()
- {
- UI_Style_Initialize();
- }
- // 스타일 초기화 함수
- private void UI_Style_Initialize()
- {
- this.uiGroupBox.VisualStyle = _Data.Style_PanelVisualStyle;
- this.uiButton_New.VisualStyle = _Data.Style_VisualStyle;
- this.GridEx_UserList.VisualStyle = _Style.Get_GridEXVisualStyle(_Data.Style_VisualStyle.ToString());
- this.editBox_ID.VisualStyle = _Style.Get_GridEXVisualStyle(_Data.Style_VisualStyle.ToString());
- this.editBox_PW.VisualStyle = _Style.Get_GridEXVisualStyle(_Data.Style_VisualStyle.ToString());
- this.editBox_RePW.VisualStyle = _Style.Get_GridEXVisualStyle(_Data.Style_VisualStyle.ToString());
- this.editBox_Name.VisualStyle = _Style.Get_GridEXVisualStyle(_Data.Style_VisualStyle.ToString());
- this.editBox_CompanyName.VisualStyle = _Style.Get_GridEXVisualStyle(_Data.Style_VisualStyle.ToString());
- this.editBox_CompanyPosition.VisualStyle = _Style.Get_GridEXVisualStyle(_Data.Style_VisualStyle.ToString());
- this.editBox_Phone.VisualStyle = _Style.Get_GridEXVisualStyle(_Data.Style_VisualStyle.ToString());
- this.uiButton_Save.VisualStyle = _Data.Style_VisualStyle;
- this.UiButton_SameIdChk.VisualStyle = _Data.Style_VisualStyle;
- }
- // 폼닫기 이벤트를 등록 (이벤트 핸들러 해제용)
- public void CreateForm_FormClosing(object sender, FormClosingEventArgs e)
- {
- // 윈도우 스타일 변경 이벤트 핸들러 해제
- _Event.WindowStyleSet_SendMessage_Event -= new _Event.WindowStyleSet_SendMessage_Handler(_Event_WindowStyleSet_SendMessage_Event);
- }
- // 기본값 초기화
- public void Initialize_Defalut(bool Enable)
- {
- // 중복 체크를 누르기 전까지는 모두 비활성화
- this.editBox_ID.Enabled = !Enable;
- this.UiButton_SameIdChk.Enabled = !Enable;
- this.editBox_PW.Enabled = Enable;
- this.editBox_RePW.Enabled = Enable;
- this.editBox_Name.Enabled = Enable;
- this.editBox_CompanyName.Enabled = Enable;
- this.editBox_CompanyPosition.Enabled = Enable;
- this.editBox_Phone.Enabled = Enable;
- this.uiButton_Save.Enabled = Enable;
- }
- public void UI_EditBox_Clear()
- {
- // 중복 체크를 누르기 전까지는 모두 비활성화
- this.editBox_ID.Text = null;
- this.editBox_PW.Text = null;
- this.editBox_RePW.Text = null;
- this.editBox_Name.Text = null;
- this.editBox_CompanyName.Text = null;
- this.editBox_CompanyPosition.Text = null;
- this.editBox_Phone.Text = null;
- }
- // 데이타베이스에서 USER 정보 가져오기 (DEVICE CONFIG 혹은 CARD REG 용인지 내부에서 구분해서 리스트 생성됨)
- public static bool GET_DB_USER_INFO()
- {
- try
- {
- // 초기화
- _Data.HASH_USER.Clear();
- _Data.LIST_USER_KEY.Clear();
- ///
- /// DB -> 해쉬에 저장
- ///
- DataRowCollection DB_TABLE_USER = null;
- DB_TABLE_USER = _Db.ExecuteRead_SqlDataAdapter(_Sql.SearchAll_Table_Value("TB_USERS", null));
- if (DB_TABLE_USER != null)
- {
- foreach (DataRow dr in DB_TABLE_USER)
- {
-
- _USER USER = new _USER();
- USER.USER_NO = dr["USER_NO"].ToString();
- USER.USER_NAME = dr["USER_NAME"].ToString();
- USER.USER_ID = dr["USER_ID"].ToString();
- USER.USER_PW = dr["USER_PW"].ToString();
- USER.USER_COMPANY = dr["USER_COMPANY"].ToString();
- USER.USER_POSITION = dr["USER_POSITION"].ToString();
- USER.USER_PHONE = dr["USER_PHONE"].ToString();
- // 해쉬에 추가 (키값은 항상 String 으로 접근)
- if (_Hash.Add(_Data.HASH_USER, USER.USER_ID, USER) == true)
- {
- // 키리스트에 추가
- _Data.LIST_USER_KEY.Add(USER.USER_ID);
- }
- }
- }
- return true;
- }
- catch (Exception e)
- {
- // LOG
- _Event.DebugView_SendMessage_Write(e.ToString());
- return false;
- }
- }
- // 사용자 정보 리스트 초기화
- public void UI_GridEx_Initialize()
- {
- // 초기화
- this.GridEx_UserList.ClearItems();
- int i = 0;
- foreach (string USER_KEY in _Data.LIST_USER_KEY)
- {
- // 접근하려는 USER 정보 추출
- _USER USER = ((_USER)_Data.HASH_USER[USER_KEY]);
- // 기본 출력될 컬럼
- string GridexAddItem = null;
- // 생성된 컬럼명에 맞게 데이타를 추가한다
- GridexAddItem =
- // NO
- ColumnNames_Headers[0] + _Text.Equal + (++i).ToString() + _Text.SemiColon +
- // ID
- ColumnNames_Headers[1] + _Text.Equal + USER.USER_ID + _Text.SemiColon +
- // PW
- ColumnNames_Headers[2] + _Text.Equal + USER.USER_PW + _Text.SemiColon +
- // Name
- ColumnNames_Headers[3] + _Text.Equal + USER.USER_NAME + _Text.SemiColon +
- // Company_Name
- ColumnNames_Headers[4] + _Text.Equal + USER.USER_COMPANY + _Text.SemiColon +
- // Company_Positon
- ColumnNames_Headers[5] + _Text.Equal + USER.USER_POSITION + _Text.SemiColon +
- // Phone
- ColumnNames_Headers[6] + _Text.Equal + USER.USER_PHONE;
-
- // 컬럼추가
- _Gridex.Column_Data_Add(this.GridEx_UserList, false, GridexAddItem);
- }
- }
- // 중복체크 버튼 누름
- private void UiButton_SameIdChk_Click(object sender, EventArgs e)
- {
- // 자동으로 공백처리
- this.editBox_ID.Text = this.editBox_ID.Text.Trim();
- // 예외처리
- string TempError = _Error.Data_Confirm_NotDefineString(this.editBox_ID.Text);
- if (TempError != null)
- {
- // 입력부 비활성화
- Initialize_Defalut(false);
- // 경고 문구
- _Popup.Create(Popup_Type.Confirm, Popup_Style.Normal, _Text.OK, 250, 150, TempError, 0); // 에러 문구
- }
- // 그룹명을 지정해야만 한다
- else if (this.editBox_ID.Text == null || this.editBox_ID.Text.Trim().Length == 0)
- {
- // 입력부 비활성화
- Initialize_Defalut(false);
- // 경고 문구
- _Popup.Create(Popup_Type.Confirm, Popup_Style.Normal, _Text.OK, 250, 150, _Text.NameNotInput, 0); // 이름을 입력해 주세요
-
- }
- // 현재 등록하려는 아이디가 포함되는지 알아본다
- else if (_Data.LIST_USER_KEY.Contains(this.editBox_ID.Text) == true)
- {
- // 입력부 비활성화
- Initialize_Defalut(false);
- // 경고 문구
- _Popup.Create(Popup_Type.Confirm, Popup_Style.Normal, _Text.OK, 400, 150, _Text.UserIDUsingFail, 0);
- }
- else
- {
- // 입력부 활성화
- Initialize_Defalut(true);
- // 확인 문구
- _Popup.Create(Popup_Type.Confirm, Popup_Style.Normal, _Text.OK, 400, 150, _Text.UserIDUsingSuccess, 0);
- }
- }
- // 저장버튼 누름
- private void uiButton_Save_Click(object sender, EventArgs e)
- {
- // 패스워드 정보 체크
- if (this.editBox_PW.Text != this.editBox_RePW.Text || this.editBox_PW.Text == null || this.editBox_PW.Text.Trim().Length == 0)
- {
- _Popup.Create(Popup_Type.Confirm, Popup_Style.Normal, _Text.OK, 250, 150, _Text.UserPWUsingFail, 0);
- return;
- }
- // 모든 입력 체크
- if (this.editBox_Name.Text == null || this.editBox_Name.Text.Trim().Length == 0
- || this.editBox_CompanyName.Text == null || this.editBox_CompanyName.Text.Trim().Length == 0
- || this.editBox_Phone.Text == null || this.editBox_Phone.Text.Trim().Length == 0
- || this.editBox_CompanyPosition.Text == null || this.editBox_CompanyPosition.Text.Trim().Length == 0
- )
- {
- _Popup.Create(Popup_Type.Confirm, Popup_Style.Normal, _Text.OK, 250, 150, _Text.UserInfoNot, 0);
- return;
- }
- // 사용자 저장합니다. 진행하시겠습니까?
- DialogPopup_User_Save = _PopupDialog.Create(Popup_Type.Dialog, Popup_Style.Normal, _Text.OK, 450, 150, _Text.UserSave_Continue, _Event_DialogPopup_User_Save_SendMessage_Event);
- }
- // 리스트에서 아이템 마우스 클릭
- private void GridEx_UserList_MouseClick(object sender, MouseEventArgs e)
- {
- // 선택한 아이템이 없으면
- if (this.GridEx_UserList.CurrentRow == null ||
- this.GridEx_UserList.CurrentRow.Cells["ID"] == null ||
- this.GridEx_UserList.CurrentRow.Cells["ID"].Value == null)
- return;
-
- // 오른쪽 마우스를 선택할 경우
- if (e.Button == System.Windows.Forms.MouseButtons.Right)
- {
- //if (this.GridEx_UserList.CurrentRow.Cells["ID"].Value.ToString() != _Data.Super_User_ID)
- {
- _Contextmenustrip.Create(this.GridEx_UserList, e.Location,
- _Text.Delete + ";" +
- _Text.ContextStripSeparator + ";" +
- _Text.AllDelete,
- Selected_Menustrip_ItemClicked);
- }
- }
-
- // 선택한 그룹이름을 저장한다
- gridEX_Selected_User_ID = this.GridEx_UserList.CurrentRow.Cells["ID"].Value.ToString();
- // UI 표시
- this.editBox_ID.Text = ((_USER)_Data.HASH_USER[gridEX_Selected_User_ID]).USER_ID;
- this.editBox_PW.Text = ((_USER)_Data.HASH_USER[gridEX_Selected_User_ID]).USER_PW;
- this.editBox_RePW.Text = ((_USER)_Data.HASH_USER[gridEX_Selected_User_ID]).USER_PW;
- this.editBox_Name.Text = ((_USER)_Data.HASH_USER[gridEX_Selected_User_ID]).USER_NAME;
- this.editBox_CompanyName.Text = ((_USER)_Data.HASH_USER[gridEX_Selected_User_ID]).USER_COMPANY;
- this.editBox_CompanyPosition.Text = ((_USER)_Data.HASH_USER[gridEX_Selected_User_ID]).USER_POSITION;
- this.editBox_Phone.Text = ((_USER)_Data.HASH_USER[gridEX_Selected_User_ID]).USER_PHONE;
- Initialize_Defalut(true);
- }
- ///
- /// 팝업 메뉴 선택
- ///
-
- public void Selected_Menustrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
- {
- // 리스트에서 팝업창 메뉴중 전체 삭제를 선택
- if (e.ClickedItem.Text == _Text.AllDelete)
- {
- // 시스템 사용자 모두 삭제됩니다. 계속 진행하시겠습니까?"
- DialogPopup_User_AllDelete = _PopupDialog.Create(Popup_Type.Dialog, Popup_Style.Normal, _Text.OK, 450, 150, _Text.UserAllDelete_Continue, _Event_DialogPopup_User_AllDelete_SendMessage_Event);
- }
- // 리스트에서 팝업창 메뉴중 삭제를 선택
- else if (e.ClickedItem.Text == _Text.Delete)
- {
- // 시스템 사용자 삭제됩니다. 계속 진행하시겠습니까?"
- DialogPopup_User_Delete = _PopupDialog.Create(Popup_Type.Dialog, Popup_Style.Normal, _Text.OK, 450, 150, _Text.UserDelete_Continue, _Event_DialogPopup_User_Delete_SendMessage_Event);
- }
- }
- // 전체 삭제 여부
- public void _Event_DialogPopup_User_AllDelete_SendMessage_Event(object sender, object etc)
- {
- // 대화 팝업 주체
- Form popup = (Form)sender;
- if (DialogPopup_User_AllDelete.Name == popup.Name && etc.ToString() == _Text.OK)
- {
- // DB 삭제
- _Db.Execute("DELETE FROM TB_USERS");
-
- // DB 로 부터 해쉬 테이블 및 리스트 정리
- GET_DB_USER_INFO();
- // 선택한 아이디를 초기화
- gridEX_Selected_User_ID = null;
- // UI 초기화
- Initialize_Defalut(false);
- UI_EditBox_Clear();
- // UI 갱신
- UI_GridEx_Initialize();
- }
- }
- // 삭제 여부
- public void _Event_DialogPopup_User_Delete_SendMessage_Event(object sender, object etc)
- {
- // 대화 팝업 주체
- Form popup = (Form)sender;
- if (DialogPopup_User_Delete.Name == popup.Name && etc.ToString() == _Text.OK)
- {
- // DB 삭제
- string sql = string.Format("DELETE FROM TB_USERS WHERE USER_ID = '{0}'", gridEX_Selected_User_ID);
- _Db.Execute(sql);
-
- // DB 로 부터 해쉬 테이블 및 리스트 정리
- GET_DB_USER_INFO();
- // 선택한 아이디를 초기화
- gridEX_Selected_User_ID = null;
- // UI 초기화
- Initialize_Defalut(false);
- UI_EditBox_Clear();
-
- // UI 갱신
- UI_GridEx_Initialize();
- }
- }
- // 저장 여부
- public void _Event_DialogPopup_User_Save_SendMessage_Event(object sender, object etc)
- {
- // 대화 팝업 주체
- Form popup = (Form)sender;
- if (DialogPopup_User_Save.Name == popup.Name && etc.ToString() == _Text.OK)
- {
- // 데이타 저장하자
- _USER USER = new _USER();
- USER.USER_ID = this.editBox_ID.Text;
- USER.USER_PW = this.editBox_PW.Text;
- USER.USER_NAME = this.editBox_Name.Text;
- USER.USER_COMPANY = this.editBox_CompanyName.Text;
- USER.USER_POSITION = this.editBox_CompanyPosition.Text;
- USER.USER_PHONE = this.editBox_Phone.Text;
- // 새로 추가인지 편집인지 구분해서 루틴을 타도록 한다
- if (_Data.LIST_USER_KEY.Contains(USER.USER_ID) == false)
- {
- // 해쉬에 추가
- if (_Hash.Add(_Data.HASH_USER, USER.USER_ID, USER) == true)
- {
- // 키리스트에 추가
- _Data.LIST_USER_KEY.Add(USER.USER_ID);
- }
-
- // UI 표시
- UI_GridEx_Initialize();
- // DB 저장
- 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)",
- _Data.LIST_USER_KEY.IndexOf(USER.USER_ID),
- USER.USER_ID,
- USER.USER_PW,
- USER.USER_NAME,
- USER.USER_COMPANY,
- USER.USER_POSITION,
- USER.USER_PHONE
- );
- _Db.Execute(sql);
- }
- // 편집
- else
- {
- // 해쉬에 내용 변경
- ((_USER)_Data.HASH_USER[USER.USER_ID]).USER_PW = USER.USER_PW;
- ((_USER)_Data.HASH_USER[USER.USER_ID]).USER_NAME = USER.USER_NAME;
- ((_USER)_Data.HASH_USER[USER.USER_ID]).USER_COMPANY = USER.USER_COMPANY;
- ((_USER)_Data.HASH_USER[USER.USER_ID]).USER_POSITION = USER.USER_POSITION;
- ((_USER)_Data.HASH_USER[USER.USER_ID]).USER_PHONE = USER.USER_PHONE;
- // UI 표시
- _Gridex.Column_Data_Edit(this.GridEx_UserList, ColumnNames_Headers[1] + _Text.Equal + USER.USER_ID,
- // PW
- ColumnNames_Headers[2] + _Text.Equal + USER.USER_PW + _Text.SemiColon +
- // Name
- ColumnNames_Headers[3] + _Text.Equal + USER.USER_NAME + _Text.SemiColon +
- // Company_Name
- ColumnNames_Headers[4] + _Text.Equal + USER.USER_COMPANY + _Text.SemiColon +
- // Company_Postion
- ColumnNames_Headers[5] + _Text.Equal + USER.USER_POSITION + _Text.SemiColon +
- // Phone
- ColumnNames_Headers[6] + _Text.Equal + USER.USER_PHONE);
- // DB 저장
- 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}'",
- USER.USER_ID,
- USER.USER_PW,
- USER.USER_NAME,
- USER.USER_PHONE,
- USER.USER_COMPANY,
- USER.USER_POSITION);
- _Db.Execute(sql);
- }
- // 선택한 아이디 초기화
- gridEX_Selected_User_ID = null;
- // UI 초기화
- Initialize_Defalut(false);
- UI_EditBox_Clear();
- }
- // 팝업창 이벤트 처리 해제
- //_Event.PopupClose_SendMessage_Event -= new _Event.PopupClose_SendMessage_Handler(_Event_DialogPopup_User_Save_SendMessage_Event);
- }
-
- // 새로 만들기 버튼
- private void uiButton_New_Click(object sender, EventArgs e)
- {
- // 선택한 아이디 초기화
- gridEX_Selected_User_ID = null;
- // UI 초기화
- Initialize_Defalut(false);
- UI_EditBox_Clear();
- }
-
-
- }
- }
|