补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";

posted @ 2022-07-19 16:00  枫叶轻翔  阅读(35)  评论(0编辑  收藏  举报