检查文本框输入自动增加数量,由输入总记录确定

时间:2019-02-26 03:02:52

标签: c# winforms

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

第一个文本框用于自动递增编号:用户可能会输入“ 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”。

1 个答案:

答案 0 :(得分:0)

如果我了解您的要求,则想将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