我工作的C#項目,所以我有2個功能,我只需要如果FUNCTION1已經做到,那麼我想要的功能2執行,其他功能2,必須防止執行(Didnot Execute !!)。如果FUN1做做FUN2,否則不做FUN2
我的功能1名爲SaveDuplicatCourse()
和功能2呼籲Save()
,對方的代碼如下:
public void SaveDuplicatCourse()
{
if(con.State !=ConnectionState.Open)
con.Open();
List<int> IDs = new List<int>();
foreach (DataGridViewRow r in dataGridViewStudents.Rows)
{
if (r.Cells[0].Value != null && bool.Parse(r.Cells[0].Value.ToString()))
{
IDs.Add(int.Parse(r.Cells[1].Value.ToString()));
}
}
foreach (int i in IDs)
{
try
{
SqlCommand com = new SqlCommand(@"Insert into DuplicateCourses
values(" + i + "," + CCID + ")", con);
com.ExecuteNonQuery();
}
catch (Exception)
{
MessageBox.Show("They are exist");
}
}
con.Close();
}
public void Save()
{
SqlCommand com = new SqlCommand(@"Delete from students
where
Course_ID = " + ID, con);
con.Open();
com.ExecuteNonQuery();
List<int> IDs = new List<int>();
foreach (DataGridViewRow r in dataGridViewStudents.Rows)
{
if (r.Cells[0].Value!=null && bool.Parse(r.Cells[0].Value.ToString()))
{
IDs.Add(int.Parse(r.Cells[1].Value.ToString()));
}
}
foreach (int i in IDs)
{
com.CommandText = "Insert into students values(" + i + "," + ID + ")";
com.ExecuteNonQuery();
}
con.Close();
}
我ButtonClick
稱這些功能如下
private void buttonSaveChanges_Click(object sender, EventArgs e)
{
SaveDuplicatCourse();
Save();
}
請告訴我怎麼回事將會完成。
我不知道你在說什麼。 'unexecuted'?什麼......? –
使這些函數返回布爾值而不是void。 – MikeTheLiar
第一個函數返回'bool'? if(Func1())Func2();' –