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
这个每添加完一条记录时最后一位都自动加一
查看全文
相关阅读:
大道至简 第一章 读后随笔
大道至简 第二章 读后随笔
动手动脑及实验性练习总结
大道至简 第三章 阅读心得
课程作业01 相加运算
JS函数与BOM
设备像素,设备独立像素,CSS像素
斐波那契数列
JS基础与循环
吴requests类库 作业总结
原文地址:https://www.cnblogs.com/xiaotuni/p/2365766.html
最新文章
excel画数据分析图
从移动硬盘启动电脑与重装注意事项
XP与Windows 7(Win7)等操作系统Ghost备份
电脑Win7与Android(安卓)手机之间的共享
2012年10月显卡性能天梯图
机械键盘小知识
Window7文件共享之法
2013年1月CPU性能天梯图
word文档字体显示不正常或没有想要的字体
JAVA Web 实现会话跟踪的技术笔记
热门文章
Spring AOP 四大通知
(爱加密系列教程七)程序员应该学习的签名破解
(爱加密系列教程九)APK广告嵌入大揭秘
(爱加密系列教程八)Android APP如何防止二次打包
(爱加密系列教程五) APK反编译去广告大揭秘
(爱加密系列教程三) android反编译 学习如何隐藏应用图标
(爱加密系列教程六)Android代码注入大揭秘
(爱加密系列教程二) apk反编译生成程序的源代码和图片、XML配置、语言资源等文件
(爱加密系列教程一) Android Apk反编译得到Java源代码
(爱加密系列教程四) 破解APK注入代码大揭秘
Copyright © 2011-2022 走看看