254 lines
9.5 KiB
C#
254 lines
9.5 KiB
C#
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Kindlebox
|
|
{
|
|
public partial class Launch : Form
|
|
{
|
|
BindingSource bindingSource = new BindingSource();
|
|
DataTable dtBirthdays = new DataTable();
|
|
BindingSource bindingSource1 = new BindingSource();
|
|
DataTable dtBreedings = new DataTable();
|
|
|
|
public Launch()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void bAddRabbitByPedigree_Click(object sender, EventArgs e)
|
|
{
|
|
AddRabbitPedigree addRabbitPedigree = new AddRabbitPedigree();
|
|
addRabbitPedigree.Show();
|
|
}
|
|
|
|
private void Launch_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
//---DEBUG
|
|
//Properties.Settings.Default.RabbitFile = "C:\\Users\\rory5\\Documents\\rabbits.json";
|
|
//Properties.Settings.Default.LitterFile = "C:\\Users\\rory5\\Documents\\litters.json";
|
|
//Properties.Settings.Default.BreedingFile = "C:\\Users\\rory5\\Documents\\breedings.json";
|
|
|
|
//Properties.Settings.Default.FarmName = "Whispering Wilds";
|
|
//Properties.Settings.Default.FarmStreet = "3800 Byrd Rd";
|
|
//Properties.Settings.Default.FarmCity = "Augusta";
|
|
//Properties.Settings.Default.FarmState = "GA";
|
|
//Properties.Settings.Default.FarmZIP = "30906";
|
|
|
|
//Properties.Settings.Default.FarmWWW = "www.whisperingwilds.com";
|
|
//---DEBUG
|
|
|
|
string fileName = "";
|
|
string litterFileName = "";
|
|
string breedingFileName = "";
|
|
|
|
string directoryName = "";
|
|
|
|
|
|
// Set up rabbit birthday table
|
|
dtBirthdays.Columns.Add("Farm Name");
|
|
dtBirthdays.Columns.Add("Rabbit Name");
|
|
dtBirthdays.Columns.Add("6 Month Birthday");
|
|
dtBirthdays.Columns.Add("Days Until 6 Month Birthday");
|
|
|
|
// Set up rabbit breedings table
|
|
dtBreedings.Columns.Add("Doe Name");
|
|
dtBreedings.Columns.Add("Breeding Date");
|
|
dtBreedings.Columns.Add("Estimated Birthdate");
|
|
dtBreedings.Columns.Add("Days until kindling");
|
|
|
|
|
|
fileName = Properties.Settings.Default.RabbitFile;
|
|
litterFileName = Properties.Settings.Default.LitterFile;
|
|
breedingFileName = Properties.Settings.Default.BreedingFile;
|
|
|
|
string json = System.IO.File.ReadAllText(fileName);
|
|
RabbitList.rabbits = JsonConvert.DeserializeObject<List<Rabbit>>(json);
|
|
|
|
string litterJson = System.IO.File.ReadAllText(litterFileName);
|
|
LitterList.litters = JsonConvert.DeserializeObject<List<Litter>>(litterJson);
|
|
|
|
string breedingJson = System.IO.File.ReadAllText(breedingFileName);
|
|
BreedingList.breedings = JsonConvert.DeserializeObject<List<Breeding>>(breedingJson);
|
|
|
|
FillTables();
|
|
|
|
|
|
}
|
|
|
|
private void FillTables()
|
|
{
|
|
|
|
|
|
DateTime now = DateTime.Now;
|
|
|
|
// Birthday Table
|
|
dtBirthdays.Clear();
|
|
|
|
foreach (Rabbit r in RabbitList.rabbits ?? Enumerable.Empty<Rabbit>())
|
|
{
|
|
if (r.Status == 0)
|
|
{
|
|
var rBDay = r.Birthday.Date;
|
|
DateTime endDate = new DateTime(rBDay.Year, rBDay.Month, rBDay.Day).AddMonths(6);
|
|
|
|
|
|
var age = now.Subtract(r.Birthday).Days / (365.25 / 12);
|
|
var daysTil6Mo = now.Subtract(endDate).Days * -1;
|
|
|
|
if (age < 6 && age > 4)
|
|
{
|
|
DataRow row = dtBirthdays.NewRow();
|
|
row["Farm Name"] = r.FarmName;
|
|
row["Rabbit Name"] = r.RabbitName;
|
|
row["6 Month Birthday"] = endDate.ToShortDateString();
|
|
row["Days Until 6 Month Birthday"] = daysTil6Mo;
|
|
|
|
dtBirthdays.Rows.Add(row);
|
|
}
|
|
}
|
|
}
|
|
|
|
dataGridView1.DataSource = dtBirthdays;
|
|
dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
|
|
dataGridView1.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
|
|
dataGridView1.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
|
|
dataGridView1.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
|
|
dataGridView1.Columns[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
|
|
|
for (int i = 0; i < dataGridView1.Columns.Count - 1; i++)
|
|
{
|
|
int colw = dataGridView1.Columns[i].Width;
|
|
dataGridView1.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
|
|
dataGridView1.Columns[i].Width = colw;
|
|
}
|
|
dataGridView1.Refresh();
|
|
|
|
//Breedings Table
|
|
dtBreedings.Clear();
|
|
|
|
foreach (Breeding b in BreedingList.breedings ?? Enumerable.Empty<Breeding>())
|
|
{
|
|
if (b.isActive == true)
|
|
{
|
|
var bDate = b.BreedingDate;
|
|
var bBirthdate = bDate.AddDays(30);
|
|
var daysTilBirth = now.Subtract(bBirthdate).Days * -1;
|
|
|
|
string doeName = "";
|
|
|
|
foreach (Rabbit r in RabbitList.rabbits)
|
|
{
|
|
if (r.RabbitID == b.DamID)
|
|
{
|
|
doeName = r.RabbitName; break;
|
|
}
|
|
}
|
|
|
|
DataRow dtrow = dtBreedings.NewRow();
|
|
dtrow["Doe Name"] = doeName;
|
|
dtrow["Breeding Date"] = bDate.Date.ToShortDateString();
|
|
dtrow["Estimated Birthdate"] = bBirthdate.Date.ToShortDateString();
|
|
dtrow["Days until kindling"] = daysTilBirth;
|
|
|
|
dtBreedings.Rows.Add(dtrow);
|
|
}
|
|
|
|
}
|
|
|
|
dataGridView2.DataSource = dtBreedings;
|
|
dataGridView2.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
|
|
dataGridView2.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
|
|
dataGridView2.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
|
|
dataGridView2.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
|
|
dataGridView2.Columns[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
|
|
|
for (int i = 0; i < dataGridView2.Columns.Count - 1; i++)
|
|
{
|
|
int colw = dataGridView2.Columns[i].Width;
|
|
dataGridView2.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
|
|
dataGridView2.Columns[i].Width = colw;
|
|
}
|
|
dataGridView2.Refresh();
|
|
}
|
|
|
|
private void openToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
string openFileName = "";
|
|
string openLitterFileName = "";
|
|
string openBreedingFileName = "";
|
|
|
|
if (openFileDialog1.ShowDialog() == DialogResult.OK)
|
|
{
|
|
openFileName = openFileDialog1.FileName;
|
|
|
|
openLitterFileName = Path.GetDirectoryName(openFileName) + "litters.json";
|
|
openBreedingFileName = Path.GetDirectoryName(openFileName) + "breedings.json";
|
|
|
|
Properties.Settings.Default.RabbitFile = openFileName;
|
|
Properties.Settings.Default.LitterFile = openLitterFileName;
|
|
Properties.Settings.Default.BreedingFile = openBreedingFileName;
|
|
|
|
Console.WriteLine("File opened: " + Properties.Settings.Default.RabbitFile);
|
|
|
|
string json = System.IO.File.ReadAllText(openFileName);
|
|
RabbitList.rabbits = JsonConvert.DeserializeObject<List<Rabbit>>(json);
|
|
|
|
string litterJson = System.IO.File.ReadAllText(openLitterFileName);
|
|
LitterList.litters = JsonConvert.DeserializeObject<List<Litter>>(litterJson);
|
|
|
|
string breedingJson = System.IO.File.ReadAllText(openBreedingFileName);
|
|
BreedingList.breedings = JsonConvert.DeserializeObject<List<Breeding>>(breedingJson);
|
|
}
|
|
}
|
|
|
|
private void bViewHerd_Click(object sender, EventArgs e)
|
|
{
|
|
RabbitryListByType rabbitryListByType = new RabbitryListByType("herd");
|
|
rabbitryListByType.Show();
|
|
}
|
|
|
|
private void bViewDoes_Click(object sender, EventArgs e)
|
|
{
|
|
RabbitryListByType rabbitryListByType = new RabbitryListByType("does");
|
|
rabbitryListByType.Show();
|
|
}
|
|
|
|
private void bViewBucks_Click(object sender, EventArgs e)
|
|
{
|
|
RabbitryListByType rabbitryListByType = new RabbitryListByType("bucks");
|
|
rabbitryListByType.Show();
|
|
}
|
|
|
|
private static bool IsBeforeNow(DateTime now, DateTime dateTime)
|
|
{
|
|
return dateTime.Month < now.Month
|
|
|| (dateTime.Month == now.Month && dateTime.Day < now.Day);
|
|
}
|
|
|
|
private void bAddSingleRabbit_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void Launch_Activated_1(object sender, EventArgs e)
|
|
{
|
|
FillTables();
|
|
}
|
|
|
|
private void Launch_FormClosed(object sender, FormClosedEventArgs e)
|
|
{
|
|
Application.Exit();
|
|
}
|
|
}
|
|
}
|