Example #1
0
        /// <summary>
        /// Save the current function back out to the DB, this is an UPDATE
        /// function, not an add a new one to the database type function.
        /// </summary>
        /// <param name="ListViewPosition">Position of the function in the listview</param>
        private void SaveFunctionToDB(int ListViewPosition)
        {
            //
            // Get the DBCode first
            int             FunctionID = (int)lvFunctions.Items[ListViewPosition].Tag;
            OleDbConnection con        = GPDatabaseUtils.Connect();

            //
            // Build the command to update the various values
            string sSQL = "UPDATE tblFitnessFunction SET ";

            sSQL += "Name = '" + txtFunctionName.Text + "'";
            sSQL += ", Code = '" + txtSource.Text + "'";
            sSQL += ", Validated = False";

            sSQL += " WHERE DBCode = " + FunctionID;

            OleDbCommand cmd = new OleDbCommand(sSQL, con);

            //
            // Execute the command
            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (OleDbException ex)
            {
                string sError = ex.Message.ToString();
            }

            con.Close();
        }
        /// <summary>
        /// Add a new simulation to be performed.
        /// </summary>
        public void AddSimulation(GPProjectProfile Profile, int TrainingDataID, int ProjectID)
        {
            BatchProcess NewProcess = new BatchProcess(Profile, TrainingDataID, ProjectID);

            m_Queue.Add(NewProcess);

            //
            // Inform all clients a new process was just added
            foreach (KeyValuePair <IBatchClient, IBatchClient> Client in m_Clients)
            {
                Client.Value.AddProcess(
                    NewProcess,
                    GPDatabaseUtils.FieldValue(NewProcess.ProjectID, "tblProject", "Name"),
                    NewProcess.Profile.Name,
                    NewProcess.TimeAdded,
                    NewProcess.TimeStarted,
                    NewProcess.IsStarted);
            }

            //
            // Indicate to the thread a new model has been requested.  This is done by sending
            // a "Default" command.  What the effectively does is to make execing of simulations
            // the lowest priority event.  We want register client events to take priority
            // over exec simulations, so they start getting updated as soon as possible.
            m_CommandQueue.Enqueue(Command.Default);
            wh_CommandEvent.Set();
        }
