Asked — Edited
Resolved Resolved by ptp!

Configuration Form When Creating A Plugin

I have went thru the tutorial for the plugin and have successfully created a basic plugin. Now I want to go the next step and create a plugin that has a configuration page that is accessed by clicking the gear icon but can not figure out how to do it.

The plugin I hope to create will allow the user to create a connection to a database using a DSN.

RichardZ

Update: One Step Closer - I found the UCConfigurationButton

Update2: Stumbled upon ptp's testplugin on github and creating a ConfigForm.cs using it as my example.


ARC Pro

Upgrade to ARC Pro

Your robot can be more than a simple automated machine with the power of ARC Pro!

PRO
USA
#9  

To solve my problem I have decided to go with just one command.


$X = DSNQuery("Query String", "DSN Name")


This command will open the DSN connection to the database, Send the query string and return it as an array to your variable and then close the DSN connection. This should make the process (and the programming) much simpler.

Well at least that is the new plan.

@plcdroid As for being your final project, it just might be, as the code I posted is not complete and does not work.

RichardZ

PRO
USA
#10  

@richard,

The plcdroid post is SPAM!

The user registed today and add a link to a website.

Soon will add (edit the post) more spam links.

PRO
USA
#11  

@ptp, I expected it was but figured it would not hurt to answer since I was posting anyway. but thanks for the confirmation.

PRO
USA
#12  

Did you hit any wall. Do you need help with your plugin?

PRO
USA
#13  

I think now that I am going with only a single command in the plugin, I can follow DJ's tutorial. I will let you know this evening when I rewrite the code. But not knowing C# and just using Google for find the code snippets there is a good chance I will need help so keep an eye on this thread. Thanks much, I will keep you posted on my progress.

PRO
USA
#14  

@ptp,

Does this look correct?


 private void FunctionEval_AdditionalFunctionEvent(object sender, ExpressionEvaluation.AdditionalFunctionEventArgs e)
        {

            // Check if the function is our function (DSNQuery)
            if (e.Name.Equals("DSNQuery", StringComparison.InvariantCultureIgnoreCase))
            {

                // Check if the correct number of parameters were passed to this function
                if (e.Parameters.Length != 2)
                    throw new Exception("Expects 2 parameters. Usage: DSNQuery(''QueryString'',''DSNname'' )");


                // Do something
                string myDSN = Convert.ToString(e.Parameters[1]);
                string myQuery = Convert.ToString(e.Parameters[0]);
                OdbcCommand cmd;
                OdbcConnection cn;
                cn = new OdbcConnection("dsn=" + myDSN);
                cn.Open();
                cmd = new OdbcCommand(myQuery, cn);
                e.ReturnValue = cmd;
                cn.Close();


            }
            
            
                
            }
            return;

        }

PRO
USA
#15  

@rz90208: You need more code.


e.ReturnValue = cmd;

You can't return a OdbcCommand.

In a few minutes I'll post some code.

PRO
Synthiam
#16  

I don't have visual studio in front of me but i think those might be Disposable objects, which means you can help the garbage collector by wrapping them in Using() statements like so...


private void FunctionEval_AdditionalFunctionEvent(object sender, ExpressionEvaluation.AdditionalFunctionEventArgs e)
        {

            // Check if the function is our function (DSNQuery)
            if (e.Name.Equals("DSNQuery", StringComparison.InvariantCultureIgnoreCase))
            {

                // Check if the correct number of parameters were passed to this function
                if (e.Parameters.Length != 2)
                    throw new Exception("Expects 2 parameters. Usage: DSNQuery(''QueryString'',''DSNname'')");

                // Do something
                string myDSN = Convert.ToString(e.Parameters[1]);
                string myQuery = Convert.ToString(e.Parameters[0]);

                using (var cn = new OdbcConnection("dsn=" + myDSN)) {

                  cn.Open();

                  using (var cmd = new OdbcCommand(myQuery, cn))
                    e.ReturnValue = cmd;

                  cn.Close();
                }


            }
            
            
                
            }
            return;

        }