/// <summary> /// 標準コンストラクタ /// </summary> public ItemInfo() { Name = string.Empty; Price = 1; Amount = 1; ProductSpeed = 100; ProductTime = 1; Royality = 0; MaterialList = new List <MaterialInfo>(); Analyze = new AnalyzeInfo(); }
/// <summary> /// フォームのインスタンスの受け渡しをするためのコンストラクタ /// </summary> /// <param name="mainForm"></param> public ItemInfo(MainWindow mainForm) { main = mainForm; Name = string.Empty; Price = 1; Amount = 1; ProductSpeed = 100; ProductTime = 1; Royality = 0; MaterialList = new List <MaterialInfo>(); Analyze = new AnalyzeInfo(); }
public static AnalyzeInfo DoAnalyze(ItemInfo item) { double allCash = (item.Price - (item.Price * ((double)ShopInfo.Tax / 100.0))) * item.Amount + item.Royality; double cost = 0; foreach (MaterialInfo material in item.MaterialList) { if (material.Type == MaterialInfo.MaterialType.Tool) { cost += material.BuyPrice * (material.RequiredAmount * 0.2); } else { cost += material.BuyPrice * material.RequiredAmount; } } if (item.Royality.Equals(string.Empty) == false) { cost += item.Royality; } double productSpeed = (double)item.ProductSpeed / 100; double profit = allCash - cost; double profitPer = profit / allCash * 100; double costPer = cost / allCash * 100; double amount = item.Amount; double profitPerItem = profit / amount; double costPerItem = cost / amount; double productTime = item.ProductTime; double perTime = profit / (productTime / productSpeed); AnalyzeInfo analyze = new AnalyzeInfo(); analyze.Profit = profit; analyze.ProfitPer = profitPer; analyze.Cost = cost; analyze.CostPer = costPer; analyze.ProfitPerItem = profitPerItem; analyze.CostPerItem = costPerItem; analyze.PerTime = perTime; item.Analyze = analyze; return(analyze); }
private void ShowAnalyze() { //ToString("F")は、小数点以下第二位を四捨五入する(多分) AnalyzeInfo analyze = AnalyzeInfo.DoAnalyze(ItemList[nowRecord]); TBProfit.Text = analyze.Profit.ToString("F"); TBProfitPer.Text = analyze.ProfitPer.ToString("F"); TBCost.Text = analyze.Cost.ToString("F"); TBCostPer.Text = analyze.CostPer.ToString("F"); TBProfitPerItem.Text = analyze.ProfitPerItem.ToString("F"); TBCostPerItem.Text = analyze.CostPerItem.ToString("F"); TBPerTime.Text = analyze.PerTime.ToString("F"); }
/// <summary> /// CSVファイルを保存する処理 /// </summary> /// <param name="fileName"></param> public void SaveCsv(string fileName) { main.SaveNowInfo(); //using (FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write)) using (StreamWriter sw = new StreamWriter(fileName, false, Encoding.UTF8)) { sw.WriteLine("Tax," + ShopInfo.Tax); sw.Write("Name,Price,Amount,ProductSpeed,ProductTime,Royality,"); sw.Write("Profit,ProfitPercent,Cost,CostPercent,ProfitPerItem,CostPerItem,ProfitPerHour,"); sw.WriteLine("MaterialName,BuyPrice,RequiredAmount,MaterialType"); foreach (ItemInfo item in MainWindow.ItemList) { sw.Write(item.Name + "," + item.Price.ToString() + "," + item.Amount.ToString() + ","); sw.Write(item.ProductSpeed.ToString() + "," + item.ProductTime.ToString() + "," + item.Royality.ToString() + ","); item.Analyze = AnalyzeInfo.DoAnalyze(item); sw.Write(item.Analyze.Profit.ToString() + "," + item.Analyze.ProfitPer.ToString() + ","); sw.Write(item.Analyze.Cost.ToString() + "," + item.Analyze.CostPer.ToString() + ","); sw.Write(item.Analyze.ProfitPerItem.ToString() + "," + item.Analyze.CostPerItem.ToString() + ","); sw.Write(item.Analyze.PerTime.ToString() + ","); sw.Flush(); int i = 1; foreach (MaterialInfo material in item.MaterialList) { sw.Write(material.MaterialName + "," + material.BuyPrice.ToString() + ","); sw.Write(material.RequiredAmount.ToString() + "," + MaterialInfo.GetMaterialString(material.Type)); if (item.MaterialList.Count == i) { break; } else { sw.Write(","); } i++; sw.Flush(); } sw.Flush(); sw.WriteLine(); sw.Flush(); } } }
internal void SaveJson(string fileName) { main.SaveNowInfo(); for (int i = 0; i < MainWindow.ItemList.Count; i++) { MainWindow.ItemList[i].Analyze = AnalyzeInfo.DoAnalyze(MainWindow.ItemList[i]); } //var setting = new JsonSerializerSettings(); //setting. var json = JsonConvert.SerializeObject(MainWindow.ItemList, Formatting.Indented); using (StreamWriter sw = new StreamWriter(fileName, false, Encoding.UTF8)) //using (var jw = new JsonTextWriter(sw)) { sw.Write(json); //jw.Formatting = Formatting.Indented; //jw.IndentChar = '\t'; //jw.WriteRaw(JObject.Parse(?????????)); } }