public override AstVisitAction VisitPropertyMember(PropertyMemberAst propertyMemberAst)
        {
            HelpEntity helpResult  = null;
            var        description = "";

            if ((propertyMemberAst.Parent as TypeDefinitionAst).IsClass)
            {
                var attributes = propertyMemberAst.Attributes.Count >= 0 ?
                                 $", with attributes '{string.Join(", ", propertyMemberAst.Attributes.Select(p => p.TypeName.Name))}'." :
                                 ".";
                description = $"Property '{propertyMemberAst.Name}' of type '{propertyMemberAst.PropertyType.TypeName.FullName}'{attributes}";
                helpResult  = HelpTableQuery("about_classes");
                helpResult.DocumentationLink += "#class-properties";
            }

            if ((propertyMemberAst.Parent as TypeDefinitionAst).IsEnum)
            {
                description = $"Enum label '{propertyMemberAst.Name}', with value '{propertyMemberAst.InitialValue}'.";
                helpResult  = HelpTableQuery("about_enum");
            }

            explanations.Add(new Explanation()
            {
                Description     = description,
                CommandName     = "Property member",
                HelpResult      = helpResult,
                TextToHighlight = propertyMemberAst.Name
            }.AddDefaults(propertyMemberAst, explanations));

            return(base.VisitPropertyMember(propertyMemberAst));
        }
        public override AstVisitAction VisitTypeConstraint(TypeConstraintAst typeConstraintAst)
        {
            if (typeConstraintAst.Parent is CatchClauseAst)
            {
                return(base.VisitTypeConstraint(typeConstraintAst));
            }

            var        typeName    = typeConstraintAst.TypeName.Name;
            var        accelerator = ".";
            var        cmdName     = "Type constraint";
            HelpEntity help        = null;

            var(acceleratorName, acceleratorFullTypeName) = Helpers.ResolveAccelerator(typeName);
            if (acceleratorName != null)
            {
                typeName    = acceleratorName;
                accelerator = $", which is a type accelerator for '{acceleratorFullTypeName}'";
                help        = HelpTableQuery("about_type_accelerators");
                cmdName     = "Type accelerator";
            }
            else if (typeConstraintAst.Parent is ConvertExpressionAst)
            {
                return(base.VisitTypeConstraint(typeConstraintAst));
            }

            explanations.Add(
                new Explanation()
            {
                Description = $"Constrains the type to '{typeName}'{accelerator}",
                CommandName = cmdName,
                HelpResult  = help
            }.AddDefaults(typeConstraintAst, explanations));

            return(base.VisitTypeConstraint(typeConstraintAst));
        }
        public override AstVisitAction VisitTypeExpression(TypeExpressionAst typeExpressionAst)
        {
            if (typeExpressionAst.Parent is BinaryExpressionAst ||
                typeExpressionAst.Parent is CommandExpressionAst ||
                typeExpressionAst.Parent is AssignmentStatementAst)
            {
                HelpEntity help        = null;
                var        description = string.Empty;

                if (typeExpressionAst.TypeName.IsArray)
                {
                    description = $"Array of '{typeExpressionAst.TypeName.Name}'";
                    help        = new HelpEntity()
                    {
                        DocumentationLink = "https://docs.microsoft.com/en-us/powershell/scripting/lang-spec/chapter-04"
                    };
                }
                else if (typeExpressionAst.TypeName.IsGeneric)
                {
                    description = $"Generic type";
                    help        = new HelpEntity()
                    {
                        DocumentationLink = "https://docs.microsoft.com/en-us/powershell/scripting/lang-spec/chapter-04#44-generic-types"
                    };
                }

                explanations.Add(new Explanation()
                {
                    Description = description,
                    CommandName = "Type expression",
                    HelpResult  = help
                }.AddDefaults(typeExpressionAst, explanations));
            }
            return(base.VisitTypeExpression(typeExpressionAst));
        }
