Subversion Repository Public Repository

ConnectionOdbcSdk

Diff Revisions 4 vs 8 for /trunk/ConnectionServer/ConnectionServerOdbc.cs

Diff revisions: vs.
  @@ -26,7 +26,6 @@
26 26 LoginFailed = 2,
27 27 Connected = 3
28 28 }
29 -
30 29
31 30 /// <summary>
32 31 /// Set of properties and methods for connecting to and getting version information from a remote Unity Connection server.
  @@ -142,7 +141,7 @@
142 141 /// <summary>
143 142 /// default TUI language installed
144 143 /// </summary>
145 - private int _defaultLanguage;
144 + private int _defaultLanguage = -1;
146 145
147 146 public override string ToString()
148 147 {
  @@ -210,11 +209,14 @@
210 209 // dispose managed resources
211 210 try
212 211 {
213 -
212 + if (DatabaseFunctions != null)
213 + {
214 + DatabaseFunctions.Disconnect();
215 + }
214 216 }
215 - catch
217 + catch (Exception ex)
216 218 {
217 - //just eat the error here
219 + RaiseErrorEvent("error disposing ConnectionServer class:"+ex);
218 220 }
219 221 }
220 222 }
  @@ -256,6 +258,8 @@
256 258 /// </param>
257 259 internal void RaiseErrorEvent(string pLine)
258 260 {
261 + DatabaseLastError = pLine;
262 +
259 263 //notify registered clients
260 264 LoggingEventHandler handler = ErrorEvents;
261 265
  @@ -297,13 +301,14 @@
297 301 /// </summary>
298 302 private void FillLocationProperties()
299 303 {
304 + RaiseDebugEvent("[DEBUG] entering FillLocationProperties on ConnectionServerOdbc.cs");
305 +
300 306 DataTable oTableLocations;
301 307
302 308 //there should only ever be one row returned from this query - if not we have a problem
303 309 DbFetchResult ret = DatabaseFunctions.FillDataTableBlocking("SELECT * FROM vw_LocalVMS", out oTableLocations);
304 310 if (ret.Successful == false)
305 311 {
306 - if (Debugger.IsAttached) Debugger.Break();
307 312 RaiseErrorEvent("(error) fetching location properties in FillLocationProperties on ConnectionServerOdbc.cs:" + ret.ErrorDetails);
308 313 }
309 314
  @@ -321,12 +326,12 @@
321 326 if (!IsConnectionVersionAtLeast(9, 5, 0, 0))
322 327 {
323 328 //this is a pre 9.5 installation, all network nodes are "meshed" together - everyone is a neighbor of everyone else
324 - DatabaseFunctions.FillDataTableBlocking("Select ObjectId FROM vw_Location WHERE ObjectId <> ? ",
329 + ret =DatabaseFunctions.FillDataTableBlocking("Select ObjectId FROM vw_Location WHERE ObjectId <> ? ",
325 330 out oTableLocations, false, PrimaryLocationObjectId);
326 - //fail silently here
327 - if (oTableLocations == null)
331 +
332 + if (!ret.Successful | oTableLocations == null)
328 333 {
329 - if (Debugger.IsAttached) Debugger.Break();
334 + RaiseErrorEvent("Null table locations returned in FillLocationProperties:" + ret);
330 335 return;
331 336 }
332 337
  @@ -338,14 +343,13 @@
338 343 else
339 344 {
340 345 //Post 9.5 we may be in an HTTP network where there is a hierarchy of nodes
341 - DatabaseFunctions.FillDataTableBlocking(
346 + ret = DatabaseFunctions.FillDataTableBlocking(
342 347 "Select ObjectId FROM vw_NetworkTopology WHERE ObjectId <> NeighbourLocationObjectId " +
343 348 "AND NeighbourLocationObjectId = ?", out oTableLocations, false, PrimaryLocationObjectId);
344 349
345 - //fail silently here
346 - if (oTableLocations == null)
350 + if (!ret.Successful | oTableLocations == null)
347 351 {
348 - if (Debugger.IsAttached) Debugger.Break();
352 + RaiseErrorEvent("Null table locations returned in FillLocationProperties:"+ret);
349 353 return;
350 354 }
351 355
  @@ -420,6 +424,7 @@
420 424 /// </summary>
421 425 public void LogoutBlocking()
422 426 {
427 + RaiseDebugEvent("[DEBUG] entering LogoutBlocking on ConnectionServerOdbc.cs");
423 428 DatabaseConnectionStatus = ConnectionStatus.OffLine;
424 429 DatabaseFunctions.Disconnect();
425 430 }
  @@ -451,6 +456,8 @@
451 456 /// </returns>
452 457 public DbFetchResult LoginDatabaseBlocking(string pLoginName, string pPassword, string pServerName, string pProxyLoginName = "", string pProxyPassword = "")
453 458 {
459 + RaiseDebugEvent("[DEBUG] entering LoginDatabaseBlocking on ConnectionServerOdbc.cs");
460 +
454 461 DatabaseLoginName = pLoginName;
455 462 DatabaseLoginPassword = pPassword;
456 463 DatabaseServerName = pServerName;
  @@ -466,6 +473,8 @@
466 473 {
467 474 res.ErrorDetails=string.Format("Unable to resolve address via DNS: {0} - make sure the host name/IP address is correct and that your DNS " +
468 475 "configuration is functioning correclty:{1}",pServerName,ex.Message);
476 +
477 + RaiseErrorEvent(res.ErrorDetails);
469 478 res.Successful = false;
470 479 }
471 480
  @@ -478,7 +487,6 @@
478 487
479 488 //update the grid to show connected status
480 489 DatabaseConnectionStatus = ConnectionStatus.Connected;
481 - DatabaseLastError = "";
482 490
483 491 //get version information for the server we've attached to
484 492 InitVersionInfo();
  @@ -495,11 +503,8 @@
495 503 /// </summary>
496 504 private void InitVersionInfo()
497 505 {
498 - DbFetchResult ret;
499 - string strTemp;
500 - string[] strVersion;
501 - int iTemp;
502 - string strEs;
506 + RaiseDebugEvent("[DEBUG] entering InitVersionInfo on ConnectionServerOdbc.cs");
507 +
503 508 DataTable dtTemp;
504 509
505 510 //init everything to 0s
  @@ -518,7 +523,7 @@
518 523 }
519 524
520 525 //first check if this is a co-res install
521 - strTemp = DatabaseFunctions.GetConfigurationString("System.SystemSetup.PlatformConfiguration.deployment");
526 + string strTemp = DatabaseFunctions.GetConfigurationString("System.SystemSetup.PlatformConfiguration.deployment");
522 527 if (strTemp.Length > 0)
523 528 {
524 529 if (strTemp.CompareTo("coresident") == 0)
  @@ -528,7 +533,7 @@
528 533 }
529 534
530 535 //now fetch the version string from the schema information
531 - ret = DatabaseFunctions.FillDataTableBlocking("SELECT * FROM vw_Schemainformation WHERE IsCurrent=1", out dtTemp);
536 + DbFetchResult ret = DatabaseFunctions.FillDataTableBlocking("SELECT * FROM vw_Schemainformation WHERE IsCurrent=1", out dtTemp);
532 537 if (ret.Successful == false)
533 538 {
534 539 RaiseErrorEvent("Unable to pull SchemaInformation data in InitVersionInfo - cannot fetch version.");
  @@ -552,7 +557,7 @@
552 557 return;
553 558 }
554 559
555 - strVersion = strTemp.Split('.'.ToString().ToCharArray());
560 + string[] strVersion = strTemp.Split('.'.ToString().ToCharArray());
556 561
557 562 //it must contain at least 3 parts seperated by periods
558 563 if ((strVersion.Length - 1) != 3)
  @@ -586,9 +591,9 @@
586 591 if (strVersion[3].Contains("ES"))
587 592 {
588 593 //trim off the "ES" portion and drop the rest into the ES string for display purposes
589 - iTemp = strVersion[3].IndexOf("ES", 0);
594 + int iTemp = strVersion[3].IndexOf("ES", 0);
590 595
591 - strEs = strVersion[3].Substring(iTemp + 2);
596 + string strEs = strVersion[3].Substring(iTemp + 2);
592 597 _unityVersion.Es = strEs;
593 598
594 599 //the ES will not always be a number but if it is, store it in the EsInt field for comparison purposes
  @@ -660,10 +665,11 @@
660 665 /// </returns>
661 666 public bool ChangeActiveDatabase(string pNewDbName)
662 667 {
668 + RaiseDebugEvent("[DEBUG] entering ChangeActiveDatabase on ConnectionServerOdbc.cs");
669 +
663 670 //validate the name
664 671 if (string.IsNullOrEmpty(pNewDbName))
665 672 {
666 - if (Debugger.IsAttached) Debugger.Break();
667 673 RaiseErrorEvent("(error) Empty database name passed to ChangeActiveDatabase in clsConnectionServer");
668 674 DatabaseConnectionStatus = ConnectionStatus.LoginFailed;
669 675
  @@ -691,8 +697,6 @@
691 697 return false;
692 698 }
693 699
694 - //break the connection and rebuild it - since we validated on first login the values here should be fine.
695 -
696 700 CurrentDatabaseName = pNewDbName;
697 701
698 702 DatabaseFunctions.Disconnect();
  @@ -704,8 +708,6 @@
704 708 //set the properties on this instance so the calling party knows what happened
705 709 DatabaseConnectionStatus = ConnectionStatus.LoginFailed;
706 710
707 - DatabaseLastError = res.ErrorDetails;
708 -
709 711 //display a formatted error dialog with as much detail as we can muster about the failure reason
710 712 RaiseErrorEvent("(error) while changing databases in ChangeActiveDatabase: " + res);
711 713
  @@ -713,11 +715,34 @@
713 715
714 716 //update the status to show connected status
715 717 DatabaseConnectionStatus = ConnectionStatus.Connected;
716 - DatabaseLastError = "";
717 718
718 719 return true;
719 720 }
720 721
722 + /// <summary>
723 + /// Simple method that determins if the database name string is a valid Unity Connection database
724 + /// </summary>
725 + /// <param name="pDbName"></param>
726 + /// <returns></returns>
727 + public static bool IsValidDatabaseName(string pDbName)
728 + {
729 + //make sure the DB name is valid
730 + switch (pDbName.ToUpper())
731 + {
732 + case "UNITYDIRDB":
733 + case "UNITYDYNDB":
734 + case "UNITYRPTDB":
735 + case "UNITYMBXDB1":
736 + case "UNITYMBXDB2":
737 + case "UNITYMBXDB3":
738 + case "UNITYMBXDB4":
739 + case "UNITYMBXDB5":
740 + case "UNITYMBXDB6":
741 + return true;
742 + }
743 +
744 + return false;
745 + }
721 746
722 747 /// <summary>
723 748 ///this function calls the stored procs necessary to tell the grammar compilation engine to wait until we're done before recompiling
  @@ -733,7 +758,7 @@
733 758 /// </param>
734 759 public void LargeDbOperationPause(bool pPauseNetworking)
735 760 {
736 - RaiseDebugEvent("[DEBUG] entering LargeDBOperationPause on ConnectionServerOdbc.cs");
761 + RaiseDebugEvent("[DEBUG] entering LargeDbOperationPause on ConnectionServerOdbc.cs");
737 762
738 763 if (DatabaseFunctions.StartNewCommand("csp_grammarcompilepause") == false)
739 764 {
  @@ -743,7 +768,7 @@
743 768 DbFetchResult res = DatabaseFunctions.ExecuteProc();
744 769 if (res.Successful == false)
745 770 {
746 - RaiseErrorEvent("(error) in LargeDbOperationPause pausing grammar compiles on ConnectionServerOdbc.cs:"+res.ToString());
771 + RaiseErrorEvent("(error) in LargeDbOperationPause pausing grammar compiles on ConnectionServerOdbc.cs:"+res);
747 772 }
748 773
749 774
  @@ -757,7 +782,7 @@
757 782 if (res.Successful == false)
758 783 {
759 784 RaiseErrorEvent("(error) in LargeDbOperationPause pausing networking replication on ConnectionServerOdbc.cs:" +
760 - res.ToString());
785 + res);
761 786 }
762 787 }
763 788
  @@ -777,7 +802,8 @@
777 802 /// </param>
778 803 public DbFetchResult UpdateStatisticsForMailstore(string pMailstoreName)
779 804 {
780 - return DatabaseFunctions.UpdateStatisticsForMailstore(pMailstoreName, DatabaseServerName,DatabaseLoginName, DatabaseLoginPassword);
805 + RaiseDebugEvent("[DEBUG] entering UpdateStatisticsForDatabase on ConnectionServerOdbc.cs");
806 + return DatabaseFunctions.UpdateStatisticsForDatabase(pMailstoreName, DatabaseServerName,DatabaseLoginName, DatabaseLoginPassword);
781 807 }
782 808
783 809 #endregion
  @@ -795,6 +821,8 @@
795 821 /// </returns>
796 822 public bool IsLanguageInstalled(string pLanguageCode)
797 823 {
824 + RaiseDebugEvent("[DEBUG] entering IsLanguageInstalled with string language code on ConnectionServerOdbc.cs");
825 +
798 826 int iTemp;
799 827 if (int.TryParse(pLanguageCode, out iTemp))
800 828 {
  @@ -812,13 +840,15 @@
812 840 /// </returns>
813 841 public bool IsLanguageInstalled(int pLanguageCode)
814 842 {
843 + RaiseDebugEvent("[DEBUG] entering IsLanguageInstalled with integer language code on ConnectionServerOdbc.cs");
844 +
815 845 //do a "lazy fetch" of the languages installed
816 846 if (_installedLanguages == null)
817 847 {
818 848 GetInstalledLanguages();
819 849 }
820 850
821 - if (_installedLanguages.Count == 0)
851 + if (_installedLanguages == null || _installedLanguages.Count == 0)
822 852 {
823 853 return false;
824 854 }
  @@ -834,6 +864,8 @@
834 864 /// </returns>
835 865 public int GetDefaultLanguage()
836 866 {
867 + RaiseDebugEvent("[DEBUG] entering GetDefaultLanguage on ConnectionServerOdbc.cs");
868 +
837 869 if (_defaultLanguage!=-1)
838 870 {
839 871 return _defaultLanguage;
  @@ -850,7 +882,7 @@
850 882 /// </summary>
851 883 private void GetInstalledLanguages()
852 884 {
853 - int iLang;
885 + RaiseDebugEvent("[DEBUG] entering GetInstalledLanguages on ConnectionServerOdbc.cs");
854 886
855 887 _installedLanguages = new List<int>();
856 888
  @@ -867,7 +899,7 @@
867 899 ShortLanguageNames oLanguageCode;
868 900 if (Enum.TryParse(strCode, true, out oLanguageCode))
869 901 {
870 - iLang = (int) oLanguageCode;
902 + int iLang = (int) oLanguageCode;
871 903 _installedLanguages.Add(iLang);
872 904 }
873 905 }
  @@ -977,276 +1009,6 @@
977 1009
978 1010 #endregion
979 1011
980 -
981 - #region ComboBox Methods
982 -
983 - /// <summary>
984 - /// The ConnectionObject class is used to add objects to drop down lists - this allows you to fetch the objectId
985 - /// from a user selection easily while still allowing standard drop down lists to display objects normally.
986 - /// The ConnectionObject is merely a display name (which can be anything - alias, display name, first name, whatever
987 - /// you want to present to the user as a selection item) and a unique identifier for that item (most often an ObjectID).
988 - /// </summary>
989 - private class ConnectionObject
990 - {
991 - private string DisplayName { get; set; }
992 - public string ObjectId { get; private set; }
993 -
994 - //creation definition - must pass in display string and unique identifier
995 - public ConnectionObject(string pDisplayName, string pObjectId)
996 - {
997 - DisplayName = pDisplayName;
998 - ObjectId = pObjectId;
999 - }
1000 -
1001 - //when we add an instance of this object to a drop down list it needs to know how to display it to the
1002 - //user - just resturn the display name
1003 - public override string ToString()
1004 - {
1005 - //only use the numbers of interview handler questions and private lists - other items are out of the range
1006 - return DisplayName;
1007 - }
1008 -
1009 - }
1010 -
1011 -
1012 - /// <summary>
1013 - /// Function that lets you fill in lists of objects into a combo box using the ConnectionObject class such that it's
1014 - /// easy to show the objects with human readable display strings and fetch the unique identifier off them at the same time
1015 - /// (usually the ObjecTID). You can stick anything in here you want but this is most often used for things that you
1016 - /// know will typically have fewer than 100 items (i.e. COSes, schedules, partitions, search spaces, templates etc...). Often
1017 - /// you just want to present the user with the option of picking one and going - this is a quick and easy way to go about it
1018 - /// coupled with the FetchIDFromCurrentComboBoxItem function for pulling off the ObjectID value.
1019 - /// </summary>
1020 - /// <param name="pComboBox" type="System.Windows.Forms.ComboBox">
1021 - /// A handle to a combo box to be filled with the items you want.
1022 - /// </param>
1023 - /// <param name="pViewName" type="string">
1024 - /// The database view name (for instance vw_COS or vw_Partition) you want to pull data from.
1025 - /// </param>
1026 - /// <param name="pDisplayStringColumnName" type="string">
1027 - /// The display name field for this view. Normally this is "DisplayName" but some views use "Description" or just "Name".
1028 - /// </param>
1029 - /// <param name="pUniqueIdColumnName" type="string">
1030 - /// The Unique identifier column. Most of the time this is just "ObjectID" however some view use other identifier names.
1031 - /// </param>
1032 - /// <param name="pLocalOnly" type="bool">
1033 - /// Optional boolean, defaults to TRUE which means limit the searches to only objects that are homed on the current Unity Connection server. If FALSE is
1034 - /// passed in the search is done against all objects. If they are replicated in a digital network (for instance as partitions are) then all partitions for
1035 - /// all Connection servers in the network will be included.
1036 - /// </param>
1037 - /// <param name="pWhereClause">
1038 - /// Optional WHERE clause if the view name is not enough detail. Do NOT include the 'WHERE' key word here, it's added on for you.
1039 - /// </param>
1040 - /// <param name="pDefaultItemDescription">
1041 - /// Description for an optional default item that goes up top and will be selected by default - this will
1042 - /// have the description passed in by the calling function and an empty string for the ObjectID - this typically gets used for
1043 - /// something like "[none selected]" or the like.
1044 - /// </param>
1045 - public void FillComboBoxWithObjects(ComboBox pComboBox, string pViewName, string pDisplayStringColumnName,
1046 - string pUniqueIdColumnName, bool pLocalOnly = true, string pWhereClause = "",
1047 - string pDefaultItemDescription = "")
1048 - {
1049 - ConnectionObject oObject;
1050 - DataTable dtTemp;
1051 -
1052 - if (pComboBox == null)
1053 - {
1054 - if (Debugger.IsAttached) Debugger.Break();
1055 - return;
1056 - }
1057 -
1058 - //clear the combo box out
1059 - pComboBox.Items.Clear();
1060 -
1061 - //if the user passed in a default item it goes up top and will be selected by default - this will
1062 - //have the description passed in by the calling function and an empty string for the ObjectID - this typically gets used for
1063 - //something like "none selected" or the like.
1064 - if (pDefaultItemDescription.Length > 0)
1065 - {
1066 - oObject = new ConnectionObject(pDefaultItemDescription, "");
1067 - pComboBox.Items.Add(oObject);
1068 - }
1069 -
1070 - string strSql = "SELECT " + pUniqueIdColumnName + " as ObjectID, " + pDisplayStringColumnName + " as DisplayName FROM " + pViewName;
1071 -
1072 - //tack on optional where clause if it exists
1073 - if (!string.IsNullOrEmpty(pWhereClause))
1074 - {
1075 - strSql += " WHERE " + pWhereClause;
1076 - }
1077 -
1078 - //if only local objects are desired filter by the location OBjectID matching that of the connection server we're attached to.
1079 - if (pLocalOnly)
1080 - {
1081 - strSql += " WHERE LocationObjectID=\'" + PrimaryLocationObjectId + "\'";
1082 - }
1083 -
1084 - //get a data reader full of all the user templates names/objectIDs on the server
1085 - DbFetchResult ret = DatabaseFunctions.FillDataTableBlocking(strSql, out dtTemp);
1086 - if (ret.Successful == false)
1087 - {
1088 - RaiseErrorEvent("(error) Fetching data in FillComboBoxWithObjects on ConnectionServerOdbc.cs with query=" + strSql + "\nError=" + ret.ErrorDetails);
1089 - }
1090 - if (dtTemp.Rows.Count == 0)
1091 - {
1092 - RaiseErrorEvent("(info) No objects found in FillComboBoxWithObjects on ConnectionServerOdbc.cs using query=" + strSql);
1093 - }
1094 -
1095 - foreach (DataRow oRow in dtTemp.Rows)
1096 - {
1097 - //populate the combo box with all the values found
1098 - oObject = new ConnectionObject(oRow["DisplayName"].ToString(), oRow["ObjectID"].ToString());
1099 - pComboBox.Items.Add(oObject);
1100 - //force the first item in the list to be selected - we know there's at least one item in the list at
1101 - //this point so this should be a safe operation
1102 - pComboBox.SelectedIndex = 0;
1103 - }
1104 - }
1105 -
1106 -
1107 - /// <summary>
1108 - /// For a combo box filled with ConnectionObject references (using the FillComboBoxWithObjects routine) this helper function grabs
1109 - /// the unique ID off the currently selected item - simplifies fetching the ObjectIDs off these for you.
1110 - /// </summary>
1111 - /// <param name="pComboBox" type="System.Windows.Forms.ComboBox">
1112 - /// A handle to a combo box that's been filled with ConnectionObject types using the FillComboBoxWithObjects routine.
1113 - /// </param>
1114 - /// <returns>
1115 - /// The ObjectID of the currently selected item in the oComboBox object passed in. If no items are in the combo box or it is not filled with ConnectionServerOdbc
1116 - /// objects then a blank string is returned.
1117 - /// </returns>
1118 - public string GetIdFromCurrentComboBoxItem(ComboBox pComboBox)
1119 - {
1120 - //consider using contract logic here for 2010.
1121 - if (pComboBox == null)
1122 - {
1123 - RaiseErrorEvent("(error) NULL reference for ComboBox passed to GetIDFromCurrentComboBoxItem on ConnectionADONETDatabaseFunctions");
1124 - return "";
1125 - }
1126 -
1127 - if (pComboBox.InvokeRequired)
1128 - {
1129 - return "";
1130 - }
1131 -
1132 - //empty combo box
1133 - if (pComboBox.Items.Count < 1)
1134 - {
1135 - return "";
1136 - }
1137 -
1138 - //cast the current item into the ConnectionObject type and pull the ObjectID off of it. If the combobox is not
1139 - //full of these objects this will fail
1140 - ConnectionObject oTemp = pComboBox.SelectedItem as ConnectionObject;
1141 -
1142 - if (oTemp == null)
1143 - {
1144 - RaiseErrorEvent("(error) pulling ObjectId from the currently selected item from ComboBox: " + pComboBox.Name +
1145 - " in GetIDFromCurrentComboBoxItem on ConnectionADONETDatabaseFunctions");
1146 - return "";
1147 - }
1148 - return oTemp.ObjectId;
1149 - }
1150 -
1151 -
1152 - /// <summary>
1153 - /// Sets the currently selected item in a combo box to the item associated with the unique ID passed in. If the ID is not found in the
1154 - /// combo box list then FALSE is returned and the currently selected item is left alone.
1155 - /// </summary>
1156 - /// <param name="pComboBox">
1157 - /// A handle to a combo box that's been filled with ConnectionObject types using teh FillComboBoxWithObjects routine.
1158 - /// </param>
1159 - /// <param name="pUniqueId">
1160 - /// Unique ID (usually a GUID) to search for among items in the combo box
1161 - /// </param>
1162 - /// <returns>
1163 - /// TRUE if the ID is found and that item is now selected, FALSE if the item is not found.
1164 - /// </returns>
1165 - public bool SetSelectedComboBoxItemById(ComboBox pComboBox, string pUniqueId)
1166 - {
1167 - //make sure box handle is not null
1168 - if (pComboBox == null)
1169 - {
1170 - RaiseErrorEvent("(error) NULL reference for ComboBox passed to SetSelectedComboBoxItemById on ConnectionADONETDatabaseFunctions");
1171 - return false;
1172 - }
1173 -
1174 - //empty combo box check
1175 - if (pComboBox.Items.Count < 1)
1176 - {
1177 - RaiseErrorEvent("(error) Empty ComboBox passed to SetSelectedComboBoxItemById on ConnectionADONETDatabaseFunctions");
1178 - return false;
1179 - }
1180 -
1181 - //loop through each item in the combo box and look for a match on the unique ID property if any
1182 - foreach (var oItem in pComboBox.Items)
1183 - {
1184 - ConnectionObject oObject = oItem as ConnectionObject;
1185 - if (oObject != null)
1186 - {
1187 - if (oObject.ObjectId.Equals(pUniqueId))
1188 - {
1189 - pComboBox.SelectedItem = oItem;
1190 - return true;
1191 - }
1192 - }
1193 - }
1194 -
1195 - //if we're here no match was found.
1196 - return false;
1197 - }
1198 -
1199 - /// <summary>
1200 - /// Gets the display name of an object from a combo box using it's unique ID. If the unique Id is not found in the combo
1201 - /// box then an empty string is returned.
1202 - /// </summary>
1203 - /// <param name="pComboBox">
1204 - /// A handle to a combo box that's been filled with ConnectionObject types using the FillComboBoxWithObjects routine.
1205 - /// </param>
1206 - /// <param name="pUniqueId">
1207 - /// Unique ID (usually a GUID) to search for among items in the combo box
1208 - /// </param>
1209 - /// <returns>
1210 - /// Display name of item with unique id is returned if found, empty string otherwise
1211 - /// </returns>
1212 - public string GetComboBoxDisplayNameByItemId(ComboBox pComboBox, string pUniqueId)
1213 - {
1214 - //make sure box handle is not null
1215 - if (pComboBox == null)
1216 - {
1217 - if (Debugger.IsAttached) Debugger.Break();
1218 - RaiseErrorEvent("(error) NULL reference for ComboBox passed to GetComboBoxDisplayNameByItemId on ConnectionServerOdbc.cs");
1219 - return "";
1220 - }
1221 -
1222 - //empty combo box check
1223 - if (pComboBox.Items.Count < 1)
1224 - {
1225 - if (Debugger.IsAttached) Debugger.Break();
1226 - RaiseErrorEvent("(error) Empty ComboBox passed to GetComboBoxDisplayNameByItemId on ConnectionServerOdbc.cs");
1227 - return "";
1228 - }
1229 -
1230 - //look thorugh each item and fine the one that matches the Unique ID passed in if any.
1231 - foreach (var oItem in pComboBox.Items)
1232 - {
1233 - ConnectionObject oObject = oItem as ConnectionObject;
1234 - if (oObject != null)
1235 - {
1236 - if (oObject.ObjectId.Equals(pUniqueId))
1237 - {
1238 - return oObject.ToString();
1239 - }
1240 - }
1241 - }
1242 -
1243 - //if we're here no match was found.
1244 - return "";
1245 - }
1246 -
1247 -
1248 -
1249 - #endregion
1250 1012 }
1251 1013
1252 1014