public bool CheckExists(DeviceInfo objDeviceInfo)
        {
            string sql = null;
            List<DbParameter> parameterList = new List<DbParameter>();

            sql = " select count(1) from tbl_device_info where DeviceNumber=:DeviceNumber ";

            parameterList.Add(new OracleParameter(":DeviceNumber", objDeviceInfo.DeviceNumber));

            return int.Parse(DbHelper.ExecuteScalar(sql, CommandType.Text, parameterList.ToArray()).ToString()) > 0;
        }
Exemplo n.º 2
0
        public static bool TryGetDeviceInfo(string key, out DeviceInfo device)
        {
            _deviceInfos = _impl.GetData("DeviceInfo") as ConcurrentDictionary<string, DeviceInfo>;
            if ( _deviceInfos == null)
            {
                lock (_sync)
                {
                    if( _deviceInfos == null)
                        _deviceInfos = LoadDeviceInfo();
                }
            }

            return _deviceInfos.TryGetValue(key, out device);
        }
Exemplo n.º 3
0
        public void CacheTest()
        {
            string key = "ABC";
            var item = new DeviceInfo() { DeviceNumber = key, KindCode = 1, OrgId = 1 };

            DeviceCache.Current.Set(item);
            var actual = DeviceCache.Current.Get(key);
            Assert.IsNotNull(actual);

            item.OrgId = 2;
            DeviceCache.Current.Set(item);
            actual = DeviceCache.Current.Get(key);
            Assert.IsNotNull(actual);
            Assert.IsTrue(actual.OrgId == 2);

            DeviceCache.Current.Remove(key);
            actual = DeviceCache.Current.Get(key);
            Assert.IsNull(actual);
        }
Exemplo n.º 4
0
        public static Message ConvertFrom(byte[] buffer)
        {
            if (!Validate(buffer))
            {
                Log(buffer);
                return null;
            }

            var length = buffer.ReadShort(2);
            string key = Unity.GetDeviceNumber(buffer, 4);
            DeviceInfo device = new DeviceInfo();

            device.OrgId = 0;
            device.ModelCode = 0;
            device.KindCode = 0;
            device.DeviceNumber = key;
            device.OnLineTime = DateTime.Now;
            device.DeviceStatus = 1;
            device.SoftwareVersion = "00000000";// Unity.GetMechineVersion(buffer, 15);

            var messageType = buffer[13];// (short)(BitConverter.ToInt16(buffer, 12) >> 8);

            var msg = new Message()
            {
                Length = length,
                Type = messageType,
                Device = device
            };

            msg.Key = buffer[14];

            int KEY_LENGTH = 1;
            var dataLength = length - PAKAGE_FLAG_LENGTH;

            if (dataLength > 0)
            {
                dataLength -= KEY_LENGTH;

                if (messageType == (short)MessageType.Detail || messageType == 160)
                {
                    msg.Currency = Unity.GetCurrency(buffer, 15, msg.Key);

                    if (msg.Device != null)
                    {
                        msg.Currency.OrgId = msg.Device.OrgId;
                        msg.Currency.DeviceKindCode = msg.Device.KindCode;
                        msg.Currency.DeviceModelCode = msg.Device.ModelCode;
                        msg.Currency.DeviceNumber = msg.Device.DeviceNumber;
                    }
                }

                else
                {
                    var index = 15;
                    if (messageType == (short)MessageType.DownLoadBlackTable)
                    {
                        dataLength += KEY_LENGTH;
                        index -= KEY_LENGTH;
                    }
                    var data = new byte[dataLength];
                    Array.Copy(buffer, index, data, 0, dataLength);
                    msg.Datas = data;
                }
            }

            return msg;
        }
Exemplo n.º 5
0
        public static void UpdateDeviceState(DeviceInfo deviceinfo, Device device, bool disconnected)
        {
            if (device.Updated && !disconnected)
            {
                return;
            }
            try
            {
                if (string.IsNullOrEmpty(device.Number))
                {
                    return;
                }

                var service = ServiceFactory.GetService<IDeviceService>();

                if (deviceinfo != null && deviceinfo.PkId == 0)
                {
                    deviceinfo.RegisterIp = device.RemoteIP;

                    service.Save_Info(deviceinfo);
                }

                var item = service.GetObjectByDeviceNumber_Connection(device.Number);

                if (item == null)
                {
                    item = new DeviceConnection();
                }

                item.CollectorName = CurrencyStore.Common.Configration.CurrencyStoreSection.Instance.Name;
                item.ConnectTime = device.ConnectionDate;
                item.DisconnectTime = device.DisconnectionDate;
                item.UploadCount = device.Counter;
                item.DeviceIp = device.RemoteIP;
                item.DeviceNumber = device.Number;
                item.CollectorIp = device.LocalIP;
                item.ConnectionStatus = (byte)(device.Connected ? 1 : 2);

                service.Save_Connection(item);

                device.Updated = true;
            }
            catch (Exception ex)
            {
                logger.Error("更新连接状态错误.", ex);
            }
        }
        public void Save(DeviceInfo objDeviceInfo)
        {
            string sql = null;
            List<DbParameter> parameterList = new List<DbParameter>();

            if (objDeviceInfo.PkId == 0)
            {
                sql = "insert into tbl_device_info(PkId, DeviceNumber, SoftwareVersion, RegisterIp, KindCode, ModelCode, OrgId, OnLineTime, DeviceStatus) " +
                      " values(TDI_PKID.NEXTVAL, :DeviceNumber, :SoftwareVersion, :RegisterIp, :KindCode, :ModelCode, :OrgId, :OnLineTime, :DeviceStatus) " +
                      " RETURNING PkId INTO :PkId";

                parameterList.Add(new OracleParameter(":DeviceNumber", objDeviceInfo.DeviceNumber));
                parameterList.Add(new OracleParameter(":SoftwareVersion", objDeviceInfo.SoftwareVersion));
                parameterList.Add(new OracleParameter(":RegisterIp", objDeviceInfo.RegisterIp));
                parameterList.Add(new OracleParameter(":KindCode", objDeviceInfo.KindCode));
                parameterList.Add(new OracleParameter(":ModelCode", objDeviceInfo.ModelCode));
                parameterList.Add(new OracleParameter(":OrgId", objDeviceInfo.OrgId));
                parameterList.Add(new OracleParameter(":OnLineTime", objDeviceInfo.OnLineTime));
                parameterList.Add(new OracleParameter(":DeviceStatus", objDeviceInfo.DeviceStatus));
                var p = new OracleParameter(":PkId", OracleDbType.Int32, 0, ParameterDirection.Output);
                parameterList.Add(p);

                DbHelper.ExecuteNonQuery(sql, CommandType.Text, parameterList.ToArray());

                objDeviceInfo.PkId = Convert.ToInt32(((OracleDecimal)p.Value).Value);
            }
            else
            {
                sql = " update tbl_device_info set DeviceNumber=:DeviceNumber, SoftwareVersion=:SoftwareVersion, " +
                      " RegisterIp=:RegisterIp, KindCode=:KindCode, ModelCode=:ModelCode, OrgId=:OrgId, " +
                      " OnLineTime=:OnLineTime, DeviceStatus=:DeviceStatus where PkId=:PkId ";

                parameterList.Add(new OracleParameter(":DeviceNumber", objDeviceInfo.DeviceNumber));
                parameterList.Add(new OracleParameter(":SoftwareVersion", objDeviceInfo.SoftwareVersion));
                parameterList.Add(new OracleParameter(":RegisterIp", objDeviceInfo.RegisterIp));
                parameterList.Add(new OracleParameter(":KindCode", objDeviceInfo.KindCode));
                parameterList.Add(new OracleParameter(":ModelCode", objDeviceInfo.ModelCode));
                parameterList.Add(new OracleParameter(":OrgId", objDeviceInfo.OrgId));
                parameterList.Add(new OracleParameter(":OnLineTime", objDeviceInfo.OnLineTime));
                parameterList.Add(new OracleParameter(":DeviceStatus", objDeviceInfo.DeviceStatus));
                parameterList.Add(new OracleParameter(":PkId", objDeviceInfo.PkId));

                DbHelper.ExecuteNonQuery(sql, CommandType.Text, parameterList.ToArray());
            }
        }
Exemplo n.º 7
0
        private void InitData()
        {
            IBasicService basicService = ServiceFactory.GetService<IBasicService>();
            IDeviceService deviceService = ServiceFactory.GetService<IDeviceService>();

            int orgCount = this.txtOrgCount.Text.Trim().ToInt();
            int relevanceDeviceCount = this.txtRelevanceDeviceCount.Text.Trim().ToInt();
            int deviceGroup = this.txtDeviceGroup.Text.Trim().ToInt();
            int perGroupOrgCount = orgCount / deviceGroup;

            this.BeginInvoke(new EventHandler((a, b) =>
            {
                this.pbFinish.Minimum = 0;
                this.pbFinish.Maximum = orgCount * relevanceDeviceCount;
                this.pbFinish.Value = 0;
            })).AsyncWaitHandle.WaitOne(10);

            for (int i = 1; i <= deviceGroup; i++)
            {
                int deviceIndex = 0;

                for (int j = 1; j <= perGroupOrgCount; j++)
                {
                    int orgId = (i - 1) * perGroupOrgCount + j;

                    BasicOrganization org = new BasicOrganization()
                    {
                        OrgNumber = "ORG" + orgId.ToString().PadLeft(4, '0'),
                        OrgName = "网点机构" + orgId.ToString().PadLeft(4, '0'),
                        OrgAddress = "网点机构" + orgId.ToString().PadLeft(4, '0'),
                        OrgParentId = 0
                    };

                    basicService.Save_Organization(org);

                    org.OrgFullPath = org.OrgParentId.ToString().GetOrgFullPath() + "[" + org.PkId + "]";

                    basicService.Save_Organization(org);

                    for (int k = 1; k <= relevanceDeviceCount; k++)
                    {
                        deviceIndex += 1;

                        string deviceNumber = "ABCD" + (int.Parse(i + "00000000") + deviceIndex).ToString();

                        DeviceInfo device = new DeviceInfo()
                        {
                            DeviceNumber = deviceNumber,
                            SoftwareVersion = "000000",
                            RegisterIp = "127.0.0.1",
                            KindCode = 1,
                            ModelCode = 1,
                            OrgId = org.PkId,
                            OnLineTime = DateTime.Now,
                            DeviceStatus = 1
                        };

                        deviceService.Save_Info(device);

                        this.BeginInvoke(new EventHandler((a, b) => { this.pbFinish.PerformStep(); }));
                    }
                }
            }

            this.BeginInvoke(new EventHandler((a, b) => { this.btnInit.Enabled = true; }));

            MessageBox.Show("数据初始化完毕", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Exemplo n.º 8
0
 public static void UpdateDevice(DeviceInfo item)
 {
     Update();
     _deviceInfos[item.DeviceNumber] = item;
 }
Exemplo n.º 9
0
 public static bool Removeevice(DeviceInfo item)
 {
     Update();
     return _deviceInfos.TryRemove(item.DeviceNumber, out item);
 }
Exemplo n.º 10
0
 public static bool AddDevice(DeviceInfo item)
 {
     Update();
     return _deviceInfos.TryAdd(item.DeviceNumber, item);
 }
Exemplo n.º 11
0
        public void Save(DeviceInfo objDeviceInfo)
        {
            string sql = null;
            List<DbParameter> parameterList = new List<DbParameter>();

            if (objDeviceInfo.PkId == 0)
            {
                sql = " insert into tbl_device_info(DeviceNumber, SoftwareVersion, RegisterIp, KindCode, ModelCode, OrgId, OnLineTime, DeviceStatus) " +
                      " values(@DeviceNumber, @SoftwareVersion, @RegisterIp, @KindCode, @ModelCode, @OrgId, @OnLineTime, @DeviceStatus); " +
                      " select LAST_INSERT_ID(); ";

                parameterList.Add(new MySqlParameter("@DeviceNumber", objDeviceInfo.DeviceNumber));
                parameterList.Add(new MySqlParameter("@SoftwareVersion", objDeviceInfo.SoftwareVersion));
                parameterList.Add(new MySqlParameter("@RegisterIp", objDeviceInfo.RegisterIp));
                parameterList.Add(new MySqlParameter("@KindCode", objDeviceInfo.KindCode));
                parameterList.Add(new MySqlParameter("@ModelCode", objDeviceInfo.ModelCode));
                parameterList.Add(new MySqlParameter("@OrgId", objDeviceInfo.OrgId));
                parameterList.Add(new MySqlParameter("@OnLineTime", objDeviceInfo.OnLineTime));
                parameterList.Add(new MySqlParameter("@DeviceStatus", objDeviceInfo.DeviceStatus));

                objDeviceInfo.PkId = DbHelper.ExecuteScalar(sql, CommandType.Text, parameterList.ToArray()).ToString().ToInt();
            }

            else
            {
                sql = " update tbl_device_info set DeviceNumber=@DeviceNumber, SoftwareVersion=@SoftwareVersion, " +
                      " RegisterIp=@RegisterIp, KindCode=@KindCode, ModelCode=@ModelCode, OrgId=@OrgId, " +
                      " OnLineTime=@OnLineTime, DeviceStatus=@DeviceStatus where PkId=@PkId ";

                parameterList.Add(new MySqlParameter("@PkId", objDeviceInfo.PkId));
                parameterList.Add(new MySqlParameter("@DeviceNumber", objDeviceInfo.DeviceNumber));
                parameterList.Add(new MySqlParameter("@SoftwareVersion", objDeviceInfo.SoftwareVersion));
                parameterList.Add(new MySqlParameter("@RegisterIp", objDeviceInfo.RegisterIp));
                parameterList.Add(new MySqlParameter("@KindCode", objDeviceInfo.KindCode));
                parameterList.Add(new MySqlParameter("@ModelCode", objDeviceInfo.ModelCode));
                parameterList.Add(new MySqlParameter("@OrgId", objDeviceInfo.OrgId));
                parameterList.Add(new MySqlParameter("@OnLineTime", objDeviceInfo.OnLineTime));
                parameterList.Add(new MySqlParameter("@DeviceStatus", objDeviceInfo.DeviceStatus));

                DbHelper.ExecuteNonQuery(sql, CommandType.Text, parameterList.ToArray());
            }
        }
Exemplo n.º 12
0
        public bool CheckExists_Info(DeviceInfo objDeviceInfo)
        {
            var repository = ServiceFactory.GetService<IDeviceInfoRepository>();

            return repository.CheckExists(objDeviceInfo);
        }
Exemplo n.º 13
0
        public void Save_Info(DeviceInfo objDeviceInfo)
        {
            var deviceInfoRepository = ServiceFactory.GetService<IDeviceInfoRepository>();
            var deviceConnectionRepository = ServiceFactory.GetService<IDeviceConnectionRepository>();

            if (objDeviceInfo.PkId == 0)
            {
                DeviceInfo diTemp = deviceInfoRepository.GetObjectByDeviceNumber(objDeviceInfo.DeviceNumber);

                if (diTemp != null)
                {
                    objDeviceInfo.PkId = diTemp.PkId;
                }
            }

            deviceInfoRepository.Save(objDeviceInfo);

            var objDeviceConnection = deviceConnectionRepository.GetObjectByDeviceNumber(objDeviceInfo.DeviceNumber);

            if (objDeviceConnection == null)
            {
                objDeviceConnection = new DeviceConnection()
                {
                    DeviceNumber = objDeviceInfo.DeviceNumber,
                    DeviceIp = objDeviceInfo.RegisterIp,
                    OrgId = objDeviceInfo.OrgId,
                    CollectorName = String.Empty,
                    CollectorIp = String.Empty,
                    ConnectTime = DateTime.MinValue,
                    DisconnectTime = DateTime.MinValue,
                    ConnectionStatus = (int)DeviceConnection.ConnectionStatusEnum.Disconnect,
                    UploadCount = 0
                };
            }

            else
            {
                objDeviceConnection.OrgId = objDeviceInfo.OrgId;
            }

            deviceConnectionRepository.Save(objDeviceConnection);

            DeviceCache.Current.Set(objDeviceInfo);
        }
Exemplo n.º 14
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (this.IsValid)
            {
                IDeviceService service = ServiceFactory.GetService<IDeviceService>();

                bool isRegister = false;
                DeviceInfo entity = null;

                if (this.IsInsert)
                {
                    entity = new DeviceInfo()
                    {
                        DeviceNumber = this.txtDeviceNumber.Text.Trim(),
                        SoftwareVersion = this.txtSoftwareVersion.Text.Trim(),
                        RegisterIp = this.txtRegisterIp.Text.Trim(),
                        KindCode = this.ddlDeviceKind.SelectedValue.ToByte(0),
                        ModelCode = this.ddlDeviceModel.SelectedValue.ToByte(0),
                        OrgId = this.hfOrgId.Value.Trim().ToInt(),
                        OnLineTime = this.txtOnLineTime.Text.Trim().ToDateTime(),
                        DeviceStatus = this.ddlDeviceStatus.SelectedValue.ToByte(0)
                    };

                    if (service.CheckExists_Info(entity))
                    {
                        this.JscriptMsg("设备号码已存在", null, "Error");

                        return;
                    }
                }

                else
                {
                    entity = service.GetObject_Info(this.PkId);

                    if (entity != null)
                    {
                        isRegister = (entity.OrgId == 0 && entity.KindCode == 0 && entity.ModelCode == 0);

                        entity.SoftwareVersion = this.txtSoftwareVersion.Text.Trim();
                        entity.RegisterIp = this.txtRegisterIp.Text.Trim();
                        entity.KindCode = this.ddlDeviceKind.SelectedValue.ToByte(0);
                        entity.ModelCode = this.ddlDeviceModel.SelectedValue.ToByte(0);
                        entity.OrgId = this.hfOrgId.Value.Trim().ToInt();
                        entity.OnLineTime = this.txtOnLineTime.Text.Trim().ToDateTime();
                        entity.DeviceStatus = this.ddlDeviceStatus.SelectedValue.ToByte(0);
                    }
                }

                service.Save_Info(entity);

                if (isRegister)
                {
                    CurrencyInfo objCurrencyInfo = new CurrencyInfo()
                    {
                        OrgId = entity.OrgId,
                        DeviceNumber = entity.DeviceNumber,
                        DeviceKindCode = entity.KindCode,
                        DeviceModelCode = entity.ModelCode
                    };

                    ICurrencyService currencyService = ServiceFactory.GetService<ICurrencyService>();

                    currencyService.BatchRegister_Info(objCurrencyInfo);
                }

                if (this.IsInsert && (sender as Button).CommandName == "SubmitContinue")
                {
                    this.ReturnUrl = this.Request.Url.PathAndQuery;
                }

                this.JscriptMsg("数据保存成功", this.ReturnUrl, "Success");
            }
        }