コード例 #1
0
        /// <summary>
        /// 写日志到数据库
        /// </summary>
        /// <param name="md"></param>
        public void ThreadLog(object obj)
        {
            SqlConnection conn2 = new SqlConnection(connStr);

            try
            {
                LogMod mod       = (LogMod)obj;
                string SQLString = "insert into ts_uidp_loginfo(ACCESS_TIME,USER_ID,USER_NAME,IP_ADDR,LOG_TYPE,LOG_CONTENT,REMARK,ALARM_LEVEL)"
                                   + " VALUES(@ACCESS_TIME, @USER_ID, @USER_NAME, @IP_ADDR, @LOG_TYPE, @LOG_CONTENT, @REMARK,@ALARM_LEVEL)";
                SqlParameter[] cmdParms = new SqlParameter[8];
                cmdParms[0] = new SqlParameter("@ACCESS_TIME", mod.ACCESS_TIME == null ? DateTime.Now : mod.ACCESS_TIME);
                cmdParms[1] = new SqlParameter("@USER_ID", mod.USER_ID == null ? "" : mod.USER_ID);
                cmdParms[2] = new SqlParameter("@USER_NAME", mod.USER_NAME == null ? "" : mod.USER_NAME);
                cmdParms[3] = new SqlParameter("@IP_ADDR", mod.IP_ADDR == null ? "" : mod.IP_ADDR);
                cmdParms[4] = new SqlParameter("@LOG_TYPE", mod.LOG_TYPE);
                cmdParms[5] = new SqlParameter("@LOG_CONTENT", mod.LOG_CONTENT == null ? "" : mod.LOG_CONTENT);
                cmdParms[6] = new SqlParameter("@REMARK", mod.REMARK == null ? "" : mod.REMARK);
                cmdParms[7] = new SqlParameter("@ALARM_LEVEL", mod.ALARM_LEVEL == null ? 1 : mod.ALARM_LEVEL);
                using (SqlCommand cmd = new SqlCommand(SQLString, conn2))
                {
                    cmd.Parameters.AddRange(cmdParms);
                    if (conn2.State != System.Data.ConnectionState.Open)
                    {
                        conn2.Open();
                    }
                    cmd.ExecuteNonQuery();//s返回受影响行数
                    conn2.Close();
                }
            }
            catch (SqlException e)
            {
                conn2.Close();
                throw e;
            }
        }
コード例 #2
0
        /// <summary>
        /// 关闭连接
        /// </summary>
        //public void Close()
        //{
        //    if (conn.State != System.Data.ConnectionState.Closed)
        //    {
        //        conn.Close();
        //    }
        //}
        public void Info(DateTime ACCESS_TIME, string USER_ID, string USER_NAME, string IP_ADDR, int LOG_TYPE, string LOG_CONTENT, string REMARK, int?ALARM_LEVEL)
        {
            LogMod mod = new LogMod();

            mod.ACCESS_TIME = ACCESS_TIME;
            mod.USER_ID     = USER_ID;
            mod.USER_NAME   = USER_NAME;
            mod.IP_ADDR     = IP_ADDR;
            mod.LOG_TYPE    = LOG_TYPE;
            mod.LOG_CONTENT = "执行了" + LOG_CONTENT + "方法";
            mod.REMARK      = REMARK;
            mod.ALARM_LEVEL = ALARM_LEVEL == null ? 1 : ALARM_LEVEL;
            //Thread thread = new Thread(ThreadLog);
            // thread.Start(mod);
            ThreadLog(mod);
        }
コード例 #3
0
ファイル: ClsSysLogOracle.cs プロジェクト: zpjune/WZGX_API
        /// <summary>
        /// 写日志到数据库
        /// </summary>
        /// <param name="md"></param>
        public void ThreadLog(object obj)
        {
            OracleConnection conn2 = new OracleConnection(connStr);

            try
            {
                LogMod mod = (LogMod)obj;
                //       string SQLString = "insert into ts_uidp_loginfo(ACCESS_TIME,USER_ID,USER_NAME,IP_ADDR,LOG_TYPE,LOG_CONTENT,REMARK,ALARM_LEVEL)"
                //+ " VALUES(@ACCESS_TIME, @USER_ID, @USER_NAME, @IP_ADDR, @LOG_TYPE, @LOG_CONTENT, @REMARK,@ALARM_LEVEL)".ToUpper();
                //       OracleParameter[] cmdParms = new OracleParameter[8];
                //       cmdParms[0] = new OracleParameter("@ACCESS_TIME", mod.ACCESS_TIME == null ? DateTime.Now : mod.ACCESS_TIME);
                //       cmdParms[1] = new OracleParameter("@USER_ID", mod.USER_ID == null ? "" : mod.USER_ID);
                //       cmdParms[2] = new OracleParameter("@USER_NAME", mod.USER_NAME == null ? "" : mod.USER_NAME);
                //       cmdParms[3] = new OracleParameter("@IP_ADDR", mod.IP_ADDR == null ? "" : mod.IP_ADDR);
                //       cmdParms[4] = new OracleParameter("@LOG_TYPE", mod.LOG_TYPE);
                //       cmdParms[5] = new OracleParameter("@LOG_CONTENT", mod.LOG_CONTENT == null ? "" : mod.LOG_CONTENT);
                //       cmdParms[6] = new OracleParameter("@REMARK", mod.REMARK == null ? "" : mod.REMARK);
                //       cmdParms[7] = new OracleParameter("@ALARM_LEVEL", mod.ALARM_LEVEL == null ? 1 : mod.ALARM_LEVEL);

                string sql = " INSERT INTO TS_UIDP_LOGINFO(ACCESS_TIME,USER_ID,USER_NAME,IP_ADDR,LOG_TYPE,LOG_CONTENT,REMARK,ALARM_LEVEL) VALUES(";
                sql += " TO_DATE('" + mod.ACCESS_TIME + "','yyyy-mm-dd hh24:mi:ss'),";
                sql += GetSQLStr(mod.USER_ID);
                sql += GetSQLStr(mod.USER_NAME);
                sql += GetSQLStr(mod.IP_ADDR);
                sql += mod.LOG_TYPE == null ? "null" : mod.LOG_TYPE + ",";
                sql += GetSQLStr(mod.LOG_CONTENT);
                sql += GetSQLStr(mod.REMARK);
                sql += mod.ALARM_LEVEL + ")";
                //if (conn.State != System.Data.ConnectionState.Open)
                //{
                //    conn = new OracleConnection(connStr);
                //    conn.Open();
                //}
                //using (OracleCommand cmd = new OracleCommand(SQLString, conn))
                //{
                //    OracleTransaction tran = conn.BeginTransaction();
                //    cmd.Parameters.AddRange(cmdParms);
                //    cmd.ExecuteNonQuery();//s返回受影响行数
                //    tran.Commit();
                //}


                using (OracleCommand cmd = new OracleCommand(sql, conn2))
                {
                    // MySqlTransaction tran = conn.BeginTransaction();
                    //cmd.Parameters.AddRange(cmdParms);
                    if (conn2.State != System.Data.ConnectionState.Open)
                    {
                        conn2.Open();
                    }
                    cmd.ExecuteNonQuery();//s返回受影响行数
                    conn2.Close();
                    // tran.Commit();
                }
            }
            catch (OracleException e)
            {
                conn2.Close();
                throw e;
            }
        }