我不確定在If/Else語句中調用函數時要傳遞哪些參數。由於參數,無法調用方法
If/Else語句正在調用2個函數之一Online_Version或Offline版本。
代碼如下:
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 [email protected]");
cmd.CommandText = ("SELECT last_name +', '+ first_name from name where id [email protected]");
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;
}
}
}
任何幫助表示讚賞!
他們看起來像他們應該用作事件處理程序給我。可能要處理重要新聞事件。像'this.KeyDown + = OfflineRegister;'可能是你正在尋找的東西。然後,當按下某個鍵時,您的'OfflineRegister'處理程序將響應事件的觸發。 – Jodrell
沒有關於這些方法做什麼的更多細節,唯一合理的猜測將是Form1_Load函數,sender和e的參數。 –
我認爲你應該在某些方法的事件處理程序中包裝代碼,並在'if/else'中調用這些方法。 – V4Vendetta