?? addupdateform.cs
字號(hào):
this.lbCollegeCo.Items.Insert(1, array[0]);
this.cmbCollegeNa.Items.Insert(1, array[1]);
this.cmbCollege.Items.Insert(1, array[1]);
this.cmbCollegeNa.SelectedIndex = 1;
this.ResetLC(this.lbMemberCo, this.cmbMemberNa, "請(qǐng)選擇成員", "… 新增成員 …");
return;
}
else
{
int collegeCo = Convert.ToInt32(this.tbC.Tag);
this.cmbCollegeNa.SelectedIndex = this.lbCollegeCo.Items.IndexOf(collegeCo);
}
}
if(this.cmbCollegeNa.SelectedIndex == 0) //選擇“請(qǐng)選擇院系”
{
this.cmbMemberNa.Enabled = false;
this.ResetLC(this.lbMemberCo, this.cmbMemberNa, "請(qǐng)選擇成員", "… 新增成員 …");
}
else //選擇某一院系
{
this.ReadMember();
this.cmbMemberNa.Enabled = true;
}
}
private void cmbMemberNa_SelectionChangeCommitted(object sender, System.EventArgs e)
{
if(this.cmbMemberNa.SelectedIndex == (this.cmbMemberNa.Items.Count - 1)) //選擇“新增成員”
{
ArrayList array = null;
//調(diào)用新增成員窗體f
AddMember addMemberForm = new AddMember();
addMemberForm.Connection = this.sqlConnection;
addMemberForm.ShowDialog();
//array = f.GetArrayList();
array = addMemberForm.GetArrayList();
if(array != null && array[2].ToString() == this.lbCollegeCo.Items[this.cmbCollegeNa.SelectedIndex].ToString())
{
this.lbMemberCo.Items.Insert(1, array[0]);
this.cmbMemberNa.Items.Insert(1, array[1]);
this.cmbMemberNa.SelectedIndex = 1;
}
else
{
int memberCo = Convert.ToInt32(this.tbM.Tag);
this.cmbMemberNa.SelectedIndex = this.lbMemberCo.Items.IndexOf(memberCo);
}
}
}
private void cmbCollege_SelectionChangeCommitted(object sender, System.EventArgs e)
{
if(this.cmbCollege.SelectedIndex == (this.cmbCollegeNa.Items.Count - 1)) //選擇“新增院系”
{
ArrayList array = null;
//調(diào)用新增院系窗體f
//array = f.GetArrayList();
AddCollege addCollegeForm = new AddCollege();
addCollegeForm.Connection = this.sqlConnection;
addCollegeForm.ShowDialog();
if(array != null)
{
this.lbCollegeCo.Items.Insert(1, array[0]);
this.cmbCollegeNa.Items.Insert(1, array[1]);
this.cmbCollege.Items.Insert(1, array[1]);
this.cmbCollege.SelectedIndex = 1;
return;
}
else
{
int collegeCo = Convert.ToInt32(this.cmbCollege.Tag);
this.cmbCollege.SelectedIndex = this.lbCollegeCo.Items.IndexOf(collegeCo);
return;
}
}
this.cmbCollege.Tag = this.lbCollegeCo.Items[this.cmbCollege.SelectedIndex];
}
private void ResetLC(ListBox listBox, ComboBox comboBox, string chooseStr, string addStr)
{
listBox.Items.Clear();
comboBox.Items.Clear();
listBox.Items.Insert(0, 0);
comboBox.Items.Insert(0, chooseStr);
listBox.Items.Add(-1);
comboBox.Items.Add(addStr);
comboBox.SelectedIndex = 0;
}
private void ReadLC(ListBox listBox, ComboBox comboBox, string selectStr)
{
try
{
this.sqlConnection.Open();
this.sqlCommand.CommandText = selectStr;
this.sqlDataReader = this.sqlCommand.ExecuteReader();
while(this.sqlDataReader.Read())
{
listBox.Items.Insert(1, this.sqlDataReader[0]);
comboBox.Items.Insert(1, this.sqlDataReader[1]);
}
this.sqlDataReader.Close();
}
catch(Exception caught)
{
MessageBox.Show(caught.Message);
}
finally
{
this.sqlConnection.Close();
}
}
#endregion
#region /* 修改、刪除“負(fù)責(zé)人及主要合作者”部分 */
private void btnUpdate_Click(object sender, System.EventArgs e)
{
System.Windows.Forms.Button button = (Button)sender;
int tag = Convert.ToInt32(button.Tag);
this.SetButtonEnabled(false);
this.SetTools(tag);
int collegeCo = Convert.ToInt32(this.tbC.Tag);
int memberCo = Convert.ToInt32(this.tbM.Tag);
this.cmbCollegeNa.SelectedIndex = this.lbCollegeCo.Items.IndexOf(collegeCo);
this.ReadMember();
this.cmbCollegeNa_SelectionChangeCommitted(this.cmbCollegeNa, null);
this.cmbMemberNa.SelectedIndex = this.lbMemberCo.Items.IndexOf(memberCo);
this.panelMember.Location = lCollegeNa.Location;
this.panelMember.Visible = true;
this.cmbCollegeNa.Focus();
}
private void btnDelete_Click(object sender, System.EventArgs e)
{
System.Windows.Forms.Button button = (Button)sender;
int tag = Convert.ToInt32(button.Tag);
this.SetTools(tag);
DialogResult dialogResult = MessageBox.Show("是否確定刪除該負(fù)責(zé)人?", "系統(tǒng)提問(wèn)", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if(dialogResult == DialogResult.Yes)
{
//刪除操作
this.tbC.Text = " ——— 無(wú) ———";
this.tbC.Tag = 0;
this.tbM.Text = " —— 無(wú) ——";
this.tbM.Tag = 0;
}
}
private void btnCommit_Click(object sender, System.EventArgs e)
{
if(this.cmbCollegeNa.SelectedIndex != 0 && this.cmbMemberNa.SelectedIndex != 0)
{
this.tbC.Text = this.cmbCollegeNa.Text;
this.tbC.Tag = this.lbCollegeCo.Items[this.cmbCollegeNa.SelectedIndex];
this.tbM.Text = this.cmbMemberNa.Text;
this.tbM.Tag = this.lbMemberCo.Items[this.cmbMemberNa.SelectedIndex];
}
this.panelMember.Visible = false;
this.SetButtonEnabled(true);
}
private void btnBack_Click(object sender, System.EventArgs e)
{
this.panelMember.Visible = false;
this.SetButtonEnabled(true);
}
#endregion
#region /* 公有屬性 */
/// <summary>
/// 設(shè)置該窗體所使用的 SqlConnection 。
/// </summary>
public System.Data.SqlClient.SqlConnection Connection
{
set
{
this.sqlConnection = value;
this.sqlCommand.Connection = this.sqlConnection;
this.storedProcedure.Connection = this.sqlConnection;
}
}
/// <summary>
/// 設(shè)置該窗體所使用的 DataRow 。
/// </summary>
public System.Data.DataRow DataRow
{
set
{
this.dataRow = value;
}
}
/// <summary>
/// 獲取修改或新添加的課題編號(hào)的集合。
/// </summary>
public ArrayList NewTaskArrayList
{
get
{
return this.newTaskArrayList;
}
}
#endregion
#region /* 相關(guān)數(shù)據(jù)設(shè)置 */
/// <summary>
/// 顯示該窗體。
/// </summary>
public void ShowForm()
{
if(this.dataRow == null)
{
return;
}
else if(this.dataRow.IsNull("課題ID"))
{
this.Text = "添加課題";
this.btnOK.Text = "添 加";
this.ShowDialog();
}
else if(this.DataBind())
{
this.Text = "修改課題";
this.btnOK.Text = "修 改";
this.ShowDialog();
}
}
/// <summary>
/// 相關(guān)數(shù)據(jù)綁定
/// </summary>
/// <returns></returns>
private bool DataBind()
{
try
{
this.tbTaskName.Tag = this.dataRow["課題ID"];
this.cmbSortNa.Tag = this.dataRow["分類編號(hào)"];
this.cmbLevelNa.Tag = this.dataRow["級(jí)別編號(hào)"];
this.dtpYear.Value = Convert.ToDateTime(this.dataRow["年份"]);
this.tbTaskCo.Tag = this.dataRow["序號(hào)"];
this.cmbCollege.Tag = this.dataRow["所屬院系"];
this.tbTaskName.Text = this.dataRow["課題名稱"].ToString();
this.tbStart.Text = Convert.ToString(this.dataRow["立項(xiàng)日期"]);
this.tbPlan.Text = Convert.ToString(this.dataRow["擬結(jié)項(xiàng)日期"]);
this.tbEnd.Text = Convert.ToString(this.dataRow["結(jié)項(xiàng)日期"]);
this.nudStandard.Value = Convert.ToDecimal(this.dataRow["經(jīng)費(fèi)標(biāo)準(zhǔn)"]);
this.nudAlready.Value = Convert.ToDecimal(this.dataRow["已撥經(jīng)費(fèi)"]);
this.nudSurplus.Value = Convert.ToDecimal(this.dataRow["剩余經(jīng)費(fèi)"]);
this.tbTel.Text = this.dataRow["聯(lián)系電話"].ToString();
this.tbEmail.Text = this.dataRow["Email"].ToString();
this.tbRemark.Text = this.dataRow["備注"].ToString();
if(this.dataRow["負(fù)責(zé)人"] != Convert.DBNull)
this.tbMemberNaMain.Tag = this.dataRow["負(fù)責(zé)人"];
if(this.dataRow["參研人1"] != Convert.DBNull)
this.tbMemberNa1.Tag = this.dataRow["參研人1"];
if(this.dataRow["參研人2"] != Convert.DBNull)
this.tbMemberNa2.Tag = this.dataRow["參研人2"];
if(this.dataRow["參研人3"] != Convert.DBNull)
this.tbMemberNa3.Tag = this.dataRow["參研人3"];
if(this.dataRow["參研人4"] != Convert.DBNull)
this.tbMemberNa4.Tag = this.dataRow["參研人4"];
if(this.dataRow["參研人5"] != Convert.DBNull)
this.tbMemberNa5.Tag = this.dataRow["參研人5"];
this.tbTaskCo.Text = this.dataRow["分類拼音"].ToString();
this.tbTaskCo.Text += this.dataRow["級(jí)別拼音"].ToString();
this.tbTaskCo.Text += this.dataRow["年份"].ToString().Substring(2, 2);
this.tbTaskCo.Text += "-";
this.tbTaskCo.Text += this.dataRow["序號(hào)"].ToString().PadLeft(2, '0');
return true;
}
catch
{
return false;
}
}
/// <summary>
/// 顯示相關(guān)數(shù)據(jù)。
/// </summary>
private void DataShow()
{
if(this.dataRow.IsNull("課題ID"))
{
return;
}
try
{
this.sqlConnection.Open();
for(int i = 0; i < 6; i++)
{
this.SetTools(i);
if(Convert.ToInt32(this.tbM.Tag) == 0)
{
continue;
}
this.sqlCommand.CommandText = "select MemberNa, CollegeCo, CollegeNa from viewCM";
this.sqlCommand.CommandText += " where MemberCo = " + this.tbM.Tag;
this.sqlDataReader = this.sqlCommand.ExecuteReader();
if(this.sqlDataReader.Read())
{
this.tbM.Text = this.sqlDataReader["MemberNa"].ToString();
this.tbC.Tag = this.sqlDataReader["CollegeCo"];
this.tbC.Text = this.sqlDataReader["CollegeNa"].ToString();
}
this.sqlDataReader.Close();
}
this.cmbSortNa.SelectedIndex = this.lbSortCo.Items.IndexOf(this.cmbSortNa.Tag);
this.cmbLevelNa.SelectedIndex = this.lbLevelCo.Items.IndexOf(this.cmbLevelNa.Tag);
this.cmbCollege.SelectedIndex = this.lbCollegeCo.Items.IndexOf(this.cmbCollege.Tag);
}
catch(Exception caught)
{
MessageBox.Show(caught.Message);
}
finally
{
this.sqlConnection.Close();
}
}
/// <summary>
/// 重新設(shè)置相關(guān)數(shù)據(jù)。
/// </summar
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -