/* * public int AddIngredient() { * string sql = "INSERT INTO whatsfordinner.ingredient(name, measure_type) VALUES (@name, @measure_type)"; * * NpgsqlCommand command = new NpgsqlCommand(sql, conn); * command.Parameters.AddWithValue("@name", "test1"); * command.Parameters.AddWithValue("@measure_type", "test2"); * * return NonQuery(command, "whatsfordinner.ingredient"); * } * * public int AddOneTestAccount() { * string sql = "INSERT INTO accounts(username, password, email, settings, preferences) VALUES (@username, @password, @email, @settings, @preferences)"; * * NpgsqlCommand command = new NpgsqlCommand(sql, conn); * command.Parameters.AddWithValue("@username", "andrejas"); * command.Parameters.AddWithValue("@password", "drdrois"); * command.Parameters.AddWithValue("@email", "*****@*****.**"); * command.Parameters.AddWithValue("@settings", "noget med settings"); * command.Parameters.AddWithValue("@preferences", "noget med preferences"); * * return NonQuery(command, "accounts"); * } * * public int AddTwoTestAccount() { * string sql = "INSERT INTO accounts(username, password, email, settings, preferences) VALUES (@username, @password, @email, @settings, @preferences), (@username, @password, @email, @settings, @preferences)"; * * NpgsqlCommand command = new NpgsqlCommand(sql, conn); * command.Parameters.AddWithValue("@username", "andrejas"); * command.Parameters.AddWithValue("@password", "drdrois"); * command.Parameters.AddWithValue("@email", "*****@*****.**"); * command.Parameters.AddWithValue("@settings", "noget med settings"); * command.Parameters.AddWithValue("@preferences", "noget med preferences"); * * return NonQuery(command, "accounts"); * } */ public static void dbMassEntityInsert() { DBController dbc = new DBController(); dbc.AddAccount(ModelDebug.GetTestAccount()); dbc.AddIngredient(ModelDebug.GetTestIngredient()); dbc.AddRetailer(ModelDebug.GetTestRetailer()); dbc.AddRecipe(ModelDebug.GetTestRecipe()); dbc.AddComment(ModelDebug.GetTestComment()); dbc.Close(); }
public void AddIngredient(Ingredient ing) { DBController dbc = new DBController(); try { dbc.AddIngredient(ing); } catch (NpgsqlException e) { Console.WriteLine((Program.sqlDebugMessages) ? "AddIngredient: " + e.BaseMessage.ToString() : ""); WebOperationContext ctx = WebOperationContext.Current; ctx.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Conflict; ctx.OutgoingResponse.StatusDescription = e.BaseMessage; } finally { dbc.Close(); } }
public static void dbMassInsert() { DBController dbc = new DBController(); dbc.AddAccount(ModelDebug.GetTestAccount()); dbc.AddIngredient(ModelDebug.GetTestIngredient()); dbc.AddRetailer(ModelDebug.GetTestRetailer()); dbc.AddRecipe(ModelDebug.GetTestRecipe()); dbc.AddComment(ModelDebug.GetTestComment()); dbc.AddFavorises(ModelDebug.GetTestFavorises()); dbc.AddHasEaten(ModelDebug.GetTestHasEaten()); dbc.AddIngredientIn(ModelDebug.GetTestIngredientIn()); dbc.AddOffers(ModelDebug.GetTestOffers()); dbc.AddPictures(ModelDebug.GetTestPictures()); dbc.Close(); }
public static void ExcelExtractionScript() { List <string> Groceries = new List <string>(); List <string> MeasurementType = new List <string>(); List <decimal> Measure = new List <decimal>(); List <decimal> Price = new List <decimal>(); int i; string tempString; decimal tempValueOne; decimal tempValuetwo; using (StreamReader reader = new StreamReader(@"C:/Users/Casper/Dropbox/P8/gnmsnit.csv", Encoding.Default)) { string line; while ((line = reader.ReadLine()) != null) { string[] fields = line.Split(';'); Groceries.Add(fields[0]); string[] tempPrice = fields[13].Split('.'); tempValueOne = Convert.ToDecimal(tempPrice[0]); tempValuetwo = Convert.ToDecimal(tempPrice[1]) * Convert.ToDecimal(0.01); Price.Add(tempValueOne + tempValuetwo); tempString = fields[1]; var measurefields = tempString.Split(' '); if (measurefields.Count() > 1) { if (measurefields[1] == "kg") { MeasurementType.Add("gram"); decimal numVal = Convert.ToDecimal(measurefields[0]); Measure.Add(numVal * 1000); } else if (measurefields[1] == "stk") { MeasurementType.Add("stk"); decimal numVal = Convert.ToDecimal(measurefields[0]); Measure.Add(numVal); } else if (measurefields[1] == "ltr" || measurefields[1] == "ltr.") { MeasurementType.Add("Deciliter"); decimal numVal = Convert.ToDecimal(measurefields[0]); Measure.Add(numVal * 10); } else if (measurefields[1] == "g") { MeasurementType.Add("gram"); decimal numVal = Convert.ToDecimal(measurefields[0]); Measure.Add(numVal); } else { } } } } for (i = 1; i < Groceries.Count; i++) { Console.WriteLine(Groceries[i].ToString()); DBController dbc = new DBController(); dbc.AddIngredient(new Ingredient(Groceries[i], MeasurementType[i], (int)Measure[i], Price[i], false, 0.00m, false, null)); dbc.Close(); } }