265 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			265 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System;
 | |
| using System.Data;
 | |
| using System.Data.SqlClient;
 | |
| using System.Collections;
 | |
| using System.Collections.Generic;
 | |
| using AIMSModel;
 | |
| using AIMSObjectQuery;
 | |
| using System.Text;
 | |
| using DrawGraph;
 | |
| 
 | |
| namespace AIMSDAL
 | |
| {
 | |
|     internal partial class DFactEvents
 | |
|     {
 | |
|         internal static int DeleteById(string factEventsId)
 | |
|         {
 | |
|             using (SqlConnection conn = new SqlConnection(Connection.ConnectionString))
 | |
|             {
 | |
|                 conn.Open();
 | |
|                 using (SqlCommand cmd = conn.CreateCommand())
 | |
|                 {
 | |
|                     cmd.Parameters.Clear();
 | |
|                     cmd.CommandText = "delete from FactEvents where Id=@Id";
 | |
|                     //从实体中取出值放入Command的参数列表
 | |
|                     cmd.Parameters.Add(new SqlParameter("@Id", factEventsId));
 | |
|                     return cmd.ExecuteNonQuery();
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         public static void Add(FactEvents model)
 | |
|         {
 | |
| 
 | |
|             StringBuilder strSql = new StringBuilder();
 | |
|             StringBuilder strSql1 = new StringBuilder();
 | |
|             StringBuilder strSql2 = new StringBuilder();
 | |
|             if (model.EventTypeId != null)
 | |
|             {
 | |
|                 strSql1.Append("EventTypeId,");
 | |
|                 strSql2.Append("" + model.EventTypeId + ",");
 | |
|             }
 | |
|             if (model.PatientId != null)
 | |
|             {
 | |
|                 strSql1.Append("PatientId,");
 | |
|                 strSql2.Append("" + model.PatientId + ",");
 | |
|             }
 | |
|             if (model.EventId != null)
 | |
|             {
 | |
|                 strSql1.Append("EventId,");
 | |
|                 strSql2.Append("" + model.EventId + ",");
 | |
|             }
 | |
|             if (model.EventBeginTime != null)
 | |
|             {
 | |
|                 strSql1.Append("EventBeginTime,");
 | |
|                 strSql2.Append("'" + model.EventBeginTime + "',");
 | |
|             }
 | |
|             if (model.EventEndTime != null)
 | |
|             {
 | |
|                 strSql1.Append("EventEndTime,");
 | |
|                 strSql2.Append("'" + model.EventEndTime + "',");
 | |
|             }
 | |
|             if (model.IsContinue != null)
 | |
|             {
 | |
|                 strSql1.Append("IsContinue,");
 | |
|                 strSql2.Append("" + model.IsContinue + ",");
 | |
|             }
 | |
|             if (model.Remark != null)
 | |
|             {
 | |
|                 strSql1.Append("Remark,");
 | |
|                 strSql2.Append("'" + model.Remark + "',");
 | |
|             }
 | |
|             if (model.OperatorNo != null)
 | |
|             {
 | |
|                 strSql1.Append("OperatorNo,");
 | |
|                 strSql2.Append("'" + model.OperatorNo + "',");
 | |
|             }
 | |
|             if (model.OperatorName != null)
 | |
|             {
 | |
|                 strSql1.Append("OperatorName,");
 | |
|                 strSql2.Append("'" + model.OperatorName + "',");
 | |
|             }
 | |
|             if (model.OperateDate != null)
 | |
|             {
 | |
|                 strSql1.Append("OperateDate,");
 | |
|                 strSql2.Append("'" + model.OperateDate + "',");
 | |
|             }
 | |
|             strSql.Append("insert into FactEvents(");
 | |
|             strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
 | |
|             strSql.Append(")");
 | |
|             strSql.Append(" values (");
 | |
|             strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
 | |
|             strSql.Append(")");
 | |
| 
 | |
| 
 | |
|             HelperDB.DbHelperSQL.ExecNonQuery(strSql.ToString());
 | |
|         }
 | |
| 
 | |
|         public static bool IsValid(int EventsId)
 | |
|         {
 | |
|             bool Temp = false;
 | |
|             string strSql = "  SELECT * FROM Events WHERE Id =" + EventsId + " and NAME NOT IN ('入室','手术开始','手术结束','出室') and IsValid=1";
 | |
|             DataTable dt = HelperDB.DbHelperSQL.GetDataTable(strSql.ToString());
 | |
|             if (dt.Rows.Count > 0)
 | |
|             {
 | |
|                 Temp = true;
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 Temp = false;
 | |
|             }
 | |
|             return Temp;
 | |
|         }
 | |
| 
 | |
|         //public static void Update(FactEvents model)
 | |
|         //{
 | |
|         //    StringBuilder strSql = new StringBuilder();
 | |
|         //    strSql.Append("update FactEvents set ");
 | |
|         //    if (model.EventTypeId != null)
 | |
|         //    {
 | |
|         //        strSql.Append("EventTypeId=" + model.EventTypeId + ",");
 | |
|         //    }
 | |
|         //    if (model.PatientId != null)
 | |
|         //    {
 | |
|         //        strSql.Append("PatientId=" + model.PatientId + ",");
 | |
|         //    }
 | |
|         //    if (model.EventId != null)
 | |
|         //    {
 | |
|         //        strSql.Append("EventId=" + model.EventId + ",");
 | |
|         //    }
 | |
|         //    if (model.EventBeginTime != null)
 | |
|         //    {
 | |
|         //        strSql.Append("EventBeginTime='" + model.EventBeginTime + "',");
 | |
|         //    }
 | |
|         //    if (model.EventEndTime != null)
 | |
|         //    {
 | |
|         //        strSql.Append("EventEndTime='" + model.EventEndTime + "',");
 | |
|         //    }
 | |
|         //    if (model.IsContinue != null)
 | |
|         //    {
 | |
|         //        strSql.Append("IsContinue=" + model.IsContinue + ",");
 | |
|         //    }
 | |
|         //    if (model.Remark != null)
 | |
|         //    {
 | |
|         //        strSql.Append("Remark='" + model.Remark + "',");
 | |
|         //    }
 | |
|         //    if (model.OperatorNo != null)
 | |
|         //    {
 | |
|         //        strSql.Append("OperatorNo='" + model.OperatorNo + "',");
 | |
|         //    }
 | |
|         //    if (model.OperatorName != null)
 | |
|         //    {
 | |
|         //        strSql.Append("OperatorName='" + model.OperatorName + "',");
 | |
|         //    }
 | |
|         //    if (model.OperateDate != null)
 | |
|         //    {
 | |
|         //        strSql.Append("OperateDate='" + model.OperateDate + "',");
 | |
|         //    }
 | |
|         //    int n = strSql.ToString().LastIndexOf(",");
 | |
|         //    strSql.Remove(n, 1);
 | |
|         //    strSql.Append(" where Id=" + model.Id + " ");
 | |
| 
 | |
|         //    HelperDB.DbHelperSQL.ExecNonQuery(strSql.ToString());
 | |
|         //}
 | |
| 
 | |
|         public static void Delete(int Id)
 | |
|         {
 | |
|             StringBuilder strSql = new StringBuilder();
 | |
|             strSql.Append("delete FactEvents ");
 | |
|             strSql.Append(" where Id=" + Id + "");
 | |
|             HelperDB.DbHelperSQL.ExecNonQuery(strSql.ToString());
 | |
|         }
 | |
| 
 | |
|         public static FactEvents GetModel(int Id)
 | |
|         {
 | |
|             StringBuilder strSql = new StringBuilder();
 | |
|             strSql.Append("select  top 1  ");
 | |
|             strSql.Append(" Id,EventTypeId,PatientId,EventId,EventBeginTime,EventEndTime,IsContinue,Remark,OperatorNo,OperatorName,OperateDate ");
 | |
|             strSql.Append(" from FactEvents ");
 | |
|             strSql.Append(" where Id=" + Id + " ");
 | |
|             FactEvents model = new FactEvents();
 | |
|             DataSet ds = HelperDB.DbHelperSQL.GetDataSet(strSql.ToString());
 | |
|             if (ds.Tables[0].Rows.Count > 0)
 | |
|             {
 | |
|                 if (ds.Tables[0].Rows[0]["Id"].ToString() != "")
 | |
|                 {
 | |
|                     model.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString());
 | |
|                 }
 | |
|                 if (ds.Tables[0].Rows[0]["EventTypeId"].ToString() != "")
 | |
|                 {
 | |
|                     model.EventTypeId = int.Parse(ds.Tables[0].Rows[0]["EventTypeId"].ToString());
 | |
|                 }
 | |
|                 if (ds.Tables[0].Rows[0]["PatientId"].ToString() != "")
 | |
|                 {
 | |
|                     model.PatientId = int.Parse(ds.Tables[0].Rows[0]["PatientId"].ToString());
 | |
|                 }
 | |
|                 if (ds.Tables[0].Rows[0]["EventId"].ToString() != "")
 | |
|                 {
 | |
|                     model.EventId = int.Parse(ds.Tables[0].Rows[0]["EventId"].ToString());
 | |
|                 }
 | |
|                 if (ds.Tables[0].Rows[0]["EventBeginTime"].ToString() != "")
 | |
|                 {
 | |
|                     model.EventBeginTime = DateTime.Parse(ds.Tables[0].Rows[0]["EventBeginTime"].ToString());
 | |
|                 }
 | |
|                 if (ds.Tables[0].Rows[0]["EventEndTime"].ToString() != "")
 | |
|                 {
 | |
|                     model.EventEndTime = DateTime.Parse(ds.Tables[0].Rows[0]["EventEndTime"].ToString());
 | |
|                 }
 | |
|                 if (ds.Tables[0].Rows[0]["IsContinue"].ToString() != "")
 | |
|                 {
 | |
|                     model.IsContinue = int.Parse(ds.Tables[0].Rows[0]["IsContinue"].ToString());
 | |
|                 }
 | |
|                 model.Remark = ds.Tables[0].Rows[0]["Remark"].ToString();
 | |
|                 model.OperatorNo = ds.Tables[0].Rows[0]["OperatorNo"].ToString();
 | |
|                 model.OperatorName = ds.Tables[0].Rows[0]["OperatorName"].ToString();
 | |
|                 if (ds.Tables[0].Rows[0]["OperateDate"].ToString() != "")
 | |
|                 {
 | |
|                     model.OperateDate = DateTime.Parse(ds.Tables[0].Rows[0]["OperateDate"].ToString());
 | |
|                 }
 | |
|                 return model;
 | |
|             }
 | |
|             return model;
 | |
|         }
 | |
| 
 | |
|         public static DataTable GetDataTable(int PatientId, int EventTypeId)
 | |
|         {
 | |
|             StringBuilder strSql = new StringBuilder();
 | |
|             strSql.Append("SELECT s.Id, e.Id AS EventId, e.Name AS EventName, s.EventBeginTime, s.EventEndTime, s.Remark, s.[OperatorNo],s.[OperatorName],s.[OperateDate]");
 | |
|             strSql.Append(" FROM FactEvents s LEFT JOIN Events e ON e.Id =s.EventId WHERE s.EventTypeId=" + EventTypeId + " AND s.PatientId=" + PatientId + "  ORDER BY s.EventBeginTime");
 | |
|             return HelperDB.DbHelperSQL.GetDataTable(strSql.ToString());
 | |
|         }
 | |
| 
 | |
|         public static bool IsExists(int EventTypeId, int PatientId, string Name)
 | |
|         {
 | |
|             string strSql = "SELECT * FROM FactEvents fe LEFT JOIN Events e ON e.Id =fe.EventId WHERE fe.EventTypeId=" + EventTypeId + " AND fe.PatientId=" + PatientId + " and  e.Name IN ('入室','出室','手术开始','手术结束') AND  e.Name IN ('" + Name + "')";
 | |
| 
 | |
|             DataTable dt = HelperDB.DbHelperSQL.GetDataTable(strSql.ToString());
 | |
| 
 | |
|             if (dt.Rows.Count > 0)
 | |
|             {
 | |
|                 return true;
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 return false;
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         public static string GetTitleEvent(int PatientId, int TypeId)
 | |
|         {
 | |
|             string Temp = "";
 | |
|             string strSql = "SELECT e.Name,fe.EventBeginTime FROM FactEvents fe LEFT JOIN Events e ON e.Id = fe.EventId " +
 | |
|                             "WHERE fe.EventTypeId = " + TypeId + " and fe.PatientId =" + PatientId + " AND  e.Name IN ('入室','出室','手术开始','手术结束') order by EventBeginTime ";
 | |
| 
 | |
|             DataTable dt = HelperDB.DbHelperSQL.GetDataTable(strSql);
 | |
| 
 | |
|             for (int i = 0; i < dt.Rows.Count; i++)
 | |
|             {
 | |
|                 Temp += "   " + dt.Rows[i]["Name"].ToString() + "  " + dt.Rows[i]["EventBeginTime"].ToString();
 | |
|             }
 | |
| 
 | |
|             return Temp;
 | |
|         }
 | |
|     }
 | |
| }
 |