public ActionResult EditDevice(WebDevice webDevice)
        {
            DeviceBLL deviceBLL = new DeviceBLL();
            var       cResult   = deviceBLL.UpdateDevice(webDevice);

            return(JsonContentHelper.GetJsonContent(cResult));
        }
        public ActionResult CreateDevice(WebDevice webDevice)
        {
            webDevice.CreateUserID = this.GetCurrentUserID();
            webDevice.ProjectID    = this.GetCurrentProjectID();
            DeviceBLL deviceBLL = new DeviceBLL();
            var       cResult   = deviceBLL.InsertDevice(webDevice);

            return(JsonContentHelper.GetJsonContent(cResult));
        }
Exemple #3
0
        public CResult <WebDevice> GetDeviceByID(string DeviceID)
        {
            LogHelper.Info(MethodBase.GetCurrentMethod().ToString());
            LogHelper.Info("DeviceID", DeviceID);

            if (string.IsNullOrEmpty(DeviceID))
            {
                return(new CResult <WebDevice>(null, ErrorCode.ParameterError));
            }

            using (var context = new DeviceMgmtEntities())
            {
                var entity = context.Device.FirstOrDefault(t => t.ID == DeviceID && t.IsValid);
                if (entity == null)
                {
                    return(new CResult <WebDevice>(null, ErrorCode.DataNoExist));
                }

                var model = new WebDevice()
                {
                    ID          = entity.ID,
                    Num         = entity.Num,
                    Note        = entity.Note,
                    Name        = entity.Name,
                    DeviceState = (DeviceStateEnum)entity.DeviceState,

                    CreateDate       = entity.CreateDate,
                    CreateUserID     = entity.CreateUserID,
                    CreateUserName   = entity.User.Name,
                    ProjectID        = entity.ProjectID,
                    DeviceTypeID     = entity.DeviceTypeID,
                    DeviceTypeName   = entity.DeviceType.Name,
                    MaintainDate     = entity.MaintainDate,
                    ManufacturerID   = entity.ManufacturerID,
                    ManufacturerName = string.IsNullOrEmpty(entity.ManufacturerID) ? "" : entity.Manufacturer.Name,
                    ProductDate      = entity.ProductDate,
                    SupplierID       = entity.SupplierID,
                    SupplierName     = string.IsNullOrEmpty(entity.SupplierID) == false ? "" : entity.Supplier.Name
                };

                LogHelper.Info("result", model);

                return(new CResult <WebDevice>(model));
            }
        }
        public ActionResult CreateDevice(string returnUrl)
        {
            DeviceTypeBLL   deviceBLL     = new DeviceTypeBLL();
            ManufacturerBLL manufacturBLL = new ManufacturerBLL();
            SupplierBLL     supplierBLL   = new SupplierBLL();

            var deviceType = deviceBLL.GetDeviceTypeDir(this.GetCurrentProjectID());

            ViewBag.ManufacturList = manufacturBLL.GetManufacturerDir(this.GetCurrentProjectID()).Data;
            ViewBag.SupperList     = supplierBLL.GetSupplierDir(this.GetCurrentProjectID()).Data;
            ViewBag.DeviceType     = deviceType.Data;
            ViewBag.Action         = "Add";
            ViewBag.ReturnUrl      = returnUrl;

            WebDevice webDevice = new WebDevice();

            return(View(webDevice));
        }
Exemple #5
0
        public CResult <bool> InsertDevice(WebDevice model)
        {
            LogHelper.Info(MethodBase.GetCurrentMethod().ToString());
            LogHelper.Info("model", model);

            if (string.IsNullOrEmpty(model.ProjectID))
            {
                return(new CResult <bool>(false, ErrorCode.ParameterError));
            }

            using (var context = new DeviceMgmtEntities())
            {
                if (context.Project.Any(t => t.IsValid && t.ID == model.ProjectID) == false)
                {
                    return(new CResult <bool>(false, ErrorCode.ProjectNotExist));
                }

                if (context.Device.Any(t => t.Num.ToUpper() == model.Num.ToUpper() && t.ProjectID == model.ProjectID && t.IsValid))
                {
                    return(new CResult <bool>(false, ErrorCode.DeviceNumIsExist));
                }

                var entity = new Device();
                entity.CreateDate     = DateTime.Now;
                entity.CreateUserID   = model.CreateUserID;
                entity.ID             = Guid.NewGuid().ToString();
                entity.Num            = model.Num;
                entity.Name           = model.Name;
                entity.IsValid        = true;
                entity.Note           = model.Note;
                entity.ProjectID      = model.ProjectID;
                entity.DeviceTypeID   = model.DeviceTypeID;
                entity.MaintainDate   = model.MaintainDate;
                entity.ManufacturerID = model.ManufacturerID;
                entity.ProductDate    = model.ProductDate;
                entity.SupplierID     = model.SupplierID;
                entity.DeviceState    = (int)model.DeviceState;

                context.Device.Add(entity);

                return(context.Save());
            }
        }
Exemple #6
0
        private async void UpdeteTile(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName != "UpdateTime")
            {
                return;
            }
            await Task.Run(() =>
            {
                var text    = WebConnect.Current.WebTrafficExact.ToString();
                var manager = TileUpdateManager.CreateTileUpdaterForApplication();
                manager.Clear();
                manager.EnableNotificationQueue(true);

                var squareTile = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150Text01);
                var longTile   = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150Text01);
                var node       = squareTile.ImportNode(longTile.GetElementsByTagName("binding").Item(0), true);
                squareTile.GetElementsByTagName("visual").Item(0).AppendChild(node);
                var bindings = squareTile.GetElementsByTagName("binding");
                ((XmlElement)bindings[0]).SetAttribute("branding", "name");
                ((XmlElement)bindings[1]).SetAttribute("branding", "name");
                var tileTexts          = squareTile.GetElementsByTagName("text");
                tileTexts[0].InnerText = text;
                tileTexts[4].InnerText = string.Format("已用流量:{0}", text);
                var devices            = new WebDevice[5];
                WebConnect.Current.DeviceList.CopyTo(devices, 0);
                foreach (var item in devices)
                {
                    if (item == null)
                    {
                        break;
                    }
                    tileTexts[1].InnerText          = tileTexts[5].InnerText = item.Name;
                    tileTexts[2].InnerText          = tileTexts[6].InnerText = item.IPAddress.ToString();
                    tileTexts[3].InnerText          = tileTexts[7].InnerText = item.LogOnDateTime.ToString();
                    var tileNotification            = new Windows.UI.Notifications.TileNotification(squareTile);
                    tileNotification.ExpirationTime = new DateTimeOffset(DateTime.Now.AddDays(1));
                    manager.Update(tileNotification);
                }
            });
        }
Exemple #7
0
        public CResult <bool> UpdateDevice(WebDevice model)
        {
            LogHelper.Info(MethodBase.GetCurrentMethod().ToString());
            LogHelper.Info("model", model);

            if (string.IsNullOrEmpty(model.ID))
            {
                return(new CResult <bool>(false, ErrorCode.ParameterError));
            }

            using (var context = new DeviceMgmtEntities())
            {
                var entity = context.Device.FirstOrDefault(t => t.ID == model.ID && t.IsValid);
                if (entity == null)
                {
                    return(new CResult <bool>(false, ErrorCode.DataNoExist));
                }

                if (context.Device.Any(t => t.Num.ToUpper() == model.Num.ToUpper() && t.ProjectID == entity.ProjectID && t.IsValid && t.ID != model.ID))
                {
                    return(new CResult <bool>(false, ErrorCode.DeviceNumIsExist));
                }

                entity.Num          = model.Num;
                entity.Name         = model.Name;
                entity.Note         = model.Note;
                entity.ProductDate  = model.ProductDate;
                entity.MaintainDate = model.MaintainDate;
                entity.DeviceState  = (int)model.DeviceState;

                entity.DeviceTypeID   = model.DeviceTypeID;
                entity.ManufacturerID = model.ManufacturerID;
                entity.SupplierID     = model.SupplierID;

                context.Entry(entity).State = EntityState.Modified;
                return(context.Save());
            }
        }
        public ActionResult EditDevice(string deviceTypeID, string returnUrl)
        {
            DeviceBLL deviceBLL = new DeviceBLL();
            var       result    = deviceBLL.GetDeviceByID(deviceTypeID);
            WebDevice webDevice = null;

            if (result.Code == 0)
            {
                webDevice = result.Data;
            }
            ManufacturerBLL manufacturBLL = new ManufacturerBLL();
            SupplierBLL     supplierBLL   = new SupplierBLL();

            DeviceTypeBLL deviceTypeBll = new DeviceTypeBLL();
            var           deviceType    = deviceTypeBll.GetDeviceTypeDir(this.GetCurrentProjectID());

            ViewBag.ManufacturList = manufacturBLL.GetManufacturerDir(this.GetCurrentProjectID()).Data;
            ViewBag.SupperList     = supplierBLL.GetSupplierDir(this.GetCurrentProjectID()).Data;
            ViewBag.DeviceType     = deviceType.Data;
            ViewBag.Action         = "Update";
            ViewBag.ReturnUrl      = returnUrl;
            return(View(webDevice));
        }
Exemple #9
0
        public CResult <bool> ImportDeviceFromExcel(HttpPostedFileBase file, string projectID, string operatorUserID)
        {
            LogHelper.Info(MethodBase.GetCurrentMethod().ToString());

            if (string.IsNullOrEmpty(projectID) || string.IsNullOrEmpty(operatorUserID))
            {
                return(new CResult <bool>(false, ErrorCode.ParameterError));
            }

            var fileName = string.Format("{0}{1}", Guid.NewGuid().ToString(), Path.GetExtension(file.FileName));
            var filePath = FileHelper.SaveFile(file, SystemInfo.TempFileFolder, fileName);

            if (string.IsNullOrEmpty(filePath))
            {
                return(new CResult <bool>(false, ErrorCode.SystemError));
            }

            var dataTable = ExcelHelper.ExcelToDataTable(filePath, 0);

            if (dataTable.Rows.Count == 0)
            {
                return(new CResult <bool>(false, ErrorCode.FileContainNoData));
            }

            LogHelper.Info("读取数据行数为" + dataTable.Rows.Count);

            var webDeviceList = new List <WebDevice>();

            foreach (DataRow row in dataTable.Rows)
            {
                int i         = 0;
                var webDevice = new WebDevice();
                webDevice.Num            = row[i++].ToString();
                webDevice.Name           = row[i++].ToString();
                webDevice.DeviceTypeName = row[i++].ToString();
                DeviceStateEnum state;
                if (Enum.TryParse <DeviceStateEnum>(row[i++].ToString(), out state))
                {
                    webDevice.DeviceState = state;
                }
                else
                {
                    webDevice.DeviceState = DeviceStateEnum.未使用;
                }
                webDevice.SupplierName     = row[i++].ToString();
                webDevice.ManufacturerName = row[i++].ToString();

                DateTime tempTime;
                if (DateTime.TryParse(row[i++].ToString(), out tempTime))
                {
                    webDevice.ProductDate = tempTime;
                }

                if (DateTime.TryParse(row[i++].ToString(), out tempTime))
                {
                    webDevice.MaintainDate = tempTime;
                }
                webDevice.Note = row[i++].ToString();

                webDeviceList.Add(webDevice);
            }

            var deviceTypeNameList   = webDeviceList.Select(t => t.DeviceTypeName).Distinct().ToList();
            var supplierNameList     = webDeviceList.Select(t => t.SupplierName).Distinct().ToList();
            var manufacturerNameList = webDeviceList.Select(t => t.ManufacturerName).Distinct().ToList();
            var deviceNumList        = webDeviceList.Select(t => t.Num).Distinct().ToList();

            if (deviceNumList.Count < webDeviceList.Count)
            {
                return(new CResult <bool>(false, ErrorCode.DeviceNumIsExist));
            }


            using (var context = new DeviceMgmtEntities())
            {
                if (context.Project.Any(t => t.IsValid && t.ID == projectID) == false)
                {
                    return(new CResult <bool>(false, ErrorCode.ProjectNotExist));
                }

                if (context.User.Any(t => t.IsValid && t.UserID == operatorUserID) == false)
                {
                    return(new CResult <bool>(false, ErrorCode.UserNotExist));
                }

                if (context.Device.Any(t => t.ProjectID == projectID && t.IsValid && deviceNumList.Contains(t.Num)))
                {
                    return(new CResult <bool>(false, ErrorCode.DeviceNumIsExist));
                }

                var deviceTypeList = context.DeviceType.Where(t => t.IsValid && t.ProjectID == projectID && deviceTypeNameList.Contains(t.Name)).Select(t => new { t.ID, t.Name }).ToList();
                if (deviceTypeList.Count < deviceTypeNameList.Count)
                {
                    return(new CResult <bool>(false, ErrorCode.DeviceTypeNotExist));
                }

                var supplierList = context.Supplier.Where(t => t.IsValid && t.ProjectID == projectID && supplierNameList.Contains(t.Name)).Select(t => new { t.ID, t.Name }).ToList();
                if (supplierList.Count < supplierNameList.Count)
                {
                    return(new CResult <bool>(false, ErrorCode.SupplierNotExist));
                }

                var manufacturerList = context.Manufacturer.Where(t => t.IsValid && t.ProjectID == projectID && manufacturerNameList.Contains(t.Name)).Select(t => new { t.ID, t.Name }).ToList();
                if (manufacturerList.Count < manufacturerNameList.Count)
                {
                    return(new CResult <bool>(false, ErrorCode.ManufacturerNotExist));
                }

                var currentTime = DateTime.Now;
                foreach (var webDevice in webDeviceList)
                {
                    var device = new Device()
                    {
                        CreateDate     = currentTime,
                        CreateUserID   = operatorUserID,
                        DeviceTypeID   = deviceTypeList.FirstOrDefault(t => t.Name == webDevice.DeviceTypeName).ID,
                        ID             = Guid.NewGuid().ToString(),
                        IsValid        = true,
                        MaintainDate   = webDevice.MaintainDate,
                        ManufacturerID = manufacturerList.FirstOrDefault(t => t.Name == webDevice.ManufacturerName).ID,
                        Num            = webDevice.Num,
                        Name           = webDevice.Name,
                        Note           = webDevice.Note,
                        ProductDate    = webDevice.ProductDate,
                        ProjectID      = projectID,
                        SupplierID     = supplierList.FirstOrDefault(t => t.Name == webDevice.SupplierName).ID,
                    };

                    context.Device.Add(device);
                }

                LogHelper.Info("importList", webDeviceList);

                return(context.Save());
            }
        }
Exemple #10
0
 public void InitializeDevice()
 {
     device = new WebDevice();
 }