Пример #1
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;
            });
        }
Пример #2
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);
                }
            }
        }
Пример #3
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);
            }
        }
Пример #4
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.");
        }
Пример #5
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!");
                }
            }
        }
Пример #6
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;
     });
 }
Пример #7
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;
     });
 }
Пример #8
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;
     });
 }
Пример #9
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.");
         }
     }
 }
Пример #10
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);
            }
        }
Пример #11
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;
     });
 }
Пример #12
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;
                }
            });
        }
Пример #13
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) + "\"");
        }
Пример #14
0
        protected void btBoundSatellite_Click(object sender, EventArgs e)
        {
            var value = hidBoundSatellite.Value.Trim();

            if (string.IsNullOrEmpty(value))
            {
                return;
            }
            // 为终端绑定卫星模块
            var index = value.IndexOf(',');

            if (index < 0)
            {
                // 没有,分割的是解绑卫星模块
                UnboundSatellite();
                return;
            }
            var tid = value.Substring(0, index);
            var gid = value.Substring(index + 1);

            gid = Utility.Decrypt(gid);
            var t = TerminalInstance.Find(f => f.id == int.Parse(tid));

            if (null == t)
            {
                ShowNotification("./terminal_list.aspx", "Bound fail: Terminal not exists.", false);
            }
            else
            {
                if (t.Satellite != (int?)null)
                {
                    ShowNotification("./terminal_list.aspx", "Terminal \"" + t.Number + "\" has bound Satellite: " + t.TB_Satellite.CardNo, false);
                }
                else
                {
                    var g = SatelliteInstance.Find(f => f.id == int.Parse(gid));
                    if (null == g)
                    {
                        ShowNotification("./terminal_list.aspx", "No Satellite info exists.", false);
                    }
                    else
                    {
                        if (g.Bound == true)
                        {
                            var gt = TerminalInstance.Find(f => f.TB_Satellite.id == g.id);
                            ShowNotification("./terminal_list.aspx", "Satellite \"" + g.CardNo + "\" has bound on Terminal: " + gt.Number, false);
                        }
                        else
                        {
                            TerminalInstance.Update(f => f.id == t.id, act =>
                            {
                                act.Satellite = g.id;
                            });
                            t = TerminalInstance.Find(f => f.id == t.id);
                            SatelliteInstance.Update(f => f.id == g.id, act => { act.Bound = true; });
                            // 发送绑定卫星模块的命令
                            SendDD02Command(true, t);
                            // 保存绑定卫星模块的历史记录
                            SaveHistory(new TB_AccountHistory()
                            {
                                ActionId = ActionInstance.Find(f => f.Name.Equals("BindSat")).id,
                                ObjectA  = TerminalInstance.ToString(t)
                            });
                            //ShowTerminals();
                            ShowNotification("./terminal_list.aspx", "Terminal \"" + t.Number + "\" bound Satellite \"" + g.CardNo + "\" OK!");
                        }
                    }
                }
            }
        }
Пример #15
0
        /// <summary>
        /// 保存设备的更改信息
        /// </summary>
        private void SaveChanges()
        {
            var    id = ParseInt(Utility.Decrypt(_key));
            var    equipment = EquipmentInstance.Find(f => f.id == id && f.Deleted == false);
            bool   needSave = false;
            string msg = "";
            int    wh = 0, md = 0;

            if (null != equipment)
            {
                msg = EquipmentInstance.GetFullNumber(equipment);
                var tmp = int.Parse(hidWarehouse.Value);
                if (tmp > 0)
                {
                    var oh = WarehouseInstance.Find(f => f.id == equipment.Warehouse);
                    var nh = WarehouseInstance.Find(f => f.id == tmp && f.Delete == false);
                    msg += ", " + oh.Name + " to " + nh.Name;
                    //equipment.Warehouse = tmp;
                    wh       = tmp;
                    needSave = true;
                }
                tmp = int.Parse(selectedModel.Value);
                if (tmp > 0)
                {
                    var om = ModelInstance.Find(f => f.id == equipment.Model);
                    var nm = ModelInstance.Find(f => f.id == tmp && f.Delete == false);
                    msg += ", " + om.Code + " to " + nm.Code;
                    //equipment.Model = tmp;
                    md       = tmp;
                    needSave = true;
                }
                tmp = int.Parse(hidFunctional.Value);
                if (tmp != 0 && tmp != int.Parse(oldFunc.Value))
                {
                    msg += ", " + Utility.GetEquipmentFunctional(equipment.Functional.Value) + " to " + Utility.GetEquipmentFunctional((byte)tmp);
                    equipment.Functional = (byte)tmp;
                    needSave             = true;
                }
                var num = number.Value.Trim();
                if (!string.IsNullOrEmpty(num))
                {
                    if (!num.Equals(equipment.Number))
                    {
                        msg += ", Number: " + equipment.Number + " to " + num;
                        equipment.Number = num;
                        needSave         = true;
                    }
                }
                //tmp = int.Parse(Utility.Decrypt(Utility.UrlDecode(oldTerminal.Value)));
                var         n      = string.IsNullOrEmpty(newTerminal.Value) ? 0 : int.Parse(Utility.Decrypt(Utility.UrlDecode(newTerminal.Value)));
                TB_Terminal newOne = null;
                if (n > 0)
                {
                    msg += ", Terminal: ";
                    // 更新旧终端为未绑定状态
                    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 " + ter + " and equipment " + EquipmentInstance.GetFullNumber(equipment)
                        });
                        msg += ter + "(unbind) to ";
                    }
                    newOne             = TerminalInstance.Find(f => f.id == n);
                    msg               += newOne.Number + "(bind)";
                    equipment.Terminal = n;
                    // 更新新终端的绑定状态
                    TerminalInstance.Update(f => f.id == n, act => { act.HasBound = true; });
                    // 保存新终端的绑定状态
                    SaveHistory(new TB_AccountHistory()
                    {
                        ActionId = ActionInstance.Find(f => f.Name.Equals("Unbind")).id,
                        ObjectA  = "bind terminal " + newOne.Number + " and equipment " + EquipmentInstance.GetFullNumber(equipment)
                    });
                    needSave = true;
                }
                if (needSave)
                {
                    EquipmentInstance.Update(f => f.id == equipment.id && f.Deleted == false, act =>
                    {
                        if (md > 0)
                        {
                            //if (act.Model != equipment.Model)
                            act.Model = md;
                        }
                        if (wh > 0)
                        {
                            //if (act.Warehouse != equipment.Warehouse)
                            act.Warehouse = wh;
                        }
                        if (!act.Number.Equals(equipment.Number))
                        {
                            act.Number = equipment.Number;
                        }
                        if (act.Functional != equipment.Functional)
                        {
                            act.Functional = equipment.Functional;
                        }
                        if (act.Terminal != equipment.Terminal)
                        {
                            act.Terminal    = equipment.Terminal;
                            act.Socket      = newOne.Socket;
                            act.OnlineTime  = newOne.OnlineTime;
                            act.OnlineStyle = newOne.OnlineStyle;
                        }
                    });
                    // 保存更改设备信息的历史
                    SaveHistory(new TB_AccountHistory()
                    {
                        ActionId = ActionInstance.Find(f => f.Name.Equals("EditEquipmentInfo")).id,
                        ObjectA  = msg
                    });
                    ShowNotification("./equipment_setting.aspx?key=" + Utility.UrlEncode(_key), "You have saved the equipment info.", true);
                }
            }
            else
            {
                ShowNotification("./equipment_setting.aspx?key=" + Utility.UrlEncode(_key), "Not found the equipment", false);
            }
        }