📄 frmroomtype.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using HotelManageDBL;
using HotelManageMDL;
using HotelManageDAL;
namespace HotelManager
{
public partial class frmRoomType : Form
{
DataSet ds = new DataSet();
HotelManageDA hmDA = new HotelManageDA();
RoomTypeDB rtDB = new RoomTypeDB();
RoomType rt = new RoomType();
public frmRoomType()
{
InitializeComponent();
}
/// <summary>
/// 加载事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void frmRoomType_Load(object sender, EventArgs e)
{
SelectAll();
this.toolStripButton2.Enabled = false;
this.toolStripButton4.Enabled = false;
}
/// <summary>
/// 按类型名称查找事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
string typeName = txtRoomType.Text;
if (typeName == "")
{
MessageBox.Show("客房类型不能为空,请输入!", "友情提示", MessageBoxButtons.OK, MessageBoxIcon.None);
return;
}
ds = rtDB.SelByTypeName(typeName);
if (ds != null)
{
dataGridView1.DataSource = ds.Tables[0];
this.txtRoomType.Clear();
}
else
{
MessageBox.Show("对不起,您输入的客房类型不存在!", "友情提示", MessageBoxButtons.OK, MessageBoxIcon.None);
}
}
/// <summary>
/// 新增按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toolStripButton1_Click(object sender, EventArgs e)
{
UnLock();
Clear();
this.toolStripButton4.Enabled = true;
}
/// <summary>
/// 修改按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toolStripButton2_Click(object sender, EventArgs e)
{
isEmpty();
RoomTypeObject();
bool flag = rtDB.UpdateRoomType(rt);
if (flag)
{
MessageBox.Show("修改成功!", "修改", MessageBoxButtons.OK, MessageBoxIcon.None);
}
else
{
MessageBox.Show("修改失败!", "修改", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
frmRoomType_Load(this, e);
SelectAll();
Clear();
Lock();
this.toolStripButton4.Enabled = true;
}
/// <summary>
/// 删除按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toolStripButton3_Click(object sender, EventArgs e)
{
RoomTypeObject();
bool flag=rtDB.DeleteRoomType(rt);
if (flag)
{
MessageBox.Show("删除成功!", "删除", MessageBoxButtons.OK, MessageBoxIcon.None);
Clear();
Lock();
}
else
{
MessageBox.Show("删除失败!");
}
SelectAll();
}
/// <summary>
/// 在选中的行的值设置到相应的文本框中
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
UnLock();
try
{
txtTypeName.Text = dataGridView1.SelectedCells[1].Value.ToString();
txtPrice.Text = dataGridView1.SelectedCells[2].Value.ToString();
txtAddBedPrice.Text = dataGridView1.SelectedCells[3].Value.ToString();
// MessageBox.Show(dataGridView1.Rows[e.RowIndex].Cells["IsAddBed"].Value.ToString());
if (dataGridView1.Rows[e.RowIndex].Cells["IsAddBed"].Value.ToString().Trim() == "是")
{
chkIsAddBed.Checked = true;
}
else if (dataGridView1.Rows[e.RowIndex].Cells["IsAddBed"].Value.ToString().Trim() == "否")
{
chkIsAddBed.Checked = false;
}
txtRemark.Text = dataGridView1.SelectedCells[5].Value.ToString();
}
catch
{ }
this.toolStripButton4.Enabled = false;
this.toolStripButton2.Enabled = true;
}
/// <summary>
///保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toolStripButton4_Click(object sender, EventArgs e)
{
RoomTypeObject();
isEmpty();
bool flag;
flag = rtDB.InsertRoomType(rt);
if (flag)
{
MessageBox.Show("保存成功!", "保存", MessageBoxButtons.OK, MessageBoxIcon.None);
}
else
{
MessageBox.Show("保存失败!", "保存", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
Clear();
Lock();
SelectAll();
}
/// <summary>
/// 取消按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toolStripButton5_Click(object sender, EventArgs e)
{
Lock();
Clear();
}
/// <summary>
/// 退出按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toolStripButton6_Click(object sender, EventArgs e)
{
if (MessageBox.Show("是否真的要退出?", "友情提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
this.Close();
}
}
/// <summary>
/// 非空判断的方法
/// </summary>
/// <returns></returns>
public bool isEmpty()
{
try
{
if (txtTypeName.Text == "")
{
MessageBox.Show("类型名称不能为空!", "保存", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return false;
}
if (txtPrice.Text == "")
{
MessageBox.Show("价格不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return false;
}
if (txtAddBedPrice.Text == "")
{
MessageBox.Show("加床价格不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return false;
}
if (txtTypeName.Text == "")
{
MessageBox.Show("类型名称不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return false;
}
if (txtTypeName.Text == "")
{
MessageBox.Show("类型名称不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return false;
}
}
catch { };
return true;
}
/// <summary>
/// 锁定文本框的方法
/// </summary>
public void Lock()
{
this.txtTypeName.Enabled = false;
this.txtPrice.Enabled = false;
this.txtAddBedPrice.Enabled = false;
this.chkIsAddBed.Enabled = false;
this.txtRemark.Enabled = false;
}
/// <summary>
/// 解锁的方法
/// </summary>
public void UnLock()
{
this.txtTypeName.Enabled = true;
this.txtPrice.Enabled = true;
this.txtAddBedPrice.Enabled = true;
this.chkIsAddBed.Enabled = true;
this.txtRemark.Enabled = true;
}
/// <summary>
/// 清空文本框的方法
/// </summary>
public void Clear()
{
this.txtTypeName.Clear();
this.txtPrice.Clear();
this.txtAddBedPrice.Clear();
this.chkIsAddBed.Checked=false;
this.txtRemark.Clear();
}
/// <summary>
/// 客房类型对象的封装
/// </summary>
public void RoomTypeObject()
{
rt = new RoomType();
try
{
rt.TypeID = Convert.ToInt32(dataGridView1.SelectedCells[0].Value);
}
catch { }
rt.TypeName = txtTypeName.Text.Trim();
rt.TypePrice = Convert.ToDouble(txtPrice.Text.Trim());
rt.AddBedPrice = Convert.ToDouble(txtAddBedPrice.Text.Trim());
if (chkIsAddBed.Checked == true)
{
rt.IsAddBed = "是";
}
else if (chkIsAddBed.Checked == false)
{
rt.IsAddBed = "否";
}
rt.Remark = txtRemark.Text.Trim();
}
/// <summary>
/// 查找所有的方法
/// </summary>
public void SelectAll()
{
try
{
ds = rtDB.SelectRoomType();
}
catch
{
MessageBox.Show("查找失败");
}
//邦定数据源
this.dataGridView1.DataSource = ds.Tables[0];
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -