增加日志
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
using System.Data;
|
||||
using CliWrap;
|
||||
using DAL.New_Models;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.OutputCaching;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using NLog;
|
||||
using RestSharp;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
@@ -15,6 +18,252 @@ namespace UseSQLQueryData.Controllers
|
||||
public class ValuesController : ControllerBase
|
||||
{
|
||||
public static string SqlConnectionString = "server=WIN-061EVIHKD86\\BLW;database=CRICS;uid=sa;pwd=pass@123$%^;TrustServerCertificate=True;";
|
||||
//public static string SqlConnectionString = "Data Source=DESKTOP-DUNS5K7;Initial Catalog=RICS;User ID=sa;Password=123456;Trust Server Certificate=True";
|
||||
|
||||
public RicsContext db { get; set; }
|
||||
public IMemoryCache _memorycache { get; set; }
|
||||
public ValuesController(RicsContext context, IMemoryCache cache)
|
||||
{
|
||||
this.db = context;
|
||||
this._memorycache = cache;
|
||||
}
|
||||
public record hotelinfo
|
||||
{
|
||||
public string HotelID { get; set; }
|
||||
public string? HotelCode { get; set; }
|
||||
public string? HotelName { get; set; }
|
||||
}
|
||||
|
||||
public record hostinfo
|
||||
{
|
||||
public string ID { get; set; }
|
||||
public string HotelID { get; set; }
|
||||
public string RoomTypeID { get; set; }
|
||||
public string? RoomNumber { get; set; }
|
||||
public string? HostNumber { get; set; }
|
||||
public string? MAC { get; set; }
|
||||
}
|
||||
public record roomtype_info
|
||||
{
|
||||
public string ID { get; set; }
|
||||
public string HotelID { get; set; }
|
||||
public string? RoomTypeName { get; set; }
|
||||
}
|
||||
public record roomtype_modalinfo
|
||||
{
|
||||
public string ID { get; set; }
|
||||
public string RoomTypeID { get; set; }
|
||||
public string? ModalAddress { get; set; }
|
||||
public string? Type { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取酒店列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[OutputCache()]
|
||||
public async Task<ReturnInfo> GetHotelList()
|
||||
{
|
||||
ReturnInfo returnInfo = new ReturnInfo();
|
||||
//return returnInfo;
|
||||
try
|
||||
{
|
||||
using SqlConnection con = new SqlConnection(SqlConnectionString);
|
||||
con.Open();
|
||||
using SqlCommand sqlCommand = con.CreateCommand();
|
||||
|
||||
string sql = @"select ID,Code,Name from tb_Sys_Hotels where IsDeleted=0;";
|
||||
sqlCommand.CommandText = sql;
|
||||
SqlDataAdapter adapter = new SqlDataAdapter(sqlCommand);
|
||||
DataSet dataSet = new DataSet();
|
||||
adapter.Fill(dataSet);
|
||||
|
||||
DataTable dt = dataSet.Tables[0];
|
||||
List<hotelinfo> chaList = new List<hotelinfo>();
|
||||
if (dt != null && dt.Rows.Count > 0)
|
||||
{
|
||||
foreach (DataRow item in dt.Rows)
|
||||
{
|
||||
var id = item["ID"].ToString();
|
||||
var code = item["Code"].ToString();
|
||||
var Name = item["Name"].ToString();
|
||||
hotelinfo cha = new hotelinfo();
|
||||
cha.HotelID = id;
|
||||
cha.HotelCode = code;
|
||||
cha.HotelName = Name;
|
||||
chaList.Add(cha);
|
||||
}
|
||||
}
|
||||
returnInfo.isok = true;
|
||||
returnInfo.response = chaList;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
returnInfo.isok = false;
|
||||
returnInfo.message = ex.Message;
|
||||
}
|
||||
return returnInfo;
|
||||
}
|
||||
|
||||
[OutputCache()]
|
||||
public async Task<ReturnInfo> GetHostList()
|
||||
{
|
||||
ReturnInfo returnInfo = new ReturnInfo();
|
||||
//return returnInfo;
|
||||
try
|
||||
{
|
||||
using SqlConnection con = new SqlConnection(SqlConnectionString);
|
||||
con.Open();
|
||||
using SqlCommand sqlCommand = con.CreateCommand();
|
||||
|
||||
string sql = @"select ID,HotelID,RoomTypeID,RoomNumber,HostNumber,MAC from tb_Hosts where IsDeleted=0;";
|
||||
sqlCommand.CommandText = sql;
|
||||
SqlDataAdapter adapter = new SqlDataAdapter(sqlCommand);
|
||||
DataSet dataSet = new DataSet();
|
||||
adapter.Fill(dataSet);
|
||||
|
||||
DataTable dt = dataSet.Tables[0];
|
||||
List<hostinfo> chaList = new List<hostinfo>();
|
||||
if (dt != null && dt.Rows.Count > 0)
|
||||
{
|
||||
foreach (DataRow item in dt.Rows)
|
||||
{
|
||||
var id = item["ID"].ToString();
|
||||
var hid = item["HotelID"].ToString();
|
||||
var RoomTypeID = item["RoomTypeID"].ToString();
|
||||
var RoomNumber = item["RoomNumber"].ToString();
|
||||
var HostNumber = item["HostNumber"].ToString();
|
||||
var MAC = item["MAC"].ToString();
|
||||
hostinfo cha = new hostinfo();
|
||||
cha.ID = id;
|
||||
cha.HotelID = hid;
|
||||
cha.RoomTypeID = RoomTypeID;
|
||||
cha.RoomNumber = RoomNumber;
|
||||
cha.HostNumber = HostNumber;
|
||||
cha.MAC = MAC;
|
||||
chaList.Add(cha);
|
||||
}
|
||||
}
|
||||
returnInfo.isok = true;
|
||||
returnInfo.response = chaList;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
returnInfo.isok = false;
|
||||
returnInfo.message = ex.Message;
|
||||
}
|
||||
return returnInfo;
|
||||
}
|
||||
|
||||
[OutputCache()]
|
||||
public async Task<ReturnInfo> GetRoomType_Info()
|
||||
{
|
||||
ReturnInfo returnInfo = new ReturnInfo();
|
||||
try
|
||||
{
|
||||
using SqlConnection con = new SqlConnection(SqlConnectionString);
|
||||
con.Open();
|
||||
using SqlCommand sqlCommand = con.CreateCommand();
|
||||
|
||||
string sql = @"select ID,HotelID,Name from tb_RoomType where IsDeleted=0;";
|
||||
sqlCommand.CommandText = sql;
|
||||
SqlDataAdapter adapter = new SqlDataAdapter(sqlCommand);
|
||||
DataSet dataSet = new DataSet();
|
||||
adapter.Fill(dataSet);
|
||||
|
||||
DataTable dt = dataSet.Tables[0];
|
||||
List<roomtype_info> chaList = new List<roomtype_info>();
|
||||
if (dt != null && dt.Rows.Count > 0)
|
||||
{
|
||||
foreach (DataRow item in dt.Rows)
|
||||
{
|
||||
var id = item["ID"].ToString();
|
||||
var HotelID = item["HotelID"].ToString();
|
||||
var Name = item["Name"].ToString();
|
||||
roomtype_info cha = new roomtype_info();
|
||||
cha.HotelID = HotelID;
|
||||
cha.ID = id;
|
||||
cha.RoomTypeName = Name;
|
||||
chaList.Add(cha);
|
||||
}
|
||||
}
|
||||
returnInfo.isok = true;
|
||||
returnInfo.response = chaList;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
returnInfo.isok = false;
|
||||
returnInfo.message = ex.Message;
|
||||
}
|
||||
return returnInfo;
|
||||
}
|
||||
|
||||
[OutputCache()]
|
||||
[HttpPost()]
|
||||
public async Task<ReturnInfo> GetRoomType_ModalInfo([FromBody] List<int> RoomTypeIDList)
|
||||
{
|
||||
ReturnInfo returnInfo = new ReturnInfo();
|
||||
try
|
||||
{
|
||||
var parameters = string.Join(',', RoomTypeIDList);
|
||||
string sql = @$"select ID,RoomTypeID,ModalAddress,Type, Name from tb_RoomTypeModal WHERE RoomTypeID IN ({parameters});";
|
||||
//var sql = $"SELECT * FROM Products WHERE Id IN ({string.Join(",", parameters)})";
|
||||
//var qqq = await db.TbRoomTypeModals.Where(A => RoomTypeIDList.Contains<int>(A.RoomTypeId)).ToListAsync();
|
||||
//var qqq = await db.TbRoomTypeModals.Where(A=>A.RoomTypeId==1).ToListAsync();
|
||||
using SqlConnection con = new SqlConnection(SqlConnectionString);
|
||||
con.Open();
|
||||
using SqlCommand sqlCommand = con.CreateCommand();
|
||||
|
||||
sqlCommand.CommandText = sql;
|
||||
SqlDataAdapter adapter = new SqlDataAdapter(sqlCommand);
|
||||
DataSet dataSet = new DataSet();
|
||||
adapter.Fill(dataSet);
|
||||
|
||||
DataTable dt = dataSet.Tables[0];
|
||||
List<roomtype_modalinfo> chaList = new List<roomtype_modalinfo>();
|
||||
if (dt != null && dt.Rows.Count > 0)
|
||||
{
|
||||
foreach (DataRow item in dt.Rows)
|
||||
{
|
||||
var id = item["ID"].ToString();
|
||||
var RoomTypeID = item["RoomTypeID"].ToString();
|
||||
var ModalAddress = item["ModalAddress"].ToString();
|
||||
var Type = item["Type"].ToString();
|
||||
var Name = item["Name"].ToString();
|
||||
roomtype_modalinfo cha = new roomtype_modalinfo();
|
||||
cha.ID = id;
|
||||
cha.RoomTypeID = RoomTypeID;
|
||||
cha.Name = Name;
|
||||
cha.ModalAddress = ModalAddress;
|
||||
cha.Type = Type;
|
||||
chaList.Add(cha);
|
||||
}
|
||||
}
|
||||
|
||||
//List<roomtype_modalinfo> chaList = new List<roomtype_modalinfo>();
|
||||
//foreach (var item in qqq)
|
||||
//{
|
||||
|
||||
// roomtype_modalinfo cha = new roomtype_modalinfo();
|
||||
// cha.ID = item.Id.ToString();
|
||||
// cha.RoomTypeID = item.RoomTypeId.ToString();
|
||||
// cha.Name = item.Name;
|
||||
// cha.ModalAddress = item.ModalAddress;
|
||||
// cha.Type = item.Type.ToString();
|
||||
// chaList.Add(cha);
|
||||
//}
|
||||
returnInfo.isok = true;
|
||||
returnInfo.response = chaList;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
returnInfo.isok = false;
|
||||
returnInfo.message = ex.Message;
|
||||
}
|
||||
return returnInfo;
|
||||
}
|
||||
|
||||
//public static string SqlConnectionString = "Data Source=DESKTOP-DUNS5K7;Initial Catalog=CRICS;User ID=sa;Password=123456;Trust Server Certificate=True";
|
||||
public static Logger logger = LogManager.GetCurrentClassLogger();
|
||||
[HttpGet()]
|
||||
|
||||
Reference in New Issue
Block a user