public FarrowSow(int id) { InitializeComponent(); // select the sow from the database using the id passed in the constructor using (SQLiteConnection conn = new SQLiteConnection(App.FilePath)) { this.sow = conn.Table <Sow>().Where(x => x.ID == id).SingleOrDefault(); } }
public SowDetails(int id) { InitializeComponent(); editMode = false; // using the id passed to this page, select the corresponding sow from the databases using (SQLiteConnection conn = new SQLiteConnection(App.FilePath)) { this.sow = conn.Table <Sow>().Where(x => x.ID == id).SingleOrDefault(); } }
// Add Sow Button, adds a new sow to the database async void AddButtonClicked(object sender, EventArgs args) { // get user input from the form string sowno = SowNo.Text; string knickname = KnickName.Text; DateTime farrowed = SowFarrowedDate.Date; DateTime bred = SowBredDate.Date; DateTime due = bred.AddDays(113); DateTime usound = bred.AddDays(27); // TODO: determine status // if farrowed date > bred date: // status = "READY_TO_BREED" // if bred date > farrowed date: // status = "BRED" // use sow.update() instead after the sow object has been created // create a sow object with the input // leav status empty as it will be determined by sow.update() Sow sow = new Sow() { SowNo = sowno, KnickName = knickname, FarrowedDate = farrowed, BredDate = bred, DueDate = due, UltrasoundDate = usound, }; sow.DetermineStatus(); // insert sow into the database using (SQLiteConnection conn = new SQLiteConnection(App.FilePath)) { conn.CreateTable <Sow>(); int rowsAdded = conn.Insert(sow); } // return to the sows page await Navigation.PopAsync(); }
// temporary method for adding test data async void TestDataButtonClicked(object sender, EventArgs args) { // delete all sows using (SQLiteConnection conn = new SQLiteConnection(App.FilePath)) { conn.CreateTable <Sow>(); conn.CreateTable <Litter>(); conn.CreateTable <Ultrasound>(); conn.DeleteAll <Sow>(); conn.DeleteAll <Litter>(); conn.DeleteAll <Ultrasound>(); // sows with statuses that need an action Sow sow1 = new Sow() { SowNo = "4352", KnickName = "Jim" }; sow1.DetermineStatus(); Sow sow2 = new Sow() { SowNo = "4356", KnickName = "Jimbo", BredDate = DateTime.Now.AddDays(-27), Status = "PENDING_ULTRASOUND" }; Sow sow3 = new Sow() { SowNo = "4354", KnickName = "Jimmy", BredDate = DateTime.Now.AddDays(-113) }; sow3.DetermineStatus(); // sows with status's that do not need to be actions Sow sow4 = new Sow() { SowNo = "4111", KnickName = "Jarge", BredDate = DateTime.Now.AddDays(-10) }; sow4.DetermineStatus(); Sow sow5 = new Sow() { SowNo = "4222", KnickName = "Yorg", BredDate = DateTime.Now.AddDays(-30) }; sow5.DetermineStatus(); Sow sow6 = new Sow() { SowNo = "4333", KnickName = "Gark", BredDate = DateTime.Now.AddDays(-150), FarrowedDate = DateTime.Now.AddDays(-5) }; sow6.DetermineStatus(); int rowsAdded; rowsAdded = conn.Insert(sow1); rowsAdded = conn.Insert(sow2); rowsAdded = conn.Insert(sow3); rowsAdded = conn.Insert(sow4); rowsAdded = conn.Insert(sow5); rowsAdded = conn.Insert(sow6); } }