/// <summary>
        /// 生成请求
        /// </summary>
        /// <returns></returns>
        private string HandleQueryEquipmentWorkTime2Excel()
        {
            var id    = ParseInt(Utility.Decrypt(data));
            var obj   = EquipmentInstance.Find(f => f.id == id && f.Deleted == false);
            var json  = HandleQueryEquipmentWorktime(false);
            var date1 = GetParamenter("date");
            var date2 = GetParamenter("date1");
            var daily = DailyInstance.Find(f => f.Equipment == id && f.Type == (byte)ExcelExportType.DailyWork &&
                                           f.Deleted == false && f.StartDate == date1 && f.EndDate == date2);

            if (null == daily)
            {
                daily           = DailyInstance.GetObject();
                daily.Data      = json;
                daily.Equipment = id;
                daily.Type      = (byte)ExcelExportType.DailyWork;
                // json为空时,不需要处理了
                daily.Handled   = string.IsNullOrEmpty(json) || json.Equals("[]");
                daily.StartDate = GetParamenter("date");
                daily.EndDate   = GetParamenter("date1");
                daily           = DailyInstance.Add(daily);
            }
            else
            {
                DailyInstance.Update(f => f.id == daily.id, act =>
                {
                    act.Data = json;
                    // json为空时,不需要处理了
                    daily.Handled = string.IsNullOrEmpty(json) || json.Equals("[]");
                });
            }

            return(DailyWorkReturn(0, "SUCCESS", daily.id.ToString()));
        }
Esempio n. 2
0
        /// <summary>
        /// 显示待修改的设备的信息
        /// </summary>
        private void ShowOldInformations()
        {
            var id        = ParseInt(Utility.Decrypt(_key));
            var equipment = EquipmentInstance.Find(f => f.id == id && f.Deleted == false);

            if (null != equipment)
            {
                number.Value  = equipment.Number;
                old.Value     = equipment.Number;
                oldFunc.Value = equipment.Functional.Value.ToString();
                if (equipment.Terminal != (int?)null)
                {
                    oldTerminal.Value = Utility.UrlEncode(Utility.Encrypt(equipment.Terminal.Value.ToString()));
                    terminalInfo.Cells[1].InnerHtml = equipment.TB_Terminal.Number + " <a href=\"#unbind\">Unbind?</a>";
                    terminalInfo.Cells[3].InnerText = equipment.TB_Terminal.Sim;
                }
                else
                {
                    oldTerminal.Value = "";
                    terminalInfo.Cells[1].InnerHtml = "<a href=\"#bind\">Click here to bind</a>";
                    terminalInfo.Cells[3].InnerText = "-";
                }
            }
            // 显示设备的类型
            ShowEquipmentFunctional();
        }
Esempio n. 3
0
        /// <summary>
        /// 查询设备的运转时间
        /// </summary>
        /// <returns></returns>
        private string HandleEquipment6004()
        {
            var ret = "{}";
            var id  = ParseInt(Utility.Decrypt(data));
            var obj = EquipmentInstance.Find(f => f.id == id && f.Deleted == false);

            if (null != obj)
            {
                var date     = DateTime.Parse(GetParamenter("date") + " 23:59:59");
                var runtimes = DataInstance.FindList(f => f.mac_id.Equals(EquipmentInstance.GetFullNumber(obj)) &&
                                                     f.command_id.Equals("0x6004") && f.receive_time < date).OrderByDescending(o => o.receive_time).FirstOrDefault();
                if (null != runtimes)
                {
                    _0x6004DX x6004 = new _0x6004DX();
                    x6004.Command     = "0x6004";
                    x6004.HexContent  = runtimes.message_content;
                    x6004.DataType    = doosan.DX;
                    x6004.MacID       = obj.TB_EquipmentModel.Code + obj.Number;
                    x6004.ReceiveTime = runtimes.receive_time.Value;
                    x6004.SimNo       = runtimes.terminal_id;
                    x6004.Unpackage();
                    ret = JsonConverter.ToJson(x6004);
                }
            }
            return(ret);
        }
