Exemplo n.º 1
0
 public void ActionApply(FormBaoCaoTongHopModel model, MSoLuongSuCoModelForm entitySuCo)
 {
     if (ValidSave(model, entitySuCo))
     {
         ApplyRedirect(model.RecordID, entity.ID);
     }
 }
Exemplo n.º 2
0
 public void ActionSave(FormBaoCaoTongHopModel model, MSoLuongSuCoModelForm entitySuCo)
 {
     if (ValidSave(model, entitySuCo))
     {
         SaveRedirect();
     }
 }
Exemplo n.º 3
0
        private bool ValidSave(FormBaoCaoTongHopModel model, MSoLuongSuCoModelForm entitySuCo)
        {
            TryUpdateModel(entity);

            //chong hack
            entity.ID = model.RecordID;

            ViewBag.Data  = entity;
            ViewBag.Model = model;

            CPViewPage.Message.MessageType = Message.MessageTypeEnum.Error;

            //kiem tra quyen han
            if ((model.RecordID < 1 && !CPViewPage.UserPermissions.Add) || (model.RecordID > 0 && !CPViewPage.UserPermissions.Edit))
            {
                CPViewPage.Message.ListMessage.Add("Quyền hạn chế.");
            }

            //kiem tra ten
            if (entity.Name.Trim() == string.Empty)
            {
                CPViewPage.Message.ListMessage.Add("Nhập tên.");
            }

            //kiem tra chuyen muc
            //if (entity.MenuID < 1)
            //    CPViewPage.Message.ListMessage.Add("Chọn chuyên mục.");

            if (CPViewPage.Message.ListMessage.Count == 0)
            {
                //neu khong nhap code -> tu sinh
                if (entity.Code.Trim() == string.Empty)
                {
                    entity.Code = Data.GetCode(entity.Name);
                }

                //cap nhat state
                entity.State = GetState(model.ArrState);

                //save
                int id = ModBaoCaoTongHopService.Instance.Save(entity);
                if (model.RecordID > 0)
                {
                    UpdateOther(entity, entitySuCo);
                }
                else
                {
                    SaveOther(id, entitySuCo);
                }

                return(true);
            }

            return(false);
        }
Exemplo n.º 4
0
        public void SaveOther(int id, MSoLuongSuCoModelForm entitySuCo)
        {
            DateTime date = DateTime.Now;

            int c = entitySuCo.MN.Length;

            for (int i = 0; i < c; i++)
            {
                var  suCo = new ModSoLuongSuCoEntity();
                bool flag = false;
                if (entitySuCo.SoLuong[i] > 0)
                {
                    suCo.SoLuong = entitySuCo.SoLuong[i];
                    flag         = true;
                }
                if (entitySuCo.TuXuLy[i] > 0)
                {
                    suCo.TuXuLy = entitySuCo.TuXuLy[i];
                    flag        = true;
                }
                if (entitySuCo.ToChucHoTro[i] > 0)
                {
                    suCo.ToChucHoTro = entitySuCo.ToChucHoTro[i];
                    flag             = true;
                }
                if (entitySuCo.ToChucNuocNgoaiHoTro[i] > 0)
                {
                    suCo.ToChucNuocNgoaiHoTro = entitySuCo.ToChucNuocNgoaiHoTro[i];
                    flag = true;
                }
                if (entitySuCo.DeNghi[i] > 0)
                {
                    suCo.DeNghi = entitySuCo.DeNghi[i];
                    flag        = true;
                }
                if (entitySuCo.ThietHaiUocTinh[i] > 0)
                {
                    suCo.ThietHaiUocTinh = entitySuCo.ThietHaiUocTinh[i];
                    flag = true;
                }
                if (flag == true)
                {
                    suCo.BaoCaoTongHopID = id;
                    suCo.MenuID          = entitySuCo.MN[i];
                    suCo.Published       = date;
                    suCo.Order           = GetMaxOrder_SoSuCo();
                    suCo.Activity        = true;

                    ModSoLuongSuCoService.Instance.Save(suCo);
                }
            }
        }
Exemplo n.º 5
0
        public void UpdateOther(ModBaoCaoTongHopEntity entityBc, MSoLuongSuCoModelForm entitySuCo)
        {
            int userId = HL.Lib.Global.CPLogin.UserID;
            var entity = ModBaoCaoTongHopService.Instance.CreateQuery()
                         //.Where(userId > 0, o => o.UserID == userId)
                         .Where(o => o.Code == entityBc.Code)
                         .ToSingle();

            if (entity != null)
            {
                DateTime date = DateTime.Now;

                entityBc.ID         = entity.ID;
                entityBc.UserID     = entity.UserID;
                entityBc.UserID1    = userId;
                entityBc.MenuID     = entity.MenuID;
                entityBc.State      = entity.State;
                entityBc.Name       = entity.Name;
                entityBc.Code       = entity.Code;
                entityBc.Order      = entity.Order;
                entityBc.Published  = entity.Published;
                entityBc.Published1 = date;
                entityBc.Activity   = false;

                var lstSuCo = ModSoLuongSuCoService.Instance.CreateQuery().Where(o => o.BaoCaoTongHopID == entity.ID).ToList();
                if (lstSuCo != null)
                {
                    ModSoLuongSuCoService.Instance.Delete(lstSuCo);
                }
                int c = entitySuCo.MN.Length;
                for (int i = 0; i < c; i++)
                {
                    var  suCo = new ModSoLuongSuCoEntity();
                    bool flag = false;
                    if (entitySuCo.SoLuong[i] > 0)
                    {
                        suCo.SoLuong = entitySuCo.SoLuong[i];
                        flag         = true;
                    }
                    if (entitySuCo.TuXuLy[i] > 0)
                    {
                        suCo.TuXuLy = entitySuCo.TuXuLy[i];
                        flag        = true;
                    }
                    if (entitySuCo.ToChucHoTro[i] > 0)
                    {
                        suCo.ToChucHoTro = entitySuCo.ToChucHoTro[i];
                        flag             = true;
                    }
                    if (entitySuCo.ToChucNuocNgoaiHoTro[i] > 0)
                    {
                        suCo.ToChucNuocNgoaiHoTro = entitySuCo.ToChucNuocNgoaiHoTro[i];
                        flag = true;
                    }
                    if (entitySuCo.DeNghi[i] > 0)
                    {
                        suCo.DeNghi = entitySuCo.DeNghi[i];
                        flag        = true;
                    }
                    if (entitySuCo.ThietHaiUocTinh[i] > 0)
                    {
                        suCo.ThietHaiUocTinh = entitySuCo.ThietHaiUocTinh[i];
                        flag = true;
                    }
                    if (flag == true)
                    {
                        int id = ModBaoCaoTongHopService.Instance.Save(entityBc);
                        suCo.BaoCaoTongHopID = id;
                        suCo.MenuID          = entitySuCo.MN[i];
                        suCo.Published       = date;
                        suCo.Order           = GetMaxOrder_SoSuCo();
                        suCo.Activity        = true;

                        ModSoLuongSuCoService.Instance.Save(suCo);
                    }
                }

                ViewBag.BaoCao = entityBc;
            }
        }