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