Ejemplo n.º 1
0
        /// <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()));
        }
Ejemplo 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();
        }
Ejemplo n.º 3
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);
                }
            }
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
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.");
            }
        }
Ejemplo n.º 7
0
        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);
            }
        }
Ejemplo n.º 8
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 + ".");
                }
            }
        }
Ejemplo n.º 9
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.");
        }
Ejemplo n.º 10
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");
         }
     }
 }
Ejemplo n.º 11
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);
     }
 }
Ejemplo n.º 12
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();
            }
        }
Ejemplo n.º 13
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.");
                    }
                }
            }
        }
Ejemplo n.º 14
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();
                }
            }
        }
Ejemplo n.º 15
0
        protected void btRepairComplete_Click(object sender, EventArgs e)
        {
            if (!HasSessionLose)
            {
                var id        = int.Parse(hidRepairId.Value);
                var equipment = EquipmentInstance.Find(f => f.id == id && f.Deleted == false);
                if (null == equipment)
                {
                    ShowNotification("./equipment_overhaul.aspx", "Cannot find the equipment: object is not exist.", false);
                }
                else
                {
                    EquipmentInstance.Update(f => f.id == equipment.id && f.Deleted == false, act =>
                    {
                        act.Status = StatusInstance.Find(f => f.IsItInventory == true).id;
                    });
                    //RepairOK
                    equipment = EquipmentInstance.Find(f => f.id == equipment.id && f.Deleted == false);

                    var history = StoreInstance.GetObject();
                    history.Equipment = equipment.id;
                    // 先保存维修状态
                    history.Status = equipment.Status;
                    // 保存维修完成信息
                    history.Stocktime = DateTime.Now;
                    // 入库次数不变
                    history.StoreTimes = equipment.StoreTimes;
                    history.Warehouse  = equipment.Warehouse;
                    StoreInstance.Add(history);

                    // 保存维修完毕操作历史记录
                    SaveHistory(new TB_AccountHistory()
                    {
                        ActionId = ActionInstance.Find(f => f.Name.Equals("RepairOK")).id,
                        ObjectA  = EquipmentInstance.ToString(equipment)
                    });

                    ShowNotification("./equipment_overhaul.aspx", "Equipment \"" +
                                     EquipmentInstance.GetFullNumber(equipment) + "\" inspection & repair complete, and re-store in warehouse.");
                }
            }
        }
Ejemplo n.º 16
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.");
         }
     }
 }
Ejemplo n.º 17
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);
            }
        }
Ejemplo n.º 18
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) + "\"");
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 显示普通可发送的命令列表
        /// </summary>
        private void ShowSecurityCommands()
        {
            var id         = ParseInt(Utility.Decrypt(_key));
            var equipment  = EquipmentInstance.Find(f => f.id == id && f.Deleted == false);
            var functional = null == equipment ? EquipmentFunctional.Mechanical : (EquipmentFunctional)equipment.Functional;

            // 链接未知时,不能发送任何命令  2015/09/18 18:20
            if ((byte?)null == equipment.OnlineStyle)
            {
                return;
            }

            var link     = (LinkType)equipment.OnlineStyle;
            var commands = CommandUtility.GetCommand(true);
            var html     = "";

            foreach (var command in commands)
            {
                // 禁止在这里发送启用或禁用卫星命令 2015/11/26 16:35
                if (command.Flag == "satenable" || command.Flag == "satdisable" || command.Flag == "reset_gsm")
                {
                    continue;
                }
                // 卫星链接时,不能发送以下几个命令  2015/09/16 15:50
                if (link == LinkType.SATELLITE)
                {
                    if (command.Flag == "satenable" || command.Flag == "satdisable" || command.Flag == "reset_sat")
                    {
                        continue;
                    }
                }
                else
                {
                    // 睡眠模式下禁止发送转Satellite命令  2015/09/18 11:00
                    if (command.Flag == "reset_gsm" || (equipment.OnlineStyle == (byte)LinkType.SLEEP && command.Flag == "reset_sat"))
                    {
                        continue;
                    }
                }
                if (functional == EquipmentFunctional.Mechanical)
                {
                    // 机械式的挖掘机,不显示装载机的命令
                    if (command.Title.IndexOf("Loader") < 0)
                    {
                        var lok = equipment.LockStatus;
                        if (string.IsNullOrEmpty(lok))
                        {
                            lok = "00";
                        }
                        // 未锁车时不显示解锁
                        if (lok.Equals("00"))
                        {
                            if (command.Flag.Equals("enable"))
                            {
                                continue;
                            }
                        }
                        else
                        {
                            if (command.Flag.Equals("full"))
                            {
                                // 锁车时不显示锁车
                                continue;
                            }
                        }
                        html += "<li role=\"presentation\"><a role=\"menuitem\" tabindex=\"-1\" href=\"#" + command.Flag + "\">" + command.Title + "</a></li>";
                    }
                }
                else if (functional == EquipmentFunctional.Electric)
                {
                    // 电子式的挖掘机,不显示普通挖掘机的EPOS命令
                    if (command.Title.IndexOf("Security") < 0)
                    {
                        html += "<li role=\"presentation\"><a role=\"menuitem\" tabindex=\"-1\" href=\"#" + command.Flag + "\">" + command.Title.Replace("Loader", "Equipment") + "</a></li>";
                    }
                }
                else if (functional == EquipmentFunctional.Loader)
                {
                    // 装载机不显示挖掘机的命令
                    if (command.Title.IndexOf("Security") < 0)
                    {
                        html += "<li role=\"presentation\"><a role=\"menuitem\" tabindex=\"-1\" href=\"#" + command.Flag + "\">" + command.Title + "</a></li>";
                    }
                }
            }
            menuCommands.InnerHtml = html;
        }
        /// <summary>
        /// 查询指定日期范围内的运转时间并补偿相应的数量
        /// </summary>
        /// <param name="averagable"></param>
        /// <returns></returns>
        private string HandleQueryEquipmentWorktime(bool averagable = true)
        {
            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") + " 00:00:00");
                // 如果不是求平均值则将日期往前推一天
                //if (!averagable) { date = date.AddDays(-1); }
                var date1 = DateTime.Parse(GetParamenter("date1") + " 23:59:59");
                List <WorktimeChart> avg  = new List <WorktimeChart>();
                List <WorktimeChart> work = new List <WorktimeChart>();
                DateTime             dt   = date;
                // 循环每天一个节点
                while (dt.Ticks < date1.Ticks)
                {
                    avg.Add(new WorktimeChart()
                    {
                        date = dt.ToString("yyyy/MM/dd"), x = Utility.DateTimeToJavascriptDate(dt.Date), y = 0, min = 0
                    });
                    work.Add(new WorktimeChart()
                    {
                        date = dt.ToString("yyyy/MM/dd"), x = Utility.DateTimeToJavascriptDate(dt.Date), y = 0, min = 0
                    });
                    dt = dt.AddDays(1);
                }
                var macid    = EquipmentInstance.GetFullNumber(obj);
                var cmds     = new string[] { "0x1000", "0x600B" };
                var runtimes = DataInstance.FindList(f => f.mac_id.Equals(macid) && cmds.Contains(f.command_id) &&
                                                     f.receive_time >= date && f.receive_time <= date1).OrderBy(o => o.receive_time);
                var list = new List <Worktime>();
                if (null != runtimes)
                {
                    long today        = 0;
                    long timeInterval = 0;
                    foreach (var r in runtimes)
                    {
                        bool gps = r.command_id.Equals("0x1000");
                        if (today == 0)
                        {
                            dt = r.receive_time.Value;
                        }
                        else
                        {
                            // 计算与上一条数据的实际接收时间之间的时间差
                            timeInterval = (long)(r.receive_time.Value - dt).TotalSeconds;
                        }
                        var t = Utility.DateTimeToJavascriptDate(r.receive_time.Value.Date);
                        // 日期不同则重置日期和运转时间
                        if (today != t)
                        {
                            today = t;
                        }

                        byte[] temp  = null;
                        int    index = 0;
                        if (gps)
                        {
                            if (r.protocol_type == ProtocolTypes.SATELLITE)
                            {
                                temp  = CustomConvert.GetBytes(r.message_content);
                                index = 13;
                            }
                        }
                        else
                        {
                            temp  = CustomConvert.GetBytes(r.message_content);
                            index = 0;
                        }

                        // 增加一个节点
                        Worktime wt = new Worktime();
                        wt.date     = r.receive_time.Value.ToString("yyyy/MM/dd HH:mm:ss");
                        wt.worktime = null == temp ? 0 : BitConverter.ToUInt32(temp, index);
                        var bin = !gps ? "00000000" : CustomConvert.IntToDigit(temp[4], CustomConvert.BIN, 8);
                        // 如果list已经有数据则计算与上一条数据之间的差值
                        var cnt = list.Count;
                        if (cnt > 0)
                        {
                            if (wt.worktime < list[cnt - 1].worktime)
                            {
                                // 当前运转时间小于前一条时,小计为0
                                wt.interval = 0;
                            }
                            else
                            {
                                // 差值
                                wt.interval = !gps ? 0 : (wt.worktime - list[cnt - 1].worktime);
                                // 计算差值与实际两条数据的接收时间差值的对比
                                if (wt.interval > timeInterval)
                                {
                                    // 如果运转时间差超过了这两条数据接收时间的差值,则记为0
                                    wt.interval = 0;
                                }
                                // 计算运转时间之间的差值  2016/08/15 15:00
                                if (wt.interval > 0)
                                {
                                    uint hour = (uint)r.receive_time.Value.Hour, min = (uint)r.receive_time.Value.Minute;
                                    // 凌晨0点的运转时间需要分开到两个日期里
                                    if (hour == 0)
                                    {
                                        // 时间间隔大于0点已过的分钟数,则需要把时间差分开到两个日期里
                                        if (wt.interval > min)
                                        {
                                            list[cnt - 1].interval += wt.interval - min;
                                            wt.interval             = min;
                                        }
                                    }
                                }
                                // 补偿的分钟
                                if (wt.interval > 0)
                                {
                                    uint ad = 0;
                                    if (wt.interval > 60)
                                    {
                                        ad = wt.interval / 60;
                                    }
                                    else
                                    {
                                        ad = 1;
                                    }
                                    if (bin[6] == '1')
                                    {
                                        ad += 1;
                                    }
                                    wt.added = ad;
                                }
                                else
                                {
                                    wt.interval = 0;
                                }
                                // 所用的小时
                                wt.hours = wt.interval > 0 ? (wt.interval > 60 ? wt.interval / 60 : 1) : 0;
                            }
                        }
                        else
                        {
                            // 第一条数据小计为0
                            wt.interval = 0;
                        }
                        list.Add(wt);

                        // 更新本日最后的运转时间
                        var wk = work.FirstOrDefault(f => f.x == today);
                        if (null != wk)
                        {
                            //if (wk.min == 0) { wk.min = run; }
                            wk.min = wt.worktime;
                        }
                    }// end of foreach

                    // 工作时间总计
                    var totalWorkMins = list.Sum(s => s.interval);
                    // 补偿的分钟
                    var totalAddMins = list.Sum(s => s.added);
                    // 所用的小时数
                    var totalUsedHours = list.Sum(s => s.hours);
                    // 工作效率
                    var compensate = totalWorkMins / 60.0 / totalUsedHours;
                    // 最终增加的小时数
                    var finalAdded = totalAddMins / 60.0 * compensate;

                    // 计算每日运转时间
                    foreach (var f in work)
                    {
                        f.y   = Math.Round(list.Where(w => w.date.Contains(f.date)).Sum(s => s.interval) / 60.0, 2);
                        f.add = finalAdded;
                    }
                    // 有工作时间的天数里平均加入补偿的小时数
                    var per = finalAdded / work.Count(c => c.y > 0);
                    //per = Math.Round(per, 2);
                    // 加入补偿
                    foreach (var w in work)
                    {
                        //if (!averagable)
                        {
                            w.y += w.y > 0 ? per : 0;
                            // 如果超过24小时则直接设为24小时  2016/08/15 15:16
                            if (w.y >= 24)
                            {
                                w.y = 24;
                            }
                        }
                        if (averagable)
                        {
                            w.y = Math.Round(w.y, 2);
                        }
                    }

                    // 计算平均值
                    var avgg = Math.Round(work.Sum(s => s.y) * 1.0 / work.Count, 2);
                    foreach (var a in avg)
                    {
                        a.y = avgg;
                    }
                }
                if (averagable)
                {
                    ret = string.Format("{0}\"Average\":{1},\"Worktime\":{2}{3}", "{", JsonConverter.ToJson(avg), JsonConverter.ToJson(work), "}");
                }
                else
                {
                    ret = JsonConverter.ToJson(work);
                }
            }
            return(ret);
        }
