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;
    
    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.Execute();
                    childf.childForm.RefreshForm();
                }
                RefreshForm();
                ExecuteForm();
    
            }
    
            protected void ExecuteForm() {
                foreach (var childf in checkoutContext.formHierachy)
                {
                    childf.childForm.Execute();
                    RefreshForm();
                }
            }
    
            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);
            }        
         }
    }
  • 相关阅读:
    JSP基础语法
    MySQL数据库_数据的增删改查
    [数据库] windows server 2003下mysql出现10048错误的解决办法 Can't connect to MySQL server on '127.0.0.1' (10048)(抄)
    支持onvif的摄像机,可以通过onvif工具来设置预置位,odm工具
    word里面对齐用Tab键
    Plctext 如何发送默认的模式
    关于TVWALL 通过AS300获取状态连接失败
    测试人员需要了解的测试工具(转)
    国内可用的Internet时间同步服务器地址(NTP时间服务器) 好在阿里云提供了7个NTP时间服务器也就是Internet时间同步服务器地址(转)
    修改MAC地址的方法 破解MAC地址绑定(抄)
  • 原文地址:https://www.cnblogs.com/rosizel/p/3859388.html
Copyright © 2011-2022 走看看