⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myhotelroomtypeform.cs

📁 酒店管理系统项目内容 包含当前常用的全部功能
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MyHotelModel;
using MyHotelIBLL;
using MyHotelBLL;
using MyHotelBLLFactory;

namespace MyHotel
{
    public partial class MyHotelRoomTypeForm : Form
    {   
        #region 定义变量

        IRoomTypeManager roomTypeManager;
        IRoomTypeCommandManager cmdManager;
        BindingManagerBase manager;
        IList<RoomType> types;

        bool searchFlag = false;

        #endregion

        #region 系统事件

        public MyHotelRoomTypeForm()
        {
            InitializeComponent();
            types = new List<RoomType>();
        }

        /// <summary>
        /// 界面加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MyHotelRoomTypeForm_Load(object sender, EventArgs e)
        {
            if (this.txtTypeName.Text == "")
            {
                this.tsBtnModify.Enabled = false;
            }
            roomTypeManager = ManagerFactory.CreateRoomTypeManager();

            cmdManager = ManagerFactory.CreateRoomTypeCommandManager();

            types = roomTypeManager.FindAllRoomTypes();

            ShowGridView(types);

            this.dgvRoomType.AutoGenerateColumns = false;

            searchFlag = false;
        }

        /// <summary>
        /// 数据查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSearch_Click(object sender, EventArgs e)
        {
            roomTypeManager = ManagerFactory.CreateRoomTypeManager();

            types = roomTypeManager.FindRoomTypeByName(this.txtTypeNameSearch.Text.Trim());
            if (types.Count == 0)
            {
                this.epNoData.SetError(this.txtTypeNameSearch, "没有数据!");
                this.dgvRoomType.DataSource = null;
            }
            else
            {
                ShowGridView(types);
                this.epNoData.Clear();
            }
            searchFlag = true;
        }

        /// <summary>
        /// 添加数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsBtnAdd_Click(object sender, EventArgs e)
        {
            this.txtTypeName.Focus();

            if (this.txtTypeName.Text != "")
            {
                roomTypeManager = ManagerFactory.CreateRoomTypeManager();

               IList<RoomType> typeSearch = roomTypeManager.FindRoomTypeByName(this.txtTypeName.Text.Trim());

                if (typeSearch.Count == 0)
                {
                    RoomType type = new RoomType();

                    type.TypeName = this.txtTypeName.Text.Trim();
                    type.TypePrice = Convert.ToDecimal(this.txtTypePrice.Text.Trim());
                    type.AddBedPrice = Convert.ToDecimal(this.txtAddBedPrice.Text.Trim());
                    if (this.rdoBtnYes.Checked)
                    {
                        type.IsAddBed = "是";
                    }
                    else
                    {
                        type.IsAddBed = "否";
                    }
                    type.Remark = this.txtRemark.Text.Trim();

                    types.Add(type);

                    this.dgvRoomType.DataSource = null;

                    this.dgvRoomType.DataSource = types;

                    cmdManager.CreateAddRoomTypeCommand(type);

                    ClearText();
                }
                else 
                {
                    this.epHaveData.SetError(this.txtTypeName, "数据已存在!");
                }
            }
        }

        /// <summary>
        /// 修改数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsBtnModify_Click(object sender, EventArgs e)
        {
            this.epHaveData.Clear();

            RoomType type = this.dgvRoomType.Rows[this.dgvRoomType.SelectedCells[0].RowIndex].DataBoundItem as RoomType;

            type.TypeName = this.txtTypeName.Text.Trim();
            type.TypePrice = Convert.ToDecimal(this.txtTypePrice.Text.Trim());
            type.AddBedPrice = Convert.ToDecimal(this.txtAddBedPrice.Text.Trim());
            if (this.rdoBtnYes.Checked)
            {
                type.IsAddBed = "是";
            }
            else
            {
                type.IsAddBed = "否";
            }
            type.Remark = this.txtRemark.Text.Trim();

            this.dgvRoomType.DataSource = null;

            this.dgvRoomType.DataSource = types;

            cmdManager.CreateUpdateRoomTypeCommand(type);
        }

        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsBtnDelete_Click(object sender, EventArgs e)
        {
            this.epHaveData.Clear();

            RoomType type = this.dgvRoomType.Rows[this.dgvRoomType.SelectedCells[0].RowIndex].DataBoundItem as RoomType;

            types.Remove(type);

            if (types.Count <= 0)
            {
                this.tsBtnDelete.Enabled = false;
                this.tsBtnModify.Enabled = false;
            }

            this.dgvRoomType.DataSource = null;

            this.dgvRoomType.DataSource = types;

            cmdManager.CreateDeleteRoomTypeCommand(type.TypeId);

            ClearText();

        }

