?? 主窗口.cs
字號:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace 系統管理員
{
/// <summary>
/// 主窗口 的摘要說明。
/// </summary>
public class 主窗口 : System.Windows.Forms.Form
{
/// <summary>
/// 必需的設計器變量。
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private 讀者信息dll.UserControl1 userControl11;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.MenuItem menuItem6;
private 書目管理dll.UserControl1 userControl12;
public Form1 p;
public 主窗口()
{
//
// Windows 窗體設計器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 調用后添加任何構造函數代碼
//
}
/// <summary>
/// 清理所有正在使用的資源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗體設計器生成的代碼
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.userControl11 = new 讀者信息dll.UserControl1();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.label1 = new System.Windows.Forms.Label();
this.userControl12 = new 書目管理dll.UserControl1();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem2});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem3,
this.menuItem4});
this.menuItem1.Text = "讀者管理";
//
// menuItem3
//
this.menuItem3.Index = 0;
this.menuItem3.Text = "增加讀者";
this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
//
// menuItem4
//
this.menuItem4.Index = 1;
this.menuItem4.Text = "讀者管理";
this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
//
// menuItem2
//
this.menuItem2.Index = 1;
this.menuItem2.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem5,
this.menuItem6});
this.menuItem2.Text = "書目管理";
//
// menuItem5
//
this.menuItem5.Index = 0;
this.menuItem5.Text = "增加書目";
this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click);
//
// menuItem6
//
this.menuItem6.Index = 1;
this.menuItem6.Text = "書目管理";
this.menuItem6.Click += new System.EventHandler(this.menuItem6_Click);
//
// userControl11
//
this.userControl11.Location = new System.Drawing.Point(0, -16);
this.userControl11.Name = "userControl11";
this.userControl11.Size = new System.Drawing.Size(752, 432);
this.userControl11.TabIndex = 0;
this.userControl11.Load += new System.EventHandler(this.userControl11_Load);
this.userControl11.textBox1.KeyDown+=new KeyEventHandler(textBox1_KeyDown);
//
// button1
//
this.button1.Location = new System.Drawing.Point(384, 248);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "確定";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(480, 248);
this.button2.Name = "button2";
this.button2.TabIndex = 2;
this.button2.Text = "取消";
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(24, 288);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.ReadOnly = true;
this.dataGrid1.Size = new System.Drawing.Size(712, 88);
this.dataGrid1.TabIndex = 3;
//
// label1
//
this.label1.Font = new System.Drawing.Font("宋體", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.ForeColor = System.Drawing.Color.Crimson;
this.label1.Location = new System.Drawing.Point(216, 80);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 32);
this.label1.TabIndex = 4;
this.label1.Text = "*輸入證件號回車可查詢";
//
// userControl12
//
this.userControl12.Location = new System.Drawing.Point(8, 0);
this.userControl12.Name = "userControl12";
this.userControl12.Size = new System.Drawing.Size(728, 440);
this.userControl12.TabIndex = 5;
this.userControl12.Load += new System.EventHandler(this.userControl12_Load);
//
// 主窗口
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(744, 425);
this.Controls.Add(this.userControl12);
this.Controls.Add(this.label1);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.userControl11);
this.Menu = this.mainMenu1;
this.Name = "主窗口";
this.Text = "主窗口";
this.Closed += new System.EventHandler(this.主窗口_Closed);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void 主窗口_Closed(object sender, System.EventArgs e)
{
this.p.Close();
}
private void menuItem3_Click(object sender, System.EventArgs e)
{
this.userControl11.Visible=true;
this.userControl12.Visible=false;
this.userControl11.button1.Visible=false;
this.userControl11.button2.Visible=false;
this.button1.Visible=true;
this.button2.Visible=true;
公共數據dll.Store.ds.Clear();
this.userControl11.textBox4.Text="";
this.userControl11.textBox2.Text="";
this.userControl11.textBox1.Text="";
this.userControl11.textBox3.Text="";
this.userControl11.textBox5.Text="";
}
private void userControl11_Load(object sender, System.EventArgs e)
{
this.userControl11.button1.Enabled=false;
this.userControl11.button2.Enabled=false;
this.button1.Visible=false;
this.button2.Visible=false;
}
private void button1_Click(object sender, System.EventArgs e)//增加讀者
{
公共數據dll.Store.cn.Open();
公共數據dll.Store.sqlStr="insert into readerinfo(密碼,證件號,姓名,年齡,性別,出生日期,文化程度,工作單位,職業,電話,[E-MAIL],最大借書量) values ('"+this.userControl11.textBox2.Text+"','"+this.userControl11.textBox1.Text+"','"+this.userControl11.textBox4.Text+"','"+this.userControl11.numericUpDown1.Value+"','"+this.userControl11.comboBox3.Text+"','"+this.userControl11.dateTimePicker1.Value+"','"+this.userControl11.comboBox1.Text+"','"+this.userControl11.comboBox6.Text+"','"+this.userControl11.comboBox4.Text+"','"+this.userControl11.textBox3.Text+"','"+this.userControl11.textBox5.Text+"','"+this.userControl11.comboBox5.Text+"')";
MessageBox.Show(公共數據dll.Store.sqlStr);
公共數據dll.Store.cmd=new System.Data.SqlClient.SqlCommand(公共數據dll.Store.sqlStr,公共數據dll.Store.cn);
try
{
if(公共數據dll.Store.cmd.ExecuteNonQuery()==1)
{
公共數據dll.Store.ds.Clear();
公共數據dll.Store.sqlStr="select * from readerinfo where 證件號='"+this.userControl11.textBox1.Text+"'";
公共數據dll.Store.myDataAdapter=new System.Data.SqlClient.SqlDataAdapter(公共數據dll.Store.sqlStr,公共數據dll.Store.cn);
公共數據dll.Store.myDataAdapter.Fill(公共數據dll.Store.ds,"onlyonerecord");
this.dataGrid1.SetDataBinding(公共數據dll.Store.ds,"onlyonerecord");
}
}
catch(Exception E)
{
MessageBox.Show(E.Message);
}
公共數據dll.Store.cn.Close();
}
private void menuItem4_Click(object sender, System.EventArgs e)//修改/刪除讀者
{
this.userControl11.Visible=true;
this.userControl12.Visible=false;
this.userControl11.button1.Visible=true;
this.userControl11.button2.Visible=true;
this.userControl11.button1.Enabled=true;
this.userControl11.button2.Enabled=true;
this.button1.Visible=false;
this.button2.Visible=false;
公共數據dll.Store.str_temp=this.userControl11.textBox1.Text;
}
private void userControlbutton1_Click(object sender, EventArgs e)
{
公共數據dll.Store.str_temp=this.userControl11.textBox1.Text;
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)//在第一個自定義控件中回車的響應///注意,每次更新容易造成代碼修改器里的textBox1回車事件失效.
{
if(e.KeyValue==13)
{
公共數據dll.Store.ds.Clear();
公共數據dll.Store.sqlStr="select * from readerinfo where 證件號='"+this.userControl11.textBox1.Text+"'";
公共數據dll.Store.myDataAdapter=new System.Data.SqlClient.SqlDataAdapter(公共數據dll.Store.sqlStr,公共數據dll.Store.cn);
公共數據dll.Store.myDataAdapter.Fill(公共數據dll.Store.ds,"inquirereader");
this.dataGrid1.SetDataBinding(公共數據dll.Store.ds,"inquirereader");
////////////////////////////////////////////////////////////////////
foreach(DataRow dr in 公共數據dll.Store.ds.Tables["inquirereader"].Rows)
{
this.userControl11.textBox4.Text=dr["姓名"].ToString();
this.userControl11.textBox2.Text=dr["密碼"].ToString();//////////////////
this.userControl11.textBox1.Text=dr["證件號"].ToString();
this.userControl11.comboBox1.Text=dr["文化程度"].ToString();
this.userControl11.dateTimePicker1.Text=dr["出生日期"].ToString();
decimal year=(decimal)int.Parse(dr["年齡"].ToString());
this.userControl11.numericUpDown1.Value=year;
this.userControl11.comboBox6.Text=dr["工作單位"].ToString();
this.userControl11.comboBox3.Text=dr["性別"].ToString();
this.userControl11.comboBox4.Text=dr["職業"].ToString();
this.userControl11.comboBox5.Text=dr["最大借書量"].ToString();
this.userControl11.textBox3.Text=dr["電話"].ToString();////////////////////////////
this.userControl11.textBox5.Text=dr["E-MAIL"].ToString();/////////////////////////
}
公共數據dll.Store.cn.Close();
}
}
private void menuItem5_Click(object sender, System.EventArgs e)//書目新增時的外觀
{
/////////////////////////////////////自定義控件可見
this.userControl11.Visible=false;
this.userControl12.Visible=true;
/////////////////////////////////////按鈕的可見
this.userControl12.button1.Enabled=true;
this.userControl12.button4.Enabled=true;
this.userControl12.button5.Enabled=false;
this.userControl12.button6.Enabled=false;
this.userControl12.button7.Enabled=false;
this.userControl12.button8.Enabled=false;
}
private void userControl12_Load(object sender, System.EventArgs e)
{
公共數據dll.Store.cn.Close();
this.userControl12.Visible=false;
}
private void menuItem6_Click(object sender, System.EventArgs e)//書目管理時的外觀
{
/////////////////////////////////////自定義控件可見
this.userControl11.Visible=false;
this.userControl12.Visible=true;
/////////////////////////////////////按鈕的可見
this.userControl12.button1.Enabled=false;
this.userControl12.button4.Enabled=false;
this.userControl12.button5.Enabled=true;
this.userControl12.button6.Enabled=true;
this.userControl12.button7.Enabled=true;
this.userControl12.button8.Enabled=true;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -