コード例 #1
0
        private void UpdateDepartmentTotalDownTime(DownTimeDTO uDto)
        {
            var pr         = new DepartmentTotalRepository();
            var prod       = new DepartmentTotal();
            var prodexists = pr.GetByDateAndDepartment(DateTime.Parse(uDto.DownTimeDate), int.Parse(uDto.DepartmentID));
            int wb         = 0;

            wb = uDto.Minutes == null ? 0 : int.Parse(uDto.Minutes);

            if (prodexists == null)
            {
                prod.DepartmentID = int.Parse(uDto.DepartmentID);
                prod.DTDate       = DateTime.Parse(uDto.DownTimeDate);
                prod.DownTime     = wb;
                pr.Save(prod);
            }
            else
            {
                prod = prodexists;
                var             wbr = new DownTimeRepository();
                List <DownTime> wbl = wbr.GetByDateAndDepartment(DateTime.Parse(uDto.DownTimeDate), int.Parse(uDto.DepartmentID));
                wb = wbl.Where(x => x.Minutes != null).Sum(x => x.Minutes);


                if (wb != 0)
                {
                    prod.DownTime = wb;
                }
                pr.Save(prod);
            }
        }
コード例 #2
0
        internal HttpResponseMessage DepartmentDates(HttpRequestMessage request, DepartmentTotalDTO cqDTO)
        {
            string key;
            var    aur       = new AppUserRepository();
            var    companyId = 0;
            var    userId    = aur.ValidateUser(cqDTO.Key, out key, ref companyId);

            if (userId > 0)
            {
                var ur = new DepartmentTotalRepository();
                var u  = new DepartmentTotal();
                if (cqDTO.DTDate != null)
                {
                    cqDTO.Start_DTDate = DateTime.Parse(cqDTO.DTDate).ToString();
                    cqDTO.End_DTDate   = DateTime.Parse(cqDTO.DTDate).AddDays(1).ToString();
                }
                else
                {
                    int sm = int.Parse(cqDTO.StartDateMonth);
                    if (sm == 1)
                    {
                        cqDTO.Start_DTDate = DateTime.Parse("12/23/" + (int.Parse(cqDTO.StartDateYear) - 1).ToString()).ToString();
                        cqDTO.End_DTDate   = DateTime.Parse("2/14/" + cqDTO.StartDateYear).ToString();
                    }
                    else if (sm == 12)
                    {
                        cqDTO.Start_DTDate = DateTime.Parse("11/23/" + cqDTO.StartDateYear).ToString();
                        cqDTO.End_DTDate   = DateTime.Parse("1/14/" + (int.Parse(cqDTO.StartDateYear) + 1).ToString()).ToString();
                    }
                    else
                    {
                        cqDTO.Start_DTDate = DateTime.Parse((int.Parse(cqDTO.StartDateMonth) - 1).ToString() + "/23/" + cqDTO.StartDateYear).ToString();
                        cqDTO.End_DTDate   = DateTime.Parse((int.Parse(cqDTO.StartDateMonth) + 1).ToString() + "/14/" + cqDTO.StartDateYear).ToString();
                    }

                    cqDTO.StartDateMonth = null;
                    cqDTO.StartDateYear  = null;
                }
                var predicate = ur.GetPredicate(cqDTO, u, companyId);
                var data      = ur.GetByPredicate(predicate);
                data = data.GroupBy(x => x.DTDate).Select(x => x.First()).OrderBy(x => x.DTDate).ToList();
                var col = new Collection <Dictionary <string, string> >();
                foreach (var item in data)
                {
                    var dic = new Dictionary <string, string>();
                    dic.Add("DTDate", item.DTDate.ToShortDateString());
                    col.Add(dic);
                }

                var retVal = new GenericDTO
                {
                    Key        = key,
                    ReturnData = col
                };
                return(Request.CreateResponse(HttpStatusCode.OK, retVal));
            }
            var message = "validation failed";

            return(request.CreateResponse(HttpStatusCode.NotFound, message));
        }
コード例 #3
0
        private void UpdateDepartmentTotalAbsence(AbsenceDTO uDto)
        {
            var pr         = new DepartmentTotalRepository();
            var prod       = new DepartmentTotal();
            var prodexists = pr.GetByDateAndDepartment(DateTime.Parse(uDto.AbsenceDate), int.Parse(uDto.DepartmentID));
            int wb         = 0;

            wb  = uDto.RegEmpLate == null ? 0 : int.Parse(uDto.RegEmpLate);
            wb += uDto.RegEmpLeftEarly == null ? 0 : int.Parse(uDto.RegEmpLeftEarly);
            wb += uDto.RegEmpOut == null ? 0 : int.Parse(uDto.RegEmpOut);
            wb += uDto.TempEmpLate == null ? 0 : int.Parse(uDto.TempEmpLate);
            wb += uDto.TempEmpLeftEarly == null ? 0 : int.Parse(uDto.TempEmpLeftEarly);
            wb += uDto.TempEmpOut == null ? 0 : int.Parse(uDto.TempEmpOut);
            wb += uDto.InmateLeftEarly == null ? 0 : int.Parse(uDto.InmateLeftEarly);
            wb += uDto.InmateOut == null ? 0 : int.Parse(uDto.InmateOut);
            wb += uDto.EmployeesOnVacation == null ? 0 : int.Parse(uDto.EmployeesOnVacation);
            if (prodexists == null)
            {
                prod.DepartmentID = int.Parse(uDto.DepartmentID);
                prod.DTDate       = DateTime.Parse(uDto.AbsenceDate);
                prod.Absences     = wb;
                pr.Save(prod);
            }
            else
            {
                prod = prodexists;
                var            wbr = new AbsenceRepository();
                List <Absence> wbl = wbr.GetByDateAndDepartment(DateTime.Parse(uDto.AbsenceDate), int.Parse(uDto.DepartmentID));
                wb  = wbl.Where(x => x.RegEmpLate != null).Sum(x => x.RegEmpLate).Value;
                wb += wbl.Where(x => x.RegEmpLeftEarly != null).Sum(x => x.RegEmpLeftEarly).Value;
                wb += wbl.Where(x => x.RegEmpOut != null).Sum(x => x.RegEmpOut).Value;
                wb += wbl.Where(x => x.TempEmpLate != null).Sum(x => x.TempEmpLate).Value;
                wb += wbl.Where(x => x.TempEmpLeftEarly != null).Sum(x => x.TempEmpLeftEarly).Value;
                wb += wbl.Where(x => x.TempEmpOut != null).Sum(x => x.TempEmpOut).Value;
                wb += wbl.Where(x => x.InmateLeftEarly != null).Sum(x => x.InmateLeftEarly).Value;
                wb += wbl.Where(x => x.InmateOut != null).Sum(x => x.InmateOut).Value;
                wb += wbl.Where(x => x.EmployeesOnVacation != null).Sum(x => x.EmployeesOnVacation).Value;

                if (wb != 0)
                {
                    prod.Absences = wb;
                }
                pr.Save(prod);
            }
        }
コード例 #4
0
        private void UpdateDepartmentTotalFinishTime(FinishTimeDTO uDto)
        {
            var      pr         = new DepartmentTotalRepository();
            var      prod       = new DepartmentTotal();
            var      prodexists = pr.GetByDateAndDepartment(DateTime.Parse(DateTime.Parse(uDto.FinishDateTime).ToShortDateString()), int.Parse(uDto.DepartmentID));
            DateTime fdt        = DateTime.Parse(uDto.FinishDateTime);

            if (prodexists == null)
            {
                prod.DepartmentID = int.Parse(uDto.DepartmentID);
                prod.DTDate       = DateTime.Parse(DateTime.Parse(uDto.FinishDateTime).ToShortDateString());
                prod.FinishTime   = fdt;
                pr.Save(prod);
            }
            else
            {
                prod = prodexists;
                var wbr = new FinishTimeRepository();
                List <FinishTime> wbl = wbr.GetByDateAndDepartment(DateTime.Parse(DateTime.Parse(uDto.FinishDateTime).ToShortDateString()), int.Parse(uDto.DepartmentID));
                fdt             = wbl.Select(x => x.FinishDateTime).FirstOrDefault();
                prod.FinishTime = fdt;
                pr.Save(prod);
            }
        }
コード例 #5
0
        public HttpResponseMessage DepartmentTotals([FromBody] DepartmentTotalDTO cqDTO)
        {
            string key;
            var    aur       = new AppUserRepository();
            var    companyId = 0;
            var    userId    = aur.ValidateUser(cqDTO.Key, out key, ref companyId);

            if (userId > 0)
            {
                var ur = new DepartmentTotalRepository();
                var u  = new DepartmentTotal();
                if (cqDTO.DTDate != null)
                {
                    cqDTO.Start_DTDate = DateTime.Parse(cqDTO.DTDate).ToString();
                    cqDTO.End_DTDate   = DateTime.Parse(cqDTO.DTDate).AddDays(1).ToString();
                }
                else
                {
                    int sm = int.Parse(cqDTO.StartDateMonth);
                    if (sm == 1)
                    {
                        cqDTO.Start_DTDate = DateTime.Parse("12/23/" + (int.Parse(cqDTO.StartDateYear) - 1).ToString()).ToString();
                        cqDTO.End_DTDate   = DateTime.Parse("2/14/" + cqDTO.StartDateYear).ToString();
                    }
                    else if (sm == 12)
                    {
                        cqDTO.Start_DTDate = DateTime.Parse("11/23/" + cqDTO.StartDateYear).ToString();
                        cqDTO.End_DTDate   = DateTime.Parse("1/14/" + (int.Parse(cqDTO.StartDateYear) + 1).ToString()).ToString();
                    }
                    else
                    {
                        cqDTO.Start_DTDate = DateTime.Parse((int.Parse(cqDTO.StartDateMonth) - 1).ToString() + "/23/" + cqDTO.StartDateYear).ToString();
                        cqDTO.End_DTDate   = DateTime.Parse((int.Parse(cqDTO.StartDateMonth) + 1).ToString() + "/14/" + cqDTO.StartDateYear).ToString();
                    }

                    cqDTO.StartDateMonth = null;
                    cqDTO.StartDateYear  = null;
                }
                SGApp.DTOs.GenericDTO dto = new GenericDTO();
                dto.StartDate = DateTime.Parse(cqDTO.Start_DTDate);
                dto.EndDate   = DateTime.Parse(cqDTO.End_DTDate);

                var predicate = ur.GetPredicate(cqDTO, u, companyId);
                var data      = ur.GetByPredicate(predicate);
                var col       = new Collection <Dictionary <string, string> >();
                data = data.OrderBy(x => x.DTDate).ToList();

                var depr = new DepartmentRepository();
                var deps = depr.GetDepartments();

                foreach (Department dep in deps)
                {
                    DepartmentTotal dt  = data.Where(x => x.DepartmentID == dep.DepartmentID).FirstOrDefault();
                    var             dic = new Dictionary <string, string>();
                    if (dt != null)
                    {
                        dic.Add("DepartmentTotalId", dt.DepartmentTotalID.ToString());
                        dic.Add("DepartmentID", dt.DepartmentID.ToString());
                        dic.Add("DepartmentName", dt.Department.DepartmentName);
                        dic.Add("DTDate", dt.DTDate.ToShortDateString());
                        dic.Add("FinishTime", dt.FinishTime != null ? dt.FinishTime.Value.ToShortTimeString() : "---");
                        dic.Add("DownTime", dt.DownTime != null ? dt.DownTime.ToString() : "---");
                        dic.Add("ShiftWeight", dt.ShiftWeight != null ? dt.ShiftWeight.ToString() : "---");
                        dic.Add("Absences", dt.Absences != null ? dt.Absences.ToString() : "---");
                    }
                    else
                    {
                        dic.Add("DepartmentTotalId", "-1");
                        dic.Add("DepartmentID", dep.DepartmentID.ToString());
                        dic.Add("DepartmentName", dep.DepartmentName);
                        dic.Add("DTDate", dto.StartDate.ToShortDateString());
                        dic.Add("FinishTime", "---");
                        dic.Add("DownTime", "---");
                        dic.Add("ShiftWeight", "---");
                        dic.Add("Absences", "---");
                    }

                    col.Add(dic);
                }
                var retVal = new GenericDTO
                {
                    Key        = key,
                    ReturnData = col
                };
                return(Request.CreateResponse(HttpStatusCode.OK, retVal));
            }
            var message = "validation failed";

            return(Request.CreateResponse(HttpStatusCode.NotFound, message));
        }