00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 using System;
00013 using System.Collections.Generic;
00014 using System.Windows.Forms;
00015 using Mcs.Epm.MicrosoftProject.mpFx.CustomFieldsWebService;
00016
00017 namespace Mcs.Epm.MicrosoftProject.mpFx.WinForms
00018 {
00019
00020
00021
00022 public partial class CustomFieldSelectorForm : Form
00023 {
00024 #region Instance Data
00025
00026 private readonly ProjectServer _ProjectServer;
00027 private readonly Dictionary<Guid, string> _OriginallySelectedFields;
00028 private Dictionary<Guid, string> _SelectedFields;
00029 private Guid _EntityGuid;
00030
00031 #endregion
00032
00033 #region Constructor
00034
00035
00036
00037
00038
00039
00040
00041 public CustomFieldSelectorForm(ProjectServer projectServer,
00042 Guid entityGuid,
00043 Dictionary<Guid, string> selectedFields)
00044 {
00045 InitializeComponent();
00046
00047 _ProjectServer = projectServer;
00048 _OriginallySelectedFields = selectedFields;
00049 _EntityGuid = entityGuid;
00050 }
00051
00052 public Dictionary<Guid, string> SelectedFields
00053 {
00054 get
00055 {
00056 if (_SelectedFields == null)
00057 {
00058 _SelectedFields = new Dictionary<Guid, string>();
00059
00060 foreach (DataGridViewRow row in selectedCustomFieldDataGridView.Rows)
00061 {
00062 _SelectedFields.Add(new Guid(row.Cells[0].Value.ToString()),
00063 row.Cells[1].Value.ToString());
00064 }
00065 }
00066
00067 return _SelectedFields;
00068 }
00069 }
00070
00071 #endregion
00072
00073 #region Private Methods
00074
00075 private bool CheckAvailableFields()
00076 {
00077 if (availableCustomFieldsDataGridView.CurrentRow == null)
00078 {
00079 MessageBox.Show(this,
00080 "Please select an available custom field.",
00081 "BELS",
00082 MessageBoxButtons.OK,
00083 MessageBoxIcon.Warning);
00084
00085 return false;
00086 }
00087
00088 if (availableCustomFieldsDataGridView.Rows.Count == 0)
00089 {
00090 MessageBox.Show(this,
00091 "All available custom fields have been added.",
00092 "BELS",
00093 MessageBoxButtons.OK,
00094 MessageBoxIcon.Warning);
00095
00096 return false;
00097 }
00098
00099 return true;
00100 }
00101
00102 private bool CheckSelectedFields()
00103 {
00104 if (selectedCustomFieldDataGridView.CurrentRow == null)
00105 {
00106 MessageBox.Show(this,
00107 "Please select a custom field in the selected fields list.",
00108 "BELS",
00109 MessageBoxButtons.OK,
00110 MessageBoxIcon.Warning);
00111
00112 return false;
00113 }
00114
00115 if (selectedCustomFieldDataGridView.Rows.Count == 0)
00116 {
00117 MessageBox.Show(this,
00118 "All custom fields have been removed.",
00119 "BELS",
00120 MessageBoxButtons.OK,
00121 MessageBoxIcon.Warning);
00122
00123 return false;
00124 }
00125
00126 return true;
00127 }
00128
00129 #endregion
00130
00131 #region Event Handlers
00132
00133 private void CustomFieldSelectorForm_Shown(object sender,
00134 EventArgs e)
00135 {
00136 Cursor = Cursors.WaitCursor;
00137
00138 Application.DoEvents();
00139
00140 foreach (
00141 CustomFieldDataSet.CustomFieldsRow customField in
00142 _ProjectServer.Projects.CustomFieldsDataSet.CustomFields.Rows)
00143 {
00144 if (_OriginallySelectedFields.ContainsKey(customField.MD_PROP_UID))
00145 {
00146 selectedCustomFieldDataGridView.Rows.Add(customField.MD_PROP_UID,
00147 customField.MD_PROP_NAME);
00148 }
00149 else
00150 {
00151 availableCustomFieldsDataGridView.Rows.Add(customField.MD_PROP_UID,
00152 customField.MD_PROP_NAME);
00153 }
00154 }
00155
00156 Cursor = Cursors.Default;
00157 }
00158
00159 private void availableCustomFieldsDataGridView_RowEnter(object sender,
00160 DataGridViewCellEventArgs e)
00161 {
00162 addAllButton.Enabled = true;
00163 addOneButton.Enabled = true;
00164 }
00165
00166 private void selectedCustomFieldDataGridView_RowEnter(object sender,
00167 DataGridViewCellEventArgs e)
00168 {
00169 removeAllButton.Enabled = true;
00170 removeOneButton.Enabled = true;
00171 }
00172
00173 private void addAllButton_Click(object sender,
00174 EventArgs e)
00175 {
00176 if (CheckAvailableFields())
00177 {
00178 foreach (DataGridViewRow row in availableCustomFieldsDataGridView.Rows)
00179 {
00180 selectedCustomFieldDataGridView.Rows.Add(row.Cells[0].Value,
00181 row.Cells[1].Value);
00182 }
00183
00184 availableCustomFieldsDataGridView.Rows.Clear();
00185 }
00186 }
00187
00188 private void addOneButton_Click(object sender,
00189 EventArgs e)
00190 {
00191 if (CheckAvailableFields())
00192 {
00193 selectedCustomFieldDataGridView.Rows.Add(availableCustomFieldsDataGridView.CurrentRow.Cells[0].Value,
00194 availableCustomFieldsDataGridView.CurrentRow.Cells[1].Value);
00195
00196 availableCustomFieldsDataGridView.Rows.Remove(availableCustomFieldsDataGridView.CurrentRow);
00197 }
00198 }
00199
00200 private void availableCustomFieldsDataGridView_RowsRemoved(object sender,
00201 DataGridViewRowsRemovedEventArgs e)
00202 {
00203 if (availableCustomFieldsDataGridView.Rows.Count == 0)
00204 {
00205 addOneButton.Enabled = false;
00206 addAllButton.Enabled = false;
00207 }
00208 }
00209
00210 private void removeOneButton_Click(object sender,
00211 EventArgs e)
00212 {
00213 if (CheckSelectedFields())
00214 {
00215 availableCustomFieldsDataGridView.Rows.Add(selectedCustomFieldDataGridView.CurrentRow.Cells[0].Value,
00216 selectedCustomFieldDataGridView.CurrentRow.Cells[1].Value);
00217
00218 selectedCustomFieldDataGridView.Rows.Remove(selectedCustomFieldDataGridView.CurrentRow);
00219 }
00220 }
00221
00222 private void removeAllButton_Click(object sender,
00223 EventArgs e)
00224 {
00225 if (CheckSelectedFields())
00226 {
00227 foreach (DataGridViewRow row in selectedCustomFieldDataGridView.Rows)
00228 {
00229 availableCustomFieldsDataGridView.Rows.Add(row.Cells[0].Value,
00230 row.Cells[1].Value);
00231 }
00232
00233 selectedCustomFieldDataGridView.Rows.Clear();
00234 }
00235 }
00236
00237 private void selectedCustomFieldDataGridView_RowsRemoved(object sender,
00238 DataGridViewRowsRemovedEventArgs e)
00239 {
00240 if (selectedCustomFieldDataGridView.Rows.Count == 0)
00241 {
00242 removeAllButton.Enabled = false;
00243 removeOneButton.Enabled = false;
00244 }
00245 }
00246
00247
00248 private void okButton_Click(object sender,
00249 EventArgs e)
00250 {
00251 Close();
00252 }
00253
00254 #endregion
00255 }
00256 }