示例#1
0
        /// <summary>
        /// chuyen phan hang sang trang thai xoa cho nhung mat hang da bi xoa
        /// </summary>
        /// <param name="commoId"></param>
        /// <returns></returns>
        public static ResponseBase ChangeAssignmentStatusforAllDelatedCommodities()
        {
            var result = new ResponseBase();

            try
            {
                var db      = new PMSEntities();
                var assigns = db.Chuyen_SanPham.Where(x => !x.IsDelete && (x.Chuyen.IsDeleted || x.SanPham.IsDelete));
                if (assigns != null && assigns.Count() > 0)
                {
                    foreach (var item in assigns)
                    {
                        item.IsDelete = true;
                    }
                    db.SaveChanges();
                }
            }
            catch (Exception)
            { }
            return(result);
        }
示例#2
0
        public void UpdatePhaseDayQuantity(int assignId, int phaseType, DateTime date, int quantities)
        {
            using (var db = new PMSEntities())
            {
                var details = from x in db.P_PhaseDaily
                              where x.CreatedDate.Day == date.Day &&
                              x.CreatedDate.Month == date.Month &&
                              x.CreatedDate.Year == date.Year &&
                              x.AssignId == assignId &&
                              x.P_Phase.Type == phaseType
                              select x;
                foreach (var item in details)
                {
                    item.Quantity = 0;
                }

                var first = details.FirstOrDefault(x => x.CommandTypeId == (int)eCommandRecive.ProductIncrease);
                first.Quantity = quantities;
                db.SaveChanges();
            }
        }
示例#3
0
        public ResponseBase Update(int Id, List <ReadPercent> items)
        {
            var result = new ResponseBase();

            try
            {
                db = new PMSEntities();
                var olds = db.ReadPercents.Where(x => !x.IsDeleted && x.IdParent != null && x.IdParent.Value == Id);
                if (olds != null && olds.Count() > 0)
                {
                    foreach (var item in olds)
                    {
                        item.IsDeleted = true;
                    }
                }

                if (items != null && items.Count > 0)
                {
                    ReadPercent subItem;
                    foreach (var itemObj in items)
                    {
                        subItem = new ReadPercent();
                        Parse.CopyObject(itemObj, ref subItem);
                        subItem.IsDeleted = false;
                        subItem.IdParent  = Id;
                        db.ReadPercents.Add(subItem);
                    }
                }
                db.SaveChanges();
                result.IsSuccess = true;
                result.Messages.Add(new Message()
                {
                    Title = "Thông Báo", msg = "Lưu thành công."
                });
            }
            catch (Exception ex)
            {
            }
            return(result);
        }
示例#4
0
        public ResponseBase Delete(int Id)
        {
            var result = new ResponseBase();

            try
            {
                db = new PMSEntities();
                var olds = db.ReadPercents.Where(x => !x.IsDeleted && x.Id == Id || (x.IdParent != null && x.IdParent.Value == Id));
                if (olds != null && olds.Count() > 0)
                {
                    foreach (var item in olds)
                    {
                        item.IsDeleted = true;
                    }
                    db.SaveChanges();
                    result.IsSuccess = true;
                    result.Messages.Add(new Message()
                    {
                        Title = "Thông Báo", msg = "Xóa Thành công."
                    });
                }
                else
                {
                    result.IsSuccess = false;
                    result.Messages.Add(new Message()
                    {
                        Title = "Lỗi", msg = "không tìm thấy thông tin."
                    });
                }
            }
            catch (Exception)
            {
                result.IsSuccess = false;
                result.Messages.Add(new Message()
                {
                    Title = "Lỗi", msg = "không tìm thấy thông tin."
                });
            }
            return(result);
        }
示例#5
0
        public ResponseBase Delete(int Id)
        {
            var rs = new ResponseBase();

            try
            {
                using (var db = new PMSEntities())
                {
                    var obj = db.Errors.FirstOrDefault(x => !x.IsDeleted && x.Id == Id);
                    if (obj != null)
                    {
                        obj.IsDeleted = true;
                        db.SaveChanges();
                        rs.IsSuccess = true;
                        rs.Messages.Add(new Message()
                        {
                            Title = "Thông Báo", msg = "Xóa Thành công."
                        });
                    }
                    else
                    {
                        rs.IsSuccess = false;
                        rs.Messages.Add(new Message()
                        {
                            Title = "Lỗi", msg = "không tìm thấy lỗi."
                        });
                    }
                }
            }
            catch (Exception)
            {
                rs.IsSuccess = false;
                rs.Messages.Add(new Message()
                {
                    Title = "Lỗi", msg = "không tìm thấy lỗi."
                });
            }
            return(rs);
        }
