//新增異動單品項 public int addChangeOrderItem(PLAN_COSTCHANGE_ITEM item) { int i = 0; //2.將資料寫入 using (var context = new TopmepEntities()) { try { log.Debug("create COSTCHANGE_FORM:" + item.FORM_ID); context.PLAN_COSTCHANGE_ITEM.Add(item); i = context.SaveChanges(); } catch (Exception ex) { log.Error(ex.Message + ":" + ex.StackTrace); } } return(i); }
//將Excel Row 轉製成物件 public void ConvertExcel2Object() { lstItem = new List <PLAN_COSTCHANGE_ITEM>(); logger.Debug(sheet.LastRowNum); for (int idxRow = 4; idxRow < sheet.LastRowNum + 1; idxRow++) { PLAN_COSTCHANGE_ITEM item = new PLAN_COSTCHANGE_ITEM(); if (costChangeForm.FORM_ID != "") { item.FORM_ID = costChangeForm.FORM_ID; item.PROJECT_ID = project.PROJECT_ID; } //編號 標單編號 項次 品項名稱 單位 單價 異動數量 備註說明 轉入標單 IRow row = sheet.GetRow(idxRow); ICell cell = row.GetCell(0); if (null != cell) { string strUid = cell.ToString(); try { item.ITEM_UID = long.Parse(strUid); } catch (Exception ex) { logger.Warn("Excel Row=" + idxRow + " not UID;"); logger.Error(ex.Message + ":" + ex.StackTrace); } } cell = row.GetCell(1); if (null != cell) { item.PLAN_ITEM_ID = cell.ToString();//標單編號 } cell = row.GetCell(2); if (null != cell) { item.ITEM_ID = cell.ToString();//標單像次 } cell = row.GetCell(3); if (null != cell) { item.ITEM_DESC = cell.ToString();// 品項名稱 } cell = row.GetCell(4); if (null != cell) { item.ITEM_UNIT = cell.ToString(); } logger.Debug("Row Id=" + idxRow + "," + item.ITEM_DESC); //異動數量 cell = row.GetCell(5); string strQty = ""; if (null != cell) { strQty = cell.ToString(); } try { item.ITEM_QUANTITY = long.Parse(strQty); } catch (Exception ex) { logger.Warn("Excel Row=" + idxRow + " Qty can not covert"); logger.Error(ex.Message + ":" + ex.StackTrace); } //異動單價 cell = row.GetCell(6); string strPrice = ""; if (null != cell) { strPrice = cell.ToString(); try { item.ITEM_UNIT_PRICE = long.Parse(strPrice); } catch (Exception ex) { logger.Warn("Excel Row=" + idxRow + " Priec can not covert"); logger.Error(ex.Message + ":" + ex.StackTrace); } } //複價7 //8 備註 //異動數量 cell = row.GetCell(8); if (null != cell) { item.ITEM_REMARK = cell.ToString(); } //9 追加/轉入標單row.Cells[8].ToString(); cell = row.GetCell(9); string strTransFlag = "Y"; if (null != cell) { strTransFlag = cell.ToString(); } if (null != strTransFlag && strTransFlag != "" && strTransFlag != "N") { item.TRANSFLAG = "1"; } else { item.TRANSFLAG = "0"; } lstItem.Add(item); } }