[Abstract] in succession this year wrote the fixed assets and low-value consumable goods, procurement mold management and will be carried out in the process management subsystem, are each to write a small program, each time to build the environment. Every time a small system is deployed, it has to be packaged once. Simply make a simple framework to achieve it.
Rights Management is modeled after its own collaborative work platform.
Table I: Menu management
CREATE TABLE [dbo]. [Winform_menuinfo] ([ID] [int] IDENTITY (max) not null,[name] [nvarchar] (+) not Null,[parentid] [int.] not null,[formname] [nvarchar] (+) NU LL,[TYPE] [int] null,[sortindex] [int] NULL, CONSTRAINT [Pk_winform_menuinfo] PRIMARY KEY CLUSTERED ([ID] ASC) with (pad_in DEX = off, statistics_norecompute = off, Ignore_dup_key = off, allow_row_locks = on, allow_page_locks = On [PRIMARY]) on [Primary]goalter TABLE [dbo]. [Winform_menuinfo] ADD CONSTRAINT [Df_winform_menuinfo_parentid] DEFAULT (( -1)) for [Parentid]goalter TABLE [dbo].[ Winform_menuinfo] ADD CONSTRAINT [Df_winform_menuinfo_type] DEFAULT ((0)) for [Type]goalter TABLE [dbo].[ Winform_menuinfo] ADD CONSTRAINT [Df_winform_menuinfo_sortindex] DEFAULT ((0)) for [Sortindex]go
Table II: Role Management
CREATE TABLE [dbo]. [Winform_roleinfo] ([ID] [int] IDENTITY (max) not null,[name] [nvarchar] (+) not null,[descript] [nvarchar] (+) null,[parentid] [int] not NU LL, CONSTRAINT [Pk_winform_roleinfo] PRIMARY KEY CLUSTERED ([ID] ASC) with (pad_index = OFF, statistics_norecompute< c1/>= off, Ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [PRIMARY]) on [Primary]go
Table Three: Role menu
CREATE TABLE [dbo]. [Winform_rolemenu] ([ID] [int] IDENTITY () not Null,[rid] [int.] NOT NULL,[MID] [int.] Not NULL, CONSTRAINT [Pk_winform_rolemenu] PRIMARY KEY CLUSTERED ([id] ASC) with (pad_index = off, statistics_norecompute = off, Ignore_dup_key = off, allow_row_locks
= on, allow_page_locks = on) on [PRIMARY]) on [Primary]go
Menu Management:
Role Authorization:
User Role Management
Here's the point:
How does WinForm load?
Simple layout:
Top title
On the left is a tree-shaped menu
On the right is tabcontorl.
Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.data.sqlclient;using system.drawing;using system.linq;using system.text;using System.Windows.Forms;using Erpsystem.dbutility;namespace erpsystem{public partial class Frmmain:form {public int userid; Public frmmain (int userid) {InitializeComponent (); This.userid = userid; private void Frmmain_load (object sender, EventArgs e) {this. Icon = Icon.fromhandle (new Bitmap (Imagelist1.images[2]). Gethicon ()); Empties the control//this. MainTabControl.TabPages.Clear (); The way ownerdrawfixed is drawn is represented by the form drawing size as well as this. Maintabcontrol.drawmode = tabdrawmode.ownerdrawfixed; This. maintabcontrol.padding = new System.Drawing.Point (close_size, close_size); This. Maintabcontrol.drawitem + = new Drawitemeventhandler (this. Maintabcontrol_drawitem); This. Maintabcontrol.MouseDown + = new System.Windows.Forms.MouseEventHandler (this. Maintabcontrol_mousedown); Bindtree (); This.trvMeun.ExpandAll (); } const int close_size = 10; TabPage label image Bitmap image = Global::erpsystem.properties.resources.close; Draw "X" or Close button private void Maintabcontrol_drawitem (object sender, DrawItemEventArgs e) {try {Rectangle Mytabrect = this. Maintabcontrol.gettabrect (E.index); First add the TabPage property e.graphics.drawstring (this. Maintabcontrol.tabpages[e.index]. Text, this. Font, Systembrushes.controltext, Mytabrect.x + 2, Mytabrect.y + 2); Draw another rectangle using the (Pen p = new Pen (color.white)) {Mytabrect.offset (mytabre Ct. Width-(close_size + 3), 2); Mytabrect.width = close_size; Mytabrect.height = close_size; E.graphics.drawrectangle (P, mYtabrect); }//Fill rectangle box Color reccolor = E.state = = drawitemstate.selected? Color.White:Color.White; using (Brush B = new SolidBrush (Reccolor)) {E.graphics.fillrectangle (b, Mytabrect); }//Draw close symbol using (Pen Objpen = new Pen (color.black)) { =============================================//painting x////"\" line Point P1 = new Point (Mytabrect.x + 3, Mytabrect.y + 3); Point P2 = new Point (Mytabrect.x + mytabrect.width-3, Mytabrect.y + mytabrect.height-3); E.graphics.drawline (Objpen, p1, p2); "/" line//point p3 = new Point (Mytabrect.x + 3, Mytabrect.y + mytabrect.height-3); Point P4 = new Point (Mytabrect.x + mytabrect.width-3, Mytabrect.y + 3); E.graphics.drawline (Objpen, P3, p4); =============================================//Use picture Bitmap BT = new Bitmap (imag e); Point P5 = new Point (Mytabrect.x, 4); E.graphics.drawimage (BT, p5); E.graphics.drawstring (this. Maintabcontrol.tabpages[e.index]. Text, this. Font, Objpen. Brush, p5); } e.graphics.dispose (); } catch (Exception) {}}//Close button function private void Maintabcontrol_mousedown (object sender, MouseEventArgs e) {if (E.button = = mousebuttons.left) {int x = e.x, y = e.y; Calculates the closed area Rectangle Mytabrect = this. Maintabcontrol.gettabrect (this. Maintabcontrol.selectedindex); Mytabrect.offset (Mytabrect.width-(close_size + 3), 2); Mytabrect.width = close_size; MytabreCt. Height = close_size; If the mouse is within the area, close the tab BOOL Isclose = x > Mytabrect.x && x < mytabrect.right && y > M Ytabrect.y && Y < Mytabrect.bottom; if (Isclose = = True) {this. MainTabControl.TabPages.Remove (this. Maintabcontrol.selectedtab); }}}///<summary>//Initialize tree menu///</summary> private void Bind Tree () {//Custom menu table, can be read from XML or database/* DataTable Tbldatas = new DataTable ("Datas"); TBLDATAS.COLUMNS.ADD ("ID", Type.GetType ("System.Int32")); TBLDATAS.COLUMNS.ADD ("Title", Type.GetType ("System.String")); TBLDATAS.COLUMNS.ADD ("Name", Type.GetType ("System.String")); TBLDATAS.COLUMNS.ADD ("ParentID", Type.GetType ("System.Int32")); TBLDATAS.ROWS.ADD (New object[] {1, "System administration", "", 0}); TBLDATAS.ROWS.ADD (New object[] {2, "electronic process Management", "", 0}); TBLDATAS.ROWS.ADD (New object[] {3, "menu Management", "Form1", 1}); TBLDATAS.ROWS.ADD (New object[] {4, "role Management", "Form2", 1}); TBLDATAS.ROWS.ADD (New object[] {5, "User Authorization", "Form2", 1}); */String Strrid = "Select Wf_roleid from Users where id=" + userid; string rid = string. Empty; using (SqlDataReader dr = Sqlhelper.executereader (Sqlhelper.conn, CommandType.Text, Strrid)) {i F (Dr. Read ()) {rid = dr["Wf_roleid"]. ToString (); }} String strSQL = "SELECT * FROM dbo. Winform_menuinfo where ID in (select distinct mid from Winform_rolemenu where RIDs in ("+ RIDs +")) Order by SortIndex ASC " ; DataTable Tbldatas = SqlHelper.ExecuteDataset (Sqlhelper.conn, CommandType.Text, strSQL). Tables[0]; Initparent (Tbldatas); }//Initialize root node private void Initparent (DaTatable DT) {datarow[] drs = dt. Select ("Parentid=-1"); foreach (DataRow Dr in Drs) {TreeNode tn = new TreeNode (); Tn. Text = dr["NAME"]. ToString (); Tn. ToolTipText = dr["FORMNAME"]. ToString (); Tn. Tag = dr["ID"]. ToString (); Tn. ImageIndex = 1; This.trvMeun.Nodes.Add (TN); Initialize the subordinate node initleaf (DT, TN); }}//Initialize subordinate node private void Initleaf (DataTable dt, TreeNode TN) {datarow[] drs = DT . Select ("parentid=" + tn. Tag as String); foreach (DataRow Dr in Drs) {TreeNode ctn = new TreeNode (); Ctn. Text = dr["NAME"]. ToString (); Ctn. ToolTipText = dr["FORMNAME"]. ToString (); Ctn. Tag = dr["ID"]. ToString (); Tn. ImageIndex = 1; Tn. Nodes.Add (CTN); Recursive invocation, continuously looping to leaf nodes Initleaf (DT, CTN); }}//Double-click to close tab private void Maintabcontrol_doubleclick (object sender, EventArgs e) { Point pt = new Point (e.x, e.y); if (Maintabcontrol.tabcount > 0) {if (Maintabcontrol.tabcount > 0) { This. MainTabControl.TabPages.Remove (Maintabcontrol.selectedtab); }}}///<summary>//double-click the node to open the form///</summary>//<param NA Me= "Sender" ></param>//<param name= "E" ></param> private void Trvmeun_nodemousedoublec Lick (object sender, TreeNodeMouseClickEventArgs e) {TreeNode node = E.node; if (trvMeun.SelectedNode.Parent = = null) {} else {if (! Findtabcontrol (node. Text.trim ())) {Erpsystem.moduleclass myfrm = new Moduleclass (); if (myfrm. Show_form (node. Text.trim (), node. Tooltiptext.tostring (). Trim ()) = null) {this. MAINTABCONTROL.TABPAGES.ADD (myfrm. Show_form (node. Text.trim (), node. Tooltiptext.tostring (). Trim ())); This. Maintabcontrol.selectedindex = this. maintabcontrol.tabpages.count-1; } else {//MessageBox.Show ("Still under construction ...!!", "ERROR"); }}}}///<summary>///whether a tab with the same name exists in the Query tab collection///</ summary> private bool Findtabcontrol (string tabname) {BOOL flag = false; foreach (TabPage item in maintabcontrol.tabpages) {if (item. Text = = tabname) {flag = true; }} return flag; } }}
ModuleClass.cs
Using system;using system.collections.generic;using system.linq;using system.text;using System.Windows.Forms;using System.reflection;using System.runtime.remoting;namespace erpsystem{class Moduleclass {public TabPage Show_ Form (String formtitle,string FormName) {string strnamespace = "Erpsystem"; if (FormName = "") {ObjectHandle obj = Activator.CreateInstance (null, strNameSpace + "." + for Mname); Obj. Unwrap returns the wrapped object Form frm = (form) obj. Unwrap (); Return Initfrom (frm, formtitle); } else {return null; }/* Switch (formtitle) {Case "menu Management": String FormName = "Form1"; Case "Database disk usage": Erpsystem.form1 frm2 = new Erpsystem.form1 (); Return Initfrom (Frm2, formtitle); Case "IO condition": Erpsystem.form1 frm3 = new Erpsystem.form1 (); Return Initfrom (FRM3, formtitle); Case "Job status": Erpsystem.form1 FRM4 = new Erpsystem.form1 (); Return Initfrom (FRM4, formtitle); Case "Memory Usage": erpsystem.form1 FRM5 = new Erpsystem.form1 (); Return Initfrom (FRM5, formtitle); Default:return null; }/////<summary>///form dynamically loaded into the page///</summary>//<param Name= "frm" ></param>//<param name= "name" ></param>//<returns></returns> Private TabPage Initfrom (Form frm, String Name) {if (!string. IsNullOrEmpty (Name)) {frm. Text = Name; frm. TopLevel = false; TabPage TP = new TabPage (Name); frm. FormbordersTyle = Formborderstyle.none; Tp. Controls.Add (frm); frm. Dock = DockStyle.Fill; frm. Show (); return TP; } else {return null; } } }}
Test: