首页 > 代码库 > MainForm()

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);        }             }}