99 lines
		
	
	
		
			6.4 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			99 lines
		
	
	
		
			6.4 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 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.ValueString)
 | |
|                                   };
 | |
|             return DBHelper.ExecNonQuery(sql, para);
 | |
|         }
 | |
|         public static void AddPhysioDatas(List<PhysioData> physioData)
 | |
|         {
 | |
|             StringBuilder deleteStr = new StringBuilder();
 | |
|             StringBuilder insterStr = new StringBuilder();
 | |
|             foreach (var item in physioData)
 | |
|             {
 | |
|                 deleteStr.Append(" Delete FROM PhysioData where RecordTime ='" + item.RecordTime + "' and PatientId='" + item.PatientId + "' and PhysioDataConfigId='" + item.PhysioDataConfigId + "' ");
 | |
|                 insterStr.Append(" INSERT PhysioData (PatientId,  PhysioDataConfigId, RecordTime, Value )VALUES ('" + item.PatientId + "' , '" + item.PhysioDataConfigId + "' ,'" + item.RecordTime + "', '" + item.ValueString + "'  )");
 | |
|             }
 | |
|             DBHelper.ExecNonQuery(deleteStr.ToString());
 | |
|             DBHelper.ExecNonQuery(insterStr.ToString());
 | |
|         }
 | |
| 
 | |
|         public static void AddPhysioDatas2(List<PhysioData> physioData)
 | |
|         {
 | |
|             StringBuilder insterStr = new StringBuilder();
 | |
|             foreach (var item in physioData)
 | |
|             {
 | |
|                 insterStr.Append(" INSERT PhysioData (PatientId,  PhysioDataConfigId, RecordTime, Value )VALUES ('" + item.PatientId + "' , '" + item.PhysioDataConfigId + "' ,'" + item.RecordTime + "', '" + item.ValueString + "'  )");
 | |
|             }
 | |
|             if (insterStr.ToString() != "")
 | |
|                 DBHelper.ExecNonQuery(insterStr.ToString());
 | |
|         }
 | |
| 
 | |
|         public static void UpdatePhysioData(PhysioData oldphysioData, PhysioData newphysioData, string OperatorName)
 | |
|         {
 | |
|             string sql = "update PhysioData set Value= '" + newphysioData.ValueString + "' 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;
 | |
|             int value = DBHelper.ExecNonQuery(sql);
 | |
|             if (value == 0)
 | |
|             {
 | |
|                 string sql2 = "delete from PhysioData 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(sql2);
 | |
|                 AddPhysioData(newphysioData);
 | |
|             }
 | |
|             //InsertPhysioDataUpdate(oldphysioData, newphysioData, OperatorName);
 | |
| 
 | |
|         }
 | |
| 
 | |
|         public static void InsertPhysioDataUpdate(PhysioData oldphysioData, PhysioData newphysioData, string OperatorName)
 | |
|         {
 | |
|             StringBuilder sb = new StringBuilder();
 | |
|             sb.Append(string.Format(@" INSERT PhysioDataUpdate (PatientId, PhysioDataConfigId, RecordTime, OldParamValue,ParamValue,  OperatorName,OperatorTime)VALUES ({0},{1},'{2}','{3}','{4}','{5}','{6}')  ", newphysioData.PatientId, newphysioData.PhysioDataConfigId, newphysioData.RecordTime, oldphysioData.ValueString, newphysioData.ValueString, OperatorName, DateTime.Now));
 | |
|             DBHelper.ExecNonQuery(sb.ToString());
 | |
|         }
 | |
| 
 | |
|         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 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 ISNUMERIC([Value])=1 and convert(decimal, [Value]) >='" + startValue + "' and convert(decimal, [Value]) <='" + endValue + "'  ";
 | |
|             DBHelper.ExecNonQuery(sqlStr);
 | |
|         }
 | |
|     }
 | |
| } |