Beispiel #1
0
        public static void SqlDelete(int id)
        {
            var curr = LemHeader.GetLogHeader(id);

            if (curr.MatchId != -1)
            {
                string sql = $"update LemHeader set deleted=1 where id={id}";
                MobileCommon.ExecuteNonQuery(sql);

                DeleteHistory.SqlInsert(DeleteHistory.LemHeader, curr.MatchId);

                var labourList = LabourTimeEntry.GetLabourEntryList(id);
                labourList.ForEach(x => LabourTimeEntry.DeleteEntry(x.Id));

                var equipList = EquipTimeEntry.GetEquipEntryList(id);
                equipList.ForEach(x => EquipTimeEntry.DeleteEntry(x.Id));

                var attachList = Attachment.GetAttachList(Attachment.LemHeaderId, id);
                attachList.ForEach(x => Attachment.DeleteAttach(DeleteHistory.LemHeaderAttach, x.RepositoryId));
            }
            else
            {
                SqlForceDelete(id);
            }
        }
Beispiel #2
0
        public static LabourTimeEntry GetLabourEntry(int id)
        {
            DataTable       table = MobileCommon.ExecuteDataAdapter($"select * from LabourTimeEntry where id={id} and companyId={Company.CurrentId}");
            LabourTimeEntry entry = table.Select().Select(r => new LabourTimeEntry(r)).Single();

            entry.GetDetailList();
            return(entry);
        }
Beispiel #3
0
        public static void DeleteEntry(int id)
        {
            LabourTimeEntry curr = LabourTimeEntry.GetLabourEntry(id);

            if (curr.MatchId != -1)
            {
                MobileCommon.ExecuteNonQuery($"update LabourTimeEntry set deleted=1 where id={id}");
                DeleteHistory.SqlInsert(DeleteHistory.LabourTimeEntry, curr.MatchId);
            }
            else
            {
                SqlForceDelete(id);
            }
        }
Beispiel #4
0
        public override void RollbackReceive()
        {
            if (new EnumTableSyncStatus[] { EnumTableSyncStatus.Receiving, EnumTableSyncStatus.CompleteReceive, EnumTableSyncStatus.ErrorInReceive }.Contains(SyncInfo.Status))
            {
                DataTable  table  = MobileCommon.ExecuteDataAdapter($"select Id from LabourTimeEntry where SyncStatus='{EnumRecordSyncStatus.Receiving}' and CompanyId={CompanyId}");
                List <int> idList = table.Select().ToList().Select(r => (int)r["Id"]).ToList();
                idList.ForEach(id => LabourTimeEntry.SqlForceDelete(id));

                string sql = $"update LabourTimeEntry set SyncStatus='{EnumRecordSyncStatus.NoSubmit}' where SyncStatus='{EnumRecordSyncStatus.Updating}' and CompanyId={CompanyId}";
                MobileCommon.ExecuteNonQuery(sql);

                UpdateStatus(EnumTableSyncStatus.ReadyToSync);
            }
        }
Beispiel #5
0
        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);
            }
        }
Beispiel #6
0
        public override void CommitReceive()
        {
            if (new EnumTableSyncStatus[] { EnumTableSyncStatus.Receiving, EnumTableSyncStatus.CompleteReceive }.Contains(SyncInfo.Status))
            {
                DataTable table      = MobileCommon.ExecuteDataAdapter($"select Id from LabourTimeEntry where SyncStatus='{EnumRecordSyncStatus.Updating}' and CompanyId={CompanyId}");
                var       deleteList = table.Select().ToList().Select(r => (int)r["Id"]).ToList();
                deleteList.ForEach(x => LabourTimeEntry.SqlForceDelete(x));

                table = MobileCommon.ExecuteDataAdapter($"select * from LabourTimeEntry where CompanyId={CompanyId} and SyncStatus='{EnumRecordSyncStatus.Receiving}'");
                List <LabourTimeEntry> list = table.Select().Select(r => new LabourTimeEntry(r)).ToList();

                foreach (var item in list)
                {
                    int    localHeaderId = (int)MobileCommon.ExecuteScalar($"select id from LemHeader where MatchId={item.HeaderId} and CompanyId={CompanyId} and Deleted=0 ");
                    string sql           = $"update LabourTimeEntry set SyncStatus='{EnumRecordSyncStatus.NoSubmit}', LogHeaderId={localHeaderId} where Id={item.Id}";
                    MobileCommon.ExecuteNonQuery(sql);
                }

                UpdateStatus(EnumTableSyncStatus.ReadyToSync);
            }
        }