Example #1
0
        private void BtnDelNormal_Click(object sender, EventArgs e)
        {
            int nCount = listViewNormalEvent.Items.Count;

            for (int i = 0; i < nCount; i++)
            {
                if (listViewNormalEvent.Items[i].Checked)
                {
                    DateTime queryID = Convert.ToDateTime(listViewNormalEvent.Items[i].SubItems[1].Text);
                    if (m_db != null)
                    {
                        var QueryDel = from aa in m_db.Eventcommons
                                       where aa.time == queryID
                                       select aa;
                        foreach (var del in QueryDel)
                        {
                            m_db.Eventcommons.Remove(del);
                        }
                        m_db.SaveChanges();
                    }
                }
            }
            checkBoxNormalAll.Checked = false;
            BtnNormalRefresh_Click(this, e);
        }
Example #2
0
        private void BtnRefreshOnline_Click(object sender, EventArgs e)
        {
            int nCount = listViewSIPAccount.Items.Count;

            for (int i = 0; i < nCount; i++)
            {
                if (listViewSIPAccount.Items[i].Checked)
                {
                    string     SipServerAndPort = Config.Instance.SIPServerIP + ":" + Config.Instance.SIPServerPort.ToString();
                    string     account          = listViewSIPAccount.Items[i].SubItems[1].Text;
                    string     httpPush         = "http://" + SipServerAndPort + "/QuerySipAccountOnline?account=" + account;
                    WebRequest request          = (HttpWebRequest)WebRequest.Create(httpPush);
                    request.Method      = WebRequestMethods.Http.Get;
                    request.ContentType = "";
                    request.Timeout     = 1000 * 5;
                    try
                    {
                        var resp = new StreamReader(request.GetResponse().GetResponseStream()).ReadToEnd();
                        if (resp.ToString() == "100")
                        {
                            listViewSIPAccount.Items[i].SubItems[0].Text = strings.online;//"在線";
                            var QueryAccount = (from sip in m_DB.Sipaccounts
                                                where sip.C_user == account
                                                select sip).FirstOrDefault();
                            if (QueryAccount != null)
                            {
                                QueryAccount.C_registerstatus = 1;
                            }
                        }
                        else if (resp.ToString() == "200")
                        {
                            listViewSIPAccount.Items[i].SubItems[0].Text = strings.offline;// "離線";
                            var QueryAccount = (from sip in m_DB.Sipaccounts
                                                where sip.C_user == account
                                                select sip).FirstOrDefault();
                            if (QueryAccount != null)
                            {
                                QueryAccount.C_registerstatus = 0;
                            }
                        }
                        else
                        {
                            listViewSIPAccount.Items[i].SubItems[0].Text = strings.unExpectedError;//"未预期错误";
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Time out!");
                    }
                    m_DB.SaveChanges();
                }
            }
        }
Example #3
0
        private void BtnDown_Click(object sender, EventArgs e)
        {
            ICMDBContext db = new ICMDBContext();

            foreach (ListViewItem tmp in listViewOrder.Items)
            {
                if (tmp.Selected == true)
                {
                    int seq = int.Parse(tmp.SubItems[0].Text);
                    if (seq < last)
                    {
                        var query = from zz in db.Advertisements
                                    where zz.C_no == seq || zz.C_no == seq + 1
                                    select zz;
                        foreach (var swap in query)
                        {
                            if (swap.C_no == seq)
                            {
                                swap.C_no += 1;
                            }
                            else
                            {
                                swap.C_no -= 1;
                            }
                        }
                        db.SaveChanges();
                    }
                }
            }
            listRefresh();
        }
Example #4
0
 private void BtnOK_Click(object sender, EventArgs e)
 {
     if (textBoxAccount.Text == "")
     {
         MessageBox.Show(strings.UserCannotBeNull);//"用户名不得为空");
         return;
     }
     using (var db = new ICMDBContext())
     {
         sipaccount SIP            = new sipaccount();
         string     account        = textBoxAccount.Text;
         var        checkNameExist = (from check in db.Sipaccounts
                                      where check.C_user == account
                                      select check).FirstOrDefault();
         if (checkNameExist != null)
         {
             MessageBox.Show("Account already exitst!\nPlease choose another name.");
             return;
         }
         SIP.C_user           = textBoxAccount.Text;
         SIP.C_password       = textBoxPasswd.Text;
         SIP.C_room           = DevicesAddressConverter.ChStrToRo(textBoxRoomID.Text);
         SIP.C_usergroup      = textBoxGroup.Text;
         SIP.C_updatetime     = DateTime.Now;
         SIP.C_sync           = 0;
         SIP.C_registerstatus = 0;
         SIP.C_randomcode     = randomcode.ToString();
         db.Sipaccounts.Add(SIP);
         db.SaveChanges();
     }
     this.Close();
 }
Example #5
0
 public void HasPolled()
 {
     if (LastPollingTime > LastResponseTime &&
         (LastPollingTime - LastResponseTime).TotalSeconds >= 3)
     {
         if (DeviceEntity.online != 0)
         {
             Task.Run(() =>
             {
                 using (var db = new ICMDBContext())
                 {
                     try
                     {
                         db.Devices.Attach(DeviceEntity);
                         DeviceEntity.online = 0;
                         db.SaveChanges();
                     }
                     catch (Exception) { }
                 }
             });
         }
     }
     LastPollingTime = DateTime.Now;
     PollingCount++;
 }
        private void UpdateDevice(string DeviceId, int DeviceType, XElement DeviceInfo)
        {
            using (var db = new ICMDBContext())
            {
                var Device = (from d in db.Devices
                              where d.roomid == DeviceId
                              select d).FirstOrDefault();
                if (Device != null)
                {
                    if (DeviceInfo.Attribute("ip") != null) // TODO: error check
                    {
                        Device.ip = DeviceInfo.Attribute("ip").Value;
                    }
                    if (DeviceInfo.Attribute("mc") != null) // TODO: error check
                    {
                        Device.mac = DeviceInfo.Attribute("mc").Value;
                    }
                    Device.type   = DeviceType;
                    Device.online = 1;

                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception) { }
                }
                // TODO: Send message to UI.
            }
        }
