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
这个每添加完一条记录时最后一位都自动加一
查看全文
相关阅读:
人生苦短,我用python!
Pycharm快捷键
查看java进程
带你掌握Arthas
高并发场景下System.currentTimeMillis()的性能问题的优化
SpringBoot整合Dubbo&ZooKeeper
CentOS7下yum安装Mysql5.7
SpringCache整合Redis实现自定义缓存时间
Java开发神器lombok
CentOS7安装Nginx
原文地址:https://www.cnblogs.com/xiaotuni/p/2365766.html
最新文章
一天一次面试题之java基础
搬家
.net面试基础(转)
Redis连接字符串
vs2013 更新最新的NuGet
nginx 分布式的使用
redis 安装 使用 以及遇到的问题
asp.net 注册到IIS
Ajax.BeginForm使用时注意的细节
sql语句
热门文章
[ Windwos的日常 ] Windows路上的石子
[ Linux的日常 ] Linux路上的石子
[ 前端框架/Vue ] Vue大杂烩
[文章] 小本本记下来--CC
[ 那些让人发笑的句子 ] 那些让人发笑的句子
[ JS/NodeJS ] 我是真不会记学习笔记
[ HTML/CSS ] 我是真不会记学习笔记
[ Windows/VSCode ] VSCode 配置 C/C++环境、编译 C/C++
[ Windows ] Windows路上的石子
[Linux的日常] Linux路上的石子
Copyright © 2011-2022 走看看