public string GetNextAutoNum(string autoCode, out int autoIndex) { autoIndex = 0; CPAutoNum auto = this.GetAutoNum(autoCode); if (auto == null) { return(""); } string s = auto.AutoTemplate; if (s == null) { throw new Exception("没有找到编号为【" + autoCode + "】的自动编号,或者此自动编号的编号模板为空!"); } if (s.IndexOf("{@AutoNum@}", StringComparison.CurrentCultureIgnoreCase) != -1) { autoIndex = this._CPAutoNumRep.GetMaxAutoIndex(auto); autoIndex++; string sIntValue = autoIndex.ToString().Trim(); int nLength = sIntValue.Length; for (int i = 0; i < auto.AutoNumLen - nLength; i++) { sIntValue = "0" + sIntValue; } s = s.Replace("{@AutoNum@}", sIntValue); } s = CPExpressionHelper.Instance.RunCompile(s); return(s); }
public override int GetMaxAutoIndex(CPAutoNum auto) { DbHelper _db = new DbHelper(auto.FormDbIns, CPAppContext.CurDbType()); if (CPAppContext.CurDbType() == DbHelper.DbTypeEnum.SqlServer) { string strSql = @"SELECT ISNULL(MAX(" + auto.FormAumField + @"),0) FROM dbo." + auto.FormTableName; if (auto.FormAutoYearSplit.Value) { strSql += " WHERE " + auto.FormYearField + "=" + DateTime.Now.Year; if (string.IsNullOrEmpty(auto.FormDataSearch) == false) { strSql += " AND (" + CPExpressionHelper.Instance.RunCompile(auto.FormDataSearch) + " ) "; } } else { if (string.IsNullOrEmpty(auto.FormDataSearch) == false) { strSql += " WHERE (" + CPExpressionHelper.Instance.RunCompile(auto.FormDataSearch) + " ) "; } } int NextAutoNum = Convert.ToInt32(_db.ExecuteScalar(strSql)); return(NextAutoNum); } else { throw new Exception("未实现"); } }