www.pudn.com > WorkflowDesigner.rar > MainForm.cs, change:2007-11-28,size:23451b


using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Text; 
using System.Windows.Forms; 
using WorkflowDesigner.Designer; 
namespace WorkflowDesigner 
{ 
    public partial class MainForm : Form 
    { 
        public MainForm() 
        { 
             
 
            InitializeComponent(); 
             
            _menu = new MainMenuBar(this.toolStripToolView, this.MITool); 
        } 
 
 
        private void MainForm_Load(object sender, EventArgs e) 
        { 
            
 
            Program.WorkflowControl.WfPackageChanged += new WorkflowControl.WorkflowChangedEventHandler(OnWorkflowChanged); 
            Program.WorkflowControl.NewWorkflow(); 
 
            packageTree.TreeItemRClick += new WfPackageTree.TreeItemRClickEventHandler(OnPackageTreeContextMenu); 
            packageTree.TreeItemClick += new WfPackageTree.TreeItemClickEventHandler(OnPackageTreeClick); 
 
   
        } 
 
        /// <summary> 
        /// 业务换事件 
        /// </summary> 
        /// <param name="sender">参数</param> 
        /// <param name="e">参数</param> 
        private void OnWorkflowChanged(object sender, WfPackageChangedEventArg e) 
        { 
            if (e.type == WfPackageChangedType.Reset) 
            { 
                packageTree.InitContent(e.package); 
            } 
            else if (e.type == WfPackageChangedType.AddFlow) 
            { 
                packageTree.AddFlow((e.changeObject as WfFlowDocument).Name); 
            } 
            else if (e.type == WfPackageChangedType.AddRole) 
            { 
                packageTree.AddRole((e.changeObject as WfRole).Name); 
            } 
            else if (e.type == WfPackageChangedType.AddApplication) 
            { 
                packageTree.AddApplication((e.changeObject as WfApplication).Name); 
            } 
            else if (e.type == WfPackageChangedType.RoleNameChange) 
            { 
                packageTree.RenameRole(e.oldObject.ToString(), (e.changeObject as WfRole).Name); 
            } 
            else if (e.type == WfPackageChangedType.AppNameChange) 
            { 
                packageTree.RenameApp(e.oldObject.ToString(), (e.changeObject as WfApplication).Name); 
            } 
            else if (e.type == WfPackageChangedType.FlowNameChange) 
            { 
                packageTree.RenameFlow(e.oldObject.ToString(), (e.changeObject as WfFlowDocument).Name); 
            } 
            else if (e.type == WfPackageChangedType.PackageNameChange) 
            { 
                packageTree.Nodes["root"].Text = (e.changeObject as String); 
            } 
            else if (e.type == WfPackageChangedType.AddParam) 
            { 
                packageTree.AddParam((e.changeObject as WfParam).Name); 
            } 
            else if (e.type == WfPackageChangedType.ParamNameChange) 
            { 
                packageTree.RenameParam(e.oldObject.ToString(), (e.changeObject as WfParam).Name); 
            } 
        } 
 