Example #3
0
        //
        // Grab the main project settings
        private bool Load_tblProject(int ProjectID)
        {
            OleDbConnection con = GPDatabaseUtils.Connect();

            try
            {
                OleDbDataAdapter daTable = new OleDbDataAdapter("SELECT Name,Description,TrainingFileID FROM tblProject WHERE DBCode = " + ProjectID, con);
                DataSet          dSet    = new DataSet();
                daTable.Fill(dSet);

                //
                // "In Theory" there should be only one row - guaranteed :)
                foreach (DataRow row in dSet.Tables[0].Rows)
                {
                    this.Name           = row.ItemArray.GetValue(0).ToString();
                    this.DataTrainingID = Convert.ToInt32(row.ItemArray.GetValue(2).ToString());
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                con.Close();
            }

            return(true);
        }
Example #4
0
        //
        // Loads the list of Training files already imported into the database.  Loads
        // only the list of files with the matching input dimension.
        private void InitializeFileList(int InputDimension)
        {
            OleDbConnection con = GPDatabaseUtils.Connect();

            String sSQL = "SELECT DBCode,Name,Description FROM tblModelingFile";

            if (InputDimension > 0)
            {
                sSQL += " WHERE InputCount = " + InputDimension;
            }

            OleDbDataAdapter daFiles = new OleDbDataAdapter(sSQL, con);
            DataSet          dSet    = new DataSet();

            daFiles.Fill(dSet);

            foreach (DataRow row in dSet.Tables[0].Rows)
            {
                ListViewItem lvItem = lvFiles.Items.Add(row.ItemArray.GetValue(1).ToString());
                lvItem.ToolTipText = row.ItemArray.GetValue(2).ToString();
                lvItem.Tag         = row.ItemArray.GetValue(0);
                lvItem.Group       = lvFiles.Groups[0];
            }

            con.Close();
        }
Example #5
0
        //
        // A static method available to delete a project entry
        public static bool DeleteProject(int ProjectID)
        {
            //
            // Open the database connection
            OleDbConnection con = GPDatabaseUtils.Connect();

            String sSQL = "DELETE FROM tblProject WHERE DBCode = " + ProjectID;

            OleDbCommand cmd = new OleDbCommand("Delete Project", con);

            cmd.CommandText = sSQL;
            cmd.CommandType = CommandType.Text;
            //
            // Execute the command
            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (OleDbException)
            {
                return(false);
            }

            con.Close();

            return(true);
        }
Example #6
0
        /// <summary>
        /// Remove the indicated Training set from the database
        /// </summary>
        /// <param name="ModelingFileID">DBCode of the Training set to delete</param>
        /// <returns>True/False upon success or failure</returns>
        public static bool DeleteData(int ModelingFileID)
        {
            //
            // Get the DB connection
            using (OleDbConnection DBConnection = GPDatabaseUtils.Connect())
            {
                String sSQL = "DELETE FROM tblModelingFile WHERE DBCode = " + ModelingFileID;

                OleDbCommand cmd = new OleDbCommand("Delete File", DBConnection);
                cmd.CommandText = sSQL;
                cmd.CommandType = CommandType.Text;
                //
                // Execute the command
                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (OleDbException)
                {
                    return(false);
                }
            }

            return(true);
        }
Example #7
0
        /// <summary>
        /// Removes the selected profile from the database
        /// </summary>
        /// <param name="ProfileID">DBCode of the profile to remove</param>
        /// <returns>True/False upon success or failure</returns>
        public bool DeleteProfile(int ProfileID)
        {
            //
            // Open the database connection
            OleDbConnection con = GPDatabaseUtils.Connect();

            String sSQL = "DELETE FROM tblProjectProfiles WHERE ProjectID = " + this.DBCode;

            sSQL += " AND ModelProfileID = " + ProfileID;

            OleDbCommand cmd = new OleDbCommand("Delete Profile", con);

            cmd.CommandText = sSQL;
            cmd.CommandType = CommandType.Text;
            //
            // Execute the command
            try
            {
                cmd.ExecuteNonQuery();
                //
                // Remove the entry from the list of profiles
                m_ModelProfiles.Remove(ProfileID);
            }
            catch (OleDbException)
            {
                return(false);
            }

            con.Close();

            return(true);
        }
Example #8
0
        /// <summary>
        /// Updates the database entry of this function to be validated or not
        /// validated according to the Validated parameter.
        /// </summary>
        /// <param name="FunctionID">DBCode of the function</param>
        /// <param name="Validated">Validation state of the function</param>
        private void SetValidation(int FunctionID, bool Validated)
        {
            OleDbConnection con = GPDatabaseUtils.Connect();

            //
            // Build the command to update the various values
            string sSQL = "UPDATE tblFunctionSet SET ";

            sSQL += "Validated = " + Validated.ToString();
            sSQL += " WHERE DBCode = " + FunctionID;

            OleDbCommand cmd = new OleDbCommand(sSQL, con);

            //
            // Execute the command
            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (OleDbException ex)
            {
                string sError = ex.Message.ToString();
            }

            con.Close();
        }
Example #9
0
        //
        // Handles the details of seeing if a profile is already defined for
        // the project, if not, it is added.
        private void AddProjectProfile(int ProfileID)
        {
            OleDbConnection con = GPDatabaseUtils.Connect();

            //
            // Check to see if the profile is already defined
            OleDbCommand cmd = new OleDbCommand("Find Profile", con);

            cmd.CommandText = "SELECT DBCode FROM tblProjectProfiles WHERE ModelProfileID = " + ProfileID + " AND ProjectID = " + this.DBCode;
            cmd.CommandType = CommandType.Text;

            OleDbDataReader reader = cmd.ExecuteReader();

            if (!reader.HasRows)
            {
                cmd.Dispose();
                //
                // Add the profile
                String sSQL = "INSERT INTO tblProjectProfiles(ProjectID,ModelProfileID) ";
                sSQL += "VALUES ('" + this.DBCode + "',";
                sSQL += "'" + ProfileID + "')";

                cmd             = new OleDbCommand("Add Profile", con);
                cmd.CommandText = sSQL;
                cmd.CommandType = CommandType.Text;
                cmd.ExecuteNonQuery();
            }

            con.Close();
        }
Example #10
0
        /// <summary>
        /// Checks to see if this file is in use by a project
        /// </summary>
        /// <param name="ModelingFileID">DBCode of the file to check out</param>
        /// <returns>True/False depending upon if the file is being used</returns>
        public static bool FileInUse(int ModelingFileID)
        {
            using (OleDbConnection con = GPDatabaseUtils.Connect())
            {
                //
                // Start by checking the project table
                string sSQL = "SELECT DBCode FROM tblProject ";
                sSQL += "WHERE TrainingFileID = " + ModelingFileID;
                OleDbCommand    cmd = new OleDbCommand(sSQL, con);
                OleDbDataReader rdr = cmd.ExecuteReader();
                if (rdr.HasRows)
                {
                    return(true);
                }

                //
                // Next, check the training file table
                sSQL = "SELECT DBCode FROM tblValidationFiles WHERE ModelingFileID = " + ModelingFileID;
                cmd  = new OleDbCommand(sSQL, con);
                rdr  = cmd.ExecuteReader();
                if (rdr.HasRows)
                {
                    return(true);
                }
            }

            //
            // Not found, so return false
            return(false);
        }
Example #11
0
        /// <summary>
        /// Loads the list of function categories available for selection
        /// </summary>
        private void InitializeCategories()
        {
            //
            // Clear any previous categories
            cbCategory.Items.Clear();

            //
            // Build the query
            using (OleDbConnection con = GPDatabaseUtils.Connect())
            {
                String           SQL          = "SELECT DBCode,Name FROM tblFunctionCategory ORDER BY Name";
                OleDbDataAdapter daCategories = new OleDbDataAdapter(SQL, con);
                DataSet          dSet         = new DataSet();
                daCategories.Fill(dSet);

                foreach (DataRow row in dSet.Tables[0].Rows)
                {
                    String Name       = row.ItemArray.GetValue(1).ToString();
                    int    CategoryID = Convert.ToInt32(row.ItemArray.GetValue(0).ToString());

                    //
                    // Add it to the UI
                    cbCategory.Items.Add(row.ItemArray.GetValue(1).ToString());
                    //
                    // Maintain a list of categories and their associated DBCodes
                    m_FunctionCategory[Name] = CategoryID;
                }
            }
        }
Example #12
0
        /// <summary>
        /// Given the DBCode, Load and display that function
        /// </summary>
        /// <param name="FunctionID">DBCode of the function to load</param>
        /// <returns>True if this is a master function, False otherwise</returns>
        private bool DisplayFunction(long FunctionID)
        {
            bool IsMasterFunction = false;

            using (OleDbConnection con = GPDatabaseUtils.Connect())
            {
                String SQL = "SELECT tblFunctionSet.Name,tblFunctionSet.Description";
                SQL += ",tblFunctionSet.Arity,tblFunctionSet.Code,tblFunctionSet.MasterLock,";
                SQL += "tblFunctionSet.Validated,tblFunctionCategory.Name,tblFunctionSet.TerminalParameters ";
                SQL += "FROM tblFunctionSet ";
                SQL += "INNER JOIN tblFunctionCategory ON tblFunctionSet.CategoryID = tblFunctionCategory.DBCode  ";
                SQL += "WHERE tblFunctionSet.DBCode = " + FunctionID;

                OleDbDataAdapter daFiles = new OleDbDataAdapter(SQL, con);
                DataSet          dSet    = new DataSet();
                daFiles.Fill(dSet);

                //
                // There better be a single row! :)
                DataRow row = dSet.Tables[0].Rows[0];
                txtFunctionName.Text          = row.ItemArray.GetValue(0).ToString();
                udParamterCount.Value         = Convert.ToDecimal(row.ItemArray.GetValue(2).ToString());
                txtSource.Text                = row.ItemArray.GetValue(3).ToString();
                txtDescription.Text           = row.ItemArray.GetValue(1).ToString();
                IsMasterFunction              = Convert.ToBoolean(row.ItemArray.GetValue(4).ToString());
                chkValidated.Checked          = Convert.ToBoolean(row.ItemArray.GetValue(5).ToString());
                cbCategory.SelectedIndex      = cbCategory.Items.IndexOf(row.ItemArray.GetValue(6).ToString());
                chkTerminalParameters.Checked = Convert.ToBoolean(row.ItemArray.GetValue(7).ToString());
            }

            return(IsMasterFunction);
        }
Example #13
0
        private void btnDataValidationAdd_Click(object sender, EventArgs e)
        {
            //
            // Bring up the modeling Training selection dialog box; only allow files
            // that match the training file input count.
            int InputDimension       = Convert.ToInt32(GPDatabaseUtils.FieldValue(m_Project.DataTrainingID, "tblModelingFile", "InputCount"));
            fmSelectModelingFile dlg = new fmSelectModelingFile(InputDimension);

            if (dlg.ShowDialog(this) == DialogResult.OK)
            {
                //
                // Add the selection to the project
                if (dlg.lvFiles.SelectedItems.Count > 0)
                {
                    ListViewItem  lvSelected = dlg.lvFiles.Items[dlg.lvFiles.SelectedItems[0].Index];
                    ComboDataItem cbItem     = new ComboDataItem(lvSelected.Text, Convert.ToInt32(lvSelected.Tag.ToString()));
                    cbDataValidation.Items.Add(cbItem);
                    //
                    // Add it to the results page also
                    cbResultsDataSet.Items.Add(cbItem);

                    //
                    // Select this item
                    cbDataValidation.SelectedIndex = cbDataValidation.Items.Count - 1;

                    //
                    // Add it to the project and Save
                    m_Project.DataValidation.Add(Convert.ToInt32(lvSelected.Tag.ToString()));
                    m_Project.Save();
                }
            }
        }
Example #14
0
        /// <summary>
        /// Given the DBCode, Load and display that function
        /// </summary>
        /// <param name="FunctionID">DBCode of the function to load</param>
        /// <returns>True if this is a master function, False otherwise</returns>
        private bool DisplayFunction(int FunctionID)
        {
            bool IsMasterFunction = false;

            using (OleDbConnection con = GPDatabaseUtils.Connect())
            {
                String SQL = "SELECT Name,Code,MasterLock,Validated FROM tblFitnessFunction ";
                SQL += "WHERE DBCode = " + FunctionID;

                OleDbDataAdapter daFiles = new OleDbDataAdapter(SQL, con);
                DataSet          dSet    = new DataSet();
                daFiles.Fill(dSet);

                //
                // There better be a single row! :)
                DataRow row = dSet.Tables[0].Rows[0];
                txtFunctionName.Text = row.ItemArray.GetValue(0).ToString();
                txtSource.Text       = row.ItemArray.GetValue(1).ToString();
                IsMasterFunction     = Convert.ToBoolean(row.ItemArray.GetValue(2).ToString());
                chkValidated.Checked = Convert.ToBoolean(row.ItemArray.GetValue(3).ToString());
                //
                // Also need to see if it is in use
                chkInUse.Checked = IsFunctionInUse(FunctionID);
            }

            return(IsMasterFunction);
        }
Example #15
0
        /// <summary>
        /// Prepare the list of validated functions that can be selected
        /// </summary>
        private void InitializeFunctionSet()
        {
            using (OleDbConnection con = GPDatabaseUtils.Connect())
            {
                //
                // Select only functions from the C# list
                String SQL = "SELECT tblFunctionSet.DBCode,tblFunctionSet.Name";
                SQL += ",tblFunctionSet.Arity,tblFunctionSet.Description";
                SQL += ",tblFunctionCategory.Name ";
                SQL += "FROM tblFunctionSet ";
                SQL += "INNER JOIN tblFunctionCategory ON tblFunctionSet.CategoryID = tblFunctionCategory.DBCode  ";
                SQL += "WHERE tblFunctionSet.FunctionLanguageID = 3 ";
                SQL += "AND tblFunctionSet.Validated = TRUE ";
                SQL += "ORDER BY tblFunctionCategory.Name,tblFunctionSet.Name";

                OleDbCommand    cmd = new OleDbCommand(SQL, con);
                OleDbDataReader rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    ListViewItem lvItem = lvFunctions.Items.Add(rdr["tblFunctionSet.Name"].ToString());
                    lvItem.SubItems.Add(((short)rdr["Arity"]).ToString());
                    lvItem.SubItems.Add(rdr["Description"].ToString());
                    lvItem.SubItems.Add(rdr["tblFunctionCategory.Name"].ToString());

                    lvItem.ToolTipText = rdr["Description"].ToString();
                    lvItem.Tag         = Convert.ToInt32(rdr["DBCode"]);
                }
            }
        }
