📄 depart.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace kaoqin.sys
{
public partial class man : Form
{
public man()
{
InitializeComponent();
}
//SqlConnection con = DB.CON;
private void depart_Load(object sender, EventArgs e)
{
BindData();
}
private void BindData()
{
this.listBox1.Items.Clear();
string sql = "select * from depart";
DataTable dt = DB.getTable(sql);
for (int i = 0; i < dt.Rows.Count; i++)
{
this.listBox1.Items.Add(dt.Rows[i]["departName"].ToString().Trim());
}
}
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 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 Add()
{
if (this.textBox1.Text.Trim() == "")
{
MessageBox.Show("系部名不能为空!");
this.textBox1.Focus();
return;
}
string sql = "select * from depart where departName='"+this.textBox1.Text.Trim()+"'";
DataTable dt = DB.getTable(sql);
if (dt.Rows.Count != 0)
{
MessageBox.Show("系部"+this.textBox1.Text.Trim()+"已存在!");
return;
}
sql = "insert into depart values ('" + this.textBox1.Text.Trim() + "')";
if(DB.executeSql(sql))
{
MessageBox.Show("操作成功!");
this.BindData();
}
else
{
MessageBox.Show("操作失败!");
}
}
private void Mod()
{
if (this.textBox1.Text.Trim() == "")
{
MessageBox.Show("系部名不能为空!");
this.textBox1.Focus();
return;
}
if (this.listBox1.SelectedIndex == -1)
{
MessageBox.Show("请选择一个系部!");
this.listBox1.Focus();
return;
}
string sql = "select * from depart where departName='"+this.textBox1.Text.Trim()+"'";
DataTable dt = DB.getTable(sql);
if (dt.Rows.Count != 0)
{
MessageBox.Show("系部"+this.textBox1.Text.Trim()+"已存在!");
return;
}
sql = "update depart set departName='" + this.textBox1.Text.Trim() + "' where departName='"+this.listBox1.SelectedItem.ToString()+"'";
if(DB.executeSql(sql))
{
MessageBox.Show("操作成功!");
this.BindData();
}
else
{
MessageBox.Show("操作失败!");
}
}
private void Del()
{
if (this.listBox1.SelectedIndex == -1)
{
MessageBox.Show("请选择一个系部!");
this.listBox1.Focus();
return;
}
string sql = "delete depart where departName='" + this.textBox1.Text.Trim() + "'";
if (DB.executeSql(sql))
{
MessageBox.Show("操作成功!");
this.BindData();
}
else
{
MessageBox.Show("操作失败!");
}
}
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 + -