protected void Page_Load(object sender, EventArgs e)
        {
            User sessionUser = this.Session[Constant.SESSION_KEY_USER] as User;
            DateTime now = DateTime.Now;

            SaveJsonData saveJsonData = new SaveJsonData();

            DetectorBusiness business = new DetectorBusiness();

            const int attributeCount = 3;
            int count = this.Request.Form.Count / attributeCount;
            List<Detector> detectors = new List<Detector>();
            for (int i = 0; i < count; i++)
            {
                Detector detector = new Detector();
                detector.Guid = this.Request.Form[(i * attributeCount) + 0];
                detector.UpdateUserId = sessionUser.Guid;
                detector.UpdateTime = now;
                try
                {
                    detector.PositionX = int.Parse(this.Request.Form[(i * attributeCount) + 1]);
                }
                catch (Exception exception)
                {
                    EnvironmentalMonitor.Support.Resource.Variable.Logger.Log(exception);
                }
                try
                {
                    detector.PositionY = int.Parse(this.Request.Form[(i * attributeCount) + 2]);
                }
                catch (Exception exception)
                {
                    EnvironmentalMonitor.Support.Resource.Variable.Logger.Log(exception);
                }
                detectors.Add(detector);
            }
            saveJsonData.success = business.UpdatePosition(detectors);
            if (saveJsonData.success)
            {
                saveJsonData.msg = "布局保存成功!";
            }
            else
            {
                saveJsonData.msg = "布局保存失败";
            }

            string json = JsonConvert.SerializeObject(saveJsonData);

            this.Response.Write(json);
            this.Response.Flush();
            this.Response.End();
        }
Exemplo n.º 2
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);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        protected void ButtonOK_Click(object sender, EventArgs e)
        {
            bool done = false;
            StringBuilder stringBuilder = new StringBuilder();

            DetectorBusiness business = new DetectorBusiness();

            if (this.CheckBoxListDetectors.Items != null)
            {
                List<Detector> detectors = new List<Detector>();
                for (int i = 0; i < this.CheckBoxListDetectors.Items.Count; i++)
                {
                    if (this.CheckBoxListDetectors.Items[i].Selected)
                    {
                        Detector detector = new Detector();
                        detector.Guid = this.CheckBoxListDetectors.Items[i].Value;
                        detectors.Add(detector);
                    }
                }

                if ((detectors != null) && (detectors.Count > 0))
                {
                    int success = 0;
                    int fail = 0;
                    for (int i = 0; i < detectors.Count; i++)
                    {
                        done = business.Delete(detectors[i]);
                        if (done)
                        {
                            success++;
                        }
                        else
                        {
                            fail++;
                        }
                    }
                    stringBuilder.Append(string.Format("删除{0}个探头成功!", success));
                    stringBuilder.Append(string.Format("删除{0}个探头失败!", fail));
                }
            }

            this.LabelMessage.Text = stringBuilder.ToString();

            this.InitializeBind();
        }
        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();
        }
Exemplo n.º 5
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();
            }
        }
Exemplo n.º 6
0
        protected void ButtonOK_Click(object sender, EventArgs e)
        {
            bool done = false;
            StringBuilder stringBuilder = new StringBuilder();

            string machineId = this.DropDownListMachines.SelectedValue;
            if (!string.IsNullOrEmpty(machineId))
            {
                try
                {
                    if (!this.TextBoxMinimumA.Visible)
                    {
                        this.TextBoxMinimumA.Text = "0";
                        this.TextBoxMaximumA.Text = "1";
                        this.TextBoxMinimumB.Text = "0";
                        this.TextBoxMaximumB.Text = "1";
                    }

                    DetectorBusiness business = new DetectorBusiness();
                    Detector module = new Detector();

                    this.InitializeInsertModule(module);

                    module.MachineId = this.DropDownListMachines.SelectedValue;
                    module.DetectorTypeId = this.DropDownListDetectorTypes.SelectedValue;
                    module.Serial = int.Parse(this.TextBoxSerial.Text);
                    module.MinimumA = int.Parse(this.TextBoxMinimumA.Text);
                    module.MaximumA = int.Parse(this.TextBoxMaximumA.Text);
                    module.MinimumB = int.Parse(this.TextBoxMinimumB.Text);
                    module.MaximumB = int.Parse(this.TextBoxMaximumB.Text);

                    int mum = 0;
                    if (module.MinimumA > module.MaximumA)
                    {
                        mum = module.MinimumA;
                        module.MinimumA = module.MaximumA;
                        module.MaximumA = mum;
                    }
                    if (module.MinimumB > module.MaximumB)
                    {
                        mum = module.MinimumB;
                        module.MinimumB = module.MaximumB;
                        module.MaximumB = mum;
                    }

                    done = business.Insert(module);

                    if (done)
                    {
                        stringBuilder.Append("新增探头成功!");
                    }
                    else
                    {
                        stringBuilder.Append("新增探头失败!");
                    }
                }
                catch (Exception exception)
                {
                    stringBuilder.Append("新增探头错误!");
                    Variable.Logger.Log(exception);
                }
            }
            else
            {
                stringBuilder.Append("没有选择检测仪!");
            }

            this.LabelMessage.Text = stringBuilder.ToString();

            this.InitializeBind();
        }
Exemplo n.º 7
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();
        }
Exemplo n.º 8
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;
        }
Exemplo n.º 11
0
        private void InitializeBindInput()
        {
            this.TextBoxSerial.Text = string.Empty;
            this.TextBoxMinimumA.Text = string.Empty;
            this.TextBoxMaximumA.Text = string.Empty;
            this.TextBoxMinimumB.Text = string.Empty;
            this.TextBoxMaximumB.Text = string.Empty;

            if (!string.IsNullOrEmpty(this.DropDownListDetectors.SelectedValue))
            {
                DetectorBusiness business = new DetectorBusiness();

                string guid = this.DropDownListDetectors.SelectedValue;
                Detector value = business.QueryByGuid(guid);

                if (value != null)
                {
                    this.DropDownListRooms.SelectedValue = value.Machine.RoomId;

                    this.InitializeBindMachine();

                    this.DropDownListMachines.SelectedValue = value.MachineId;
                    this.DropDownListDetectorTypes.SelectedValue = value.DetectorTypeId;
                    this.TextBoxSerial.Text = value.Serial.ToString();
                    this.TextBoxMinimumA.Text = value.MinimumA.ToString();
                    this.TextBoxMaximumA.Text = value.MaximumA.ToString();
                    this.TextBoxMinimumB.Text = value.MinimumB.ToString();
                    this.TextBoxMaximumB.Text = value.MaximumB.ToString();
                }
            }
        }
Exemplo n.º 12
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);
                        }
                    }
                }
            }
        }