Ejemplo n.º 4
0
        public ActionResult Create(int topicHelpId)
        {
            HelpEntity help = new HelpEntity();

            help.TopicId = topicHelpId;

            return(PartialView("_Edit", help));
        }
Ejemplo n.º 5
0
        public void Setup()
        {
            var filename = "../../../testfiles/test_get_help.json";
            var json     = File.ReadAllText(filename);

            helpItem = JsonSerializer.Deserialize <HelpEntity>(json);
            doc      = JsonSerializer.Deserialize <List <ParameterData> >(helpItem.Parameters);
        }
Ejemplo n.º 6
0
        public ActionResult Save(HelpEntity entity)
        {
            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    if (ModelState.IsValid)
                    {
                        if (entity.Id > 0)
                        {
                            entity.Status    = GenericStatus.ACTIVE;
                            entity.FirmId    = CurrentFirm.Id;
                            entity.UpdatedBy = CurrentUserId;

                            ValidateModel(entity);

                            HelpRepository.Instance.UpdateHelp(entity);

                            Success("Ajuda atualizada com sucesso.");
                            scope.Complete();
                        }
                        else
                        {
                            entity.Status    = GenericStatus.ACTIVE;
                            entity.FirmId    = CurrentFirm.Id;
                            entity.UpdatedBy = CurrentUserId;

                            ValidateModel(entity);

                            HelpRepository.Instance.CreateHelp(entity);

                            Success("Ajuda criada com sucesso.");
                            scope.Complete();
                        }
                    }
                    else
                    {
                        Error("Alguns campos são obrigatórios para salvar a ajuda.");

                        ModelState.AddModelError("", "Ocorreu um erro ao tentar salvar a ajuda.");

                        return(PartialView("_Edit", entity));
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
                ModelState.AddModelError("", "Ocorreu um erro ao tentar salvar a ajuda.");

                return(PartialView("_Edit", entity));
            }

            ViewBag.TopicHelpId = entity.TopicId;

            return(new EmptyResult());
        }
