public static List <Employee> GetEnterEstimate(string month, string year, string listname, string siteUrl) { List <Employee> _returnEmployee = new List <Employee>(); try { using (MSC.ClientContext context = CustomSharePointUtility.GetContext(siteUrl)) { if (context != null) { MSC.List SalesEstimateEmployee = context.Web.Lists.GetByTitle(listname); MSC.ListItemCollectionPosition itemPosition = null; string fromday = year + "-" + month + "-" + "1"; string Today = year + "-" + month + "31"; while (true) { MSC.CamlQuery camlQuery = new MSC.CamlQuery(); camlQuery.ListItemCollectionPosition = itemPosition; camlQuery.ViewXml = @"<View><Query><Where> <Eq><FieldRef Name='Date' /> <Value IncludeTimeValue='FLASE' Type='DateTime'>" + fromday + "</Value></Eq>"; camlQuery.ViewXml += @" </Where></Query> <RowLimit>5000</RowLimit> <FieldRef Name='ID'/> <FieldRef Name='EmployeeName'/> <FieldRef Name='Author'/> <FieldRef Name='Created'/> </View>"; MSC.ListItemCollection Items = SalesEstimateEmployee.GetItems(camlQuery); context.Load(Items); context.ExecuteQuery(); itemPosition = Items.ListItemCollectionPosition; foreach (MSC.ListItem item in Items) { _returnEmployee.Add(new Employee { EmployeeName = Convert.ToString((item["EmployeeName"] as Microsoft.SharePoint.Client.FieldUserValue).LookupValue), EmployeeID = Convert.ToString((item["EmployeeName"] as Microsoft.SharePoint.Client.FieldUserValue).LookupId) }); } if (itemPosition == null) { break; // TODO: might not be correct. Was : Exit While } } } } } catch (Exception ex) { } return(_returnEmployee); }
//public static List<PurchaseOrder> GetAll_PurchaseOrderFromSharePoint(string siteUrl, string listName, string DaysDifference) //{ // List<PurchaseOrder> _retList = new List<PurchaseOrder>(); // try // { // using (MSC.ClientContext context = CustomSharePointUtility.GetContext(siteUrl)) // { // if (context != null) // { // MSC.List list = context.Web.Lists.GetByTitle(listName); // MSC.ListItemCollectionPosition itemPosition = null; // while (true) // { // var dataDateValue = DateTime.Now.AddDays(-Convert.ToInt32(DaysDifference)); // MSC.CamlQuery camlQuery = new MSC.CamlQuery(); // camlQuery.ListItemCollectionPosition = itemPosition; // camlQuery.ViewXml = @"<View> // <Query> // <Where> // <And> // <Or> // <Or> // <Eq> // <FieldRef Name='ApprovalStatus'/> // <Value Type='text'>Submitted</Value> // </Eq> // <Eq> // <FieldRef Name='ApprovalStatus'/> // <Value Type='text'>Approved By Functional Head</Value> // </Eq> // </Or> // <Or> // <Eq> // <FieldRef Name='ApprovalStatus'/> // <Value Type='text'>Approved By Purchase Head</Value> // </Eq> // <Eq> // <FieldRef Name='ApprovalStatus'/> // <Value Type='text'>Approved By Plant Head</Value> // </Eq> // </Or> // </Or> // <Leq><FieldRef Name='Modified'/><Value Type='DateTime'>" + dataDateValue.ToString("o") + "</Value></Leq>"; // camlQuery.ViewXml += @"</And></Where></Query> // <RowLimit>5000</RowLimit> // <ViewFields> // <FieldRef Name='ID'/> // <FieldRef Name='POReferenceNumber'/> // <FieldRef Name='Author'/> // <FieldRef Name='Created'/> // <FieldRef Name='DepartmentName'/> // <FieldRef Name='DepartmentID'/> // <FieldRef Name='LocationName'/> // <FieldRef Name='LocationID'/> // <FieldRef Name='LocationType'/> // <FieldRef Name='DivisionName'/> // <FieldRef Name='DivisionID'/> // <FieldRef Name='PONumber'/> // <FieldRef Name='POCost'/> // <FieldRef Name='MaterialDetails'/> // <FieldRef Name='ApprovalStatus'/> // <FieldRef Name='FHCode'/> // <FieldRef Name='Modified'/> // </ViewFields></View>"; // MSC.ListItemCollection Items = list.GetItems(camlQuery); // context.Load(Items); // context.ExecuteQuery(); // itemPosition = Items.ListItemCollectionPosition; // foreach (MSC.ListItem item in Items) // { // _retList.Add(new PurchaseOrder // { // Id = Convert.ToInt32(item["ID"]), // POReferenceNumber = Convert.ToString(item["POReferenceNumber"]).Trim(), // Author = Convert.ToString((item["Author"] as Microsoft.SharePoint.Client.FieldUserValue).LookupValue), // Created = Convert.ToString(item["Created"]).Trim(), // DepartmentName = Convert.ToString(item["DepartmentName"]).Trim(), // DepartmentID = Convert.ToString(item["DepartmentID"]).Trim(), // LocationName = Convert.ToString(item["LocationName"]).Trim(), // LocationID = Convert.ToString(item["LocationID"]).Trim(), // LocationType = Convert.ToString(item["LocationType"]).Trim(), // ////Author = Convert.ToString((item["Author"] as Microsoft.SharePoint.Client.FieldUserValue).LookupId), // //Author = Convert.ToString((item["Author"] as Microsoft.SharePoint.Client.FieldUserValue).LookupValue), // //FunctionalHead = Convert.ToString((item["FunctionalHead"] as Microsoft.SharePoint.Client.FieldUserValue[])[0].LookupId), // //HRHead = Convert.ToString((item["HRHead"] as Microsoft.SharePoint.Client.FieldUserValue[])[0].LookupId), // //HRHeadOnly = Convert.ToString((item["HRHeadOnly"] as Microsoft.SharePoint.Client.FieldUserValue).LookupId), // //MDorJMD = item["MDorJMD"] == null ? "" : Convert.ToString((item["MDorJMD"] as Microsoft.SharePoint.Client.FieldUserValue).LookupId), // //Recruiter = Convert.ToString((item["Recruiter"] as Microsoft.SharePoint.Client.FieldUserValue[])[0].LookupId), // DivisionName = Convert.ToString(item["DivisionName"]).Trim(), // DivisionID = Convert.ToString(item["DivisionID"]).Trim(), // PONumber = Convert.ToString(item["PONumber"]).Trim(), // POCost = Convert.ToString(item["POCost"]).Trim(), // MaterialDetails = Convert.ToString(item["MaterialDetails"]).Trim(), // ApprovalStatus = Convert.ToString(item["ApprovalStatus"]).Trim(), // FHCode = Convert.ToString(item["FHCode"]).Trim(), // Modified = Convert.ToString(item["Modified"]).Trim(), // }); // } // if (itemPosition == null) // { // break; // TODO: might not be correct. Was : Exit While // } // } // } // } // } // catch (Exception ex) // { // CustomSharePointUtility.WriteLog("Error in GetAll_ManpowerRequisitionFromSharePoint()" + " Error:" + ex.Message); // } // return _retList; //} #endregion /// New Code to Get Employee /// public static List <Employee> GetEmployees(string siteUrl, string listName) { List <Employee> _returnEmployee = new List <Employee>(); try { using (MSC.ClientContext context = CustomSharePointUtility.GetContext(siteUrl)) { if (context != null) { MSC.List HODList = context.Web.Lists.GetByTitle(listName); MSC.ListItemCollectionPosition itemPosition = null; while (true) { MSC.CamlQuery camlQuery = new MSC.CamlQuery(); camlQuery.ListItemCollectionPosition = itemPosition; camlQuery.ViewXml = @"<View><Query><Where> <Eq><FieldRef Name='Reminder' /><Value Type='Choice'>Yes</Value></Eq> </Where></Query> <RowLimit>5000</RowLimit> <FieldRef Name='ID'/> <FieldRef Name='EmployeeName'/> <FieldRef Name='Author'/> <FieldRef Name='Created'/> </View>"; MSC.ListItemCollection Items = HODList.GetItems(camlQuery); context.Load(Items); context.ExecuteQuery(); itemPosition = Items.ListItemCollectionPosition; foreach (MSC.ListItem item in Items) { _returnEmployee.Add(new Employee { EmployeeName = Convert.ToString((item["EmployeeName"] as Microsoft.SharePoint.Client.FieldUserValue).LookupValue), EmployeeID = Convert.ToString((item["EmployeeName"] as Microsoft.SharePoint.Client.FieldUserValue).LookupId) }); } if (itemPosition == null) { break; // TODO: might not be correct. Was : Exit While } } } } } catch (Exception ex) { } return(_returnEmployee); }
public static bool EmailData(PurchaseOrder updationList, string FunctionalHeadEmail, string PurchaseHead, string PlantHead, string MD, string siteUrl, string listName) { bool retValue = false; try { using (MSC.ClientContext context = CustomSharePointUtility.GetContext(siteUrl)) { //List<Mailing> varx = new List<Mailing>(); MSC.List list = context.Web.Lists.GetByTitle(listName); //for (var i = 0; i < updationList.Count; i++) //{ //var updateList = updationList.Skip(i).Take(1).ToList(); //if (updateList != null && updateList.Count > 0) //{ // foreach (var updateItem in updateList) // { MSC.ListItem listItem = null; MSC.ListItemCreationInformation itemCreateInfo = new MSC.ListItemCreationInformation(); listItem = list.AddItem(itemCreateInfo); var obj = new Object(); //Mailing data = new Mailing(); //var _From = ""; var _To = ""; //var _Cc = ""; var _Body = ""; var _Subject = ""; if (updationList.ApprovalStatus == "Submitted" && updationList.LocationType == "Office") { _To = FunctionalHeadEmail; } else if (updationList.ApprovalStatus == "Approved By Functional Head" && updationList.LocationType == "Office") { _To = MD; } else if (updationList.ApprovalStatus == "Submitted" && updationList.LocationType == "Plant") { _To = PurchaseHead; } else if (updationList.ApprovalStatus == "Approved By Purchase Head" && updationList.LocationType == "Plant") { _To = PlantHead; } else if (updationList.ApprovalStatus == "Approved By Plant Head" && Convert.ToInt32(updationList.POCost) > 50000 && updationList.LocationType == "Plant") { _To = MD; } _Subject = "Gentle Reminder"; _Body += "Dear User, <br><br>This is to inform you that below request is pending for your Approval."; _Body += "<br><b>Workflow Name :</b> Purchase Order "; _Body += "<br><b>Voucher No :</b> " + updationList.POReferenceNumber; _Body += "<br><b>Date of Creation :</b> " + updationList.Created; _Body += "<br><b>Employee : </b> " + updationList.Author; _Body += "<br><b>Department :</b> " + updationList.DepartmentName; _Body += "<br><b>Location :</b> " + updationList.LocationName; _Body += "<br><b>PO No : </b> " + updationList.PONumber; _Body += "<br><b> PO Amount : </b> " + updationList.POCost; _Body += "<br><b> Material Details : </b> " + updationList.MaterialDetails; if (updationList.ApprovalStatus == "Submitted" && updationList.LocationType == "Office") { _Body += "<br><b>Status :</b> Pending With Functional Head"; } else if (updationList.ApprovalStatus == "Approved By Functional Head" && updationList.LocationType == "Office") { _Body += "<br><b>Status :</b> Pending With MD"; } else if (updationList.ApprovalStatus == "Submitted" && updationList.LocationType == "Plant") { _Body += "<br><b>Status :</b> Pending With Purchase Head"; } else if (updationList.ApprovalStatus == "Approved By Purchase Head" && updationList.LocationType == "Plant") { _Body += "<br><b>Status :</b> Pending With Plant Head"; } else if (updationList.ApprovalStatus == "Approved By Plant Head" && Convert.ToInt32(updationList.POCost) > 50000 && updationList.LocationType == "Plant") { _Body += "<br><b>Status :</b> Pending With MD"; } _Body += "<br><h3>Kindly provide your approval</h3>"; _Body += "<br><h3>For Approval Please Click in the below link</h3>"; if (updationList.ApprovalStatus == "Submitted" && updationList.LocationType == "Office") { // _Body += "<br><a href=\"https://aparindltd.sharepoint.com/PurchaseOrder/SitePages/PendingWithFunctionalHead.aspx\">View Link</a>"; } else if (updationList.ApprovalStatus == "Approved By Functional Head" && updationList.LocationType == "Office") { // _Body += "<br><a href=\"https://aparindltd.sharepoint.com/PurchaseOrder/SitePages/PendingWithMD.aspx\">View Link</a>"; } else if (updationList.ApprovalStatus == "Submitted" && updationList.LocationType == "Plant") { // _Body += "<br><a href=\"https://aparindltd.sharepoint.com/PurchaseOrder/SitePages/PendingWithPurchaseHead.aspx\">View Link</a>"; } else if (updationList.ApprovalStatus == "Approved By Purchase Head" && updationList.LocationType == "Plant") { // _Body += "<br><a href=\"https://aparindltd.sharepoint.com/PurchaseOrder/SitePages/PendingWithPlantHead.aspx\">View Link</a>"; } else if (updationList.ApprovalStatus == "Approved By Plant Head" && updationList.LocationType == "Plant") { // _Body += "<br><a href=\"https://aparindltd.sharepoint.com/PurchaseOrder/SitePages/PendingWithManagingDirector.aspx\">View Link</a>"; } //data.MailTo = _From; //data.MailTo = _To; //data.MailCC = _Cc; //data.MailSubject = _Subject; //data.MailBody = _Body; //varx.Add(data); listItem["ToUser"] = _To; listItem["SubjectDesc"] = _Subject; listItem["BodyDesc"] = _Body; if (_To != "") { listItem.Update(); } try { context.ExecuteQuery(); retValue = true; } catch (Exception ex) { CustomSharePointUtility.WriteLog(string.Format("Error in InsertUpdate_EmployeeMaster ( context.ExecuteQuery();): Error ({0}) ", ex.Message)); return(false); //continue; } } // } // } //} //} } catch (Exception ex) { CustomSharePointUtility.WriteLog(string.Format("Error in InsertUpdate_EmployeeMaster: Error ({0}) ", ex.Message)); } return(retValue); }
public static bool EmailDataPlant(PurchaseOrder updationList, string siteUrl, string listName) { bool retValue = false; try { using (MSC.ClientContext context = CustomSharePointUtility.GetContext(siteUrl)) { //List<Mailing> varx = new List<Mailing>(); MSC.List list = context.Web.Lists.GetByTitle(listName); MSC.ListItem listItem = null; MSC.ListItemCreationInformation itemCreateInfo = new MSC.ListItemCreationInformation(); listItem = list.AddItem(itemCreateInfo); var obj = new Object(); var _To = ""; var _Body = ""; var _Subject = ""; _To = updationList.CurrentApprover; _Subject = "Gentle Reminder"; _Body += "Dear User, <br><br>This is to inform you that below request is pending for your Approval."; _Body += "<br><b>Workflow Name :</b> Purchase Order "; _Body += "<br><b>Voucher No :</b> " + updationList.POReferenceNumber; _Body += "<br><b>Date of Creation :</b> " + updationList.Created; _Body += "<br><b>Employee : </b> " + updationList.Author; _Body += "<br><b>Department :</b> " + updationList.DepartmentName; _Body += "<br><b>Location :</b> " + updationList.LocationName; _Body += "<br><b>PO No : </b> " + updationList.PONumber; _Body += "<br><b> PO Amount : </b> " + updationList.POCost; _Body += "<br><b> Material Details : </b> " + updationList.MaterialDetails; if (updationList.NewStatus == "1") { _Body += "<br><b>Status :</b> Pending With Purchase Head"; } else if (updationList.NewStatus == "2") { _Body += "<br><b>Status :</b> Pending With Plant Head"; } _Body += "<br><h3>Kindly provide your approval</h3>"; _Body += "<br><h3>For Approval Please Click in the below link</h3>"; if (updationList.NewStatus == "1") { /// _Body += "<br><a href=\"https://aparindltd.sharepoint.com/PurchaseOrder/SitePages/PendingWithApprover.aspx\">View Link</a>"; } else if (updationList.NewStatus == "2") { /// _Body += "<br><a href=\"https://aparindltd.sharepoint.com/PurchaseOrder/SitePages/PendingWithManagingDirector.aspx\">View Link</a>"; } listItem["ToUser"] = _To; listItem["SubjectDesc"] = _Subject; listItem["BodyDesc"] = _Body; if (_To != "") { listItem.Update(); } try { context.ExecuteQuery(); retValue = true; } catch (Exception ex) { CustomSharePointUtility.WriteLog(string.Format("Error in InsertUpdate_EmployeeMaster ( context.ExecuteQuery();): Error ({0}) ", ex.Message)); return(false); //continue; } } } catch (Exception ex) { CustomSharePointUtility.WriteLog(string.Format("Error in InsertUpdate_EmployeeMaster: Error ({0}) ", ex.Message)); } return(retValue); }
public static List <PurchaseOrder> GetAll_PurchaseOrderFromSharePoint(string siteUrl, string listName, string DaysDifference) { List <PurchaseOrder> _retList = new List <PurchaseOrder>(); try { using (MSC.ClientContext context = CustomSharePointUtility.GetContext(siteUrl)) { if (context != null) { MSC.List list = context.Web.Lists.GetByTitle(listName); MSC.ListItemCollectionPosition itemPosition = null; while (true) { var dataDateValue = DateTime.Now.AddDays(-Convert.ToInt32(DaysDifference)); MSC.CamlQuery camlQuery = new MSC.CamlQuery(); camlQuery.ListItemCollectionPosition = itemPosition; camlQuery.ViewXml = @"<View> <Query> <Where> <And> <Or> <Or> <Eq> <FieldRef Name='ApprovalStatus'/> <Value Type='text'>Submitted</Value> </Eq> <Eq> <FieldRef Name='ApprovalStatus'/> <Value Type='text'>Approved By Functional Head</Value> </Eq> </Or> <Or> <Eq> <FieldRef Name='ApprovalStatus'/> <Value Type='text'>Approved By Purchase Head</Value> </Eq> <Eq> <FieldRef Name='ApprovalStatus'/> <Value Type='text'>Approved By Plant Head</Value> </Eq> </Or> </Or> <Leq><FieldRef Name='Modified'/><Value Type='DateTime'>" + dataDateValue.ToString("o") + "</Value></Leq>"; camlQuery.ViewXml += @"</And></Where></Query> <RowLimit>5000</RowLimit> <ViewFields> <FieldRef Name='ID'/> <FieldRef Name='POReferenceNumber'/> <FieldRef Name='Author'/> <FieldRef Name='Created'/> <FieldRef Name='DepartmentName'/> <FieldRef Name='DepartmentID'/> <FieldRef Name='LocationName'/> <FieldRef Name='LocationID'/> <FieldRef Name='LocationType'/> <FieldRef Name='DivisionName'/> <FieldRef Name='DivisionID'/> <FieldRef Name='PONumber'/> <FieldRef Name='POCost'/> <FieldRef Name='MaterialDetails'/> <FieldRef Name='ApprovalStatus'/> <FieldRef Name='FHCode'/> <FieldRef Name='Modified'/> <FieldRef Name='CurrentApprover'/> <FieldRef Name='NewStatus'/> <FieldRef Name='NewFlow'/> </ViewFields></View>"; // camlQuery.ViewXml = "<View><Query><Where><Eq><FieldRef Name='ID' /><Value Type='Counter'>769</Value></Eq></Where></Query></View>"; MSC.ListItemCollection Items = list.GetItems(camlQuery); context.Load(Items); context.ExecuteQuery(); itemPosition = Items.ListItemCollectionPosition; foreach (MSC.ListItem item in Items) { _retList.Add(new PurchaseOrder { Id = Convert.ToInt32(item["ID"]), POReferenceNumber = Convert.ToString(item["POReferenceNumber"]).Trim(), Author = Convert.ToString((item["Author"] as Microsoft.SharePoint.Client.FieldUserValue).LookupValue), Created = Convert.ToString(item["Created"]).Trim(), DepartmentName = Convert.ToString(item["DepartmentName"]).Trim(), DepartmentID = Convert.ToString(item["DepartmentID"]).Trim(), LocationName = Convert.ToString(item["LocationName"]).Trim(), LocationID = Convert.ToString(item["LocationID"]).Trim(), LocationType = Convert.ToString(item["LocationType"]).Trim(), ////Author = Convert.ToString((item["Author"] as Microsoft.SharePoint.Client.FieldUserValue).LookupId), //Author = Convert.ToString((item["Author"] as Microsoft.SharePoint.Client.FieldUserValue).LookupValue), //FunctionalHead = Convert.ToString((item["FunctionalHead"] as Microsoft.SharePoint.Client.FieldUserValue[])[0].LookupId), //HRHead = Convert.ToString((item["HRHead"] as Microsoft.SharePoint.Client.FieldUserValue[])[0].LookupId), //HRHeadOnly = Convert.ToString((item["HRHeadOnly"] as Microsoft.SharePoint.Client.FieldUserValue).LookupId), //MDorJMD = item["MDorJMD"] == null ? "" : Convert.ToString((item["MDorJMD"] as Microsoft.SharePoint.Client.FieldUserValue).LookupId), //Recruiter = Convert.ToString((item["Recruiter"] as Microsoft.SharePoint.Client.FieldUserValue[])[0].LookupId), DivisionName = Convert.ToString(item["DivisionName"]).Trim(), DivisionID = Convert.ToString(item["DivisionID"]).Trim(), PONumber = Convert.ToString(item["PONumber"]).Trim(), POCost = Convert.ToString(item["POCost"]).Trim(), MaterialDetails = Convert.ToString(item["MaterialDetails"]).Trim(), ApprovalStatus = Convert.ToString(item["ApprovalStatus"]).Trim(), FHCode = Convert.ToString(item["FHCode"]).Trim(), Modified = Convert.ToString(item["Modified"]).Trim(), CurrentApprover = Convert.ToString(item["CurrentApprover"]).Trim(), NewStatus = Convert.ToString(item["NewStatus"]).Trim(), NewFlow = Convert.ToString(item["NewFlow"]).Trim(), }); } if (itemPosition == null) { break; // TODO: might not be correct. Was : Exit While } } } } } catch (Exception ex) { CustomSharePointUtility.WriteLog("Error in GetAll_ManpowerRequisitionFromSharePoint()" + " Error:" + ex.Message); } return(_retList); }
public static bool EmailData(List <Employee> PendingEmployee, string siteUrl, string listName) { bool retValue = false; try { using (MSC.ClientContext context = CustomSharePointUtility.GetContext(siteUrl)) { //List<Mailing> varx = new List<Mailing>(); MSC.List list = context.Web.Lists.GetByTitle(listName); MSC.ListItem listItem = null; MSC.ListItemCreationInformation itemCreateInfo = new MSC.ListItemCreationInformation(); listItem = list.AddItem(itemCreateInfo); // MSC.UserCollection users = new MSC.UserCollection(); //MSC.FieldUserValue fieldUserValue = new MSC.FieldUserValue(); MSC.FieldUserValue[] userValueCollection = new MSC.FieldUserValue[PendingEmployee.Count]; for (var i = 0; i < PendingEmployee.Count; i++) { MSC.FieldUserValue fieldUserVal = new MSC.FieldUserValue(); fieldUserVal.LookupId = Convert.ToInt32(PendingEmployee[i].EmployeeID); userValueCollection.SetValue(fieldUserVal, i); } //var _From = ""; var _To = ""; //var _Cc = ""; var _Body = ""; var _Subject = ""; _To = "1247"; _Subject = "Sales Estimate is not submitted"; _Body += "Dear User, <br><br>This is to inform you that still your Sales Estimate is not submitted kindly fill and submit on priority.<br><br>Kindly click on below link for submit estimate"; _Body += "<br><a href=" + siteUrl + "/SitePages/NewRequest.aspx>Submit Estimate</ a>"; listItem["ToUser"] = userValueCollection; listItem["SubjectDesc"] = _Subject; listItem["BodyDesc"] = _Body; listItem.Update(); try { context.ExecuteQuery(); retValue = true; } catch (Exception ex) { CustomSharePointUtility.WriteLog(string.Format("Error in InsertUpdate_EmployeeMaster ( context.ExecuteQuery();): Error ({0}) ", ex.Message)); return(false); //continue; } } // } // } //} //} } catch (Exception ex) { CustomSharePointUtility.WriteLog(string.Format("Error in InsertUpdate_EmployeeMaster: Error ({0}) ", ex.Message)); } return(retValue); }