Ejemplo n.º 1
0
        protected void ButtonAlarm_Click(object sender, EventArgs e)
        {
            if (this.DropDownListMachines.SelectedValue != null)
            {
                string guid = this.DropDownListMachines.SelectedValue;
                if (!string.IsNullOrEmpty(guid))
                {
                    MachineBusiness business = new MachineBusiness();
                    Machine value = business.QueryByGuid(guid);

                    if ((value != null) && (!string.IsNullOrEmpty(value.Guid)))
                    {
                        DetectorBusiness detectorBusiness = new DetectorBusiness();
                        List<Detector> detectors = detectorBusiness.QueryByMachine(value.Guid);

                        Random random = new Random();
                        if ((detectors != null) && (detectors.Count > 0))
                        {
                            for (int i = 0; i < detectors.Count; i++)
                            {
                                Detector current = detectors[i];
                                switch (current.DetectorType.Type)
                                {
                                    case DetectorTypes.Switch:
                                        current.Value = (ushort)random.Next(0, 2);
                                        break;
                                    case DetectorTypes.DoubleArea:
                                        byte valueA = (byte)random.Next(0, byte.MaxValue);
                                        byte valueB = (byte)random.Next(0, byte.MaxValue);
                                        current.Value = (ushort)((valueA * 0x100) + valueB);
                                        break;
                                }
                            }

                            string ipValue = value.Ip;
                            IPAddress ip = IPAddress.Parse(ipValue);
                            IPEndPoint remoteEP = new IPEndPoint(ip, Variable.Port);
                            List<AbstractInstruction> instructions = new List<AbstractInstruction>();

                            AlarmInstruction instruction = new AlarmInstruction(detectors);
                            instructions.Add(instruction);

                            Terminal.ExecuteInstruction(remoteEP, instructions);
                        }
                    }
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            const string MACHINE_ID = "machineId";

            string machineId = this.ParameterString(MACHINE_ID);

            DetectorBusiness business = new DetectorBusiness();
            List<Detector> modules = business.QueryByMachine(machineId);

            LoadJsonData loadJsonData = new LoadJsonData();
            loadJsonData.total = modules.Count;
            loadJsonData.rows = modules;
            string json = JsonConvert.SerializeObject(loadJsonData);

            this.Response.Write(json);
            this.Response.Flush();
            this.Response.End();
        }
Ejemplo n.º 3
0
        private void InitializeBindDetectors()
        {
            if (this.DropDownListMachines.SelectedValue != null)
            {
                DetectorBusiness business = new DetectorBusiness();

                string machineId = this.DropDownListMachines.SelectedValue;
                List<Detector> detectors = business.QueryByMachine(machineId);

                this.CheckBoxListDetectors.DataSource = detectors;
                this.CheckBoxListDetectors.DataTextField = "Name";
                this.CheckBoxListDetectors.DataValueField = "Guid";
                this.CheckBoxListDetectors.DataBind();
            }
        }
Ejemplo n.º 4
0
        protected void ButtonOK_Click(object sender, EventArgs e)
        {
            StringBuilder stringBuilder = new StringBuilder();

            DateTime now = DateTime.Now;
            DateTime beginDate = new DateTime(now.Year, now.Month, 1);
            DateTime endDate = beginDate.AddMonths(1).AddSeconds(-1);

            try
            {
                if (!string.IsNullOrEmpty(this.TextBoxBeginDate.Text))
                {
                    beginDate = DateTime.Parse(this.TextBoxBeginDate.Text);
                }
                if (!string.IsNullOrEmpty(this.TextBoxEndDate.Text))
                {
                    endDate = DateTime.Parse(this.TextBoxEndDate.Text);
                    endDate = endDate.AddDays(1).AddSeconds(-1);
                }
            }
            finally
            {
            }

            if (this.DropDownListMachines.SelectedValue != null)
            {
                string guid = this.DropDownListMachines.SelectedValue;
                if (!string.IsNullOrEmpty(guid))
                {
                    MachineBusiness machineBusiness = new MachineBusiness();
                    this.Machine = machineBusiness.QueryByGuid(guid);

                    if (this.Machine != null)
                    {
                        if (!string.IsNullOrEmpty(this.Machine.RoomId))
                        {
                            RoomBusiness roomBusiness = new RoomBusiness();
                            this.Room = roomBusiness.QueryByGuid(this.Machine.RoomId);
                        }

                        if (!string.IsNullOrEmpty(this.Machine.Guid))
                        {
                            DetectorBusiness detectorBusiness = new DetectorBusiness();
                            this.Detectors = detectorBusiness.QueryByMachine(this.Machine.Guid);

                            this.NormalDataCaches = detectorBusiness.QueryNormalDataCacheByMachine(this.Machine.Guid, beginDate, endDate);
                            this.AlarmDataCaches = detectorBusiness.QueryAlarmDataCacheByMachine(this.Machine.Guid, beginDate, endDate);

                            MessageCacheBusiness messageCacheBusiness = new MessageCacheBusiness();
                            this.MessageCaches = messageCacheBusiness.QueryByMachine(this.Machine.Guid, beginDate, endDate);
                        }
                    }
                }
                else
                {
                    stringBuilder.Append("没有选择检测仪!");
                }
            }

            this.LabelMessage.Text = stringBuilder.ToString();
        }
Ejemplo n.º 5
0
        public string Threshold(Machine value)
        {
            string result = null;

            StringBuilder stringBuilder = new StringBuilder();
            DetectorBusiness detectorBusiness = new DetectorBusiness();
            List<Detector> detectors = detectorBusiness.QueryByMachine(value.Guid);

            if ((detectors != null) && (detectors.Count > 0))
            {
                bool rightAddress = true;
                for (int i = 0; i < detectors.Count; i++)
                {
                    if (detectors[i].Serial != i)
                    {
                        rightAddress = false;
                        break;
                    }
                }

                if (rightAddress)
                {
                    stringBuilder.Append(this.MinimumThreshold(value, detectors));
                    stringBuilder.Append(this.MaximumThreshold(value, detectors));
                }
                else
                {
                    stringBuilder.Append("探头地址错误!");
                }
            }

            result = stringBuilder.ToString();

            return result;
        }
        private void InitializeBindInput()
        {
            this.GridViewDetectors.DataSource = null;
            this.GridViewDetectors.DataBind();
            this.RadioButtonListMobileAlarm.SelectedValue = false.ToString();
            this.TextBoxMobileA.Text = string.Empty;
            this.TextBoxMobileB.Text = string.Empty;
            this.TextBoxMobileC.Text = string.Empty;

            if (this.DropDownListMachines.SelectedValue != null)
            {
                string guid = this.DropDownListMachines.SelectedValue;
                if (!string.IsNullOrEmpty(guid))
                {
                    MachineBusiness business = new MachineBusiness();
                    Machine value = business.QueryByGuid(guid);

                    if ((value != null) && (!string.IsNullOrEmpty(value.Guid)))
                    {
                        DetectorBusiness detectorBusiness = new DetectorBusiness();
                        List<Detector> detectors = detectorBusiness.QueryByMachine(value.Guid);

                        DataTable dataTable = new DataTable();
                        dataTable.Columns.Add("C1");
                        dataTable.Columns.Add("C2");
                        dataTable.Columns.Add("C3");
                        dataTable.Columns.Add("C4");
                        dataTable.Columns.Add("C5");
                        dataTable.Columns.Add("C6");
                        for (int i = 0; i < detectors.Count; i++)
                        {
                            object[] datas = new object[dataTable.Columns.Count];
                            datas[0] = detectors[i].Serial;
                            datas[1] = detectors[i].DetectorType.Name;
                            if (detectors[i].DetectorType.Type == Support.Resource.DetectorTypes.Switch)
                            {
                                datas[2] = detectors[i].DetectorType.DescriptionA;
                                datas[3] = detectors[i].DetectorType.DescriptionB;
                                datas[4] = string.Empty;
                                datas[5] = string.Empty;
                            }
                            else
                            {
                                datas[2] = string.Format("{0}阀值下限{1}{2}", detectors[i].DetectorType.DescriptionA, detectors[i].MinimumA, detectors[i].DetectorType.UnitA);
                                datas[3] = string.Format("{0}阀值上限{1}{2}", detectors[i].DetectorType.DescriptionA, detectors[i].MaximumA, detectors[i].DetectorType.UnitA);
                                datas[4] = string.Format("{0}阀值下限{1}{2}", detectors[i].DetectorType.DescriptionB, detectors[i].MinimumB, detectors[i].DetectorType.UnitB);
                                datas[5] = string.Format("{0}阀值上限{1}{2}", detectors[i].DetectorType.DescriptionB, detectors[i].MaximumB, detectors[i].DetectorType.UnitB);
                            }
                            dataTable.Rows.Add(datas);
                        }

                        this.GridViewDetectors.DataSource = dataTable;
                        this.GridViewDetectors.DataBind();

                        this.RadioButtonListMobileAlarm.SelectedValue = value.Alarm.ToString();
                        this.TextBoxMobileA.Text = value.MobileA;
                        this.TextBoxMobileB.Text = value.MobileB;
                        this.TextBoxMobileC.Text = value.MobileC;
                    }
                }
            }
        }
        public override ProcessResult Process(string ip, InstructionTask instructionTask)
        {
            ProcessResult result = new ProcessResult();
            result.Done = false;
            result.Message = string.Empty;

            bool right = true;
            List<DataCache> dataCaches = new List<DataCache>();
            List<Detector> detectors = new List<Detector>();
            if ((instructionTask != null) && (instructionTask.Instructions != null) && (instructionTask.Instructions.Count > 0))
            {
                for (int i = 0; i < instructionTask.Instructions.Count; i++)
                {
                    AlarmInstruction instruction = instructionTask.Instructions[i] as AlarmInstruction;
                    if (instruction == null)
                    {
                        right = false;
                        break;
                    }
                    else
                    {
                        if (instruction.Detectors != null)
                        {
                            for (int j = 0; j < instruction.Detectors.Count; j++)
                            {
                                detectors.Add(instruction.Detectors[j]);
                            }
                        }
                    }
                }
            }
            if (right)
            {
                MachineBusiness machineBusiness = new MachineBusiness();
                Machine machine = machineBusiness.QueryByIp(ip);
                if (machine != null)
                {
                    DetectorBusiness detectorBusiness = new DetectorBusiness();
                    List<Detector> currentDetectors = detectorBusiness.QueryByMachine(machine.Guid);
                    if ((currentDetectors != null) && (currentDetectors.Count == detectors.Count))
                    {
                        for (int i = 0; i < detectors.Count; i++)
                        {
                            string userId = this.GetType().Name;
                            DateTime now = DateTime.Now;

                            DataCache dataCache = new DataCache();

                            dataCache.InsertUserId = ip;
                            dataCache.InsertTime = now;
                            dataCache.UpdateUserId = userId;
                            dataCache.UpdateTime = now;
                            dataCache.Remark = string.Empty;
                            dataCache.Validity = true;
                            dataCache.DetectorId = currentDetectors[i].Guid;

                            byte[] values = BitConverter.GetBytes(detectors[i].Value);
                            Array.Reverse(values);
                            currentDetectors[i].Decode(values);
                            dataCache.Value = currentDetectors[i].Value;

                            dataCache.RefreshTime = now;
                            dataCache.Newest = true;

                            dataCaches.Add(dataCache);
                        }
                    }
                }

                DataCacheBusiness dataCacheBusiness = new DataCacheBusiness();
                result.Done = dataCacheBusiness.Insert(dataCaches);
            }

            return result;
        }
Ejemplo n.º 8
0
        protected void ButtonMessage_Click(object sender, EventArgs e)
        {
            if (this.DropDownListMachines.SelectedValue != null)
            {
                string guid = this.DropDownListMachines.SelectedValue;
                if (!string.IsNullOrEmpty(guid))
                {
                    MachineBusiness business = new MachineBusiness();
                    Machine value = business.QueryByGuid(guid);

                    if ((value != null) && (!string.IsNullOrEmpty(value.Guid)))
                    {
                        DetectorBusiness detectorBusiness = new DetectorBusiness();
                        List<Detector> detectors = detectorBusiness.QueryByMachine(value.Guid);

                        Random random = new Random();
                        if ((detectors != null) && (detectors.Count > 0))
                        {
                            int address = random.Next(0, detectors.Count);
                            Detector detector = detectors[address];
                            bool result = false;
                            int resultRandom = random.Next(0, 2);
                            if (resultRandom == 0)
                            {
                                result = true;
                            }

                            string ipValue = value.Ip;
                            IPAddress ip = IPAddress.Parse(ipValue);
                            IPEndPoint remoteEP = new IPEndPoint(ip, Variable.Port);
                            List<AbstractInstruction> instructions = new List<AbstractInstruction>();

                            MessageInstruction instruction = new MessageInstruction(detector.DetectorType.Code, result, DateTime.Now);
                            instructions.Add(instruction);

                            Terminal.ExecuteInstruction(remoteEP, instructions);
                        }
                    }
                }
            }
        }