📄 读者类型管理.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 图书馆管理系统
{
public partial class 读者类型管理 : Form
{
public 读者类型管理()
{
InitializeComponent();
}
public BindingManagerBase Navigator;
public void TextReadOnly(bool A)
{
textBox2.ReadOnly = A;
textBox3.ReadOnly = A;
textBox4.ReadOnly = A;
textBox5.ReadOnly = A;
}
private void 读者类型管理_Load(object sender, EventArgs e)
{
sqlDataAdapter1.Fill(dataSet11,"读者类型");
Navigator = this.BindingContext[dataSet11, "读者类型"];
TextReadOnly(true);
}
private void button1_Click(object sender, EventArgs e)
{
dataGrid1.UnSelect(Navigator.Position);
Navigator.Position = 0;
dataGrid1.Select(Navigator.Position);
dataGrid1.CurrentRowIndex = Navigator.Position;
return;
}
private void button2_Click(object sender, EventArgs e)
{
if (Navigator.Position != 0)
{
dataGrid1.UnSelect(Navigator.Position);
Navigator.Position--;
dataGrid1.Select(Navigator.Position);
dataGrid1.CurrentRowIndex = Navigator.Position;
}
else
return;
}
private void button3_Click(object sender, EventArgs e)
{
if (Navigator.Position != Navigator.Count - 1)
{
dataGrid1.UnSelect(Navigator.Position);
Navigator.Position++;
dataGrid1.Select(Navigator.Position);
dataGrid1.CurrentRowIndex = Navigator.Position;
}
else
return;
}
private void button4_Click(object sender, EventArgs e)
{
dataGrid1.UnSelect(Navigator.Position);
Navigator.Position = Navigator.Count - 1;
dataGrid1.Select(Navigator.Position);
dataGrid1.CurrentRowIndex = Navigator.Position;
return;
}
//------------------------------新增-------------
private void button5_Click(object sender, EventArgs e)
{
Navigator.AddNew();
TextReadOnly(false);
}
//-------------------修改--------------
private void button6_Click(object sender, EventArgs e)
{
TextReadOnly(false);
}
//------------------------删除-------------
private void button7_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("确定删除这条记录吗?","删除提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Error);
if (result == DialogResult.OK)
{
Navigator.RemoveAt(Navigator.Position);
sqlDataAdapter1.Update(dataSet11, "读者类型");
}
else
{
MessageBox.Show("无可删除数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
//--------------------提交 -----------
private void button8_Click(object sender, EventArgs e)
{
if (textBox2.Text == "")
{
MessageBox.Show("类型不能为空");
}
Navigator.EndCurrentEdit();
if (dataSet11.GetChanges() != null)
{
try
{
sqlDataAdapter1.Update(dataSet11, "读者类型");
TextReadOnly(true);
}
catch (Exception express)
{
MessageBox.Show(express.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
dataSet11.RejectChanges();
}
MessageBox.Show("操作成功!");
}
return;
}
//---------------------取消----------------
private void button9_Click(object sender, EventArgs e)
{
Navigator.CancelCurrentEdit();
TextReadOnly(true);
}
//-------------------退出--------------------
private void button10_Click(object sender, EventArgs e)
{
this.Close();
}
//--------------------搜索-------------------------
private void button11_Click(object sender, EventArgs e)
{
sqlConnection1.Open();
SqlDataAdapter myda = new SqlDataAdapter("select * from 读者类型 where 类型 like '%"+textBox1.Text+"%'",sqlConnection1);
dataSet11.Clear();
myda.Fill(dataSet11,"读者类型");
sqlConnection1.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -