Files
zy-jjdj/Tool/SqlHelper.cs
2025-07-11 14:12:47 +08:00

166 lines
5.9 KiB
C#

using Model;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tool
{
public class SqlHelper
{
private ConnectionConfig connection2 = null;
public SqlSugarClient db2 = null;
private ConnectionConfig connection3 = null;
public SqlSugarClient db3 = null;
public SqlHelper()
{
string SqlIP2 = "192.168.2.2";
string SqlIP3 = "192.168.2.3";
string database = "MESDB";
string uid = "sa";
string pwd = "8ik,9ol.";
connection2 = new ConnectionConfig()
{
ConnectionString = "server='" + SqlIP2 + "';initial catalog='" + database + "';uid='" + uid + "';pwd='" + pwd + "'",
DbType = DbType.SqlServer,
IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute
};
db2 = new SqlSugarClient(connection2);
connection3 = new ConnectionConfig()
{
ConnectionString = "server='" + SqlIP3 + "';initial catalog='" + database + "';uid='" + uid + "';pwd='" + pwd + "'",
DbType = DbType.SqlServer,
IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute
};
db3 = new SqlSugarClient(connection3);
}
#region t_CMCC_Jinji
[SugarTable("t_CMCC_Jinji")]
public class t_CMCC_Jinji
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int id { get; set; }
public string type { get; set; }
public string snimei { get; set; }
public string inname { get; set; }
public DateTime? inTime { get; set; }
public string endname { get; set; }
public DateTime? endTime { get; set; }
}
#endregion
#region t_CMCC_JinjiPower
[SugarTable("t_CMCC_JinjiPower")]
public class t_CMCC_JinjiPower
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int id { get; set; }
public string type { get; set; }
public string snimei { get; set; }
public string Devcode { get; set; }
public string Band { get; set; }
public string Channel { get; set; }
public string Result { get; set; }
public string kind { get; set; }
public string textname { get; set; }
public string Powername { get; set; }
public DateTime? PowerTime { get; set; }
}
#endregion
#region t_CMCC_JinjiLine
[SugarTable("t_CMCC_JinjiLine")]
public class t_CMCC_JinjiLine
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int id { get; set; }
/// <summary>
/// 机型
/// </summary>
public string type { get; set; }
/// <summary>
/// 金机编码
/// </summary>
public string snimei { get; set; }
/// <summary>
/// 夹具号
/// </summary>
public string Devcode { get; set; }
/// <summary>
/// 类别
/// </summary>
public string kind { get; set; }
/// <summary>
/// 第几项线损
/// </summary>
public string several_line_loss { get; set; }
public string LTE_BAND_TX_LOW_LOSS { get; set; }
public string LTE_BAND_TX_MID_LOSS { get; set; }
public string LTE_BAND_TX_HIGH_LOSS { get; set; }
public string LTE_BAND_RX_LOW_LOSS { get; set; }
public string LTE_BAND_RX_MID_LOSS { get; set; }
public string LTE_BAND_RX_HIGH_LOSS { get; set; }
/// <summary>
/// 线损文件名称
/// </summary>
public string textname { get; set; }
/// <summary>
/// 录入人员名称
/// </summary>
public string Linename { get; set; }
/// <summary>
/// 录入时间
/// </summary>
public DateTime? LineTime { get; set; }
}
#endregion
#region t_DD_UserDetail
[SugarTable("t_DD_UserDetail")]
public class t_DD_UserDetail
{
/// <summary>
/// 姓名
/// </summary>
public string username { get; set; }
/// <summary>
/// 工号
/// </summary>
public string jobnumber { get; set; }
/// <summary>
/// 公司
/// </summary>
public string companyName { get; set; }
/// <summary>
/// 部门
/// </summary>
public string workPlace { get; set; }
/// <summary>
/// 职位
/// </summary>
public string position { get; set; }
}
#endregion
public UserModel GetUser(string jobnumber)
{
try
{
var userModel = db2.Queryable<t_DD_UserDetail>().Where(it => it.jobnumber == jobnumber && it.companyName == "重庆盟讯电子科技有限公司").First();
if (userModel == null)
{
return null;
}
return new UserModel() { userName = jobnumber, nickName = userModel.username, bumen = userModel.workPlace, zhiwei = userModel.position };
}
// return db.Queryable<t_DD_UserDetail>().Where(it => it.jobnumber == jobnumber && it.companyName == "重庆盟讯电子科技有限公司").First().username;
//}
catch (System.Exception ee)
{
LogHelper.WriteLog(ee.ToString());
throw ee;
}
}
}
}