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();
        }
        /// <summary>
        /// 增加
        /// </summary>
        /// <param name="value">值</param>
        /// <returns>结果</returns>
        public bool Insert(DetectorType value)
        {
            bool result = false;

            string sql = string.Format("insert into e_detector_type ({0}) values (:guid, :insert_user_id, :insert_time, :update_user_id, :update_time, :remark, :validity, :name, :type, :code, :description_a, :description_b, :unit_a, :unit_b)", this.Asterisk(""));
            List<Parameter> parameters = new List<Parameter>();

            if (string.IsNullOrEmpty(value.Guid))
            {
                value.Guid = DatabaseHibernate.GUID();
            }

            parameters.Add(new Parameter("guid", DatabaseHibernate.Parameter(value.Guid)));
            parameters.Add(new Parameter("insert_user_id", DatabaseHibernate.Parameter(value.InsertUserId)));
            parameters.Add(new Parameter("insert_time", DatabaseHibernate.Parameter(value.InsertTime)));
            parameters.Add(new Parameter("update_user_id", DatabaseHibernate.Parameter(value.UpdateUserId)));
            parameters.Add(new Parameter("update_time", DatabaseHibernate.Parameter(value.UpdateTime)));
            parameters.Add(new Parameter("remark", DatabaseHibernate.Parameter(value.Remark)));
            parameters.Add(new Parameter("validity", DatabaseHibernate.Parameter(value.Validity)));

            parameters.Add(new Parameter("name", DatabaseHibernate.Parameter(value.Name)));
            parameters.Add(new Parameter("type", DatabaseHibernate.Parameter((int)value.Type)));
            parameters.Add(new Parameter("code", DatabaseHibernate.Parameter(value.Code)));
            parameters.Add(new Parameter("description_a", DatabaseHibernate.Parameter(value.DescriptionA)));
            parameters.Add(new Parameter("description_b", DatabaseHibernate.Parameter(value.DescriptionB)));
            parameters.Add(new Parameter("unit_a", DatabaseHibernate.Parameter(value.UnitA)));
            parameters.Add(new Parameter("unit_b", DatabaseHibernate.Parameter(value.UnitB)));

            DatabaseHibernate hibernate = new DatabaseHibernate();

            result = hibernate.Write(Variable.Link, sql, parameters);

            return result;
        }
        /// <summary>
        /// 增加
        /// </summary>
        /// <param name="value">值</param>
        /// <returns>结果</returns>
        public bool Insert(DetectorType value)
        {
            bool result = false;

            DetectorTypeHibernate hibernate = new DetectorTypeHibernate();
            result = hibernate.Insert(value);

            return result;
        }
        public bool Delete(DetectorType value)
        {
            bool result = false;

            DetectorTypeHibernate hibernate = new DetectorTypeHibernate();
            result = hibernate.Delete(value);

            return result;
        }
        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();
        }
        public bool Delete(DetectorType value)
        {
            bool result = false;

            DatabaseHibernate hibernate = new DatabaseHibernate();

            string sql = string.Format("delete from e_detector as t where [t].[detector_type_id] = '{0}'", value.Guid);
            List<Parameter> parameters = new List<Parameter>();

            result = hibernate.Write(Variable.Link, sql, parameters);

            if (result)
            {
                sql = string.Format("delete from e_detector_type as t where [t].[guid] = '{0}'", value.Guid);
                parameters.Clear();
                result = hibernate.Write(Variable.Link, sql, parameters);
            }

            return result;
        }
        /// <summary>
        /// 解析数据
        /// </summary>
        /// <param name="values">数据</param>
        /// <returns>探头类型</returns>
        public DetectorType Parse(object[] values)
        {
            DetectorType result = new DetectorType();

            try
            {
                result = DatabaseHibernate.ParseModule(result, values) as DetectorType;

                result.Name = DatabaseHibernate.ParseString(values[7]);
                result.Type = DatabaseHibernate.ParseDetectorTypes(values[8]);
                result.Code = DatabaseHibernate.ParseByte(values[9]);
                result.DescriptionA = DatabaseHibernate.ParseString(values[10]);
                result.DescriptionB = DatabaseHibernate.ParseString(values[11]);
                result.UnitA = DatabaseHibernate.ParseString(values[12]);
                result.UnitB = DatabaseHibernate.ParseString(values[13]);
            }
            catch (Exception exception)
            {
                result = null;
                EnvironmentalMonitor.Support.Resource.Variable.Logger.Log(exception);
            }

            return result;
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="value">值</param>
        /// <returns>结果</returns>
        public bool Update(DetectorType value)
        {
            bool result = false;

            string sql = string.Format("update e_detector_type as t set [t].[update_user_id] = :update_user_id, [t].[update_time] = :update_time, [t].[remark] = :remark, [t].[validity] = :validity, [t].[name] = :name, [t].[type] = :type, [t].[code] = :code, [t].[description_a] = :description_a, [t].[description_b] = :description_b, [t].[unit_a] = :unit_a, [t].[unit_b] = :unit_b where [t].[guid] = '{0}'", value.Guid);
            List<Parameter> parameters = new List<Parameter>();

            parameters.Add(new Parameter("update_user_id", DatabaseHibernate.Parameter(value.UpdateUserId)));
            parameters.Add(new Parameter("update_time", DatabaseHibernate.Parameter(value.UpdateTime)));
            parameters.Add(new Parameter("remark", DatabaseHibernate.Parameter(value.Remark)));
            parameters.Add(new Parameter("validity", DatabaseHibernate.Parameter(value.Validity)));

            parameters.Add(new Parameter("name", DatabaseHibernate.Parameter(value.Name)));
            parameters.Add(new Parameter("type", DatabaseHibernate.Parameter((int)value.Type)));
            parameters.Add(new Parameter("code", DatabaseHibernate.Parameter(value.Code)));
            parameters.Add(new Parameter("description_a", DatabaseHibernate.Parameter(value.DescriptionA)));
            parameters.Add(new Parameter("description_b", DatabaseHibernate.Parameter(value.DescriptionB)));
            parameters.Add(new Parameter("unit_a", DatabaseHibernate.Parameter(value.UnitA)));
            parameters.Add(new Parameter("unit_b", DatabaseHibernate.Parameter(value.UnitB)));

            DatabaseHibernate hibernate = new DatabaseHibernate();

            result = hibernate.Write(Variable.Link, sql, parameters);

            return result;
        }
        private void InitializeBindCode()
        {
            DetectorType switchDetectorType = new DetectorType();
            switchDetectorType.Type = EnvironmentalMonitor.Support.Resource.DetectorTypes.Switch;
            DetectorType doubleAreaDetectorType = new DetectorType();
            doubleAreaDetectorType.Type = EnvironmentalMonitor.Support.Resource.DetectorTypes.DoubleArea;

            List<DetectorType> detectorTypes = new List<DetectorType>();
            detectorTypes.Add(switchDetectorType);
            detectorTypes.Add(doubleAreaDetectorType);

            this.DropDownListTypes.DataSource = detectorTypes;
            this.DropDownListTypes.DataTextField = "TypeText";
            this.DropDownListTypes.DataValueField = "TypeValue";
            this.DropDownListTypes.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();
        }