Exemplo n.º 1
0
        public ResponseBase InsertOrUpdate(P_DepartmentDailyLabour objModel)
        {
            var rs = new ResponseBase();

            using (var db = new PMSEntities())
            {
                try
                {
                    if (CheckName(objModel, db) != null)
                    {
                        rs.IsSuccess = false;
                        rs.Messages.Add(new Message()
                        {
                            msg = "Bộ phận đã tồn tại. Vui lòng chọn lại Bộ phận khác", Title = "Lỗi trùng tên"
                        });
                    }
                    else
                    {
                        if (objModel.Id == 0)
                        {
                            db.P_DepartmentDailyLabour.Add(objModel);
                            rs.IsSuccess = true;
                        }
                        else
                        {
                            var oldObj = db.P_DepartmentDailyLabour.FirstOrDefault(x => x.Id == objModel.Id);
                            if (oldObj != null)
                            {
                                oldObj.DepartmentId = objModel.DepartmentId;
                                oldObj.LDVacation   = objModel.LDVacation;
                                oldObj.LDPregnant   = objModel.LDPregnant;
                                oldObj.LDOff        = objModel.LDOff;
                                oldObj.LDNew        = objModel.LDNew;
                                oldObj.LDCurrent    = objModel.LDCurrent;
                                rs.IsSuccess        = true;
                            }
                            else
                            {
                                rs.IsSuccess = false;
                                rs.Messages.Add(new Message()
                                {
                                    msg = "Bộ phận đang thao tác không tồn tại hoặc đã bị xóa. ", Title = "Lỗi trùng tên"
                                });
                            }
                        }
                        if (rs.IsSuccess)
                        {
                            db.SaveChanges();
                            rs.IsSuccess = true;
                        }
                    }
                }
                catch (Exception)
                {
                }
            }
            return(rs);
        }
Exemplo n.º 2
0
        public void AutoSetFromYesterday()
        {
            using (var db = new PMSEntities())
            {
                try
                {
                    var latetestWork = BLLProductivity_.Instance.GetLatestWork();
                    if (latetestWork != null)
                    {
                        string date           = latetestWork.CreatedDate.ToString("dd/MM/yyyy");
                        var    yesterdayInfos = db.P_DepartmentDailyLabour.Where(x => x.Date == date).OrderByDescending(x => x.CreatedAt).Select(x => new DepartmentDailyLaboursModel()
                        {
                            Id           = x.Id,
                            DepartmentId = x.DepartmentId,
                            LDCurrent    = x.LDCurrent,
                            LDNew        = x.LDNew,
                            LDOff        = x.LDOff,
                            LDPregnant   = x.LDPregnant,
                            LDVacation   = x.LDVacation
                        }).ToList();

                        if (yesterdayInfos.Count > 0)
                        {
                            P_DepartmentDailyLabour departmentDailyLabour;
                            DateTime now      = DateTime.Now;
                            string   todayStr = now.ToString("dd/MM/yyyy");
                            var      departs  = db.P_DepartmentDailyLabour.Where(x => x.Date == todayStr).Select(x => x.DepartmentId).ToArray();
                            yesterdayInfos = yesterdayInfos.Where(x => !departs.Contains(x.DepartmentId)).ToList();

                            foreach (var item in yesterdayInfos)
                            {
                                departmentDailyLabour = new P_DepartmentDailyLabour();
                                Parse.CopyObject(item, ref departmentDailyLabour);
                                departmentDailyLabour.Date      = todayStr;
                                departmentDailyLabour.CreatedAt = now;
                                db.P_DepartmentDailyLabour.Add(departmentDailyLabour);
                            }
                            db.SaveChanges();
                        }
                    }
                }
                catch (Exception)
                {
                }
            }
        }
        private void Save()
        {
            int Id = 0;

            int.TryParse(gridView.GetRowCellValue(gridView.FocusedRowHandle, "Id").ToString(), out Id);
            if (string.IsNullOrEmpty(gridView.GetRowCellValue(gridView.FocusedRowHandle, "DepartmentId").ToString()))
            {
                MessageBox.Show("Vui lòng chọn bộ phận.", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (string.IsNullOrEmpty(gridView.GetRowCellValue(gridView.FocusedRowHandle, "LDCurrent").ToString()) &&
                     Convert.ToDouble(gridView.GetRowCellValue(gridView.FocusedRowHandle, "LDCurrent").ToString()) <= 0)
            {
                MessageBox.Show("lao động định biên phải lớn hơn 0, hoặc bạn nhập sai định dạng dữ liệu.\n", "Lỗi nhập liệu");
            }
            else
            {
                var obj = new P_DepartmentDailyLabour();
                obj.Id           = Id;
                obj.Date         = dtDate.Value.ToString("dd/MM/yyyy");
                obj.CreatedAt    = dtDate.Value;
                obj.DepartmentId = Convert.ToInt32(gridView.GetRowCellValue(gridView.FocusedRowHandle, "DepartmentId").ToString());
                obj.LDCurrent    = Convert.ToInt32(gridView.GetRowCellValue(gridView.FocusedRowHandle, "LDCurrent").ToString());
                obj.LDNew        = Convert.ToInt32(gridView.GetRowCellValue(gridView.FocusedRowHandle, "LDNew").ToString());
                obj.LDOff        = Convert.ToInt32(gridView.GetRowCellValue(gridView.FocusedRowHandle, "LDOff").ToString());
                obj.LDPregnant   = Convert.ToInt32(gridView.GetRowCellValue(gridView.FocusedRowHandle, "LDPregnant").ToString());
                obj.LDVacation   = Convert.ToInt32(gridView.GetRowCellValue(gridView.FocusedRowHandle, "LDVacation").ToString());

                var rs = BLLDepartmentDailyLabour.Instance.InsertOrUpdate(obj);
                if (rs.IsSuccess)
                {
                    LoadGrid();
                }
                else
                {
                    MessageBox.Show(rs.Messages[0].msg, rs.Messages[0].Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemplo n.º 4
0
 private P_DepartmentDailyLabour CheckName(P_DepartmentDailyLabour obj, PMSEntities db)
 {
     return(db.P_DepartmentDailyLabour.FirstOrDefault(x => x.Id != obj.Id && x.Date == obj.Date && x.DepartmentId == obj.DepartmentId));
 }