Example #16
0
        /// <summary>
        /// Prepare the list of validated fitness functions that can be
        /// chosen from.
        /// </summary>
        private void InitializeFitnessFunctions()
        {
            OleDbConnection con = GPDatabaseUtils.Connect();

            {
                String SQL = "SELECT DBCode,Name FROM tblFitnessFunction ";
                SQL += "WHERE Validated = TRUE ";
                SQL += "ORDER BY Name";

                OleDbDataAdapter daFunctions = new OleDbDataAdapter(SQL, con);
                DataSet          dSet        = new DataSet();
                daFunctions.Fill(dSet);

                foreach (DataRow row in dSet.Tables[0].Rows)
                {
                    RadioButton btnItem = new RadioButton();
                    btnItem.Text   = row.ItemArray.GetValue(1).ToString();
                    btnItem.Tag    = row.ItemArray.GetValue(0);
                    btnItem.Click += FitnessRadioButton_Click;

                    btnItem.Parent = flowFitnessFunctions;
                }
            }
            con.Close();
        }
Example #17
0
        /// <summary>
        /// Load the fitness settings from the XML document
        /// </summary>
        /// <param name="xmlRoot">Element the the settings are contained within</param>
        /// <returns>True/False upon success or failure</returns>
        private bool LoadFitnessOptions(XmlElement xmlRoot)
        {
            try
            {
                //
                // Fitness function is actually stored in the database
                FitnessFunctionID = Convert.ToInt32(GPDatabaseUtils.FieldValue(this.ProfileID, "tblModelProfile", "FitnessFunctionID"));

                //
                // SPEA2 Multi-Objective setting.  Placed in a try-catch block because legacy profiles will
                // not have this setting, so we need a default setting of false to be set.
                XmlNode xmlNode = xmlRoot.SelectSingleNode(PROFILE_FILE_SPEA2MULTIOBJECTIVE);
                try
                {
                    this.ModelingProfile.SPEA2MultiObjective = Convert.ToBoolean(xmlNode.InnerText);
                }
                catch
                {
                    this.ModelingProfile.SPEA2MultiObjective = false;
                }

                //
                // Adaptive parsimony setting
                xmlNode = xmlRoot.SelectSingleNode(PROFILE_FILE_ADAPTIVEPARSIMONY);
                this.ModelingProfile.AdaptiveParsimony = Convert.ToBoolean(xmlNode.InnerText);
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }
Example #18
0
        /// <summary>
        /// Grab the function specs from the database
        /// </summary>
        /// <param name="Name"></param>
        /// <param name="Arity"></param>
        /// <param name="Code"></param>
        /// <param name="LanguageID"></param>
        /// <returns></returns>
        public static bool LoadFunctionFromDB(String Name, ref short Arity, ref bool TerminalParameters, ref String Code, int LanguageID)
        {
            OleDbConnection con = GPDatabaseUtils.Connect();

            try
            {
                String           SQL     = "SELECT Arity,TerminalParameters,Code FROM tblFunctionSet WHERE Name = '" + Name + "' AND FunctionLanguageID = " + LanguageID;
                OleDbDataAdapter daFiles = new OleDbDataAdapter(SQL, con);
                DataSet          dSet    = new DataSet();
                daFiles.Fill(dSet);

                //
                // There better be a single row! :)
                Arity = Convert.ToInt16(dSet.Tables[0].Rows[0].ItemArray.GetValue(0).ToString());
                TerminalParameters = Convert.ToBoolean(dSet.Tables[0].Rows[0].ItemArray.GetValue(1).ToString());
                Code = dSet.Tables[0].Rows[0].ItemArray.GetValue(2).ToString();
            }
            catch (Exception)
            {
                return(false);
            }
            finally
            {
                con.Close();
            }

            return(true);
        }
Example #19
0
        private void btnNew_Click(object sender, EventArgs e)
        {
            //
            // Create a blank entry in the database for a new function
            OleDbConnection con = GPDatabaseUtils.Connect();

            //
            // Build the command to insert a new record in the DB
            String sSQL = "INSERT INTO tblFunctionSet(Name,Description,Arity,TerminalParameters,Code,FunctionLanguageID,CategoryID) ";
            //
            // Get the language ID
            String FunctionLanguageID = (String)tsMainLanguage.Tag;

            sSQL = sSQL + "VALUES ('New_Function','Function Description',1,false,''," + FunctionLanguageID + "," + m_FunctionCategory["Other"] + ")";

            OleDbCommand cmd = new OleDbCommand(sSQL, con);

            //
            // Execute the command
            try
            {
                cmd.ExecuteNonQuery();
                //
                // Grab the DBCode generated for this file
                cmd.CommandText = "SELECT @@IDENTITY";
                OleDbDataReader reader = cmd.ExecuteReader();
                reader.Read();
                int FunctionID = Convert.ToInt32(reader[0].ToString());;
                reader.Close();

                //
                // Add the new item to the list of functions and get it
                // displayed
                ListViewItem item = lvFunctions.Items.Add("New_Function");
                item.Tag      = FunctionID;
                item.Group    = lvFunctions.Groups[0];
                item.Selected = true;
            }
            catch (OleDbException ex)
            {
                string sError = ex.Message.ToString();
            }

            con.Close();

            if (!this.ProgramUpdating)
            {
                FunctionDirty = true;
            }

            //
            // Place the focus on the function name text box so the user
            // can start typing the name in without doing anything else.
            txtFunctionName.Focus();
        }
Example #20
0
        /// <summary>
        /// Creates an entry for this profile in the database
        /// </summary>
        /// <param name="ModelProfileID">DBCode of the newly created profile</param>
        /// <returns>True/False upon success or failure</returns>
        public bool CreateProfileInDB(ref int ModelProfileID)
        {
            //
            // Save the profile to a memory stream and then pull out the bytes
            byte[] blobData = null;
            using (MemoryStream ms = new MemoryStream())
            {
                this.Save(ms);

                blobData = new byte[ms.Length];
                ms.Seek(0, SeekOrigin.Begin);
                ms.Read(blobData, 0, (int)ms.Length);
            }

            OleDbParameter param = new OleDbParameter(
                "@Profile",
                OleDbType.VarBinary,
                blobData.Length,
                ParameterDirection.Input,
                false,
                0, 0, null,
                DataRowVersion.Current, blobData);

            OleDbConnection con = GPDatabaseUtils.Connect();

            //
            // Build the command to add the blob to the database
            OleDbCommand cmd = new OleDbCommand("INSERT INTO tblModelProfile(Name,Profile) VALUES ('New Profile',?)", con);

            cmd.Parameters.Add(param);

            //
            // Execute the command
            try
            {
                cmd.ExecuteNonQuery();
                //
                // Grab the DBCode generated for this file
                cmd.CommandText = "SELECT @@IDENTITY";
                OleDbDataReader reader = cmd.ExecuteReader();
                reader.Read();
                this.ProfileID = Convert.ToInt32(reader[0].ToString());;
                ModelProfileID = this.ProfileID;
                reader.Close();
            }
            catch (OleDbException ex)
            {
                string sError = ex.Message.ToString();
                return(false);
            }

            con.Close();

            return(true);
        }
Example #21
0
        private void tsMainAdd_Click(object sender, EventArgs e)
        {
            //
            // Create a blank entry in the database for a new function
            OleDbConnection con = GPDatabaseUtils.Connect();

            //
            // Build the command to insert a new record in the DB
            String SQL = "INSERT INTO tblFitnessFunction(Name,Code) ";

            SQL += "VALUES ('New_Function','-- Source Code Goes Here ---')";

            OleDbCommand cmd = new OleDbCommand(SQL, con);

            //
            // Execute the command
            try
            {
                cmd.ExecuteNonQuery();
                //
                // Grab the DBCode generated for this file
                cmd.CommandText = "SELECT @@IDENTITY";
                OleDbDataReader reader = cmd.ExecuteReader();
                reader.Read();
                int FunctionID = Convert.ToInt32(reader[0].ToString());;
                reader.Close();

                //
                // Add the new item to the list of functions and get it
                // displayed
                ListViewItem item = lvFunctions.Items.Add("New_Function");
                item.Tag      = FunctionID;
                item.Group    = lvFunctions.Groups[0];
                item.Selected = true;
            }
            catch (OleDbException ex)
            {
                string sError = ex.Message.ToString();
            }

            con.Close();

            if (!this.ProgramUpdating)
            {
                FunctionDirty = true;
            }

            //
            // Place the focus on the function name text box so the user
            // can start typing the name in without doing anything else.
            txtFunctionName.Focus();
        }
Example #22
0
        //
        // Update the list of validation files.  Just wipe out whatever was there
        // previously and rewrite the values.
        private bool Update_tblValidationFiles()
        {
            //
            // Open the database connection
            OleDbConnection con = GPDatabaseUtils.Connect();

            String sSQL = "DELETE FROM tblValidationFiles WHERE ProjectID = " + this.DBCode;

            OleDbCommand cmd = new OleDbCommand("Delete Files", con);

            cmd.CommandText = sSQL;
            cmd.CommandType = CommandType.Text;
            //
            // Execute the command
            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (OleDbException)
            {
                return(false);
            }

            //
            // Add everything back into the database
            foreach (int FileID in this.DataValidation)
            {
                sSQL  = "INSERT INTO tblValidationFiles(ProjectID,ModelingFileID) ";
                sSQL += "VALUES ('" + this.DBCode + "',";
                sSQL += "'" + FileID + "')";

                cmd             = new OleDbCommand("Add Validation File", con);
                cmd.CommandText = sSQL;
                cmd.CommandType = CommandType.Text;

                //
                // Execute the command
                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (OleDbException ex)
                {
                    string sError = ex.Message.ToString();
                    return(false);
                }
            }

            con.Close();

            return(true);
        }
Example #23
0
        /// <summary>
        /// Updates an existing profile in the database with the current specifications
        /// </summary>
        /// <returns>True/False upon success or failure</returns>
        public bool UpdateProfileInDB()
        {
            //
            // Save the profile to a memory stream and then pull out the bytes
            byte[] blobData = null;
            using (MemoryStream ms = new MemoryStream())
            {
                this.Save(ms);

                blobData = new byte[ms.Length];
                ms.Seek(0, SeekOrigin.Begin);
                ms.Read(blobData, 0, (int)ms.Length);
            }

            OleDbParameter param = new OleDbParameter(
                "@Profile",
                OleDbType.VarBinary,
                blobData.Length,
                ParameterDirection.Input,
                false,
                0, 0, null,
                DataRowVersion.Current, blobData);

            OleDbConnection con = GPDatabaseUtils.Connect();

            //
            // Execute the command
            try
            {
                //
                // Build the command to clear the blob in the database
                OleDbCommand cmd = new OleDbCommand("UPDATE tblModelProfile SET Profile = NULL WHERE DBCode = " + this.ProfileID, con);
                cmd.ExecuteNonQuery();

                //
                // Build the command to replace the blob in the database
                cmd = new OleDbCommand("UPDATE tblModelProfile SET Profile = ? WHERE DBCode = " + this.ProfileID, con);
                cmd.Parameters.Add(param);
                cmd.ExecuteNonQuery();
            }
            catch (OleDbException ex)
            {
                string sError = ex.Message.ToString();
                return(false);
            }

            con.Close();

            return(true);
        }
Example #24
0
        /// <summary>
        /// Update the project settings to tblProject
        /// </summary>
        private void Update_tblProject()
        {
            OleDbConnection con = GPDatabaseUtils.Connect();

            OleDbCommand cmd = new OleDbCommand("UPDATE tblProject SET Name = '" + this.Name + "' WHERE DBCode = " + this.DBCode, con);

            cmd.ExecuteNonQuery();

            if (this.DataTrainingID != 0)
            {
                cmd = new OleDbCommand("UPDATE tblProject SET TrainingFileID = " + this.DataTrainingID + " WHERE DBCode = " + this.DBCode, con);
                cmd.ExecuteNonQuery();
            }

            con.Close();
        }
Example #25
0
        /// <summary>
        /// Prepares the fitness graph for use
        /// </summary>
        private void InitializeFitnessGraph()
        {
            //
            // Decide on a title
            String Y1Title = "Fitness";

            //
            // The try-catch block is to handle the initialization case with no modeling
            // profile yet defined.
            if (m_ModelProfile != null)
            {
                Y1Title = "Fitness Error : " + GPDatabaseUtils.FieldValue(m_ModelProfile.FitnessFunctionID, "tblFitnessFunction", "Name");
            }

            ZedGraph.GraphPane pane = new ZedGraph.GraphPane(
                new Rectangle(0, 0, graphFitness.Width, graphFitness.Height),
                "Best Program Fitness",
                "Generation",
                Y1Title);

            graphFitness.GraphPane = pane;

            //
            // Need a second Y-Axis for the hit counts
            graphFitness.GraphPane.AddY2Axis("# Hits");
            graphFitness.GraphPane.Y2Axis.Title.Text = "# Hits";
            graphFitness.GraphPane.Y2Axis.IsVisible  = true;

            graphFitness.GraphPane.YAxis.Title.FontSpec.FontColor  = Color.Blue;
            graphFitness.GraphPane.YAxis.Scale.FontSpec.FontColor  = Color.Blue;
            graphFitness.GraphPane.Y2Axis.Title.FontSpec.FontColor = Color.Maroon;
            graphFitness.GraphPane.Y2Axis.Scale.FontSpec.FontColor = Color.Maroon;

            graphFitness.GraphPane.Fill       = new ZedGraph.Fill(Color.AliceBlue, Color.WhiteSmoke, 0F);
            graphFitness.GraphPane.Chart.Fill = new ZedGraph.Fill(Color.Silver, Color.White, 45.0f);

            //
            // Prepare the plotting curve
            m_ptListFitness = new ZedGraph.PointPairList();
            m_ptListHits    = new ZedGraph.PointPairList();
            ZedGraph.CurveItem CurveFitness = graphFitness.GraphPane.AddCurve("Fitness", m_ptListFitness, Color.Blue);
            ZedGraph.CurveItem CurveHits    = graphFitness.GraphPane.AddCurve("Hits", m_ptListHits, Color.Maroon);
            CurveHits.IsY2Axis = true;

            ((ZedGraph.LineItem)CurveFitness).Symbol.Size = 4;
            ((ZedGraph.LineItem)CurveHits).Symbol.Size    = 4;
        }
Example #26
0
        /// <summary>
        /// Checks to see if this fitness function is in use.
        /// </summary>
        /// <param name="FunctionID">DBCode of the function to test</param>
        /// <returns>True if it is in use, False otherwise</returns>
        private bool IsFunctionInUse(int FunctionID)
        {
            using (OleDbConnection con = GPDatabaseUtils.Connect())
            {
                string sSQL = "SELECT DBCode FROM tblModelProfile ";
                sSQL += "WHERE FitnessFunctionID = " + FunctionID;
                OleDbDataAdapter daFiles = new OleDbDataAdapter(sSQL, con);
                DataSet          dSet    = new DataSet();
                daFiles.Fill(dSet);

                if (dSet.Tables[0].Rows.Count > 0)
                {
                    return(true);
                }

                return(false);
            }
        }
Example #27
0
 /// <summary>
 /// Loads the list of data files imported into the database into the
 /// left side listview display.
 /// </summary>
 private void InitializeFileList()
 {
     //
     // Get the DB connection
     using (OleDbConnection DBConnection = GPDatabaseUtils.Connect())
     {
         OleDbCommand    cmd = new OleDbCommand("SELECT DBCode,Name,Description FROM tblModelingFile;", DBConnection);
         OleDbDataReader rdr = cmd.ExecuteReader();
         while (rdr.Read())
         {
             ListViewItem lvItem = lvFiles.Items.Add(rdr["Name"].ToString());
             lvItem.Group       = lvFiles.Groups[0];
             lvItem.ImageIndex  = 0;
             lvItem.ToolTipText = rdr["Description"].ToString();
             lvItem.Tag         = Convert.ToInt32(rdr["DBCode"]);
         }
     }
 }
Example #28
0
        /// <summary>
        /// Load the list of functions into the listview, select from the
        /// indicated language.
        /// </summary>
        /// <param name="FunctionLanguageID">Which language to load from</param>
        private void InitializeFunctionSet(String FunctionLanguageID)
        {
            this.ProgramUpdating = true;

            //
            // If an item is selected, unselect it.  This causes the form
            // to revert to an initial disabled state
            if (lvFunctions.SelectedItems.Count > 0)
            {
                lvFunctions.SelectedItems[0].Selected = false;
            }

            //
            // Clear any previous functions
            lvFunctions.Items.Clear();

            //
            // Get the next set queried up!
            OleDbConnection con = GPDatabaseUtils.Connect();

            String           sSQL    = "SELECT DBCode,Name FROM tblFunctionSet WHERE FunctionLanguageID = " + FunctionLanguageID + " ORDER BY Name";
            OleDbDataAdapter daFiles = new OleDbDataAdapter(sSQL, con);
            DataSet          dSet    = new DataSet();

            daFiles.Fill(dSet);

            foreach (DataRow row in dSet.Tables[0].Rows)
            {
                ListViewItem lvItem = lvFunctions.Items.Add(row.ItemArray.GetValue(1).ToString());
                lvItem.Group = lvFunctions.Groups[0];
                lvItem.Tag   = row.ItemArray.GetValue(0);
            }

            //
            // Autoselect the first one (if any)
            if (lvFunctions.Items.Count > 0)
            {
                lvFunctions.Items[0].Selected = true;
            }

            con.Close();

            this.ProgramUpdating = false;
        }
Example #29
0
        //
        // Loads the list of Training files already imported into the database
        private void InitializeProjectList()
        {
            OleDbConnection con = GPDatabaseUtils.Connect();

            OleDbDataAdapter daFiles = new OleDbDataAdapter("SELECT DBCode,Name,Description FROM tblProject", con);
            DataSet          dSet    = new DataSet();

            daFiles.Fill(dSet);

            foreach (DataRow row in dSet.Tables[0].Rows)
            {
                ListViewItem lvItem = lvProjects.Items.Add(row.ItemArray.GetValue(1).ToString());
                lvItem.ToolTipText = row.ItemArray.GetValue(2).ToString();
                lvItem.Tag         = row.ItemArray.GetValue(0);
                lvItem.ImageIndex  = 0;
            }

            con.Close();
        }
Example #30
0
        /// <summary>
        /// Updates an integer (ID) value for the specified table, field and record.
        /// This is a somewhat common task, so a function was made to do it.  This
        /// should not be used for a high-frequency situation.
        /// </summary>
        /// <param name="DBCode">DBCode of the record to update</param>
        /// <param name="Table">Table to update</param>
        /// <param name="Field">Field to update</param>
        /// <param name="Value">New string value</param>
        /// <returns>True/False upon success or failure</returns>
        public static bool UpdateField(int DBCode, String Table, String Field, String Value)
        {
            using (OleDbConnection con = GPDatabaseUtils.Connect())
            {
                String SQL = "UPDATE " + Table + " SET " + Field + " = \"" + Value + "\" WHERE DBCode = " + DBCode;

                OleDbCommand cmd = new OleDbCommand(SQL, con);

                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (OleDbException)
                {
                    return(false);
                }
            }

            return(true);
        }