public JsonResult SaveBasNormalScheduleVCt(CBasNormalScheduleVCt BasNormalScheduleVCt) { 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 { CBasNormalScheduleVCt tmpBasNormalScheduleVCt = null; str = "<=SaveSuccess>"; if (!string.IsNullOrEmpty(BasNormalScheduleVCt.BasNormalScheduleVCtId)) { tmpBasNormalScheduleVCt = _BasNormalScheduleVCtDBAccess.Get(BasNormalScheduleVCt.BasNormalScheduleVCtId); TryUpdateModel <CBasNormalScheduleVCt>(tmpBasNormalScheduleVCt); } else { tmpBasNormalScheduleVCt = BasNormalScheduleVCt; } string errMsg; bool Success; Success = _BasNormalScheduleVCtDBAccess.Save(tmpBasNormalScheduleVCt, out errMsg); return(Json(new { Success = Success, Msg = Success ? str : errMsg, BasNormalScheduleVCt = tmpBasNormalScheduleVCt }, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// Normal Schedule V Cargo Type Import /// </summary> /// <param name="basNormalScheduleId"></param> /// <param name="strPath"></param> private void NormalScheduleVCtImport(string basNormalScheduleId, string strPath) { try { NpoiHelper npoiHelper = new NpoiHelper(strPath, false); DataTable dt = npoiHelper.ExcelToDataTable(0); //替换为从表里获取 var warehouse = DataContext.CBasPdcSequence.Select(p => p.Pdc); //string[] warehouse = new string[] { "BJ", "SH", "GZ", "YZ", "CD" }; Dictionary <string, string> dicDealerCode = new Dictionary <string, string>(); if (dt != null && dt.Rows.Count > 0) { int index = 2; foreach (DataRow row in dt.Rows) { //验证指定字段不能为空 NormalScheduleVCtImportCheckData(row, index); string dealerCode = row["Dealer_Code"].ToString(); if (dicDealerCode.ContainsKey(dealerCode)) { throw new Exception(string.Format(@"Dealer Code ""{0}"" <=Duplicate>", dealerCode)); } dicDealerCode.Add(dealerCode, dealerCode); CBasNormalScheduleVCt item = new CBasNormalScheduleVCt(); Dashboard.Authentication.Authentication.UpdateEntity <CBasNormalScheduleVCt>(item); item.BasNormalScheduleId = basNormalScheduleId; item.BasNormalScheduleVCtId = Guid.NewGuid().ToString(); item.DealerCode = dealerCode; item.FacingPdc = row["Facing_PDC"].ToString(); item.DealerType = row["Dealer_Type"].ToString(); item.DealerName = row["Dealer_Name"].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.CBasNormalScheduleVCt.Add(item); foreach (var strPdc in warehouse) { if (!dt.Columns.Contains(strPdc + "_2nd_V_Normal_Trans_Mode")) { continue; } DataValidator <int>(row, strPdc + "_2nd_V_Normal_Leadtime", index); DataValidator <DateTime>(row, strPdc + "_2nd_V_Normal_Leadtime_Start", index); DataValidator <DateTime>(row, strPdc + "_2nd_V_Normal_Leadtime_End", index); DataValidator <int>(row, strPdc + "_2nd_V_DG_Bulky_Leadtime", index); DataValidator <DateTime>(row, strPdc + "_2nd_V_DG_Bulky_Leadtime_Start", index); DataValidator <DateTime>(row, strPdc + "_2nd_V_DG_Bulky_Leadtime_End", index); CBasNormalScheduleVCtDet itemNormal = new CBasNormalScheduleVCtDet(); Dashboard.Authentication.Authentication.UpdateEntity <CBasNormalScheduleVCtDet>(itemNormal); itemNormal.BasNormalScheduleId = basNormalScheduleId; itemNormal.BasNormalScheduleVCtId = item.BasNormalScheduleVCtId; itemNormal.BasNormalScheduleVCtDetId = Guid.NewGuid().ToString(); itemNormal.Pdc = strPdc; itemNormal.CargoType = "Normal"; itemNormal.SecondVTransMode = row[strPdc + "_2nd_V_Normal_Trans_Mode"].ToString(); itemNormal.SecondVLeadtime = Convert.ToInt32(row[strPdc + "_2nd_V_Normal_Leadtime"].ToString()); itemNormal.SecondVLeadtimeAmPm = row[strPdc + "_2nd_V_Normal_Leadtime_AM_PM"].ToString(); itemNormal.SecondVLeadtimeStart = Convert.ToDateTime(row[strPdc + "_2nd_V_Normal_Leadtime_Start"].ToString()); itemNormal.SecondVLeadtimeEnd = Convert.ToDateTime(row[strPdc + "_2nd_V_Normal_Leadtime_End"].ToString()); DataContext.CBasNormalScheduleVCtDet.Add(itemNormal); CBasNormalScheduleVCtDet itemDgBulky = new CBasNormalScheduleVCtDet(); Dashboard.Authentication.Authentication.UpdateEntity <CBasNormalScheduleVCtDet>(itemDgBulky); itemDgBulky.BasNormalScheduleId = basNormalScheduleId; itemDgBulky.BasNormalScheduleVCtId = item.BasNormalScheduleVCtId; itemDgBulky.BasNormalScheduleVCtDetId = Guid.NewGuid().ToString(); itemDgBulky.Pdc = strPdc; itemDgBulky.CargoType = "DG/Bulky"; itemDgBulky.SecondVTransMode = row[strPdc + "_2nd_V_DG_Bulky_Trans_Mode"].ToString(); itemDgBulky.SecondVLeadtime = Convert.ToInt32(row[strPdc + "_2nd_V_DG_Bulky_Leadtime"].ToString()); itemDgBulky.SecondVLeadtimeAmPm = row[strPdc + "_2nd_V_DG_Bulky_Leadtime_AM_PM"].ToString(); itemDgBulky.SecondVLeadtimeStart = Convert.ToDateTime(row[strPdc + "_2nd_V_DG_Bulky_Leadtime_Start"].ToString()); itemDgBulky.SecondVLeadtimeEnd = Convert.ToDateTime(row[strPdc + "_2nd_V_DG_Bulky_Leadtime_End"].ToString()); DataContext.CBasNormalScheduleVCtDet.Add(itemDgBulky); } index++; } } } catch (Exception ex) { throw ex; } }