Example #7
0
        private void BtnDelAdmin_Click(object sender, EventArgs e)
        {
            int ID     = 0;
            int nCount = listViewAdmin.Items.Count;

            for (int i = 0; i < nCount; i++)
            {
                if (listViewAdmin.Items[i].Checked)
                {
                    ID = int.Parse(listViewAdmin.Items[i].SubItems[2].Text);
                }
            }
            if (ID != 0)
            {
                ICMDBContext db       = new ICMDBContext();
                var          queryDel = from user in db.Users
                                        where user.C_id == ID
                                        select user;
                foreach (var user in queryDel)
                {
                    db.Users.Remove(user);
                }
                db.SaveChanges();
                listViewRefresh();
            }
            else
            {
                MessageBox.Show("Choose the item you want to delete");
            }
        }
Example #8
0
        // 刪除广告文件
        private void BtnDelData_Click(object sender, EventArgs e)
        {
            int      nCount = listViewPlaySeq.Items.Count;
            DateTime queryID;

            for (int i = 0; i < nCount; i++)
            {
                if (listViewPlaySeq.Items[i].Checked)
                {
                    // 上传时间
                    queryID = Convert.ToDateTime(listViewPlaySeq.Items[i].SubItems[2].Text);
                    if (db != null)
                    {
                        var QueryDel = (from aa in db.Advertisements
                                        where aa.C_time == queryID
                                        select aa).FirstOrDefault();
                        db.Advertisements.Remove(QueryDel); // 拿时间來反查资料库取得特定资料並刪除

                        //decrese idseq
                        var QueryOrder = from zz in db.Advertisements
                                         where zz.C_no > QueryDel.C_no
                                         select zz;
                        foreach (var decrese in QueryOrder)
                        {
                            decrese.C_no -= 1;
                        }
                        //decrese idseq
                        db.SaveChanges();
                    }
                }
            }

            CountSeqNum();
            RefreshPlaySeq();
        }
        private void BtnDel_Click(object sender, EventArgs e)
        {
            if (dataGridViewLeaveMsgs.SelectedRows.Count > 0)
            {
                using (var db = new ICMDBContext())
                {
                    var LeaveMsgs = (from DataGridViewRow row in dataGridViewLeaveMsgs.SelectedRows
                                     select(db.Leavewords.Attach(row.DataBoundItem as leaveword))).ToList();

                    db.Leavewords.RemoveRange(LeaveMsgs);
                    db.SaveChanges();
                }
                System.IO.FileInfo fiSdp   = new System.IO.FileInfo(m_filename + ".sdp");
                System.IO.FileInfo fiRtpaD = new System.IO.FileInfo(m_filename + ".rtpa.data");
                System.IO.FileInfo fiRtpaI = new System.IO.FileInfo(m_filename + ".rtpa.index");
                System.IO.FileInfo fiRtpvD = new System.IO.FileInfo(m_filename + ".rtpv.data");
                System.IO.FileInfo fiRtpvI = new System.IO.FileInfo(m_filename + ".rtpv.index");
                try
                {
                    fiSdp.Delete();
                    fiRtpaD.Delete();
                    fiRtpaI.Delete();
                    fiRtpvD.Delete();
                    fiRtpvI.Delete();
                }
                catch { }
                RefreshLeaveMsgsGridView();
            }
        }
Example #10
0
 // 查看公告信息
 private void BtnCheck_Click(object sender, EventArgs e)
 {
     if (dataGridViewPublishInfo.SelectedRows.Count > 0)
     {
         using (var db = new ICMDBContext())
         {
             bool NeedRefresh = false;
             var  PublishInfo = (from DataGridViewRow row in dataGridViewPublishInfo.SelectedRows
                                 select(db.Publishinfoes.Attach(row.DataBoundItem as publishinfo))).ToList();
             foreach (var filepath in PublishInfo)
             {
                 string curPth = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
                 if (File.Exists(curPth + "\\" + filepath.filepath))
                 {
                     DialogMsgView CheckForm = new DialogMsgView(filepath.id);
                     CheckForm.ShowDialog();
                 }
                 else
                 {
                     MessageBox.Show(strings.FilePathNotExist);
                     db.Publishinfoes.Remove(filepath);
                     NeedRefresh = true;
                 }
             }
             if (NeedRefresh)
             {
                 db.SaveChanges();
                 RefreshPublishInfoGridView();
             }
         }
     }
 }
 private void BtnPlay_Click(object sender, EventArgs e)
 {
     if (dataGridViewLeaveMsgs.SelectedRows.Count > 0)
     {
         using (var db = new ICMDBContext())
         {
             bool NeedRefresh = false;
             var  LeaveMsgs   = (from DataGridViewRow row in dataGridViewLeaveMsgs.SelectedRows
                                 select(db.Leavewords.Attach(row.DataBoundItem as leaveword))).ToList();
             foreach (var filepath in LeaveMsgs)
             {
                 if (File.Exists(filepath.filenames + ".sdp"))
                 {
                     (new DialogLeaveMsgPlayer(filepath.filenames)).ShowDialog();
                 }
                 else
                 {
                     MessageBox.Show(strings.FilePathNotExist);
                     db.Leavewords.Remove(filepath);
                     NeedRefresh = true;
                 }
             }
             if (NeedRefresh)
             {
                 db.SaveChanges();
                 RefreshLeaveMsgsGridView();
             }
         }
     }
 }
        private void BtnDel_Click(object sender, EventArgs e)
        {
            int nCount = listViewResidentInfo.Items.Count;

            for (int i = 0; i < nCount; i++)
            {
                if (listViewResidentInfo.Items[i].Checked)
                {
                    int queryID = int.Parse(listViewResidentInfo.Items[i].SubItems[5].Text);
                    if (db != null)
                    {
                        var QueryDel = from aa in db.Holderinfoes
                                       where aa.C_id == queryID
                                       select aa;
                        foreach (var del in QueryDel)
                        {
                            db.Holderinfoes.Remove(del);
                        }
                        db.SaveChanges();
                    }
                }
            }
            checkBoxAllSelect.Checked = false;
            RefreshListview();
        }
        private void AddPasswords(string DeviceId, IEnumerable <XElement> events)
        {
            if (events.Count() == 0)
            {
                return;
            }

            using (var db = new ICMDBContext())
            {
                foreach (var e in events)
                {
                    doorbellpassword password = new doorbellpassword
                    {
                        C_roomid   = DeviceId,
                        C_password = e.Attribute("password").Value,
                        C_time     = DateTime.Parse(e.Attribute("time").Value)
                    };

                    db.Doorbellpasswords.Add(password);
                }
                try
                {
                    db.SaveChanges();
                }
                catch (Exception) { }
            }
        }
Example #14
0
 private void BtnDel_Click(object sender, EventArgs e)
 {
     using (var db = new ICMDBContext())
     {
         int nCount = listViewSIPAccount.Items.Count;
         for (int i = 0; i < nCount; i++)
         {
             if (listViewSIPAccount.Items[i].Checked)
             {
                 string queryAccount = listViewSIPAccount.Items[i].SubItems[0].Text;
                 if (db != null)
                 {
                     var QueryDel = from aa in db.Sipaccounts
                                    where aa.C_user == queryAccount
                                    select aa;
                     foreach (var del in QueryDel)
                     {
                         db.Sipaccounts.Remove(del);
                     }
                     db.SaveChanges();
                 }
             }
         }
     }
     BtnQuery_Click(this, e);
 }
 private void BtnCardDel_Click(object sender, EventArgs e)
 {
     if (iccardDataGridView.SelectedRows.Count > 0)
     {
         var cards = (from DataGridViewRow row in iccardDataGridView.SelectedRows
                      select((ObjectView <Iccard>)row.DataBoundItem).Object as Iccard);
         foreach (var card in cards)
         {
             var maps = (from m in db.Icmaps
                         where m.C_icno == card.C_icno
                         select m).ToList();
             if (maps != null)
             {
                 db.Icmaps.RemoveRange(maps);
             }
             db.Iccards.Remove(card);
         }
         db.SaveChanges();
         RefreshCardList();
     }
 }
Example #16
0
        private void BtnDel_Click(object sender, EventArgs e)
        {
            if (eventwarnDataGridView.SelectedRows.Count > 0)
            {
                using (var db = new ICMDBContext())
                {
                    var alarms = (from DataGridViewRow row in eventwarnDataGridView.SelectedRows
                                  select(db.Eventwarns.Attach(row.DataBoundItem as eventwarn))).ToList();

                    db.Eventwarns.RemoveRange(alarms);
                    db.SaveChanges();
                }
                RefreshAlarmList();
            }
        }
Example #17
0
        private void BtnDelOpen_Click(object sender, EventArgs e)
        {
            if (eventopendoordataGridView.SelectedRows.Count > 0)
            {
                using (var db = new ICMDBContext())
                {
                    var opens = (from DataGridViewRow row in eventopendoordataGridView.SelectedRows
                                 select(db.Eventopendoors.Attach(row.DataBoundItem as eventopendoor))).ToList();

                    db.Eventopendoors.RemoveRange(opens);
                    db.SaveChanges();
                }
                RefreshOpendoorList();
                return;
            }
        }
Example #18
0
        private void BtnOK_Click(object sender, EventArgs e)
        {
            string addr = "";

            addr = DevicesAddressConverter.ChStrToRo(textBoxDeviceAddr.Text);
            string AddrIP = ipAddressControlDevIP.Text;
            string gate   = AddrIP;
            int    index  = gate.LastIndexOf(".");

            if (index > 0)
            {
                gate = gate.Substring(0, index + 1) + 1;
            }

            /**
             * Start fetch user input and save
             **/
            using (var db = new ICMDBContext())
            {
                Device dev = new Device();
                dev.ip     = AddrIP;
                dev.roomid = addr;
                dev.Alias  = textBoxAlias.Text;
                try { dev.group = ComboBoxGroupIp.SelectedItem.ToString(); }
                catch { dev.group = ""; }
                if (textBoxDeviceMac.Text == "  :  :  :  :  :")
                {
                    dev.mac = "";
                }
                //try { dev.mac = textBoxDeviceMac.Text; }
                //catch { dev.mac = ""; }
                dev.type = ComboBoxDeviceType.SelectedIndex;
                dev.sm   = "255.255.255.0";
                dev.gw   = gate;
                db.Devices.Add(dev);
                try
                {
                    db.SaveChanges();
                    DialogResult = DialogResult.OK;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.InnerException.Message);
                }
            }
            this.Close();
        }
Example #19
0
        private void BtnOK_Click(object sender, EventArgs e)
        {
            string addr = DeviceAddressControl.Text;
            //string addr = textBoxDeviceAddr.Text;
            string AddrIP = ipAddressControlDevIP.Text;
            string gate   = AddrIP;
            int    index  = gate.LastIndexOf(".");

            if (index > 0)
            {
                gate = gate.Substring(0, index + 1) + 1;
            }

            /**
             * Start fetch user input and save
             **/
            //List<string> xmlrow = new List<string>();
            //ListViewItem item;
            //using (var db = new ICMDBContext())
            {
                var dev = m_Device;
                if (dev != null)
                {
                    dev.ip     = AddrIP;
                    dev.roomid = addr;
                    dev.Alias  = textBoxAlias.Text;
                    try { dev.group = ComboBoxGroupIp.SelectedItem.ToString(); }
                    catch { dev.group = "NO"; }
                    if (textBoxDeviceMac.Text == "  :  :  :  :  :")
                    {
                        dev.mac = "";
                    }
                    //try { dev.mac = textBoxDeviceMac.Text; }
                    //catch { dev.mac = ""; }
                    dev.type = ComboBoxDeviceType.SelectedIndex;
                    dev.sm   = "255.255.255.0";
                    dev.gw   = gate;
                    if (m_DB != null)
                    {
                        m_DB.SaveChanges();
                        DialogResult = DialogResult.OK;
                    }
                }
            }
            this.Close();
        }
Example #20
0
            public void HasResponsed()
            {
                LastResponseTime = DateTime.Now;
                ResponseCount++;

                if (DeviceEntity.online != 1)
                {
                    using (var db = new ICMDBContext())
                    {
                        try
                        {
                            db.Devices.Attach(DeviceEntity);
                            DeviceEntity.online = 1;
                            db.SaveChanges();
                        }
                        catch (Exception) { }
                    }
                }
            }
 private void BtnOK_Click(object sender, EventArgs e)
 {
     using (var db = new ICMDBContext())
     {
         db.Eventwarns.Attach(m_Alarm);
         m_Alarm.handler      = handlerTextBox.Text;
         m_Alarm.handlestatus = handlestatusListBox.SelectedIndex;
         if (m_Alarm.handlestatus == 2)
         {
             m_Alarm.handletime = DateTime.Now;
         }
         else
         {
             m_Alarm.handletime = null;
         }
         db.SaveChanges();
         DialogResult = DialogResult.OK;
     }
 }
Example #22
0
        public static int UpdateDeviceToken(string platform, string account, string deviceID, string tokenID)
        {
            int result = 0;

            using (var db = new ICMDBContext())
            {   // 開啟資料庫
                var sipAccount = GetSipAccount(db, account);
                if (sipAccount != null)
                {
                    sipAccount.Platform = platform;
                    sipAccount.DeviceID = deviceID;
                    sipAccount.TokenID  = tokenID;
                    db.SaveChanges();
                    result = 100;
                }
            }

            return(result);
        }
Example #23
0
 private void BtnOk_Click(object sender, EventArgs e)
 {
     if ((textBoxPath.Text == "") || (textBoxTopic.Text == ""))
     {
         MessageBox.Show(strings.AdsTitleAndFilePathCannotBeNull);//"广告标题和文件位置不得为空");
     }
     else
     {
         ads.C_title = textBoxTopic.Text;
         ads.C_path  = textBoxPath.Text;
         ads.C_time  = DateTime.Now;
         ads.C_no    = Order;
         db.Advertisements.Add(ads);
         db.SaveChanges();
         //BtnOk.DialogResult = DialogResult.OK;
         this.DialogResult = DialogResult.OK;
         this.Close();
     }
 }
Example #24
0
 private void BtnOk_Click(object sender, EventArgs e)
 {
     if (txtBoxPassword.Text != "")
     {
         if (txtBoxPassword.Text == txtBoxPassword2.Text)
         {
             if (m_id == 0)
             {
                 user users = new Models.user();
                 //User user = new User();
                 users.C_username = txtBoxName.Text;
                 users.C_userno   = txtBoxNum.Text;
                 users.C_password = txtBoxPassword.Text;
                 users.C_powerid  = cmbBoxAuthority.SelectedIndex;//.SelectedItem.ToString();
                 m_db.Users.Add(users);
             }
             else
             {
                 var query = from users in m_db.Users
                             where users.C_id == m_id
                             select users;
                 foreach (var user in query)
                 {
                     user.C_username = txtBoxName.Text;
                     user.C_userno   = txtBoxNum.Text;
                     user.C_password = txtBoxPassword.Text;
                     user.C_powerid  = cmbBoxAuthority.SelectedIndex;//.SelectedItem.ToString();
                 }
             }
             m_db.SaveChanges();
             this.Close();
         }
         else
         {
             MessageBox.Show(strings.PwEnterNotTheSame);//"兩次输入的密码不一致!");
         }
     }
     else
     {
         MessageBox.Show(strings.plzEnterPw);//"请输入密码");
     }
 }
        private async void AddSnapshotsAsync(string DeviceId, string clientIP, IEnumerable <XElement> events)
        {
            if (events.Count() == 0)
            {
                return;
            }

            using (var db = new ICMDBContext())
            {
                foreach (var e in events)
                {
                    if (e.Attribute("time").Value != null)
                    {
                        photograph snapshot = new photograph
                        {
                            C_srcaddr = DeviceId,
                            C_time    = DateTime.Parse(e.Attribute("time").Value)
                        };

                        string imagePath = string.Format("http://{0}/photo?ro={1}&time={2}",
                                                         clientIP,
                                                         DeviceId,
                                                         e.Attribute("time").Value.Replace(" ", "%20"));

                        System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
                        try
                        {
                            snapshot.C_img = await client.GetByteArrayAsync(new Uri(imagePath));

                            db.Photographs.Add(snapshot);
                        }
                        catch (Exception) { }
                    }
                }
                try
                {
                    db.SaveChanges();
                }
                catch (Exception) { }
            }
        }
Example #26
0
 private void BtnOk_Click(object sender, EventArgs e)
 {
     if (ID == 0)
     {
         auth.C_name      = textBoxAuthoName.Text;
         auth.C_authority = CalcLevel();
         db.Authorities.Add(auth);
     }
     else
     {
         var query = from zz in db.Authorities
                     where zz.C_id == ID
                     select zz;
         foreach (var a in query)
         {
             a.C_name      = textBoxAuthoName.Text;
             a.C_authority = CalcLevel();
         }
     }
     db.SaveChanges();
     this.Close();
 }
Example #27
0
 private void BtnDel_Click(object sender, EventArgs e)
 {
     if (dataGridViewPublishInfo.SelectedRows.Count > 0)
     {
         using (var db = new ICMDBContext())
         {
             var PublishInfo = (from DataGridViewRow row in dataGridViewPublishInfo.SelectedRows
                                select(db.Publishinfoes.Attach(row.DataBoundItem as publishinfo))).ToList();
             foreach (var delPublish in PublishInfo)
             {
                 System.IO.FileInfo fiPublish = new System.IO.FileInfo(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\" + delPublish.filepath);
                 try
                 {
                     fiPublish.Delete();
                 }
                 catch { }
             }
             db.Publishinfoes.RemoveRange(PublishInfo);
             db.SaveChanges();
         }
         RefreshPublishInfoGridView();
     }
 }
Example #28
0
        private void BtnStartSync_Click(object sender, EventArgs e)
        {
            // TODO: 把整個行为丟到 background thread 去做
            if (Config.Instance.SIPServerIP.Length == 0 || Config.Instance.SIPServerPort == 0)
            {
                // TODO: 提示 sip server 的資訊尚未输入
                return;
            }

            // http://172.29.1.21:5050/AddSipAccount?sip_account=account1&sip_pwd=BqVXrqD0YS&apply=1
            // ring group
            // account1-account2-account3
            // http://172.29.1.21:5050/AddRingGroup?group_num=0000000000&group_list=account1-account2-account3
            foreach (var account in m_SipAccounts)
            {
                WebRequest request = (HttpWebRequest)WebRequest.Create("http://" + m_SipServerAndPort + "/AddSipAccount?sip_account=" + account.C_user + "&sip_pwd=" + account.C_password + "&apply=0");
                //http://sp.ite.com.tw:5050/AddSipAccount?sip_account=" + result.user + "&sip_pwd=" + result.passwd + "&apply=0");
                request.Method      = WebRequestMethods.Http.Get;
                request.ContentType = "";
                request.Timeout     = 1000 * 5;
                try
                {
                    var resp = new StreamReader(request.GetResponse().GetResponseStream()).ReadToEnd();
                    if (resp.ToString() != "0")
                    {
                        MessageBox.Show("Add SIP Account Failed!");
                        return;
                    }
                }
                catch
                {
                    MessageBox.Show("Time out!");
                    return;
                }
            }

            // Add ring group
            foreach (var ringGroup in m_RingGroups)
            {
                string httpUrl    = m_AddRingGroup + ringGroup + "&group_list=";
                string groupNum   = ringGroup;
                var    QueryGroup = from sip in m_DB.Sipaccounts
                                    where sip.C_usergroup == groupNum
                                    select sip;
                foreach (var result in QueryGroup)
                {
                    httpUrl      += result.C_user + "-";
                    result.C_sync = 1;
                }
                httpUrl = httpUrl.Substring(0, httpUrl.Length - 1);
                WebRequest request = (HttpWebRequest)WebRequest.Create(httpUrl);
                request.Method      = WebRequestMethods.Http.Get;
                request.ContentType = "";
                request.Timeout     = 1000 * 5;
                try
                {
                    var resp = new StreamReader(request.GetResponse().GetResponseStream()).ReadToEnd();
                    if (resp.ToString() != "0")
                    {
                        MessageBox.Show("Add Ring Group Failed!");
                        return;
                    }
                }
                catch
                {
                    MessageBox.Show("Time out!");
                    return;
                }
            }

            // Apply all
            WebRequest apply = (HttpWebRequest)WebRequest.Create("http://" + m_SipServerAndPort + "/ApplySipAccount");

            //"http://sp.ite.com.tw:5050/ApplySipAccount");
            apply.Method      = WebRequestMethods.Http.Get;
            apply.ContentType = "";
            apply.Timeout     = 1000 * 5;
            try
            {
                var applyresp = new StreamReader(apply.GetResponse().GetResponseStream()).ReadToEnd();
                if (applyresp.ToString() != "100")
                {
                    MessageBox.Show("Apply SIP Account Failed!");
                    return;
                }
            }
            catch
            {
                MessageBox.Show("Time out!");
                return;
            }


            m_DB.SaveChanges();
            MessageBox.Show(strings.SyncFinish);//"同步完成!");
            this.Close();
        }
Example #29
0
 public IRepository <T> SaveChanges()
 {
     _db.SaveChanges();
     return(this);
 }
        public ModulePushServer()
            : base("/")
        {
            Get["/register_udid.php", true] = async(parameters, ct) =>
            {
                string udid         = this.Request.Query["udid"];
                string responseText = "";

                using (var db = new ICMDBContext())
                {
                    var sipAccount = (from account in db.Sipaccounts
                                      where account.C_randomcode == udid &&
                                      account.C_registerstatus == 0
                                      select account).FirstOrDefault();
                    if (sipAccount != null)
                    {
                        responseText = sipAccount.C_user + "\n" + sipAccount.C_password;
                        sipAccount.C_registerstatus = 1;
                        db.SaveChanges();

                        var Device = (from d in db.Devices
                                      where d.roomid == sipAccount.C_room
                                      select d).FirstOrDefault();
                        if (Device != null)
                        {
                            string uri = string.Format("http://{0}/doorbell/register_success?ro={1}&account={2}", Device.ip, Device.roomid, sipAccount.C_user);
                            System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
                            try
                            {
                                var response = await client.GetStringAsync(uri);
                            }
                            catch (Exception) { }
                        }
                    }
                }
                return(responseText);
            };

            Get["/open_door.php", true] = async(parameters, ct) =>
            {
                string toAccount    = this.Request.Query["to_account"];
                string responseText = "open door fail,error = 1";

                using (var db = new ICMDBContext())
                {
                    var sipAccount = (from account in db.Sipaccounts
                                      where account.C_user == toAccount
                                      select account).FirstOrDefault();
                    if (sipAccount != null)
                    {
                        var Device = (from d in db.Devices
                                      where d.roomid == sipAccount.C_room
                                      select d).FirstOrDefault();
                        if (Device != null)
                        {
                            string uri = string.Format("http://{0}/open_door?ro=00-00-00-00-00-00", Device.ip);
                            System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
                            try
                            {
                                var response = await client.GetStringAsync(uri);

                                return("open door success");
                            }
                            catch (Exception) { }
                        }
                    }
                    else
                    {
                        responseText = "open door fail,error = 2";
                    }
                }

                return(responseText);
            };
        }