この If/Else ステートメントで関数を呼び出すときに、どのパラメーターを渡す必要があるのか わかりません。
If/Else ステートメントは、Online_Version または Offline Version の 2 つの関数のうちの 1 つを呼び出しています。
コードは次のとおりです。
public void Form1_Load(object sender, EventArgs e)
{
if (MessageBox.Show("Would you like to run the Event Register?", "Registration Selection", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
label5.Text = "Event Registration";
textBox1.Select();
this.TopMost = true;
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
var fileSave = new FileStream(fullFileName, FileMode.Create);
fileSave.Close();
OfflineRegister();
}
else
{
label5.Text = "ICAS Register";
textBox1.Select();
this.TopMost = true;
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
var fileSave = new FileStream(fullFileName, FileMode.Create);
fileSave.Close();
OnlineRegister();
}
}
public void Online_Register(object sender, KeyPressEventArgs e)
{
OnlineRegister();
}
public void Offline_Register(object sender, KeyPressEventArgs e)
{
OfflineRegister();
}
public void OnlineRegister()
{
SqlConnection DBConnection = new SqlConnection("Data Source=DATABASE;Initial Catalog=imis;Integrated Security=True");
SqlCommand cmd = new SqlCommand();
Object returnValue;
string txtend = textBox1.Text;
string lastTwoChars = txtend.Substring(txtend.Length - 1);
if (textBox1.Text.Length != 6 && e.KeyChar != '*') return;
//cmd.CommandText = ("SELECT last_name +', '+ first_name +'\t ('+major_key+')\t' from name where id =@Name");
cmd.CommandText = ("SELECT last_name +', '+ first_name from name where id =@Name");
cmd.Parameters.Add(new SqlParameter("Name", textBox1.Text.Replace(@"L", "")));
cmd.CommandType = CommandType.Text;
cmd.Connection = DBConnection;
//Time = DateTime.Now.ToString("HH:mm");
//TimeIn = "Time In: ";
//TimeOut = "Time Out: ";
returnValue = cmd.ExecuteScalar() + "\t (" + textBox1.Text.Replace(@"L", "") + ")";
DBConnection.Close();
if (listBox1.Items.Contains(returnValue))
{
for (int n = listBox1.Items.Count - 1; n >= 0; --n)
{
string removelistitem = returnValue.ToString();
if (listBox1.Items[n].ToString().Contains(removelistitem))
{
listBox1.Items.RemoveAt(n);
//listBox1.Items.Add(removelistitem + " " + 'TimeOut' + 'Time');
}
}
}
else
listBox1.Items.Add(returnValue);
textBox1.Clear();
System.IO.StreamWriter sw = new System.IO.StreamWriter(fullFileName);
foreach (object item in listBox1.Items)
sw.WriteLine(item.ToString());
sw.Flush();
sw.Close();
if (listBox1.Items.Count != 0) { DisableCloseButton(); }
else
{
EnableCloseButton();
}
label6.Text = "Currently " + listBox1.Items.Count.ToString() + " in attendance.";
e.Handled = true;
}
public void OfflineRegister()
{
Object returnValue;
string txtend = textBox1.Text;
returnValue = textBox1.Text.Replace(@"*", "");
if (e.KeyChar != '*') return;
{
if (listBox1.Items.Contains(returnValue))
{
for (int n = listBox1.Items.Count - 1; n >= 0; --n)
{
string removelistitem = returnValue.ToString();
if (listBox1.Items[n].ToString().Contains(removelistitem))
{
//listBox1.Items.RemoveAt(n);
}
}
}
else
{
listBox1.Items.Add(returnValue);
textBox1.Clear();
System.IO.StreamWriter sw = new System.IO.StreamWriter(fullFileName);
foreach (object item in listBox1.Items)
sw.WriteLine(item.ToString());
sw.Flush();
sw.Close();
if (listBox1.Items.Count != 0) { DisableCloseButton(); }
else
{
EnableCloseButton();
}
label6.Text = "Currently " + listBox1.Items.Count.ToString() + " in attendance.";
e.Handled = true;
}
}
}
どんな助けでも大歓迎です!