zoukankan
html css js c++ java
生成像这样得编号 XX2007032100001
/**/
///
<summary>
///
最后一个编号 XX200703060001
///
</summary>
///
<param name="fieldName">
字段ID号
</param>
///
<param name="tableName">
表得名字
</param>
///
<returns></returns>
public
static
object
GetLastCode(
string
fieldName,
string
tableName,
int
autoBuildCodeLength)
...
{
string
executeString
=
"
SELECT
"
+
fieldName
+
"
FROM
"
+
tableName
+
"
WHERE LEN(
"
+
fieldName
+
"
) =
"
+
autoBuildCodeLength
+
"
ORDER BY ID DESC
"
;
return
Common.GetDatabase().GetFirstData(executeString, CommandType.Text);
}
/**/
///
<summary>
///
第一位为0
///
</summary>
private
static
int
_autoBuildCount
=
0
;
/**/
///
<summary>
///
自动生成编号 如 "XXXX" + 2007030600001 这样的
///
"XXXX" 传来的
///
</summary>
///
<param name="codeFormat">
编号得格式
</param>
///
<param name="fieldName">
字段ID号
</param>
///
<param name="tableName">
表得名字
</param>
///
<param name="autoBuildCodeLength">
自动生成编号得长度
</param>
///
<returns></returns>
public
static
string
GetAutomatismBuildCode(
string
codeFormat,
string
fieldName,
string
tableName,
int
autoBuildCodeLength)
...
{
string
yearMonthDay1
=
""
;
string
yearMonthDay2
=
codeFormat
+
DateTime.Now.Year.ToString()
+
NumberIsLessThan10(DateTime.Now.Month)
+
NumberIsLessThan10(DateTime.Now.Day);
object
autoBuildCode;
string
AutomatismNumber
=
""
;
autoBuildCode
=
GetLastCode(fieldName, tableName, autoBuildCodeLength);
if
(autoBuildCode
==
null
)
...
{
_autoBuildCount
=
1
;
}
else
...
{
yearMonthDay1
=
autoBuildCode.ToString().Substring(
0
, autoBuildCodeLength
-
5
);
if
(yearMonthDay2
==
yearMonthDay1)
...
{
_autoBuildCount
=
int
.Parse(autoBuildCode.ToString().Substring(autoBuildCodeLength
-
5
,
5
));
}
++
_autoBuildCount;
}
AutomatismNumber
=
yearMonthDay2
+
_autoBuildCount.ToString(
"
00000
"
);
_autoBuildCount
=
0
;
return
AutomatismNumber;
}
/**/
///
<summary>
///
判断月日是一位还是两位数
///
</summary>
///
<param name="aa"></param>
///
<returns></returns>
private
static
string
NumberIsLessThan10(
int
monthOrDay)
...
{
if
(monthOrDay
<
10
)
...
{
return
"
0
"
+
monthOrDay.ToString();
}
return
monthOrDay.ToString();
}
XX2007032100001
这个每添加完一条记录时最后一位都自动加一
查看全文
相关阅读:
火眼金睛算法,教你海量短文本场景下去重
CynosDB技术详解——架构设计
CynosDB技术详解——存储集群管理
解决 "Script Error" 的另类思路
Go 语言实践(一)
Vue.js的复用组件开发流程
MYSQL中的COLLATE是什么?
Blending
AlphaTesting
Culling & Depth Testing
原文地址:https://www.cnblogs.com/xiaotuni/p/2365766.html
最新文章
git的本质是资源库和版本(资源)目录的维护过程
创建Maven项目时,GroupId和Artifact Id该怎么填写呢?
理论与原理
主观与客观
建模理论--有序的结构是否可以通过有限的基础组件来建模
人类的认知过程是对目标事物的建模过程
git账户配置
laravel 中first和find区别(总结一)
laravel中跟据某个特定顺序去排序查出来的数据:FIND_IN_SET
Laravel find in set排序
热门文章
laravel的ORM模型的find(),findOrFail(),first(),firstOrFail(),get(),list(),toArray()之间的区别
Laravel5.2中Eloquent与DB类的区别是什么?
Laravel 中如何区别 Model 或者是 Builder?
laravel查询构造器DB还是ORM,这两者有什么区别,各该用在什么场景中
HTTP请求错误400、401、402、403、404、405、406、407、412、414、500、501、502解析
excel怎么只打印某页?excel怎么只打印某几页
excel中如何设置只打印第一页
详谈js防抖和节流
web模拟终端博客系统
为什么CynosDB叫真正的云原生数据库?
Copyright © 2011-2022 走看看