Example #1
0
        public bool AddDefaultScene(int formId)
        {
            CPForm form = this._CPFormRep.Get(formId);

            if (form == null)
            {
                return(false);
            }
            CPFormUseScene scene = new CPFormUseScene();
            int            autoIndex;

            scene.FormId          = formId;
            scene.SceneCode       = CPAutoNumHelper.Instance().GetNextAutoNum("FormSceneCodeAuto", out autoIndex);
            scene.AutoIndex       = autoIndex;
            scene.FormSavedAction = CPFormEnum.FormSavedActionEnum.ReturnEditPage;
            scene.SceneName       = "默认";
            scene.FuncCol         = new List <CPFormUseSceneFunc>();
            CPFormUseSceneFunc func = new CPFormUseSceneFunc();

            func.FuncTitle        = "保存";
            func.ShowOrder        = 10;
            func.FuncExeJS        = "CPFormSaveFormData()";
            func.FuncIsShowInView = CPFormEnum.FuncIsShowInViewEnum.OnlyWriteShow;
            func.IsControlByRight = false;
            func.FormId           = formId;
            scene.FuncCol.Add(func);
            this._CPFormUseSceneRep.Add(scene);
            return(true);
        }
Example #2
0
        public GetFormInfoReturn GetFormInfo(string FormCode, string SceneCode, string ViewCode, string InitGroupCode,
                                             string RightGroupCode, string PKValues
                                             , int CurUserId, string CurUserIden, string DeviceType = "1",
                                             bool IsView = false
                                             )
        {
            GetFormInfoReturn re = new GetFormInfoReturn();

            try
            {
                base.SetHeader();
                FormCode       = CPAppContext.FormatSqlPara(FormCode);
                SceneCode      = CPAppContext.FormatSqlPara(SceneCode);
                ViewCode       = CPAppContext.FormatSqlPara(ViewCode);
                InitGroupCode  = CPAppContext.FormatSqlPara(InitGroupCode);
                RightGroupCode = CPAppContext.FormatSqlPara(RightGroupCode);
                PKValues       = CPAppContext.FormatSqlPara(PKValues);
                CurUserIden    = CPAppContext.FormatSqlPara(CurUserIden);
                DeviceType     = CPAppContext.FormatSqlPara(DeviceType);

                if (this.CheckUserIden(CurUserId, CurUserIden) == false)
                {
                    re.Result   = false;
                    re.ErrorMsg = "系统检测到非法获取数据,请传入正确的用户会话Key与用户Id参数!";
                    return(re);
                }
                CPForm form = CPFormTemplate.Instance(CurUserId).GetForm(FormCode, true, true, false, false, false, true);
                form.ViewCol = new List <CPFormView>();
                form.ViewCol.Add(CPFormTemplate.Instance(CurUserId).GetFormView(ViewCode, true));
                //re.Form = EmitMapper.ObjectMapperManager.DefaultInstance.GetMapper<CPForm, CPFormClient>()
                //                                  .Map(form);
                Mapper.Initialize(cfg =>
                {
                    cfg.CreateMap <CPForm, CPFormClient>();
                });

                re.Form = AutoMapper.Mapper.Map <CPFormClient>(form);
                CPFormGroup rightGroup = CPFormTemplate.Instance(CurUserId).GetFormRightGroup(RightGroupCode, true);
                // re.FieldRightCol = (rightGroup == null ? null : rightGroup.FieldRightCol);
                CPFormGroup initGroup = CPFormTemplate.Instance(CurUserId).GetFormInitGroup(InitGroupCode, true);
                re.Form.FieldInitCol = (initGroup == null ? null : initGroup.FieldInitCol);
                re.ViewHTML          = CPFormTemplate.Instance(CurUserId).FormatFormViewHtml(form, form.FieldCol, form.ViewCol[0],
                                                                                             (rightGroup == null ? null : rightGroup.FieldRightCol),
                                                                                             CPEnum.ConvertDeviceTypeEnum(int.Parse(DeviceType)), true, IsView);
                //获取应用场景
                re.Form.UseSceneCol = new List <CPFormUseScene>();
                re.Form.UseSceneCol.Add(CPFormTemplate.Instance(CurUserId).GetFormUseScene(SceneCode, true));
                re.Form.UseSceneCol.ForEach(t =>
                {
                    t.FormSavedInfo = CPExpressionHelper.Instance.RunCompile(t.FormSavedInfo);

                    //处理按钮是否显示
                    List <CPFormUseSceneFunc> funcCol = new List <CPFormUseSceneFunc>();
                    t.FuncCol.ForEach(func => {
                        if (func.FuncIsShowInView == CPFormEnum.FuncIsShowInViewEnum.ShowAll)
                        {
                            funcCol.Add(func);
                        }
                        else if (func.FuncIsShowInView == CPFormEnum.FuncIsShowInViewEnum.OnlyWriteShow)
                        {
                            if (IsView == false)
                            {
                                funcCol.Add(func);
                            }
                        }
                        else if (func.FuncIsShowInView == CPFormEnum.FuncIsShowInViewEnum.OnlyReadShow)
                        {
                            if (IsView == true)
                            {
                                funcCol.Add(func);
                            }
                        }
                    });
                    #region 添加修改配置按钮
                    if (re.Form.SysId.HasValue && re.Form.SysId.Value.Equals(CPAppContext.InnerSysId) == false)
                    {
                        string UserAdminSysIds = CPExpressionHelper.Instance.RunCompile("${CPUser.UserAdminSysIds()}");
                        if (UserAdminSysIds.Split(',').ToList().Contains(re.Form.SysId.ToString()))
                        {
                            CPFormUseSceneFunc func1 = new CPFormUseSceneFunc();
                            func1.FuncTitle          = "修改配置";
                            func1.ShowOrder          = 999999;
                            func1.FuncIcon           = "icon-shezhi1";
                            func1.IsControlByRight   = false;
                            func1.FuncIsShowInView   = CPFormEnum.FuncIsShowInViewEnum.ShowAll;
                            func1.FuncExeJS          = "CPFormUpdateConfig(" + re.Form.Id + ")";
                            func1.SceneID            = t.Id;
                            funcCol.Add(func1);
                        }
                    }
                    #endregion
                    t.FuncCol = funcCol;
                    t.FuncCol = t.FuncCol.OrderBy(c => c.ShowOrder).ToList();
                });

                //读取真实数据
                re.FormDataJSON = CPFormEngine.Instance(CurUserId).GetFormDataJSON(form, form.ChildTableCol,
                                                                                   form.FieldCol, re.Form.FieldInitCol, PKValues, re.Form.UseSceneCol[0]);
                re.Result = true;
                return(re);
            }
            catch (Exception ex)
            {
                re.Result   = false;
                re.ErrorMsg = ex.Message.ToString();
                return(re);
            }
        }