Exemple #1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (!CheckInput())
            {
                return;
            }
            bool flag = TestConn(sqlType);

            if (flag)
            {
                if (chkRem.Checked)
                {
                    DataSet ds = dal.GetList("IP='" + cboServer.Text.Trim() + "'");
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        dal.DeleteByCond("IP='" + cboServer.Text.Trim() + "'");
                    }
                    DbConnect model = new DbConnect();
                    model.CreateDate = DateTime.Now.ToString();
                    model.IP         = cboServer.Text.Trim();
                    model.Pwd        = DESEncryptHelper.Encrypt(txtPassword.Text.Trim(), "test332211");
                    model.User       = cboUser.Text.Trim();
                    model.Remark     = sqlType.ToString().ToLower();
                    dal.Add(model);
                }
                strConn = DESEncryptHelper.Encrypt(BuildConn(sqlType), "test332211");
                DBName  = txtDB.Text.Trim();
                MessageBox.Show("连接成功");
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show("测试连接失败");
            }
        }
Exemple #2
0
 private void cboServer_SelectedIndexChanged(object sender, EventArgs e)
 {
     DataRow[] drs = dt.Select("IP='" + cboServer.Text.Trim() + "'");
     if (drs.Length > 0)
     {
         cboUser.Text     = drs[0]["User"].ToString();
         txtPassword.Text = DESEncryptHelper.Decrypt(drs[0]["Pwd"].ToString(), "test332211");
     }
 }
Exemple #3
0
        /// <summary>
        /// 初始化日志表
        /// </summary>
        /// <param name="strExistsTbSql">判断日志表是否存在的sql语句</param>
        /// <param name="strTbName">表名</param>
        /// <param name="strDbName">数据库名</param>
        /// <returns></returns>
        private bool InitLogTable(string strExistsTbSql, string strTbName, string strDbName)
        {
            bool    flag    = true;
            string  strConn = DESEncryptHelper.Decrypt(txtConnection.Text.Trim(), "test332211");
            SqlType sqlType = SqlType.SQLite;

            if (cboLogType.Text == "sqlite")
            {
                sqlType = SqlType.SQLite;
            }
            else if (cboLogType.Text == "sqlserver")
            {
                sqlType = SqlType.SqlServer;
            }
            else if (cboLogType.Text == "mysql")
            {
                sqlType = SqlType.MySql;
            }

            IDbHelper dbHelper = LoggerHelper.GetDBHelper(sqlType, strConn);

            if (dbHelper != null)
            {
                dbHelper.CreateCommand(strExistsTbSql);
                int intResult = dbHelper.ExecuteQuery().Rows.Count;
                if (intResult > 0)
                {
                    if (MessageBox.Show("已经存在日志记录表" + strTbName + ",是否删除重新建立?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        string strDropTable = "DROP TABLE " + strTbName + "";
                        dbHelper.CreateCommand(strDropTable);
                        try
                        {
                            dbHelper.ExecuteNonQuery();
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("删除失败");
                            flag = false;
                        }
                        flag = DoCreateTable(dbHelper);
                    }
                }
                else
                {
                    flag = DoCreateTable(dbHelper);
                }
            }
            return(flag);
        }
Exemple #4
0
        /// <summary>获取日志存储库连接字符串
        ///
        /// </summary>
        /// <returns></returns>
        public static string GetConn()
        {
            string conn = string.Empty;

            if (!string.IsNullOrEmpty(StaticInfoHelper.ConnString))
            {
                conn = StaticInfoHelper.ConnString;
            }
            else
            {
                string strFilePath = Application.StartupPath + "\\log.ini";
                if (File.Exists(strFilePath))
                {
                    conn = INIOperationHelper.INIGetStringValue(strFilePath, "LogConnection", "Connection", null);
                    conn = DESEncryptHelper.Decrypt(conn, "test332211");
                    StaticInfoHelper.ConnString = conn;
                }
            }

            return(conn);
        }
Exemple #5
0
        /// <summary>创建本地配置文件
        /// 创建本地配置文件
        /// </summary>
        private void CreateIniFile()
        {
            string filePath = Application.StartupPath + "\\" + "Log.ini";

            if (!File.Exists(filePath))
            {
                File.Create(filePath).Close();
            }
            else
            {
                File.Delete(filePath);
                File.Create(filePath).Close();
            }
            if (cboLogType.Text.Trim().ToLower() == "sqlite")
            {
                INIOperationHelper.INIWriteValue(filePath, "LogConnection", "Connection", DESEncryptHelper.Encrypt("LogLocalDB", "test332211"));
            }
            else
            {
                INIOperationHelper.INIWriteValue(filePath, "LogConnection", "Connection", txtConnection.Text.Trim());
            }
            INIOperationHelper.INIWriteValue(filePath, "LogType", "Type", cboLogType.Text.Trim().ToLower() + "log");
        }