Ejemplo n.º 1
0
    public static void CreateNoteColumn(this SPWeb web, string group, string description, string name, string displayName, int numberOfLines, bool richText = true)
    {
        try
        {
            if (!web.Fields.ContainsField(name))
            {
                string fieldName = web.Fields.Add(name, SPFieldType.Note, false);

                SPFieldMultiLineText field = (SPFieldMultiLineText)web.Fields.GetField(name);

                field.Group         = group;
                field.RichText      = richText;
                field.NumberOfLines = numberOfLines;
                field.StaticName    = name;
                field.Title         = displayName;
                field.NoCrawl       = false;
                field.Description   = description;

                field.Update();
            }
        }
        catch (Exception ex)
        {
            SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("CORE:HELPERS", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, String.Format("Exception happened in Helpers:CreateNoteColumn. MESSAGE: {0}. EXCEPTION TRACE: {1} ", ex.Message, ex.StackTrace), ex.StackTrace);
        }
    }
Ejemplo n.º 2
0
        public ArtDevField CreateFieldMultiLineText(string Name)
        {
            SPFieldMultiLineText Field       = NewOrRefMultiLineText(Name);
            ArtDevField          ArtDevField = new ArtDevField(Field);

            return(ArtDevField);
        }
Ejemplo n.º 3
0
        public SPFieldMultiLineText NewOrRefMultiLineText(string Name)
        {
            string NoteName = this.Web().Fields.ContainsField(Name) ? Name : this.Web().Fields.Add(Name, SPFieldType.Note, false);
            SPFieldMultiLineText NoteField = (SPFieldMultiLineText)this.Web().Fields.GetFieldByInternalName(NoteName);

            NoteField.Group = this.columnGroup;
            return(NoteField);
        }
Ejemplo n.º 4
0
        protected void AddRichTexField(String FieldName, Boolean Required)
        {
            String RichTextFieldName           = List.Fields.Add(FieldName, SPFieldType.Note, Required);
            SPFieldMultiLineText RichTextField = (SPFieldMultiLineText)List.Fields.GetFieldByInternalName(RichTextFieldName);

            RichTextField.RichText     = true;
            RichTextField.RichTextMode = SPRichTextMode.FullHtml;
            RichTextField.Update();
        }
