Beispiel #1
0
        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 System.Threading.Tasks.Task <SyncResult> Receive(Guid token)
        {
            try
            {
                LabourTemplate.Refresh();
                using (HttpClient client = new HttpClient())
                {
                    client.Init(token);

                    HttpResponseMessage response = await client.GetAsync($"api/LabourTemplates?companyId={CompanyId}");

                    if (response.IsSuccessStatusCode)
                    {
                        UpdateStatus(EnumTableSyncStatus.Receiving);

                        List <LabourTemplate> list = await response.Content.ReadAsAsync <List <LabourTemplate> >();

                        list.ForEach(x =>
                        {
                            string sql = $"insert LabourTemplate(MatchId, CompanyId, ProjectId, EmpNum, WorkClassCode, StartDate, EndDate, InSync)  " +
                                         $"values({x.MatchId}, {x.CompanyId}, {x.ProjectId}, {x.EmpNum}, '{x.WorkClassCode}', {StrEx.StrOrNull(x.StartDate)}, {StrEx.StrOrNull(x.EndDate)}, 1)";
                            MobileCommon.ExecuteNonQuery(sql);
                        });

                        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
                });
            }
        }