private void btn_OK_Click(object sender, EventArgs e) { string userName = tbx_UserName.Text.Trim(); if (userName == "") { MessageBox.Show(ResourceHelper.Instance.GetString("UserForm.InvalidUserName"), Text); return; } string fullName = tbx_FullName.Text.Trim(); if (fullName == "") { MessageBox.Show(ResourceHelper.Instance.GetString("UserForm.InvalidFullName"), Text); return; } UserInfo ui = new UserInfo(); ui.Email = tbx_Email.Text.Trim(); ui.FullName = fullName; ui.UserName = userName; if (DataService.Instance.UpdateUserInfo(ui)) { DialogResult = DialogResult.OK; Close(); } else { MessageBox.Show(ResourceHelper.Instance.GetString("UserForm.UpdateUser.Failed"), Text); } }
public bool UpdateUserInfo(UserInfo ui) { if (ui == null) return false; if (currentUser == null) return false; try { DataSet ds = SqlHelper.ExecuteDataset(sqlConn, "UpdateUser", new object[] { currentUser.UserID, currentUser.UserID, currentUser.Password, currentUser.UserType, ui.UserName, ui.FullName, ui.Email }); if (ds != null && ds.Tables != null && ds.Tables.Count > 0) { DataTable table = ds.Tables[0]; UserInfo newUI = GetUserInfoFrom(table.Rows[0]); currentUser.UserName = newUI.UserName; currentUser.FullName = newUI.FullName; currentUser.Email = newUI.Email; return true; } } catch (Exception ex) { LoggerBase.Instance.Error(ex.ToString()); } return false; }
public UserInfo Authenticate(string id, string password) { if (id == null || id.Trim() == "") return null; if (password == null || password.Trim() == "") return null; try { string passwordEncrypted = DataProtection.Encrypt(password, id); ComputerSystem cs = WMIVendor.Instance.GetComputerSystem(); NetworkAdapterConfiguration network = WMIVendor.Instance.GetNetworkConfig(); ProductMan.Win32.OperatingSystem os = WMIVendor.Instance.GetOS(); string ip = ""; if (network.IPAddress != null && network.IPAddress.Length > 0) ip = network.IPAddress[0]; DataSet ds = SqlHelper.ExecuteDataset(sqlConn, "AuthenticateUser", new object[] { id, passwordEncrypted, ip, network.MACAddress, cs.Domain, cs.UserName, os.SerialNumber, "ProductMan", typeof(DataService).Assembly.GetName().Version.ToString(), "" }); if (ds != null && ds.Tables != null && ds.Tables.Count > 0) { DataTable table = ds.Tables[0]; currentUser = GetUserInfoFrom(table.Rows[0]); return currentUser; } } catch (Exception ex) { LoggerBase.Instance.Error(ex.ToString()); } return null; }
private UserInfo GetUserInfoFrom(DataRow row) { if (row == null) return null; UserInfo ui = new UserInfo(); ui.Email = Formatter.GetStringValueFrom(row, "Email"); ui.FullName = Formatter.GetStringValueFrom(row, "FullName"); ui.Password = Formatter.GetStringValueFrom(row, "Password"); ui.UserID = Formatter.GetStringValueFrom(row, "UserID"); ui.UserName = Formatter.GetStringValueFrom(row, "UserName"); ui.UserType = Formatter.GetIntValueFrom(row, "UserType"); return ui; }