protected void ButtonOK_Click(object sender, EventArgs e)
        {
            bool done = false;
            StringBuilder stringBuilder = new StringBuilder();

            try
            {
                DetectorTypeBusiness business = new DetectorTypeBusiness();
                DetectorType module = new DetectorType();

                this.InitializeInsertModule(module);

                module.Name = this.TextBoxName.Text;
                module.Type = (EnvironmentalMonitor.Support.Resource.DetectorTypes)(int.Parse(this.DropDownListTypes.SelectedValue));
                module.Code = byte.Parse(this.TextBoxCode.Text);
                module.DescriptionA = this.TextBoxDescriptionA.Text;
                module.DescriptionB = this.TextBoxDescriptionB.Text;
                module.UnitA = this.TextBoxUnitA.Text;
                module.UnitB = this.TextBoxUnitB.Text;

                DetectorType detectorType = business.QueryByNameOrCode(module.Name, module.Code);

                if (detectorType == null)
                {
                    done = business.Insert(module);

                    if (done)
                    {
                        stringBuilder.Append("新增探头类型成功!");
                        detectorType = business.QueryByNameOrCode(module.Name, module.Code);
                        if (detectorType != null)
                        {
                            string[] imageFiles = { this.MapPath(detectorType.NormalHref), this.MapPath(detectorType.ErrorHref) };
                            FileUpload[] fileUploads = { this.FileUploadNormal, this.FileUploadError };
                            for (int i = 0; i < imageFiles.Length; i++)
                            {
                                this.UploadFileSave(fileUploads[i], imageFiles[i]);
                            }
                        }
                    }
                    else
                    {
                        stringBuilder.Append("新增探头类型失败!");
                    }
                }
                else
                {
                    stringBuilder.Append("探头类型已经存在(名称或代码相同)!");
                }
            }
            catch (Exception exception)
            {
                stringBuilder.Append("新增探头类型错误!");
                Variable.Logger.Log(exception);
            }

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

            this.InitializeBind();
        }
        protected void ButtonOK_Click(object sender, EventArgs e)
        {
            bool done = false;
            StringBuilder stringBuilder = new StringBuilder();

            DetectorTypeBusiness business = new DetectorTypeBusiness();

            if (this.CheckBoxListDetectorTypes.Items != null)
            {
                List<DetectorType> detectorTypes = new List<DetectorType>();
                for (int i = 0; i < this.CheckBoxListDetectorTypes.Items.Count; i++)
                {
                    if (this.CheckBoxListDetectorTypes.Items[i].Selected)
                    {
                        DetectorType detectorType = new DetectorType();
                        detectorType.Guid = this.CheckBoxListDetectorTypes.Items[i].Value;
                        detectorTypes.Add(detectorType);
                    }
                }

                if ((detectorTypes != null) && (detectorTypes.Count > 0))
                {
                    int success = 0;
                    int fail = 0;
                    for (int i = 0; i < detectorTypes.Count; i++)
                    {
                        try
                        {
                            this.UploadFileDelete(this.MapPath(detectorTypes[i].NormalHref));
                            this.UploadFileDelete(this.MapPath(detectorTypes[i].ErrorHref));
                        }
                        finally
                        {
                        }
                        done = business.Delete(detectorTypes[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();
        }
        private void InitializeBindType()
        {
            if (this.DropDownListDetectorTypes.SelectedValue != null)
            {
                string guid = this.DropDownListDetectorTypes.SelectedValue;
                DetectorTypeBusiness business = new DetectorTypeBusiness();
                DetectorType detectorType = business.QueryByGuid(guid);
                switch (detectorType.Type)
                {
                    case Support.Resource.DetectorTypes.Switch:
                        this.LabelMinimumA.Visible = false;
                        this.LabelMaximumA.Visible = false;
                        this.LabelMinimumB.Visible = false;
                        this.LabelMaximumB.Visible = false;
                        this.TextBoxMinimumA.Visible = false;
                        this.TextBoxMaximumA.Visible = false;
                        this.TextBoxMinimumB.Visible = false;
                        this.TextBoxMaximumB.Visible = false;

                        this.RequiredFieldValidatorMinimumA.Visible = false;
                        this.RequiredFieldValidatorMaximumA.Visible = false;
                        this.RequiredFieldValidatorMinimumB.Visible = false;
                        this.RequiredFieldValidatorMaximumB.Visible = false;
                        this.RangeValidatorMinimumA.Visible = false;
                        this.RangeValidatorMaximumA.Visible = false;
                        this.RangeValidatorMinimumB.Visible = false;
                        this.RangeValidatorMaximumB.Visible = false;

                        this.RequiredFieldValidatorMinimumA.Enabled = false;
                        this.RequiredFieldValidatorMaximumA.Enabled = false;
                        this.RequiredFieldValidatorMinimumB.Enabled = false;
                        this.RequiredFieldValidatorMaximumB.Enabled = false;
                        this.RangeValidatorMinimumA.Enabled = false;
                        this.RangeValidatorMaximumA.Enabled = false;
                        this.RangeValidatorMinimumB.Enabled = false;
                        this.RangeValidatorMaximumB.Enabled = false;

                        this.LabelMinimumA.Text = string.Format("{0}:", detectorType.DescriptionA);
                        break;
                    case Support.Resource.DetectorTypes.DoubleArea:
                        this.LabelMinimumA.Visible = true;
                        this.LabelMaximumA.Visible = true;
                        this.LabelMinimumB.Visible = true;
                        this.LabelMaximumB.Visible = true;
                        this.TextBoxMinimumA.Visible = true;
                        this.TextBoxMaximumA.Visible = true;
                        this.TextBoxMinimumB.Visible = true;
                        this.TextBoxMaximumB.Visible = true;

                        this.RequiredFieldValidatorMinimumA.Visible = true;
                        this.RequiredFieldValidatorMaximumA.Visible = true;
                        this.RequiredFieldValidatorMinimumB.Visible = true;
                        this.RequiredFieldValidatorMaximumB.Visible = true;
                        this.RangeValidatorMinimumA.Visible = true;
                        this.RangeValidatorMaximumA.Visible = true;
                        this.RangeValidatorMinimumB.Visible = true;
                        this.RangeValidatorMaximumB.Visible = true;

                        this.RequiredFieldValidatorMinimumA.Enabled = true;
                        this.RequiredFieldValidatorMaximumA.Enabled = true;
                        this.RequiredFieldValidatorMinimumB.Enabled = true;
                        this.RequiredFieldValidatorMaximumB.Enabled = true;
                        this.RangeValidatorMinimumA.Enabled = true;
                        this.RangeValidatorMaximumA.Enabled = true;
                        this.RangeValidatorMinimumB.Enabled = true;
                        this.RangeValidatorMaximumB.Enabled = true;

                        this.LabelMinimumA.Text = string.Format("{0}阀值下限:<br />({1})", detectorType.DescriptionA, detectorType.UnitA);
                        this.LabelMaximumA.Text = string.Format("{0}阀值上限:<br />({1})", detectorType.DescriptionA, detectorType.UnitA);
                        this.LabelMinimumB.Text = string.Format("{0}阀值下限:<br />({1})", detectorType.DescriptionB, detectorType.UnitB);
                        this.LabelMaximumB.Text = string.Format("{0}阀值上限:<br />({1})", detectorType.DescriptionB, detectorType.UnitB);

                        this.RequiredFieldValidatorMinimumA.ErrorMessage = string.Format("{0}阀值下限不允许为空!<br />", detectorType.DescriptionA);
                        this.RequiredFieldValidatorMaximumA.ErrorMessage = string.Format("{0}阀值上限不允许为空!<br />", detectorType.DescriptionA);
                        this.RequiredFieldValidatorMinimumB.ErrorMessage = string.Format("{0}阀值下限不允许为空!<br />", detectorType.DescriptionB);
                        this.RequiredFieldValidatorMaximumB.ErrorMessage = string.Format("{0}阀值上限不允许为空!<br />", detectorType.DescriptionB);
                        this.RangeValidatorMinimumA.ErrorMessage = string.Format("{0}阀值下限范围从0到255!<br />", detectorType.DescriptionA);
                        this.RangeValidatorMaximumA.ErrorMessage = string.Format("{0}阀值上限范围从0到255!<br />", detectorType.DescriptionA);
                        this.RangeValidatorMinimumB.ErrorMessage = string.Format("{0}阀值下限范围从0到255!<br />", detectorType.DescriptionB);
                        this.RangeValidatorMaximumB.ErrorMessage = string.Format("{0}阀值上限范围从0到255!<br />", detectorType.DescriptionB);
                        break;
                }
            }
        }
        private void InitializeBindDetectorType()
        {
            DetectorTypeBusiness business = new DetectorTypeBusiness();

            int total = 0;
            List<DetectorType> detectorTypes = business.Query(1, int.MaxValue, ref total);

            this.DropDownListDetectorTypes.DataSource = detectorTypes;
            this.DropDownListDetectorTypes.DataTextField = "Name";
            this.DropDownListDetectorTypes.DataValueField = "Guid";
            this.DropDownListDetectorTypes.DataBind();
        }
        private void InitializeBindDetectorType()
        {
            DetectorTypeBusiness business = new DetectorTypeBusiness();

            int total = 0;
            List<DetectorType> detectorTypes = business.Query(1, int.MaxValue, ref total);
            DetectorType emptyDetectorType = new DetectorType();
            emptyDetectorType.Guid = string.Empty;
            emptyDetectorType.Name = string.Empty;
            detectorTypes.Insert(0, emptyDetectorType);

            this.DropDownListDetectorTypes.DataSource = detectorTypes;
            this.DropDownListDetectorTypes.DataTextField = "Name";
            this.DropDownListDetectorTypes.DataValueField = "Guid";
            this.DropDownListDetectorTypes.DataBind();
        }
        protected void DropDownListDetectorTypes_SelectedIndexChanged(object sender, EventArgs e)
        {
            string guid = this.DropDownListDetectorTypes.SelectedValue;
            if (!string.IsNullOrEmpty(guid))
            {
                this.LabelMessage.Text = string.Empty;
                DetectorTypeBusiness business = new DetectorTypeBusiness();

                DetectorType currentDetectorType = business.QueryByGuid(guid);

                if (currentDetectorType != null)
                {
                    this.TextBoxName.Text = currentDetectorType.Name;
                    this.DropDownListTypes.SelectedValue = currentDetectorType.TypeValue.ToString();
                    this.TextBoxCode.Text = currentDetectorType.Code.ToString();
                    this.TextBoxDescriptionA.Text = currentDetectorType.DescriptionA;
                    this.TextBoxDescriptionB.Text = currentDetectorType.DescriptionB;
                    this.TextBoxUnitA.Text = currentDetectorType.UnitA;
                    this.TextBoxUnitB.Text = currentDetectorType.UnitB;

                    this.ImageNormal.ImageUrl = currentDetectorType.NormalHref;
                    this.ImageError.ImageUrl = currentDetectorType.ErrorHref;
                }
            }
        }