示例#1
0
        public void WriteLogOP(string sFunID, string sFSubunID, string sFdesc, string sSql)
        {
            string sql = "insert into sys_log( FID, FDate, FUserID, FFunctionID, FSubFunctionID, FDescription, FMachineName, FIPAddress, FSQL) ";

            sql += " values(" + DocNoTool.GetTableID(_Loginer.DBName, "sys_log", "FID", _Loginer) + ",";
            if (_Loginer.DbType == DbAcessTyp.Oracle)
            {
                sql += "sysdate,";
            }
            else
            {
                sql += "getdate(),";
            }
            sql += _Loginer.Fid + "," + sFunID + "," + sFSubunID + ",'" + sFdesc + "','" + _Loginer.MachineName + "','" + _Loginer.IPAddress + "','" + sSql + "')";

            new DataBaseLayer(_Loginer.DBName).ExecuteSql(sql);
        }
示例#2
0
 /// <summary>
 /// 返回表的FID最大值,用于保存数据时获取Key的最大值
 /// </summary>
 /// <param name="sTableName"></param>
 /// <param name="sFieldID"></param>
 /// <returns></returns>
 public string GetTableID(string sTableName, string sFieldID)
 {
     return(DocNoTool.GetTableID(_Loginer.DBName, sTableName, sFieldID, _Loginer));
 }
