/// <summary> /// Call by the button in the ListView of tasks to do /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Feed(object sender, ListViewColumnMouseEventArgs e) { ListViewItem item = e.Item; // Exactly the same than listViewTODO.SelectedItems[0] string when = item.SubItems[2].Text; if (when == "Today") { int lot_id = Int32.Parse(item.SubItems[3].Text); FormFeed form = new FormFeed(); Lot lot = db_manager.GetLotById(lot_id); double f_quantity = lot.FoodQuantity; form.Quantity = f_quantity.ToString(); form.SetTrayId(lot.TrayId.ToString()); if (form.ShowDialog() == DialogResult.OK) { double real_quantity = form.RealQantity == 0 ? lot.FoodQuantity : form.RealQantity; Task feed = new Task("Feed", form.FeedBack, DateTime.Now, real_quantity, lot_id, lot.TrayId); db_manager.AddTask(feed); UpdateTODO(); } } else { int n_when = Int32.Parse(item.SubItems[2].Text); MessageBox.Show($"This task sould be done in {n_when.ToString()} day{((n_when == 1) ? "": "s")}."); } }
/// <summary> /// Collect task. Called by the button in the ListView of tasks to do. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Collect(object sender, ListViewColumnMouseEventArgs e) { string when = e.Item.SubItems[2].Text; if (when == "Today") { FormCollect form = new FormCollect(); if (form.ShowDialog() == DialogResult.OK) { int lot_id = Int32.Parse(e.Item.SubItems[3].Text); Lot lot = db_manager.GetLotById(lot_id); lot.CollectDate = DateTime.Now; lot.ProductivityUnit = form.ProductivityUnit; lot.ProductivityWeight = form.ProductivityWeight; listViewTODO.Items[e.Item.Index].Remove(); // Remove task from ListViewTODO // Update the harvested lot in the listview foreach (ListViewItem lot_item in listViewLot.Items) { if (Int32.Parse(lot_item.SubItems[0].Text) == lot.Id) { listViewLot.Items[lot_item.Index].Remove(); // Remove the lot in the listview } } // readd the lot in the listview: AddLotListView(lot); // Update the harvested lot in the bd: db_manager.UpdateLot(lot); // Create a collect task, save and display Task collect = new Task("Collect", form.Feedback, DateTime.Now, -1, lot.Id, lot.TrayId); db_manager.AddTask(collect); AddTaskListView(collect); // The tray is now empty, so: update tray state UpdateTrayState(lot.TrayId, "Empty"); // Update the label in the listview // Add Fill task Task fill = new Task("Fill"); AddTODOListView(fill, new Lot(lot.TrayId), -1); } } else { int n_when = Int32.Parse(e.Item.SubItems[2].Text); MessageBox.Show($"This task sould be done in {n_when.ToString()} day{((n_when == 1) ? "" : "s")}."); } }
/// <summary> /// New lot task. Called by the button in the ListView of tasks to do. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void NewLot(object sender, ListViewColumnMouseEventArgs e) { ListViewItem item = e.Item; // Exactly the same than listViewTODO.SelectedItems[0] FormFill form = new FormFill(); if (form.ShowDialog() == DialogResult.OK) { string tray_id = item.SubItems[1].Text; // Find the id of the tray relative to the new lot double food_quantity = form.Quantity; // Create new lot object: int id = db_manager.GetNewLotId(); // Find the last lot + 1: this will be the id of the new lot Lot lot = new Lot(id, food_quantity, form.Clutch, form.FeedFrequency, form.BreedingTime, tray_id); // Show the lot in ListViewLot: AddLotListView(lot); // Save the lot in database: db_manager.AddLot(lot); // Update tray state UpdateTrayState(tray_id, "Active"); // Update the label in the listview // Remove Fill task listViewTODO.Items[item.Index].Remove(); // Create Fill task, save it Task fill = new Task("Fill", form.Feedback, DateTime.Now, -1, id, tray_id); db_manager.AddTask(fill); // Display finished Fill task: AddTaskListView(fill); // Create a Feed task Task feed = new Task("Feed", lot.Id, tray_id); int when_feed = lot.WhenFeed(DateTime.Today); AddTODOListView(feed, lot, when_feed); // Create a Collect task Task collect = new Task("Collect", lot.Id, tray_id); int when_collect = lot.WhenCollect(DateTime.Today); AddTODOListView(collect, lot, when_collect); } }
/// <summary> /// Call by a click on the button in the todo Listview /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ExecuteTask(object sender, ListViewColumnMouseEventArgs e) { // ListViewExtender ListViewItem item = e.Item; switch (e.Item.SubItems[0].Text) { case "Fill": // Show Fill Task dialog window: NewLot(sender, e); break; case "Feed": // Show Feed Task dialog window: Feed(sender, e); break; case "Collect": // Show Collect Task dialog window: Collect(sender, e); break; } }