Ejemplo n.º 7
0
        public ActionResult Remove(int topicHelpId)
        {
            HelpEntity help = HelpRepository.Instance.GetById(topicHelpId);

            help.Status = GenericStatus.INACTIVE;

            HelpRepository.Instance.UpdateHelp(help);

            return(Redirect("admin/ajuda/" + topicHelpId));
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Salva uma ajuda na base de dados
 /// </summary>
 /// <param name="newEntity"></param>
 /// <returns></returns>
 public HelpEntity CreateHelp(HelpEntity newEntity)
 {
     using (ModelContext context = new ModelContext())
     {
         newEntity.LastUpdate = DateTime.UtcNow;
         context.Helps.Attach(newEntity);
         context.Entry(newEntity).State = System.Data.Entity.EntityState.Added;
         context.SaveChanges();
     }
     return(newEntity);
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Atualiza uma ajuda
        /// </summary>
        /// <param name="updatedEntity"></param>
        /// <returns></returns>
        public HelpEntity UpdateHelp(HelpEntity updatedEntity)
        {
            using (ModelContext context = new ModelContext())
            {
                updatedEntity.LastUpdate = DateTime.UtcNow;
                context.Helps.Attach(updatedEntity);
                context.Entry(updatedEntity).State = System.Data.Entity.EntityState.Modified;
                context.SaveChanges();
            }

            return(updatedEntity);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 获得系统帮助信息;
        /// </summary>
        /// <param name="helpId">帮助id;</param>
        /// <returns></returns>
        public HelpEntity GetRichHelpItem(string helpId)
        {
            if (string.IsNullOrEmpty(helpId))
            {
                throw new ArgumentException("helpid is null");
            }
            var item = HttpRuntime.Cache.Get(HELPKEY + helpId) as HelpEntity;

            if (item == null)
            {
                item = new HelpEntity();
                string fullpath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "NG3Config" + Path.DirectorySeparatorChar + "EFormHelp.xml");

                var sql = new StringBuilder();
                sql.Append("select * from fg_helpinfo_master ")
                .Append("where helpid = \'" + helpId + "\'");

                var helpdt = new DataTable();
                helpdt = DbHelper.GetDataTable(sql.ToString());

                if (helpdt == null || helpdt.Rows.Count < 1)
                {
                    item.HelpId  = helpId;
                    item.FromSql = "0";
                    item.Sql     = string.Empty;
                    return(item);
                }
                else
                {
                    /*获得帮助表字段信息;*/
                    item.HelpId     = helpId;
                    item.Title      = GetFieldValue(helpdt, "title");
                    item.CodeField  = GetFieldValue(helpdt, "codefield");
                    item.NameField  = GetFieldValue(helpdt, "namefield");
                    item.AllField   = item.CodeField + "," + item.NameField;
                    item.HeadText   = "代码,名称";
                    item.FromSql    = "1";
                    item.TableName  = GetFieldValue(helpdt, "tablename");
                    item.Sql        = "select " + item.AllField + " from " + item.TableName;
                    item.DynamicSql = item.Sql;
                }

                HttpRuntime.Cache.Add(HELPKEY + helpId,
                                      item,
                                      new CacheDependency(fullpath),
                                      DateTime.Now.AddHours(2),
                                      Cache.NoSlidingExpiration,
                                      CacheItemPriority.NotRemovable,
                                      null);
            }

            return(item);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 获取帮助信息;
        /// </summary>
        /// <param name="helpId"></param>
        /// <returns></returns>
        public string GetHelpInfo(string helpId)
        {
            HelpEntity item = Fac.GetHelpItem(helpId);

            JObject jo = new JObject();

            jo.Add("Title", item.Title);
            jo.Add("HeadText", item.HeadText);
            jo.Add("AllField", item.AllField);
            jo.Add("codeField", item.CodeField);
            jo.Add("nameField", item.NameField);
            string str = JsonConvert.SerializeObject(jo);

            return("{status : \"ok\", data:" + str + "}");
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 验证用户输入数据的合法性;
        /// </summary>
        /// <param name="helpId"></param>
        /// <param name="inputValue"></param>
        /// <returns></returns>
        public bool ValidateData(string helpId, string inputValue)
        {
            HelpEntity    item = this.GetHelpItem(helpId);
            string        CodeFlag = "0", FieldFlag = "0";
            StringBuilder strb = new StringBuilder();

            try
            {
                strb.Append("select COUNT(*) from ");
                strb.Append(item.TableName);
                strb.Append(" where ");
                strb.Append(item.CodeField + " ={0}");
                IDataParameter[] p = new NGDataParameter[] { new NGDataParameter(item.CodeField, inputValue) };
                CodeFlag = DbHelper.GetString(strb.ToString(), p);
            }
            catch (Exception e)
            {
            }

            try
            {
                strb.Clear();
                strb.Append("select COUNT(*) from ");
                strb.Append(item.TableName);
                strb.Append(" where ");
                strb.Append(item.NameField + " ={0}");

                IDataParameter[] p = new NGDataParameter[] { new NGDataParameter(item.NameField, inputValue) };
                FieldFlag = DbHelper.GetString(strb.ToString(), p);
            }
            catch (Exception e)
            {
            }

            if (CodeFlag == "0" && FieldFlag == "0")
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 13
0
        public IDataParameter[] BuildInputQuery(string helpid, string queryValue, string outJsonQuery, string leftLikeJsonQuery, ref string query)
        {
            HelpEntity    helpitem = this.GetHelpItem(helpid);
            StringBuilder strb     = new StringBuilder();

            int  paramCount = 0;
            bool valueflg   = false;
            bool nameflg    = false;

            //无奈
            NG3.Data.Service.DbHelper.Open();
            NG3.Data.DbVendor vender = NG3.Data.Service.DbHelper.Vendor;
            NG3.Data.Service.DbHelper.Close();

            string codeLikeStr = string.Empty;
            string nameLikeStr = string.Empty;

            if (helpitem.CodeField.IndexOf(".") > 0)
            {
                codeLikeStr = " like '%" + queryValue + "%'";
            }
            else
            {
                valueflg = true;
                //codeLikeStr = " like '%'+{" + paramCount.ToString() + "}+'%'";
                codeLikeStr = " like {" + paramCount.ToString() + "}";
                paramCount++;
            }

            if (helpitem.NameField.IndexOf(".") > 0)
            {
                nameLikeStr = " like '%" + queryValue + "%'";
            }
            else
            {
                nameflg = true;
                //nameLikeStr = " like '%'+{" + paramCount + "}+'%'";
                nameLikeStr = " like {" + paramCount + "}";
                paramCount++;
            }

            //获取汉字拼音首字母函数
            string functionName = "dbo.fun_getPY";

            //if (vender == NG3.Data.DbVendor.Oracle)
            if (vender == NG3.Data.DbVendor.Oracle || vender == NG3.Data.DbVendor.MySql)
            {
                functionName = "fun_getPY";
            }

            strb.Append(" ( ");
            strb.Append(helpitem.CodeField);
            strb.Append(codeLikeStr);
            strb.Append(" or ");
            strb.Append(helpitem.NameField);
            strb.Append(nameLikeStr);
            strb.Append(" or ");
            strb.Append(functionName + "(");
            strb.Append(helpitem.NameField);
            strb.Append(") like '%");
            strb.Append(queryValue);
            strb.Append("%' )");


            List <NGDataParameter> paramList = new List <NGDataParameter>();

            if (valueflg && nameflg)
            {
                NGDataParameter[] p = new NGDataParameter[2];
                p[0] = new NGDataParameter(helpitem.CodeField, DbType.AnsiString);
                //p[0].Value = queryValue;
                p[0].Value = "%" + queryValue + "%";

                p[1] = new NGDataParameter(helpitem.NameField, DbType.AnsiString);
                //p[1].Value = queryValue;
                p[1].Value = "%" + queryValue + "%";
                paramList.Add(p[0]);
                paramList.Add(p[1]);
            }
            else if (valueflg && !nameflg)
            {
                NGDataParameter[] p = new NGDataParameter[1];
                p[0] = new NGDataParameter(helpitem.CodeField, DbType.AnsiString);
                //p[0].Value = queryValue;
                p[0].Value = "%" + queryValue + "%";
                paramList.Add(p[0]);
            }
            else if (!valueflg && nameflg)
            {
                NGDataParameter[] p = new NGDataParameter[1];
                p[0] = new NGDataParameter(helpitem.NameField, DbType.AnsiString);
                //p[0].Value = queryValue;
                p[0].Value = "%" + queryValue + "%";
                paramList.Add(p[0]);
            }


            if (!string.IsNullOrEmpty(outJsonQuery))                                                                                //通用帮助外部条件处理
            {
                Dictionary <string, object> outFilter = JsonConvert.DeserializeObject <Dictionary <string, object> >(outJsonQuery); //通用帮助
                foreach (KeyValuePair <string, object> item in outFilter)
                {
                    if (item.Value is string)
                    {
                        if (!string.IsNullOrEmpty(item.Value.ToString()))
                        {
                            strb.Append(" and ");

                            string columnName = string.Empty;
                            DbType dbtype     = DbType.AnsiString;

                            if (item.Key.ToString().EndsWith("*ngLow"))//下限
                            {
                                string[] arr = item.Key.Split('*');

                                if (arr[1] == "num")//数字字段
                                {
                                    strb.Append(arr[0] + " >= " + item.Value);
                                }
                                else//日期字段
                                {
                                    strb.Append(arr[0] + " >= '" + item.Value + "'");
                                }
                            }
                            else if (item.Key.ToString().EndsWith("*ngUP"))//上限
                            {
                                string[] arr = item.Key.Split('*');

                                if (arr[1] == "num")//数字字段
                                {
                                    strb.Append(arr[0] + " <= " + item.Value);
                                }
                                else//日期
                                {
                                    strb.Append(arr[0] + " <= '" + item.Value + "'");
                                }
                            }
                            else
                            {
                                columnName = item.Key;

                                if (columnName.IndexOf(".") > 0)
                                {
                                    strb.Append(item.Key + "='" + item.Value + "'");//带表名不参数化
                                }
                                else
                                {
                                    strb.Append(item.Key + "={" + paramCount.ToString() + "}");//外部条件用"="

                                    NGDataParameter param = new NGDataParameter(columnName, dbtype);
                                    param.Value = item.Value;
                                    paramList.Add(param);

                                    paramCount++;
                                }
                            }
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(leftLikeJsonQuery))
            {
                Dictionary <string, object> d = JsonConvert.DeserializeObject <Dictionary <string, object> >(leftLikeJsonQuery);

                foreach (KeyValuePair <string, object> item in d)
                {
                    if (item.Value is string)
                    {
                        if (!string.IsNullOrEmpty(item.Value.ToString()))
                        {
                            strb.Append(" and ");


                            string columnName = string.Empty;
                            DbType dbtype     = DbType.AnsiString;

                            columnName = item.Key;

                            if (columnName.IndexOf(".") > 0)//字段带点号,无法参数化
                            {
                                strb.Append(item.Key + " like '" + item.Value + "%'");
                            }
                            else
                            {
                                //匹配like value%
                                //strb.Append(item.Key + " like '' +{" + paramCount.ToString() + "}+ '%'");
                                strb.Append(item.Key + " like  +{" + paramCount.ToString() + "}");

                                //判断是否带表名,如果带表名,则去掉,表名不能参数化
                                string[] cols = columnName.Split('.');

                                if (cols.Length > 1)
                                {
                                    columnName = cols[1];
                                }
                                NGDataParameter p = new NGDataParameter(columnName, dbtype);
                                //p.Value = item.Value;
                                p.Value = item.Value + "%";
                                paramList.Add(p);

                                paramCount++;
                            }
                        }
                    }
                }
            }

            query = strb.ToString();
            return(paramList.ToArray());
        }
Ejemplo n.º 14
0
        /// <summary>
        /// DataTable代码转名称,动态where条件;
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="codeField"></param>
        /// <param name="helpId"></param>
        /// <param name="selectMode"></param>
        public void CodeToName(DataTable dt, string codeField, string helpId, string selectMode)
        {
            if (helpId == "")
            {
                return;
            }
            HelpEntity item = this.GetHelpItem(helpId);

            if (item.FromSql != "1")
            {
                return;
            }
            if (string.IsNullOrEmpty(item.Sql))
            {
                return;
            }
            if (item.Sql.Length < 15)
            {
                return;                       //如select , from
            }
            //project_table.phid,如果带表名则去掉表名
            string codeStr = item.CodeField;
            string nameStr = item.NameField;

            if (item.CodeField.IndexOf(".") > 0)
            {
                codeStr = item.CodeField.Substring(item.CodeField.IndexOf(".") + 1).Trim();
            }
            if (item.NameField.IndexOf(".") > 0)
            {
                nameStr = item.NameField.Substring(item.NameField.IndexOf(".") + 1).Trim();
            }

            //如果sql语句带:,说明是动态sql,动态替换很麻烦,暂时截断sql到表名
            var sqlStr = item.Sql;

            if (item.Sql.IndexOf(":") > 0)
            {
                sqlStr = item.DynamicSql;
            }

            DataTable helpdt = DbHelper.GetDataTable(sqlStr);

            if (helpdt == null || helpdt.Rows.Count == 0)
            {
                return;
            }

            foreach (DataRow dr in dt.Rows)
            {
                string codeValue = (dr[codeField] == null || dr[codeField] == DBNull.Value) ? string.Empty : dr[codeField].ToString();

                if (!string.IsNullOrWhiteSpace(codeValue))
                {
                    if (SelectMode.Multi.ToString().ToUpper() == selectMode.ToUpper())  //自定义复选帮助
                    {
                        DataRow[] helpdrs = helpdt.Select(codeStr + " in (" + codeValue + ")");

                        if (helpdrs.Length > 0)
                        {
                            StringBuilder buildstr = new StringBuilder();
                            int           count    = helpdrs.Length - 1;

                            for (int i = 0; i < helpdrs.Length; i++)
                            {
                                buildstr.Append(helpdrs[i][nameStr]);

                                if (i < count)
                                {
                                    buildstr.Append(",");
                                }
                            }

                            dr[codeField] = buildstr.ToString();  //代码转成名称;
                        }
                    }
                    else
                    {
                        DataRow[] helpdrs = helpdt.Select(codeStr + " = '" + codeValue + "'");

                        if (helpdrs.Length > 0)
                        {
                            dr[codeField] = helpdrs[0][nameStr];  //代码转成名称;
                        }
                    }
                }
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 获得通用帮助信息;
        /// </summary>
        /// <param name="helpId">帮助id;</param>
        /// <returns></returns>
        public HelpEntity GetCustomFormHelpItem(string helpId)
        {
            if (string.IsNullOrEmpty(helpId))
            {
                throw new ArgumentException("helpid is null");
            }
            var item = HttpRuntime.Cache.Get(HELPKEY + helpId) as HelpEntity;

            if (item == null)
            {
                item = new HelpEntity();
                string fullpath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "NG3Config" + Path.DirectorySeparatorChar + "EFormHelp.xml");

                var sql = new StringBuilder();
                sql.Append("select * from p_form_base ").Append("where phid = \'" + helpId + "\'");

                var helpdt = new DataTable();
                helpdt = DbHelper.GetDataTable(sql.ToString());

                if (helpdt == null || helpdt.Rows.Count < 1)
                {
                    item.HelpId  = helpId;
                    item.FromSql = "0";
                    item.Sql     = string.Empty;
                    return(item);
                }
                else
                {
                    /*获得帮助表字段信息;*/
                    item.HelpId  = helpId;
                    item.Title   = GetFieldValue(helpdt, "base_name");
                    item.FromSql = GetFieldValue(helpdt, "fromsql");

                    //帮助数据来自sql
                    if (item.FromSql == "1")
                    {
                        item.CodeField = GetFieldValue(helpdt, "col_data");
                        item.NoField   = GetFieldValue(helpdt, "col_filter");
                        item.NameField = GetFieldValue(helpdt, "col_view");
                        item.AllField  = item.NoField + "," + item.NameField + "," + item.CodeField;
                        item.HeadText  = GetFieldValue(helpdt, "filtertitle") + "," + GetFieldValue(helpdt, "viewtitle");

                        item.Sql        = GetFieldValue(helpdt, "sql_str");
                        item.DynamicSql = item.Sql;

                        //获取表名和转换动态sql
                        if (!string.IsNullOrEmpty(item.Sql))
                        {
                            int spacePos;
                            do
                            {
                                item.Sql = item.Sql.Replace("  ", " ");
                                spacePos = item.Sql.IndexOf("  ");
                            } while (spacePos != (-1));

                            int fromPos = item.Sql.IndexOf("from", StringComparison.OrdinalIgnoreCase);
                            int onePos  = item.Sql.IndexOf(" ", fromPos + 4);
                            int twoPos  = item.Sql.IndexOf(" ", onePos + 1);

                            if (twoPos == (-1))
                            {
                                item.TableName = item.Sql.Substring(fromPos + 4).Trim();
                            }
                            else
                            {
                                item.TableName = item.Sql.Substring(onePos, twoPos - onePos).Trim();
                            }

                            //带:动态sql转换
                            if (item.Sql.IndexOf(":") > 0)
                            {
                                //得到sql中:和空格之间的串
                                string          start      = @"\:";
                                string          end        = @"\ ";
                                Regex           rg         = new Regex("(?<=(" + start + "))[.\\s\\S]*?(?=(" + end + "))", RegexOptions.Multiline | RegexOptions.Singleline);
                                MatchCollection macths     = rg.Matches(item.DynamicSql + " ");
                                int             bracketPos = 0;
                                string          tempValue  = string.Empty;

                                if (macths.Count > 0)
                                {
                                    for (int i = 0; i < macths.Count; i++)
                                    {
                                        tempValue = macths[i].Value;

                                        //去掉可能存在的小括号符
                                        do
                                        {
                                            tempValue  = tempValue.Replace(")", "");
                                            bracketPos = tempValue.IndexOf(")");
                                        } while (bracketPos != (-1));

                                        item.DynamicSql = item.DynamicSql.Replace(":" + tempValue.Trim(), " null or 1=1 ");
                                    }
                                }
                            }
                        }
                    }
                    else  //帮助数据是手工录入的,不来自sql
                    {
                        item.CodeField = "phid";
                        item.NoField   = "base_code";
                        item.NameField = "base_name";
                        item.AllField  = item.NoField + "," + item.NameField + "," + item.CodeField;
                        item.HeadText  = "代码,名称";
                    }
                }

                HttpRuntime.Cache.Add(HELPKEY + helpId,
                                      item,
                                      new CacheDependency(fullpath),
                                      DateTime.Now.AddHours(2),
                                      Cache.NoSlidingExpiration,
                                      CacheItemPriority.NotRemovable,
                                      null);
            }

            return(item);
        }
Ejemplo n.º 16
0
        public ActionResult Edit(int helpId)
        {
            HelpEntity help = HelpRepository.Instance.GetById(helpId);

            return(PartialView("_Edit", help));
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 转换某一个code的代码转名称,支持多选帮助列;
        /// </summary>
        /// <param name="helpId"></param>
        /// <param name="codeValue"></param>
        /// <param name="selectMode"></param>
        /// <returns></returns>
        public string GetName(string helpId, string codeValue, string selectMode)
        {
            string result = string.Empty;

            if (helpId == "")
            {
                return(string.Empty);
            }
            HelpEntity item = this.GetHelpItem(helpId);

            if (item.FromSql != "1")
            {
                return(string.Empty);
            }

            //project_table.phid,如果带表名则去掉表名
            string codeStr = item.CodeField;
            string nameStr = item.NameField;

            if (item.CodeField.IndexOf(".") > 0)
            {
                codeStr = item.CodeField.Substring(item.CodeField.IndexOf(".") + 1).Trim();
            }
            if (item.NameField.IndexOf(".") > 0)
            {
                nameStr = item.NameField.Substring(item.NameField.IndexOf(".") + 1).Trim();
            }

            //如果sql语句带:,说明是动态sql,动态替换很麻烦,暂时截断sql到表名
            var sqlStr = item.Sql;

            if (item.Sql.IndexOf(":") > 0)
            {
                sqlStr = item.DynamicSql;
            }

            DataTable helpdt = DbHelper.GetDataTable(sqlStr);

            if (helpdt == null || helpdt.Rows.Count == 0)
            {
                return(string.Empty);
            }

            if (SelectMode.Multi.ToString().ToUpper() == selectMode.ToUpper())  //自定义复选帮助
            {
                DataRow[] helpdrs = helpdt.Select(codeStr + " in (" + codeValue + ")");

                if (helpdrs.Length > 0)
                {
                    StringBuilder buildstr = new StringBuilder();
                    int           count    = helpdrs.Length - 1;

                    for (int i = 0; i < helpdrs.Length; i++)
                    {
                        buildstr.Append(helpdrs[i][nameStr]);
                        if (i < count)
                        {
                            buildstr.Append(",");
                        }
                    }

                    result = buildstr.ToString();  //代码转成名称;
                }
            }
            else
            {
                DataRow[] helpdrs = helpdt.Select(codeStr + " = '" + codeValue + "'");

                if (helpdrs.Length > 0)
                {
                    result = helpdrs[0][nameStr].ToString();  //代码转成名称;
                }
            }

            return(result);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 获得help数据列表;
        /// </summary>
        /// <param name="helpId">帮助id;</param>
        /// <param name="pageSize">分页大小;</param>
        /// <param name="pageIndex">页码;</param>
        /// <param name="totalRecord">总记录长度;</param>
        /// <param name="clientFilter">过滤条件;</param>
        /// <returns></returns>
        public DataTable GetHelpList(string helpId, int pageSize, int pageIndex, ref int totalRecord, string clientFilter, bool isAutoComplete, string outJsonQuery)
        {
            HelpEntity item = GetHelpItem(helpId);
            DataTable  dt   = null;

            /*如果没有sql则返回;*/
            if (item.FromSql == "1")
            {
                string sortField = string.Empty;
                string sql       = item.Sql;

                //填充“:参数”
                if (sql.IndexOf(":") > 0)
                {
                    if (!string.IsNullOrEmpty(outJsonQuery))
                    {
                        JObject jo = JObject.Parse(outJsonQuery.ToString());

                        foreach (var it in jo)
                        {
                            if (string.IsNullOrWhiteSpace(it.Value.ToString()))
                            {
                                sql = sql.Replace(":" + it.Key.ToString(), "''");
                            }
                            else
                            {
                                sql = sql.Replace(":" + it.Key.ToString(), it.Value.ToString());
                            }
                        }
                    }
                }

                int n = sql.ToUpper().IndexOf("ORDER BY", StringComparison.OrdinalIgnoreCase);
                if (n > 0)
                {
                    sortField = sql.Substring(n);
                    sql       = sql.Substring(0, n - 1);
                }
                else
                {
                    sortField = item.CodeField + " asc";
                }

                if (!string.IsNullOrEmpty(clientFilter))
                {
                    IDataParameter[] p;
                    string           joinStr = string.Empty;

                    //sql中有无where
                    if (sql.IndexOf("where", StringComparison.OrdinalIgnoreCase) > 0)
                    {
                        joinStr = " and ";
                    }
                    else
                    {
                        joinStr = " where ";
                    }

                    if (isAutoComplete)
                    {
                        string query = string.Empty;
                        p = BuildInputQuery(helpId, clientFilter, string.Empty, string.Empty, ref query);

                        if (!string.IsNullOrEmpty(query))
                        {
                            sql += joinStr + query;
                        }
                    }
                    else
                    {
                        string query = string.Empty;
                        p = DataConverterHelper.BuildQueryWithParam(clientFilter, string.Empty, ref query);

                        if (!string.IsNullOrEmpty(query))
                        {
                            sql += joinStr + query;
                        }
                    }

                    string sqlstr = PaginationAdapter.GetPageDataSql(sql, pageSize, ref pageIndex, ref totalRecord, sortField, p);
                    dt = DbHelper.GetDataTable(sqlstr, p);
                }
                else
                {
                    string sqlstr = PaginationAdapter.GetPageDataSql(sql, pageSize, ref pageIndex, ref totalRecord, sortField);
                    dt = DbHelper.GetDataTable(sqlstr);
                }
            }
            else
            {
                dt = Common.GetHelpInfo(item.HelpId);
            }

            return(dt);
        }