public void add()
{
int i_orderID = 0;
string s_Year = string.Format(("{0:D4}"),int.Parse(DateTime.Now.Year.ToString()));
string s_Month = string.Format(("{0:D2}"),int.Parse(DateTime.Now.Month.ToString()));
string s_Day = string.Format(("{0:D2}"),int.Parse(DateTime.Now.Day.ToString()));
DataSet ds=new DataSetDA().selectData("select num from fId");
for (int i = 0; i < ds.Tables[0].Rows.Count;i++ )
{
string str_Date = s_Year + s_Month + s_Day;
string s_Date = ds.Tables[0].Rows[i]["num"].ToString().Substring(0,8);
string s_id = ds.Tables[0].Rows[i]["num"].ToString().Substring(8,4);
if(str_Date.Trim()==s_Date.ToString().Trim())
{
if (int.Parse(s_id) > i_orderID)
{
i_orderID = int.Parse(s_id);
}
}
}
string s_orderID = string.Format(("{0:D4}"),i_orderID + 1);
this.lblfreightID.Text =s_Year + s_Month+s_Day + s_orderID;
new DataSetDA().insert("insert into fId values('"+lblfreightID.Text+"')");
}
本文介绍了一种基于当前日期和数据库中已有的订单编号来生成唯一订单号的方法。该方法首先获取系统的当前日期,并从数据库中选取特定字段,通过对比日期部分相同的记录,找出最大的订单编号,然后在此基础上加一生成新的订单号。
1200

被折叠的 条评论
为什么被折叠?



