Esempio n. 1
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);
        }
Esempio n. 2
0
        public override async System.Threading.Tasks.Task <SyncResult> Receive(Guid token)
        {
            try
            {
                EquipmentTemplate.Refresh();
                using (HttpClient client = new HttpClient())
                {
                    client.Init(token);

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

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

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

                        list.ForEach(x =>
                        {
                            string sql = $"insert EquipmentTemplate(MatchId, CompanyId, ProjectId, EqpNum, EquipClassCode, StartDate, EndDate, InSync) " +
                                         $"values({x.MatchId}, {x.CompanyId}, {x.ProjectId}, {x.EqpNum}, '{x.EquipClassCode}', {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
                });
            }
        }