Both functions look fairly similar to each other, but they are different in the type of string. I have 6 functions like this and all differ only in the "string cmd". Any ideas on how I can put it all into one?
public void getFrmSingProgTbl(int flg)
{
if (flg == 1)
{
object[] astatus = new object[1];
astatus = td.CheckOk(td.t1snd);
string status = (string)astatus[0];
if (status == "true")
{
string cmd = getCurrTime() + "|" + "part-type" + "|" + t1prtNameTxt.Text + "\n";
cmd += getCurrTime() + "|" + "operation-type" + "|" + t1oprNameTxt.Text + "\n";
string showCmd = "Part Type - " + t1prtNameTxt.Text + "\nOperation - " + t1oprNameTxt.Text;
if (MessageBox.Show(showCmd, "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
HandleAfterSend(td.t1snd, td.t1stp, flg, td.t1btn);
sndData(cmd,1);
}
}
else
{
this.ActiveControl = (TextBox)astatus[1];
MessageBox.Show(status, "Error");
}
}
else if (flg == 2)
{
object[] astatus = new object[1];
astatus = td.CheckOk(td.t1stp);
string status = (string)astatus[0];
if (status == "true")
{
string cmd = getCurrTime() + "|" + "part-count-good" + "|" + t1gpTxt.Text + "\n";
cmd += getCurrTime() + "|" + "part-count-bad" + "|" + t1bpTxt.Text + "\n";
string showCmd = "Good Parts - " + t1gpTxt.Text + "\nBad Parts - " + t1bpTxt.Text;
if (td.CheckNumeric(td.t1stp))
{
if (MessageBox.Show(showCmd, "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
HandleAfterSend(td.t1stp, td.t1snd, flg, td.t1btn);
sndData(cmd,0);
}
}
else
{
MessageBox.Show("Enter only numbers for Part Count","Error");
}
}
else
{
this.ActiveControl = (TextBox)astatus[1];
MessageBox.Show(status, "Error");
}
}
}
public void getFrmSingFixtTbl(int flg)
{
if (flg == 1)
{
object[] astatus = new object[1];
astatus = td.CheckOk(td.t3snd);
string status = (string)astatus[0];
if (status == "true")
{
string cmd = getCurrTime() + "|" + "part-type" + "|" + t3prtNameTxt.Text + "\n";
cmd += getCurrTime() + "|" + "operation-type" + "|" + t3oprNameTxt.Text + "\n";
cmd += getCurrTime() + "|" + "fixture-positions" + "|" + t3fixPosnTxt.Text + "\n";
string showCmd = "Part Type" + " - " + t3prtNameTxt.Text + "\n";
showCmd += "Operation" + " - " + t3oprNameTxt.Text + "\n";
showCmd += "Parts per Fixture " + " - " + t3fixPosnTxt.Text + "\n";
if (MessageBox.Show(showCmd, "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
HandleAfterSend(td.t3snd, td.t3stp, flg, td.t3btn);
sndData(cmd,1);
}
}
else
{
this.ActiveControl = (TextBox)astatus[1];
MessageBox.Show(status, "Error");
}
}
else if (flg == 2)
{
object[] astatus = new object[1];
astatus = td.CheckOk(td.t3stp);
string status = (string)astatus[0];
if (status == "true")
{
string cmd = getCurrTime() + "|" + "part-count-good" + "|" + t3gpTxt.Text + "\n";
cmd += getCurrTime() + "|" + "part-count-bad" + "|" + t3bpTxt.Text + "\n";
string showCmd = "Good Parts" + " - " + t3gpTxt.Text + "\n";
showCmd += "Bad Parts" + " - " + t3bpTxt.Text + "\n";
if (td.CheckNumeric(td.t3stp))
{
if (MessageBox.Show(showCmd, "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
HandleAfterSend(td.t3stp, td.t3snd, flg, td.t3btn);
sndData(cmd,0);
}
}
else
{
MessageBox.Show("Enter only numbers for Part Count","Error");
}
}
else
{
this.ActiveControl = (TextBox)astatus[1];
MessageBox.Show(status, "Error");
}
}
}