using JLHHJSvr;
using JLHHJSvr.BLL;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System;
using System.Data;
using JLHHJSvr.Com.Model;

namespace JLHHJSvr.Helper
{
    internal sealed class LogHelper : HelperBase
    {
        /// <summary>
        /// 写日志(函数内截断超长字符)
        /// </summary>
        /// <param name="logType">日志类型char(50)</param>
        /// <param name="logDscrp">日志描述varchar(8000)</param>
        /// <param name="opEmp">操作用户名char(10)</param>
        /// <param name="useID">是否使用通用方法生成ID, 默认使用</param>
        public void SetSysoplog(string logType, string logDscrp, string opEmp, bool useID = true)
        {
            int logid;
            if (useID)
            {
                //logid = IDHelper.f_sys_scidentity(0, "Sys_oplog", "logid", id_cmd);
                logid = BllHelper.GetID(cmd, "Sys_oplog");
            }
            else
            {
                cmd.CommandText = "SELECT ISNULL(MAX(logid), 10) FROM sys_oplog";
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.Clear();
                logid = Convert.ToInt32(cmd.ExecuteScalar());
                logid = logid + 1;
            }
            cmd.CommandText = @"insert into sys_oplog
	                                        ( logid,
	                                        logtype,
	                                        dscrp,
	                                        optime,
	                                        opemp )
	                                        values ( @logid,
	                                        @arg_logtype,
	                                        @arg_dscrp,
	                                        getdate(),
	                                        @opemp )";
            cmd.Parameters.Clear();
            cmd.Parameters.AddWithValue("@logid", logid);
            cmd.Parameters.AddWithValue("@arg_logtype", logType.SubStringEx(50));
            cmd.Parameters.AddWithValue("@arg_dscrp", logDscrp.SubStringEx(8000));
            cmd.Parameters.AddWithValue("@opemp", opEmp.SubStringEx(10));
            cmd.ExecuteNonQuery();
        }

        public void SetSysoplog(Sys_oplog log)
        {
            SetSysoplog(log.Logtype, log.Dscrp, log.opemp);
        }
    }
}
