⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 orgsettings.cs

📁 C#2.0宝典源码,C#经典书籍,很多例子
💻 CS
📖 第 1 页 / 共 5 页
字号:
        {
          try
          {
            managerCol.Delete(txtCollegeID.Text.Trim());            
            Bind_gridCollege();
          }
          catch(Exception e1)
          {
            MessageBox.Show(e1.Message);
          }
        }
      }
    }

    /// <summary>
    /// 获取一个值,该值指示用户输入的学院信息是否符合要求。若符合返回true,否则返回false。
    /// </summary>
    private bool CollegeInfoValidated
    {
      get
      {
        if(!StringValidation.isLengthSetNumString(txtCollegeID.Text.Trim(),2))
        {
          MessageBox.Show("学院编号必须是两位数字,请重新输入或选择。");
          return false;
        }
        else if(txtCollegeName.Text.Trim() == "")
        {
          MessageBox.Show("请先输入学院名称。");
          return false;
        }
        else
          return true;
      }
    }

    /// <summary>
    /// 获取一个值,该值指示用户输入的专业信息是否符合要求。若符合返回true,否则返回false。
    /// </summary>
    private bool SpecialityInfoValidated
    {
      get
      {
        if(this.labelSpeID.Text.Trim()=="XX-")
        {
          MessageBox.Show("请先选择专业所属的学院。");
          return false;
        }
        else if(!StringValidation.isLengthSetNumString(txtSpecialityID.Text.Trim(),2))
        {
          MessageBox.Show("专业编号须填入的部分必须是两位数字,请重新输入或选择。");
          return false;
        }
        else if(txtSpecialityName.Text.Trim() == "")
        {
          MessageBox.Show("请先输入专业名称");
          return false;
        }
        else
          return true;
      }
    }

    private bool ClassInfoValidated
    {
      get
      {
        if(labelClassID.Text.Trim() == "XX")
        {
          MessageBox.Show("请选择班级所在的学院。");
          return false;
        }
        else if(!StringValidation.isLengthSetNumString(txtClassID.Text.Trim(),4))
        {
          MessageBox.Show("班级编号须填入的部分必须是四位数字,请重新输入或选择。");
          return false;
        }
        else if(txtClassName.Text.Trim() == "")
        {
          MessageBox.Show("请先输入班级名称。");
          return false;
        }
        else
        {
          entityClass.ClassID = labelClassID.Text.Trim() + txtClassID.Text.Trim();
          entityClass.ClassName = txtClassName.Text.Trim();
          entityClass.ClassSpecialityID = cmbSpeciality.SelectedValue.ToString();
          entityClass.ClassHeadTeacher = txtHeadTeacher.Text.Trim();
          return true;
        }
      }
    }

    /// <summary>
    /// 用于将选定项或者查找结果的值绑定到学院设置操作面板中。
    /// </summary>
    private void BindCollegeInfo()
    {
      txtCollegeID.Text = dataSetOrgs.colleges.Rows[gridCollege.CurrentRowIndex]["college_ID"].ToString();
      txtCollegeName.Text = dataSetOrgs.colleges.Rows[gridCollege.CurrentRowIndex]["college_name"].ToString();
    }

    /// <summary>
    /// 用于将选定项或者查找结果的值绑定到专业设置操作面板中。
    /// </summary>
    private void BindSpecialityInfo()
    {
      cmbCollegeSpe.SelectedValue = dataSetOrgs.speciality.Rows[gridSpeciality.CurrentRowIndex]["speciality_college"].ToString();
      labelSpeID.Text = dataSetOrgs.speciality.Rows[gridSpeciality.CurrentRowIndex]["speciality_ID"].ToString().Substring(0,3);
      txtSpecialityID.Text = dataSetOrgs.speciality.Rows[gridSpeciality.CurrentRowIndex]["speciality_ID"].ToString().Remove(0,3);
      txtSpecialityName.Text = dataSetOrgs.speciality.Rows[gridSpeciality.CurrentRowIndex]["speciality_name"].ToString();
    }

    private void BindClassInfo()
    {
      cmbCollege.SelectedValue = dataSetOrgs.classes.Rows[gridClass.CurrentRowIndex]["speciality_college"].ToString();
      cmbSpeciality.SelectedValue = dataSetOrgs.classes.Rows[gridClass.CurrentRowIndex]["class_speciality"].ToString();
      labelClassID.Text = dataSetOrgs.classes.Rows[gridClass.CurrentRowIndex]["class_ID"].ToString().Trim().Substring(0,2);
      txtClassID.Text = dataSetOrgs.classes.Rows[gridClass.CurrentRowIndex]["class_ID"].ToString().Trim().Remove(0,2);
      txtClassName.Text = dataSetOrgs.classes.Rows[gridClass.CurrentRowIndex]["class_name"].ToString().Trim();
      txtHeadTeacher.Text = dataSetOrgs.classes.Rows[gridClass.CurrentRowIndex]["class_headTeacher"].ToString().Trim();
    }

    private void gridCollege_Click(object sender, System.EventArgs e)
    {
      BindCollegeInfo();
      btnInsertCollege.Enabled = false;
    }

    private void gridSpeciality_Click(object sender, System.EventArgs e)
    {
      BindSpecialityInfo();
      btnInsertSpeciality.Enabled = false;
    }

    private void gridClass_Click(object sender, System.EventArgs e)
    {
      BindClassInfo();
      btnInsertClass.Enabled = false;
    }

    private void cmbCollegeSpe_SelectedIndexChanged(object sender, System.EventArgs e)
    {
      labelSpeID.Text = cmbCollegeSpe.SelectedValue + "-";
      txtSpecialityID.Text = "";
      txtSpecialityName.Text = "";
      txtSpecialityID.Focus();
    }

    #region 专业设置面板中按钮激发的事件代码

    private void btnInsertSpeciality_Click(object sender, System.EventArgs e)
    {
      if(this.SpecialityInfoValidated)
      {
        switch(managerSpe.Insert(labelSpeID.Text.Trim()+txtSpecialityID.Text.Trim(),cmbCollegeSpe.SelectedValue.ToString().Trim(),txtSpecialityName.Text.Trim()))
        {
          case 0 : MessageBox.Show("此专业编号已经有纪录存在,不能重复。");break;
          case 1 : MessageBox.Show("您选中的学院已经有此专业名称的纪录存在,不能重复。");break;
          case 2 : Bind_gridSpeciality();break;
        }
      }
    }

    private void btnUpdateSpeciality_Click(object sender, System.EventArgs e)
    {
      if(this.SpecialityInfoValidated)
      {
        try
        {
          if(managerSpe.Update(labelSpeID.Text.Trim()+txtSpecialityID.Text.Trim(),cmbCollegeSpe.SelectedValue.ToString().Trim(),txtSpecialityName.Text.Trim())==0)
            MessageBox.Show("您选中的学院已经有此专业名称的纪录存在,不能重复。");
          else
            Bind_gridSpeciality();
        }
        catch(Exception e1)
        {
          MessageBox.Show(e1.Message);
        }
      }
    }  

    private void btnDeleteSpeciality_Click(object sender, System.EventArgs e)
    {
      if(this.SpecialityInfoValidated)
      {
        DialogResult result = MessageBox.Show("确实要删除此行纪录吗?","删除确认",MessageBoxButtons.OKCancel,MessageBoxIcon.Question,MessageBoxDefaultButton.Button2);
        if(result == DialogResult.OK)
        {
          try
          {
            managerSpe.Delete(labelSpeID.Text.Trim()+txtSpecialityID.Text.Trim());            
            Bind_gridSpeciality();
          }
          catch(Exception e1)
          {
            MessageBox.Show(e1.Message);
          }
        }
      }
    }

    #endregion      

    private void cmbCollege_SelectedIndexChanged(object sender, System.EventArgs e)
    {
      this.labelClassID.Text = cmbCollege.SelectedValue.ToString().Trim();
    }

    private void cmbSpeciality_SelectedIndexChanged(object sender, System.EventArgs e)
    {
      this.cmbCollege.SelectedValue = cmbSpeciality.SelectedValue.ToString().Substring(0,2);
    }

    private void btnInsertClass_Click(object sender, System.EventArgs e)
    {
      if(this.ClassInfoValidated)
      {
        try
        {
          if(managerClass.Insert(entityClass)==0)
            MessageBox.Show("此班级编号已经有记录存在,不能重复。");
          else
            Bind_gridClass();
        }
        catch(Exception e1)
        {
          MessageBox.Show(e1.Message);
        }
      }
    }

    private void btnUpdateClass_Click(object sender, System.EventArgs e)
    {
      if(this.ClassInfoValidated)
      {
        try
        {
          managerClass.Update(entityClass);
          Bind_gridClass();
        }
        catch(Exception e1)
        {
          MessageBox.Show(e1.Message);
        }
      }
    }

    private void btnDeleteClass_Click(object sender, System.EventArgs e)
    {
      if(this.ClassInfoValidated)
      {
        DialogResult result = MessageBox.Show("确定要删除此行纪录吗?","删除确认",MessageBoxButtons.OKCancel,MessageBoxIcon.Question,MessageBoxDefaultButton.Button2);
        if(result == DialogResult.OK)
        {
          managerClass.Delete(entityClass.ClassID);
          Bind_gridClass();
        }
      }
    }

    private void linkAddClass_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
    {
      btnInsertClass.Enabled = true;
      labelClassID.Text = "XX";
      txtClassID.Text = "";
      txtClassName.Text = "";
      txtHeadTeacher.Text = "";
    }

    private void linkAddSpeciality_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
    {
      labelSpeID.Text = "XX-";
      txtSpecialityID.Text = "";
      txtSpecialityName.Text = "";
      btnInsertSpeciality.Enabled = true;
    }

    private void linkAddCollege_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
    {
      txtCollegeID.Text = "";
      txtCollegeName.Text = "";
      btnInsertCollege.Enabled = true;
    }    
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -