Files
LottoProject/WindowsFormsCore/Form1.cs
2020-12-10 23:42:03 +01:00

248 lines
6.6 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WindowsFormsCore.Operations;
namespace WindowsFormsCore
{
public enum LNum
{
x1 = 1,
x2 = 2,
x3 = 3,
x4 = 4,
x5 = 5,
x6 = 6,
x7 = 7,
x8 = 8,
x9 = 9,
x10 = 10,
x11 = 11,
x12 = 12,
x13 = 13,
x14 = 14,
x15 = 15,
x16 = 16,
x17 = 17,
x18 = 18,
x19 = 19,
x20 = 20,
x21 = 21,
x22 = 22,
x23 = 23,
x24 = 24,
x25 = 25,
x26 = 26,
x27 = 27,
x28 = 28,
x29 = 29,
x30 = 30,
x31 = 31,
x32 = 32,
x33 = 33,
x34 = 34,
x35 = 35
}
public partial class Form1 : Form
{
Random rnd = new CryptoRandom(DateTime.Now.DayOfYear);
private Lotto lotto;
private List<string> clicked;
private bool clearing;
private TextBox[] txtBGrp1 = new TextBox[7];
private TextBox[] txtBGrp2 = new TextBox[7];
public Form1()
{
InitializeComponent();
lotto = new Lotto(rnd);
ClearChks();
for (int i = 0; i < txtBGrp1.Count(); i++)
{
txtBGrp1[i] = (TextBox)this.Controls["txtNr" + (i + 1).ToString()];
txtBGrp2[i] = (TextBox)this.Controls["txtNr2" + (i + 1).ToString()];
}
}
private void btnGenerate_Click(object sender, EventArgs e)
{
var ansver = lotto.RandomRad();
for (int i = 0; i < txtBGrp1.Count(); i++)
{
txtBGrp1[i].Text = ansver[i];
}
}
private string randomNum()
{
return Enum.GetName(typeof(LNum), rnd.Next((int)LNum.x1, (int)LNum.x35));
}
private void btnGenMotNr_Click(object sender, EventArgs e)
{
lblIndicator.BackColor = SystemColors.Control;
lblIndicator.Text = " ";
List<string> jmfList = new List<string>();
for (int i = 0; i < txtBGrp1.Count(); i++)
{
txtBGrp2[i].Text = string.IsNullOrEmpty(txtNr1.Text) ? "" : lotto.AntiCircularValue(int.Parse(txtBGrp1[i].Text)).ToString();
jmfList.Add(txtBGrp2[i].Text);
}
jmfList.Sort();
var prev = string.Empty;
foreach (var str in jmfList)
{
if (str == prev)
{
lblIndicator.BackColor = Color.Red;
lblIndicator.Text = str;
break;
}
prev = str;
}
}
private void btnTest_Click(object sender, EventArgs e)
{
var tstIn = decimal.Parse(txtTestIn.Text);
txtTestOut.Text = $"number for angle {tstIn} = {lotto.GetNumberByAngle(tstIn)}";
}
private void chk_CheckedChanged(object sender, EventArgs e)
{
if (!clearing)
{
var clickTxt = ((CheckBox)sender).Text;
if (clicked.Any(c => c == clickTxt))
{
clicked.Remove(clickTxt);
clicked.ToList().ForEach(x => Debug.Write($"{x},"));
Debug.WriteLine("");
}
else
{
clicked.Add(clickTxt);
}
if (clicked.Count() > 6)
{
for (int i = 0; i < 7; i++)
{
txtBGrp1[i].Text = clicked[i];
}
ClearChks();
}
}
}
private void ClearChks()
{
clearing = true;
foreach (var chk in gpbInmata.Controls)
{
if (chk.GetType() == typeof(CheckBox))
{
((CheckBox)chk).Checked = false;
}
}
clicked = new List<string>();
clearing = false;
}
private void btnClear_Click(object sender, EventArgs e)
{
ClearChks();
gpbInmata.Refresh();
}
private void Text_TextChanged(object sender, EventArgs e)
{
var n = 0;
var nochange = false;
if (!int.TryParse(((TextBox)sender).Text, out n))
{
if (nochange)
{
nochange = false;
return;
}
var lngd = ((TextBox)sender).Text.Length;
if (lngd > 1)
{
var repl = ((TextBox)sender).Text.Substring(0, lngd - 1);
((TextBox)sender).Text = repl;
((TextBox)sender).SelectionStart = lngd-1;
((TextBox)sender).SelectionLength = 0;
}
else ((TextBox)sender).Text = string.Empty;
nochange = true;
}
}
private void Text_TextChanged(object sender, KeyEventArgs e)
{
var n = 0;
if (!int.TryParse(((TextBox)sender).Text, out n))
{
var lngd = ((TextBox)sender).Text.Length;
((TextBox)sender).Text = ((TextBox)sender).Text.Substring(0, lngd - 1);
}
}
private void AddNumbersToList1()
{
if(txtBGrp1.Any(tx => tx.Text.Length == 0))
{
return;
}
ListViewItem lvRow = new ListViewItem(txtBGrp1[0].Text);
for(int i = 1; i < txtBGrp1.Length;i++)
{
lvRow.SubItems.Add(txtBGrp1[i].Text);
}
lvRows.Items.Add(lvRow);
}
private void AddNumbersToList2()
{
if (txtBGrp2.Any(tx => tx.Text.Length == 0))
{
return;
}
ListViewItem lvRow = new ListViewItem(txtBGrp2[0].Text);
for (int i = 1; i < txtBGrp2.Length; i++)
{
lvRow.SubItems.Add(txtBGrp2[i].Text);
}
lvRows.Items.Add(lvRow);
}
private void btnDwn_Click(object sender, EventArgs e)
{
AddNumbersToList1();
}
private void btnDown2_Click(object sender, EventArgs e)
{
AddNumbersToList2();
}
}
}