/// <summary>
        /// 添加一个Employee记录到数据库
        /// </summary>
        /// <param name="Code"></param>
        /// <param name="Name"></param>
        /// <param name="Email"></param>
        /// <param name="Dept"></param>
        public static void AddNewEmployee(string Code, string Name, string Email, string Dept)
        {
            Employee newEmployee = new Employee(Code, Name, Email, Dept);

            DakkaLinqDataContext db = DBHelper.GetDakkaLinqDataContext();

            db.Employee.InsertOnSubmit(newEmployee);

            db.SubmitChanges();
        }
Esempio n. 2
0
        public static void DakkaByID(string ID)
        {
            DakkaLinqDataContext db = DBHelper.GetDakkaLinqDataContext();

            WorkRecord re = db.WorkRecord.Single(wr => wr.ID == long.Parse(ID));

            re.Status = StatusEnum.OK.Value;

            db.SubmitChanges();
        }
        /// <summary>
        /// 从数据库删除指定的Employee
        /// </summary>
        /// <param name="ID"></param>
        public static void RemoveEmployee(long ID)
        {
            DakkaLinqDataContext db = DBHelper.GetDakkaLinqDataContext();

            var result = db.Employee.Single(em => em.ID == ID);

            db.Employee.DeleteOnSubmit(result);

            db.SubmitChanges();
        }
        /// <summary>
        /// 获得指定范围的ShiftDef的List
        /// </summary>
        /// <param name="start"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public static List <ShiftDef.DTO> GetSome(int start, int limit)
        {
            DakkaLinqDataContext db = DBHelper.GetDakkaLinqDataContext();

            var result = db.ShiftDef.Select(sd => new DTO()
            {
                ID = sd.ID, Code = sd.Code, Name = sd.Name, Description = sd.Description, ShiftType = sd.ShiftType
            }).Skip(start).Take(limit).ToList();

            return(result);
        }
Esempio n. 5
0
        public static void UpdateEmployee(string Code, string Name, string Email, string Dept)
        {
            DakkaLinqDataContext db = DBHelper.GetDakkaLinqDataContext();

            var result = db.Employee.Single(em => em.Code == Code);

            result.Name  = Name;
            result.Email = Email;
            result.Dept  = Dept;

            db.SubmitChanges();
        }
Esempio n. 6
0
        public static Employee GetByCode(string Code)
        {
            DakkaLinqDataContext db = DBHelper.GetDakkaLinqDataContext();

            if (!IsEmployeeCodeExist(Code))
            {
                throw new Exception("Can not find employee (Code: )" + Code);
            }

            var result = db.Employee.SingleOrDefault(em => em.Code == Code);

            return(result);
        }
Esempio n. 7
0
        public static WorkCalendar GetByCode(string Code)
        {
            DakkaLinqDataContext db = DBHelper.GetDakkaLinqDataContext();

            if (!IsWorkCalendarCodeExist(Code))
            {
                throw new Exception("Can not find workCalendar (Code: )" + Code);
            }

            var result = db.WorkCalendar.SingleOrDefault(wc => wc.Code == Code);

            return(result);
        }
        /// <summary>
        /// 获得所有ShiftDef的List
        /// </summary>
        /// <returns></returns>
        public static List <ShiftDef.DTO> GetAll()
        {
            DakkaLinqDataContext db = DBHelper.GetDakkaLinqDataContext();

            var result = db.ShiftDef.Select(sd => new DTO()
            {
                ID          = sd.ID,
                Code        = sd.Code,
                Name        = sd.Name,
                Description = sd.Description,
                ShiftType   = new ShiftTypeEnum(sd.ShiftType).Name
            }).ToList();

            return(result);
        }
Esempio n. 9
0
        public static bool IsEmployeeCodeExist(string Code)
        {
            DakkaLinqDataContext db = DBHelper.GetDakkaLinqDataContext();

            var result = db.Employee.Count(em => em.Code == Code);

            if (result > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 10
0
        public static void RemoveShiftDef(long ID)
        {
            DakkaLinqDataContext db = DBHelper.GetDakkaLinqDataContext();

            var result = db.ShiftDef.Single(em => em.ID == ID);

            foreach (var line in result.ShiftPoint)
            {
                db.ShiftPoint.DeleteOnSubmit(line);
            }

            db.ShiftDef.DeleteOnSubmit(result);

            db.SubmitChanges();
        }
Esempio n. 11
0
        public static bool IsWorkCalendarCodeExist(string Code)
        {
            DakkaLinqDataContext db = DBHelper.GetDakkaLinqDataContext();

            var result = db.WorkCalendar.Count(wc => wc.Code == Code);

            if (result > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 12
0
        public static List <Employee.DTO> GetSome(int start, int limit)
        {
            DakkaLinqDataContext db = DBHelper.GetDakkaLinqDataContext();

            var result = db.Employee.Select(em => new DTO
            {
                ID    = em.ID,
                Code  = em.Code,
                Name  = em.Name,
                Email = em.Email,
                Dept  = em.Dept
            }).Skip(start).Take(limit).ToList();

            return(result);
        }
Esempio n. 13
0
        public static List <WorkCalendar.DTO> GetAll()
        {
            DakkaLinqDataContext db = DBHelper.GetDakkaLinqDataContext();

            var result = db.WorkCalendar.Select(wc => new DTO()
            {
                ID          = wc.ID,
                Code        = wc.Code,
                Name        = wc.Name,
                Description = wc.Description,
                FromDate    = wc.FromDate.HasValue ? wc.FromDate.GetValueOrDefault().ToShortDateString() : null,
                ToDate      = wc.ToDate.HasValue ? wc.ToDate.GetValueOrDefault().ToShortDateString() : null
            }).ToList();

            return(result);
        }
Esempio n. 14
0
        public static void AddNewEmployee(Employee.DTO headDto)
        {
            Employee newEmployee = new Employee()
            {
                Code  = headDto.Code,
                Name  = headDto.Name,
                Email = headDto.Email,
                Dept  = headDto.Dept
            };

            DakkaLinqDataContext db = DBHelper.GetDakkaLinqDataContext();

            db.Employee.InsertOnSubmit(newEmployee);

            db.SubmitChanges();
        }
Esempio n. 15
0
        public static Employee.DTO GetByID(long ID)
        {
            DakkaLinqDataContext db = DBHelper.GetDakkaLinqDataContext();

            var result = db.Employee.SingleOrDefault(sd => sd.ID == ID);

            if (result == null)
            {
                throw new Exception("Can not find shiftDef by id: " + ID.ToString());
            }

            Employee.DTO head = new Employee.DTO()
            {
                ID    = result.ID,
                Code  = result.Code,
                Name  = result.Name,
                Email = result.Email,
                Dept  = result.Dept
            };

            return(head);
        }
Esempio n. 16
0
        public static WorkCalendar.DTO GetByID(long ID)
        {
            DakkaLinqDataContext db = DBHelper.GetDakkaLinqDataContext();

            var result = db.WorkCalendar.SingleOrDefault(wc => wc.ID == ID);

            if (result == null)
            {
                throw new Exception("Can not find shiftDef by id: " + ID.ToString());
            }

            WorkCalendar.DTO head = new WorkCalendar.DTO()
            {
                Code              = result.Code,
                Name              = result.Name,
                Description       = result.Description,
                FromDate          = result.FromDate.HasValue ? result.FromDate.GetValueOrDefault().ToString("yyyy-MM-dd") : null,
                ToDate            = result.ToDate.HasValue ? result.ToDate.GetValueOrDefault().ToString("yyyy-MM-dd") : null,
                WorkCalendarRules = new List <WorkCalendarRule.DTO>()
            };

            foreach (var rule in result.WorkCalendarRule)
            {
                var line = new WorkCalendarRule.DTO()
                {
                    RuleType  = new RuleTypeEnum(rule.RuleType).Name,
                    IsWorkDay = rule.IsWorkDay.ToString(),
                    Week      = new WeekEnum(rule.Week).Name,
                    Month     = rule.Month.ToString(),
                    Year      = rule.Year.ToString(),
                    Day       = rule.Day.ToString(),
                    Number    = rule.Number.ToString(),
                    ShiftDef  = rule.ShiftDef.ToString()
                };
                head.WorkCalendarRules.Add(line);
            }

            return(head);
        }
Esempio n. 17
0
        public static List <WorkRecord.DTO> GetFive(string EmployeeCode, DateTime Now)
        {
            DakkaLinqDataContext db = DBHelper.GetDakkaLinqDataContext();

            var result = db.WorkRecord.Where(wr => wr.Employee1.Code == EmployeeCode && wr.WorkPoint >= Now).OrderBy(wr => wr.WorkPoint).Take(3).Concat(
                db.WorkRecord.Where(wr => wr.Employee1.Code == EmployeeCode && wr.WorkPoint < Now).OrderByDescending(wr => wr.WorkPoint).Take(2));

            result = result.OrderBy(wr => wr.WorkPoint);

            List <WorkRecord.DTO> DTOs = new List <DTO>();

            foreach (var re in result)
            {
                DTO dto = new DTO();
                dto.ID        = re.ID.ToString();
                dto.WorkPoint = re.WorkPoint.ToString();
                dto.PointType = new PointTypeEnum(re.PointType).Name;

                if (DateTime.Now < re.WorkPoint)
                {
                    dto.Status = "";
                }
                else
                {
                    if (re.Status == StatusEnum.OK.Value)
                    {
                        dto.Status = StatusEnum.OK.Name;
                    }
                    else
                    {
                        dto.Status = StatusEnum.Exception.Name;
                    }
                }

                DTOs.Add(dto);
            }

            return(DTOs);
        }
Esempio n. 18
0
        public static string GetNavPages(long ID)
        {
            DakkaLinqDataContext db = DBHelper.GetDakkaLinqDataContext();

            string first = "0";
            string prev  = "0";
            string next  = "0";
            string last  = "0";

            var xfirst = db.Employee.OrderBy(em => em.ID);

            if (xfirst.Count() > 0)
            {
                first = xfirst.First().ID.ToString();
            }

            var xprev = db.Employee.Where(em => em.ID < ID).OrderByDescending(em => em.ID);

            if (xprev.Count() > 0)
            {
                prev = xprev.First().ID.ToString();
            }

            var xlast = db.Employee.OrderByDescending(em => em.ID);

            if (xlast.Count() > 0)
            {
                last = xlast.First().ID.ToString();
            }

            var xnext = db.Employee.Where(em => em.ID > ID).OrderBy(em => em.ID);

            if (xnext.Count() > 0)
            {
                next = xnext.First().ID.ToString();
            }

            return("[" + first + "," + prev + "," + next + "," + last + "]");
        }
Esempio n. 19
0
        public static List <WorkRecord.DTO> GetSome(string EmployeeCode, DateTime FromDate, DateTime ToDate)
        {
            DakkaLinqDataContext db = DBHelper.GetDakkaLinqDataContext();

            var result = db.WorkRecord.Where(wr => wr.Employee1.Code == EmployeeCode && wr.WorkPoint >= FromDate && wr.WorkPoint <= ToDate)
                         .Select(wr => new { WorkPoint = wr.WorkPoint, PointType = wr.PointType, Status = wr.Status }).ToList();

            List <WorkRecord.DTO> DTOs = new List <DTO>();

            foreach (var re in result)
            {
                DTO dto = new DTO();
                dto.WorkPoint = re.WorkPoint.ToString();
                dto.PointType = new PointTypeEnum(re.PointType).Name;


                if (re.Status == StatusEnum.OK.Value)
                {
                    dto.Status = StatusEnum.OK.Name;
                }

                else
                {
                    if (DateTime.Now < re.WorkPoint)
                    {
                        dto.Status = "";
                    }
                    else
                    {
                        dto.Status = StatusEnum.Exception.Name;
                    }
                }

                DTOs.Add(dto);
            }

            return(DTOs);
        }
Esempio n. 20
0
        public static ShiftDef.DTO GetByID(long ID)
        {
            DakkaLinqDataContext db = DBHelper.GetDakkaLinqDataContext();

            var result = db.ShiftDef.SingleOrDefault(sd => sd.ID == ID);

            if (result == null)
            {
                throw new Exception("Can not find shiftDef by id: " + ID.ToString());
            }

            ShiftDef.DTO head = new ShiftDef.DTO()
            {
                Code        = result.Code,
                Name        = result.Name,
                Description = result.Description,
                ShiftType   = new ShiftTypeEnum(result.ShiftType).Name,
                ShiftPoints = new List <ShiftPoint.DTO>()
            };

            foreach (var point in result.ShiftPoint)
            {
                var line = new ShiftPoint.DTO()
                {
                    IndexNumber = point.IndexNumber,
                    Name        = point.Name,
                    Description = point.Description,
                    PointTime   = point.PointTime.ToLongTimeString(),
                    Before      = point.Before.ToString(),
                    After       = point.After.ToString(),
                    PointType   = new PointTypeEnum(point.PointType).Name
                };
                head.ShiftPoints.Add(line);
            }

            return(head);
        }
Esempio n. 21
0
        public static void AddNewWorkCalendar(WorkCalendar.DTO headDTO, List <WorkCalendarRule.DTO> lineDTOs)
        {
            DakkaLinqDataContext db = DBHelper.GetDakkaLinqDataContext();

            WorkCalendar workCalendar = new WorkCalendar
            {
                Code        = headDTO.Code,
                Name        = headDTO.Name,
                Description = headDTO.Description,
                //FromDate = DateTime.Parse(headDTO.FromDate),
                //ToDate = DateTime.Parse(headDTO.ToDate)
            };

            if (headDTO.FromDate != null)
            {
                workCalendar.FromDate = DateTime.Parse(headDTO.FromDate);
            }
            if (headDTO.ToDate != null)
            {
                workCalendar.ToDate = DateTime.Parse(headDTO.ToDate);
            }

            foreach (var line in lineDTOs)
            {
                WorkCalendarRule workCalendarRule = new WorkCalendarRule()
                {
                    RuleType  = new RuleTypeEnum(line.RuleType).Value,
                    IsWorkDay = new IsWorkDayEnum(line.IsWorkDay).Value
                };

                if (line.Week != "" && line.Week != "null")
                {
                    workCalendarRule.Week = new WeekEnum(line.Week).Value;
                }
                if (line.Year != "" && line.Year != "null")
                {
                    workCalendarRule.Year = int.Parse(line.Year);
                }
                if (line.Month != "" && line.Month != "null")
                {
                    workCalendarRule.Month = int.Parse(line.Month);
                }
                if (line.Day != "" && line.Day != "null")
                {
                    workCalendarRule.Day = int.Parse(line.Day);
                }
                if (line.Number != "" && line.Number != "null")
                {
                    workCalendarRule.Number = int.Parse(line.Number);
                }
                if (line.ShiftDef != "" && line.ShiftDef != "null")
                {
                    ShiftDef sd = ShiftDef.GetByCode(line.ShiftDef);

                    if (sd != null)
                    {
                        workCalendarRule.ShiftDef = sd.ID;
                    }
                }

                workCalendarRule.RuleValue = "0";
                // TODO: 此处RuleValue在数据库中不能为空, 故先赋值, 待修改.

                workCalendar.WorkCalendarRule.Add(workCalendarRule);
            }

            db.WorkCalendar.InsertOnSubmit(workCalendar);

            db.SubmitChanges();
        }
Esempio n. 22
0
        public static void Make(string EmployeeCode, string WorkCalendarCode, DateTime FromDate, DateTime ToDate)
        {
            Employee     employee     = DakkaData.Employee.GetByCode(EmployeeCode);
            WorkCalendar workCalendar = DakkaData.WorkCalendar.GetByCode(WorkCalendarCode);

            long EmployeeID = employee.ID;

            List <WorkRecord> records = new List <WorkRecord>();

            do
            {
                bool     isWorkDay = false;
                ShiftDef shiftDef  = null;

                foreach (var rule in workCalendar.WorkCalendarRule)
                {
                    if (rule.RuleType == RuleTypeEnum.Week.Value)
                    {
                        if (rule.Week == new WeekEnum(FromDate.DayOfWeek.ToString()).Value)
                        {
                            isWorkDay = rule.IsWorkDay;
                            shiftDef  = rule.ShiftDef1;
                        }
                    }
                    else if (rule.RuleType == RuleTypeEnum.Month.Value)
                    {
                        if (rule.Day == FromDate.Day)
                        {
                            isWorkDay = rule.IsWorkDay;
                            shiftDef  = rule.ShiftDef1;
                        }
                    }
                    else if (rule.RuleType == RuleTypeEnum.Year.Value)
                    {
                        if (rule.Month == FromDate.Month && rule.Day == FromDate.Day)
                        {
                            isWorkDay = rule.IsWorkDay;
                            shiftDef  = rule.ShiftDef1;
                        }
                    }
                    else if (rule.RuleType == RuleTypeEnum.Date.Value)
                    {
                        if (rule.Year == FromDate.Year &&
                            rule.Month == FromDate.Month &&
                            rule.Day == FromDate.Day)
                        {
                            isWorkDay = rule.IsWorkDay;
                            shiftDef  = rule.ShiftDef1;
                        }
                    }
                }

                if (isWorkDay && shiftDef != null)
                {
                    foreach (var shiftPoint in shiftDef.ShiftPoint)
                    {
                        WorkRecord workRecord = new WorkRecord()
                        {
                            Employee  = EmployeeID,
                            WorkPoint = new DateTime(FromDate.Year, FromDate.Month, FromDate.Day,
                                                     shiftPoint.PointTime.Hour, shiftPoint.PointTime.Minute, shiftPoint.PointTime.Second),
                            PointType = shiftPoint.PointType,
                            Status    = StatusEnum.Null.Value
                        };

                        records.Add(workRecord);
                    }
                }

                FromDate = FromDate.AddDays(1);
            }while (FromDate.Date <= ToDate);

            DakkaLinqDataContext db = DBHelper.GetDakkaLinqDataContext();

            db.WorkRecord.InsertAllOnSubmit(records);

            db.SubmitChanges();
        }