Update:
Okay, after a little bit of cleanup and testing, I have come up with the following...
private void dgEoM_Invoices_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
Dictionary<string, string> dict = new Dictionary<string, string>
{
{"01", "001_JAN" }, {"02", "002_FEB" }, {"03", "003_MAR" }, {"04", "004_APR" }, {"05", "005_MAY" }, {"06", "006_JUN" },
{ "07", "007_JUL" }, {"08", "008_AUG" }, {"09", "009_SEP" }, {"10", "010_OCT" }, {"11", "011_NOV" }, {"12", "012_DEC" },
};
string keyValue;
string folderPath = @"C:\Users\Steve Fontenot\Documents\Projects\Database _ WORKING\OUTGOING\";
if (e.RowIndex >= 0)
{
DataGridViewRow row = dgEoM_Invoices.Rows[e.RowIndex];
string company = row.Cells[0].Value.ToString();
string InvLocation2 = row.Cells[1].Value.ToString();
string[] invoiceMT = InvLocation2.Split('-');
string folderPath2 = (company + "\\MT " + InvLocation2 + "\\");
if (dict.TryGetValue(invoiceMT[1], out keyValue))
{
if (Directory.Exists(folderPath + company + "\\" + invoiceMT[0] + "\\" + keyValue + "\\MT " + InvLocation2 + "\\"))
{
ProcessStartInfo startInfo = new ProcessStartInfo
{
Arguments = (folderPath + company + "\\" + invoiceMT[0] + "\\" + keyValue + "\\MT " + InvLocation2 + "\\"),
FileName = "explorer.exe"
};
Process.Start(startInfo);
}
else
{
Console.WriteLine("NOT MATCHED!!!!!");
MessageBox.Show("ERROR!!! : The directory does not exist!");
}
}
}
}
I moved the if statement handling the directory check, so now it checks the entire string and notifies if the directory exits or not.
I also changed my approach on parsing out the information from the DGV after the user clicks it. It will read the cells containing the Company name and the invoice number, which is compared against a dictionary to account for the directory structure on the remote storage drive. It parses the invoice number string and determines the correct year and month, along with company name form another cell, and can locate the remote directory by splicing everything together.
It works for both methods, Incoming & Outgoing invoices, both generated from DGV event clicks and mapped to the corresponding directories.
I am still debating on adding a try/catch block, but for the moment, there is only 3 people using this little program, and of those 3, I am the primary user and the other two (for whom this feature was created) rarely utilize the program at all.
Alas, I am happy with the results and it is sufficient for their needs should they choose to use it.
Plus, I learned something in the process. :)
Regards. (marking this /solved)