Beispiel #1
0
        private void btnDatabaseCopy_Click(object sender, EventArgs e)
        {
            LoginForm loginForm = new LoginForm(LoginForm.LoginType.DataBaseDataCopy);

            loginForm.ShowDialog();

            if (loginForm.DialogResult == DialogResult.OK)
            {
                SqlData importSqlData = loginForm.GetGeneratedSqlData();

                WaitingForm waitingForm = new WaitingForm(sqlData, importSqlData);
                waitingForm.ShowDialog();

                MessageBox.Show("数据复制完成!");
            }
        }
Beispiel #2
0
        private void btnUpdateROF4K_Click(object sender, EventArgs e)
        {
            LoginConfig.LoginConfigData loginConfigData =
                LoginConfig.LoadXml(LoginForm.LoginConfigPath);
            WaitingForm waitingForm = new WaitingForm(
                SetWebCaptureDataResult, sqlData, loginConfigData.crawlConfig.CrawlURL);

            waitingForm.ShowDialog();

            if (this.webDataCaptureResult.code >= 0)
            {
                LoginConfig.DataBaseType databaseType = this.sqlData.GetDataBaseType();
                loginConfigData.dataBaseType = databaseType;
                if (databaseType == LoginConfig.DataBaseType.MYSQL)
                {
                    SqlDataInMySql sqlDataInMySql = sqlData as SqlDataInMySql;
                    loginConfigData.mysqlConfig.selectedDataBaseName = sqlDataInMySql.DbName;
                    loginConfigData.mysqlConfig.SelectedDataBaseWebDataCaptureTime =
                        this.webDataCaptureResult.crawlTime.ToString("yyyy-MM-dd HHH:mm:ss");
                }
                else if (databaseType == LoginConfig.DataBaseType.SQLITE)
                {
                    SqlDataInSqlite sqlDataInSqlite = sqlData as SqlDataInSqlite;
                    loginConfigData.sqliteConfig.selectedDataBasePath =
                        sqlDataInSqlite.SqliteDataBasePath;
                    loginConfigData.sqliteConfig.SelectedDataBaseWebDataCaptureTime =
                        this.webDataCaptureResult.crawlTime.ToString("yyyy-MM-dd HHH:mm:ss");
                }
                LoginConfig.SaveXml(loginConfigData, LoginForm.LoginConfigPath);
            }

            if (this.webDataCaptureResult.code > 0)
            {
                this.needReFillRamData = true;
            }

            MessageBox.Show(this.webDataCaptureResult.strMsg);
        }
