public static bool CopyDataFromTemplate(int projectId, DateTime currDate, int currHeaderId) { var filtered = LabourTemplate.GetTemplate(projectId, currDate); if (filtered.Count > 0) { Project project = Project.GetProject(projectId); foreach (var src in filtered) { int entryId = SqlInsert(currHeaderId, src.EmpNum, null, null, null, null, null, project.Billable, false, src.WorkClassCode, null, null, null); foreach (var tc in TimeCode.SubList(TimeCode.EnumValueType.Hours)) { decimal?billRate = ProjectWorkClass.GetBillRate(projectId, tc.MatchId, src.WorkClassCode); LabourTimeDetail.SqlInsert(entryId, tc.MatchId, billRate, null, null); } foreach (var tc in TimeCode.SubList(TimeCode.EnumValueType.Dollars)) { LabourTimeDetail.SqlInsert(entryId, tc.MatchId, null, null, null); } } return(true); } return(false); }
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["clientMac"] = MobileCommon.MachineMac; query["contactId"] = LoginUser.CurrUser.MatchId.ToString(); HttpResponseMessage response = await client.GetAsync($"api/LabourTimeEntry?{query.ToString()}"); if (response.IsSuccessStatusCode) { UpdateStatus(EnumTableSyncStatus.Receiving); var list = await response.Content.ReadAsAsync <List <LabourTimeEntry> >(); list.ForEach(x => { BeforeReceiveRecord(x.MatchId); string sql = $"insert LabourTimeEntry(MatchId, CompanyId, LogHeaderId, EmpNum, ChangeOrderId, Level1Id, Level2Id, Level3Id, Level4Id, Billable, Manual, WorkClassCode, IncludedHours, TotalHours, BillAmount, SyncStatus, Deleted) " + $"values({x.MatchId}, {x.CompanyId}, {x.HeaderId}, {x.EmpNum}, {StrEx.ValueOrNull(x.ChangeOrderId)}, {StrEx.ValueOrNull(x.Level1Id)}, {StrEx.ValueOrNull(x.Level2Id)}, " + $"{StrEx.ValueOrNull(x.Level3Id)}, {StrEx.ValueOrNull(x.Level4Id)}, '{x.Billable}', '{x.Manual}', '{x.WorkClassCode}', {StrEx.ValueOrNull(x.IncludedHours)}, {StrEx.ValueOrNull(x.TotalHours)}, {StrEx.ValueOrNull(x.BillAmount)}, '{EnumRecordSyncStatus.Receiving}', 0); " + $"Select CAST(SCOPE_IDENTITY() AS INT);"; int entryId = Convert.ToInt32(MobileCommon.ExecuteScalar(sql)); foreach (var d in x.DetailList) { LabourTimeDetail.SqlInsert(entryId, d.TimeCodeId, d.BillRate, d.WorkHours, d.Amount); } }); 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 static bool CopyDataFromPrevDay(int projectId, DateTime currDate, int currHeaderId) { string sql = $"select top 1 id from LemHeader " + $"where LogDate<'{currDate.Date}' and ProjectID = {projectId} and CompanyId = {Company.CurrentId} and deleted = 0 " + $"order by LogDate desc"; object srcHeaderId = MobileCommon.ExecuteScalar(sql); if (srcHeaderId != null) { var srcList = GetLabourEntryList((int)srcHeaderId); foreach (var src in srcList) { int entryId = SqlInsert(currHeaderId, src.EmpNum, src.ChangeOrderId, src.Level1Id, src.Level2Id, src.Level3Id, src.Level4Id, src.Billable, src.Manual, src.WorkClassCode, src.IncludedHours, src.TotalHours, src.BillAmount); src.DetailList.ForEach(d => LabourTimeDetail.SqlInsert(entryId, d.TimeCodeId, d.BillRate, d.WorkHours, d.Amount)); } return(srcList.Any()); } return(false); }