首页 > 解决方案 > 检查文本框输入自动增加数量由输入总记录确定

问题描述

两个文本框用于检查输入结果以确定需要生成多少条记录。

第一个 用于自动递增编号的文本框:用户可能会输入“000000”“001000” 如果用户输入“ 090000 ”或“ 123456 ”,这部分会很棘手,请参阅代码变量getSequance。

用于检查总记录的第二个文本框需要生成参考代码变量 getrecords 。

我尝试自动增加最后一位数字:

private void input_autoincrement()
{
     string getrecords = "10";     // first textbox:records generate
     string getSequance = "000000"; //second textbox:auto increment number

     for( int ix = 0; ix < Convert.ToInt32(getrecords); ix++)
     {
         string autoincrno = ix.ToString().PadLeft(1,'0');  // if autoincrno default value is "123456" how to make it change here?
     }
}

我有一个问题,如果 autoincrno 具有默认值,例如“123456”,我这样做会将值重置为“000000”。

标签: c#winforms

解决方案


如果我明白你在问什么,你想将 ix 转换为带有前导 0 的 6 位字符串

for( int ix = 0; ix < Convert.ToInt32(getrecords); ix++)
{
    string autoincrno = ix.ToString("D6"); // 000001, 000002 etc
}

根据您的评论,如果您有一个表示数字的字符串并且想要增加它,您可以将其解析为整数。

string autoincro = "123456";

int temp = int.Parse(autoincrno);

temp++;

autoincrno = temp.ToString("D6"); // 123457

推荐阅读