public int addNewFertiliser(Fertiliser fertiliser) { MySqlCommand sqlComm = new MySqlCommand("INSERT INTO" + " fertiliser(name, quantity_kg, remark)" + " VALUES" + " (@name, @quantity_kg, @remark)", MysqlDbc.Instance.getConn()); sqlComm.Parameters.Add("@name", MySqlDbType.Text).Value = fertiliser.Name; sqlComm.Parameters.Add("@quantity_kg", MySqlDbType.UInt32).Value = fertiliser.Quantity_kg; sqlComm.Parameters.Add("@remark", MySqlDbType.Text).Value = fertiliser.Remark; return(sqlComm.ExecuteNonQuery()); }
public int updateFertiliser(Fertiliser fertiliser) { string query = "UPDATE" + " fertiliser SET name=@name, quantity_kg=@quantity_kg, remark=@remark " + "WHERE id = " + fertiliser.Id; MySqlCommand sqlComm = new MySqlCommand(query, MysqlDbc.Instance.getConn()); sqlComm.Parameters.Add("@name", MySqlDbType.Text).Value = fertiliser.Name; sqlComm.Parameters.Add("@quantity_kg", MySqlDbType.UInt32).Value = fertiliser.Quantity_kg; sqlComm.Parameters.Add("@remark", MySqlDbType.Text).Value = fertiliser.Remark; return(sqlComm.ExecuteNonQuery()); }
public void AddNewFertiliser() { DbConnector dbconn = new DbConnector(); string resp = dbconn.connect(); Assert.AreEqual("Done", resp); Fertiliser fert = new Fertiliser(); fert.FertiliserType = "Urea"; fert.FertiliserQuantity = 30.00M; fert.FertiliserCompany = "Just Good Turds"; FertiliserHandler fertHandlr = new FertiliserHandler(); int resp2 = fertHandlr.addNewFertiliser(dbconn.getConn(), fert); Assert.AreEqual(1, resp2); }
public void Fertiliser_EnsureApplyWorks() { // Create a tree with a root node for our models. Simulation simulation = new Simulation(); Clock clock = new Clock(); clock.StartDate = new DateTime(2015, 1, 1); clock.EndDate = new DateTime(2015, 1, 1); simulation.Children.Add(clock); MockSummary summary = new MockSummary(); simulation.Children.Add(summary); MockSoil soil = new MockSoil(); soil.Thickness = new double[] { 100, 100, 100 }; soil.NO3 = new double[] { 1, 2, 3 }; simulation.Children.Add(soil); Fertiliser fertiliser = new Fertiliser(); fertiliser.Name = "Fertilise"; simulation.Children.Add(fertiliser); Operations operations = new Operations(); Operation fertiliseOperation = new Operation(); fertiliseOperation.Date = "1-jan"; fertiliseOperation.Action = "[Fertilise].Apply(Amount: 100, Type:Fertiliser.Types.NO3N, Depth:300)"; operations.Schedule = new List <Operation>(); operations.Schedule.Add(fertiliseOperation); simulation.Children.Add(operations); simulation.Children.Add(new SoluteManager()); ISimulationEngine simulationEngine = Simulations.Create(new Model[] { simulation }); simulationEngine.Run(simulation, doClone: false); Assert.AreEqual(soil.NO3, new double[] { 1, 2, 103 }); Assert.AreEqual(MockSummary.messages[0], "100 kg/ha of NO3N added at depth 300 layer 3"); }
public List <Fertiliser> GetFertiliserList() //string employee_id { List <Fertiliser> fertiliserLists = new List <Fertiliser>(); MySqlDataReader rdr = null; try { string stm = "SELECT * FROM fertiliser"; MySqlCommand cmd = new MySqlCommand(stm, MysqlDbc.Instance.getConn()); rdr = cmd.ExecuteReader(); while (rdr.Read()) { Fertiliser sj1 = new Fertiliser(); sj1.Id = rdr.GetInt32("id");; sj1.Name = rdr.GetString("name"); sj1.Quantity_kg = rdr.GetInt32("quantity_kg"); sj1.Remark = rdr.GetString("remark"); fertiliserLists.Add(sj1); } } catch (MySqlException ex) { Console.WriteLine("Error: {0}", ex.ToString()); } finally { if (rdr != null) { rdr.Close(); } } return(fertiliserLists); }