public DATABASE_INFO LoadCredential() { try { INIFile iniF = new INIFile(Path.Combine(Application.StartupPath, OISBaseConstant.iniFileName)); string serverName = iniF.Read(OISBaseConstant.SectionNameDatabaseSetting, OISBaseConstant.KeyServerName); string dbName = iniF.Read(OISBaseConstant.SectionNameDatabaseSetting, OISBaseConstant.KeyDatabaseName); string username = iniF.Read(OISBaseConstant.SectionNameDatabaseSetting, OISBaseConstant.KeyUsername); string password = iniF.Read(OISBaseConstant.SectionNameDatabaseSetting, OISBaseConstant.KeyPassword); DATABASE_INFO credential = new DATABASE_INFO() { DATASOURCE = serverName, DATABASENAME = dbName, USERNAME = username, PASSWORD = password, }; iniF.Dispose(); return(credential); } catch (Exception ex) { throw ex; } }
private void btnTest_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; DATABASE_INFO credential = new DATABASE_INFO() { DATASOURCE = txtServerName.GetValue(), DATABASENAME = txtDatabaseName.GetValue(), USERNAME = txtUserName.GetValue(), PASSWORD = txtPassword.GetValue(), }; if (vmSys.TestConnection(credential)) { rMessageBox.ShowInfomation(this, "เชื่อมต่อสำเร็จ"); } else { rMessageBox.ShowWarning(this, "ไม่สามารถเชื่อมต่อได้", MessageBoxButtons.OK); } } catch (Exception ex) { rMessageBox.ShowException(this, ex); } finally { this.Cursor = Cursors.Default; } }
private void SettingForm_Load(object sender, EventArgs e) { DATABASE_INFO c = vmSys.LoadCredential(); txtServerName.Text = c.DATASOURCE; txtDatabaseName.Text = c.DATABASENAME; txtUserName.Text = c.USERNAME; txtPassword.Text = c.PASSWORD; }
public bool TestConnection(DATABASE_INFO data) { using (var l_oConnection = new SqlConnection(data.ConnectionString)) { try { l_oConnection.Open(); return(true); } catch (SqlException) { return(false); } } }
public void SaveCredential(DATABASE_INFO data) { try { INIFile iniF = new INIFile(Path.Combine(Application.StartupPath, OISBaseConstant.iniFileName)); iniF.Write(OISBaseConstant.SectionNameDatabaseSetting, OISBaseConstant.KeyServerName, data.DATASOURCE); iniF.Write(OISBaseConstant.SectionNameDatabaseSetting, OISBaseConstant.KeyDatabaseName, data.DATABASENAME); iniF.Write(OISBaseConstant.SectionNameDatabaseSetting, OISBaseConstant.KeyUsername, data.USERNAME); iniF.Write(OISBaseConstant.SectionNameDatabaseSetting, OISBaseConstant.KeyPassword, data.PASSWORD); iniF.Dispose(); } catch (Exception ex) { throw ex; } }
private void btnOK_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; if (txtServerName.GetValue() == null) { MessageBox.Show(this, "กรุณาระบบชื่อเซิฟเวอร์", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.ActiveControl = txtServerName; } if (txtDatabaseName.GetValue() == null) { MessageBox.Show(this, "กรุณาระบุชื่อฐานข้อมูล", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.ActiveControl = txtDatabaseName; } if (txtUserName.GetValue() == null) { MessageBox.Show(this, "กรุณาระบุชื่อผู้ใช้", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.ActiveControl = txtUserName; } if (txtPassword.GetValue() == null) { MessageBox.Show(this, "กรุณาระบุรหัสผ่าน", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.ActiveControl = txtPassword; } else { DATABASE_INFO credential = new DATABASE_INFO() { DATASOURCE = txtServerName.GetValue(), DATABASENAME = txtDatabaseName.GetValue(), USERNAME = txtUserName.GetValue(), PASSWORD = txtPassword.GetValue(), }; vmSys.SaveCredential(credential); this.DialogResult = DialogResult.OK; } } catch (Exception ex) { rMessageBox.ShowException(this, ex); } finally { this.Cursor = Cursors.Default; } }
public bool Login(string UserId, string Password) { try { DATABASE_INFO credential = LoadCredential(); OISDataInfo.RegisterDatabaseInformation(credential); Password = Encryption.GetMd5Hash(Password); sp_SYS_UserLogin_Result user = service.UserLogin(UserId, Password); if (user != null) { USER_INFO userInfo = new USER_INFO() { USER_ID = user.USER_ID, USER_FNAME = user.USER_FNAME, USER_LNAME = user.USER_LNAME, USER_FULLNAME = user.USER_FULLNAME, BIRTH_DATE = user.BIRTHDATE, GROUP_ID = user.GROUP_ID, GROUP_NAME = user.GROUP_NAME, DIVISION_ID = user.DIVISION_ID, DIVISION_NAME = user.DIVISION_NAME, SUBDIVISION_ID = user.SUBDIVISION_ID, SUBDIVISION_NAME = user.SUBDIVISION_NAME, POSITION_ID = user.POSITION_ID, POSITION_NAME = user.POSITION_NAME, MACHINE = Environment.MachineName, LAST_LOGIN = user.LAST_LOGIN, }; OISDataInfo.RegisterUserInformation(userInfo); SaveLastUserLogin(userInfo); return(true); } else { return(false); } } catch (Exception ex) { throw ex; } }
public static void RegisterDatabaseInformation(DATABASE_INFO DbInfo) { m_DatabaseInformation = DbInfo; }