Advertisement
GlobalAccessSoftware

AppStatic.cs Public Methods ToolBox3 sample

May 19th, 2017
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 12.53 KB | None | 0 0
  1. #region Other Public Static Methods
  2.  
  3.     /// <summary> Overloaded and multi-Use YesNoDialog is programmable.
  4.     /// All Overloads call The Bottom Method with either a text or a title and
  5.     /// The other is defaulted-to there.
  6.     /// The DefaultButton is programmable as well:
  7.     /// false tells it to default to NO, true tells it to default to YES.
  8.     /// true is returned if YES, false if NO.
  9.     /// Calling this Overload gives:
  10.     /// you a default title of "User Input Required:"
  11.     /// and a default text of "Are You Sure?
  12.     /// and a default default-button of No.
  13.     /// returns true if Yes, false if No.
  14.     /// </summary>
  15.      public static bool YesNoDialog()
  16.     {
  17.       return YesNoDialog("");
  18.     }
  19.  
  20.     /// <summary> Overloaded and multi-Use YesNoDialog is programmable.
  21.     /// All Overloads call The Bottom Method with either a text or a title and
  22.     /// The other is defaulted-to there.
  23.     /// The DefaultButton is programmable as well:
  24.     /// false tells it to default to NO, true tells it to default to YES.
  25.     /// true is returned if YES, false if NO.
  26.     /// Calling this Overload gives:
  27.     /// you a default title of "User Input Required:"
  28.     /// and a default default-button of No.
  29.     /// returns true if Yes, false if No.
  30.     /// </summary>
  31.     /// <param name="text"></param>
  32.     /// <returns></returns>
  33.     public static bool YesNoDialog(string text)
  34.     {
  35.       return YesNoDialog(text, 2);
  36.       // defaults to default of No.
  37.     }
  38.  
  39.     /// <summary> Overloaded and multi-Use YesNoDialog is programmable.
  40.     /// All Overloads call The Bottom Method with either a text or a title and
  41.     /// The other is defaulted-to there.
  42.     /// The DefaultButton is programmable as well:
  43.     /// false tells it to default to NO, true tells it to default to YES.
  44.     /// true is returned if YES, false if NO.
  45.     /// Calling this Overload gives:
  46.     /// you a default title of "User Input Required:"
  47.     /// and a default text of "Are You Sure?
  48.     /// and a default default-button of No.
  49.     /// returns true if Yes, false if No.
  50.     /// </summary>
  51.     /// <param name="text"></param>
  52.     /// <param name="defaultButton"></param>
  53.     /// <returns></returns>
  54.     public static bool YesNoDialog(string text, int defaultButton)
  55.     {
  56.       return YesNoCancel(text, "", defaultButton, false).Equals(1);
  57.       // defaults to this title.
  58.     }
  59.  
  60.     /// <summary> Overloaded and multi-Use YesNoDialog is programmable.
  61.     /// All Overloads call The Bottom Method with either a text or a title and
  62.     /// The other is defaulted-to there.
  63.     /// The DefaultButton is programmable as well:
  64.     /// false tells it to default to NO, true tells it to default to YES.
  65.     /// true is returned if YES, false if NO.
  66.     /// Calling this Overload gives:
  67.     /// you a default default-button of No.
  68.     /// returns true if Yes, false if No.
  69.     /// </summary>
  70.     /// <param name="text"></param>
  71.     /// <param name="title"></param>
  72.     /// <returns></returns>
  73.     public static bool YesNoDialog(string text, string title)
  74.     {
  75.       return YesNoDialog(text, title, 2);
  76.       // defaults to default defaultButton of 2 = No.
  77.     }
  78.  
  79.     /// <summary> Overloaded and multi-Use YesNoDialog is programmable.
  80.     /// All Overloads call The Bottom Method with either a text or a title and
  81.     /// The other is defaulted-to there.
  82.     /// The DefaultButton is programmable as well:
  83.     /// false tells it to default to NO, true tells it to default to YES.
  84.     /// true is returned if YES, false if NO.
  85.     /// Calling this Overload gives:
  86.     /// you a Flexible YesNoDialog to customize.
  87.     /// Calls YesNoCancel Overloads in the end.
  88.     /// See YesNoCancel() Overloads for more.
  89.     /// </summary>
  90.     /// <param name="text"></param>
  91.     /// <param name="title"></param>
  92.     /// <param name="defaultButton"></param>
  93.     /// <returns></returns>
  94.     public static bool YesNoDialog(string text, string title, int defaultButton)
  95.     {
  96.       if (string.IsNullOrEmpty(text))  text  = "Are You Sure?";
  97.       if (string.IsNullOrEmpty(title)) title = "User Input Required:";
  98.       if (defaultButton != 1) defaultButton  = 2;
  99.       return YesNoCancel(text, title, defaultButton, false).Equals(1);
  100.       // Last YesNo Dialog: Defaults to the above & to YesNo Buttons.
  101.     }
  102.  
  103.     /// <summary> Overloaded and multi-Use YesNoCancel is programmable.
  104.     /// All Overloads call The Bottom Method with either a text or a title and
  105.     /// The other is defaulted-to there.
  106.     /// The DefaultButton is programmable as well:
  107.     /// false tells it to default to NO, true tells it to default to YES.
  108.     /// true is returned if YES, false if NO.
  109.     /// Calling this Overload gives:
  110.     /// you a default title of "User Input Required:"
  111.     /// and a default text of "Are You Sure?
  112.     /// and a default default-button of No.
  113.     /// returns true if Yes, false if No.
  114.     /// </summary>
  115.     /// <returns></returns>
  116.        public static int YesNoCancel()
  117.     {
  118.       return YesNoCancel(2);
  119.     }
  120.  
  121.     /// <summary> Overloaded and multi-Use YesNoCancel is programmable.
  122.     /// All Overloads call The Bottom Method with either a text or a title and
  123.     /// The other is defaulted-to there.
  124.     /// The DefaultButton is programmable as well:
  125.     /// false tells it to default to NO, true tells it to default to YES.
  126.     /// true is returned if YES, false if NO.
  127.     /// Calling this Overload gives:
  128.     /// you a default title of "User Input Required:"
  129.     /// and a default text of "Are You Sure?
  130.     /// returns true if Yes, false if No.
  131.     /// </summary>
  132.     /// <param name="defaultButton"></param>
  133.     /// <returns></returns>
  134.        public static int YesNoCancel(int defaultButton)
  135.     {
  136.       return YesNoCancel("", defaultButton);
  137.     }
  138.  
  139.     /// <summary> Overloaded and multi-Use YesNoCancel is programmable.
  140.     /// All Overloads call The Bottom Method with either a text or a title and
  141.     /// The other is defaulted-to there.
  142.     /// The DefaultButton is programmable as well:
  143.     /// false tells it to default to NO, true tells it to default to YES.
  144.     /// true is returned if YES, false if NO.
  145.     /// Calling this Overload gives:
  146.     /// you a default title of "User Input Required:"
  147.     /// returns true if Yes, false if No.
  148.     /// </summary>
  149.     /// <param name="text"></param>
  150.     /// <param name="defaultButton"></param>
  151.     /// <returns></returns>
  152.        public static int YesNoCancel(string text, int defaultButton)
  153.     {
  154.       return YesNoCancel(text, "", defaultButton);
  155.     }
  156.  
  157.     /// <summary> Overloaded and multi-Use YesNoCancel is programmable.
  158.     /// All Overloads call The Bottom Method with either a text or a title and
  159.     /// The other is defaulted-to there.
  160.     /// The DefaultButton is programmable as well:
  161.     /// false tells it to default to NO, true tells it to default to YES.
  162.     /// true is returned if YES, false if NO.
  163.     /// Calling this Overload gives:
  164.     /// you a default default-button of No.
  165.     /// returns true if Yes, false if No.
  166.     /// </summary>
  167.     /// <param name="text"></param>
  168.     /// <param name="title"></param>
  169.     /// <returns></returns>
  170.        public static int YesNoCancel(string text, string title)
  171.     {
  172.       return YesNoCancel(text, title, 2);
  173.       // Cancel Dialog defaults to defaultButton of No.
  174.     }
  175.  
  176.     /// <summary> Overloaded and multi-Use YesNoCancel is programmable.
  177.     /// All Overloads call The Bottom Method with either a text or a title and
  178.     /// The other is defaulted-to there.
  179.     /// The DefaultButton is programmable as well:
  180.     /// false tells it to default to NO, true tells it to default to YES.
  181.     /// true is returned if YES, false if NO.
  182.     /// Calling this Overload gives:
  183.     /// an easy to use and customizable YesNoCancel Dialog.
  184.     /// returns true if Yes, false if No.
  185.     /// </summary>
  186.     /// <param name="text"></param>
  187.     /// <param name="title"></param>
  188.     /// <param name="defaultButton"></param>
  189.     /// <returns></returns>
  190.       public static int YesNoCancel(string text, string title, int defaultButton)
  191.     {
  192.       if (string.IsNullOrEmpty(text))  text  = "Are You Sure?";
  193.       if (string.IsNullOrEmpty(title)) title = "User Input Required:";
  194.       return YesNoCancel(text, title, defaultButton, true);
  195.       // YesNoCancel Overlaods all get true for 3 buttons.
  196.     }
  197.  
  198.     /// <summary> Overloaded and multi-Use YesNoCancel is programmable.
  199.     /// All Overloads call The Bottom Method with either a text or a title and
  200.     /// The other is defaulted-to there.
  201.     /// The DefaultButton is programmable as well:
  202.     /// false tells it to default to NO, true tells it to default to YES.
  203.     /// true is returned if YES, false if NO.
  204.     /// Calling gives full access to all of the above defaults:
  205.     /// and is called, in one way or the other, by all of the YesNoDialog
  206.     /// returns true if Yes, false if No.
  207.     /// </summary>
  208.     /// <param name="text"></param>
  209.     /// <param name="title"></param>
  210.     /// <param name="defaultButton"></param>
  211.     /// <param name="cancel"></param>
  212.     /// <returns></returns>
  213.     public static int YesNoCancel(string text, string title, int defaultButton, bool cancel)
  214.     {
  215.       var
  216.         _default = MessageBoxDefaultButton.Button2;
  217.       if (defaultButton.Equals(1))
  218.         _default = MessageBoxDefaultButton.Button1;
  219.       if (defaultButton.Equals(3))
  220.         _default = MessageBoxDefaultButton.Button3;
  221.       var which  = MessageBoxButtons.YesNo;
  222.       if (cancel) which = MessageBoxButtons.YesNoCancel;
  223.       var result = MessageBox.Show(text, title,
  224.         which, MessageBoxIcon.Question, _default);
  225.       if (result.Equals(DialogResult.Cancel)) return 3;
  226.       return result.Equals(DialogResult.Yes) ? 1 : 2;
  227.     }
  228. #endregion Other Public Static Methods
  229.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  230.  
  231. // Sample Usages from Dealing with Listboxes and Collections.
  232.       foreach
  233.         (var path in from path in unused
  234.                      where OPS.Default.reportsListBoxItems.IndexOf(path) >= 1
  235.                      let text = ORS.OMA_ViewAss + "\n\nPath:\n" + path
  236.                      where AppStatic.YesNoDialog(text, ORS.OMA_ViewAssTitle)
  237.                      select path)
  238.       {
  239.         if (path.Equals(OPS.Default.PrefReportsDir))
  240.         {
  241.           var target =
  242.             OPS.Default.reportsListBoxItems.IndexOf(path) + 1;
  243.           // if Pref Adopt next in List automatically as new Pref.
  244.           if (target == unused.Count) target = 0;
  245.           ReportsTextBox.Text = WhatWasItB2 =
  246.             OPS.Default.PrefReportsDir =
  247.             OPS.Default.reportsListBoxItems[target];
  248.           if (target < 1) continue;
  249.         }
  250.         OPS.Default.reportsListBoxItems.Remove(path);
  251.       }
  252.  
  253.         merge = AppStatic.YesNoDialog(ORS.OMA_R1, 1);
  254.  
  255.     private void ClearToolStrip1MenuItemClick(object sender, EventArgs e)
  256.     {
  257.       var test = OPS.Default.dataListBoxItems.Count;
  258.       if (test < 2) return; // Keep The Default.
  259.       if (!AppStatic.YesNoDialog("Clear This Entire List?")) return;
  260.  
  261.       OPS.Default.dataListBoxItems.Clear();
  262.       AddDefaultsToPathCollectionsLocal(true);
  263.       DataTextBox.Text =
  264.         OPS.Default.dataListBoxItems[0];
  265.     }
  266.  
  267.     private void OpenToolStrip2MenuItemClick(object sender, EventArgs e)
  268.     {
  269.       if (OPS.Default.reportsListBoxItems.Count < 2) return;
  270.       if (!AppStatic.YesNoDialog("Open This Folder?")) return;
  271.       var folder = reportsListBox.SelectedItem.ToString();
  272.       PrintMasterForm.OpenFolder(folder);
  273.     }
  274.  
  275.     private void RemoveToolStrip2MenuItemClick(object sender, EventArgs e)
  276.     {
  277.       var item = reportsListBox.SelectedIndex;
  278.       if (item.Equals(0))
  279.       {
  280.         MessageBox.Show(ORS.OF_Remove);
  281.         return;
  282.       }
  283.       if (item.Equals(1))
  284.       {
  285.         MessageBox.Show(ORS.OF_Reselect);
  286.         return;
  287.       }
  288.       if (!AppStatic.YesNoDialog(string.Format(
  289.         "Remove this Folder from the List?\n{0}", reportsListBox.Items[item]))) return;
  290.  
  291.       OPS.Default.reportsListBoxItems.RemoveAt(item);
  292.       PopulateListBoxes();
  293.     }
  294.  
  295.     private void ClearToolStrip2MenuItemClick(object sender, EventArgs e)
  296.     {
  297.       if (OPS.Default.reportsListBoxItems.Count < 2) return;
  298.       // ^ Keep The Default.
  299.       if (!AppStatic.YesNoDialog("Clear This Entire List?")) return;
  300.       OPS.Default.reportsListBoxItems.Clear();
  301.       AddDefaultsToPathCollectionsLocal(false);
  302.       ReportsTextBox.Text = OPS.Default.reportsListBoxItems[0];
  303.     }
  304. // See Dealing with Listboxes and Collections for many more examples of useage. it comes in very handy.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement