private void mnuCurrentUser_Click(object sender, EventArgs e) { string originalStatus = Status; try { DialogResult result = DialogResult.Cancel; User currentUserClone = GlobalDataCache.Instance.CurrentUser.Clone(); using (UserForm f = new UserForm(currentUserClone, EntityOperation.LimitedUpdate, null)) { result = f.ShowDialog(); } if (result == DialogResult.OK) { using (WaitCursor w = new WaitCursor()) { Status = "Saving current user to server ..."; ServiceProcedureResult userResult = GlobalDataCache.Instance.Service.SaveUser(new User[] { currentUserClone }, GlobalDataCache.Instance.CurrentUser, false); if (ServiceResultHandler.HandleServiceResult(userResult)) { return; } } currentUserClone.CopyTo(GlobalDataCache.Instance.CurrentUser); } } finally { if (Status != originalStatus) { Status = originalStatus; } } }
private void mnuLogin_Click(object sender, EventArgs e) { string originalStatus = Status; try { if (string.IsNullOrEmpty(txtUserName.Text)) { txtUserName.Focus(); throw new UserThrownException("Username not entered.", false, true, false); } if (string.IsNullOrEmpty(txtPassword.Text)) { txtPassword.Focus(); throw new UserThrownException("Password not entered.", false, true, false); } using (WaitCursor w = new WaitCursor()) { Status = "Attempting to login ..."; ServiceFunctionResultOfUser result = GlobalDataCache.Instance.Service.Login(txtUserName.Text, txtPassword.Text, UserRoleId.Web); if (ServiceResultHandler.HandleServiceResult(result)) { return; } User u = result.Contents; if (u == null) { throw new UserThrownException("Invalid username/password", false, true, false); } GlobalDataCache.Instance.CurrentUser = u; Status = "Downloading user permissions ..."; if (GlobalDataCache.Instance.CurrentUser.UserPermissionCache.RefreshFromServerForUser(GlobalDataCache.Instance.CurrentUser)) { return; } Status = "Downloading global server variables ..."; if (GlobalDataCache.Instance.GlobalServerVariables.RefreshFromServer()) { return; } } this.DialogResult = DialogResult.OK; Close(); } finally { if (Status != originalStatus) { Status = originalStatus; } } }
private void mnuApprove_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtDeviceId.Text)) { txtDeviceId.Focus(); throw new UserThrownException("Device id may not be left empty.", false, true, false); } if (string.IsNullOrEmpty(txtApplicationName.Text)) { txtApplicationName.Focus(); throw new UserThrownException("Application Name may not be left empty.", false, true, false); } if (_selectedCustomer == null) { btnSelectCustomer.Focus(); throw new UserThrownException("Customer not selected.", false, true, false); } string originalStatus = Status; try { using (WaitCursor w = new WaitCursor()) { Status = "Approving device ..."; ServiceProcedureResult result = GlobalDataCache.Instance.Service.ApproveDevicePendingApproval( txtDeviceId.Text, txtApplicationName.Text, txtApplicationWebServiceURL.Text, txtApplicationReplicationWebServiceURL.Text, txtFiglutWebServiceURL.Text, Convert.ToInt32(nudDaysToActivate.Value), _selectedCustomer, GlobalDataCache.Instance.CurrentUser); if (ServiceResultHandler.HandleServiceResult(result)) { return; } } UIHelper.DisplayInformation(string.Format("Device {0} approved.", txtDeviceId.Text)); this.DialogResult = DialogResult.OK; Close(); } finally { if (Status != originalStatus) { Status = originalStatus; } } }
private void mnuLog_Click(object sender, EventArgs e) { string originalStatus = statusMain.Text; try { if (string.IsNullOrEmpty(txtFunction.Text)) { txtFunction.Focus(); UIHelper.DisplayError("Function not entered."); return; } ServiceFunctionResultOfDeviceConfigAction result = null; using (WaitCursor w = new WaitCursor()) { statusMain.Text = "Logging action to server ..."; string deviceId = DeviceConfigManager.GetDeviceId(); string applicationName = Path.GetFileName(Assembly.GetExecutingAssembly().GetName().CodeBase); result = DeviceConfigOptions.Instance.Service.LogDeviceConfigAction( txtFunction.Text, deviceId, applicationName, string.IsNullOrEmpty(txtTag.Text) ? null : txtTag.Text); } if (ServiceResultHandler.HandleServiceResult(result)) { return; } UIHelper.DisplayInformation("Device Action logged successfully."); } catch (Exception ex) { ExceptionHandler.HandleException(ex, true, true); } finally { statusMain.Text = originalStatus; } }