namespace_2017test{internalstaticclassProgram{/// <summary>/// The main entry point for the application./// </summary>[STAThread]staticvoidMain(){
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);try{
DB.conn =newSystem.Data.SqlClient.SqlConnection(DB.connStr);
DB.conn.Open();}catch(Exception ex){
MessageBox.Show(ex.Message);}
Application.Run(newMainForm());
DB.conn.Close();}}}
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Data.SqlClient;usingSystem.Drawing;usingSystem.Linq;usingSystem.Security.Cryptography;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;usingstaticSystem.Windows.Forms.VisualStyles.VisualStyleElement;namespace_2017test{publicpartialclassFormSearch:Form{publicFormSearch(){InitializeComponent();MyShow();}privatevoidbutton1_Click(object sender,EventArgs e){string sql =@"SELECT d.DeptName,g.GroupName,p.PName
FROM [2017].[dbo].[Patients] p ,[2017].[dbo].[Departments] d,[2017].[dbo].[Groups] g
WHERE p.GroupNo =g.GroupNo and g.DeptNo=d.DeptNo";if(!string.IsNullOrEmpty(textBox1.Text)){//sql += @" and d.DeptName like " + textBox1.Text + @" ";
sql +=@" and d.DeptName like '%"+ textBox1.Text +"%' ";}if(!string.IsNullOrEmpty(textBox2.Text)){//sql += @" and g.GroupName like " + textBox2.Text + @" ";
sql +=@" and d.DeptName like '%"+ textBox2.Text +"%' ";}
Console.Write(textBox1.Text);
Console.Write(textBox2.Text);
Console.Write(textBox3.Text);if(!string.IsNullOrEmpty(textBox3.Text)){//sql += @" and p.PName like " + @" %"+textBox3.Text + @"% ";
sql +=@" and d.DeptName like '%"+ textBox3.Text +"%' ";}
sql +=@" order by d.DeptNo desc,g.GroupNo ,p.GroupNo desc";
DB.TableSelect(sql);
dv.DataSource = DB.TableSelect(sql);}publicvoidMyShow(){string sql =@"SELECT d.DeptName,g.GroupName,p.PName
FROM [2017].[dbo].[Patients] p ,[2017].[dbo].[Departments] d,[2017].[dbo].[Groups] g
WHERE p.GroupNo =g.GroupNo and g.DeptNo=d.DeptNo
order by d.DeptNo desc,g.GroupNo ,p.GroupNo desc";
dv.DataSource = DB.TableSelect(sql);}privatevoiddataGridView1_CellContentClick(object sender,DataGridViewCellEventArgs e){}}}
病人表维护窗体
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Data.SqlClient;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;usingstaticSystem.Windows.Forms.VisualStyles.VisualStyleElement;namespace_2017test{publicpartialclassFormPatients:Form{publicFormPatients(){InitializeComponent();MyShow();}privatevoidbutton1_Click(object sender,EventArgs e){string sql =@"INSERT INTO [2017].[dbo].[Patients]
([PID]
,[PName]
,[Date]
,[GroupNo])
VALUES(@PID,@PName,@Date,@GroupNo)";SqlParameter[] para ={newSqlParameter("@PID", textBox1.Text),newSqlParameter("@PName", textBox2.Text),newSqlParameter("@Date", textBox3.Text),newSqlParameter("@GroupNo",textBox4.Text)};
DB.TableChange(sql, para);MyShow();}privatevoidbutton2_Click(object sender,EventArgs e){string sql =@"DELETE FROM [2017].[dbo].[Patients]
WHERE [PID] = @PID;";SqlParameter[] para ={newSqlParameter("@PID", textBox1.Text)};
DB.TableChange(sql, para);MyShow();}privatevoidbutton3_Click(object sender,EventArgs e){string sql =@"UPDATE [2017].[dbo].[Patients]
SET [PName]=@PName
,[Date]=@Date
,[GroupNo]=@GroupNo
WHERE [PID]=@PID;";SqlParameter[] para ={newSqlParameter("@PID", textBox1.Text),newSqlParameter("@PName", textBox2.Text),newSqlParameter("@Date", textBox3.Text),newSqlParameter("@GroupNo",textBox4.Text)};
DB.TableChange(sql, para);MyShow();}publicvoidMyShow(){string sql =@"SELECT *
FROM [2017].[dbo].[Patients]";
dv.DataSource = DB.TableSelect(sql);}}}
小科室表维护窗体
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Data.SqlClient;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespace_2017test{publicpartialclassFormGroup:Form{publicFormGroup(){InitializeComponent();MyShow();}//增privatevoidbutton1_Click(object sender,EventArgs e){string sql =@"INSERT INTO [2017].[dbo].[Groups]
([GroupNo]
,[GroupName]
,[DeptNo]
,[Month]
,[Number])
VALUES(@GroupNo,@GroupName,@DeptNo,@Month,@Number)";SqlParameter[] para ={newSqlParameter("@GroupNo", textBox1.Text),newSqlParameter("@GroupName", textBox2.Text),newSqlParameter("@DeptNo", textBox3.Text),newSqlParameter("@Month",textBox4.Text),newSqlParameter("@Number",textBox5.Text)};
DB.TableChange(sql, para);MyShow();}//删privatevoidbutton2_Click(object sender,EventArgs e){string sql =@"DELETE FROM [2017].[dbo].[Groups]
WHERE [GroupNo] = @GroupNo;";SqlParameter[] para ={newSqlParameter("@GroupNo", textBox1.Text)};
DB.TableChange(sql, para);MyShow();}//改privatevoidbutton3_Click(object sender,EventArgs e){string sql =@"UPDATE [2017].[dbo].[Groups]
SET [GroupName]=@GroupName
,[DeptNo]=@DeptNo
,[Month]=@Month
,[Number]=@Number
WHERE [GroupNo]=@GroupNo;";SqlParameter[] para ={newSqlParameter("@GroupNo", textBox1.Text),newSqlParameter("@GroupName", textBox2.Text),newSqlParameter("@DeptNo", textBox3.Text),newSqlParameter("@Month",textBox4.Text),newSqlParameter("@Number",textBox5.Text)};
DB.TableChange(sql, para);MyShow();}publicvoidMyShow(){string sql =@"SELECT *
FROM [2017].[dbo].[Groups]
WHERE [2017].[dbo].[Groups].Number=(select MAX([2017].[dbo].[Groups].Number) from [2017].[dbo].[Groups])
OR [2017].[dbo].[Groups].Number=(select MIN([2017].[dbo].[Groups].Number) from [2017].[dbo].[Groups]);";
dv.DataSource = DB.TableSelect(sql);}privatevoidtextBox1_TextChanged(object sender,EventArgs e){}}}
统计窗口
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespace_2017test{publicpartialclassFormStatistics:Form{publicFormStatistics(){InitializeComponent();}privatevoidbutton1_Click(object sender,EventArgs e){string sql =@"SELECT a.DeptName 大科室名 ,sum(b.Number) 病人人数
FROM [2017].[dbo].[Departments] a ,[2017].[dbo].[Groups] b WHERE a.DeptNo=b.DeptNo
Group by a.DeptName";
dv.DataSource = DB.TableSelect(sql);}privatevoidbutton2_Click(object sender,EventArgs e){string sql =@"SELECT a.Month 月份 ,sum(a.Number) 病人人数
FROM [2017].[dbo].[Groups] a
Group by a.Month";
dv.DataSource = DB.TableSelect(sql);}}}