Ejemplo n.º 5
0
 public override void AddFieldTo(SPFieldCollection fieldCollection)
 {
     AddFieldTo(fieldCollection, f =>
     {
         SPFieldMultiLineText field = (SPFieldMultiLineText)f;
         field.AppendOnly           = AppendOnly;
         field.RichText             = RichText;
         field.RichTextMode         = RichTextMode;
     });
 }
        private void LoadData(SPListItemCollection currentUserDetails)
        {
            DataTable leavetable = LeavestableStructure();

            if (currentUserDetails.Count > 0)
            {
                foreach (SPListItem spListItem in currentUserDetails)
                {
                    DataRow dataRow = leavetable.NewRow();

                    var requestedto = new SPFieldLookupValue(spListItem["RequestedTo"].ToString());

                    dataRow["Requested To"] = requestedto.LookupValue;

                    var requestedFrom = new SPFieldLookupValue(spListItem["RequestedFrom"].ToString());

                    dataRow["Requested From"] = requestedFrom.LookupValue;
                    dataRow["Leave Type"]     = spListItem[Utilities.LeaveType].ToString();
                    dataRow["Starting Date"]  =
                        DateTime.Parse(spListItem[Utilities.StartingDate].ToString()).ToShortDateString();
                    dataRow["Ending Date"] =
                        DateTime.Parse(spListItem[Utilities.EndingDate].ToString()).ToShortDateString();
                    dataRow["Leave Days"] = spListItem[Utilities.LeaveDays].ToString();
                    if (spListItem[Utilities.Remarks] != null)
                    {
                        dataRow["Remarks"] = spListItem[Utilities.Remarks].ToString();
                    }
                    dataRow["Status"] = spListItem[Utilities.Status].ToString();
                    if (spListItem["Purpose of Leave"] != null)
                    {
                        SPFieldMultiLineText mlt = spListItem.Fields.GetField("Purpose of Leave") as SPFieldMultiLineText;

                        dataRow["Reason"] = mlt.GetFieldValueAsText(spListItem["Purpose of Leave"]);
                    }
                    string url = "'" + SPContext.Current.Site.Url + "/Pages/CancelLeaves.aspx?LeaveId=" + spListItem.ID + "'";
                    if (spListItem[Utilities.Status].ToString() == "Approved")
                    {
                        dataRow["Cancel"] = "<a href=\"JavaScript:openDialog(" + url + ");\">Cancel</a>";
                    }
                    leavetable.Rows.Add(dataRow);
                }
            }


            DataView dataView = new DataView(leavetable);

            dataView.Sort = "Starting Date DESC";

            ViewState["Result"] = dataView.Table;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Bind timsheet details
        /// </summary>
        /// <param name="timesheetId"></param>
        private void BindTimesheetData(int timesheetId)
        {
            try
            {
                using (SPSite site = new SPSite(SPContext.Current.Site.Url))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        TimesheetRespository objRepository = new TimesheetRespository();
                        SPListItem           item          = objRepository.GetListItemById(web, Constants.TimesheetListName, timesheetId);
                        if (item != null)
                        {
                            lblCategory.Text    = Convert.ToString(item["Category"]);
                            lblDescription.Text = Convert.ToString(item["Description"]);
                            lblDate.Text        = Convert.ToDateTime(item["TimesheetDate"]).ToString("yyyy-MM-dd");
                            lblHours.Text       = Convert.ToString(item["Hours"]);

                            SPFieldMultiLineText multilineField = item.Fields.GetField("Description") as SPFieldMultiLineText;
                            if (multilineField != null)
                            {
                                txtDescription.Text = multilineField.GetFieldValueAsText(item["Description"]);
                            }
                            ddlCategory.ClearSelection();
                            if (ddlCategory.Items.FindByValue(Convert.ToString(item["Category"])) != null)
                            {
                                ddlCategory.Items.FindByValue(Convert.ToString(item["Category"])).Selected = true;
                            }
                            dtDate.SelectedDate = Convert.ToDateTime(item["TimesheetDate"]);
                            txtHours.Text       = Convert.ToString(item["Hours"]);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Common.HandleException(ex, SPContext.Current.Web.Url, "BindTimesheetData", "ManageTimesheetUserControl", SPContext.Current.Web.CurrentUser.Name);
                lblMsg.Text = Constants.ErrorMsg;
            }
        }
Ejemplo n.º 8
0
        private void LoadLeaveDetails()
        {
            try
            {
                DataTable leavetable = LeavestableStructure();

                using (var site = new SPSite(SPContext.Current.Site.Url))
                {
                    using (var web = site.OpenWeb())
                    {
                        var leaveList = web.Lists.TryGetList(Utilities.LeaveRequest);
                        if (leaveList != null)
                        {
                            SPUser user        = web.CurrentUser;
                            string currentUser = user.Name;
                            SPListItemCollection currentUserDetails;
                            currentUserDetails = GetListItemCollection(leaveList, "RequestedFrom",
                                                                       currentUser, "Employee Status", "Active");

                            if (currentUserDetails.Count > 0)
                            {
                                foreach (SPListItem spListItem in currentUserDetails)
                                {
                                    DataRow dataRow = leavetable.NewRow();

                                    var requestedto = new SPFieldLookupValue(spListItem["RequestedTo"].ToString());

                                    dataRow["Requested To"] = requestedto.LookupValue;

                                    var requestedFrom = new SPFieldLookupValue(spListItem["RequestedFrom"].ToString());

                                    dataRow["Requested From"] = requestedFrom.LookupValue;
                                    dataRow["Leave Type"]     = spListItem[Utilities.LeaveType].ToString();
                                    dataRow["Starting Date"]  =
                                        DateTime.Parse(spListItem[Utilities.StartingDate].ToString()).ToShortDateString();
                                    dataRow["Ending Date"] =
                                        DateTime.Parse(spListItem[Utilities.EndingDate].ToString()).ToShortDateString();
                                    dataRow["Leave Days"] = spListItem[Utilities.LeaveDays].ToString();
                                    if (spListItem[Utilities.Remarks] != null)
                                    {
                                        dataRow["Remarks"] = spListItem[Utilities.Remarks].ToString();
                                    }
                                    dataRow["Status"] = spListItem[Utilities.Status].ToString();
                                    if (spListItem["Purpose of Leave"] != null)
                                    {
                                        SPFieldMultiLineText mlt = spListItem.Fields.GetField("Purpose of Leave") as SPFieldMultiLineText;

                                        dataRow["Reason"] = mlt.GetFieldValueAsText(spListItem["Purpose of Leave"]);
                                    }

                                    leavetable.Rows.Add(dataRow);
                                }
                            }


                            DataView dataView = new DataView(leavetable);
                            dataView.Sort = "Starting Date DESC";

                            ViewState["Result"] = dataView.Table;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                lblErr.Text = ex.Message;
            }
        }
Ejemplo n.º 9
0
        //Create Site Columns
        public void CreateSiteColumns()
        {
            using (SPWeb oSPWeb = oSPSite.RootWeb)
            {
                try
                {
                    //if (!oSPWeb.Fields.ContainsField("Codigo"))
                    //{

                    //Codigo de Documento
                    string      codigoField = oSPWeb.Fields.Add("Codigo", SPFieldType.Text, false);
                    SPFieldText Codigo      = (SPFieldText)oSPWeb.Fields.GetFieldByInternalName(codigoField);
                    Codigo.Group = groupColumn;
                    Codigo.Update();
                    //}

                    //if (!oSPWeb.Fields.ContainsField("Referencia"))
                    //{
                    string      referenciaField = oSPWeb.Fields.Add("Referencia", SPFieldType.Text, false);
                    SPFieldText Referencia      = (SPFieldText)oSPWeb.Fields.GetFieldByInternalName(referenciaField);
                    Referencia.Group = groupColumn;
                    Referencia.Update();
                    //}

                    //if (!oSPWeb.Fields.ContainsField("Comentario")) {
                    string      comentarioField = oSPWeb.Fields.Add("Comentario", SPFieldType.Text, false);
                    SPFieldText Comentario      = (SPFieldText)oSPWeb.Fields.GetFieldByInternalName(comentarioField);
                    Comentario.Group = groupColumn;
                    Comentario.Update();
                    //}


                    //if (!oSPWeb.Fields.ContainsField("Remitente"))
                    //{
                    string      remitenteField = oSPWeb.Fields.Add("Remitente", SPFieldType.Text, false);
                    SPFieldText Remitente      = (SPFieldText)oSPWeb.Fields.GetFieldByInternalName(remitenteField);
                    Remitente.Group = groupColumn;
                    Remitente.Update();

                    //}

                    //if (!oSPWeb.Fields.ContainsField("Factura")) {
                    string        facturaField = oSPWeb.Fields.Add("Factura", SPFieldType.Number, false);
                    SPFieldNumber Factura      = (SPFieldNumber)oSPWeb.Fields.GetFieldByInternalName(facturaField);
                    Factura.Group = groupColumn;
                    Factura.Update();
                    //}


                    //if (!oSPWeb.Fields.ContainsField("Fecha Receopcion")) {
                    string          fechaRecepcionField = oSPWeb.Fields.Add("Fecha Recepcion", SPFieldType.DateTime, true);
                    SPFieldDateTime FechaRecepcion      = (SPFieldDateTime)oSPWeb.Fields.GetFieldByInternalName(fechaRecepcionField);
                    FechaRecepcion.Group = groupColumn;
                    FechaRecepcion.Update();

                    //}

                    //Method 3 using Field schema
                    //if (!oSPWeb.Fields.ContainsField("Nota"))
                    //{
                    string notaField          = oSPWeb.Fields.Add("Nota", SPFieldType.Note, false);
                    SPFieldMultiLineText Nota = (SPFieldMultiLineText)oSPWeb.Fields.GetFieldByInternalName(notaField);
                    Nota.Group = groupColumn;
                    Nota.Update();
                    //}

                    //if (!oSPWeb.Fields.ContainsField("Gerencias"))
                    //{

                    // Lookup Column
                    SPList gerenciasList = oSPWeb.Lists.TryGetList("Gerencias");

                    string        GerenciaField  = oSPWeb.Fields.AddLookup("Gerencia", gerenciasList.ID, true);
                    SPFieldLookup gerenciaLookup = (SPFieldLookup)oSPWeb.Fields.GetFieldByInternalName(GerenciaField);

                    gerenciaLookup.Group       = groupColumn;
                    gerenciaLookup.LookupField = "Title";
                    gerenciaLookup.Update();
                    //}

                    SPList listas = oSPWeb.Lists.TryGetList("Listas");
                    //if (!oSPWeb.Fields.ContainsField("Nivel Prioridad"))
                    //{

                    string        nivelPrioridadField  = oSPWeb.Fields.AddLookup("Nivel Prioridad", listas.ID, true);
                    SPFieldLookup nivelPrioridadLookup = (SPFieldLookup)oSPWeb.Fields.GetFieldByInternalName(nivelPrioridadField);
                    nivelPrioridadLookup.Group       = groupColumn;
                    nivelPrioridadLookup.LookupField = "Title";
                    nivelPrioridadLookup.Update();
                    //}

                    //if (!oSPWeb.Fields.ContainsField("Clasificacion"))
                    //{

                    string        clasificacionField  = oSPWeb.Fields.AddLookup("Clasificacion", listas.ID, true);
                    SPFieldLookup clasificacionLookup = (SPFieldLookup)oSPWeb.Fields.GetFieldByInternalName(clasificacionField);
                    clasificacionLookup.Group       = groupColumn;
                    clasificacionLookup.LookupField = "Title";
                    clasificacionLookup.Update();
                    //}

                    //if (!oSPWeb.Fields.ContainsField("Estado"))
                    //{

                    string        estadoField  = oSPWeb.Fields.AddLookup("Estado", listas.ID, false);
                    SPFieldLookup estadoLookup = (SPFieldLookup)oSPWeb.Fields.GetFieldByInternalName(estadoField);
                    estadoLookup.Group       = groupColumn;
                    estadoLookup.LookupField = "Title";
                    estadoLookup.Update();
                    //}
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Ejemplo n.º 10
0
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWeb  web  = (SPWeb)properties.Feature.Parent;
            SPSite site = web.Site;

            web.AllowUnsafeUpdates = true;
            Lists listRoot = GetListsInfo(properties);

            foreach (List listInfo in listRoot.Items)
            {
                SPList tempList = null;
                if (listInfo.name != null)
                {
                    listName = listInfo.name.Trim();
                }
                else
                {
                    throw new Exception(Constants.LIST_NAME_ERROR);
                }
                descName = listInfo.description;
                if (CheckList(web, listName))
                {
                    tempList = web.Lists[web.Lists.Add(listName, descName, SPListTemplateType.GenericList)];
                }
                else
                {
                    tempList = web.Lists[listName];
                }
                if (tempList != null)
                {
                    foreach (Field fields in listInfo.Fields)
                    {
                        SPFieldType fldType = SPFieldType.Text;
                        ClearFlags();

                        if (fields.name != null)
                        {
                            fieldname = fields.name.Trim();
                        }
                        else
                        {
                            throw new Exception(Constants.FIELD_NAME_ERROR + listName);
                        }

                        if (fields.datatype != null)
                        {
                            fieldtype = fields.datatype.Trim();
                        }

                        if (fields.required != null)
                        {
                            required = fields.required.Trim();
                        }

                        if (fields.defaultvalue != null)
                        {
                            defaultValue = fields.defaultvalue.Trim();
                        }

                        if (fields.textformat != null)
                        {
                            textFormat = fields.textformat.Trim();
                        }

                        if (fields.displaychoicesusing != null)
                        {
                            displayChoicesUsing = fields.displaychoicesusing.Trim();
                        }

                        if (fields.lookuplist != null)
                        {
                            lookupList = fields.lookuplist.Trim();
                        }

                        if (fields.lookupfield != null)
                        {
                            lookupfield = fields.lookupfield.Trim();
                        }

                        switch (fieldtype.ToLower())
                        {
                        case Constants.SINGLE_LINE_TEXT_TYPE:
                            fldType = SPFieldType.Text;
                            break;

                        case Constants.MULTIPLE_LINE_TEXT_TYPE:
                            fldType = SPFieldType.Note;
                            break;

                        case Constants.DATETIME_TYPE:
                            fldType = SPFieldType.DateTime;
                            break;

                        case Constants.NUMBER_TYPE:
                            fldType = SPFieldType.Number;
                            break;

                        case Constants.CURRENCY_TYPE:
                            fldType = SPFieldType.Currency;
                            break;

                        case Constants.YESNO_TYPE:
                            fldType = SPFieldType.Boolean;
                            break;

                        case Constants.PERSON_GROUP_TYPE:
                            fldType = SPFieldType.User;
                            break;

                        case Constants.HYPERLINK_PICTURE_TYPE:
                            fldType = SPFieldType.URL;
                            break;

                        case Constants.CHOICE_TYPE:
                            if (displayChoicesUsing.ToLower().Trim().Equals(Constants.MULTICHECKBOX))
                            {
                                fldType = SPFieldType.MultiChoice;
                            }
                            else
                            {
                                fldType = SPFieldType.Choice;
                            }
                            break;

                        case Constants.LOOKUP_TYPE:
                            fldType = SPFieldType.Lookup;
                            break;
                        }

                        SPField field = tempList.Fields.CreateNewField(fldType.ToString(), fieldname);
                        field.DefaultValue = defaultValue;
                        field.Description  = fielddesc;
                        field.Required     = (required.ToLower().Trim().Equals(Constants.YES) ? true : false);

                        if (!tempList.Fields.ContainsField(fieldname))
                        {
                            tempList.Fields.Add(field);
                        }

                        if ((tempList.Fields[fieldname] as SPFieldText) != null)
                        {
                            int maxLength;
                            int.TryParse(maxCount, out maxLength);
                            var fldText = tempList.Fields[fieldname] as SPFieldText;

                            if (fldText != null && maxLength > 0)
                            {
                                fldText.MaxLength = maxLength;
                                fldText.Update();
                                tempList.Update();
                            }

                            continue;
                        }

                        if ((tempList.Fields[fieldname] as SPFieldMultiLineText) != null)
                        {
                            int noOfLines;
                            int.TryParse(NoOfLines, out noOfLines);
                            SPFieldMultiLineText fldMultiText = tempList.Fields[fieldname] as SPFieldMultiLineText;
                            fldMultiText.NumberOfLines = (noOfLines > 0) ? noOfLines : fldMultiText.NumberOfLines;
                            fldMultiText.RichText      = (textFormat.ToLower().Trim().Equals(Constants.RICHTEXT)) ? true : false;
                            fldMultiText.Update();
                            tempList.Update();

                            continue;
                        }

                        if ((tempList.Fields[fieldname] as SPFieldBoolean) != null)
                        {
                            SPFieldBoolean fldBoolean = (tempList.Fields[fieldname]) as SPFieldBoolean;
                            // useful in future
                            tempList.Update();

                            continue;
                        }

                        if ((tempList.Fields[fieldname] as SPFieldUser) != null)
                        {
                            SPFieldUser fldUser = tempList.Fields[fieldname] as SPFieldUser;
                            // useful in future
                            tempList.Update();

                            continue;
                        }

                        if (tempList.Fields[fieldname] as SPFieldMultiChoice != null)
                        {
                            SPFieldMultiChoice fldMultiChoice = tempList.Fields[fieldname] as SPFieldMultiChoice;

                            foreach (Choice choiceNodes in fields.Choices)
                            {
                                fldMultiChoice.Choices.Add(choiceNodes.Value);
                            }
                            fldMultiChoice.Update();
                            tempList.Update();

                            continue;
                        }

                        if ((tempList.Fields[fieldname] as SPFieldChoice) != null)
                        {
                            SPFieldChoice fldChoice = tempList.Fields[fieldname] as SPFieldChoice;

                            if (displayChoicesUsing.ToLower().Trim().Equals(Constants.DROPDOWNMENU))
                            {
                                fldChoice.EditFormat = SPChoiceFormatType.Dropdown;
                            }

                            if (displayChoicesUsing.ToLower().Trim().Equals(Constants.RADIOBUTTONS))
                            {
                                fldChoice.EditFormat = SPChoiceFormatType.RadioButtons;
                            }

                            // Add the choices
                            foreach (Choice choiceNodes in fields.Choices)
                            {
                                fldChoice.Choices.Add(choiceNodes.Value);
                            }
                            fldChoice.Update();
                            tempList.Update();

                            continue;
                        }

                        if ((tempList.Fields[fieldname] as SPFieldLookup) != null)
                        {
                            SPFieldLookup fldLookup  = tempList.Fields[fieldname] as SPFieldLookup;
                            SPList        parentList = web.Lists[lookupList];
                            fldLookup.LookupList  = parentList.ID.ToString();
                            fldLookup.LookupField = parentList.Fields[lookupfield].InternalName;
                            fldLookup.Update();
                            tempList.Update();

                            continue;
                        }
                    }
                }
            }
            web.Update();
            web.AllowUnsafeUpdates = true;
        }
Ejemplo n.º 11
0
        public static SPList CreateList(SPWeb web, string listName, string description, string displayName, string templateName)
        {
            SPList list = web.Lists.TryGetList(listName);

            try
            {
                if (list == null)
                {
                    web.AllowUnsafeUpdates = true;

                    var lstTemp = web.Site.GetCustomListTemplates(web);

                    var template = lstTemp[templateName];

                    var listId = web.Lists.Add(listName, description, template);

                    list       = web.Lists[listId];
                    list.Title = listName;

                    if (listName.Equals("BreakThroughProcertProjectsTracking"))
                    {
                        string[] colName = { "Bacground Attachments", "Problem Attachments", "ProjectMetrics Attachments", "Benifits Attachments", "Costs Attachments", "Financial Attachments", "Milestones Attachments", "Define Attachments", "Measure Attachments", "Analyze Attachments", "Investigate Attachments", "Control Attachments", "FinalReport Attachments" };

                        for (int i = 0; i < colName.Length; i++)
                        {
                            SPFieldMultiLineText multiLineField = (SPFieldMultiLineText)list.Fields.CreateNewField(
                                SPFieldType.Note.ToString(), colName[i]);
                            multiLineField.RichText          = true;
                            multiLineField.RichTextMode      = SPRichTextMode.FullHtml;
                            multiLineField.ShowInEditForm    = false;
                            multiLineField.ShowInNewForm     = false;
                            multiLineField.ShowInDisplayForm = true;
                            multiLineField.ShowInViewForms   = true;
                            SPFieldCollection fields = list.Fields;
                            if (!fields.ContainsField(colName[i]))
                            {
                                list.Fields.Add(multiLineField);
                            }
                            list.Update();
                            //int viewsCount = list.Views.Count;
                            //for (int j = 0; j < viewsCount; j++)
                            //{
                            //    SPView view = list.Views[j];
                            //    if (!view.ViewFields.Exists(colName[j]))
                            //    {
                            //        view.ViewFields.Add(list.Fields[colName[i]]);
                            //        view.Update();
                            //    }
                            //}
                        }
                    }


                    list.Update();
                    if (listName.Equals("BreakThroughProcertProjectsTracking"))
                    {
                        AddCustomAction(list, "HideProperties");
                        SPFieldCollection Tagfields  = list.Fields;
                        string[]          TagcolName = { "Tags" };
                        if (!Tagfields.ContainsField(TagcolName[0]))
                        {
                            TaxonomySession taxonomySession = new TaxonomySession(SPContext.Current.Site);
                            TermStore       termStore       = taxonomySession.TermStores["Managed Metadata Service"];
                            termStore = taxonomySession.DefaultSiteCollectionTermStore;
                            Group   GroupTerm = termStore.CreateGroup("BreakThroughProcertProjectsTracking");
                            TermSet termset   = GroupTerm.CreateTermSet("Tags");
                            termStore.CommitAll();
                            TaxonomyField taxonomyField = list.Fields.CreateNewField("TaxonomyFieldType", "Tags") as TaxonomyField;
                            taxonomyField.AllowMultipleValues = true;
                            list.Fields.Add(taxonomyField);
                            TaxonomyField field = list.Fields["Tags"] as TaxonomyField;
                            field.Title = "Tags";
                            field.Update(true);
                            taxonomyField.SspId = termset.Id;
                            field.Update(true);
                        }
                    }

                    list.Update();
                    web.AllowUnsafeUpdates = false;
                }
            }

            catch (Exception ex)
            {
                //  ULSLogger.LogErrorInULS(ex.Message, TraceSeverity.Unexpected);
            }

            return(list);
        }
Ejemplo n.º 12
0
        private SPList EnsureGlymaExportsList()
        {
            bool   isNewList = false;
            SPList list      = Site.EnsureList(GlymaLists.GlymaExportsList, ref isNewList);

            SPField titleColumn = list.Fields[SPBuiltInFieldId.Title];

            titleColumn.Indexed             = true;
            titleColumn.Title               = "WorkItem ID";
            titleColumn.EnforceUniqueValues = true;
            titleColumn.Update();

            bool    isNewColumn  = false;
            SPField exportStatus = list.EnsureColumn(GlymaColumns.ExportStatus, false, ref isNewColumn);

            exportStatus.Required = true;
            exportStatus.Update();

            isNewColumn = false;
            SPField exportType = list.EnsureColumn(GlymaColumns.ExportType, false, ref isNewColumn);

            exportType.Required = true;
            exportType.Update();

            isNewColumn = false;
            SPField mapType = list.EnsureColumn(GlymaColumns.MapType, false, ref isNewColumn);

            mapType.Required = true;
            mapType.Update();

            isNewColumn = false;
            SPField       percentageCompletedField = list.EnsureColumn(GlymaColumns.PercentageComplete, false, ref isNewColumn);
            SPFieldNumber percentComplete          = percentageCompletedField as SPFieldNumber;

            percentComplete.Required         = true;
            percentComplete.ShowAsPercentage = true;
            percentComplete.MaximumValue     = 1;
            percentComplete.MinimumValue     = 0;
            percentComplete.Update();

            isNewColumn = false;
            SPField domainUid = list.EnsureColumn(GlymaColumns.DomainUid, false, ref isNewColumn);

            domainUid.Required = true;
            domainUid.Update();

            isNewColumn = false;
            SPField rootMapUid = list.EnsureColumn(GlymaColumns.RootMapUid, false, ref isNewColumn);

            rootMapUid.Required = true;
            rootMapUid.Update();

            isNewColumn = false;
            SPField exportPropertiesField         = list.EnsureColumn(GlymaColumns.ExportProperties, false, ref isNewColumn);
            SPFieldMultiLineText exportProperties = exportPropertiesField as SPFieldMultiLineText;

            exportProperties.Required   = false;
            exportProperties.AppendOnly = false;
            exportProperties.RichText   = false;
            exportProperties.Update();

            isNewColumn = false;
            SPField logMessagesField         = list.EnsureColumn(GlymaColumns.LogMessages, false, ref isNewColumn);
            SPFieldMultiLineText logMessages = logMessagesField as SPFieldMultiLineText;

            logMessages.Required   = false;
            logMessages.AppendOnly = true;
            logMessages.RichText   = false;
            logMessages.Update();

            SPField lastModifiedField = list.Fields[SPBuiltInFieldId.Modified];

            // Configure the default view for the list.
            SPView defaultView = list.DefaultView;

            defaultView.ViewFields.DeleteAll();
            defaultView.ViewFields.Add(titleColumn);
            defaultView.ViewFields.Add(exportStatus);
            defaultView.ViewFields.Add(exportType);
            defaultView.ViewFields.Add(mapType);
            defaultView.ViewFields.Add(percentComplete);
            defaultView.ViewFields.Add(domainUid);
            defaultView.ViewFields.Add(rootMapUid);
            defaultView.ViewFields.Add(exportProperties);
            defaultView.ViewFields.Add(logMessages);
            defaultView.Query = "<OrderBy><FieldRef Name=\"" + lastModifiedField.InternalName + "\" Ascending=\"FALSE\" /></OrderBy>";
            defaultView.Update();

            return(list);
        }
Ejemplo n.º 13
0
 public static string GetRichTextMode(this SPFieldMultiLineText field)
 {
     return(field.RichTextMode.ToString());
 }
Ejemplo n.º 14
0
        public void LoadDetails()
        {
            try
            {
                using (var site = new SPSite(SPContext.Current.Site.Url))
                {
                    using (var web = site.OpenWeb())
                    {
                        var leavestatus = new DataTable();
                        leavestatus.Columns.Add("Id");
                        leavestatus.Columns.Add("RequestedFrom");
                        leavestatus.Columns.Add("Leave Type");
                        leavestatus.Columns.Add("Starting Date");
                        leavestatus.Columns.Add("Employee Type");
                        leavestatus.Columns.Add("Ending Date");
                        leavestatus.Columns.Add("Duration");
                        leavestatus.Columns.Add("Reason");
                        leavestatus.Columns.Add("Remarks");
                        leavestatus.Columns.Add("Status");
                        var emplist = web.Lists.TryGetList(Utilities.LeaveRequest);

                        if (emplist != null)
                        {
                            SPUser user = web.CurrentUser;

                            string currentUser = user.Name;
                            SPListItemCollection currentUserDetails;

                            if (IsMemberInGroup("Admin"))
                            {
                                currentUserDetails = GetListItemCollection(emplist, "Status", "Pending", "Year",
                                                                           hdnCurrentYear.Value, "Employee Status", "Active");
                            }
                            else
                            {
                                currentUserDetails = GetListItemCollection(emplist, "RequestedTo",
                                                                           currentUser, "Status", "Pending", "Year",
                                                                           hdnCurrentYear.Value, "Employee Status", "Active");
                            }
                            if (currentUserDetails.Count > 0)
                            {
                                foreach (SPListItem item in currentUserDetails)
                                {
                                    var spv = new SPFieldLookupValue(item["RequestedFrom"].ToString());

                                    DataRow dataRow = leavestatus.NewRow();
                                    dataRow["Id"]            = item.ID;
                                    dataRow["RequestedFrom"] = spv.LookupValue;//item["RequestedFrom"].ToString();
                                    dataRow["Leave Type"]    = item["Leave Type"].ToString();

                                    //dataRow["Applied Date"] = item["Starting Date"].ToString();
                                    dataRow["Starting Date"] = DateTime.Parse(item["Starting Date"].ToString()).ToShortDateString();
                                    dataRow["Ending Date"]   = DateTime.Parse(item["Ending Date"].ToString()).ToShortDateString();
                                    dataRow["Duration"]      = item["Leave Days"].ToString();

                                    if (item["Purpose of Leave"] != null)
                                    {
                                        SPFieldMultiLineText mlt = item.Fields.GetField("Purpose of Leave") as SPFieldMultiLineText;

                                        dataRow["Reason"] = mlt.GetFieldValueAsText(item["Purpose of Leave"]);
                                    }

                                    //dataRow["Reason"] = (item["Purpose of Leave"] == null) ? "" : item["Purpose of Leave"].ToString();
                                    dataRow["Remarks"] = (item["Remarks"] == null)
                                                             ? ""
                                                             : item["Remarks"].ToString();

                                    //dataRow["App/Rej by Remarks"] = item.ToString();
                                    dataRow["Status"] = item["Status"].ToString();

                                    leavestatus.Rows.Add(dataRow);
                                }
                            }
                            else
                            {
                                BtnApprove.Visible = false;
                                BtnReject.Visible  = false;
                                //  lblErr.Text = "No records found";
                            }
                        }

                        DataView dataView = new DataView(leavestatus);
                        dataView.Sort = "Id DESC";

                        //grid.DataSource = leavestatus;

                        //grid.DataBind();
                        ViewState["Results"] = leavestatus;
                    }
                }
            }
            catch (Exception ex)
            {
                lblErr.Text = ex.Message;
            }
        }
        internal static string GetExportValue(SPWeb exportWeb, object val, SPField field, string locale, bool forceDate, string mulSep)
        {
            string                  colVal;
            int                     pos;
            DateTime                dtVal;
            SPFieldDateTime         dtField = field as SPFieldDateTime;
            SPFieldLookup           pgField = field as SPFieldLookup;
            SPFieldMultiLineText    rtField = field as SPFieldMultiLineText;
            SPFieldMultiChoiceValue mcv;
            XmlDocument             doc;

            if (field is SPFieldCalculated)
            {
                val = ((SPFieldCalculated)field).GetFieldValueAsText(val);
            }
            if (field is SPFieldUrl)
            {
                val = ((SPFieldUrl)field).GetFieldValue(val + string.Empty);
            }
            if (forceDate && (DateTime.TryParse(val + string.Empty, out dtVal) || DateTime.TryParse(val + string.Empty, JsonSchemaManager.Property.Type.LocaleChoice.GetCulture(locale), DateTimeStyles.AllowWhiteSpaces, out dtVal)))
            {
                val = dtVal;
            }
            if ((val is DateTime) && ((dtField != null) || forceDate))
            {
                colVal = ((DateTime)val).ToString((dtField == null) ? "m" : ((dtField.DisplayFormat == SPDateTimeFieldFormatType.DateOnly) ? "d" : "g"), JsonSchemaManager.Property.Type.LocaleChoice.GetCulture(locale));
            }
            else if (val is SPFieldUrlValue)
            {
                colVal = ((SPFieldUrlValue)val).Url;
            }
            else if (val is SPFieldLookupValueCollection)
            {
                colVal = string.Join(mulSep, ((SPFieldLookupValueCollection)val).ConvertAll <string> ((lv) => {
                    return(lv.LookupValue);
                }).ToArray());
            }
            else if (val is SPFieldLookupValue)
            {
                colVal = ((SPFieldLookupValue)val).LookupValue;
            }
            else if ((mcv = val as SPFieldMultiChoiceValue) != null)
            {
                colVal = string.Empty;
                for (int i = 0; i < mcv.Count; i++)
                {
                    colVal += (mulSep + mcv [i]);
                }
                if (colVal.Length > mulSep.Length)
                {
                    colVal = colVal.Substring(mulSep.Length);
                }
            }
            else if (((pgField = field as SPFieldLookup) != null) || (((rtField = field as SPFieldMultiLineText) != null) && rtField.RichText))
            {
                colVal = val + string.Empty;
                if (pgField != null)
                {
                    if ((pos = colVal.IndexOf(";#", StringComparison.InvariantCultureIgnoreCase)) >= 0)
                    {
                        colVal = colVal.Substring(pos + 2);
                    }
                    if ((pos = colVal.IndexOf(";#")) > 0)
                    {
                        colVal = colVal.Substring(0, pos);
                    }
                }
                colVal = htmlRegex.Replace(colVal.Replace(WEIRD_CHAR, string.Empty).Replace("<br>", "\r\n").Replace("<BR>", "\r\n").Replace("<br/>", "\r\n").Replace("<BR/>", "\r\n").Replace("<br />", "\r\n").Replace("<BR />", "\r\n"), string.Empty);
            }
            else
            {
                colVal = val + string.Empty;
            }
            if (colVal.StartsWith("<roxhtml/>"))
            {
                colVal = htmlRegex.Replace(colVal.Substring("<roxhtml/>".Length).Replace(WEIRD_CHAR, string.Empty).Replace("<br>", "\r\n").Replace("<BR>", "\r\n").Replace("<br/>", "\r\n").Replace("<BR/>", "\r\n").Replace("<br />", "\r\n").Replace("<BR />", "\r\n"), string.Empty);
                try {
                    doc = new XmlDocument();
                    doc.LoadXml(colVal);
                    colVal = doc.DocumentElement.InnerText;
                } catch {
                }
                colVal = colVal.Replace('\r', ' ').Replace('\n', ' ').Trim();
            }
            return(colVal);
        }
        private void LoadLeaveDetails()
        {
            DataTable leavetable = LeavestableStructure();

            try
            {
                using (var site = new SPSite(SPContext.Current.Site.Url))
                {
                    using (var web = site.OpenWeb())
                    {
                        var leaveList = web.Lists.TryGetList(Utilities.LeaveRequest);
                        if (leaveList != null)
                        {
                            SPUser user = web.CurrentUser;

                            string currentUser = user.Name;
                            SPListItemCollection currentUserDetails;

                            currentUserDetails = GetListItemCollection(leaveList, "RequestedFrom",
                                                                       currentUser, "Year", hdnCurrentYear.Value, "Employee Status", "Active");

                            if (currentUserDetails.Count > 0)
                            {
                                // var itemCollection = leaveList.Items;

                                foreach (SPListItem spListItem in currentUserDetails)
                                {
                                    DataRow dataRow = leavetable.NewRow();

                                    var requestedto = new SPFieldLookupValue(spListItem["RequestedTo"].ToString());

                                    dataRow["Requested To"]  = requestedto.LookupValue;
                                    dataRow["Leave Type"]    = spListItem[Utilities.LeaveType].ToString();
                                    dataRow["Starting Date"] =
                                        DateTime.Parse(spListItem[Utilities.StartingDate].ToString()).ToShortDateString();
                                    dataRow["Ending Date"] =
                                        DateTime.Parse(spListItem[Utilities.EndingDate].ToString()).ToShortDateString();
                                    dataRow["Leave Days"] = spListItem[Utilities.LeaveDays].ToString();
                                    if (spListItem[Utilities.Remarks] != null)
                                    {
                                        dataRow["Remarks"] = spListItem[Utilities.Remarks].ToString();
                                    }
                                    dataRow["Status"] = spListItem[Utilities.Status].ToString();
                                    if (spListItem["Purpose of Leave"] != null)
                                    {
                                        SPFieldMultiLineText mlt = spListItem.Fields.GetField("Purpose of Leave") as SPFieldMultiLineText;

                                        dataRow["Reason"] = mlt.GetFieldValueAsText(spListItem["Purpose of Leave"]);
                                    }
                                    string url = "'" + site.Url + "/Pages/CancelLeaves.aspx?LeaveId=" + spListItem.ID + "'";
                                    if (spListItem[Utilities.Status].ToString() == "Pending")
                                    {
                                        dataRow["Cancel"] = "<a href=\"JavaScript:openDialog(" + url + ");\">Cancel</a>";
                                    }
                                    leavetable.Rows.Add(dataRow);
                                }
                            }
                            DataView dataView = new DataView(leavetable);
                            dataView.Sort = "Starting Date DESC";

                            ViewState["Result"] = dataView.Table;
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                lblErr.Text = ex.Message;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            culture = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
            if (!string.IsNullOrEmpty(Convert.ToString(Request.QueryString["AttachmentColumn"])))
            {
                AttachedColumn = Convert.ToString(Request.QueryString["AttachmentColumn"]);
            }
            if (!string.IsNullOrEmpty(Convert.ToString(Request.QueryString["ItemId"])))
            {
                itemId = Convert.ToString(Request.QueryString["ItemId"]);
            }
            TasksVariables();
            try
            {
                if (!Page.IsPostBack)
                {
                    string urlSite     = SPContext.Current.Web.Url;
                    string COLUMN_NAME = AttachedColumn;
                    using (SPSite currentsite = new SPSite(urlSite))
                    {
                        using (SPWeb DestWeb = currentsite.OpenWeb())
                        {
                            SPList     listdata      = DestWeb.Lists[new Guid(Request.QueryString["ListId"])];
                            SPListItem listitemtoadd = listdata.GetItemById(Convert.ToInt16(Convert.ToString(Request.QueryString["ItemId"])));

                            SPFieldMultiLineText multilineField = listitemtoadd.Fields.GetField(COLUMN_NAME) as SPFieldMultiLineText;

                            if (multilineField != null)
                            {
                                // Get the field value as HTML
                                string text = multilineField.GetFieldValueAsHtml(listitemtoadd[COLUMN_NAME], listitemtoadd);
                                if (!string.IsNullOrEmpty(text))
                                {
                                    string      sharePointNewLine = "<br/>";
                                    XmlDocument doc = new XmlDocument();
                                    //string finalHtml=divAttachments.InnerHtml.fi
                                    string attachmentHTML = "<div>" + text + "</div>";
                                    doc.LoadXml(attachmentHTML);
                                    XmlNodeList nodeList = doc.GetElementsByTagName("a");
                                    string      newhtml  = string.Empty;

                                    DataTable  dtActionLog = new DataTable();
                                    DataColumn c1          = new DataColumn("link", typeof(string));
                                    dtActionLog.Columns.Add(c1);

                                    foreach (XmlNode node in nodeList)
                                    {
                                        DataRow drw = dtActionLog.NewRow();
                                        drw[0] = node.InnerXml;
                                        dtActionLog.Rows.Add(drw);
                                        dtActionLog.AcceptChanges();
                                    }
                                    grdview.DataSource = dtActionLog;
                                    grdview.DataBind();
                                }
                                else
                                {
                                    lblerror.Text                  = "No Attachment Found.";
                                    btnsave.Style["Display"]       = "none";
                                    trerror.Style["Display"]       = "";
                                    btnRemoveFile.Style["Display"] = "none";
                                }
                            }
                        }
                    }

                    GetConfigurations(AttachedColumn, itemId);

                    if (isallowDeletionoffiles)
                    {
                        btnRemoveFile.Visible = true;
                    }
                    else
                    {
                        btnRemoveFile.Visible = false;
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 18
0
        private static string GetFieldType(SPField oField, out string senum, out string senumkeys, out string sFormat, out string sRange, SPWeb oWeb)
        {
            var currencyFormatDictionary = new Dictionary <int, string> {
                { 0, "$n" }, { 1, "n$" }, { 2, "$ n" }, { 3, "n $" }
            };

            senum     = "";
            senumkeys = "";
            sFormat   = "";
            sRange    = "";

            switch (oField.Type)
            {
            case SPFieldType.Boolean:
                return("Bool");

            case SPFieldType.DateTime:
                SPFieldDateTime oDTField   = (SPFieldDateTime)oField;
                string          dateFormat = GetExampleDateFormat(oWeb, "yyyy", "M", "d");
                sFormat = oDTField.GetProperty("Format").Equals("DateOnly") ? dateFormat : string.Format("{0} h:mm tt", dateFormat);
                return("Date");

            case SPFieldType.Currency:
                var currenvyCultureInfo           = new CultureInfo(((SPFieldCurrency)oField).CurrencyLocaleId);
                NumberFormatInfo numberFormatInfo = currenvyCultureInfo.NumberFormat;

                sFormat = currencyFormatDictionary[numberFormatInfo.CurrencyPositivePattern]
                          .Replace("$", numberFormatInfo.CurrencySymbol)
                          .Replace("n",
                                   string.Format(",0.{0}", new string('0', numberFormatInfo.CurrencyDecimalDigits)));
                return("Float");

            case SPFieldType.Note:
                SPFieldMultiLineText field = (SPFieldMultiLineText)oField;
                if (field.RichText)
                {
                    return("Html");
                }
                else
                {
                    return("Lines");
                }

            case SPFieldType.Number:
                string percentageSign = string.Empty;

                if (((SPFieldNumber)oField).ShowAsPercentage)
                {
                    //sFormat = "0\\%;0\\%;0\\%";
                    return("Float");
                }

                switch (((SPFieldNumber)oField).DisplayFormat)
                {
                case SPNumberFormatTypes.Automatic:
                    sFormat = ",#0.##########" + percentageSign;
                    break;

                case SPNumberFormatTypes.NoDecimal:
                    sFormat = ",#0" + percentageSign;
                    break;

                case SPNumberFormatTypes.OneDecimal:
                    sFormat = ",#0.0" + percentageSign;
                    break;

                case SPNumberFormatTypes.TwoDecimals:
                    sFormat = ",#0.00" + percentageSign;
                    break;

                case SPNumberFormatTypes.ThreeDecimals:
                    sFormat = ",#0.000" + percentageSign;
                    break;

                case SPNumberFormatTypes.FourDecimals:
                    sFormat = ",#0.0000" + percentageSign;
                    break;

                case SPNumberFormatTypes.FiveDecimals:
                    sFormat = ",#0.00000" + percentageSign;
                    break;
                }
                return("Float");

            case SPFieldType.Choice:
                SPFieldChoice oCField = (SPFieldChoice)oField;
                foreach (string sChoice in oCField.Choices)
                {
                    senum += ";" + sChoice;
                }
                return("Enum");

            case SPFieldType.Lookup:
                SPFieldLookup oLField = (SPFieldLookup)oField;
                if (oLField.AllowMultipleValues)
                {
                    sRange = "1";
                }

                SPList oLookupList = oWeb.Lists[new Guid(oLField.LookupList)];

                foreach (SPListItem li in oLookupList.Items)
                {
                    senum     += ";" + li.Title.Replace(";", "");
                    senumkeys += ";" + li.ID;
                }

                return("Enum");

            case SPFieldType.MultiChoice:
                SPFieldMultiChoice oMCField = (SPFieldMultiChoice)oField;
                foreach (string sChoice in oMCField.Choices)
                {
                    senum += ";" + sChoice;
                }
                sRange = "1";
                return("Enum");

            case SPFieldType.User:

                DataTable dtResources = EPMLiveCore.API.APITeam.GetResourcePool("<Pool><Columns>SimpleColumns</Columns></Pool>", oWeb);

                foreach (DataRow dr in dtResources.Rows)
                {
                    senum     += ";" + dr["Title"].ToString();
                    senumkeys += ";" + dr["SPID"].ToString();
                }

                SPFieldUser oUField = (SPFieldUser)oField;
                if (oUField.AllowMultipleValues)
                {
                    sRange = "1";
                }
                return("Enum");

            default:
                return("Text");
            }
        }
        private void LoadLeaves(string leaveId)
        {
            try
            {
                hdnLeaveId.Value = leaveId;
                using (var site = new SPSite(SPContext.Current.Site.Url))
                {
                    using (var web = site.OpenWeb())
                    {
                        var leavelist = web.Lists.TryGetList(Utilities.LeaveRequest);
                        var emplist   = web.Lists.TryGetList(Utilities.EmployeeScreen);
                        var levitem   = leavelist.GetItemById(Convert.ToInt16(leaveId));
                        var spv       = new SPFieldLookupValue(levitem["RequestedTo"].ToString());

                        SPUser user =
                            new SPFieldUserValue(web, levitem["RequestedFrom"].ToString()).User;

                        SPListItemCollection empDetails = GetListItemCollection(emplist, "Employee Name",
                                                                                user.Name);
                        hdnCurrentUsername.Value = user.Name;
                        foreach (SPListItem empDetail in empDetails)
                        {
                            lblEmpID.Text       = empDetail["Title"].ToString();
                            lblDepartment.Text  = empDetail["Department"].ToString();
                            lblDesgination.Text = empDetail["Designation"].ToString();
                        }
                        txtDuration.InnerText  = levitem["Leave Days"].ToString();
                        hdnLeaveDuration.Value = levitem["Leave Days"].ToString();
                        if (levitem["Purpose of Leave"] != null)
                        {
                            SPFieldMultiLineText mlt = levitem.Fields.GetField("Purpose of Leave") as SPFieldMultiLineText;

                            txtPurpose.Text = mlt.GetFieldValueAsText(levitem["Purpose of Leave"]);
                        }
                        ddlTypeofLeave.SelectedItem.Text = levitem["Leave Type"].ToString().Trim();
                        if (levitem["Leave Type"].ToString().Trim() != "Optional")
                        {
                            Selecteddates.Visible = true;
                            optinalDates.Visible  = false;
                        }
                        else
                        {
                            txtOptionalLeaves.Text = DateTime.Parse(levitem["Starting Date"].ToString()).ToShortDateString();
                            Selecteddates.Visible  = false;
                            optinalDates.Visible   = true;
                        }
                        ddlReportingTo.Text            = spv.LookupValue;
                        dateTimeEndDate.SelectedDate   = DateTime.Parse(levitem["Ending Date"].ToString());
                        dateTimeStartDate.SelectedDate = DateTime.Parse(levitem["Starting Date"].ToString());
                        hdnStrtDate.Value = DateTime.Parse(levitem["Starting Date"].ToString()).ToString(CultureInfo.InvariantCulture);
                        hdnEndDate.Value  = DateTime.Parse(levitem["Ending Date"].ToString()).ToString(CultureInfo.InvariantCulture);

                        ddlTypeofLeave.Enabled = false;
                    }
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message;
            }
        }