Skip to content

Commit

Permalink
Cleaned UI and added explainations to user errors
Browse files Browse the repository at this point in the history
  • Loading branch information
xangelix committed Dec 12, 2017
1 parent b799759 commit 57053bc
Show file tree
Hide file tree
Showing 5 changed files with 1,152 additions and 149 deletions.
4 changes: 3 additions & 1 deletion OCR to SQL/OCR to SQL/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

296 changes: 151 additions & 145 deletions OCR to SQL/OCR to SQL/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,202 +47,208 @@ class Person

private void button1_Click(object sender, EventArgs e)
{
string ex1 = textBox1.Text;
if (textBox1.Text != "" && textBox3.Text != "")
{
string ex1 = textBox1.Text;

var dictionary = new Dictionary<string, Person>();

string[] files = Directory.GetFiles(textBox1.Text);
List<string> outputs = new List<string>();
List<string> resolvedoutputs = new List<string>();
var dictionary = new Dictionary<string, Person>();

string[] files = Directory.GetFiles(textBox1.Text);
List<string> outputs = new List<string>();
List<string> resolvedoutputs = new List<string>();

for (int i = 0; i < files.Length; i++)
{
try

for (int i = 0; i < files.Length; i++)
{
using (var engine = new TesseractEngine(@"tessdata", "eng", EngineMode.Default))
try
{
using (var img = Pix.LoadFromFile(files[i]))
using (var engine = new TesseractEngine(@"tessdata", "eng", EngineMode.Default))
{
using (var page = engine.Process(img))
using (var img = Pix.LoadFromFile(files[i]))
{
var text = page.GetText();
using (var page = engine.Process(img))
{
var text = page.GetText();

outputs.Add(text);
outputs.Add(text);

}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(String.Format("Error: {0}", ex.Message));
}
catch (Exception ex)
{
MessageBox.Show(String.Format("Error: {0}", ex.Message));
}

resolvedoutputs.Add(outputs[i]);
resolvedoutputs.Add(outputs[i]);

int indexOfFirstPhrase = outputs[i].IndexOf("32920");
if (indexOfFirstPhrase >= 0)
{
indexOfFirstPhrase += "32920".Length;
int indexOfSecondPhrase = outputs[i].IndexOf("khfjlkahfgkjeahfjhaekhfkjahjslf", indexOfFirstPhrase);
if (indexOfSecondPhrase >= 0)
resolvedoutputs[i] = outputs[i].Substring(indexOfFirstPhrase, indexOfSecondPhrase - indexOfFirstPhrase);
else
resolvedoutputs[i] = outputs[i].Substring(indexOfFirstPhrase);
}
string tempOut = DeleteLines(resolvedoutputs[i], 3, false);
//MessageBox.Show(resolvedoutputs[i]);
int indexOfFirstPhrase = outputs[i].IndexOf("32920");
if (indexOfFirstPhrase >= 0)
{
indexOfFirstPhrase += "32920".Length;
int indexOfSecondPhrase = outputs[i].IndexOf("khfjlkahfgkjeahfjhaekhfkjahjslf", indexOfFirstPhrase);
if (indexOfSecondPhrase >= 0)
resolvedoutputs[i] = outputs[i].Substring(indexOfFirstPhrase, indexOfSecondPhrase - indexOfFirstPhrase);
else
resolvedoutputs[i] = outputs[i].Substring(indexOfFirstPhrase);
}
string tempOut = DeleteLines(resolvedoutputs[i], 3, false);
//MessageBox.Show(resolvedoutputs[i]);

//MessageBox.Show(tempOut);
//MessageBox.Show(tempOut);


int index = resolvedoutputs[i].IndexOf(tempOut, StringComparison.Ordinal);
string cleanPath = (index < 0)
? resolvedoutputs[i]
: resolvedoutputs[i].Remove(index, tempOut.Length);
int index = resolvedoutputs[i].IndexOf(tempOut, StringComparison.Ordinal);
string cleanPath = (index < 0)
? resolvedoutputs[i]
: resolvedoutputs[i].Remove(index, tempOut.Length);

//MessageBox.Show(resolvedoutputs[i]);
//string[] resolvedOutputsName = resolvedoutputs[i].Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
string[] resolvedOutputsName = resolvedoutputs[i].Split(new Char[] { '\n' });
//MessageBox.Show(resolvedoutputs[i]);
//string[] resolvedOutputsName = resolvedoutputs[i].Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
string[] resolvedOutputsName = resolvedoutputs[i].Split(new Char[] { '\n' });

int resolvingIndex = 0;
resolvedOutputsName = resolvedOutputsName.Where(x => !string.IsNullOrEmpty(x)).ToArray();
int resolvingIndex = 0;
resolvedOutputsName = resolvedOutputsName.Where(x => !string.IsNullOrEmpty(x)).ToArray();

string personName = "name not set";
string personStreet = "street not set";
string personCity = "person not set";
string personState = "state not set";
string personZip = "zip not set";
string personName = "name not set";
string personStreet = "street not set";
string personCity = "person not set";
string personState = "state not set";
string personZip = "zip not set";


foreach (string s in resolvedOutputsName)
{

if (true)
foreach (string s in resolvedOutputsName)
{
switch (resolvingIndex)

if (true)
{
case 0:
//MessageBox.Show("Name: " + s);
personName = s;
break;
case 1:
//MessageBox.Show("Street Address: " + s);
personStreet = s;
break;
case 2:
//MessageBox.Show("City: " + s);
personCity = s;
break;
switch (resolvingIndex)
{
case 0:
//MessageBox.Show("Name: " + s);
personName = s;
break;
case 1:
//MessageBox.Show("Street Address: " + s);
personStreet = s;
break;
case 2:
//MessageBox.Show("City: " + s);
personCity = s;
break;
}

}

resolvingIndex++;

}
resolvingIndex++;

}
//personZip = int.Parse(personCity.Substring(Math.Max(0, personCity.Length - 5)));

//personZip = int.Parse(personCity.Substring(Math.Max(0, personCity.Length - 5)));


//personCity = personCity.Remove(personCity.Length - 3);
//personCity = personCity.Remove(personCity.Length - 3);

try
{
personZip = personCity.Substring(personCity.Length - 5);
}
catch (Exception ex)
{
MessageBox.Show(String.Format("Error: {0}", ex.Message));
}
try
{
personZip = personCity.Substring(personCity.Length - 5);
}
catch (Exception ex)
{
MessageBox.Show(String.Format("Error: {0}", ex.Message));
}




int cityIndex = personCity.IndexOf(",");
int cityIndex = personCity.IndexOf(",");

if (cityIndex > 0)
{
personState = personCity.Substring(cityIndex + 2, 2);
}
if (cityIndex > 0)
{
personState = personCity.Substring(cityIndex + 2, 2);
}

if (cityIndex > 0)
{
personCity = personCity.Substring(0, cityIndex);
}
if (cityIndex > 0)
{
personCity = personCity.Substring(0, cityIndex);
}

dictionary.Add("NewPerson" + i, new Person());
dictionary["NewPerson" + i].Name = personName;
dictionary["NewPerson" + i].Street = personStreet;
dictionary["NewPerson" + i].City = personCity;
dictionary["NewPerson" + i].State = personState;
dictionary["NewPerson" + i].Zip = personZip;
dictionary.Add("NewPerson" + i, new Person());
dictionary["NewPerson" + i].Name = personName;
dictionary["NewPerson" + i].Street = personStreet;
dictionary["NewPerson" + i].City = personCity;
dictionary["NewPerson" + i].State = personState;
dictionary["NewPerson" + i].Zip = personZip;

Form2 form2 = new Form2();

form2.Text = files[i];
Form2 form2 = new Form2();

form2.textBox1.Text = dictionary["NewPerson" + i].Name;
form2.textBox2.Text = dictionary["NewPerson" + i].Street;
form2.textBox3.Text = dictionary["NewPerson" + i].City;
form2.textBox4.Text = dictionary["NewPerson" + i].State;
form2.textBox5.Text = dictionary["NewPerson" + i].Zip.ToString();
form2.Text = files[i];

form2.textBox6.Text = textBox3.Text;
form2.textBox1.Text = dictionary["NewPerson" + i].Name;
form2.textBox2.Text = dictionary["NewPerson" + i].Street;
form2.textBox3.Text = dictionary["NewPerson" + i].City;
form2.textBox4.Text = dictionary["NewPerson" + i].State;
form2.textBox5.Text = dictionary["NewPerson" + i].Zip.ToString();

form2.richTextBox1.Text = resolvedoutputs[i];
form2.textBox6.Text = textBox3.Text;

form2.pictureBox1.Image = Image.FromFile(files[i]);
form2.richTextBox1.Text = resolvedoutputs[i];

form2.ShowDialog();
form2.pictureBox1.Image = Image.FromFile(files[i]);

string reason = "";
form2.ShowDialog();

string reason = "";

//Determining Reason
if (form2.radioButton1.Checked)
{
reason = "Not Deliverable as Addressed";
}
else if (form2.radioButton2.Checked)
{
reason = "No Such Number";
}
else if (form2.radioButton3.Checked)
{
reason = "No Mail Receptacle";
}
else if (form2.radioButton4.Checked)
{
reason = "No Such Street";
}
else if (form2.radioButton5.Checked)
{
reason = "Vacant";
}
else if (form2.radioButton6.Checked)
{
reason = form2.textBox7.Text;
}

using (StreamWriter sw = File.AppendText(textBox1.Text + "\\" + form2.textBox6.Text + ".sql"))
{
sw.WriteLine(String.Format("INSERT INTO people (name, street, city, state, zip, reason) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}');", form2.textBox1.Text, form2.textBox2.Text, form2.textBox3.Text, form2.textBox4.Text, form2.textBox5.Text, reason));
}
//Determining Reason
if (form2.radioButton1.Checked)
{
reason = "Not Deliverable as Addressed";
}
else if (form2.radioButton2.Checked)
{
reason = "No Such Number";
}
else if (form2.radioButton3.Checked)
{
reason = "No Mail Receptacle";
}
else if (form2.radioButton4.Checked)
{
reason = "No Such Street";
}
else if (form2.radioButton5.Checked)
{
reason = "Vacant";
}
else if (form2.radioButton6.Checked)
{
reason = form2.textBox7.Text;
}

if (i == files.Length - 1)
{
//Confirmation
MessageBox.Show("Saved to: " + textBox1.Text + "\\" + form2.textBox6.Text + ".sql");
}

}
using (StreamWriter sw = File.AppendText(textBox1.Text + "\\" + form2.textBox6.Text + ".sql"))
{
sw.WriteLine(String.Format("INSERT INTO people (name, street, city, state, zip, reason) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}');", form2.textBox1.Text, form2.textBox2.Text, form2.textBox3.Text, form2.textBox4.Text, form2.textBox5.Text, reason));
}

//string outputsString = string.Join(", ", outputs.ToArray());
//MessageBox.Show(outputsString);
if (i == files.Length - 1)
{
//Confirmation
MessageBox.Show("Saved to: " + textBox1.Text + "\\" + form2.textBox6.Text + ".sql");
}

}

Application.Exit();
//string outputsString = string.Join(", ", outputs.ToArray());
//MessageBox.Show(outputsString);

Application.Exit();
}
else
{
MessageBox.Show("Please fill in all required forms!");
}
}

private void button2_Click(object sender, EventArgs e)
Expand Down
Loading

0 comments on commit 57053bc

Please sign in to comment.