private void FrmMain_Load(object sender, EventArgs e) { if (SQLData.CheckRubberSoftConnection() == false) { XtraMessageBox.Show("Not connect database", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { if (SQLData.CheckConnection() == false) { XtraMessageBox.Show("Not Connection database", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } Load_Form(); } lblUserName.Text = "ยินดีต้อนรับ : " + ClassProperty.permisUserNm; }
private bool Login() { try { if (SQLData.CheckRubberSoftConnection() == false || SQLData.CheckConnection() == false) { XtraMessageBox.Show("ไม่สามารถเชื่อมต่อระบบได้", "คำเตือน", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } if (TxtUserName.Text.Trim() == "" || TxtPassword.Text == "") { Alert(); return(false); } if (TxtUserName.Text.Trim() == SQLData.ID && TxtPassword.Text.Trim() == SQLData.DecryptString(SQLData.KEY)) { ClassProperty.permisUserID = -1; ClassProperty.permisUserNm = SQLData.ID; ClassProperty.permisRole = "IT"; ClassProperty.permisRoleId = -1; ClassProperty.permisUserPass = TxtPassword.Text.Trim(); CheckLogin(); } else { if (ClassProperty.EnableTerminal == false) { XtraMessageBox.Show("เครื่องใช้งานไม่มีสิทธิ์เข้าใช้งานระบบ", "คำเตือน", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } using (var context = new RubberSoftEntities()) { var query = context.spt_GetUsers().Where(o => o.UserName == TxtUserName.Text && SQLData.DecryptString(o.Password) == TxtPassword.Text.Trim()).ToList(); if (query.Count > 0) { foreach (spt_GetUsers_Result dt in query) { ClassProperty.permisUserID = dt.UserId; ClassProperty.permisUserNm = dt.UserName; ClassProperty.permisRole = dt.RoleName; ClassProperty.permisRoleId = dt.UserTypeId.Value; ClassProperty.permisUserPass = TxtPassword.Text.Trim(); // 1-001 1 : สิทธิ์ใช้งานหน้าเข้าสู่ระบบ เข้าสู่ระบบ int AuthorizeId = 1; if (SQLAuthorized.CheckAuthorized(ClassProperty.permisRoleId, AuthorizeId) == false) { SQLAuthorized.AlertAuthorized("สิทธิ์ใช้งานหน้าเข้าสู่ระบบ", "ไม่มีสิทธิ์การใช้งานระบบ"); return(false); } CheckLogin(); } } else { //XtraMessageBox.Show("ข้อมูลผู้ใช้งานมีปัญหา กรุณาติดต่อ IT !", "คำเตือน", MessageBoxButtons.OK, MessageBoxIcon.Warning); Alert(); return(false); } } } return(true); } catch (Exception ex) { XtraMessageBox.Show(ex.Message); return(false); } }