Exemplo n.º 1
0
        public void insertDeviceRouting(DeviceRoutingEntity devRoutingEntity)
        {
            validateTargetId(devRoutingEntity);

            string sqltext = "INSERT INTO RBFX.DeviceRouting ("
                             + "DeviceId,RoutingKeyword,TargetType,TargetDeviceGroupId,TargetDeviceId,"
                             + "Status,Description,Registered_DateTime"
                             + ") VALUES "
                             + "(@p1,@p2,@p3,@p4,@p5,@p6,@p7,@p8)";

            SqlConnection conn = new SqlConnection(this.sqlConnectionString);

            try
            {
                conn.Open();

                SqlCommand cmd = new SqlCommand(sqltext, conn);
                AddSqlParameter(ref cmd, "@p1", SqlDbType.NVarChar, devRoutingEntity.DeviceId);
                AddSqlParameter(ref cmd, "@p2", SqlDbType.NVarChar, devRoutingEntity.RoutingKeyword);
                AddSqlParameter(ref cmd, "@p3", SqlDbType.NVarChar, devRoutingEntity.TargetType);
                AddSqlParameter(ref cmd, "@p4", SqlDbType.NVarChar, devRoutingEntity.TargetDeviceGroupId);
                AddSqlParameter(ref cmd, "@p5", SqlDbType.NVarChar, devRoutingEntity.TargetDeviceId);
                AddSqlParameter(ref cmd, "@p6", SqlDbType.NVarChar, devRoutingEntity.Status);
                AddSqlParameter(ref cmd, "@p7", SqlDbType.NVarChar, devRoutingEntity.Description);
                AddSqlParameter(ref cmd, "@p8", SqlDbType.DateTime, devRoutingEntity.Registered_DateTime);
                cmd.ExecuteNonQuery();

                conn.Close();
            }
            catch (Exception ex)
            {
                conn.Close();
                throw ex;
            }
        }
        public EditDevRoutingForm(string sqlConnectionString)
        {
            InitializeComponent();

            this.sqlConnectionString        = sqlConnectionString;
            devRoutingEntity                = new DeviceRoutingEntity();
            devRoutingEntity.DeviceId       = string.Empty;
            devRoutingEntity.RoutingKeyword = CRoboticsConst.RoutingKeywordDefault;
            this.createStatus               = true;
        }
        private DeviceRoutingEntity getDeviceRoutingEntity()
        {
            DeviceRoutingEntity devRoutingEntity = new DeviceRoutingEntity();

            devRoutingEntity.DeviceId            = textBoxDeviceId.Text;
            devRoutingEntity.RoutingKeyword      = textBoxRoutingKeyword.Text;
            devRoutingEntity.TargetType          = comboBoxTargetDeviceType.Text;
            devRoutingEntity.TargetDeviceGroupId = textBoxTargetDevGroupId.Text;
            devRoutingEntity.TargetDeviceId      = textBoxTargetDeviceId.Text;
            devRoutingEntity.Status              = comboBoxStatus.Text;
            devRoutingEntity.Description         = textBoxDesc.Text;
            devRoutingEntity.Registered_DateTime = DateTime.Now;

            return(devRoutingEntity);
        }
        public EditDevRoutingForm(string sqlConnectionString, DeviceRoutingEntity devRoutingEntity)
        {
            InitializeComponent();

            this.sqlConnectionString = sqlConnectionString;
            this.devRoutingEntity    = devRoutingEntity;
            if (devRoutingEntity.DeviceId == string.Empty)
            {
                throw (new ApplicationException("Device ID is nothing !!"));
            }

            if (devRoutingEntity.RoutingKeyword == string.Empty)
            {
                throw (new ApplicationException("Routing Keyword is nothing !!"));
            }

            this.createStatus = false;
        }
        private void createButton_Click(object sender, EventArgs e)
        {
            if (!checkInputData())
            {
                return;
            }

            try
            {
                DeviceRoutingEntity    devRoutingEntity  = getDeviceRoutingEntity();
                DeviceRoutingProcessor devRouteProcessor = new DeviceRoutingProcessor(sqlConnectionString);
                devRouteProcessor.insertDeviceRouting(devRoutingEntity);

                MessageBox.Show("Device Routing created successfully!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            this.Close();
        }
Exemplo n.º 6
0
        public void updateDeviceRouting(DeviceRoutingEntity devRoutingEntity)
        {
            validateTargetId(devRoutingEntity);

            string sqltext = "UPDATE RBFX.DeviceRouting SET "
                             + "TargetType = @p3,"
                             + "TargetDeviceGroupId = @p4,"
                             + "TargetDeviceId = @p5,"
                             + "Status = @p6,"
                             + "Description = @p7,"
                             + "Registered_DateTime = @p8 "
                             + "WHERE DeviceId = @p1 AND RoutingKeyword = @p2";

            SqlConnection conn = new SqlConnection(this.sqlConnectionString);

            try
            {
                conn.Open();

                SqlCommand cmd = new SqlCommand(sqltext, conn);
                AddSqlParameter(ref cmd, "@p1", SqlDbType.NVarChar, devRoutingEntity.DeviceId);
                AddSqlParameter(ref cmd, "@p2", SqlDbType.NVarChar, devRoutingEntity.RoutingKeyword);
                AddSqlParameter(ref cmd, "@p3", SqlDbType.NVarChar, devRoutingEntity.TargetType);
                AddSqlParameter(ref cmd, "@p4", SqlDbType.NVarChar, devRoutingEntity.TargetDeviceGroupId);
                AddSqlParameter(ref cmd, "@p5", SqlDbType.NVarChar, devRoutingEntity.TargetDeviceId);
                AddSqlParameter(ref cmd, "@p6", SqlDbType.NVarChar, devRoutingEntity.Status);
                AddSqlParameter(ref cmd, "@p7", SqlDbType.NVarChar, devRoutingEntity.Description);
                AddSqlParameter(ref cmd, "@p8", SqlDbType.DateTime, devRoutingEntity.Registered_DateTime);
                cmd.ExecuteNonQuery();

                conn.Close();
            }
            catch (Exception ex)
            {
                conn.Close();
                throw ex;
            }
        }
Exemplo n.º 7
0
 private void validateTargetId(DeviceRoutingEntity devRoutingEntity)
 {
     if (devRoutingEntity.TargetType == CRoboticsConst.TypeDeviceGroup)
     {
         if (!existDeviceGroupId(devRoutingEntity.TargetDeviceGroupId))
         {
             ae = new ApplicationException("Input Device Group ID not exist in RBFX.DeviceGroup");
             throw ae;
         }
     }
     else if (devRoutingEntity.TargetType == CRoboticsConst.TypeDevice)
     {
         if (!existDeviceId(devRoutingEntity.TargetDeviceId))
         {
             ae = new ApplicationException("Input Device ID not exist in RBFX.DeviceMaster");
             throw ae;
         }
     }
     else
     {
         ae = new ApplicationException($"Input Target Type must be \"{CRoboticsConst.TypeDeviceGroup}\" or \"{CRoboticsConst.TypeDevice}\"");
         throw ae;
     }
 }
Exemplo n.º 8
0
        public List <DeviceRoutingEntity> GetDeviceRoutings(string deviceId)
        {
            deviceId = deviceId.Replace("*", "%");

            string sqltext = "SELECT DeviceId,RoutingKeyword,TargetType,TargetDeviceGroupId,TargetDeviceId,"
                             + "Status,Description,Registered_DateTime "
                             + "FROM RBFX.DeviceRouting "
                             + "WHERE DeviceId LIKE @p1 ORDER BY DeviceId,RoutingKeyword";

            List <DeviceRoutingEntity> listOfDeviceRoutings = new List <DeviceRoutingEntity>();

            SqlConnection conn = new SqlConnection(this.sqlConnectionString);

            try
            {
                conn.Open();

                SqlCommand cmd = new SqlCommand(sqltext, conn);
                AddSqlParameter(ref cmd, "@p1", SqlDbType.NVarChar, deviceId);
                SqlDataReader reader = cmd.ExecuteReader();

                if (!reader.HasRows)
                {
                    ae = new ApplicationException("No record was found in RBFX.DeviceRouting");
                    throw ae;
                }

                while (reader.Read())
                {
                    DeviceRoutingEntity devRoutingEntity = new DeviceRoutingEntity();
                    devRoutingEntity.DeviceId       = reader.GetString(0);
                    devRoutingEntity.RoutingKeyword = reader.GetString(1);
                    devRoutingEntity.TargetType     = reader.GetString(2);
                    if (!reader.IsDBNull(3))
                    {
                        devRoutingEntity.TargetDeviceGroupId = reader.GetString(3);
                    }
                    else
                    {
                        devRoutingEntity.TargetDeviceGroupId = string.Empty;
                    }

                    if (!reader.IsDBNull(4))
                    {
                        devRoutingEntity.TargetDeviceId = reader.GetString(4);
                    }
                    else
                    {
                        devRoutingEntity.TargetDeviceId = string.Empty;
                    }

                    devRoutingEntity.Status = reader.GetString(5);

                    if (!reader.IsDBNull(6))
                    {
                        devRoutingEntity.Description = reader.GetString(6);
                    }
                    else
                    {
                        devRoutingEntity.Description = string.Empty;
                    }

                    if (!reader.IsDBNull(7))
                    {
                        devRoutingEntity.Registered_DateTime = reader.GetDateTime(7);
                    }

                    listOfDeviceRoutings.Add(devRoutingEntity);
                }

                reader.Close();
                conn.Close();
            }
            catch (Exception ex)
            {
                if (ex.GetType().Equals(ae))
                {
                    conn.Close();
                }
                throw (ex);
            }

            return(listOfDeviceRoutings);
        }