Ejemplo n.º 1
0
        //public void SetControlEnable(bool connectState)
        //{
        //    if (connectState)
        //    {
        //        int i = 0;
        //        foreach (Control cl in this.Controls) cl.Enabled = controlEnableArray[i++];
        //    }
        //    else
        //    {
        //        int i = 0;
        //        foreach (Control cl in this.Controls)
        //        {
        //            controlEnableArray[i++] = cl.Enabled;
        //            cl.Enabled = false;
        //        }
        //    }
        //}

        private void ManagerForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (needReFillRamData)
            {
                sqlData.FillRamData();
            }
            this.closeAction?.Invoke();
        }
Ejemplo n.º 2
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);
            }
        }