00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 using System;
00013 using System.Collections;
00014 using System.Collections.Generic;
00015 using System.Collections.ObjectModel;
00016 using Mcs.Epm.MicrosoftProject.mpFx.CustomFieldsWebService;
00017 using Mcs.Epm.MicrosoftProject.mpFx.ProjectsWebService;
00018 using Microsoft.Office.Project.Server.Library;
00019
00020 namespace Mcs.Epm.MicrosoftProject.mpFx
00021 {
00022
00023
00024
00025 public class ProjectCustomFieldsCollection : ICollection<ProjectCustomField>
00026 {
00027 #region Static Methods
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 public static bool TryGetFieldValueInformation(ProjectServer projectServer,
00039 CustomFieldDataSet.CustomFieldsRow customFieldDefinition,
00040 ProjectDataSet.ProjectCustomFieldsRow customField,
00041 bool multiLang,
00042 out object value,
00043 out CustomFieldValueType type)
00044 {
00045 PSDataType dataType = (PSDataType) customField.FIELD_TYPE_ENUM;
00046
00047 type = CustomFieldValueType.None;
00048 value = null;
00049
00050 switch (dataType)
00051 {
00052 case PSDataType.STRING:
00053
00054 if (customField.IsTEXT_VALUENull() == false)
00055 {
00056 value = customField.TEXT_VALUE;
00057 type = CustomFieldValueType.Text;
00058 }
00059 else if (customField.IsCODE_VALUENull() == false)
00060 {
00061 if (multiLang)
00062 {
00063 value = projectServer.LookupTables.MultiLangGetLookupTableTextValue(customFieldDefinition.MD_LOOKUP_TABLE_UID,
00064 customField.CODE_VALUE,
00065 1033);
00066 }
00067
00068 type = CustomFieldValueType.Text;
00069 }
00070 break;
00071
00072 case PSDataType.NUMBER:
00073
00074 value = customField.NUM_VALUE.ToString();
00075 type = CustomFieldValueType.Number;
00076 break;
00077
00078 case PSDataType.DATE:
00079
00080 value = customField.DATE_VALUE.ToUniversalTime().ToLongDateString();
00081 type = CustomFieldValueType.Date;
00082 break;
00083
00084 default:
00085 break;
00086 }
00087
00088 return type != CustomFieldValueType.None;
00089 }
00090
00091 #endregion
00092
00093 #region Instance Data
00094
00095 private Collection<ProjectCustomField> _ProjectCustomFieldsCollection;
00096 private readonly bool _IsReadOnly;
00097
00098 #endregion
00099
00100 #region Constructor
00101
00102
00103
00104
00105
00106 internal ProjectCustomFieldsCollection(EnterpriseProject parent)
00107 {
00108
00109
00110 if (parent == null)
00111 {
00112 throw new ArgumentNullException( );
00113 }
00114
00115 Parent = parent;
00116
00117 _IsReadOnly = true;
00118
00119 LoadProjectCustomFieldsCollection();
00120 }
00121
00122 #endregion;
00123
00124 #region Internal Properties
00125
00126
00127
00128
00129 internal EnterpriseProject Parent { get; private set; }
00130
00131 #endregion
00132
00133 #region Indexer
00134
00135
00136
00137
00138
00139
00140 public ProjectCustomField this[Guid fieldGuid]
00141 {
00142 get
00143 {
00144 foreach (ProjectCustomField customField in _ProjectCustomFieldsCollection)
00145 {
00146 if (customField.PropertyGuid == fieldGuid)
00147 {
00148 return customField;
00149 }
00150 }
00151
00152 return null;
00153 }
00154 }
00155
00156 #endregion
00157
00158 #region Private Methods
00159
00160
00161
00162
00163 private void LoadProjectCustomFieldsCollection()
00164 {
00165 if (_ProjectCustomFieldsCollection == null)
00166 {
00167 _ProjectCustomFieldsCollection = new Collection<ProjectCustomField>();
00168 }
00169 else
00170 {
00171 _ProjectCustomFieldsCollection.Clear();
00172 }
00173
00174 List<Guid> loadedFields = new List<Guid>();
00175
00176 foreach (ProjectDataSet.ProjectCustomFieldsRow customField in Parent.CustomFieldsDataSet.Rows)
00177 {
00178 if (!loadedFields.Contains(customField.MD_PROP_UID))
00179 {
00180 ProjectCustomField field = new ProjectCustomField(this,
00181 customField.MD_PROP_UID,
00182 Parent.Parent.CustomFieldsDataSet.CustomFields.FindByMD_PROP_UID(customField.MD_PROP_UID).MD_PROP_NAME);
00183
00184 _ProjectCustomFieldsCollection.Add(field);
00185
00186 loadedFields.Add(customField.MD_PROP_UID);
00187 }
00188 }
00189 }
00190
00191 #endregion
00192
00193 public bool ContainsKey(Guid key)
00194 {
00195 foreach (ProjectCustomField field in _ProjectCustomFieldsCollection)
00196 {
00197 if (field.PropertyGuid == key)
00198 {
00199 return true;
00200 }
00201 }
00202 return false;
00203 }
00204
00205 #region ICollection<ProjectCustomField> Members
00206
00207
00208
00209
00210
00211
00212
00213 void ICollection<ProjectCustomField>.Add(ProjectCustomField item)
00214 {
00215 _ProjectCustomFieldsCollection.Add(item);
00216 }
00217
00218
00219
00220
00221
00222
00223 void ICollection<ProjectCustomField>.Clear()
00224 {
00225 _ProjectCustomFieldsCollection.Clear();
00226 }
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237 bool ICollection<ProjectCustomField>.Contains(ProjectCustomField item)
00238 {
00239 return _ProjectCustomFieldsCollection.Contains(item);
00240 }
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251 void ICollection<ProjectCustomField>.CopyTo(ProjectCustomField[] array,
00252 int arrayIndex)
00253 {
00254 _ProjectCustomFieldsCollection.CopyTo(array, arrayIndex);
00255 }
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267 bool ICollection<ProjectCustomField>.Remove(ProjectCustomField item)
00268 {
00269 return _ProjectCustomFieldsCollection.Remove(item);
00270 }
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280 int ICollection<ProjectCustomField>.Count
00281 {
00282 get { return _ProjectCustomFieldsCollection.Count; }
00283 }
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293 bool ICollection<ProjectCustomField>.IsReadOnly
00294 {
00295 get { return _IsReadOnly; }
00296 }
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306 IEnumerator<ProjectCustomField> IEnumerable<ProjectCustomField>.GetEnumerator()
00307 {
00308 return _ProjectCustomFieldsCollection.GetEnumerator();
00309 }
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319 IEnumerator IEnumerable.GetEnumerator()
00320 {
00321 return ((IEnumerable<ResourceCustomField>) this).GetEnumerator();
00322 }
00323
00324 #endregion
00325 }
00326 }
00327
00328
00329
00330
00331
00332
00333