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

📄 mainform.cs

📁 工资结算系统 拥有权限控制 临时工资表 自动导入导出Excel 以及邮件群发功能
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
using System.Data.OracleClient; 
using HrSalary.employee;
//using HrSalary.dep;


namespace HrSalary
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	
	public class MainForm : System.Windows.Forms.Form
	{
	  
	  	private System.Windows.Forms.MainMenu mainMenu1;
		private System.Windows.Forms.MenuItem menuItem1;
		private System.Windows.Forms.MenuItem menuItem2;
		private System.Windows.Forms.MenuItem menuItem6;
		private System.Windows.Forms.MenuItem menuItem7;
		private System.Windows.Forms.MenuItem menuItem8;
		private System.Windows.Forms.MenuItem menuItem9;
		private System.Windows.Forms.MenuItem menuItem10;
		private System.Windows.Forms.MenuItem menuItem11;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.MenuItem menuItem13;
		private System.Windows.Forms.MenuItem menuItem16;
		private System.Windows.Forms.MenuItem menuItem17;
		private OracleConnection myConnection;

		private static OleDbConnection dbCon = null;


		public MainForm()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			
			InitializeComponent();
			
			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MainForm));
			this.mainMenu1 = new System.Windows.Forms.MainMenu();
			this.menuItem1 = new System.Windows.Forms.MenuItem();
			this.menuItem2 = new System.Windows.Forms.MenuItem();
			this.menuItem13 = new System.Windows.Forms.MenuItem();
			this.menuItem16 = new System.Windows.Forms.MenuItem();
			this.menuItem17 = new System.Windows.Forms.MenuItem();
			this.menuItem7 = new System.Windows.Forms.MenuItem();
			this.menuItem6 = new System.Windows.Forms.MenuItem();
			this.menuItem8 = new System.Windows.Forms.MenuItem();
			this.menuItem9 = new System.Windows.Forms.MenuItem();
			this.menuItem10 = new System.Windows.Forms.MenuItem();
			this.menuItem11 = new System.Windows.Forms.MenuItem();
			// 
			// mainMenu1
			// 
			this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.menuItem1,
																					  this.menuItem16,
																					  this.menuItem7,
																					  this.menuItem6});
			// 
			// menuItem1
			// 
			this.menuItem1.Index = 0;
			this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.menuItem2,
																					  this.menuItem13});
			this.menuItem1.Text = "员工信息管理";
			// 
			// menuItem2
			// 
			this.menuItem2.Index = 0;
			this.menuItem2.Text = "增加员工信息";
			this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
			// 
			// menuItem13
			// 
			this.menuItem13.Index = 1;
			this.menuItem13.Text = "员工信息查询";
			this.menuItem13.Click += new System.EventHandler(this.menuItem13_Click);
			// 
			// menuItem16
			// 
			this.menuItem16.Index = 1;
			this.menuItem16.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					   this.menuItem17});
			this.menuItem16.Text = "工资管理";
			// 
			// menuItem17
			// 
			this.menuItem17.Index = 0;
			this.menuItem17.Text = "工资管理";
			this.menuItem17.Click += new System.EventHandler(this.menuItem17_Click);
			// 
			// menuItem7
			// 
			this.menuItem7.Index = 2;
			this.menuItem7.MdiList = true;
			this.menuItem7.Text = "窗口列表";
			// 
			// menuItem6
			// 
			this.menuItem6.Index = 3;
			this.menuItem6.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.menuItem8,
																					  this.menuItem9,
																					  this.menuItem10,
																					  this.menuItem11});
			this.menuItem6.Text = "系统工具";
			// 
			// menuItem8
			// 
			this.menuItem8.Index = 0;
			this.menuItem8.Text = "用户管理";
			this.menuItem8.Click += new System.EventHandler(this.menuItem8_Click);
			// 
			// menuItem9
			// 
			this.menuItem9.Index = 1;
			this.menuItem9.Text = "修改密码";
			this.menuItem9.Click += new System.EventHandler(this.menuItem9_Click);
			// 
			// menuItem10
			// 
			this.menuItem10.Index = 2;
			this.menuItem10.Text = "重新登录";
			this.menuItem10.Click += new System.EventHandler(this.menuItem10_Click);
			// 
			// menuItem11
			// 
			this.menuItem11.Index = 3;
			this.menuItem11.Text = "退出系统";
			this.menuItem11.Click += new System.EventHandler(this.menuItem11_Click);
			// 
			// MainForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackColor = System.Drawing.Color.Gray;
			this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
			this.ClientSize = new System.Drawing.Size(672, 353);
			this.IsMdiContainer = true;
			this.MaximizeBox = false;
			this.Menu = this.mainMenu1;
			this.Name = "MainForm";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Hr工资管理系统";
			this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
			this.Closing += new System.ComponentModel.CancelEventHandler(this.MainForm_Closing);
			this.Load += new System.EventHandler(this.MainForm_Load);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]

		static void Main() 
		{ 
			Application.Run(new MainForm());//
			
		}
        //判断主窗体中是否 已经具有某个MdiChild
		public bool has(string formName)
		{
			bool result = false;
			for(int i=0;i<this.MdiChildren.Length;i++)
			{
				if (this.MdiChildren[i].Name == formName)
				{
					result = true;
					break;
				}
				else
				{
					result = false;
				}
			}
			return result;
		}
        //在主窗体中显示MdiChild
		public Form showModal(string formName)
		{
			for(int i=0;i<this.MdiChildren.Length;i++)
			{
				if (this.MdiChildren[i].Name == formName)
				{
					this.MdiChildren[i].Activate();
					return this.MdiChildren[i];;
				}
			}
			return null;
		}
        //主窗体Load的时候 设置所有主菜单项不可见
		private void MainForm_Load(object sender, System.EventArgs e)
		{
			try
			{
				int num=this.mainMenu1.MenuItems.Count;				
				this.mainMenu1.MenuItems[num-1].MenuItems[0].Visible=false;	
				for ( int i=0; i<num;i++)
				{
					this.mainMenu1.MenuItems[i].Visible=false;					
				};			
				login();				
			}
			catch(Exception ee)
			{
				MessageBox.Show(this.mainMenu1.MenuItems.Count+ee.ToString());
			}
		}

		//调用登录界面
		private void login()
		{
			HrSalary.user.login  login = new HrSalary.user.login();
			login.MdiParent=this;			
			login.Show();	
		}
		public Menu getMainMenu()
		{
			return this.mainMenu1;
		}
		//获得数据库连接
		public static OleDbConnection getConnection()
		{
			if(dbCon==null)
			{
				dbCon = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=HrSys.mdb"); //HrSalary
				dbCon.Open();
			}
			return dbCon;
		}
        //单击添加新员工菜单 打开添加新员工模块
		private void menuItem2_Click(object sender, System.EventArgs e)
		{
			if (this.has("StaffManager"))
			{
				showModal("StaffManager");
			}
			else
			{
				StaffManager p = new StaffManager();
				p.MdiParent = this;
				p.Show();
			}
		}
        //主窗体被关闭的时候,断开与数据库的连接
		private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			if(dbCon!=null)
			{
				dbCon.Close();
			}
		}
		//单击员工信息查询菜单 开打查询员工信息模块
		private void menuItem13_Click(object sender, System.EventArgs e)
		{
			if (this.has("StaffQuery"))
			{
				showModal("StaffQuery");
			}
			else
			{
				StaffQuery p = new StaffQuery();
				p.MdiParent = this;
				p.Show();
			}
		}

		//单击退出系统菜单 退出系统
		private void menuItem11_Click(object sender, System.EventArgs e)
		{
			 this.Close();
			 Application.Exit();
		}
        //单击用户管理菜单 将打开用户及用户权限管理模块
		private void menuItem8_Click(object sender, System.EventArgs e)
		{
		   user.PowerManager   pri_manager=new HrSalary.user.PowerManager();
				pri_manager.ShowDialog();
		}

	    //单击修改密码菜单 将打开修改密码窗体
		private void menuItem9_Click(object sender, System.EventArgs e)
		{
			a_user.ModifyPasswd  mp=new HrSalary.a_user.ModifyPasswd();
            mp.ShowDialog();
		}
        //单击重新登录菜单 将打开登录窗体
		private void menuItem10_Click(object sender, System.EventArgs e)
		{
			try
			{  
				login();			
			}
			catch(Exception ee)
			{
				MessageBox.Show(ee.ToString());
			}
		}
        //单击 工资管理菜单 将打开工资管理窗体
		private void menuItem17_Click(object sender, System.EventArgs e)
		{
		   HrSalary.salary.QueryEmployeeSalary   qes=new HrSalary.salary.QueryEmployeeSalary();
			qes.ShowDialog();
		}

		
	}
}

⌨️ 快捷键说明

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