Пример #1
0
 public ResponseData UpdateByEntity(PositionRateViewModel newdata)
 {
     using (SATEntities db = new SATEntities())
     {
         ResponseData result = new Models.ResponseData();
         try
         {
             var model = db.tb_Man_Power.Single(x => x.MpID == newdata.MpID);
             model.DivID      = newdata.DivID;
             model.DepID      = newdata.DepID;
             model.SecID      = newdata.SecID;
             model.PoID       = newdata.PoID;
             model.DisID      = newdata.DisID;
             model.UserID     = newdata.UserID;
             model.EduID      = newdata.EduID;
             model.ModifyBy   = UtilityService.User.UserID;
             model.ModifyDate = DateTime.Now;
             db.SaveChanges();
         }
         catch (Exception ex)
         {
             result.MessageCode = "";
             result.MessageText = ex.Message;
         }
         return(result);
     }
 }
Пример #2
0
        public ResponseData AddByEntity(PositionRateViewModel data)
        {
            using (SATEntities db = new SATEntities())
            {
                ResponseData result = new Models.ResponseData();
                try
                {
                    int maxID = db.tb_Man_Power.Where(m => m.TypeID == data.TypeID).Max(m => (int)m.MpID);

                    tb_Man_Power model = new tb_Man_Power();
                    model.MpID       = maxID;
                    model.TypeID     = data.TypeID;
                    model.DivID      = data.DivID;
                    model.DepID      = data.DepID;
                    model.SecID      = data.SecID;
                    model.PoID       = data.PoID;
                    model.DisID      = data.DisID;
                    model.UserID     = data.UserID;
                    model.EduID      = data.EduID;
                    model.CreateBy   = UtilityService.User.UserID;
                    model.CreateDate = DateTime.Now;
                    model.ModifyBy   = UtilityService.User.UserID;
                    model.ModifyDate = DateTime.Now;
                    db.tb_Man_Power.Add(model);
                    db.SaveChanges();
                    result.ID = model.MpID;
                }
                catch (Exception ex)
                {
                    result.MessageCode = "";
                    result.MessageText = ex.Message;
                }
                return(result);
            }
        }
Пример #3
0
        public List <PositionRateViewModel> GetPositionManPower(int?type, int?divid, int?depid, int?secid)
        {
            List <PositionRateViewModel> list = new List <PositionRateViewModel>();

            using (SATEntities db = new SATEntities())
            {
                var position = db.vw_Man_Power.Where(m => m.TypeID == type && m.DivID == divid && m.DepID == depid && m.SecID == secid && !string.IsNullOrEmpty(m.PoName))
                               .GroupBy(item => item.PoID, (key, group) => new
                {
                    PoID   = key,
                    PoName = group.FirstOrDefault().PoName,
                    MpID   = group.FirstOrDefault().MpID,
                    DivID  = group.FirstOrDefault().DivID,
                    DepID  = group.FirstOrDefault().DepID,
                    SecID  = group.FirstOrDefault().SecID
                }).OrderBy(o => o.PoName).ToList();

                foreach (var item in position)
                {
                    PositionRateViewModel model = new PositionRateViewModel();
                    model.MpID = item.MpID;
                    //model.MpCode = (type == 1) ? item.MpID.ToString().PadLeft(3, '0') : item.MpID.ToString().PadLeft(4, '0');
                    model.PoID   = item.PoID;
                    model.PoName = item.PoName;
                    model.DivID  = item.DivID;
                    model.DepID  = item.DepID;
                    model.SecID  = item.SecID;
                    list.Add(model);
                }
            }
            return(list);
        }
Пример #4
0
        public List <PositionRateViewModel> GetDivisionManPower(int?type)
        {
            List <PositionRateViewModel> list = new List <PositionRateViewModel>();

            using (SATEntities db = new SATEntities())
            {
                var deivision = db.vw_Man_Power.Where(m => m.TypeID == type && m.DivID != null)
                                .GroupBy(item => item.DivID, (key, group) => new
                {
                    DivID   = key,
                    DivName = group.FirstOrDefault().DivName,
                    MpID    = group.FirstOrDefault().MpID
                }).OrderBy(o => o.DivName).ToList();

                foreach (var item in deivision)
                {
                    PositionRateViewModel model = new PositionRateViewModel();
                    model.MpID = item.MpID;
                    //model.MpCode = (type == 1) ? item.MpID.ToString().PadLeft(3, '0') : item.MpID.ToString().PadLeft(4, '0');
                    model.DivID   = item.DivID;
                    model.DivName = item.DivName;
                    list.Add(model);
                }
            }
            return(list);
        }
Пример #5
0
        public PositionRateViewModel GetByID(int?id)
        {
            PositionRateViewModel model = new PositionRateViewModel();

            try
            {
                using (SATEntities db = new SATEntities())
                {
                    var data = db.vw_Man_Power.Where(x => x.MpID == id).FirstOrDefault();
                    if (data != null)
                    {
                        model.MpID = data.MpID;
                        //model.MpCode = data.TypeID == 1 ? data.MpID.ToString().PadLeft(3, '0') : data.MpID.ToString().PadLeft(4, '0');
                        model.DivID      = data.DivID;
                        model.DepID      = data.DepID;
                        model.SecID      = data.SecID;
                        model.PoID       = data.PoID;
                        model.DisID      = data.DisID;
                        model.UserID     = data.UserID;
                        model.FullNameTh = data.TiShortName + data.FullNameTh;
                        model.EduID      = data.EduID;
                        model.TypeID     = data.TypeID;
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(model);
        }
Пример #6
0
        public JsonResult SavePositionRate(PositionRateViewModel data)
        {
            ResponseData result = new Models.ResponseData();

            if (data.MpID != 0)
            {
                result = new PositionRateRepository().UpdateByEntity(data);
            }
            else
            {
                result = new PositionRateRepository().AddByEntity(data);
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Пример #7
0
        public List <PositionRateViewModel> GetPositionRate(int?type)
        {
            using (SATEntities db = new SATEntities())
            {
                List <PositionRateViewModel> list = new List <PositionRateViewModel>();

                var position = db.vw_Man_Power.Where(m => m.TypeID == type && !string.IsNullOrEmpty(m.PoName))
                               .GroupBy(item => item.PoID, (key, group) => new { PoID = key, MpID = group.FirstOrDefault().MpID, PoName = group.FirstOrDefault().PoName })
                               .OrderBy(o => o.MpID)
                               .ToList();

                foreach (var item in position)
                {
                    PositionRateViewModel model = new PositionRateViewModel();
                    model.MpID = item.MpID;
                    //model.MpCode = type == 1 ? item.MpID.ToString().PadLeft(3, '0') : item.MpID.ToString().PadLeft(4, '0');
                    model.PoName = item.PoName;
                    list.Add(model);
                }

                return(list);
            }
        }