📄 addnewcard.cs
字号:
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(54, 17);
this.label8.TabIndex = 9;
this.label8.Text = "出生日期";
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(239, 119);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(54, 17);
this.label7.TabIndex = 8;
this.label7.Text = "联系电话";
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(24, 209);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(29, 17);
this.label5.TabIndex = 6;
this.label5.Text = "类型";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(24, 119);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(54, 17);
this.label4.TabIndex = 5;
this.label4.Text = "办证日期";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(24, 74);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(29, 17);
this.label3.TabIndex = 4;
this.label3.Text = "性别";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(264, 29);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(29, 17);
this.label2.TabIndex = 3;
this.label2.Text = "姓名";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(24, 29);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(54, 17);
this.label1.TabIndex = 2;
this.label1.Text = "证件号码";
//
// textBox8
//
this.textBox8.Location = new System.Drawing.Point(88, 297);
this.textBox8.Name = "textBox8";
this.textBox8.Size = new System.Drawing.Size(328, 21);
this.textBox8.TabIndex = 13;
this.textBox8.Text = "";
//
// label12
//
this.label12.AutoSize = true;
this.label12.Location = new System.Drawing.Point(24, 299);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(54, 17);
this.label12.TabIndex = 13;
this.label12.Text = "联系地址";
//
// btnAddNewCard
//
this.btnAddNewCard.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.btnAddNewCard.Location = new System.Drawing.Point(272, 368);
this.btnAddNewCard.Name = "btnAddNewCard";
this.btnAddNewCard.TabIndex = 10;
this.btnAddNewCard.Text = "新增";
this.btnAddNewCard.Click += new System.EventHandler(this.btnAddNewCard_Click);
//
// btnCancel
//
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.btnCancel.Location = new System.Drawing.Point(360, 368);
this.btnCancel.Name = "btnCancel";
this.btnCancel.TabIndex = 11;
this.btnCancel.Text = "取消";
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// AddNewCard
//
this.AcceptButton = this.btnAddNewCard;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.CancelButton = this.btnCancel;
this.ClientSize = new System.Drawing.Size(458, 408);
this.ControlBox = false;
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnAddNewCard);
this.Controls.Add(this.groupBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "AddNewCard";
this.ShowInTaskbar = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "办理读者证件";
this.Load += new System.EventHandler(this.AddNewCard_Load);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 初始化界面
/// </summary>
private void initializeScreen()
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
textBox6.Text = "";
textBox7.Text = "";
textBox8.Text = "";
comboBox1.Items.Clear();
comboBox2.Items.Clear();
dateTimePicker1.Value = DateTime.Now;
dateTimePicker2.Value = DateTime.Now;
radioButton1.Checked = true;
string str = "select 部门名称 from 部门";
cmd.CommandText = str;
try
{
dr = cmd.ExecuteReader();
while(dr.Read())
{
comboBox1.Items.Add(dr.GetString(0));
}
dr.Close();
}
catch(Exception ex)
{
if(dr != null ) dr.Close();
MessageBox.Show(ex.ToString());
return;
}
str = "select 类型名称 from 读者类型";
cmd.CommandText = str;
try
{
dr = cmd.ExecuteReader();
while(dr.Read())
{
comboBox2.Items.Add(dr.GetString(0));
}
dr.Close();
}
catch(Exception ex)
{
if(dr != null ) dr.Close();
MessageBox.Show(ex.ToString());
return;
}
radioButton1.Checked = true;
textBox1.Focus();
}
private void initializeScreen(string readerID)
{
string sqlstr = "select * from 读者信息 where 借书证号='" + readerID + "'";
}
/// <summary>
/// 显示各类型读者能够借书数量
/// </summary>
/// <param name="type">类型</param>
private void showInfo(string type)
{
string str = "select 借阅天数,借阅量,超期罚款额 from 读者类型 where 类型名称='" + type + "'";
cmd.CommandText = str;
try
{
dr = cmd.ExecuteReader();
dr.Read();
if(dr.HasRows)
{
textBox5.Text = dr.GetInt32(0).ToString();
textBox6.Text = dr.GetInt32(1).ToString();
textBox7.Text = dr.GetValue(2).ToString();
}
dr.Close();
}
catch(Exception ex)
{
if(dr != null) dr.Close();
MessageBox.Show(ex.ToString());
return;
}
}
/// <summary>
/// 新增记录
/// </summary>
private void insertData()
{
if(this.comboBox2.SelectedIndex<0)
{
MessageBox.Show("读者类型不能为空!");
return;
}
int count=0;
string str;
string sex;
if(radioButton1.Checked)
{
sex = "男";
}
else
{
sex = "女";
}
int i;
string s = "select 部门编号 from 部门 where 部门名称='" + comboBox1.Text + "'";
cmd.CommandText = s;
try
{
dr = cmd.ExecuteReader();
dr.Read();
if(dr.HasRows)
{
i = dr.GetInt32(0);
}
else
{
i=0;
}
dr.Close();
}
catch(Exception ex)
{
if(dr != null)dr.Close();
MessageBox.Show(ex.ToString());
return;
}
str = "insert into 读者 values('" + textBox2.Text + "','" +
sex + "','" + dateTimePicker1.Value.ToShortDateString() + "','" +
textBox3.Text + "','" + textBox4.Text + "','" + textBox8.Text + "'," + i + ",";
s = "select 类型编号 from 读者类型 where 类型名称 ='" + comboBox2.Text +"'";
cmd.CommandText = s;
try
{
dr = cmd.ExecuteReader();
dr.Read();
if(dr.HasRows)
{
i = dr.GetInt32(0);
}
else
{
i=0;
}
dr.Close();
}
catch(Exception ex)
{
if(dr != null)dr.Close();
MessageBox.Show(ex.ToString());
return;
}
//此处str后面添加的0表示证件状态
str += i + ")";
string str2;
//创建事务
SqlTransaction trans = Global.conn.BeginTransaction();
cmd.Transaction = trans;
try
{
//数据插入 1
cmd.CommandText = str;
cmd.ExecuteNonQuery();
//数据查询 1
str= "select 读者编号 from 读者";
cmd.CommandText = str;
try
{
dr = cmd.ExecuteReader();
while(dr.Read())
{
count = dr.GetInt32(0);
}
dr.Close();
//count ++;
}
catch(Exception ex)
{
if(dr != null) dr.Close();
MessageBox.Show(ex.ToString());
return;
}
//数据插入 2
str2 = "insert into 借书证 values('" + textBox1.Text + "'," + count + ",'" +
dateTimePicker2.Value.ToShortDateString() + "',0)";
cmd.CommandText = str2;
cmd.ExecuteNonQuery();
//事务提交
trans.Commit();
if(MessageBox.Show("读者证件办理成功!\n是否继续办理?","提示与询问",MessageBoxButtons.YesNo)==DialogResult.Yes)
{
initializeScreen();
}
else
{
Global.sbpGlobal.Text = "就绪";
this.Close();
}
}
catch(Exception e)
{
try
{
trans.Rollback();
}
catch (SqlException ex)
{
if (trans.Connection != null)
{
MessageBox.Show(ex.ToString());
}
}
MessageBox.Show(e.ToString());
}
}
/// <summary>
/// 窗体加载代码
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void AddNewCard_Load(object sender, System.EventArgs e)
{
}
/// <summary>
/// 新增记录
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnAddNewCard_Click(object sender, System.EventArgs e)
{
insertData();
initializeScreen();
}
/// <summary>
/// 读者类型改变后显示相关信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void comboBox2_SelectedIndexChanged(object sender, System.EventArgs e)
{
showInfo(comboBox2.Text);
}
/// <summary>
/// 取消
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnCancel_Click(object sender, System.EventArgs e)
{
Global.sbpGlobal.Text = "就绪";
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -