コード例 #1
0
ファイル: MasterDataHelper.cs プロジェクト: cloverspd1/DCRDCN
        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>
        /// Esclates the request.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="web">The web.</param>
        /// <param name="item">The item.</param>
        /// <param name="mainListName">Name of the main list.</param>
        /// <param name="approverListName">Name of the approver list.</param>
        /// <returns>to users</returns>
        public static DataTable EsclateRequest(ClientContext context, Web web, ListItem item, string mainListName, string approverListName, DataTable tblEscalation, ref string toUser, int actionStatus)
        {
            try
            {
                DataRow dr      = tblEscalation.NewRow();
                string  userIDs = BELDataAccessLayer.GetEmailsFromPersonField(context, web, item["Approver"] as FieldUserValue[]);

                if (Convert.ToInt32(actionStatus) == 1)   //For Escalation Only
                {
                    string to = string.Empty;
                    foreach (string id in userIDs.Split(','))
                    {
                        UserDetails userDetail = BELDataAccessLayer.Instance.GetUserInformation(context, web, id);
                        if (userDetail != null)
                        {
                            to += "," + GetManagerEmail(context, web, userDetail.ReportingManager);
                            dr["UserFullName"] += userDetail.FullName + ", ";
                            dr["UserEmail"]    += userDetail.UserEmail + ", ";
                            dr["CCEmail"]      += userDetail.UserEmail + ",";
                        }
                    }
                    dr["ToEmail"]      = to.Trim(',');
                    dr["UserFullName"] = dr["UserFullName"].ToString().Trim(',');
                }
                else if (Convert.ToInt32(actionStatus) == 2) //For Reminder Only
                {
                    dr["UserEmail"]   = dr["ToEmail"] = BELDataAccessLayer.GetEmailUsingUserID(context, web, userIDs);
                    dr["PendingWith"] = dr["UserFullName"] = BELDataAccessLayer.GetNameUsingUserID(context, web, userIDs);
                }
                EmailHelper eHelper = new EmailHelper();/// Check if we can remove this.
                //List<ListItemDetail> listDetails = new List<ListItemDetail>();
                int      reqId    = (item["RequestID"] as FieldLookupValue).LookupId;
                List     mainList = web.Lists.GetByTitle(mainListName);
                ListItem mainItem = mainList.GetItemById(reqId);
                context.Load(mainItem);
                context.Load(mainList, m => m.DefaultDisplayFormUrl);
                context.ExecuteQuery();


                // dr["CCEmail"] = toUser;
                dr["EscOrReminder"]   = actionStatus;
                dr["ApplicationName"] = Convert.ToString(item["ApplicationName"]);
                dr["FormName"]        = Convert.ToString(item["FormName"]);
                // dr["ReferenceNo"] = (mainItem["DCRNo"] != null ? Convert.ToString(mainItem["DCRNo"]) : string.Empty);
                dr["RequestDate"] = (mainItem["RequestDate"] != null ? Convert.ToDateTime(mainItem["RequestDate"]).ToString("dd-MM-yyyy") : string.Empty);
                dr["AssignDate"]  = (item["AssignDate"] != null ? Convert.ToDateTime(item["AssignDate"]).ToLocalTime().ToString("dd-MM-yyyy") : string.Empty);
                //dr["BusinessUnit"] = (mainItem["BusinessUnit"] != null ? Convert.ToString(mainItem["BusinessUnit"]) : string.Empty);
                // dr["ProductName"] = (mainItem["ProductName"] != null ? Convert.ToString(mainItem["ProductName"]) : string.Empty);
                string link           = string.Empty;
                string referenceNo    = string.Empty;
                string emailSignature = string.Empty;
                link           = "#URL" + mainList.DefaultDisplayFormUrl + "?ID=" + mainItem["ID"];
                dr["ListName"] = mainListName;
                dr["ID"]       = mainItem.Id;
                if (mainListName == "DCR")
                {
                    referenceNo    = (mainItem["DCRNo"] != null ? Convert.ToString(mainItem["DCRNo"]) : string.Empty);
                    emailSignature = "DCRDCN Team";
                }
                else if (mainListName == "DCN")
                {
                    referenceNo    = (mainItem["DCNNo"] != null ? Convert.ToString(mainItem["DCNNo"]) : string.Empty);
                    emailSignature = "DCRDCN Team";
                }
                else if (mainListName == "NPD")
                {
                    referenceNo    = (mainItem["ProjectNo"] != null ? Convert.ToString(mainItem["ProjectNo"]) : string.Empty);
                    emailSignature = "NPD Team";
                }
                else if (mainListName == "Feedbacks")
                {
                    referenceNo    = (mainItem["FeedbackNo"] != null ? Convert.ToString(mainItem["FeedbackNo"]) : string.Empty);
                    emailSignature = "CC Department";
                }
                else if (mainListName == "ExistingArtwork")
                {
                    referenceNo    = (mainItem["ReferenceNo"] != null ? Convert.ToString(mainItem["ReferenceNo"]) : string.Empty);
                    emailSignature = "Artwork Team";
                }
                else if (mainListName == "NewArtwork")
                {
                    referenceNo    = (mainItem["ReferenceNo"] != null ? Convert.ToString(mainItem["ReferenceNo"]) : string.Empty);
                    emailSignature = "Artwork Team";
                }
                else if (mainListName == "ItemCodePreProcess")
                {
                    referenceNo    = (mainItem["Title"] != null ? Convert.ToString(mainItem["Title"]) : string.Empty);
                    emailSignature = "Item Code Document Management S​​ystem (SharePoint​)​​";
                }
                dr["Link"]           = link;
                dr["ReferenceNo"]    = referenceNo;
                dr["EmailSignature"] = emailSignature;
                dr["ActionStatus"]   = actionStatus;
                dr["DueDate"]        = (item["DueDate"] != null ? Convert.ToDateTime(item["DueDate"]).ToLocalTime().ToString("dd-MM-yyyy") : string.Empty);

                if (item["DueDate"] != null)
                {
                    dr["PendingSince"] = GetPendingDays(Convert.ToDateTime(item["DueDate"]));
                }
                else
                {
                    dr["PendingSince"] = "0";
                }
                string workflowstatus = Convert.ToString(mainItem["WorkflowStatus"]);
                if (!workflowstatus.Equals("Draft"))
                {
                    tblEscalation.Rows.Add(dr);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error Request Escalation: " + ex.Message);
                Console.Write(ex.StackTrace + "==>" + ex.Message);
                Logger.Error("Error Request Escalation: " + ex.Message);
            }
            return(tblEscalation);
        }
コード例 #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);
 }