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

📄 banji.cs

📁 这是一个考勤系统大家多多指教
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace kaoqin.sys
{
    public partial class banji : Form
    {
        public banji()
        {
            InitializeComponent();
        }

        private void banji_Load(object sender, EventArgs e)
        {
            BindData();
        }
        private void BindData()
        {
            this.comboBox1.Items.Clear();
            string sql = "select * from depart";
            DataTable dt = DB.getTable(sql);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                this.comboBox1.Items.Add(dt.Rows[i]["departName"].ToString().Trim());
            }
        }
        private void BindList()
        {
            this.listBox1.Items.Clear();
            if (this.comboBox1.SelectedIndex != -1 && this.comboBox1.Items.Count != 0)
            {
                string sql = "select departID from depart where departName='"+this.comboBox1.SelectedItem.ToString()+"'";
                string id = DB.getID(sql);
                sql = "select * from class where departID='"+id+"'";
                DataTable dt = DB.getTable(sql);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    this.listBox1.Items.Add(dt.Rows[i]["className"].ToString());
                }
                //DataTable dt = DB.getTable(
            }
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (this.radioButton1.Checked == true)
            {
                this.lblFlag.Text = "添加";
                this.textBox1.Text = "";
                this.textBox1.Enabled = true;
            }
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            if (this.radioButton2.Checked == true)
            {
                this.lblFlag.Text = "删除";
                this.textBox1.Enabled = false;
                if (this.listBox1.SelectedIndex == -1)
                {
                    this.textBox1.Text = "";
                    return;
                }
                this.textBox1.Text = this.listBox1.SelectedItem.ToString().Trim();
            }
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            if (this.radioButton3.Checked == true)
            {
                this.lblFlag.Text = "修改";
                this.textBox1.Enabled = true;
                if (this.listBox1.SelectedIndex == -1)
                {
                    this.textBox1.Text = "";
                    return;
                }
                this.textBox1.Text = this.listBox1.SelectedItem.ToString().Trim();
            }
            else
            {
                this.textBox1.Enabled = true;
            }
        }

     
      
        private void Add()
        {
            if (this.comboBox1.SelectedIndex == -1)
            {
                MessageBox.Show("请选择班级的所属系部!");
                this.comboBox1.Focus();
                return;
            }
            if (this.textBox1.Text.Trim() == "")
            {
                MessageBox.Show("班级名不能为空!");
                this.textBox1.Focus();
                return;
            }
           
            string sql = "select * from depart where departName='" + this.comboBox1.Text.Trim() + "'";
            DataTable dt = DB.getTable(sql);
            if (dt.Rows.Count == 0)
            {
                MessageBox.Show("系部" + this.comboBox1.Text.Trim() + "不存在!");
                return;
            }
            sql = "select departID from depart where departName='"+this.comboBox1.Text.Trim()+"'";
            string id = DB.getID(sql);
            sql = "select * from class where className='" + this.textBox1.Text.Trim() + "' and departID='"+id+"'";
            dt.Clear();
            dt = DB.getTable(sql);
            if (dt.Rows.Count != 0)
            {
                MessageBox.Show("班级" + this.textBox1.Text.Trim() + "已存在!");
                this.listBox1.SelectedItem = this.textBox1.Text.Trim();
                this.textBox1.Focus();
                return;
            }

            sql = "insert into class values ('" + this.textBox1.Text.Trim() + "','"+id+"')";
            if (DB.executeSql(sql))
            {
                MessageBox.Show("操作成功!");
                this.BindList();
                this.textBox1.Text = "";
            }
            else
            {
                MessageBox.Show("操作失败!");
            }
        }
        private void Mod()
        {
            if (this.comboBox1.SelectedIndex == -1)
            {
                MessageBox.Show("请选择班级的所属系部!");
                this.comboBox1.Focus();
                return;
            }
            if (this.textBox1.Text.Trim() == "")
            {
                MessageBox.Show("班级名不能为空!");
                this.textBox1.Focus();
                return;
            }

            string sql = "select * from depart where departName='" + this.comboBox1.Text.Trim() + "'";
            DataTable dt = DB.getTable(sql);
            if (dt.Rows.Count == 0)
            {
                MessageBox.Show("系部" + this.comboBox1.Text.Trim() + "不存在!");
                return;
            }
            sql = "select departID from depart where departName='" + this.comboBox1.Text.Trim() + "'";
            string id = DB.getID(sql);
            sql = "select * from class where className='" + this.textBox1.Text.Trim() + "' and departID='" + id + "'";
            dt.Clear();
            dt = DB.getTable(sql);
            if (dt.Rows.Count != 0)
            {
                MessageBox.Show("班级" + this.textBox1.Text.Trim() + "已存在!");
                this.listBox1.SelectedItem = this.textBox1.Text.Trim();
                this.textBox1.Focus();
                return;
            }

            sql = "update class set className='" + this.textBox1.Text.Trim() + "' where className='"+this.listBox1.SelectedItem.ToString()+"'";
            if (DB.executeSql(sql))
            {
                MessageBox.Show("操作成功!");
                this.BindList();
                this.textBox1.Text = "";
            }
            else
            {
                MessageBox.Show("操作失败!");
            }
        }
        private void Del()
        {
            if (this.comboBox1.SelectedIndex == -1)
            {
                MessageBox.Show("请选择班级的所属系部!");
                this.comboBox1.Focus();
                return;
            }

            if (this.listBox1.SelectedIndex == -1)
            {
                MessageBox.Show("请选择要删除的班级!");
                this.listBox1.Focus();
                return;
            }
            
            string sql = "delete class where className='" + this.listBox1.SelectedItem.ToString() + "'";
            if (DB.executeSql(sql))
            {
                MessageBox.Show("操作成功!");
                this.BindList();
                this.textBox1.Text = "";
            }
            else
            {
                MessageBox.Show("操作失败!");
            }
     
        }

       

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.BindList();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (this.radioButton1.Checked == true)
            {
                Add();
            }
            else if (this.radioButton2.Checked == true)
            {
                if (MessageBox.Show("你真的想要删除此记录吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    Del();
                }
            }
            else if (this.radioButton3.Checked == true)
            {
                Mod();
            }
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.radioButton3.Checked == true || this.radioButton2.Checked == true)
            {
                if (this.listBox1.SelectedIndex == -1)
                {
                    return;
                }
                this.textBox1.Text = this.listBox1.SelectedItem.ToString();
            }
        }
     
    }
}

⌨️ 快捷键说明

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