📄 readerclassify.cs
字号:
this.checkBox1.Name = "checkBox1";
this.checkBox1.TabIndex = 0;
this.checkBox1.Text = "限制图书";
//
// checkBox2
//
this.checkBox2.DataBindings.Add(new System.Windows.Forms.Binding("Checked", this.dataSet11, "读者类型.限制期刊"));
this.checkBox2.Location = new System.Drawing.Point(256, 16);
this.checkBox2.Name = "checkBox2";
this.checkBox2.TabIndex = 0;
this.checkBox2.Text = "限制期刊";
//
// txt3
//
this.txt3.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "读者类型.图书册书"));
this.txt3.Location = new System.Drawing.Point(152, 56);
this.txt3.Name = "txt3";
this.txt3.ReadOnly = true;
this.txt3.TabIndex = 5;
this.txt3.Text = "";
//
// txt4
//
this.txt4.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "读者类型.期刊册书"));
this.txt4.Location = new System.Drawing.Point(272, 56);
this.txt4.Name = "txt4";
this.txt4.ReadOnly = true;
this.txt4.TabIndex = 6;
this.txt4.Text = "";
//
// label1
//
this.label1.Location = new System.Drawing.Point(32, 40);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(56, 16);
this.label1.TabIndex = 3;
this.label1.Text = "读者类型";
//
// txt2
//
this.txt2.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "读者类型.类型"));
this.txt2.Location = new System.Drawing.Point(32, 56);
this.txt2.Name = "txt2";
this.txt2.ReadOnly = true;
this.txt2.TabIndex = 4;
this.txt2.Text = "";
//
// txt5
//
this.txt5.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "读者类型.续借次数"));
this.txt5.Location = new System.Drawing.Point(408, 56);
this.txt5.Name = "txt5";
this.txt5.ReadOnly = true;
this.txt5.TabIndex = 6;
this.txt5.Text = "";
//
// label4
//
this.label4.Location = new System.Drawing.Point(272, 40);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(96, 16);
this.label4.TabIndex = 1;
this.label4.Text = "可借期刊册数";
//
// label5
//
this.label5.Location = new System.Drawing.Point(408, 40);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(96, 16);
this.label5.TabIndex = 1;
this.label5.Text = "允许续借次数";
//
// da1
//
this.da1.DeleteCommand = this.sqlDeleteCommand1;
this.da1.InsertCommand = this.sqlInsertCommand1;
this.da1.SelectCommand = this.sqlSelectCommand1;
this.da1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "读者类型", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("类型", "类型"),
new System.Data.Common.DataColumnMapping("图书册书", "图书册书"),
new System.Data.Common.DataColumnMapping("期刊册书", "期刊册书"),
new System.Data.Common.DataColumnMapping("续借次数", "续借次数"),
new System.Data.Common.DataColumnMapping("限制图书", "限制图书"),
new System.Data.Common.DataColumnMapping("限制期刊", "限制期刊")})});
this.da1.UpdateCommand = this.sqlUpdateCommand1;
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = @"DELETE FROM 读者类型 WHERE (类型 = @Original_类型) AND (图书册书 = @Original_图书册书 OR @Original_图书册书 IS NULL AND 图书册书 IS NULL) AND (期刊册书 = @Original_期刊册书 OR @Original_期刊册书 IS NULL AND 期刊册书 IS NULL) AND (续借次数 = @Original_续借次数 OR @Original_续借次数 IS NULL AND 续借次数 IS NULL) AND (限制图书 = @Original_限制图书 OR @Original_限制图书 IS NULL AND 限制图书 IS NULL) AND (限制期刊 = @Original_限制期刊 OR @Original_限制期刊 IS NULL AND 限制期刊 IS NULL)";
this.sqlDeleteCommand1.Connection = this.sqlConnection1;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_类型", System.Data.SqlDbType.VarChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "类型", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_图书册书", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "图书册书", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_期刊册书", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "期刊册书", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_续借次数", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "续借次数", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_限制图书", System.Data.SqlDbType.Bit, 1, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "限制图书", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_限制期刊", System.Data.SqlDbType.Bit, 1, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "限制期刊", System.Data.DataRowVersion.Original, null));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=localhost;Integrated Security=SSPI;Database=libbook;";
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO 读者类型(类型, 图书册书, 期刊册书, 续借次数, 限制图书, 限制期刊) VALUES (@类型, @图书册书, @期刊册书, @续借" +
"次数, @限制图书, @限制期刊); SELECT 类型, 图书册书, 期刊册书, 续借次数, 限制图书, 限制期刊 FROM 读者类型 WHERE (类型 =" +
" @类型)";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@类型", System.Data.SqlDbType.VarChar, 20, "类型"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@图书册书", System.Data.SqlDbType.SmallInt, 2, "图书册书"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@期刊册书", System.Data.SqlDbType.SmallInt, 2, "期刊册书"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@续借次数", System.Data.SqlDbType.Int, 4, "续借次数"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@限制图书", System.Data.SqlDbType.Bit, 1, "限制图书"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@限制期刊", System.Data.SqlDbType.Bit, 1, "限制期刊"));
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT 类型, 图书册书, 期刊册书, 续借次数, 限制图书, 限制期刊 FROM 读者类型 WHERE (类型 LIKE @Param2)";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param2", System.Data.SqlDbType.VarChar, 20, "类型"));
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = @"UPDATE 读者类型 SET 类型 = @类型, 图书册书 = @图书册书, 期刊册书 = @期刊册书, 续借次数 = @续借次数, 限制图书 = @限制图书, 限制期刊 = @限制期刊 WHERE (类型 = @Original_类型) AND (图书册书 = @Original_图书册书 OR @Original_图书册书 IS NULL AND 图书册书 IS NULL) AND (期刊册书 = @Original_期刊册书 OR @Original_期刊册书 IS NULL AND 期刊册书 IS NULL) AND (续借次数 = @Original_续借次数 OR @Original_续借次数 IS NULL AND 续借次数 IS NULL) AND (限制图书 = @Original_限制图书 OR @Original_限制图书 IS NULL AND 限制图书 IS NULL) AND (限制期刊 = @Original_限制期刊 OR @Original_限制期刊 IS NULL AND 限制期刊 IS NULL); SELECT 类型, 图书册书, 期刊册书, 续借次数, 限制图书, 限制期刊 FROM 读者类型 WHERE (类型 = @类型)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@类型", System.Data.SqlDbType.VarChar, 20, "类型"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@图书册书", System.Data.SqlDbType.SmallInt, 2, "图书册书"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@期刊册书", System.Data.SqlDbType.SmallInt, 2, "期刊册书"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@续借次数", System.Data.SqlDbType.Int, 4, "续借次数"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@限制图书", System.Data.SqlDbType.Bit, 1, "限制图书"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@限制期刊", System.Data.SqlDbType.Bit, 1, "限制期刊"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_类型", System.Data.SqlDbType.VarChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "类型", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_图书册书", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "图书册书", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_期刊册书", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "期刊册书", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_续借次数", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "续借次数", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_限制图书", System.Data.SqlDbType.Bit, 1, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "限制图书", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_限制期刊", System.Data.SqlDbType.Bit, 1, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "限制期刊", System.Data.DataRowVersion.Original, null));
//
// ReaderClassify
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(552, 477);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.toolBar1);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.groupBox1);
this.Name = "ReaderClassify";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "【读者类别设置】";
this.Load += new System.EventHandler(this.ReaderClassfy_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
//--------------创建窗体时读入全部数据--------------
private void ReaderClassfy_Load(object sender, System.EventArgs e)
{
da1.SelectCommand.Parameters[0].Value="%%";
da1.Fill(dataSet11);
//为数据集添加数据项浏览控制
cmOrders=(CurrencyManager) BindingContext[dataSet11,"读者类型"];
}
//--------------根据输入查询数据--------------
private void btnSearch_Click(object sender, System.EventArgs e)
{
da1.SelectCommand.Parameters[0].Value="%%";
if(txt1.Text.Trim()!="")
{
da1.SelectCommand.Parameters[0].Value="%"+txt1.Text.Trim()+"%";
}
//清空数据表,并根据新设置的查询参数重新填充
dataSet11.读者类型.Clear();
da1.Fill(dataSet11);
}
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
if (e.Button.ToolTipText == "首记录")
{
this.dataGrid1.UnSelect(cmOrders.Position); //取消原选中的行
cmOrders.Position = 0;
this.dataGrid1.Select(cmOrders.Position); //选中当前行
this.dataGrid1.CurrentRowIndex = cmOrders.Position; //移动表头指示图标
return;
}
if (e.Button.ToolTipText == "上一记录")
{
if (cmOrders.Position >= 0)
{
this.dataGrid1.UnSelect(cmOrders.Position);
cmOrders.Position--;
this.dataGrid1.Select(cmOrders.Position);
this.dataGrid1.CurrentRowIndex = cmOrders.Position;
}
return;
}
if (e.Button.ToolTipText == "下一记录")
{
if (cmOrders.Position <= cmOrders.Count-1)
{
this.dataGrid1.UnSelect(cmOrders.Position);
cmOrders.Position++;
this.dataGrid1.Select(cmOrders.Position);
this.dataGrid1.CurrentRowIndex = cmOrders.Position;
}
return;
}
if (e.Button.ToolTipText == "尾记录")
{
this.dataGrid1.UnSelect(cmOrders.Position);
cmOrders.Position = cmOrders.Count-1;
this.dataGrid1.Select(cmOrders.Position);
this.dataGrid1.CurrentRowIndex = cmOrders.Position;
return;
}
if(e.Button.ToolTipText=="新增")
{
cmOrders.AddNew();
//设置默认值
txt3.Text="1";
txt4.Text="1";
txt5.Text="1";
SetModifyMode(true);
}
if(e.Button.ToolTipText=="修改")
{
SetModifyMode(true);
}
if(e.Button.ToolTipText=="删除")
{
DialogResult result=MessageBox.Show("确认删除?","删除数据",MessageBoxButtons.OKCancel);
if(result==DialogResult.OK)
if(cmOrders.Count>0)//立即从数据集中删除
{
cmOrders.RemoveAt(cmOrders.Position);
da1.Update(dataSet11);
}
else
MessageBox.Show("表中为空,已无可删除数据","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
if(e.Button.ToolTipText=="提交")
{
if(txt2.Text.Trim()=="")//检查非空字段
{
MessageBox.Show("类型名称不能为空","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
cmOrders.EndCurrentEdit();
if(dataSet11.GetChanges()!=null)
{
try
{
da1.Update(dataSet11);
SetModifyMode(false);
}
catch(Exception express)
{
MessageBox.Show(express.ToString(),"提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
dataSet11.RejectChanges();
}
}
return;
}
if (e.Button.ToolTipText == "取消")
{
try
{
cmOrders.CancelCurrentEdit(); //取消编辑
SetModifyMode(false);
}
catch(Exception express)
{
MessageBox.Show(express.ToString(),"提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
return;
}
if(e.Button.ToolTipText=="退出")
{
this.Close();
}
}
//--------------对控件的属性做设置---------------
private void SetModifyMode(bool blnEdit)
{
//设置文本框和下拉列表框属性
txt2.ReadOnly=!blnEdit;
txt3.ReadOnly=!blnEdit;
txt4.ReadOnly=!blnEdit;
txt5.ReadOnly=!blnEdit;
//设置搜索按钮属性
btnSearch.Enabled=!blnEdit;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -