コード例 #1
0
 private void AddTaskCenterField(SPField field, CustomFieldDataSet customFieldDataSet, DictionaryEntry dictionaryEntry)
 {
     if (field != null)
     {
         if (field.Type == SPFieldType.Choice)
         {
             using (var command = new SqlCommand("select * from customfields where wssfieldname=@fieldname and fieldcategory=3", cn))
             {
                 command.Parameters.AddWithValue("@fieldname", field.InternalName);
                 using (var dataReader = command.ExecuteReader())
                 {
                     if (dataReader.Read())
                     {
                         field.SchemaXml = getSchemaXml(field, dataReader.GetString(0));
                     }
                 }
             }
         }
         if (isCalculated(customFieldDataSet, dictionaryEntry.Key.ToString().Substring(3)))
         {
             field.ShowInEditForm = false;
             field.ShowInNewForm  = false;
         }
         field.Update();
     }
 }
コード例 #2
0
ファイル: DataHelper.cs プロジェクト: jgoodso2/PMMP
 public static object GetValueFromCustomFieldTextOrDate(DataRow dataRow, CustomFieldType type, CustomFieldDataSet dataSet)
 {
     try
     {
         StringCollection value = new StringCollection();
         Guid mdPropID = Guid.Empty;
         if ((dataSet as CustomFieldDataSet).CustomFields.Any(t => t.MD_PROP_NAME == type.GetString()))
         {
             mdPropID = (dataSet as CustomFieldDataSet).CustomFields.First(t => t.MD_PROP_NAME == type.GetString()).MD_PROP_UID;
         }
         if (mdPropID == Guid.Empty)
         {
             return null;
         }
         if (type == CustomFieldType.EstStart || type == CustomFieldType.EstFinish)
         {
             if ((dataRow.Table.DataSet as ProjectDataSet).TaskCustomFields.Any(t => t.TASK_UID == (dataRow as ProjectDataSet.TaskRow).TASK_UID && t.MD_PROP_UID == mdPropID))
                 return (dataRow.Table.DataSet as ProjectDataSet).TaskCustomFields.First(t => t.TASK_UID == (dataRow as ProjectDataSet.TaskRow).TASK_UID && t.MD_PROP_UID == mdPropID && !t.IsDATE_VALUENull()).DATE_VALUE;
             else
                 return null;
         }
         else if (type == CustomFieldType.PMT || type == CustomFieldType.ReasonRecovery)
         {
             if ((dataRow.Table.DataSet as ProjectDataSet).TaskCustomFields.Any(t => t.TASK_UID == (dataRow as ProjectDataSet.TaskRow).TASK_UID && t.MD_PROP_UID == mdPropID && !t.IsTEXT_VALUENull()))
                 return (dataRow.Table.DataSet as ProjectDataSet).TaskCustomFields.First(t => t.TASK_UID == (dataRow as ProjectDataSet.TaskRow).TASK_UID && t.MD_PROP_UID == mdPropID && !t.IsTEXT_VALUENull()).TEXT_VALUE;
             else
                 return null;
         }
         return null;
     }
     catch
     {
         return null;
     }
 }
コード例 #3
0
        private void UpdateFields(Hashtable updFields, SPList list, CustomFieldDataSet customFieldDataSet)
        {
            foreach (DictionaryEntry dictionaryEntry in updFields)
            {
                try
                {
                    var field = list.Fields[new Guid(dictionaryEntry.Key.ToString())];
                    if (field.Type == SPFieldType.Choice)
                    {
                        var fieldName = field.InternalName.Substring(3);
                        var temp      = 0;
                        if (int.TryParse(fieldName, out temp))
                        {
                            field.SchemaXml = getSchemaXml(field, fieldName);
                        }
                    }

                    if (isCalculated(customFieldDataSet, field.InternalName.Substring(3)))
                    {
                        field.ShowInEditForm = false;
                        field.ShowInNewForm  = false;
                    }

                    field.Update();
                }
                catch (Exception ex)
                {
                    myLog.WriteEntry(
                        string.Format("Error Updating Field ({0}): {1}{2}", dictionaryEntry.Key, ex.Message, ex.StackTrace),
                        EventLogEntryType.Error,
                        ErrorUpdatingFieldId);
                }
            }
        }
コード例 #4
0
ファイル: EnvUtil.cs プロジェクト: FluentProSoftware/FluentPS
        public void CreateCustomFields <T>(List <T> customFields)
        {
            var cfds = new CustomFieldDataSet();

            _mapper.Map(customFields, cfds.CustomFields);
            _customFieldsPsiService.Invoke(c => c.CreateCustomFields2(cfds, false, true));
        }
コード例 #5
0
ファイル: DataSetBuilder.cs プロジェクト: jgoodso2/PMIS
        static DataSetBuilder()
        {
            Console.WriteLine("Starting Set up for PMS Import");
            customDataSet = Repository.customFieldsClient.ReadCustomFields("", false);

            Console.WriteLine("Set up for PMS Import done successfully");
        }
コード例 #6
0
        public void DeleteCustomField(string target, string field)
        {
            CustomFieldDataSet cfDS = new CustomFieldDataSet();
            var RowField            = this.dsGenerico.Tables[0].Select("MD_PROP_NAME ='" + field + "'").CopyToDataTable();

            SvcCustomFields.CustomFieldsClient fieldTarget = new CustomFieldsClient(Binding, endPointAdress(target, "/_vti_bin/psi/CustomFields.asmx"));
            fieldTarget.ClientCredentials.Windows.ClientCredential = new NetworkCredential(this.User, this.PassWord, this.Domain);
            Guid[] fieldsArray = new Guid[1];
            //fieldsArray[0] =
            fieldTarget.DeleteCustomFields(fieldsArray);
        }
コード例 #7
0
        public void processProjectCenter()
        {
            try
            {
                var newFields    = new ArrayList();
                var allFields    = new Hashtable();
                var updateFields = new Hashtable();

                PopulateProjectCenterFieldsLists(allFields, newFields);


                SPList list = null;
                try
                {
                    list = myWebToPublish.Lists["Project Center"];
                }
                catch (Exception ex)
                {
                    Trace.TraceError("Exception Suppressed {0}", ex);
                }

                if (list != null)
                {
                    AddCustomProjectCenterFields(list);

                    var customFieldDataSet = new CustomFieldDataSet();
                    try
                    {
                        customFieldDataSet = pCf.ReadCustomFieldsByEntity(new Guid(PSLibrary.EntityCollection.Entities.TaskEntity.UniqueId));
                    }
                    catch (Exception ex)
                    {
                        myLog.WriteEntry(
                            string.Format("Error in publishProject() Reading Custom Fields: {0}{1}", ex.Message, ex.StackTrace),
                            EventLogEntryType.Error,
                            ErrorReadingCustomFieldId);
                    }

                    PopulateAddAndUpdateLists(list, newFields, customFieldDataSet, updateFields);
                    ProcessProjectCenterFieldsToUpdate(updateFields, list);
                    ProcessNewProjectCenterFields(newFields, list);
                }
            }
            catch (Exception ex)
            {
                myLog.WriteEntry(
                    string.Format("Error Processing Project Center: {0}{1}", ex.Message, ex.StackTrace),
                    EventLogEntryType.Error,
                    ErrorProcessingTaskCenterId);
            }
        }
コード例 #8
0
 private void AddNewFields(Hashtable newFields, SPList list, CustomFieldDataSet customFieldDataSet)
 {
     foreach (DictionaryEntry dictionaryEntry in newFields)
     {
         try
         {
             var field = GetTaskCenterFieldToAdd(dictionaryEntry, list);
             AddTaskCenterField(field, customFieldDataSet, dictionaryEntry);
         }
         catch (Exception ex)
         {
             myLog.WriteEntry(
                 string.Format("Error Adding Field: {0}{1}", ex.Message, ex.StackTrace),
                 EventLogEntryType.Error,
                 ErrorAddingFieldId);
         }
     }
 }
コード例 #9
0
        private CustomFieldDataSet GetCustomTaskCenterFieldDataSet()
        {
            var customFieldDataSet = new CustomFieldDataSet();

            try
            {
                SPSecurity.RunWithElevatedPrivileges(
                    delegate
                {
                    customFieldDataSet = pCf.ReadCustomFieldsByEntity(new Guid(PSLibrary.EntityCollection.Entities.TaskEntity.UniqueId));
                });
            }
            catch (Exception ex)
            {
                myLog.WriteEntry(
                    string.Format("Error in publishProject() Reading Custom Fields: {0}{1}", ex.Message, ex.StackTrace),
                    EventLogEntryType.Error,
                    ErrorReadingCustomFieldId);
            }
            return(customFieldDataSet);
        }
コード例 #10
0
        private static void PopulateAddAndUpdateLists(SPList list, ArrayList newFields, CustomFieldDataSet customFieldDataSet, Hashtable updateFields)
        {
            foreach (SPField field in list.Fields)
            {
                if (field.Type == SPFieldType.Boolean ||
                    field.Type == SPFieldType.Text ||
                    field.Type == SPFieldType.Number ||
                    field.Type == SPFieldType.Currency ||
                    field.Type == SPFieldType.DateTime ||
                    field.Type == SPFieldType.Choice ||
                    field.InternalName == "AssignedTo")
                {
                    if (!newFields.Contains(field.InternalName))
                    {
                        if (field.InternalName.Length > 3)
                        {
                            var fieldName = field.InternalName.Substring(3);
                            var temp      = 0;
                            if (int.TryParse(fieldName, out temp))
                            {
                                var customFieldsRows = (CustomFieldDataSet.CustomFieldsRow[])customFieldDataSet.CustomFields.Select(
                                    string.Format("MD_PROP_ID={0}", fieldName));

                                if (customFieldsRows.Length > 0)
                                {
                                    updateFields.Add(field.Id, false);
                                }
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            updateFields.Add(field.Id, field.ShowInEditForm);
                        }
                        catch (Exception ex)
                        {
                            Trace.TraceError("Exception Suppressed {0}", ex);
                        }
                        try
                        {
                            newFields.Remove(field.InternalName);
                        }
                        catch (Exception ex)
                        {
                            Trace.TraceError("Exception Suppressed {0}", ex);
                        }
                    }
                }
            }

            try
            {
                newFields.Remove("StartDate");
            }
            catch (Exception ex)
            {
                Trace.TraceError("Exception Suppressed {0}", ex);
            }
            try
            {
                newFields.Remove("DueDate");
            }
            catch (Exception ex)
            {
                Trace.TraceError("Exception Suppressed {0}", ex);
            }
        }
コード例 #11
0
ファイル: TaskItemRepository.cs プロジェクト: jgoodso2/PMMP
 private static TaskItem BuildTaskItem(string dPath, DataRow item, CustomFieldDataSet dataSet)
 {
     DateTime? estFinish = (DateTime?)DataHelper.GetValueFromCustomFieldTextOrDate(item, CustomFieldType.EstFinish, dataSet);
     DateTime? estStart = (DateTime?)DataHelper.GetValueFromCustomFieldTextOrDate(item, CustomFieldType.EstStart, dataSet);
     object objreason = DataHelper.GetValueFromCustomFieldTextOrDate(item, CustomFieldType.ReasonRecovery, dataSet);
     string reasonrecovery = objreason != null ? objreason.ToString() : "";
     return new TaskItem
     {
         ID = DataHelper.GetValueAsInteger(item["TASK_ID"].ToString()),
         UniqueID = DataHelper.GetValue(item["TASK_UID".ToString()]),
         DrivingPath = dPath,
         Task = DataHelper.GetValue(item["TASK_NAME"].ToString()),
         Duration = DataHelper.GetValue(item["TASK_DUR"].ToString()),
         Predecessor = DataHelper.GetValue(item["TASK_PREDECESSORS"].ToString()),
         Start = DataHelper.GetValueAsDateTime(item["TASK_START_DATE"].ToString()),
         Finish = DataHelper.GetValueAsDateTime(item["TASK_FINISH_DATE"].ToString()),
         Deadline = DataHelper.GetValueAsDateTime(item["TASK_DEADLINE"].ToString()),
         ShowOn = DataHelper.GetValueFromMultiChoice(item["CUSTOMFIELD_DESC"].ToString(), CustomFieldType.ShowOn),
         CA = string.Join(",", DataHelper.GetValueFromMultiChoice(item["CUSTOMFIELD_DESC"].ToString(), CustomFieldType.CA)),
         EstFinish = estFinish,
         EstStart = estStart,
         PMT = string.Join(",", DataHelper.GetValueFromMultiChoice(item["CUSTOMFIELD_DESC"].ToString(), CustomFieldType.PMT)),
         ReasonRecovery = reasonrecovery,
         ModifiedOn = DataHelper.GetValueAsDateTime(item["TASK_MODIFIED_ON"].ToString()),
         WorkCompletePercentage = DataHelper.GetValueAsInteger(item["TASK_PCT_COMP"].ToString()),
         TotalSlack = DataHelper.GetValue(item["TASK_TOTAL_SLACK"].ToString()),
         BaseLineStart = DataHelper.GetValueAsDateTime(item["TB_START"].ToString()),
         BaseLineFinish = DataHelper.GetValueAsDateTime(item["TB_FINISH"].ToString()),
         Hours = DataHelper.GetValue(item["TASK_WORK"].ToString()),
         BLDuration = DataHelper.GetValue(item["TB_DUR"].ToString())
     };
 }
コード例 #12
0
        /// <summary>
        /// Metodo para criar o Custom Field no Detino
        /// </summary>
        /// <param name="source">Origem</param>
        /// <param name="target">Destino</param>
        /// <param name="field">Nome CustomField</param>
        public void CreateCustomField(string source, string target, string field, string lookupTable)
        {
            CustomFieldDataSet cfDS = new CustomFieldDataSet();
            var RowField            = this.dsGenerico.Tables[0].Select("MD_PROP_NAME ='" + field + "'").CopyToDataTable();

            SvcCustomFields.CustomFieldsClient fieldTarget = new CustomFieldsClient(Binding, endPointAdress(target, "/_vti_bin/psi/CustomFields.asmx"));
            fieldTarget.ClientCredentials.Windows.ClientCredential = new NetworkCredential(this.User, this.PassWord, this.Domain);

            Guid cfUid = Guid.NewGuid();

            foreach (DataRow item in RowField.Rows)
            {
                SvcCustomFields.CustomFieldDataSet.CustomFieldsRow cfRow = cfDS.CustomFields.NewCustomFieldsRow();

                foreach (DataColumn itemColumn in RowField.Columns)
                {
                    if (!cfDS.CustomFields.Columns.Contains(itemColumn.ToString()))
                    {
                        continue;
                    }

                    if (itemColumn.ToString() == "MD_LOOKUP_TABLE_UID" && lookupTable != string.Empty)
                    {
                        var  lt     = GetLookupTable(target).Tables[0].Select("LT_NAME ='" + lookupTable + "'").CopyToDataTable();
                        Guid lt_Uid = Guid.Parse(lt.Rows[0]["LT_UID"].ToString());
                        cfRow[itemColumn.ToString()] = lt_Uid;
                        continue;
                    }

                    if (itemColumn.ToString().Equals("MD_PROP_UID"))
                    {
                        cfRow[itemColumn.ToString()] = cfUid;
                        continue;
                    }

                    if (itemColumn.ToString().Equals("MD_PROP_DEFAULT_VALUE"))
                    {
                        continue;
                    }

                    if (item[itemColumn.ToString()] != null && !itemColumn.ReadOnly)
                    {
                        cfRow[itemColumn.ToString()] = item[itemColumn.ToString()];
                    }
                }
                cfDS.CustomFields.Rows.Add(cfRow);
            }

            try
            {
                bool validateOnly = false;
                bool autoCheckIn  = true;
                fieldTarget.CreateCustomFields(cfDS, validateOnly, autoCheckIn);
            }
            catch (SoapException ex)
            {
                string errMess = "";
                PSLibrary.PSClientError psiError  = new PSLibrary.PSClientError(ex);
                PSLibrary.PSErrorInfo[] psiErrors = psiError.GetAllErrors();

                for (int j = 0; j < psiErrors.Length; j++)
                {
                    errMess += psiErrors[j].ErrId.ToString() + "\n";
                }
                errMess += "\n" + ex.Message.ToString();
                throw ex;
            }
        }
コード例 #13
0
ファイル: TaskItemRepository.cs プロジェクト: jgoodso2/PMMP
        private static IList<TaskItemGroup> GetupComingTasksData(DataTable tasksDataTable, FiscalUnit month, CustomFieldDataSet dataSet)
        {
            if (month.From == DateTime.MinValue && month.To == DateTime.MaxValue)
                return new List<TaskItemGroup>();

            FiscalUnit fiscalUnit = new FiscalUnit() { From = month.From, To = month.To.AddMonths(1) };

            Repository.Utility.WriteLog("GetupComingTasksData started", System.Diagnostics.EventLogEntryType.Information);
            int count = -1;
            int upComingTaskCount = 0;
            IList<TaskItemGroup> retVal = new List<TaskItemGroup>();

            TaskItemGroup taskData = new TaskItemGroup() { TaskItems = new List<TaskItem>() };
            IList<TaskItem> items = new List<TaskItem>();
            EnumerableRowCollection<DataRow> collection =

                tasksDataTable.AsEnumerable()
                .Where((t => t.Field<bool>("TASK_IS_SUMMARY") == false && t.Field<int>("TASK_PCT_COMP") < 100
                    && t.Field<DateTime?>("TASK_FINISH_DATE").HasValue && t.Field<DateTime?>("TASK_FINISH_DATE").Value.InCurrentFiscalMonth(fiscalUnit)
                       )).OrderBy(t => t.Field<int>("TASK_ID"));

            foreach (DataRow item in collection)
            {
                count++;
                upComingTaskCount++;
                TaskItem taskItem = BuildTaskItem("", item, dataSet);
                if (count == 10)
                {
                    retVal.Add(taskData);
                    taskData = new TaskItemGroup { TaskItems = new List<TaskItem>() };
                    count = -1;
                    taskData.TaskItems.Add(BuildTaskItem("", item, dataSet));
                }
                else
                {
                    taskData.TaskItems.Add(BuildTaskItem("", item, dataSet));
                }
            }

            if (count % 10 != 0)
            {
                retVal.Add(taskData);

            }
            Repository.Utility.WriteLog("GetupComingTasksData completed successfully", System.Diagnostics.EventLogEntryType.Information);
            return retVal;
        }
コード例 #14
0
ファイル: TaskItemRepository.cs プロジェクト: jgoodso2/PMMP
        private static Dictionary<string, IList<TaskItem>> GetChartsData(DataTable tasksDataTable, CustomFieldDataSet dataSet)
        {
            Repository.Utility.WriteLog("GetLateTasksData started", System.Diagnostics.EventLogEntryType.Information);
            Dictionary<string, IList<TaskItem>> chartsData = new Dictionary<string, IList<TaskItem>>();

            var chartTypes = tasksDataTable.AsEnumerable().Select(t => t.Field<string>("CUSTOMFIELD_DESC")).Distinct();
            foreach (string chartType in chartTypes)
            {
                if (!string.IsNullOrEmpty(chartType))
                {
                    foreach (string chartTypeItem in chartType.Split(",".ToCharArray()))
                    {
                        IList<TaskItem> items = new List<TaskItem>();
                        EnumerableRowCollection<DataRow> collection = tasksDataTable.AsEnumerable().Where(t => t.Field<string>("CUSTOMFIELD_DESC") != null && t.Field<string>("CUSTOMFIELD_DESC").Split(",".ToCharArray()).Contains(chartTypeItem)).OrderBy(t => t.Field<int>("TASK_ID")).OrderByDescending(t=>t.Field<int>("TASK_ID"));
                        foreach (DataRow item in collection)
                        {
                            TaskItem taskItem = BuildTaskItem("", item, dataSet);
                            items.Add(taskItem);
                        }
                        if (items.Count > 0)
                        {
                            if (!chartsData.ContainsKey(chartTypeItem))
                            {
                                chartsData.Add(chartTypeItem, items);
                            }
                        }
                    }
                }
            }
            Repository.Utility.WriteLog("GetChartsData completed successfully", System.Diagnostics.EventLogEntryType.Information);
            return chartsData;
        }
コード例 #15
0
        private static void PopulateListsToAddAndUpdate(SPList list, Hashtable newFields, CustomFieldDataSet customFieldDataSet, Hashtable updFields)
        {
            foreach (SPField field in list.Fields)
            {
                if (!newFields.Contains(field.InternalName))
                {
                    //Enterprise Fields
                    if (field.InternalName.Length > 3)
                    {
                        var fieldName = field.InternalName.Substring(3);
                        var temp      = 0;
                        if (int.TryParse(fieldName, out temp))
                        {
                            var customFieldsRows =
                                (CustomFieldDataSet.CustomFieldsRow[])customFieldDataSet.CustomFields.Select(
                                    string.Format("MD_PROP_ID={0}", fieldName));

                            if (customFieldsRows.Length > 0)
                            {
                                updFields.Add(field.Id, field.ShowInEditForm);
                            }
                        }
                    }
                }
                else
                {
                    try
                    {
                        updFields.Add(field.Id, newFields[field.InternalName].ToString());
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError("Exception Suppressed {0}", ex);
                    }
                    try
                    {
                        newFields.Remove(field.InternalName);
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError("Exception Suppressed {0}", ex);
                    }
                }
            }
        }
コード例 #16
0
        private void UpdatePublisherCheckPercentCompleteFive(int pubType, DateTime dtStart)
        {
            if (dtStart == null)
            {
                throw new ArgumentNullException(nameof(dtStart));
            }

            using (var pubSite = new SPSite(publishSiteUrl))
            {
                mySiteToPublish = pubSite.OpenWeb();

                pCf = new CustomFields
                {
                    Url = $"{mySite.Url}/_vti_bin/psi/customfields.asmx",
                    UseDefaultCredentials = true
                };
                cfDs = new CustomFieldDataSet();

                psiLookupTable = new LookupTable
                {
                    Url = $"{mySite.Url}/_vti_bin/psi/lookuptable.asmx",
                    UseDefaultCredentials = true
                };

                pResource = new Resource
                {
                    Url = $"{mySite.Url}/_vti_bin/psi/resource.asmx",
                    UseDefaultCredentials = true
                };

                pService = new Project
                {
                    Url = $"{mySite.Url}/_vti_bin/psi/project.asmx",
                    UseDefaultCredentials = true
                };

                Statusing = new Statusing
                {
                    Url = $"{mySite.Url}/_vti_bin/psi/statusing.asmx",
                    UseDefaultCredentials = true
                };

                pWssInterop = new WssInterop
                {
                    Url = $"{mySite.Url}/_vti_bin/psi/wssinterop.asmx",
                    UseDefaultCredentials = true
                };

                linkProjectWss();

                var          trackingGuid = Guid.NewGuid();
                const string Lcid         = "1033";
                StatusingDerived.SetImpersonationContext(true, contextInfo.UserName, contextInfo.UserGuid, trackingGuid, contextInfo.SiteGuid, Lcid);

                workspaceSynch = new ProjectWorkspaceSynch(mySiteGuid, publishSiteUrl, projectGuid, contextInfo.UserName);
                workspaceSynch.setUpGroups();
                workspaceSynch.processTaskCenter();
                workspaceSynch.processProjectCenter();
                workspaceSynch.processResources();

                using (var sqlCommand1 = new SqlCommand(
                           "UPDATE publishercheck set percentcomplete=5,laststatusdate=getdate() where projectguid=@projectguid",
                           cn))
                {
                    sqlCommand1.Parameters.AddWithValue("@projectguid", eventArgs.ProjectGuid);
                    sqlCommand1.ExecuteNonQuery();
                }

                loadFields();

                LoadCurrentTasks(pubType, dtStart);
            }
        }
コード例 #17
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (!SPContext.Current.Web.Users[HttpContext.Current.User.Identity.Name].IsSiteAdmin)
            //if (!SPContext.Current.Web.Users[SPContext.Current.Web.CurrentUser.LoginName].IsSiteAdmin)
            if (!SPContext.Current.Web.UserIsSiteAdmin)
            {
                Response.Redirect(SPContext.Current.Site.Url + "/_layouts/accessdenied.aspx");
            }

            //Guid siteGuid = SPContext.Current.Site.ID;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                try
                {
                    if (!IsPostBack)
                    {
                        using (var connection = new SqlConnection(EPMLiveCore.CoreFunctions.getConnectionString(SPContext.Current.Site.WebApplication.Id)))
                        {
                            connection.Open();

                            if (Request[TypeParameter] == Type1 || Request[TypeParameter] == Type2)
                            {
                                if (Request["pj"] == Type1)
                                {
                                    using (var command = new SqlCommand("SELECT fieldname,displayname from customfields where fieldcategory=@type and pjvisible=0 order by displayname", connection))
                                    {
                                        command.Parameters.AddWithValue("@type", Request[TypeParameter]);

                                        using (var adapter = new SqlDataAdapter(command))
                                        {
                                            var dataSet = new DataSet();
                                            adapter.Fill(dataSet);

                                            ListBox1.DataSource     = dataSet.Tables[0];
                                            ListBox1.DataTextField  = "displayname";
                                            ListBox1.DataValueField = "fieldname";
                                            ListBox1.DataBind();
                                        }
                                    }
                                }
                                else
                                {
                                    using (var command = new SqlCommand("SELECT fieldname,displayname from customfields where fieldcategory=@type and visible=0 order by displayname", connection))
                                    {
                                        command.Parameters.AddWithValue("@type", Request[TypeParameter]);

                                        using (var adapter = new SqlDataAdapter(command))
                                        {
                                            var dataSet = new DataSet();
                                            adapter.Fill(dataSet);

                                            ListBox1.DataSource     = dataSet.Tables[0];
                                            ListBox1.DataTextField  = "displayname";
                                            ListBox1.DataValueField = "fieldname";
                                            ListBox1.DataBind();
                                        }
                                    }
                                }
                            }
                            else if (Request[TypeParameter] == "3")
                            {
                                string modifier = "";
                                if (Request["pj"] == Type1)
                                {
                                    modifier = " pjvisible = 1";
                                }
                                else
                                {
                                    modifier = " visible = 1";
                                }

                                CustomFields cf          = new CustomFields();
                                cf.Url                   = SPContext.Current.Site.Url + "/_vti_bin/PSI/customfields.asmx";
                                cf.UseDefaultCredentials = true;

                                CustomFieldDataSet dsF = cf.ReadCustomFieldsByEntity(new Guid(PSLibrary.EntityCollection.Entities.TaskEntity.UniqueId));
                                for (int i = 0; i < dsF.CustomFields.Count; i++)
                                {
                                    CustomFieldDataSet.CustomFieldsRow customField = dsF.CustomFields[i];

                                    using (var command = new SqlCommand("SELECT fieldname from customfields where fieldname=@fieldname and " + modifier, connection))
                                    {
                                        command.Parameters.AddWithValue("@fieldname", customField.MD_PROP_ID.ToString());
                                        using (var reader = command.ExecuteReader())
                                        {
                                            if (!reader.Read())
                                            {
                                                var table = string.Empty;
                                                try
                                                {
                                                    table = customField.MD_LOOKUP_TABLE_UID.ToString();
                                                }
                                                catch (Exception ex)
                                                {
                                                    SystemTrace.WriteLine(ex.ToString());
                                                }
                                                var cfData = string.Empty;
                                                var choice = "CHOICE";
                                                if (table == string.Empty)
                                                {
                                                    choice = ((PSLibrary.PropertyType)customField.MD_PROP_TYPE_ENUM).ToString();
                                                }

                                                if (customField.IsMD_PROP_FORMULANull())
                                                {
                                                    cfData = $"{customField.MD_PROP_ID}#{choice}#{customField.MD_PROP_UID_SECONDARY}#{customField.MD_PROP_UID_SECONDARY}";
                                                }
                                                else
                                                {
                                                    cfData = customField.MD_PROP_ID + "#" + choice + "#" + customField.MD_PROP_UID_SECONDARY + "#";
                                                }

                                                var listItem = new ListItem(customField.MD_PROP_NAME, cfData);
                                                ListBox1.Items.Add(listItem);
                                            }
                                        }
                                    }
                                }
                            }
                            else if (Request[TypeParameter] == "4")
                            {
                                string modifier = string.Empty;
                                if (Request["pj"] == Type1)
                                {
                                    modifier = " pjvisible = 1";
                                }
                                else
                                {
                                    modifier = " visible = 1";
                                }

                                var cf = new CustomFields();
                                cf.Url = SPContext.Current.Site.Url + "/_vti_bin/PSI/customfields.asmx";
                                cf.UseDefaultCredentials = true;

                                CustomFieldDataSet dsF = cf.ReadCustomFieldsByEntity(new Guid(PSLibrary.EntityCollection.Entities.ProjectEntity.UniqueId));
                                for (int i = 0; i < dsF.CustomFields.Count; i++)
                                {
                                    CustomFieldDataSet.CustomFieldsRow customField = dsF.CustomFields[i];

                                    using (var command = new SqlCommand("SELECT fieldname from customfields where fieldname=@fieldname and " + modifier, connection))
                                    {
                                        command.Parameters.AddWithValue("@fieldname", customField.MD_PROP_ID.ToString());

                                        using (var reader = command.ExecuteReader())
                                        {
                                            if (!reader.Read())
                                            {
                                                var table = string.Empty;
                                                try
                                                {
                                                    table = customField.MD_LOOKUP_TABLE_UID.ToString();
                                                }
                                                catch (Exception ex)
                                                {
                                                    SystemTrace.WriteLine(ex.ToString());
                                                }
                                                var cfData = string.Empty;
                                                if (table == string.Empty)
                                                {
                                                    cfData = customField.MD_PROP_ID + "#" + ((PSLibrary.PropertyType)customField.MD_PROP_TYPE_ENUM).ToString() + "##";
                                                }
                                                else
                                                {
                                                    cfData = customField.MD_PROP_ID + "#CHOICE##";
                                                }

                                                var listItem = new ListItem(customField.MD_PROP_NAME, cfData);
                                                ListBox1.Items.Add(listItem);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                    SystemTrace.WriteLine(ex.ToString());
                }
            });
        }