        /// <summary> 
        /// 生成快捷菜单 
        /// </summary> 
        /// <param name="sender"></param> 
        /// <param name="e"></param> 
        private void OnPackageTreeContextMenu(object sender, WfPackageTree.TreeItemClickEventArg e) 
        { 
            ContextMenuStrip menu = new ContextMenuStrip(); 
            switch (e.Item.Tag.ToString()) 
            { 
                case "roleColl": 
                    menu.Items.Add("增加新角色").Click += delegate(object sender1, EventArgs e1) 
                    { 
                        using (RoleInfoDlg dlg = new RoleInfoDlg(null)) 
                        { 
                            dlg.ShowDialog(); 
                        } 
                    }; 
                    break; 
                case "paramColl": 
                    menu.Items.Add("增加新参数").Click += delegate(object sender1, EventArgs e1) 
                   { 
                       using (ParamInfoDlg dlg = new ParamInfoDlg(null)) 
                       { 
                           dlg.ShowDialog(); 
                       } 
                   }; 
                    break; 
                case "appColl": 
                    menu.Items.Add("增加新应用").Click += delegate(object sender1, EventArgs e1) 
                    { 
                        using (AppInfoDlg dlg = new AppInfoDlg(null)) 
                        { 
                            dlg.ShowDialog(); 
                        } 
                    }; 
                    // sm add 
                    //menu.Items.Add("应用排序").Click += delegate(object sender1, EventArgs e1) 
                    //{ 
                    //    using (RankAppDlg dlg = new RankAppDlg()) 
                    //    { 
                    //        dlg.ShowDialog(); 
                    //    } 
                    //}; 
                    break; 
                case "flowColl": 
                    menu.Items.Add("增加新流程").Click += delegate(object sender1, EventArgs e1) 
                    { 
                        using (AppInfoDlg dlg = new AppInfoDlg(null)) 
                        { 
                            Program.WorkflowControl.NewFlow(); 
                        } 
                    }; 
                    break; 
                case "root": 
                    menu.Items.Add("属性").Click += delegate(object sender1, EventArgs e1) 
                    { 
                        using (PackageInfoDlg dlg = new PackageInfoDlg()) 
                        { 
                            dlg.ShowDialog(); 
                        } 
                    }; 
                    break; 
                case "roleObj": 
                case "appObj": 
                case "flowObj": 
                case "paramObj": 
                    menu.Items.Add("属性").Click += delegate(object sender1, EventArgs e1) 
                    { 
                        String objectName = e.Item.Name.Split('.')[1]; 
                        switch (e.Item.Tag.ToString()) 
                        { 
                            case "roleObj": 
                                using (RoleInfoDlg dlg = new RoleInfoDlg(Program.WorkflowControl.WfPackageDocument.GetRoleByName(objectName))) 
                                { 
                                    dlg.ShowDialog(); 
                                } 
                                break; 
                            case "appObj": 
                                using (AppInfoDlg dlg = new AppInfoDlg(Program.WorkflowControl.WfPackageDocument.GetApplicationByName(objectName))) 
                                { 
                                    dlg.ShowDialog(); 
                                } 
                                break; 
                            case "flowObj": 
                                using (FlowInfoDlg dlg = new FlowInfoDlg(Program.WorkflowControl.WfPackageDocument.GetFlowByName(objectName))) 
                                { 
                                    dlg.ShowDialog(); 
                                } 
                                break; 
                            case "paramObj": 
                                using (ParamInfoDlg dlg = new ParamInfoDlg(Program.WorkflowControl.WfPackageDocument.GetParamByName(objectName))) 
                                { 
                                    dlg.ShowDialog(); 
                                } 
                                break; 
                        } 
                    }; 
                    menu.Items.Add("删除").Click += delegate(object sender1, EventArgs e1) 
                    { 
                        try 
                        { 
                            String objectName = e.Item.Name.Split('.')[1]; 
                            switch (e.Item.Tag.ToString()) 
                            { 
                                case "roleObj": 
                                    if (MessageBox.Show("是否要删除该角色?", "询问", MessageBoxButtons.YesNo,MessageBoxIcon.Question) == DialogResult.Yes) 
                                    { 
                                        Program.WorkflowControl.RemoveRole(objectName); 
                                        packageTree.RemoveRole(objectName); 
                                    } 
                                    break; 
                                case "appObj": 
                                    if (MessageBox.Show("是否要删除该应用?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) 
                                    { 
 
                                        Program.WorkflowControl.RemoveApplication(objectName); 
                                        packageTree.RemoveApp(objectName); 
                                    } 
                                    break; 
                                case "flowObj": 
                                    if (MessageBox.Show("是否要删除该业务?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) 
                                    { 
 
                                        Program.WorkflowControl.RemoveFlow(objectName); 
                                        packageTree.RemoveFlow(objectName); 
                                        //判断如果一个flow都没有 
                                        if (Program.WorkflowControl.WfPackageDocument.FlowList.Count <= 0) 
                                        { 
                                            this._menu.DisableAllWorkflowItem(); 
                                            this._menu.CheckAllWorkFlowItem(false); 
 
                                        } 
 
                                        this.flowview.Hide(); 
                                    } 
                                    break; 
                                case "paramObj": 
                                    if (MessageBox.Show("是否要删除该参数?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) 
                                    { 
 
                                        Program.WorkflowControl.RemoveParam(objectName); 
                                        packageTree.RemoveParam(objectName); 
                                    } 
                                    break; 
                            } 
                        } 
                        catch (Exception ex) 
                        { 
                            MessageBox.Show(ex.Message); 
                        } 
 
                    }; 
                    break; 
                default: 
                    break; 
            } 
            menu.Show(Control.MousePosition); 
        } 
        void OnPackageTreeClick(object sender, WfPackageTree.TreeItemClickEventArg e) 
        { 
            switch (e.Item.Tag.ToString()) 
            { 
                case "flowObj": 
                    OpenFlowView(e.Item.Name.Split('.')[1]); 
                    break; 
                case "root": 
                    OpenPackageView(); 
                    break; 
            } 
        } 
 
        public void OpenPackageView() 
        { 
            flowview.Hide(); 
            this.PackageView.Show(); 
            this.mainmenubar.DisableAllWorkflowItem(); 
        } 
 
        public void OpenFlowView(String flowName) 
        { 
            flowview.Hide(); 
            flowview.Show(); 
            this.toolStripToolView.Enabled = true; 
            this.MITool.Enabled = true; 
 
            mainmenubar.EnableAllWorkflowItem(); 
            mainmenubar.CheckButton(MainMenuBar.StateButton.Select); 
 
            mainmenubar.EnableStartActivityItem(); 
            foreach (WfFlowDocument flow in Program.WorkflowControl.WfPackageDocument.FlowList) 
            { 
                if (flow.Name == flowName) 
                { 
                    flowview.Document = flow; 
                    flowview.RedrawAll(); 
                    foreach (Designer.DesignerVisualObject vo in flow.VisualObjectList) 
                    { 
                        if (vo is Designer.WfStartActivity) 
                        { 
                            mainmenubar.DisableStartActivityItem(); 
                            break; 
                        } 
                    } 
                    break; 
                } 
            } 
        } 
       /* private void OnToolClick(object sender, ToolClickEventArgs e) 
        { 
            if ((e.Tool is StateButtonTool) && ((e.Tool as StateButtonTool).OptionSet.Key == "flowTool")) 
            { 
                switch (e.Tool.Key) 
                { 
                    case "flowSelect": 
                        flowView.CurrentTool = new DesignerSelector(); 
                        break; 
                    case "flowActivity": 
                        flowView.CurrentTool = new DesignerNewActivityTool(); 
                        break; 
                    case "flowStartActivity": 
                        flowView.CurrentTool = new DesignerNewStartActivityTool(); 
                        break; 
                    case "flowEndActivity": 
                        flowView.CurrentTool = new DesignerNewEndActivityTool(); 
                        break; 
                    case "flowTransition": 
                        flowView.CurrentTool = new DesignerNewTransitionTool(); 
                        break; 
                    case "flowWsActivity": 
                        flowView.CurrentTool = new DesignerNewWsActivityTool(); 
                        break; 
                    case "flowSyncAllWorkItemActivity": 
                        flowView.CurrentTool = new DesignerNewSyncActivityTool(); 
                        break; 
                    case "flowBranchActivity": 
                        flowView.CurrentTool = new DesignerNewBranchActivityTool(); 
                        break; 
                    case "flowGatherActivity": 
                        flowView.CurrentTool = new DesignerNewGatherActivityTool(); 
                        break; 
                } 
            } 
            else 
            { 
                switch (e.Tool.Key) 
                { 
                    case "newFile": 
                        Program.WorkflowControl.NewWorkflow(); 
                        break; 
                    case "fileSave": 
                        Program.WorkflowControl.Save(); 
                        break; 
                    case "fileSaveAs": 
                        Program.WorkflowControl.SaveAs(); 
                        break; 
                    case "fileOpen": 
                        Program.WorkflowControl.Open(); 
                        break; 
                    case "serviceSetting": 
                        ServiceSettingDlg dlg = new ServiceSettingDlg(); 
                        dlg.ServiceMgrUrl = Program.WorkflowControl.ServiceMgrUrl; 
                        if (dlg.ShowDialog() == DialogResult.OK) 
                        { 
                            Program.WorkflowControl.ServiceMgrUrl = dlg.ServiceMgrUrl; 
                        } 
                        break; 
 
                } 
            } 
        }*/ 
         
 
        private void OnVisualObjectAdd(object sender, VisualObjectAddEventArg e) 
        { 
            if (e.newObject is Designer.WfStartActivity) 
            { 
                mainmenubar.DisableStartActivityItem(); 
            } 
        } 
        private void OnVisualObjectDelete(object sender, VisualObjectDeleteEventArg e) 
        { 
            if (e.deleteObject is Designer.WfStartActivity) 
            { 
                mainmenubar.EnableStartActivityItem(); 
            } 
        } 
 
 
        public MainMenuBar mainmenubar 
        { 
            get { return _menu; } 
            set { _menu = value; } 
        } 
 
        private MainMenuBar _menu; 
 
        private void OnWorkflowToolClick(object sender, EventArgs e) 
        { 
            //this._menu.CheckAllWorkFlowItem(false); 
           // CheckTool(((ToolStripButton)sender).Name); 
 
            switch (((ToolStripButton)sender).Name) 
            { 
                 
                case "TSBSelect": 
                        flowview.CurrentTool = new DesignerSelector(); 
                        break; 
                    case "TSBActive": 
                        flowview.CurrentTool = new DesignerNewActivityTool(); 
                        break; 
                    case "TSBStart": 
                        flowview.CurrentTool = new DesignerNewStartActivityTool(); 
                        break; 
                    case "TSBEnd": 
                        flowview.CurrentTool = new DesignerNewEndActivityTool(); 
                        break; 
                    case "TSBTrans": 
                        flowview.CurrentTool = new DesignerNewTransitionTool(); 
                        break; 
                    //case "TSBBacth": 
                    //    flowView.CurrentTool = new (); 
                    //    break; 
                    //case "TSBConverge": 
                    //    flowView.CurrentTool = new (); 
                    //    break; 
                    case "TSBBack": 
                        flowview.CurrentTool = new DesignerBackTransitionTool(); 
                        break; 
            } 
        } 
        private void CheckTool(String Name) 
        { 
            this._menu.CheckAllWorkFlowItem(false); 
            switch (Name) 
            { 
                case "DesignerSelector": 
                    _menu.CheckButton(MainMenuBar.StateButton.Select); 
                    break; 
                case "DesignerNewActivityTool": 
                    _menu.CheckButton(MainMenuBar.StateButton.Activity); 
                    break; 
                case "DesignerNewStartActivityTool": 
                    _menu.CheckButton(MainMenuBar.StateButton.StartActivity); 
                    break; 
                case "DesignerNewEndActivityTool": 
                    _menu.CheckButton(MainMenuBar.StateButton.EndActivity); 
                    break; 
                case "DesignerNewTransitionTool": 
                    _menu.CheckButton(MainMenuBar.StateButton.Transition); 
                    break; 
                //case "DesignerNewBranchActivityTool": 
                //    _menu.CheckButton(MainMenuBar.StateButton.BrachActivity); 
                //    break; 
                //case "DesignerNewGatherActivityTool": 
                //    _menu.CheckButton(MainMenuBar.StateButton.GatherActivity); 
                //    break; 
                case "DesignerNewBackTransitionTool": 
                    _menu.CheckButton(MainMenuBar.StateButton.Back); 
                    break; 
               
            } 
        } 
        private void OnWorkflowToolMenuCheckStateChanged(object sender, EventArgs e) 
        { 
            //this._menu.CheckAllWorkFlowItem(false); 
           // CheckTool(((ToolStripMenuItem)sender).Name); 
 
            switch (((ToolStripMenuItem)sender).Name) 
            { 
                 
                case "MISelect": 
                    flowview.CurrentTool = new DesignerSelector(); 
                        break; 
                    case "MIActive": 
                        flowview.CurrentTool = new DesignerNewActivityTool(); 
                        break; 
                    case "MIStart": 
                        flowview.CurrentTool = new DesignerNewStartActivityTool(); 
                        break; 
                    case "MIEnd": 
                        flowview.CurrentTool = new DesignerNewEndActivityTool(); 
                        break; 
                    case "MITrans": 
                        flowview.CurrentTool = new DesignerNewTransitionTool(); 
                        break; 
                    //case "MIBatch": 
                    //    flowView.CurrentTool = new (); 
                    //    break; 
                    //case "MIconverge": 
                    //    flowView.CurrentTool = new (); 
                    //    break; 
                    case "MIBack": 
                        flowview.CurrentTool = new DesignerBackTransitionTool(); 
                        break; 
            } 
        } 
 
        private void OnMainClick(object sender, EventArgs e) 
        { 
            if ((sender is ToolStripButton) || (sender is ToolStripMenuItem)) 
            { 
                String Name = ""; 
                if (sender is ToolStripButton) 
                { 
                    Name = (sender as ToolStripButton).Name; 
                } 
                if (sender is ToolStripMenuItem) 
                { 
                    Name = (sender as ToolStripMenuItem).Name; 
                } 
 
                switch (Name) 
                { 
                        
                     
                    case "MInew": 
                    case "TSBnew": 
                        Program.WorkflowControl.NewWorkflow(); 
                        break; 
                    case "MISave": 
                    case "TSBSave": 
                        Program.WorkflowControl.Save(); 
                        break; 
                    case "MISaveAs": 
                        Program.WorkflowControl.SaveAs(); 
                        break; 
                    case "TSBOpen": 
                    case "MIOpen": 
                        Program.WorkflowControl.Open(); 
                        break; 
                    case "MIClose": 
                        this.Close(); 
                        break; 
                    case "MIImport": 
                        Program.WorkflowControl.ImportToDataBase(); 
                        break; 
                    case "MINomalView": 
                        //if() 
                        if ((sender as ToolStripMenuItem).CheckState == CheckState.Checked) 
                        { 
                            (sender as ToolStripMenuItem).CheckState = CheckState.Unchecked; 
                            this.toolStripNomalView.Hide(); 
                        } 
                        else { 
                            (sender as ToolStripMenuItem).CheckState = CheckState.Checked; 
                            this.toolStripNomalView.Show(); 
                        } 
                        break; 
                    case "MIToolView": 
                        if ((sender as ToolStripMenuItem).CheckState == CheckState.Checked) 
                        { 
                            (sender as ToolStripMenuItem).CheckState = CheckState.Unchecked; 
                            this.toolStripToolView.Visible=false; 
                        } 
                        else 
                        { 
                            (sender as ToolStripMenuItem).CheckState = CheckState.Checked; 
                            this.toolStripToolView.Visible=true; 
                        } 
                        break; 
 
                   
                } 
            } 
        } 
 
        private void flowview_CurrentToolChange(object sender, CurrentToolChangeEventArg e) 
        { 
            //switch (e.newTool.GetType().Name) 
            //{ 
                CheckTool( e.newTool.GetType().Name); 
            //} 
        } 
 
    } 
}