如何在c#中生成包含字母和数字的产品ID

时间:2018-02-14 10:41:33

标签: c# mysql

如何在c#中创建一行代码,用于为我添加到产品表中的每个新产品?我使用的是MySQL数据库。  这是我到目前为止所尝试的,虽然这不是我真正需要的。

//auto product number
static string IncrementID(string startValue, int numNonDigits)
{
    string nonDigits = startValue.Substring(0, numNonDigits);
    int len = startValue.Length - numNonDigits;
    int number = int.Parse(startValue.Substring(numNonDigits));
    number++;
    if (number >= Math.Pow(10, len)) number = 1; // start again at 1
    return String.Format("{0}{1:D" + len.ToString() + "}", nonDigits, number);
}
private void Genarate_productcode()
{
    product_code.Text = IncrementID("QIEpl/PO/0000009", 9); // produces QIEpl/PO/0000010 // C00011 PCI0001
}  

0 个答案:

没有答案