/// <summary> /// 这是获取维修单号的唯一方法,防止出现同时取最大号的情况 /// 使用的技术叫做: Double check Lock /// </summary> /// <returns>快递单号,如果是0则表示生成失败</returns> #region 获取最大维修单号 private static int getMaxWXNo() { int iRst = 0; if (dbhle == null) { lock (syncRoot) { if (dbhle == null) { dbhle = new DBHandle("SPWX"); string select = @"SELECT [ID],[Value] FROM [dbo].[SPWX_Dict] WHERE Type = 'MaxWxNo'"; DataTable dtMax = dbhle.GetData(select, new object[0]); int iMax = Int32.Parse(dtMax.Rows[0][1].ToString()); iRst = ++iMax; dtMax.Rows[0][1] = iRst.ToString(); bool b = dbhle.Update("[dbo].[SPWX_Dict]", "ID", dtMax); if (!b) { iRst = 0; }; }; dbhle = null; }; }; return iRst; }