流水编号规则功能
因为在Epicor二次开发中使用流水编号时,总感觉非常繁琐,所以就想到开发一个功能用于获取流水编号。
功能要求
- 可设定前缀字符串
- 可设定流水号长度
- 可设定下一编号
字段使用
字段(UD05表) | 字段描述 | 初始默认值 |
---|---|---|
Key1 | 编号规则代码 | |
Key2 | 数据类型 | NumberingRule |
ShortChar01 | 规则名称 | |
Character01 | 规则描述 | |
ShortChar02 | 格式化代码 | |
ShortChar03 | 规则分类 | |
Number01 | 下一编号 | 1 |
界面设计
取号代码
public static string GetNewCode(EpiTransaction otrans, string ruleCode) {
if (string.IsNullOrEmpty(ruleCode)) throw new Exception("获取'"+ ruleCode + "'编号失败!");
string code = "";
AdpUDBase ud05 = new AdpUDBase(otrans, "UD05");
try
{
bool bl = ud05.GetByID(ruleCode, "NumberingRule", "", "", "");
if (bl)
{
string formatCode = Convert.ToString(ud05.GetValue("UD05", "ShortChar02"));
int nextNum = Convert.ToInt32(ud05.GetValue("UD05", "Number01"));
if (string.IsNullOrEmpty(formatCode)) code = nextNum.ToString();
else
{
string qz = formatCode.TrimEnd('0');
int length = formatCode.Length - qz.Length;
code = qz + nextNum.ToString().PadLeft(length, '0');
}
ud05.UpdateValue("UD05", "Number01", nextNum + 1);
}else throw new Exception("获取'"+ ruleCode + "'编号失败!");
}
catch(Exception e1)
{
throw new Exception("获取'" + ruleCode + "'编号失败!"+e1.Message);
}
finally
{
ud05.Dispose();
}
return code;
}
上面代码中用的AdpUDBase类请查看Epicor10中Adapter使用封装