Exemplo n.º 1
0
        /// <summary>
        /// 处理数据并更新终端和设备的状态
        /// </summary>
        /// <param name="obj"></param>
        private void HandleDataStatus(TX300 obj)
        {
            var sim      = GetSimFromData(obj);
            var terminal = TerminalInstance.Find(f => f.Sim.Equals(sim));

            if (null == terminal)
            {
                return;
            }

            var equipment = EquipmentInstance.Find(f => f.TB_Terminal.Sim.Equals(sim) && f.Deleted == false);

            HandleOnline(sim, obj.CommandID);
            SaveTX300History(obj, (null == equipment ? "" : EquipmentInstance.GetFullNumber(equipment)));
            // 卫星数据只有0x1000和0x6007(0x6007会有0xEE00存在)两种
            switch (obj.CommandID)
            {
            case 0x1000:
                Handle0x1000(obj, equipment);
                break;

            case 0x6007:
                Handle0x6007(obj, equipment);
                break;

            case 0xEE00:
                Handle0xEE00(obj, equipment);
                // 483130433130372007600140A5
                // 5831304331303530076001403F
                break;
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 返回状态信息
 /// </summary>
 /// <param name="status"></param>
 /// <param name="text"></param>
 /// <param name="json"></param>
 private void ResponseData(int status, string text, bool json = false)
 {
     SatelliteInstance.Close();
     TerminalInstance.Close();
     ResponseJson(string.Format("{0}\"State\":{1},\"Type\":\"{2}\",\"Data\":{3}{4}{5}{6}",
                                "{", status, type, (json ? "" : "\""), text, (json ? "" : "\""), "}"));
 }
Exemplo n.º 3
0
        private void EditTerminal()
        {
            var id = ParseInt(Utility.Decrypt(hidID.Value));
            var t  = TerminalInstance.Find(f => (f.Number.Equals(txtNumber.Value.Trim()) || f.Sim.Equals(txtSimcard.Value.Trim())) &&
                                           f.id != id && f.Delete == false);

            if (null == t)
            {
                t = TerminalInstance.Find(f => f.id == ParseInt(Utility.Decrypt(hidID.Value)));
                if (null != t)
                {
                    BuildObject(t);
                    Update(t);

                    SaveHistory(new TB_AccountHistory
                    {
                        ActionId = ActionInstance.Find(f => f.Name.Equals("EditTerminal")).id,
                        ObjectA  = TerminalInstance.ToString(t)
                    });
                    ShowNotification("./terminal_list.aspx", "You changed terminal: " + TerminalInstance.ToString(t));
                }
                else
                {
                    ShowNotification("./terminal_list.aspx", "Error: Cannot edit null object of Terminal.", false);
                }
            }
            else
            {
                ShowNotification("./terminal_register.aspx?key=" + Utility.UrlEncode(hidID.Value),
                                 "Error: New terminal number or sim card number has exists: " + TerminalInstance.ToString(t), false);
            }
        }
Exemplo n.º 4
0
        private void NewTerminal()
        {
            TB_Terminal t = null;

            // 如果没有输入Sim卡号码则查询是否具有相同终端号码的记录
            if (string.IsNullOrEmpty(txtSimcard.Value.Trim()))
            {
                t = TerminalInstance.Find(f => f.Number.Equals(txtNumber.Value.Trim()) && f.Delete == false);
            }
            else
            {
                // 如果有Sim卡号码输入则查询终端或Sim卡号码是否有相同记录存在
                t = TerminalInstance.Find(f => (f.Number.Equals(txtNumber.Value.Trim()) || f.Sim.Equals(txtSimcard.Value.Trim())) && f.Delete == false);
            }

            if (null != t)
            {
                ShowNotification("./terminal_register.aspx", "Terminal exist: " + TerminalInstance.ToString(t), false);
            }
            else
            {
                t = TerminalInstance.GetObject();
                BuildObject(t);
                TerminalInstance.Add(t);

                SaveHistory(new TB_AccountHistory
                {
                    ActionId = ActionInstance.Find(f => f.Name.Equals("AddTerminal")).id,
                    ObjectA  = TerminalInstance.ToString(t)
                });

                ShowNotification("./terminal_list.aspx", "You added a new terminal: " + TerminalInstance.ToString(t));
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 根据TX300数据包更新终端和设备的在线状态
        /// </summary>
        /// <param name="tx300"></param>
        private void HandleTX300Status(TX300 tx300, AsyncUserDataBuffer data)
        {
            var sim       = GetSimFromData(tx300);
            var equipment = EquipmentInstance.Find(f => f.TB_Terminal.Sim.Equals(sim));
            var terminal  = TerminalInstance.Find(f => f.Sim.Equals(sim));

            // 终端不存在的话,不用再继续处理数据了
            if (null == terminal)
            {
                return;
            }

            HandleOnline(sim, tx300.CommandID, data);

            if (tx300.CommandID != 0xAA00)
            {
                SaveTX300History(tx300, data.ReceiveTime,
                                 (null == equipment ? "" : EquipmentInstance.GetFullNumber(equipment)));

                // TX10G的数据
                if (tx300.CommandID == 0x7010 || tx300.CommandID == 0x7020 || tx300.CommandID == 0x7030)
                {
                    HandleTX10G(tx300, data);
                }
                else
                {
                    // 根据命令的不同处理各个命令详情
                    HandleCommand(tx300, equipment, terminal);
                }
            }
        }
Exemplo n.º 6
0
        protected void btnSatelliteStopping_Click(object sender, EventArgs e)
        {
            var value = hidBoundSatellite.Value.Trim();

            if (string.IsNullOrEmpty(value))
            {
                ShowNotification("./terminal_list.aspx", "Cannot find object with null parameter.", false);
            }
            else
            {
                var id       = int.Parse(value);
                var terminal = TerminalInstance.Find(f => f.id == id);
                if (null == terminal)
                {
                    ShowNotification("./terminal_list.aspx", "Terminal is not exist.", false);
                }
                else
                {
                    // 更新终端的连接为卫星停止状态
                    TerminalInstance.Update(f => f.id == terminal.id, act => { act.OnlineStyle = (byte)LinkType.SATELLITE_STOP; });
                    // 更新设备的连接为卫星停止状态
                    EquipmentInstance.Update(f => f.Terminal == terminal.id, act => { act.OnlineStyle = (byte)LinkType.SATELLITE_STOP; });

                    ShowNotification("./terminal_list.aspx", "You have stopped satellite " + terminal.TB_Satellite.CardNo, true);
                }
            }
        }
Exemplo n.º 7
0
        private void ShowEdit()
        {
            var t = TerminalInstance.Find(f => f.id == ParseInt(Utility.Decrypt(hidID.Value)));

            if (null != t)
            {
                txtNumber.Value = t.Number;
                //txtSatellite.Value = t.Satellite;
                txtSimcard.Value = t.Sim;
                if (t.Type == TerminalTypes.DX)
                {
                    _dx_normal.Checked = true;
                }
                else if (t.Type == TerminalTypes.DXE)
                {
                    _dx.Checked = true;
                }
                else
                {
                    _ld.Checked = true;
                }
            }
            else
            {
                ShowNotification("./terminal_list.aspx", "Error: Cannot edit null object of Terminal.", false);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// 处理旧的链接或长时间未动的客户端节点
        /// </summary>
        public void HandleOlderClients()
        {
            LastOlderLinkHandledTime = DateTime.Now;

            // 处理旧的TCP链接为SMS链接(1小时15分钟之前有TCP数据来的链接会被置为SMS)
            EquipmentInstance.Update(f => f.OnlineStyle < (byte)LinkType.SMS && f.OnlineTime < DateTime.Now.AddMinutes(-75), act =>
            {
                act.Socket      = 0;
                act.OnlineStyle = (byte)LinkType.SMS;
                act.Voltage     = "G0000";
            });
            // 处理终端连接
            TerminalInstance.Update(f => f.OnlineStyle < (byte)LinkType.SMS && f.OnlineTime < DateTime.Now.AddMinutes(-75), act => {
                act.Socket      = 0;
                act.OnlineStyle = (byte)LinkType.SMS;
            });
            // 处理旧的SMS连接为SLEEP状态(SMS链接超过12小时的)
            EquipmentInstance.Update(f => f.OnlineStyle < (byte)LinkType.SLEEP && f.OnlineTime < DateTime.Now.AddMinutes(-720), act =>
            {
                act.OnlineStyle = (byte)LinkType.SLEEP;
            });
            // 处理终端连接
            TerminalInstance.Update(f => f.OnlineStyle < (byte)LinkType.SLEEP && f.OnlineTime < DateTime.Now.AddMinutes(-720), act =>
            {
                act.OnlineStyle = (byte)LinkType.SLEEP;
            });
            // 处理旧的SLEEP连接为盲区(SLEEP超过7天的)
            EquipmentInstance.Update(f => f.OnlineStyle < (byte)LinkType.BLIND && f.OnlineTime < DateTime.Now.AddMinutes(-10080), act =>
            {
                act.OnlineStyle = (byte)LinkType.BLIND;
            });
        }
Exemplo n.º 9
0
        protected void btDelete_Click(object sender, EventArgs e)
        {
            // 删除设备
            var id        = ParseInt(Utility.Decrypt(_key));
            var equipment = EquipmentInstance.Find(f => f.id == id);

            if (null == equipment)
            {
                ShowNotification("./equipment_setting.aspx?key=" + Utility.UrlEncode(_key), "Not found the equipment", false);
            }
            else
            {
                string number = EquipmentInstance.GetFullNumber(equipment);
                if ((int?)null != equipment.Terminal)
                {
                    var ter = equipment.TB_Terminal.Number;
                    // 解绑终端
                    TerminalInstance.Update(f => f.id == equipment.Terminal, act =>
                    {
                        act.HasBound = false;
                    });
                    // 保存解绑终端历史
                    SaveHistory(new TB_AccountHistory()
                    {
                        ActionId = ActionInstance.Find(f => f.Name.Equals("Unbind")).id,
                        ObjectA  = "unbind terminal(delete equipment) " + ter + " and equipment " + EquipmentInstance.GetFullNumber(equipment)
                    });
                }
                // 更新Deleted=true
                EquipmentInstance.Update(f => f.id == equipment.id, act => {
                    act.Deleted        = true;
                    act.GpsAddress     = "";
                    act.IP             = "";
                    act.LastAction     = "";
                    act.LastActionBy   = "";
                    act.LastActionTime = null;
                    act.Latitude       = 0.0;
                    act.Longitude      = 0.0;
                    act.OnlineStyle    = null;
                    act.OnlineTime     = null;
                    act.Port           = 0;
                    act.Rpm            = 0;
                    act.Runtime        = 0;
                    act.ServerName     = "";
                    act.Signal         = 0;
                    act.Socket         = 0;
                    act.Terminal       = null;
                    act.Voltage        = "G0000";
                });
                // 保存删除设备历史
                SaveHistory(new TB_AccountHistory()
                {
                    ActionId = ActionInstance.Find(f => f.Name.Equals("Unbind")).id,
                    ObjectA  = "delete equipment " + number
                });
                ShowNotification("./equipment_inquiry.aspx", "You have deleted a equipment: " + number);
            }
        }
Exemplo n.º 10
0
        protected void btUnbindEquipment_Click(object sender, EventArgs e)
        {
            var value = hidBoundSatellite.Value.Trim();

            if (string.IsNullOrEmpty(value))
            {
                return;
            }
            var id       = int.Parse(value);
            var terminal = TerminalInstance.Find(f => f.id == id);

            if (null == terminal)
            {
                return;
            }

            var equipment = EquipmentInstance.Find(f => f.Terminal == id && f.Deleted == false);

            // 更新设备的终端为空并清空设备的相应值
            EquipmentInstance.Update(f => f.Terminal == id && f.Deleted == false, act =>
            {
                act.Terminal       = (int?)null;
                act.GpsAddress     = "";
                act.LastAction     = "";
                act.LastActionBy   = "";
                act.LastActionTime = (DateTime?)null;
                act.Latitude       = 0.0;
                act.Longitude      = 0.0;
                act.OnlineStyle    = (byte?)null;
                act.OnlineTime     = (DateTime?)null;
                act.Runtime        = 0;
                act.Socket         = 0;
                act.Port           = 0;
                act.IP             = "";
                act.LockStatus     = "00";
                act.Rpm            = 0;
                act.Signal         = 0;
                act.Voltage        = "G0000";
            });
            // 更新终端的绑定状态为false
            TerminalInstance.Update(f => f.id == id, act =>
            {
                act.HasBound = false;
            });
            // 保存解绑终端历史
            SaveHistory(new TB_AccountHistory()
            {
                ActionId = ActionInstance.Find(f => f.Name.Equals("Unbind")).id,
                ObjectA  = "unbind terminal " + terminal.Number + " and equipment " + EquipmentInstance.GetFullNumber(equipment)
            });

            ShowNotification("./terminal_list.aspx", "You have unbind the terminal and equipment.");
        }
Exemplo n.º 11
0
 protected void bt_Test_Click(object sender, EventArgs e)
 {
     if (!HasSessionLose)
     {
         if ("" != hidID.Value)
         {
             var id       = int.Parse(Utility.Decrypt(hidID.Value));
             var terminal = TerminalInstance.Find(f => f.id == id && f.Delete == false);
             if (null != terminal)
             {
                 if (terminal.HasBound.Value == false)
                 {
                     ShowNotification("./terminal_list.aspx", "No equipment bind on this terminal.", false);
                 }
                 else
                 {
                     var test = StatusInstance.Find(f => f.IsItTesting == true);
                     if (null == test)
                     {
                         ShowNotification("Situation code is not exist.", "", false);
                     }
                     else
                     {
                         var equip = terminal.TB_Equipment.FirstOrDefault();
                         if (null != equip)
                         {
                             EquipmentInstance.Update(f => f.id == equip.id, act =>
                             {
                                 act.Status = StatusInstance.Find(f => f.IsItTesting == true).id;
                             });
                             SaveHistory(new TB_AccountHistory
                             {
                                 ActionId = ActionInstance.Find(f => f.Name.Equals("EditTerminal")).id,
                                 ObjectA  = EquipmentInstance.GetFullNumber(equip) + ", " + terminal.Number + ", set to test mode"
                             });
                             ShowNotification("./terminal_list.aspx", EquipmentInstance.GetFullNumber(equip) + ", " + terminal.Number + ", set to test mode");
                         }
                         else
                         {
                             ShowNotification("./terminal_list.aspx", "No equipment bind on this terminal.", false);
                         }
                     }
                 }
             }
             else
             {
                 ShowNotification("./terminal_list.aspx", "Terminal is not exist.", false);
             }
         }
     }
 }
Exemplo n.º 12
0
        /// <summary>
        /// 解绑终端和卫星模块
        /// </summary>
        private void UnboundSatellite()
        {
            var id = int.Parse(hidBoundSatellite.Value.Trim());
            var t  = TerminalInstance.Find(f => f.id == id);

            if (null == t)
            {
                ShowNotification("./terminal_list.aspx", "Unbind fail: Terminal not exists.", false);
            }
            else
            {
                if ((int?)null == t.Satellite)
                {
                    ShowNotification("./terminal_list.aspx", "Unbind fail: No Satellite bound on it.", false);
                }
                else
                {
                    string satno = t.TB_Satellite.CardNo;
                    TerminalInstance.Update(f => f.id == t.id, act =>
                    {
                        act.Satellite = (int?)null;
                        // 更新终端的链接为OFF
                        if (act.OnlineStyle == (byte)LinkType.SATELLITE)
                        {
                            act.OnlineStyle = (byte?)null;
                        }
                        // 更新卫星功能为false
                        act.SatelliteStatus = false;
                    });
                    // 更新设备的链接为OFF
                    EquipmentInstance.Update(f => f.Terminal == t.id, act =>
                    {
                        if (act.OnlineStyle == (byte)LinkType.SATELLITE)
                        {
                            act.OnlineStyle = (byte?)null;
                        }
                        act.SatelliteStatus = false;
                    });
                    SatelliteInstance.Update(f => f.id == t.Satellite, act => { act.Bound = false; });
                    // 发送解绑卫星模块的命令
                    SendDD02Command(false, t);
                    SaveHistory(new TB_AccountHistory()
                    {
                        ActionId = ActionInstance.Find(f => f.Name.Equals("UnbindSat")).id,
                        ObjectA  = "Ter: " + t.Number + " unbind Sat: " + satno
                    });
                    ShowNotification("./terminal_list.aspx", "Ter: " + t.Number + " unbind Sat: " + satno + " OK!");
                }
            }
        }
Exemplo n.º 13
0
 /// <summary>
 /// 更新终端的信息
 /// </summary>
 /// <param name="obj"></param>
 protected void Update(TB_Terminal obj)
 {
     TerminalInstance.Update(f => f.id == obj.id, act =>
     {
         act.Delete    = obj.Delete;
         act.Firmware  = obj.Firmware;
         act.HasBound  = obj.HasBound;
         act.Number    = obj.Number;
         act.Revision  = obj.Revision;
         act.Satellite = obj.Satellite;
         act.Sim       = obj.Sim;
         act.Type      = obj.Type;
     });
 }
Exemplo n.º 14
0
 /// <summary>
 /// 更新客户端断开连接之后的在线状况
 /// </summary>
 /// <param name="socket"></param>
 private void HandleClientDisconnect(int socket)
 {
     // 更新设备的在线状态
     EquipmentInstance.Update(f => f.Socket == socket, act =>
     {
         act.Socket      = 0;
         act.OnlineStyle = (byte)LinkType.SMS;
         act.Voltage     = "G0000";
     });
     // 更新终端的在线状态
     TerminalInstance.Update(f => f.Socket == socket, act => {
         act.Socket      = 0;
         act.OnlineStyle = (byte)LinkType.SMS;
     });
 }
Exemplo n.º 15
0
        private void NewTerminalNo()
        {
            var no = DateTime.Now.ToString("yyyyMMdd");
            // 查找当前日期中比1号更大的终端号码并倒叙排列
            var ter = TerminalInstance.FindList <TB_Terminal>(f => f.Number.StartsWith(no) && f.Delete == false, "Number", true).FirstOrDefault();

            if (null != ter)
            {
                no = (ParseInt(ter.Number) + 1).ToString();
            }
            else
            {
                no += "01";
            }
            txtNumber.Value = no;
            NewSimNo();
        }
Exemplo n.º 16
0
        private void NewSimNo()
        {
            var auto = int.Parse(ConfigurationManager.AppSettings["AutoSimCardNumber"]);

            if (auto > 0)
            {
                var tmp = TerminalInstance.FindList <TB_Terminal>(f => f.Sim.Contains("89000"), "Sim", true).FirstOrDefault();
                if (null != tmp)
                {
                    var s = int.Parse(tmp.Sim);
                    txtSimcard.Value = (s + 1).ToString();
                }
                else
                {
                    txtSimcard.Value = "89000001";
                }
            }
        }
Exemplo n.º 17
0
 /// <summary>
 /// 更新在线时间和在线状态
 /// </summary>
 private void HandleOnline(string sim, ushort CommandID, AsyncUserDataBuffer data)
 {
     EquipmentInstance.Update(f => f.TB_Terminal.Sim.Equals(sim), act =>
     {
         act.IP             = data.IP;
         act.Port           = data.Port;
         act.Socket         = data.SocketHandle;
         act.OnlineTime     = data.ReceiveTime;
         act.OnlineStyle    = (byte)(data.PackageType == AsyncDataPackageType.TCP ? LinkType.TCP : LinkType.UDP);
         act.LastAction     = "0x" + CustomConvert.IntToDigit(CommandID, CustomConvert.HEX, 4);
         act.LastActionBy   = data.PackageType == AsyncDataPackageType.TCP ? "TCP" : "UDP";
         act.LastActionTime = data.ReceiveTime;
     });
     TerminalInstance.Update(f => f.Sim.Equals(sim), act =>
     {
         act.Socket      = data.SocketHandle;
         act.OnlineStyle = (byte)(data.PackageType == AsyncDataPackageType.TCP ? LinkType.TCP : LinkType.UDP);
         act.OnlineTime  = data.ReceiveTime;
     });
 }
Exemplo n.º 18
0
 protected void btUnbind_Click(object sender, EventArgs e)
 {
     if (!HasSessionLose)
     {
         var id        = ParseInt(Utility.Decrypt(_key));
         var equipment = EquipmentInstance.Find(f => f.id == id && f.Deleted == false);
         if (null == equipment)
         {
             ShowNotification("./equipment_setting.aspx?key=" + Utility.UrlEncode(_key), "Not found the equipment", false);
         }
         else
         {
             var ter = equipment.TB_Terminal.Number;
             TerminalInstance.Update(f => f.id == equipment.Terminal, act => { act.HasBound = false; });
             EquipmentInstance.Update(f => f.id == equipment.id, act =>
             {
                 act.Terminal       = null;
                 act.OnlineStyle    = null;
                 act.OnlineTime     = null;
                 act.Socket         = 0;
                 act.IP             = "";
                 act.LastAction     = "";
                 act.LastActionBy   = "";
                 act.LastActionTime = null;
                 act.Latitude       = 0.0;
                 act.Longitude      = 0.0;
                 act.GpsAddress     = "";
                 act.Rpm            = 0;
                 act.ServerName     = "";
                 act.Voltage        = "G0000";
             });
             // 保存解绑终端历史
             SaveHistory(new TB_AccountHistory()
             {
                 ActionId = ActionInstance.Find(f => f.Name.Equals("Unbind")).id,
                 ObjectA  = "unbind terminal " + ter + " and equipment " + EquipmentInstance.GetFullNumber(equipment)
             });
             ShowNotification("./equipment_setting.aspx?key=" + Utility.UrlEncode(_key), "You have unbind terminal & equipment.");
         }
     }
 }
Exemplo n.º 19
0
        private void SaveWorkDetail()
        {
            var id   = ParseInt(Utility.Decrypt(hidKey.Value));
            var work = WorkInstance.Find(f => f.id == id && f.Deleted == false);

            if (null != work)
            {
                var obj = WorkDetailInstance.GetObject();
                if (!string.IsNullOrEmpty(hiddenTerminal.Value))
                {
                    obj.BookedTerminal = int.Parse(hiddenTerminal.Value);
                }
                obj.Equipment = int.Parse(hiddenEquipment.Value);
                obj.Type      = byte.Parse(hiddenType.Value);
                obj.Details   = detail.Value;
                obj.Work      = work.id;
                WorkDetailInstance.Add(obj);

                // 更新终端的预定状态
                if ((int?)null != obj.BookedTerminal)
                {
                    TerminalInstance.Update(f => f.id == obj.BookedTerminal && f.Delete == false, act =>
                    {
                        act.Booked = true;
                    });
                }
                // 保存操作历史记录
                SaveHistory(new TB_AccountHistory()
                {
                    ActionId = ActionInstance.Find(f => f.Name.Equals("EditWorkDetail")).id,
                    ObjectA  = WorkDetailInstance.ToString(obj)
                });

                ShowNotification("../service/as_work_details.aspx?key=" + hidKey.Value, "Add new work.");
            }
            else
            {
                ShowNotification("../service/as_work_dispatch.aspx", "This work is not exist.", false);
            }
        }
Exemplo n.º 20
0
        private void ShowTerminals()
        {
            var totalRecords = 0;
            var pageIndex    = "" == hidPageIndex.Value ? 1 : int.Parse(hidPageIndex.Value);
            var list         = TerminalInstance.FindPageList <TB_Terminal>(pageIndex, PageSize, out totalRecords,
                                                                           f => f.Delete == false && f.HasBound == false && f.Type == TerminalType, "Number");
            var totalPages = totalRecords / PageSize + (totalRecords % PageSize > 0 ? 1 : 0);

            string html = "";

            if (totalRecords < 1)
            {
                html = "<tr><td colspan=\"6\">No records</tr>";
            }
            else
            {
                var cnt = (pageIndex - 1) * PageSize;
                var n   = (int?)null;
                foreach (var obj in list)
                {
                    cnt++;
                    var id = Utility.UrlEncode(Utility.Encrypt(obj.id.ToString()));
                    html += "<tr>" +
                            "<td style=\"text-align: center;\"><input type=\"radio\" name=\"satId\" id=\"cb_" + id + "\" /></td>" +
                            "<td style=\"text-align: center;\">" + cnt + "</td>" +
                            "<td><a>" + obj.Number + "</a></td>" +
                            "<td>" + obj.Sim + "</td>" +
                            "<td>" + (n == obj.Satellite ? "-" : obj.TB_Satellite.CardNo) + "</td>" +
                            "<td>" + TerminalTypes.GetTerminalType(obj.Type.Value) + "</td>" +
                            "<td></td>" +
                            "</tr>";
                }
            }
            tbodyBody.InnerHtml  = html;
            divPagging.InnerHtml = "";
            if (totalRecords > 0)
            {
                ShowPaggings(pageIndex, totalPages, totalRecords, "./terminals.aspx", divPagging);
            }
        }
Exemplo n.º 21
0
 /// <summary>
 /// 更新在线时间和在线状态
 /// </summary>
 private void HandleOnline(string sim, ushort CommandID)
 {
     // 更新设备在线状态为卫星通信
     EquipmentInstance.Update(f => f.TB_Terminal.Sim.Equals(sim) && f.Deleted == false, act =>
     {
         act.IP             = "";
         act.Port           = 0;
         act.Socket         = 0;
         act.OnlineTime     = DateTime.Now;
         act.OnlineStyle    = (byte)(LinkType.SATELLITE);
         act.LastAction     = "0x" + CustomConvert.IntToDigit(CommandID, CustomConvert.HEX, 4);
         act.LastActionBy   = "SAT";
         act.LastActionTime = DateTime.Now;
     });
     // 更新终端在线状态为卫星通信
     TerminalInstance.Update(f => f.Sim.Equals(sim), act =>
     {
         act.Socket      = 0;
         act.OnlineStyle = (byte)(LinkType.SATELLITE);
         act.OnlineTime  = DateTime.Now;
     });
 }
Exemplo n.º 22
0
        /// <summary>
        /// 显示已选择的终端的信息
        /// </summary>
        private void ShowTerminalInfo()
        {
            var id       = int.Parse(Utility.Decrypt(hidTerminalId.Value));
            var terminal = TerminalInstance.Find(f => f.id == id);

            if (null == terminal)
            {
                ShowNotification("./terminal_list.aspx", "Error: terminal not exist.", false);
            }
            else
            {
                hiddenType.Value  = terminal.Type.Value.ToString();
                terType.InnerText = Wbs.Protocol.TerminalTypes.GetTerminalType(terminal.Type.Value);
                terminalinfo.Rows[1].Cells[1].InnerText = terminal.Number;
                terminalinfo.Rows[1].Cells[3].InnerText = terminal.Sim;
                terminalinfo.Rows[1].Cells[5].InnerText = (int?)null == terminal.Satellite ? "-" : terminal.TB_Satellite.CardNo;

                terminalinfo.Rows[2].Cells[1].InnerText = terminal.Firmware;
                terminalinfo.Rows[2].Cells[3].InnerText = (DateTime?)null == terminal.OnlineTime ? "-" : terminal.OnlineTime.Value.ToString("yyyy/MM/dd HH:mm:ss");
                terminalinfo.Rows[2].Cells[5].InnerHtml = Utility.GetOnlineStyle(terminal.OnlineStyle, terminal.OnlineTime, false);
            }
        }
Exemplo n.º 23
0
        internal TerminalSink()
        {
            this.outputHandle = TerminalInstance.CreateFileW(
                "CONOUT$",
                0x40000000,
                2,
                IntPtr.Zero,
                FileMode.Open,
                0,
                IntPtr.Zero);

            if (this.outputHandle.IsInvalid)
            {
                Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
            }

            this.outputStreamHandle = TerminalInstance.GetStdHandle(STD_OUTPUT_HANDLE);
            if (this.outputStreamHandle.IsInvalid)
            {
                Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// 处理终端版本的信息
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="terminal"></param>
        private void HandleTerminalVersion(TX300 obj, TB_Terminal terminal)
        {
            // 处理终端版本信息
            byte[] version = new byte[7];
            byte   rev     = 0;

            if (obj.CommandID == 0xDD00)
            {
                Buffer.BlockCopy(obj.MsgContent, 0, version, 0, 7);
            }
            else if (obj.CommandID == 0x1001)
            {
                Buffer.BlockCopy(obj.MsgContent, 25, version, 0, 7);
                // revision
                rev = obj.MsgContent[32];
            }
            else
            {
                Buffer.BlockCopy(obj.MsgContent, 0, version, 0, 7);
            }
            string ver = ASCIIEncoding.ASCII.GetString(version);

            version = null;
            if (obj.CommandID == 0xBB00)
            {
                // revision
                string s = ASCIIEncoding.ASCII.GetString(obj.MsgContent, 7, 2);
                rev = byte.Parse(s);
            }
            TerminalInstance.Update(f => f.id == terminal.id, act =>
            {
                act.Firmware = ver;
                if (rev > 0)
                {
                    act.Revision = rev;
                }
            });
        }
Exemplo n.º 25
0
        protected void btDelete_Click(object sender, EventArgs e)
        {
            if (!HasSessionLose)
            {
                if ("" != hidID.Value)
                {
                    var ids  = GetIdList(hidID.Value.Split(new char[] { ',' }));
                    var list = TerminalInstance.FindList(f => ids.Contains(f.id) && f.Delete == false);
                    foreach (var terminal in list)
                    {
                        terminal.Delete = true;
                        Update(terminal);

                        SaveHistory(new TB_AccountHistory
                        {
                            ActionId = ActionInstance.Find(f => f.Name.Equals("DeleteTerminal")).id,
                            ObjectA  = TerminalInstance.ToString(terminal)
                        });
                    }
                    ShowNotification("./terminal_list.aspx", "Success: You have delete " + ids.Count() + " terminal(s).");
                }
            }
        }
Exemplo n.º 26
0
 /// <summary>
 /// 关闭bll
 /// </summary>
 private void CloseBlls()
 {
     EquipmentInstance.Close();
     TerminalInstance.Close();
 }
Exemplo n.º 27
0
        private void BindEquipment(int terminal, int equipment)
        {
            var ter = TerminalInstance.Find(f => f.id == terminal);

            if (null == ter)
            {
                ShowNotification("./terminal_list.aspx", "Error: Cannot find the terminal.", false);
                return;
            }
            else if (ter.HasBound == true)
            {
                ShowNotification("./terminal_list.aspx", "Error: The terminal \"" + ter.Number + "\" has been bound before this time.", false);
                return;
            }
            var equ = EquipmentInstance.Find(f => f.id == equipment && f.Deleted == false);

            if (null == equ)
            {
                ShowNotification("./terminal_list.aspx", "Error: Cannot find the equipment.", false);
                return;
            }
            else if (equ.Terminal > 0)
            {
                ShowNotification("./terminal_list.aspx", "Error: The equipment \"" +
                                 EquipmentInstance.GetFullNumber(equ) + "\" has bound an other terminal: \"" + equ.TB_Terminal.Number + "\".", false);
                return;
            }

            // 开始绑定流程
            var storage = StatusInstance.Find(f => f.IsItInventory == true);

            EquipmentInstance.Update(f => f.id == equ.id && f.Deleted == false, act =>
            {
                act.Terminal = ter.id;
                // 更新设备的相应信息为终端的信息
                act.OnlineStyle = ter.OnlineStyle;
                act.OnlineTime  = ter.OnlineTime;
                act.Socket      = ter.Socket;
                // 新品等待入库的,绑定终端之后直接确定为库存状态
                act.Status = storage.id;
            });
            TerminalInstance.Update(f => f.id == ter.id, act => { act.HasBound = true; });

            // 保存入库信息
            var history = StoreInstance.GetObject();

            history.Equipment = equ.id;
            history.Status    = storage.id;
            history.Stocktime = DateTime.Now;
            // 绑定终端时,入库次数不变
            history.StoreTimes = equ.StoreTimes;
            history.Warehouse  = equ.Warehouse;
            StoreInstance.Add(history);

            // 保存操作历史记录
            SaveHistory(new TB_AccountHistory()
            {
                ActionId = ActionInstance.Find(f => f.Name.Equals("Bind")).id,
                ObjectA  = "bind equipment " + EquipmentInstance.GetFullNumber(equ) + " and terminal " + ter.Number
            });

            ShowNotification("./terminal_list.aspx", "You have bound \"" + ter.Number + "\" on equipment \"" +
                             EquipmentInstance.GetFullNumber(equ) + "\"");
        }
Exemplo n.º 28
0
        private async void ConnectToDeviceButton_Tapped(object sender, TappedRoutedEventArgs e)
        {
            var device = (Model.Device)DevicesView.SelectedItem;

            if (device == null)
            {
                return;
            }

            var terminals = Terminals.Instance;

            var destinationUri   = new Uri(device.Destination);
            var terminalInstance = terminals.Where(x => x.Connection.Destination.Equals(destinationUri)).SingleOrDefault();

            if (terminalInstance == null)
            {
                terminalInstance = new TerminalInstance();
                terminalInstance.PropertyChanged += TerminalInstance_PropertyChanged;

                terminals.Add(terminalInstance);
            }

            var username = string.Empty;
            var password = string.Empty;

            if (device.AuthenticationMethod == Model.EAuthenticationMethod.NoAuthentication)
            {
            }
            else if (device.AuthenticationMethod == Model.EAuthenticationMethod.UsernamePassword)
            {
                username = device.Username;
                password = await device.Password.Unprotect();
            }
            else
            {
                var authenticationProfile = Model.Context.Current.AuthenticationProfiles.Where(x => x.Id == device.AuthenticationProfileId).SingleOrDefault();
                if (authenticationProfile == null)
                {
                    System.Diagnostics.Debug.WriteLine("Failed to find an authentication profile");
                    return;
                }
                username = authenticationProfile.Username;
                password = await device.Password.Unprotect();
            }

            DisconnectToDeviceButton.ClearValue(IsEnabledProperty);

            var newBinding = new Binding
            {
                Source = device,
                Path   = new PropertyPath("Connected"),
                Mode   = BindingMode.TwoWay
            };

            DisconnectToDeviceButton.SetBinding(IsEnabledProperty, newBinding);

            if (!terminalInstance.ConnectTo(new Uri(device.Destination), username, password))
            {
                System.Diagnostics.Debug.WriteLine("Failed to connect to destination");
                return;
            }
        }
Exemplo n.º 29
0
        private void ShowFlow()
        {
            var month = int.Parse(selectedMonths.Value);

            spanMonthly.InnerText = string.Format("for {0}{1:00}", selectedYears.Value, (month == 0 ? " full year" : ("/" + month.ToString("00"))));

            var query = txtQueryNumber.Value.Trim();

            // 模糊查询时页码置为空
            if (!string.IsNullOrEmpty(query))
            {
                hidPageIndex.Value = "";
            }

            var totalRecords = 0;
            var pageIndex    = "" == hidPageIndex.Value ? 1 : int.Parse(hidPageIndex.Value);
            var list         = TerminalInstance.FindPageList <TB_Terminal>(pageIndex, PageSize, out totalRecords,
                                                                           f => f.Delete == false && (f.Sim.Contains(query) || f.TB_Satellite.CardNo.Contains(query)), "Number");
            var totalPages = totalRecords / PageSize + (totalRecords % PageSize > 0 ? 1 : 0);

            var    monthly = int.Parse(string.Format("{0}{1:00}", selectedYears.Value, month));
            string html    = "";

            if (totalRecords < 1)
            {
                html = "<tr><td colspan=\"13\">No records, Change condition and try again.</td></tr>";
            }
            else
            {
                var cnt = (pageIndex - 1) * PageSize;
                var n   = (int?)null;
                foreach (var obj in list)
                {
                    cnt++;
                    // var id = Utility.UrlEncode(Utility.Encrypt(obj.id.ToString()));
                    // 查找绑定的设备信息
                    var equipment = obj.TB_Equipment.FirstOrDefault();
                    // 查找选定月的流量统计
                    var flow = obj.TB_TerminalFlow.Where <TB_TerminalFlow>(o => (month == 0 ?
                                                                                 (o.Monthly >= monthly && o.Monthly <= monthly + 100) :
                                                                                 o.Monthly == monthly));

                    var _flow = FlowInstance.GetObject();
                    _flow.GPRSDeliver = flow.Select(s => s.GPRSDeliver).Sum();
                    _flow.GPRSReceive = flow.Select(s => s.GPRSReceive).Sum();
                    _flow.SMSDeliver  = flow.Select(s => s.SMSDeliver).Sum();
                    _flow.SMSReceive  = flow.Select(s => s.SMSReceive).Sum();
                    // 查找选定月的铱星流量
                    var _sat = IridiumInstance.GetObject();
                    if (obj.Satellite != n)
                    {
                        var sat = obj.TB_Satellite.TB_IridiumFlow.Where(w => (month == 0 ?
                                                                              (w.Monthly >= monthly && w.Monthly <= monthly + 100) : w.Monthly == monthly));
                        _sat.MOPayload = sat.Select(s => s.MOPayload).Sum();
                        _sat.MOTimes   = sat.Select(s => s.MOTimes).Sum();
                        _sat.MTPayload = sat.Select(s => s.MTPayload).Sum();
                        _sat.MTTimes   = sat.Select(s => s.MTTimes).Sum();
                    }

                    html += "<tr>" +
                            "<td class=\"in-tab-txt-b\">" + cnt + "</td>" +
                            "<td class=\"in-tab-txt-b\" style=\"text-align: left;\">" + (null == equipment ? "not bind" : EquipmentInstance.GetFullNumber(equipment)) + "</td>" +
                            "<td class=\"in-tab-txt-rb\" style=\"text-align: left;\">" + obj.Number + "</td>" +
                            "<td class=\"in-tab-txt-b\">" + CustomConvert.FormatSize(_flow.GPRSReceive.Value) + "</td>" +
                            "<td class=\"in-tab-txt-rb\">" + CustomConvert.FormatSize(_flow.GPRSDeliver.Value) + "</td>" +
                            "<td class=\"in-tab-txt-b\">" + _flow.SMSReceive.Value.ToString() + "</td>" +
                            "<td class=\"in-tab-txt-rb\">" + _flow.SMSDeliver.Value.ToString() + "</td>" +
                            "<td class=\"in-tab-txt-rb\" style=\"text-align: left;\">" + (n == obj.Satellite ? "not bind" : obj.TB_Satellite.CardNo) + "</td>" +
                            "<td class=\"in-tab-txt-b\">" + _sat.MOTimes.Value.ToString() + "</td>" +
                            "<td class=\"in-tab-txt-rb\">" + CustomConvert.FormatSize(_sat.MOPayload.Value) + "</td>" +
                            "<td class=\"in-tab-txt-b\">" + _sat.MTTimes.Value.ToString() + "</td>" +
                            "<td class=\"in-tab-txt-b\">" + CustomConvert.FormatSize(_sat.MTPayload.Value) + "</td>" +
                            "<td class=\"in-tab-txt-b\"></td>" +
                            "</tr>";
                }
            }
            tbodyBody.InnerHtml  = html;
            divPagging.InnerHtml = "";
            if (totalRecords > 0)
            {
                ShowPaggings(pageIndex, totalPages, totalRecords, "./terminal_flow.aspx", divPagging);
            }
        }
Exemplo n.º 30
0
 public static async Task Main(string[] args)
 {
     using (TerminalInstance terminal = await TerminalInstance.GetInstanceAsync(default))