Пример #1
0
        private IMaster AssignPropertyValues(dynamic objMaster, ClientContext context, Web web, ListItemCollection items, Type itemType)
        {
            List <IMasterItem> masterItems = new List <IMasterItem>();

            foreach (ListItem item in items)
            {
                dynamic        listItem       = Activator.CreateInstance(itemType);
                PropertyInfo[] itemProperties = listItem.GetType().GetProperties();
                foreach (PropertyInfo property in itemProperties)
                {
                    if (property.GetCustomAttribute <FieldColumnNameAttribute>() != null && !string.IsNullOrEmpty(property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation))
                    {
                        if (property.GetCustomAttribute <IsPersonAttribute>() != null && property.GetCustomAttribute <IsPersonAttribute>().IsPerson&& !property.GetCustomAttribute <IsPersonAttribute>().ReturnName)
                        {
                            if (item[property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation] is FieldUserValue[])
                            {
                                property.SetValue(listItem, BELDataAccessLayer.GetEmailsFromPersonField(context, web, (FieldUserValue[])item[property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation]));
                            }
                            else
                            {
                                property.SetValue(listItem, BELDataAccessLayer.GetEmailsFromPersonField(context, web, (FieldUserValue)item[property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation]));
                            }
                        }
                        else if (property.GetCustomAttribute <IsPersonAttribute>() != null && property.GetCustomAttribute <IsPersonAttribute>().IsPerson&& property.GetCustomAttribute <IsPersonAttribute>().ReturnName)
                        {
                            if (item[property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation] is FieldUserValue[])
                            {
                                property.SetValue(listItem, BELDataAccessLayer.GetNameFromPersonField(context, web, (FieldUserValue[])item[property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation]));
                            }
                            else
                            {
                                property.SetValue(listItem, BELDataAccessLayer.GetNameFromPersonField(context, web, (FieldUserValue)item[property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation]));
                            }
                        }
                        else if (property.GetCustomAttribute <FieldColumnNameAttribute>().IsLookup)
                        {
                            if (item[property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation] is FieldLookupValue[])
                            {
                                FieldLookupValue[] lookupFields = item[property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation] as FieldLookupValue[];
                                List <string>      reletedto    = new List <string>();
                                foreach (FieldLookupValue lookupField in lookupFields)
                                {
                                    reletedto.Add(lookupField.LookupValue);
                                }
                                property.SetValue(listItem, reletedto);
                            }
                            else
                            {
                                FieldLookupValue lookupField = item[property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation] as FieldLookupValue;
                                if (lookupField != null)
                                {
                                    property.SetValue(listItem, lookupField.LookupValue);
                                }
                            }
                        }
                        else
                        {
                            property.SetValue(listItem, item[property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation]);
                        }
                    }
                }
                masterItems.Add(listItem);
            }
            PropertyInfo prop = objMaster.GetType().GetProperty("Items");

            prop.SetValue(objMaster, masterItems, null);
            return(objMaster);
        }
Пример #2
0
        /// <summary>
        /// Gets the DCN details.
        /// </summary>
        /// <param name="objDict">The object dictionary.</param>
        /// <returns>byte array</returns>
        public List <DCRDetails> RetrieveAllDCRNos(IDictionary <string, string> objDict)
        {
            List <DCRDetails> dcrs = new List <DCRDetails>();
            List      spList       = this.web.Lists.GetByTitle(DCRDCNListNames.DCRLIST);
            CamlQuery query        = new CamlQuery();

            if (objDict != null && objDict.ContainsKey("UserEmail"))
            {
                User loggedinuser = BELDataAccessLayer.EnsureUser(context, web, objDict["UserEmail"].ToString());
                query.ViewXml = @"<View>
                                        <Query>
                                                  <Where>
                                                        <And>
                                                            <Eq>
                                                                    <FieldRef Name='FinalDesignEngineer' /><Value Type='User'>" + loggedinuser.Title + @"</Value>
                                                            </Eq>
                                                        <And>
                                                            <Eq>
                                                                    <FieldRef Name='Status' />
                                                                    <Value Type='Text'>" + FormStatus.COMPLETED + @"</Value>
                                                            </Eq>
                                                            <Eq>
                                                                    <FieldRef Name='IsDCNGenerated' />
                                                                    <Value Type='Boolean'>0</Value>
                                                            </Eq>
                                                    </And>
                                                   </And>
                                                 </Where>
                                        </Query>
                            </View>";
            }
            else
            {
                query.ViewXml = @"<View>
                                                        <Query>
                                                                  <Where>
                                                                    <And>
                                                                      <Eq>
                                                                            <FieldRef Name='Status' />
                                                                            <Value Type='Text'>" + FormStatus.COMPLETED + @"</Value>
                                                                       </Eq>
                                                                       <Eq>
                                                                             <FieldRef Name='IsDCNGenerated' />
                                                                             <Value Type='Boolean'>0</Value>
                                                                       </Eq>
                                                                    </And>
                                                                 </Where>
                                                        </Query>
                                            </View>";
            }
            //  query.ViewXml = @"<View><ViewFields><FieldRef Name='ID' /><FieldRef Name='DCRNo' /><FieldRef Name='ProductName' /><FieldRef Name='RequestDate' /><FieldRef Name='ProposedBy' /></ViewFields></View>";
            ListItemCollection items = spList.GetItems(query);

            this.context.Load(items);
            this.context.ExecuteQuery();
            if (items != null && items.Count != 0)
            {
                foreach (ListItem item in items)
                {
                    DCRDetails dcr = new DCRDetails();
                    dcr.DCRNo = Convert.ToString(item["DCRNo"]);
                    dcr.ID    = item.Id;
                    FieldUserValue user = item["ProposedBy"] as FieldUserValue;
                    dcr.ProposedBy  = BELDataAccessLayer.GetNameFromPersonField(context, web, user);
                    dcr.ProductName = Convert.ToString(item["ProductName"]);
                    dcr.RequestDate = Convert.ToDateTime(item["RequestDate"]);
                    dcrs.Add(dcr);
                }
            }
            return(dcrs);
        }
Пример #3
0
 private ITrans SetTranProperties(ClientContext context, Web web, ListItem listItem, ITrans tranItem, PropertyInfo[] properties, bool getSubItems = true)
 {
     foreach (PropertyInfo property in properties)
     {
         bool   isListColumn  = property.GetCustomAttribute <IsListColumnAttribute>() == null || property.GetCustomAttribute <IsListColumnAttribute>().IsListColumn;
         bool   isTask        = property.GetCustomAttribute <IsTaskAttribute>() != null && property.GetCustomAttribute <IsTaskAttribute>().IsTaskField;
         bool   isTran        = property.GetCustomAttribute <IsTranAttribute>() != null && property.GetCustomAttribute <IsTranAttribute>().IsTranField;
         string listCoumnName = property.GetCustomAttribute <FieldColumnNameAttribute>() != null && !string.IsNullOrEmpty(property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation) ? property.GetCustomAttribute <FieldColumnNameAttribute>().FieldsInformation : property.Name;
         bool   isFile        = property.GetCustomAttribute <IsFileAttribute>() != null && property.GetCustomAttribute <IsFileAttribute>().IsFile;
         if (isListColumn)
         {
             if (property.GetCustomAttribute <FieldColumnNameAttribute>() != null && property.GetCustomAttribute <FieldColumnNameAttribute>().IsLookup)
             {
                 FieldLookupValue lookupField = listItem[listCoumnName] as FieldLookupValue;
                 property.SetValue(tranItem, lookupField.LookupId);
             }
             else if (property.GetCustomAttribute <IsPersonAttribute>() != null && property.GetCustomAttribute <IsPersonAttribute>().IsPerson)
             {
                 FieldUserValue[] users = null;
                 if (listItem[listCoumnName] != null)
                 {
                     if (property.GetCustomAttribute <IsPersonAttribute>().IsMultiple)
                     {
                         users = listItem[listCoumnName] as FieldUserValue[];
                     }
                     else
                     {
                         users    = new FieldUserValue[1];
                         users[0] = listItem[listCoumnName] as FieldUserValue;
                     }
                 }
                 if (users != null && !property.GetCustomAttribute <IsPersonAttribute>().ReturnName)
                 {
                     string personEmails = BELDataAccessLayer.GetEmailsFromPersonField(context, web, users);
                     property.SetValue(tranItem, personEmails);
                 }
                 else if (users != null && property.GetCustomAttribute <IsPersonAttribute>().ReturnName)
                 {
                     string personEmails = BELDataAccessLayer.GetNameFromPersonField(context, web, users);
                     property.SetValue(tranItem, personEmails);
                 }
             }
             else if (isFile)
             {
                 if (Convert.ToString(listItem["Attachments"]) == "True")
                 {
                     context.Load(listItem.AttachmentFiles);
                     context.ExecuteQuery();
                     AttachmentCollection attachments        = listItem.AttachmentFiles;
                     List <FileDetails>   objAttachmentFiles = this.GetAttachments(attachments);
                     property.SetValue(tranItem, objAttachmentFiles);
                 }
             }
             else
             {
                 object value     = listItem[listCoumnName];
                 Type   t         = Nullable.GetUnderlyingType(property.PropertyType) ?? property.PropertyType;
                 object safeValue = (value == null) ? null : Convert.ChangeType(value, t);
                 property.SetValue(tranItem, safeValue);
             }
         }
         else if (isTran)
         {
             if (getSubItems)
             {
                 string listName = property.GetCustomAttribute <IsTranAttribute>().TranListName;
                 Type   tSubTran = property.GetCustomAttribute <IsTranAttribute>().TranType;
                 if (!string.IsNullOrEmpty(listName))
                 {
                     List <ITrans> subTrans = this.GetTransactionListData(context, web, tSubTran, listName, Convert.ToInt32(listItem["ID"]));
                     property.SetValue(tranItem, subTrans);
                 }
             }
         }
         ////else if (isTask)
         ////{
         ////    string listName = property.GetCustomAttribute<IsTaskAttribute>().TaskListName;
         ////    Type tSubTask = property.GetCustomAttribute<IsTaskAttribute>().TaskType;
         ////    if (!string.IsNullOrEmpty(listName))
         ////    {
         ////        List<ITask> subTasks = this.GetTaskListData(context, web, tSubTask, listName, Convert.ToInt32(listItem["ID"]));
         ////        property.SetValue(taskItem, subTasks);
         ////    }
         ////}
     }
     return(tranItem);
 }