MainFrm.cs
上传用户:ksd66jhda
上传日期:2013-04-03
资源大小:234k
文件大小:14k
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Data;
- namespace 进销存管理系统
- {
- /// <summary>
- /// Form1 的摘要说明。
- /// </summary>
- public class MainFrm : System.Windows.Forms.Form
- {
- private DataSet ds = new DataSet();
- private LinkDataBase link = new LinkDataBase();
- private string sendTableName = "权限清单";
- private string sendStrSQL;
- private System.Windows.Forms.MainMenu mainMenu1;
- private System.Windows.Forms.MenuItem menuItem1;
- private System.Windows.Forms.MenuItem menuItem2;
- private System.Windows.Forms.MenuItem menuItem3;
- private System.Windows.Forms.MenuItem menuItem4;
- private System.Windows.Forms.MenuItem menuItem5;
- private System.Windows.Forms.MenuItem mnu_WareDataManage;
- private System.Windows.Forms.MenuItem mnu_StokerDataManage;
- private System.Windows.Forms.MenuItem mnu_ClientDataManage;
- private System.Windows.Forms.MenuItem mnu_StockTable;
- private System.Windows.Forms.MenuItem mnu_StorageSearch;
- private System.Windows.Forms.MenuItem mnu_PopedomManage;
- private System.Windows.Forms.MenuItem mnu_SellTable;
- private System.Windows.Forms.StatusBar statusBar1;
- private System.Windows.Forms.StatusBarPanel statusBarPanel1;
- private System.Windows.Forms.StatusBarPanel statusBarPanel2;
- private System.Windows.Forms.MenuItem menuItemQuit;
- /// <summary>
- /// 必需的设计器变量。
- /// </summary>
- private System.ComponentModel.Container components = null;
- public MainFrm()
- {
- //
- // 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()
- {
- this.mainMenu1 = new System.Windows.Forms.MainMenu();
- this.menuItem1 = new System.Windows.Forms.MenuItem();
- this.mnu_WareDataManage = new System.Windows.Forms.MenuItem();
- this.mnu_StokerDataManage = new System.Windows.Forms.MenuItem();
- this.mnu_ClientDataManage = new System.Windows.Forms.MenuItem();
- this.menuItem2 = new System.Windows.Forms.MenuItem();
- this.mnu_StockTable = new System.Windows.Forms.MenuItem();
- this.menuItem3 = new System.Windows.Forms.MenuItem();
- this.mnu_SellTable = new System.Windows.Forms.MenuItem();
- this.menuItem4 = new System.Windows.Forms.MenuItem();
- this.mnu_StorageSearch = new System.Windows.Forms.MenuItem();
- this.menuItem5 = new System.Windows.Forms.MenuItem();
- this.mnu_PopedomManage = new System.Windows.Forms.MenuItem();
- this.menuItemQuit = new System.Windows.Forms.MenuItem();
- this.statusBar1 = new System.Windows.Forms.StatusBar();
- this.statusBarPanel1 = new System.Windows.Forms.StatusBarPanel();
- this.statusBarPanel2 = new System.Windows.Forms.StatusBarPanel();
- ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).BeginInit();
- this.SuspendLayout();
- //
- // mainMenu1
- //
- this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
- this.menuItem1,
- this.menuItem2,
- this.menuItem3,
- this.menuItem4,
- this.menuItem5,
- this.menuItemQuit});
- //
- // menuItem1
- //
- this.menuItem1.Index = 0;
- this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
- this.mnu_WareDataManage,
- this.mnu_StokerDataManage,
- this.mnu_ClientDataManage});
- this.menuItem1.Text = "资料管理";
- //
- // mnu_WareDataManage
- //
- this.mnu_WareDataManage.Enabled = false;
- this.mnu_WareDataManage.Index = 0;
- this.mnu_WareDataManage.Text = "商品信息维护";
- this.mnu_WareDataManage.Click += new System.EventHandler(this.mnu_WareDataManage_Click);
- //
- // mnu_StokerDataManage
- //
- this.mnu_StokerDataManage.Enabled = false;
- this.mnu_StokerDataManage.Index = 1;
- this.mnu_StokerDataManage.Text = "供货商信息维护";
- this.mnu_StokerDataManage.Click += new System.EventHandler(this.mnu_StokerDataManage_Click);
- //
- // mnu_ClientDataManage
- //
- this.mnu_ClientDataManage.Enabled = false;
- this.mnu_ClientDataManage.Index = 2;
- this.mnu_ClientDataManage.Text = "客户信息维护";
- this.mnu_ClientDataManage.Click += new System.EventHandler(this.mnu_ClientDataManage_Click);
- //
- // menuItem2
- //
- this.menuItem2.Index = 1;
- this.menuItem2.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
- this.mnu_StockTable});
- this.menuItem2.Text = "进货管理";
- //
- // mnu_StockTable
- //
- this.mnu_StockTable.Enabled = false;
- this.mnu_StockTable.Index = 0;
- this.mnu_StockTable.Text = "进货单";
- this.mnu_StockTable.Click += new System.EventHandler(this.mnu_StockTable_Click);
- //
- // menuItem3
- //
- this.menuItem3.Index = 2;
- this.menuItem3.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
- this.mnu_SellTable});
- this.menuItem3.Text = "销售管理";
- //
- // mnu_SellTable
- //
- this.mnu_SellTable.Enabled = false;
- this.mnu_SellTable.Index = 0;
- this.mnu_SellTable.Text = "销售单";
- this.mnu_SellTable.Click += new System.EventHandler(this.mnu_SellTable_Click);
- //
- // menuItem4
- //
- this.menuItem4.Index = 3;
- this.menuItem4.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
- this.mnu_StorageSearch});
- this.menuItem4.Text = "库存管理";
- //
- // mnu_StorageSearch
- //
- this.mnu_StorageSearch.Enabled = false;
- this.mnu_StorageSearch.Index = 0;
- this.mnu_StorageSearch.Text = "库存查询";
- this.mnu_StorageSearch.Click += new System.EventHandler(this.mnu_StorageSearch_Click);
- //
- // menuItem5
- //
- this.menuItem5.Index = 4;
- this.menuItem5.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
- this.mnu_PopedomManage});
- this.menuItem5.Text = "系统管理";
- //
- // mnu_PopedomManage
- //
- this.mnu_PopedomManage.Enabled = false;
- this.mnu_PopedomManage.Index = 0;
- this.mnu_PopedomManage.Text = "权限管理";
- this.mnu_PopedomManage.Click += new System.EventHandler(this.mnu_PopedomManage_Click);
- //
- // menuItemQuit
- //
- this.menuItemQuit.Index = 5;
- this.menuItemQuit.Text = "退出系统";
- this.menuItemQuit.Click += new System.EventHandler(this.menuItemQuit_Click);
- //
- // statusBar1
- //
- this.statusBar1.Location = new System.Drawing.Point(0, 551);
- this.statusBar1.Name = "statusBar1";
- this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
- this.statusBarPanel1,
- this.statusBarPanel2});
- this.statusBar1.ShowPanels = true;
- this.statusBar1.Size = new System.Drawing.Size(792, 22);
- this.statusBar1.TabIndex = 1;
- //
- // statusBarPanel1
- //
- this.statusBarPanel1.Alignment = System.Windows.Forms.HorizontalAlignment.Center;
- this.statusBarPanel1.MinWidth = 200;
- this.statusBarPanel1.Text = "《数据库开发经典案例解析》 清华大学出版社";
- this.statusBarPanel1.Width = 300;
- //
- // statusBarPanel2
- //
- this.statusBarPanel2.MinWidth = 200;
- this.statusBarPanel2.Width = 300;
- //
- // MainFrm
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
- this.ClientSize = new System.Drawing.Size(792, 573);
- this.Controls.Add(this.statusBar1);
- this.IsMdiContainer = true;
- this.Menu = this.mainMenu1;
- this.Name = "MainFrm";
- this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
- this.Text = "【进销存管理系统】";
- this.Load += new System.EventHandler(this.MainFrm_Load);
- ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).EndInit();
- this.ResumeLayout(false);
- }
- #endregion
- /// <summary>
- /// 应用程序的主入口点。
- /// </summary>
- [STAThread]
- static void Main()
- {
- //整个程序启动时先显示登录框,登录成功再显示主界面
- LoginFrm login = new LoginFrm();
- login.ShowDialog();
- if (LoginFrm.blCanLogin==true)
- {
- Application.Run(new MainFrm());
- }
- }
- //------------创建窗体时,通过登录用户的名称和权限,设置可以访问的功能--------------
- private void MainFrm_Load(object sender, System.EventArgs e)
- {
- this.statusBarPanel2.Text = " 当前用户: " + LoginFrm.strUser +" 所属部门: " + LoginFrm.strDepartment;
- //通过用户编号查询权限清单控制主窗体菜单使能状态
- this.sendStrSQL = "SELECT 权限名称 from 权限清单 where 用户编号 = '" + LoginFrm.strUser +"'";
- this.ds = this.link.SelectDataBase(sendStrSQL,sendTableName);
- //系统管理用户为特殊权限用户,他始终拥有所有权利
- if ( LoginFrm.strDepartment == "系统管理")
- {
- this.mnu_WareDataManage.Enabled = true;
- this.mnu_StokerDataManage.Enabled = true;
- this.mnu_ClientDataManage.Enabled = true;
- this.mnu_StockTable.Enabled = true;
- this.mnu_SellTable.Enabled = true;
- this.mnu_StorageSearch.Enabled = true;
- this.mnu_PopedomManage.Enabled = true;
- }
- else
- {
- //根据从数据库中检索到的用户的权限来设置其有权使用的菜单
- for (int intCounter=0;intCounter<this.ds.Tables[0].Rows.Count;intCounter++)
- {
- if (this.ds.Tables[0].Rows[intCounter][0].ToString().Trim() == "商品资料维护")
- {
- this.mnu_WareDataManage.Enabled = true; continue;
- }
- if (this.ds.Tables[0].Rows[intCounter][0].ToString().Trim() == "供货商资料维护")
- {
- this.mnu_StokerDataManage.Enabled = true; continue;
- }
- if (this.ds.Tables[0].Rows[intCounter][0].ToString().Trim() == "客户资料维护")
- {
- this.mnu_ClientDataManage.Enabled = true; continue;
- }
- if (this.ds.Tables[0].Rows[intCounter][0].ToString().Trim() == "进货单")
- {
- this.mnu_StockTable.Enabled = true; continue;
- }
- if (this.ds.Tables[0].Rows[intCounter][0].ToString().Trim() == "销售单")
- {
- this.mnu_SellTable.Enabled = true; continue;
- }
- if (this.ds.Tables[0].Rows[intCounter][0].ToString().Trim() == "库存查询")
- {
- this.mnu_StorageSearch.Enabled = true; continue;
- }
- if (this.ds.Tables[0].Rows[intCounter][0].ToString().Trim() == "权限管理")
- {
- this.mnu_PopedomManage.Enabled = true; continue;
- }
- }
- }
- }
- //-----------------查询一个子窗体是否存在----------------
- private bool checkChildFrmExist(string childFrmName)
- {
- foreach(Form childFrm in this.MdiChildren)
- {
- //用子窗体的Name进行判断,如果已经存在则将他激活
- if(childFrm.Name == childFrmName)
- {
- if(childFrm.WindowState == FormWindowState.Minimized)
- childFrm.WindowState = FormWindowState.Normal;
- childFrm.Activate();
- return true;
- }
- }
- return false;
- }
- //-----------显示商品信息维护窗口----------
- private void mnu_WareDataManage_Click(object sender, System.EventArgs e)
- {
- if (this.checkChildFrmExist("WareDataManage") == true)
- {
- return;
- }
- // 如果该窗体不存在则新生成一个商品信息维护窗体
- WareDataManage newFrm = new WareDataManage(true);
- newFrm.MdiParent = this;
- newFrm.Show();
- }
- //-----------显示供货商信息维护窗口----------
- private void mnu_StokerDataManage_Click(object sender, System.EventArgs e)
- {
- if (this.checkChildFrmExist("StokerDataManage") == true)
- {
- return;
- }
- // 如果该窗体不存在则新生成一个供货商信息维护维护窗体
- StokerDataManage newFrm = new StokerDataManage(true);
- newFrm.MdiParent = this;
- newFrm.Show();
- }
- //-----------显示客户信息维护窗口----------
- private void mnu_ClientDataManage_Click(object sender, System.EventArgs e)
- {
- if (this.checkChildFrmExist("ClientDataManage") == true)
- {
- return;
- }
- // 如果该窗体不存在则新生成一个客户信息维护窗体
- ClientDataManage newFrm = new ClientDataManage(true);
- newFrm.MdiParent = this;
- newFrm.Show();
- }
- //-----------显示进货单窗口----------
- private void mnu_StockTable_Click(object sender, System.EventArgs e)
- {
- if (this.checkChildFrmExist("StockTable") == true)
- {
- return;
- }
- // 如果该窗体不存在则新生成一个进货单窗体
- StockTable newFrm = new StockTable();
- newFrm.MdiParent = this;
- newFrm.Show();
-
- }
- //-----------显示销售单窗口----------
- private void mnu_SellTable_Click(object sender, System.EventArgs e)
- {
- if (this.checkChildFrmExist("SellTable") == true)
- {
- return;
- }
- // 如果该窗体不存在则新生成一个销售单窗体
- SellTable newFrm = new SellTable();
- newFrm.MdiParent = this;
- newFrm.Show();
-
- }
- //-----------显示库存查询窗口----------
- private void mnu_StorageSearch_Click(object sender, System.EventArgs e)
- {
- if (this.checkChildFrmExist("StorageSearch") == true)
- {
- return;
- }
- // 如果该窗体不存在则新生成一个库存查询窗体
- StorageSearch newFrm = new StorageSearch();
- newFrm.MdiParent = this;
- newFrm.Show();
-
- }
- //-----------显示权限管理窗口----------
- private void mnu_PopedomManage_Click(object sender, System.EventArgs e)
- {
- if (this.checkChildFrmExist("PopedomManage") == true)
- {
- return;
- }
- // 如果该窗体不存在则新生成一个权限管理窗体
- PopedomManage newFrm = new PopedomManage();
- newFrm.MdiParent = this;
- newFrm.Show();
- }
-
-
- //-----------退出窗体,先询问用户是否退出-------------
- private void menuItemQuit_Click(object sender, System.EventArgs e)
- {
- if (MessageBox.Show("确实要退出系统吗?","询问",MessageBoxButtons.YesNo) == DialogResult.Yes)
- {
- this.Close();
- }
- }
- }
- }