コード例 #1
0
        /* If user has clicked the change button, do a couple of things
         * 1) First checks if user has selected anything
         * 2) Then verify if the user entered parameters conform to the parameter format
         *    of each parameter
         * 3) If there are no errors, run procedure to update the database
         * 4) Then, run a command to get the current sequence from database (after changes
         *    have been applied) and display it
         * */
        private void change_Click(object sender, EventArgs e)
        {
            //Get Selected index
            int currentIndex = listBox1.SelectedIndex;

            //Check if something is selected
            if (currentIndex == -1)
            {
                DialogResult confirmation = MessageBox.Show("Please Select a Step");
            }
            else
            {
                //Need to find out the object ID for the object name selected
                String columnIDObj = "ID";
                DataSet objectID = getObjID();

                //Need to find out the function ID for the function name selected
                String columnIDFunc = "ID";
                DataSet functionID = getFuncID();

                String tableName = "kex.macro_viewfunction";
                String columnNameFunc = "ID";
                String columnNameObj = "Object_ID";

                DataSet functionData = mySqlInterface.Query("SELECT * FROM " + tableName + " WHERE "
                                        + columnNameFunc + "='" + functionID.Tables[0].Rows[0][columnIDFunc].ToString() + "'" + "and " +
                                        columnNameObj + "='" + objectID.Tables[0].Rows[0][columnIDObj].ToString() + "'");

                //Get Data for the relevant function row
                DataRow functionRow = functionData.Tables[0].Rows[0];

                //Add a new entryData
                EntryData entryData = new EntryData();

                //Iterate over all parameters
                for (int i = 1; i < parameterFields.GetLength(0); i++)
                {
                    //Only if field is visible
                    if (parameterFields[i].Visible == true)
                    {
                        String curFormat = "para0" + i.ToString() + "_format";
                        String curminLim = "para0" + i.ToString() + "_minlimit";
                        String curmaxLim = "para0" + i.ToString() + "_maxlimit";

                        submit_ErrorChecking(functionRow[curFormat].ToString(), parameterFields[i].Text,
                            parameterTitles[i].Text, functionRow[curminLim].ToString(), functionRow[curmaxLim].ToString(), i);

                        if (userEntryError == false)
                        {
                            //Edit that particular entry in the entryData array
                            entryData.parameterVals[i] = parameterFields[i].Text;
                        }

                        //Reset userEntryError to check for the next parameter
                        userEntryError = false;
                    }
                }

                //No Errors
                if (userErrors == "")
                {
                    checkConnect();

                    //Get the sequence ID
                    String columnNameID = "ID";
                    String columnNameSeq = "name";
                    tableName = "kex.macro_viewsequence";
                    DataSet seqID = mySqlInterface.Query("SELECT " + columnNameID + " FROM " + tableName +
                                                            " WHERE " + columnNameSeq + "=" + "'" +
                                                            sqNames.Text + "'");

                    //Get the Channel ID
                    tableName = "kex.macro_viewchannel";
                    DataSet tableID = mySqlInterface.Query("SELECT " + columnNameID + " FROM " + tableName +
                                            " WHERE " + columnNameSeq + "=" + "'" +
                                            chNames.Text + "'");

                    //Need to find out the object ID for the object name selected
                    columnIDObj = "ID";
                    objectID = getObjID();

                    //Need to find out the function ID for the function name selected
                    columnIDFunc = "ID";
                    functionID = getFuncID();

                    //Run Procedure
                    mySqlInterface.runProcedure(
                        null,
                        "kex.macro_updateSequenceStep",
                        "sequence_ID_in", seqID.Tables[0].Rows[0][columnNameID],
                        "channel_ID_in", tableID.Tables[0].Rows[0][columnNameID],
                        "stepnumber_in", Convert.ToInt32(STEPNUM_CHANGE),
                        "function_ID_in", functionID.Tables[0].Rows[0][columnIDFunc],
                        "object_ID_in", objectID.Tables[0].Rows[0][columnIDObj],
                        "para01_in", entryData.parameterVals[1],
                        "para02_in", entryData.parameterVals[2],
                        "para03_in", entryData.parameterVals[3],
                        "para04_in", entryData.parameterVals[4],
                        "para05_in", entryData.parameterVals[5],
                        "para06_in", entryData.parameterVals[6],
                        "para07_in", entryData.parameterVals[7],
                        "para08_in", entryData.parameterVals[8],
                        "memo_in", "Insert Here");

                    tableName = "kex.macro_viewsequencestep";
                    columnNameSeq = "sequence_name";
                    String columnNameCh = "channel_name";

                    DataSet seqData = mySqlInterface.Query("SELECT * FROM " + tableName + " WHERE " +
                                 columnNameSeq + "=" + "'" + sqNames.Text + "'" + " and " +
                                 columnNameCh + "=" + "'" + chNames.Text + "'");

                    //Add entries to Array and display on screen
                    addtoArray(seqData);

                    //Refocus cursor
                    listBox1.SelectedIndex = currentIndex;
                }
                else
                {
                    //Show the errors user has
                    MessageBox.Show("You have errors in your input. Please see below: \n" + userErrors);
                }

                //Reset userErrors String
                userErrors = "";
            }
        }
