Exemplo n.º 1
0
        public override async Task <SyncResult> Receive(Guid token)
        {
            try
            {
                EquipmentAssignment.Refresh();
                using (HttpClient client = new HttpClient())
                {
                    client.Init(token);

                    HttpResponseMessage response = await client.GetAsync($"api/EquipmentAssignments?companyId={Company.CurrentId}");

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

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

                        list.ForEach(x =>
                        {
                            string sql = $"insert EquipmentAssignment(CompanyId, EqpNum, EmpNum, AssignedDate, ReleasedDate, EarnGroup, EarnCode, inSync) " +
                                         $"values({x.CompanyId}, '{x.EqpNum}', {x.EmpNum}, {StrEx.StrOrNull(x.AssignedDate)}, {StrEx.StrOrNull(x.ReleasedDate)}, {StrEx.StrOrNull(x.EarnGroup)}, {StrEx.StrOrNull(x.EarnCode)}, 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
                });
            }
        }
Exemplo n.º 2
0
        public static bool CopyDataFromTemplate(int projectId, DateTime currDate, int currHeaderId)
        {
            var filtered = EquipmentTemplate.GetTemplate(projectId, currDate);

            if (filtered.Count > 0)
            {
                Project project = Project.GetProject(projectId);

                foreach (var src in filtered)
                {
                    Equipment equip    = GetEquipment(src.EqpNum);
                    Employee  employee = (equip.OwnerType == EnumOwnerType.Employee) ? EquipmentAssignment.GetEmployee(equip.EqpNum, currDate) : null;
                    var       pec      = ProjectEquipmentClass.GetProjectEquipmentClass(projectId, src.EquipClassCode);
                    SqlInsert(currHeaderId, src.EqpNum, employee?.EmpNum, null, null, null, null, null, project.Billable, 0, pec.BillCycle, null);
                }
                return(true);
            }

            return(false);
        }