Пример #1
0
        /// <summary>
        /// 添加信息事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddInfo_Click(object sender, EventArgs e)
        {
            //把当前点击本身实例化出来
            Button btn = (Button)sender;
            //把添加信息的界面new出来
            AddStudent addInfo = new AddStudent();

            addInfo.Updata_btn.Visible       = false;
            addInfo.updataInfo_lable.Visible = false;
            switch (btn.Name)
            {
            case "AddStudent_btn":

                //获取当前dataview中最后一行的值在加1,这样就是自动增加学号了
                addInfo.stuid_txt.Text = (Convert.ToInt32(dl.ShowInfo(static_SQL_CRUD.AllInfoOfStudent).Tables["info"].Rows[dl.ShowInfo(static_SQL_CRUD.AllInfoOfStudent).Tables["info"].Rows.Count - 1][0]) + 1).ToString();

                addInfo.AddStudent_pal.Visible = true;
                //addInfo.ShowDialog();
                if (addInfo.ShowDialog() == DialogResult.OK)
                {
                    Baind();
                }

                break;

            case "AddTeacher_btn":
                addInfo.teacherid_txt.Text     = (Convert.ToInt32(dl.ShowInfo(static_SQL_CRUD.AllInfoOfTeacher).Tables["info"].Rows[dl.ShowInfo(static_SQL_CRUD.AllInfoOfTeacher).Tables["info"].Rows.Count - 1][0]) + 1).ToString();
                addInfo.AddTeacher_pal.Visible = true;
                if (addInfo.ShowDialog() == DialogResult.OK)
                {
                    Baind();
                }
                break;

            case "AddAdmin_btn":
                addInfo.adminid_txt.Text     = (Convert.ToInt32(dl.ShowInfo(static_SQL_CRUD.AllInfoOfAdmin).Tables["info"].Rows[dl.ShowInfo(static_SQL_CRUD.AllInfoOfAdmin).Tables["info"].Rows.Count - 1][0]) + 1).ToString();
                addInfo.AddAdmin_pal.Visible = true;
                if (addInfo.ShowDialog() == DialogResult.OK)
                {
                    Baind();
                }
                break;
            }
        }
Пример #2
0
        /// <summary>
        /// 修改信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UpdataInfo_Click(object sender, EventArgs e)
        {
            //把当前点击本身实例化出来
            Button btn = (Button)sender;
            //把修改页面new出来
            AddStudent updata = new AddStudent();

            //确认按钮不显示
            updata.Confirm_btn.Visible   = false;
            updata.addInfo_lable.Visible = false;
            //修改时ID不能修改
            updata.stuid_txt.ReadOnly     = true;
            updata.teacherid_txt.ReadOnly = true;

            int checkedCount = 0;//checked的行数

            switch (btn.Name)
            {
            case "UpdataStudent_btn":

                for (int i = 0; i < this.Student_data.Rows.Count; i++)
                {
                    if (this.Student_data.Rows[i].Cells[0].FormattedValue.ToString().ToUpper() == "TRUE")
                    {
                        checkedCount++;
                    }
                }

                if (checkedCount == 1)
                {
                    for (int i = 0; i < this.Student_data.Rows.Count; i++)
                    {
                        if (this.Student_data.Rows[i].Cells[0].FormattedValue.ToString().ToUpper() == "TRUE")
                        {
                            //获取当前选中行的关键字段存到用户字段静态类中
                            staticModle.DU = new List <string>();
                            staticModle.DU.Add(this.Student_data.Rows[i].Cells[1].Value.ToString());
                            updata.AddStudent_pal.Visible = true;
                            updata.AddTeacher_pal.Visible = false;
                            updata.AddAdmin_pal.Visible   = false;
                        }
                    }



                    //刷新
                    if (updata.ShowDialog() == DialogResult.OK)
                    {
                        Baind();
                    }
                }
                else if (checkedCount <= 0)
                {
                    MessageBox.Show("请选中要修改的信息!!");
                }
                else
                {
                    MessageBox.Show("只能单个修改!!");
                }
                checkedCount = 0;
                break;

            case "TeacherUpdata_btn":
                for (int i = 0; i < this.Teacher_data.Rows.Count; i++)
                {
                    if (this.Teacher_data.Rows[i].Cells[0].FormattedValue.ToString().ToUpper() == "TRUE")
                    {
                        checkedCount++;
                    }
                }
                if (checkedCount == 1)
                {
                    for (int i = 0; i < this.Teacher_data.Rows.Count; i++)
                    {
                        if (this.Teacher_data.Rows[i].Cells[0].FormattedValue.ToString().ToUpper() == "TRUE")
                        {
                            //获取当前选中行的关键字段存到用户字段静态类中
                            staticModle.DU = new List <string>();
                            staticModle.DU.Add(this.Teacher_data.Rows[i].Cells[1].Value.ToString());
                            updata.AddTeacher_pal.Visible = true;
                            updata.AddStudent_pal.Visible = false;
                            updata.AddAdmin_pal.Visible   = false;
                        }
                    }



                    //刷新
                    if (updata.ShowDialog() == DialogResult.OK)
                    {
                        Baind();
                    }
                }
                else if (checkedCount <= 0)
                {
                    MessageBox.Show("请选中要修改的信息!!");
                }
                else
                {
                    MessageBox.Show("只能单个修改!!");
                }
                checkedCount = 0;
                break;

            case "AdminUpdataInfo_btn":
                DialogResult res = MessageBox.Show("确定修改!!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (res == DialogResult.OK)
                {
                    //点击修改就把当前文本框的值赋给staticModle类里
                    staticModle.adminid   = this.ID_txt.Text;
                    staticModle.adminname = this.Name_txt.Text;
                    staticModle.password  = this.password_txt.Text;
                    if (dl.Updta(static_SQL_CRUD.UpdataAdmin()) > 0)
                    {
                        MessageBox.Show("修改成功!!");
                    }
                    else
                    {
                        MessageBox.Show("修改失败!!");
                    }
                }
                break;
            }
        }