Beispiel #1
0
        public static List <PurchaseApprovers> PurchaseApproversData(PurchaseOrder purchaseDataFinal, string RootsiteUrl, string siteUrl, string listName, string EmaillistName)
        {
            List <PurchaseApprovers> _returnList = new List <PurchaseApprovers>();

            try
            {
                using (MSC.ClientContext context = CustomSharePointUtility.GetEmpContext(RootsiteUrl))
                {
                    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>
                                        <Eq>
                                            <FieldRef Name='Division' LookupId='True'/>
                                            <Value Type='Lookup'>" + purchaseDataFinal.DivisionID + "</Value></Eq>";
                            camlQuery.ViewXml += @"<Eq>
                                            <FieldRef Name ='Location' LookupId='True'/>
                                            <Value Type='Lookup'>" + purchaseDataFinal.LocationID + "</Value></Eq>";

                            camlQuery.ViewXml += @"</And></Where>
                                 </Query>
                                <RowLimit>5000</RowLimit>
                                <ViewFields>
                                <FieldRef Name='ID'/>
                                <FieldRef Name='ApproverName'/>
                                <FieldRef Name='ApproverType'/>
                                </ViewFields></View>";
                            MSC.ListItemCollection Items = list.GetItems(camlQuery);

                            context.Load(Items);
                            context.ExecuteQuery();
                            itemPosition = Items.ListItemCollectionPosition;
                            foreach (MSC.ListItem item in Items)
                            {
                                _returnList.Add(new PurchaseApprovers
                                {
                                    ApproverName = item["ApproverName"] == null ? "" : Convert.ToString((item["ApproverName"] as Microsoft.SharePoint.Client.FieldUserValue[])[0].LookupId),
                                    ApproverType = Convert.ToString(item["ApproverType"]).Trim(),
                                });
                            }
                            if (itemPosition == null)
                            {
                                break; // TODO: might not be correct. Was : Exit While
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CustomSharePointUtility.WriteLog("Error in  PurchaseApproversData()" + " Error:" + ex.Message);
            }
            for (var i = 0; i < _returnList.Count; i++)
            {
                if (_returnList[i].ApproverType == "MD" || _returnList[i].ApproverType == "JMD")
                {
                    String MDorJMD = _returnList[i].ApproverName;
                    var    success = CustomSharePointUtility.EmailData(purchaseDataFinal, "", "", "", MDorJMD, siteUrl, EmaillistName);
                    if (success)
                    {
                    }
                }
                else if (_returnList[i].ApproverType == "PURCHASE HEAD")
                {
                    String PurchaseHead = _returnList[i].ApproverName;
                    var    success      = CustomSharePointUtility.EmailData(purchaseDataFinal, "", PurchaseHead, "", "", siteUrl, EmaillistName);
                    if (success)
                    {
                    }
                }
                else if (_returnList[i].ApproverType == "PLANT HEAD")
                {
                    String PlantHead = _returnList[i].ApproverName;
                    var    success   = CustomSharePointUtility.EmailData(purchaseDataFinal, "", "", PlantHead, "", siteUrl, EmaillistName);
                    if (success)
                    {
                    }
                }
            }
            return(_returnList);
        }
Beispiel #2
0
        public static List <EmployeeMaster> EmployeeMasterData(PurchaseOrder purchaseDataFinal, string RootsiteUrl, string siteUrl, string listName, string EmaillistName)
        {
            List <EmployeeMaster> _returnList = new List <EmployeeMaster>();

            try
            {
                using (MSC.ClientContext context = CustomSharePointUtility.GetEmpContext(RootsiteUrl))
                {
                    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>
                                        <Eq>
                                            <FieldRef Name='Employee_x0020_Code'/>
                                            <Value Type='text'>" + purchaseDataFinal.FHCode + "</Value></Eq>";

                            camlQuery.ViewXml += @"</Where>
                                 </Query>
                                <RowLimit>5000</RowLimit>
                                <ViewFields>
                                <FieldRef Name='ID'/>
                                <FieldRef Name='Employee_x0020_Code'/>
                                <FieldRef Name='Employee_x0020_Email'/>
                                </ViewFields></View>";
                            MSC.ListItemCollection Items = list.GetItems(camlQuery);

                            context.Load(Items);
                            context.ExecuteQuery();
                            itemPosition = Items.ListItemCollectionPosition;
                            foreach (MSC.ListItem item in Items)
                            {
                                _returnList.Add(new EmployeeMaster
                                {
                                    Employee_x0020_Code  = Convert.ToString(item["Employee_x0020_Code"]).Trim(),
                                    Employee_x0020_Email = Convert.ToString(item["Employee_x0020_Email"]).Trim(),
                                });
                            }
                            if (itemPosition == null)
                            {
                                break; // TODO: might not be correct. Was : Exit While
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CustomSharePointUtility.WriteLog("Error in  EmployeeMasterData()" + " Error:" + ex.Message);
            }
            var success = CustomSharePointUtility.EmailData(purchaseDataFinal, _returnList[0].Employee_x0020_Email, "", "", "", siteUrl, EmaillistName);

            if (success)
            {
            }
            return(_returnList);
        }