修改公司级培训
This commit is contained in:
@@ -468,5 +468,135 @@ namespace BLL
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static string InsertCodeRecordsByMenuIdProjectIdUnitIdForApi(string menuId, string projectId, string unitId, string dataId, DateTime? compileDate)
|
||||
{
|
||||
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
||||
{
|
||||
string ruleCode = string.Empty;
|
||||
var IsHaveCodeRecords = db.Sys_CodeRecords.FirstOrDefault(x => x.DataId == dataId);
|
||||
if (IsHaveCodeRecords == null) ///是否已存在编码
|
||||
{
|
||||
string ruleCodeower = string.Empty;
|
||||
int digit = 4; ///流水位数
|
||||
string symbolower = "-"; ///业主间隔符
|
||||
int digitower = 4; ///业主流水位数
|
||||
string symbol = "-"; ///间隔符
|
||||
var project = db.Base_Project.FirstOrDefault(e => e.ProjectId == projectId); ////项目
|
||||
if (project != null && !string.IsNullOrEmpty(dataId))
|
||||
{
|
||||
string projectCode = project.ProjectCode; ///项目编号
|
||||
////编码规则表
|
||||
var sysCodeTemplateRule = db.ProjectData_CodeTemplateRule.FirstOrDefault(x => x.MenuId == menuId && x.ProjectId == projectId);
|
||||
if (sysCodeTemplateRule != null)
|
||||
{
|
||||
symbol = sysCodeTemplateRule.Symbol;
|
||||
symbolower = sysCodeTemplateRule.OwerSymbol;
|
||||
|
||||
if (sysCodeTemplateRule.Digit.HasValue)
|
||||
{
|
||||
digit = sysCodeTemplateRule.Digit.Value;
|
||||
}
|
||||
if (sysCodeTemplateRule.OwerDigit.HasValue)
|
||||
{
|
||||
digitower = sysCodeTemplateRule.OwerDigit.Value;
|
||||
}
|
||||
if (sysCodeTemplateRule.IsProjectCode == true)
|
||||
{
|
||||
ruleCode = projectCode + symbol;
|
||||
}
|
||||
if (sysCodeTemplateRule.OwerIsProjectCode == true)
|
||||
{
|
||||
ruleCodeower = projectCode + symbolower;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(sysCodeTemplateRule.Prefix))
|
||||
{
|
||||
ruleCode += sysCodeTemplateRule.Prefix + symbol;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(sysCodeTemplateRule.OwerPrefix))
|
||||
{
|
||||
ruleCodeower += sysCodeTemplateRule.OwerPrefix + symbolower;
|
||||
}
|
||||
if (sysCodeTemplateRule.IsUnitCode == true || sysCodeTemplateRule.OwerIsUnitCode == true)
|
||||
{
|
||||
var unit = db.Base_Unit.FirstOrDefault(x => x.UnitId == unitId);
|
||||
if (unit != null)
|
||||
{
|
||||
if (sysCodeTemplateRule.IsUnitCode == true)
|
||||
{ ruleCode = unit.UnitCode + symbol; }
|
||||
|
||||
if (sysCodeTemplateRule.OwerIsUnitCode == true)
|
||||
{
|
||||
ruleCodeower = unit.UnitCode + symbolower;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////获取编码记录表最大排列序号
|
||||
int maxNewSortIndex = 0;
|
||||
if (!String.IsNullOrEmpty(projectId))
|
||||
{
|
||||
var maxSortIndex = db.Sys_CodeRecords.Where(x => x.ProjectId == projectId && x.MenuId == menuId).Select(x => x.SortIndex).Max();
|
||||
if (maxSortIndex.HasValue)
|
||||
{
|
||||
maxNewSortIndex = maxSortIndex.Value;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var maxSortIndexNull = db.Sys_CodeRecords.Where(x => x.MenuId == menuId).Select(x => x.SortIndex).Max();
|
||||
if (maxSortIndexNull.HasValue)
|
||||
{
|
||||
maxNewSortIndex = maxSortIndexNull.Value;
|
||||
}
|
||||
}
|
||||
maxNewSortIndex = maxNewSortIndex + 1;
|
||||
////插入数据库
|
||||
Model.Sys_CodeRecords newCodeRecords = new Model.Sys_CodeRecords
|
||||
{
|
||||
CodeRecordId = SQLHelper.GetNewID(typeof(Model.Sys_CodeRecords))
|
||||
};
|
||||
if (project != null)
|
||||
{
|
||||
newCodeRecords.ProjectId = project.ProjectId;
|
||||
}
|
||||
newCodeRecords.MenuId = menuId;
|
||||
newCodeRecords.DataId = dataId;
|
||||
newCodeRecords.UnitId = unitId;
|
||||
newCodeRecords.SortIndex = maxNewSortIndex;
|
||||
newCodeRecords.CompileDate = compileDate;
|
||||
newCodeRecords.RuleCodes = ruleCode;
|
||||
newCodeRecords.Digit = digit;
|
||||
newCodeRecords.OwnerRuleCodes = ruleCodeower;
|
||||
newCodeRecords.OwerDigit = digitower;
|
||||
if (!string.IsNullOrEmpty(ruleCode))
|
||||
{
|
||||
newCodeRecords.Code = ruleCode + (maxNewSortIndex.ToString().PadLeft(digit, '0')); ///字符自动补零 编码
|
||||
}
|
||||
else
|
||||
{
|
||||
newCodeRecords.Code = (maxNewSortIndex.ToString().PadLeft(digit, '0'));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(ruleCodeower))
|
||||
{
|
||||
newCodeRecords.OwnerCode = ruleCodeower + (maxNewSortIndex.ToString().PadLeft(digitower, '0')); ///字符自动补零 业主编码
|
||||
}
|
||||
else
|
||||
{
|
||||
newCodeRecords.OwnerCode = (maxNewSortIndex.ToString().PadLeft(digitower, '0'));
|
||||
}
|
||||
db.Sys_CodeRecords.InsertOnSubmit(newCodeRecords);
|
||||
db.SubmitChanges();
|
||||
}
|
||||
else
|
||||
{
|
||||
ruleCode = IsHaveCodeRecords.Code;
|
||||
}
|
||||
|
||||
return ruleCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user