新增记录时自动生成记录的序号号码(或单据号码)并填充文本框
新增记录时自动生成记录的序号号码(或单据号码)并填充文本框
扫一扫加微信
1. 在点击【新增】后调用函数自动计算出文档编号并填充到对应的文本框,如何实现?
重写DoAdd方法,首先获取号码,然后给文本框赋值。
2. 【新增】后代码哪里触发这个函数或方法?
【新增】按钮事件:DoAdd方法
代码参考:
C# Code:
public override void DoAdd(IButtonInfo sender)
{
base.DoAdd(sender);
if (this._UpdateType == UpdateType.Add)
{
string SN = CommonData.GetDataSN("XX", true);//如:XX00000001
string DN = CommonData.GetDocNo("XX");//如:XX202000000002
//给界面的组件赋值
SetEditorBindingValue(txtRowID, SN, true);
//或者给数据源对于的字段赋值,都可以!
//_BLLInstance.DataBinderRow["RowID"] = SN;
//SetEditorBindingValue(txtRowID, DN, true);
//SetEditorBindingValue(txtRowID, "*自动生成*", true);
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
{
base.DoAdd(sender);
if (this._UpdateType == UpdateType.Add)
{
string SN = CommonData.GetDataSN("XX", true);//如:XX00000001
string DN = CommonData.GetDocNo("XX");//如:XX202000000002
//给界面的组件赋值
SetEditorBindingValue(txtRowID, SN, true);
//或者给数据源对于的字段赋值,都可以!
//_BLLInstance.DataBinderRow["RowID"] = SN;
//SetEditorBindingValue(txtRowID, DN, true);
//SetEditorBindingValue(txtRowID, "*自动生成*", true);
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
DocNoTool.cs文件,DocNoTool类提供2个公共静态方法:
GetDataSN方法:用于生成带有前缀的序号,比如:XX000000001
C# Code:
/// <summary>
/// 生成流水号,格式:XX00000001
/// </summary>
/// <param name="conn">SQL连接</param>
/// <param name="dataCode">字头</param>
/// <param name="asHeader">当号码表没有该字头的定义,自动初始化一条序号为1的记录</param>
/// <returns></returns>
public static string GetDataSN(DbConnection conn, string dataCode, bool asHeader)
{
string SQL = "sp_sys_GetDataSN '" + dataCode + "','" + (asHeader ? "Y" : "N") + "'";
DbCommand cmd = DocNoTool.CreateSpCommand(conn);
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = SQL;
object no = cmd.ExecuteScalar();
return ConvertEx.ToString(no);
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
/// <summary>
/// 生成流水号,格式:XX00000001
/// </summary>
/// <param name="conn">SQL连接</param>
/// <param name="dataCode">字头</param>
/// <param name="asHeader">当号码表没有该字头的定义,自动初始化一条序号为1的记录</param>
/// <returns></returns>
public static string GetDataSN(DbConnection conn, string dataCode, bool asHeader)
{
string SQL = "sp_sys_GetDataSN '" + dataCode + "','" + (asHeader ? "Y" : "N") + "'";
DbCommand cmd = DocNoTool.CreateSpCommand(conn);
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = SQL;
object no = cmd.ExecuteScalar();
return ConvertEx.ToString(no);
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
GetDocNo方法:用于生成带有前缀以及日期格式的序号,比如:XX20201111000001
C# Code:
/// <summary>
/// 获取单据的流水号码
/// </summary>
/// <param name="conn">当前SQL连接</param>
/// <param name="DocNoName">单据名称,前缀,如:SO, AR,AP</param>
/// <returns></returns>
public static string GetDocNo(DbConnection conn, string DocNoName)
{
DbCommand cmd = DocNoTool.CreateSpCommand(conn);
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "sp_sys_GetDocNo '" + DocNoName + "'";
object no = cmd.ExecuteScalar();
return ConvertEx.ToString(no);
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
/// 获取单据的流水号码
/// </summary>
/// <param name="conn">当前SQL连接</param>
/// <param name="DocNoName">单据名称,前缀,如:SO, AR,AP</param>
/// <returns></returns>
public static string GetDocNo(DbConnection conn, string DocNoName)
{
DbCommand cmd = DocNoTool.CreateSpCommand(conn);
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "sp_sys_GetDocNo '" + DocNoName + "'";
object no = cmd.ExecuteScalar();
return ConvertEx.ToString(no);
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
扫一扫加微信
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网