示例#3
0
        /// <summary>
        /// 保存日志
        /// </summary>
        /// <param name="log"></param>
        private void WriteLog(LogDef log)
        {
            string sql1 = "";
            string sql2 = "";

            if (_Loginer.DbType == DbAcessTyp.SQLServer)
            {
                sql1 = "INSERT INTO sys_Log_Table(fid,GUID32 ,LogUser ,LogDate ,OPType ,DocNo ,TableName ,KeyFieldName,IsMaster) " +
                       "           VALUES (@fid,@GUID32,@LogUser,@LogDate,@OPType,@DocNo,@TableName,@KeyFieldName,@IsMaster)";
                sql2 = "INSERT INTO sys_Log_TableDtl (fid,GUID32,TableName,FieldName,OldValue,NewValue) VALUES(@fid,@GUID32,@TableName,@FieldName,@OldValue,@NewValue)";
            }
            else
            {
                sql1 = "INSERT INTO sys_Log_Table(fid,GUID32 ,LogUser ,LogDate ,OPType ,DocNo ,TableName ,KeyFieldName,IsMaster) " +
                       "           VALUES (:fid,:GUID32,:LogUser,:LogDate,:OPType,:DocNo,:TableName,:KeyFieldName,:IsMaster)";
                sql2 = "INSERT INTO sys_Log_TableDtl (fid,GUID32,TableName,FieldName,OldValue,NewValue) VALUES(:fid,:GUID32,:TableName,:FieldName,:OldValue,:NewValue)";
            }

            IDbConnection conn   = DataProvider.Instance.CreateConnection(_Loginer.DBName);
            IDbCommand    cmd    = null;
            IDbCommand    cmdDtl = null;

            try
            {
                if (_Loginer.DbType == DbAcessTyp.SQLServer)
                {
                    if (log.IsMaster == true) //注意! 只有主表才写入tb_Log表
                    {
                        cmd             = new SqlCommand();
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = sql1;
                        cmd.Connection  = conn;
                        SqlParameter spara = new SqlParameter("@fid", SqlDbType.VarChar);
                        spara.Value = DocNoTool.GetTableID(_Loginer.DBName, "sys_Log_Table", "fid", _Loginer);
                        cmd.Parameters.Add(spara);
                        spara       = new SqlParameter("@GUID32", SqlDbType.VarChar);
                        spara.Value = log.GUID32;
                        cmd.Parameters.Add(spara);
                        spara       = new SqlParameter("@LogUser", SqlDbType.VarChar);
                        spara.Value = log.LogUser;
                        cmd.Parameters.Add(spara);
                        spara       = new SqlParameter("@LogDate", SqlDbType.DateTime);
                        spara.Value = log.LogDate;
                        cmd.Parameters.Add(spara);
                        spara       = new SqlParameter("@OPType", SqlDbType.Int);
                        spara.Value = log.OPType;
                        cmd.Parameters.Add(spara);
                        spara       = new SqlParameter("@DocNo", SqlDbType.VarChar);
                        spara.Value = log.DocNo;
                        cmd.Parameters.Add(spara);
                        spara       = new SqlParameter("@TableName", SqlDbType.VarChar);
                        spara.Value = log.TableName;
                        cmd.Parameters.Add(spara);
                        spara       = new SqlParameter("@KeyFieldName", SqlDbType.VarChar);
                        spara.Value = log.KeyFieldName;
                        cmd.Parameters.Add(spara);
                        spara       = new SqlParameter("@IsMaster", SqlDbType.VarChar);
                        spara.Value = log.IsMaster ? "Y" : "N";
                        cmd.Parameters.Add(spara);

                        cmd.ExecuteNonQuery();
                    }

                    //log明细
                    foreach (LogDefDtl d in log.Details)
                    {
                        cmdDtl             = new SqlCommand();;
                        cmdDtl.CommandType = CommandType.Text;
                        cmdDtl.CommandText = sql2;
                        cmdDtl.Connection  = conn;
                        SqlParameter spara = new SqlParameter("@fid", SqlDbType.VarChar);
                        spara.Value = DocNoTool.GetTableID(_Loginer.DBName, "sys_Log_TableDtl", "fid", _Loginer);
                        cmdDtl.Parameters.Add(spara);
                        spara       = new SqlParameter("@GUID32", SqlDbType.VarChar);
                        spara.Value = d.GUID32;
                        cmdDtl.Parameters.Add(spara);
                        spara       = new SqlParameter("@TableName", SqlDbType.VarChar);
                        spara.Value = d.TableName;
                        cmdDtl.Parameters.Add(spara);
                        spara       = new SqlParameter("@FieldName", SqlDbType.VarChar);
                        spara.Value = d.FieldName;
                        cmdDtl.Parameters.Add(spara);
                        spara       = new SqlParameter("@OldValue", SqlDbType.VarChar);
                        spara.Value = d.OldValue;
                        cmdDtl.Parameters.Add(spara);
                        spara       = new SqlParameter("@NewValue", SqlDbType.VarChar);
                        spara.Value = d.NewValue;
                        cmdDtl.Parameters.Add(spara);
                        cmdDtl.ExecuteNonQuery();
                    }
                }
                else
                {
                    if (log.IsMaster == true) //注意! 只有主表才写入tb_Log表
                    {
                        cmd             = new OracleCommand();
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = sql1;
                        cmd.Connection  = conn;
                        OleDbParameter spara = new OleDbParameter("fid", OleDbType.VarChar);
                        spara.Value = DocNoTool.GetTableID(_Loginer.DBName, "sys_Log_Table", "fid", _Loginer);
                        cmd.Parameters.Add(spara);
                        spara       = new OleDbParameter("GUID32", OleDbType.VarChar);
                        spara.Value = log.GUID32;
                        cmd.Parameters.Add(spara);
                        spara       = new OleDbParameter("LogUser", OleDbType.VarChar);
                        spara.Value = log.LogUser;
                        cmd.Parameters.Add(spara);
                        spara       = new OleDbParameter("LogDate", OleDbType.Date);
                        spara.Value = log.LogDate;
                        cmd.Parameters.Add(spara);
                        spara       = new OleDbParameter("OPType", OleDbType.Integer);
                        spara.Value = log.OPType;
                        cmd.Parameters.Add(spara);
                        spara       = new OleDbParameter("DocNo", OleDbType.VarChar);
                        spara.Value = log.DocNo;
                        cmd.Parameters.Add(spara);
                        spara       = new OleDbParameter("TableName", OleDbType.VarChar);
                        spara.Value = log.TableName;
                        cmd.Parameters.Add(spara);
                        spara       = new OleDbParameter("KeyFieldName", OleDbType.VarChar);
                        spara.Value = log.KeyFieldName;
                        cmd.Parameters.Add(spara);
                        spara       = new OleDbParameter("IsMaster", OleDbType.VarChar);
                        spara.Value = log.IsMaster ? "Y" : "N";
                        cmd.Parameters.Add(spara);

                        cmd.ExecuteNonQuery();
                    }

                    //log明细
                    foreach (LogDefDtl d in log.Details)
                    {
                        cmdDtl             = new SqlCommand();;
                        cmdDtl.CommandType = CommandType.Text;
                        cmdDtl.CommandText = sql2;
                        cmdDtl.Connection  = conn;
                        OleDbParameter spara = new OleDbParameter("fid", OleDbType.VarChar);
                        spara.Value = DocNoTool.GetTableID(_Loginer.DBName, "sys_Log_TableDtl", "fid", _Loginer);
                        cmdDtl.Parameters.Add(spara);
                        spara       = new OleDbParameter("GUID32", OleDbType.VarChar);
                        spara.Value = d.GUID32;
                        cmdDtl.Parameters.Add(spara);
                        spara       = new OleDbParameter("TableName", OleDbType.VarChar);
                        spara.Value = d.TableName;
                        cmdDtl.Parameters.Add(spara);
                        spara       = new OleDbParameter("FieldName", OleDbType.VarChar);
                        spara.Value = d.FieldName;
                        cmdDtl.Parameters.Add(spara);
                        spara       = new OleDbParameter("OldValue", OleDbType.VarChar);
                        spara.Value = d.OldValue;
                        cmdDtl.Parameters.Add(spara);
                        spara       = new OleDbParameter("NewValue", OleDbType.VarChar);
                        spara.Value = d.NewValue;
                        cmdDtl.Parameters.Add(spara);
                        cmdDtl.ExecuteNonQuery();
                    }
                }
            }
            catch
            {
            }
        }