/// <summary> /// Readjust and Recalulate Prices. /// </summary> public void RecalculatePrices() { // TODO Allow for this to be modified by variations // TODO Create a way to allow for faster Price changes, when supply/demand differences are large. // for each product in the market. foreach (var pair in ProductPrices) { // Get the product var product = pair.Item1; double surplus; double shortfall; try { // get surplus product not spent surplus = Surplus.GetProductValue(product); // get product that was desired to buy. shortfall = Shortfall.GetProductValue(product); } catch (KeyNotFoundException) { // if the item does not exist in surplus or shortfal, then it probably was not // sold or desired in the market. Give it a boost to denote it's rarity, and try and encourage it. ProductPrices.AddProducts(product, 0.01); continue; } // the amount of change to make to the good's price. double priceChange = 0; // If any surplus and shortfall exists, price was too high if (surplus > 0 && shortfall > 0) { priceChange += -0.01; } else if (surplus > 0) { // If no shortfall but still surplus, try lowering price to sell it, oversupply is not good. priceChange += -0.01; } else if (shortfall > 0) { // if shortfall but no surplus, price is too low. priceChange += 0.01; } // In no surplus nor shortfall, then we have hit equilibrium. // No change in price. // add the change in price to the new price // TODO make this more flexible and reactive. // going in 0.01 ABS price unit sized steps is too small // and may make prices too stagnant var newPrice = ProductPrices.GetProductValue(product) + priceChange; // update to said price. ProductPrices.SetProductAmount(product, newPrice); } }
public void PrintLabel(Surplus surplus) { string savefolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); string wordFilename = savefolder + "\\surplus.docx"; Word.Application wordApp = new Word.Application { Visible = false }; wordApp.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone; Word.Document wordDoc = wordApp.Documents.Open(wordFilename, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); wordDoc.Activate(); FindAndReplace(wordApp, "{type}", surplus.Type); FindAndReplace(wordApp, "{court}", surplus.Court); FindAndReplace(wordApp, "{county}", surplus.County); FindAndReplace(wordApp, "{state}", surplus.State); FindAndReplace(wordApp, "{serial}", surplus.Serial); FindAndReplace(wordApp, "{make}", surplus.Make); FindAndReplace(wordApp, "{model}", surplus.Model); FindAndReplace(wordApp, "{useable_parts}", surplus.Useable_Parts); FindAndReplace(wordApp, "{reuseable}", surplus.Reuseable_Equipment); //FindAndReplace(wordApp, "{type}", surplus.Reason_for_Surplus); FindAndReplace(wordApp, "{date}", DateTime.Now.ToString("MM-dd-yyyy")); wordDoc.PrintOut(); wordDoc.Close(SaveChanges: false); wordApp.Quit(Type.Missing, Type.Missing, Type.Missing); }
public void UpdateSurplus(Surplus surplus) { this.DbExecuteNonQuery(String.Format("update IPSCM.dbo.Users set [Money]='{1}' where [UserId]='{0}'", surplus.UserId, surplus.Money)); }
static void SaveToExcel(Surplus surplus) { // Set file location to desktop string savefolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); string xlfilename = savefolder + "\\surplus.xlsx"; var excelApp = new Excel.Application(); // Make excel invisible and turn off "file already exists alert before save". excelApp.Visible = false; excelApp.DisplayAlerts = false; // Check if file exists, if not create it and then open it at the end. if (File.Exists(xlfilename)) { } else { var newworkbook = excelApp.Workbooks.Add(); newworkbook.SaveAs(xlfilename, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookDefault, Type.Missing, Type.Missing, false, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); }; var workbook = excelApp.Workbooks.Open(xlfilename, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); // Just set the column header each time, less code and work right now than checking it all and then setting it. Excel._Worksheet workSheet = (Excel.Worksheet)excelApp.ActiveSheet; workSheet.Cells[1, "A"] = "Type"; workSheet.Cells[1, "B"] = "Court"; workSheet.Cells[1, "C"] = "County"; workSheet.Cells[1, "D"] = "State"; workSheet.Cells[1, "E"] = "Serial"; workSheet.Cells[1, "F"] = "Make"; workSheet.Cells[1, "G"] = "Model"; workSheet.Cells[1, "H"] = "Useable Parts"; workSheet.Cells[1, "I"] = "Reuseable Equipment"; workSheet.Cells[1, "J"] = "Reason for Surplus"; workSheet.Cells[1, "K"] = "TimeStamp"; var row = workSheet.UsedRange.Row +workSheet.UsedRange.Rows.Count - 1; row++; workSheet.Cells[row, "A"] = surplus.Type; workSheet.Cells[row, "B"] = surplus.Court; workSheet.Cells[row, "C"] = surplus.County; workSheet.Cells[row, "D"] = surplus.State; workSheet.Cells[row, "E"] = surplus.Serial; workSheet.Cells[row, "F"] = surplus.Make; workSheet.Cells[row, "G"] = surplus.Model; workSheet.Cells[row, "H"] = surplus.Useable_Parts; workSheet.Cells[row, "I"] = surplus.Reuseable_Equipment; workSheet.Cells[row, "J"] = surplus.Reason_for_Surplus; workSheet.Cells[row, "K"] = surplus.TimeStamp; workSheet.Columns[1].AutoFit(); workSheet.Columns[2].AutoFit(); workSheet.Columns[3].AutoFit(); workSheet.Columns[4].AutoFit(); workSheet.Columns[5].AutoFit(); workSheet.Columns[6].AutoFit(); workSheet.Columns[7].AutoFit(); workSheet.Columns[8].AutoFit(); workSheet.Columns[9].AutoFit(); workSheet.Columns[10].AutoFit(); workSheet.Columns[11].AutoFit(); workbook.SaveAs(xlfilename, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookDefault, Type.Missing, Type.Missing, false, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); workbook.Close(); }
private void savePrintButton_Click(object sender, EventArgs e) { var surplusEntry = new Surplus { Type = typeBox.Text, Court = courtBox.Text, County = countyBox.Text, State = stateBox.Text, Serial = serialBox.Text, Make = makeBox.Text, Model = modelBox.Text, Useable_Parts = useablePartsBox.Text, Reuseable_Equipment = reuseableEquipmentBox.Text, Reason_for_Surplus = surplusReasonBox.Text, TimeStamp = DateTime.Now.ToString("MM-dd-yyyy hh:mm:ss") }; SaveToExcel(surplusEntry); PrintLabel(surplusEntry); typeBox.Text = ""; courtBox.Text = ""; countyBox.Text = ""; stateBox.Text = ""; serialBox.Text = ""; makeBox.Text = ""; modelBox.Text = ""; useablePartsBox.Text = ""; reuseableEquipmentBox.Text = ""; surplusReasonBox.Text = ""; typeBox.Select(); typeBox.Focus(); }