Skip to content

Commit

Permalink
Restore.
Browse files Browse the repository at this point in the history
  • Loading branch information
YBCA7 committed Feb 9, 2024
1 parent 5fa7796 commit 2c25169
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 41 deletions.
13 changes: 7 additions & 6 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public MainWindow()

private void Gen()
{
MyMessageBox m = new MyMessageBox();
Random random = new Random();
HashSet<int> iset = new HashSet<int>();
foreach (string str in ignt.Text.Split(' '))
Expand All @@ -53,7 +54,7 @@ private void Gen()
if (mini > maxi) (mini, maxi) = (maxi, mini);
int quai = int.TryParse(quat.Text, out int _quai) ? _quai : 1;
if (quai > maxi - mini + 1 && c.IsChecked == true) throw new NotImplementedException();
if (quai < 1 || quai > 99999) MyMessageBox.Display("Range", "The value of 'Quality' you entered is not in the valid range. Valid range: 1~99999.", this, MyMessageBoxStyles.Error);
if (quai < 1 || quai > 99999) m.Display("Range", "The value of 'Quality' you entered is not in the valid range. Valid range: 1~99999.", this, MyMessageBoxStyles.Error);
else if (quai != 1)
{
int r;
Expand All @@ -75,13 +76,13 @@ private void Gen()
rl[i] = r;
}
}
MyMessageBox.Display("Generate", $"Numbers: {string.Join(", ", rl)}.", this, Gen);
m.Display("Generate", $"Numbers: {string.Join(", ", rl)}.", this, Gen);
}
else MyMessageBox.Display("Generate", $"Number {Generate(mini, maxi, iset, random)}.", this, Gen);
else m.Display("Generate", $"Number {Generate(mini, maxi, iset, random)}.", this, Gen);
}
catch (FormatException) { MyMessageBox.Display("Check", "Please enter correct numbers.", this, MyMessageBoxStyles.Warning); }
catch (NotImplementedException) { MyMessageBox.Display("Joke", "This is not a joke.", this, MyMessageBoxStyles.Warning); }
catch (Exception ex) when (ex is OverflowException || ex is ArgumentException) { MyMessageBox.Display("Range", "The value of 'Minimum' or 'Maximum' entered is not in the valid range. Valid range: -2147483648~2147483646.", this, MyMessageBoxStyles.Error); }
catch (FormatException) { m.Display("Check", "Please enter correct numbers.", this, MyMessageBoxStyles.Warning); }
catch (NotImplementedException) { m.Display("Joke", "This is not a joke.", this, MyMessageBoxStyles.Warning); }
catch (Exception ex) when (ex is OverflowException || ex is ArgumentException) { m.Display("Range", "The value of 'Minimum' or 'Maximum' entered is not in the valid range. Valid range: -2147483648~2147483646.", this, MyMessageBoxStyles.Error); }
}

private int Generate(int min, int max, HashSet<int> iset, Random r)
Expand Down
67 changes: 32 additions & 35 deletions MyMessageBox.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,30 @@ private void SetMore(Brush start, Brush mid, Brush end)
Ani.ButtonBind(conb, start, mid, end);
}

private void Register(string title, string content, Window owner, bool co, MyMessageBoxStyles style)
private void Register(string title, string content, Window owner, bool c, MyMessageBoxStyles style)
{
switch (style)
{
case MyMessageBoxStyles.Information:
if (c) SetMore(Brushes.DeepSkyBlue, Brushes.DodgerBlue, Brushes.CornflowerBlue);
else Set(Brushes.DeepSkyBlue, Brushes.DodgerBlue, Brushes.CornflowerBlue);
break;
case MyMessageBoxStyles.Warning:
if (c) SetMore(Brushes.Orange, Brushes.DarkOrange, Brushes.Coral);
else Set(Brushes.Orange, Brushes.DarkOrange, Brushes.Coral);
break;
case MyMessageBoxStyles.Error:
if (c) SetMore(new SolidColorBrush(Color.FromRgb(255, 75, 75)), Brushes.Red, Brushes.Crimson);
else Set(new SolidColorBrush(Color.FromRgb(255, 75, 75)), Brushes.Red, Brushes.Crimson);
break;
}
Title = title;
Owner = owner;
t.Text = content;
ShowDialog();
}

public MyMessageBox()
{
InitializeComponent();
cb.ItemsSource = new int[] { 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29 };
Expand All @@ -57,36 +80,20 @@ private void Register(string title, string content, Window owner, bool co, MyMes
if (dialog.ShowDialog() == true)
{
try { File.WriteAllText(dialog.FileName, t.Text); }
catch (Exception ex) { Display("Error", $"Error message: {ex.Message}", this, MyMessageBoxStyles.Error); }
catch (Exception ex)
{
MyMessageBox m = new MyMessageBox();
m.Display("Error", $"Error message: {ex.Message}", this, MyMessageBoxStyles.Error);
}
}
};
switch (style)
{
case MyMessageBoxStyles.Information:
if (co) SetMore(Brushes.DeepSkyBlue, Brushes.DodgerBlue, Brushes.CornflowerBlue);
else Set(Brushes.DeepSkyBlue, Brushes.DodgerBlue, Brushes.CornflowerBlue);
break;
case MyMessageBoxStyles.Warning:
if (co) SetMore(Brushes.Orange, Brushes.DarkOrange, Brushes.Coral);
else Set(Brushes.Orange, Brushes.DarkOrange, Brushes.Coral);
break;
case MyMessageBoxStyles.Error:
if (co) SetMore(new SolidColorBrush(Color.FromRgb(255, 75, 75)), Brushes.Red, Brushes.Crimson);
else Set(new SolidColorBrush(Color.FromRgb(255, 75, 75)), Brushes.Red, Brushes.Crimson);
break;
}
Title = title;
Owner = owner;
t.Text = content;
}

public MyMessageBox(string title, string content, Window owner, MyMessageBoxStyles style) { Register(title, content, owner, false, style); }

public MyMessageBox(string title, string content, Window owner, Action action, MyMessageBoxStyles style)
public void Display(string title, string content, Window owner, Action action, MyMessageBoxStyles style = MyMessageBoxStyles.Information)
{
conb.Click += (s, e) => {
Close();
action();
action();
};
RowDefinition newRow = new RowDefinition { Height = new GridLength(36) };
g.RowDefinitions.Add(newRow);
Expand All @@ -97,16 +104,6 @@ public MyMessageBox(string title, string content, Window owner, Action action, M
Register(title, content, owner, true, style);
}

public static void Display(string title, string content, Window owner, Action action, MyMessageBoxStyles style = MyMessageBoxStyles.Information)
{
MyMessageBox m = new MyMessageBox(title, content, owner, action, style);
m.ShowDialog();
}

public static void Display(string title, string content, Window owner, MyMessageBoxStyles style = MyMessageBoxStyles.Information)
{
MyMessageBox m = new MyMessageBox(title, content, owner, style);
m.ShowDialog();
}
public void Display(string title, string content, Window owner, MyMessageBoxStyles style = MyMessageBoxStyles.Information) { Register(title, content, owner, false, style); }
}
}

0 comments on commit 2c25169

Please sign in to comment.