Beispiel #1
0
        public static void GetPMPSubSiteTaskLists(string siteUrl, string sharepoint_Login, SecureString securePassword, string taskName, List <AllTimeSheetData> allMilestoneItems, SupplementalData sd)
        {
            ClientContext clientContext = new ClientContext(siteUrl);

            List oList = clientContext.Web.Lists.GetByTitle("Schedule");

            CamlQuery          camlQuery    = new CamlQuery();
            ListItemCollection collListItem = oList.GetItems(camlQuery);

            clientContext.Load(collListItem);

            var onlineCredentials = new SharePointOnlineCredentials(sharepoint_Login, securePassword);

            clientContext.Credentials = onlineCredentials;
            clientContext.ExecuteQuery();

            //var groupItem = allTimeSheetData.Where(x => x.jobcode_id == spItem.Select(y => y.id).FirstOrDefault()).GroupBy(x => x.id);

            long   installation = 0; long projectManagement = 0; long fabrication = 0; long preProduction = 0;
            string installationVal = string.Empty; string projectManagementVal = string.Empty;
            string fabricationVal = string.Empty; string preProductionVal = string.Empty;

            foreach (var item in allMilestoneItems)
            {
                if (item.customfields.SecondColumn == "Installation")
                {
                    installation = installation + Convert.ToInt64(item.duration);
                }
                else if (item.customfields.SecondColumn == "Project Management")
                {
                    projectManagement = projectManagement + Convert.ToInt64(item.duration);
                }
                else if (item.customfields.SecondColumn == "Fabrication")
                {
                    fabrication = fabrication + Convert.ToInt64(item.duration);
                }
                else if (item.customfields.SecondColumn == "Pre Production")
                {
                    preProduction = preProduction + Convert.ToInt64(item.duration);
                }
            }

            TimeSpan duration = new TimeSpan();

            duration        = TimeSpan.FromSeconds(Convert.ToInt64(installation));
            installationVal = string.Format("{0:D2}.{1:D2}",
                                            duration.Hours,
                                            duration.Minutes,
                                            duration.Seconds,
                                            duration.Milliseconds);

            duration             = new TimeSpan();
            duration             = TimeSpan.FromSeconds(Convert.ToInt64(projectManagement));
            projectManagementVal = string.Format("{0:D2}.{1:D2}",
                                                 duration.Hours,
                                                 duration.Minutes,
                                                 duration.Seconds,
                                                 duration.Milliseconds);

            duration       = new TimeSpan();
            duration       = TimeSpan.FromSeconds(Convert.ToInt64(fabrication));
            fabricationVal = string.Format("{0:D2}.{1:D2}",
                                           duration.Hours,
                                           duration.Minutes,
                                           duration.Seconds,
                                           duration.Milliseconds);

            duration         = new TimeSpan();
            duration         = TimeSpan.FromSeconds(Convert.ToInt64(preProduction));
            preProductionVal = string.Format("{0:D2}.{1:D2}",
                                             duration.Hours,
                                             duration.Minutes,
                                             duration.Seconds,
                                             duration.Milliseconds);

            foreach (ListItem oListItem in collListItem)
            {
                if (Convert.ToString(oListItem["Title"]) == taskName)
                {
                    ListItemCreationInformation itemInfo = new ListItemCreationInformation();
                    ListItem myItem = oList.GetItemById(Convert.ToString(oListItem["ID"]));
                    myItem["Actual_x0020_Install"]             = installationVal;
                    myItem["Actual_x0020_Project_x0020_Manag"] = projectManagementVal;
                    myItem["Actual_x0020_Fabrication"]         = fabricationVal;
                    myItem["Actual_x0020_Pre_x0020_Productio"] = preProductionVal;
                    try
                    {
                        myItem.Update();
                        clientContext.Credentials = onlineCredentials;
                        clientContext.ExecuteQuery();
                        Console.WriteLine("Item Updated Successfully name: " + taskName);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
            }
        }
Beispiel #2
0
        public static void GetPMPSitesAndSubSiteTasks(long project_id, string taskName, List <AllTimeSheetData> allMilestoneItems, SupplementalData sd)
        {
            string        siteUrl       = "https://leonlebeniste.sharepoint.com/sites/PMP";
            ClientContext clientContext = new ClientContext(siteUrl);

            List oList = clientContext.Web.Lists.GetByTitle("LL Projects List");

            CamlQuery          camlQuery    = new CamlQuery();
            ListItemCollection collListItem = oList.GetItems(camlQuery);

            clientContext.Load(collListItem);

            string sharepoint_Login    = ConfigurationManager.AppSettings.Get("sharepoint_Login_PMP");
            string sharepoint_Password = ConfigurationManager.AppSettings.Get("sharepoint_Password_PMP");
            var    securePassword      = new SecureString();

            foreach (char c in sharepoint_Password)
            {
                securePassword.AppendChar(c);
            }

            var onlineCredentials = new SharePointOnlineCredentials(sharepoint_Login, securePassword);

            clientContext.Credentials = onlineCredentials;
            clientContext.ExecuteQuery();

            foreach (ListItem oListItem in collListItem)
            {
                if (project_id == Convert.ToInt64(oListItem["ProjID"]))
                {
                    string subSiteURL = ((Microsoft.SharePoint.Client.FieldUrlValue)oListItem["SiteURL"]).Url;

                    //NOTE: Get Sub Site Tasks items.
                    GetPMPSubSiteTaskLists(subSiteURL, sharepoint_Login, securePassword, taskName, allMilestoneItems, sd);
                }
            }
        }