zoukankan      html  css  js  c++  java
  • MainForm()

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using WindowsFormsApplication3.Model;
    using WindowsFormsApplication3.Enums;
    using WindowsFormsApplication3.FormPage;
    using WindowsFormsApplication3.DataStorge;
    using System.Threading;
    
    namespace WindowsFormsApplication3
    {
        public partial class MainForm : Form
        {
            protected static readonly Color[] TREE_VIEW_FORE_COLOR = new Color[] { Color.Black, Color.Black, Color.Black, Color.Red, Color.Black };
            
            protected BaseWorkerForm activeForm;
            protected Dictionary<string, BaseWorkerForm> formDictionary;
            protected Dictionary<string, TreeNode> nodeDictionary;
            protected FormStatus status;
            protected CheckoutContext checkoutContext;
            public CheckoutContext CheckoutContext
            {
                get { return checkoutContext; }
            }
    
            public MainForm():base()
            {
                this.checkoutContext = new CheckoutContext();
                InitializeComponent();
            }
    
            protected void BuildNodeDictionary(TreeNodeCollection nodes) {
                foreach (TreeNode node in nodes) { 
                if(formDictionary.ContainsKey(node.Name)){
                    node.Tag=formDictionary[node.Name];
                    nodeDictionary.Add(node.Name,node);
                }
                BuildNodeDictionary(node.Nodes);
                }
            }
    
            private void buttonTroubleshoot_Click(object sender, EventArgs e)
            {
                Execute();
            }
    
            public void Execute() {
                status = FormStatus.Processing;
                buttonTroubleshoot.Enabled = false;
                foreach (var childf in checkoutContext.formHierachy)
                {
                    childf.childForm.ResetForm();;
                    childf.childForm.RefreshForm();
                }
                RefreshForm();
                ExecuteForm();
    
            }
    
            protected void ExecuteForm() {
                foreach (var childf in checkoutContext.formHierachy)
                {
    
                    ThreadPool.QueueUserWorkItem(new WaitCallback(childf.childForm.Execute),null);
                }
            }
    
            public void ChildFormStatusChanged() {
               // RefreshForm();
            }
            private void MainForm_Load(object sender, System.EventArgs e) {
                
                nodeDictionary=new Dictionary<string,TreeNode>();
                checkoutContext.formHierachy.Add(new FormHierachy("null", new IntroductionForm(checkoutContext, CheckoutStep.Introduction)));
                //checkoutContext.formHierachy.Add(new FormHierachy("IntroductionForm", new ClientForm(checkoutContext, CheckoutStep.Client)));
                //checkoutContext.formHierachy.Add(new FormHierachy("IntroductionForm", new ServerForm(checkoutContext, CheckoutStep.Server)));
                //checkoutContext.formHierachy.Add(new FormHierachy("ServerForm", new CellsForm(checkoutContext, CheckoutStep.Cells)));
                //checkoutContext.formHierachy.Add(new FormHierachy("ServerForm", new VolumesForm(checkoutContext, CheckoutStep.Volumes)));
                checkoutContext.formHierachy.Add(new FormHierachy("ClientForm", new OperationSystemForm(checkoutContext, CheckoutStep.OperationSystem)));
    
                foreach (var childf in checkoutContext.formHierachy)
                {
                    childf.childForm.TopLevel = false;
                    childf.childForm.Dock = DockStyle.Fill;
                    childf.childForm.Visible = true;
                    childf.childForm.FormBorderStyle = FormBorderStyle.None;                                
                }
    
                formDictionary=new Dictionary<string,BaseWorkerForm>();
                foreach (var childf in checkoutContext.formHierachy)
                {
                    formDictionary.Add(childf.childForm.Text, childf.childForm);
                    childf.childForm.FormStatusChanged += ChildFormStatusChanged;
                }
                activeForm = formDictionary["IntroductionForm"] as BaseWorkerForm;
                splitContainer1.Panel2.Controls.Add(activeForm);
                BuildNodeDictionary(treeViewSteps.Nodes);
                treeViewSteps.ImageList = ImageConstants.IMAGE_LIST_FORM_STATUS;
                treeViewSteps.ExpandAll();
                RefreshForm();
            }
    
            public void RefreshForm() {
                richTextBox.Clear();
                RefreshTreeNodes(treeViewSteps.Nodes);
                foreach(LogEntry le in checkoutContext.logData.logList){
                    richTextBox.AppendText(le.ToString());
                }            
            }
    
            public void RefreshTreeNodes(TreeNodeCollection nodes) {
                foreach (TreeNode node in nodes) {
                    BaseWorkerForm form = node.Tag as BaseWorkerForm;
                    FormStatus formstatus = form == null ? FormStatus.Waiting : form.Status;
                    node.ForeColor = TREE_VIEW_FORE_COLOR[(int)formstatus];
                    node.SelectedImageIndex = node.ImageIndex = (int)formstatus;
                    RefreshTreeNodes(node.Nodes);
                }
            }
    
            private void treeViewSteps_AfterSelect(object sender, TreeViewEventArgs e)
            {
                TreeNode treeNode = e.Node;
                if (activeForm != null)
                    splitContainer1.Panel2.Controls.Remove(activeForm);
                activeForm = treeNode.Tag as BaseWorkerForm;
                if (activeForm != null)
                    splitContainer1.Panel2.Controls.Add(activeForm);
            }        
         }
    }
  • 相关阅读:
    Python疑难杂症:SyntaxError: NonASCII character Python中文处理问题
    程序员健康大全透视身体24小时工作时间表
    ConnectionTimeout,CommandTimeout和executionTimeout的理解
    google map api 与jquery结合使用(3) 图标样式,使用xml和异步请求【转帖】
    新手8周跑步训练计划
    57商城温州地区最大本土网上超市
    7 款仿照 Sinatra 思路的 .NET 框架
    线程池的原理和连接池的原理
    免费网站模版:一个黑色系的公司网站模版(flash幻灯)
    深入浅出REST
  • 原文地址:https://www.cnblogs.com/rosizel/p/3861622.html
Copyright © 2011-2022 走看看