📄 roomtype.cs
字号:
//
this.textSearch.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textSearch.Location = new System.Drawing.Point(8, 144);
this.textSearch.Multiline = true;
this.textSearch.Name = "textSearch";
this.textSearch.Size = new System.Drawing.Size(68, 20);
this.textSearch.TabIndex = 21;
this.textSearch.Text = "";
//
// btnSearch
//
this.btnSearch.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnSearch.Image = ((System.Drawing.Image)(resources.GetObject("btnSearch.Image")));
this.btnSearch.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnSearch.Location = new System.Drawing.Point(16, 80);
this.btnSearch.Name = "btnSearch";
this.btnSearch.Size = new System.Drawing.Size(56, 24);
this.btnSearch.TabIndex = 20;
this.btnSearch.Text = "查找";
this.btnSearch.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
//
// btnDelete
//
this.btnDelete.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnDelete.Image = ((System.Drawing.Image)(resources.GetObject("btnDelete.Image")));
this.btnDelete.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnDelete.Location = new System.Drawing.Point(16, 48);
this.btnDelete.Name = "btnDelete";
this.btnDelete.Size = new System.Drawing.Size(56, 23);
this.btnDelete.TabIndex = 19;
this.btnDelete.Text = "删除";
this.btnDelete.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
//
// btnNew
//
this.btnNew.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnNew.Image = ((System.Drawing.Image)(resources.GetObject("btnNew.Image")));
this.btnNew.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnNew.Location = new System.Drawing.Point(16, 16);
this.btnNew.Name = "btnNew";
this.btnNew.Size = new System.Drawing.Size(56, 23);
this.btnNew.TabIndex = 18;
this.btnNew.Text = "新建";
this.btnNew.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.btnNew.Click += new System.EventHandler(this.btnNew_Click);
//
// btnSave
//
this.btnSave.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnSave.Image = ((System.Drawing.Image)(resources.GetObject("btnSave.Image")));
this.btnSave.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnSave.Location = new System.Drawing.Point(16, 256);
this.btnSave.Name = "btnSave";
this.btnSave.Size = new System.Drawing.Size(56, 24);
this.btnSave.TabIndex = 17;
this.btnSave.Text = "保存";
this.btnSave.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
//
// btnCancel
//
this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnCancel.Image = ((System.Drawing.Image)(resources.GetObject("btnCancel.Image")));
this.btnCancel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnCancel.Location = new System.Drawing.Point(16, 224);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(56, 23);
this.btnCancel.TabIndex = 16;
this.btnCancel.Text = "取消";
this.btnCancel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// btnExit
//
this.btnExit.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnExit.Image = ((System.Drawing.Image)(resources.GetObject("btnExit.Image")));
this.btnExit.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnExit.Location = new System.Drawing.Point(16, 328);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(56, 23);
this.btnExit.TabIndex = 15;
this.btnExit.Text = "退出";
this.btnExit.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// RoomType
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.SystemColors.Window;
this.ClientSize = new System.Drawing.Size(644, 475);
this.Controls.Add(this.panel2);
this.Controls.Add(this.listView1);
this.Controls.Add(this.panel1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "RoomType";
this.Text = "客房标准";
this.Load += new System.EventHandler(this.RoomType_Load);
this.panel1.ResumeLayout(false);
this.panel2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void RoomType_Load(object sender, System.EventArgs e)
{
this.SearchControl(false);
this.UpdateListView();
}
private void UpdateListView()
{
this.listView1.Items.Clear();
this.listView1.Refresh();
this.selectStr="select * from RoomType";
//this.sqlCommand1=new SqlCommand(this.selectStr,this.sqlConnection1);
this.sqlCommand1.CommandText=this.selectStr;
try
{
if(this.sqlConnection1.State==ConnectionState.Closed)this.sqlConnection1.Open();
this.sqlDataReader1=this.sqlCommand1.ExecuteReader();
while(this.sqlDataReader1.Read())
{
ListViewItem li = new ListViewItem ( ) ;
li.SubItems.Clear ( ) ;
li.SubItems[0].Text = sqlDataReader1["RoomTypeName"].ToString ( ) ;
li.SubItems.Add ( sqlDataReader1["Area"].ToString ( ) ) ;
li.SubItems.Add ( sqlDataReader1["BedNum"].ToString ( ) ) ;
li.SubItems.Add (sqlDataReader1["Price"].ToString ( ) ) ;
if(Convert.ToBoolean(sqlDataReader1["AirCondition"]) ==true)
li.SubItems.Add ("是" ) ;
else
li.SubItems.Add("否");
if(Convert.ToBoolean(sqlDataReader1["Phone"]) ==true)
li.SubItems.Add ("是" ) ;
else
li.SubItems.Add("否");
if(Convert.ToBoolean(sqlDataReader1["Television"]) ==true)
li.SubItems.Add ("是" ) ;
else
li.SubItems.Add("否");
if(Convert.ToBoolean(sqlDataReader1["Toilet"]) ==true)
li.SubItems.Add ("是" ) ;
else
li.SubItems.Add("否");
this.listView1.Items.Add ( li ) ;
}
}
catch(System.Exception E)
{
MessageBox.Show(E.ToString());
}
finally
{
this.sqlDataReader1.Close();
this.sqlConnection1.Close();
}
if(this.listView1.Items.Count==0)
{
MessageBox.Show("没有记录存在","没有记录",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
private void btnExit_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void btnDelete_Click(object sender, System.EventArgs e)
{
int i;
this.selectStr="delete from RoomType where RoomTypeName="+"'"+this.textTypeName.Text+"'";
this.sqlCommand1.CommandText=this.selectStr;
if(MessageBox.Show("确定删除此记录吗?","删除",MessageBoxButtons.YesNo,MessageBoxIcon.Question)==DialogResult.Yes)
{
for(i=0;i<this.listView1.Items.Count;i++)
{
if(this.listView1.Items[i].Selected==true)
break;
}
try
{
this.sqlConnection1.Open();
this.sqlCommand1.ExecuteNonQuery();
this.UpdateListView();
this.TextChangeWithList(i);
}
catch(System.Exception E)
{
MessageBox.Show(E.ToString());
}
finally
{
this.sqlConnection1.Close();
}
}
else
return;
}
private void TextChangeWithList(int i)
{
if(i>this.listView1.Items.Count)i=0;
this.textTypeName.Text=this.listView1.Items[i].SubItems[0].Text.ToString();
this.textArea.Text=this.listView1.Items[i].SubItems[1].Text.ToString();
this.textBedNum.Text=this.listView1.Items[i].SubItems[2].Text.ToString();
this.textPrice.Text=this.listView1.Items[i].SubItems[3].Text.ToString();
if(this.listView1.Items[i].SubItems[4].Text.ToString()=="是")
{
this.checkAirCondition.Checked=true;
}
else
{
this.checkAirCondition.Checked=false;
}
if(this.listView1.Items[i].SubItems[5].Text.ToString()=="是")
{
this.checkTelephone.Checked=true;
}
else
{
this.checkTelephone.Checked=false;
}
if(this.listView1.Items[i].SubItems[6].Text=="是")
{
this.checkTV.Checked=true;
}
else
{
this.checkTV.Checked=false;
}
if(this.listView1.Items[i].SubItems[7].Text=="是")
{
this.checkToilet.Checked=true;
}
else
{
this.checkToilet.Checked=false;
}
}
private void listView1_SelectedIndexChanged(object sender, System.EventArgs e)
{
foreach(int i in this.listView1.SelectedIndices)
{
this.TextChangeWithList(i);
}
}
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 SearchControl(bool visible)
{
if(visible)
{
this.label7.Visible=true;
this.textSearch.Visible=true;
this.btnStart.Visible=true;
}
else
{
this.label7.Visible=false;
this.textSearch.Visible=false;
this.btnStart.Visible=false;
}
}
private void btnSearch_Click(object sender, System.EventArgs e)
{
this.textSearch.Clear();
this.SearchControl(true);
}
private void btnStart_Click(object sender, System.EventArgs e)
{
for(int i=0;i<this.listView1.Items.Count;i++)
{
if(this.listView1.Items[i].SubItems[0].Text==this.textSearch.Text)
{
this.listView1.Items[i].Selected=true;
this.SearchControl(false);
return;
}
}
MessageBox.Show("没有找到该记录","没有找到");
this.SearchControl(false);
}
private void btnCancel_Click(object sender, System.EventArgs e)
{
this.add=false;
foreach(int i in this.listView1.SelectedIndices)
{
this.TextChangeWithList(i);
this.listView1.Items[i].BackColor=Color.Silver;
}
}
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 toilet=Convert.ToInt16(this.checkToilet.Checked);
if(add)
{
//this.selectStr="insert into RoomType values("+"'"+typename+"',"+area+","+bednum+","+price+","+aircondition+","+telephone+","+tv+","+toilet+")";
this.roomtypeManage.RoomType_Add(typename,area,bednum,price,telephone,tv,toilet,aircondition);
MessageBox.Show("添加信息成功");
this.UpdateListView();
}
else
{
if(this.roomtypeManage.Room_Modify(typename,area,bednum,price,telephone,tv,toilet,aircondition)==true)
{
MessageBox.Show("修改信息成功","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.UpdateListView();
}
else
{
MessageBox.Show("修改信息失败","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
//this.selectStr="update RoomType set Area="+area+","+"BedNum="+bednum+","+"Price="+price+","+"AirCondition="+aircondition+","+"Phone="+telephone+","+"Television"+tv+","+"Toilet="+toilet+" where RoomTypeName="+"'"+typename+"'";
this.sqlCommand1.CommandText=this.selectStr;
try
{
this.sqlConnection1.Open();
this.sqlCommand1.ExecuteNonQuery();
this.UpdateListView();
}
catch(System.Exception E)
{
MessageBox.Show(E.ToString());
}
finally
{
this.sqlConnection1.Close();
}
this.add=false;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -