public int Create(EstimatedPrice obj) { MySqlConnection conn = new MySqlConnection(connStr); try { conn.Open(); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conn; cmd.CommandText = "INSERT INTO `EstimatedPrice`(`Estimatedtime`, `Name`) VALUES (?, ?);" + "SELECT last_insert_id();"; //cmd.Parameters.Add("?Id", MySqlDbType.Int32).Value = obj.Id; cmd.Parameters.Add("?Estimatedtime", MySqlDbType.Int32).Value = obj.estimatedTime; cmd.Parameters.Add("?Name", MySqlDbType.VarChar).Value = obj.Name; //cmd.ExecuteNonQuery(); return(Convert.ToInt32(cmd.ExecuteScalar())); } catch (Exception e) { Console.WriteLine(e.ToString()); } conn.Close(); return(-1); }
public static double CalculatePrice(EstimatedPrice estimatedPrice) { double returnPrice = 0; var json = Newtonsoft.Json.JsonConvert.SerializeObject(estimatedPrice); string url = "http://jatotalservice.slund.info/api/EstimatedPrice/CalculatePrice"; var httpWebRequest = (HttpWebRequest)WebRequest.Create(url); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; //Sending the request using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); } //Getting the response var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var returnString = streamReader.ReadToEnd().Replace('.', ','); //Converterer . til , for ellers kan den ikke konvertere returprisen ordentligt double.TryParse(returnString, out returnPrice); } return(returnPrice); }
public List <EstimatedPrice> GetAll() { MySqlConnection connection = new MySqlConnection(connStr); List <EstimatedPrice> estimatedPriceList = new List <EstimatedPrice>(); try { connection.Open(); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = connection; cmd.CommandText = "SELECT * FROM `EstimatedPrice`"; MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { EstimatedPrice estimatedPrice = new EstimatedPrice(); estimatedPrice.Id = reader.GetInt32(0); estimatedPrice.estimatedTime = reader.GetInt32(1); estimatedPrice.materials = null; estimatedPriceList.Add(estimatedPrice); } reader.Close(); } catch (Exception e) { Console.WriteLine(e.ToString()); } connection.Close(); return(estimatedPriceList); }
public EstimatedPrice Get(int id) { MySqlConnection connection = new MySqlConnection(connStr); EstimatedPrice estimatedPrice = new EstimatedPrice(); try { connection.Open(); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = connection; cmd.CommandText = "SELECT * FROM `EstimatedPrice` WHERE Id = @Id"; cmd.Parameters.Add("@Id", MySqlDbType.Int32).Value = id; MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { estimatedPrice.Id = reader.GetInt32(0); estimatedPrice.estimatedTime = reader.GetInt32(1); estimatedPrice.materials = null; } reader.Close(); } catch (Exception e) { Console.WriteLine(e.ToString()); } connection.Close(); return(estimatedPrice); }
public static void PutEstimatedPrice(EstimatedPrice estimatedPrice) { var json = Newtonsoft.Json.JsonConvert.SerializeObject(estimatedPrice); string url = "http://jatotalservice.slund.info/api/EstimatedPrice/Put"; var httpWebRequest = (HttpWebRequest)WebRequest.Create(url); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "PUT"; //Sending the request using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); } //Getting the response var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); } }
public void PostEstimatedPrice(EstimatedPrice estimatedPrice) { estimatedPrice.materials = MaterialsAmount; //Kalder EstimatedPrice service og poster Estimated price til db var didsucced = EstimatedPriceService.PostEstimatedPrice(estimatedPrice); MaterialsAmount.Clear(); }
public static bool PostEstimatedPrice(EstimatedPrice estimatedPrice) { IRestRequest request = new RestRequest("Post", Method.POST); var json = Newtonsoft.Json.JsonConvert.SerializeObject(estimatedPrice); request.AddParameter("application/json; charset=utf-8", json, ParameterType.RequestBody); request.RequestFormat = DataFormat.Json; var response = client.Execute(request); return(Convert.ToBoolean(response.Content)); }
private void CalculatePriceButtonPressed(Context context) { EstimatedPrice estimatedPrice = new EstimatedPrice(); estimatedPrice.Name = estimatedTimeName.Text; estimatedPrice.estimatedTime = estimatedTimeNumberPicker.Value; double calculatedPrice = ViewModel.CalculatePrice(estimatedPrice); Toast.MakeText(context, "Det vil koste " + calculatedPrice + "kroner", ToastLength.Long).Show(); }
public void UpdateTest() { //Arrange DBEstimatedPrice estimatedPrice = new DBEstimatedPrice(); var update = new EstimatedPrice(); update.Id = 666; update.estimatedTime = 60; update.materials = null; //Act var sucess = estimatedPrice.Update(update); //Assert Assert.IsTrue(sucess); }
public void CreateTest() { //Arrange DBEstimatedPrice estimatedPrice = new DBEstimatedPrice(); var create = new EstimatedPrice(); //create.Id = 666; create.estimatedTime = 60; create.materials = null; //Act var sucess = estimatedPrice.Create(create); //Assert Assert.AreNotEqual(-1, sucess); }
public void GetTest() { //Arrange DBEstimatedPrice estimatedPrice = new DBEstimatedPrice(); int id = 666; var expected = new EstimatedPrice(); expected.Id = 666; expected.estimatedTime = 60; expected.materials = null; //Act var sucess = estimatedPrice.Get(id); //Assert Assert.AreEqual(expected.Id, sucess.Id); Assert.AreEqual(expected.estimatedTime, sucess.estimatedTime); Assert.AreEqual(expected.materials, sucess.materials); }
public bool Update(EstimatedPrice obj) { MySqlConnection connection = new MySqlConnection(connStr); bool succes = false; try { connection.Open(); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = connection; cmd.CommandText = "UPDATE `EstimatedPrice` SET `Id`=@Id,`Estimatedtime`=@EstimatedTime WHERE Id = @Id"; cmd.Parameters.Add("@Id", MySqlDbType.Int32).Value = obj.Id; cmd.Parameters.Add("@EstimatedTime", MySqlDbType.Int32).Value = obj.estimatedTime; cmd.ExecuteNonQuery(); succes = true; } catch (Exception e) { Console.WriteLine(e.ToString()); } connection.Close(); return(false); }
public double CalculatePrice(EstimatedPrice estimatedPrice) { return(estimatedPriceController.CalculatePrice(estimatedPrice)); }
public bool Update(EstimatedPrice estimatedPrice) { return(estimatedPriceController.Update(estimatedPrice)); }
public bool Post(EstimatedPrice estimatedPrice) { return(estimatedPriceController.Create(estimatedPrice)); }
public void StartProgress(double commission) { switch (strategics) { case ScenarioAccordingToTrend st: Commission = commission > 0 ? commission : 1.5e-4; if (StartProgress(strategics.Code as string) > 0) { var price = SendMessage.Price; var estimate = EstimatedPrice.Where(o => o.Key.ToString(format.Substring(0, 6)).CompareTo(SendMessage.Date) > 0); var find = FindTheNearestQuarter(SendMessage.Date); var key = string.Concat("ST.", st.Calendar.Substring(0, 4), "15.", st.Trend, '.', st.CheckSales.ToString().Substring(0, 1), '.', st.Sales * 0x64, '.', st.CheckOperatingProfit.ToString().Substring(0, 1), '.', st.OperatingProfit * 0x64, '.', st.CheckNetIncome.ToString().Substring(0, 1), '.', st.NetIncome * 0x64); if (client.PutContext(new Catalog.Request.Consensus { Code = st.Code, Strategics = key, Date = SendMessage.Date, FirstQuarter = (estimate.Last(o => o.Key.ToString(format.Substring(0, 6)).Equals(find[0])).Value - price) / price, SecondQuarter = (estimate.Last(o => o.Key.ToString(format.Substring(0, 6)).Equals(find[1])).Value - price) / price, ThirdQuarter = (estimate.Last(o => o.Key.ToString(format.Substring(0, 6)).Equals(find[2])).Value - price) / price, Quarter = (estimate.Last(o => o.Key.ToString(format.Substring(0, 6)).Equals(find[find.Length - 2])).Value - price) / price, TheNextYear = (estimate.LastOrDefault(o => o.Key.ToString(format.Substring(0, 6)).Equals(find[find.Length - 1])).Value - price) / price, TheYearAfterNext = (estimate.Last().Value - price) / price }).Result > 0) { consecutive.Dispose(); } SendMessage = new Statistics { Base = SendMessage.Base, Cumulative = SendMessage.Cumulative, Date = SendMessage.Date, Statistic = SendMessage.Statistic, Price = (int)estimate.Max(o => o.Value), Key = key }; SendStocks?.Invoke(this, new SendHoldingStocks(EstimatedPrice, SendMessage.Date)); } break; case TrendsInStockPrices ts: Commission = commission > 0 ? commission : 1.5e-4; if (StartProgress(strategics.Code as string) > 0) { SendMessage = new Statistics { Base = SendMessage.Base, Cumulative = SendMessage.Cumulative, Date = SendMessage.Date, Statistic = SendMessage.Statistic, Key = string.Concat("TS.", ts.Short, '.', ts.Long, '.', ts.Trend, '.', (int)(ts.RealizeProfit * 0x2710), '.', (int)(ts.AdditionalPurchase * 0x2710), '.', ts.QuoteUnit, '.', (char)ts.LongShort, '.', (char)ts.TrendType, '.', (char)ts.Setting) }; consecutive.Dispose(); } break; case TrendFollowingBasicFutures _: Commission = commission > 0 ? commission : 3e-5; IsDebugging(); if (StartProgress(strategics.Code as string) > 0) { foreach (var con in Consecutive) { con.Dispose(); } } break; default: return; } SendBalance?.Invoke(this, new SendSecuritiesAPI(strategics, SendMessage)); }
public double CalculatePrice(EstimatedPrice estimatedPrice) { estimatedPrice.materials = MaterialsAmount; return(EstimatedPriceService.CalculatePrice(estimatedPrice)); }
public async Task <IActionResult> PutContext([FromBody] EstimatedPrice param) { if (await context.Catalog.AnyAsync(o => o.Strategics.Equals(param.Strategics)) == false) { var temp = param.Strategics.Split('.'); if (Enum.TryParse(temp[0], out Strategics initial)) { switch (initial) { case Strategics.ST: if (int.TryParse(temp[8], out int stNet) && int.TryParse(temp[6], out int stOp) && int.TryParse(temp[4], out int stSales) && int.TryParse(temp[2], out int stTrend) && int.TryParse(temp[1], out int calendar)) { context.Catalog.Add(new CatalogStrategics { Strategics = param.Strategics, Short = calendar, Long = stSales, Trend = stTrend, RealizeProfit = stOp * 1e-2, AdditionalPurchase = stNet * 1e-2, LongShort = temp[3], TrendType = temp[5], Setting = temp[7] }); } break; case Strategics.TS: if (int.TryParse(temp[6], out int unit) && int.TryParse(temp[5], out int purchase) && int.TryParse(temp[4], out int profit) && int.TryParse(temp[3], out int trend) && int.TryParse(temp[2], out int iLong) && int.TryParse(temp[1], out int iShort)) { context.Catalog.Add(new CatalogStrategics { Strategics = param.Strategics, Short = iShort, Long = iLong, Trend = trend, RealizeProfit = profit * 1e-4, AdditionalPurchase = purchase * 1e-4, QuoteUnit = unit, LongShort = temp[7], TrendType = temp[8], Setting = temp[9] }); } break; default: return(BadRequest()); } await context.BulkSaveChangesAsync(); } else { return(BadRequest()); } } if (await context.Estimate.AnyAsync(o => o.Code.Equals(param.Code) && o.Strategics.Equals(param.Strategics))) { context.Entry(param).State = EntityState.Modified; } else { context.Estimate.Add(param); } await context.BulkSaveChangesAsync(); return(Ok()); }