private void SaveXmlButton_Click(object sender, RoutedEventArgs e)
        {
            if (UserMessageBox.Show("消息提示", "确认修改数据库信息?") == true)
            {
                string          ConnectionString = "Data Source = " + DataSourceBox.Text + "; User Id = " + UserIDBox.Text + "; Password ="******" CREATE database if not exists " + DataBaseBox.Text + ";DROP TABLE IF EXISTS " + DataBaseBox.Text + ".`firewallip`;" +
                                     " CREATE TABLE " + DataBaseBox.Text + ".`firewallip` (fw_ip VARCHAR(255) DEFAULT NULL, `fw_mac` varchar(255) DEFAULT NULL," +
                                     " dev_ip VARCHAR(255) DEFAULT NULL, dev_mac VARCHAR(255) DEFAULT NULL, dev_type VARCHAR(255) DEFAULT NULL)" +
                                     " ENGINE = InnoDB DEFAULT CHARSET = utf8;" +
                                     " DROP TABLE IF EXISTS " + DataBaseBox.Text + ".`firewallrules`;" +
                                     " CREATE TABLE " + DataBaseBox.Text + ".`firewallrules` (`fw_mac` varchar(255) DEFAULT NULL,`protocol` varchar(255) DEFAULT NULL," +
                                     " `source` varchar(255) DEFAULT NULL,`destination` varchar(255) DEFAULT NULL,`coiladdressstart` varchar(255) DEFAULT NULL," +
                                     " `coiladdressend` varchar(255) DEFAULT NULL, minspeed varchar(255) DEFAULT NULL, maxspeed varchar(255) DEFAULT NULL," +
                                     " `functioncode` varchar(255) DEFAULT NULL,`log` varchar(255) DEFAULT NULL" +
                                     " ) ENGINE = InnoDB DEFAULT CHARSET = utf8;" +
                                     " DROP TABLE IF EXISTS " + DataBaseBox.Text + ".`useraccount`;" +
                                     " CREATE TABLE " + DataBaseBox.Text + ".`useraccount` (`UserID` tinyint(3) unsigned NOT NULL AUTO_INCREMENT," +
                                     " `UserName` char(16) NOT NULL,`Password` char(8) DEFAULT NULL,`Purview` char(32) DEFAULT NULL," +
                                     " PRIMARY KEY(`UserID`),UNIQUE KEY `useName` (`UserName`)) ENGINE = InnoDB AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8;" +
                                     " INSERT INTO " + DataBaseBox.Text + ".`useraccount` (`UserID`, `UserName`, `Password`, `Purview`) VALUES('1', 'admin', 'admin', 'SUPER');";
                try
                {
                    //Open DataBase
                    //打开数据库
                    conn.Open();
                    MySqlCommand cmd = new MySqlCommand(CommandText, conn);
                    cmd.ExecuteNonQuery();
                    //读取全局配置信息
                    XmlSerializationHelper configContext = new XmlSerializationHelper("Config");
                    GlobalConfig           globalconfig  = configContext.Get <GlobalConfig>();

                    globalconfig.DataBaseConfigs[0].DataBase   = DataBaseBox.Text;
                    globalconfig.DataBaseConfigs[0].DataSource = DataSourceBox.Text;
                    globalconfig.DataBaseConfigs[0].UserId     = UserIDBox.Text;
                    globalconfig.DataBaseConfigs[0].Password   = PassWordBox.Text;
                    configContext.Save(globalconfig);

                    StaticGlobal.database         = DataBaseBox.Text;
                    StaticGlobal.datasource       = DataSourceBox.Text;
                    StaticGlobal.userid           = UserIDBox.Text;
                    StaticGlobal.password         = PassWordBox.Text;
                    StaticGlobal.ConnectionString = "Database = " + StaticGlobal.database + ";Data Source = " + StaticGlobal.datasource + "; User Id = " + StaticGlobal.userid + "; Password ="******"提示", "输入信息有误或Mysql服务未打开,无法连接数据库!");
                }
                finally
                {
                    //Close DataBase
                    //关闭数据库连接
                    conn.Close();
                }
            }
        }
Пример #2
0
        //*----------------------------------------------------------------
        //函数说明:静态方法读取全局变量
        //输入:无
        //输出:无
        //----------------------------------------------------------------*//
        public static void ReadXmlConfig()
        {
            //读取全局配置信息
            XmlSerializationHelper configContext = new XmlSerializationHelper("Config");
            GlobalConfig           globalconfig  = configContext.Get <GlobalConfig>();

            //数据库连接配置
            StaticGlobal.database         = globalconfig.DataBaseConfigs[0].DataBase;
            StaticGlobal.datasource       = globalconfig.DataBaseConfigs[0].DataSource;
            StaticGlobal.userid           = globalconfig.DataBaseConfigs[0].UserId;
            StaticGlobal.password         = globalconfig.DataBaseConfigs[0].Password;
            StaticGlobal.ConnectionString = "Database = " + StaticGlobal.database + ";Data Source = " + StaticGlobal.datasource + "; User Id = " + StaticGlobal.userid + "; Password =" + StaticGlobal.password;

            //参数配置
            StaticGlobal.FunctionCodeNumber = globalconfig.Parameters[0].FunctionCodeNum;

            //第一次使用软件标志
            StaticGlobal.firstloginflag = globalconfig.LoginSettings[0].firstloginflag;
        }
Пример #3
0
        //设备扫描IP范围删除
        private void IPDeletButton_Click(object sender, RoutedEventArgs e)
        {
            string[] Array1;
            Array1 = StaticGlobal.ScanIP.Split('+');
            string[] Array2 = new string[Array1.Length - 1];
            int      darray = ScanIPrangeBox.SelectedIndex;

            if (StaticGlobal.ScanIP != "")
            {
                int j = 0;
                while (j < darray)
                {
                    Array2[j] = Array1[j];
                    j++;
                }
                while (darray < Array1.Length - 1)
                {
                    Array2[darray] = Array1[darray + 1];
                    darray++;
                }
                string NewIP = Array2[0];
                for (int i = 1; i < Array2.Length; i++)
                {
                    NewIP = NewIP + "+" + Array2[i];
                }
                StaticGlobal.ScanIP         = NewIP;
                ScanIPrangeBox.SelectedItem = ScanIPrangeBox.Items[0];
            }
            //将设备扫描范围存入配置文件
            XmlSerializationHelper configContext = new XmlSerializationHelper("Config");
            GlobalConfig           globalconfig  = configContext.Get <GlobalConfig>();

            globalconfig.ScanIPConfig[0].scanip = StaticGlobal.ScanIP;
            configContext.Save(globalconfig);
            StaticGlobal.ScanIP = globalconfig.ScanIPConfig[0].scanip;

            ScanIPrangeBox.Items.Remove(ScanIPrangeBox.SelectedItem);
        }