From bfa2db035a42e251b9b7203fdeb690928bd4890b Mon Sep 17 00:00:00 2001 From: Matt Moening Date: Fri, 17 Apr 2015 20:14:20 -0700 Subject: [PATCH] Updated Printer Auto Name Auto Name will now suggest names without numbers if there are no printers of the same make and model Auto Name will now suggest the lowest possible number if there are printers of the same make and model --- .../SetupStepMakeModelName.cs | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/PrinterControls/PrinterConnections/SetupStepMakeModelName.cs b/PrinterControls/PrinterConnections/SetupStepMakeModelName.cs index 68fd4e333..835769044 100644 --- a/PrinterControls/PrinterConnections/SetupStepMakeModelName.cs +++ b/PrinterControls/PrinterConnections/SetupStepMakeModelName.cs @@ -4,6 +4,7 @@ using MatterHackers.Localizations; using MatterHackers.MatterControl.DataStorage; using System; using System.Collections.Generic; +using System.Linq; namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections { @@ -199,7 +200,30 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections SetElementState(); if (usingDefaultName) { - printerNameInput.Text = String.Format("{0} {1} ({2})", this.ActivePrinter.Make, this.ActivePrinter.Model, ExistingPrinterCount() + 1); + string printerInputName = String.Format("{0} {1}", this.ActivePrinter.Make, this.ActivePrinter.Model); + string query = string.Format("SELECT Name FROM Printer WHERE Name LIKE \'{0}%\';", printerInputName); + var names = Datastore.Instance.dbSQLite.Query(query).Select(item => item.Name).ToList(); + + if (!names.Contains(printerInputName)) + { + printerNameInput.Text = printerInputName; + } + else + { + + int printerModelCount = 0; //Used to keep track of how many of the printer models we run into before and empty one + string possiblePrinterName; + + do + { + printerModelCount++; + possiblePrinterName = String.Format("{0} ({1})", printerInputName, printerModelCount); + } while (names.Contains(possiblePrinterName)); + + + printerNameInput.Text = possiblePrinterName; + } + } }); } @@ -247,6 +271,12 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections return Convert.ToInt32(result); } + private class sqlName + { + public string Name { get; set; } + } + + private bool OnSave() { if (printerNameInput.Text != "")