Exemplo n.º 1
0
        private void Tools_Clicked(object tag)
        {
            if (tag != null)
            {
                switch (tag.ToString())
                {
                case "1":
                    #region 添加学生
                    using (frmAddStudent frm = new frmAddStudent(null))
                    {
                        if (frm.ShowDialog() == DialogResult.OK)
                        {
                            string sql = "INSERT INTO [Students] " +
                                         "([XH], [XM], [MM], [XB], [NJ], [DH], [DZ], [CSRQ], [Email]) VALUES " +
                                         "('{0}', '{1}', '{2}', {3}, {4}, '{5}', '{6}', '{7}', '{8}')";

                            sql = string.Format(sql, frm.XH, frm.XM,
                                                frm.MM, frm.XB, frm.NJ, frm.DH,
                                                frm.DZ, frm.CSRQ, frm.Email);

                            using (SqlServerHelper ssh = new SqlServerHelper(
                                       DataConst.dataBase, DataConst.userName, DataConst.password))
                            {
                                object o = ssh.ExecuteScalar(string.Format("Select count(*) from Students where xh = '{0}'",
                                                                           frm.XH));

                                if ((int)o != 0)
                                {
                                    MessageBox.Show(string.Format("学号为 {0} 的学生已经存在,请重新分配学号!",
                                                                  frm.XH), "添加学生出错提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                                else
                                {
                                    if (ssh.ExecuteNonQuery(sql) > 0)
                                    {
                                        this.DialogResult = DialogResult.OK;
                                    }
                                }
                            }
                        }
                    }
                    #endregion
                    break;

                case "2":
                    #region 修改学生

                    if (lvStudents.SelectedItems.Count > 0)
                    {
                        ListViewItem lvi = lvStudents.SelectedItems[0];
                        if (lvi != null && lvi.Tag is DataRow)
                        {
                            using (frmAddStudent frm =
                                       new frmAddStudent(lvi.Tag as DataRow, true))
                            {
                                if (frm.ShowDialog() == DialogResult.OK)
                                {
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("选中的学生信息不正确!");
                        }
                    }
                    else
                    {
                        MessageBox.Show("请先选中需要修改的学生!");
                    }
                    #endregion
                    break;

                case "3":
                    #region 修改密码
                    using (frmAlterPwd frm = new frmAlterPwd(m_UserName))
                    {
                        if (frm.ShowDialog() == DialogResult.OK)
                        {
                        }
                    }
                    #endregion
                    break;

                case "4":
                    #region 查询学生
                    using (frmEnquiry frm = new frmEnquiry("Students"))
                    {
                        if (frm.ShowDialog() == DialogResult.OK)
                        {
                        }
                    }
                    #endregion
                    break;

                case "9":
                    this.Close();
                    break;
                }
            }
        }
Exemplo n.º 2
0
        private void Tools_Clicked(object tag)
        {
            if (tag != null)
            {
                switch (tag.ToString())
                {
                    case "1":
                        #region 添加学生
                        using (frmAddStudent frm = new frmAddStudent(null))
                        {
                            if (frm.ShowDialog() == DialogResult.OK)
                            {
                                string sql = "INSERT INTO [Students] " +
                                            "([XH], [XM], [MM], [XB], [NJ], [DH], [DZ], [CSRQ], [Email]) VALUES " +
                                            "('{0}', '{1}', '{2}', {3}, {4}, '{5}', '{6}', '{7}', '{8}')";

                                sql = string.Format(sql, frm.XH, frm.XM,
                                    frm.MM, frm.XB, frm.NJ, frm.DH,
                                    frm.DZ, frm.CSRQ, frm.Email);

                                using (SqlServerHelper ssh = new SqlServerHelper(
                                    DataConst.dataBase, DataConst.userName, DataConst.password))
                                {
                                    object o = ssh.ExecuteScalar(string.Format("Select count(*) from Students where xh = '{0}'",
                                        frm.XH));

                                    if ((int)o != 0)
                                    {
                                        MessageBox.Show(string.Format("学号为 {0} 的学生已经存在,请重新分配学号!",
                                            frm.XH), "添加学生出错提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    }
                                    else
                                    {
                                        if (ssh.ExecuteNonQuery(sql) > 0)
                                        {
                                            this.DialogResult = DialogResult.OK;
                                        }
                                    }
                                }
                            }
                        }
                        #endregion
                        break;
                    case "2":
                        #region 修改学生

                        if (lvStudents.SelectedItems.Count > 0)
                        {
                            ListViewItem lvi = lvStudents.SelectedItems[0];
                            if (lvi != null && lvi.Tag is DataRow)
                            {
                                using (frmAddStudent frm =
                                    new frmAddStudent(lvi.Tag as DataRow, true))
                                {
                                    if (frm.ShowDialog() == DialogResult.OK)
                                    {
                                    }
                                }
                            }
                            else
                                MessageBox.Show("选中的学生信息不正确!");
                        }
                        else
                            MessageBox.Show("请先选中需要修改的学生!");
                        #endregion
                        break;
                    case "3":
                        #region 修改密码
                        using (frmAlterPwd frm = new frmAlterPwd(m_UserName))
                        {
                            if (frm.ShowDialog() == DialogResult.OK)
                            {
                            }
                        }
                        #endregion
                        break;
                    case "4":
                        #region 查询学生
                        using (frmEnquiry frm = new frmEnquiry("Students"))
                        {
                            if (frm.ShowDialog() == DialogResult.OK)
                            {
                            }
                        }
                        #endregion
                        break;

                    case "9":
                        this.Close();
                        break;
                }
            }
        }