📄 副本 addupdateform.cs
字号:
private void cmbCollegeNa_SelectionChangeCommitted(object sender, System.EventArgs e)
{
if(this.cmbCollegeNa.SelectedIndex == (this.cmbCollegeNa.Items.Count - 1)) //选择“新增院系”
{
ArrayList array = null;
//调用新增院系窗体f
AddCollege addCollegeForm = new AddCollege();
addCollegeForm.Connection = this.sqlConnection;
addCollegeForm.ShowDialog();
//array = f.GetArrayList();
array = addCollegeForm.GetArrayList();
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.cmbCollegeNa.SelectedIndex = 1;
this.ResetLC(this.lbMemberCo, this.cmbMemberNa, "请选择成员", "… 新增成员 …");
return;
}
else
{
int collegeCo = Convert.ToInt32(this.tbC.Tag);
this.cmbCollegeNa.SelectedIndex = this.lbCollegeCo.Items.IndexOf(collegeCo);
}
}
if(this.cmbCollegeNa.SelectedIndex == 0) //选择“请选择院系”
{
this.cmbMemberNa.Enabled = false;
this.ResetLC(this.lbMemberCo, this.cmbMemberNa, "请选择成员", "… 新增成员 …");
}
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;
//调用新增成员窗体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;
//调用新增院系窗体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 /* 修改、删除“负责人及主要合作者”部分 */
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("是否确定删除该负责人?", "系统提问", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if(dialogResult == DialogResult.Yes)
{
//删除操作
this.tbC.Text = " ——— 无 ———";
this.tbC.Tag = 0;
this.tbM.Text = " —— 无 ——";
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>
/// 设置该窗体所使用的 SqlConnection 。
/// </summary>
public System.Data.SqlClient.SqlConnection Connection
{
set
{
this.sqlConnection = value;
this.sqlCommand.Connection = this.sqlConnection;
this.storedProcedure.Connection = this.sqlConnection;
}
}
/// <summary>
/// 设置该窗体所使用的 DataRow 。
/// </summary>
public System.Data.DataRow DataRow
{
set
{
this.dataRow = value;
}
}
/// <summary>
/// 获取修改或新添加的课题编号的集合。
/// </summary>
public ArrayList NewTaskArrayList
{
get
{
return this.newTaskArrayList;
}
}
#endregion
#region /* 相关数据设置 */
/// <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>
/// 相关数据绑定
/// </summary>
/// <returns></returns>
private bool DataBind()
{
try
{
this.tbTaskName.Tag = this.dataRow["课题ID"];
this.cmbSortNa.Tag = this.dataRow["分类编号"];
this.cmbLevelNa.Tag = this.dataRow["级别编号"];
this.dtpYear.Value = Convert.ToDateTime(this.dataRow["年份"]);
this.tbTaskCo.Tag = this.dataRow["序号"];
this.cmbCollege.Tag = this.dataRow["所属院系"];
this.tbTaskName.Text = this.dataRow["课题名称"].ToString();
this.tbStart.Text = Convert.ToString(this.dataRow["立项日期"]);
this.tbPlan.Text = Convert.ToString(this.dataRow["拟结项日期"]);
this.tbEnd.Text = Convert.ToString(this.dataRow["结项日期"]);
this.nudStandard.Value = Convert.ToDecimal(this.dataRow["经费标准"]);
this.nudAlready.Value = Convert.ToDecimal(this.dataRow["已拨经费"]);
this.nudSurplus.Value = Convert.ToDecimal(this.dataRow["剩余经费"]);
this.tbTel.Text = this.dataRow["联系电话"].ToString();
this.tbEmail.Text = this.dataRow["Email"].ToString();
this.tbRemark.Text = this.dataRow["备注"].ToString();
if(this.dataRow["负责人"] != Convert.DBNull)
this.tbMemberNaMain.Tag = this.dataRow["负责人"];
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["级别拼音"].ToString();
this.tbTaskCo.Text += this.dataRow["年份"].ToString().Substring(2, 2);
this.tbTaskCo.Text += "-";
this.tbTaskCo.Text += this.dataRow["序号"].ToString().PadLeft(2, '0');
return true;
}
catch
{
return false;
}
}
/// <summary>
/// 显示相关数据。
/// </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.cm
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -