private void DBConfig_Load(object sender, EventArgs e) { tblLogin = ProfileConfig.Load(); if (tblLogin.DBProfile.Count > 0) { txtServerName.Text = tblLogin.DBProfile[0].ServerName; txtDatabaseName.Text = tblLogin.DBProfile[0].DataBase; txtUsername.Text = tblLogin.DBProfile[0].DBLogin; txtPassword.Text = tblLogin.DBProfile[0].DBPassword; } }
private void tsLogin_Click(object sender, EventArgs e) { bool IsCheckLogin = false; if (string.IsNullOrEmpty(txtUsername.Text)) { MessageBox.Show("กรุณากรอกรหัสผู้ใช้", dbConString.xMessage, MessageBoxButtons.OK, MessageBoxIcon.Question); txtUsername.Focus(); return; } if (string.IsNullOrEmpty(txtPassword.Text)) { MessageBox.Show("กรุณากรอกรหัสผ่าน", dbConString.xMessage, MessageBoxButtons.OK, MessageBoxIcon.Question); txtUsername.Focus(); return; } if (!IsCheckLogin) { tblLogin = ProfileConfig.Load(); if (tblLogin.DBProfile.Count > 0) { dbConString.ServerName = tblLogin.DBProfile[0].ServerName; dbConString.DBName = tblLogin.DBProfile[0].DataBase; dbConString.Sa = tblLogin.DBProfile[0].DBLogin; dbConString.SaPassword = tblLogin.DBProfile[0].DBPassword; IsCheckLogin = dbConString.CheckOpenConn(); if (!IsCheckLogin) { DBConfig fConfig = new DBConfig(); fConfig.ShowDialog(); IsCheckLogin = dbConString.CheckOpenConn(); txtPassword.Focus(); return; } } else { DBConfig fConfig = new DBConfig(); fConfig.ShowDialog(); IsCheckLogin = dbConString.CheckOpenConn(); txtPassword.Focus(); return; } } if (IsCheckLogin) { try { string sqlTmp = ""; sqlTmp = "SELECT * FROM tbUser WHERE UserName = '******' AND Password = '******' "; DataSet Ds = new DataSet(); dbConString.Com = new SqlCommand(); dbConString.Com.CommandType = CommandType.Text; dbConString.Com.CommandText = sqlTmp; dbConString.Com.Connection = dbConString.mySQLConn; SqlCommand cmd = new SqlCommand(sqlTmp, dbConString.mySQLConn); //dr = dbConString.Com.ExecuteReader(); SqlDataAdapter da = new SqlDataAdapter(cmd); tblUser.Clear(); da.Fill(tblUser, "tbUser"); da.Dispose(); if (tblUser.tbUser.Rows.Count > 0) { dbConString.UserID = tblUser.tbUser[0].UserID; this.Close(); } else { MessageBox.Show("รหัสผ่านไม่ถูกต้อง !!", dbConString.xMessage, MessageBoxButtons.OK, MessageBoxIcon.Question); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } }
private void tsLogin_Click(object sender, EventArgs e) { bool IsCheckLogin = false; if (string.IsNullOrEmpty(txtUsername.Text)) { MessageBox.Show("กรุณากรอกรหัสผู้ใช้", dbConString.xMessage, MessageBoxButtons.OK, MessageBoxIcon.Question); txtUsername.Focus(); return; } if (string.IsNullOrEmpty(txtPassword.Text)) { MessageBox.Show("กรุณากรอกรหัสผ่าน", dbConString.xMessage, MessageBoxButtons.OK, MessageBoxIcon.Question); txtUsername.Focus(); return; } if (!IsCheckLogin) { tblLogin = ProfileConfig.Load(); if (tblLogin.DBProfile.Count > 0) { dbConString.ServerName = tblLogin.DBProfile[0].ServerName; dbConString.DBName = tblLogin.DBProfile[0].DataBase; dbConString.Sa = tblLogin.DBProfile[0].DBLogin; dbConString.SaPassword = tblLogin.DBProfile[0].DBPassword; IsCheckLogin = dbConString.CheckOpenConn(); if (!IsCheckLogin) { DBConfig fConfig = new DBConfig(); fConfig.ShowDialog(); IsCheckLogin = dbConString.CheckOpenConn(); } } else { DBConfig fConfig = new DBConfig(); fConfig.ShowDialog(); IsCheckLogin = dbConString.CheckOpenConn(); } } if (IsCheckLogin) { try { string sqlTmp = ""; sqlTmp = "SELECT * FROM tblUser WHERE Username = '******' AND User_Password = '******' "; DataSet Ds = new DataSet(); dbConString.Com = new SqlCommand(); dbConString.Com.CommandType = CommandType.Text; dbConString.Com.CommandText = sqlTmp; dbConString.Com.Connection = dbConString.mySQLConn; SqlCommand cmd = new SqlCommand(sqlTmp, dbConString.mySQLConn); //dr = dbConString.Com.ExecuteReader(); SqlDataAdapter da = new SqlDataAdapter(cmd); tblUser.Clear(); da.Fill(tblUser, "tblUser"); da.Dispose(); if (tblUser.tblUser.Rows.Count > 0) { // if (tblUser.tblOrg.Rows.Count > 0) // { // dbConString.OrgName = tblUser.tblOrg[0].OrgName; // dbConString.TraderName = tblUser.tblOrg[0].TraderName; // dbConString.Address = tblUser.tblOrg[0].Address; // dbConString.TaxID = tblUser.tblOrg[0].TaxID; // dbConString.TaxRate = tblUser.tblOrg[0].TaxRate; // dbConString.Tel = tblUser.tblOrg[0].Tel; // dbConString.Fax = tblUser.tblOrg[0].Fax; // dbConString.EmpId = tblUser.uv_User[0].EmpID; // dbConString.EmpCode = tblUser.uv_User[0].EmpCode; // dbConString.EmpName = tblUser.uv_User[0].FullName; // dbConString.SerialPorts = tblUser.tblDrawerSetting[0].SerialPorts; // dbConString.Baudrates = Convert.ToInt32(tblUser.tblDrawerSetting[0].Baudrates); // dbConString.IsUsing = tblUser.tblDrawerSetting[0].IsUsing; // ((frmMain)this.Owner).rbMenuOnEnabled = true; // this.Close(); // } } else { MessageBox.Show("รหัสผ่านไม่ถูกต้อง !!", dbConString.xMessage, MessageBoxButtons.OK, MessageBoxIcon.Question); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } }