Example #1
0
 public TblUpdate GetClientLastUpdate()
 {
     DateTime min = DateTime.Parse("2000/01/01");
     TblUpdate novalue = new TblUpdate()
     {
         LastActivityLogUpdate = min,
         LastClientUpdate = min,
         LastConsutantUpdate = min,
         LastInfoUpdate = min,
         LastUserPermissionUpdate = min,
         LocalActivityLogUpdate = min,
         LocalClientUpdate = min,
         LocalConsutantUpdate = min,
         LocalInfoUpdate = min,
         LocalUserUpdate = min
     };
     List<TblUpdate> u = new List<TblUpdate>();
     var conn = new System.Data.SqlServerCe.SqlCeConnection(connectionString);
     using (Sonartez_server db = new Sonartez_server(conn))
     {
         var q =
         from a in db.TblUpdate
         select a;
         u = q.ToList();
     }
     if (u.FirstOrDefault() != null)
     {
         if (u.FirstOrDefault().LastClientUpdate != null)
             return u.FirstOrDefault();
         else
             return novalue;
     }
     else
         return novalue;
 }
 /// <summary>
 /// Get SERVER TABLE LASTUPDATE TIME
 /// </summary>
 /// <returns></returns>
 public TblUpdate GetUpdateStatus()
 {
     TblUpdate u = new TblUpdate();
     using (Sonartez_server db = new Sonartez_server(connectionString))
     {
         var q =
         from a in db.TblUpdate
         select a;
         u = q.FirstOrDefault<TblUpdate>();
     }
     return u;
 }
Example #3
0
 partial void DeleteTblUpdate(TblUpdate instance);
Example #4
0
 partial void UpdateTblUpdate(TblUpdate instance);
Example #5
0
 partial void InsertTblUpdate(TblUpdate instance);
Example #6
0
        internal void ServiceUpdate(string baseHost)
        {
            //1 -  Lấy giờ
            TblUpdate lastUpdate = GetClientLastUpdate();

            //2 -  Kéo về
            var data = GetUpdateConsultants(baseHost, lastUpdate.LastConsutantUpdate.Value);

            //3 -  Cập Nhập
            if (data != null && data.Count() > 0)
            {
                // update

                foreach (var item in data)
                {
                    if (item.IsDeleted.Value == 0)
                    {
                        InsertOrUpdate(item);
                    }
                    else
                    {
                        Delete(item);
                    }
                }

            }

            //4 -  Lấy ra
            var postData = GetAll().Where(x => x.UpdateDate >= lastUpdate.LocalConsutantUpdate.Value).ToList();
            DateTime updateDate = DateTime.Now;

            //5 -  Đẩy lên
            var res = PostUpdateToServer(baseHost, postData);

            //6 -  Lưu giờ
            if (res.Success)
            {
                BBLUpdate upData = new BBLUpdate();
                TblUpdate u = upData.GetCurrent();
                if (u == null)
                {
                    u = new TblUpdate();
                    DateTime mindate = DateTime.Parse("2000/01/01");
                    u.LastActivityLogUpdate = mindate;
                    u.LastUserUpdate = mindate;
                    u.LastConsutantUpdate = res.UpdateDate;
                    u.LastInfoUpdate = mindate;
                    u.LastUserPermissionUpdate = mindate;
                    u.LastClientUpdate = mindate;

                    u.LocalClientUpdate = mindate;
                    u.LocalActivityLogUpdate = mindate;
                    u.LocalInfoUpdate = mindate;
                    u.LocalUserUpdate = mindate;
                    u.LocalConsutantUpdate = updateDate;
                }
                else
                {
                    u.LastConsutantUpdate = res.UpdateDate;

                    u.LocalConsutantUpdate = updateDate;
                }
                upData.Update(u);

            }
        }
Example #7
0
        static bool PostUpdateClients(string uri, DateTime date)
        {
            try
            {
                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri(uri);

                client.DefaultRequestHeaders.Accept.Add(
                   new MediaTypeWithQualityHeaderValue("application/json"));
                BBLClient clientData = new BBLClient();
                var postData = clientData.GetAll().Where(x => x.UpdateDate >= date);

                var response = client.PostAsJsonAsync("api/Update/UpdateClients", postData).Result;
                response.EnsureSuccessStatusCode();
                if (response.IsSuccessStatusCode)
                {
                    APIResult data = response.Content.ReadAsAsync<APIResult>().Result;
                    if (data.Success == true)
                    {
                        BBLUpdate upData = new BBLUpdate();
                        TblUpdate u = upData.GetCurrent();
                        if (u == null)
                        {
                            u = new TblUpdate();
                            DateTime mindate = DateTime.Parse("2000/01/01");
                            u.LastActivityLogUpdate = mindate;
                            u.LastClientUpdate = DateTime.Now;
                            u.LastConsutantUpdate = mindate;
                            u.LastInfoUpdate = mindate;
                            u.LastUserPermissionUpdate = mindate;
                            u.LastUserUpdate = mindate;
                        }
                        else {
                            u.LastClientUpdate = DateTime.Now;
                        }
                        upData.Update(u);
                    }
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception)
            {
                return false;
            }
        }