Ejemplo n.º 21
0
        protected void btRentalEdit_Click(object sender, EventArgs e)
        {
            if (!HasSessionLose)
            {
                var id        = ParseInt(Utility.Decrypt(hiddenEditId.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
                {
                    // 延期
                    if (optionExtend.Checked == true)
                    {
                        EquipmentInstance.Update(f => f.id == equipment.id, act =>
                        {
                            act.ReclaimTime = DateTime.Parse(deadLineExtend.Value);
                        });
                        equipment = EquipmentInstance.Find(f => f.id == id && f.Deleted == false);
                        // 保存操作历史记录
                        SaveHistory(new TB_AccountHistory()
                        {
                            ActionId = ActionInstance.Find(f => f.Name.Equals("ExtendRental")).id,
                            ObjectA  = EquipmentInstance.ToString(equipment) + ", Extend rental to: " +
                                       equipment.ReclaimTime.Value.ToString("yyyy/MM/dd")
                        });

                        ShowNotification("./equipment_rental.aspx", "You have extended the rental date.");
                    }
                    else if (optionReclaim.Checked == true)
                    {
                        // 保存之前的状态
                        var history = StoreInstance.GetObject();
                        history.Equipment = equipment.id;
                        history.Status    = equipment.Status;

                        // 更新
                        EquipmentInstance.Update(f => f.id == equipment.id, act =>
                        {
                            // 保存仓库信息
                            act.Warehouse = int.Parse(hiddenWarehouse.Value);
                            // 清除出厂日期和出厂时运转时间
                            act.OutdoorWorktime = 0;
                            act.OutdoorTime     = (DateTime?)null;
                            // 清除到期时间
                            act.ReclaimTime = (DateTime?)null;
                            // 客户信息清除
                            act.Customer   = (int?)null;
                            act.StoreTimes = equipment.StoreTimes + 1;
                            // 需要维修
                            if (cbRepair.Checked)
                            {
                                act.Status = StatusInstance.Find(f => f.IsItOverhaul == true).id;
                            }
                            else
                            {
                                act.Status = StatusInstance.Find(f => f.IsItInventory == true).id;
                            }
                        });
                        // 重新查询
                        equipment = EquipmentInstance.Find(f => f.id == id && f.Deleted == false);
                        // 保存入库信息
                        history.Stocktime = DateTime.Now;
                        // 入库次数加1
                        history.StoreTimes = equipment.StoreTimes;
                        history.Warehouse  = equipment.Warehouse;
                        StoreInstance.Add(history);

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

                        ShowNotification("./equipment_rental.aspx", "Equipment has been recovered.");
                    }
                }
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// 显示普通可发送的命令列表
        /// </summary>
        private void ShowCustomCommands()
        {
            var id         = ParseInt(Utility.Decrypt(_key));
            var equipment  = EquipmentInstance.Find(f => f.id == id && f.Deleted == false);
            var functional = null == equipment ? EquipmentFunctional.Mechanical : (EquipmentFunctional)equipment.Functional;
            var commands   = CommandUtility.GetCommand(false);

            // 链接未知时,不能发送任何命令  2015/09/18 18:20
            if ((byte?)null == equipment.OnlineStyle)
            {
                return;
            }

            var link = (LinkType)equipment.OnlineStyle;
            var html = "";

            foreach (var command in commands)
            {
                // 卫星链接时,不能发送以下几个命令  2015/09/16 15:40
                if (link == LinkType.SATELLITE)
                {
                    if (command.Flag == "signal" || command.Flag == "ld_daily" || command.Flag == "ld_worktime" ||
                        command.Flag == "monitor" || command.Flag == "fault" || command.Flag == "worktime")
                    {
                        continue;
                    }
                }
                else
                {
                    if (command.Flag == "ld_daily")
                    {
                        continue;
                    }
                }
                if (functional == EquipmentFunctional.Mechanical)
                {
                    // 机械式的挖掘机,不显示装载机的命令
                    if (command.Title.IndexOf("Loader") < 0)
                    {
                        // 未启动时不能发送EPOS命令
                        var vol = equipment.Voltage;
                        if (!vol.Contains("G2") && command.Title.Contains("Equipment"))
                        {
                            continue;
                        }

                        html += "<li role=\"presentation\"><a role=\"menuitem\" tabindex=\"-1\" href=\"#" + command.Flag + "\">" + command.Title + "</a></li>";
                    }
                }
                else if (functional == EquipmentFunctional.Electric)
                {
                    // 电子式的挖掘机,不显示普通挖掘机的EPOS命令
                    if (command.Title.IndexOf("Equipment") < 0)
                    {
                        html += "<li role=\"presentation\"><a role=\"menuitem\" tabindex=\"-1\" href=\"#" + command.Flag + "\">" + command.Title.Replace("Loader", "Equipment") + "</a></li>";
                    }
                }
                else if (functional == EquipmentFunctional.Loader)
                {
                    // 装载机不显示挖掘机的命令
                    if (command.Title.IndexOf("Equipment") < 0)
                    {
                        html += "<li role=\"presentation\"><a role=\"menuitem\" tabindex=\"-1\" href=\"#" + command.Flag + "\">" + command.Title + "</a></li>";
                    }
                }
            }
            menuCommands.InnerHtml = html;
        }
Ejemplo n.º 23
0
        private void ShowTerminalsNotBind(int pageIndex)
        {
            var totalRecords = 0;

            // 表达式
            Expression <Func <TB_Terminal, bool> > expression = PredicateExtensions.True <TB_Terminal>();

            expression = expression.And(a => a.Delete == false);
            // 是否绑定卫星 -1:ignore,0:not,1:bound
            var sat = int.Parse(selectedSatellite.Value);

            spanSatellite.InnerHtml = "Satellite:" + GotSelectedType(sat);
            if (sat >= 0)
            {
                if (sat == 0)
                {
                    expression = expression.And(a => a.Satellite == null);
                }
                else
                {
                    expression = expression.And(a => a.Satellite != null);
                }
            }
            // 是否绑定设备-1:ignore,0:not,1:bound
            var equ = int.Parse(selectedEquipment.Value);

            spanEquipment.InnerHtml = "Equipment:" + GotSelectedType(equ);
            if (equ >= 0)
            {
                if (equ == 0)
                {
                    expression = expression.And(a => a.HasBound == false);
                }
            }
            // 模糊查询
            var query = txtNumber.Value.Trim();

            if (!string.IsNullOrEmpty(query))
            {
                expression = expression.And(a => a.Number.Contains(query) || a.TB_Satellite.CardNo.Contains(query));
            }

            var list       = TerminalInstance.FindPageList <TB_Terminal>(pageIndex, PageSize, out totalRecords, expression, "Number");
            var totalPages = totalRecords / PageSize + (totalRecords % PageSize > 0 ? 1 : 0);

            string html = "";

            if (totalRecords < 1)
            {
                html = "<tr><td colspan=\"11\">No records, You can change condition and try again or " +
                       " <a href=\"./terminal_register.aspx\">ADD</a> new one.</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()));
                    //-1:ignore,0:not,1:bound
                    var equipment = EquipmentInstance.Find(f => f.TB_Terminal.id == obj.id && f.Deleted == false);
                    //if(equ==0&&equi)
                    html += "<tr>" +
                            //"<td class=\"in-tab-txt-rb\"><input type=\"checkbox\" id=\"cb_" + id + "\" /></td>" +
                            "<td class=\"in-tab-txt-rb\">" + cnt + "</td>" +
                            "<td class=\"in-tab-txt-rb\" style=\"text-align: left !important;\"><a href=\"./terminal_register.aspx?key=" + id + "\" >" + CheckQueryString(obj.Number) + "</a></td>" +
                            "<td class=\"in-tab-txt-rb\" style=\"text-align: left !important; cursor: pointer;\" title=\"Click to show advanced options\">" + CheckQueryString(TerminalInstance.GetSatellite(obj, true)) + "</td>" +
                            "<td class=\"in-tab-txt-rb\">" + obj.Firmware + "</td>" +
                            "<td class=\"in-tab-txt-rb\">" + obj.Revision.ToString() + "</td>" +
                            "<td style=\"text-align: left !important;\" class=\"in-tab-txt-rb\">" + TerminalTypes.GetTerminalType(obj.Type.Value) + "</td>" +
                            "<td class=\"in-tab-txt-rb\" style=\"text-align: left !important;\">" + obj.ProductionDate.Value.ToString("yyyy/MM/dd") + "</td>" +
                            "<td class=\"in-tab-txt-rb\">" + (obj.HasBound == true ? "yes" : "no") + "</td>" +
                            "<td class=\"in-tab-txt-rb\" style=\"text-align: left !important;\">" + CheckQueryString(GetEquipment(obj, equipment)) + "</td>" +
                            "<td class=\"in-tab-txt-b\">" + Utility.GetOnlineStyle(obj.OnlineStyle, obj.OnlineTime, false) + "</td>" +
                            //"<td class=\"in-tab-txt-rb\" style=\"text-align: left !important;\">" + obj.Sim + "</td>" +
                            "<td class=\"in-tab-txt-b\"></td>" +
                            "</tr>";
                }
            }
            ShowFooter(totalRecords, pageIndex, totalPages, html);
        }
Ejemplo n.º 24
0
        protected void btSaveOldInStorage_Click(object sender, EventArgs e)
        {
            if (!HasSessionLose)
            {
                var id    = int.Parse(Utility.Decrypt(Utility.UrlDecode(hidOldInstorage.Value)));
                var exist = EquipmentInstance.Find(f => f.id == id && f.Deleted == false);
                if (null != exist)
                {
                    bool repaired = false;
                    EquipmentInstance.Update(f => f.id == exist.id && f.Deleted == false, act =>
                    {
                        // 保存仓库信息
                        act.Warehouse = int.Parse(hiddenOldWarehouse.Value);
                        // 清除出厂日期和出厂时运转时间
                        act.OutdoorWorktime = 0;
                        act.OutdoorTime     = null;
                        // 客户信息清除
                        act.Customer   = null;
                        act.StoreTimes = exist.StoreTimes + 1;
                        // 需要维修
                        if (cbRepair.Checked)
                        {
                            repaired   = true;
                            act.Status = StatusInstance.Find(f => f.IsItOverhaul == true).id;
                        }
                        else
                        {
                            act.Status = StatusInstance.Find(f => f.IsItInventory == true).id;
                        }
                    });
                    // 重新查询设备信息
                    exist = EquipmentInstance.Find(f => f.id == exist.id && f.Deleted == false);
                    var history = StoreInstance.GetObject();
                    history.Equipment = exist.id;
                    // 保存之前的状态
                    history.Status = exist.Status;
                    // 保存入库信息
                    var      idate = inDate.Value;
                    DateTime dt    = DateTime.Now;
                    if (!string.IsNullOrEmpty(idate))
                    {
                        try { dt = DateTime.Parse(idate); } catch { }
                    }
                    history.Stocktime = dt;
                    // 入库次数加1
                    history.StoreTimes = exist.StoreTimes;
                    history.Warehouse  = exist.Warehouse;
                    StoreInstance.Add(history);

                    // 保存入库操作历史记录
                    SaveHistory(new TB_AccountHistory()
                    {
                        ActionId = ActionInstance.Find(f => f.Name.Equals("InStoreOld" + (repaired ? "Repair" : ""))).id,
                        ObjectA  = EquipmentInstance.ToString(exist)
                    });

                    ShowNotification("./equipment_rental_fleet.aspx", "Equipment has been store in warehouse.");
                }
                else
                {
                    ShowNotification("./equipment_rental_fleet.aspx", "Cannot change storage status: object is not exist.", false);
                }
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// 查询指定设备在指定日期范围内每日运转时间
        /// </summary>
        /// <returns></returns>
        private string HandleEquipmentWorktime(bool averagable = true)
        {
            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") + " 00:00:00");
                // 如果不是求平均值则将日期往前推一天
                //if (!averagable) { date = date.AddDays(-1); }
                var date1 = DateTime.Parse(GetParamenter("date1") + " 23:59:59");
                List <WorktimeChart> avg  = new List <WorktimeChart>();
                List <WorktimeChart> work = new List <WorktimeChart>();
                DateTime             dt   = date;
                // 循环每天一个节点
                while (dt.Ticks < date1.Ticks)
                {
                    avg.Add(new WorktimeChart()
                    {
                        date = dt.ToString("yyyy/MM/dd"), x = Utility.DateTimeToJavascriptDate(dt.Date), y = 0, min = 0
                    });
                    work.Add(new WorktimeChart()
                    {
                        date = dt.ToString("yyyy/MM/dd"), x = Utility.DateTimeToJavascriptDate(dt.Date), y = 0, min = 0
                    });
                    dt = dt.AddDays(1);
                }
                var macid    = EquipmentInstance.GetFullNumber(obj);
                var cmds     = new string[] { "0x1000", "0x1001", "0x5000", "0x6004", "0x600B", "0xCC00" };
                var runtimes = DataInstance.FindList(f => f.mac_id.Equals(macid) && cmds.Contains(f.command_id) &&
                                                     f.receive_time >= date.AddDays(-1) && f.receive_time <= date1.AddDays(1)).OrderBy(o => o.receive_time);
                var list = new List <WorkTime>();
                if (null != runtimes)
                {
                    long today = 0;
                    foreach (var r in runtimes)
                    {
                        var t = Utility.DateTimeToJavascriptDate(r.receive_time.Value.Date);
                        // 日期不同则重置日期和运转时间
                        if (today != t)
                        {
                            today = t;
                        }

                        byte[] temp  = null;
                        int    index = 0;
                        if (r.command_id.Equals("0x1000"))
                        {
                            if (r.protocol_type == ProtocolTypes.SATELLITE)
                            {
                                temp  = CustomConvert.GetBytes(r.message_content);
                                index = 13;
                            }
                        }
                        else if (r.command_id.Equals("0x1001"))
                        {
                            temp  = CustomConvert.GetBytes(r.message_content);
                            index = 37;
                        }
                        else if (r.command_id.Equals("0x5000"))
                        {
                            // 只有装载机和电装的挖掘机才能有5000命令的总运转时间
                            if (r.terminal_type >= TerminalTypes.DXE)
                            {
                                temp  = CustomConvert.GetBytes(r.message_content);
                                index = 0;
                            }
                        }
                        else if (r.command_id.Equals("0x600B"))
                        {
                            temp  = CustomConvert.GetBytes(r.message_content);
                            index = 0;
                        }
                        else if (r.command_id.Equals("0xCC00"))
                        {
                            temp  = CustomConvert.GetBytes(r.message_content);
                            index = 12;
                        }
                        else
                        {
                            temp = CustomConvert.GetBytes(r.message_content);

                            byte tp = r.terminal_type.Value;
                            index = tp == TerminalTypes.DH ? 2 : (tp == TerminalTypes.DX ? 5 : 1);
                        }

                        // 增加一个节点
                        WorkTime wt = new WorkTime();
                        wt.date = r.receive_time.Value.ToString("yyyy/MM/dd HH:mm:ss");
                        wt.time = null == temp ? 0 : BitConverter.ToUInt32(temp, index);
                        // 如果list已经有数据则计算与上一条数据之间的差值
                        var cnt = list.Count;
                        if (cnt > 0)
                        {
                            if (wt.time < list[cnt - 1].time)
                            {
                                // 当前运转时间小于前一条时,小计为0
                                wt.subtotal = 0;
                            }
                            else
                            {
                                // 否则小计为差值
                                wt.subtotal = wt.time - list[cnt - 1].time;
                                // 每日凌晨1点之前,如果计算的时间差超过了当前时间的分钟数,则只计算分钟数
                                if (r.receive_time.Value.Hour < 1 && wt.subtotal > r.receive_time.Value.Minute)
                                {
                                    // 每日1时之前计算的时间差大于已经过去了的分钟数则将差值算到前一天最后一条数据里
                                    if (cnt > 0)
                                    {
                                        list[cnt - 1].subtotal += (uint)(wt.subtotal - r.receive_time.Value.Minute);
                                    }
                                    wt.subtotal = (uint)r.receive_time.Value.Minute;
                                }
                                // 小于0时算作0
                                if (wt.subtotal < 0)
                                {
                                    wt.subtotal = 0;
                                }
                                // 如果与上一条日期的分钟数相差12个小时以上则记为0
                                DateTime lst = DateTime.Parse(list[cnt - 1].date);
                                if ((lst - r.receive_time.Value).Duration().TotalMinutes >= DAY_MINUTES / 2)
                                {
                                    wt.subtotal = 0;
                                }
                                // 大于24小时算作0
                                if (wt.subtotal >= DAY_MINUTES)
                                {
                                    wt.subtotal = 0;
                                }
                            }
                        }
                        else
                        {
                            // 第一条数据小计为0
                            wt.subtotal = 0;
                        }
                        list.Add(wt);

                        // 更新本日最后的运转时间
                        var wk = work.FirstOrDefault(f => f.x == today);
                        if (null != wk)
                        {
                            //if (wk.min == 0) { wk.min = run; }
                            wk.min = wt.time;
                        }
                    }// end of foreach

                    // 计算每日运转时间
                    foreach (var f in work)
                    {
                        f.y = Math.Round(list.Where(w => w.date.Contains(f.date)).Sum(s => s.subtotal) / 60.0, 2);
                    }

                    // 计算平均值
                    var avgg = Math.Round(work.Sum(s => s.y) * 1.0 / work.Count, 2);
                    foreach (var a in avg)
                    {
                        a.y = avgg;
                    }
                }
                if (averagable)
                {
                    ret = string.Format("{0}\"Average\":{1},\"Worktime\":{2}{3}", "{", JsonConverter.ToJson(avg), JsonConverter.ToJson(work), "}");
                }
                else
                {
                    ret = JsonConverter.ToJson(work);
                }
            }
            return(ret);
        }