在文本框中自动创建帐单编号 [英] Auto creation of bill number in a textbox

查看:94
本文介绍了在文本框中自动创建帐单编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有

在我的Windows应用程序中,我想在用户运行创建帐单表单时自动创建帐单编号。账单号码应该在文本框中创建,如下所示: -

B / 092013/001之后。我为这个代码编写了



DateTime dt = DateTime.Now;

int mon = dt.Month;

int mon1 = dt.Year;

SqlConnection con = new SqlConnection();

con.ConnectionString =Data Source = MASHKOOR-PC; Initial Catalog = Check_Details;用户ID = sa;密码= md22mashkoor;

con.Open();

string id1,id2;

int id;

string query =select'BillNumber'= max(Bill_No)来自Check_Detail;

SqlCommand cm = new SqlCommand(query,con);

SqlDataReader dr = cm.ExecuteReader();

dr.Read();

{

if(dr [0] .ToString() ==)

{

id1 =000000;

}

其他

{

id1 = dr [0] .ToString();

}

id2 = id1.Substring(1,4 );

id = Convert.ToInt32(id2);



if((id> = 0)&&(id < 9))

{

id = id + 1;

textBox1.Text =B /+ mon.ToString()+ mon1.ToString()+/+00000+ id;

}

else if((id> = 9)&& (id< 99))

{

id = id + 1;

textBox1.Text =B /+ mon.ToString ()+ mon1.ToString()+/+0000+ id;

}

else if((id> = 99)&& (id< 999))

{

id = id + 1;

textBox1.Text =B /+ mon.ToString ()+ mon1.ToString()+/+000+ id;

}

dr.Close();

}

con.Close();



当我运行此代码时,账号自动创建,如 B / 92013 / 000001 并添加到数据库中。每当我为下一个账单号运行它时,它会显示一条错误消息,例如

输入字符串格式不正确。我无法找出背后的原因这个错误。请帮助我找出它。

Dear All
In my windows application, i want to create the bill number automatically while the user run the Create Bill form. The bill number should be created in a textbox like this format :-
"B/092013/001" afterwards. I wrote code for thi as

DateTime dt = DateTime.Now;
int mon = dt.Month;
int mon1 = dt.Year;
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=MASHKOOR-PC;Initial Catalog=Check_Details;User Id= sa; Password=md22mashkoor";
con.Open();
string id1, id2;
int id;
string query = "select 'BillNumber'=max(Bill_No) from Check_Detail";
SqlCommand cm = new SqlCommand(query, con);
SqlDataReader dr = cm.ExecuteReader();
dr.Read();
{
if (dr[0].ToString() == "")
{
id1 = "000000";
}
else
{
id1 = dr[0].ToString();
}
id2 = id1.Substring(1,4);
id = Convert.ToInt32(id2);

if ((id >= 0) && (id < 9))
{
id = id + 1;
textBox1.Text = "B/" + mon.ToString() + mon1.ToString() + "/" + "00000" + id;
}
else if ((id >= 9) && (id < 99))
{
id = id + 1;
textBox1.Text = "B/" + mon.ToString() + mon1.ToString() + "/" + "0000" + id;
}
else if ((id >= 99) && (id < 999))
{
id = id + 1;
textBox1.Text = "B/" + mon.ToString() + mon1.ToString() + "/" + "000" + id;
}
dr.Close();
}
con.Close();

while I run this code the Bill Number gets created automatically like "B/92013/000001" and added to database. Whenever I run it for next Bill Number it shows an error message such as
"Input string was not in a correct format." I am unable to find out the reason behind this error. Please some help me find out it.

推荐答案

Hello Md M Ahmed,

您将此帐单号存储在数据库中。编写一种方法,为每笔交易生成账单编号。在生成此数字时,您可以从数据库中读取最后一条记录。

阅读092013 i。即我想你的最后一次记录是你的月份和年份。你可以使用字符串类方法。如果它们相同,则从数据库服务器交叉检查年份和月份,从最后一个帐单编号中提取最后一个部分字符并添加一个。这是您的下一个帐单编号,如果在数据库中更改月份和年份,您必须在帐单编号中更改它。这就是为什么我建议你检查每个账单号码。您可以根据需要应用剩余的逻辑。

就是这样。希望这很有用。

请回复



-

谢谢
Hello Md M Ahmed ,
You store this bill number in database. Write a method that will generate bill number for each transaction. While generating this number you read last record from database.
read 092013 i. e. I think your month and year from this last record . you can use string class methods for this. Cross check it with year and month from database server if they are same extract last part characters from last bill number and add one to it . This is your next bill number if month and year are changed in database you have to change it in your bill number. That is why I am suggesting you to check for each bill number. You can apply remaining logic as per your need.
That's It . Hope this is useful.
Please reply

--
Thanks


这篇关于在文本框中自动创建帐单编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