将枚举定义生成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 ...
随机推荐
- NO.2
虚拟语气的终结版.英语语法的终结时刻.迎接新的英语挑战!!!
- uniq,sort,
语 法:uniq [-cdu][-f<栏位>][-s<字符位置>][-w<字符位置>][--help][--version][输入文件][输出文件] 补充说明: ...
- js 更改head的title
使用document.title = "hello"; 不能使用 $("title").text("dd");或者 $ ...
- Mycat配置文件rule.xml
打开<MyCAT_HOME>/conf/rule.xml,对应的分片配置截取内容如下: <tableRule name="auto-sharding-rang-mod&qu ...
- kindeditor编辑器的使用
KindEditor是一款用Javascript编写的开源在线HTML编辑器,主要用户是让用户在网站上获得可见即可得的编辑效果,开发人员可以用 KindEditor 把传统的多行文本输入框(texta ...
- VC++绘图时,利用双缓冲解决屏幕闪烁 转载
最近做中国象棋,绘制界面时遇到些问题,绘图过程中屏幕闪烁,估计都会想到利用双缓冲来解决问题,但查了下网上双缓冲的资料,发现基本是MFC的,转化为VC++后,大概代码如下: void DrawBmp(H ...
- Android四大组件之——Activity的生命周期(图文详解)
转载请在文章开头处注明本博客网址:http://www.cnblogs.com/JohnTsai 联系方式:JohnTsai.Work@gmail.com [Andro ...
- oracle中rownum和rowid的区别
rownum和rowid的区别总括: rownum和rowid都是伪列,但是两者的根本是不同的. rownum是根据sql查询出的结果给每行分配一个逻辑编号,所以你的sql不同也就会导致最终rownu ...
- constraint更新表列约束默认值
--更新约束 alter TABLE [dbo].[Sk_Recruit] drop constraint DF_Sk_Recruit_lastcommenttime go alter TABLE ...
- golang--gopher北京大会(2)(rework)
三.七牛老许 qlang: github qiniu/qlang microservice architecture: http://martinfowler.com/articles/microse ...