Example #1
0
        /// <summary>
        /// 预占资产
        /// </summary>
        /// <returns></returns>
        public ActionResult PreholdAsset()
        {
            string dbpath     = HttpContext.Server.MapPath("~/App_Data/DB/demo.db");
            string orderNo    = Request.QueryString["OrderNo"];
            string cabinetNo  = Request.QueryString["CabinetNo"];
            string layerCount = Request.QueryString["CabinetLayer"];

            SqliteHelper.BLL.Cabinet cabintbll = new SqliteHelper.BLL.Cabinet(dbpath);
            SqliteHelper.BLL.Asset   assetbll  = new SqliteHelper.BLL.Asset(dbpath);
            //获取待预占的资产
            var assetModel         = assetbll.GetModel(int.Parse(orderNo));
            var assetListOfCabinet = assetbll.GetModelList(string.Format("CabinetNo='{0}' and State in ('1','2')", cabinetNo));

            assetModel.State      = "1";
            assetModel.StartLayer = int.Parse(layerCount);
            assetbll.Update(assetModel);
            //预占完了之后,插入一条changelog
            SqliteHelper.BLL.ChangeLog changelogBll = new SqliteHelper.BLL.ChangeLog(dbpath);
            var model = new SqliteHelper.Model.ChangeLog();

            model.AssetNo         = assetModel.OrderNo;
            model.CabinetNo       = 1;
            model.CreateTime      = DateTime.Now;
            model.OperationDetail = string.Format("{0},{1}预占到第{2}U", assetModel.Type, assetModel.BM, layerCount);
            model.OperationType   = "1";
            changelogBll.Add(model);
            return(Content("1"));
        }
Example #2
0
        /// <summary>
        /// 获取上架下架信息
        /// </summary>
        /// <returns></returns>
        public ActionResult GetChangeLog()
        {
            string dbpath = HttpContext.Server.MapPath("~/App_Data/DB/demo.db");

            SqliteHelper.BLL.ChangeLog changLogBll = new SqliteHelper.BLL.ChangeLog(dbpath);
            var        logList = changLogBll.GetModelList(string.Format("CabinetNo='1'"));
            JsonResult js      = new JsonResult()
            {
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };

            js.Data = logList;
            return(js);
        }
Example #3
0
        /// <summary>
        /// 下架资产
        /// </summary>
        /// <returns></returns>
        public ActionResult OffLineAsset()
        {
            string dbpath  = HttpContext.Server.MapPath("~/App_Data/DB/demo.db");
            string orderNo = Request.QueryString["OrderNo"];

            SqliteHelper.BLL.Asset assetbll = new SqliteHelper.BLL.Asset(dbpath);
            //获取待预占的资产
            var assetModel = assetbll.GetModel(int.Parse(orderNo));

            assetModel.State = "0";
            assetbll.Update(assetModel);
            //下架成功后,插入一条上架ChangeLog
            SqliteHelper.BLL.ChangeLog changelogBll = new SqliteHelper.BLL.ChangeLog(dbpath);
            var model = new SqliteHelper.Model.ChangeLog();

            model.AssetNo         = assetModel.OrderNo;
            model.CabinetNo       = 1;
            model.CreateTime      = DateTime.Now;
            model.OperationDetail = string.Format("{0},{1}从第{2}U下架", assetModel.Type, assetModel.BM, assetModel.StartLayer);
            model.OperationType   = "3";
            changelogBll.Add(model);
            return(Content("1"));
        }
Example #4
0
        /// <summary>
        /// 获取机柜内的资产列表
        /// </summary>
        /// <returns></returns>
        public ActionResult GetCabinetAssetInfo()
        {
            //if ((DateTime.Now - lastDatetime).TotalSeconds < 2)
            //{
            //    return Content("-1");
            //}
            //lastDatetime = DateTime.Now;
            string dbpath = HttpContext.Server.MapPath("~/App_Data/DB/demo.db");

            NLog.LogManager.GetCurrentClassLogger().Debug(dbpath);
            string cabinetNo = Request.QueryString["CabinetNo"];

            SqliteHelper.BLL.Asset assetbll = new SqliteHelper.BLL.Asset(dbpath);
            var assetList = assetbll.GetModelList(string.Format("CabinetNo='{0}' and State in ('1','2')", cabinetNo));
            var assetAll  = assetbll.GetModelList("1=1");

            SqliteHelper.BLL.RealTimeData realDataBll = new SqliteHelper.BLL.RealTimeData(dbpath);
            var realTimeData = realDataBll.GetModelList(string.Format("cabinetNo='1'"));

            foreach (var asset in assetList)
            {
                //遍历每个资产,判断资产状态
                if (asset.State == "1")
                {
                    var list = realTimeData.Find(m => m.RFID == asset.RfidId && m.LayerIndex == asset.StartLayer);
                    if (list == null)
                    {
                        //如果资产是已预占,且没有检测到信息
                        asset.CabinetState = "预占";
                    }
                    else
                    {
                        //如果资产是已预占,检测到信息
                        asset.CabinetState = "在架";
                        //预占的资产,如果上架了,自动变为已上架
                        asset.State = "2";
                        assetbll.Update(asset);
                        //上架成功后,插入一条上架ChangeLog
                        var dtime = DateTime.Now;
                        SqliteHelper.BLL.ChangeLog changelogBll = new SqliteHelper.BLL.ChangeLog(dbpath);
                        var model = new SqliteHelper.Model.ChangeLog();
                        model.AssetNo         = asset.OrderNo;
                        model.CabinetNo       = 1;
                        model.CreateTime      = dtime;
                        model.OperationDetail = string.Format("{0},{1}上架到第{2}U", asset.Type, asset.BM, asset.StartLayer);
                        model.OperationType   = "2";
                        var datalist = changelogBll.GetModelList(string.Format("CreateTime>='{0}' and CreateTime<'{1}' and cabinetNo='1' and AssetNo='{2}' and OperationType='2'", dtime.AddSeconds(-1).ToString("yyyy-MM-dd HH:mm:ss"), dtime.AddSeconds(1).ToString("yyyy-MM-dd HH:mm:ss"), model.AssetNo));
                        if (datalist.Count == 0)
                        {
                            changelogBll.Add(model);
                        }
                    }
                }
                else if (asset.State == "2")
                {
                    var list = realTimeData.Find(m => m.RFID == asset.RfidId && m.LayerIndex == asset.StartLayer);
                    if (list == null)
                    {
                        //如果资产是已预占,且没有检测到信息
                        asset.CabinetState = "遗失";
                    }
                    else
                    {
                        //如果资产是已预占,检测到信息
                        asset.CabinetState = "在架";
                    }
                }
            }
            foreach (var realItem in realTimeData)
            {
                var asset = assetList.Find(m => m.StartLayer == realItem.LayerIndex);
                //如果当前层位没有资产,
                if (asset == null)
                {
                    var otherAsset = assetAll.Find(m => m.RfidId == realItem.RFID);
                    otherAsset.CabinetState = "非法";
                    otherAsset.StartLayer   = realItem.LayerIndex;
                    assetList.Add(otherAsset);
                }
                else
                {
                    if (asset.RfidId != realItem.RFID)
                    {
                        assetList.Remove(asset);//移除机柜内该层位的资产,显示非法的资产优先级高
                        var otherAsset = assetAll.Find(m => m.RfidId == realItem.RFID);
                        otherAsset.CabinetState = "非法";
                        otherAsset.StartLayer   = realItem.LayerIndex;
                        assetList.Add(otherAsset);
                    }
                }
            }
            //从RealData中获取
            JsonResult js = Json(assetList, JsonRequestBehavior.AllowGet);

            return(js);
        }