00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 using System;
00013 using System.Collections.Generic;
00014 using System.Diagnostics;
00015 using Mcs.Epm.MicrosoftProject.mpFx.ProjectsWebService;
00016
00017 namespace Mcs.Epm.MicrosoftProject.mpFx
00018 {
00019
00020
00021
00022 public class ProjectCustomField
00023 {
00024 #region Instance data
00025
00026 private readonly ProjectCustomFieldsCollection _Parent;
00027 private object _Value;
00028
00029 #endregion
00030
00031 #region Constructor
00032
00033
00034
00035
00036
00037
00038
00039 internal ProjectCustomField(ProjectCustomFieldsCollection parent,
00040 Guid propertyGuid,
00041 string name)
00042 {
00043 if (parent == null)
00044 {
00045 throw new ArgumentNullException( );
00046 }
00047
00048 _Parent = parent;
00049 Name = name;
00050 PropertyGuid = propertyGuid;
00051 }
00052
00053 #endregion
00054
00055 #region Public Properties
00056
00057
00058
00059
00060 public bool IsList
00061 {
00062 get { return _Value as List<object> != null; }
00063 }
00064
00065
00066
00067
00068 public List<object> List
00069 {
00070 get
00071 {
00072 if (IsList)
00073 {
00074 return _Value as List<object>;
00075 }
00076 return null;
00077 }
00078 }
00079
00080
00081
00082
00083 public CustomFieldValueType Type { get; private set; }
00084
00085
00086
00087
00088 public Guid PropertyGuid { get; private set; }
00089
00090
00091
00092
00093 public string Name { get; private set; }
00094
00095
00096
00097
00098 public object Value
00099 {
00100 get
00101 {
00102 if (_Value == null)
00103 {
00104 LoadProjectCustomFieldValue();
00105 }
00106
00107 return _Value;
00108 }
00109 }
00110
00111 #endregion
00112
00113 #region Private Methods
00114
00115
00116
00117
00118 private void LoadProjectCustomFieldValue()
00119 {
00120 var values = new List<object>();
00121
00122 CustomFieldValueType type = CustomFieldValueType.None;
00123
00124 foreach (ProjectDataSet.ProjectCustomFieldsRow customField in _Parent.Parent.CustomFieldsDataSet.Rows)
00125 {
00126 if (customField.MD_PROP_UID == PropertyGuid)
00127 {
00128 object value;
00129
00130 if (ProjectCustomFieldsCollection.TryGetFieldValueInformation(_Parent.Parent.Parent.Parent,
00131 _Parent.Parent.Parent.
00132 CustomFieldsDataSet.CustomFields.
00133 FindByMD_PROP_UID(PropertyGuid),
00134 customField,
00135 true,
00136 out value,
00137 out type))
00138 {
00139 values.Add(value);
00140 }
00141 }
00142 }
00143
00144 if (values.Count > 1)
00145 {
00146 _Value = values;
00147 }
00148 else
00149 {
00150 if (values.Count == 1)
00151 {
00152 _Value = values[0];
00153
00154 Type = type;
00155 }
00156 else
00157 {
00158 Debug.Assert(values.Count == 0);
00159
00160 _Value = null;
00161
00162 Type = CustomFieldValueType.None;
00163 }
00164 }
00165 }
00166
00167 #endregion
00168
00169 public void Update(string newValue, bool checkOut)
00170 {
00171 Guid sessionGuid = Guid.NewGuid();
00172 Guid projectGuid = _Parent.Parent.ProjectGuid;
00173
00174 if (checkOut)
00175 {
00176 _Parent.Parent.Parent.Parent.WebServices.Projects.CheckOutProject(projectGuid, sessionGuid, newValue);
00177 }
00178
00179 using (ProjectDataSet customFieldDataSet =_Parent.Parent.Parent.Parent.WebServices.Projects.ReadProjectEntities(_Parent.Parent.ProjectGuid,
00180 (int)(ProjectEntityType.ProjectCustomFields | ProjectEntityType.Project),
00181 _Parent.Parent.Parent.Parent.Store))
00182 {
00183 if (customFieldDataSet != null)
00184 {
00185 foreach (ProjectDataSet.ProjectCustomFieldsRow customField in customFieldDataSet.ProjectCustomFields.Rows)
00186 {
00187 if (customField.MD_PROP_UID == PropertyGuid)
00188 {
00189 customField.TEXT_VALUE = newValue;
00190 break;
00191 }
00192 }
00193
00194 sessionGuid = customFieldDataSet.Project[0].PROJ_SESSION_UID;
00195
00196 _Parent.Parent.Parent.Parent.WebServices.Projects.QueueUpdateProject(Guid.NewGuid(),
00197 sessionGuid,
00198 customFieldDataSet,
00199 false);
00200 }
00201 }
00202
00203 if (checkOut)
00204 {
00205 string errorMessage;
00206
00207 _Parent.Parent.Parent.CheckIn(projectGuid, sessionGuid, false, true, out errorMessage);
00208 }
00209 }
00210 }
00211 }
00212
00213
00214
00215
00216
00217
00218