129 lines
7.0 KiB
C#
129 lines
7.0 KiB
C#
using HelperDB;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.SqlClient;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace DrawGraph
|
|
{
|
|
public static partial class PhysioDataService
|
|
{
|
|
//Add Mothed Start
|
|
public static readonly string InsertSql = "INSERT PhysioData (PatientId, PhysioDataConfigId, RecordTime, Value )VALUES (@PatientId, @PhysioDataConfigId, @RecordTime, @Value )";
|
|
public static readonly string UpdateSql = "Update PhysioData set PatientId=@PatientId, PhysioDataConfigId=@PhysioDataConfigId, RecordTime=@RecordTime, Value=@Value where Id=@Id";
|
|
public static readonly string DeleteSql = "Delete FROM PhysioData where Id=@Id";
|
|
public static readonly string SelectSql = "Select * FROM PhysioData";
|
|
public static readonly string SelectSqlById = "Select * FROM PhysioData where Id =@Id";
|
|
public static int AddPhysioData(PhysioData physioData)
|
|
{
|
|
string sql = InsertSql;
|
|
SqlParameter[] para = new SqlParameter[]
|
|
{
|
|
new SqlParameter("@PatientId",physioData.PatientId), new SqlParameter("@PhysioDataConfigId",physioData.PhysioDataConfigId), new SqlParameter("@RecordTime",physioData.RecordTime), new SqlParameter("@Value",physioData.Value)
|
|
};
|
|
return DBHelper.ExecNonQuery(sql, para);
|
|
}
|
|
public static int UpdatePhysioData(PhysioData physioData)
|
|
{
|
|
string sql = UpdateSql;
|
|
SqlParameter[] para = new SqlParameter[]
|
|
{
|
|
new SqlParameter("@Id",physioData.Id), new SqlParameter("@PatientId",physioData.PatientId), new SqlParameter("@PhysioDataConfigId",physioData.PhysioDataConfigId), new SqlParameter("@RecordTime",physioData.RecordTime), new SqlParameter("@Value",physioData.Value)
|
|
};
|
|
return DBHelper.ExecNonQuery(sql, para);
|
|
}
|
|
public static int DelPhysioData(PhysioData physioData)
|
|
{
|
|
string sql = DeleteSql;
|
|
SqlParameter[] para = new SqlParameter[]
|
|
{
|
|
new SqlParameter("@Id",physioData.Id)
|
|
};
|
|
return DBHelper.ExecNonQuery(sql, para);
|
|
}
|
|
public static IList<PhysioData> GetAllList()
|
|
{
|
|
string sql = SelectSql;
|
|
return GetListBySql(sql);
|
|
}
|
|
|
|
public static void UpdatePhysioData(PhysioData oldphysioData, PhysioData newphysioData)
|
|
{
|
|
string sql = "update PhysioData set Value= '" + newphysioData.Value + "' where convert(varchar,RecordTime,120) >='" + oldphysioData.RecordTime.AddSeconds(-120).ToString("yyyy-MM-dd HH:mm:ss") + "' and convert(varchar,RecordTime,120) <='" + oldphysioData.RecordTime.AddSeconds(120).ToString("yyyy-MM-dd HH:mm:ss") + "' and PhysioDataConfigId=" + oldphysioData.PhysioDataConfigId + " and PatientId=" + oldphysioData.PatientId;
|
|
DBHelper.ExecNonQuery(sql);
|
|
}
|
|
|
|
|
|
public static void DelPhysioByValueData(PhysioData physioData)
|
|
{
|
|
string sql = "Delete FROM PhysioData where RecordTime between DATEADD( minute,-2,@RecordTime) and DATEADD( minute,2,@RecordTime) and PatientId=@PatientId and PhysioDataConfigId=@PhysioDataConfigId ";
|
|
SqlParameter[] para = new SqlParameter[]
|
|
{
|
|
new SqlParameter("@RecordTime",physioData.RecordTime),
|
|
new SqlParameter("@PatientId",physioData.PatientId),
|
|
new SqlParameter("@PhysioDataConfigId",physioData.PhysioDataConfigId)
|
|
};
|
|
DBHelper.ExecNonQuery(sql, para);
|
|
}
|
|
|
|
public static void DelPhysioasDataParameterID(DateTime RecordTime, DateTime EndTime, int PhysioParamID, int PatientId)
|
|
{
|
|
string sql = "Delete FROM PhysioData where RecordTime between DATEADD( ss,-59,@RecordTime) and DATEADD( ss,59,@EndTime) and PatientId=@PatientId and PhysioDataConfigId=@PhysioDataConfigId ";
|
|
SqlParameter[] para = new SqlParameter[]
|
|
{
|
|
new SqlParameter("@RecordTime",RecordTime),
|
|
new SqlParameter("@EndTime",EndTime),
|
|
new SqlParameter("@PatientId",PatientId),
|
|
new SqlParameter("@PhysioDataConfigId",PhysioParamID)
|
|
};
|
|
DBHelper.ExecNonQuery(sql, para);
|
|
}
|
|
public static PhysioData GetPhysioDataById(int Id)
|
|
{
|
|
string sql = SelectSqlById;
|
|
SqlParameter para = new SqlParameter("@Id", Id);
|
|
IList<PhysioData> list = GetListBySql(sql, para);
|
|
if (list.Count > 0)
|
|
return list[0];
|
|
else
|
|
return null;
|
|
}
|
|
|
|
|
|
public static int DeletePhysioDataByID(int operationId, DateTime startTime, DateTime endTime, double startValue, double endValue, params int[] PhysioId)
|
|
{
|
|
string sqlStr = "delete FROM PhysioData where PatientId = " + operationId + " and [RecordTime] >='" + startTime + "' and [RecordTime] <='" + endTime + "' and [Value] >='" + startValue + "' and [Value] <='" + endValue + "' ";
|
|
if (PhysioId != null && PhysioId.Length > 0) sqlStr += " and PhysioDataConfigId=" + PhysioId[0];
|
|
return DBHelper.ExecNonQuery(sqlStr);
|
|
}
|
|
private static IList<PhysioData> GetListBySql(string sql, params SqlParameter[] para)
|
|
{
|
|
IList<PhysioData> list = new List<PhysioData>();
|
|
using (SqlDataReader reader = DBHelper.GetReader(sql, para))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
PhysioData temp = new PhysioData();
|
|
|
|
temp.Id = DBHelper.GetInt(reader["Id"]);
|
|
temp.PatientId = DBHelper.GetInt(reader["PatientId"]);
|
|
temp.PhysioDataConfigId = DBHelper.GetInt(reader["PhysioDataConfigId"]);
|
|
temp.RecordTime = DBHelper.GetDateTime(reader["RecordTime"]);
|
|
temp.Value = DBHelper.GetDouble(reader["Value"]);
|
|
|
|
list.Add(temp);
|
|
}
|
|
reader.Close();
|
|
return list;
|
|
}
|
|
}
|
|
|
|
|
|
public static void DelectPhysioDataByID(int operationId, DateTime startTime, DateTime endTime, double startValue, double endValue, int PhysioDataConfigId)
|
|
{
|
|
string sqlStr = "delete FROM PhysioData where PhysioDataConfigId = " + PhysioDataConfigId + " and PatientId = " + operationId + " and [RecordTime] >='" + startTime + "' and [RecordTime] <='" + endTime + "' and [Value] >='" + startValue + "' and [Value] <='" + endValue + "' ";
|
|
DBHelper.ExecNonQuery(sqlStr);
|
|
}
|
|
}
|
|
} |