コード例 #2
0
        //This shows the dataset onto the listbox
        private void addtoArray(DataSet seqData)
        {
            allEntries.Clear();

            String curID, curName, curValue = null;

            foreach (DataRow row in seqData.Tables[0].Rows)
            {
                EntryData newEntry = new EntryData();

                //20150518 By Bx.
                newEntry.backColor = Color.LightBlue;

                newEntry.IDnum = row["stepnumber"].ToString();

                for (int i = 1; i < parameterFields.GetLength(0); i++)
                {
                    curID = "para0" + i.ToString() + "_ID";
                    //An entry exists
                    if (row["function_name"].ToString() != "")
                    {
                        curName = "para0" + i.ToString() + "_name";
                        curValue = "para0" + i.ToString();

                        //Populate Text
                        newEntry.parameterVals[i] = row[curValue].ToString();

                        //Populate Name
                        newEntry.parameterNames[i] = row[curName].ToString();

                        //Populate Object
                        newEntry.objName = row["object_name"].ToString();

                        //Populate Function
                        newEntry.funcName = row["function_name"].ToString();
                    }
                }
                //Add Entry to Array
                allEntries.Add(newEntry);
            }

            //Refresh the ListBox
            listBox1.BeginUpdate();
            listBox1.Items.Clear();
            listBox1.Items.AddRange(allEntries.ToArray());
            listBox1.EndUpdate();
        }