Esempio n. 4
0
        private void ShowWorkDetails(TB_Work work)
        {
            var html = "";

            if (null == work || work.TB_WorkDetail.Count < 1)
            {
                html = "<tr><td colspan=\"8\">No equipment(s) exist.</td></tr>";
            }
            else
            {
                var cnt = 0;
                var n   = (int?)null;
                foreach (var obj in work.TB_WorkDetail)
                {
                    cnt++;
                    html += "<tr>" +
                            "<td style=\"text-align: center;\">" + cnt + "</td>" +
                            "<td>" + (n == obj.Equipment ? "-" : EquipmentInstance.GetFullNumber(obj.TB_Equipment)) + "</td>" +
                            "<td class=\"textoverflow\">" + WorkDetailInstance.GetWorkType(obj.Type.Value) + "</td>" +
                            "<td>" + (n == obj.BookedTerminal ? "-" : obj.TB_Terminal.Number) + "</td>" +
                            "<td>" + (n == obj.BookedTerminal ? "-" : obj.TB_Terminal.Sim) + "</td>" +
                            "<td>" + (n == obj.BookedTerminal ? "-" : (n == obj.TB_Terminal.Satellite ? "-" : obj.TB_Terminal.TB_Satellite.CardNo)) + "</td>" +
                            "<td style=\"text-align: left;\">" + obj.Details + "</td>" +
                            "<td></td>" +
                            "</tr>";
                }
            }
            tbodyBody.InnerHtml = html;
        }
Esempio n. 5
0
        /// <summary>
        /// 处理报警信息
        /// </summary>
        /// <param name="obj"></param>
        private void Handle0x2000(TX300 obj, TB_Equipment equipment, TB_Terminal terminal)
        {
            // 报警
            _0x2000 x2000 = new _0x2000();

            x2000.Content = obj.MsgContent;
            x2000.Unpackage();
            if (null != equipment)
            {
                EquipmentInstance.Update(f => f.id == equipment.id, act =>
                {
                    if (x2000.AlarmBIN[0] == '1')
                    {
                        // Main Power Disconnect
                        act.Voltage = "G0000";
                        // 主电断报警之后进入睡眠状态
                        act.OnlineStyle = (byte)LinkType.SLEEP;
                    }
                    if (x2000.GPSInfo.Available)
                    {
                        act.Latitude   = x2000.GPSInfo.Latitude;
                        act.Longitude  = x2000.GPSInfo.Longitude;
                        act.GpsUpdated = false;
                    }
                });
            }
            if (x2000.GPSInfo.Available)
            {
                SaveGpsInfo(x2000.GPSInfo, equipment, obj.TerminalID, "0x2000");
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 处理设备的开关机信息
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="equipment"></param>
        /// <param name="terminal"></param>
        private void Handle0x5000(TX300 obj, TB_Equipment equipment, TB_Terminal terminal)
        {
            // 发动机启动/关闭信息
            _0x5000 x5000 = new _0x5000();

            x5000.Content = obj.MsgContent;
            x5000.Unpackage();
            if (null != equipment)
            {
                EquipmentInstance.Update(f => f.id == equipment.id, act =>
                {
                    act.Voltage = string.Format("G{0}", ((int)Math.Floor(x5000.GeneratorVoltage * 10)).ToString("0000"));

                    if (x5000.GPSInfo.Available)
                    {
                        act.Latitude   = x5000.GPSInfo.Latitude;
                        act.Longitude  = x5000.GPSInfo.Longitude;
                        act.GpsUpdated = false;
                    }
                });
            }
            if (x5000.GPSInfo.Available)
            {
                SaveGpsInfo(x5000.GPSInfo, equipment, obj.TerminalID, "0x5000");
            }
        }
Esempio n. 7
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);
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// 处理定期报告信息
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="equipment"></param>
        /// <param name="terminal"></param>
        private void Handle0x1001(TX300 obj, TB_Equipment equipment, TB_Terminal terminal)
        {
            _0x1001 x1001 = new _0x1001();

            x1001.Content = obj.MsgContent;
            x1001.Unpackage();
            if (null != equipment)
            {
                EquipmentInstance.Update(f => f.id == equipment.id, act => {
                    act.Signal = x1001.CSQ_1 > 0 ? x1001.CSQ_1 : (x1001.CSQ_2 > 0 ? x1001.CSQ_2 : byte.MinValue);
                    if (x1001.WorkTime > 0)
                    {
                        act.Runtime = (int)x1001.WorkTime;
                    }
                });
            }

            var pos = GetGpsinfoFrom1001(x1001, true);

            pos.Equipment  = null == equipment ? (int?)null : equipment.id;
            pos.Terminal   = obj.TerminalID;
            pos.StoreTimes = null == equipment ? 0 : equipment.StoreTimes;
            PositionInstance.Add(pos);

            pos            = GetGpsinfoFrom1001(x1001, false);
            pos.Equipment  = null == equipment ? (int?)null : equipment.id;
            pos.Terminal   = obj.TerminalID;
            pos.StoreTimes = null == equipment ? 0 : equipment.StoreTimes;
            PositionInstance.Add(pos);
        }
Esempio n. 9
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;
            });
        }
