 |
|
เอาโค้ดมาให้ช่วยดูหน่อยค่ะ ต้องการรัน memberID 10 หลัก และใช้ substring จะมีหลักของ ประเภทบัตร 2 หลัก เดือน 2 หลัก ปี 2 หลัก และเลข run number 4 หลัก ค่ะ
แต่พอใส่แล้วมันออกมาตามจำนวนหลักแต่เลขไม่ยอม run number ให้อะค่ะ
และกรณีที่ต้องการนำค่าจาก comboxType มาเพื่อเช็คว่าผู้ใช้เครื่องประเภทให้และให้บันทึกข้อมูลไม่ในใจว่าเขียนถูกหรือป่าวค่ะ
Code (C#)
private string GetNewMemberId()
{
string nextId = String.Format("{0:00}", 1) + DateTime.Now.ToString("MMyy") + String.Format("{0:0000}", 1);
string currentId = lbMemberID.Text;
if(currentId== null)
currentId = String.Format("{0:00}", 0) + DateTime.Now.ToString("MMyy") + String.Format("{0:0000}", 0);
int maxid = 0;
int type = 0;
int tototype = 0;
if (currentId.Substring(2, 0) == DateTime.Now.ToString("MMyy"))
{
try
{
tototype = Convert.ToInt32(currentId.Substring(1, 1));
}
catch { }
if (type == comboBox1.SelectedIndex)
tototype = type;
}
if (currentId.Substring(0, 4) == DateTime.Now.ToString("MMyy"))
{
try
{
maxid = Convert.ToInt32(currentId.Substring(6, 4));
}
catch { }
if (maxid < 9999)
maxid++;
else
maxid = 1;
}
nextId = String.Format("{0:00}", 1) + DateTime.Now.ToString("MMyy") + String.Format("{0:0000}", maxid);
return nextId;
}
ลบกวนช่วยแนะนำหน่อยนะค่ะ
ขอบคุณค่ะ
Tag : .NET, Ms SQL Server 2005, Win (Windows App), C#, VS 2008 (.NET 3.x)
|
ประวัติการแก้ไข 2010-09-08 16:20:00 2010-09-08 16:20:47
|
 |
 |
 |
 |
Date :
2010-09-08 16:17:29 |
By :
Jing_Jai |
View :
1172 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |