Beispiel #1
0
 public ActionResult SaveForm(string keyValue, KbsdeviceEntity entity)
 {
     if (keyValue == "")
     {
         entity.State = "在线";
     }
     kbsdevicebll.SaveForm(keyValue, entity);
     return(Success("操作成功。"));
 }
Beispiel #2
0
 /// <summary>
 /// 接口修改状态用方法
 /// </summary>
 /// <param name="entity"></param>
 public void UpdateState(KbsdeviceEntity entity)
 {
     try
     {
         service.UpdateState(entity);
     }
     catch (Exception e)
     {
         throw;
         throw;
     }
 }
Beispiel #3
0
 /// <summary>
 /// 保存表单(新增、修改)
 /// </summary>
 /// <param name="keyValue">主键值</param>
 /// <param name="entity">实体对象</param>
 /// <returns></returns>
 public void SaveForm(string keyValue, KbsdeviceEntity entity)
 {
     try
     {
         service.SaveForm(keyValue, entity);
         RabbitMQHelper rh = RabbitMQHelper.CreateInstance();
         SendData       sd = new SendData();
         if (keyValue == "")
         {
             sd.DataName = "AddDevice";
         }
         else
         {
             sd.DataName = "UpdateDevice";
         }
         sd.EntityString = JsonConvert.SerializeObject(entity);
         rh.SendMessage(JsonConvert.SerializeObject(sd));
     }
     catch (Exception)
     {
         throw;
     }
 }
