private XElement BuildViewString(EmployeeInfo currentEmployeeInfo, string departmentId) { EmployeeRole currentUserRole = UserPermission.GetCurrentUserRole(currentEmployeeInfo); XElement filterElement = null; string deptFilterStr = @"<Eq> <FieldRef Name='CommonDepartment' LookupId='TRUE'/> <Value Type='Lookup'>{DepartmentId}</Value> </Eq>"; if (currentUserRole == EmployeeRole.BOD || currentUserRole == EmployeeRole.AdminOfHR || currentUserRole == EmployeeRole.DepartmentHeadOfHR) { if (!string.IsNullOrEmpty(departmentId) && departmentId.Trim().Equals("0")) { deptFilterStr = @"<IsNotNull> <FieldRef Name='CommonDepartment' /> </IsNotNull>"; } } deptFilterStr = $@"<And> {deptFilterStr} <Eq> <FieldRef Name='CommonLocation' LookupId='TRUE'/> <Value Type='Lookup'>{currentEmployeeInfo.FactoryLocation.LookupId}</Value> </Eq> </And>"; string statusQuery = @"<Gt> <FieldRef Name='ID' /> <Value Type='Counter'>0</Value> </Gt>"; if (currentUserRole == EmployeeRole.AdminOfHR) { statusQuery = @"<Eq> <FieldRef Name='ApprovalStatus' /> <Value Type='Text'>Approved</Value> </Eq>"; } filterElement = XElement.Parse(@"<And>" + statusQuery + @"<And>" + deptFilterStr + @"<And> <Geq> <FieldRef Name='Created' /> <Value IncludeTimeValue='TRUE' Type='DateTime'>{StartMonth}</Value> </Geq> <Leq> <FieldRef Name='Created' /> <Value IncludeTimeValue='TRUE' Type='DateTime'>{EndMonth}</Value> </Leq> </And> </And> </And>"); return(filterElement); }
private XElement BuildViewString(EmployeeInfo currentEmployeeInfo, string departmentId, string vehicleId) { EmployeeRole currentUserRole = UserPermission.GetCurrentUserRole(currentEmployeeInfo); XElement filterElement = null; string fromDate = this.Page.Request.Params.Get("AdminFromDate"); string fromDateValue = $"{DateTime.Now.Year}-{DateTime.Now.Month}-{DateTime.Now.Day}"; if (!string.IsNullOrEmpty(fromDate)) { DateTime dtFromDate; bool isValidFromDate = DateTime.TryParseExact(fromDate, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture, DateTimeStyles.None, out dtFromDate); if (isValidFromDate) { fromDateValue = $"{dtFromDate:yyyy-MM-dd}"; } } string toDate = this.Page.Request.Params.Get("AdminToDate"); string toDateValue = $"{DateTime.Now.Year}-{DateTime.Now.Month}-{DateTime.Now.Day}"; if (!string.IsNullOrEmpty(toDate)) { DateTime dtToDate; bool isValidToDate = DateTime.TryParseExact(toDate, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture, DateTimeStyles.None, out dtToDate); if (isValidToDate) { toDateValue = $"{dtToDate:yyyy-MM-dd};"; } } string filterStr = $@"<And> <Geq> <FieldRef Name='TransportTime' /> <Value IncludeTimeValue='FALSE' Type='DateTime'>{fromDateValue}</Value> </Geq> <Leq> <FieldRef Name='TransportTime' /> <Value IncludeTimeValue='FALSE' Type='DateTime'>{toDateValue}</Value> </Leq> </And>"; string deptFilterStr = @"<Eq> <FieldRef Name='CommonDepartment' LookupId='TRUE'/> <Value Type='Lookup'>{DepartmentId}</Value> </Eq>"; string vehicleFilterStr = @"<Eq> <FieldRef Name='VehicleLookup' LookupId='TRUE'/> <Value Type='Lookup'>{VehicleId}</Value> </Eq>"; if (currentUserRole == EmployeeRole.BOD || currentUserRole == EmployeeRole.AdminOfHR || currentUserRole == EmployeeRole.DepartmentHeadOfHR) { if (!string.IsNullOrEmpty(departmentId) && !departmentId.Trim().Equals("0")) { filterStr = string.Format("<And>{0}{1}</And>", deptFilterStr, filterStr); } if (!string.IsNullOrEmpty(vehicleId) && !vehicleId.Trim().Equals("0")) { filterStr = string.Format("<And>{0}{1}</And>", vehicleFilterStr, filterStr); } } filterStr = $@"<And>{filterStr}<Eq><FieldRef Name='CommonLocation' LookupId='TRUE'/><Value Type='Lookup'>{currentEmployeeInfo.FactoryLocation.LookupId}</Value></Eq></And>"; if (currentUserRole != EmployeeRole.BOD && currentUserRole == EmployeeRole.AdminOfHR) { filterStr = string.Format(@"<And>{0}<Eq><FieldRef Name='ApprovalStatus' /><Value Type='Text'>Approved</Value></Eq></And>", filterStr); } filterElement = XElement.Parse(filterStr); return(filterElement); }