Exemplo n.º 1
0
        public Dictionary<int, GroupInfo> GetAllGroupInfos(ref string errMessage)
        {
            Database db = DatabaseFactory.CreateDatabase();
            errMessage = "";
            Dictionary<int, GroupInfo> list = new Dictionary<int, GroupInfo>();
            try
            {
                GroupInfo oGroupInfo;
                DeviceInfo oDevice;
                DataSet ds= GroupDataAccess.GetAllGroupInfo(db);
                DataSet dsDevice;
                DataSet dsCamera;
                CameraInfo oCamera;
                DataSet dsAlarm;
                AlarmInfo oAlarm;
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    oGroupInfo = new GroupInfo(ds.Tables[0].Rows[i]);
                    dsDevice = DeviceDataAccess.GetDeviceInfoByGroupId(db, oGroupInfo.GroupID);
                    oGroupInfo.ListDevice = new Dictionary<int, DeviceInfo>();
                    foreach (DataRow dr in dsDevice.Tables[0].Rows)
                    {
                        oDevice = new DeviceInfo(dr);
                        oDevice.ListCamera = new Dictionary<int, CameraInfo>();
                        dsCamera = CameraDataAccess.GetCamInfoByDeviceId(db, oDevice.DeviceId);
                        foreach (DataRow drCam in dsCamera.Tables[0].Rows)
                        {
                            oCamera=new CameraInfo(drCam);
                            oDevice.ListCamera.Add(oCamera.CameraId, oCamera);
                        }

                        oDevice.ListAlarm = new Dictionary<int, AlarmInfo>();
                        dsAlarm = AlarmDataAccess.GetAlarmInfoByDeviceId(db, oDevice.DeviceId);
                        foreach (DataRow drAlarm in dsAlarm.Tables[0].Rows)
                        {
                            oAlarm = new AlarmInfo(drAlarm);
                            oDevice.ListAlarm.Add(oAlarm.AlarmId, oAlarm);
                        }

                        oGroupInfo.ListDevice.Add(oDevice.DeviceId, oDevice);

                    }
                    list.Add(oGroupInfo.GroupID, oGroupInfo);
                }
                return list;

            }
            catch (Exception ex)
            {
                errMessage = ex.Message + ex.StackTrace;
                logger.Error("Error Message:" + ex.Message + " Trace:" + ex.StackTrace);
                return null;
            }
        }
Exemplo n.º 2
0
 private void btnOK_Click(object sender, EventArgs e)
 {
     GroupInfo ogroup=new GroupInfo();
     ogroup.Name = txtName.Text;
     ogroup.Description =txtDescription.Text;
     ogroup.ParentId = ParentGroupId;
     ogroup.GroupID = GroupId;
     errMessage = "";
     switch (Opt)
     {
         case Util.Operateion.Add:
             GroupId = GroupBusiness.Instance.Insert(ref errMessage, ogroup);
             ogroup = GroupBusiness.Instance.GetGroupInfoByGroupName(ref errMessage, ogroup.Name);
             OperateLogBusiness.Instance.Insert(ref errMessage, new OperateLog
             {
                 HappenTime = DateTime.Now,
                 OperateTypeId = (int)(OperateLogTypeId.GroupAdd),
                 OperateTypeName = OperateLogTypeName.GroupAdd,
                 Content = ogroup.ToString(),
                 GroupId = ogroup.GroupID,
                 OperateUserName = MainForm.CurrentUser.UserName,
                 ClientUserName = MainForm.CurrentUser.UserName,
                 ClientUserId = MainForm.CurrentUser.UserId
             });
             break;
         case Util.Operateion.Update:
             ogroup = GroupBusiness.Instance.GetGroupInfoByGroupId(ref errMessage, GroupId);
             ogroup.Name = txtName.Text;
             ogroup.Description = txtDescription.Text;
             GroupId = GroupBusiness.Instance.Update(ref errMessage, ogroup);
             OperateLogBusiness.Instance.Insert(ref errMessage, new OperateLog
             {
                 HappenTime = DateTime.Now,
                 OperateTypeId = (int)(OperateLogTypeId.GroupUpdate),
                 OperateTypeName = OperateLogTypeName.GroupUpdate,
                 Content = ogroup.ToString(),
                 GroupId = ogroup.GroupID,
                 OperateUserName = MainForm.CurrentUser.UserName,
                 ClientUserName = MainForm.CurrentUser.UserName,
                 ClientUserId = MainForm.CurrentUser.UserId
             });
             break;
         case Util.Operateion.Delete:
             ogroup = GroupBusiness.Instance.GetGroupInfoByGroupId(ref errMessage, GroupId);
             GroupId = GroupBusiness.Instance.Delete(ref errMessage, GroupId);
             OperateLogBusiness.Instance.Insert(ref errMessage, new OperateLog
                 {
                     HappenTime = DateTime.Now,
                     OperateTypeId = (int)(OperateLogTypeId.GroupDelete),
                     OperateTypeName = OperateLogTypeName.GroupDelete ,
                     Content = ogroup.ToString(),
                     GroupId = ogroup.GroupID,
                     OperateUserName = MainForm.CurrentUser.UserName,
                     ClientUserName = MainForm.CurrentUser.UserName,
                     ClientUserId = MainForm.CurrentUser.UserId
                 });
             break;
         default:
             break;
     }
     if (errMessage.Length == 0)
     {
         this.Close();
     }
 }
