Пример #1
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();
        }
Пример #2
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();
        }
Пример #3
0
 partial void UpdateShiftDef(ShiftDef instance);
Пример #4
0
 partial void DeleteShiftDef(ShiftDef instance);
Пример #5
0
 partial void InsertShiftDef(ShiftDef instance);