示例#6
0
        static void PerformScheduledTasks(string key, Object value, CacheItemRemovedReason reason)
        {
            try
            {
                PMSEntities context = new PMSEntities();

                SerialPort Stream = new SerialPort("COM15", 9600);
                Stream.Close();
                Stream.Open();


                string parkID    = Stream.ReadLine();
                string parkIDNew = parkID.Remove(parkID.Length - 1);
                System.Threading.Thread.Sleep(1000);
                string value1   = Stream.ReadLine();
                string valueNew = value1.Remove(value1.Length - 1);

                parking objParking = context.parkings.Where(o => o.parking_id == parkIDNew).FirstOrDefault();
                if (valueNew == "in")
                {
                    objParking.parking_available_slots = objParking.parking_available_slots - 1;
                }
                else
                {
                    objParking.parking_available_slots = objParking.parking_available_slots + 1;
                }
                context.Entry(objParking).State = EntityState.Modified;
                context.SaveChanges();

                //GetCount();
                Stream.Close();

                ScheduleTaskTrigger();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#7
0
        public ResponseBase Delete(int Id)
        {
            var result = new ResponseBase();

            using (var db = new PMSEntities())
            {
                try
                {
                    var commo = db.P_DepartmentDailyLabour.FirstOrDefault(x => x.Id == Id);
                    if (commo != null)
                    {
                        db.P_DepartmentDailyLabour.Remove(commo);
                        db.SaveChanges();
                        result.IsSuccess = true;
                        result.Messages.Add(new Message()
                        {
                            msg = "Xóa Bộ phận thành công.", Title = "Thông Báo"
                        });
                    }
                    else
                    {
                        result.IsSuccess = true;
                        result.Messages.Add(new Message()
                        {
                            msg = "Không tìm thấy thông tin Bộ phận . Xóa Bộ phận thất bại.", Title = "Lỗi CSDL"
                        });
                    }
                }
                catch (Exception)
                {
                    result.IsSuccess = true;
                    result.Messages.Add(new Message()
                    {
                        msg = "Không tìm thấy thông tin Bộ phận . Xóa Bộ phận thất bại.", Title = "Lỗi Exception"
                    });
                }
            }
            return(result);
        }
示例#8
0
        /// <summary>
        /// Delete công đoạn hoàn thành
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public static ResponseBase Delete(int Id)
        {
            var result = new ResponseBase();

            try
            {
                var db  = new PMSEntities();
                var obj = db.P_CompletionPhase.FirstOrDefault(x => !x.IsDeleted && x.Id == Id);
                if (obj != null)
                {
                    obj.IsDeleted   = true;
                    obj.DeletedDate = DateTime.Now;
                    db.SaveChanges();
                    result.IsSuccess = true;
                    result.Messages.Add(new Message()
                    {
                        Title = "Thông Báo", msg = "Xóa Thành công."
                    });
                }
                else
                {
                    result.IsSuccess = false;
                    result.Messages.Add(new Message()
                    {
                        Title = "Lỗi", msg = "không tìm thấy thông tin cần xóa."
                    });
                }
            }
            catch (Exception)
            {
                result.IsSuccess = false;
                result.Messages.Add(new Message()
                {
                    Title = "Lỗi", msg = "không tìm thấy thông tin cần xóa. Exception"
                });
            }
            return(result);
        }
示例#9
0
        public ResponseBase Insert(ReadPercentKCSInventoryModel obj)
        {
            var result = new ResponseBase();

            try
            {
                db = new PMSEntities();
                P_ReadPercent_KCSInventory newObj;
                newObj = new P_ReadPercent_KCSInventory();
                Parse.CopyObject(obj, ref newObj);
                newObj.IsDeleted = false;

                if (obj.Childs != null && obj.Childs.Count > 0)
                {
                    newObj.P_ReadPercent_KCSInventory_De = new List <P_ReadPercent_KCSInventory_De>();
                    P_ReadPercent_KCSInventory_De subItem;
                    foreach (var itemObj in obj.Childs)
                    {
                        subItem = new P_ReadPercent_KCSInventory_De();
                        Parse.CopyObject(itemObj, ref subItem);
                        subItem.IsDeleted = false;
                        subItem.P_ReadPercent_KCSInventory = newObj;
                        newObj.P_ReadPercent_KCSInventory_De.Add(subItem);
                    }
                }
                db.P_ReadPercent_KCSInventory.Add(newObj);
                db.SaveChanges();
                result.IsSuccess = true;
                result.Messages.Add(new Message()
                {
                    Title = "Thông Báo", msg = "Lưu thành công."
                });
            }
            catch (Exception ex)
            {
            }
            return(result);
        }
示例#10
0
        public static ResponseBase Delete(int Id)
        {
            var result = new ResponseBase();

            try
            {
                var db    = new PMSEntities();
                var error = db.GroupErrors.FirstOrDefault(x => !x.IsDeleted && x.Id == Id);
                if (error != null)
                {
                    error.IsDeleted = true;
                    db.SaveChanges();
                    result.IsSuccess = true;
                    result.Messages.Add(new Message()
                    {
                        Title = "Thông Báo", msg = "Xóa Thành công."
                    });
                }
                else
                {
                    result.IsSuccess = false;
                    result.Messages.Add(new Message()
                    {
                        Title = "Lỗi", msg = "không tìm thấy lỗi."
                    });
                }
            }
            catch (Exception)
            {
                result.IsSuccess = false;
                result.Messages.Add(new Message()
                {
                    Title = "Lỗi", msg = "không tìm thấy lỗi."
                });
            }
            return(result);
        }
示例#11
0
        public ResponseBase Delete(int Id)
        {
            var result = new ResponseBase();

            try
            {
                var db  = new PMSEntities();
                var obj = db.P_Color.FirstOrDefault(x => x.Id == Id);
                if (obj != null)
                {
                    obj.IsDeleted = true;
                    db.SaveChanges();
                    result.IsSuccess = true;
                    result.Messages.Add(new Message()
                    {
                        msg = "Xóa mã màu thành công.", Title = "Thông Báo"
                    });
                }
                else
                {
                    result.IsSuccess = true;
                    result.Messages.Add(new Message()
                    {
                        msg = "Không tìm thấy thông tin mã màu . Xóa mã màu thất bại.", Title = "Lỗi CSDL"
                    });
                }
            }
            catch (Exception)
            {
                result.IsSuccess = true;
                result.Messages.Add(new Message()
                {
                    msg = "Không tìm thấy thông tin mã màu . Xóa mã màu thất bại.", Title = "Lỗi Exception"
                });
            }
            return(result);
        }
示例#12
0
        public static ResponseBase Delete(int lineId)
        {
            var result = new ResponseBase();

            try
            {
                var db   = new PMSEntities();
                var line = db.Chuyens.FirstOrDefault(x => !x.IsDeleted && !x.Floor.IsDeleted && x.MaChuyen == lineId);
                if (line != null)
                {
                    line.IsDeleted = true;
                    db.SaveChanges();
                    result.IsSuccess = true;
                    result.Messages.Add(new Message()
                    {
                        Title = "Thông Báo", msg = "Xóa thành công."
                    });
                }
                else
                {
                    result.IsSuccess = true;
                    result.Messages.Add(new Message()
                    {
                        Title = "Lỗi", msg = "không tìm thấy thông tin chuyền."
                    });
                }
            }
            catch (Exception ex)
            {
                result.IsSuccess = true;
                result.Messages.Add(new Message()
                {
                    Title = "Lỗi", msg = "Xóa chuyền không thành công.\n" + ex.Message
                });
            }
            return(result);
        }
示例#13
0
        /// <summary>
        /// update
        /// </summary>
        /// <param name="items"></param>
        /// <param name="type">1=> KCSInventory ; 2=> Light Kanban ; 3 => production light</param>
        /// <returns></returns>
        public ResponseBase Update(List <P_ReadPercentOfLine> items, int type)
        {
            var result = new ResponseBase();

            try
            {
                db = new PMSEntities();
                if (items != null && items.Count > 0)
                {
                    var ids  = items.Select(x => x.Id).ToArray();
                    var objs = db.P_ReadPercentOfLine.Where(x => !x.IsDeleted && ids.Contains(x.Id));
                    foreach (var itemObj in objs)
                    {
                        var obj = items.FirstOrDefault(x => x.Id == itemObj.Id);
                        switch (type)
                        {
                        case 1: itemObj.ReadPercent_KCSInventoryId = ((obj == null || obj.ReadPercent_KCSInventoryId == 0) ? null : obj.ReadPercent_KCSInventoryId);      break;

                        case 2: itemObj.KanbanLightPercentId = ((obj == null || obj.KanbanLightPercentId == 0) ? null : obj.KanbanLightPercentId); break;

                        case 3: itemObj.ProductLightPercentId = ((obj == null || obj.ProductLightPercentId == 0) ? null : obj.ProductLightPercentId); break;
                        }
                    }
                }
                db.SaveChanges();
                result.IsSuccess = true;
                result.Messages.Add(new Message()
                {
                    Title = "Thông Báo", msg = "Lưu thành công."
                });
            }
            catch (Exception ex)
            {
            }
            return(result);
        }
示例#14
0
        ///=============================================================================================

        /// <summary>
        /// Tạo mới một particition
        /// </summary>
        /// <param name="idUser">Id User</param>
        /// <param name="idGroup">Id Group</param>
        /// <param name="part">Model Participate</param>
        /// <param name="isOwner">Có phải owner hông??</param>
        public void createParticipate(string idUser, int idGroup, Participate part, bool isOwner)
        {
            part.IdGroup = idGroup;
            part.IdUser  = idUser;
            if (isOwner)
            {
                part.IsOwner   = true;
                part.IsAdmin   = true;
                part.IsManager = true;
            }
            else
            {
                part.IsOwner   = false;
                part.IsAdmin   = false;
                part.IsManager = false;
            }
            part.Created_At = DateTime.Now;
            part.Updated_At = DateTime.Now;
            db.Participates.Add(part);
            db.SaveChanges();
        }
示例#15
0
        public static ResponseBase CreateOrUpdate(MailTemplateModel obj)
        {
            var           result       = new ResponseBase();
            var           flag         = true;
            MAIL_TEMPLATE mailTemplate = null;
            MAIL_T_M      attachFile   = null;

            try
            {
                var db = new PMSEntities();
                if (BLLMailTemplate.CheckExists(obj.Id, obj.Name) != null)
                {
                    result.IsSuccess = false;
                    result.Messages.Add(new Message()
                    {
                        Title = "Lỗi", msg = "Tên mail này đã tồn tại."
                    });
                }
                else
                {
                    if (obj.Id == 0)
                    {
                        mailTemplate = new MAIL_TEMPLATE();
                        Parse.CopyObject(obj, ref mailTemplate);
                        //mailTemplate.Name = obj.Name;
                        //mailTemplate.Subject = obj.Subject;
                        //mailTemplate.Content = obj.Content;
                        //mailTemplate.MailSendId = obj.MailSendId;
                        //mailTemplate.MailReceiveIds = obj.MailReceiveIds;
                        //mailTemplate.MailFileIds = obj.MailFileIds;
                        //mailTemplate.Description = obj.Description;
                        //mailTemplate.IsActive = obj.IsActive;
                        //if (obj.AttachFiles != null && obj.AttachFiles.Count > 0)
                        //{
                        //    mailTemplate.MAIL_T_M = new List<MAIL_T_M>();
                        //    foreach (var item in obj.AttachFiles)
                        //    {
                        //        attachFile = new MAIL_T_M();
                        //        attachFile.MailFileId = item;
                        //        attachFile.MAIL_TEMPLATE = mailTemplate;
                        //        mailTemplate.MAIL_T_M.Add(attachFile);
                        //    }
                        //}
                        db.MAIL_TEMPLATE.Add(mailTemplate);
                    }
                    else
                    {
                        mailTemplate = db.MAIL_TEMPLATE.FirstOrDefault(x => !x.IsDeleted && x.Id == obj.Id);
                        if (mailTemplate != null)
                        {
                            mailTemplate.Name           = obj.Name;
                            mailTemplate.Subject        = obj.Subject;
                            mailTemplate.Content        = obj.Content;
                            mailTemplate.MailSendId     = obj.MailSendId;
                            mailTemplate.MailReceiveIds = obj.MailReceiveIds;
                            mailTemplate.MailFileIds    = obj.MailFileIds;
                            mailTemplate.Description    = obj.Description;
                            mailTemplate.IsActive       = obj.IsActive;

                            //if (obj.AttachFileChange)
                            //{
                            //    var oldAtt = db.MAIL_T_M.Where(x => !x.IsDeleted && x.MailTemplateId == mailTemplate.Id);
                            //    var ids = new List<int>();
                            //    if (oldAtt != null && oldAtt.Count() > 0)
                            //    {
                            //        if (obj.AttachFiles != null && obj.AttachFiles.Count > 0)
                            //        {
                            //            foreach (var item in obj.AttachFiles)
                            //            {
                            //                var exists = oldAtt.FirstOrDefault(x => x.MailFileId == item);
                            //                if (exists != null)
                            //                {
                            //                    ids.Add(exists.Id);
                            //                }
                            //                else
                            //                {
                            //                    attachFile = new MAIL_T_M();
                            //                    attachFile.MailFileId = item;
                            //                    attachFile.IsActive = true;
                            //                    attachFile.MailTemplateId = mailTemplate.Id;
                            //                    db.MAIL_T_M.Add(attachFile);
                            //                }
                            //            }
                            //        }

                            //        var deleteobj = oldAtt.Where(x => !ids.Contains(x.Id));
                            //        foreach (var item in deleteobj)
                            //        {
                            //            item.IsDeleted = true;
                            //        }
                            //    }
                            //    else
                            //    {
                            //        foreach (var item in obj.AttachFiles)
                            //        {
                            //            attachFile = new MAIL_T_M();
                            //            attachFile.MailFileId = item;
                            //            attachFile.MailTemplateId = mailTemplate.Id;
                            //            attachFile.IsActive = true;
                            //            db.MAIL_T_M.Add(attachFile);
                            //        }
                            //    }
                            //}
                        }
                        else
                        {
                            result.IsSuccess = false;
                            result.Messages.Add(new Message()
                            {
                                Title = "Thông Báo", msg = "Không tìm thấy thông tin Mail bạn đang thao tác."
                            });
                        }
                    }
                    if (flag)
                    {
                        db.SaveChanges();
                        result.IsSuccess = true;
                        result.Messages.Add(new Message()
                        {
                            Title = "Thông Báo", msg = "Lưu thành công."
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(result);
        }
示例#16
0
 public void Add(HMS_Control control)
 {
     dbContext.HMS_Control.Add(control);
     dbContext.SaveChanges();
 }
示例#17
0
        public static ResponseBase InsertForNewMonth()
        {
            var result = new ResponseBase();

            try
            {
                var db   = new PMSEntities();
                var c_sp = db.Chuyen_SanPham.Where(x => !x.IsDelete && !x.IsFinish && !x.IsFinishNow && x.Thang > 0 && x.Nam > 0).ToList();
                if (c_sp != null && c_sp.Count() > 0)
                {
                    // thay đổi lai sl kế hoach trong tháng trước nếu mã hàng vẫn chua finish sau đó chuyển sang tháng mới
                    var stt             = c_sp.Select(x => x.STT).Distinct();
                    var preMonth        = DateTime.Now.Month - 1;
                    var thisMonth       = DateTime.Now.Month;
                    var old_MonthDetail = db.P_MonthlyProductionPlans.Where(x => !x.IsDeleted && stt.Contains(x.STT_C_SP) && x.Month == preMonth && x.Year == DateTime.Now.Year).ToList();
                    if (old_MonthDetail != null && old_MonthDetail.Count() > 0)
                    {
                        foreach (var item in old_MonthDetail)
                        {
                            item.ProductionPlans = item.LK_TH;
                        }
                    }

                    P_MonthlyProductionPlans obj;
                    var new_MonthDetail = db.P_MonthlyProductionPlans.Where(x => !x.IsDeleted && stt.Contains(x.STT_C_SP) && x.Month == thisMonth && x.Year == DateTime.Now.Year).ToList();

                    // tao thong tin cho thang moi
                    if (new_MonthDetail != null && new_MonthDetail.Count() > 0)
                    {
                        // neu co thong tin thang nay roi thi can phai loc trùng
                        foreach (var item in c_sp)
                        {
                            if (new_MonthDetail != null && new_MonthDetail.Count() > 0)
                            {
                                var exists = new_MonthDetail.FirstOrDefault(x => x.STT_C_SP == item.STT);
                                if (exists == null)
                                {
                                    obj                 = new P_MonthlyProductionPlans();
                                    obj.STT_C_SP        = item.STT;
                                    obj.ProductionPlans = item.SanLuongKeHoach - item.LuyKeTH;
                                    obj.Month           = thisMonth;
                                    obj.Year            = DateTime.Now.Year;
                                    db.P_MonthlyProductionPlans.Add(obj);
                                }
                            }
                        }
                    }
                    else
                    {
                        // ko co thi them moi
                        foreach (var item in c_sp)
                        {
                            obj                 = new P_MonthlyProductionPlans();
                            obj.STT_C_SP        = item.STT;
                            obj.ProductionPlans = item.SanLuongKeHoach - item.LuyKeTH;
                            obj.Month           = thisMonth;
                            obj.Year            = DateTime.Now.Year;
                            db.P_MonthlyProductionPlans.Add(obj);
                        }
                    }
                    db.SaveChanges();
                    result.IsSuccess = true;
                }
                else
                {
                    result.IsSuccess = false;
                    result.Messages.Add(new Message()
                    {
                        Title = "Thông Báo", msg = "Không tìm dữ liệu phân hàng cho chuyền. Vui lòng Phân hàng mới cho chuyền"
                    });
                }
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Messages.Add(new Message()
                {
                    Title = "Lỗi Tạo Thông tin Tháng", msg = "Tạo thông tin cho tháng mới từ tháng cũ bị lỗi.\n" + ex.Message
                });
            }
            return(result);
        }
示例#18
0
 /// <summary>
 /// Xóa tất cả các step thuộc nhiều procses
 /// </summary>
 /// <param name="process">Process Model</param>
 public void removeSteps(List <Process> processes)
 {
     foreach (Process process in processes)
     {
         List <Step> steps = findStepsOfProcess(process.Id);
         db.Steps.RemoveRange(steps);
     }
     db.SaveChanges();
 }
示例#19
0
        public static ResponseBase InsertOrUpdate(Chuyen obj)
        {
            var result = new ResponseBase();

            try
            {
                var db = new PMSEntities();

                Chuyen line = null;
                line = db.Chuyens.FirstOrDefault(x => !x.IsDeleted && !x.Floor.IsDeleted && x.MaChuyen != obj.MaChuyen && x.Code.Trim().ToUpper().Equals(obj.Code.Trim().ToUpper()));
                if (line != null)
                {
                    result.IsSuccess = false;
                    result.Messages.Add(new Message()
                    {
                        Title = "Lỗi trùng mã", msg = "Mã chuyền này đã tồn tại vui lòng chọn mã chuyền khác."
                    });
                }
                else
                {
                    var check = false;
                    if (obj.MaChuyen == 0)
                    {
                        db.Chuyens.Add(obj);
                        check = true;
                    }
                    else
                    {
                        line = db.Chuyens.FirstOrDefault(x => !x.IsDeleted && !x.Floor.IsDeleted && x.MaChuyen == obj.MaChuyen);
                        if (line != null)
                        {
                            line.Code            = obj.Code;
                            line.TenChuyen       = obj.TenChuyen;
                            line.DinhNghia       = obj.DinhNghia;
                            line.Sound           = obj.Sound;
                            line.LaoDongDinhBien = obj.LaoDongDinhBien;
                            line.FloorId         = obj.FloorId;
                            check = true;
                        }
                    }
                    if (check)
                    {
                        db.SaveChanges();
                        result.IsSuccess = true;
                        result.Messages.Add(new Message()
                        {
                            Title = "Thông Báo", msg = "Lưu thành công."
                        });
                    }
                    else
                    {
                        result.IsSuccess = true;
                        result.Messages.Add(new Message()
                        {
                            Title = "Lỗi", msg = "không tìm thấy thông tin chuyền."
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                result.IsSuccess = true;
                result.Messages.Add(new Message()
                {
                    Title = "Lỗi", msg = "Lỗi Lưu thông tin không thành công.\n" + ex.Message
                });
            }
            return(result);
        }
示例#20
0
        public static bool AddMapIdSanPhamNgay(List <int> LineIds, List <MapIdSanPhamNgay> listMapIdSanPhamNgay)
        {
            try
            {
                var           db         = new PMSEntities();
                bool          result     = false;
                List <string> listStrSql = new List <string>();
                var           now        = DateTime.Now.Day + "/" + DateTime.Now.Month + "/" + DateTime.Now.Year;

                var oldMaps = db.MapIdSanPhamNgays.Where(x => !x.IsDeleted && x.Ngay == now && LineIds.Contains(x.MaChuyen));
                if (oldMaps != null && oldMaps.Count() > 0)
                {
                    foreach (var item in oldMaps)
                    {
                        item.IsDeleted = true;
                    }
                }

                if (listMapIdSanPhamNgay != null && listMapIdSanPhamNgay.Count > 0)
                {
                    foreach (var map in listMapIdSanPhamNgay)
                    {
                        //  string strSQLInsert = "Insert Into MapIdSanPhamNgay(Ngay, MaChuyen, STT, STTChuyenSanPham, MaSanPham) Values('" + map.Ngay + "', " + map.MaChuyen + ", " + map.STT + "," + map.STTChuyenSanPham + "," + map.MaSanPham + ")";
                        // listStrSql.Add(strSQLInsert);
                        db.MapIdSanPhamNgays.Add(map);
                    }
                    db.SaveChanges();
                    result = true;
                }



                //    string strSQLMapInDay = "Select Id From MapIdSanPhamNgay Where Ngay='" + now + "' and MaChuyen in (" + strListChuyen + ") and IsDeleted=0";
                //DataTable dtMapInDay = dbclass.TruyVan_TraVe_DataTable(strSQLMapInDay);
                //if (dtMapInDay != null && dtMapInDay.Rows.Count > 0)
                //{
                //    foreach (DataRow row in dtMapInDay.Rows)
                //    {
                //        string strSQLDeleteMapOld = "Update MapIdSanPhamNgay Set IsDeleted=1 Where Id=" + row["Id"].ToString();
                //        listStrSql.Add(strSQLDeleteMapOld);
                //    }
                //}
                //if (listMapIdSanPhamNgay != null && listMapIdSanPhamNgay.Count > 0)
                //{
                //    foreach (var map in listMapIdSanPhamNgay)
                //    {
                //        string strSQLInsert = "Insert Into MapIdSanPhamNgay(Ngay, MaChuyen, STT, STTChuyenSanPham, MaSanPham) Values('" + map.Ngay + "', " + map.MaChuyen + ", " + map.STT + "," + map.STTChuyenSanPham + "," + map.MaSanPham + ")";
                //        listStrSql.Add(strSQLInsert);
                //    }
                //}
                //if (listStrSql.Count > 0)
                //{
                //    int rs = dbclass.ExecuteSqlTransaction(listStrSql);
                //    if (rs > 0)
                //        result = true;
                //}
                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#21
0
        public static ResponseBase CreateOrUpdate(MAIL_SEND obj)
        {
            var result = new ResponseBase();
            var flag   = true;

            try
            {
                var db = new PMSEntities();
                if (CheckExists(obj.Id, obj.MailTypeId, obj.Address) != null)
                {
                    result.IsSuccess = false;
                    result.Messages.Add(new Message()
                    {
                        Title = "Lỗi", msg = "Loại Mail với địa chỉ mail này đã tồn tại."
                    });
                }
                else
                {
                    if (obj.Id == 0)
                    {
                        db.MAIL_SEND.Add(obj);
                    }
                    else
                    {
                        var mail = db.MAIL_SEND.FirstOrDefault(x => !x.IsDeleted && x.Id == obj.Id);
                        if (mail != null)
                        {
                            mail.Address    = obj.Address;
                            mail.MailTypeId = obj.MailTypeId;
                            mail.IsActive   = obj.IsActive;
                            if (!string.IsNullOrEmpty(obj.PassWord))
                            {
                                mail.PassWord = obj.PassWord;
                            }
                            mail.Note = obj.Note;
                        }
                        else
                        {
                            result.IsSuccess = false;
                            result.Messages.Add(new Message()
                            {
                                Title = "Thông Báo", msg = "Không tìm thấy thông tin Mail bạn đang thao tác."
                            });
                        }
                    }
                    if (flag)
                    {
                        db.SaveChanges();
                        result.IsSuccess = true;
                        result.Messages.Add(new Message()
                        {
                            Title = "Thông Báo", msg = "Lưu thành công."
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(result);
        }
示例#22
0
        public ResponseBase InsertOrUpdate(LightPercentModel model)
        {
            var result = new ResponseBase();

            try
            {
                using (var _db = new PMSEntities())
                {
                    P_LightPercent lightObj;
                    if (model.Id == 0)
                    {
                        lightObj = new P_LightPercent();
                        Parse.CopyObject(model, ref lightObj);
                        lightObj.IsDeleted = false;
                        if (model.Childs != null && model.Childs.Count > 0)
                        {
                            lightObj.P_LightPercent_De = new List <P_LightPercent_De>();
                            P_LightPercent_De subItem;
                            foreach (var itemObj in model.Childs)
                            {
                                subItem = new P_LightPercent_De();
                                Parse.CopyObject(itemObj, ref subItem);
                                subItem.IsDeleted      = false;
                                subItem.P_LightPercent = lightObj;
                                lightObj.P_LightPercent_De.Add(subItem);
                            }
                        }
                        _db.P_LightPercent.Add(lightObj);
                    }
                    else
                    {
                        lightObj = _db.P_LightPercent.FirstOrDefault(x => x.Id == model.Id);
                        if (lightObj != null)
                        {
                            lightObj.Name = model.Name;
                            lightObj.P_LightPercent_De.ToList().ForEach(x => _db.P_LightPercent_De.Remove(x));
                            lightObj.P_LightPercent_De = new List <P_LightPercent_De>();
                            if (model.Childs.Count > 0)
                            {
                                P_LightPercent_De subItem;
                                foreach (var itemObj in model.Childs)
                                {
                                    subItem = new P_LightPercent_De();
                                    Parse.CopyObject(itemObj, ref subItem);
                                    subItem.IsDeleted      = false;
                                    subItem.P_LightPercent = lightObj;
                                    lightObj.P_LightPercent_De.Add(subItem);
                                }
                            }
                        }
                    }
                    _db.SaveChanges();
                    result.IsSuccess = true;
                    result.Messages.Add(new Message()
                    {
                        Title = "Thông Báo", msg = "Lưu thành công."
                    });
                }
            }
            catch (Exception ex)
            { }
            return(result);
        }
示例#23
0
        public static ResponseBase InsertOrUpdate(LineWorkingShiftModel obj)
        {
            var result = new ResponseBase();

            try
            {
                var db = new PMSEntities();
                P_LineWorkingShift lineShift;

                lineShift = db.P_LineWorkingShift.FirstOrDefault(x => !x.IsDeleted && x.LineId == obj.LineId && x.ShiftId == obj.ShiftId && x.Id != obj.Id);
                if (lineShift != null)
                {
                    result.IsSuccess = false;
                    result.Messages.Add(new Message()
                    {
                        Title = "Trùng ca Làm Việc", msg = "Chuyển :'" + obj.LineName + "' đã có ca làm việc này rồi. Vui lòng chọn ca làm việc khác."
                    });
                }
                else
                {
                    lineShift = db.P_LineWorkingShift.FirstOrDefault(x => !x.IsDeleted && x.LineId == obj.LineId && x.ShiftOrder == obj.ShiftOrder && x.Id != obj.Id);
                    if (lineShift != null)
                    {
                        result.IsSuccess = false;
                        result.Messages.Add(new Message()
                        {
                            Title = "Trùng số thứ tự Ca", msg = "Chuyển :'" + obj.LineName + "' đã có số thứ tự ca làm việc này rồi. Vui lòng chọn số thứ tự ca làm việc khác."
                        });
                    }
                    else
                    {
                        var check = false;
                        if (obj.Id == 0)
                        {
                            lineShift = new P_LineWorkingShift();
                            Parse.CopyObject(obj, ref lineShift);
                            db.P_LineWorkingShift.Add(lineShift);
                            check = true;
                        }
                        else
                        {
                            lineShift = db.P_LineWorkingShift.FirstOrDefault(x => !x.IsDeleted && x.Id == obj.Id);
                            if (lineShift != null)
                            {
                                check                = true;
                                lineShift.LineId     = obj.LineId;
                                lineShift.ShiftOrder = obj.ShiftOrder;
                                lineShift.ShiftId    = obj.ShiftId;
                            }
                            else
                            {
                                result.IsSuccess = false;
                                result.Messages.Add(new Message()
                                {
                                    Title = "Lỗi", msg = "Không tìm thấy thông tin."
                                });
                                check = false;
                            }
                        }

                        if (check)
                        {
                            db.SaveChanges();
                            result.IsSuccess = true;
                            result.Messages.Add(new Message()
                            {
                                Title = "Thông Báo", msg = "Lưu thành công."
                            });
                        }
                    }
                }
            }
            catch (Exception)
            { }
            return(result);
        }
示例#24
0
        public static ResponseBase InsertOrUpdate(Error obj)
        {
            var result = new ResponseBase();

            try
            {
                using (var db = new PMSEntities())
                {
                    var isOk = true;
                    if (CheckExists(obj) != null)
                    {
                        isOk             = false;
                        result.IsSuccess = false;
                        result.Messages.Add(new Message()
                        {
                            Title = "Lỗi Trùng Mã", msg = "Mã Lỗi tồn tại vui lòng chọn Mã khác."
                        });
                    }
                    else
                    {
                        if (obj.Id == 0)
                        {
                            db.Errors.Add(obj);
                        }
                        else
                        {
                            var error = db.Errors.FirstOrDefault(x => !x.IsDeleted && x.Id == obj.Id);
                            if (error != null)
                            {
                                error.Code         = obj.Code;
                                error.Name         = obj.Name;
                                error.Description  = obj.Description;
                                error.GroupErrorId = obj.GroupErrorId;
                                error.PhaseId      = obj.PhaseId;
                            }
                            else
                            {
                                isOk             = false;
                                result.IsSuccess = false;
                                result.Messages.Add(new Message()
                                {
                                    Title = "Lỗi", msg = "cập nhật thông tin thất bại"
                                });
                            }
                        }
                    }
                    if (isOk)
                    {
                        db.SaveChanges();
                        result.IsSuccess = true;
                        result.Messages.Add(new Message()
                        {
                            Title = "Thông Báo", msg = "Lưu thành công."
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(result);
        }
示例#25
0
 public bool UpdateComport(int AppId, string comName, int baudRate, int dataBit, int parity, int stopBit, bool IsKeyPad)
 {
     try
     {
         var db        = new PMSEntities();
         var configs   = db.Configs;
         var configApp = db.Config_App.Where(x => x.AppId == AppId);
         if (IsKeyPad)
         {
             #region COM KEYPAD
             // comname
             var cf = configs.FirstOrDefault(x => x.Name.Trim().ToUpper().Equals("COM2"));
             if (cf != null)
             {
                 var cfApp = configApp.FirstOrDefault(x => x.ConfigId == cf.Id);
                 if (cfApp != null)
                 {
                     cfApp.Value = comName;
                 }
                 else
                 {
                     cf.ValueDefault = comName;
                 }
             }
             //
             cf = configs.FirstOrDefault(x => x.Name.Trim().ToUpper().Equals("BaudRate2"));
             if (cf != null)
             {
                 var cfApp = configApp.FirstOrDefault(x => x.ConfigId == cf.Id);
                 if (cfApp != null)
                 {
                     cfApp.Value = baudRate.ToString();
                 }
                 else
                 {
                     cf.ValueDefault = baudRate.ToString();
                 }
             }
             //
             cf = configs.FirstOrDefault(x => x.Name.Trim().ToUpper().Equals("DataBits2"));
             if (cf != null)
             {
                 var cfApp = configApp.FirstOrDefault(x => x.ConfigId == cf.Id);
                 if (cfApp != null)
                 {
                     cfApp.Value = dataBit.ToString();
                 }
                 else
                 {
                     cf.ValueDefault = dataBit.ToString();
                 }
             }
             //
             cf = configs.FirstOrDefault(x => x.Name.Trim().ToUpper().Equals("Parity2"));
             if (cf != null)
             {
                 var cfApp = configApp.FirstOrDefault(x => x.ConfigId == cf.Id);
                 if (cfApp != null)
                 {
                     cfApp.Value = parity.ToString();
                 }
                 else
                 {
                     cf.ValueDefault = parity.ToString();
                 }
             }
             //
             cf = configs.FirstOrDefault(x => x.Name.Trim().ToUpper().Equals("StopBits2"));
             if (cf != null)
             {
                 var cfApp = configApp.FirstOrDefault(x => x.ConfigId == cf.Id);
                 if (cfApp != null)
                 {
                     cfApp.Value = stopBit.ToString();
                 }
                 else
                 {
                     cf.ValueDefault = stopBit.ToString();
                 }
             }
             #endregion
         }
         else
         {
             #region COM TABLE
             // comname
             var cf = configs.FirstOrDefault(x => x.Name.Trim().ToUpper().Equals("COM"));
             if (cf != null)
             {
                 var cfApp = configApp.FirstOrDefault(x => x.ConfigId == cf.Id);
                 if (cfApp != null)
                 {
                     cfApp.Value = comName;
                 }
                 else
                 {
                     cf.ValueDefault = comName;
                 }
             }
             //
             cf = configs.FirstOrDefault(x => x.Name.Trim().ToUpper().Equals("BaudRate"));
             if (cf != null)
             {
                 var cfApp = configApp.FirstOrDefault(x => x.ConfigId == cf.Id);
                 if (cfApp != null)
                 {
                     cfApp.Value = baudRate.ToString();
                 }
                 else
                 {
                     cf.ValueDefault = baudRate.ToString();
                 }
             }
             //
             cf = configs.FirstOrDefault(x => x.Name.Trim().ToUpper().Equals("DataBits"));
             if (cf != null)
             {
                 var cfApp = configApp.FirstOrDefault(x => x.ConfigId == cf.Id);
                 if (cfApp != null)
                 {
                     cfApp.Value = dataBit.ToString();
                 }
                 else
                 {
                     cf.ValueDefault = dataBit.ToString();
                 }
             }
             //
             cf = configs.FirstOrDefault(x => x.Name.Trim().ToUpper().Equals("Parity"));
             if (cf != null)
             {
                 var cfApp = configApp.FirstOrDefault(x => x.ConfigId == cf.Id);
                 if (cfApp != null)
                 {
                     cfApp.Value = parity.ToString();
                 }
                 else
                 {
                     cf.ValueDefault = parity.ToString();
                 }
             }
             //
             cf = configs.FirstOrDefault(x => x.Name.Trim().ToUpper().Equals("StopBits"));
             if (cf != null)
             {
                 var cfApp = configApp.FirstOrDefault(x => x.ConfigId == cf.Id);
                 if (cfApp != null)
                 {
                     cfApp.Value = stopBit.ToString();
                 }
                 else
                 {
                     cf.ValueDefault = stopBit.ToString();
                 }
             }
             #endregion
         }
         db.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
     }
     return(false);
 }
示例#26
0
        public List <ReadPercentOfLineModel> GetAll(int[] LineIds)
        {
            var list = new List <ReadPercentOfLineModel>();

            try
            {
                db = new PMSEntities();
                list.AddRange(db.P_ReadPercentOfLine.Where(x => !x.IsDeleted && LineIds.Contains(x.Chuyen_SanPham.MaChuyen)).Select(x => new ReadPercentOfLineModel()
                {
                    Id                           = x.Id,
                    LineId                       = x.LineId,
                    LineName                     = x.Chuyen.TenChuyen,
                    IsDeleted                    = x.IsDeleted,
                    AssignmentId                 = x.AssignmentId,
                    CommoId                      = x.Chuyen_SanPham.MaSanPham,
                    CommoName                    = x.Chuyen_SanPham.SanPham.TenSanPham,
                    ReadPercentId                = x.ReadPercentId,
                    ReadPercentName              = x.ReadPercent.Name,
                    ReadPercent_KCSInventoryId   = x.ReadPercent_KCSInventoryId,
                    ReadPercent_KCSInventoryName = x.P_ReadPercent_KCSInventory.Name,
                    KanbanLightPercentId         = x.KanbanLightPercentId,
                    KanbanLightReadPercentName   = x.P_LightPercent.Name,
                    ProductLightPercentId        = x.ProductLightPercentId,
                    ProductLightReadPercentName  = x.P_LightPercent.Name
                }).OrderBy(x => x.LineId).ThenBy(x => x.AssignmentId));

                var csp = db.Chuyen_SanPham.Where(x => !x.IsDelete && !x.Chuyen.IsDeleted && !x.SanPham.IsDelete && !x.IsFinish && LineIds.Contains(x.MaChuyen)).ToArray();
                if (csp.Length > 0)
                {
                    var useIds = new List <int>();
                    int count  = 0;
                    P_ReadPercentOfLine obj;
                    foreach (var item in csp)
                    {
                        var obj_ = list.FirstOrDefault(x => x.AssignmentId == item.STT);
                        if (obj_ == null)
                        {
                            obj = new P_ReadPercentOfLine();
                            obj.AssignmentId  = item.STT;
                            obj.LineId        = item.MaChuyen;
                            obj.ReadPercentId = null;
                            obj.ReadPercent_KCSInventoryId = null;
                            obj.AssignmentId = item.STT;
                            db.P_ReadPercentOfLine.Add(obj);
                            count++;
                        }
                        else
                        {
                            useIds.Add(obj_.Id);
                        }
                    }

                    var removeObjs = db.P_ReadPercentOfLine.Where(x => !x.IsDeleted && !useIds.Contains(x.Id));
                    if (removeObjs != null && removeObjs.Count() > 0)
                    {
                        foreach (var item in removeObjs)
                        {
                            item.IsDeleted = true;
                        }
                    }
                    db.SaveChanges();

                    list.Clear();
                    list.AddRange(db.P_ReadPercentOfLine.Where(x => !x.IsDeleted && LineIds.Contains(x.Chuyen_SanPham.MaChuyen)).Select(x => new ReadPercentOfLineModel()
                    {
                        Id                           = x.Id,
                        LineId                       = x.LineId,
                        LineName                     = x.Chuyen.TenChuyen,
                        IsDeleted                    = x.IsDeleted,
                        AssignmentId                 = x.AssignmentId,
                        CommoId                      = x.Chuyen_SanPham.MaSanPham,
                        CommoName                    = x.Chuyen_SanPham.SanPham.TenSanPham,
                        ReadPercentId                = x.ReadPercentId,
                        ReadPercentName              = x.ReadPercent.Name,
                        ReadPercent_KCSInventoryId   = x.ReadPercent_KCSInventoryId,
                        ReadPercent_KCSInventoryName = x.P_ReadPercent_KCSInventory.Name,
                        KanbanLightPercentId         = x.KanbanLightPercentId,
                        KanbanLightReadPercentName   = x.P_LightPercent.Name,
                        ProductLightPercentId        = x.ProductLightPercentId,
                        ProductLightReadPercentName  = x.P_LightPercent.Name
                    }).OrderBy(x => x.LineId).ThenBy(x => x.AssignmentId));
                }
                else
                {
                    list.Clear();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(list);
        }
示例#27
0
        public TaskProcess addtask(int idStep, string name, int?role, string description, string inputConfig, string fileConfig)
        {
            TaskProcess task = new TaskProcess();

            task.IdStep         = idStep;
            task.Name           = name;
            task.IdRole         = role;
            task.Description    = description;
            task.IsRun          = false;
            task.ValueInputText = inputConfig;
            task.ValueInputFile = fileConfig;
            task.Color          = commonService.getRandomColor();
            task.Position       = getLastPosition(idStep) + 1;
            task.Created_At     = DateTime.Now;
            task.Updated_At     = DateTime.Now;
            db.TaskProcesses.Add(task);
            db.SaveChanges();
            return(task);
        }
示例#28
0
 public void Add(T model)
 {
     dbEntity.Add(model);
     dataContext.SaveChanges();
 }
示例#29
0
        public JsonResult Draw(int processId, string data, string nodeData, string linkData, string imageprocess)
        {
            Process ps = processService.findProcess(processId);

            processService.insertDataJson(ps, data, imageprocess);
            JArray     nodeArray   = JArray.Parse(nodeData);
            JArray     linkArray   = JArray.Parse(linkData);
            JToken     idfirstStep = linkArray.Where(x => (int)x["from"] == -1).FirstOrDefault();
            List <int> b           = new List <int>();
            string     circle      = "Circle";

            for (int i = 0; i < nodeArray.Count; i++)
            {
                if (nodeArray[i]["figure"] != null)
                {
                    if (nodeArray[i]["figure"].ToString() == circle && nodeArray[i]["fill"].ToString() == "#f20000")
                    {
                        b.Add((int)nodeArray[i]["key"]);
                    }
                }
            }
            for (int i = 0; i < nodeArray.Count; i++)
            {
                int           key  = (int)nodeArray[i]["key"];
                List <JToken> from = linkArray.Where(x => (int)x["from"] == key).ToList();
                Step          step = new Step();
                int           j    = 1;
                if (from != null)
                {
                    foreach (JToken item in from)
                    {
                        int to = (int)item["to"];
                        if (j == 1)
                        {
                            step.NextStep1 = to;
                        }
                        else if (j == 2)
                        {
                            step.NextStep2 = to;
                        }
                        j++;
                    }
                    if (step.NextStep1 == null)
                    {
                        step.NextStep1 = 0;
                    }
                    if (step.NextStep2 == null)
                    {
                        step.NextStep2 = 0;
                    }
                    foreach (int tokey in b)
                    {
                        if (step.NextStep1 == tokey)
                        {
                            step.NextStep1 = 0;
                        }
                    }
                }

                step.IdProcess  = ps.Id;
                step.Name       = nodeArray[i]["text"].ToString().Trim();
                step.Key        = key;
                step.IsRun      = false;
                step.StartStep  = (int)idfirstStep["to"] == (int)nodeArray[i]["key"] ? true : false;
                step.Color      = commonService.getRandomColor();
                step.Figure     = nodeArray[i]["figure"] == null ? "Step" : nodeArray[i]["figure"].ToString();
                step.Created_At = DateTime.Now;
                step.Updated_At = DateTime.Now;
                if (step.Figure != "Circle")
                {
                    db.Steps.Add(step);
                    db.SaveChanges();
                    string directoryPath = String.Format("Upload/{0}/{1}/{2}", ps.Group.Id, ps.Id, step.Id);
                    fileService.createDirectory(directoryPath);
                }
            }
            return(Json(new { id = ps.Id }));
        }
示例#30
0
        public ResponseBase InsertOrUpdate(Chuyen_SanPham model)
        {
            var result = new ResponseBase();

            try
            {
                using (var db = new PMSEntities())
                {
                    var csp = db.Chuyen_SanPham.FirstOrDefault(x => !x.IsDelete && x.STT != model.STT && x.MaChuyen == model.MaChuyen && x.MaSanPham == model.MaSanPham && !x.IsFinish);
                    if (csp == null)
                    {
                        if (!CheckOrderIndex(model.STT, model.MaChuyen, model.STTThucHien, db))
                        {
                            if (model.STT == 0)
                            {
                                #region add
                                csp = new Chuyen_SanPham();
                                Parse.CopyObject(model, ref csp);
                                var monthDetail = new P_MonthlyProductionPlans();
                                monthDetail.Chuyen_SanPham   = csp;
                                monthDetail.Month            = DateTime.Now.Month;
                                monthDetail.Year             = DateTime.Now.Year;
                                monthDetail.ProductionPlans  = csp.SanLuongKeHoach;
                                csp.P_MonthlyProductionPlans = new List <P_MonthlyProductionPlans>();
                                csp.P_MonthlyProductionPlans.Add(monthDetail);
                                csp.TimeAdd = DateTime.Now;
                                db.Chuyen_SanPham.Add(csp);
                                db.SaveChanges();
                                result.IsSuccess = true;
                                result.Messages.Add(new Message()
                                {
                                    Title = "Thông Báo", msg = "Lưu Phân công thành công."
                                });

                                #endregion
                            }
                            else
                            {
                                csp = db.Chuyen_SanPham.FirstOrDefault(x => !x.IsDelete && x.STT == model.STT);
                                if (csp != null)
                                {
                                    var mDetail = db.P_MonthlyProductionPlans.FirstOrDefault(x => !x.IsDeleted && x.STT_C_SP == model.STT && x.Month == DateTime.Now.Month && x.Year == DateTime.Now.Year);
                                    if (mDetail != null)
                                    {
                                        if (csp.SanLuongKeHoach > model.SanLuongKeHoach)
                                        {
                                            mDetail.ProductionPlans -= (csp.SanLuongKeHoach - model.SanLuongKeHoach);
                                        }
                                        else
                                        {
                                            mDetail.ProductionPlans += (model.SanLuongKeHoach - csp.SanLuongKeHoach);
                                        }
                                    }

                                    csp.STTThucHien            = model.STTThucHien;
                                    csp.MaSanPham              = model.MaSanPham;
                                    csp.UpdatedDate            = model.UpdatedDate;
                                    csp.SanLuongKeHoach        = model.SanLuongKeHoach;
                                    csp.IsFinish               = csp.SanLuongKeHoach > csp.LuyKeTH ? false : true;
                                    csp.IsFinishBTPThoatChuyen = model.IsFinishBTPThoatChuyen;

                                    // update lai nang suat san suat va dinh muc ngay hien tai
                                    var ngay = DateTime.Now.Day + "/" + DateTime.Now.Month + "/" + DateTime.Now.Year;
                                    var tp   = db.ThanhPhams.FirstOrDefault(x => !x.IsDeleted && x.STTChuyen_SanPham == csp.STT && x.Ngay == ngay);
                                    var nx   = db.NangXuats.FirstOrDefault(x => !x.IsDeleted && x.STTCHuyen_SanPham == csp.STT && x.Ngay == ngay);
                                    if (tp != null && nx != null)
                                    {
                                        var tgLVTrongNgay = (int)BLLShift.GetTotalWorkingHourOfLine(csp.MaChuyen).TotalSeconds;
                                        tp.NangXuatLaoDong = (float)Math.Round((tgLVTrongNgay / csp.SanPham.ProductionTime), 2);

                                        nx.DinhMucNgay    = (float)Math.Round((tp.NangXuatLaoDong * tp.LaoDongChuyen), 1);
                                        nx.NhipDoSanXuat  = (float)Math.Round((csp.SanPham.ProductionTime / tp.LaoDongChuyen), 1);
                                        nx.TimeLastChange = DateTime.Now.TimeOfDay;
                                    }
                                    db.SaveChanges();
                                    //BLLProductivity.ResetNormsDayAndBTPInLine(2, obj.MaChuyen, false);
                                    result.IsSuccess = true;
                                    result.Messages.Add(new Message()
                                    {
                                        Title = "Thông Báo", msg = "Lưu Phân công thành công."
                                    });
                                }
                                else
                                {
                                    result.IsSuccess = false;
                                    result.Messages.Add(new Message()
                                    {
                                        Title = "Lỗi Lưu Phân Công", msg = "không tìm thấy Phân Công.\n"
                                    });
                                }
                            }
                        }
                        else
                        {
                            result.IsSuccess = false;
                            result.Messages.Add(new Message()
                            {
                                Title = "Thông Báo Trùng số thứ tự", msg = "Số thứ tự thực hiện  này được chọn. Vui lòng chọn số thứ tự thực hiện khác."
                            });
                        }
                    }
                    else
                    {
                        result.IsSuccess = false;
                        result.Messages.Add(new Message()
                        {
                            Title = "Lỗi Lưu Phân Công", msg = "Sản phẩm này đã được phân công và đang sản xuất.\n"
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Messages.Add(new Message()
                {
                    Title = "Lỗi Lưu Phân Công", msg = "Lưu Phân công cho Chuyền bị lỗi.\n" + ex.Message
                });
            }
            return(result);
        }