...
 
Commits (2)
  • Meelad Vahdat's avatar
    Lots of changes in this one: · 3073682f
    Meelad Vahdat authored
    - General
    -- Changed logos and icons to official Listware Desktop logos and icons
    
    - AutoDetectInputs.cs
    -- Added phone and email variations
    
    - Output.cs
    -- Added a linesWritten counter as well as method numberOfLinesWritten
    
    - MainForm.cs
    -- Changed backgroundWorker1_DoWork to utilize multi-threading
    
    - MainForm.Designer.cs
    -- Added a location at the top to change number of threads
    
    - GenerateReport.cs
    -- Made it so that any result codes not found in the config do not cause an exception and are counted as "XXXX" in the report
    
    - ValidDescriptions.cfg
    -- Added "XXXX" to mean "Could not find results"
    
    - AboutForm.Designer.cs
    -- Changed pictureBox1 to new logo
    
    - InputPreviewForm.cs
    -- Added and call resizeForm() in the constructor to resize the form automatically
    
    - SetConfigurationForm.cs
    -- Changed logic to correctly show setConfigurationFormCheckedListBox
    -- Added and call resizeForm() in the constructor to resize the form automatically
    
    - SetInputsForm.cs
    -- Added and call resizeForm() in the constructor to resize the form automatically
    
    - SetOutputsForm.cs
    -- Added and call resizeForm() in the constructor to resize the form automatically
    Signed-off-by: Meelad Vahdat's avatarMeelad Vahdat <meelad@melissadata.com>
    3073682f
  • Meelad Vahdat's avatar
    Merge branch 'MeeladWorkingBranch' into 'master' · 01f4156d
    Meelad Vahdat authored
    Lots of changes in this one:
    
    See merge request !3
    01f4156d
