private void btnOK_Click(object sender, EventArgs e)
        {
            ProgSwitchInfo progSwitchInfo = new ProgSwitchInfo();
            if (txtName.Text.Trim() == "" || comboBoxEditDisplayChannel.Text.Trim() == "" || comboBoxEditDisplaySplitScreenNo.Text.Trim() == "")
            {
                return;
            }
            progSwitchInfo.Name = txtName.Text;
            progSwitchInfo.Description =txtDescription.Text;
            progSwitchInfo.DisplayChannelId = _listMonitorByName[comboBoxEditDisplayChannel.Text].DisplayChannelId;
            progSwitchInfo.DisplaySplitScreenNo = int.Parse(comboBoxEditDisplaySplitScreenNo.Text) - 1;
            errMessage = "";
            switch (Opt)
            {
                case Util.Operateion.Add:
                    GroupId = ProgSwitchBusiness.Instance.Insert(ref errMessage, progSwitchInfo);
                    OperateLogBusiness.Instance.Insert(ref errMessage, new OperateLog
                       {
                           HappenTime = DateTime.Now,
                           ClientUserId = MainForm.CurrentUser.UserId,
                           ClientUserName = MainForm.CurrentUser.UserName,
                           Content = progSwitchInfo.ToString(),
                           OperateTypeId =(int) OperateLogTypeId.ProgSwitchAdd,
                           OperateTypeName = OperateLogTypeName.ProgSwitchAdd,
                           OperateUserName = MainForm.CurrentUser.UserName

                       });
                    break;
                case Util.Operateion.Update:
                    //ogroup.GroupID = GeroupId;
                    GroupId = ProgSwitchBusiness.Instance.Update(ref errMessage, progSwitchInfo);

                    OperateLogBusiness.Instance.Insert(ref errMessage, new OperateLog
                    {
                        HappenTime = DateTime.Now,
                        ClientUserId = MainForm.CurrentUser.UserId,
                        ClientUserName = MainForm.CurrentUser.UserName,
                        Content = progSwitchInfo.ToString(),
                        OperateTypeId = (int)OperateLogTypeId.GroupSwitchUpdate,
                        OperateTypeName = OperateLogTypeName.GroupSwitchUpdate,
                        OperateUserName = MainForm.CurrentUser.UserName

                    });
                    break;
                case Util.Operateion.Delete:
                    break;
                default:
                    break;
            }
            if (errMessage.Length == 0)
            {
                this.Close();
            }
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            ProgSwitchInfo progSwitchInfo = new ProgSwitchInfo();
            progSwitchInfo.Name = txtName.Text;
            progSwitchInfo.Description =txtDescription.Text;
            errMessage = "";
            switch (Opt)
            {
                case Util.Operateion.Add:
                    GroupId = ProgSwitchBusiness.Instance.Insert(ref errMessage, progSwitchInfo);
                    OperateLogBusiness.Instance.Insert(ref errMessage, new OperateLog
                       {
                           HappenTime = DateTime.Now,
                           ClientUserId = MainForm.CurrentUser.UserId,
                           ClientUserName = MainForm.CurrentUser.UserName,
                           Content = progSwitchInfo.ToString(),
                           OperateTypeId =(int) OperateLogTypeId.ProgSwitchAdd,
                           OperateTypeName = OperateLogTypeName.ProgSwitchAdd,
                           OperateUserName = MainForm.CurrentUser.UserName

                       });
                    break;
                case Util.Operateion.Update:
                    //ogroup.GroupID = GeroupId;
                    GroupId = ProgSwitchBusiness.Instance.Update(ref errMessage, progSwitchInfo);

                    OperateLogBusiness.Instance.Insert(ref errMessage, new OperateLog
                    {
                        HappenTime = DateTime.Now,
                        ClientUserId = MainForm.CurrentUser.UserId,
                        ClientUserName = MainForm.CurrentUser.UserName,
                        Content = progSwitchInfo.ToString(),
                        OperateTypeId = (int)OperateLogTypeId.ProgSwitchUpdate,
                        OperateTypeName = OperateLogTypeName.ProgSwitchUpdate,
                        OperateUserName = MainForm.CurrentUser.UserName

                    });
                    break;
                case Util.Operateion.Delete:
                    break;
                default:
                    break;
            }
            if (errMessage.Length == 0)
            {
                this.Close();
            }
        }
        public Dictionary<int, ProgSwitchInfo> GetAllProgSwitchs(ref string errMessage)
        {
            Database db = DatabaseFactory.CreateDatabase();
            errMessage = "";
            var list = new Dictionary<int, ProgSwitchInfo>();
            try
            {
                ProgSwitchInfo progSwitchInfo;
                DataSet ds = ProgSwitchDataAccess.GetAllProgSwitchInfo(db);
                DataSet dsProgSwitchDetail;
                ProgSwitchDetailInfo progSwitchDetailInfo;

                //对于每一个程序切换
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    progSwitchInfo = new ProgSwitchInfo(ds.Tables[0].Rows[i]);

                    dsProgSwitchDetail = ProgSwitchDetailDataAccess.GetProgSwitchDetailByProgSwitchId(db, progSwitchInfo.Id);
                    progSwitchInfo.ListProgSwitchDetailInfo = new Dictionary<int, ProgSwitchDetailInfo>();
                    //对于一个程序切换中的所有与程序切换有联系的记录
                    foreach (DataRow drpsd in dsProgSwitchDetail.Tables[0].Rows)
                    {
                        progSwitchDetailInfo = new ProgSwitchDetailInfo(drpsd);

                        progSwitchInfo.ListProgSwitchDetailInfo.Add(progSwitchDetailInfo.ProgSwitchDetailId, progSwitchDetailInfo);
                    }

                    list.Add(progSwitchInfo.Id, progSwitchInfo);
                }
                return list;

            }
            catch (Exception ex)
            {
                errMessage = ex.Message + ex.StackTrace;
                Logger.Error("Error Message:" + ex.Message + " Trace:" + ex.StackTrace);
                return null;
            }
        }
        public int Update(ref string errMessage, ProgSwitchInfo progSwitchInfo)
        {
            Database db = DatabaseFactory.CreateDatabase();
            errMessage = "";
            try
            {
                return ProgSwitchDataAccess.Update(db, progSwitchInfo);

            }
            catch (Exception ex)
            {
                errMessage = ex.Message + ex.StackTrace;
                Logger.Error("Error Message:" + ex.Message + " Trace:" + ex.StackTrace);
                return -1;
            }
        }
        public ProgSwitchInfo GetProgSwitchById(ref string errMessage, int progSwitchId)
        {
            Database db = DatabaseFactory.CreateDatabase();
            errMessage = "";
            try
            {
                DataSet ds = ProgSwitchDataAccess.GetProgSwitchById(db, progSwitchId);
                if (ds.Tables[0].Rows.Count == 0)
                {
                    return null;
                }
                var progSwitchInfo = new ProgSwitchInfo(ds.Tables[0].Rows[0]) { ListProgSwitchDetailInfo = new Dictionary<int, ProgSwitchDetailInfo>() };

                var progSwitchDetail = ProgSwitchDetailDataAccess.GetProgSwitchDetailByProgSwitchId(db, progSwitchInfo.Id);
                progSwitchInfo.ListProgSwitchDetailInfo = new Dictionary<int, ProgSwitchDetailInfo>();
                //对于一个程序切换中的所有与程序切换有联系的记录
                foreach (DataRow drpsd in progSwitchDetail.Tables[0].Rows)
                {
                    var progSwitchDetailInfo = new ProgSwitchDetailInfo(drpsd);
                    progSwitchInfo.ListProgSwitchDetailInfo.Add(progSwitchDetailInfo.ProgSwitchDetailId, progSwitchDetailInfo);
                }
                return progSwitchInfo;

            }
            catch (Exception ex)
            {
                errMessage = ex.Message + ex.StackTrace;
                Logger.Error("Error Message:" + ex.Message + " Trace:" + ex.StackTrace);
                return null;
            }
        }
        public static int Insert(Database db, ProgSwitchInfo progSwitchInfo)
        {
            StringBuilder sbField = new StringBuilder();
            StringBuilder sbValue = new StringBuilder();
            sbField.Append("INSERT INTO ProgSwitch(");
            sbValue.Append("values(");
            sbField.Append("Name");
            sbValue.AppendFormat("'{0}'", progSwitchInfo.Name);
            sbField.Append(",Description");
            sbValue.AppendFormat(",'{0}'", progSwitchInfo.Description);
            sbField.Append(",DisplayChannelId");
            sbValue.AppendFormat(",{0}", progSwitchInfo.DisplayChannelId);
            sbField.Append(",DisplaySplitScreenNo)");
            sbValue.AppendFormat(",{0})", progSwitchInfo.DisplaySplitScreenNo);
            string cmdText = sbField.ToString() + " " + sbValue.ToString() + "";
            try
            {
                return db.ExecuteNonQuery(CommandType.Text, cmdText);

            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
        public static int Update(Database db, ProgSwitchInfo progSwitchInfo)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("update ProgSwitch set");
            sb.AppendFormat(" Name='{0}'", progSwitchInfo.Name);
            sb.AppendFormat(",Description='{0}'", progSwitchInfo.Description);
            sb.AppendFormat(",DisplaySplitScreenNo={0}", progSwitchInfo.DisplaySplitScreenNo);
            sb.AppendFormat(",DisplayChannelId={0} ", progSwitchInfo.DisplayChannelId);
            sb.AppendFormat(" where ID={0})", progSwitchInfo.Id);
            string cmdText = sb.ToString();
            try
            {
                return db.ExecuteNonQuery(CommandType.Text, cmdText);

            }
            catch (Exception ex)
            {

                throw ex;
            }
        }