public JsonResult SaveBasNormalScheduleVTm(CBasNormalScheduleVTm BasNormalScheduleVTm) { string str = string.Empty; if (!ModelState.IsValid) { List <string> errorList = ModelStateExtension.GetModelError(ViewData); str = string.Join(",", errorList.ToArray()); return(Json(new { Success = false, Msg = str }, JsonRequestBehavior.AllowGet)); } else { CBasNormalScheduleVTm tmpBasNormalScheduleVTm = null; str = "<=SaveSuccess>"; if (!string.IsNullOrEmpty(BasNormalScheduleVTm.BasNormalScheduleVTmId)) { tmpBasNormalScheduleVTm = _BasNormalScheduleVTmDBAccess.Get(BasNormalScheduleVTm.BasNormalScheduleVTmId); TryUpdateModel <CBasNormalScheduleVTm>(tmpBasNormalScheduleVTm); } else { tmpBasNormalScheduleVTm = BasNormalScheduleVTm; } string errMsg; bool Success; Success = _BasNormalScheduleVTmDBAccess.Save(tmpBasNormalScheduleVTm, out errMsg); return(Json(new { Success = Success, Msg = Success ? str : errMsg, BasNormalScheduleVTm = tmpBasNormalScheduleVTm }, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// Normal Schedule V Trans Mode Import /// </summary> /// <param name="basNormalScheduleId"></param> /// <param name="strPath"></param> private void NormalScheduleVTmImport(string basNormalScheduleId, string strPath) { try { NpoiHelper npoiHelper = new NpoiHelper(strPath, false); DataTable dt = npoiHelper.ExcelToDataTable(0); //替换为从表里获取 var pdcs = DataContext.CBasPdcSequence.Select(p => p.Pdc); //string[] pdcs = new string[] { "BJ", "SH", "GZ", "YZ", "CD" }; string[] transModes = new string[] { "FTL_Line", "FTL_DTD", "LTL", "Air", "Courier" }; Dictionary <string, string> dicDestination = new Dictionary <string, string>(); if (dt != null && dt.Rows.Count > 0) { int index = 2; foreach (DataRow row in dt.Rows) { NormalScheduleVTmImportCheckData(row, index); string destination = row["Destination"].ToString(); if (dicDestination.ContainsKey(destination)) { throw new Exception(string.Format(@"Destination ""{0}"" <=Duplicate>", destination)); } dicDestination.Add(destination, destination); CBasNormalScheduleVTm item = new CBasNormalScheduleVTm(); Dashboard.Authentication.Authentication.UpdateEntity <CBasNormalScheduleVTm>(item); item.BasNormalScheduleId = basNormalScheduleId; item.BasNormalScheduleVTmId = Guid.NewGuid().ToString(); item.Destination = row["Destination"].ToString(); item.Province = row["Province"].ToString(); if (!DataIsNullValidator(row, "1st_V_Cutoff_Day") && !DataIsNullValidator(row, "1st_V_Cutoff_Time") && !DataIsNullValidator(row, "1st_V_Pickup_Day") && !DataIsNullValidator(row, "1st_V_Pickup_Time") && !DataIsNullValidator(row, "1st_V_Trans_Mode") && !DataIsNullValidator(row, "1st_V_Leadtime") && !DataIsNullValidator(row, "1st_V_Leadtime_AM_PM") && !DataIsNullValidator(row, "1st_V_Leadtime_Start") && !DataIsNullValidator(row, "1st_V_Leadtime_End")) { DataValidator <DateTime>(row, "1st_V_Cutoff_Time", index); DataValidator <DateTime>(row, "1st_V_Pickup_Time", index); DataValidator <int>(row, "1st_V_Leadtime", index); DataValidator <DateTime>(row, "1st_V_Leadtime_Start", index); DataValidator <DateTime>(row, "1st_V_Leadtime_End", index); item.FirstVCutoffDay = row["1st_V_Cutoff_Day"].ToString(); item.FirstVCutoffTime = Convert.ToDateTime(row["1st_V_Cutoff_Time"].ToString()); item.FirstVPickupDay = row["1st_V_Pickup_Day"].ToString(); item.FirstVPickupTime = Convert.ToDateTime(row["1st_V_Pickup_Time"].ToString()); item.FirstVTransMode = row["1st_V_Trans_Mode"].ToString(); item.FirstVLeadtime = Convert.ToInt32(row["1st_V_Leadtime"].ToString()); item.FirstVLeadtimeAmPm = row["1st_V_Leadtime_AM_PM"].ToString(); item.FirstVLeadtimeStart = Convert.ToDateTime(row["1st_V_Leadtime_Start"].ToString()); item.FirstVLeadtimeEnd = Convert.ToDateTime(row["1st_V_Leadtime_End"].ToString()); } item.SecondVCutoffDay = row["2nd_V_Cutoff_Day"].ToString(); item.SecondVCutoffTime = Convert.ToDateTime(row["2nd_V_Cutoff_Time"].ToString()); item.SecondVPickupDay = row["2nd_V_Pickup_Day"].ToString(); item.SecondVPickupTime = Convert.ToDateTime(row["2nd_V_Pickup_Time"].ToString()); DataContext.CBasNormalScheduleVTm.Add(item); foreach (var strPdc in pdcs) { foreach (var strTransMode in transModes) { if (!dt.Columns.Contains(strPdc + "_2nd_V_" + strTransMode + "_Leadtime")) { continue; } if (row[strPdc + "_2nd_V_" + strTransMode + "_Leadtime"] != null && !row[strPdc + "_2nd_V_" + strTransMode + "_Leadtime"].ToString().IsNullString()) { DataValidator <int>(row, strPdc + "_2nd_V_" + strTransMode + "_Leadtime", index); DataValidator <DateTime>(row, strPdc + "_2nd_V_" + strTransMode + "_Leadtime_Start", index); DataValidator <DateTime>(row, strPdc + "_2nd_V_" + strTransMode + "_Leadtime_End", index); CBasNormalScheduleVTmDet itemDet = new CBasNormalScheduleVTmDet(); Dashboard.Authentication.Authentication.UpdateEntity <CBasNormalScheduleVTmDet>(itemDet); itemDet.BasNormalScheduleId = basNormalScheduleId; itemDet.BasNormalScheduleVTmId = item.BasNormalScheduleVTmId; itemDet.BasNormalScheduleVTmDetId = Guid.NewGuid().ToString(); itemDet.Pdc = strPdc; itemDet.TransMode = strTransMode; itemDet.SecondVLeadtime = Convert.ToInt32(row[strPdc + "_2nd_V_" + strTransMode + "_Leadtime"].ToString()); itemDet.SecondVLeadtimeAmPm = row[strPdc + "_2nd_V_" + strTransMode + "_Leadtime_AM_PM"].ToString(); itemDet.SecondVLeadtimeStart = Convert.ToDateTime(row[strPdc + "_2nd_V_" + strTransMode + "_Leadtime_Start"].ToString()); itemDet.SecondVLeadtimeEnd = Convert.ToDateTime(row[strPdc + "_2nd_V_" + strTransMode + "_Leadtime_End"].ToString()); DataContext.CBasNormalScheduleVTmDet.Add(itemDet); } } } index++; } } } catch (Exception ex) { throw ex; } }