Exemple #1
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();
        }
Exemple #2
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();
        }
        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(),
                    PointType   = new PointTypeEnum(point.PointType).Name
                };
                head.ShiftPoints.Add(line);
            }

            return(head);
        }