コード例 #3
0
        /* submit_Click - runs if user has selected the Submit button
         * 1) Verify if the user entered parameters conform to the parameter format
         *    of each parameter
         * 3) If there are no errors, run procedure to add to the database
         * 4) Then, run a command to get the current sequence from database (after changes
         *    have been applied) and display it
         */
        private void submit_Click(object sender, EventArgs e)
        {
            //Check if it is connected
            checkConnect();

            //Need to find out the object ID for the object name selected
            String columnIDObj = "ID";
            DataSet objectID = getObjID();

            //Need to find out the function ID for the function name selected
            String columnIDFunc = "ID";
            DataSet functionID = getFuncID();

            String tableName = "kex.macro_viewfunction";
            String columnNameFunc = "ID";
            String columnNameObj = "Object_ID";

            DataSet functionData = mySqlInterface.Query("SELECT * FROM " + tableName + " WHERE "
                                    + columnNameFunc + "='" + functionID.Tables[0].Rows[0][columnIDFunc].ToString() + "'" + "and " +
                                    columnNameObj + "='" + objectID.Tables[0].Rows[0][columnIDObj].ToString() + "'");

            //Create new EntryData
            EntryData entryData = new EntryData();

            //Get Data for the relevant function row
            DataRow functionRow = functionData.Tables[0].Rows[0];

            //Iterate over all fields
            for (int i = 1; i < parameterFields.GetLength(0); i++)
            {
                //Only do bottom tests if it is visible
                if (parameterFields[i].Visible == true)
                {
                    String curFormat = "para0" + i.ToString() + "_format";
                    String curminLim = "para0" + i.ToString() + "_minlimit";
                    String curmaxLim = "para0" + i.ToString() + "_maxlimit";

                    submit_ErrorChecking(functionRow[curFormat].ToString(), parameterFields[i].Text,
                        parameterTitles[i].Text, functionRow[curminLim].ToString(), functionRow[curmaxLim].ToString(), i);

                    //All error checking done for para0# and can be added to EntryData
                    if (userEntryError == false)
                    {
                        //Populate Text
                        entryData.parameterVals[i] = parameterFields[i].Text;

                        //Populate Name
                        entryData.parameterNames[i] = parameterTitles[i].Text;

                        //Populate Object
                        entryData.objName = objNames.Text;

                        //Populate Function
                        entryData.funcName = funcNames.Text;
                    }

                    //Reset userEntryError to check for the next parameter
                    userEntryError = false;
                }
            }

            //No errors have occurred - thus the string for the errors is empty
            if (userErrors == "")
            {
                //Set the ID Number
                entryData.IDnum = (allEntries.Count + 1).ToString();

                checkConnect();

                //Get the sequence ID
                String columnNameID = "ID";
                DataSet seqID = getSeqID();

                //Get the Channel ID
                DataSet chID = getChID();

                //Need to find out the object ID for the object name selected
                columnIDObj = "ID";
                objectID = getObjID();

                //Need to find out the function ID for the function name selected
                columnIDFunc = "ID";
                functionID = getFuncID();

                mySqlInterface.runProcedure(
                    null,
                    "kex.macro_insertSequenceStep",
                    "sequence_ID_in", seqID.Tables[0].Rows[0][columnNameID],
                    "channel_ID_in", chID.Tables[0].Rows[0][columnNameID],
                    "stepnumber_in", -1,
                    "function_ID_in", functionID.Tables[0].Rows[0][columnIDFunc].ToString(),
                    "object_ID_in", objectID.Tables[0].Rows[0][columnIDObj].ToString(),
                    "para01_in", entryData.parameterVals[1],
                    "para02_in", entryData.parameterVals[2],
                    "para03_in", entryData.parameterVals[3],
                    "para04_in", entryData.parameterVals[4],
                    "para05_in", entryData.parameterVals[5],
                    "para06_in", entryData.parameterVals[6],
                    "para07_in", entryData.parameterVals[7],
                    "para08_in", entryData.parameterVals[8],
                    "memo_in", "Insert Here");

                tableName = "kex.macro_viewsequencestep";
                String columnNameSeq = "sequence_name";
                String columnNameCh = "channel_name";

                DataSet seqData = mySqlInterface.Query("SELECT * FROM " + tableName + " WHERE " +
                             columnNameSeq + "=" + "'" + sqNames.Text + "'" + " and " +
                             columnNameCh + "=" + "'" + chNames.Text + "'");

                //Add entries to Array and display on screen
                addtoArray(seqData);

                //Null out values so next time a user enters something, the old text is not there
                nullBoxes();

                //Move cursor
                listBox1.SelectedIndex = allEntries.Count - 1;
            }
            else
            {
                //Show the errors user has
                MessageBox.Show("You have errors in your input. Please see below: \n" + userErrors);
            }

            //Reset userErrors String
            userErrors = "";
        }
