//Check public bool FindDevice(string deviceid) { LoraPlatformEntities db = new LoraPlatformEntities(); Device data = new Device(); List <Device> datalist = db.Device.ToList(); try { foreach (var item in datalist) { if (deviceid == item.DeviceId) { data = item; } } } catch (Exception ex) { data = null; throw new Exception(ex.Message.ToString()); } finally { db.Dispose(); } bool result = (data == null); return(result); }
public List <ConnectTable> GetConnectTableList() { LoraPlatformEntities db = new LoraPlatformEntities(); List <ConnectTable> data = db.ConnectTable.OrderBy(model => model.DeviceId).ToList(); return(data); }
public bool ElderCheck(string name, string idcard) { LoraPlatformEntities db = new LoraPlatformEntities(); Elder data = new Elder(); try { data = db.Elder.Find(idcard); } catch (Exception ex) { data = null; throw new Exception(ex.Message.ToString()); } finally { db.Dispose(); } if (data != null) { if (data.Name == name) { return(true); } else { return(false); } } else { return(false); } }
public string EmailValidate(string account, string authcode) { LoraPlatformEntities db = new LoraPlatformEntities(); string validatestr = ""; Members ValidateMember = GetAccount(account); if (ValidateMember != null) { if (ValidateMember.AuthCode == authcode) { try { Members data = db.Members.Find(account); data.AuthCode = "true"; db.SaveChanges(); } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } finally { db.Dispose(); } validatestr = "信箱驗證成功,歡迎開始體驗LoraPlatform的各項服務!"; } else { validatestr = "驗證碼錯誤,請重新確認或再註冊一次!"; } } else { validatestr = "傳送資料錯誤,請重新確認或再註冊一次!"; } return(validatestr); }
public List <LoraData> GetHistory(string deviceid) { LoraPlatformEntities db = new LoraPlatformEntities(); List <LoraData> data = db.LoraData.Where(model => model.DeviceId == deviceid).Take(30).ToList(); return(data); }
public LoraData GetLoraData() { LoraPlatformEntities db = new LoraPlatformEntities(); LoraData data = new LoraData(); if (ConnectCheck()) { string DataString = serialPort1.ReadLine(); if (DataString == "NO_GPS\r") { data = null; } else { List <string> DataList = DataString.Split(',').ToList(); Device device = db.Device.Find(Convert.ToInt32(DataList[3])); data.DeviceId = device.DeviceId; data.Latitude = DataList[0]; data.Longitude = DataList[1]; data.Time = DateTime.Now; } db.Dispose(); } return(data); }
public bool ReadData(string deviceid) { LoraPlatformEntities db = new LoraPlatformEntities(); if (ConnectCheck()) { string DataString = serialPort1.ReadLine(); if (DataString == "NO_GPS\r") { return(false); } else { List <string> DataList = DataString.Split(',').ToList(); Device device = db.Device.Find(Convert.ToInt32(DataList[3])); if (device.DeviceId == deviceid) { return(true); } else { return(false); } } } else { return(false); } }
public Device GetDevice(int id) { LoraPlatformEntities db = new LoraPlatformEntities(); Device data = db.Device.Find(id); db.Dispose(); return(data); }
public List <Members> GetAccountList() { LoraPlatformEntities db = new LoraPlatformEntities(); List <Members> data = db.Members.ToList(); db.Dispose(); return(data); }
//Elder Service public void AddElder(Elder NewElder) { LoraPlatformEntities db = new LoraPlatformEntities(); db.Elder.Add(NewElder); db.SaveChanges(); db.Dispose(); }
//Connect Table public List <ConnectTable> GetConnectTable(string account) { LoraPlatformEntities db = new LoraPlatformEntities(); List <ConnectTable> data = db.ConnectTable.Where(model => model.Account == account).ToList(); db.Dispose(); return(data); }
public List <Device> SearchDevice(string idcard) { LoraPlatformEntities db = new LoraPlatformEntities(); List <Device> target = db.Device.Where(model => model.Elder == idcard).ToList(); db.Dispose(); return(target); }
public List <Elder> GetElderList() { LoraPlatformEntities db = new LoraPlatformEntities(); List <Elder> data = db.Elder.ToList(); db.Dispose(); return(data); }
public void DeleteConnect(int id) { LoraPlatformEntities db = new LoraPlatformEntities(); ConnectTable data = db.ConnectTable.Find(id); db.ConnectTable.Remove(data); db.SaveChanges(); db.Dispose(); }
public void UpdateDevice(int id, string idcard) { LoraPlatformEntities db = new LoraPlatformEntities(); Device data = db.Device.Find(id); data.Elder = idcard; db.SaveChanges(); db.Dispose(); }
public void AddTemporaryPassword(string account, string TemporaryPassword) { LoraPlatformEntities db = new LoraPlatformEntities(); Members data = db.Members.Find(account); data.Password = HashPassword(TemporaryPassword); db.SaveChanges(); db.Dispose(); }
public void AddValidateCode(string account, string ValidateCode) { LoraPlatformEntities db = new LoraPlatformEntities(); Members data = db.Members.Find(account); data.AuthCode = ValidateCode; db.SaveChanges(); db.Dispose(); }
//Device Service public List <Device> GetDeviceList() { LoraPlatformEntities db = new LoraPlatformEntities(); ConnectCheck(); List <Device> datalist = db.Device.ToList(); db.Dispose(); return(datalist); }
public void ChangePassword(string account, string newpassword) { LoraPlatformEntities db = new LoraPlatformEntities(); Members data = db.Members.Find(account); string changepassword = HashPassword(newpassword); data.Password = changepassword; data.AuthCode = "true"; db.SaveChanges(); db.Dispose(); }
public void AddConnect(string deviceid, string idcard, string account) { LoraPlatformEntities db = new LoraPlatformEntities(); ConnectTable data = new ConnectTable(); data.DeviceId = deviceid; data.Elder = idcard; data.Account = account; db.ConnectTable.Add(data); db.SaveChanges(); db.Dispose(); }
public void AddDevice(string idcard) { LoraPlatformEntities db = new LoraPlatformEntities(); Device data = new Device(); Elder wear = GetElder(idcard); data.Elder = wear.IdCard; data.ConnectState = "未連接"; data.DeviceId = Guid.NewGuid().ToString(); db.Device.Add(data); db.SaveChanges(); db.Dispose(); }
public void Register(Members member) { LoraPlatformEntities db = new LoraPlatformEntities(); member.Password = HashPassword(member.Password); try { db.Members.Add(member); db.SaveChanges(); } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } finally { db.Dispose(); } }
public void DeleteElder(string idcard) { LoraPlatformEntities db = new LoraPlatformEntities(); try { Elder data = db.Elder.Find(idcard); db.Elder.Remove(data); } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } finally { db.SaveChanges(); db.Dispose(); } }
public Elder GetElder(string idcard) { LoraPlatformEntities db = new LoraPlatformEntities(); Elder data = new Elder(); try { data = db.Elder.Find(idcard); } catch { data = null; } finally { db.Dispose(); } return(data); }
public void EditMember(string account, string name, string email, string phone) { LoraPlatformEntities db = new LoraPlatformEntities(); try { Members data = db.Members.Find(account); data.Name = name; data.Email = email; data.Phonenumber = phone; } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } finally { db.SaveChanges(); db.Dispose(); } }
public Members GetAccount(string account) { LoraPlatformEntities db = new LoraPlatformEntities(); Members data = new Members(); try { data = db.Members.Find(account); } catch (Exception ex) { data = null; throw new Exception(ex.Message.ToString()); } finally { db.Dispose(); } return(data); }
public void ConnectCheck() { LoraPlatformEntities db = new LoraPlatformEntities(); List <Device> datalist = db.Device.ToList(); foreach (var item in datalist) { Device target = db.Device.Find(item.Id); if (item.ConnectState != "未連接") { if (!lora.ReadData(item.DeviceId)) { target.ConnectState = "未連接"; db.SaveChanges(); } } } db.Dispose(); }
public void UpdateElder(Elder elder) { LoraPlatformEntities db = new LoraPlatformEntities(); try { Elder data = db.Elder.Find(elder.IdCard); data.Name = elder.Name; data.Birthday = elder.Birthday; data.Sex = elder.Sex; data.ContactPhone = elder.ContactPhone; db.SaveChanges(); } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } finally { db.Dispose(); } }
public void SaveLoraData() { LoraPlatformEntities db = new LoraPlatformEntities(); if (ConnectCheck()) { string DataString = serialPort1.ReadLine(); if (DataString != "NO_GPS\r") { LoraData data = new LoraData(); List <string> DataList = DataString.Split(',').ToList(); Device device = db.Device.Find(Convert.ToInt32(DataList[3])); device.ConnectState = "已連接"; device.ConnectTime = DateTime.Now; data.DeviceId = device.DeviceId; data.Latitude = DataList[0]; data.Longitude = DataList[1]; data.Time = DateTime.Now; db.LoraData.Add(data); db.SaveChanges(); db.Dispose(); } } }