📄 图书征定.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 图书馆管理系统
{
/// <summary>
/// 可选择精确或模糊进行查询
/// 新增或修改 根据选择图书名称的下拉列调出的表进行双击选择
/// 通过调用存储过程实现图书征订和图书信息之间的改变
///
/// </summary>
public partial class 图书征定 : Form
{
private BindingManagerBase Navigator;
public static string bookID, bookName;//保存选择而来的书名和编号
public 图书征定()
{
InitializeComponent();
}
//---------------------------------------------------------------窗体加载-----------------------------------
private void 图书征定_Load(object sender, EventArgs e)
{
//sqlDataAdapter1.Fill(dataSet11,"图书征订");
TextReadOnly(true);
Navigator = this.BindingContext[dataSet11, "图书征订"];
}
//----------------------------------------------是否可更改-----------------------------------
private void TextReadOnly(bool A)
{
textBox3.ReadOnly = A;
textBox4.ReadOnly = A;
textBox5.ReadOnly = A;
textBox6.ReadOnly = A;
textBox7.ReadOnly = A;
textBox8.ReadOnly = A;
textBox10.ReadOnly =A;
textBox11.ReadOnly =A;
// textBox12.ReadOnly = A;
comboBox1.Enabled=! A;
checkBox1.Enabled =!A;
}
//---------------------------------------------------首条---上一条---下一条----尾条------------------
private void button1_Click(object sender, EventArgs e)
{
dataGrid1.UnSelect(Navigator.Position);
Navigator.Position = 0;
dataGrid1.Select(Navigator.Position);
dataGrid1.CurrentRowIndex = Navigator.Position;
}
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
{
dataGrid1.UnSelect(Navigator.Position);
Navigator.Position = 0;
dataGrid1.Select(Navigator.Position);
dataGrid1.CurrentRowIndex = Navigator.Position;
}
}
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
{
dataGrid1.UnSelect(Navigator.Position);
Navigator.Position = Navigator.Count - 1;
dataGrid1.Select(Navigator.Position);
dataGrid1.CurrentRowIndex = Navigator.Count - 1;
}
}
private void button4_Click(object sender, EventArgs e)
{
dataGrid1.UnSelect(Navigator.Position);
Navigator.Position = Navigator.Count-1;
dataGrid1.Select(Navigator.Position);
dataGrid1.CurrentRowIndex = Navigator.Count-1;
}
//----------------------------------------------------新增------------------------------------
private void button5_Click(object sender, EventArgs e)
{
dataSet11.Clear();
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.Information);
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)
{
Navigator.CancelCurrentEdit();
TextReadOnly(true);
}
//-------------------------------------------------------提交--------------------------------------------
private void button11_Click(object sender, EventArgs e)
{
if (textBox3.Text == "" )
{
MessageBox.Show("征订编号是必填字段!请填写完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
else
{
Navigator.EndCurrentEdit();
if (dataSet11.GetChanges() != null)
{
sqlDataAdapter1.Update(dataSet11, "图书征订");
MessageBox.Show("操作成功,数据库以进行相关的更改!");
TextReadOnly(true);
}
else
return;
}
}
//----------------------------------------------------------------------退出-----------------------------------------
private void button9_Click(object sender, EventArgs e)
{
this.Close();
}
//-------------------------------------------------提交征订-----------------------
private void button10_Click(object sender, EventArgs e)
{
sqlConnection1.Open();
SqlCommand mycom = new SqlCommand("exec sf_图书征订 '"+textBox6.Text+"'", sqlConnection1);
SqlDataAdapter dr = new SqlDataAdapter(mycom);
DataSet ds = new DataSet();
dr.Fill(ds);
// DataTable dt = new DataTable();
//dr.Fill(dt);
//dataGrid1.DataSource = dt.DefaultView;
int num = mycom.ExecuteNonQuery();
if (num!=0)
{
MessageBox.Show("操作成功!");
}
else
MessageBox.Show("操作失败!");
/*try
{
mycom.ExecuteNonQuery();
// dataSet11.Clear();
sqlDataAdapter1.Fill(dataSet11);
sqlDataAdapter1.Update(dataSet11, "图书征订");
MessageBox.Show("操作成功!");
return;
}
catch (Exception express)
{
MessageBox.Show(express.ToString(), "无法验收!", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}*/
sqlConnection1.Close();
}
//-------------------------------------------------------------搜索---------------------------------------------
private void button12_Click(object sender, EventArgs e)
{
/*sqlConnection1.Open();
string str = "";
if (textBox1.Text == "" && textBox2.Text == "")
{
str = "select * from 图书征订";
}
else
{
if (textBox1.Text != "" && textBox2.Text != "")
{
str = "select * from 图书征订 where 征订编号=" + textBox1.Text + " and 图书编号=" + textBox2.Text + "";
}
if (textBox1.Text != "" && textBox2.Text == "")
{
str = "select * from 图书征订 where 征订编号=" + textBox1.Text + "";
}
if (textBox1.Text == "" && textBox2.Text != "")
{
str = "select * from 图书征订 where 图书编号=" + textBox2.Text + "";
}
}
dataSet11.Clear();
SqlDataAdapter myda = new SqlDataAdapter(str, sqlConnection1);
myda.Fill(dataSet11, "图书征订");
sqlConnection1.Close();*/
sqlConnection1.Open();
string str = "";
switch (comboBox2.SelectedIndex)
{
case 0:
str = "select * from 图书征订";
break;
case 1:
case 2:
case 3:
str = "select * from 图书征订 where " + comboBox2.Text + "='" + textBox2.Text + "'";
break;
default:
str = "";
break;
}
dataSet11.Clear();
SqlDataAdapter myda = new SqlDataAdapter(str, sqlConnection1);
myda.Fill(dataSet11, "图书征订");
sqlConnection1.Close();
}
//--------------------------------------刷新-------------------------------------
/*( private void button13_Click(object sender, EventArgs e)
{
dataSet11.Clear();
sqlDataAdapter1.Fill(dataSet11, "图书征订");
}*/
private void comboBox1_DropDown(object sender, EventArgs e)
{
comboBox1.Text = "";//清空原有书名
Selectbook newfrm = new Selectbook();
newfrm.Text = "双击表格选择图书";
newfrm.ShowDialog();
textBox6.Text = bookID;//读入选择的图书信息
comboBox1.Text = bookName;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -