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

            string sql = string.Format("insert into e_room ({0}) values (:guid, :insert_user_id, :insert_time, :update_user_id, :update_time, :remark, :validity, :name, :address, :contact, :phone)", this.Asterisk(""));
            List<Parameter> parameters = new List<Parameter>();

            parameters.Add(new Parameter("guid", DatabaseHibernate.Parameter(DatabaseHibernate.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("address", DatabaseHibernate.Parameter(value.Address)));
            parameters.Add(new Parameter("contact", DatabaseHibernate.Parameter(value.Contact)));
            parameters.Add(new Parameter("phone", DatabaseHibernate.Parameter(value.Phone)));

            DatabaseHibernate hibernate = new DatabaseHibernate();

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

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

            MachineHibernate machineHibernate = new MachineHibernate();
            result = machineHibernate.DeleteByRoom(value.Guid);

            DatabaseHibernate hibernate = new DatabaseHibernate();
            List<Parameter> parameters = new List<Parameter>();

            if (result)
            {
                string sql = string.Format("delete from e_user_room as t where [t].[room_id] = '{0}'", value.Guid);
                parameters.Clear();

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

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

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

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

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

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

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

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

            RoomBusiness business = new RoomBusiness();

            if (this.CheckBoxListRooms.Items != null)
            {
                List<Room> rooms = new List<Room>();
                for (int i = 0; i < this.CheckBoxListRooms.Items.Count; i++)
                {
                    if (this.CheckBoxListRooms.Items[i].Selected)
                    {
                        Room room = new Room();
                        room.Guid = this.CheckBoxListRooms.Items[i].Value;
                        rooms.Add(room);
                    }
                }

                if ((rooms != null) && (rooms.Count > 0))
                {
                    int success = 0;
                    int fail = 0;
                    for (int i = 0; i < rooms.Count; i++)
                    {
                        done = business.Delete(rooms[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 ButtonOK_Click(object sender, EventArgs e)
        {
            bool done = false;
            StringBuilder stringBuilder = new StringBuilder();

            RoomBusiness business = new RoomBusiness();
            Room module = new Room();

            this.InitializeInsertModule(module);

            module.Name = this.TextBoxName.Text;
            module.Address = this.TextBoxAddress.Text;
            module.Contact = this.TextBoxContact.Text;
            module.Phone = this.TextBoxPhone.Text;

            Room room = business.QueryByName(module.Name);

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

                if (done)
                {
                    stringBuilder.Append("新增机房成功!");
                }
                else
                {
                    stringBuilder.Append("新增机房失败!");
                }
            }
            else
            {
                stringBuilder.Append("机房已经存在(名称相同)!");
            }

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

            this.InitializeBind();
        }
        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();
        }
        private void InitializeBind()
        {
            this.TextBoxName.Text = string.Empty;
            this.TextBoxAddress.Text = string.Empty;
            this.TextBoxContact.Text = string.Empty;
            this.TextBoxPhone.Text = string.Empty;

            RoomBusiness business = new RoomBusiness();

            int total = 0;
            List<Room> rooms = business.Query(1, int.MaxValue, ref total);
            Room emptyRoom = new Room();
            emptyRoom.Guid = string.Empty;
            emptyRoom.Name = string.Empty;
            rooms.Insert(0, emptyRoom);
            this.DropDownListRooms.DataSource = rooms;
            this.DropDownListRooms.DataTextField = "Name";
            this.DropDownListRooms.DataValueField = "Guid";
            this.DropDownListRooms.DataBind();
        }
        /// <summary>
        /// 解析数据
        /// </summary>
        /// <param name="values">数据</param>
        /// <returns>机房</returns>
        public Room Parse(object[] values)
        {
            Room result = new Room();

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

                result.Name = DatabaseHibernate.ParseString(values[7]);
                result.Address = DatabaseHibernate.ParseString(values[8]);
                result.Contact = DatabaseHibernate.ParseString(values[9]);
                result.Phone = DatabaseHibernate.ParseString(values[10]);
            }
            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(Room value)
        {
            bool result = false;

            string sql = string.Format("update e_room 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].[address] = :address, [t].[contact] = :contact, [t].[phone] = :phone 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("address", DatabaseHibernate.Parameter(value.Address)));
            parameters.Add(new Parameter("contact", DatabaseHibernate.Parameter(value.Contact)));
            parameters.Add(new Parameter("phone", DatabaseHibernate.Parameter(value.Phone)));

            DatabaseHibernate hibernate = new DatabaseHibernate();

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

            return result;
        }
        public Room QueryByName(string name)
        {
            Room result = null;

            string sql = string.Format("select {0} from e_room as t where ucase([t].[name]) = ucase(:name)", this.Asterisk("[t]."));
            List<Parameter> parameters = new List<Parameter>();

            parameters.Add(new Parameter("name", DatabaseHibernate.Parameter(name)));

            DatabaseHibernate hibernate = new DatabaseHibernate();

            List<object[]> values = hibernate.Read(Variable.Link, sql, parameters);

            if ((values != null) && (values.Count == 1))
            {
                result = new Room();

                object[] moduleValues = values[0];

                result = this.Parse(moduleValues);
            }

            return result;
        }
        public Room QueryByGuid(string guid)
        {
            Room result = null;

            string sql = string.Format("select {0} from e_room as t where [t].[guid] = '{1}'", this.Asterisk("[t]."), guid);
            List<Parameter> parameters = new List<Parameter>();

            DatabaseHibernate hibernate = new DatabaseHibernate();

            List<object[]> values = hibernate.Read(Variable.Link, sql, parameters);

            if ((values != null) && (values.Count == 1))
            {
                result = new Room();

                object[] moduleValues = values[0];

                result = this.Parse(moduleValues);
            }

            return result;
        }