Ejemplo n.º 1
0
        /// <summary>
        /// Show a message box and return result
        /// </summary>
        /// <param name="messageText"></param>
        /// <param name="titleCaption"></param>
        /// <param name="buttons"></param>
        /// <param name="icon"></param>
        /// <returns></returns>
        ///
        public static DialogResult Show(
            string messageText,
            string titleCaption,
            MessageBoxButtons buttons,
            MessageBoxIcon icon,
            int width  = -1,
            int height = -1)
        {
            DialogResult dr = DialogResult.OK;

            if (!Lex.IsNullOrEmpty(ScriptLog.FileName))
            {
                ScriptLog.Message("> " + messageText);
            }

            if (!SS.I.Attended)
            {
                ClientLog.Message("Show: " + messageText);
                return(DialogResult.OK);
            }

            else if (SS.I.QueryTestMode)
            {
                QueryTest.LogMessage("Show: " + messageText);
                return(DialogResult.OK);
            }

            //DebugLog.Message(messageText += "\r\n" + new StackTrace(true)); // debug where message is called from"

            Progress.Hide();                       // hide any progress message

            if (Lex.Contains(messageText, "<br>")) // replace "<br>" with newlines
            {
                messageText = messageText.Replace("<br>", "\r\n");
            }

            if (Lex.CountLines(messageText) > 5)
            {
                if (width <= 0)
                {
                    width = 650;
                }
                if (height <= 0)
                {
                    height = 400;
                }
                dr = ShowWithCustomSize(messageText, titleCaption, buttons, icon, width, height);
                return(dr);
            }

            if (messageText.Length > 72 && !messageText.Contains("\r") && !messageText.Contains("\n"))
            {
                messageText = WrapText(messageText, 6000);
            }
            //icon = MessageBoxIcon.Information;
            dr = XtraMessageBox.Show(messageText, titleCaption, buttons, icon);
            return(dr);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Show Mobius system availability message
        /// </summary>
        /// <param name="messageText"></param>
        /// <param name="messageTitle"></param>
        /// <param name="icon"></param>

        public static void Show(
            string messageText,
            string messageTitle,
            MessageBoxIcon icon,
            Form parentForm)
        {
            if (!Lex.IsNullOrEmpty(ScriptLog.FileName))
            {
                ScriptLog.Message("> " + messageTitle + " - " + messageText);
            }

            if (!SS.I.Attended)
            {
                ClientLog.Message("Show: " + messageTitle + " - " + messageText);
                return;
            }

            bool error = (icon == MessageBoxIcon.Error);

            SystemAvailabilityMsg sam = new SystemAvailabilityMsg();

            sam.Text             = messageTitle;
            sam.SysAvailMsg.Text = messageText;
            MessageBoxMx.SetIconImageIndex(sam.IconImage, icon);

            if (!error && SS.I != null && SS.I.UserIniFile != null)
            {
                string dontShowMsg = SS.I.UserIniFile.Read("SystemAvailabilityMsgDontShowMsg");
                if (Lex.Eq(messageText, dontShowMsg))
                {
                    return;                                                   // if msg not to show just return
                }
                sam.DontShowAgainButton.Visible = true;
            }

            else
            {
                sam.DontShowAgainButton.Visible = false;             // hide for error
            }
            if (parentForm != null && parentForm.Visible)            // put in front of supplied form if any
            {
                sam.ShowDialog(parentForm);
            }

            else
            {
                sam.ShowDialog();
            }

            return;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Show progress message
        /// </summary>
        /// <param name="caption"></param>
        /// <param name="title"></param>
        /// <param name="allowCancel"></param>
        /// <param name="cancellingMessage"></param>

        void ShowInstance(
            string caption,
            string title,
            bool allowCancel,
            string cancellingMessage)
        {
            LastUpdateTime = TimeOfDay.Milliseconds();

            //SystemUtil.Beep(); // debug
            if (Debug)
            {
                ClientLog.Message("Progress - Show: " + caption);
            }
            //bool disabled = true; // debug
            //if (disabled) return;

            if (!SS.I.Attended)
            {
                ClientLog.Message("Show: " + caption);
                return;
            }

            if (!Lex.IsNullOrEmpty(ScriptLog.FileName))
            {
                ScriptLog.Message("Progress.Show: " + caption);
            }

            if (Lex.IsNullOrEmpty(caption))             // hide if no caption
            {
                Progress.Hide();
                return;
            }

            bool sameMessage = Visible &&
                               Text == title && Caption.Text == caption &&
                               Cancel.Enabled == allowCancel &&
                               CancellingMessage.Text == cancellingMessage;

            //if (sameMessage) return;

            if (Debug)
            {
                ClientLog.Message("Progress - Show 2");
            }

            // Adjust size of form to fit number of lines

            Size           s2  = new Size(OriginalFormSize.Width, OriginalFormSize.Height);
            LexLineMetrics llm = Lex.AnalyzeLines(caption);

            int lineCnt = (llm.LineCnt > OriginalLines) ? llm.LineCnt : OriginalLines;             // lines to display?

            int newCaptionHeight = (int)(lineCnt * (OriginalCaptionSize.Height / (OriginalLines * 1.0) + .5));

            s2.Height = OriginalFormSize.Height + (newCaptionHeight - OriginalCaptionSize.Height);

            int lineLength      = (llm.LongestLine > OriginalCharsPerLine) ? llm.LongestLine : OriginalCharsPerLine;        // longer lines?
            int newCaptionWidth = (int)(llm.LongestLine * (OriginalCaptionSize.Width / (OriginalCharsPerLine * 1.0) + .5));

            s2.Width = OriginalFormSize.Width + (newCaptionWidth - OriginalCaptionSize.Width);

            if (Height < s2.Height)
            {
                Height = s2.Height;                                 // enlarge if necessary
            }
            if (Width < s2.Width)
            {
                Width = s2.Width;
            }

            // Fill in the form

            Text                   = title;
            Caption.Text           = caption;
            Cancel.Enabled         = allowCancel;
            CancellingMessage.Text = cancellingMessage;
            Refresh();                                      // force update of dialog

            if (SessionManager.ActiveForm == GetInstance()) // if this progress form is the active form then be sure it's visible
            {
                try
                {
                    BringToFront();
                    Activate();
                    Focus();
                    //Application.DoEvents();
                    Showing = true;
                }
                catch (Exception ex)
                { ClientLog.Message("Show exception: " + DebugLog.FormatExceptionMessage(ex)); }
            }

            else if (!Showing)
            {
                try
                {
                    //CenterToScreen();
                    Form owner = OwnerFormToUse;
                    if (owner == null)
                    {
                        owner = SessionManager.ActiveForm; // if not defined get from session manager
                    }
                    Show(owner);                           // show the form, note: non-modal so we can return immediately to caller
                    Showing = true;
                }

                catch (InvalidOperationException opEx)
                {
                    ClientLog.Message("Show exception 1: " + DebugLog.FormatExceptionMessage(opEx));

                    // apparently something strange happened with focus...  Try to recover gracefully
                    Form shellForm = null;
                    foreach (Form form in Application.OpenForms)
                    {
                        Type type = form.GetType();
                        if (type.FullName == "Mobius.Client.Shell")
                        {
                            shellForm = form;
                            break;
                        }
                    }
                    if (shellForm != null && !shellForm.Visible)
                    {
                        try
                        {
                            //Instance.CenterToScreen();
                            GetInstance().Show(shellForm);
                        }
                        catch (Exception ex)
                        { ClientLog.Message("Instance.Show exception: " + DebugLog.FormatExceptionMessage(ex)); }
                    }
                }

                catch (Exception ex)                 // some other error
                {
                    string msg = "Show exception 2: ";
                    if (SessionManager.ActiveForm != null)
                    {
                        msg += "ActiveForm: " + SessionManager.ActiveForm.Text + " ";
                    }
                    msg += DebugLog.FormatExceptionMessage(ex);
                    ClientLog.Message(msg);
                }

                PerShowCancelRequestedFlag = false;
            }

            return;
        }