コード例 #4
0
        /*There are 2 reasons why you would be in this:
         * 1 - You have selected something to view the data
         * 2 - You want to insert data
           */
        private void listBox1_Click(object sender, EventArgs e)
        {
            if (!(listBox1.SelectedItem == null))
            {
                //You are in here for the purposes of changing something
                if (insertSelected == false)
                {
                    //Gets data in the entry selected
                    EntryData entryData = new EntryData();
                    entryData = listBox1.SelectedItem as EntryData;

                    //Store the IDnum to be used when user clicks the "Change" button
                    STEPNUM_CHANGE = entryData.IDnum;

                    //Change Object
                    objNames.Text = entryData.objName;

                    //Change Function
                    funcNames.Text = entryData.funcName;

                    //Show values selected
                    for (int i = 1; i < parameterFields.GetLength(0); i++)
                    {
                        if (parameterFields[i].Visible == true)
                        {
                            parameterFields[i].Text = entryData.parameterVals[i];
                        }
                    }
                }
                //You want to insert something
                else
                {
                    int selectedIndex = listBox1.SelectedIndex;

                    if (selectedIndex != -1)
                    {

                        //This is the data that the user enters
                        EntryData entryData = new EntryData();

                        //This is the position that the user has clicked - with this, we can get the
                        //Stepnumber of the point the user wants to insert at
                        EntryData chosenInsertPoint = new EntryData();
                        chosenInsertPoint = listBox1.SelectedItem as EntryData;

                        //Check if it is connected
                        checkConnect();

                        //Need to find out the object ID for the object name selected
                        String columnIDObj = "ID";
                        DataSet objectID = getObjID();

                        //Need to find out the function ID for the function name selected
                        String columnIDFunc = "ID";
                        DataSet functionID = getFuncID();

                        //Get the functionRow
                        String tableName = "kex.macro_viewfunction";
                        String columnNameFunc = "ID";
                        String columnNameObj = "Object_ID";
                        DataSet functionData = mySqlInterface.Query("SELECT * FROM " + tableName + " WHERE "
                                                + columnNameFunc + "='" + functionID.Tables[0].Rows[0][columnIDFunc] +
                                                "'" + "and " + columnNameObj + "='" + objectID.Tables[0].Rows[0][columnIDObj].ToString() + "'");

                        //Get Data for the relevant function row
                        DataRow functionRow = functionData.Tables[0].Rows[0];

                        for (int i = 1; i < parameterFields.GetLength(0); i++)
                        {
                            if (parameterFields[i].Visible == true)
                            {
                                /*   Error Checking   */
                                String curFormat = "para0" + i.ToString() + "_format";
                                String curminLim = "para0" + i.ToString() + "_minlimit";
                                String curmaxLim = "para0" + i.ToString() + "_maxlimit";

                                submit_ErrorChecking(functionRow[curFormat].ToString(), parameterFields[i].Text,
                                    parameterTitles[i].Text, functionRow[curminLim].ToString(), functionRow[curmaxLim].ToString(), i);

                                //All error checking done for para0# and can be added to EntryData
                                if (userEntryError == false)
                                {
                                    //Populate Text
                                    entryData.parameterVals[i] = parameterFields[i].Text;

                                    //Populate Name
                                    entryData.parameterNames[i] = parameterTitles[i].Text;
                                }

                                //Reset userEntryError to check for the next parameter
                                userEntryError = false;
                            }
                            //Populate Object
                            entryData.objName = objNames.Text;

                            //Populate Function
                            entryData.funcName = funcNames.Text;
                        }

                        //No errors have occurred - thus the string for the errors is empty
                        if (userErrors == "")
                        {
                            DialogResult confirmation = MessageBox.Show("Are you sure you want to insert at Step " + chosenInsertPoint.IDnum + "?",
                                "Confirmation", MessageBoxButtons.YesNo);

                            if (confirmation == System.Windows.Forms.DialogResult.Yes)
                            {
                                //get TopIndex to stop moving cursor
                                int tempTopIndex = listBox1.TopIndex;

                                checkConnect();

                                String columnNameID = "ID";
                                String columnNameSeq = "name";
                                tableName = "kex.macro_viewsequence";

                                DataSet seqID = mySqlInterface.Query("SELECT " + columnNameID + " FROM " + tableName +
                                                                        " WHERE " + columnNameSeq + "=" + "'" +
                                                                        sqNames.Text + "'");

                                tableName = "kex.macro_viewchannel";
                                DataSet tableID = mySqlInterface.Query("SELECT " + columnNameID + " FROM " + tableName +
                                                        " WHERE " + columnNameSeq + "=" + "'" +
                                                        chNames.Text + "'");

                                //Need to find out the object ID for the object name selected
                                columnIDObj = "ID";
                                objectID = getObjID();

                                //Need to find out the function ID for the function name selected
                                String columnIDFuncNew = "ID";
                                DataSet functionIDNew = getFuncID();

                                mySqlInterface.runProcedure(
                                    null,
                                    "kex.macro_insertSequenceStep",
                                    "sequence_ID_in", seqID.Tables[0].Rows[0][columnNameID],
                                    "channel_ID_in", tableID.Tables[0].Rows[0][columnNameID],
                                    "stepnumber_in", Convert.ToInt32(chosenInsertPoint.IDnum),
                                    "function_ID_in", functionID.Tables[0].Rows[0][columnIDFuncNew],
                                    "object_ID_in", objectID.Tables[0].Rows[0][columnIDObj],
                                    "para01_in", entryData.parameterVals[1],
                                    "para02_in", entryData.parameterVals[2],
                                    "para03_in", entryData.parameterVals[3],
                                    "para04_in", entryData.parameterVals[4],
                                    "para05_in", entryData.parameterVals[5],
                                    "para06_in", entryData.parameterVals[6],
                                    "para07_in", entryData.parameterVals[7],
                                    "para08_in", entryData.parameterVals[8],
                                    "memo_in", "Insert Here");

                                tableName = "kex.macro_viewsequencestep";
                                columnNameSeq = "sequence_name";
                                String columnNameCh = "channel_name";

                                DataSet seqData = mySqlInterface.Query("SELECT * FROM " + tableName + " WHERE " +
                                             columnNameSeq + "=" + "'" + sqNames.Text + "'" + " and " +
                                             columnNameCh + "=" + "'" + chNames.Text + "'");

                                //Add entries to Array and display on screen
                                addtoArray(seqData);

                                //Null out values so next time a user enters something, the old text is not there
                                nullBoxes();

                                //Move cursor - doesn't select but just moves the viewing area
                                listBox1.TopIndex = tempTopIndex;
                            }
                        }
                        else
                        {
                            //Show the errors user has
                            MessageBox.Show("You have errors in your input. Please see below: \n" + userErrors);
                        }

                        //Reset userErrors String
                        userErrors = "";

                        //InsertSelected back to false
                        insertSelected = false;

                        //Enable Fields
                        foreach (var combobox in parameterFields)
                        {
                            //if (textbox != null) textbox.ReadOnly = false;
                            if (combobox != null) combobox.Enabled = true;
                        }
                        objNames.Enabled = true;
                        funcNames.Enabled = true;
                        chNames.Enabled = true;
                        sqNames.Enabled = true;
                        msg_box.Text = "";
                    }
                    else
                    {
                        MessageBox.Show("Please select an entry to insert at.");

                        //Reset userErrors String
                        userErrors = "";

                        //InsertSelected back to false
                        insertSelected = false;

                        //Enable Fields
                        foreach (var combobox in parameterFields)
                        {
                            //if (textbox != null) textbox.ReadOnly = false;
                            if (combobox != null) combobox.Enabled = true;
                        }
                        objNames.Enabled = true;
                        funcNames.Enabled = true;
                        chNames.Enabled = true;
                        sqNames.Enabled = true;
                        msg_box.Text = "";
                    }
                }
            }
        }