This feature is used to generate custom code in business process such as product code, warehouse code, user code and so on.
For example
Airwaybill code:9991323457,999-5555555
Produce code:X807035-002
SKU code:LR332, 350145
Inventory Order Code:200902040032

In Database
there is a table called tbl_Code. All the code data is saved in this table.
Script
CREATE TABLE [dbo].[tbl_Code](
[CodeName] [varchar](5) COLLATE Chinese_PRC_CI_AS NOT NULL,
[CurrentNo] [int] NOT NULL CONSTRAINT [DF_tbl_Code_CurrentNo] DEFAULT ((0)),
[LastCode] [varchar](30) COLLATE Chinese_PRC_CI_AS NULL,
CONSTRAINT [PK_tbl_Code] PRIMARY KEY CLUSTERED
(
[CodeName] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

How to implement a new code
To implement a new code, you must implement ICode interface or inherit from CodeBase class.
Here is a example:
public class DateSNCode:CodeBase
{
public DateSNCode():base("SN")
{

}

public override string Format
{
get
{
return "SN{0:yyyyMMdd}{1:000}";
}
}

public override string CalculateNextCode(int currentNo)
{
return string.Format(this.Format,DateTime.Now,currentNo);
}
}

In web.config
<!-- unity section for CodeGenerator -->
<unity>
<typeAliases>
<typeAlias alias="Singleton"
type="Microsoft.Practices.Unity.ContainerControlledLifetimeManager,Microsoft.Practices.Unity"/>
<!--CodeManager Configuration-->
*
<typeAlias alias="ICode" type="Dragon.Prototype1.Infrastructure.CodeGenerator.ICode,Dragon.Prototype1.Infrastructure"/>
<typeAlias alias="DateSNCode" type="Dragon.Prototype1.Infrastructure.CodeGenerator.DateSNCode,Dragon.Prototype1.Infrastructure"/>
*
<!--CodeManager Configuration end-->
</typeAliases>
<containers>
<container>
<types>
<!--CodeManager Configuration-->
*<type name="DateSN" type="ICode" mapTo="DateSNCode">
<lifetime type="Singleton" />
</type>*
<!--CodeManager Configuration end-->
</types>
</container>
</containers>
</unity>
<!-- unity section for CodeGenerator end-->

In Code
ICode mycode = CodeManager.CreateInstance("DateSN");
string newCode=mycode.GetNextCode();

Last edited Nov 8, 2009 at 4:27 AM by tonyqus, version 2

Comments

No comments yet.