......@@ -33,6 +33,10 @@ namespace ListwareDesktop.Framework
static string[] recordIDVariations = { "recordid", "recnum", "recno", "recid", "id", "rec" };
static string[] phoneVariations = { "phone", "phonenumber", "fone", "fonenumber", "phonenum", "fonenum" };
static string[] emailVariations = { "email", "emailaddress", "emailaddr", "e-mail" };
//This relates input column names to the variation lists
//Add input columns from services here in all lower case as the key, then the variation list as the value
internal static Dictionary<string, string[]> variationDictionary = new Dictionary<string, string[]>()
......@@ -52,7 +56,9 @@ namespace ListwareDesktop.Framework
{"lastname", lastNameVariations},
{"fullname", fullNameVariations},
{"companyname", companyVariations},
{"recordid", recordIDVariations}
{"recordid", recordIDVariations},
{"emailaddress", emailVariations},
{"phonenumber", phoneVariations}
};
}
}
......@@ -14,10 +14,12 @@ namespace ListwareDesktop.Framework
private string filePath { get; set; }
private string delimiter;
private string qualifier;
private int linesWritten;
//Constructor that sets all the settings for the writer
internal Output(string filePath, string delimiter, string qualifier)
{
this.linesWritten = 0;
this.filePath = filePath;
this.delimiter = delimiter;
this.qualifier = qualifier;
......@@ -36,17 +38,23 @@ namespace ListwareDesktop.Framework
{
if ((qualifier == null) && (tempRecord.fieldAndData[currentHeader].Contains(delimiter)))
{
tempString += "\"" + tempRecord.fieldAndData[currentHeader] + "\"" + delimiter;
tempString += "\"" + tempRecord.fieldAndData[currentHeader].Trim() + "\"" + delimiter;
}
else
{
tempString += qualifier + tempRecord.fieldAndData[currentHeader] + qualifier + delimiter;
tempString += qualifier + tempRecord.fieldAndData[currentHeader].Trim() + qualifier + delimiter;
}
}
streamWriter.WriteLine(tempString);
streamWriter.WriteLine(tempString.TrimEnd(new char[]{delimiter[0]}));
linesWritten++;
}
}
internal int numberOfLinesWritten()
{
return this.linesWritten;
}
//Writes header line
internal void writeHeaders(Record sampleRecord)
{
......@@ -59,7 +67,7 @@ namespace ListwareDesktop.Framework
tempString += qualifier + header + qualifier + delimiter;
}
streamWriter.WriteLine(tempString);
streamWriter.WriteLine(tempString.TrimEnd(new char[]{delimiter[0]}));
}
internal void checkIfEmpty(Record sampleRecord)
......
......@@ -160,11 +160,11 @@
</ItemGroup>
<ItemGroup>
<Content Include="Images\ListwareDesktop.PNG" />
<Content Include="Images\Melissa-favicon-32x32.png" />
<Content Include="Images\Melissa-new-logo-no-tag-200px.png" />
<Content Include="Images\Melissa.ico" />
<Content Include="Images\LWDT.ico" />
<Content Include="Images\LWDT.png" />
<Content Include="Reporting\ReportTemplate.html" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
......
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishUrlHistory>publish\</PublishUrlHistory>
<InstallUrlHistory />
<SupportUrlHistory>https://www.melissa.com/company/support</SupportUrlHistory>
<UpdateUrlHistory />
<BootstrapperUrlHistory />
<ErrorReportUrlHistory>http://wiki.melissadata.com/</ErrorReportUrlHistory>
<FallbackCulture>en-US</FallbackCulture>
<VerifyUploadedFiles>false</VerifyUploadedFiles>
</PropertyGroup>
</Project>
\ No newline at end of file
......@@ -96,6 +96,9 @@
this.aboutCreditsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.purchaseCreditsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.optionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.numberOfThreadsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.numberOfThreadsMenuStripTextBox = new System.Windows.Forms.ToolStripTextBox();
this.pauseButton = new System.Windows.Forms.Button();
this.inputFileGroupBox.SuspendLayout();
this.inputFileQualifierGroupBox.SuspendLayout();
......@@ -184,7 +187,6 @@
this.backgroundWorker1.WorkerReportsProgress = true;
this.backgroundWorker1.WorkerSupportsCancellation = true;
this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork);
this.backgroundWorker1.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.backgroundWorker1_ProgressChanged);
this.backgroundWorker1.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.backgroundWorker1_RunWorkerCompleted);
//
// inputFileGroupBox
......@@ -778,7 +780,8 @@
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.licenseToolStripMenuItem,
this.creditsToolStripMenuItem,
this.aboutToolStripMenuItem});
this.aboutToolStripMenuItem,
this.optionsToolStripMenuItem});
this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip";
this.menuStrip.Size = new System.Drawing.Size(841, 24);
......@@ -833,6 +836,33 @@
this.aboutToolStripMenuItem.Text = "About";
this.aboutToolStripMenuItem.Click += new System.EventHandler(this.aboutToolStripMenuItem_Click);
//
// optionsToolStripMenuItem
//
this.optionsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.numberOfThreadsToolStripMenuItem});
this.optionsToolStripMenuItem.Font = new System.Drawing.Font("Segoe UI", 8.25F);
this.optionsToolStripMenuItem.Name = "optionsToolStripMenuItem";
this.optionsToolStripMenuItem.Size = new System.Drawing.Size(61, 20);
this.optionsToolStripMenuItem.Text = "Options";
//
// numberOfThreadsToolStripMenuItem
//
this.numberOfThreadsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.numberOfThreadsMenuStripTextBox});
this.numberOfThreadsToolStripMenuItem.Name = "numberOfThreadsToolStripMenuItem";
this.numberOfThreadsToolStripMenuItem.Size = new System.Drawing.Size(172, 22);
this.numberOfThreadsToolStripMenuItem.Text = "Number of Threads";
this.numberOfThreadsToolStripMenuItem.MouseEnter += new System.EventHandler(this.numberOfThreadsToolStripMenuItem_MouseEnter);
//
// numberOfThreadsMenuStripTextBox
//
this.numberOfThreadsMenuStripTextBox.Font = new System.Drawing.Font("Segoe UI", 8.25F);
this.numberOfThreadsMenuStripTextBox.MaxLength = 2;
this.numberOfThreadsMenuStripTextBox.Name = "numberOfThreadsMenuStripTextBox";
this.numberOfThreadsMenuStripTextBox.Size = new System.Drawing.Size(100, 22);
this.numberOfThreadsMenuStripTextBox.Text = "5";
this.numberOfThreadsMenuStripTextBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.numberOfThreadsMenuStripTextBox_KeyPress);
//
// pauseButton
//
this.pauseButton.Enabled = false;
......@@ -964,6 +994,9 @@
private System.Windows.Forms.TextBox reportingClientNameTextBox;
private System.Windows.Forms.ToolStripMenuItem aboutToolStripMenuItem;
private System.Windows.Forms.Button pauseButton;
private System.Windows.Forms.ToolStripMenuItem optionsToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem numberOfThreadsToolStripMenuItem;
private System.Windows.Forms.ToolStripTextBox numberOfThreadsMenuStripTextBox;
}
}
......@@ -7,6 +7,7 @@ using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Concurrent;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
......@@ -26,13 +27,19 @@ namespace ListwareDesktop
{
#region Global Vars
//Some static fields that are used between the service, the GUI, and the different windows
private static readonly string _version = "2.0";
internal static readonly string _lwdtSrc = "mdSrc:{product:ListwareDesktop;version:" + _version + "}";
private static string creditAmt = "";
//Service Options
private static ConcurrentQueue<Record[]> inputQueue;
private static ConcurrentQueue<Record[]> outputQueue;
private static IWS serviceObject;
private static string userLicense;
private static IWS userService;
internal static Type serviceType;
internal static Dictionary<string, string> inputAliases;
internal static string[] selectedOutputs;
private static readonly string _version = "1.1";
internal static readonly string _lwdtSrc = "mdSrc:{product:ListwareDesktop;version:" + _version + "}";
private static string creditAmt = "";
internal static Dictionary<string, string> serviceOptions = new Dictionary<string, string>();
//To make sure the input and output files are set before running
private string inputFilePath;
......@@ -50,7 +57,6 @@ namespace ListwareDesktop
//Generate all available classes from the "Services" folder at runtime
this.generateClassesForComboBox();
//Pull up saved license if any
if (!String.IsNullOrEmpty(Properties.Settings.Default.customerID))
{
......@@ -91,10 +97,9 @@ namespace ListwareDesktop
//The title of the form is changed
private void serviceSelectComboBox_SelectionChangeCommitted(object sender, EventArgs e)
{
Type classType = Type.GetType("ListwareDesktop.Services." + serviceSelectComboBox.SelectedItem.ToString());
userService = Activator.CreateInstance(classType) as IWS;
serviceType = Type.GetType("ListwareDesktop.Services." + serviceSelectComboBox.SelectedItem.ToString());
this.Text = "Listware Desktop " + _version + " : " + serviceType.Name;
serviceProgressCheckBox.Checked = true;
this.Text = "Listware Desktop " + _version + ": " + userService.GetType().Name;
this.Update();
}
......@@ -150,7 +155,6 @@ namespace ListwareDesktop
Properties.Settings.Default.customerID = setLicenseTextBox.Text;
Properties.Settings.Default.Save();
this.setLicenseTextBox.PasswordChar = '\u2022';
//this.enableGroupBoxes();
this.enableInputProgressGroupBoxes();
new Thread(() =>
{
......@@ -194,7 +198,7 @@ namespace ListwareDesktop
//Check textbox if it is empty, if it's not then check if the path is valid then open that directory
//Otherwise open the current directory
if ((String.IsNullOrEmpty(inputFileTextBox.Text) || (!Directory.Exists(Path.GetDirectoryName(outputFileTextBox.Text)))))
if ((String.IsNullOrEmpty(inputFileTextBox.Text) || ((!string.IsNullOrWhiteSpace(outputFileTextBox.Text.Trim())) &&(!Directory.Exists(Path.GetDirectoryName(outputFileTextBox.Text))))))
{
defaultLocation = Directory.GetCurrentDirectory();
}
......@@ -414,50 +418,27 @@ namespace ListwareDesktop
}
}
serviceObject = Activator.CreateInstance(serviceType) as IWS;
serviceObject.serviceOptions = new Dictionary<string, string>(MainForm.serviceOptions);
serviceObject.userLicense = MainForm.userLicense;
//If the run button is clicked
//Display and enable the pause button
//Change the run button size
//Start the worker thread
if ((inputColumnProgressCheckBox.Checked) && (!userService.errorStatus))
if ((inputColumnProgressCheckBox.Checked) || (this.setInputAliases()))
{
pauseButton.Enabled = true;
this.changeRunButtonSize();
statusTextBox.Text = "";
backgroundWorker1.WorkerReportsProgress = true;
backgroundWorker1.RunWorkerAsync();
runButton.Text = "Cancel";
this.changeRunButtonSize();
}
//If the input columns weren't explicitly set
//Try to set them using our input field name dictionary
//If we can't, don't run and let the customer know
else if ((!inputColumnProgressCheckBox.Checked) && (!userService.errorStatus))
{
if (!this.setInputAliases())
{
statusTextBox.Text = "Input columns were not able to be autodetected.\r\nPlease set manually.";
}
else
{
pauseButton.Enabled = true;
statusTextBox.Text = "";
backgroundWorker1.WorkerReportsProgress = true;
backgroundWorker1.RunWorkerAsync();
runButton.Text = "Cancel";
this.changeRunButtonSize();
}
}
//If there's something wrong with the service, don't process and tell the user why
else if (userService.errorStatus)
else
{
userService.errorStatus = false; ;
statusTextBox.Text = "Pre Process Check Failed:\r\n" + userService.statusMessage;
backgroundWorker1.CancelAsync();
runButton.Text = "Run";
this.changeRunButtonSize();
statusTextBox.Text = "Input columns were not able to be autodetected.\r\nPlease set manually.";
}
}
//If we are not in a passive state, we are in a run state, records are running, and the run button says "Cancel"
else
else
{
//If the cancel button is selected while we are paused, then resume the backgroundworker thread but flag for cancellation
//If the cancel button is selected while we are not paused, then just flag backgroundworker for cancellation
......@@ -476,14 +457,18 @@ namespace ListwareDesktop
//If we are in a passive state, the run button is large and "welcoming" and the pause button is hidden
if (runButton.Text == "Run")
{
runButton.Height = 63;
pauseButton.Visible = false;
runButton.Text = "Cancel";
pauseButton.Enabled = true;
runButton.Height = 29;
pauseButton.Visible = true;
}
//If we are in a run state, the run button is half the size to make room for the pause button that was previously hidden
else
{
runButton.Height = 29;
pauseButton.Visible = true;
runButton.Text = "Run";
pauseButton.Enabled = false;
runButton.Height = 63;
pauseButton.Visible = false;
}
}
......@@ -515,8 +500,10 @@ namespace ListwareDesktop
if (serviceProgressCheckBox.Checked)
{
statusTextBox.Text = "";
SetConfigurationForm setConfigurationForm = new SetConfigurationForm(userService, configurationProgressCheckBox);
setConfigurationForm.Show();
SetConfigurationForm setConfigurationForm = new SetConfigurationForm(configurationProgressCheckBox);
setConfigurationForm.StartPosition = FormStartPosition.CenterParent;
setConfigurationForm.Focus();
setConfigurationForm.ShowDialog();
}
else
{
......@@ -530,7 +517,9 @@ namespace ListwareDesktop
if (inputFileProgressCheckBox.Checked)
{
InputPreviewForm inputPreviewForm = new InputPreviewForm(inputFilePath, getInputDelimiter(), getInputQualifier());
inputPreviewForm.Show();
inputPreviewForm.StartPosition = FormStartPosition.CenterParent;
inputPreviewForm.Focus();
inputPreviewForm.ShowDialog();
}
else
{
......@@ -548,8 +537,10 @@ namespace ListwareDesktop
{
Input inputFile = new Input(inputFilePath, getInputDelimiter(), getInputQualifier());
statusTextBox.Text = "";
SetInputsForm setInputsForm = new SetInputsForm(userService, inputFilePath, getInputDelimiter(), getInputQualifier(), inputColumnProgressCheckBox);
setInputsForm.Show();
SetInputsForm setInputsForm = new SetInputsForm(inputFilePath, getInputDelimiter(), getInputQualifier(), inputColumnProgressCheckBox);
setInputsForm.StartPosition = FormStartPosition.CenterParent;
setInputsForm.Focus();
setInputsForm.ShowDialog();
}
else
{
......@@ -574,8 +565,10 @@ namespace ListwareDesktop
if (!string.IsNullOrEmpty(setLicenseTextBox.Text) && serviceProgressCheckBox.Checked)
{
statusTextBox.Text = "";
SetOutputsForm setOutputsForm = new SetOutputsForm(userService, outputColumnProgressCheckBox);
setOutputsForm.Show();
SetOutputsForm setOutputsForm = new SetOutputsForm(outputColumnProgressCheckBox);
setOutputsForm.StartPosition = FormStartPosition.CenterParent;
setOutputsForm.Focus();
setOutputsForm.ShowDialog();
}
else
{
......@@ -595,229 +588,260 @@ namespace ListwareDesktop
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region Background Worker
//Use backgroundworker to process
void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
statusTextBox.Invoke(new Action(() => statusTextBox.Text = ""));
int totalRecs = 0;
//Create input and output objects, initialize input and output queue, clear status texbox
Input inputFile = new Input(inputFilePath, getInputDelimiter(), getInputQualifier());
Output outputFile = new Output(outputFilePath, getOutputDelimiter(), getOutputQualifier());
Record[] fullInputRecords;
bool firstTimeWritten = new bool();
userService.userLicense = MainForm.userLicense;
//Get an array of the full input records for passthrough, the pruned input records only for what we're sending in, and output records
#region NonDataCollectionService
if (!userService.needsAllRecords)
{
int recordCounter = 0;
while ((!inputFile.checkForEnd()) && (!backgroundWorker1.CancellationPending))
inputQueue = new ConcurrentQueue<Record[]>();
outputQueue = new ConcurrentQueue<Record[]>();
statusTextBox.Invoke(new Action(() => statusTextBox.Text += ""));
int recordCount = 0;
int numThreads = (numberOfThreadsMenuStripTextBox.Text.Equals(""))? 1 : int.Parse(numberOfThreadsMenuStripTextBox.Text);
#region Multi-thread WS send logic
if (!serviceObject.needsAllRecords)
{
//Keep looping until
//1. User wants to cancel OR
//2. Input file is done being read AND input queue is empty AND output queue is empty
while (!inputFile.checkForEnd())
{
fullInputRecords = inputFile.getRecords(userService.maxRecsPerRequest);
List<Record> recsToServiceTemp = new List<Record>();
foreach (Record tempRecord in fullInputRecords)
//If user clicks cancel, break from loop
if (backgroundWorker1.CancellationPending)
{
Dictionary<string, string> prunedDictionary = new Dictionary<string, string>();
foreach (KeyValuePair<string, string> tempKVP in tempRecord.fieldAndData)
{
if (inputAliases.ContainsKey(tempKVP.Key))
{
prunedDictionary.Add(inputAliases[tempKVP.Key], tempKVP.Value);
}
}
tempRecord.recordID = recordCounter;
Record prunedRecord = new Record(prunedDictionary);
prunedRecord.recordID = recordCounter;
recsToServiceTemp.Add(prunedRecord);
recordCounter++;
e.Cancel = true;
break;
}
//Send records and get outputs
Record[] recsToService = recsToServiceTemp.ToArray();
userService.sendToService(recsToService);
Record[] outputRecords = userService.outputRecords;
//Pause if user wants to pause
if (!manualResetEvent.WaitOne(0))
{
statusTextBox.Invoke(new Action(() => (statusTextBox.Text += " (Paused)").Trim()));
}
manualResetEvent.WaitOne(Timeout.Infinite);
//This big if statement is if they didn't want to return everything.
if (selectedOutputs != null)
//Write to input queue while we have records and one record array for each thread
while (inputFiletoInputQueue(ref recordCount, inputFile))
{
List<Record> tempRecords = new List<Record>();
foreach (Record tempRecord in outputRecords)
if (inputQueue.Count >= numThreads)
{
Record newRecord = new Record();
foreach (string selectedOutput in selectedOutputs)
{
foreach (KeyValuePair<string, string> entry in tempRecord.fieldAndData)
{
if (entry.Key.Contains(selectedOutput) || entry.Key.ToLowerInvariant().Contains("results"))
{
newRecord.addField(entry.Key, entry.Value);
}
}
}
newRecord.recordID = tempRecord.recordID;
tempRecords.Add(newRecord);
break;
}
outputRecords = tempRecords.ToArray();
}
//Make sure we past post process check, return if we do, break if we don't and return the error message
if (!userService.errorStatus)
//Queue a "send to service" event for each batch in the input queue
int numObjects = inputQueue.Count;
ManualResetEvent[] doneEvents = new ManualResetEvent[numObjects];
for (int i = 0; i < numObjects; i++)
{
if (passThroughCheckBox.Checked)
{
Dictionary<int, Record> inputPlaceHolder = fullInputRecords.ToDictionary(s => s.recordID);
foreach (Record tempOutputRecord in outputRecords)
{
if (inputPlaceHolder.ContainsKey(tempOutputRecord.recordID))
{
Record tempInRecord = new Record(inputPlaceHolder[tempOutputRecord.recordID]);
Record tempOutRecord = new Record(tempOutputRecord);
tempInRecord.combineRecord(tempOutRecord);
outputRecords[Array.IndexOf(outputRecords, tempOutputRecord)] = tempInRecord;
}
}
}
doneEvents[i] = new ManualResetEvent(false);
ThreadPool.QueueUserWorkItem(new WaitCallback(sendRecordToService), doneEvents[i]);
statusTextBox.Invoke(new Action(() => statusTextBox.Text = generateProgressString((i + 1), outputFile.numberOfLinesWritten())));
}
if (!firstTimeWritten)
{
outputFile.writeHeaders(outputRecords[0]);
firstTimeWritten = true;
}
WaitHandle.WaitAll(doneEvents.ToArray());
outputFile.sendRecords(outputRecords);
totalRecs += outputRecords.Length;
backgroundWorker1.ReportProgress(totalRecs, "records are being written.");
//Write records to file when we are done
while (!outputQueue.IsEmpty)
{
writeFromOutputQueueToFile(outputFile);
statusTextBox.Invoke(new Action(() => statusTextBox.Text = generateProgressString(0, outputFile.numberOfLinesWritten())));
}
else
}
}
#endregion
#region Matchup WS Logic
else
{
//This is a service that needs all records before returning (like Matchup WS)
List<Record> inputHolder = new List<Record>();
while (!serviceObject.serviceFinishedProcessing)
{
//If user clicks cancel, break from loop
if (backgroundWorker1.CancellationPending)
{
backgroundWorker1.CancelAsync();
e.Cancel = true;
break;
}
//ManualResetEvent is a class that allows threads to pause other threads
//Check if we are paused - if we are, let the user know through the status text box that we are paused
//Otherwise, if we are not paused and get the flag from the pause button, then pause backgroundworker
if (!manualResetEvent.WaitOne(0))
//Send all records to the service
while(!inputFile.checkForEnd())
{
statusTextBox.Invoke(new Action(() => statusTextBox.Text += " (Paused)"));
Record[] fullInputRecords = inputFile.getRecords(serviceObject.maxRecsPerRequest);
this.createRecordID(ref recordCount, fullInputRecords);
inputHolder.AddRange(fullInputRecords);
Record[] aliasedRecords = this.aliasRecords(fullInputRecords);
serviceObject.sendToService(aliasedRecords);
}
manualResetEvent.WaitOne(Timeout.Infinite);
}
if (backgroundWorker1.CancellationPending)
{
e.Cancel = true;
//Mark us as done when we're done sending records
if (!serviceObject.inputRecordsFinished)
{
serviceObject.inputRecordsFinished = true;
}
}
//When we're done processing, combine and write the records
Record[] outputRecords = serviceObject.outputRecords;
if (passThroughCheckBox.Checked) outputRecords = this.combineRecordsIfPassThrough(inputHolder.ToArray(), outputRecords);
outputFile.sendRecords(outputRecords);
}
#endregion
//This next region is for services that need all of the records at once - which is only Matchup Webservice currently
//For every other product, set the service as a non data collection service
#region DataCollectionService
if (userService.needsAllRecords)
inputFile.closeReader();
outputFile.closeWriter();
}
//Method to give each record a recordID
private void createRecordID(ref int recordCount, Record[] inputRecords)
{
foreach (Record inputRecord in inputRecords)
{
inputRecord.recordID = recordCount;
recordCount++;
}
}
//Generate the string to display to the user
private string generateProgressString(int threads, int recordsWritten)
{
string returnStr = "";
if (threads > 0)
{
int recordCounter = 0;
Dictionary<int, Record> inputPlaceHolder = new Dictionary<int, Record>();
returnStr += "Using " + threads + " threads:";
}
while ((!inputFile.checkForEnd()) && (!backgroundWorker1.CancellationPending))
if (recordsWritten > 0)
{
if (!string.IsNullOrEmpty(returnStr))
{
fullInputRecords = inputFile.getRecords(userService.maxRecsPerRequest);
returnStr += "\r\n";
}
List<Record> recsToServiceTemp = new List<Record>();
returnStr += recordsWritten + " records written.";
}
else
{
returnStr += "\r\nProcessing records.";
}
return returnStr;
}
foreach (Record tempRecord in fullInputRecords)
{
Dictionary<string, string> prunedDictionary = new Dictionary<string, string>();
//Read from the input file and send to the input queue
private bool inputFiletoInputQueue(ref int recordCount, Input inputFile)
{
if (inputFile.checkForEnd())
{
return false;
}
foreach (KeyValuePair<string, string> tempKVP in tempRecord.fieldAndData)
{
if (inputAliases.ContainsKey(tempKVP.Key))
{
prunedDictionary.Add(inputAliases[tempKVP.Key], tempKVP.Value);
}
}
Record[] fullInputRecords = inputFile.getRecords(serviceObject.maxRecsPerRequest);
this.createRecordID(ref recordCount, fullInputRecords);
foreach (Record fullInputRecord in fullInputRecords)
{
fullInputRecord.recordID = recordCount;
recordCount++;
}
inputQueue.Enqueue(fullInputRecords);
return true;
}
Record prunedRecord = new Record(prunedDictionary);
prunedRecord.recordID = recordCounter;
recsToServiceTemp.Add(prunedRecord);
inputPlaceHolder.Add(prunedRecord.recordID, prunedRecord);
recordCounter++;
}
//Method to control writing to an output file
private void writeFromOutputQueueToFile(Output outputFile)
{
while (!outputQueue.IsEmpty)
{
Record[] outputRecords;
if (outputQueue.TryDequeue(out outputRecords))
{
outputFile.sendRecords(outputRecords);
}
}
}
//Send records
Record[] recsToService = recsToServiceTemp.ToArray();
//Method to send records to a specific service object, and apply user options
private void sendRecordToService(object state)
{
IWS localService = Activator.CreateInstance(serviceType) as IWS;
localService.userLicense = MainForm.userLicense;
localService.serviceOptions = new Dictionary<string,string>(MainForm.serviceOptions);
if (inputFile.checkForEnd())
{
userService.inputRecordsFinished = true;
}
Record[] inputRecords;
if (inputQueue.TryDequeue(out inputRecords))
{
Record[] aliasedRecords = this.aliasRecords(inputRecords);
localService.sendToService(aliasedRecords);
Record[] localOutputRecords = localService.outputRecords;
userService.sendToService(recsToService);
if (!String.IsNullOrEmpty(userService.statusMessage))
{
backgroundWorker1.ReportProgress(0, userService.statusMessage);
}
}
if (selectedOutputs != null) localOutputRecords = pruneNotSelectedOutputs(localOutputRecords);
if (passThroughCheckBox.Checked) localOutputRecords = combineRecordsIfPassThrough(inputRecords, localOutputRecords);
outputQueue.Enqueue(localOutputRecords);
((ManualResetEvent)state).Set();
}
}
while (!userService.serviceFinishedProcessing)
//Method used to combine input and output records if passthrough is selected
private Record[] combineRecordsIfPassThrough(Record[] inputRecords, Record[] outputRecords)
{
Dictionary<int, Record> inputPlaceHolder = inputRecords.ToDictionary(s => s.recordID);
foreach (Record tempOutputRecord in outputRecords)
{
if (inputPlaceHolder.ContainsKey(tempOutputRecord.recordID))
{
int waitingNum = 0;
if (waitingNum == 0)
{
waitingNum = 1;
}
else
{
waitingNum = 0;
}
backgroundWorker1.ReportProgress(waitingNum, "Processing, Please Wait");
Record tempInRecord = new Record(inputPlaceHolder[tempOutputRecord.recordID]);
Record tempOutRecord = new Record(tempOutputRecord);
tempInRecord.combineRecord(tempOutRecord);
outputRecords[Array.IndexOf(outputRecords, tempOutputRecord)] = tempInRecord;
}
}
return outputRecords;
}
if (!userService.errorStatus)
//Method to prune the unselected outputs from the output record
private Record[] pruneNotSelectedOutputs(Record[] outputRecords)
{
List<Record> tempRecords = new List<Record>();
foreach (Record tempRecord in outputRecords)
{
Record newRecord = new Record();
foreach (string selectedOutput in selectedOutputs)
{
Record[] outputRecords = userService.outputRecords;
if (passThroughCheckBox.Checked)
foreach (KeyValuePair<string, string> entry in tempRecord.fieldAndData)
{
foreach (Record tempOutputRecord in outputRecords)
if ((entry.Key.Contains(selectedOutput)) || (entry.Key.ToLowerInvariant().Contains("results")))
{
if (inputPlaceHolder.ContainsKey(tempOutputRecord.recordID))
{
inputPlaceHolder[tempOutputRecord.recordID].combineRecord(tempOutputRecord);
outputRecords[Array.IndexOf(outputRecords, tempOutputRecord)] = inputPlaceHolder[tempOutputRecord.recordID];
}
newRecord.addField(entry.Key, entry.Value);
}
}
}
newRecord.recordID = tempRecord.recordID;
tempRecords.Add(newRecord);
}
return tempRecords.ToArray();
}
if (!firstTimeWritten)
{
outputFile.writeHeaders(outputRecords[0]);
firstTimeWritten = true;
}
//Method to translate input file header names to service input record names
private Record[] aliasRecords(Record[] fullInputRecords)
{
Record[] aliasedRecords = new Record[fullInputRecords.Length];
foreach (Record fullInputRecord in fullInputRecords)
{
Record aliasedRecord = new Record();
outputFile.sendRecords(outputRecords);
totalRecs += outputRecords.Length;
backgroundWorker1.ReportProgress(totalRecs, "records are being written.");
}
else
foreach (KeyValuePair<string, string> fieldAndData in fullInputRecord.fieldAndData)
{
backgroundWorker1.CancelAsync();
if (inputAliases.ContainsKey(fieldAndData.Key))
{
aliasedRecord.addField(inputAliases[fieldAndData.Key], fieldAndData.Value);
}
}
aliasedRecord.recordID = fullInputRecord.recordID;
aliasedRecords[Array.IndexOf(fullInputRecords, fullInputRecord)] = aliasedRecord;
}
#endregion
//Release the input and output files when we're done
inputFile.closeReader();
outputFile.closeWriter();
return aliasedRecords;
}
//Enable button when backgroundworker is finished
......@@ -825,16 +849,13 @@ namespace ListwareDesktop
{
//Hide and disable the pause button and reset the text on it
//Set run button text to "Run"
pauseButton.Enabled = false;
pauseButton.Text = "Pause";
runButton.Text = "Run";
this.changeRunButtonSize();
//If there was something wrong with processing, tell the customer
if (userService.errorStatus)
if (serviceObject.errorStatus)
{
userService.errorStatus = false;
statusTextBox.Text = "Something went wrong with processing:\r\n" + userService.statusMessage;
serviceObject.errorStatus = false;
statusTextBox.Text = "Something went wrong with processing:\r\n" + serviceObject.statusMessage;
//Get the current amount of credits for the license
new Thread(() =>
......@@ -853,7 +874,7 @@ namespace ListwareDesktop
}
else
{
statusTextBox.Text = "Processing has finished!";
statusTextBox.Text = "Processing finished!";
if (reportingCheckBox.Checked)
{
this.createReport();
......@@ -871,12 +892,6 @@ namespace ListwareDesktop
}).Start();
}
}
//To show progress
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
statusTextBox.Text = e.ProgressPercentage.ToString() + " " + e.UserState.ToString();
}
#endregion
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
......@@ -1025,8 +1040,7 @@ namespace ListwareDesktop
Input tempInput = new Input(inputFilePath, getInputDelimiter(), getInputQualifier());
string[] headers = tempInput.headerFieldNames;
foreach (string serviceInput in userService.inputColumns)
foreach (string serviceInput in serviceObject.inputColumns)
{
if (headers.Select(s => s.ToLowerInvariant()).Contains(serviceInput.ToLowerInvariant()))
{
......@@ -1048,14 +1062,7 @@ namespace ListwareDesktop
}
}
if (inputAliases.Count > 0)
{
return true;
}
else
{
return false;
}
return (inputAliases.Count > 0);
}
//Get the amount of credits the user has
......@@ -1260,8 +1267,22 @@ namespace ListwareDesktop
{
AboutForm aboutForm = new AboutForm(_version);
aboutForm.StartPosition = FormStartPosition.CenterParent;
aboutForm.Focus();
aboutForm.ShowDialog();
}
private void numberOfThreadsMenuStripTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = !char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar);
}
private void numberOfThreadsToolStripMenuItem_MouseEnter(object sender, EventArgs e)
{
if (numberOfThreadsMenuStripTextBox.Text.Equals(""))
{
numberOfThreadsMenuStripTextBox.Text = "1";
}
}
#endregion
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -59,15 +59,5 @@ namespace ListwareDesktop.Properties {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap Melissa_new_logo_no_tag_200px {
get {
object obj = ResourceManager.GetObject("Melissa-new-logo-no-tag-200px", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}
......@@ -118,7 +118,4 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="Melissa-new-logo-no-tag-200px" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Images\Melissa-new-logo-no-tag-200px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
\ No newline at end of file
......@@ -162,21 +162,42 @@ namespace ListwareDesktop.Reporting
foreach (int x in rcFields)
{
string mdresults = Fields[x];
string mdresults = "";
try
{
mdresults = Fields[x];
}
catch (IndexOutOfRangeException)
{
mdresults = "XXXX";
}
string[] rowcodes = mdresults.Split(',');
foreach (string rcode in rowcodes)
{
if (!this.openWith.ContainsKey(rcode))
if ((rcode.Length != 4) || ((rcode.Length == 4) && ((!char.IsLetter(rcode[0])) || (!char.IsLetter(rcode[1])) || (!char.IsDigit(rcode[2])) || (!char.IsDigit(rcode[3])))))
{
this.openWith.Add(rcode, 1);
if (!this.openWith.ContainsKey("XXXX"))
{
this.openWith.Add("XXXX", 1);
}
else
{
this.openWith["XXXX"] = openWith["XXXX"] + 1;
}
}
else
{
this.openWith[rcode] = openWith[rcode] + 1;
if (!this.openWith.ContainsKey(rcode))
{
this.openWith.Add(rcode, 1);
}
else
{
this.openWith[rcode] = openWith[rcode] + 1;
}
}
}
}
TTotal++;
......
......@@ -334,3 +334,4 @@ FS08 MEK Match
FE01 No Match
FE02 Minimum Input Not Met
FE03 Multiple Matches
XXXX Could not find results in row. Please check input delimiters and qualifiers.
\ No newline at end of file
......@@ -43,7 +43,7 @@
// companyLabel
//
this.companyLabel.AutoSize = true;
this.companyLabel.Location = new System.Drawing.Point(12, 116);
this.companyLabel.Location = new System.Drawing.Point(12, 101);
this.companyLabel.Name = "companyLabel";
this.companyLabel.Size = new System.Drawing.Size(176, 39);
this.companyLabel.TabIndex = 0;
......@@ -53,7 +53,7 @@
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(12, 184);
this.label5.Location = new System.Drawing.Point(12, 169);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(246, 39);
this.label5.TabIndex = 4;
......@@ -63,7 +63,7 @@
// techSupportEmailLinkLabel
//
this.techSupportEmailLinkLabel.AutoSize = true;
this.techSupportEmailLinkLabel.Location = new System.Drawing.Point(53, 210);
this.techSupportEmailLinkLabel.Location = new System.Drawing.Point(53, 195);
this.techSupportEmailLinkLabel.Name = "techSupportEmailLinkLabel";
this.techSupportEmailLinkLabel.Size = new System.Drawing.Size(117, 13);
this.techSupportEmailLinkLabel.TabIndex = 5;
......@@ -74,7 +74,7 @@
// wikiLabel
//
this.wikiLabel.AutoSize = true;
this.wikiLabel.Location = new System.Drawing.Point(12, 162);
this.wikiLabel.Location = new System.Drawing.Point(12, 147);
this.wikiLabel.Name = "wikiLabel";
this.wikiLabel.Size = new System.Drawing.Size(205, 13);
this.wikiLabel.TabIndex = 6;
......@@ -94,7 +94,7 @@
// websiteLinkLabel
//
this.websiteLinkLabel.AutoSize = true;
this.websiteLinkLabel.Location = new System.Drawing.Point(12, 103);
this.websiteLinkLabel.Location = new System.Drawing.Point(12, 88);
this.websiteLinkLabel.Name = "websiteLinkLabel";
this.websiteLinkLabel.Size = new System.Drawing.Size(91, 13);
this.websiteLinkLabel.TabIndex = 8;
......@@ -104,7 +104,9 @@
//
// pictureBox1
//
this.pictureBox1.Image = global::ListwareDesktop.Properties.Resources.Melissa_new_logo_no_tag_200px;
this.pictureBox1.ErrorImage = null;
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.InitialImage = null;
this.pictureBox1.Location = new System.Drawing.Point(26, 2);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(213, 70);
......@@ -114,7 +116,7 @@
// versionLabel
//
this.versionLabel.AutoSize = true;
this.versionLabel.Location = new System.Drawing.Point(12, 90);
this.versionLabel.Location = new System.Drawing.Point(12, 75);
this.versionLabel.Name = "versionLabel";
this.versionLabel.Size = new System.Drawing.Size(127, 13);
this.versionLabel.TabIndex = 10;
......@@ -124,7 +126,7 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(261, 228);
this.ClientSize = new System.Drawing.Size(261, 216);
this.Controls.Add(this.versionLabel);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.websiteLinkLabel);
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -37,11 +37,15 @@
//
this.previewDataGridView.AllowUserToAddRows = false;
this.previewDataGridView.AllowUserToDeleteRows = false;
this.previewDataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.DisplayedCells;
this.previewDataGridView.AllowUserToResizeRows = false;
this.previewDataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
this.previewDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.previewDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
this.previewDataGridView.Location = new System.Drawing.Point(0, 0);
this.previewDataGridView.Name = "previewDataGridView";
this.previewDataGridView.ReadOnly = true;
this.previewDataGridView.RowHeadersVisible = false;
this.previewDataGridView.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;
this.previewDataGridView.Size = new System.Drawing.Size(551, 261);
this.previewDataGridView.TabIndex = 0;
//
......
......@@ -26,10 +26,44 @@ namespace ListwareDesktop.Windows
InitializeComponent();
this.fillDGV();
this.resizeForm();
ClientSize = new Size(previewDataGridView.Width,previewDataGridView.Height);
}
private void resizeForm()
{
int originalHeight = this.previewDataGridView.Height;
int originalWidth = this.previewDataGridView.Width;
int sumHeight = this.previewDataGridView.ColumnHeadersHeight;
int sumWidth = 0;
foreach (DataGridViewRow row in this.previewDataGridView.Rows)
{
sumHeight += row.Height;
}
foreach (DataGridViewColumn column in this.previewDataGridView.Columns)
{
sumWidth += column.Width;
}
int heightDiff = originalHeight - sumHeight;
int widthDiff = originalWidth - sumWidth;
if (heightDiff > 0)
{
this.previewDataGridView.Height = sumHeight + 1;
this.Height = this.Height - heightDiff;
}
if (widthDiff > 0)
{
this.previewDataGridView.Width = sumWidth + 1;
this.Width = this.Width - widthDiff;
}
}
private void fillDGV()
{
Input inputPreview = new Input(inputFilePath, delimiter, qualifier);
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -42,15 +42,15 @@
//
this.setConfigurationFormDataGridView.AllowUserToAddRows = false;
this.setConfigurationFormDataGridView.AllowUserToDeleteRows = false;
this.setConfigurationFormDataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.setConfigurationFormDataGridView.AllowUserToResizeRows = false;
this.setConfigurationFormDataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.DisplayedCells;
this.setConfigurationFormDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.setConfigurationFormDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.setConfigurationFormDGVOptionName,
this.setConfigurationFormDGVOptionValues});
this.setConfigurationFormDataGridView.Dock = System.Windows.Forms.DockStyle.Top;
this.setConfigurationFormDataGridView.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter;
this.setConfigurationFormDataGridView.Location = new System.Drawing.Point(0, -2);
this.setConfigurationFormDataGridView.Location = new System.Drawing.Point(0, 0);
this.setConfigurationFormDataGridView.Name = "setConfigurationFormDataGridView";
this.setConfigurationFormDataGridView.RowHeadersVisible = false;
this.setConfigurationFormDataGridView.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;
......@@ -104,7 +104,6 @@
this.setConfigurationFormCheckedListBox.Size = new System.Drawing.Size(120, 94);
this.setConfigurationFormCheckedListBox.TabIndex = 3;
this.setConfigurationFormCheckedListBox.Visible = false;
this.setConfigurationFormCheckedListBox.Leave += new System.EventHandler(this.setConfigurationFormCheckedListBox_Leave);
//
// SetConfigurationForm
//
......
......@@ -15,15 +15,36 @@ namespace ListwareDesktop.Windows
{
IWS inputService;
CheckBox setConfigurationFormCheckBox;
DataGridViewCell currentCell;
DataGridViewCell currentMultipleCell;
Dictionary<string, string> localServiceOptions;
//Get which service we are using in constructor
internal SetConfigurationForm(IWS inputService, CheckBox setConfigurationFormCheckBox)
internal SetConfigurationForm(CheckBox setConfigurationFormCheckBox)
{
this.inputService = inputService;
this.inputService = Activator.CreateInstance(MainForm.serviceType) as IWS;
this.setConfigurationFormCheckBox = setConfigurationFormCheckBox;
localServiceOptions = MainForm.serviceOptions;
InitializeComponent();
this.fillDGV();
this.resizeForm();
}
//Auto size the form to the options
private void resizeForm()
{
int originalHeight = this.setConfigurationFormDataGridView.Height;
int sum = this.setConfigurationFormDataGridView.ColumnHeadersHeight;
foreach (DataGridViewRow row in this.setConfigurationFormDataGridView.Rows)
{
sum += row.Height;
}
this.setConfigurationFormDataGridView.Height = sum + 1;
int heightDiff = originalHeight - sum;
this.Height = this.Height - heightDiff;
this.setConfigurationFormSaveButton.Location = new Point(this.setConfigurationFormSaveButton.Location.X, this.setConfigurationFormSaveButton.Location.Y - heightDiff);
this.setConfigurationFormCancelButton.Location = new Point(this.setConfigurationFormCancelButton.Location.X, this.setConfigurationFormCancelButton.Location.Y - heightDiff);
}
//Fill datagridview for options from current service
......@@ -69,35 +90,35 @@ namespace ListwareDesktop.Windows
switch (optionType.ToLowerInvariant())
{
case "manual":
if (inputService.serviceOptions.ContainsKey(optionName))
if (localServiceOptions.ContainsKey(optionName))
{
row.Cells[1].Value = inputService.serviceOptions[optionName];
row.Cells[1].Value = localServiceOptions[optionName];
}
row.Cells[1].ReadOnly = false;
break;
case "single":
DataGridViewComboBoxCell comboboxCell = new DataGridViewComboBoxCell();
comboboxCell.Items.AddRange(inputService.settingsList[row.Cells[0].Value.ToString()].Where((v, i) => i != 0).ToArray());
if (inputService.serviceOptions.ContainsKey(optionName))
if (localServiceOptions.ContainsKey(optionName))
{
comboboxCell.Value = inputService.serviceOptions[optionName];
comboboxCell.Value = localServiceOptions[optionName];
}
row.Cells[1] = comboboxCell;
break;
case "multiple":
if (inputService.serviceOptions.ContainsKey(optionName))
if (localServiceOptions.ContainsKey(optionName))
{
row.Cells[1].Value = inputService.serviceOptions[optionName];
row.Cells[1].Value = localServiceOptions[optionName];
}
row.Cells[1].ReadOnly = true;
break;
}
}
}
}
}
//When the save button is hit, add all settings and values to the service
private void setConfigurationFormSaveButton_Click(object sender, EventArgs e)
//Method to save all of the cells to the service options dictionary
private void saveCellsToServiceOptions()
{
foreach (DataGridViewRow row in setConfigurationFormDataGridView.Rows)
{
......@@ -105,33 +126,45 @@ namespace ListwareDesktop.Windows
string optionType = inputService.settingsList[optionName][0];
List<string> optionValues = inputService.settingsList[optionName].Where((v, i) => i != 0).ToList();
//Go through each row in the datagridview and save the values to userService.serviceOptions
if ((row.Cells[1].Value != null) && (!row.Cells[1].Value.ToString().Trim().Equals("")))
if (row.Cells[1].Value != null)
{
if ((optionType.ToLowerInvariant().Equals("manual")) && (optionValues.Count > 0) && (row.Cells[1].Value.ToString().Equals(optionValues[0])))
if (localServiceOptions.ContainsKey(optionName))
{
//ignore these ones
}
else if ((optionType.ToLowerInvariant().Equals("multiple")) && (optionValues.Count > 0) && (row.Cells[1].Value.ToString().Equals("Click to Select")))
{
//ignore these too
}
else
{
if (inputService.serviceOptions.ContainsKey(row.Cells[0].Value.ToString()))
if (row.Cells[1].Value.ToString().Trim().Equals(""))
{
inputService.serviceOptions[row.Cells[0].Value.ToString()] = row.Cells[1].Value.ToString();
localServiceOptions.Remove(optionName);
}
else
{
inputService.serviceOptions.Add(row.Cells[0].Value.ToString(), row.Cells[1].Value.ToString());
localServiceOptions[optionName] = row.Cells[1].Value.ToString();
}
}
else
{
localServiceOptions.Add(optionName, row.Cells[1].Value.ToString());
}
}
}
}
//When the save button is hit, add all settings and values to the service
private void setConfigurationFormSaveButton_Click(object sender, EventArgs e)
{
if (setConfigurationFormCheckedListBox.Visible)
{
setConfigurationFormCheckedListBox.Hide();
setCellValue(currentMultipleCell);
setConfigurationFormCheckedListBox.Update();
}
this.saveCellsToServiceOptions();
this.Close();
setConfigurationFormCheckBox.Checked = true;
MainForm.serviceOptions = new Dictionary<string, string>(localServiceOptions);
if (localServiceOptions.Count > 0)
{
setConfigurationFormCheckBox.Checked = true;
}
}
//When cancel is hit, close the window
......@@ -140,81 +173,112 @@ namespace ListwareDesktop.Windows
this.Close();
}
//Method to move the checkedlistbox
private void moveCheckedListBox(DataGridViewCell inputCell)
{
int RowHeight1 = setConfigurationFormDataGridView.Rows[inputCell.RowIndex].Height;
Rectangle CellRectangle1 = setConfigurationFormDataGridView.GetCellDisplayRectangle(inputCell.ColumnIndex, inputCell.RowIndex, false);
CellRectangle1.X += setConfigurationFormDataGridView.Left;
CellRectangle1.Y += setConfigurationFormDataGridView.Top + RowHeight1;
setConfigurationFormCheckedListBox.Left = CellRectangle1.X;
setConfigurationFormCheckedListBox.Top = CellRectangle1.Y;
}
//This one is a little complicated, since there is no way to created a checkedlistbox cell other than to overload the method
//Essentially, we have a floating checkedlistbox that appears and disappears based on the user clicks
//It changes location based on what cell is clicked
//And it saves values when it is closed
private void setConfigurationFormDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
{
//This one is a little complicated, since there is no way to created a checkedlistbox cell other than to overload the method
//Essentially, we have a floating checkedlistbox that appears and disappears based on the user clicks
//It changes location based on what cell is clicked
//And it saves values when it is closed
if ((e.RowIndex >= 0) && (e.ColumnIndex >= 0))
if ((e.RowIndex >= 0) && (e.ColumnIndex == 1))
{
DataGridViewCell nameCell = setConfigurationFormDataGridView.Rows[e.RowIndex].Cells[0];
DataGridViewCell valueCell = setConfigurationFormDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex];
currentCell = valueCell;
DataGridViewCell valueCell = setConfigurationFormDataGridView.Rows[e.RowIndex].Cells[1];
string optionName = nameCell.Value.ToString();
string optionType = inputService.settingsList[optionName][0];
List<string> optionValues = inputService.settingsList[optionName].Where((v, i) => i != 0).ToList();
if ((e.ColumnIndex == 1) && (optionType.ToLowerInvariant().Equals("multiple")))
//If the checkedlistbox is invisible, and we are on the proper option type
//Move the checkedlistbox to the proper location, fill in the listbox items, set the proper checkmarks, show, then update
if (!setConfigurationFormCheckedListBox.Visible)
{
if(!setConfigurationFormCheckedListBox.Visible)
if (optionType.ToLowerInvariant().Equals("multiple"))
{
setConfigurationFormCheckedListBox.Items.Clear();
int RowHeight1 = setConfigurationFormDataGridView.Rows[e.RowIndex].Height;
Rectangle CellRectangle1 = setConfigurationFormDataGridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false);
CellRectangle1.X += setConfigurationFormDataGridView.Left;
CellRectangle1.Y += setConfigurationFormDataGridView.Top + RowHeight1;
setConfigurationFormCheckedListBox.Left = CellRectangle1.X;
setConfigurationFormCheckedListBox.Top = CellRectangle1.Y;
setConfigurationFormCheckedListBox.Items.AddRange(optionValues.ToArray());
if (inputService.serviceOptions.ContainsKey(optionName))
{
foreach(string individualOption in inputService.serviceOptions[optionName].Split(','))
{
if (optionValues.Contains(individualOption))
{
setConfigurationFormCheckedListBox.SetItemChecked(optionValues.IndexOf(individualOption), true);
}
}
}
this.moveCheckedListBox(valueCell);
this.setCheckedListBoxItems(valueCell);
this.setCheckedListBoxChecks(valueCell);
setConfigurationFormCheckedListBox.Show();
setConfigurationFormCheckedListBox.Update();
currentMultipleCell = valueCell;
}
}
else
{
//If the listbox is already visible, if we move to a different "multiple" option type, update the previous cell then
//Update the listbox, checks, and location
if ((optionType.ToLowerInvariant().Equals("multiple")) && (valueCell.RowIndex != currentMultipleCell.RowIndex))
{
this.setCellValue(currentMultipleCell);
this.setCheckedListBoxItems(valueCell);
this.setCheckedListBoxChecks(valueCell);
this.moveCheckedListBox(valueCell);
currentMultipleCell = valueCell;
}
//If the listbox is visible and we click on the same option as before, set the cell value and hide the listbox
else
{
this.setCellValue(valueCell);