示例#1
0
        public static bool IsDelegationOfNewTaskExisted(int fromEmployeeId, List <int> toEmployeeIds, string listUrl, DateTime fromDate, DateTime toDate, string siteUrl)
        {
            bool ret = false;

            DelegationsOfNewTaskDAL delegationsOfNewTaskDALObject = new DelegationsOfNewTaskDAL(siteUrl);

            if (delegationsOfNewTaskDALObject != null)
            {
                string queryString = $@"<Where>
                                            <And>
                                                <And>
                                                    <Eq>
                                                        <FieldRef Name='{StringConstant.DelegationsOfNewTaskList.Fields.ListUrl}' />
                                                        <Value Type='Text'>{listUrl}</Value>
                                                    </Eq>
                                                    <Eq>
                                                        <FieldRef Name='{StringConstant.DelegationsOfNewTaskList.Fields.FromEmployee}' LookupId='TRUE'/>
                                                        <Value Type='Lookup'>{fromEmployeeId}</Value>
                                                    </Eq>
                                                </And>
                                                <And>
                                                    <Eq>
                                                        <FieldRef Name='{StringConstant.DelegationsOfNewTaskList.Fields.FromDate}' />
                                                        <Value IncludeTimeValue='FALSE' Type='DateTime'>{fromDate.ToString(StringConstant.DateFormatForCAML)}</Value>
                                                    </Eq>
                                                    <Eq>
                                                        <FieldRef Name='{StringConstant.DelegationsOfNewTaskList.Fields.ToDate}' />
                                                        <Value IncludeTimeValue='FALSE' Type='DateTime'>{toDate.ToString(StringConstant.DateFormatForCAML)}</Value>
                                                    </Eq>
                                                </And>
                                            </And>
                                    </Where>";

                toEmployeeIds.Sort();
                string toEmployeeIdsStr = string.Join("#", toEmployeeIds);
                toEmployeeIdsStr = !string.IsNullOrEmpty(toEmployeeIdsStr) ? string.Format("#{0}#", toEmployeeIdsStr) : toEmployeeIdsStr;

                SPQuery query = new SPQuery {
                    Query = queryString
                };
                var delegations = delegationsOfNewTaskDALObject.GetByQuery(query);
                if (delegations != null && delegations.Count > 0)
                {
                    foreach (var delegation in delegations)
                    {
                        List <int> delegatedEmployeeIds = delegation.ToEmployee.Select(e => e.LookupId).ToList();
                        delegatedEmployeeIds.Sort();
                        string delegatedEmployeeIdsStr = string.Join("#", delegatedEmployeeIds);
                        delegatedEmployeeIdsStr = !string.IsNullOrEmpty(delegatedEmployeeIdsStr) ? string.Format("#{0}#", delegatedEmployeeIdsStr) : delegatedEmployeeIdsStr;
                        if (delegatedEmployeeIdsStr.IndexOf(toEmployeeIdsStr) >= 0)
                        {
                            ret = true;
                            break;
                        }
                    }
                }
            }

            return(ret);
        }
 private void InitObjects()
 {
     this.employeeInfoDAL = new EmployeeInfoDAL(this.SiteUrl);
     this.InitCurrentEmployeeInfoObject();
     this.employeePositionDAL            = new EmployeePositionDAL(this.SiteUrl);
     this.delegationModulesDAL           = new DelegationModulesDAL(this.SiteUrl);
     this.delegationEmployeePositionsDAL = new DelegationEmployeePositionsDAL(this.SiteUrl);
     this.delegationsOfNewTaskDAL        = new DelegationsOfNewTaskDAL(this.SiteUrl);
     this.delegationsDAL = new DelegationsDAL(this.SiteUrl);
     this.departmentDAL  = new DepartmentDAL(this.SiteUrl);
 }
        /// <summary>
        /// To check employee who is delegated to process for new task.
        /// </summary>
        /// <param name="fromEmployeeId">The employ id who is processing for this task.</param>
        /// <param name="toEmployeeId"></param>
        /// <param name="listUrl">The url of list object. For example: /Lists/Requests, /Lists/Recruitments</param>
        /// <param name="itemId">The id of SPListItem (task).</param>
        /// <param name="siteUrl">The current site url.</param>
        /// <returns></returns>
        public static DelegationOfNewTask IsDelegationOfNewTask(int fromEmployeeId, int toEmployeeId, string listUrl, string siteUrl)
        {
            DelegationOfNewTask res = null;

            if (delegationsOfNewTaskDAL == null)
            {
                delegationsOfNewTaskDAL = new DelegationsOfNewTaskDAL(siteUrl);
            }

            string  queryString = $@"<Where>
                                        <And>
                                            <Leq>
                                                <FieldRef Name='{StringConstant.DelegationsOfNewTaskList.Fields.FromDate}' />
                                                <Value IncludeTimeValue='FALSE' Type='DateTime'>{DateTime.Today.Date.ToString(StringConstant.DateFormatForCAML)}</Value>
                                            </Leq>
                                            <And>
                                                <Geq>
                                                    <FieldRef Name='{StringConstant.DelegationsOfNewTaskList.Fields.ToDate}' />
                                                    <Value IncludeTimeValue='FALSE' Type='DateTime'>{DateTime.Today.Date.ToString(StringConstant.DateFormatForCAML)}</Value>
                                                </Geq>
                                                <And>
                                                    <Eq>
                                                        <FieldRef Name='{StringConstant.DelegationsOfNewTaskList.Fields.FromEmployee}' LookupId='TRUE'/>
                                                        <Value Type='Lookup'>{fromEmployeeId}</Value>
                                                    </Eq>
                                                        <And>
                                                            <Eq>
                                                                <FieldRef Name='{StringConstant.DelegationsOfNewTaskList.Fields.ToEmployee}' LookupId='TRUE'/>
                                                                <Value Type='Lookup'>{toEmployeeId}</Value>
                                                            </Eq>
                                                            <Eq>
                                                                <FieldRef Name='{StringConstant.DelegationsOfNewTaskList.Fields.ListUrl}' />
                                                                <Value Type='Text'>{listUrl}</Value>
                                                            </Eq>
                                                        </And>
                                                </And>
                                            </And>
                                        </And>
                                    </Where>";
            SPQuery query       = new SPQuery {
                Query = queryString, RowLimit = 1
            };
            var delegationsOfNewTask = delegationsOfNewTaskDAL.GetByQuery(query);

            if (delegationsOfNewTask != null && delegationsOfNewTask.Count > 0)
            {
                res = delegationsOfNewTask[0];
            }

            return(res);
        }
        /// <summary>
        ///  To check employee who has delegation of new task.
        /// </summary>
        /// <param name="fromEmployeeId">The employ id who is processing for this task.</param>
        /// <param name="listUrl">The url of list object. For example: /Lists/Requests, /Lists/Recruitments</param>
        /// <param name="webUrl">The url of current web.</param>
        /// <returns>Returns list of configurations about DelegationOfNewTasks which allows to create new delegation for delegated employees.</returns>
        public static List <DelegationOfNewTask> HasDelegationOfNewTasks(int fromEmployeeId, string listUrl, string webUrl)
        {
            List <DelegationOfNewTask> res = null;

            if (delegationsOfNewTaskDAL == null)
            {
                delegationsOfNewTaskDAL = new DelegationsOfNewTaskDAL(webUrl);
            }

            string  queryString = $@"<Where>
                                        <And>
                                            <Leq>
                                                <FieldRef Name='{StringConstant.DelegationsOfNewTaskList.Fields.FromDate}' />
                                                <Value IncludeTimeValue='FALSE' Type='DateTime'>{DateTime.Today.Date.ToString(StringConstant.DateFormatForCAML)}</Value>
                                            </Leq>
                                            <And>
                                                <Geq>
                                                    <FieldRef Name='{StringConstant.DelegationsOfNewTaskList.Fields.ToDate}' />
                                                    <Value IncludeTimeValue='FALSE' Type='DateTime'>{DateTime.Today.Date.ToString(StringConstant.DateFormatForCAML)}</Value>
                                                </Geq>
                                                <And>
                                                    <Eq>
                                                        <FieldRef Name='{StringConstant.DelegationsOfNewTaskList.Fields.FromEmployee}' LookupId='TRUE'/>
                                                        <Value Type='Lookup'>{fromEmployeeId}</Value>
                                                    </Eq>
                                                    <Eq>
                                                        <FieldRef Name='{StringConstant.DelegationsOfNewTaskList.Fields.ListUrl}' />
                                                        <Value Type='Text'>{listUrl}</Value>
                                                    </Eq>
                                                </And>
                                            </And>
                                        </And>
                                    </Where>";
            SPQuery query       = new SPQuery {
                Query = queryString
            };

            res = delegationsOfNewTaskDAL.GetByQuery(query);

            return(res);
        }