private void DoTransaction(string TransactionCode) { TransactionExecution Execution = new TransactionExecution(this.UserContext); bool ReturnAfterDcal = false; if (this.UserContext.Status != TroposStatus.AwaitingTransaction) { Execution.DoReply("N", new ElectronicSignatureData(), int.Parse(this.UserContext.DataValidAttachKey, CultureInfo.InvariantCulture)); } bool?NoUpdate = Session["DcalNoUpdate"] as bool?; if (NoUpdate != null && (bool)NoUpdate && TransactionCode == "UCAL") { // No Update flag is set, so do DCAL instead of UCAL TransactionCode = "DCAL"; ReturnAfterDcal = true; } Session["CalculatorModeFieldValues"] = DimensionHelper.EvaluateFields(TroposFields.Controls[3].Controls); ExecuteReturn ReturnValue; ReturnValue = Execution.DoTransaction(TroposFields.Controls[3].Controls, TransactionCode, ScreenCode, false, false); { Dictionary <string, string> FieldValues = null; Dictionary <string, string> _fieldValues = null; object SessionFieldValues = null; DataTable FieldValuesTable = ReturnValue.FieldValuesTable; DataRow FieldValuesRow = FieldValuesTable.Rows[0]; switch (ReturnValue.WaitefReturn) { case "ExoutvarOk": case "Exread": case "Exread2": // The DCAL transaction comes here - set up the fields in case we need to return them FieldValuesTable = ReturnValue.FieldValuesTable; FieldValuesRow = FieldValuesTable.Rows[0]; FieldValues = RowToDictionary(FieldValuesTable, FieldValuesRow); if (ReturnAfterDcal) { TransactionReturn(FieldValues); } break; case "ExdoneOk": // UCAL comes here - set up the fields from the pre-update values, then add the result fields SessionFieldValues = Session["CalculatorModeFieldValues"]; if (SessionFieldValues != null) { FieldValues = (Dictionary <string, string>)SessionFieldValues; Session.Remove("CalculatorModeFieldValues"); } FieldValuesTable = ReturnValue.FieldValuesTable; FieldValuesRow = FieldValuesTable.Rows[0]; _fieldValues = RowToDictionary(FieldValuesTable, FieldValuesRow); FieldValues["iATTVALFROM-DQ"] = _fieldValues["iATTVALFROM-DQ"]; FieldValues["iUOM-ATT1"] = _fieldValues["iUOM-ATT1"]; TransactionReturn(FieldValues); break; case "ExoutvarFail": TroposResourceProvider Trp = new TroposResourceProvider(UserContext); if (ReturnValue.Message.Trim() == Trp.GetResource("MSG_NO_CHANGES")) { switch (TransactionCode) { case "UCAL": // set up the fields from the pre-update values, then add the result fields SessionFieldValues = Session["CalculatorModeFieldValues"]; if (SessionFieldValues != null) { FieldValues = (Dictionary <string, string>)SessionFieldValues; Session.Remove("CalculatorModeFieldValues"); } FieldValuesTable = ReturnValue.FieldValuesTable; FieldValuesRow = FieldValuesTable.Rows[0]; _fieldValues = RowToDictionary(FieldValuesTable, FieldValuesRow); FieldValues["iATTVALFROM-DQ"] = _fieldValues["iATTVALFROM-DQ"]; FieldValues["iUOM-ATT1"] = _fieldValues["iUOM-ATT1"]; TransactionReturn(FieldValues); break; case "DCAL": if (ReturnAfterDcal) { FieldValuesTable = ReturnValue.FieldValuesTable; FieldValuesRow = FieldValuesTable.Rows[0]; FieldValues = RowToDictionary(FieldValuesTable, FieldValuesRow); TransactionReturn(FieldValues); } break; } } break; } } ValidationResult MandatoryCheckResult = new ValidationResult(); Execution.LoadScreenFields( ReturnValue.FieldValuesTable, ReturnValue.Message, ReturnValue.ScrollTable, ReturnValue.TextTable, TroposFields.Controls[3].Controls, TransactionCode, MandatoryCheckResult); Label ErrorField = (Label)TroposFields.FindControl("eError"); if (ErrorField != null) { if (ReturnValue.Success) { ErrorField.Text = ""; ErrorField.CssClass = "TroposError TroposDisplay TroposField"; } else { ErrorField.Text = ReturnValue.Message; if (string.IsNullOrEmpty(ReturnValue.Message)) { ErrorField.CssClass = "TroposError TroposDisplay TroposField"; } else { ErrorField.CssClass = "TroposErrorPopulated TroposDisplay TroposField"; } } } }
protected void btnLogon_Click(object sender, EventArgs e) { try { if (this.chkSaveSettings.Checked) { HttpCookie LoginCookie = new HttpCookie("TroposLogin"); //LoginCookie.Path = Request.ApplicationPath; LoginCookie.Values.Add("Server", txtServer.Text); LoginCookie.Values.Add("Database", txtDatabase.Text); LoginCookie.Values.Add("Identity", txtIdentity.Text); LoginCookie.Values.Add("Business", txtBusiness.Text); LoginCookie.Values.Add("Manager", chkManager.Checked.ToString()); LoginCookie.Values.Add("WindowsAuth", chkWindowsAuth.Checked.ToString()); LoginCookie.Expires = DateTime.Now.AddYears(1);; Response.Cookies.Add(LoginCookie); } WindowsImpersonationContext Ctx = null; UserContext context; if (chkWindowsAuth.Checked) { context = new UserContext(txtServer.Text, txtDatabase.Text, txtBusiness.Text); if (HttpContext.Current.User.Identity.IsAuthenticated) { WindowsIdentity WinId = (WindowsIdentity)HttpContext.Current.User.Identity; Ctx = WinId.Impersonate(); } } else { context = new UserContext(txtServer.Text, txtDatabase.Text, txtIdentity.Text, txtPassword.Text, txtBusiness.Text, chkManager.Checked); } //Store this applications url prefix for use when launching items from the menu context.ParentUrlPrefix = UrlHelper.UrlPrefix(); bool attachedByMe = false; try { context.Load(Session); //This is a hack to load the resource management libraries for the 1st user to log in if (!context.AttachedToTropos) { TroposCS.Attach(context); attachedByMe = true; } TroposResourceProvider _trp = new TroposResourceProvider(context); _trp.GetResource("TEST"); } finally { if (attachedByMe) { TroposCS.Detach(context); } if (Ctx != null) { Ctx.Undo(); } } // Create the user data string userDataString = string.Concat(txtServer.Text, "|" , txtDatabase.Text, "|" , txtIdentity.Text, "|" , txtPassword.Text, "|" , txtBusiness.Text, "|" , chkManager.Checked.ToString(), "|" , context.ParentUrlPrefix, "|" , context.WindowsAuthentication.ToString()); // Create the cookie that contains the forms authentication ticket HttpCookie authCookie = FormsAuthentication.GetAuthCookie(txtIdentity.Text, false); // Get the FormsAuthenticationTicket out of the encrypted cookie FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value); // Create a new FormsAuthenticationTicket that includes our custom User Data FormsAuthenticationTicket newTicket = new FormsAuthenticationTicket(ticket.Version, ticket.Name, ticket.IssueDate, ticket.Expiration, ticket.IsPersistent, userDataString); // Update the authCookie's Value to use the encrypted version of newTicket authCookie.Value = FormsAuthentication.Encrypt(newTicket); // Manually add the authCookie to the Cookies collection Response.Cookies.Add(authCookie); // Determine redirect URL and send user there string redirUrl = FormsAuthentication.GetRedirectUrl(txtIdentity.Text, false); Response.Redirect(redirUrl); //FormsAuthentication.RedirectFromLoginPage(this.UserContext.TroposIdentity, false); } catch (TroposDbUnexpectedErrorException) { TroposResourceProvider trp = new TroposResourceProvider(this.UserContext); lblError.Text = trp.GetResource("MSG_DB_ERROR"); } catch (TroposDbTableExistsException) { TroposResourceProvider trp = new TroposResourceProvider(this.UserContext); lblError.Text = trp.GetResource("MSG_DB_ERROR"); } catch (TroposDbPermissionsException) { TroposResourceProvider trp = new TroposResourceProvider(this.UserContext); lblError.Text = trp.GetResource("MSG_DB_PERMISSIONS"); } catch (Exception ex) { lblError.Text = ex.Message; return; } }
public void DoQuickCode(string quickCode, string reference, bool newPage, bool saveHistory, bool autoExecute) { quickCode = quickCode.Trim(); if (Array.Find(UserContext.ProhibitedActions, x => string.Compare(x.Trim(), quickCode.Trim(), StringComparison.OrdinalIgnoreCase) == 0) != null) { // Some quick codes are just prohibited, so don't even try to process them. return; } bool inMenu = false; TroposResourceProvider trp = new TroposResourceProvider(this.UserContext); if (quickCode == null || string.IsNullOrEmpty(quickCode.Trim())) { StringBuilder message = new StringBuilder(); message.Append(trp.GetResource("MSG_QUICK_CODE_MISSING").Trim()); message.Append("."); message.Append("<br/>"); message.Append("<br/>"); message.Append(trp.GetResource("MSG_ENTER_VALUE_AND_TRY_AGAIN").Trim()); message.Append(" "); message.Append(trp.GetResource("MSG_OR_SELECT_FROM_MENU").Trim()); message.Append("."); QCError(quickCode, message.ToString()); return; } Session["menuStateArray"] = menuStateControl.Value; //Save current menu state in session for cross page navigation AbstractMenuItem _mi; //Find the quick code in the user menu if (UserContext.QuickCodes.Find(x => string.Compare(x.Trim(), quickCode.Trim(), StringComparison.OrdinalIgnoreCase) == 0) == null) { inMenu = false; if (UserContext.BypassMenus || Array.Find(UserContext.PermittedActions, x => string.Compare(x.Trim(), quickCode.Trim(), StringComparison.OrdinalIgnoreCase) == 0) != null) { //Not found in user menu, try to get details from Tropos MenuItemFactory _mif = new MenuItemFactory(); _mi = _mif.ItemForQuickCode(this.UserContext, quickCode); if (_mi == null) { StringBuilder message = new StringBuilder(); message.AppendFormat(trp.GetResource("MSG_QUICK_CODE_X_DOES_NOT_EXIST").Trim(), quickCode.Trim()); message.Append("."); message.Append("<br/>"); message.Append("<br/>"); message.Append(trp.GetResource("MSG_ENTER_VALUE_AND_TRY_AGAIN").Trim()); message.Append("."); QCError(quickCode, message.ToString()); return; } } else { StringBuilder message = new StringBuilder(); message.AppendFormat(trp.GetResource("MSG_QUICK_CODE_X_DOES_NOT_EXIST").Trim(), quickCode.Trim()); message.Append(" "); message.Append(trp.GetResource("MSG_IN_YOUR_MENU").Trim()); message.Append("."); message.Append("<br/>"); message.Append("<br/>"); message.Append(trp.GetResource("MSG_ENTER_VALUE_AND_TRY_AGAIN").Trim()); message.Append(" "); message.Append(trp.GetResource("MSG_OR_SELECT_FROM_MENU").Trim()); message.Append("."); QCError(quickCode, message.ToString()); return; } } else { inMenu = true; _mi = UserContext.TroposRoles.Find(x => ((x is TroposUI.Common.Menu.Transaction && x.TransactionList.IndexOf(quickCode.Trim(), StringComparison.OrdinalIgnoreCase) >= 0) || x.TransactionList.ToUpper(CultureInfo.InvariantCulture) == quickCode.ToUpper(CultureInfo.InvariantCulture).Trim())); if (_mi == null) { StringBuilder message = new StringBuilder(); message.AppendFormat(trp.GetResource("MSG_QUICK_CODE_X_DOES_NOT_EXIST").Trim(), quickCode.Trim()); message.Append(" "); message.Append(trp.GetResource("MSG_IN_YOUR_MENU").Trim()); message.Append("."); message.Append("<br/>"); message.Append("<br/>"); message.Append(trp.GetResource("MSG_REFRESH_PAGE_AND_TRY_AGAIN").Trim()); message.Append("."); QCError(quickCode, message.ToString()); return; } } if (!(newPage || _mi.LaunchInNewWindow) || !_mi.AllowNewWindow) { //selectedNode.Value = _mi.ChildCode; selectedNode.Value = _mi.TroposUniqueMenuID.ToString(CultureInfo.InvariantCulture); ScriptManager.RegisterStartupScript(this, this.GetType(), "reinstateMenu", "$(initialise);$(forceMenuSelection);", true); } LaunchMenuItem(_mi, quickCode, reference, newPage, inMenu, saveHistory, autoExecute); }