예제 #1
0
        public LabourDivisionModel GetById(int labourId)
        {
            var objReturn = new LabourDivisionModel();

            try
            {
                using (db = new IEDEntities())
                {
                    var obj = Get(labourId);
                    if (obj != null)
                    {
                        Parse.CopyObject(obj, ref objReturn);

                        #region positions
                        var linPos = db.T_LinePosition.Where(x => !x.IsDeleted && x.LabourDivisionId == labourId).Select(x => new LinePositionModel()
                        {
                            Id = x.Id,
                            LabourDivisionId = x.LabourDivisionId,
                            OrderIndex       = x.OrderIndex,
                            EmployeeId       = x.EmployeeId,
                            EmployeeLastName = x.HR_Employee.LastName,
                            EmployeeName     = (x.HR_Employee.FirstName + " " + x.HR_Employee.LastName),
                            LineId           = x.T_LabourDivision.LineId,
                            IsHasBTP         = x.IsHasBTP,
                            IsHasExitLine    = x.IsHasExitLine
                        }).ToList();

                        if (linPos != null && linPos.Count() > 0)
                        {
                            foreach (var item in linPos)
                            {
                                item.Details = db.T_LinePositionDetail.Where(x => !x.IsDeleted && item.Id == x.Line_PositionId).Select(x => new LinePositionDetailModel()
                                {
                                    Id = x.Id,
                                    Line_PositionId      = x.Line_PositionId,
                                    TechProVerDe_Id      = x.TechProVerDe_Id,
                                    OrderIndex           = x.OrderIndex,
                                    Note                 = x.Note == null ? "" : x.Note,
                                    IsPass               = x.IsPass,
                                    PhaseCode            = x.T_TechProcessVersionDetail.T_CA_Phase.Code,
                                    PhaseName            = x.T_TechProcessVersionDetail.T_CA_Phase.Name,
                                    PhaseGroupId         = x.T_TechProcessVersionDetail.T_CA_Phase.T_PhaseGroup.Id,
                                    EquipmentId          = x.T_TechProcessVersionDetail.T_CA_Phase.EquipmentId ?? 0,
                                    EquipmentCode        = x.T_TechProcessVersionDetail.T_CA_Phase.EquipmentId != null ? x.T_TechProcessVersionDetail.T_CA_Phase.T_Equipment.T_EquipmentGroup.GroupCode : "",
                                    EquipmentName        = x.T_TechProcessVersionDetail.T_CA_Phase.EquipmentId != null ? x.T_TechProcessVersionDetail.T_CA_Phase.T_Equipment.T_EquipmentGroup.GroupName : "",
                                    TotalTMU             = x.T_TechProcessVersionDetail.TimeByPercent,
                                    NumberOfLabor        = ((x.T_TechProcessVersionDetail.Worker * x.DevisionPercent) / 100),
                                    DevisionPercent      = x.DevisionPercent,
                                    DevisionPercent_Temp = x.DevisionPercent,
                                    TotalLabor           = x.T_TechProcessVersionDetail.Worker,
                                    Index                = x.T_TechProcessVersionDetail.T_CA_Phase.Index
                                }).ToList();
                            }
                            objReturn.Positions.AddRange(linPos);
                        }
                        #endregion

                        #region thong tin TKC
                        objReturn.TechProcess = db.T_TechProcessVersion.Where(x => !x.IsDeleted && x.Id == obj.TechProVer_Id).Select(x => new TechProcessVersionModel()
                        {
                            Id = x.Id,
                            //   CommodityId = x.CommodityId,
                            //   CommodityName = string.Empty,
                            TimeCompletePerCommo = x.TimeCompletePerCommo,
                            NumberOfWorkers      = x.NumberOfWorkers,
                            WorkingTimePerDay    = x.WorkingTimePerDay,
                            PacedProduction      = x.PacedProduction,
                            ProOfGroupPerDay     = x.ProOfGroupPerDay,
                            ProOfGroupPerHour    = x.ProOfGroupPerHour,
                            ProOfPersonPerDay    = x.ProOfPersonPerDay,
                            Note = x.Note
                        }).FirstOrDefault();

                        if (objReturn.TechProcess != null)
                        {
                            var details = db.T_TechProcessVersionDetail.Where(x => !x.IsDeleted && x.TechProcessVersionId == obj.TechProVer_Id).Select(x => new TechProcessVerDetailModel()
                            {
                                Id = x.Id,
                                TechProcessVersionId = x.TechProcessVersionId,
                                PhaseGroupId         = x.T_CA_Phase.T_PhaseGroup.Id,
                                CA_PhaseId           = x.CA_PhaseId,
                                PhaseCode            = x.T_CA_Phase.Code,
                                PhaseName            = x.T_CA_Phase.Name,
                                StandardTMU          = Math.Round(x.StandardTMU, 3),
                                Percent            = x.Percent,
                                EquipmentId        = x.T_CA_Phase.EquipmentId != null ? x.T_CA_Phase.EquipmentId ?? 0 : 0,
                                EquipmentCode      = x.T_CA_Phase.EquipmentId != null ? x.T_CA_Phase.T_Equipment.T_EquipmentGroup.GroupCode : string.Empty,
                                EquipmentName      = x.T_CA_Phase.EquipmentId != null ? x.T_CA_Phase.T_Equipment.T_EquipmentGroup.GroupName : string.Empty,
                                EquipmentGroupCode = x.T_CA_Phase.EquipmentId != null ? x.T_CA_Phase.T_Equipment.T_EquipmentGroup.GroupCode : string.Empty,
                                TimeByPercent      = Math.Round(x.TimeByPercent, 3),
                                Worker             = x.Worker,
                                De_Percent         = 0,
                                Description        = x.Description == null ? "" : x.Description,
                                Coefficient        = x.T_CA_Phase.SWorkerLevel.Coefficient,
                                WorkerLevelId      = x.T_CA_Phase.WorkerLevelId,
                                WorkerLevelName    = x.T_CA_Phase.SWorkerLevel.Name,
                                Index = x.T_CA_Phase.Index
                            }).OrderBy(x => x.PhaseCode).ToList();
                            objReturn.TechProcess.details.AddRange(details);
                        }
                        #endregion
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(objReturn);
        }
예제 #2
0
        public ResponseBase Insert(LabourDivisionModel objModel)
        {
            try
            {
                using (db = new IEDEntities())
                {
                    var                  rs        = new ResponseBase();
                    T_LinePosition       linePo    = null;
                    T_LinePositionDetail linePoDe  = null;
                    T_LabourDivision     labourObj = null;
                    if (Check(objModel.Id, objModel.ParentId, objModel.LineId) != null)
                    {
                        rs.IsSuccess = false;
                        rs.Errors.Add(new Error()
                        {
                            MemberName = "update", Message = "Chuyền này đã có sơ đồ thiết kế chuyền không thể tạo thêm được. Vui Lòng Kiểm Tra Lại"
                        });
                    }
                    else
                    {
                        if (objModel.Id == 0)
                        {
                            #region
                            labourObj = new T_LabourDivision();
                            Parse.CopyObject(objModel, ref labourObj);
                            labourObj.CreatedDate = DateTime.Now;
                            labourObj.CreatedUser = objModel.ActionUser;

                            if (objModel.Positions != null && objModel.Positions.Count > 0)
                            {
                                labourObj.T_LinePosition = new Collection <T_LinePosition>();
                                for (int i = 0; i < objModel.Positions.Count; i++)
                                {
                                    linePo = new T_LinePosition();
                                    Parse.CopyObject(objModel.Positions[i], ref linePo);
                                    linePo.CreatedUser = labourObj.CreatedUser;
                                    linePo.CreatedDate = labourObj.CreatedDate;
                                    linePo.OrderIndex  = i + 1;
                                    if (objModel.Positions[i].Details != null && objModel.Positions[i].Details.Count > 0)
                                    {
                                        linePo.T_LinePositionDetail = new Collection <T_LinePositionDetail>();
                                        foreach (var de in objModel.Positions[i].Details)
                                        {
                                            if (de.OrderIndex < objModel.Positions[i].Details.Count)
                                            {
                                                linePoDe = new T_LinePositionDetail();
                                                Parse.CopyObject(de, ref linePoDe);
                                                linePoDe.CreatedUser    = labourObj.CreatedUser;
                                                linePoDe.CreatedDate    = labourObj.CreatedDate;
                                                linePoDe.T_LinePosition = linePo;
                                                linePo.T_LinePositionDetail.Add(linePoDe);
                                            }
                                        }
                                    }
                                    labourObj.T_LinePosition.Add(linePo);
                                }
                            }

                            db.T_LabourDivision.Add(labourObj);
                            rs.IsSuccess = true;
                            #endregion
                        }
                        else
                        {
                            #region
                            labourObj = Get(objModel.Id);
                            if (labourObj != null)
                            {
                                labourObj.UpdatedUser   = objModel.ActionUser;
                                labourObj.UpdatedDate   = DateTime.Now;
                                labourObj.TotalPosition = objModel.TotalPosition;
                                labourObj.TechProVer_Id = objModel.TechProVer_Id;
                                labourObj.LineId        = objModel.LineId;

                                #region remove old
                                var oldLinePo = db.T_LinePosition.Where(x => !x.IsDeleted && objModel.Id == x.LabourDivisionId);
                                if (oldLinePo != null && oldLinePo.Count() > 0)
                                {
                                    foreach (var item in oldLinePo)
                                    {
                                        item.IsDeleted = true;
                                        var de = db.T_LinePositionDetail.Where(x => !x.IsDeleted && x.Line_PositionId == item.Id);
                                        if (de != null && de.Count() > 0)
                                        {
                                            foreach (var detail in de)
                                            {
                                                detail.IsDeleted = true;
                                            }
                                        }
                                    }
                                }
                                #endregion

                                #region add new
                                if (objModel.Positions != null && objModel.Positions.Count > 0)
                                {
                                    for (int i = 0; i < objModel.Positions.Count; i++)
                                    {
                                        linePo = new T_LinePosition();
                                        Parse.CopyObject(objModel.Positions[i], ref linePo);
                                        linePo.CreatedUser      = objModel.ActionUser;
                                        linePo.CreatedDate      = DateTime.Now;
                                        linePo.OrderIndex       = i + 1;
                                        linePo.LabourDivisionId = objModel.Id;
                                        if (objModel.Positions[i].Details != null && objModel.Positions[i].Details.Count > 0)
                                        {
                                            linePo.T_LinePositionDetail = new Collection <T_LinePositionDetail>();
                                            foreach (var de in objModel.Positions[i].Details)
                                            {
                                                if (de.OrderIndex < objModel.Positions[i].Details.Count)
                                                {
                                                    linePoDe = new T_LinePositionDetail();
                                                    Parse.CopyObject(de, ref linePoDe);
                                                    linePoDe.CreatedUser    = objModel.ActionUser;
                                                    linePoDe.CreatedDate    = DateTime.Now;
                                                    linePoDe.T_LinePosition = linePo;
                                                    linePo.T_LinePositionDetail.Add(linePoDe);
                                                }
                                            }
                                        }
                                        db.T_LinePosition.Add(linePo);
                                    }
                                }
                                #endregion

                                rs.IsSuccess = true;
                            }
                            else
                            {
                                rs.IsSuccess = false;
                                rs.Errors.Add(new Error()
                                {
                                    MemberName = "update", Message = "Đối Tượng Đã Bị Xóa. Vui Lòng Kiểm Tra Lại"
                                });
                            }
                            #endregion
                        }
                        if (rs.IsSuccess)
                        {
                            db.SaveChanges();
                            rs.IsSuccess = true;
                        }
                    }
                    return(rs);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #3
0
        public LabourDivisionModel RefreshById(int labourId)
        {
            var objReturn = new LabourDivisionModel();

            try
            {
                using (db = new IEDEntities())
                {
                    var obj = Get(labourId);
                    if (obj != null)
                    {
                        var _qtcn           = db.T_TechProcessVersion.FirstOrDefault(x => x.Id == obj.TechProVer_Id);
                        var newQTCN         = db.T_TechProcessVersion.FirstOrDefault(x => !x.IsDeleted && x.ParentId == _qtcn.ParentId);
                        var newQTCN_Details = db.T_TechProcessVersionDetail
                                              .Where(x => !x.IsDeleted && x.TechProcessVersionId == newQTCN.Id)
                                              .Select(x => new TechProcessVerDetailModel()
                        {
                            Id = x.Id,
                            TechProcessVersionId = x.TechProcessVersionId,
                            PhaseGroupId         = x.T_CA_Phase.T_PhaseGroup.Id,
                            CA_PhaseId           = x.CA_PhaseId,
                            PhaseCode            = x.T_CA_Phase.Code,
                            PhaseName            = x.T_CA_Phase.Name,
                            StandardTMU          = Math.Round(x.StandardTMU, 3),
                            Percent            = x.Percent,
                            EquipmentId        = x.T_CA_Phase.EquipmentId != null ? x.T_CA_Phase.EquipmentId ?? 0 : 0,
                            EquipmentCode      = x.T_CA_Phase.EquipmentId != null ? x.T_CA_Phase.T_Equipment.T_EquipmentGroup.GroupCode : string.Empty,
                            EquipmentName      = x.T_CA_Phase.EquipmentId != null ? x.T_CA_Phase.T_Equipment.T_EquipmentGroup.GroupName : string.Empty,
                            EquipmentGroupCode = x.T_CA_Phase.EquipmentId != null ? x.T_CA_Phase.T_Equipment.T_EquipmentGroup.GroupCode : string.Empty,
                            TimeByPercent      = Math.Round(x.TimeByPercent, 3),
                            Worker             = x.Worker,
                            De_Percent         = 0,
                            Description        = x.Description == null ? "" : x.Description,
                            Coefficient        = x.T_CA_Phase.SWorkerLevel.Coefficient,
                            WorkerLevelId      = x.T_CA_Phase.WorkerLevelId,
                            WorkerLevelName    = x.T_CA_Phase.SWorkerLevel.Name,
                            Index = x.T_CA_Phase.Index
                        })
                                              .ToList();

                        #region positions
                        var linPos = db.T_LinePosition.Where(x => !x.IsDeleted && x.LabourDivisionId == labourId).Select(x => new LinePositionModel()
                        {
                            Id = x.Id,
                            LabourDivisionId = x.LabourDivisionId,
                            OrderIndex       = x.OrderIndex,
                            EmployeeId       = x.EmployeeId,
                            EmployeeLastName = x.HR_Employee.LastName,
                            EmployeeName     = (x.HR_Employee.FirstName + " " + x.HR_Employee.LastName),
                            LineId           = x.T_LabourDivision.LineId,
                            IsHasBTP         = x.IsHasBTP,
                            IsHasExitLine    = x.IsHasExitLine
                        }).ToList();

                        if (linPos != null && linPos.Count() > 0)
                        {
                            foreach (var item in linPos)
                            {
                                var poDetails = db.T_LinePositionDetail
                                                .Where(x => !x.IsDeleted && item.Id == x.Line_PositionId);
                                if (poDetails.Count() > 0)
                                {
                                    foreach (var subItem in poDetails)
                                    {
                                        var phaseObj = newQTCN_Details.FirstOrDefault(x => x.CA_PhaseId == subItem.T_TechProcessVersionDetail.CA_PhaseId);
                                        if (phaseObj != null)
                                        {
                                            subItem.TechProVerDe_Id = phaseObj.Id;
                                        }
                                    }
                                }

                                //.Select(x => new LinePositionDetailModel()
                                //{
                                //    Id = x.Id,
                                //    Line_PositionId = x.Line_PositionId,
                                //    TechProVerDe_Id = x.TechProVerDe_Id,
                                //    PhaseId = x.T_TechProcessVersionDetail.T_CA_Phase.Id,
                                //    OrderIndex = x.OrderIndex,
                                //    Note = x.Note == null ? "" : x.Note,
                                //    IsPass = x.IsPass,
                                //    PhaseCode = x.T_TechProcessVersionDetail.T_CA_Phase.Code,
                                //    PhaseName = x.T_TechProcessVersionDetail.T_CA_Phase.Name,
                                //    PhaseGroupId = x.T_TechProcessVersionDetail.T_CA_Phase.T_PhaseGroup.Id,
                                //    EquipmentId = x.T_TechProcessVersionDetail.T_CA_Phase.EquipmentId ?? 0,
                                //    EquipmentCode = x.T_TechProcessVersionDetail.T_CA_Phase.EquipmentId != null ? x.T_TechProcessVersionDetail.T_CA_Phase.T_Equipment.T_EquipmentGroup.GroupCode : "",
                                //    EquipmentName = x.T_TechProcessVersionDetail.T_CA_Phase.EquipmentId != null ? x.T_TechProcessVersionDetail.T_CA_Phase.T_Equipment.T_EquipmentGroup.GroupName : "",
                                //    TotalTMU = x.T_TechProcessVersionDetail.TimeByPercent,
                                //    NumberOfLabor = ((x.T_TechProcessVersionDetail.Worker * x.DevisionPercent) / 100),
                                //    DevisionPercent = x.DevisionPercent,
                                //    DevisionPercent_Temp = x.DevisionPercent,
                                //    TotalLabor = x.T_TechProcessVersionDetail.Worker,
                                //    Index = x.T_TechProcessVersionDetail.T_CA_Phase.Index
                                //}).ToList();
                            }
                            objReturn.Positions.AddRange(linPos);
                        }
                        #endregion

                        obj.TechProVer_Id = newQTCN.Id;
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(objReturn);
        }