Beispiel #3
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            LoginConfig.DataBaseType databaseType =
                this.tabControl.SelectedIndex == 0 ?
                LoginConfig.DataBaseType.MYSQL :
                LoginConfig.DataBaseType.SQLITE;

            String dbIP               = String.Empty;
            String dbUserName         = String.Empty;
            String dbPassword         = String.Empty;
            String dbName             = String.Empty;
            String sqliteDateBasePath = String.Empty;

            CommonString.NeedDeleteAllTableData = false;

            if (databaseType == LoginConfig.DataBaseType.MYSQL)
            {
                dbIP       = this.comboBoxIP.Text;
                dbUserName = this.comboBoxUser.Text;
                dbPassword = this.textBoxPwd.Text;
                dbName     = this.comboBoxDataBase.Text;

                List <String> databaseNameList = null;
                try
                {
                    databaseNameList = SqlDataInMySql.QueryAllDataBaseNames(
                        dbIP, dbUserName, dbPassword);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK);
                    return;
                }

                if (!databaseNameList.Contains(dbName))
                {
                    if (MessageBox.Show(String.Format("数据库 \"{0}\" 不存在,要创建吗?",
                                                      dbName), "提示",
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        try
                        {
                            SqlDataInMySql.CreateDataBase(dbIP, dbUserName, dbPassword, dbName);
                            generatedSqlData = new SqlDataInMySql(dbIP, dbUserName, dbPassword, dbName);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK);
                            return;
                        }
                    }
                    else
                    {
                        return;
                    }
                }
                else if (this.loginType == LoginType.DataBaseDataCopy)
                {
                    if (MessageBox.Show(String.Format(
                                            "数据库 \"{0}\" 已存在,此操作会覆盖该数据库相同的表,仍然要复制到该数据库吗?",
                                            dbName), "提示",
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        generatedSqlData = new SqlDataInMySql(dbIP, dbUserName, dbPassword, dbName);
                        CommonString.NeedDeleteAllTableData = true;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    generatedSqlData = new SqlDataInMySql(dbIP, dbUserName, dbPassword, dbName);
                }
            }
            else
            {
                sqliteDateBasePath = this.cbSQLiteDataBase.Text;
                generatedSqlData   = new SqlDataInSqlite(sqliteDateBasePath);

                if (this.loginType == LoginType.DataBaseDataCopy && File.Exists(sqliteDateBasePath))
                {
                    if (MessageBox.Show(String.Format(
                                            "数据库 \"{0}\"\n已存在,此操作会覆盖该数据库相同的表,仍然要复制到该数据库吗?",
                                            sqliteDateBasePath), "提示",
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    {
                        return;
                    }
                    else
                    {
                        CommonString.NeedDeleteAllTableData = true;
                    }
                }
            }

            try
            {
                generatedSqlData.CreateTables();

                DateTime dateTimeLast = DateTime.MinValue;

                if (databaseType == LoginConfig.DataBaseType.MYSQL)
                {
                    if (!CommonString.LoginConfigData.mysqlConfig.hostIPs.Contains(dbIP))
                    {
                        CommonString.LoginConfigData.mysqlConfig.hostIPs.Add(dbIP);
                    }

                    if (CommonString.LoginConfigData.mysqlConfig.userNameAndPassWords.FindIndex(
                            x => x.UserName == dbUserName) == -1)
                    {
                        CommonString.LoginConfigData.mysqlConfig.userNameAndPassWords.Add(
                            new LoginConfig.UserNameAndPassWord()
                        {
                            UserName = dbUserName,
                            PassWord = Helper.Encryption(dbPassword)
                        });
                    }

                    if (CommonString.LoginConfigData.mysqlConfig.dataBaseConfigs.FindIndex(
                            x => x.Name == dbName) == -1)
                    {
                        CommonString.LoginConfigData.mysqlConfig.dataBaseConfigs.Add(
                            new LoginConfig.DataBaseConfig()
                        {
                            Name = dbName,
                            WebDataCaptureTime =
                                DateTime.MinValue.ToString("yyyy-MM-dd HHH:mm:ss")
                        });
                    }

                    CommonString.LoginConfigData.mysqlConfig.selectedUserName     = dbUserName;
                    CommonString.LoginConfigData.mysqlConfig.selectedIP           = dbIP;
                    CommonString.LoginConfigData.mysqlConfig.selectedDataBaseName = dbName;

                    DateTime.TryParse(
                        CommonString.LoginConfigData.mysqlConfig.SelectedDataBaseWebDataCaptureTime,
                        out dateTimeLast);
                }
                else
                {
                    if (CommonString.LoginConfigData.sqliteConfig.dataBaseConfigs.FindIndex(
                            x => x.Name == sqliteDateBasePath) == -1)
                    {
                        CommonString.LoginConfigData.sqliteConfig.dataBaseConfigs.Add(
                            new LoginConfig.DataBaseConfig()
                        {
                            Name = sqliteDateBasePath,
                            WebDataCaptureTime =
                                DateTime.MinValue.ToString("yyyy-MM-dd HHH:mm:ss")
                        });
                    }
                    CommonString.LoginConfigData.sqliteConfig.selectedDataBasePath = sqliteDateBasePath;

                    DateTime.TryParse(
                        CommonString.LoginConfigData.sqliteConfig.SelectedDataBaseWebDataCaptureTime,
                        out dateTimeLast);
                }

                if (this.loginType == LoginType.Normal &&
                    CommonString.LoginConfigData.crawlConfig.IsCrawl)
                {
                    TimeSpan ts = DateTime.Now.Subtract(dateTimeLast);
                    if (ts.Days >= CommonString.LoginConfigData.crawlConfig.IntervalDays)
                    {
                        WaitingForm waitingForm = new WaitingForm(
                            SetWebCaptureDataResult, generatedSqlData,
                            CommonString.LoginConfigData.crawlConfig.CrawlURL);
                        waitingForm.ShowDialog();

                        if (this.webDataCaptureResult.code >= 0)
                        {
                            dateTimeLast = this.webDataCaptureResult.crawlTime;
                        }
                        MessageBox.Show(this.webDataCaptureResult.strMsg);
                    }
                }

                if (databaseType == LoginConfig.DataBaseType.MYSQL)
                {
                    CommonString.LoginConfigData.mysqlConfig.SelectedDataBaseWebDataCaptureTime
                        = dateTimeLast.ToString("yyyy-MM-dd HHH:mm:ss");
                }
                else
                {
                    CommonString.LoginConfigData.sqliteConfig.SelectedDataBaseWebDataCaptureTime
                        = dateTimeLast.ToString("yyyy-MM-dd HHH:mm:ss");
                }

                CommonString.LoginConfigData.dataBaseType = databaseType;

                LoginConfig.SaveXml(CommonString.LoginConfigData, LoginConfigPath);

                if (this.loginType == LoginType.Normal)
                {
                    generatedSqlData.FillRamData();
                }

                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK);
            }
        }