zoukankan      html  css  js  c++  java
  • 将枚举定义生成SQL中的Case-When-then语句

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Text.RegularExpressions;
    
    namespace TestPro
    {
        public partial class CaseWhenSqlGeneration : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            protected void btnOk_Click(object sender, EventArgs e)
            {
                string enumString = this.txtEnum.Text.Trim().Replace("
    ","");
                bool useMark = this.chkUseMark.Enabled;
                string result = string.Empty;
                List<EnumInfo> enumInfos = new List<EnumInfo>();
    
                string regString = "(?:(?:\s*///\s*<summary>)\s*///\s*(?<mark>[\S]*?)(?:\s*///\s*</summary>))*\s*((?<key>[\S]+)\s*=\s*(?<value>[\d]+))";
                Regex regex = new Regex(regString, RegexOptions.None);
    
                MatchCollection matchs = regex.Matches(enumString);
                foreach (Match match in matchs)
                {
                    enumInfos.Add(new EnumInfo
                    {
                        Mark = match.Groups["mark"].Value,
                        Key = match.Groups["key"].Value,
                        Value = match.Groups["value"].Value
                    });
                }
    
                foreach (var item in enumInfos)
                {
                    if (this.chkUseMark.Checked)
                    {
                        result += string.Format("
     when {0} then '{1}' ", item.Value, string.IsNullOrEmpty(item.Mark) ? item.Key : item.Mark);
                    }
                    else
                    {
                        result += string.Format("
     when {0} then '{1}' ", item.Value, item.Key);
                    }
                }
    
                if (enumInfos != null) { result += "
     else '未知枚举' end"; }
                this.txtResult.Text = result;
            }
        }
    
        public class EnumInfo
        {
            public string Mark { get; set; }
            public string Key { get; set; }
            public string Value { get; set; }
        }
    }
  • 相关阅读:
    贝叶斯分类
    K-Means算法
    python数组
    深度学习与神经网络
    数据挖掘算法之-关联规则挖掘(Association Rule)
    k8s记录-pip源配置
    k8s记录-yum本地仓库部署
    k8s记录-不同集群服务互联
    k8s记录-kube-dns(core-dns)配置(七)
    k8s记录-kubectl常用
  • 原文地址:https://www.cnblogs.com/huangzelin/p/4495368.html
Copyright © 2011-2022 走看看