Example #1
0
        //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);
        }
Example #2
0
        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);
        }
Example #3
0
        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);
            }
        }
Example #4
0
        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);
        }
Example #5
0
        public List <Members> GetAccountList()
        {
            LoraPlatformEntities db   = new LoraPlatformEntities();
            List <Members>       data = db.Members.ToList();

            db.Dispose();
            return(data);
        }
Example #6
0
        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);
        }
Example #7
0
        //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);
        }
Example #8
0
        //Elder Service
        public void AddElder(Elder NewElder)
        {
            LoraPlatformEntities db = new LoraPlatformEntities();

            db.Elder.Add(NewElder);
            db.SaveChanges();
            db.Dispose();
        }
Example #9
0
        public Device GetDevice(int id)
        {
            LoraPlatformEntities db = new LoraPlatformEntities();
            Device data             = db.Device.Find(id);

            db.Dispose();
            return(data);
        }
Example #10
0
        public List <Elder> GetElderList()
        {
            LoraPlatformEntities db   = new LoraPlatformEntities();
            List <Elder>         data = db.Elder.ToList();

            db.Dispose();
            return(data);
        }
Example #11
0
        public void UpdateDevice(int id, string idcard)
        {
            LoraPlatformEntities db = new LoraPlatformEntities();
            Device data             = db.Device.Find(id);

            data.Elder = idcard;
            db.SaveChanges();
            db.Dispose();
        }
Example #12
0
        public void DeleteConnect(int id)
        {
            LoraPlatformEntities db   = new LoraPlatformEntities();
            ConnectTable         data = db.ConnectTable.Find(id);

            db.ConnectTable.Remove(data);
            db.SaveChanges();
            db.Dispose();
        }
Example #13
0
        public void AddValidateCode(string account, string ValidateCode)
        {
            LoraPlatformEntities db = new LoraPlatformEntities();
            Members data            = db.Members.Find(account);

            data.AuthCode = ValidateCode;
            db.SaveChanges();
            db.Dispose();
        }
Example #14
0
        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();
        }
Example #15
0
        //Device Service
        public List <Device> GetDeviceList()
        {
            LoraPlatformEntities db = new LoraPlatformEntities();

            ConnectCheck();
            List <Device> datalist = db.Device.ToList();

            db.Dispose();
            return(datalist);
        }
Example #16
0
        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();
        }
Example #17
0
        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();
        }
Example #18
0
        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();
        }
Example #19
0
        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();
            }
        }
Example #20
0
        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);
        }
Example #21
0
        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();
            }
        }
Example #22
0
        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();
            }
        }
Example #23
0
        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);
        }
Example #24
0
        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();
        }
Example #25
0
        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();
            }
        }
Example #26
0
        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();
                }
            }
        }