Esempio n. 10
0
        /// <summary>
        /// 显示我作为购买者名下的所有设备列表
        /// </summary>
        private void ShowMyDevices()
        {
            var items = EquipmentInstance.FindList(f => f.Customer == me.id && f.Deleted == false);
            var html  = "";

            foreach (var item in items)
            {
                var eng = EquipmentInstance.GetEngStatus(item);
                html += "<dl class=\"invest-type\" id=\"" + item.id.ToString() + "\">" +
                        "            <dt>" +
                        "                <span class=\"iconleft\">" +
                        "                    <img class=\"img-rounded ex\" src=\"" + item.TB_EquipmentModel.TB_EquipmentType.Image + "\">" +
                        "                </span>" + EquipmentInstance.GetFullNumber(item) +
                        "                <em class=\"status\">" + item.TB_EquipmentModel.TB_EquipmentType.Name + "</em>" +
                        "            </dt>" +
                        "            <dd>" +
                        "                <span class=\"text-" + (eng.Equals("ON") ? "success" : "danger") + "\"><span class=\"signal cell-engine\"></span> Engine " + eng + "</span>" +
                        "                <em class=\"status\"><span class=\"glyphicon glyphicon-time\"></span> " + EquipmentBLL.GetRuntime(item.Runtime + item.InitializedRuntime, item.CompensatedHours.Value) + "</em>" +
                        "            </dd>" +
                        "            <dd>" +
                        "                <span class=\"text-info\"><span class=\"signal cell-signal-" + Utility.ASU2Signal(item.Signal.Value) + "\"></span> Signal: " + Utility.ASU2DBM(item.Signal.Value) + "dBm(ASU: " + item.Signal + ")</span>" +
                        "                <div class=\"total-num\">" + Utility.GetOnlineStyle(item.OnlineStyle, item.OnlineTime, false) + "</div>" +
                        "            </dd>" +
                        "            <dd class=\"desc\"><span class=\"glyphicon glyphicon-globe\"></span> " + item.GpsAddress + "</dd>" +
                        "</dl>";
            }
            equipmentItems.InnerHtml = html;
        }
Esempio n. 11
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);
                }
            }
        }
