00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 using System;
00013 using System.Collections.Generic;
00014 using System.Globalization;
00015 using Mcs.Epm.MicrosoftProject.mpFx.LookupTablesWebService;
00016
00017 namespace Mcs.Epm.MicrosoftProject.mpFx
00018 {
00019
00020
00021
00022 public class LookupTables
00023 {
00024 #region Instance Data
00025
00026 private readonly ProjectServer _Parent;
00027 private bool _CacheLookupTables;
00028 private Dictionary<Guid, LookupTableMultiLangDataSet.LookupTableValuesDataTable> _MultiLanguageLookupTableValues;
00029
00030 #endregion
00031
00032 #region Constructors
00033
00034
00035
00036
00037
00038
00039 internal LookupTables(ProjectServer parent,
00040 bool cacheLookupTables)
00041 {
00042 if (parent == null)
00043 {
00044 throw new ArgumentNullException( );
00045 }
00046
00047 _Parent = parent;
00048
00049 CacheLookupTables = cacheLookupTables;
00050 }
00051
00052 #endregion
00053
00054 #region Public Properties
00055
00056
00057
00058
00059 public bool CacheLookupTables
00060 {
00061 get { return _CacheLookupTables; }
00062
00063 set
00064 {
00065 _CacheLookupTables = value;
00066
00067 if (value == false)
00068 {
00069 _MultiLanguageLookupTableValues.Clear();
00070 _MultiLanguageLookupTableValues = null;
00071 }
00072 else
00073 {
00074 _MultiLanguageLookupTableValues = new Dictionary<Guid, LookupTableMultiLangDataSet.LookupTableValuesDataTable>();
00075 }
00076 }
00077 }
00078
00079 #endregion
00080
00081 #region Public Methods
00082
00083
00084
00085
00086
00087
00088
00089 public LookupTableMultiLangDataSet MultiLangGetLookupTables(string xmlFilter,
00090 bool autoCheckout)
00091 {
00092 return _Parent.WebServices.LookupTables.ReadLookupTablesMultiLang(xmlFilter, autoCheckout);
00093 }
00094
00095 public LookupTableDataSet GetLookupTables(string xmlFilter,
00096 bool autoCheckout,
00097 int lcid)
00098 {
00099 return _Parent.WebServices.LookupTables.ReadLookupTables(xmlFilter, autoCheckout, lcid);
00100 }
00101
00102
00103
00104
00105
00106
00107
00108 public LookupTableMultiLangDataSet.LookupTableValuesDataTable MultiLangLoadLookupTableValues(Guid lookupTableGuid,
00109 string xmlFilter)
00110 {
00111 if (_CacheLookupTables)
00112 {
00113 if (_MultiLanguageLookupTableValues.ContainsKey(lookupTableGuid))
00114 {
00115 return _MultiLanguageLookupTableValues[lookupTableGuid];
00116 }
00117 }
00118
00119 LookupTableMultiLangDataSet.LookupTableValuesDataTable valuesTable = MultiLangGetLookupTableValues(xmlFilter, false);
00120
00121 if (_CacheLookupTables)
00122 {
00123 _MultiLanguageLookupTableValues.Add(lookupTableGuid, valuesTable);
00124 }
00125
00126 return valuesTable;
00127 }
00128
00129
00130
00131
00132
00133
00134
00135 public LookupTableMultiLangDataSet.LookupTableValuesDataTable MultiLangGetLookupTableValues(string xmlFilter,
00136 bool autoCheckout)
00137 {
00138 using (LookupTableMultiLangDataSet lookupTableMultiLangDataSet = MultiLangGetLookupTables(xmlFilter, autoCheckout))
00139 {
00140 return lookupTableMultiLangDataSet.LookupTableValues;
00141 }
00142 }
00143
00144
00145
00146
00147
00148
00149
00150 public static Guid FindInLookupTable(string value,
00151 LookupTableMultiLangDataSet.LookupTableValuesDataTable lookupTable)
00152 {
00153 value = value.Trim().ToUpper(CultureInfo.InvariantCulture);
00154
00155 if (! string.IsNullOrEmpty(value))
00156 {
00157 foreach (LookupTableMultiLangDataSet.LookupTableValuesRow row in lookupTable.Rows)
00158 {
00159 if (row.LT_VALUE_TEXT.ToUpper(CultureInfo.InvariantCulture) == value)
00160 {
00161 return row.LT_STRUCT_UID;
00162 }
00163 }
00164 }
00165
00166 return Guid.Empty;
00167 }
00168
00169
00170
00171
00172
00173
00174
00175
00176 public string MultiLangGetLookupTableTextValue(Guid lookupTableGuid,
00177 Guid valueGuid,
00178 int languageCode)
00179 {
00180 using (
00181 LookupTableMultiLangDataSet.LookupTableValuesDataTable lookupTableValues = MultiLangLoadLookupTableValues(lookupTableGuid,
00182 LookupTableFilters.ItemBasicInformation(lookupTableGuid)))
00183 {
00184 if (lookupTableValues == null)
00185 {
00186 throw new ArgumentNullException( );
00187 }
00188
00189 LookupTableMultiLangDataSet.LookupTableValuesRow valuesTable = lookupTableValues.FindByLT_STRUCT_UIDLCID(valueGuid, languageCode);
00190
00191 if (valuesTable == null)
00192 {
00193 throw new InvalidOperationException( );
00194 }
00195
00196 return valuesTable.LT_VALUE_TEXT;
00197 }
00198 }
00199
00200 public void AddLookupTableTextValue(Guid lookupTableGuid, Guid valueGuid, string value, int lcid)
00201 {
00202 LookupTableMultiLangDataSet lookupTableDataSet = null;
00203 bool checkedOut = false;
00204
00205 try
00206 {
00207 lookupTableDataSet = _Parent.WebServices.LookupTables.ReadLookupTablesMultiLangByUids(new[] { lookupTableGuid }, true);
00208
00209 checkedOut = true;
00210
00211 LookupTableMultiLangDataSet.LookupTableStructuresRow structureRow = lookupTableDataSet.LookupTableStructures.NewLookupTableStructuresRow();
00212 structureRow.LT_UID = lookupTableGuid;
00213
00214 structureRow.LT_STRUCT_UID = valueGuid;
00215 lookupTableDataSet.LookupTableStructures.Rows.Add(structureRow);
00216
00217 LookupTableMultiLangDataSet.LookupTableValuesRow newValue = lookupTableDataSet.LookupTableValues.NewLookupTableValuesRow();
00218
00219 newValue.LCID = lcid;
00220 newValue.LT_VALUE_TEXT = value;
00221 newValue.LT_STRUCT_UID = structureRow.LT_STRUCT_UID;
00222
00223 newValue.LT_VALUE_SORT_INDEX = lookupTableDataSet.LookupTables[0].LT_SORT_ORDER_ENUM;
00224
00225 lookupTableDataSet.LookupTableValues.AddLookupTableValuesRow(newValue);
00226
00227 _Parent.WebServices.LookupTables.UpdateLookupTablesMultiLang(lookupTableDataSet, false, true);
00228
00229 checkedOut = false;
00230 }
00231 finally
00232 {
00233 if (lookupTableDataSet != null)
00234 {
00235 lookupTableDataSet.Dispose();
00236 }
00237
00238 if (checkedOut)
00239 {
00240 try
00241 {
00242 _Parent.WebServices.LookupTables.CheckInLookupTables(new[] { lookupTableGuid }, true);
00243 }
00244 catch
00245 {
00246
00247 }
00248 }
00249 }
00250 }
00251
00252 public Guid GetTextLookupTableValueGuid(Guid lookupTableGuid, string value)
00253 {
00254 using (LookupTableMultiLangDataSet.LookupTableValuesDataTable valuesTable = MultiLangLoadLookupTableValues(lookupTableGuid, string.Empty))
00255 {
00256 return FindInLookupTable(value, valuesTable);
00257 }
00258 }
00259
00260 #endregion
00261 }
00262 }