将枚举定义生成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("\r\n","");
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("\r\n when {0} then '{1}' ", item.Value, string.IsNullOrEmpty(item.Mark) ? item.Key : item.Mark);
}
else
{
result += string.Format("\r\n when {0} then '{1}' ", item.Value, item.Key);
}
} if (enumInfos != null) { result += "\r\n else '未知枚举' end"; }
this.txtResult.Text = result;
}
} public class EnumInfo
{
public string Mark { get; set; }
public string Key { get; set; }
public string Value { get; set; }
}
}
将枚举定义生成SQL中的Case-When-then语句的更多相关文章
- 转载:SQL中的case when then else end用法
SQL中的case when then else end用法 来源: http://www.cnblogs.com/prefect/p/5746624.html Case具有两种格式.简单Case函数 ...
- sql中对于case when...then...else...end的写法和理解
查询配件主数据表(tbl_part_base_info)的所有数据和配件是否有物料(物料表(tbl_material)中有配件主数据表的part_no,就表示有物料,反之,则表示没有物料),用sql中 ...
- sql中的case when
sql语言中有没有类似C语言中的switch case的语句?? 没有,用case when 来代替就行了. 例如,下面的语句显示中文年月 select ...
- 转-sql中的case when的用法
Case具有两种格式.简单Case函数和Case搜索函数. --简单Case函数 CASE sex WHEN '1' THEN '男' WHEN '2' THEN '女' ELSE '其他' END ...
- SQL中的case when then else end用法
--简单Case函数 CASE sex WHEN '1' THEN '男' WHEN '2' THEN '女' ELSE '其他' END --Case搜索函数 CASE WHEN sex = '1' ...
- sql中的case when then else end
hive中的case when的用法举例 select * from (select id, count(distinct ] in ("Virus","Worm&quo ...
- [转]SQL中的case when then else end用法
Case具有两种格式.简单Case函数和Case搜索函数. --简单Case函数 CASE sex WHEN '1' THEN '男' WHEN '2' THEN '女' ELSE '其他' EN ...
- SQL中的CASE的用法
CASE在SQL语句中,很有点类似java等高级编程语言中的switch这样子的多分枝语句,但是有点不同的是,case后面接的是when,另外,when的后续分枝有点类似if后面接else.这个是我的 ...
- SQL中的CASE WHEN用法
其语法如下: 1)case vlaue when [compare-value]then reslut [when[compare-value]] then result ...] [else res ...
随机推荐
- Backbone笔记(续)
Backbone Bockbone 总览 Backbone 与 MVC 模式:解决某一类问题的通用方案 - 套路 MVC:一种架构模式,解耦代码,分离关注点 M(Model) - 数据模型 V(Vie ...
- java的InputStream和OutputStream的理解【转】
1.在java中stream代表一种数据流(源),javaio的底层数据元,---(想像成水龙头)2.任何有能力产生数据流(源)的javaio对象就可以看作是一个InputStream对象既然它能产生 ...
- CentOS网络配置详解
转载于CentOS中文站:http://www.centoscn.com/CentOS/2015/0507/5376.html一.配置文件详解 在RHEL或者CentOS等Redhat系的Linux系 ...
- 使用CocoaPods配置工程
1.首先搭建环境,配置CocoaPods,具体请参考 http://code4app.com/article/cocoapods-install-usage 2.打开终端,输入 cd 空格 把工程拖入 ...
- 117 FP页面无法查看
用户表示117 FP页面无法查看,提示如下错误: 跟进: 1.进入FP服务器可看到以下错误 这个错误的框就表示FP的一个进程报错,自动断掉了,需要重新跑一次EXIT,INIT,PLAN,EXPORT, ...
- 使用sessionStorage、localStorage存储数组与对象(转)
http://my.oschina.net/crazymus/blog/371757 使用sessionStorage.localStorage存储数组与对象 发表于3个月前(2015-01-26 1 ...
- Python-类的概念及使用1
1.类:用来描述具有相同的属性和方法的对象的集合.它定义了该集合中每个对象所共有的属性和方法.对象是类的实例. #!/usr/bin/python # -*- coding: UTF-8 -*- cl ...
- push
1:收到通知的那一刻,app的状态可能是未启动,前台以及后台 如果未启动,等待点击app的时候进行界面跳转的时候接收到通知(didFinishLaunchngWithOPtions) 如果是前台以及后 ...
- linux--杂记(rework)
1.The mind behind Linux https://www.ted.com/talks/linus_torvalds_the_mind_behind_linux 2.Emacs ORG-M ...
- Java 基础知识总结 (一、标识符)
一.Identifiers: 标识符 Names of class,method and variable 用于类名.方法名.变量名 Begin with character,'_' or '$' 标 ...