public List <Attachment> GetSendList() { List <SyncCoreMatch> matchList = SyncCoreMatch.GetMatchList("LemHeader"); string linkIds = StrEx.GetIdListText(matchList.Select(x => x.SourceId).ToList()); string sql = $"select r.*, l.CompanyId, l.MatchId, l.ContextItem_ID, l.TableDotField, l.IdValue, l.Comment from CFS_FileRepository r join CFS_FileLink l on l.FileRepository_ID = r.ID " + $"where TableDotField='{Attachment.LemHeaderId}' and IdValue in ({linkIds}) and (SyncStatus='{EnumRecordSyncStatus.NoSubmit}' or SyncStatus is null)"; DataTable table = MobileCommon.ExecuteDataAdapter(sql); List <Attachment> listLem = table.Select().Select(r => new Attachment(r)).ToList(); listLem.ForEach(x => x.LinkMatchId = matchList.Single(m => m.SourceId == x.LinkMatchId).MatchId); matchList = SyncCoreMatch.GetMatchList("FieldPO"); linkIds = StrEx.GetIdListText(matchList.Select(x => x.SourceId).ToList()); sql = $"select r.*, l.CompanyId, l.MatchId, l.ContextItem_ID, l.TableDotField, l.IdValue, l.Comment from CFS_FileRepository r join CFS_FileLink l on l.FileRepository_ID = r.ID " + $"where TableDotField='{Attachment.FieldPOId}' and IdValue in ({linkIds}) and (SyncStatus='{EnumRecordSyncStatus.NoSubmit}' or SyncStatus is null)"; table = MobileCommon.ExecuteDataAdapter(sql); List <Attachment> listPo = table.Select().Select(r => new Attachment(r)).ToList(); listPo.ForEach(x => x.LinkMatchId = matchList.Single(m => m.SourceId == x.LinkMatchId).MatchId); listLem.AddRange(listPo); return(listLem); }
public List <EquipTimeEntry> GetSendList() // must after sent headers { List <SyncCoreMatch> matchList = SyncCoreMatch.GetMatchList("LemHeader"); string headerIds = StrEx.GetIdListText(matchList.Select(x => x.SourceId).ToList()); string sql = $"select * from EquipTimeEntry where LogHeaderId in ({headerIds}) and (SyncStatus='{EnumRecordSyncStatus.NoSubmit}' or SyncStatus is null) and Deleted=0"; DataTable table = MobileCommon.ExecuteDataAdapter(sql); List <EquipTimeEntry> list = table.Select().Select(r => new EquipTimeEntry(r)).ToList(); list.ForEach(x => x.HeaderId = matchList.Single(m => m.SourceId == x.HeaderId).MatchId); return(list); }
public override void CommitSend() { if (new EnumTableSyncStatus[] { EnumTableSyncStatus.Sending, EnumTableSyncStatus.CompleteSend }.Contains(SyncInfo.Status)) { DataTable table = MobileCommon.ExecuteDataAdapter($"select Id from LabourTimeEntry where CompanyId={CompanyId} and SyncStatus='{EnumRecordSyncStatus.Submiting}'"); var idList = table.Select().ToList().Select(r => (int)r["Id"]); foreach (int id in idList) { var match = SyncCoreMatch.GetMatch(TableName, id); MobileCommon.ExecuteNonQuery($"update LabourTimeEntry set MatchID={match.MatchId}, SyncStatus='{EnumRecordSyncStatus.Submitted}' where Id={id}"); } UpdateStatus(EnumTableSyncStatus.ReadyToSync); } }
public override void CommitSend() { if (new EnumTableSyncStatus[] { EnumTableSyncStatus.Sending, EnumTableSyncStatus.CompleteSend }.Contains(SyncInfo.Status)) { DataTable table = MobileCommon.ExecuteDataAdapter($"select FileRepository_ID from CFS_FileLink where SyncStatus='{EnumRecordSyncStatus.Submiting}' and CompanyID={CompanyId}"); var repoIdList = table.Select().Select(r => (int)r["FileRepository_ID"]); foreach (int repoId in repoIdList) { var match = SyncCoreMatch.GetMatch(TableName, repoId); MobileCommon.ExecuteNonQuery($"update CFS_FileLink set MatchID={match.MatchId}, SyncStatus='{EnumRecordSyncStatus.Submitted}' where FileRepository_ID={repoId}"); } UpdateStatus(EnumTableSyncStatus.ReadyToSync); } }
public List <LemAP> GetSendList() { new List <LemAP>(); List <SyncCoreMatch> matchList = SyncCoreMatch.GetMatchList("LemHeader"); string headerIds = StrEx.GetIdListText(matchList.Select(x => x.SourceId).ToList()); string sql = $"select * from LemAP where companyId={CompanyId} and LogHeaderId in ({headerIds}) and (SyncStatus='{EnumRecordSyncStatus.NoSubmit}' or SyncStatus is null)"; DataTable table = MobileCommon.ExecuteDataAdapter(sql); List <LemAP> list = table.Select().Select(r => new LemAP(r)).ToList(); list.ForEach(x => x.HeaderId = matchList.Single(m => m.SourceId == x.HeaderId).MatchId); list.ForEach(x => x.GetDetailList()); list.ForEach(x => x.DetailList.ForEach(d => d.LemAPId = x.MatchId)); return(list); }
public override void CommitSend() { if (new EnumTableSyncStatus[] { EnumTableSyncStatus.Sending, EnumTableSyncStatus.CompleteSend }.Contains(SyncInfo.Status)) { DataTable table = MobileCommon.ExecuteDataAdapter($"select Id from LemHeader where CompanyId={CompanyId} and SyncStatus='{EnumRecordSyncStatus.Submiting}'"); var idList = table.Select().ToList().Select(r => (int)r["Id"]); foreach (int id in idList) { var match = SyncCoreMatch.GetMatch(TableName, id); string sql = $"update LemHeader set SyncStatus='{EnumRecordSyncStatus.Submitted}', MatchID={match.MatchId}, LemNum='{match.SyncMatch}', EmailData=null, " + $"SubmitStatus='{(char)EnumSubmitStatus.Submitted}' where Id={id}"; MobileCommon.ExecuteNonQuery(sql); } UpdateStatus(EnumTableSyncStatus.ReadyToSync); } }
public override async Task <SyncResult> Send(Guid token, int syncId) { try { using (HttpClient client = new HttpClient()) { client.Init(token); UpdateStatus(EnumTableSyncStatus.Sending); SyncCoreMatch.SqlDelete(TableName); List <LabourTimeEntry> list = GetSendList(); var query = HttpUtility.ParseQueryString($"syncId={syncId}"); foreach (LabourTimeEntry item in list) { HttpResponseMessage response = await client.PostAsJsonAsync($"api/LabourTimeEntry?{query.ToString()}", item); if (response.IsSuccessStatusCode) { int matchId = await response.Content.ReadAsAsync <int>(); AfterSendRecord(item.Id); SyncCoreMatch.SqlInsert(TableName, item.Id, matchId); } else { throw new Exception($"Post Response StatusCode={response.StatusCode}"); } } UpdateStatus(EnumTableSyncStatus.CompleteSend); return(new SyncResult { Successful = true }); } } catch (Exception e) { UpdateStatus(EnumTableSyncStatus.ErrorInSend); return(new SyncResult { Successful = false, Task = TableName, Message = e.Message }); } }
public override async Task <SyncResult> Receive(Guid token) { try { using (HttpClient client = new HttpClient()) { client.Init(token); var query = HttpUtility.ParseQueryString(string.Empty); query["companyId"] = CompanyId.ToString(); query["syncId"] = CompanySyncProcess.GetSyncProcess(CompanyId, EnumSyncType.Core).SyncId.ToString(); HttpResponseMessage response = await client.GetAsync($"api/FieldPO?{query.ToString()}"); if (response.IsSuccessStatusCode) { UpdateStatus(EnumTableSyncStatus.Receiving); List <string[]> list = await response.Content.ReadAsAsync <List <string[]> >(); list.ForEach(x => { int matchId = int.Parse(x[0]); BeforeReceiveRecord(matchId); SyncCoreMatch.SqlUpdate(TableName, matchId, x[1]); }); UpdateStatus(EnumTableSyncStatus.CompleteReceive); return(new SyncResult { Successful = true }); } throw new Exception($"Response StatusCode={response.StatusCode}"); } } catch (Exception e) { UpdateStatus(EnumTableSyncStatus.ErrorInReceive); return(new SyncResult { Successful = false, Task = TableName, Message = e.Message }); } }
public override void CommitReceive() { if (new EnumTableSyncStatus[] { EnumTableSyncStatus.Receiving, EnumTableSyncStatus.CompleteReceive }.Contains(SyncInfo.Status)) { DataTable table = MobileCommon.ExecuteDataAdapter($"select Id from FieldPO where CompanyId={CompanyId} and SyncStatus='{EnumRecordSyncStatus.Updating}'"); var idList = table.Select().Select(r => (int)r["Id"]); foreach (int id in idList) { var match = SyncCoreMatch.GetMatch(TableName, id); if (match != null) { string sql = $"update FieldPO set SyncStatus='{EnumRecordSyncStatus.Submitted}', PONum='{match.SyncMatch}' where Id={id}"; MobileCommon.ExecuteNonQuery(sql); } } UpdateStatus(EnumTableSyncStatus.ReadyToSync); } }