?? 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 = "聯(lián)系電話";
//
// 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 = "聯(lián)系地址";
//
// 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>
/// 顯示各類型讀者能夠借書數(shù)量
/// </summary>
/// <param name="type">類型</param>
private void showInfo(string type)
{
string str = "select 借閱天數(shù),借閱量,超期罰款額 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表示證件狀態(tài)
str += i + ")";
string str2;
//創(chuàng)建事務(wù)
SqlTransaction trans = Global.conn.BeginTransaction();
cmd.Transaction = trans;
try
{
//數(shù)據(jù)插入 1
cmd.CommandText = str;
cmd.ExecuteNonQuery();
//數(shù)據(jù)查詢 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;
}
//數(shù)據(jù)插入 2
str2 = "insert into 借書證 values('" + textBox1.Text + "'," + count + ",'" +
dateTimePicker2.Value.ToShortDateString() + "',0)";
cmd.CommandText = str2;
cmd.ExecuteNonQuery();
//事務(wù)提交
trans.Commit();
if(MessageBox.Show("讀者證件辦理成功!\n是否繼續(xù)辦理?","提示與詢問",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>
/// 讀者類型改變后顯示相關(guān)信息
/// </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();
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -