コード例 #1
0
        private void button1_Click(object sender, EventArgs e0)
        {
            bool   bReloadClass = false;
            string _classname   = "";

            if (comboBox_classlist != null && comboBox_classlist.SelectedItem != null)
            {
                _classname = comboBox_classlist.SelectedItem.ToString();

                try
                {
                    foreach (Classes c in m_classlist)
                    {
                        if (_classname == "公共教室")
                        {
                            classid = -1;
                            break;
                        }
                        if (_classname == c.name)
                        {
                            classid = c.id;
                        }
                    }
                    if (classid != Global.getClassID())
                    {
                        bReloadClass = true;
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show("教室ID参数设置错误,请重试!", "警告");
                    return;
                }
                Log.Info("Config.2 classid=" + classid);
            }


            try
            {
                hdip = textBox_hdip.Text;
                IPAddress ip;
                if (!IPAddress.TryParse(hdip, out ip))
                {
                    MessageBox.Show("采集器IP地址设置错误,请重试!", "警告");
                    return;
                }
            }
            catch (Exception e) {
                Log.Info("Config.3 " + e.Message);
            }
            Log.Info("Config.3 hdip=" + hdip);


            SetAutoRun(true);
            Global.setAutoUpdate(1);

            button_apply.Enabled = false;

            {
                string  strHDIP  = textBox_hdip.Text;
                Boolean bAutorun = autorun == 1?true:false;
                Global.saveSchoolConfig(strHDIP, bAutorun);
            }

            //TODO:如果教室ID变化,重新获取相关信息
            if (bReloadClass)
            {
                Global.saveClassConfig(classid, _classname);

                if (Global.loadClassInfo())
                {
                    MessageBox.Show("更新成功!", "提示");

                    //更新班级的接收机ID
                    Thread th = new Thread(delegate()
                    {
                        string hdid = Common.getHDID();
                        if (hdid.Length > 0)
                        {
                            Common.uploadHDBind();
                        }
                    });
                    th.Start();
                }
                else
                {
                    MessageBox.Show("设置失败,请检查网络!", "提示");
                }
            }
            button_apply.Enabled = true;
        }