public override void RollbackReceive() { if (new EnumTableSyncStatus[] { EnumTableSyncStatus.Receiving, EnumTableSyncStatus.CompleteReceive, EnumTableSyncStatus.ErrorInReceive }.Contains(SyncInfo.Status)) { string sql = $"select Id from LemAP where SyncStatus='{EnumRecordSyncStatus.Receiving}' and CompanyId={CompanyId}"; DataTable table = MobileCommon.ExecuteDataAdapter(sql); List <int> idList = table.Select().ToList().Select(r => (int)r["Id"]).ToList(); idList.ForEach(id => LemAP.SqlForceDelete(id)); sql = $"update LemAP set SyncStatus='{EnumRecordSyncStatus.NoSubmit}' where SyncStatus='{EnumRecordSyncStatus.Updating}' and CompanyId={CompanyId}"; MobileCommon.ExecuteNonQuery(sql); UpdateStatus(EnumTableSyncStatus.ReadyToSync); } }
public static void Purge() { try { int?days = SystemInfo.Current.KeepDays; if (days is null || days == 0) { return; } DateTime purgeDate = DateTime.Today.AddDays(-days.Value); string sql = $"select id from LemHeader where LogStatus='{(char)EnumLogStatus.Billed}' and LogDate<'{purgeDate}'"; DataTable table = MobileCommon.ExecuteDataAdapter(sql); List <int> lemHeaderList = table.Select().ToList().Select(r => (int)r["id"]).ToList(); string lemHeaderListText = "0"; lemHeaderList.ForEach(id => lemHeaderListText += $",{id}"); MobileCommon.ExecuteNonQuery($"delete EquipTimeEntry where LogHeaderId in ({lemHeaderListText})"); table = MobileCommon.ExecuteDataAdapter($"select Id from LabourTimeEntry where LogHeaderId in ({lemHeaderListText})"); List <int> subIdList = table.Select().ToList().Select(r => (int)r["Id"]).ToList(); subIdList.ForEach(id => LabourTimeEntry.SqlForceDelete(id)); table = MobileCommon.ExecuteDataAdapter($"select FileRepository_ID from CFS_FileLink where IDValue in ({lemHeaderListText}) and TableDotField='{Attachment.LemHeaderId}'"); subIdList = table.Select().ToList().Select(r => (int)r["FileRepository_ID"]).ToList(); subIdList.ForEach(id => Attachment.SqlForceDelete(id)); MobileCommon.ExecuteNonQuery($"delete LemHeader where Id in ({lemHeaderListText})"); MobileCommon.ExecuteNonQuery($"delete DeleteHistory where SyncStatus='{EnumRecordSyncStatus.Submitted}' and TimeStamp<'{purgeDate}'"); sql = $"select id from FieldPO where SyncStatus='{EnumRecordSyncStatus.Submitted}' and PODate<'{purgeDate}'"; table = MobileCommon.ExecuteDataAdapter(sql); subIdList = table.Select().ToList().Select(r => (int)r["Id"]).ToList(); subIdList.ForEach(id => FieldPO.SqlDelete(id)); sql = $"select id from LemAP where SyncStatus='{EnumRecordSyncStatus.Submitted}' and InvoiceDate<'{purgeDate}'"; table = MobileCommon.ExecuteDataAdapter(sql); subIdList = table.Select().ToList().Select(r => (int)r["Id"]).ToList(); subIdList.ForEach(id => LemAP.SqlForceDelete(id)); } catch (Exception e) { ReportMessage?.Invoke(e.Message); } }