Exemplo n.º 3
0
        public static int Insert(Database db, GroupInfo oGroupInfo)
        {
            StringBuilder sbField = new StringBuilder();
            StringBuilder sbValue = new StringBuilder();
            sbField.Append("INSERT INTO GroupInfo(");
            sbValue.Append("values(");
            sbField.Append("Name");
            sbValue.AppendFormat("'{0}'", oGroupInfo.Name);
            sbField.Append(",Description");
            sbValue.AppendFormat(",'{0}'", oGroupInfo.Description);
            sbField.Append(",ParentId");
            sbValue.AppendFormat(",{0}", oGroupInfo.ParentId);
            sbField.Append(",AddBy");
            sbValue.AppendFormat(",'{0}'", oGroupInfo.AddBy);
            sbField.Append(",AddTime)");
            sbValue.AppendFormat(",'{0}')", oGroupInfo.AddTime);
            string cmdText = sbField.ToString() + " " + sbValue.ToString() + "";
            try
            {
                return db.ExecuteNonQuery(CommandType.Text, cmdText);

            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
Exemplo n.º 4
0
        public static int Update(Database db, GroupInfo oGroupInfo)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("update GroupInfo set");
            sb.AppendFormat(" Name='{0}'", oGroupInfo.Name);
            sb.AppendFormat(",Description='{0}'", oGroupInfo.Description);
            sb.AppendFormat(",ParentId={0}", oGroupInfo.ParentId);
            sb.AppendFormat(",ModifyBy='{0}'", oGroupInfo.AddBy);
            sb.AppendFormat(",ModifyTime='{0}'", oGroupInfo.AddTime ?? DateTime.Now.ToString());
            sb.AppendFormat(" where GroupID={0}", oGroupInfo.GroupID);
            string cmdText = sb.ToString();
            try
            {
                return db.ExecuteNonQuery(CommandType.Text, cmdText);

            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
Exemplo n.º 5
0
        public int Update(ref string errMessage, GroupInfo oGroupInfo)
        {
            Database db = DatabaseFactory.CreateDatabase();
            errMessage = "";
            try
            {
                return GroupDataAccess.Update(db, oGroupInfo);

            }
            catch (Exception ex)
            {
                errMessage = ex.Message + ex.StackTrace;
                logger.Error("Error Message:" + ex.Message + " Trace:" + ex.StackTrace);
                return -1;
            }
        }
Exemplo n.º 6
0
        public GroupInfo GetGroupInfoByGroupName(ref string errMessage, string groupName)
        {
            Database db = DatabaseFactory.CreateDatabase();
            errMessage = "";
            try
            {
                DataSet ds = GroupDataAccess.GetGroupInfoByGroupName(db, groupName);
                if (ds.Tables[0].Rows.Count == 0)
                {
                    return null;
                }
                DataSet dsDevice;
                DataSet dsCamera;
                CameraInfo oCamera;
                DeviceInfo oDevice;
                DataSet dsAlarm;
                AlarmInfo oAlarm;

                GroupInfo oGroupInfo = new GroupInfo(ds.Tables[0].Rows[0]);
                dsDevice = DeviceDataAccess.GetDeviceInfoByGroupId(db, oGroupInfo.GroupID);
                oGroupInfo.ListDevice = new Dictionary<int, DeviceInfo>();
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    oDevice = new DeviceInfo(dr);
                    oDevice.ListCamera = new Dictionary<int, CameraInfo>();
                    dsCamera = CameraDataAccess.GetCamInfoByDeviceId(db, oDevice.DeviceId);
                    foreach (DataRow drCam in dsCamera.Tables[0].Rows)
                    {
                        oCamera = new CameraInfo(drCam);
                        oDevice.ListCamera.Add(oCamera.CameraId, oCamera);
                    }
                    oDevice.ListAlarm = new Dictionary<int, AlarmInfo>();
                    dsAlarm = AlarmDataAccess.GetAlarmInfoByDeviceId(db, oDevice.DeviceId);
                    foreach (DataRow drAlarm in dsAlarm.Tables[0].Rows)
                    {
                        oAlarm = new AlarmInfo(drAlarm);
                        oDevice.ListAlarm.Add(oAlarm.AlarmId, oAlarm);
                    }
                    oGroupInfo.ListDevice.Add(oDevice.DeviceId, oDevice);

                }

                return oGroupInfo;

            }
            catch (Exception ex)
            {
                errMessage = ex.Message + ex.StackTrace;
                logger.Error("Error Message:" + ex.Message + " Trace:" + ex.StackTrace);
                return null;
            }
        }