        /// <summary>
        /// 取消所有操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsBtnCancel_Click(object sender, EventArgs e)
        {
            cmdManager.Cancel();
            this.epHaveData.Clear();

            this.dgvRoomType.DataSource = null;

            if (searchFlag)
                btnSearch_Click(sender, e);
            else
                MyHotelRoomTypeForm_Load(sender, e);

            this.tsBtnDelete.Enabled = true;
            this.tsBtnModify.Enabled = true;

            ClearText();

        }

        /// <summary>
        /// 保存数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsBtnSave_Click(object sender, EventArgs e)
        {
            cmdManager.SaveAll();

            this.epHaveData.Clear();
            this.dgvRoomType.DataSource = null;

            if (searchFlag)
                btnSearch_Click(sender, e);
            else
                MyHotelRoomTypeForm_Load(sender, e);

            ClearText();

        }

        /// <summary>
        /// 选中一行数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvRoomMyHotelAdmin_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            this.tsBtnModify.Enabled = true;
            this.epHaveData.Clear();

            if (manager.Count <= 0) return;

            RoomType roomType = manager.Current as RoomType;

            this.txtTypeName.Text = roomType.TypeName.ToString();
            this.txtTypePrice.Text = roomType.TypePrice.ToString();
            this.txtAddBedPrice.Text = roomType.AddBedPrice.ToString();

            if (roomType.IsAddBed.ToString().Trim() == "是")
                this.rdoBtnYes.Checked = true;
            else
                this.rdoBtnNo.Checked = true;

            this.txtRemark.Text = roomType.Remark.ToString();
        }

        /// <summary>
        /// 退出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsBtnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txtTypeName_TextChanged(object sender, EventArgs e)
        {
            this.epHaveData.Clear();
        }

        #endregion

        #region 自定义方法

        /// <summary>
        /// 数据显示
        /// </summary>
        /// <param name="list"></param>
        public void ShowGridView(IList<RoomType> list)
        {
            this.dgvRoomType.DataSource = list;
            manager = this.dgvRoomType.BindingContext[this.dgvRoomType.DataSource];
            manager.PositionChanged += new EventHandler(manager_CurrentChanged);
            if (manager.Count > 0)
            {
                manager.Position = -1;
                manager.Position = 0;
            }
        }

        /// <summary>
        /// manager_CurrentChanged
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void manager_CurrentChanged(object sender, EventArgs e)
        {
            this.tsBtnModify.Enabled = true;

            RoomType roomType = manager.Current as RoomType;

            this.txtTypeName.Text = roomType.TypeName.ToString();
            this.txtTypePrice.Text = roomType.TypePrice.ToString();
            this.txtAddBedPrice.Text = roomType.AddBedPrice.ToString();

            if (roomType.IsAddBed.ToString().Trim() == "是")
                this.rdoBtnYes.Checked = true;
            else
                this.rdoBtnNo.Checked = true ;

            this.txtRemark.Text = roomType.Remark.ToString();

        }

        /// <summary>
        /// 清空文本
        /// </summary>
        private void ClearText()
        {
            this.txtTypeName.Text = "";
            this.txtTypePrice.Text = "";
            this.txtAddBedPrice.Text = "";
            this.txtRemark.Text = "";
        }

        #endregion
        
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -