导入excel
/// <summary>
/// 导入设计地层单元数据-量纲设置
/// </summary>
/// <param name="planId">方案ID</param>
/// <param name="lists">录入基本信息</param>
/// <param name="errorMsg">错误信息</param>
/// <returns></returns>
public ResultCode ImportDesignLayerData(string planId, SaveLayerCellInfoInput lists, ref string errorMsg)
{
try
{
if (lists != null && lists.lists.Count > 0)
{
if (string.IsNullOrEmpty(planId))
{
errorMsg = "无参数";
return ResultCode.CheckException;
}
List<ml_dsg_layer_001> bitUseInfoInput = new List<ml_dsg_layer_001>();
for (int i = 0; i < lists.lists.Count; i++)
{
var item = lists.lists[i];
ml_dsg_layer_001 addItem = new ml_dsg_layer_001();
addItem.PlanId = planId;
addItem.LAYER_NAME = item.Name;
addItem.MD_TOP = item.TopMD;
addItem.MD_BOTTOM = item.BotMD;
addItem.TVD_TOP = item.TopTvd;
addItem.TVD_BOT= item.BotTvd;
addItem.THICKNESS = item.Thickness;
addItem.RELATIONS = item.ContactRelation;
addItem.ERATHEM = item.EraThem;
addItem.SYSTEM = item.SysTem;
addItem.SERIES = item.Series;
addItem.FORMATION = item.FormaTion;
addItem.MEMBER = item.Member;
addItem.DIP_ANGLE = item.DipAngle;
addItem.TREND = item.Trend;
addItem.LITH_DESC = item.LithDesc;
addItem.PRODUCE_SIGN = item.ProduceSign;
addItem.TEMP_GRAD = item.TempGrad;
addItem.FAULT_PROMPT = item.FaultPrompt;
addItem.LITH = item.Lith;
addItem.DENSITY = item.Density;
addItem.PRESSURE_LIMIT = item.PressureLimit;
addItem.REMARK = item.Remark;
bitUseInfoInput.Add(addItem);
}
Dictionary<string, string> unitlist = new Dictionary<string, string>();
foreach (UnitLists unitinfo in lists.unitLists)
unitlist.Add(unitinfo.FieldNameCN, unitinfo.UnitName);
bool result = UnitConvertManager.Instance().ConvertConfigUnitToDBUnit<ml_dsg_layer_001>(unitlist, bitUseInfoInput, ref errorMsg);
if (!result)
return ResultCode.CheckException;
var db = ContextManager.GetDbContext(DBTypeString.DB_BASE);
db.BeginTran();
db.Deleteable<ml_dsg_layer_001>().Where(f => f.PlanId == planId).ExecuteCommand();
db.Insertable<ml_dsg_layer_001>(bitUseInfoInput).ExecuteCommand();
db.CommitTran();
return ResultCode.OK;
}
else
{
errorMsg = "导入的数据为空";
return ResultCode.CheckException;
}
}
catch (Exception ex)
{
errorMsg = EnvironmentConfiguration.UserEnvironment ? EnvironmentConfiguration.ErrorMsg : ex.Message;
ILoggerRepository repository = LogManager.GetRepository("NETCoreRepository");
ILog log = LogManager.GetLogger(repository.Name, typeof(LayerService));
log.Error(ex.Message);
return ResultCode.InternalServerError;
}
}