public int[] QueryPatientCount() { using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(iDB.DbFile)) { string SqlText = @"Select Count(1) From [Patient] p Where p.[BedDoctor]=? And p.[InhosStatus]=?"; SQLite.SQLiteCommand cmd = conn.CreateCommand(SqlText, iCommon.DoctorID, "正住院"); var MyPatientCount = cmd.ExecuteScalar <string>(); SqlText = @"Select Count(1) From [Patient] p Where p.[OfficeID]=? And p.[InhosStatus]=?"; cmd.CommandText = SqlText; cmd.ClearBindings(); cmd.Bind(iCommon.DeptID); cmd.Bind("正住院"); var OfficePatientCount = cmd.ExecuteScalar <string>(); SqlText = @"Select Count(1) From [DoctorPatients] dp Where dp.[DoctorID]=? And dp.[DPType]=?"; cmd.CommandText = SqlText; cmd.ClearBindings(); cmd.Bind(iCommon.DoctorID); cmd.Bind("值班病人"); var DutyPatientCount = cmd.ExecuteScalar <string>(); cmd.ClearBindings(); cmd.Bind(iCommon.DoctorID); cmd.Bind("近期病人"); var TodayPatientCount = cmd.ExecuteScalar <string>(); SqlText = @"Select Count(1) From [Patient] p Where p.[BedDoctor]=? And p.[InhosStatus]=?"; cmd.CommandText = SqlText; cmd.ClearBindings(); cmd.Bind(iCommon.DoctorID); cmd.Bind("已出院"); var LeavehosPatientCount = cmd.ExecuteScalar <string>(); SqlText = @"select count(1) from [iAdvice] ia Where ia.[AdviceType] not in (901001,901002,901003)"; cmd.ClearBindings(); cmd.CommandText = SqlText; var NoPharmAdviceCount = cmd.ExecuteScalar <string>(); SqlText = @"select count(1) from [iAdvice] ia Where ia.[AdviceType] in (901001,901002,901003)"; cmd.CommandText = SqlText; var PharmAdviceCount = cmd.ExecuteScalar <string>(); return(new int[] { Convert.ToInt32(MyPatientCount), Convert.ToInt32(OfficePatientCount), Convert.ToInt32(DutyPatientCount), Convert.ToInt32(TodayPatientCount), Convert.ToInt32(LeavehosPatientCount), Convert.ToInt32(NoPharmAdviceCount), Convert.ToInt32(PharmAdviceCount) }); } }
private EventArgs UpdateLocalData(SQLite.SQLiteConnection conn, string SqlDelete, string SqlInsert, List <Data.DataObject> DataList, string TableName, string PrimaryKey) { SQLite.SQLiteCommand cmdDelete = conn.CreateCommand(SqlDelete); SQLite.SQLiteCommand cmdInsert = conn.CreateCommand(SqlInsert); dynamic arg = null; if (TableName == "DoctorCheckLog") { arg = new CheckLogSyncEventArgs(); } foreach (Data.DataObject data in DataList) { cmdDelete.ClearBindings(); cmdInsert.ClearBindings(); cmdDelete.Bind(data.GetExtValue(PrimaryKey)); cmdDelete.ExecuteNonQuery(); if (data.GetExtValue("ChangeType") != "DELETE") { for (int d = 0; d < data.Data.Length - 1; d++) { cmdInsert.Bind(data.Data[d]); } cmdInsert.ExecuteNonQuery(); } if (TableName == "DoctorCheckLog") { arg.DCLID.Add(data.GetExtValue(PrimaryKey)); arg.InhosID.Add(data.GetExtValue("InhosID")); arg.ChangeType.Add(data.GetExtValue("ChangeType")); arg.MedicalLog.Add(data.GetExtBytes("MedicalLog")); arg.PhotoLog.Add(data.GetExtBytes("Photo")); } } return(arg); }
/// <summary> /// 保存本地设备所属科室信息 /// </summary> public void SaveLocalDeviceOffice(string DeviceID, List <string> OfficeIDs, List <string> OfficeNames) { using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(iDB.DbFile)) { conn.BeginTransaction(); try { string SqlText = @"Delete From [iDeviceOffice] Where [DeviceID]=?"; SQLite.SQLiteCommand cmd = conn.CreateCommand(SqlText, DeviceID); cmd.ExecuteNonQuery(); SqlText = @"Insert Into [iDeviceOffice] ([DOID],[DeviceID], [OfficeID],[OfficeName],[CreateDate]) Values (@1,@2,@3,@4,@5)"; cmd.CommandText = SqlText; for (int i = 0; i < OfficeIDs.Count; i++) { cmd.ClearBindings(); cmd.Bind(Guid.NewGuid().ToString()); cmd.Bind(DeviceID); cmd.Bind(OfficeIDs[i]); cmd.Bind(OfficeNames[i]); cmd.Bind(iCommon.DateNow); cmd.ExecuteNonQuery(); } conn.Commit(); } catch { conn.Rollback(); } } }
/// <summary> /// 从服务器同步有变化的数据到本地 /// </summary> /// <param name="ChangeTableList"></param> /// <returns></returns> private async Task <bool> SyncDataFromServer(List <Data.iTableChange> ChangeTableList, SQLite.SQLiteConnection conn, string IsInitData) { foreach (Data.iTableChange itc in ChangeTableList) { object Result = await RemoteExcute(new object[] { iCommon.DeviceID, itc.TableName, itc.PrimaryKey, IsInitData }); if (Result == null) { continue; } List <Data.DataObject> DataList = Deserialize <Data.DataObject>(Result as byte[]); if (DataList == null || DataList.Count == 0) { continue; } string SqlDelete = String.Format(@"Delete From {0} Where {1}=?", itc.TableName, itc.PrimaryKey); Data.DataObject bo = DataList[0]; string[] Fields = bo.FieldArray; string SqlInsert = "Insert Into " + itc.TableName + " ("; string txtParams = " ("; for (int i = 0; i < Fields.Length - 1; i++) { SqlInsert += Fields[i] + ","; txtParams += "?,"; } SqlInsert = SqlInsert.TrimEnd(','); txtParams = txtParams.TrimEnd(','); SqlInsert = SqlInsert + ") Values " + txtParams + ")"; conn.BeginTransaction(); try { SQLite.SQLiteCommand cmdDelete = conn.CreateCommand(SqlDelete); SQLite.SQLiteCommand cmdInsert = conn.CreateCommand(SqlInsert); foreach (Data.DataObject data in DataList) { cmdDelete.ClearBindings(); cmdInsert.ClearBindings(); cmdDelete.Bind(data.GetExtValue(itc.PrimaryKey)); cmdDelete.ExecuteNonQuery(); if (data.GetExtValue("ChangeType") != "DELETE") { for (int d = 0; d < data.Data.Length - 1; d++) { cmdInsert.Bind(data.Data[d]); } cmdInsert.ExecuteNonQuery(); } } conn.Delete(itc); conn.Insert(itc); bool isSaveSuccess = await SavePadSyncLog(iCommon.DeviceID, itc.TableName, itc.LastChangeDate); if (isSaveSuccess) { conn.Commit(); } else { conn.Rollback(); } } catch (Exception ex) { conn.Rollback(); } } return(true); }