Esempio n. 12
0
        /// <summary>
        /// 处理终端OFF的信息
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="equipment"></param>
        /// <param name="terminal"></param>
        private void Handle0xFF00(TX300 obj, TB_Equipment equipment, TB_Terminal terminal)
        {
            // 终端没电关机
            _0xFF00 xff00 = new _0xFF00();

            xff00.Content = obj.MsgContent;
            xff00.Unpackage();
            if (null != equipment)
            {
                EquipmentInstance.Update(f => f.id == equipment.id, act =>
                {
                    act.Voltage     = "G0000";
                    act.OnlineStyle = (byte)LinkType.OFF;
                    if (xff00.GPSInfo.Available)
                    {
                        act.Latitude   = xff00.GPSInfo.Latitude;
                        act.Longitude  = xff00.GPSInfo.Longitude;
                        act.GpsUpdated = false;
                    }
                });
            }
            if (xff00.GPSInfo.Available)
            {
                SaveGpsInfo(xff00.GPSInfo, equipment, obj.TerminalID, "0xFF00");
            }
        }
Esempio n. 13
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);
            }
        }
Esempio n. 14
0
        protected void btCheckoutStorage_Click(object sender, EventArgs e)
        {
            var id        = int.Parse(hidCheckEquipmentId.Value);
            var equipment = EquipmentInstance.Find(f => f.id == id && f.Deleted == false);

            if (null == equipment)
            {
                ShowNotification("./equipment_checkout.aspx", "Cannot find the equipment.", false);
                //return;
            }
            else
            {
                DateTime begin;
                try { begin = DateTime.Parse(outTime.Value.Trim()); }
                catch { begin = DateTime.Now; }

                EquipmentInstance.Update(f => f.id == equipment.id, act =>
                {
                    // 出厂时,如果是普通车辆,则直接划为车辆状态,不参与出库/入库流程
                    if (act.TB_EquipmentModel.TB_EquipmentType.IsVehicle == true)
                    {
                        act.Status = StatusInstance.Find(f => f.IsItVehicle == true).id;
                    }
                    else
                    {
                        act.Status = int.Parse(ddlOuttype.SelectedValue);
                    }
                    act.Customer = int.Parse(hidCheckCustomerId.Value);
                    // 出库时的总运转时间
                    act.OutdoorWorktime = equipment.Runtime;
                    // 出库的时间
                    act.OutdoorTime = begin;
                    // 出库后库存信息置为null
                    act.Warehouse = null;
                });
                equipment = EquipmentInstance.Find(f => f.id == equipment.id);
                // 保存出库历史记录
                var history = StoreInstance.GetObject();
                history.Equipment = equipment.id;
                history.Status    = equipment.Status;
                history.Stocktime = begin;
                // 设备的出入库次数,入库时增1,出库时不变
                history.StoreTimes = equipment.StoreTimes;
                history.Warehouse  = null;
                StoreInstance.Add(history);

                // 保存操作历史记录
                SaveHistory(new TB_AccountHistory()
                {
                    ActionId = ActionInstance.Find(f => f.Name.Equals("Deliver")).id,
                    ObjectA  = EquipmentInstance.GetFullNumber(equipment) +
                               " check out(" + ddlOuttype.SelectedItem.Text + ") to: " + equipment.TB_Customer.Name
                });

                ShowNotification("./equipment_checkout.aspx", "\"" + EquipmentInstance.GetFullNumber(equipment) + "\" has delivered.");
            }
        }
Esempio n. 15
0
        private void ShowEquipments()
        {
            var totalRecords = 0;
            var pageIndex    = "" == hidPageIndex.Value ? 1 : int.Parse(hidPageIndex.Value);

            pageIndex = (0 >= pageIndex ? 1 : pageIndex);
            var model = ParseInt(selectedModels.Value);
            var house = ParseInt(hidQueryWarehouse.Value);
            var list  = EquipmentInstance.FindPageList <TB_Equipment>(pageIndex, PageSize, out totalRecords,
                                                                      f => f.Terminal == (int?)null && f.Deleted == false && (model <= 0 ? f.Model >= 0 : f.Model == model) &&
                                                                      (house <= 0 ? (f.Warehouse >= 0 || f.Warehouse == (int?)null) : f.Warehouse == house) &&
                                                                      (f.Number.IndexOf(txtQueryNumber.Value.Trim()) >= 0), null);
            var totalPages = totalRecords / PageSize + (totalRecords % PageSize > 0 ? 1 : 0);

            string html = "";

            if (totalRecords < 1)
            {
                html = "<tr><td colspan=\"11\">No records, You can change the condition and try again.</td></tr>";
            }
            else
            {
                var cnt = (pageIndex - 1) * PageSize;
                var n   = (int?)null;
                foreach (var obj in list)
                {
                    cnt++;
                    // 入库记录
                    var _in = StoreInstance.GetStoreInfo(obj.id, obj.StoreTimes.Value, true);
                    // 出库记录
                    var _out = StoreInstance.GetStoreInfo(obj.id, obj.StoreTimes.Value, false);

                    var id = Utility.UrlEncode(Utility.Encrypt(obj.id.ToString()));

                    html += "<tr title=\"click to dispatch work\">" +
                            "<td class=\"in-tab-txt-b\">" + cnt + "</td>" +
                            "<td class=\"in-tab-txt-b\">" + (n == obj.Model ? "-" : obj.TB_EquipmentModel.TB_EquipmentType.Code) + "</td>" +
                            "<td class=\"in-tab-txt-b textoverflow\" style=\"text-align: left !important;\">" + (n == obj.Model ? "-" : ("<a>" + EquipmentInstance.GetFullNumber(obj) + "</a>")) + "</td>" +
                            "<td class=\"in-tab-txt-b\" style=\"text-align: left !important;\">" + Utility.GetEquipmentFunctional(obj.Functional.Value) + "</td>" +
                            "<td class=\"in-tab-txt-rb\" title=\"" + EquipmentInstance.GetStatusTitle(obj) + "\">" + EquipmentInstance.GetStatus(obj) + "</td>" +
                            "<td class=\"in-tab-txt-b textoverflow\">" + (null == _in ? "-" : _in.Stocktime.Value.ToString("yyyy/MM/dd")) + "</td>" +
                            "<td class=\"in-tab-txt-b\" title=\"" + StoreInstance.GetStatusTitle(_in) + "\">" + StoreInstance.GetStatus(_in) + "</td>" +
                            "<td class=\"in-tab-txt-b textoverflow\">" + (null == _out ? "-" : _out.Stocktime.Value.ToString("yyyy/MM/dd")) + "</td>" +
                            "<td class=\"in-tab-txt-b\" title=\"" + StoreInstance.GetStatusTitle(_out) + "\">" + StoreInstance.GetStatus(_out) + "</td>" +
                            "<td class=\"in-tab-txt-b textoverflow\">" + (n == obj.Warehouse ? "-" : obj.TB_Warehouse.Name) + "</td>" +
                            "<td class=\"in-tab-txt-b\"></td>" +
                            "</tr>";
                }
            }
            tbodyBody.InnerHtml  = html;
            divPagging.InnerHtml = "";
            if (totalRecords > 0)
            {
                ShowPaggings(pageIndex, totalPages, totalRecords, "./equipment_inquiry.aspx", divPagging);
            }
        }
Esempio n. 16
0
 /// <summary>
 /// 关闭已打开的bll instances
 /// </summary>
 private void CloseBlls()
 {
     TrackerPositionInstance.Close();
     StorageInstance.Close();
     PositionInstance.Close();
     EquipmentInstance.Close();
     EposInstance.Close();
     DataInstance.Close();
     DailyInstance.Close();
     CustomerInstance.Close();
     AlarmInstance.Close();
 }
        private void SaveNewEquipment()
        {
            var value     = hidNewInstorage.Value;
            var equipment = JsonConverter.ToObject <TB_Equipment>(value);
            // 查找是否有相同型号的相同设备号码
            var exist = EquipmentInstance.Find(f => f.Model == equipment.Model && f.Number.Equals(equipment.Number) && f.Deleted == false);

            if (null == exist)
            {
                var model  = ModelInstance.Find(f => f.id == equipment.Model);
                var newOne = EquipmentInstance.GetObject();
                newOne.Model = equipment.Model;
                if (model.TB_EquipmentType.IsVehicle == true)
                {
                    // 新增的设备是普通车辆时,直接划为车辆,不参与出库/入库流程
                    newOne.Status = StatusInstance.Find(f => f.IsItVehicle == true).id;
                }
                else
                {
                    newOne.Status = StatusInstance.Find(f => f.IsItInventory == true).id;
                }
                newOne.Warehouse  = equipment.Warehouse;
                newOne.Number     = equipment.Number;
                newOne.StoreTimes = equipment.StoreTimes;
                newOne.Functional = equipment.Functional;
                newOne            = EquipmentInstance.Add(newOne);

                // 保存入库信息
                var history = StoreInstance.GetObject();
                history.Equipment = newOne.id;
                history.Status    = newOne.Status;
                history.Stocktime = DateTime.Parse(inDate.Value);
                // 默认第1次入库
                history.StoreTimes = newOne.StoreTimes;
                history.Warehouse  = newOne.Warehouse;
                StoreInstance.Add(history);

                // 保存入库操作历史记录
                SaveHistory(new TB_AccountHistory()
                {
                    ActionId = ActionInstance.Find(f => f.Name.Equals("InStore")).id,
                    ObjectA  = EquipmentInstance.ToString(newOne)
                });

                ShowNotification("./equipment_new_product.aspx",
                                 "New equipment \"" + EquipmentInstance.GetFullNumber(exist) + "\" has been saved.");
            }
            else
            {
                ShowNotification("./equipment_new_product.aspx",
                                 "There has a same number of \"" + EquipmentInstance.GetFullNumber(exist) + "\" exist.", false);
            }
        }
Esempio n. 18
0
        protected void confirmRental_Click(object sender, EventArgs e)
        {
            // 租赁出库
            if (!HasSessionLose)
            {
                var id        = ParseInt(Utility.Decrypt(hiddenRentalId.Value));
                var equipment = EquipmentInstance.Find(f => f.id == id && f.Deleted == false);
                if (null == equipment)
                {
                    ShowNotification("./equipment_rental.aspx", "Cannot find the equipment.", false);
                }
                else
                {
                    DateTime begin;
                    try { begin = DateTime.Parse(beginAt.Value.Trim()); }
                    catch { begin = DateTime.Now; }

                    EquipmentInstance.Update(f => f.id == equipment.id, act =>
                    {
                        act.Status          = StatusInstance.Find(f => f.IsItRental == true).id;
                        act.Customer        = int.Parse(hiddenCustomer.Value);
                        act.OutdoorTime     = begin;
                        act.OutdoorWorktime = equipment.Runtime;
                        act.Warehouse       = null;
                        act.ReclaimTime     = DateTime.Parse(deadLine.Value + " 00:00:00");
                    });

                    equipment = EquipmentInstance.Find(f => f.id == equipment.id);
                    // 保存出库历史记录
                    var history = StoreInstance.GetObject();
                    history.Equipment = equipment.id;
                    history.Status    = equipment.Status;
                    history.Stocktime = begin;
                    // 设备的出入库次数,入库时增1,出库时不变
                    history.StoreTimes = equipment.StoreTimes;
                    history.Warehouse  = (int?)null;
                    StoreInstance.Add(history);

                    // 保存操作历史记录
                    SaveHistory(new TB_AccountHistory()
                    {
                        ActionId = ActionInstance.Find(f => f.Name.Equals("Rental")).id,
                        ObjectA  = EquipmentInstance.GetFullNumber(equipment) +
                                   " rent to: " + equipment.TB_Customer.Name + ", " +
                                   equipment.OutdoorTime.Value.ToString("yyyy/MM/dd") +
                                   " to " + equipment.ReclaimTime.Value.ToString("yyyy/MM/dd")
                    });

                    ShowNotification("./equipment_rental.aspx", "\"" +
                                     EquipmentInstance.GetFullNumber(equipment) + "\" has rent to " + equipment.TB_Customer.Name + ".");
                }
            }
        }
