补0拼接,进行新编号拼接
/// <summary>
/// 补0拼接,进行新编号拼接
/// </summary>
/// <param name="contractCodePrefix">前缀</param>
/// <param name="padZero">补零位(最大值的长度)</param>
/// <param name="increase">后缀(当前数值)</param>
/// <returns></returns>
public virtual string CreateCodeResult(string contractCodePrefix, int padZero, string increase)
{
string padRightStr = $"{"".PadRight(padZero, '0')}{increase}";
string code = !string.IsNullOrEmpty(contractCodePrefix) ? $"{contractCodePrefix}-{padRightStr}" : $"{padRightStr}";
return code;
}
//使用示例
var list = _costEstimationEnityService.Instance.Where(t => t.ProjVersionGUID == requestDto.SourceGuid && t.CostEstimationName.StartsWith(codeOrder)).ToList();
string maxCode = list.Count > 0 ? codeOrder + CreateCodeResult("", 2, (list.Count + 1).ToString()) : codeOrder + "001";