public void setCOMBO() { objectLIST objList = null; // Get the selected item. objList = (objectLIST)objCOMBO.Items[objCOMBO.SelectedIndex]; }
private void createButton_Click(object sender, EventArgs e) { ADODB.Connection adoConn = new ADODB.Connection(); string strdsn = null; string sqlstring2 = null; string sqlstring3 = null; string sqlstring4 = null; string objtocreate = null; objtocreate = ""; string objtype = null; string devaddress = null; string lastdevaddress = null; //string wherestring = null; //wherestring = ""; int iocount = 0; iocount = 0; int evtlcount = 0; evtlcount = 0; int i = 0; i = 0; string evtltext = null; evtltext = ""; string createinstance = null; createinstance = ""; int j = 0; j = 1; string refobj = null; refobj = ""; string refname = null; refname = ""; int loopval = 0; loopval = 0; int numobjcreated = 0; numobjcreated = 0; int logintervalval = 0; logintervalval = 0; int bufferSize = 0; bufferSize = 2688; int startTime = 0; startTime = 0; string algval = null; algval = ""; string lowlimitval = null; lowlimitval = ""; string hilimitval = ""; bool analogevflag = false; analogevflag = false; int counter = 0; counter = 0; string monobjref = null; monobjref = ""; ListView evtlList = default(ListView); Label objectlabel = default(Label); objectLIST objrefval = default(objectLIST); string refdev = null; string iptrefobjtype = null; int ipref = 0; ipref = 0; string[,] newobjectlist = new string[101, 3]; string instance = null; try { //--------------------------------------------------------------------------------------------------------------------- //initialize boxes and labels newevtlVIEW.Items.Clear(); bufferSize = Convert.ToInt32(txtSamples.Text); newevtlVIEW.Visible = true; oldevtlVIEW.Visible = false; ProgressBar1.Value = 0; //--------------------------------------------------------------------------------------------------------------------- //set up ODBC DSN text strdsn = dsnTEXTBOX.Text; if (string.IsNullOrEmpty(strdsn)) { strdsn = "Delta Network"; } //--------------------------------------------------------------------------------------------------------------------- //connect to the ODBC DSN adoConn = new ADODB.Connection(); adoConn.ConnectionString = "DSN=" + strdsn + ";"; adoConn.Open(); //--------------------------------------------------------------------------------------------------------------------- //build up SQL Strings for generating existing object list objrefval = (objectLIST)objCOMBO.Items[objCOMBO.SelectedIndex]; objtype = objrefval.Name; iptrefobjtype = Convert.ToString(objrefval.ItemData); devaddress = devTEXTBOX.Text; lastdevaddress = lastdevTEXT.Text; if (rangeCHECK.Checked == true) { //wherestring = "DEV_ID >= " + devaddress + " AND DEV_ID <= " + lastdevaddress; } else { //wherestring = "DEV_ID = " + devaddress; } //count i/o objects iocount = Convert.ToInt32(totalrefLABEL.Text); //--------------------------------------------------------------------------------------------------------------------- //check whether user wants to create EV or TL objects if (eventRAD.Checked) { objtocreate = "EV"; trendRAD.Checked = false; } else if (trendRAD.Checked) { objtocreate = "TL"; eventRAD.Checked = false; } evtlList = oldevtlVIEW; objectlabel = totobjsLABEL; //--------------------------------------------------------------------------------------------------------------------- //build object creation string based on selected object typue - EV or TL if (objtocreate == "EV") { //determine whether to create a COS or OOR EV if (objCOMBO.Text == "BV" | objCOMBO.Text == "BI" | objCOMBO.Text == "BO" | objCOMBO.Text == "MI" | objCOMBO.Text == "MV" | objCOMBO.Text == "SCH") { algval = "COS"; //evtltext = "EV (ParametersType, DEV_ID, Instance, Name, InputRef) Values('" & algval & "', " & devaddress & ", " evtltext = "EV (ParametersType, DEV_ID, Instance, Name, InputRef) Values('" + algval + "'"; analogevflag = false; } else { algval = "Out of Range"; evtltext = "EV (ParametersType, DEV_ID, Instance, Name, InputRef, ParametersOutofRangeLowlimit, ParametersOutofRangeHiLimit) Values('" + algval + "'"; analogevflag = true; } } else if (objtocreate == "TL") { //determine whether to create a COV or Polling Trend Log if (objCOMBO.Text == "MV" | objCOMBO.Text == "BV" | objCOMBO.Text == "BI" | objCOMBO.Text == "BO" | objCOMBO.Text == "SCH") { logintervalval = 0; } else { logintervalval = Convert.ToInt32(sampleInterval.Text); } // evtltext = "TL (LogInterval, DEV_ID, Instance, Name, InputRef) Values(" & logintervalval & ", " & devaddress & ", " evtltext = "TL (LogInterval, BufferSize, DEV_ID, Instance, Name, InputRef) Values(" + logintervalval; analogevflag = false; } string objectProperty = "value"; if (objCOMBO.Text == "PI") { objectProperty = "TotalPulses"; } //--------------------------------------------------------------------------------------------------------------------- //loop to generate insert sql script that will create the objects - also calls the create object subroutine if (iocount > 0) { ProgressBar1.Increment(1); loopval = (srcobjVIEW.SelectedItems.Count - 1); //get the number of selected items in the reference object ListView. "-1" used because listview index starts at 0 newobjLABEL.Visible = true; oldobjLABEL.Visible = false; //loop through the reference object listview to grab the obj ref and obj name for (i = 0; i <= loopval; i++) { ProgressBar1.Increment(+1); refobj = srcobjVIEW.SelectedItems[i].Text; refname = srcobjVIEW.SelectedItems[i].SubItems[1].Text; refdev = chkIsRemote.Checked? devTEXTBOX.Text: srcobjVIEW.SelectedItems[i].SubItems[3].Text; instance = srcobjVIEW.SelectedItems[i].SubItems[4].Text; //If AV is being logged, use the same instance ID if ((objCOMBO.Text == "AV" & objtocreate == "TL" & chkmatchAVInstance.Checked)) { createinstance = instance; } else { sqlstring2 = "SELECT Instance, Name, InputRef FROM OBJECT_BAC_" + objtocreate + " " + " WHERE " + "DEV_ID = " + refdev; createinstance = Convert.ToString(queryTLEV(ref adoConn, sqlstring2) + 1); } //If we're looking at a remote device, set the refobj to the remote device if (chkIsRemote.Checked) { //refdev = devTEXTBOX.Text; } //special condition to set up EV parameters for out of range EV objects if (analogevflag == true) { lowlimitval = (Double.Parse(srcobjVIEW.SelectedItems[i].SubItems[2].Text) - 5).ToString(); hilimitval = (Double.Parse(srcobjVIEW.SelectedItems[i].SubItems[2].Text) + 5).ToString(); sqlstring3 = "INSERT INTO OBJECT_BAC_" + evtltext + ", " + refdev + ", " + createinstance + ", " + "'" + refname + " " + objtocreate + createinstance + "', " + "'" + refobj + ".value', " + lowlimitval + ", " + hilimitval + ")"; } else { if ((objtocreate == "TL")) { sqlstring3 = "INSERT INTO OBJECT_BAC_" + evtltext + ", " + bufferSize + " , " + refdev + ", " + createinstance + ", " + "'" + refname + " " + objtocreate + "', " + "'" + refobj + "." + objectProperty + "')"; } else { sqlstring3 = "INSERT INTO OBJECT_BAC_" + evtltext + " , " + refdev + ", " + createinstance + ", " + "'" + refname + " Alarm" + "', " + "'" + refobj + ".value')"; } } TextBox1.Text = sqlstring3; //write to a hidden text field for debugging sqlstring4 = "SELECT ObjRef, Name, InputRef FROM OBJECT_BAC_" + objtocreate + " " + " WHERE " + "DEV_ID = " + refdev + " AND Instance = " + createinstance; ipref = tstobjref(ref oldevtlVIEW, refobj); if (ipref == 0) { createOBJs(ref adoConn, sqlstring3); //call the create object subroutine newobjectlist = newobjquery(ref adoConn, sqlstring4); newevtlVIEW.Items.Add(newobjectlist[0, 0]); newevtlVIEW.Items[j - 1].SubItems.Add(newobjectlist[0, 1]); newevtlVIEW.Items[j - 1].SubItems.Add(newobjectlist[0, 2]); j = j + 1; } } ProgressBar1.Value = 100; numobjcreated = (j - 1); totobjsLABEL.Text = numobjcreated.ToString(); createdobjLABEL.Text = numobjcreated + " " + objtocreate + " objects created"; //---------old code---------- //If srcobjVIEW.SelectedItems.Count() > 0 Then 'only run the TL query if objects were created // evtlList = newevtlVIEW // sqlstring3 = "Select ObjRef, Name, InputRef, DEV_ID FROM Object_BAC_" & objtocreate & " Where " & wherestring & " AND InputRefObjectType = " & iptrefobjtype // objectlabel = totobjsLABEL // runOBJQUERY(adoConn, sqlstring3, evtlList, objectlabel) //indnewitems(newevtlVIEW, newobjectlist, numobjcreated) //Else //MessageBox.Show("No Objects Created - Please select an object reference from the list", "No Items Selected") //End If //--------------------------- //present message to the user if no items were created/selected if (srcobjVIEW.SelectedItems.Count <= 0) { MessageBox.Show("No Objects Created - Please select an object reference from the list", "No Items Selected"); } srcobjVIEW.SelectedItems.Clear(); } else { refobj = ""; refname = ""; } //--------------------------------------------------------------------------------------------------------------------- //disable the Create Object button until the network is queried again createBUTTON.Enabled = false; //--------------------------------------------------------------------------------------------------------------------- //close the result set and ODBC connection adoConn.Close(); adoConn = null; return; } catch (Exception exception) { MessageBox.Show("Data Error Detected. Please ensure that you have enter a valid object reference, valid Device Address and correct ODBC DSN", "ODBC Reference Error"); dsnTEXTBOX.Text = "Delta Network"; adoConn.Close(); adoConn = null; ProgressBar1.Value = 0; } //======================================================= //Service provided by Telerik (www.telerik.com) //Conversion powered by NRefactory. //Twitter: @telerik //Facebook: facebook.com/telerik //======================================================= }
private void getButton_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(devTEXTBOX.Text)) { MessageBox.Show("Please enter a device instance"); return; } ADODB.Connection adoConn = new ADODB.Connection(); string strdsn = null; string sqlstring1 = null; string sqlstring2 = null; string objtocreate = null; objtocreate = ""; string objtype = null; string devaddress = null; string lastdevaddress = null; string wherestring = null; wherestring = ""; int iocount = 0; iocount = 0; ListView querylist = default(ListView); ListView createlist = default(ListView); Label objectlabel = default(Label); string iptrefobjtype = null; iptrefobjtype = ""; objectLIST objrefval = default(objectLIST); try { //--------------------------------------------------------------------------------------------------------------------- //initialization srcobjVIEW.Items.Clear(); newevtlVIEW.Items.Clear(); totalrefLABEL.Text = "0"; oldevtlVIEW.Items.Clear(); srcobjVIEW.MultiSelect = true; newevtlVIEW.Visible = false; oldevtlVIEW.Visible = true; newobjLABEL.Visible = false; oldobjLABEL.Visible = true; ProgressBar1.Value = 0; clearresults(); //--------------------------------------------------------------------------------------------------------------------- //enable progress bar when button is clicked ProgressBar1.Visible = true; //--------------------------------------------------------------------------------------------------------------------- //set up ODBC DSN text strdsn = dsnTEXTBOX.Text; if (string.IsNullOrEmpty(strdsn)) { strdsn = "Delta Network"; } //--------------------------------------------------------------------------------------------------------------------- //connect to the ODBC DSN adoConn = new ADODB.Connection(); adoConn.ConnectionString = "DSN=" + strdsn + ";"; adoConn.Open(); //--------------------------------------------------------------------------------------------------------------------- //check whether user wants to create EV or TL objects if (eventRAD.Checked) { objtocreate = "EV"; trendRAD.Checked = false; } else if (trendRAD.Checked) { objtocreate = "TL"; eventRAD.Checked = false; } //--------------------------------------------------------------------------------------------------------------------- //build up SQL Strings for generating existing object list objrefval = (objectLIST)objCOMBO.Items[objCOMBO.SelectedIndex]; objtype = objrefval.Name; iptrefobjtype = Convert.ToString(objrefval.ItemData); if (chkIsRemote.Checked) { devaddress = txtRemoteDevice.Text; } else { devaddress = devTEXTBOX.Text; } lastdevaddress = lastdevTEXT.Text; if (rangeCHECK.Checked == true) { wherestring = "DEV_ID >= " + devaddress + " AND DEV_ID <= " + lastdevaddress; } else { wherestring = "DEV_ID = " + devaddress; } if (objtype == "PI") { sqlstring1 = "SELECT ObjRef, Name, TotalPulses, DEV_ID, instance FROM OBJECT_BAC_" + objtype + " WHERE" + " " + wherestring; } else { sqlstring1 = "SELECT ObjRef, Name, Value, DEV_ID, instance FROM OBJECT_BAC_" + objtype + " WHERE" + " " + wherestring; } sqlstring2 = "SELECT ObjRef, Name, inputref, DEV_ID, instance From OBJECT_BAC_" + objtocreate + " WHERE" + " " + wherestring + " AND InputRefObjectType = " + iptrefobjtype; //--------------------------------------------------------------------------------------------------------------------- //set up the listview object to dump the object result set querylist = srcobjVIEW; createlist = oldevtlVIEW; //--------------------------------------------------------------------------------------------------------------------- //call subroutine to execute SQL that returns all reference objects and existing TL/EV objects objectlabel = totobjsLABEL; runOBJQUERY(ref adoConn, sqlstring2, createlist, objectlabel); //grab existing TL/EV objects objectlabel = totalrefLABEL; runOBJQUERY(ref adoConn, sqlstring1, querylist, objectlabel); //grab reference objects //--------------------------------------------------------------------------------------------------------------------- //close the result set and ODBC connection adoConn.Close(); adoConn = null; return; } catch (Exception ex) { MessageBox.Show("Data Error Detected. Please ensure that you have entered a valid object reference, valid Device Address and correct ODBC DSN", "ODBC Reference Error"); dsnTEXTBOX.Text = "Delta Network"; adoConn.Close(); adoConn = null; ProgressBar1.Value = 0; } //======================================================= //Service provided by Telerik (www.telerik.com) //Conversion powered by NRefactory. //Twitter: @telerik //Facebook: facebook.com/telerik //======================================================= }