Esempio n. 19
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.");
        }
Esempio n. 20
0
        /// <summary>
        /// 查找定位地址属于某个省份的设备列表
        /// </summary>
        /// <returns></returns>
        private string HandleEquipmentProvinceQuest()
        {
            var ret  = "[]";
            var list = EquipmentInstance.FindList(f => f.GpsAddress.IndexOf(data) >= 0 && f.Deleted == false);
            var objs = new List <TempEquipment>();

            foreach (var obj in list)
            {
                objs.Add(new TempEquipment(obj));
            }
            ret = JsonConverter.ToJson(objs);
            return(ret);
        }
Esempio n. 21
0
        /// <summary>
        /// 处理保安命令
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="equipment"></param>
        /// <param name="terminal"></param>
        private void Handle0x6007(TX300 obj, TB_Equipment equipment, TB_Terminal terminal)
        {
            _0x6007 x6007 = new _0x6007();

            x6007.Content = obj.MsgContent;
            x6007.Unpackage();
            if (null != equipment)
            {
                EquipmentInstance.Update(f => f.id == equipment.id, act => {
                    act.LockStatus = CustomConvert.GetHex(x6007.Code);
                });
            }
        }
Esempio n. 22
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);
             }
         }
     }
 }
Esempio n. 23
0
        private string GetEquipment(TB_Terminal terminal, TB_Equipment equipment)
        {
            if (null == equipment)
            {
                return("<a href=\"./equipment_terminal.aspx?key=" + Utility.UrlEncode(Utility.Encrypt(terminal.id.ToString())) + "\">bind</a>");
            }

            if (string.IsNullOrEmpty(terminal.Sim))
            {
                return("no sim card");
            }

            return("<a href=\"#unbind_" + terminal.id + "\">" + EquipmentInstance.GetFullNumber(equipment) + "</a>");
        }
Esempio n. 24
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!");
                }
            }
        }
Esempio n. 25
0
 private void ShowStaticPosition()
 {
     if (!string.IsNullOrEmpty(_key))
     {
         var id  = ParseInt(Utility.Decrypt(_key));
         var obj = EquipmentInstance.Find(f => f.id == id && f.Deleted == false);
         if (null != obj)
         {
             Lat = obj.Latitude.ToString();
             Lng = obj.Longitude.ToString();
             Dat = (DateTime?)null == obj.LastActionTime ? "-" : obj.LastActionTime.Value.ToString("yyyy/MM/dd HH:mm:ss");
         }
     }
 }
Esempio n. 26
0
        private void ShowEquipmentInformations()
        {
            var obj = EquipmentInstance.Find(f => f.id == int.Parse(_key) && f.Deleted == false);

            if (null == obj)
            {
                ShowNotification("/mobile/devices.aspx", "No such equipment exist: paramenter error.", false);
            }
            else
            {
                equipmentId.InnerText = EquipmentInstance.GetFullNumber(obj);
                spanLat.InnerText     = obj.Latitude.ToString();
                spanLon.InnerText     = obj.Longitude.ToString();
            }
        }
Esempio n. 27
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;
     });
 }
Esempio n. 28
0
 private void GetLastReceiveDate()
 {
     if (!string.IsNullOrEmpty(_key))
     {
         var id  = ParseInt(Utility.Decrypt(_key));
         var obj = EquipmentInstance.Find(f => f.id == id && f.Deleted == false);
         if (null != obj)
         {
             MacId = EquipmentInstance.GetFullNumber(obj);
             hiddenLastDate.Value = (DateTime?)null == obj.LastActionTime ? DateTime.Now.ToString("yyyy/MM/dd") :
                                    obj.LastActionTime.Value.ToString("yyyy/MM/dd");
         }
         divWorkTime.Visible = (null != obj && obj.Functional == (byte)EquipmentFunctional.Mechanical);
     }
 }
