302 lines
11 KiB
C#
302 lines
11 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using dccdc.Models;
|
||
using Dapper;
|
||
using ZWL.Common;
|
||
using System.Web.UI.WebControls;
|
||
|
||
namespace dccdc.DAL
|
||
{
|
||
public class HarmfulFactorsMaintainDal
|
||
{
|
||
public List<HarmfulFactorsMaintainModel> GetAllList(string id, string stauts)
|
||
{
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
string param = "";
|
||
if (id != "")
|
||
{
|
||
param = " and id =@id";
|
||
}
|
||
if (stauts != "")
|
||
{
|
||
param += " and status=@stauts";
|
||
}
|
||
return conn.Query<HarmfulFactorsMaintainModel>("select * from harmful_factors_maintain where 1=1" + param, new { @id = id, @stauts = stauts }).ToList();
|
||
}
|
||
}
|
||
|
||
public int getCount(string key)
|
||
{
|
||
string sql = "select count(1) from dbo.harmful_factors_maintain where 1=1";
|
||
if (!string.IsNullOrEmpty(key))
|
||
{
|
||
sql += " and harmful_factor_name like @harmful_factor_name";
|
||
}
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
return conn.ExecuteScalar<int>(sql, new { harmful_factor_name = "%" + key + "%" });
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 根据有害因素名称查询IDs
|
||
/// </summary>
|
||
/// <param name="names"></param>
|
||
/// <returns></returns>
|
||
public string GetIdByNames(string names)
|
||
{
|
||
string ids = "";
|
||
if(string.IsNullOrEmpty(names))
|
||
return ids;
|
||
string sql = "select * from dbo.harmful_factors_maintain where harmful_factor_name in @harmful_factor_name";
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
List<HarmfulFactorsMaintainModel> al = conn.Query<HarmfulFactorsMaintainModel>(sql, new { harmful_factor_name = names.TrimStart(',').TrimEnd(',').Split(',') }).ToList();
|
||
if(al==null)
|
||
return ids;
|
||
foreach (var harmfulFactorsMaintainModel in al)
|
||
{
|
||
ids += harmfulFactorsMaintainModel.id + ",";
|
||
}
|
||
}
|
||
return ids;
|
||
}
|
||
|
||
public string getfactor_code(string harmfulid)
|
||
{
|
||
//throw new NotImplementedException();
|
||
string sql = "select code from harmful_factors_type_maintain where id=@harmfulid";
|
||
using (var conn = CommHelper.GetSqlConnection())
|
||
{
|
||
return conn.Query<string>(sql,new { harmfulid }).FirstOrDefault();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据有害因素名称获取有害因素列表
|
||
/// </summary>
|
||
/// <param name="page"></param>
|
||
/// <param name="pagesize"></param>
|
||
/// <param name="key"></param>
|
||
/// <returns></returns>
|
||
public List<HarmfulFactorsMaintainModel> getList(int page, int pagesize, string key)
|
||
{
|
||
//throw new NotImplementedException();
|
||
string sql = "select *,row_number() over(order by id desc) as rownum from harmful_factors_maintain where 1=1";
|
||
if (!string.IsNullOrEmpty(key))
|
||
{
|
||
sql += " and harmful_factor_name like @harmful_factor_name";
|
||
}
|
||
sql = "select * from (" + sql + ") t where t.rownum>(" + page + "-1)*" + pagesize + " and rownum<=" + page + "*" + pagesize;
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
return conn.Query<Models.HarmfulFactorsMaintainModel>(sql, new { harmful_factor_name = "%" + key + "%" }).ToList();
|
||
}
|
||
}
|
||
|
||
public object save(HarmfulFactorsMaintainModel hfm, ERPUser user)
|
||
{
|
||
//throw new NotImplementedException();
|
||
hfm.creator = user.TrueName;
|
||
hfm.create_time = DateTime.Now.ToString("yyyy-MM-dd");
|
||
string sql = "";
|
||
if (hfm.id == 0)
|
||
{
|
||
sql = @"INSERT INTO [dbo].[harmful_factors_maintain]
|
||
([code]
|
||
,[harmful_factor_name]
|
||
,[harmful_factor_type]
|
||
,[harmful_factor_type_name]
|
||
,[check_type]
|
||
,[check_type_maintain_id]
|
||
,[status_show_contraindicated]
|
||
,[status_show_occupationdisease]
|
||
,[status]
|
||
,[pinyin_code]
|
||
,[creator]
|
||
,[create_time]
|
||
)
|
||
VALUES
|
||
(@code
|
||
,@harmful_factor_name
|
||
,@harmful_factor_type
|
||
,@harmful_factor_type_name
|
||
,@check_type
|
||
,@check_type_maintain_id
|
||
,@status_show_contraindicated
|
||
,@status_show_occupationdisease
|
||
,@status
|
||
,@pinyin_code
|
||
,@creator
|
||
,@create_time)
|
||
";
|
||
}
|
||
else
|
||
{
|
||
sql = @"UPDATE [dbo].[harmful_factors_maintain]
|
||
SET [code]=@code,[harmful_factor_name] = @harmful_factor_name
|
||
,[harmful_factor_type]=@harmful_factor_type
|
||
,[harmful_factor_type_name]=@harmful_factor_type_name
|
||
,[check_type]=@check_type
|
||
,[check_type_maintain_id]=@check_type_maintain_id
|
||
,[status_show_contraindicated]=@status_show_contraindicated
|
||
,[status_show_occupationdisease]=@status_show_occupationdisease
|
||
,[status]=@status
|
||
,[pinyin_code]=@pinyin_code
|
||
|
||
WHERE id=@id
|
||
";
|
||
}
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
try
|
||
{
|
||
int c = conn.Execute(sql, hfm);
|
||
if (c > 0)
|
||
{
|
||
return new { State = 1, Message = "保存成功!" };
|
||
}
|
||
else
|
||
{
|
||
return new { State = 0, Message = "操作失败,请联系管理员!" };
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return new { State = 0, Message = ex.Message };
|
||
}
|
||
}
|
||
}
|
||
|
||
public List<HarmfulFactorsMaintainModel> GetAllTreeList(string yhyspy, string yhlbpy, string yhlbcode)
|
||
{
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
string param = "";
|
||
if (!string.IsNullOrEmpty(yhyspy))
|
||
{
|
||
param += " and a.pinyin_code=@yhyspy";
|
||
}
|
||
if (!string.IsNullOrEmpty(yhlbpy))
|
||
{
|
||
param += " and b.pinyin_code=@yhlbpy";
|
||
}
|
||
if (!string.IsNullOrEmpty(yhlbcode))
|
||
{
|
||
param += " and a.harmful_factor_type=@yhlbcode";
|
||
}
|
||
return conn.Query<HarmfulFactorsMaintainModel>("select a.* from harmful_factors_maintain a inner join harmful_factors_type_maintain b on a.harmful_factor_type=b.code where b.status='是' " + param, new { yhyspy = yhyspy, yhlbpy = yhlbpy, yhlbcode = yhlbcode }).ToList();
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据id删除有害因素
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <returns></returns>
|
||
public object del(string id)
|
||
{
|
||
string sql = @"delete harmful_factors_maintain where id=@id";
|
||
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
try
|
||
{
|
||
int c = conn.Execute(sql, new { id = id });
|
||
if (c > 0)
|
||
{
|
||
return new { State = 1, Message = "操作成功!" };
|
||
}
|
||
else
|
||
{
|
||
return new { State = 0, Message = "操作失败,请联系管理员!" };
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return new { State = 0, Message = ex.Message };
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据有害因素名称查询有害因素表,若不存在,先增加,再获取其id
|
||
/// 2023-10-31 xulu 因团检报告需求修改,直接手动输入有害因素、体检项目、目标疾病,暂时用不到此方法
|
||
/// </summary>
|
||
/// <param name="stringNames"></param>
|
||
/// <returns></returns>
|
||
public string GetIdsByNames(string stringNames)
|
||
{
|
||
string ids = "";
|
||
if (string.IsNullOrEmpty(stringNames))
|
||
return ids;
|
||
string names = stringNames.Replace('、', ',');
|
||
string[] arrNames = names.Split(',');
|
||
for(int i=0;i< arrNames.Length; i++)
|
||
{
|
||
string sql = "select * from dbo.harmful_factors_maintain where harmful_factor_name = '" + arrNames[i] +"'";
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
HarmfulFactorsMaintainModel al = conn.Query<HarmfulFactorsMaintainModel>(sql).FirstOrDefault();
|
||
if (al == null)
|
||
{
|
||
HarmfulFactorsMaintainModel harmful = new HarmfulFactorsMaintainModel();
|
||
harmful.harmful_factor_name = arrNames[i].ToString();
|
||
harmful.harmful_factor_type = "910";
|
||
harmful.harmful_factor_type_name = "其他危害因素";
|
||
harmful.check_type = "职业健康检查";
|
||
harmful.check_type_maintain_id = 2;
|
||
harmful.status_show_contraindicated = "是";
|
||
harmful.status_show_occupationdisease = "是";
|
||
harmful.status = "是";
|
||
harmful.code = "1";
|
||
harmful.pinyin_code = HanZi2PinYin.ConvertToPinYin(arrNames[i].ToString());
|
||
harmful.creator = "管理员";
|
||
harmful.create_time = DateTime.Now.ToString();
|
||
|
||
string sql1 = @"INSERT INTO [dbo].[harmful_factors_maintain]
|
||
([code],[harmful_factor_name]
|
||
,[harmful_factor_type]
|
||
,[harmful_factor_type_name]
|
||
,[check_type]
|
||
,[check_type_maintain_id]
|
||
,[status_show_contraindicated]
|
||
,[status_show_occupationdisease]
|
||
,[status]
|
||
,[pinyin_code]
|
||
,[creator]
|
||
,[create_time]
|
||
)
|
||
VALUES
|
||
(@code,@harmful_factor_name
|
||
,@harmful_factor_type
|
||
,@harmful_factor_type_name
|
||
,@check_type
|
||
,@check_type_maintain_id
|
||
,@status_show_contraindicated
|
||
,@status_show_occupationdisease
|
||
,@status
|
||
,@pinyin_code
|
||
,@creator
|
||
,@create_time)Select SCOPE_IDENTITY()
|
||
";
|
||
int id = conn.ExecuteScalar<int>(sql1, harmful);
|
||
ids += id.ToString()+",";
|
||
}
|
||
else
|
||
{
|
||
ids += al.id.ToString()+",";
|
||
}
|
||
}
|
||
}
|
||
|
||
return ids;
|
||
}
|
||
}
|
||
}
|