📄 mainform.cs
字号:
//文件名:MainForm.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace MyHotel
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private string MyBgPhoto ;
private string MyAddress ;
private string MyTel ;
private string MyCode;
private string MyWeb ;
private string MySlogan;
private string MyBgPhotoShow;
private string MyOperator;
private string MyCompany;
private void MainForm_Load(object sender, EventArgs e)
{
//添加ThreadException事件关联程序
Application.ThreadException += MyThreadException;
//从酒店信息数据表中读取基本信息
this.GetHotelInformation();
//显示登录对话框
LoginForm MyDlg = new LoginForm();
MyDlg.Text = "欢迎使用"+MySlogan;
MyDlg.ShowDialog(this);
this.MyOperator = MyDlg.用户名称TextBox.Text;
//根据用户的操作权限配置系统菜单
SetUserOperateMenu();
//最大化显示系统主窗体
if (MyOperator.Length > 0)
{
this.WindowState = FormWindowState.Maximized;
}
//设置系统背景图像信息
this.BackgroundImage = new Bitmap(this.MyBgPhotoShow, true);
//设置系统标题栏显示文字
this.Text = MySlogan ;
}
//系统异常处理代码
public void MyThreadException(Object sender, System.Threading.ThreadExceptionEventArgs e)
{
string MyInfo = "错误名称:" + e.Exception.Source + ",错误信息:" + e.Exception.Message;
MessageBox.Show(MyInfo, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
//实现在系统关闭前给予用户提示
protected override void WndProc(ref Message SystemMessage)
{
switch (SystemMessage.Msg)
{
case 0x0112:
if (((int)SystemMessage.WParam) ==61536)
{
退出系统EToolStripMenuItem_Click(null, null);
}
else
{
base.WndProc(ref SystemMessage);
}
break;
default:
base.WndProc(ref SystemMessage);
break;
}
}
//从酒店信息数据表中读取基本信息
public void GetHotelInformation()
{
//从app.config文件中读取数据库连接字符串信息
String MySQLConnectionString = global::MyHotel.Properties.Settings.Default.MyHotelConnectionString;
string MySQL = "Select * From 酒店信息 Where 显示优先级=1";
SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
MyConnection.Open();
DataTable MyTable = new DataTable();
SqlDataAdapter MyAdapter = new SqlDataAdapter(MySQL, MyConnection);
MyAdapter.Fill(MyTable);
MyBgPhoto = Application.StartupPath + "\\Data\\" + (String)MyTable.Rows[0]["管理系统背景照片"];
MyAddress = (String)MyTable.Rows[0]["酒店地址"];
MyTel = (String)MyTable.Rows[0]["服务电话"];
MyCode = (String)MyTable.Rows[0]["邮政编码"];
MyWeb = (String)MyTable.Rows[0]["酒店网站"];
MySlogan = (String)MyTable.Rows[0]["管理系统显示名称"];
MyCompany = (String)MyTable.Rows[0]["酒店名称"];
if (MyConnection.State == ConnectionState.Open)
{
MyConnection.Close();
}
MyBgPhotoShow = Application.StartupPath + "\\Data\\Show" + (String)MyTable.Rows[0]["管理系统背景照片"];
}
//根据用户的操作权限配置系统菜单
public void SetUserOperateMenu()
{
String MySQLConnectionString = global::MyHotel.Properties.Settings.Default.MyHotelConnectionString;
string MySQL = "Select * From 操作用户 Where 用户名称='"+this.MyOperator+"'";
SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
MyConnection.Open();
DataTable MyTable = new DataTable();
SqlDataAdapter MyAdapter = new SqlDataAdapter(MySQL, MyConnection);
MyAdapter.Fill(MyTable);
if ((int)MyTable.Rows[0]["客房管理之入住登记"] == 0)
{
this.入住登记ToolStripMenuItem.Visible = false;
this.入住登记ToolStripSeparator.Visible = false;
this.入住登记ToolStripButton.Visible = false;
}
if ((int)MyTable.Rows[0]["客房管理之换房登记"] == 0)
{
this.换房登记ToolStripMenuItem.Visible = false;
this.换房登记ToolStripSeparator.Visible = false;
this.换房登记ToolStripButton.Visible = false;
}
if ((int)MyTable.Rows[0]["客房管理之退房登记"] == 0)
{
this.退房登记ToolStripMenuItem.Visible = false;
this.退房登记ToolStripSeparator.Visible = false;
this.结帐登记ToolStripButton.Visible = false;
}
if ((int)MyTable.Rows[0]["客房管理之预订房间"] == 0)
{
this.预订房间ToolStripMenuItem.Visible = false;
this.预订房间ToolStripSeparator.Visible = false;
this.预订登记ToolStripButton.Visible = false;
}
if ((int)MyTable.Rows[0]["客房管理之预订入住"] == 0)
{
this.预订入住ToolStripMenuItem.Visible = false;
this.预订入住ToolStripSeparator.Visible = false;
this.预订入住ToolStripButton.Visible = false;
}
if ((int)MyTable.Rows[0]["客房管理之补交押金"] == 0)
{
this.补交押金ToolStripMenuItem.Visible = false;
this.补交押金ToolStripSeparator.Visible = false;
this.补交押金ToolStripButton.Visible = false;
}
if ((int)MyTable.Rows[0]["客房管理之补打帐单"] == 0)
{
this.补打帐单ToolStripMenuItem.Visible = false;
this.补交押金ToolStripSeparator.Visible = false;
this.打印帐单ToolStripButton.Visible = false;
}
if ((int)MyTable.Rows[0]["费用管理之餐费入帐"] == 0)
{
this.餐费入帐ToolStripMenuItem.Visible = false;
this.餐费入帐ToolStripSeparator.Visible = false;
this.餐费登记ToolStripButton.Visible = false;
}
if ((int)MyTable.Rows[0]["费用管理之话费入帐"] == 0)
{
this.话费入帐ToolStripMenuItem.Visible = false;
this.话费入帐ToolStripSeparator.Visible = false;
this.话费登记ToolStripButton.Visible = false;
}
if ((int)MyTable.Rows[0]["费用管理之消费入帐"] == 0)
{
this.消费入帐ToolStripMenuItem.Visible = false;
this.话费入帐ToolStripSeparator.Visible = false;
this.消费登记ToolStripButton.Visible = false;
}
if ((int)MyTable.Rows[0]["查询管理之入住旅客信息"] == 0)
{
this.入住旅客信息ToolStripMenuItem.Visible = false;
this.入住旅客信息ToolStripSeparator.Visible = false;
this.旅客信息ToolStripButton.Visible = false;
}
if ((int)MyTable.Rows[0]["查询管理之客房入住状态"] == 0)
{
this.客房入住状态ToolStripMenuItem.Visible = false;
this.客房入住状态ToolStripSeparator.Visible = false;
this.客房信息ToolStripButton.Visible = false;
}
if ((int)MyTable.Rows[0]["查询管理之物品消耗信息"] == 0)
{
this.物品消耗信息ToolStripMenuItem.Visible = false;
this.物品消耗信息ToolStripSeparator.Visible = false;
this.消耗信息ToolStripButton.Visible = false;
}
if ((int)MyTable.Rows[0]["查询管理之物品消耗汇总"] == 0)
{
this.物品消耗汇总ToolStripMenuItem.Visible = false;
this.物品消耗汇总ToolStripSeparator.Visible = false;
this.消耗汇总ToolStripButton.Visible = false;
}
if ((int)MyTable.Rows[0]["查询管理之押金消费信息"] == 0)
{
this.押金消费信息ToolStripMenuItem.Visible = false;
this.物品消耗汇总ToolStripSeparator.Visible = false;
this.押金信息ToolStripButton.Visible = false;
}
if ((int)MyTable.Rows[0]["报表管理之客房入住报表"] == 0)
{
this.客房入住报表ToolStripMenuItem.Visible = false;
this.客房入住报表ToolStripSeparator.Visible = false;
this.入住报表ToolStripButton.Visible = false;
}
if ((int)MyTable.Rows[0]["报表管理之客房餐费报表"] == 0)
{
this.客房餐费报表ToolStripMenuItem.Visible = false;
this.客房餐费报表ToolStripSeparator.Visible = false;
this.餐费报表ToolStripButton.Visible = false;
}
if ((int)MyTable.Rows[0]["报表管理之客房消费报表"] == 0)
{
this.客房消费报表ToolStripMenuItem.Visible = false;
this.客房消费报表ToolStripSeparator.Visible = false;
this.消费报表ToolStripButton.Visible = false;
}
if ((int)MyTable.Rows[0]["报表管理之客房话费报表"] == 0)
{
this.客房话费报表ToolStripMenuItem.Visible = false;
this.客房话费报表ToolStripSeparator.Visible = false;
this.话费报表ToolStripButton.Visible = false;
}
if ((int)MyTable.Rows[0]["报表管理之客房结帐汇总表"] == 0)
{
this.客房结帐汇总表ToolStripMenuItem.Visible = false;
this.客房话费报表ToolStripSeparator.Visible = false;
this.结帐报表ToolStripButton.Visible = false;
}
if ((int)MyTable.Rows[0]["系统管理之操作权限设置"] == 0)
{
this.操作权限设置ToolStripMenuItem.Visible = false;
this.操作权限设置ToolStripSeparator.Visible = false;
}
if ((int)MyTable.Rows[0]["系统管理之修改用户密码"] == 0)
{
this.修改用户密码ToolStripMenuItem.Visible = false;
this.修改用户密码ToolStripSeparator.Visible = false;
}
if ((int)MyTable.Rows[0]["系统管理之酒店信息设置"] == 0)
{
this.酒店信息设置ToolStripMenuItem.Visible = false;
this.酒店信息设置ToolStripSeparator.Visible = false;
}
if ((int)MyTable.Rows[0]["系统管理之酒店客房设置"] == 0)
{
this.酒店客房设置ToolStripMenuItem.Visible = false;
this.酒店客房设置ToolStripSeparator.Visible = false;
}
if ((int)MyTable.Rows[0]["系统管理之消费物品设置"] == 0)
{
this.消费物品设置ToolStripMenuItem.Visible = false;
this.消费物品设置ToolStripSeparator.Visible = false;
}
if (MyConnection.State == ConnectionState.Open)
{
MyConnection.Close();
}
}
private void 退出系统EToolStripMenuItem_Click(object sender, EventArgs e)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -