📄 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 MyHouse
{
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.GetCompanyInformation();
//显示登录对话框
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)
{
退出系统ToolStripMenuItem_Click(null, null);
}
else
{
base.WndProc(ref SystemMessage);
}
break;
default:
base.WndProc(ref SystemMessage);
break;
}
}
//从公司信息数据表中读取基本信息
public void GetCompanyInformation()
{
//从app.config文件中读取数据库连接字符串信息
String MySQLConnectionString = global::MyHouse.Properties.Settings.Default.MyHouseConnectionString;
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::MyHouse.Properties.Settings.Default.MyHouseConnectionString;
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;
}
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)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -