GlobalAccessSoftware icon

AppStatic.cs Public Methods ToolBox3 sample

GlobalAccessSoftware | PRO | 05/19/17 10:59:53 AM UTC | 0 ⭐ | 746 👁️ | Never ⏰ | []
C# |

12.53 KB

|

None

|

0 👍

/

0 👎

#region Other Public Static Methods
 
    /// <summary> Overloaded and multi-Use YesNoDialog is programmable.
    /// All Overloads call The Bottom Method with either a text or a title and
    /// The other is defaulted-to there.
    /// The DefaultButton is programmable as well:
    /// false tells it to default to NO, true tells it to default to YES.
    /// true is returned if YES, false if NO.
    /// Calling this Overload gives:
    /// you a default title of "User Input Required:"
    /// and a default text of "Are You Sure?
    /// and a default default-button of No.
    /// returns true if Yes, false if No.
    /// </summary>
     public static bool YesNoDialog()
    {
      return YesNoDialog("");
    }
 
    /// <summary> Overloaded and multi-Use YesNoDialog is programmable.
    /// All Overloads call The Bottom Method with either a text or a title and
    /// The other is defaulted-to there.
    /// The DefaultButton is programmable as well:
    /// false tells it to default to NO, true tells it to default to YES.
    /// true is returned if YES, false if NO.
    /// Calling this Overload gives:
    /// you a default title of "User Input Required:"
    /// and a default default-button of No.
    /// returns true if Yes, false if No.
    /// </summary>
    /// <param name="text"></param>
    /// <returns></returns>
    public static bool YesNoDialog(string text)
    {
      return YesNoDialog(text, 2);
      // defaults to default of No.
    }
 
    /// <summary> Overloaded and multi-Use YesNoDialog is programmable.
    /// All Overloads call The Bottom Method with either a text or a title and
    /// The other is defaulted-to there.
    /// The DefaultButton is programmable as well:
    /// false tells it to default to NO, true tells it to default to YES.
    /// true is returned if YES, false if NO.
    /// Calling this Overload gives:
    /// you a default title of "User Input Required:"
    /// and a default text of "Are You Sure?
    /// and a default default-button of No.
    /// returns true if Yes, false if No.
    /// </summary>
    /// <param name="text"></param>
    /// <param name="defaultButton"></param>
    /// <returns></returns>
    public static bool YesNoDialog(string text, int defaultButton)
    {
      return YesNoCancel(text, "", defaultButton, false).Equals(1);
      // defaults to this title.
    }
 
    /// <summary> Overloaded and multi-Use YesNoDialog is programmable.
    /// All Overloads call The Bottom Method with either a text or a title and
    /// The other is defaulted-to there.
    /// The DefaultButton is programmable as well:
    /// false tells it to default to NO, true tells it to default to YES.
    /// true is returned if YES, false if NO.
    /// Calling this Overload gives:
    /// you a default default-button of No.
    /// returns true if Yes, false if No.
    /// </summary>
    /// <param name="text"></param>
    /// <param name="title"></param>
    /// <returns></returns>
    public static bool YesNoDialog(string text, string title)
    {
      return YesNoDialog(text, title, 2);
      // defaults to default defaultButton of 2 = No.
    }
 
    /// <summary> Overloaded and multi-Use YesNoDialog is programmable.
    /// All Overloads call The Bottom Method with either a text or a title and
    /// The other is defaulted-to there.
    /// The DefaultButton is programmable as well:
    /// false tells it to default to NO, true tells it to default to YES.
    /// true is returned if YES, false if NO.
    /// Calling this Overload gives:
    /// you a Flexible YesNoDialog to customize.
    /// Calls YesNoCancel Overloads in the end.
    /// See YesNoCancel() Overloads for more.
    /// </summary>
    /// <param name="text"></param>
    /// <param name="title"></param>
    /// <param name="defaultButton"></param>
    /// <returns></returns>
    public static bool YesNoDialog(string text, string title, int defaultButton)
    {
      if (string.IsNullOrEmpty(text))  text  = "Are You Sure?";
      if (string.IsNullOrEmpty(title)) title = "User Input Required:";
      if (defaultButton != 1) defaultButton  = 2;
      return YesNoCancel(text, title, defaultButton, false).Equals(1);
      // Last YesNo Dialog: Defaults to the above & to YesNo Buttons.
    }
 
    /// <summary> Overloaded and multi-Use YesNoCancel is programmable.
    /// All Overloads call The Bottom Method with either a text or a title and
    /// The other is defaulted-to there.
    /// The DefaultButton is programmable as well:
    /// false tells it to default to NO, true tells it to default to YES.
    /// true is returned if YES, false if NO.
    /// Calling this Overload gives:
    /// you a default title of "User Input Required:"
    /// and a default text of "Are You Sure?
    /// and a default default-button of No.
    /// returns true if Yes, false if No.
    /// </summary>
    /// <returns></returns>
       public static int YesNoCancel()
    {
      return YesNoCancel(2);
    }
 
    /// <summary> Overloaded and multi-Use YesNoCancel is programmable.
    /// All Overloads call The Bottom Method with either a text or a title and
    /// The other is defaulted-to there.
    /// The DefaultButton is programmable as well:
    /// false tells it to default to NO, true tells it to default to YES.
    /// true is returned if YES, false if NO.
    /// Calling this Overload gives:
    /// you a default title of "User Input Required:"
    /// and a default text of "Are You Sure?
    /// returns true if Yes, false if No.
    /// </summary>
    /// <param name="defaultButton"></param>
    /// <returns></returns>
       public static int YesNoCancel(int defaultButton)
    {
      return YesNoCancel("", defaultButton);
    }
 
    /// <summary> Overloaded and multi-Use YesNoCancel is programmable.
    /// All Overloads call The Bottom Method with either a text or a title and
    /// The other is defaulted-to there.
    /// The DefaultButton is programmable as well:
    /// false tells it to default to NO, true tells it to default to YES.
    /// true is returned if YES, false if NO.
    /// Calling this Overload gives:
    /// you a default title of "User Input Required:"
    /// returns true if Yes, false if No.
    /// </summary>
    /// <param name="text"></param>
    /// <param name="defaultButton"></param>
    /// <returns></returns>
       public static int YesNoCancel(string text, int defaultButton)
    {
      return YesNoCancel(text, "", defaultButton);
    }
 
    /// <summary> Overloaded and multi-Use YesNoCancel is programmable.
    /// All Overloads call The Bottom Method with either a text or a title and
    /// The other is defaulted-to there.
    /// The DefaultButton is programmable as well:
    /// false tells it to default to NO, true tells it to default to YES.
    /// true is returned if YES, false if NO.
    /// Calling this Overload gives:
    /// you a default default-button of No.
    /// returns true if Yes, false if No.
    /// </summary>
    /// <param name="text"></param>
    /// <param name="title"></param>
    /// <returns></returns>
       public static int YesNoCancel(string text, string title)
    {
      return YesNoCancel(text, title, 2);
      // Cancel Dialog defaults to defaultButton of No.
    }
 
    /// <summary> Overloaded and multi-Use YesNoCancel is programmable.
    /// All Overloads call The Bottom Method with either a text or a title and
    /// The other is defaulted-to there.
    /// The DefaultButton is programmable as well:
    /// false tells it to default to NO, true tells it to default to YES.
    /// true is returned if YES, false if NO.
    /// Calling this Overload gives:
    /// an easy to use and customizable YesNoCancel Dialog.
    /// returns true if Yes, false if No.
    /// </summary>
    /// <param name="text"></param>
    /// <param name="title"></param>
    /// <param name="defaultButton"></param>
    /// <returns></returns>
      public static int YesNoCancel(string text, string title, int defaultButton)
    {
      if (string.IsNullOrEmpty(text))  text  = "Are You Sure?";
      if (string.IsNullOrEmpty(title)) title = "User Input Required:";
      return YesNoCancel(text, title, defaultButton, true);
      // YesNoCancel Overlaods all get true for 3 buttons.
    }
 
    /// <summary> Overloaded and multi-Use YesNoCancel is programmable.
    /// All Overloads call The Bottom Method with either a text or a title and
    /// The other is defaulted-to there.
    /// The DefaultButton is programmable as well:
    /// false tells it to default to NO, true tells it to default to YES.
    /// true is returned if YES, false if NO.
    /// Calling gives full access to all of the above defaults:
    /// and is called, in one way or the other, by all of the YesNoDialog
    /// returns true if Yes, false if No.
    /// </summary>
    /// <param name="text"></param>
    /// <param name="title"></param>
    /// <param name="defaultButton"></param>
    /// <param name="cancel"></param>
    /// <returns></returns>
    public static int YesNoCancel(string text, string title, int defaultButton, bool cancel)
    {
      var
        _default = MessageBoxDefaultButton.Button2;
      if (defaultButton.Equals(1))
        _default = MessageBoxDefaultButton.Button1;
      if (defaultButton.Equals(3))
        _default = MessageBoxDefaultButton.Button3;
      var which  = MessageBoxButtons.YesNo;
      if (cancel) which = MessageBoxButtons.YesNoCancel;
      var result = MessageBox.Show(text, title,
        which, MessageBoxIcon.Question, _default);
      if (result.Equals(DialogResult.Cancel)) return 3;
      return result.Equals(DialogResult.Yes) ? 1 : 2;
    }
#endregion Other Public Static Methods
    //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
 
// Sample Usages from Dealing with Listboxes and Collections.
      foreach
        (var path in from path in unused
                     where OPS.Default.reportsListBoxItems.IndexOf(path) >= 1
                     let text = ORS.OMA_ViewAss + "\n\nPath:\n" + path
                     where AppStatic.YesNoDialog(text, ORS.OMA_ViewAssTitle)
                     select path)
      {
        if (path.Equals(OPS.Default.PrefReportsDir))
        {
          var target =
            OPS.Default.reportsListBoxItems.IndexOf(path) + 1;
          // if Pref Adopt next in List automatically as new Pref.
          if (target == unused.Count) target = 0;
          ReportsTextBox.Text = WhatWasItB2 =
            OPS.Default.PrefReportsDir =
            OPS.Default.reportsListBoxItems[target];
          if (target < 1) continue;
        }
        OPS.Default.reportsListBoxItems.Remove(path);
      }
 
        merge = AppStatic.YesNoDialog(ORS.OMA_R1, 1);
 
    private void ClearToolStrip1MenuItemClick(object sender, EventArgs e)
    {
      var test = OPS.Default.dataListBoxItems.Count;
      if (test < 2) return; // Keep The Default.
      if (!AppStatic.YesNoDialog("Clear This Entire List?")) return;
 
      OPS.Default.dataListBoxItems.Clear();
      AddDefaultsToPathCollectionsLocal(true);
      DataTextBox.Text =
        OPS.Default.dataListBoxItems[0];
    }
 
    private void OpenToolStrip2MenuItemClick(object sender, EventArgs e)
    {
      if (OPS.Default.reportsListBoxItems.Count < 2) return;
      if (!AppStatic.YesNoDialog("Open This Folder?")) return;
      var folder = reportsListBox.SelectedItem.ToString();
      PrintMasterForm.OpenFolder(folder);
    }
 
    private void RemoveToolStrip2MenuItemClick(object sender, EventArgs e)
    {
      var item = reportsListBox.SelectedIndex;
      if (item.Equals(0))
      {
        MessageBox.Show(ORS.OF_Remove);
        return;
      }
      if (item.Equals(1))
      {
        MessageBox.Show(ORS.OF_Reselect);
        return;
      }
      if (!AppStatic.YesNoDialog(string.Format(
        "Remove this Folder from the List?\n{0}", reportsListBox.Items[item]))) return;
 
      OPS.Default.reportsListBoxItems.RemoveAt(item);
      PopulateListBoxes();
    }
 
    private void ClearToolStrip2MenuItemClick(object sender, EventArgs e)
    {
      if (OPS.Default.reportsListBoxItems.Count < 2) return;
      // ^ Keep The Default.
      if (!AppStatic.YesNoDialog("Clear This Entire List?")) return;
      OPS.Default.reportsListBoxItems.Clear();
      AddDefaultsToPathCollectionsLocal(false);
      ReportsTextBox.Text = OPS.Default.reportsListBoxItems[0];
    }
// See Dealing with Listboxes and Collections for many more examples of useage. it comes in very handy.

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