using HelperDB; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; namespace DrawGraph { public class DBManage { public static DataTable GetDictDataTable(OperationRecord OpeRecord, string HelpCode, string _title, string PersonType, string SelPerson) { string strSql = ""; switch (_title) { case "人员": if (PersonType == "0") {//AND p.DepId='" + (OpeRecord as OperationRecord).DepartmentId + "' strSql = "SELECT top 10 p.Id,p.Name,p.No Code FROM Person p WHERE p.IsValid=1 AND p.PersonType ='医生'AND (p.Name LIKE '%" + HelpCode + "%' OR p.HelpCode LIKE '%" + HelpCode + "%' OR p.No LIKE '%" + HelpCode + "%') AND p.DepId='" + OpeRecord.DepartmentId + "' "; if (SelPerson != "") strSql += " AND p.Id not in (" + SelPerson + ") "; strSql += " order by PersonOrder asc"; } else if (PersonType == "1") { strSql = "SELECT top 10 p.Id,p.Name,p.No Code FROM Person p WHERE p.IsValid=1 AND p.PersonType like '%护士%' AND (p.Name LIKE '%" + HelpCode + "%' OR p.HelpCode LIKE '%" + HelpCode + "%' OR p.No LIKE '%" + HelpCode + "%')"; if (SelPerson != "") strSql += " AND p.Id not in (" + SelPerson + ") "; strSql += " order by PersonOrder asc"; } else if (PersonType == "2") { strSql = "SELECT top 10 p.Id,p.Name,p.No Code FROM Person p WHERE p.IsValid=1 AND p.PersonType ='麻醉医生' AND (p.Name LIKE '%" + HelpCode + "%' OR p.HelpCode LIKE '%" + HelpCode + "%' OR p.No LIKE '%" + HelpCode + "%')"; if (SelPerson != "") strSql += " AND p.Id not in (" + SelPerson + ") "; strSql += " order by PersonOrder asc"; } else if (PersonType == "3") { strSql = "SELECT top 10 p.Id,p.Name,p.No Code FROM Person p WHERE p.IsValid=1 AND p.PersonType ='手术室护士' AND (p.Name LIKE '%" + HelpCode + "%' OR p.HelpCode LIKE '%" + HelpCode + "%' OR p.No LIKE '%" + HelpCode + "%')"; if (SelPerson != "") strSql += " AND p.Id not in (" + SelPerson + ") "; strSql += " order by PersonOrder asc"; } else if (PersonType == "4") { strSql = "SELECT top 10 p.Id,p.Name,p.IcdCode Code FROM Operation p WHERE p.IsValid=1 AND (p.Name LIKE '%" + HelpCode + "%' OR p.HelpCode LIKE '%" + HelpCode + "%')"; if (SelPerson != "") strSql += " AND p.Id not in (" + SelPerson + ") "; } else if (PersonType == "5") { strSql = "SELECT top 10 p.Id,p.Name,p.IcdCode Code FROM Disease p WHERE p.IsValid=1 AND (p.Name LIKE '%" + HelpCode + "%' OR p.HelpCode LIKE '%" + HelpCode + "%')"; if (SelPerson != "") strSql += " AND p.Id not in (" + SelPerson + ") "; } break; case "手术": strSql = "SELECT top 20 p.Id,p.Name,p.IcdCode Code FROM Operation p WHERE p.IsValid=1 AND (p.Name LIKE '%" + HelpCode + "%' OR p.HelpCode LIKE '%" + HelpCode + "%' OR p.IcdCode LIKE '%" + HelpCode + "%')"; if (SelPerson != "") strSql += " AND p.Id not in (" + SelPerson + ") "; strSql += " order by UseRate desc"; break; case "诊断": strSql = "SELECT top 20 p.Id,p.Name,p.IcdCode Code FROM Disease p WHERE p.IsValid=1 AND (p.Name LIKE '%" + HelpCode + "%' OR p.HelpCode LIKE '%" + HelpCode + "%' OR p.IcdCode LIKE '%" + HelpCode + "%')"; if (SelPerson != "") strSql += " AND p.Id not in (" + SelPerson + ") "; strSql += " order by UseRate desc"; break; case "麻醉方式": strSql = "SELECT top 10 p.Id,p.Name,p.HelpCode Code FROM AnaesthesiaMethod p WHERE p.IsValid=1 AND (p.Name LIKE '%" + HelpCode + "%' OR p.HelpCode LIKE '%" + HelpCode + "%' )"; if (SelPerson != "") strSql += " AND p.Id not in (" + SelPerson + ") "; break; case "手术体位": strSql = "SELECT top 10 p.Id,p.Name,p.HelpCode Code FROM OperationBodyPosition p WHERE p.IsValid=1 AND (p.Name LIKE '%" + HelpCode + "%' OR p.HelpCode LIKE '%" + HelpCode + "%' )"; if (SelPerson != "") strSql += " AND p.Id not in (" + SelPerson + ") "; break; case "手术部位": strSql = "SELECT top 10 p.Id,p.Name,p.HelpCode Code FROM OperationPosition p WHERE p.IsValid=1 AND (p.Name LIKE '%" + HelpCode + "%' OR p.HelpCode LIKE '%" + HelpCode + "%' )"; if (SelPerson != "") strSql += " AND p.Id not in (" + SelPerson + ") "; break; default: strSql = "SELECT top 10 p.Id,p.Name,p.HelpCode Code FROM BasicDictionary p WHERE p.IsValid=1 and ParentId in(select Id from BasicDictionary where Name='" + _title + "') AND (p.Name LIKE '%" + HelpCode + "%' OR p.HelpCode LIKE '%" + HelpCode + "%' )"; if (SelPerson != "") strSql += " AND p.Id not in (" + SelPerson + ") "; break; } return HelperDB.DbHelperSQL.GetDataTable(strSql.ToString()); } public static int SetOperationRecordValue(object operationRecord, string propertyName, string value) { int i = 0; OperationRecord _operationRecord = operationRecord as OperationRecord; if (_operationRecord == null) return i; string[] items = propertyName.Split('.'); try { if (items.Length < 1) return i; //if (items.Length > 2) //{ // if (items[1] == "InstrumentList") // { // i += UpdateInstrumentList(items[2] + "='" + value + "' where Id= " + _operationRecord.Id); // } // if (items[1] == "OperationRecordInfo") // { // i += UpdateOperationRecordInfo(items[2] + "='" + value + "' where Id= " + _operationRecord.Id); // } //} //else //{ if (items[1] == "OperationDoctor") { i += AddPerson(_operationRecord, _operationRecord.OperationDoctor, 1); } else if (items[1] == "Assistant1") { i += AddPerson(_operationRecord, _operationRecord.Assistant1, 2); } else if (items[1] == "Assistant2") { i += AddPerson(_operationRecord, _operationRecord.Assistant2, 3); } else if (items[1] == "Assistant3") { i += AddPerson(_operationRecord, _operationRecord.Assistant3, 4); } else if (items[1] == "AnesthesiaDoctor") { i += AddPerson(_operationRecord, _operationRecord.AnesthesiaDoctor, 5); } else if (items[1] == "InstrumentNurse") { i += AddPerson(_operationRecord, _operationRecord.InstrumentNurse, 6); } else if (items[1] == "TourNurse") { i += AddPerson(_operationRecord, _operationRecord.TourNurse, 7); } else if (items[1] == "OrtherDoctorId") { i += AddPerson(_operationRecord, _operationRecord.OrtherDoctorId, 11); } else if (items[1] == "Operation") { i += AddOperation(_operationRecord, _operationRecord.Operation); } else if (items[1] == "Applyoperation") { i += AddApplyOperation(_operationRecord, _operationRecord.Applyoperation); } else if (items[1] == "Applydiagnose") { i += AddApplyDiagnose(_operationRecord, _operationRecord.Applydiagnose); } else if (items[1] == "AnaesthesiaMethodId") { i += AddAnaesthesiaMethod(_operationRecord, _operationRecord.AnaesthesiaMethodId); } else if (items[1] == "OperationSiteId") { i += AddOperationSite(_operationRecord, _operationRecord.OperationSiteId); } else if (items[1] == "Height" || items[1] == "Weight") { i += UpdatePatient(items[1] + "='" + value + "' where Id= " + _operationRecord.PatientId); } else { i += Update(items[1] + "='" + value + "' where Id= " + _operationRecord.Id); } //} } catch (Exception) { //PublicMethod.WriteLog(new Exception("回写数据出错:" + propertyName + " 值:" + value + " 错误:" + ex.Message)); } return i; } public static int Update(string sql) { string sqlStr = "update OperationRecord set " + sql; return DBHelper.ExecNonQuery(sqlStr); } public static int UpdatePatient(string sql) { string sqlStr = "update Oris_Patient set " + sql; return DBHelper.ExecNonQuery(sqlStr); } public static int UpdateInstrumentList(string sql) { string sqlStr = "update InstrumentList set " + sql; return DBHelper.ExecNonQuery(sqlStr); } public static int UpdateOperationRecordInfo(string sql) { string sqlStr = "update OperationRecordInfo set " + sql; return DBHelper.ExecNonQuery(sqlStr); } public static int AddPerson(OperationRecord _operationRecord, string Persons, int PersonDutyId) { int i = 0; if (Persons.Trim() == "" || Persons == ",") { DeletePerson(_operationRecord.PatientId.Value, PersonDutyId); i++; } else { DeletePerson(_operationRecord.PatientId.Value, PersonDutyId); i++; string[] Personstr = Persons.Split(','); foreach (string PersonId in Personstr) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into [FactPersonDuty]("); strSql.Append("PatientId,ApplyId,PersonDutyId,PersonId,OperatorNo,OperatorName,OperateDate"); strSql.Append(")"); strSql.Append(" values ("); strSql.Append("" + _operationRecord.PatientId + ","); strSql.Append("" + _operationRecord.OperationApplyId + ","); strSql.Append("" + PersonDutyId + ","); strSql.Append("" + PersonId + ","); strSql.Append("'" + AIMSExtension.PublicMethod.OperatorNo + "',"); strSql.Append("'" + AIMSExtension.PublicMethod.OperatorName + "',"); strSql.Append("'" + DateTime.Now + "'"); strSql.Append(")"); i += HelperDB.DbHelperSQL.ExecNonQuery(strSql.ToString()); } } return i; } public static int AddOperation(OperationRecord _operationRecord, string Operation) { int i = 0; if (Operation.Trim() == "" || Operation == ",") { DeleteOperation(_operationRecord.PatientId.Value); i++; } else { DeleteOperation(_operationRecord.PatientId.Value); i++; string[] Operationstr = Operation.Split(','); foreach (string OperationId in Operationstr) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into [FactOperationInfo]("); strSql.Append("PatientId,ApplyId,OperationId,OperatorNo,OperatorName,OperateDate,OperationName,LeftRemark,RightRemark"); strSql.Append(")"); strSql.Append(" values ("); strSql.Append("" + _operationRecord.PatientId + ","); strSql.Append("" + _operationRecord.OperationApplyId + ","); strSql.Append("" + OperationId + ","); strSql.Append("'" + AIMSExtension.PublicMethod.OperatorNo + "',"); strSql.Append("'" + AIMSExtension.PublicMethod.OperatorName + "',"); strSql.Append("'" + DateTime.Now + "',"); strSql.Append("'',");//" + FactOperationInfoObj.OperationName + " strSql.Append("'',");//" + FactOperationInfoObj.LeftRemark + " strSql.Append("''");//" + FactOperationInfoObj.RightRemark + " strSql.Append(")"); i += HelperDB.DbHelperSQL.ExecNonQuery(strSql.ToString()); } } return i; } public static int AddApplyOperation(OperationRecord _operationRecord, string Operation) { int i = 0; if (Operation.Trim() == "" || Operation == ",") { DeleteApplyOperation(_operationRecord.OperationApplyId.Value); i++; } else { DeleteApplyOperation(_operationRecord.OperationApplyId.Value); i++; string[] Operationstr = Operation.Split(','); foreach (string OperationId in Operationstr) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into [ApplyOperationInfo]("); strSql.Append("OperationApplyId,OperationId,OperatorNo,OperatorName,OperateDate,OperationName,LeftRemark,RightRemark"); strSql.Append(")"); strSql.Append(" values ("); strSql.Append("" + _operationRecord.OperationApplyId + ","); strSql.Append("" + OperationId + ","); strSql.Append("'" + AIMSExtension.PublicMethod.OperatorNo + "',"); strSql.Append("'" + AIMSExtension.PublicMethod.OperatorName + "',"); strSql.Append("'" + DateTime.Now + "',"); strSql.Append("'',");//" + FactOperationInfoObj.OperationName + " strSql.Append("'',");//" + FactOperationInfoObj.LeftRemark + " strSql.Append("''");//" + FactOperationInfoObj.RightRemark + " strSql.Append(")"); i += HelperDB.DbHelperSQL.ExecNonQuery(strSql.ToString()); } } return i; } public static int AddApplyDiagnose(OperationRecord _operationRecord, string Diagnose) { int i = 0; if (Diagnose.Trim() == "" || Diagnose == ",") { DeleteApplyDiagnose(_operationRecord.OperationApplyId.Value); i++; } else { DeleteApplyDiagnose(_operationRecord.OperationApplyId.Value); i++; string[] Diagnosestr = Diagnose.Split(','); foreach (string DiagnoseId in Diagnosestr) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into [ApplyDiagnoseInfo]("); strSql.Append("OperationApplyId,DiagnoseId,OperatorNo,OperatorName,OperateDate"); strSql.Append(")"); strSql.Append(" values ("); strSql.Append("" + _operationRecord.OperationApplyId + ","); strSql.Append("" + DiagnoseId + ","); strSql.Append("'" + AIMSExtension.PublicMethod.OperatorNo + "',"); strSql.Append("'" + AIMSExtension.PublicMethod.OperatorName + "',"); strSql.Append("'" + DateTime.Now + "'"); strSql.Append(")"); i += HelperDB.DbHelperSQL.ExecNonQuery(strSql.ToString()); } } return i; } public static int AddOperationSite(OperationRecord _operationRecord, string OperationSite) { int i = 0; if (OperationSite.Trim() == "" || OperationSite == ",") { DeleteOperationSite(_operationRecord.PatientId.Value); i++; } else { DeleteOperationSite(_operationRecord.PatientId.Value); i++; string[] Operationstr = OperationSite.Split(','); foreach (string OperationSiteId in Operationstr) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into [FactOperationBodyPosition]("); strSql.Append("PatientId,ApplyId,OperationBodyPositionId,OperatorNo,OperatorName,OperateDate"); strSql.Append(")"); strSql.Append(" values ("); strSql.Append("" + _operationRecord.PatientId + ","); strSql.Append("" + _operationRecord.OperationApplyId + ","); strSql.Append("" + OperationSiteId + ","); strSql.Append("'" + AIMSExtension.PublicMethod.OperatorNo + "',"); strSql.Append("'" + AIMSExtension.PublicMethod.OperatorName + "',"); strSql.Append("'" + DateTime.Now + "'"); strSql.Append(")"); i += HelperDB.DbHelperSQL.ExecNonQuery(strSql.ToString()); } } return i; } public static int AddAnaesthesiaMethod(OperationRecord _operationRecord, string AnaesthesiaMethod) { int i = 0; if (AnaesthesiaMethod.Trim() == "" || AnaesthesiaMethod == ",") { DeleteAnaesthesiaMethod(_operationRecord.PatientId.Value); i++; } else { DeleteAnaesthesiaMethod(_operationRecord.PatientId.Value); i++; string[] Operationstr = AnaesthesiaMethod.Split(','); foreach (string AnaesthesiaMethodId in Operationstr) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into [FactAnaesthesiaMethod]("); strSql.Append("PatientId,ApplyId,AnaesthesiaMethodId,OperatorNo,OperatorName,OperateDate"); strSql.Append(")"); strSql.Append(" values ("); strSql.Append("" + _operationRecord.PatientId + ","); strSql.Append("" + _operationRecord.OperationApplyId + ","); strSql.Append("" + AnaesthesiaMethodId + ","); strSql.Append("'" + AIMSExtension.PublicMethod.OperatorNo + "',"); strSql.Append("'" + AIMSExtension.PublicMethod.OperatorName + "',"); strSql.Append("'" + DateTime.Now + "'"); strSql.Append(")"); i += HelperDB.DbHelperSQL.ExecNonQuery(strSql.ToString()); } } return i; } public static void DeletePerson(int PatientId, int PersonDutyId) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete FactPersonDuty "); strSql.Append(" where PatientId=" + PatientId + " and PersonDutyId=" + PersonDutyId + ""); HelperDB.DbHelperSQL.ExecNonQuery(strSql.ToString()); } public static void DeleteApplyOperation(int OperationApplyId) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete ApplyOperationInfo "); strSql.Append(" where OperationApplyId=" + OperationApplyId + " "); HelperDB.DbHelperSQL.ExecNonQuery(strSql.ToString()); } public static void DeleteApplyDiagnose(int OperationApplyId) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete ApplyDiagnoseInfo "); strSql.Append(" where OperationApplyId=" + OperationApplyId + " "); HelperDB.DbHelperSQL.ExecNonQuery(strSql.ToString()); } public static void DeleteOperation(int PatientId) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete FactOperationInfo "); strSql.Append(" where PatientId=" + PatientId + " "); HelperDB.DbHelperSQL.ExecNonQuery(strSql.ToString()); } public static void DeleteOperationSite(int PatientId) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete FactOperationBodyPosition "); strSql.Append(" where PatientId=" + PatientId + " "); HelperDB.DbHelperSQL.ExecNonQuery(strSql.ToString()); } public static void DeleteAnaesthesiaMethod(int PatientId) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete FactAnaesthesiaMethod "); strSql.Append(" where PatientId=" + PatientId + " "); HelperDB.DbHelperSQL.ExecNonQuery(strSql.ToString()); } public static string GetDictionaryValuesById(string Ids, string DictionaryName) { if (Ids == null || Ids.Trim() == "") return ""; string Explain = ""; string sql = ""; switch (DictionaryName) { case "手术": sql = "select dbo.GetOperation('" + Ids + "') value"; break; case "CA人员": sql = "select dbo.GetPersons('" + Ids + "') value"; break; case "人员": sql = "select dbo.GetPersons('" + Ids + "') value"; break; case "诊断": sql = "select dbo.GetDisease('" + Ids + "') value"; break; case "麻醉方式": sql = "select dbo.GetAnaesthesiaMethod('" + Ids + "') value"; break; case "手术体位": sql = "select dbo.GetOperationBodyPosition('" + Ids + "') value"; break; default: sql = "select dbo.funBasicDictionary('" + Ids + "') value"; break; } if (sql != "") { object dt = DBHelper.ExecuteScalar(sql); if (dt != null) { Explain = dt.ToString(); } } return Explain; } } }