C#生成流水号小代码

时间:2012-09-24 08:02:44
【文件属性】:

文件名称:C#生成流水号小代码

文件大小:5KB

文件格式:TXT

更新时间:2012-09-24 08:02:44

流水号 c#

自己写的一点小代码,多有不当,请指正! public string GetAutoDocNo() { string DocNo = "AD"; string today = DateTime.Today.Date.ToString("yyyyMMdd", DateTimeFormatInfo.InvariantInfo); DataSet DocDs = GetDataSet(" select * from News"); //初始化 if (DocDs.Tables[0].Rows.Count == 0) { DocNo += today + "101"; return DocNo; } /***********************/ else if (DocDs.Tables[0].Rows.Count > 0) { int count = 0; string oldDocNo = string.Empty; for (int i = 0; i < DocDs.Tables[0].Rows.Count; i++) { oldDocNo = DocDs.Tables[0].Rows[i]["NewsID"].ToString(); oldDocNo = oldDocNo.Substring(2, 8); if (oldDocNo == today) count++; } if (count == 0/*当天还没有单*/) { DocNo += today + "1001";//前面有1比较方便,没有1在后面做的时候要稍微再加几行代码 return DocNo; } else if (count > 0/*当天已经有单*/) { DocDs = GetDataSet("select MAX(CAST(SUBSTRING(NewsID,3,12) AS BIGINT)) as NewsID from News where (SUBSTRING(NewsID,3,8))='" + today + "'"); string id = DocDs.Tables[0].Rows[0]["NewsId"].ToString(); string lastid = id.Substring(8, 3); try { decimal lastidec = decimal.Parse(lastid); lastidec += 1; return DocNo + today + (lastidec.ToString()); } catch (Exception) { throw; }


网友评论

  • 谢谢分享,好的资源值得利用,也要善于利用!!
  • 有点小问题,应该是1001,不是101