240 lines
8.7 KiB
C#
240 lines
8.7 KiB
C#
|
using HL_FristAidPlatform_Help;
|
|||
|
using HL_FristAidPlatform_IDataBase;
|
|||
|
using HL_FristAidPlatform_Models;
|
|||
|
using SqlSugar;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Data;
|
|||
|
|
|||
|
namespace HL_FristAidPlatform_DataBase
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 出院带药 V2.1版
|
|||
|
/// </summary>
|
|||
|
public class T_Service_ChestPain_OutDrugDetailDB : BaseDB, IT_Service_ChestPain_OutDrugDetail
|
|||
|
{
|
|||
|
public SqlSugarClient db = GetClient();
|
|||
|
|
|||
|
#region 增
|
|||
|
/// <summary>
|
|||
|
/// 新增
|
|||
|
/// </summary>
|
|||
|
/// <param name="model">实体</param>
|
|||
|
/// <returns></returns>
|
|||
|
public bool Add(T_Service_ChestPain_OutDrugDetail model)
|
|||
|
{
|
|||
|
return db.Insertable(model).ExecuteCommand() == 0 ? false : true;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 新增 仅更新赋值的字段
|
|||
|
/// </summary>
|
|||
|
/// <param name="model">实体类</param>
|
|||
|
/// <returns></returns>
|
|||
|
public int AddNotNullColumns(T_Service_ChestPain_OutDrugDetail model)
|
|||
|
{
|
|||
|
return db.Insertable(model).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 新增 仅更新赋值的字段
|
|||
|
/// 用于移动端
|
|||
|
/// </summary>
|
|||
|
/// <param name="model">实体类</param>
|
|||
|
/// <returns></returns>
|
|||
|
public int AddForApp(T_Service_ChestPain_OutDrugDetail model)
|
|||
|
{
|
|||
|
return db.Insertable(model).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 删
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 删除一条数据
|
|||
|
/// </summary>
|
|||
|
public bool Delete(long ID)
|
|||
|
{
|
|||
|
return db.Deleteable<T_Service_ChestPain_OutDrugDetail>(it => it.ID == ID).ExecuteCommand() == 0 ? false : true; ;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 逻辑删除
|
|||
|
/// </summary>
|
|||
|
/// <param name="model">实体类</param>
|
|||
|
/// <returns></returns>
|
|||
|
public int LogicalDelete(T_Service_ChestPain_OutDrugDetail model)
|
|||
|
{
|
|||
|
return db.Updateable(model).UpdateColumns(it => new { it.DeleteFlag, it.EditorID, it.Editor, it.EditTime }).Where(it => it.ID == model.ID).ExecuteCommand();
|
|||
|
//return db.Updateable(model).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
|
|||
|
//更新忽略null字段
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 删除
|
|||
|
/// 用于移动端
|
|||
|
/// </summary>
|
|||
|
/// <param name="model">实体类,ID必填</param>
|
|||
|
/// <returns></returns>
|
|||
|
public int DeleteForApp(T_Service_ChestPain_OutDrugDetail model)
|
|||
|
{
|
|||
|
return db.Updateable(model).UpdateColumns(it => new { it.DeleteFlag, it.EditorID, it.Editor, it.EditTime }).ExecuteCommand();
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 改
|
|||
|
/// <summary>
|
|||
|
/// 更新一条数据
|
|||
|
/// </summary>
|
|||
|
public bool Update(T_Service_ChestPain_OutDrugDetail model)
|
|||
|
{
|
|||
|
return db.Updateable(model).ExecuteCommand() == 0 ? false : true;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 仅更新赋值的字段
|
|||
|
/// </summary>
|
|||
|
/// <param name="model">实体类</param>
|
|||
|
/// <returns></returns>
|
|||
|
public int UpdateNotNullColumns(T_Service_ChestPain_OutDrugDetail model)
|
|||
|
{
|
|||
|
return db.Updateable(model).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 修改--仅更新赋值的字段
|
|||
|
/// 用于移动端
|
|||
|
/// </summary>
|
|||
|
/// <param name="model">实体类</param>
|
|||
|
/// <returns></returns>
|
|||
|
public int UpdateForApp(T_Service_ChestPain_OutDrugDetail model)
|
|||
|
{
|
|||
|
return db.Updateable(model).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 查
|
|||
|
/// <summary>
|
|||
|
/// 得到一个对象实体
|
|||
|
/// </summary>
|
|||
|
public T_Service_ChestPain_OutDrugDetail GetModel(long ID)
|
|||
|
{
|
|||
|
return db.Queryable<T_Service_ChestPain_OutDrugDetail>().First(it => it.ID == ID);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 得到一个对象实体
|
|||
|
/// 用于移动端
|
|||
|
/// </summary>
|
|||
|
/// <param name="id">患者编号</param>
|
|||
|
/// <param name="guid">GUID</param>
|
|||
|
/// <returns></returns>
|
|||
|
public TableModel<T_Service_ChestPain_OutDrugDetail> GetModelForApp(long id, string guid)
|
|||
|
{
|
|||
|
TableModel<T_Service_ChestPain_OutDrugDetail> t = new TableModel<T_Service_ChestPain_OutDrugDetail>();
|
|||
|
var listMode = db.Queryable<T_Service_ChestPain_OutDrugDetail>()
|
|||
|
.Where(it => it.DeleteFlag == 0)
|
|||
|
.WhereIF(id > 0, it => it.ID == id && it.DeleteFlag == 0)
|
|||
|
.WhereIF(!string.IsNullOrEmpty(guid), it => it.GUID == guid).ToList();
|
|||
|
|
|||
|
t.Code = 0;
|
|||
|
t.PageCount = listMode.Count;
|
|||
|
t.TotalNumber = listMode.Count;
|
|||
|
t.Data = listMode;
|
|||
|
t.Msg = "成功";
|
|||
|
return t;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 获得前几行数据
|
|||
|
/// </summary>
|
|||
|
/// <param name="pageIndex">起始页</param>
|
|||
|
/// <param name="pageSize">每页条数</param>
|
|||
|
/// <returns></returns>
|
|||
|
public TableModel<T_Service_ChestPain_OutDrugDetail> GetPageList(int pageIndex, int pageSize)
|
|||
|
{
|
|||
|
int total = 0;
|
|||
|
List<T_Service_ChestPain_OutDrugDetail> data = db.Queryable<T_Service_ChestPain_OutDrugDetail>().Where(it => it.DeleteFlag == 0).ToPageList(pageIndex, pageSize, ref total);
|
|||
|
TableModel<T_Service_ChestPain_OutDrugDetail> t = new TableModel<T_Service_ChestPain_OutDrugDetail>();
|
|||
|
t.Code = 0;
|
|||
|
t.PageCount = data.Count;
|
|||
|
t.TotalNumber = total;
|
|||
|
t.Data = data;
|
|||
|
t.Msg = "成功";
|
|||
|
return t;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 根据患者编号(GUID) 获取数据信息
|
|||
|
/// </summary>
|
|||
|
/// <param name="patientGuid">病人编号(GUID)</param>
|
|||
|
/// <returns></returns>
|
|||
|
public string GetByPatientGuid(string patientGuid)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
//case when 是为了将T_Base_PublicDictionary表中的药物类型与字典表里的类型相对应匹配
|
|||
|
string SqlStr = string.Format(@"SELECT a.*,(SELECT [TEXT] FROM T_Base_PublicDictionary WHERE Type=(CASE a.Type WHEN 1 THEN '4' WHEN 2 THEN '5' WHEN 3 THEN '6' WHEN 4 THEN '7' END) AND Value=a.Name) AS NameText FROM T_Service_ChestPain_OutDrugDetail a WHERE a.PatientGuid='{0}' AND a.DeleteFlag=0", patientGuid);
|
|||
|
|
|||
|
DataTable dt = db.Ado.GetDataTable(SqlStr);
|
|||
|
|
|||
|
return Help.DataTableToJsonStr(dt);
|
|||
|
}
|
|||
|
catch (Exception)
|
|||
|
{
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 根据患者编号(GUID) 获取数据信息
|
|||
|
/// 用于移动端
|
|||
|
/// </summary>
|
|||
|
/// <param name="patientGuid">病人编号(GUID)</param>
|
|||
|
/// <returns></returns>
|
|||
|
public string GetByPatientGuidForApp(string patientGuid)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
//case when 是为了将T_Base_PublicDictionary表中的药物类型与字典表里的类型相对应匹配
|
|||
|
string SqlStr = string.Format(@"SELECT a.*,(SELECT [TEXT] FROM T_Base_PublicDictionary WHERE Type=(CASE a.Type WHEN 1 THEN '4' WHEN 2 THEN '5' WHEN 3 THEN '6' WHEN 4 THEN '7' END) AND Value=a.Name) AS NameText FROM T_Service_ChestPain_OutDrugDetail a WHERE a.PatientGuid='{0}' AND a.DeleteFlag=0", patientGuid);
|
|||
|
|
|||
|
DataTable dt = db.Ado.GetDataTable(SqlStr);
|
|||
|
|
|||
|
return Help.DataTableToJsonStr(dt);
|
|||
|
}
|
|||
|
catch (Exception)
|
|||
|
{
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 逻辑删除 出院带药
|
|||
|
/// </summary>
|
|||
|
/// <param name="model"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public bool UpdateDelete(T_Service_ChestPain_OutDrugDetail model)
|
|||
|
{
|
|||
|
var oneClass = db.Queryable<T_Service_ChestPain_OutDrugDetail>().Where(i => i.GUID == model.GUID).First();
|
|||
|
if (oneClass != null)
|
|||
|
{
|
|||
|
//oneClass.DeleteFlag = model.DeleteFlag;
|
|||
|
//oneClass.Editor = model.Editor;
|
|||
|
//oneClass.EditorID = model.EditorID;
|
|||
|
//oneClass.EditTime = DateTime.Now;
|
|||
|
//return db.Updateable<T_Service_ChestPain_OutDrugDetail>().IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand() == 1 ? true : false;
|
|||
|
return db.Updateable(model).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand() == 0 ? false : true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|