Esempio n. 29
0
        protected void btSaveChangeWarehouse_Click(object sender, EventArgs e)
        {
            if (!HasSessionLose)
            {
                var id  = ParseInt(Utility.Decrypt(hidWarehouseEquipmentId.Value));
                var obj = EquipmentInstance.Find(f => f.id == id);
                var tmp = JsonConverter.ToObject <TB_Equipment>(hidWarehouseTo.Value);
                if (obj.TB_EquipmentStatusName.IsItInventory == false)
                {
                    ShowNotification("./equipment_change_warehouse.aspx", "The equipment is not in storage status.", false);
                }
                else if (obj.Warehouse == tmp.Warehouse)
                {
                    ShowNotification("./equipment_change_warehouse.aspx", "The equipment in same warehouse you selected.", false);
                }
                else
                {
                    //var transfer = CodeInstance.Find(f =>
                    //        f.TB_EquipmentStatusName.IsInventory == true && f.Code.Equals("T"));
                    EquipmentInstance.Update(f => f.id == obj.id && f.Deleted == false, act =>
                    {
                        act.Warehouse = tmp.Warehouse;
                        // 状态变为库存转移状态
                        //act.Status = transfer.id;
                    });

                    // 保存转库信息
                    var history = StoreInstance.GetObject();
                    history.Equipment = obj.id;
                    history.Status    = obj.Status;//transfer.id;// 移库状态
                    history.Stocktime = DateTime.Now;
                    // 入库次数
                    history.StoreTimes = obj.StoreTimes;
                    history.Warehouse  = tmp.Warehouse;// 保持目的仓库
                    StoreInstance.Add(history);

                    SaveHistory(new TB_AccountHistory()
                    {
                        ActionId = ActionInstance.Find(f => f.Name.Equals("Transfer")).id,
                        ObjectA  = EquipmentInstance.GetFullNumber(obj) + ", \"" + obj.TB_Warehouse.Name + "\" to \"" +
                                   WarehouseInstance.Find(f => f.id == tmp.Warehouse).Name + "\""
                    });

                    ShowEquipments();
                }
            }
        }
Esempio n. 30
0
        protected void btSave_Click(object sender, EventArgs e)
        {
            if (!HasSessionLose)
            {
                // 设备出库
                if (!string.IsNullOrEmpty(hidCustomerId.Value.Trim()) &&
                    !string.IsNullOrEmpty(hidEquipmentId.Value.Trim()))
                {
                    var obj = EquipmentInstance.Find(f => f.id == ParseInt(hidEquipmentId.Value.Trim()) && f.Deleted == false);
                    if (obj.TB_EquipmentStatusName.IsItInventory == false)
                    {
                        // 如果不在库存状态则提示失败
                        ShowNotification("./equipment_delivery.aspx", "Error: equipment \"" +
                                         obj.TB_EquipmentModel.Code + obj.Number + "\" is not in inventory.", false);
                    }
                    else
                    {
                        EquipmentInstance.Update(f => f.id == obj.id && f.Deleted == false, act =>
                        {
                            act.Status = ParseInt(ddlSituation.SelectedValue);
                            // 出库后库存信息置为null
                            act.Warehouse = (int?)null;
                            act.Customer  = ParseInt(hidCustomerId.Value);
                        });

                        // 保存出库历史记录
                        var history = StoreInstance.GetObject();
                        history.Equipment = obj.id;
                        history.Status    = ParseInt(ddlSituation.SelectedValue);
                        history.Stocktime = DateTime.Now;
                        // 设备的出入库次数,入库时增1,出库时不变
                        history.StoreTimes = obj.StoreTimes;
                        history.Warehouse  = (int?)null;
                        StoreInstance.Add(history);

                        // 保存操作历史记录
                        SaveHistory(new Database.TB_AccountHistory()
                        {
                            ActionId = ActionInstance.Find(f => f.Name.Equals("Deliver")).id,
                            ObjectA  = ""
                        });

                        ShowNotification("./equipment_deliver.aspx", "\"" + EquipmentInstance.GetFullNumber(obj) + "\" has delivered.");
                    }
                }
            }
        }