Ejemplo n.º 1
0
        public static GuiFrameWindow QueryPA20(this GuiSession session, int employeeID, string it, string sty = null, bool asListView = false)
        {
            const string TransactionTitle = "Afficher données de base personnel";

            var window = session.BeginTransaction("PA20", TransactionTitle);

            Logger.Instance.Debug("Accessing personal data: emp={0}, it={1}, sty={2}, mode={3}", employeeID, it, sty ?? "null", asListView ? "list" : "detail");
            window.FindByName <GuiCTextField>("RP50G-PERNR").Text = employeeID.ToString();
            window.FindByName <GuiCTextField>("RP50G-CHOIC").Text = it;
            window.FindByName <GuiCTextField>("RP50G-SUBTY").Text = sty;
            window.SendVKey(asListView ? 20 : 7); // Ctrl+F8 vs F7

            // if the title remains the same, that means we have failed to access the data
            if (window.Text == TransactionTitle)
            {
                const string Message = "The employee's personal data can not be accessed. The employee's ID may be incorrect, or there is no record for the requested infotype. Or. you do not have the correct permission to access this infotype.";
                var          context = new Dictionary <string, object>
                {
                    { "EmployeeID", employeeID },
                    { "InfoType", it },
                    { "SubType", sty },
                    { "AsListView", asListView },
                    { "StatusMessage", window.FindByName <GuiStatusbar>("sbar").Text }
                };

                Logger.Instance.Error("Unable to access infotype." + context.Prettify());
                throw new InvalidOperationException(Message + Environment.NewLine + context.Prettify())
                      .BindContext(context);
            }

            return(window);
        }
        /// <summary>
        /// Start a new transaction and return the active window
        /// </summary>
        public static GuiFrameWindow BeginTransaction(this GuiSession session, string transactionID, string expectedTitle)
        {
            return(session.BeginTransaction(transactionID,
                                            x => x.Text == expectedTitle,
                                            x =>
            {
                var exception = new InvalidOperationException(string.Format("Failed to open transaction : {0}", transactionID));
                exception.Data["Transaction ID"] = transactionID;
                exception.Data["Expected Title"] = expectedTitle;
                exception.Data["Current Title"] = x.Text;
                exception.Data["Status Message"] = x.FindByName <GuiStatusbar>("sbar").Text;

                return exception;
            }));
        }
        /// <summary>
        /// Shortcut for PA30 query
        /// </summary>
        /// <param name="session"></param>
        /// <param name="employeeID"></param>
        /// <param name="it">Infotype ID</param>
        /// <param name="sty">Subtype ID</param>
        /// <param name="asListView"></param>
        /// <returns></returns>
        public static GuiFrameWindow QueryPA30(this GuiSession session, int employeeID, string it, string sty = null)
        {
            var window = session.BeginTransaction("PA30", "Gérer données de base HR");

            window.FindByName <GuiCTextField>("RP50G-PERNR").Text = employeeID.ToString();
            window.FindByName <GuiCTextField>("RP50G-CHOIC").Text = it;
            window.FindByName <GuiCTextField>("RP50G-SUBTY").Text = sty;
            window.FindByName <GuiButton>("btn[6]").Press();

            if (window.Text == "Gérer données de base HR")
            {
                var exception = new InvalidOperationException(string.Format("Failed to access to personal information of {0}", employeeID));
                exception.Data["Employee ID"]    = employeeID;
                exception.Data["Infotype"]       = it;
                exception.Data["Subtype"]        = sty;
                exception.Data["Status Message"] = window.FindByName <GuiStatusbar>("sbar").Text;

                throw exception;
            }

            return(window);
        }
        /// <summary>
        /// Shortcut for PA20 query
        /// </summary>
        /// <param name="session"></param>
        /// <param name="employeeID"></param>
        /// <param name="it">Infotype ID</param>
        /// <param name="sty">Subtype ID</param>
        /// <param name="asListView"></param>
        /// <returns></returns>
        public static GuiFrameWindow QueryPA20(this GuiSession session, int employeeID, string it, string sty = null, bool asListView = false)
        {
            var window = session.BeginTransaction("PA20", "Afficher données de base personnel");

            window.FindByName <GuiCTextField>("RP50G-PERNR").Text = employeeID.ToString();
            window.FindByName <GuiCTextField>("RP50G-CHOIC").Text = it;
            window.FindByName <GuiCTextField>("RP50G-SUBTY").Text = sty;
            window.FindByName <GuiButton>(asListView ? "btn[20]" : "btn[7]").Press();

            if (window.Text == "Afficher données de base personnel")
            {
                var exception = new InvalidOperationException(string.Format("Failed to access to personal information of {0}", employeeID));
                exception.Data["Employee ID"]    = employeeID;
                exception.Data["Infotype"]       = it;
                exception.Data["Subtype"]        = sty;
                exception.Data["View"]           = asListView ? "ListView[Mont]" : "RecordView[Glasses]";
                exception.Data["Status Message"] = window.FindByName <GuiStatusbar>("sbar").Text;

                throw exception;
            }

            return(window);
        }