Example #1
0
        /// <summary>Update Type with ID to values in instance oType</summary>
        /// <param name="lID">The ID of the Type to update</param>
        /// <param name="oType">An instance to use to update the Type</param>
        /// <returns>True if update was succeeded, false otherwise</returns>
        public bool putType(Models.Type oType)
        {
            try
            {
                MySqlDataReader oMySQLReader = null;
                String          sSql         = "SELECT * FROM type WHERE TYPE_ID = " + oType.ID.ToString() + ";";
                MySqlCommand    oCmd         = new MySqlCommand(sSql, gConn);
                oMySQLReader = oCmd.ExecuteReader();
                if (oMySQLReader.Read())
                {
                    oMySQLReader.Close();

                    sSql = @"UPDATE type 
                                    SET TYPE_NAME = " + oType.Name + ","
                           + " TYPE_DESCRIPTION = " + oType.Description + ","
                           + " TYPE_PARENT = " + oType.Parent.ToString() + ","
                           + " TYPE_MODIFIED = NOW(),"
                           + " TYPE_DELETED = " + (oType.Deleted == null ? "null" : "'" + oType.Deleted.ToString("yyyy-MM-dd HH:mm:ss")) + "'"
                           + " WHERE TYPE_ID = " + oType.ID.ToString() + ";";

                    oCmd = new MySqlCommand(sSql, gConn);
                    oCmd.ExecuteNonQuery();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                //EventLogger.Log(String.Format("{0}::{1} - {2}", mClassName, "putType", ex));
            }
            return(false);
        }
Example #2
0
 /// <summary>Check property type of iOrdinal property in oType and retrieve value from oMySQLReader if not null</summary>
 /// <param name="oMySQLReader">The reader to get the property value from</param>
 /// <param name="oType">The instance in which to set the property</param>
 /// <param name="iOrdinal">The position of the property in the instance</param>
 /// <param name="oProperty">The property info object</param>
 private void FillTypeProperty(MySqlDataReader oMySQLReader, ref Models.Type oType, int iOrdinal, PropertyInfo oProperty)
 {
     try
     {
         if (!oMySQLReader.IsDBNull(iOrdinal))
         {
             if (oProperty.PropertyType == typeof(long))
             {
                 oProperty.SetValue(oType, oMySQLReader.GetInt32(iOrdinal)); return;
             }
             if (oProperty.PropertyType == typeof(decimal))
             {
                 oProperty.SetValue(oType, oMySQLReader.GetDecimal(iOrdinal)); return;
             }
             if (oProperty.PropertyType == typeof(DateTime))
             {
                 oProperty.SetValue(oType, oMySQLReader.GetDateTime(iOrdinal)); return;
             }
             if (oProperty.PropertyType == typeof(string))
             {
                 oProperty.SetValue(oType, oMySQLReader.GetString(iOrdinal)); return;
             }
         }
     }
     catch (Exception ex)
     {
         //EventLogger.Log(String.Format("{0}::{1} - {2}", mClassName, "FillTypeProperty", ex));
     }
 }
Example #3
0
        /// <summary>Save Type instance to database</summary>
        /// <param name="oType">The Type to save</param>
        /// <returns>The ID that the new Type was given</returns>
        public long saveType(Models.Type oType)
        {
            try
            {
                String sSql = @"INSERT INTO type
                            (TYPE_NAME,
                            TYPE_DESCRIPTION,
                            TYPE_PARENT,
                            TYPE_CREATED,
                            TYPE_MODIFIED)
                            VALUES
                            ('" + oType.Name + "', '"
                              + oType.Description + "', "
                              + oType.Parent + ", '"
                              + oType.Created.ToString("yyyy-MM-dd HH:mm:ss") + "', '"
                              + oType.Modified.ToString("yyyy-MM-dd HH:mm:ss") + "');";

                MySqlCommand oCmd = new MySqlCommand(sSql, gConn);
                oCmd.ExecuteNonQuery();
                return(oCmd.LastInsertedId);
            }
            catch (Exception ex)
            {
                //EventLogger.Log(String.Format("{0}::{1} - {2}", mClassName, "saveType", ex));
            }
            return(-1);
        }
Example #4
0
 /// <summary>Create a new Type instance using the values in the MySqlDataReader</summary>
 /// <param name="oMySQLReader">The reader to get the new Type values from</param>
 /// <returns>A new Type</returns>
 private Models.Type CreateType(MySqlDataReader oMySQLReader)
 {
     Models.Type oType = new Models.Type();
     try
     {
         int            iPropCount  = 0;
         PropertyInfo[] oProperties = typeof(Models.Type).GetProperties();
         foreach (PropertyInfo oProperty in oProperties)
         {
             FillTypeProperty(oMySQLReader, ref oType, iPropCount++, oProperty);
         }
     }
     catch (Exception ex)
     {
         //EventLogger.Log(String.Format("{0}::{1} - {2}", mClassName, "CreateType", ex));
     }
     return(oType);
 }
Example #5
0
 /// <summary>Get Type with given ID</summary>
 /// <param name="lID">The id of the Type to fetch</param>
 /// <returns>The Type if found, an empty instance otherwise</returns>
 public Models.Type getType(long lID)
 {
     Models.Type oType = new Models.Type();
     try
     {
         MySqlDataReader oMySQLReader = null;
         String          sSql         = "SELECT * FROM type WHERE TYPE_ID = " + lID.ToString() + ";";
         MySqlCommand    oCmd         = new MySqlCommand(sSql, gConn);
         oMySQLReader = oCmd.ExecuteReader();
         if (oMySQLReader.Read())
         {
             oType = CreateType(oMySQLReader);
         }
     }
     catch (Exception ex)
     {
         //EventLogger.Log(String.Format("{0}::{1} - {2}", mClassName, "getType", ex));
     }
     return(oType);
 }
Example #6
0
        /// <summary>Get components in range of component with given ID</summary>
        /// <param name="lID">The id of the Pilot or Drone to get the components in range for</param>
        /// <returns>The components in range if found, an empty ArrayList otherwise</returns>
        public ArrayList getComponentsInRange(long lID)
        {
            //EventLogger.Log(String.Format("{0}::{1} - {2}", mClassName, "getComponentsInRange", String.Format("Calling for ID: {0}", lID)));

            ArrayList       oCompArray   = new ArrayList();
            MySqlDataReader oMySQLReader = null;

            try
            {
                ComponentPersistence oCP = new ComponentPersistence();
                oCompArray = oCP.getComponent(lID);
                if (oCompArray.Count == 1)
                {
                    Component   oComp = (Component)oCompArray[0];
                    Models.Type oType = new Models.Type();
                    if (oComp.Type == 2)
                    {
                        // For a Pilot, skip adding its Drone
                        oType.ID = 3;
                    }
                    else if (oComp.Type == 3)
                    {
                        // For a Drone, skip adding its Pilot
                        oType.ID = 2;
                    }
                    String       sSql = "select_components_in_range;";
                    MySqlCommand oCmd = new MySqlCommand(sSql, DBSupport.Conn);
                    oCmd.CommandType = System.Data.CommandType.StoredProcedure;
                    oCmd.Parameters.AddWithValue("iLon", oComp.Lon);
                    oCmd.Parameters["iLon"].Direction = System.Data.ParameterDirection.Input;
                    oCmd.Parameters.AddWithValue("iLat", oComp.Lat);
                    oCmd.Parameters["iLat"].Direction = System.Data.ParameterDirection.Input;
                    oCmd.Parameters.AddWithValue("iOffset", 1); // Properties.Settings.Default.CIROffset);
                    oCmd.Parameters["iOffset"].Direction = System.Data.ParameterDirection.Input;
                    // Clear array
                    oCompArray   = new ArrayList();
                    oMySQLReader = oCmd.ExecuteReader();
                    while (oMySQLReader.Read())
                    {
                        // Skip adding this Pilot/Drone and its Drone/Pilot (making it easier to process result client-side)
                        oComp = oCP.CreateComponent(oMySQLReader);
                        if (oComp.ID != lID && (oComp.Parent != lID || (oType.ID > 0 && oComp.Type != oType.ID)))
                        {
                            oCompArray.Add(oComp);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //EventLogger.Log(String.Format("{0}::{1} - {2}", mClassName, "getComponentsInRange", ex));
            }
            finally
            {
                if (oMySQLReader != null && !oMySQLReader.IsClosed)
                {
                    oMySQLReader.Close();
                }
                oMySQLReader = null;
            }
            return(oCompArray);
        }