📄 roomtypeform.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace HotelManage
{
/// <summary>
/// Form2 的摘要说明。
/// </summary>
public class RoomTypeForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Panel panel1;
private string selectStr;
private SqlConnection sqlConnection1;
private SqlCommand sqlCommand1=null;
private SqlDataReader sqlDataReader1=null;
private bool add;
private DataSet ds= null;
private System.Windows.Forms.Button btnNew;
private System.Windows.Forms.Button btnSave;
private System.Windows.Forms.TextBox textPrice;
private System.Windows.Forms.TextBox textBedNum;
private System.Windows.Forms.TextBox textArea;
private System.Windows.Forms.TextBox textTypeName;
private System.Windows.Forms.CheckBox checkAirCondition;
private System.Windows.Forms.CheckBox checkTelephone;
private System.Windows.Forms.CheckBox checkToilet;
private System.Windows.Forms.CheckBox checkTV;
HotelManage.RoomTypeManage roomtypeManage;
private System.Windows.Forms.DataGrid dataGrid1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public RoomTypeForm()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
this.sqlConnection1=new SqlConnection(HotelManage.util.Connection.ConnString);
this.sqlCommand1=new SqlCommand();
this.sqlCommand1.Connection=this.sqlConnection1;
this.add=false;
roomtypeManage=new HotelManage.RoomTypeManage();
//
// 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.checkAirCondition = new System.Windows.Forms.CheckBox();
this.checkTelephone = new System.Windows.Forms.CheckBox();
this.label5 = new System.Windows.Forms.Label();
this.textPrice = new System.Windows.Forms.TextBox();
this.checkToilet = new System.Windows.Forms.CheckBox();
this.checkTV = new System.Windows.Forms.CheckBox();
this.textBedNum = new System.Windows.Forms.TextBox();
this.textArea = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.textTypeName = new System.Windows.Forms.TextBox();
this.panel1 = new System.Windows.Forms.Panel();
this.btnNew = new System.Windows.Forms.Button();
this.btnSave = new System.Windows.Forms.Button();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// checkAirCondition
//
this.checkAirCondition.Location = new System.Drawing.Point(360, 8);
this.checkAirCondition.Name = "checkAirCondition";
this.checkAirCondition.Size = new System.Drawing.Size(64, 24);
this.checkAirCondition.TabIndex = 1;
this.checkAirCondition.Text = "空调";
//
// checkTelephone
//
this.checkTelephone.Location = new System.Drawing.Point(280, 48);
this.checkTelephone.Name = "checkTelephone";
this.checkTelephone.Size = new System.Drawing.Size(64, 24);
this.checkTelephone.TabIndex = 15;
this.checkTelephone.Text = "电话";
//
// label5
//
this.label5.Location = new System.Drawing.Point(120, 40);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(32, 23);
this.label5.TabIndex = 14;
this.label5.Text = "价钱";
//
// textPrice
//
this.textPrice.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textPrice.Location = new System.Drawing.Point(168, 40);
this.textPrice.Name = "textPrice";
this.textPrice.Size = new System.Drawing.Size(72, 21);
this.textPrice.TabIndex = 13;
this.textPrice.Text = "";
//
// checkToilet
//
this.checkToilet.Location = new System.Drawing.Point(360, 48);
this.checkToilet.Name = "checkToilet";
this.checkToilet.Size = new System.Drawing.Size(64, 24);
this.checkToilet.TabIndex = 12;
this.checkToilet.Text = "卫生间";
//
// checkTV
//
this.checkTV.ForeColor = System.Drawing.SystemColors.ControlText;
this.checkTV.Location = new System.Drawing.Point(280, 8);
this.checkTV.Name = "checkTV";
this.checkTV.Size = new System.Drawing.Size(64, 24);
this.checkTV.TabIndex = 11;
this.checkTV.Text = "电视";
//
// textBedNum
//
this.textBedNum.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textBedNum.Location = new System.Drawing.Point(40, 40);
this.textBedNum.Name = "textBedNum";
this.textBedNum.Size = new System.Drawing.Size(72, 21);
this.textBedNum.TabIndex = 10;
this.textBedNum.Text = "";
//
// textArea
//
this.textArea.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textArea.Location = new System.Drawing.Point(168, 8);
this.textArea.Name = "textArea";
this.textArea.Size = new System.Drawing.Size(72, 21);
this.textArea.TabIndex = 9;
this.textArea.Text = "";
//
// label4
//
this.label4.Location = new System.Drawing.Point(8, 40);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(32, 23);
this.label4.TabIndex = 6;
this.label4.Text = "床位";
//
// label3
//
this.label3.Location = new System.Drawing.Point(120, 16);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(32, 23);
this.label3.TabIndex = 5;
this.label3.Text = "面积";
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 8);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(32, 23);
this.label2.TabIndex = 4;
this.label2.Text = "名称";
//
// textTypeName
//
this.textTypeName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textTypeName.Enabled = false;
this.textTypeName.Location = new System.Drawing.Point(40, 8);
this.textTypeName.Name = "textTypeName";
this.textTypeName.Size = new System.Drawing.Size(72, 21);
this.textTypeName.TabIndex = 2;
this.textTypeName.Text = "";
//
// panel1
//
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel1.Controls.Add(this.label4);
this.panel1.Controls.Add(this.label3);
this.panel1.Controls.Add(this.checkTelephone);
this.panel1.Controls.Add(this.label2);
this.panel1.Controls.Add(this.label5);
this.panel1.Controls.Add(this.textPrice);
this.panel1.Controls.Add(this.textTypeName);
this.panel1.Controls.Add(this.checkToilet);
this.panel1.Controls.Add(this.checkTV);
this.panel1.Controls.Add(this.textBedNum);
this.panel1.Controls.Add(this.textArea);
this.panel1.Controls.Add(this.checkAirCondition);
this.panel1.Controls.Add(this.btnNew);
this.panel1.Controls.Add(this.btnSave);
this.panel1.ForeColor = System.Drawing.SystemColors.ControlText;
this.panel1.Location = new System.Drawing.Point(16, 16);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(528, 76);
this.panel1.TabIndex = 16;
//
// btnNew
//
this.btnNew.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnNew.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnNew.Location = new System.Drawing.Point(432, 8);
this.btnNew.Name = "btnNew";
this.btnNew.Size = new System.Drawing.Size(56, 23);
this.btnNew.TabIndex = 18;
this.btnNew.Text = "新建";
this.btnNew.Click += new System.EventHandler(this.btnNew_Click);
//
// btnSave
//
this.btnSave.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnSave.Location = new System.Drawing.Point(432, 40);
this.btnSave.Name = "btnSave";
this.btnSave.Size = new System.Drawing.Size(56, 24);
this.btnSave.TabIndex = 17;
this.btnSave.Text = "保存";
this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
//
// dataGrid1
//
this.dataGrid1.BackgroundColor = System.Drawing.SystemColors.ActiveCaptionText;
this.dataGrid1.CaptionVisible = false;
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(16, 112);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(528, 256);
this.dataGrid1.TabIndex = 18;
//
// RoomTypeForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.AliceBlue;
this.ClientSize = new System.Drawing.Size(554, 375);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.panel1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Name = "RoomTypeForm";
this.Text = "客房类型";
this.Load += new System.EventHandler(this.RoomType_Load);
this.panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void RoomType_Load(object sender, System.EventArgs e)
{
this.selectStr=" select RoomTypeName 类型名称,Area 面积,BedNum 床位,Price 价钱,"+
" case AirCondition when 1 then '有' when 0 then '无' end 空调,"+
" case HasPhone when 1 then '有' when 0 then '无' end 电话,"+
" case HasTelevision when 1 then '有' when 0 then '无' end 电视,"+
" case HasToilet when 1 then '有' when 0 then '无' end 卫生间"+
" from roomtype";
this.FillDataGrid(selectStr);
}
private void btnNew_Click(object sender, System.EventArgs e)
{
this.add=true;
this.textTypeName.Enabled=true;
this.textTypeName.Clear();
this.textArea.Clear();
this.textBedNum.Clear();
this.textPrice.Clear();
this.checkToilet.Checked=false;
this.checkTV.Checked=false;
this.checkTelephone.Checked=false;
this.checkAirCondition.Checked=false;
}
private void btnSave_Click(object sender, System.EventArgs e)
{
string typename=this.textTypeName.Text;
int area=Convert.ToInt16(this.textArea.Text);
float price=Convert.ToSingle(this.textPrice.Text);
int bednum=Convert.ToInt16(this.textBedNum.Text);
int tv=Convert.ToInt16(this.checkTV.Checked);
int telephone=Convert.ToInt16(this.checkTelephone.Checked);
int aircondition=Convert.ToInt16(this.checkAirCondition.Checked);
int HasToilet=Convert.ToInt16(this.checkToilet.Checked);
if(add)
{
//this.selectStr="insert into RoomType values("+"'"+typename+"',"+area+","+bednum+","+price+","+aircondition+","+telephone+","+tv+","+HasToilet+")";
this.roomtypeManage.RoomType_Add(typename,area,bednum,price,telephone,tv,HasToilet,aircondition);
MessageBox.Show("添加信息成功");
this.FillDataGrid(this.selectStr);
}
else
{
if(this.roomtypeManage.Room_Modify(typename,area,bednum,price,telephone,tv,HasToilet,aircondition)==true)
{
MessageBox.Show("修改信息成功","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.FillDataGrid(this.selectStr);
}
else
{
MessageBox.Show("修改信息失败","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
//this.selectStr="update RoomType set Area="+area+","+"BedNum="+bednum+","+"Price="+price+","+"AirCondition="+aircondition+","+"HasPhone="+telephone+","+"HasTelevision"+tv+","+"HasToilet="+HasToilet+" where RoomTypeName="+"'"+typename+"'";
this.sqlCommand1.CommandText=this.selectStr;
try
{
this.sqlConnection1.Open();
this.sqlCommand1.ExecuteNonQuery();
this.FillDataGrid(this.selectStr);
}
catch(System.Exception E)
{
MessageBox.Show(E.ToString());
}
finally
{
this.sqlConnection1.Close();
}
this.add=false;
}
}
private void FillDataGrid(string sql)
{
if(this.sqlConnection1.State==ConnectionState.Closed)this.sqlConnection1.Open();
Console.WriteLine(sql);
SqlDataAdapter adapter = new SqlDataAdapter(sql,sqlConnection1);
ds = new DataSet("t_user");
adapter.Fill(ds,"t_user");
this.dataGrid1.SetDataBinding(ds,"t_user");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -