Example #1
0
        public static void UpdateShiftDef(ShiftDef.DTO headDTO, List <ShiftPoint.DTO> lineDTOs)
        {
            DakkaLinqDataContext db = DBHelper.GetDakkaLinqDataContext();

            ShiftDef shiftDef = db.ShiftDef.Single(sd => sd.ID == headDTO.ID);

            foreach (ShiftPoint point in shiftDef.ShiftPoint)
            {
                db.ShiftPoint.DeleteOnSubmit(point);
            }

            shiftDef.Code        = headDTO.Code;
            shiftDef.Name        = headDTO.Name;
            shiftDef.ShiftType   = new ShiftTypeEnum(headDTO.ShiftType).Value;
            shiftDef.Description = headDTO.Description;

            foreach (var line in lineDTOs)
            {
                ShiftPoint shiftPoint = new ShiftPoint
                {
                    IndexNumber = line.IndexNumber,
                    Name        = line.Name,
                    PointTime   = DateTime.Parse(line.PointTime),
                    Before      = int.Parse(line.Before),
                    After       = int.Parse(line.After),
                    PointType   = new PointTypeEnum(line.PointType).Value
                };

                shiftDef.ShiftPoint.Add(shiftPoint);
            }

            db.SubmitChanges();
        }
Example #2
0
        public static void AddNewShiftDef(ShiftDef.DTO headDTO, List <ShiftPoint.DTO> lineDTOs)
        {
            DakkaLinqDataContext db = DBHelper.GetDakkaLinqDataContext();

            ShiftDef shiftDef = new ShiftDef
            {
                Code        = headDTO.Code,
                Name        = headDTO.Name,
                ShiftType   = new ShiftTypeEnum(headDTO.ShiftType).Value,
                Description = headDTO.Description
            };

            foreach (var line in lineDTOs)
            {
                ShiftPoint shiftPoint = new ShiftPoint
                {
                    IndexNumber = line.IndexNumber,
                    Name        = line.Name,
                    PointTime   = DateTime.Parse(line.PointTime),
                    Before      = int.Parse(line.Before),
                    After       = int.Parse(line.After),
                    PointType   = new PointTypeEnum(line.PointType).Value
                };

                shiftDef.ShiftPoint.Add(shiftPoint);
            }

            db.ShiftDef.InsertOnSubmit(shiftDef);

            db.SubmitChanges();
        }
Example #3
0
        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>
        /// 添加一个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();
        }
Example #5
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();
        }
Example #6
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();
        }
Example #7
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();
        }
Example #8
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();
        }
Example #9
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();
        }
Example #10
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();
        }