Exemplo n.º 1
0
        public void Form1_Load(object sender, EventArgs e)
        {
            //判断是否第一次使用本软件
            if (!isJudgeFirstUse && Tools.isFirstUse())
            {
                this.Hide();
                FirstUseFrm firstUseFrm = new FirstUseFrm(this);
                firstUseFrm.ShowDialog();
                return;
            }


            //创建数据库对象
            db = new DbManager();
            db.init();



            //加载配置项
            Dictionary <string, string> sysConfig = db.getRow2Dic("sysConfig");
            bool autoRun     = Convert.ToBoolean(sysConfig["autoRun"]);
            bool autoConnect = Convert.ToBoolean(sysConfig["autoConnect"]);


            company_lab.Text = sysConfig["company"].ToString();
            tel_lab.Text     = sysConfig["phone"].ToString();


            //加载各类图片
            pic_icon.Image   = imageList1.Images["icon.png"];
            pic_tubiao.Image = imageList1.Images["tubiao.png"];
            pic_check.Image  = imageList1.Images["check.png"];
            pic_min.Image    = imageList1.Images["min.png"];
            pic_close.Image  = imageList1.Images["close.png"];
            //加载左侧ip面板控件
            tbsDic.Add("ip", new TextBox[4] {
                tbIp0, tbIp1, tbIp2, tbIp3
            });
            tbsDic.Add("mask", new TextBox[4] {
                tbMask0, tbMask1, tbMask2, tbMask3
            });
            tbsDic.Add("gateway", new TextBox[4] {
                tbGateway0, tbGateway1, tbGateway2, tbGateway3
            });
            tbsDic.Add("dns1", new TextBox[4] {
                tbZDns0, tbZDns1, tbZDns2, tbZDns3
            });
            tbsDic.Add("dns2", new TextBox[4] {
                tbFdns0, tbFdns1, tbFdns2, tbFdns3
            });
            tbsDic.Add("iNode", new TextBox[1] {
                tbiNode
            });
            //加载右侧控件
            labDic.Add("taskTip", new Label[5] {
                lab_jc0, lab_jc1, lab_jc2, lab_jc3, lab_jc4
            });
            labDic.Add("msg", new Label[5] {
                lab_suggest0, lab_suggest1, lab_suggest2, lab_suggest3, lab_suggest4
            });
            picDic.Add("loading", new PictureBox[5] {
                pic_jc0, pic_jc1, pic_jc2, pic_jc3, pic_jc4
            });



            //创建ip面板管理对象
            pm = new PanelManager(comboBox1, tbsDic);


            //创建诊断对象
            networkDoctor                   = new NetworkDoctor(pm.getSelectedNetCard(), db);
            networkDoctor.TaskStart        += taskStart;
            networkDoctor.refreshUI        += refreshUI;
            networkDoctor.statusUI         += statusUI;
            networkDoctor.TaskStepCallBack += taskStepCallBack;
            networkDoctor.TaskFinish       += taskFinish;



            //创建插件面板对象
            PlugManager plugManager = new PlugManager(this, plug_gb, imageList2);

            plugManager.drawItem("radminInstallAndActive", "Radmin配置", 1, 6);
            plugManager.drawItem("systemUserSafePwd", "账户密码安全", 2, 6);
            plugManager.drawItem("winUpdate", "系统自动升级", 3, 6);
            plugManager.drawItem("printShare", "打印共享修复", 4, 6);
            plugManager.drawItem("clearCDisk", "清除C盘垃圾", 5, 7);

            //如果面板不可用,则说明就没有可用的网卡,给出提示
            if (!pm.IsEnable)
            {
                MessageBox.Show("未找到可用的网卡,请开启诊断助手进行诊断!");
                return;
            }
            else
            {
                if (pm.getSelectedNetCard().isEnableIp())
                {
                    //保存网卡信息
                    string ipInfoPath = Application.StartupPath + "\\IpInfo.json";
                    if (!File.Exists(ipInfoPath))
                    {
                        NetCard selectedNetcard         = pm.getSelectedNetCard();
                        Dictionary <string, string> dic = new Dictionary <string, string>();
                        dic.Add("ip", selectedNetcard.Ip);
                        dic.Add("mask", selectedNetcard.Mask);
                        dic.Add("gateway", selectedNetcard.Gateway);
                        dic.Add("dns1", "10.208.4.100");
                        dic.Add("dns2", "10.208.4.200");
                        Tools.saveJsonFile(ipInfoPath, dic);
                    }
                }
            }

            //更改托盘图片提示
            notifyIcon1.Text = "本机IP:" + pm.getEnableCard().Ip;

            //加载桌面悬浮信息
            SkinFrm skinfrm = new SkinFrm(pm.getSelectedNetCard(), db);

            skinfrm.Show();



            //创建计划类对象
            plm = new PlanManager(db, this);
            plm.netConnectUI += netConnectUI;
            if (autoConnect_ck.Checked)
            {
                plm.addPlan("网络连接状态");
            }
            else
            {
                plm.removePlan("网络连接状态");
            }
            //这个必须放在plm后面,因为调用了plm
            if (autoRun)
            {
                autoRun_ck.Checked = true;
            }
            else
            {
                autoRun_ck.Checked = false;
            }

            if (autoConnect)
            {
                autoConnect_ck.Checked = true;
            }
            else
            {
                autoConnect_ck.Checked = false;
            }
            plm.start();



            //绑定用户注册信息更新事件
            Tools.userInfoUI += getUserInfo;
        }