// JObject here is very very important... public ActionResult <string> Post([FromBody] JObject entityObj) { ORDER_LIST_DETAIL postedEntity = entityObj.ToObject <ORDER_LIST_DETAIL>(); // 校验主键 if (String.IsNullOrEmpty(postedEntity.ORDER_NO)) { return(""); } var orderListEntity = myContext.ORDER_LIST_DETAIL .Where(d => d.ORDER_NO.Equals(postedEntity.ORDER_NO) && d.BUMP_ID.Equals(postedEntity.BUMP_ID)); if (orderListEntity.Count() == 0) { // INSERT // MAKE BUMP ID postedEntity.BUMP_ID = postedEntity.BUMP_TYPE + "_" + postedEntity.MATERIAL; myContext.ORDER_LIST_DETAIL.Add(postedEntity); myContext.SaveChanges(); return(""); } else { orderListEntity.First().BUMP_NM = postedEntity.BUMP_NM; orderListEntity.First().STATION = postedEntity.STATION; orderListEntity.First().BUMP_TYPE = postedEntity.BUMP_TYPE; orderListEntity.First().NUMBER = postedEntity.NUMBER; orderListEntity.First().FLOW = postedEntity.FLOW; orderListEntity.First().LIFT = postedEntity.LIFT; orderListEntity.First().MATERIAL = postedEntity.MATERIAL; orderListEntity.First().SEAL = postedEntity.SEAL; orderListEntity.First().STATUS = postedEntity.STATUS; orderListEntity.First().REMARK = postedEntity.REMARK; myContext.SaveChanges(); return(""); } }
// JObject here is very very important... public ActionResult <string> Post([FromBody] JObject entityObj) { ORDER_LIST_DETAIL_DICT_NAME postedEntity = entityObj.ToObject <ORDER_LIST_DETAIL_DICT_NAME>(); // 校验主键 if (String.IsNullOrEmpty(postedEntity.ORDER_NO)) { return(""); } var orderListEntity = myContext.ORDER_LIST_DETAIL .Where(d => d.ORDER_NO.Equals(postedEntity.ORDER_NO) && d.BUMP_ID.Equals(postedEntity.BUMP_ID)); if (orderListEntity.Count() == 0) { // INSERT ORDER_LIST_DETAIL postedEntity1 = new ORDER_LIST_DETAIL(); postedEntity1.ORDER_NO = postedEntity.ORDER_NO; // MAKE BUMP ID postedEntity1.BUMP_ID = postedEntity.BUMP_TYPE + "_" + postedEntity.MATERIAL_BUMP; postedEntity1.BUMP_NM = postedEntity.BUMP_NM; postedEntity1.BUMP_TYPE = postedEntity.BUMP_TYPE; postedEntity1.NUMBER = postedEntity.NUMBER; postedEntity1.UNIT = postedEntity.UNIT; postedEntity1.PRICE = postedEntity.PRICE; postedEntity1.AMOUNT = postedEntity.AMOUNT; postedEntity1.BUMP_SERIAL_NO = postedEntity.BUMP_SERIAL_NO; postedEntity1.FLOW = postedEntity.FLOW; postedEntity1.LIFT = postedEntity.LIFT; postedEntity1.MATERIAL_BUMP = postedEntity.MATERIAL_BUMP; postedEntity1.MATERIAL_FAN = postedEntity.MATERIAL_FAN; postedEntity1.MATERIAL_ROLLER = postedEntity.MATERIAL_ROLLER; postedEntity1.MOTOR_BRAND = postedEntity.MOTOR_BRAND; postedEntity1.MOTOR_DEMAND = postedEntity.MOTOR_DEMAND; postedEntity1.SEAL_FORM = postedEntity.SEAL_FORM; postedEntity1.SEAL_BRAND = postedEntity.SEAL_BRAND; postedEntity1.ROLLER_BRAND = postedEntity.ROLLER_BRAND; postedEntity1.COUPLING = postedEntity.COUPLING; postedEntity1.SEAL_COOLER = postedEntity.SEAL_COOLER; postedEntity1.CAVITATION_ALLOWANCE = postedEntity.CAVITATION_ALLOWANCE; postedEntity1.ACTUAL_BUMP_SPEED = postedEntity.ACTUAL_BUMP_SPEED; postedEntity1.STATION = postedEntity.STATION; postedEntity1.TEMPERATURE = postedEntity.TEMPERATURE; postedEntity1.DENSITY = postedEntity.DENSITY; postedEntity1.IN_PRESSURE = postedEntity.IN_PRESSURE; postedEntity1.MEDIUM = postedEntity.MEDIUM; postedEntity1.VISCOSITY = postedEntity.VISCOSITY; postedEntity1.PARTICULATES = postedEntity.PARTICULATES; postedEntity1.WORKING_PRESSURE = postedEntity.WORKING_PRESSURE; postedEntity1.FLANGES_STANDARD = postedEntity.FLANGES_STANDARD; postedEntity1.FLANGES_LEVEL = postedEntity.FLANGES_LEVEL; postedEntity1.BASE = postedEntity.BASE; postedEntity1.COUPLING_HOOD = postedEntity.COUPLING_HOOD; postedEntity1.ANCHOR_BOLT = postedEntity.ANCHOR_BOLT; postedEntity1.PAINT = postedEntity.PAINT; postedEntity1.SURFACE_TREATMENT = postedEntity.SURFACE_TREATMENT; postedEntity1.PACKAGE = postedEntity.PACKAGE; postedEntity1.TRANSPORT = postedEntity.TRANSPORT; postedEntity1.SEAL_BRAND_MANUAL = String.IsNullOrEmpty(postedEntity.SEAL_BRAND_MANUAL) ? "" : postedEntity.SEAL_BRAND_MANUAL; myContext.ORDER_LIST_DETAIL.Add(postedEntity1); myContext.SaveChanges(); return(""); } else { orderListEntity.First().BUMP_NM = postedEntity.BUMP_NM; orderListEntity.First().BUMP_TYPE = postedEntity.BUMP_TYPE; orderListEntity.First().NUMBER = postedEntity.NUMBER; orderListEntity.First().UNIT = postedEntity.UNIT; orderListEntity.First().PRICE = postedEntity.PRICE; orderListEntity.First().AMOUNT = postedEntity.AMOUNT; orderListEntity.First().BUMP_SERIAL_NO = postedEntity.BUMP_SERIAL_NO; orderListEntity.First().FLOW = postedEntity.FLOW; orderListEntity.First().LIFT = postedEntity.LIFT; orderListEntity.First().MATERIAL_BUMP = postedEntity.MATERIAL_BUMP; orderListEntity.First().MATERIAL_FAN = postedEntity.MATERIAL_FAN; orderListEntity.First().MATERIAL_ROLLER = postedEntity.MATERIAL_ROLLER; orderListEntity.First().MOTOR_BRAND = postedEntity.MOTOR_BRAND; orderListEntity.First().MOTOR_DEMAND = postedEntity.MOTOR_DEMAND; orderListEntity.First().SEAL_FORM = postedEntity.SEAL_FORM; orderListEntity.First().SEAL_BRAND = postedEntity.SEAL_BRAND; orderListEntity.First().ROLLER_BRAND = postedEntity.ROLLER_BRAND; orderListEntity.First().COUPLING = postedEntity.COUPLING; orderListEntity.First().SEAL_COOLER = postedEntity.SEAL_COOLER; orderListEntity.First().CAVITATION_ALLOWANCE = postedEntity.CAVITATION_ALLOWANCE; orderListEntity.First().ACTUAL_BUMP_SPEED = postedEntity.ACTUAL_BUMP_SPEED; orderListEntity.First().STATION = postedEntity.STATION; orderListEntity.First().TEMPERATURE = postedEntity.TEMPERATURE; orderListEntity.First().TEMPERATURE = postedEntity.TEMPERATURE; orderListEntity.First().IN_PRESSURE = postedEntity.IN_PRESSURE; orderListEntity.First().MEDIUM = postedEntity.MEDIUM; orderListEntity.First().VISCOSITY = postedEntity.VISCOSITY; orderListEntity.First().PARTICULATES = postedEntity.PARTICULATES; orderListEntity.First().WORKING_PRESSURE = postedEntity.WORKING_PRESSURE; orderListEntity.First().FLANGES_STANDARD = postedEntity.FLANGES_STANDARD; orderListEntity.First().FLANGES_LEVEL = postedEntity.FLANGES_LEVEL; orderListEntity.First().BASE = postedEntity.BASE; orderListEntity.First().COUPLING_HOOD = postedEntity.COUPLING_HOOD; orderListEntity.First().ANCHOR_BOLT = postedEntity.ANCHOR_BOLT; orderListEntity.First().PAINT = postedEntity.PAINT; orderListEntity.First().SURFACE_TREATMENT = postedEntity.SURFACE_TREATMENT; orderListEntity.First().PACKAGE = postedEntity.PACKAGE; orderListEntity.First().TRANSPORT = postedEntity.TRANSPORT; orderListEntity.First().SEAL_BRAND_MANUAL = String.IsNullOrEmpty(postedEntity.SEAL_BRAND_MANUAL) ? "" : postedEntity.SEAL_BRAND_MANUAL; myContext.SaveChanges(); return(""); } }
public ActionResult <string> Delete(string BUMP_INFO) { Boolean isSuccess = true; string data = "Delete success"; if (!String.IsNullOrEmpty(BUMP_INFO)) { string[] ORDER_NO_AND_BUMP_IDS = BUMP_INFO.Replace("|SLASH|", "/").Split("|DASH|"); string[] BUMP_ID_LIST = { }; string ORDER_NO_T = String.Empty; if (ORDER_NO_AND_BUMP_IDS.Length > 1) { ORDER_NO_T = ORDER_NO_AND_BUMP_IDS[0]; BUMP_ID_LIST = ORDER_NO_AND_BUMP_IDS[1].Split(","); } else { isSuccess = false; data = "Need more arguments."; } foreach (string BUMP_ID_T in BUMP_ID_LIST) { ORDER_LIST_DETAIL delEntity = new ORDER_LIST_DETAIL() { BUMP_ID = BUMP_ID_T, ORDER_NO = ORDER_NO_T }; if (delEntity.Equals(null)) { isSuccess = false; data = "No such data."; break; } else { // FIND DB ITEM myContext.ORDER_LIST_DETAIL.Attach(delEntity); // DELETE DB ITEM var delRes = myContext.ORDER_LIST_DETAIL.Remove(delEntity); if (delRes.State == EntityState.Deleted) { // SAVE CHANGES AND DO NOT RETURN myContext.SaveChanges(); } else { isSuccess = false; data = "No such data."; break; } } } } else { isSuccess = false; data = "No such data."; } JsonRes res = new JsonRes(); res.isSuccess = isSuccess; res.data = data; return(JsonConvert.SerializeObject(res)); }
public ActionResult <string> UploadFile() { try { var file = Request.Form.Files[0]; string folderName = "UploadExcel"; string contentRootPath = _hostingEnvironment.ContentRootPath; string newPath = Path.Combine(contentRootPath, folderName); if (!Directory.Exists(newPath)) { Directory.CreateDirectory(newPath); } if (file.Length > 0) { string fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); string fullPath = Path.Combine(newPath, fileName); using (FileStream stream = new FileStream(fullPath, FileMode.Create)) { file.CopyTo(stream); IWorkbook workbook = WorkbookFactory.Create(stream); ISheet sheet = workbook.GetSheetAt(0); if (sheet != null) { /* * 订单信息 */ // 订单编号 String ORDER_NO = getCellValue(sheet, "C3", CELL_TYP_STRING); if (String.IsNullOrEmpty(ORDER_NO)) { // 订单号(主键)为空时,直接返回 return("OrderNo is empty."); } // 合同编号 String CONTRACT_NO = getCellValue(sheet, "C4", CELL_TYP_STRING); // 项目名称 String PROJECT_NM = getCellValue(sheet, "C5", CELL_TYP_STRING); // 销售部门/销售员 String SALES_PERSON = getCellValue(sheet, "C6", CELL_TYP_STRING); // 订货单位 String ORDER_UNIT = getCellValue(sheet, "C7", CELL_TYP_STRING); // 应用工程师 String APPLICATION_ENGINEER = getCellValue(sheet, "F3", CELL_TYP_STRING); // 下发日期 String DEPARTURE_DATE_STR = getCellValue(sheet, "F4", CELL_TYP_DATE); // 交货日期 String DELIVERY_DATE_STR = getCellValue(sheet, "F5", CELL_TYP_DATE); // 此订单页数 String BUMP_DETAIL_NUM = getCellValue(sheet, "F6", CELL_TYP_NUMBER); // 构造JObject,并保存订单信息至数据库中 JObject entityObjForOrder = new JObject(); entityObjForOrder.Add("ORDER_NO", ORDER_NO); entityObjForOrder.Add("CONTRACT_NO", CONTRACT_NO); entityObjForOrder.Add("PROJECT_NM", PROJECT_NM); entityObjForOrder.Add("SALES_PERSON", SALES_PERSON); entityObjForOrder.Add("ORDER_UNIT", ORDER_UNIT); entityObjForOrder.Add("APPLICATION_ENGINEER", APPLICATION_ENGINEER); entityObjForOrder.Add("DEPARTURE_DATE", Convert.ToDateTime(DEPARTURE_DATE_STR)); entityObjForOrder.Add("DELIVERY_DATE", Convert.ToDateTime(DELIVERY_DATE_STR)); ORDER_LIST_MST excelOrderListMstEntity = entityObjForOrder.ToObject <ORDER_LIST_MST>(); var orderListMstEntity = myContext.ORDER_LIST_MST.Where(d => d.ORDER_NO.Equals(excelOrderListMstEntity.ORDER_NO)); if (orderListMstEntity.Count() == 0) { // INSERT myContext.ORDER_LIST_MST.Add(excelOrderListMstEntity); // 以后有可能做一个FLG,到水泵信息保存完成后再保存更改 myContext.SaveChanges(); } else { orderListMstEntity.First().CONTRACT_NO = excelOrderListMstEntity.CONTRACT_NO; orderListMstEntity.First().PROJECT_NM = excelOrderListMstEntity.PROJECT_NM; orderListMstEntity.First().ORDER_UNIT = excelOrderListMstEntity.ORDER_UNIT; orderListMstEntity.First().SALES_PERSON = excelOrderListMstEntity.SALES_PERSON; orderListMstEntity.First().DEPARTURE_DATE = excelOrderListMstEntity.DEPARTURE_DATE.ToLocalTime(); orderListMstEntity.First().DELIVERY_DATE = excelOrderListMstEntity.DELIVERY_DATE.ToLocalTime(); orderListMstEntity.First().REMARK = excelOrderListMstEntity.REMARK; orderListMstEntity.First().APPLICATION_ENGINEER = excelOrderListMstEntity.APPLICATION_ENGINEER; myContext.SaveChanges(); } /* * 水泵信息 */ for (int i = 0; i < Convert.ToInt32(BUMP_DETAIL_NUM); i++) { // 序号(校验用) String NO = getCellValue(sheet, "A" + (BUMP_OFFSET + i), CELL_TYP_STRING); // 序号校验(还应考虑不是数字Convert失败的情况,未写) if (Convert.ToInt32(NO) != i + 1) { return(""); } // 泵名称 String BUMP_NM = getCellValue(sheet, "B" + (BUMP_OFFSET + i), CELL_TYP_STRING); // 工位 String STATION = getCellValue(sheet, "C" + (BUMP_OFFSET + i), CELL_TYP_STRING); // 型号 String BUMP_TYPE = getCellValue(sheet, "D" + (BUMP_OFFSET + i), CELL_TYP_STRING); // 数量 String NUMBER = getCellValue(sheet, "F" + (BUMP_OFFSET + i), CELL_TYP_NUMBER); // 流量 String FLOW = getCellValue(sheet, "G" + (BUMP_OFFSET + i), CELL_TYP_NUMBER); // 扬程 String LIFT = getCellValue(sheet, "H" + (BUMP_OFFSET + i), CELL_TYP_NUMBER); // 材质 String MATERIAL = getCellValue(sheet, "I" + (BUMP_OFFSET + i), CELL_TYP_STRING); // 机封 String SEAL = getCellValue(sheet, "J" + (BUMP_OFFSET + i), CELL_TYP_STRING); // 序列号 String BUMP_SERIAL_NO = getCellValue(sheet, "K" + (BUMP_OFFSET + i), CELL_TYP_STRING); // 备注 String REMARK = getCellValue(sheet, "L" + (BUMP_OFFSET + i), CELL_TYP_STRING); // 构造水泵ID String BUMP_ID = ""; if (String.IsNullOrEmpty(BUMP_TYPE) || String.IsNullOrEmpty(MATERIAL)) { return("BumpType or material is empty."); } else { BUMP_ID = BUMP_TYPE + "_" + MATERIAL; } // 构造JObject,并保存水泵信息至数据库中 JObject entityObjForBump = new JObject(); entityObjForBump.Add("ORDER_NO", ORDER_NO); entityObjForBump.Add("BUMP_ID", BUMP_ID); entityObjForBump.Add("BUMP_NM", BUMP_NM); entityObjForBump.Add("STATION", STATION); entityObjForBump.Add("BUMP_TYPE", BUMP_TYPE); entityObjForBump.Add("NUMBER", Convert.ToInt32(NUMBER)); entityObjForBump.Add("FLOW", Convert.ToInt32(FLOW)); entityObjForBump.Add("LIFT", Convert.ToInt32(LIFT)); entityObjForBump.Add("MATERIAL", MATERIAL); entityObjForBump.Add("SEAL", SEAL); entityObjForBump.Add("BUMP_SERIAL_NO", BUMP_SERIAL_NO); entityObjForBump.Add("REMARK", REMARK); ORDER_LIST_DETAIL excelOrderListDetailEntity = entityObjForBump.ToObject <ORDER_LIST_DETAIL>(); var orderListDetailEntity = myContext.ORDER_LIST_DETAIL .Where(d => d.ORDER_NO.Equals(excelOrderListDetailEntity.ORDER_NO)) .Where(d => d.BUMP_ID.Equals(excelOrderListDetailEntity.BUMP_ID)); if (orderListDetailEntity.Count() == 0) { // INSERT myContext.ORDER_LIST_DETAIL.Add(excelOrderListDetailEntity); // 以后有可能做一个FLG,到水泵信息保存完成后再保存更改 myContext.SaveChanges(); } else { orderListDetailEntity.First().BUMP_NM = excelOrderListDetailEntity.BUMP_NM; orderListDetailEntity.First().STATION = excelOrderListDetailEntity.STATION; orderListDetailEntity.First().BUMP_TYPE = excelOrderListDetailEntity.BUMP_TYPE; orderListDetailEntity.First().NUMBER = excelOrderListDetailEntity.NUMBER; orderListDetailEntity.First().FLOW = excelOrderListDetailEntity.FLOW; orderListDetailEntity.First().LIFT = excelOrderListDetailEntity.LIFT; orderListDetailEntity.First().MATERIAL = excelOrderListDetailEntity.MATERIAL; orderListDetailEntity.First().SEAL = excelOrderListDetailEntity.SEAL; orderListDetailEntity.First().BUMP_SERIAL_NO = excelOrderListDetailEntity.BUMP_SERIAL_NO; orderListDetailEntity.First().REMARK = excelOrderListDetailEntity.REMARK; myContext.SaveChanges(); } } } } } return(String.Empty); } catch (System.Exception ex) { return("Upload Failed: " + ex.Message); } }
public ActionResult <string> UploadFile() { try { var file = Request.Form.Files[0]; string folderName = "UploadExcel"; string contentRootPath = _hostingEnvironment.ContentRootPath; string newPath = Path.Combine(contentRootPath, folderName); if (!Directory.Exists(newPath)) { Directory.CreateDirectory(newPath); } if (file.Length > 0) { string fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); string fullPath = Path.Combine(newPath, fileName); using (FileStream stream = new FileStream(fullPath, FileMode.Create)) { file.CopyTo(stream); IWorkbook workbook = WorkbookFactory.Create(stream); ISheet sheet = workbook.GetSheetAt(0); if (sheet != null) { /* * 订单信息 */ // 订单编号 String ORDER_NO = getCellValue(sheet, ColumnIndex.C, 3, CELL_TYP_STRING); if (String.IsNullOrEmpty(ORDER_NO)) { // 订单号(主键)为空时,直接返回 return("OrderNo is empty."); } // 合同编号 String CONTRACT_NO = getCellValue(sheet, ColumnIndex.C, 4, CELL_TYP_STRING); // 项目名称 String PROJECT_NM = getCellValue(sheet, ColumnIndex.C, 5, CELL_TYP_STRING); // 销售部门/销售员 String SALES_PERSON = getCellValue(sheet, ColumnIndex.C, 6, CELL_TYP_STRING); // 付款方式 String PAYMENT = getCellValue(sheet, ColumnIndex.C, 7, CELL_TYP_STRING); // 订货单位 String ORDER_UNIT = getCellValue(sheet, ColumnIndex.C, 8, CELL_TYP_STRING); // 应用工程师 String APPLICATION_ENGINEER = getCellValue(sheet, ColumnIndex.F, 3, CELL_TYP_STRING); // 下发日期 String DEPARTURE_DATE_STR = getCellValue(sheet, ColumnIndex.F, 4, CELL_TYP_DATE); // 交货日期 String DELIVERY_DATE_STR = getCellValue(sheet, ColumnIndex.F, 5, CELL_TYP_DATE); // 交货期 String GUARANTEE_DATE = getCellValue(sheet, ColumnIndex.F, 6, CELL_TYP_DATE); // 调试 String DEBUG = getCellValue(sheet, ColumnIndex.I, 3, CELL_TYP_STRING); var Dict_DEBUG = myContext.M_DICT.Where(d => d.DICT_NAME.Equals(DEBUG)).Where(e => e.TYPE.Equals("01")); DEBUG = Dict_DEBUG.Count() == 0 ? "" : Dict_DEBUG.First().DICT_ID; // 总数量 String TOTAL_QTY = getCellValue(sheet, ColumnIndex.I, 4, CELL_TYP_NUMBER); int iTOTAL_QTY = int.TryParse(TOTAL_QTY, out iTOTAL_QTY) == true ? iTOTAL_QTY : 0; // 税率 String TEX_RATE = getCellValue(sheet, ColumnIndex.I, 5, CELL_TYP_NUMBER); var Dict_TEX_RATE = myContext.M_DICT.Where(d => d.DICT_NAME.Equals(TEX_RATE)).Where(e => e.TYPE.Equals("02")); TEX_RATE = Dict_TEX_RATE.Count() == 0 ? "" : Dict_TEX_RATE.First().DICT_ID; // 合同总额 String TOTAL_AMT = getCellValue(sheet, ColumnIndex.I, 6, CELL_TYP_NUMBER); int iTOTAL_AMT = int.TryParse(TOTAL_AMT, out iTOTAL_AMT) == true ? iTOTAL_AMT : 0; // 目标价 String TARGET_PRICE = getCellValue(sheet, ColumnIndex.I, 7, CELL_TYP_NUMBER); int iTARGET_PRICE = int.TryParse(TARGET_PRICE, out iTARGET_PRICE) == true ? iTARGET_PRICE : 0; // 折扣 String DISCOUNT = getCellValue(sheet, ColumnIndex.I, 8, CELL_TYP_NUMBER); int iDISCOUNT = int.TryParse(DISCOUNT, out iDISCOUNT) == true ? iDISCOUNT : 0; // 构造JObject,并保存订单信息至数据库中 JObject entityObjForOrder = new JObject(); entityObjForOrder.Add("ORDER_NO", ORDER_NO); entityObjForOrder.Add("CONTRACT_NO", CONTRACT_NO); entityObjForOrder.Add("PROJECT_NM", PROJECT_NM); entityObjForOrder.Add("SALES_PERSON", SALES_PERSON); entityObjForOrder.Add("PAYMENT", PAYMENT); entityObjForOrder.Add("ORDER_UNIT", ORDER_UNIT); entityObjForOrder.Add("APPLICATION_ENGINEER", APPLICATION_ENGINEER); entityObjForOrder.Add("DEPARTURE_DATE", Convert.ToDateTime(DEPARTURE_DATE_STR)); entityObjForOrder.Add("DELIVERY_DATE", Convert.ToDateTime(DELIVERY_DATE_STR)); entityObjForOrder.Add("GUARANTEE_DATE", Convert.ToDateTime(GUARANTEE_DATE)); entityObjForOrder.Add("DEBUG", DEBUG); entityObjForOrder.Add("TOTAL_QTY", iTOTAL_QTY); entityObjForOrder.Add("TEX_RATE", TEX_RATE); entityObjForOrder.Add("TOTAL_AMT", iTOTAL_AMT); entityObjForOrder.Add("TARGET_PRICE", iTARGET_PRICE); entityObjForOrder.Add("DISCOUNT", iDISCOUNT); ORDER_LIST_MST excelOrderListMstEntity = entityObjForOrder.ToObject <ORDER_LIST_MST>(); var orderListMstEntity = myContext.ORDER_LIST_MST.Where(d => d.ORDER_NO.Equals(excelOrderListMstEntity.ORDER_NO)); if (orderListMstEntity.Count() == 0) { // INSERT myContext.ORDER_LIST_MST.Add(excelOrderListMstEntity); // 以后有可能做一个FLG,到水泵信息保存完成后再保存更改 myContext.SaveChanges(); } else { orderListMstEntity.First().CONTRACT_NO = excelOrderListMstEntity.CONTRACT_NO; orderListMstEntity.First().PROJECT_NM = excelOrderListMstEntity.PROJECT_NM; orderListMstEntity.First().ORDER_UNIT = excelOrderListMstEntity.ORDER_UNIT; orderListMstEntity.First().SALES_PERSON = excelOrderListMstEntity.SALES_PERSON; orderListMstEntity.First().DEPARTURE_DATE = excelOrderListMstEntity.DEPARTURE_DATE.ToLocalTime(); orderListMstEntity.First().DELIVERY_DATE = excelOrderListMstEntity.DELIVERY_DATE.ToLocalTime(); orderListMstEntity.First().REMARK = excelOrderListMstEntity.REMARK; orderListMstEntity.First().APPLICATION_ENGINEER = excelOrderListMstEntity.APPLICATION_ENGINEER; orderListMstEntity.First().DEBUG = excelOrderListMstEntity.DEBUG; orderListMstEntity.First().TOTAL_QTY = excelOrderListMstEntity.TOTAL_QTY; orderListMstEntity.First().TEX_RATE = excelOrderListMstEntity.TEX_RATE; orderListMstEntity.First().GUARANTEE_DATE = excelOrderListMstEntity.GUARANTEE_DATE.ToLocalTime(); orderListMstEntity.First().TOTAL_AMT = excelOrderListMstEntity.TOTAL_AMT; orderListMstEntity.First().PAYMENT = excelOrderListMstEntity.PAYMENT; orderListMstEntity.First().TARGET_PRICE = excelOrderListMstEntity.TARGET_PRICE; orderListMstEntity.First().DISCOUNT = excelOrderListMstEntity.DISCOUNT; orderListMstEntity.First().CHANGE_HIS1 = excelOrderListMstEntity.CHANGE_HIS1; orderListMstEntity.First().CHANGE_HIS2 = excelOrderListMstEntity.CHANGE_HIS2; myContext.SaveChanges(); } /* * 随货资料 */ // 合格证 String QUALIFICATION = getCellValue(sheet, ColumnIndex.A, 13, CELL_TYP_STRING); var Dict_QUALIFICATION = myContext.M_DICT.Where(d => d.DICT_NAME.Equals(QUALIFICATION)).Where(e => e.TYPE.Equals("18")); QUALIFICATION = Dict_QUALIFICATION.Count() == 0 ? "" : Dict_QUALIFICATION.First().DICT_ID; // 说明书 String IDENTIFICATION = getCellValue(sheet, ColumnIndex.B, 13, CELL_TYP_STRING); var Dict_IDENTIFICATION = myContext.M_DICT.Where(d => d.DICT_NAME.Equals(IDENTIFICATION)).Where(e => e.TYPE.Equals("19")); IDENTIFICATION = Dict_IDENTIFICATION.Count() == 0 ? "" : Dict_IDENTIFICATION.First().DICT_ID; // 产品样本 String PRODUCT_SAMPLE = getCellValue(sheet, ColumnIndex.C, 13, CELL_TYP_STRING); var Dict_PRODUCT_SAMPLE = myContext.M_DICT.Where(d => d.DICT_NAME.Equals(PRODUCT_SAMPLE)).Where(e => e.TYPE.Equals("20")); PRODUCT_SAMPLE = Dict_PRODUCT_SAMPLE.Count() == 0 ? "" : Dict_PRODUCT_SAMPLE.First().DICT_ID; // 动平衡报告 String DYNAMIC_REPORT = getCellValue(sheet, ColumnIndex.D, 13, CELL_TYP_STRING); var Dict_DYNAMIC_REPORT = myContext.M_DICT.Where(d => d.DICT_NAME.Equals(DYNAMIC_REPORT)).Where(e => e.TYPE.Equals("21")); DYNAMIC_REPORT = Dict_DYNAMIC_REPORT.Count() == 0 ? "" : Dict_DYNAMIC_REPORT.First().DICT_ID; // 静压试验报告 String STATIC_REPORT = getCellValue(sheet, ColumnIndex.E, 13, CELL_TYP_STRING); var Dict_STATIC_REPORT = myContext.M_DICT.Where(d => d.DICT_NAME.Equals(STATIC_REPORT)).Where(e => e.TYPE.Equals("22")); STATIC_REPORT = Dict_STATIC_REPORT.Count() == 0 ? "" : Dict_STATIC_REPORT.First().DICT_ID; // 性能试验报告 String PERFORMANCE_REPORT = getCellValue(sheet, ColumnIndex.F, 13, CELL_TYP_STRING); var Dict_PERFORMANCE_REPORT = myContext.M_DICT.Where(d => d.DICT_NAME.Equals(PERFORMANCE_REPORT)).Where(e => e.TYPE.Equals("23")); PERFORMANCE_REPORT = Dict_PERFORMANCE_REPORT.Count() == 0 ? "" : Dict_PERFORMANCE_REPORT.First().DICT_ID; // 图纸 String BLUEPRINT = getCellValue(sheet, ColumnIndex.G, 13, CELL_TYP_STRING); var Dict_BLUEPRINT = myContext.M_DICT.Where(d => d.DICT_NAME.Equals(BLUEPRINT)).Where(e => e.TYPE.Equals("24")); BLUEPRINT = Dict_BLUEPRINT.Count() == 0 ? "" : Dict_BLUEPRINT.First().DICT_ID; // 性能曲线 String PERFORMANCE_CURVE = getCellValue(sheet, ColumnIndex.H, 13, CELL_TYP_STRING); var Dict_PERFORMANCE_CURVE = myContext.M_DICT.Where(d => d.DICT_NAME.Equals(PERFORMANCE_CURVE)).Where(e => e.TYPE.Equals("25")); PERFORMANCE_CURVE = Dict_PERFORMANCE_CURVE.Count() == 0 ? "" : Dict_PERFORMANCE_CURVE.First().DICT_ID; // 其它可手动添加 String OTHER = getCellValue(sheet, ColumnIndex.I, 13, CELL_TYP_STRING); // 构造JObject,并保存订单信息至数据库中 JObject entityObjForAttach = new JObject(); entityObjForAttach.Add("ORDER_NO", ORDER_NO); entityObjForAttach.Add("QUALIFICATION", QUALIFICATION); entityObjForAttach.Add("IDENTIFICATION", IDENTIFICATION); entityObjForAttach.Add("PRODUCT_SAMPLE", PRODUCT_SAMPLE); entityObjForAttach.Add("DYNAMIC_REPORT", DYNAMIC_REPORT); entityObjForAttach.Add("STATIC_REPORT", STATIC_REPORT); entityObjForAttach.Add("PERFORMANCE_REPORT", PERFORMANCE_REPORT); entityObjForAttach.Add("BLUEPRINT", BLUEPRINT); entityObjForAttach.Add("PERFORMANCE_CURVE", PERFORMANCE_CURVE); entityObjForAttach.Add("OTHER", OTHER); ORDER_LIST_ATTACHMENT excelOrderListAttchmentEntity = entityObjForAttach.ToObject <ORDER_LIST_ATTACHMENT>(); var orderListAttachmentEntity = myContext.ORDER_LIST_ATTACHMENT.Where(d => d.ORDER_NO.Equals(excelOrderListAttchmentEntity.ORDER_NO)); if (orderListAttachmentEntity.Count() == 0) { // INSERT myContext.ORDER_LIST_ATTACHMENT.Add(excelOrderListAttchmentEntity); // 以后有可能做一个FLG,到水泵信息保存完成后再保存更改 myContext.SaveChanges(); } else { orderListAttachmentEntity.First().QUALIFICATION = excelOrderListAttchmentEntity.QUALIFICATION; orderListAttachmentEntity.First().IDENTIFICATION = excelOrderListAttchmentEntity.IDENTIFICATION; orderListAttachmentEntity.First().PRODUCT_SAMPLE = excelOrderListAttchmentEntity.PRODUCT_SAMPLE; orderListAttachmentEntity.First().DYNAMIC_REPORT = excelOrderListAttchmentEntity.DYNAMIC_REPORT; orderListAttachmentEntity.First().STATIC_REPORT = excelOrderListAttchmentEntity.STATIC_REPORT; orderListAttachmentEntity.First().PERFORMANCE_REPORT = excelOrderListAttchmentEntity.PERFORMANCE_REPORT; orderListAttachmentEntity.First().BLUEPRINT = excelOrderListAttchmentEntity.BLUEPRINT; orderListAttachmentEntity.First().PERFORMANCE_CURVE = excelOrderListAttchmentEntity.PERFORMANCE_CURVE; orderListAttachmentEntity.First().OTHER = excelOrderListAttchmentEntity.OTHER; myContext.SaveChanges(); } /* * 水泵信息 */ int i = 0; while (true) { // 序号(校验用) String NO = getCellValue(sheet, ColumnIndex.A, (BUMP_OFFSET + i), CELL_TYP_STRING); // 序号校验(还应考虑不是数字Convert失败的情况,未写) if (NO.ToString().Trim().Equals("合计")) { break; } if (Convert.ToInt32(NO) != i + 1) { return(""); } // 泵名称 String BUMP_NM = getCellValue(sheet, ColumnIndex.B, (BUMP_OFFSET + i), CELL_TYP_STRING); // 型号 String BUMP_TYPE = getCellValue(sheet, ColumnIndex.C, (BUMP_OFFSET + i), CELL_TYP_STRING); // 数量 String NUMBER = getCellValue(sheet, ColumnIndex.D, (BUMP_OFFSET + i), CELL_TYP_NUMBER); int iNUMBER = int.TryParse(NUMBER, out iNUMBER) == true ? iNUMBER : 0; // 单位 String UNIT = getCellValue(sheet, ColumnIndex.E, (BUMP_OFFSET + i), CELL_TYP_STRING); // 单价 String PRICE = getCellValue(sheet, ColumnIndex.F, (BUMP_OFFSET + i), CELL_TYP_NUMBER); int iPRICE = int.TryParse(PRICE, out iPRICE) == true ? iPRICE : 0; // 金额 String AMOUNT = getCellValue(sheet, ColumnIndex.G, (BUMP_OFFSET + i), CELL_TYP_NUMBER); int iAMOUNT = int.TryParse(AMOUNT, out iAMOUNT) == true ? iAMOUNT : 0; // 序列号 String BUMP_SERIAL_NO = getCellValue(sheet, ColumnIndex.H, (BUMP_OFFSET + i), CELL_TYP_STRING); // 流量 String FLOW = getCellValue(sheet, ColumnIndex.I, (BUMP_OFFSET + i), CELL_TYP_NUMBER); int iFLOW = int.TryParse(FLOW, out iFLOW) == true ? iFLOW : 0; // 扬程 String LIFT = getCellValue(sheet, ColumnIndex.J, (BUMP_OFFSET + i), CELL_TYP_NUMBER); int iLIFT = int.TryParse(LIFT, out iLIFT) == true ? iLIFT : 0; // 材质 泵体 String MATERIAL_BUMP = getCellValue(sheet, ColumnIndex.K, (BUMP_OFFSET + i), CELL_TYP_STRING); // 材质 叶轮 String MATERIAL_FAN = getCellValue(sheet, ColumnIndex.L, (BUMP_OFFSET + i), CELL_TYP_STRING); // 材质 轴 String MATERIAL_ROLLER = getCellValue(sheet, ColumnIndex.M, (BUMP_OFFSET + i), CELL_TYP_STRING); // 电机 品牌 String MOTOR_BRAND = getCellValue(sheet, ColumnIndex.N, (BUMP_OFFSET + i), CELL_TYP_STRING); var Dict_MOTOR_BRAND = myContext.M_DICT.Where(d => d.DICT_NAME.Equals(MOTOR_BRAND)).Where(e => e.TYPE.Equals("03")); MOTOR_BRAND = Dict_MOTOR_BRAND.Count() == 0 ? "" : Dict_MOTOR_BRAND.First().DICT_ID; // 电机 要求 String MOTOR_DEMAND = getCellValue(sheet, ColumnIndex.O, (BUMP_OFFSET + i), CELL_TYP_STRING); // 密封/液下深度(BY&SBY) 形式 String SEAL_FORM = getCellValue(sheet, ColumnIndex.P, (BUMP_OFFSET + i), CELL_TYP_STRING); var Dict_SEAL_FORM = myContext.M_DICT.Where(d => d.DICT_NAME.Equals(SEAL_FORM)).Where(e => e.TYPE.Equals("04")); SEAL_FORM = Dict_SEAL_FORM.Count() == 0 ? "" : Dict_SEAL_FORM.First().DICT_ID; // 密封/液下深度(BY&SBY) 品牌/其它 String SEAL_BRAND = getCellValue(sheet, ColumnIndex.Q, (BUMP_OFFSET + i), CELL_TYP_STRING); var Dict_SEAL_BRAND = myContext.M_DICT.Where(d => d.DICT_NAME.Equals(SEAL_BRAND)).Where(e => e.TYPE.Equals("05")); SEAL_BRAND = Dict_SEAL_BRAND.Count() == 0 ? "" : Dict_SEAL_BRAND.First().DICT_ID; // 轴承品牌 String ROLLER_BRAND = getCellValue(sheet, ColumnIndex.R, (BUMP_OFFSET + i), CELL_TYP_STRING); var Dict_ROLLER_BRAND = myContext.M_DICT.Where(d => d.DICT_NAME.Equals(ROLLER_BRAND)).Where(e => e.TYPE.Equals("06")); ROLLER_BRAND = Dict_ROLLER_BRAND.Count() == 0 ? "" : Dict_ROLLER_BRAND.First().DICT_ID; // 联轴器 String COUPLING = getCellValue(sheet, ColumnIndex.S, (BUMP_OFFSET + i), CELL_TYP_STRING); var Dict_COUPLING = myContext.M_DICT.Where(d => d.DICT_NAME.Equals(COUPLING)).Where(e => e.TYPE.Equals("07")); COUPLING = Dict_COUPLING.Count() == 0 ? "" : Dict_COUPLING.First().DICT_ID; // 机封冷却器 String SEAL_COOLER = getCellValue(sheet, ColumnIndex.T, (BUMP_OFFSET + i), CELL_TYP_STRING); var Dict_SEAL_COOLER = myContext.M_DICT.Where(d => d.DICT_NAME.Equals(SEAL_COOLER)).Where(e => e.TYPE.Equals("03")); SEAL_COOLER = Dict_SEAL_COOLER.Count() == 0 ? "" : Dict_SEAL_COOLER.First().DICT_ID; // 装置汽蚀余量 String CAVITATION_ALLOWANCE = getCellValue(sheet, ColumnIndex.U, (BUMP_OFFSET + i), CELL_TYP_STRING); int iCAVITATION_ALLOWANCE = int.TryParse(CAVITATION_ALLOWANCE, out iCAVITATION_ALLOWANCE) == true ? iCAVITATION_ALLOWANCE : 0; // 泵实际转速 String ACTUAL_BUMP_SPEED = getCellValue(sheet, ColumnIndex.V, (BUMP_OFFSET + i), CELL_TYP_NUMBER); int iACTUAL_BUMP_SPEED = int.TryParse(ACTUAL_BUMP_SPEED, out iACTUAL_BUMP_SPEED) == true ? iACTUAL_BUMP_SPEED : 0; // 工位 String STATION = getCellValue(sheet, ColumnIndex.W, (BUMP_OFFSET + i), CELL_TYP_STRING); // 温度 String TEMPERATURE = getCellValue(sheet, ColumnIndex.X, (BUMP_OFFSET + i), CELL_TYP_NUMBER); int iTEMPERATURE = int.TryParse(TEMPERATURE, out iTEMPERATURE) == true ? iTEMPERATURE : 0; // 密度 String DENSITY = getCellValue(sheet, ColumnIndex.Y, (BUMP_OFFSET + i), CELL_TYP_STRING); // 入口压力 String IN_PRESSURE = getCellValue(sheet, ColumnIndex.Z, (BUMP_OFFSET + i), CELL_TYP_NUMBER); int iIN_PRESSURE = int.TryParse(IN_PRESSURE, out iIN_PRESSURE) == true ? iIN_PRESSURE : 0; // 介质 String MEDIUM = getCellValue(sheet, ColumnIndex.AA, (BUMP_OFFSET + i), CELL_TYP_STRING); // 粘度 String VISCOSITY = getCellValue(sheet, ColumnIndex.AB, (BUMP_OFFSET + i), CELL_TYP_NUMBER); int iVISCOSITY = int.TryParse(VISCOSITY, out iVISCOSITY) == true ? iVISCOSITY : 0; // 含颗粒情况 String PARTICULATES = getCellValue(sheet, ColumnIndex.AC, (BUMP_OFFSET + i), CELL_TYP_STRING); // 工作压力(bar) String WORKING_PRESSURE = getCellValue(sheet, ColumnIndex.AD, (BUMP_OFFSET + i), CELL_TYP_NUMBER); int iWORKING_PRESSURE = int.TryParse(WORKING_PRESSURE, out iWORKING_PRESSURE) == true ? iWORKING_PRESSURE : 0; // 法兰标准 String FLANGES_STANDARD = getCellValue(sheet, ColumnIndex.AE, (BUMP_OFFSET + i), CELL_TYP_STRING); var Dict_FLANGES_STANDARD = myContext.M_DICT.Where(d => d.DICT_NAME.Equals(FLANGES_STANDARD)).Where(e => e.TYPE.Equals("03")); FLANGES_STANDARD = Dict_FLANGES_STANDARD.Count() == 0 ? "" : Dict_FLANGES_STANDARD.First().DICT_ID; // 法兰等级(MPH/MPE) String FLANGES_LEVEL = getCellValue(sheet, ColumnIndex.AF, (BUMP_OFFSET + i), CELL_TYP_STRING); var Dict_FLANGES_LEVEL = myContext.M_DICT.Where(d => d.DICT_NAME.Equals(FLANGES_LEVEL)).Where(e => e.TYPE.Equals("03")); FLANGES_LEVEL = Dict_FLANGES_LEVEL.Count() == 0 ? "" : Dict_FLANGES_LEVEL.First().DICT_ID; // 底座 String BASE = getCellValue(sheet, ColumnIndex.AG, (BUMP_OFFSET + i), CELL_TYP_STRING); var Dict_BASE = myContext.M_DICT.Where(d => d.DICT_NAME.Equals(BASE)).Where(e => e.TYPE.Equals("03")); BASE = Dict_BASE.Count() == 0 ? "" : Dict_BASE.First().DICT_ID; // 联轴器罩 String COUPLING_HOOD = getCellValue(sheet, ColumnIndex.AH, (BUMP_OFFSET + i), CELL_TYP_STRING); var Dict_COUPLING_HOOD = myContext.M_DICT.Where(d => d.DICT_NAME.Equals(COUPLING_HOOD)).Where(e => e.TYPE.Equals("03")); COUPLING_HOOD = Dict_COUPLING_HOOD.Count() == 0 ? "" : Dict_COUPLING_HOOD.First().DICT_ID; // 地脚螺栓 String ANCHOR_BOLT = getCellValue(sheet, ColumnIndex.AI, (BUMP_OFFSET + i), CELL_TYP_STRING); var Dict_ANCHOR_BOLT = myContext.M_DICT.Where(d => d.DICT_NAME.Equals(ANCHOR_BOLT)).Where(e => e.TYPE.Equals("03")); ANCHOR_BOLT = Dict_ANCHOR_BOLT.Count() == 0 ? "" : Dict_ANCHOR_BOLT.First().DICT_ID; // 油漆 String PAINT = getCellValue(sheet, ColumnIndex.AJ, (BUMP_OFFSET + i), CELL_TYP_STRING); var Dict_PAINT = myContext.M_DICT.Where(d => d.DICT_NAME.Equals(PAINT)).Where(e => e.TYPE.Equals("03")); PAINT = Dict_PAINT.Count() == 0 ? "" : Dict_PAINT.First().DICT_ID; // 表面特殊处理 String SURFACE_TREATMENT = getCellValue(sheet, ColumnIndex.AK, (BUMP_OFFSET + i), CELL_TYP_STRING); var Dict_SURFACE_TREATMENT = myContext.M_DICT.Where(d => d.DICT_NAME.Equals(SURFACE_TREATMENT)).Where(e => e.TYPE.Equals("03")); SURFACE_TREATMENT = Dict_SURFACE_TREATMENT.Count() == 0 ? "" : Dict_SURFACE_TREATMENT.First().DICT_ID; // 包装 String PACKAGE = getCellValue(sheet, ColumnIndex.AL, (BUMP_OFFSET + i), CELL_TYP_STRING); var Dict_PACKAGE = myContext.M_DICT.Where(d => d.DICT_NAME.Equals(PACKAGE)).Where(e => e.TYPE.Equals("03")); PACKAGE = Dict_PACKAGE.Count() == 0 ? "" : Dict_PACKAGE.First().DICT_ID; // 运输 String TRANSPORT = getCellValue(sheet, ColumnIndex.AM, (BUMP_OFFSET + i), CELL_TYP_STRING); var Dict_TRANSPORT = myContext.M_DICT.Where(d => d.DICT_NAME.Equals(TRANSPORT)).Where(e => e.TYPE.Equals("03")); TRANSPORT = Dict_TRANSPORT.Count() == 0 ? "" : Dict_TRANSPORT.First().DICT_ID; // 构造水泵ID String BUMP_ID = ""; if (String.IsNullOrEmpty(BUMP_TYPE) || String.IsNullOrEmpty(MATERIAL_BUMP)) { return("BumpType or material is empty."); } else { BUMP_ID = BUMP_TYPE + "_" + MATERIAL_BUMP; } // 构造JObject,并保存水泵信息至数据库中 JObject entityObjForBump = new JObject(); entityObjForBump.Add("ORDER_NO", ORDER_NO); entityObjForBump.Add("BUMP_ID", BUMP_ID); entityObjForBump.Add("BUMP_NM", BUMP_NM); entityObjForBump.Add("BUMP_TYPE", BUMP_TYPE); entityObjForBump.Add("NUMBER", iNUMBER); entityObjForBump.Add("UNIT", UNIT); entityObjForBump.Add("PRICE", iPRICE); entityObjForBump.Add("AMOUNT", iAMOUNT); entityObjForBump.Add("BUMP_SERIAL_NO", BUMP_SERIAL_NO); entityObjForBump.Add("FLOW", iFLOW); entityObjForBump.Add("LIFT", iLIFT); entityObjForBump.Add("MATERIAL_BUMP", MATERIAL_BUMP); entityObjForBump.Add("MATERIAL_FAN", MATERIAL_FAN); entityObjForBump.Add("MATERIAL_ROLLER", MATERIAL_ROLLER); entityObjForBump.Add("MOTOR_BRAND", MOTOR_BRAND); entityObjForBump.Add("MOTOR_DEMAND", MOTOR_DEMAND); entityObjForBump.Add("SEAL_FORM", SEAL_FORM); entityObjForBump.Add("SEAL_BRAND", SEAL_BRAND); entityObjForBump.Add("ROLLER_BRAND", ROLLER_BRAND); entityObjForBump.Add("COUPLING", COUPLING); entityObjForBump.Add("SEAL_COOLER", SEAL_COOLER); entityObjForBump.Add("CAVITATION_ALLOWANCE", iCAVITATION_ALLOWANCE); entityObjForBump.Add("ACTUAL_BUMP_SPEED", iACTUAL_BUMP_SPEED); entityObjForBump.Add("STATION", STATION); entityObjForBump.Add("TEMPERATURE", iTEMPERATURE); entityObjForBump.Add("DENSITY", DENSITY); entityObjForBump.Add("IN_PRESSURE", iIN_PRESSURE); entityObjForBump.Add("MEDIUM", MEDIUM); entityObjForBump.Add("VISCOSITY", iVISCOSITY); entityObjForBump.Add("PARTICULATES", PARTICULATES); entityObjForBump.Add("WORKING_PRESSURE", iWORKING_PRESSURE); entityObjForBump.Add("FLANGES_STANDARD", FLANGES_STANDARD); entityObjForBump.Add("FLANGES_LEVEL", FLANGES_LEVEL); entityObjForBump.Add("BASE", BASE); entityObjForBump.Add("COUPLING_HOOD", COUPLING_HOOD); entityObjForBump.Add("ANCHOR_BOLT", ANCHOR_BOLT); entityObjForBump.Add("PAINT", PAINT); entityObjForBump.Add("SURFACE_TREATMENT", SURFACE_TREATMENT); entityObjForBump.Add("PACKAGE", PACKAGE); entityObjForBump.Add("TRANSPORT", TRANSPORT); ORDER_LIST_DETAIL excelOrderListDetailEntity = entityObjForBump.ToObject <ORDER_LIST_DETAIL>(); var orderListDetailEntity = myContext.ORDER_LIST_DETAIL .Where(d => d.ORDER_NO.Equals(excelOrderListDetailEntity.ORDER_NO)) .Where(d => d.BUMP_ID.Equals(excelOrderListDetailEntity.BUMP_ID)); if (orderListDetailEntity.Count() == 0) { // INSERT myContext.ORDER_LIST_DETAIL.Add(excelOrderListDetailEntity); // 以后有可能做一个FLG,到水泵信息保存完成后再保存更改 myContext.SaveChanges(); } else { orderListDetailEntity.First().BUMP_NM = excelOrderListDetailEntity.BUMP_NM; orderListDetailEntity.First().BUMP_TYPE = excelOrderListDetailEntity.BUMP_TYPE; orderListDetailEntity.First().NUMBER = excelOrderListDetailEntity.NUMBER; orderListDetailEntity.First().UNIT = excelOrderListDetailEntity.UNIT; orderListDetailEntity.First().PRICE = excelOrderListDetailEntity.PRICE; orderListDetailEntity.First().AMOUNT = excelOrderListDetailEntity.AMOUNT; orderListDetailEntity.First().BUMP_SERIAL_NO = excelOrderListDetailEntity.BUMP_SERIAL_NO; orderListDetailEntity.First().FLOW = excelOrderListDetailEntity.FLOW; orderListDetailEntity.First().LIFT = excelOrderListDetailEntity.LIFT; orderListDetailEntity.First().MATERIAL_BUMP = excelOrderListDetailEntity.MATERIAL_BUMP; orderListDetailEntity.First().MATERIAL_FAN = excelOrderListDetailEntity.MATERIAL_FAN; orderListDetailEntity.First().MATERIAL_ROLLER = excelOrderListDetailEntity.MATERIAL_ROLLER; orderListDetailEntity.First().MOTOR_BRAND = excelOrderListDetailEntity.MOTOR_BRAND; orderListDetailEntity.First().MOTOR_DEMAND = excelOrderListDetailEntity.MOTOR_DEMAND; orderListDetailEntity.First().SEAL_FORM = excelOrderListDetailEntity.SEAL_FORM; orderListDetailEntity.First().SEAL_BRAND = excelOrderListDetailEntity.SEAL_BRAND; orderListDetailEntity.First().ROLLER_BRAND = excelOrderListDetailEntity.ROLLER_BRAND; orderListDetailEntity.First().COUPLING = excelOrderListDetailEntity.COUPLING; orderListDetailEntity.First().SEAL_COOLER = excelOrderListDetailEntity.SEAL_COOLER; orderListDetailEntity.First().CAVITATION_ALLOWANCE = excelOrderListDetailEntity.CAVITATION_ALLOWANCE; orderListDetailEntity.First().ACTUAL_BUMP_SPEED = excelOrderListDetailEntity.ACTUAL_BUMP_SPEED; orderListDetailEntity.First().STATION = excelOrderListDetailEntity.STATION; orderListDetailEntity.First().TEMPERATURE = excelOrderListDetailEntity.TEMPERATURE; orderListDetailEntity.First().DENSITY = excelOrderListDetailEntity.DENSITY; orderListDetailEntity.First().IN_PRESSURE = excelOrderListDetailEntity.IN_PRESSURE; orderListDetailEntity.First().MEDIUM = excelOrderListDetailEntity.MEDIUM; orderListDetailEntity.First().VISCOSITY = excelOrderListDetailEntity.VISCOSITY; orderListDetailEntity.First().PARTICULATES = excelOrderListDetailEntity.PARTICULATES; orderListDetailEntity.First().WORKING_PRESSURE = excelOrderListDetailEntity.WORKING_PRESSURE; orderListDetailEntity.First().FLANGES_STANDARD = excelOrderListDetailEntity.FLANGES_STANDARD; orderListDetailEntity.First().FLANGES_LEVEL = excelOrderListDetailEntity.FLANGES_LEVEL; orderListDetailEntity.First().BASE = excelOrderListDetailEntity.BASE; orderListDetailEntity.First().COUPLING_HOOD = excelOrderListDetailEntity.COUPLING_HOOD; orderListDetailEntity.First().ANCHOR_BOLT = excelOrderListDetailEntity.ANCHOR_BOLT; orderListDetailEntity.First().PAINT = excelOrderListDetailEntity.PAINT; orderListDetailEntity.First().SURFACE_TREATMENT = excelOrderListDetailEntity.SURFACE_TREATMENT; orderListDetailEntity.First().PACKAGE = excelOrderListDetailEntity.PACKAGE; orderListDetailEntity.First().TRANSPORT = excelOrderListDetailEntity.TRANSPORT; myContext.SaveChanges(); } i++; } } } } return(String.Empty); } catch (System.Exception ex) { return("Upload Failed: " + ex.Message); } }
public ActionResult <string> Post([FromBody] JObject postObj) { // FROM WEB PAGE ORDER_LIST_DETAIL orderListDetailPostEntity = postObj.GetValue("orderListDetailTableModel").ToObject <ORDER_LIST_DETAIL>(); INNER_ORDER_BASIC_SEAL_MST innerOrderBasicSealPostEntity = postObj.GetValue("basicAndSealModel").ToObject <INNER_ORDER_BASIC_SEAL_MST>(); INNER_ORDER_OTHER_COMPONENT_MST innerOrderOtherComponentPostEntity = postObj.GetValue("otherComponentModel").ToObject <INNER_ORDER_OTHER_COMPONENT_MST>(); IList innerOrderBOMItemStandard = new ArrayList(); IList innerOrderBOMItemBase = new ArrayList(); if (postObj.GetValue("componentListTableData") != null) { innerOrderBOMItemStandard = postObj.GetValue("componentListTableData").ToList(); } if (postObj.GetValue("basicPartListTableData") != null) { innerOrderBOMItemBase = postObj.GetValue("basicPartListTableData").ToList(); } // 校验主键 if (String.IsNullOrEmpty(orderListDetailPostEntity.ORDER_NO) || String.IsNullOrEmpty(orderListDetailPostEntity.BUMP_ID)) { return(""); } // FROM DB // 登录BOM的GRID部分,先用SQL删除对应ID项目,之后批量插入 myContext.Database.ExecuteSqlCommand("DELETE FROM \"INNER_ORDER_BOM_ITEM_BASE\" WHERE \"ORDER_NO\" = @ORDER_NO AND \"BUMP_ID\" = @BUMP_ID", new NpgsqlParameter("@ORDER_NO", orderListDetailPostEntity.ORDER_NO), new NpgsqlParameter("@BUMP_ID", orderListDetailPostEntity.BUMP_ID)); myContext.Database.ExecuteSqlCommand("DELETE FROM \"INNER_ORDER_BOM_ITEM_STANDARD\" WHERE \"ORDER_NO\" = @ORDER_NO AND \"BUMP_ID\" = @BUMP_ID", new NpgsqlParameter("@ORDER_NO", orderListDetailPostEntity.ORDER_NO), new NpgsqlParameter("@BUMP_ID", orderListDetailPostEntity.BUMP_ID)); foreach (JObject item in innerOrderBOMItemStandard) { INNER_ORDER_BOM_ITEM_STANDARD itemEntity = item.ToObject <INNER_ORDER_BOM_ITEM_STANDARD>(); itemEntity.ORDER_NO = orderListDetailPostEntity.ORDER_NO; itemEntity.BUMP_ID = orderListDetailPostEntity.BUMP_ID; myContext.INNER_ORDER_BOM_ITEM_STANDARD.AddAsync(itemEntity); } foreach (JObject item in innerOrderBOMItemBase) { INNER_ORDER_BOM_ITEM_BASE itemEntity = item.ToObject <INNER_ORDER_BOM_ITEM_BASE>(); itemEntity.ORDER_NO = orderListDetailPostEntity.ORDER_NO; itemEntity.BUMP_ID = orderListDetailPostEntity.BUMP_ID; myContext.INNER_ORDER_BOM_ITEM_BASE.AddAsync(itemEntity); } myContext.SaveChanges(); var innerOrderbBasicSealMstEntity = myContext.INNER_ORDER_BASIC_SEAL_MST .Where(d => d.ORDER_NO.Equals(orderListDetailPostEntity.ORDER_NO) && d.BUMP_ID.Equals(orderListDetailPostEntity.BUMP_ID)); var innerOrderOtherComponentMstEntity = myContext.INNER_ORDER_OTHER_COMPONENT_MST .Where(d => d.ORDER_NO.Equals(orderListDetailPostEntity.ORDER_NO) && d.BUMP_ID.Equals(orderListDetailPostEntity.BUMP_ID)); if (innerOrderbBasicSealMstEntity.Count() == 0 && innerOrderOtherComponentMstEntity.Count() == 0) { // 补充项目 innerOrderBasicSealPostEntity.ORDER_NO = orderListDetailPostEntity.ORDER_NO; innerOrderBasicSealPostEntity.BUMP_ID = orderListDetailPostEntity.BUMP_ID; innerOrderBasicSealPostEntity.BUMP_TYPE = orderListDetailPostEntity.BUMP_TYPE; innerOrderBasicSealPostEntity.BUMP_SERIAL_NO = orderListDetailPostEntity.BUMP_SERIAL_NO; innerOrderBasicSealPostEntity.NUMBER = orderListDetailPostEntity.NUMBER; innerOrderBasicSealPostEntity.FLOW = orderListDetailPostEntity.FLOW; innerOrderBasicSealPostEntity.LIFT = orderListDetailPostEntity.LIFT; innerOrderBasicSealPostEntity.STATION = orderListDetailPostEntity.STATION; innerOrderOtherComponentPostEntity.ORDER_NO = orderListDetailPostEntity.ORDER_NO; innerOrderOtherComponentPostEntity.BUMP_ID = orderListDetailPostEntity.BUMP_ID; // TODO myContext.INNER_ORDER_OTHER_COMPONENT_MST.Add(innerOrderOtherComponentPostEntity); myContext.INNER_ORDER_BASIC_SEAL_MST.Add(innerOrderBasicSealPostEntity); myContext.SaveChanges(); return(""); } else { // 补充项目 innerOrderbBasicSealMstEntity.First().BUMP_TYPE = orderListDetailPostEntity.BUMP_TYPE; innerOrderbBasicSealMstEntity.First().BUMP_SERIAL_NO = orderListDetailPostEntity.BUMP_SERIAL_NO; innerOrderbBasicSealMstEntity.First().NUMBER = orderListDetailPostEntity.NUMBER; innerOrderbBasicSealMstEntity.First().FLOW = orderListDetailPostEntity.FLOW; innerOrderbBasicSealMstEntity.First().LIFT = orderListDetailPostEntity.LIFT; innerOrderbBasicSealMstEntity.First().STATION = orderListDetailPostEntity.STATION; // 其他项目 innerOrderbBasicSealMstEntity.First().WORKING_PRESSURE = innerOrderBasicSealPostEntity.WORKING_PRESSURE; innerOrderbBasicSealMstEntity.First().TEST_PRESSURE = innerOrderBasicSealPostEntity.TEST_PRESSURE; innerOrderbBasicSealMstEntity.First().SUPPRESS_PRESSURE = innerOrderBasicSealPostEntity.SUPPRESS_PRESSURE; innerOrderbBasicSealMstEntity.First().FLANGE_STANDARD = innerOrderBasicSealPostEntity.FLANGE_STANDARD; innerOrderbBasicSealMstEntity.First().NPSH = innerOrderBasicSealPostEntity.NPSH; innerOrderbBasicSealMstEntity.First().BUMP_SPEED = innerOrderBasicSealPostEntity.BUMP_SPEED; innerOrderbBasicSealMstEntity.First().MEDIA = innerOrderBasicSealPostEntity.MEDIA; innerOrderbBasicSealMstEntity.First().TEMPERATURE = innerOrderBasicSealPostEntity.TEMPERATURE; innerOrderbBasicSealMstEntity.First().VISCOSITY = innerOrderBasicSealPostEntity.VISCOSITY; innerOrderbBasicSealMstEntity.First().INLET_PRESSURE = innerOrderBasicSealPostEntity.INLET_PRESSURE; innerOrderbBasicSealMstEntity.First().PARTICULATES = innerOrderBasicSealPostEntity.PARTICULATES; innerOrderbBasicSealMstEntity.First().SEAL_TYPE = innerOrderBasicSealPostEntity.SEAL_TYPE; innerOrderbBasicSealMstEntity.First().SEAL_MODEL = innerOrderBasicSealPostEntity.SEAL_MODEL; innerOrderbBasicSealMstEntity.First().SEAL_MATERIAL = innerOrderBasicSealPostEntity.SEAL_MATERIAL; innerOrderbBasicSealMstEntity.First().ABD_SEAL_INFO = innerOrderBasicSealPostEntity.ABD_SEAL_INFO; innerOrderbBasicSealMstEntity.First().OTHER_SEAL_PROVIDER = innerOrderBasicSealPostEntity.OTHER_SEAL_PROVIDER; innerOrderbBasicSealMstEntity.First().OTHER_SEAL_INFO = innerOrderBasicSealPostEntity.OTHER_SEAL_INFO; innerOrderbBasicSealMstEntity.First().OTHER_SEAL_MODEL = innerOrderBasicSealPostEntity.OTHER_SEAL_MODEL; innerOrderbBasicSealMstEntity.First().NEED_SEAL_COOLER_FLG = innerOrderBasicSealPostEntity.NEED_SEAL_COOLER_FLG; innerOrderbBasicSealMstEntity.First().SEAL_COOLER_MODEL = innerOrderBasicSealPostEntity.SEAL_COOLER_MODEL; innerOrderbBasicSealMstEntity.First().BEARING_BRAND = innerOrderBasicSealPostEntity.BEARING_BRAND; innerOrderbBasicSealMstEntity.First().BEARING_OTHER_INFO = innerOrderBasicSealPostEntity.BEARING_OTHER_INFO; innerOrderbBasicSealMstEntity.First().INSTALL_DIRECTION = innerOrderBasicSealPostEntity.INSTALL_DIRECTION; innerOrderOtherComponentMstEntity.First().BASE_TYPE = innerOrderOtherComponentPostEntity.BASE_TYPE; innerOrderOtherComponentMstEntity.First().BASE_SPEC = innerOrderOtherComponentPostEntity.BASE_SPEC; innerOrderOtherComponentMstEntity.First().SPECIAL_BASE_DETAIL = innerOrderOtherComponentPostEntity.SPECIAL_BASE_DETAIL; innerOrderOtherComponentMstEntity.First().COUPLING_HOOD_TYPE = innerOrderOtherComponentPostEntity.COUPLING_HOOD_TYPE; innerOrderOtherComponentMstEntity.First().COUPLING_HOOD_SPEC = innerOrderOtherComponentPostEntity.COUPLING_HOOD_SPEC; innerOrderOtherComponentMstEntity.First().SPECIAL_HOOD_TYPE_DETAIL = innerOrderOtherComponentPostEntity.SPECIAL_HOOD_TYPE_DETAIL; innerOrderOtherComponentMstEntity.First().ANCHOR_BOLT_TYPE = innerOrderOtherComponentPostEntity.ANCHOR_BOLT_TYPE; innerOrderOtherComponentMstEntity.First().ANCHOR_BOLT_SPEC = innerOrderOtherComponentPostEntity.ANCHOR_BOLT_SPEC; innerOrderOtherComponentMstEntity.First().ANCHOR_BOLT_MATERIAL = innerOrderOtherComponentPostEntity.ANCHOR_BOLT_MATERIAL; innerOrderOtherComponentMstEntity.First().ANCHOR_BOLT_EXTRA_NUT_SPEC = innerOrderOtherComponentPostEntity.ANCHOR_BOLT_EXTRA_NUT_SPEC; innerOrderOtherComponentMstEntity.First().ANCHOR_BOLT_EXTRA_PAD_SPEC = innerOrderOtherComponentPostEntity.ANCHOR_BOLT_EXTRA_PAD_SPEC; innerOrderOtherComponentMstEntity.First().ANCHOR_BOLT_NUM = innerOrderOtherComponentPostEntity.ANCHOR_BOLT_NUM; innerOrderOtherComponentMstEntity.First().COUPLING_TYPE = innerOrderOtherComponentPostEntity.COUPLING_TYPE; innerOrderOtherComponentMstEntity.First().COUPLING_BUMP_COUPLET = innerOrderOtherComponentPostEntity.COUPLING_BUMP_COUPLET; innerOrderOtherComponentMstEntity.First().COUPLING_ELECTRIC_COUPLET = innerOrderOtherComponentPostEntity.COUPLING_ELECTRIC_COUPLET; innerOrderOtherComponentMstEntity.First().COUPLING_PIN = innerOrderOtherComponentPostEntity.COUPLING_PIN; innerOrderOtherComponentMstEntity.First().COUPLING_JUMP_RING = innerOrderOtherComponentPostEntity.COUPLING_JUMP_RING; innerOrderOtherComponentMstEntity.First().COUPLING_PROVIDER = innerOrderOtherComponentPostEntity.COUPLING_PROVIDER; innerOrderOtherComponentMstEntity.First().COUPLING_SPEC = innerOrderOtherComponentPostEntity.COUPLING_SPEC; innerOrderOtherComponentMstEntity.First().COUPLING_NUM = innerOrderOtherComponentPostEntity.COUPLING_NUM; innerOrderOtherComponentMstEntity.First().SPECIAL_COUPLING_TYPE_DETAIL = innerOrderOtherComponentPostEntity.SPECIAL_COUPLING_TYPE_DETAIL; innerOrderOtherComponentMstEntity.First().ELECTRIC_MOTER_TYPE = innerOrderOtherComponentPostEntity.ELECTRIC_MOTER_TYPE; innerOrderOtherComponentMstEntity.First().ELECTRIC_MOTER_PROVIDER = innerOrderOtherComponentPostEntity.ELECTRIC_MOTER_PROVIDER; innerOrderOtherComponentMstEntity.First().ELECTRIC_MOTER_POWER = innerOrderOtherComponentPostEntity.ELECTRIC_MOTER_POWER; innerOrderOtherComponentMstEntity.First().ELECTRIC_MOTER_SPEED = innerOrderOtherComponentPostEntity.ELECTRIC_MOTER_SPEED; innerOrderOtherComponentMstEntity.First().ELECTRIC_MOTER_PFV = innerOrderOtherComponentPostEntity.ELECTRIC_MOTER_PFV; innerOrderOtherComponentMstEntity.First().ELECTRIC_MOTER_EXTRA_INFO = innerOrderOtherComponentPostEntity.ELECTRIC_MOTER_EXTRA_INFO; innerOrderOtherComponentMstEntity.First().COLOR_TYPE = innerOrderOtherComponentPostEntity.COLOR_TYPE; innerOrderOtherComponentMstEntity.First().SPECIAL_COLOR_DETAIL = innerOrderOtherComponentPostEntity.SPECIAL_COLOR_DETAIL; innerOrderOtherComponentMstEntity.First().SURFACE_TREAT_TYPE = innerOrderOtherComponentPostEntity.SURFACE_TREAT_TYPE; innerOrderOtherComponentMstEntity.First().SURFACE_TREAT_EXTRA_INFO = innerOrderOtherComponentPostEntity.SURFACE_TREAT_EXTRA_INFO; innerOrderOtherComponentMstEntity.First().TRANSPORT_TYPE = innerOrderOtherComponentPostEntity.TRANSPORT_TYPE; innerOrderOtherComponentMstEntity.First().TRANSPORT_PLACE = innerOrderOtherComponentPostEntity.TRANSPORT_PLACE; innerOrderOtherComponentMstEntity.First().PACKAGING_TYPE = innerOrderOtherComponentPostEntity.PACKAGING_TYPE; innerOrderOtherComponentMstEntity.First().SPECIAL_PACK_DETAIL = innerOrderOtherComponentPostEntity.SPECIAL_PACK_DETAIL; innerOrderOtherComponentMstEntity.First().NEED_FUME_CERTIFICATE = innerOrderOtherComponentPostEntity.NEED_FUME_CERTIFICATE; innerOrderOtherComponentMstEntity.First().ADDRESS_INFO = innerOrderOtherComponentPostEntity.ADDRESS_INFO; innerOrderOtherComponentMstEntity.First().REMARK = innerOrderOtherComponentPostEntity.REMARK; myContext.SaveChanges(); return(""); } }