예제 #1
0
        public SysAdminInfo AdminLogin(SysAdmin admin)
        {
            var    adminInfo = new SysAdminInfo();
            string sql       = $"select * from dbo.AspNetUsers where [UserName]={admin.AdminName} and [Email]={admin.LoginPwd}";

            try
            {
                SqlDataReader objReader = SqlHelper.GetReader(sql);
                if (objReader.Read())
                {
                    adminInfo.Id       = Convert.ToInt64(objReader["UserName"].ToString());
                    adminInfo.UserName = objReader["UserName"].ToString();
                    adminInfo.Email    = objReader["Email"].ToString();
                    objReader.Close();
                }
                else
                {
                    admin = null;
                }
            }
            catch (Exception ex)
            {
                LogStoreHelper.WriteError(ex, $"SqlHelper.GetSingleResult error");
                throw ex;
            }
            return(adminInfo);
        }
예제 #2
0
        public static void ConsoleLog()
        {
            Logger logger = new LoggerConfiguration()
                            .MinimumLevel.Debug()
                            .WriteTo.Console()
                            .WriteTo.File(LogPath, rollingInterval: RollingInterval.Day)
                            .CreateLogger();

            // logger.Information("No one listens to me!");
            LogHelper.WriteInformation(null, "hello log!");
            LogStoreHelper.WriteInformation(null, "hello log!");
            int a = 10, b = 0;

            try
            {
                var log = $"Dividing {a} by {b}";
                LogHelper.WriteDebug(null, log);
                LogStoreHelper.WriteDebug(null, log);

                //  logger.Debug("Dividing {A} by {B}", a, b);
                Console.WriteLine(a / b);
            }
            catch (Exception ex)
            {
                // logger.Error(ex, "Something went wrong");
                LogHelper.WriteError(ex, "Something went wrong");
                LogStoreHelper.WriteError(ex, "Something went wrong");
            }

            // logger.CloseAndFlush();
        }
예제 #3
0
        public static object GetSingleResult(string sql)
        {
            SqlConnection conn = new SqlConnection(connString);
            SqlCommand    cmd  = new SqlCommand(sql, conn);

            try
            {
                conn.Open();
                return(cmd.ExecuteScalar());
            }
            catch (Exception ex)
            {
                LogStoreHelper.WriteError(ex, $"SqlHelper.GetSingleResult error");
                throw ex;
            }
            finally
            {
                conn.Close();
            }
        }
예제 #4
0
        public static SqlDataReader GetReader(string sql)
        {
            SqlConnection conn = new SqlConnection(connString);
            SqlCommand    cmd  = new SqlCommand(sql, conn);

            try
            {
                conn.Open();
                return(cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection));
            }
            catch (Exception ex)
            {
                conn.Close();
                LogStoreHelper.WriteError(ex, $"SqlHelper.GetSingleResult error");
                throw ex;
            }
            finally
            {
            }
        }
예제 #5
0
        public static int Update(string sql)
        {
            int           returnResult = 0;
            SqlConnection conn         = new SqlConnection(connString);
            SqlCommand    cmd          = new SqlCommand(sql, conn);

            try
            {
                conn.Open();
                returnResult = cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                LogStoreHelper.WriteError(ex, $"SqlHelper.Update error");
                throw ex;
            }
            finally
            {
                conn.Close();
                returnResult = -1;
            }
            return(returnResult);
        }