Beispiel #4
0
        public string ImportDevice()
        {
            int    error        = 0;
            string message      = "请选择格式正确的文件再导入!";
            string falseMessage = "";
            int    count        = HttpContext.Request.Files.Count;

            if (count > 0)
            {
                HttpPostedFileBase file = HttpContext.Request.Files[0];
                if (string.IsNullOrEmpty(file.FileName))
                {
                    return(message);
                }
                if (!(file.FileName.Substring(file.FileName.IndexOf('.')).Contains("xls") || file.FileName.Substring(file.FileName.IndexOf('.')).Contains("xlsx")))
                {
                    return(message);
                }
                string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + System.IO.Path.GetExtension(file.FileName);
                file.SaveAs(Server.MapPath("~/Resource/temp/" + fileName));
                DataTable dt    = ExcelHelper.ExcelImport(Server.MapPath("~/Resource/temp/" + fileName));
                int       order = 1;


                DistrictBLL           districtbll = new DistrictBLL();
                List <DistrictEntity> AreaList    = districtbll.GetListByOrgIdAndParentId("", "");


                DataItemDetailBLL    dataItemDetailBLL = new DataItemDetailBLL();
                List <DataItemModel> data = dataItemDetailBLL.GetDataItemListByItemCode("'KbsOutType'").ToList();



                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string DeviceID     = dt.Rows[i][0].ToString();
                    string ControllerId = dt.Rows[i][1].ToString();
                    string OutType      = dt.Rows[i][2].ToString();
                    string DeviceName   = dt.Rows[i][3].ToString();
                    string DeviceModel  = dt.Rows[i][4].ToString();
                    //区域
                    string AreaName  = dt.Rows[i][5].ToString();
                    string AreaValue = "";
                    string AreaCode  = "";
                    //楼层编号
                    string FloorNo     = dt.Rows[i][6].ToString();
                    string DevicePoint = dt.Rows[i][7].ToString();
                    string DeviceIp    = dt.Rows[i][8].ToString();

                    if (string.IsNullOrEmpty(DeviceID))
                    {
                        falseMessage += "</br>" + "第" + (i + 2) + "门禁ID为空,未能导入.";
                        error++;
                        continue;
                    }
                    if (string.IsNullOrEmpty(ControllerId))
                    {
                        falseMessage += "</br>" + "第" + (i + 2) + "控制器ID为空,未能导入.";
                        error++;
                        continue;
                    }
                    if (string.IsNullOrEmpty(OutType))
                    {
                        falseMessage += "</br>" + "第" + (i + 2) + "进出类型为空,未能导入.";
                        error++;
                        continue;
                    }

                    if (string.IsNullOrEmpty(DeviceName))
                    {
                        falseMessage += "</br>" + "第" + (i + 2) + "门禁名称为空,未能导入.";
                        error++;
                        continue;
                    }

                    if (string.IsNullOrEmpty(DeviceModel))
                    {
                        falseMessage += "</br>" + "第" + (i + 2) + "门禁型号为空,未能导入.";
                        error++;
                        continue;
                    }

                    if (string.IsNullOrEmpty(AreaName))
                    {
                        falseMessage += "</br>" + "第" + (i + 2) + "区域名称为空,未能导入.";
                        error++;
                        continue;
                    }

                    if (string.IsNullOrEmpty(FloorNo))
                    {
                        falseMessage += "</br>" + "第" + (i + 2) + "楼层编号为空,未能导入.";
                        error++;
                        continue;
                    }

                    if (string.IsNullOrEmpty(DevicePoint))
                    {
                        falseMessage += "</br>" + "第" + (i + 2) + "门禁坐标为空,未能导入.";
                        error++;
                        continue;
                    }

                    if (string.IsNullOrEmpty(DeviceIp))
                    {
                        falseMessage += "</br>" + "第" + (i + 2) + "IP地址为空,未能导入.";
                        error++;
                        continue;
                    }
                    var IP    = @"(^(\d+)\.(\d+)\.(\d+)\.(\d+)$)";//@"/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/g";
                    var point = @"(^\d{1,9}(.\d{1,2});\d{1,9}(.\d{1,2})$)";

                    ////验证是否是IP
                    if (!Regex.IsMatch(DeviceIp, IP))
                    {
                        falseMessage += "</br>" + "第" + (i + 2) + "行IP地址格式填写错误,未能导入.";
                        error++;
                        continue;
                    }

                    ////验证是否是坐标
                    if (!Regex.IsMatch(DevicePoint, point))
                    {
                        falseMessage += "</br>" + "第" + (i + 2) + "行坐标格式填写错误,格式应为xx.xx;xx.xx,未能导入.";
                        error++;
                        continue;
                    }

                    var area = AreaList.Where(it => it.DistrictName == AreaName).FirstOrDefault();
                    if (area == null)
                    {
                        falseMessage += "</br>" + "第" + (i + 2) + "行区域名称填写错误,未找到对应的区域,未能导入.";
                        error++;
                        continue;
                    }

                    var ot = data.Where(it => it.ItemName == OutType).FirstOrDefault();
                    if (ot == null)
                    {
                        falseMessage += "</br>" + "第" + (i + 2) + "行进出类型填写错误,未找到对应的类型,未能导入.";
                        error++;
                        continue;
                    }

                    AreaValue = area.DistrictID;
                    AreaCode  = area.DistrictCode;

                    KbsdeviceEntity kbs = new KbsdeviceEntity();
                    kbs.AreaCode     = AreaCode;
                    kbs.AreaName     = AreaName;
                    kbs.DeviceId     = DeviceID;
                    kbs.DeviceName   = DeviceName;
                    kbs.DeviceModel  = DeviceModel;
                    kbs.OutType      = Convert.ToInt32(ot.ItemValue);
                    kbs.FloorNo      = FloorNo;
                    kbs.OperUserName = OperatorProvider.Provider.Current().UserName;
                    kbs.AreaId       = AreaValue;
                    kbs.DeviceIP     = DeviceIp;
                    kbs.DevicePoint  = DevicePoint;
                    kbs.ControllerId = ControllerId;
                    kbs.State        = "在线";

                    try
                    {
                        kbsdevicebll.SaveForm("", kbs);
                    }
                    catch
                    {
                        error++;
                    }
                }
                count    = dt.Rows.Count;
                message  = "共有" + count + "条记录,成功导入" + (count - error) + "条,失败" + error + "条";
                message += "</br>" + falseMessage;
            }

            return(message);
        }