private static void ReSupplyLoop(List <Products> products, List <Cart> cart) {//allows user to add objects to products and loopd unitl user request Console.WriteLine("Press any key store or type 'y' to stock items"); string Supplier = Validators.ValidateString(Console.ReadLine()); //Supplier = Validators.YesOrNo(Supplier); string SupplyContinue; if (Supplier == "y") { SupplyContinue = "y"; } else { SupplyContinue = "n"; } while (SupplyContinue == "y") { if (Supplier == "y") { PrintInfo(products); Console.WriteLine(); Console.WriteLine($"What item are you resupplying? (1 - {products.Count}) or type {products.Count + 1} to add new item"); int SupplyItem = Validators.ValidateInt(Console.ReadLine()); SupplyItem = Validators.IsSupplyOption(SupplyItem, products); if (SupplyItem == products.Count + 1) { string NewName, NewDescription, NewTitle; double NewPrice; int NewQuantity; TakeNewInput(out NewName, out NewDescription, out NewTitle, out NewPrice, out NewQuantity); AddNewProduct(products, NewName, NewDescription, NewTitle, NewPrice, NewQuantity); AddNewCart(cart, NewName, NewPrice); //writes new item to datainput file StreamWriter wr = new StreamWriter("../../DataInput.txt", true); wr.WriteLine(); wr.Write($"{NewName},{NewDescription},{NewTitle},81818181,{NewPrice.ToString()},{NewQuantity.ToString()}"); wr.Close(); } else { PrintHeadersOne(); products[SupplyItem - 1].PrintInfo1(); Console.WriteLine(); Console.WriteLine("How many are you adding to store? (Max 15)"); int ReSupplyQuant = Validators.ValidateInt(Console.ReadLine()); ReSupplyQuant = Validators.IsReSupplyOption(ReSupplyQuant, products[SupplyItem - 1]); products[SupplyItem - 1].Quantity = products[SupplyItem - 1].Quantity + ReSupplyQuant; } } Console.WriteLine("Would you like to add more items? (y/n)"); SupplyContinue = Validators.ValidateString(Console.ReadLine()); SupplyContinue = Validators.YesOrNo(SupplyContinue); } Console.Clear(); }
public override bool Equals(object obj) { return(CategoryName.Equals(((Product)obj).CategoryName) && SubcategoryName.Equals(((Product)obj).SubcategoryName) && /*ImgHref.Equals(((Product)obj).ImgHref) &&*/ Title.Equals(((Product)obj).Title) && (NonDiscountPrice.Equals(((Product)obj).NonDiscountPrice)? true: (OldPrice.Equals(((Product)obj).OldPrice) && NewPrice.Equals(((Product)obj).NewPrice) && DiscountOff.Equals((((Product)obj).DiscountOff))))); }
public string Delete(string userId, NewPrice x) { try { SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userId, dataBase)); connection.Open(); string sql = @"BEGIN; DELETE FROM prices WHERE id = @id; COMMIT;"; SQLiteCommand command = new SQLiteCommand(sql, connection); command.Parameters.Add(new SQLiteParameter("id", x.id)); command.ExecuteNonQuery(); connection.Close(); return("ok"); } catch (Exception e) { return("Error: " + e); } }
private bool Check(string userId, NewPrice x) { try { bool result = false; SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userId, dataBase)); connection.Open(); string sql = string.Format(@"SELECT EXISTS (SELECT id FROM prices WHERE LOWER(food) = '{0}')", x.food.title.ToLower()); SQLiteCommand command = new SQLiteCommand(sql, connection); SQLiteDataReader reader = command.ExecuteReader(); while (reader.Read()) { result = reader.GetBoolean(0); } connection.Close(); return(result); } catch (Exception e) { return(false); } }
public string Save(string userId, NewPrice x) { try { //db.CreateDataBase(userId, db.prices); if (string.IsNullOrEmpty(x.id)) { if (Check(userId, x)) { return(JsonConvert.SerializeObject("the price for this food already exists", Formatting.None)); } x.id = Guid.NewGuid().ToString(); } else { x.netPrice.value = x.unitPrice.value; x.mass.value = 1000; } using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userId, dataBase))) { connection.Open(); string sql = @"BEGIN; INSERT OR REPLACE INTO prices (id, foodId, food, netPrice, currency, mass, unit, unitPrice, note) VALUES (@id, @foodId, @food, @netPrice, @currency, @mass, @unit, @unitPrice, @note); COMMIT;"; using (SQLiteCommand command = new SQLiteCommand(sql, connection)) { command.Parameters.Add(new SQLiteParameter("id", x.id)); command.Parameters.Add(new SQLiteParameter("foodId", x.food.id)); command.Parameters.Add(new SQLiteParameter("food", x.food.title)); command.Parameters.Add(new SQLiteParameter("netPrice", x.netPrice.value)); command.Parameters.Add(new SQLiteParameter("currency", x.netPrice.currency)); command.Parameters.Add(new SQLiteParameter("mass", x.mass.value)); command.Parameters.Add(new SQLiteParameter("unit", x.mass.unit)); command.Parameters.Add(new SQLiteParameter("unitPrice", x.unitPrice.value)); command.Parameters.Add(new SQLiteParameter("note", x.note)); command.ExecuteNonQuery(); } } return(JsonConvert.SerializeObject("saved", Formatting.None)); } catch (Exception e) { L.SendErrorLog(e, x.id, userId, "Prices", "Save"); return(JsonConvert.SerializeObject(e.Message, Formatting.None)); } }
/// <summary> /// 修改价格 /// </summary> public void ChangePrice() { if (this.NewPrice == "") { this.NewPrice = "0"; } else { double price = 0; if (!double.TryParse(NewPrice, out price)) { this.NewPrice = "0"; } if (!NewPrice.EndsWith(".")) { this.NewPrice = Math.Round(price, 2).ToString(); } } }
private NewPrice GetData(SQLiteDataReader reader) { NewPrice x = new NewPrice(); x.id = reader.GetValue(0) == DBNull.Value ? "" : reader.GetString(0); x.food = new IdTitle(); x.food.id = reader.GetValue(1) == DBNull.Value ? "" : reader.GetString(1); x.food.title = reader.GetValue(2) == DBNull.Value ? "" : reader.GetString(2); x.netPrice = new ValueCurrency(); x.netPrice.value = reader.GetValue(3) == DBNull.Value ? 0.0 : Convert.ToDouble(reader.GetString(3)); x.netPrice.currency = reader.GetValue(4) == DBNull.Value ? "" : reader.GetString(4); x.mass = new ValueUnit(); x.mass.value = reader.GetValue(5) == DBNull.Value ? 1 : reader.GetInt32(5); x.mass.unit = reader.GetValue(6) == DBNull.Value ? "" : reader.GetString(6); x.unitPrice = new UnitPrice(); x.unitPrice.value = reader.GetValue(7) == DBNull.Value ? 0.0 : Convert.ToDouble(reader.GetString(7)); x.unitPrice.currency = reader.GetValue(4) == DBNull.Value ? "" : reader.GetString(4); x.unitPrice.unit = reader.GetValue(6) == DBNull.Value ? "" : reader.GetString(6); x.note = reader.GetValue(8) == DBNull.Value ? "" : reader.GetString(8); return(x); }
public string Init() { NewPrice x = new NewPrice(); x.id = null; x.food = new IdTitle(); x.food.id = null; x.food.title = null; x.netPrice = new ValueCurrency(); x.netPrice.value = 0.0; x.netPrice.currency = null; x.mass = new ValueUnit(); x.mass.value = 1000; x.mass.unit = "g"; x.unitPrice = new UnitPrice(); x.unitPrice.value = 0.0; x.unitPrice.currency = null; x.unitPrice.unit = "g"; x.note = null; return(JsonConvert.SerializeObject(x, Formatting.None)); }
public string Load(string userId) { try { SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userId, dataBase)); connection.Open(); string sql = @"SELECT id, foodId, food, netPrice, currency, mass, unit, unitPrice, note FROM prices ORDER BY food ASC"; SQLiteCommand command = new SQLiteCommand(sql, connection); List <NewPrice> xx = new List <NewPrice>(); SQLiteDataReader reader = command.ExecuteReader(); while (reader.Read()) { NewPrice x = new NewPrice(); x.id = reader.GetValue(0) == DBNull.Value ? "" : reader.GetString(0); x.food = new IdTitle(); x.food.id = reader.GetValue(1) == DBNull.Value ? "" : reader.GetString(1); x.food.title = reader.GetValue(2) == DBNull.Value ? "" : reader.GetString(2); x.netPrice = new ValueCurrency(); x.netPrice.value = reader.GetValue(3) == DBNull.Value ? 0.0 : Convert.ToDouble(reader.GetString(3)); x.netPrice.currency = reader.GetValue(4) == DBNull.Value ? "" : reader.GetString(4); x.mass = new ValueUnit(); x.mass.value = reader.GetValue(5) == DBNull.Value ? 1 : reader.GetInt32(5); x.mass.unit = reader.GetValue(6) == DBNull.Value ? "" : reader.GetString(6); x.unitPrice = new UnitPrice(); x.unitPrice.value = reader.GetValue(7) == DBNull.Value ? 0.0 : Convert.ToDouble(reader.GetString(7)); x.unitPrice.currency = reader.GetValue(4) == DBNull.Value ? "" : reader.GetString(4); x.unitPrice.unit = reader.GetValue(6) == DBNull.Value ? "" : reader.GetString(6); x.note = reader.GetValue(8) == DBNull.Value ? "" : reader.GetString(8); xx.Add(x); } connection.Close(); string json = JsonConvert.SerializeObject(xx, Formatting.None); return(json); } catch (Exception e) { return("Error: " + e); } }
protected void RaiseNewPrice(PriceItem item) { NewPrice?.Invoke(this, new NewPriceEventArgs(item)); }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = 41; // Suitable nullity checks etc, of course :) if (Upc != null) { hashCode = hashCode * 59 + Upc.GetHashCode(); } if (Ean != null) { hashCode = hashCode * 59 + Ean.GetHashCode(); } if (Isbn != null) { hashCode = hashCode * 59 + Isbn.GetHashCode(); } if (Asin != null) { hashCode = hashCode * 59 + Asin.GetHashCode(); } if (Title != null) { hashCode = hashCode * 59 + Title.GetHashCode(); } if (Sku != null) { hashCode = hashCode * 59 + Sku.GetHashCode(); } if (Mpn != null) { hashCode = hashCode * 59 + Mpn.GetHashCode(); } if (PartNumber != null) { hashCode = hashCode * 59 + PartNumber.GetHashCode(); } if (Upcs != null) { hashCode = hashCode * 59 + Upcs.GetHashCode(); } if (Description != null) { hashCode = hashCode * 59 + Description.GetHashCode(); } if (Brand != null) { hashCode = hashCode * 59 + Brand.GetHashCode(); } if (Manufacturer != null) { hashCode = hashCode * 59 + Manufacturer.GetHashCode(); } if (Color != null) { hashCode = hashCode * 59 + Color.GetHashCode(); } hashCode = hashCode * 59 + NewPrice.GetHashCode(); hashCode = hashCode * 59 + UsedPrice.GetHashCode(); if (CurrencyCode != null) { hashCode = hashCode * 59 + CurrencyCode.GetHashCode(); } if (Url != null) { hashCode = hashCode * 59 + Url.GetHashCode(); } if (Features != null) { hashCode = hashCode * 59 + Features.GetHashCode(); } if (Dimensions != null) { hashCode = hashCode * 59 + Dimensions.GetHashCode(); } if (Images != null) { hashCode = hashCode * 59 + Images.GetHashCode(); } if (MatchedItems != null) { hashCode = hashCode * 59 + MatchedItems.GetHashCode(); } if (IsoCountryCodes != null) { hashCode = hashCode * 59 + IsoCountryCodes.GetHashCode(); } if (CompanyName != null) { hashCode = hashCode * 59 + CompanyName.GetHashCode(); } if (CompanyAddress != null) { hashCode = hashCode * 59 + CompanyAddress.GetHashCode(); } if (Categories != null) { hashCode = hashCode * 59 + Categories.GetHashCode(); } if (CategoryHierarchies != null) { hashCode = hashCode * 59 + CategoryHierarchies.GetHashCode(); } return(hashCode); } }
/// <summary> /// Returns true if Item instances are equal /// </summary> /// <param name="other">Instance of Item to be compared</param> /// <returns>Boolean</returns> public bool Equals(Item other) { if (other is null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( Upc == other.Upc || Upc != null && Upc.Equals(other.Upc) ) && ( Ean == other.Ean || Ean != null && Ean.Equals(other.Ean) ) && ( Isbn == other.Isbn || Isbn != null && Isbn.Equals(other.Isbn) ) && ( Asin == other.Asin || Asin != null && Asin.Equals(other.Asin) ) && ( Title == other.Title || Title != null && Title.Equals(other.Title) ) && ( Sku == other.Sku || Sku != null && Sku.Equals(other.Sku) ) && ( Mpn == other.Mpn || Mpn != null && Mpn.Equals(other.Mpn) ) && ( PartNumber == other.PartNumber || PartNumber != null && PartNumber.Equals(other.PartNumber) ) && ( Upcs == other.Upcs || Upcs != null && other.Upcs != null && Upcs.SequenceEqual(other.Upcs) ) && ( Description == other.Description || Description != null && Description.Equals(other.Description) ) && ( Brand == other.Brand || Brand != null && Brand.Equals(other.Brand) ) && ( Manufacturer == other.Manufacturer || Manufacturer != null && Manufacturer.Equals(other.Manufacturer) ) && ( Color == other.Color || Color != null && Color.Equals(other.Color) ) && ( NewPrice == other.NewPrice || NewPrice.Equals(other.NewPrice) ) && ( UsedPrice == other.UsedPrice || UsedPrice.Equals(other.UsedPrice) ) && ( CurrencyCode == other.CurrencyCode || CurrencyCode != null && CurrencyCode.Equals(other.CurrencyCode) ) && ( Url == other.Url || Url != null && Url.Equals(other.Url) ) && ( Features == other.Features || Features != null && other.Features != null && Features.SequenceEqual(other.Features) ) && ( Dimensions == other.Dimensions || Dimensions != null && other.Dimensions != null && Dimensions.SequenceEqual(other.Dimensions) ) && ( Images == other.Images || Images != null && other.Images != null && Images.SequenceEqual(other.Images) ) && ( MatchedItems == other.MatchedItems || MatchedItems != null && other.MatchedItems != null && MatchedItems.SequenceEqual(other.MatchedItems) ) && ( IsoCountryCodes == other.IsoCountryCodes || IsoCountryCodes != null && other.IsoCountryCodes != null && IsoCountryCodes.SequenceEqual(other.IsoCountryCodes) ) && ( CompanyName == other.CompanyName || CompanyName != null && CompanyName.Equals(other.CompanyName) ) && ( CompanyAddress == other.CompanyAddress || CompanyAddress != null && CompanyAddress.Equals(other.CompanyAddress) ) && ( Categories == other.Categories || Categories != null && other.Categories != null && Categories.SequenceEqual(other.Categories) ) && ( CategoryHierarchies == other.CategoryHierarchies || CategoryHierarchies != null && other.CategoryHierarchies != null && CategoryHierarchies.SequenceEqual(other.CategoryHierarchies) )); }
public OandaStreamingClient(OandaServers server, SecureString token, Func <string, int> getAccountId) { if (getAccountId == null) { throw new ArgumentNullException(nameof(getAccountId)); } switch (server) { case OandaServers.Sandbox: if (token != null) { throw new ArgumentException("token"); } _streamingUrl = "http://stream-sandbox.oanda.com"; break; case OandaServers.Practice: if (token == null) { throw new ArgumentNullException(nameof(token)); } _streamingUrl = "https://stream-fxpractice.oanda.com"; break; case OandaServers.Real: if (token == null) { throw new ArgumentNullException(nameof(token)); } _streamingUrl = "https://stream-fxtrade.oanda.com"; break; default: throw new ArgumentOutOfRangeException(nameof(server)); } _token = token; _pricesWorker = new StreamingWorker <string, StreamingPriceResponse>(this, "prices", (qs, instruments) => qs .Append("accountId", getAccountId(null)) .Append("instruments", instruments.Join(",")), price => { if (price.Tick == null) { return; } NewPrice.SafeInvoke(price.Tick); }); _eventsWorker = new StreamingWorker <int, StreamingEventResponse>(this, "events", (qs, accounts) => qs.Append("accountIds", accounts.Select(a => a.To <string>()).Join(",")), price => { if (price.Transaction == null) { return; } NewTransaction.SafeInvoke(price.Transaction); }); }
protected void RaiseStopper() { var stopper = new NewPriceEventArgs(null); NewPrice?.Invoke(this, stopper); }
private void btnChangePrice_Click(object sender, EventArgs e) { decimal NewPrice; decimal.TryParse(txtEnterPriceToChange.Text, out NewPrice); if (txtEnterPriceToChange.Text == "") { MessageBox.Show("Enter price before"); } else if (NewPrice < 0) { MessageBox.Show("Price can't be less then 0"); } else { if (listBox1.SelectedIndex == -1) { MessageBox.Show("Select car before for price change!"); } else { Price[listBox1.SelectedIndex] = NewPrice; MessageBox.Show("Price for " + Brand[listBox1.SelectedIndex] + " " + Model[listBox1.SelectedIndex] + " " + Year[listBox1.SelectedIndex] + " was changed to " + NewPrice.ToString("c")); Display(); } } }