SqeExcelService.cs 138 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Text;
  7. using Business.EntityFrameworkCore.SqlRepositories;
  8. using Business.StructuredDB.Sqe;
  9. using Newtonsoft.Json.Linq;
  10. using Volo.Abp.Application.Services;
  11. namespace Business.VSM
  12. {
  13. /// <summary>
  14. /// Sqe数据导入接口实现
  15. /// </summary>
  16. public class SqeExcelService : ApplicationService, ISqeExcelService
  17. {
  18. LoggerHelper WLLog;
  19. private readonly ISqeRepository<sqe_cto_process> _sqe_cto_process;
  20. private readonly ISqeRepository<sqe_cto_process_data> _sqe_cto_process_data;
  21. private readonly ISqeRepository<sqe_cto_process_standard> _sqe_cto_process_standard;
  22. private readonly ISqeRepository<sqe_cto_test> _sqe_cto_test;
  23. private readonly ISqeRepository<sqe_cto_test_data> _sqe_cto_test_data;
  24. private readonly ISqeRepository<sqe_cto_test_standard> _sqe_cto_test_standard;
  25. private readonly ISqeRepository<sqe_file_data> _sqe_file_data;
  26. private readonly ISqeRepository<sqe_file_upload> _sqe_file_upload;
  27. private readonly ISqeRepository<sqe_oqc> _sqe_oqc;
  28. private readonly ISqeRepository<sqe_oqc_data> _sqe_oqc_data;
  29. private readonly ISqeRepository<sqe_oqc_standard> _sqe_oqc_standard;
  30. private readonly ISqeRepository<sqe_fpy> _sqe_fpy;
  31. private readonly ISqeRepository<sqe_fpy_data> _sqe_fpy_data;
  32. private readonly ISqeRepository<sqe_op> _sqe_op;
  33. private readonly ISqeRepository<sqe_op_data> _sqe_op_data;
  34. private readonly ISqeRepository<sqe_op_data_detail> _sqe_op_data_detail;
  35. private readonly ISqeRepository<sqe_fct> _sqe_fct;
  36. private readonly ISqeRepository<sqe_fct_data> _sqe_fct_data;
  37. public SqeExcelService(
  38. ISqeRepository<sqe_cto_process> sqe_cto_process,
  39. ISqeRepository<sqe_cto_process_data> sqe_cto_process_data,
  40. ISqeRepository<sqe_cto_process_standard> sqe_cto_process_standard,
  41. ISqeRepository<sqe_cto_test> sqe_cto_test,
  42. ISqeRepository<sqe_cto_test_data> sqe_cto_test_data,
  43. ISqeRepository<sqe_cto_test_standard> sqe_cto_test_standard,
  44. ISqeRepository<sqe_file_data> sqe_file_data,
  45. ISqeRepository<sqe_file_upload> sqe_file_upload,
  46. ISqeRepository<sqe_oqc> sqe_oqc,
  47. ISqeRepository<sqe_oqc_data> sqe_oqc_data,
  48. ISqeRepository<sqe_oqc_standard> sqe_oqc_standard,
  49. ISqeRepository<sqe_fpy> sqe_fpy,
  50. ISqeRepository<sqe_fpy_data> sqe_fpy_data,
  51. ISqeRepository<sqe_op> sqe_op,
  52. ISqeRepository<sqe_op_data> sqe_op_data,
  53. ISqeRepository<sqe_op_data_detail> sqe_op_data_detail,
  54. ISqeRepository<sqe_fct> sqe_fct,
  55. ISqeRepository<sqe_fct_data> sqe_fct_data
  56. )
  57. {
  58. WLLog = new LoggerHelper();
  59. _sqe_cto_process = sqe_cto_process;
  60. _sqe_cto_process_data = sqe_cto_process_data;
  61. _sqe_cto_process_standard = sqe_cto_process_standard;
  62. _sqe_cto_test = sqe_cto_test;
  63. _sqe_cto_test_data = sqe_cto_test_data;
  64. _sqe_cto_test_standard = sqe_cto_test_standard;
  65. _sqe_file_data = sqe_file_data;
  66. _sqe_file_upload = sqe_file_upload;
  67. _sqe_oqc = sqe_oqc;
  68. _sqe_oqc_data = sqe_oqc_data;
  69. _sqe_oqc_standard = sqe_oqc_standard;
  70. _sqe_fpy = sqe_fpy;
  71. _sqe_fpy_data = sqe_fpy_data;
  72. _sqe_op = sqe_op;
  73. _sqe_op_data = sqe_op_data;
  74. _sqe_op_data_detail = sqe_op_data_detail;
  75. _sqe_fct = sqe_fct;
  76. _sqe_fct_data = sqe_fct_data;
  77. }
  78. ///// <summary>
  79. ///// 导入Excel文件的sheetName的sheet页面到数据表
  80. ///// </summary>
  81. ///// <param name="filePath"></param>
  82. ///// <param name="sheetName"></param>
  83. ///// <returns></returns>
  84. //public DataTable ImportExcelSheetToDataTable_test(string filePath, string sheetName)
  85. //{
  86. // FileStream file = null;
  87. // DataTable dt = new DataTable();
  88. // int index = 0;
  89. // try
  90. // {
  91. // file = new FileStream(filePath, FileMode.Open, FileAccess.Read);
  92. // //打开Excel对象
  93. // IWorkbook workbook;
  94. // IRow row;
  95. // string fileExt = Path.GetExtension(filePath).ToLower();
  96. // workbook = null;
  97. // if (fileExt == ".xlsx")
  98. // {
  99. // workbook = new XSSFWorkbook(file);
  100. // }
  101. // else
  102. // {
  103. // if (fileExt == ".xls")
  104. // {
  105. // workbook = new HSSFWorkbook(file);
  106. // }
  107. // else
  108. // {
  109. // workbook = null;
  110. // }
  111. // }
  112. // if (workbook == null) { return null; }
  113. // //Excel的Sheet对象
  114. // NPOI.SS.UserModel.ISheet sheet = workbook.GetSheet(sheetName);
  115. // //获取Sheet的所有的行
  116. // System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
  117. // //int colCountMax = 0;
  118. // dt.TableName = sheetName;
  119. // //判断是否拥有首行
  120. // bool firstLine = true;
  121. // //if (!haveColumnName)
  122. // //{
  123. // // firstLine = false;
  124. // //}
  125. // bool bDate = false;
  126. // while (rows.MoveNext())
  127. // {
  128. // index++;
  129. // bDate = false;
  130. // if (fileExt == ".xlsx")
  131. // {
  132. // row = (XSSFRow)rows.Current;
  133. // }
  134. // else
  135. // {
  136. // row = (HSSFRow)rows.Current;
  137. // }
  138. // if (!firstLine)
  139. // {
  140. // //生成表结构
  141. // //仅当首次调用时会进行循环生成
  142. // for (int i = dt.Columns.Count; i < row.Cells.Count; i++)
  143. // {
  144. // dt.Columns.Add(Convert.ToChar(((int)'A') + i).ToString());
  145. // }
  146. // }
  147. // else
  148. // {
  149. // //依据首行进行字段生成
  150. // for (int i = dt.Columns.Count; i < row.Cells.Count; i++)
  151. // {
  152. // dt.Columns.Add(row.Cells[i].ToString());
  153. // }
  154. // }
  155. // //没有首行,生成数据
  156. // if (!firstLine)
  157. // {
  158. // DataRow dr = dt.NewRow();
  159. // for (int i = 0; i < row.LastCellNum - 1; i++)
  160. // {
  161. // NPOI.SS.UserModel.ICell cell = row.GetCell(i);
  162. // String s = "";
  163. // if (cell != null)
  164. // {
  165. // switch (cell.CellType)
  166. // {
  167. // case NPOI.SS.UserModel.CellType.Unknown:
  168. // break;
  169. // case NPOI.SS.UserModel.CellType.Numeric:
  170. // if (HSSFDateUtil.IsCellDateFormatted(cell))
  171. // {
  172. // if (index < 6)
  173. // {
  174. // s = cell.DateCellValue.ToString();
  175. // }
  176. // else
  177. // {
  178. // s = cell.ToString();
  179. // }
  180. // }
  181. // else
  182. // {
  183. // s = cell.NumericCellValue.ToString();
  184. // }
  185. // break;
  186. // case NPOI.SS.UserModel.CellType.String:
  187. // s = cell.StringCellValue;
  188. // break;
  189. // case NPOI.SS.UserModel.CellType.Formula:
  190. // if (i == 0 || i == 1)
  191. // {
  192. // s = cell.StringCellValue;
  193. // }
  194. // else
  195. // {
  196. // try
  197. // {
  198. // if (cell.CellFormula == "序号")
  199. // {
  200. // s = cell.ToString();
  201. // }
  202. // else
  203. // {
  204. // s = cell.NumericCellValue != null ? cell.NumericCellValue.ToString() : null;
  205. // }
  206. // }
  207. // catch (Exception ex)
  208. // {
  209. // WLLog.Error("Excel导入问题:", ex);
  210. // }
  211. // }
  212. // break;
  213. // case NPOI.SS.UserModel.CellType.Blank:
  214. // if (bDate)
  215. // {
  216. // //对于日期的特殊处理
  217. // s = dr[i - 1].ToString();
  218. // }
  219. // else
  220. // {
  221. // s = cell.StringCellValue;
  222. // }
  223. // break;
  224. // case NPOI.SS.UserModel.CellType.Boolean:
  225. // break;
  226. // case NPOI.SS.UserModel.CellType.Error:
  227. // break;
  228. // default:
  229. // break;
  230. // }
  231. // }
  232. // dr[i] = s;
  233. // }
  234. // dt.Rows.Add(dr);
  235. // }
  236. // firstLine = false;
  237. // }
  238. // return dt;
  239. // }
  240. // catch (Exception ex)
  241. // {
  242. // WLLog.Error("Excel导入问题:", ex);
  243. // }
  244. // finally
  245. // {
  246. // if (file != null)
  247. // {
  248. // file.Close();
  249. // }
  250. // }
  251. // return dt;
  252. //}
  253. //public DataTable ImportExcelSheetToDataTable_process(string filePath, string sheetName)
  254. //{
  255. // FileStream file = null;
  256. // DataTable dt = new DataTable();
  257. // int index = 0;
  258. // try
  259. // {
  260. // file = new FileStream(filePath, FileMode.Open, FileAccess.Read);
  261. // //打开Excel对象
  262. // IWorkbook workbook;
  263. // IRow row;
  264. // string fileExt = Path.GetExtension(filePath).ToLower();
  265. // workbook = null;
  266. // if (fileExt == ".xlsx")
  267. // {
  268. // workbook = new XSSFWorkbook(file);
  269. // }
  270. // else
  271. // {
  272. // if (fileExt == ".xls")
  273. // {
  274. // workbook = new HSSFWorkbook(file);
  275. // }
  276. // else
  277. // {
  278. // workbook = null;
  279. // }
  280. // }
  281. // if (workbook == null) { return null; }
  282. // //Excel的Sheet对象
  283. // NPOI.SS.UserModel.ISheet sheet = workbook.GetSheet(sheetName);
  284. // //获取Sheet的所有的行
  285. // System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
  286. // //int colCountMax = 0;
  287. // dt.TableName = sheetName;
  288. // //判断是否拥有首行
  289. // bool firstLine = true;
  290. // //if (!haveColumnName)
  291. // //{
  292. // // firstLine = false;
  293. // //}
  294. // bool bDate = false;
  295. // while (rows.MoveNext())
  296. // {
  297. // index++;
  298. // bDate = false;
  299. // if (fileExt == ".xlsx")
  300. // {
  301. // row = (XSSFRow)rows.Current;
  302. // }
  303. // else
  304. // {
  305. // row = (HSSFRow)rows.Current;
  306. // }
  307. // if (!firstLine)
  308. // {
  309. // //生成表结构
  310. // //仅当首次调用时会进行循环生成
  311. // for (int i = dt.Columns.Count; i < row.Cells.Count; i++)
  312. // {
  313. // dt.Columns.Add(Convert.ToChar(((int)'A') + i).ToString());
  314. // }
  315. // }
  316. // else
  317. // {
  318. // //依据首行进行字段生成
  319. // for (int i = dt.Columns.Count; i < row.Cells.Count; i++)
  320. // {
  321. // dt.Columns.Add(row.Cells[i].ToString());
  322. // }
  323. // }
  324. // //没有首行,生成数据
  325. // if (!firstLine)
  326. // {
  327. // DataRow dr = dt.NewRow();
  328. // for (int i = 0; i < row.LastCellNum - 1; i++)
  329. // {
  330. // NPOI.SS.UserModel.ICell cell = row.GetCell(i);
  331. // String s = "";
  332. // if (cell != null)
  333. // {
  334. // switch (cell.CellType)
  335. // {
  336. // case NPOI.SS.UserModel.CellType.Unknown:
  337. // break;
  338. // case NPOI.SS.UserModel.CellType.Numeric:
  339. // if (HSSFDateUtil.IsCellDateFormatted(cell))
  340. // {
  341. // if (index < 6)
  342. // {
  343. // s = cell.DateCellValue.ToString();
  344. // }
  345. // else
  346. // {
  347. // s = cell.ToString();
  348. // }
  349. // }
  350. // else
  351. // {
  352. // s = cell.NumericCellValue.ToString();
  353. // }
  354. // break;
  355. // case NPOI.SS.UserModel.CellType.String:
  356. // s = cell.StringCellValue;
  357. // break;
  358. // case NPOI.SS.UserModel.CellType.Formula:
  359. // try
  360. // {
  361. // if (cell.CellFormula == "序号")
  362. // {
  363. // s = cell.ToString();
  364. // }
  365. // else
  366. // {
  367. // s = cell.NumericCellValue != null ? cell.NumericCellValue.ToString() : null;
  368. // }
  369. // }
  370. // catch (Exception ex)
  371. // {
  372. // WLLog.Error("Excel导入问题:", ex);
  373. // }
  374. // break;
  375. // case NPOI.SS.UserModel.CellType.Blank:
  376. // if (bDate)
  377. // {
  378. // //对于日期的特殊处理
  379. // s = dr[i - 1].ToString();
  380. // }
  381. // else
  382. // {
  383. // s = cell.StringCellValue;
  384. // }
  385. // break;
  386. // case NPOI.SS.UserModel.CellType.Boolean:
  387. // break;
  388. // case NPOI.SS.UserModel.CellType.Error:
  389. // break;
  390. // default:
  391. // break;
  392. // }
  393. // }
  394. // dr[i] = s;
  395. // }
  396. // dt.Rows.Add(dr);
  397. // }
  398. // firstLine = false;
  399. // }
  400. // return dt;
  401. // }
  402. // catch (Exception ex)
  403. // {
  404. // WLLog.Error("Excel导入问题:", ex);
  405. // }
  406. // finally
  407. // {
  408. // if (file != null)
  409. // {
  410. // file.Close();
  411. // }
  412. // }
  413. // return dt;
  414. //}
  415. ///// <summary>
  416. ///// 获取Excel文件Sheet名称列表,与Jet引擎不一致,获取的时候没有$多余字符。
  417. ///// </summary>
  418. ///// <param name="filePath"></param>
  419. ///// <returns></returns>
  420. //public List<String> GetSheetNames(string filePath)
  421. //{
  422. // List<String> tables = null;
  423. // FileStream file = null;
  424. // try
  425. // {
  426. // tables = new List<string>();
  427. // file = new FileStream(filePath, FileMode.Open, FileAccess.Read);
  428. // HSSFWorkbook hssfworkbook = new HSSFWorkbook(file);
  429. // int i = 0;
  430. // while (true)
  431. // {
  432. // try
  433. // {
  434. // String s = hssfworkbook.GetSheetName(i);
  435. // if (s != null)
  436. // {
  437. // tables.Add(s);
  438. // i++;
  439. // }
  440. // else
  441. // {
  442. // break;
  443. // }
  444. // }
  445. // catch (Exception ex)
  446. // {
  447. // break;
  448. // }
  449. // }
  450. // }
  451. // catch (Exception ex)
  452. // {
  453. // WLLog.Error("Excel导入问题:", ex);
  454. // }
  455. // finally
  456. // {
  457. // if (file != null)
  458. // {
  459. // file.Close();
  460. // }
  461. // }
  462. // return tables;
  463. //}
  464. /// <summary>
  465. /// 导入数据到检验表 sqe_cto_test、sqe_cto_test_standard、sqe_cto_test_data
  466. /// </summary>
  467. /// <param name="upload_id"></param>
  468. /// <param name="create_by"></param>
  469. /// <param name="create_date"></param>
  470. /// <param name="create_org"></param>
  471. /// <returns></returns>
  472. public string Import_Test_From_Data(int upload_id, string create_by, DateTime create_date, string create_org)
  473. {
  474. StringBuilder stringBuilder = new StringBuilder();
  475. try
  476. {
  477. List<sqe_file_data> datas = LoadData_file_data(upload_id);
  478. if (datas == null || datas.Count == 0)
  479. {
  480. stringBuilder.AppendLine("导入数据信息不存在!");
  481. return stringBuilder.ToString();
  482. }
  483. //产品特性的文件格式校验
  484. if (datas[0].c1.CompareTo("产品过程检验记录") != 0)
  485. {
  486. stringBuilder.AppendLine("文件不是【产品过程检验记录】要求的格式");
  487. return stringBuilder.ToString();
  488. }
  489. if (datas[1].c1.CompareTo("生产时间") != 0
  490. || datas[1].c3.CompareTo("生产班次") != 0
  491. || datas[1].c5.CompareTo("物料号") != 0
  492. || datas[1].c7.CompareTo("物料名称") != 0)
  493. {
  494. stringBuilder.AppendLine("文件不是【产品过程检验记录】要求的格式");
  495. return stringBuilder.ToString();
  496. }
  497. if (datas[2].c1.CompareTo("对应原材料批次号") != 0
  498. || datas[2].c3.CompareTo("原材料使用数量") != 0
  499. || datas[2].c5.CompareTo("物料批次号") != 0
  500. || datas[2].c7.CompareTo("物料数量") != 0)
  501. {
  502. stringBuilder.AppendLine("文件不是【产品过程检验记录】要求的格式");
  503. return stringBuilder.ToString();
  504. }
  505. string errorMsg;
  506. sqe_cto_test test = File_data_ToModel_test(datas, create_by, create_date, create_org, out errorMsg);
  507. if (errorMsg != null && errorMsg.Length > 0)
  508. {
  509. stringBuilder.AppendLine(errorMsg);
  510. return stringBuilder.ToString();
  511. }
  512. _sqe_cto_test.BeginTransaction();
  513. _sqe_cto_test.Insert(test);
  514. errorMsg = null;
  515. List<sqe_cto_test_standard> standards = File_data_ToModel_test_standard(datas, test, create_by, create_date, create_org, out errorMsg);
  516. if (errorMsg != null && errorMsg.Length > 0)
  517. {
  518. _sqe_cto_test.Rollback();
  519. stringBuilder.AppendLine(errorMsg);
  520. return stringBuilder.ToString();
  521. }
  522. _sqe_cto_test_standard.BeginTransaction();
  523. _sqe_cto_test_standard.Insert(standards);
  524. List<sqe_cto_test_data> test_Datas = File_data_ToModel_test_data(datas, test, standards, create_by, create_date, create_org, out errorMsg);
  525. if (errorMsg != null && errorMsg.Length > 0)
  526. {
  527. _sqe_cto_test.Rollback();
  528. _sqe_cto_test_standard.Rollback();
  529. stringBuilder.AppendLine(errorMsg);
  530. return stringBuilder.ToString();
  531. }
  532. _sqe_cto_test_data.Insert(test_Datas);
  533. _sqe_cto_test.CommitTransaction();
  534. _sqe_cto_test_standard.CommitTransaction();
  535. }
  536. catch (Exception ex)
  537. {
  538. stringBuilder.Append("数据导入失败!");
  539. }
  540. finally
  541. {
  542. }
  543. return stringBuilder.ToString();
  544. }
  545. /// <summary>
  546. /// 依据id,从sqe_file_upload和sqe_file_data,加载数据
  547. /// </summary>
  548. /// <param name="upload_id"></param>
  549. /// <returns></returns>
  550. public List<sqe_file_data> LoadData_file_data(int upload_id)
  551. {
  552. List<sqe_file_data> datas = _sqe_file_data.Select(a => a.file_id == upload_id).OrderBy(a => a.id).ToList();
  553. return datas;
  554. }
  555. #region 产品特性
  556. public sqe_cto_test File_data_ToModel_test(List<sqe_file_data> datas, string create_by, DateTime create_date, string create_org, out string errorMsg)
  557. {
  558. StringBuilder stringBuilder = new StringBuilder();
  559. sqe_cto_test model = new sqe_cto_test();
  560. DateTime timeValue;
  561. decimal realValuel;
  562. if (datas != null && datas.Count >= 5)
  563. {
  564. try
  565. {
  566. sqe_file_data data = datas[1];
  567. if (DateTime.TryParse(data.c2, out timeValue))
  568. {
  569. model.product_time = timeValue;
  570. }
  571. else
  572. {
  573. //model.product_time = DateTime.Parse("2000-01-01");
  574. model.product_time = DateTime.Now;
  575. }
  576. model.shift_no = data.c4;
  577. model.item_no = data.c6;
  578. model.item_name = data.c8;
  579. data = datas[2];
  580. model.material_batch = data.c2;
  581. if (decimal.TryParse(data.c4, out realValuel))
  582. {
  583. model.material_used = realValuel;
  584. }
  585. model.item_batch = data.c6;
  586. if (decimal.TryParse(data.c8, out realValuel))
  587. {
  588. model.item_qty = realValuel;
  589. }
  590. data = datas[3];
  591. model.op_pre = data.c2;
  592. model.op_pre_batch = data.c4;
  593. model.op_current = data.c6;
  594. model.op_batch = data.c8;
  595. data = datas[4];
  596. model.device_name = data.c2;
  597. model.device_no = data.c4;
  598. if (decimal.TryParse(data.c8, out realValuel))
  599. {
  600. model.sampling_number = realValuel;
  601. }
  602. }
  603. catch (Exception ex)
  604. {
  605. WLLog.Error("Excel数据解析问题:", ex);
  606. }
  607. model.create_by = create_by;
  608. model.create_date = create_date;
  609. model.create_org = create_org;
  610. errorMsg = string.Empty;
  611. return model;
  612. }
  613. else
  614. {
  615. errorMsg = stringBuilder.ToString();
  616. return null;
  617. }
  618. }
  619. public List<sqe_cto_test_standard> File_data_ToModel_test_standard(List<sqe_file_data> datas, sqe_cto_test test, string create_by, DateTime create_date, string create_org, out string errorMsg)
  620. {
  621. StringBuilder stringBuilder = new StringBuilder();
  622. List<sqe_cto_test_standard> modelList = new List<sqe_cto_test_standard>();
  623. decimal realValuel;
  624. if (datas != null && datas.Count >= 13)
  625. {
  626. try
  627. {
  628. //标准的起始位置
  629. int index = 5;
  630. sqe_file_data dataRow = datas[index];
  631. #region 处理尺寸的表头
  632. if (dataRow.c3 != null && dataRow.c3.Length > 0)
  633. {
  634. sqe_cto_test_standard model = new sqe_cto_test_standard();
  635. model.standard_no = dataRow.c3;
  636. model.create_by = create_by;
  637. model.create_date = create_date;
  638. model.create_org = create_org;
  639. model.test_id = test.id;
  640. modelList.Add(model);
  641. }
  642. if (dataRow.c4 != null && dataRow.c4.Length > 0)
  643. {
  644. sqe_cto_test_standard model = new sqe_cto_test_standard();
  645. model.standard_no = dataRow.c4;
  646. model.create_by = create_by;
  647. model.create_date = create_date;
  648. model.create_org = create_org;
  649. model.test_id = test.id;
  650. modelList.Add(model);
  651. }
  652. if (dataRow.c5 != null && dataRow.c5.Length > 0)
  653. {
  654. sqe_cto_test_standard model = new sqe_cto_test_standard();
  655. model.standard_no = dataRow.c5;
  656. model.create_by = create_by;
  657. model.create_date = create_date;
  658. model.create_org = create_org;
  659. model.test_id = test.id;
  660. modelList.Add(model);
  661. }
  662. if (dataRow.c6 != null && dataRow.c6.Length > 0)
  663. {
  664. sqe_cto_test_standard model = new sqe_cto_test_standard();
  665. model.standard_no = dataRow.c6;
  666. model.create_by = create_by;
  667. model.create_date = create_date;
  668. model.create_org = create_org;
  669. model.test_id = test.id;
  670. modelList.Add(model);
  671. }
  672. if (dataRow.c7 != null && dataRow.c7.Length > 0)
  673. {
  674. sqe_cto_test_standard model = new sqe_cto_test_standard();
  675. model.standard_no = dataRow.c7;
  676. model.create_by = create_by;
  677. model.create_date = create_date;
  678. model.create_org = create_org;
  679. model.test_id = test.id;
  680. modelList.Add(model);
  681. }
  682. if (dataRow.c8 != null && dataRow.c8.Length > 0)
  683. {
  684. sqe_cto_test_standard model = new sqe_cto_test_standard();
  685. model.standard_no = dataRow.c8;
  686. model.create_by = create_by;
  687. model.create_date = create_date;
  688. model.create_org = create_org;
  689. model.test_id = test.id;
  690. modelList.Add(model);
  691. }
  692. if (dataRow.c9 != null && dataRow.c9.Length > 0)
  693. {
  694. sqe_cto_test_standard model = new sqe_cto_test_standard();
  695. model.standard_no = dataRow.c9;
  696. model.create_by = create_by;
  697. model.create_date = create_date;
  698. model.create_org = create_org;
  699. model.test_id = test.id;
  700. modelList.Add(model);
  701. }
  702. if (dataRow.c10 != null && dataRow.c10.Length > 0)
  703. {
  704. sqe_cto_test_standard model = new sqe_cto_test_standard();
  705. model.standard_no = dataRow.c10;
  706. model.create_by = create_by;
  707. model.create_date = create_date;
  708. model.create_org = create_org;
  709. model.test_id = test.id;
  710. modelList.Add(model);
  711. }
  712. if (dataRow.c11 != null && dataRow.c11.Length > 0)
  713. {
  714. sqe_cto_test_standard model = new sqe_cto_test_standard();
  715. model.standard_no = dataRow.c11;
  716. model.create_by = create_by;
  717. model.create_date = create_date;
  718. model.create_org = create_org;
  719. model.test_id = test.id;
  720. modelList.Add(model);
  721. }
  722. #endregion 处理尺寸的表头
  723. if (modelList.Count > 0)
  724. {
  725. sqe_cto_test_standard model = modelList[0];
  726. dataRow = datas[index + 1];
  727. model.sampling_count = int.Parse(dataRow.c3);
  728. dataRow = datas[index + 2];
  729. model.is_associated_size = dataRow.c3;
  730. dataRow = datas[index + 3];
  731. if (dataRow.c3 != null && decimal.TryParse(dataRow.c3, out realValuel))
  732. {
  733. model.standard_value = realValuel;
  734. }
  735. dataRow = datas[index + 4];
  736. if (dataRow.c3 != null && decimal.TryParse(dataRow.c3, out realValuel))
  737. {
  738. model.delta_up = realValuel;
  739. }
  740. dataRow = datas[index + 5];
  741. if (dataRow.c3 != null && decimal.TryParse(dataRow.c3, out realValuel))
  742. {
  743. model.delta_down = realValuel;
  744. }
  745. dataRow = datas[index + 6];
  746. if (dataRow.c3 != null && decimal.TryParse(dataRow.c3, out realValuel))
  747. {
  748. model.standard_max = realValuel;
  749. }
  750. dataRow = datas[index + 7];
  751. if (dataRow.c3 != null && decimal.TryParse(dataRow.c3, out realValuel))
  752. {
  753. model.standard_min = realValuel;
  754. }
  755. }
  756. if (modelList.Count > 1)
  757. {
  758. sqe_cto_test_standard model = modelList[1];
  759. dataRow = datas[index + 1];
  760. model.sampling_count = int.Parse(dataRow.c4);
  761. dataRow = datas[index + 2];
  762. model.is_associated_size = dataRow.c4;
  763. dataRow = datas[index + 3];
  764. if (dataRow.c4 != null && decimal.TryParse(dataRow.c4, out realValuel))
  765. {
  766. model.standard_value = realValuel;
  767. }
  768. dataRow = datas[index + 4];
  769. if (dataRow.c4 != null && decimal.TryParse(dataRow.c4, out realValuel))
  770. {
  771. model.delta_up = realValuel;
  772. }
  773. dataRow = datas[index + 5];
  774. if (dataRow.c4 != null && decimal.TryParse(dataRow.c4, out realValuel))
  775. {
  776. model.delta_down = realValuel;
  777. }
  778. dataRow = datas[index + 6];
  779. if (dataRow.c4 != null && decimal.TryParse(dataRow.c4, out realValuel))
  780. {
  781. model.standard_max = realValuel;
  782. }
  783. dataRow = datas[index + 7];
  784. if (dataRow.c4 != null && decimal.TryParse(dataRow.c4, out realValuel))
  785. {
  786. model.standard_min = realValuel;
  787. }
  788. }
  789. if (modelList.Count > 2)
  790. {
  791. sqe_cto_test_standard model = modelList[2];
  792. dataRow = datas[index + 1];
  793. model.sampling_count = int.Parse(dataRow.c5);
  794. dataRow = datas[index + 2];
  795. model.is_associated_size = dataRow.c5;
  796. dataRow = datas[index + 3];
  797. if (dataRow.c5 != null && decimal.TryParse(dataRow.c5, out realValuel))
  798. {
  799. model.standard_value = realValuel;
  800. }
  801. dataRow = datas[index + 4];
  802. if (dataRow.c5 != null && decimal.TryParse(dataRow.c5, out realValuel))
  803. {
  804. model.delta_up = realValuel;
  805. }
  806. dataRow = datas[index + 5];
  807. if (dataRow.c5 != null && decimal.TryParse(dataRow.c5, out realValuel))
  808. {
  809. model.delta_down = realValuel;
  810. }
  811. dataRow = datas[index + 6];
  812. if (dataRow.c5 != null && decimal.TryParse(dataRow.c5, out realValuel))
  813. {
  814. model.standard_max = realValuel;
  815. }
  816. dataRow = datas[index + 7];
  817. if (dataRow.c5 != null && decimal.TryParse(dataRow.c5, out realValuel))
  818. {
  819. model.standard_min = realValuel;
  820. }
  821. }
  822. if (modelList.Count > 3)
  823. {
  824. sqe_cto_test_standard model = modelList[3];
  825. dataRow = datas[index + 1];
  826. model.sampling_count = int.Parse(dataRow.c6);
  827. dataRow = datas[index + 2];
  828. model.is_associated_size = dataRow.c6;
  829. dataRow = datas[index + 3];
  830. if (dataRow.c6 != null && decimal.TryParse(dataRow.c6, out realValuel))
  831. {
  832. model.standard_value = realValuel;
  833. }
  834. dataRow = datas[index + 4];
  835. if (dataRow.c6 != null && decimal.TryParse(dataRow.c6, out realValuel))
  836. {
  837. model.delta_up = realValuel;
  838. }
  839. dataRow = datas[index + 5];
  840. if (dataRow.c6 != null && decimal.TryParse(dataRow.c6, out realValuel))
  841. {
  842. model.delta_down = realValuel;
  843. }
  844. dataRow = datas[index + 6];
  845. if (dataRow.c6 != null && decimal.TryParse(dataRow.c6, out realValuel))
  846. {
  847. model.standard_max = realValuel;
  848. }
  849. dataRow = datas[index + 7];
  850. if (dataRow.c6 != null && decimal.TryParse(dataRow.c6, out realValuel))
  851. {
  852. model.standard_min = realValuel;
  853. }
  854. }
  855. if (modelList.Count > 4)
  856. {
  857. sqe_cto_test_standard model = modelList[4];
  858. dataRow = datas[index + 1];
  859. model.sampling_count = int.Parse(dataRow.c7);
  860. dataRow = datas[index + 2];
  861. model.is_associated_size = dataRow.c7;
  862. dataRow = datas[index + 3];
  863. if (dataRow.c7 != null && decimal.TryParse(dataRow.c7, out realValuel))
  864. {
  865. model.standard_value = realValuel;
  866. }
  867. dataRow = datas[index + 4];
  868. if (dataRow.c7 != null && decimal.TryParse(dataRow.c7, out realValuel))
  869. {
  870. model.delta_up = realValuel;
  871. }
  872. dataRow = datas[index + 5];
  873. if (dataRow.c7 != null && decimal.TryParse(dataRow.c7, out realValuel))
  874. {
  875. model.delta_down = realValuel;
  876. }
  877. dataRow = datas[index + 6];
  878. if (dataRow.c7 != null && decimal.TryParse(dataRow.c7, out realValuel))
  879. {
  880. model.standard_max = realValuel;
  881. }
  882. dataRow = datas[index + 7];
  883. if (dataRow.c7 != null && decimal.TryParse(dataRow.c7, out realValuel))
  884. {
  885. model.standard_min = realValuel;
  886. }
  887. }
  888. if (modelList.Count > 5)
  889. {
  890. sqe_cto_test_standard model = modelList[5];
  891. dataRow = datas[index + 1];
  892. model.sampling_count = int.Parse(dataRow.c8);
  893. dataRow = datas[index + 2];
  894. model.is_associated_size = dataRow.c8;
  895. dataRow = datas[index + 3];
  896. if (dataRow.c8 != null && decimal.TryParse(dataRow.c8, out realValuel))
  897. {
  898. model.standard_value = realValuel;
  899. }
  900. dataRow = datas[index + 4];
  901. if (dataRow.c8 != null && decimal.TryParse(dataRow.c8, out realValuel))
  902. {
  903. model.delta_up = realValuel;
  904. }
  905. dataRow = datas[index + 5];
  906. if (dataRow.c8 != null && decimal.TryParse(dataRow.c8, out realValuel))
  907. {
  908. model.delta_down = realValuel;
  909. }
  910. dataRow = datas[index + 6];
  911. if (dataRow.c8 != null && decimal.TryParse(dataRow.c8, out realValuel))
  912. {
  913. model.standard_max = realValuel;
  914. }
  915. dataRow = datas[index + 7];
  916. if (dataRow.c8 != null && decimal.TryParse(dataRow.c8, out realValuel))
  917. {
  918. model.standard_min = realValuel;
  919. }
  920. }
  921. if (modelList.Count > 6)
  922. {
  923. sqe_cto_test_standard model = modelList[6];
  924. dataRow = datas[index + 1];
  925. model.sampling_count = int.Parse(dataRow.c9);
  926. dataRow = datas[index + 2];
  927. model.is_associated_size = dataRow.c9;
  928. dataRow = datas[index + 3];
  929. if (dataRow.c9 != null && decimal.TryParse(dataRow.c9, out realValuel))
  930. {
  931. model.standard_value = realValuel;
  932. }
  933. dataRow = datas[index + 4];
  934. if (dataRow.c9 != null && decimal.TryParse(dataRow.c9, out realValuel))
  935. {
  936. model.delta_up = realValuel;
  937. }
  938. dataRow = datas[index + 5];
  939. if (dataRow.c9 != null && decimal.TryParse(dataRow.c9, out realValuel))
  940. {
  941. model.delta_down = realValuel;
  942. }
  943. dataRow = datas[index + 6];
  944. if (dataRow.c9 != null && decimal.TryParse(dataRow.c9, out realValuel))
  945. {
  946. model.standard_max = realValuel;
  947. }
  948. dataRow = datas[index + 7];
  949. if (dataRow.c9 != null && decimal.TryParse(dataRow.c9, out realValuel))
  950. {
  951. model.standard_min = realValuel;
  952. }
  953. }
  954. if (modelList.Count > 7)
  955. {
  956. sqe_cto_test_standard model = modelList[7];
  957. dataRow = datas[index + 1];
  958. model.sampling_count = int.Parse(dataRow.c10);
  959. dataRow = datas[index + 2];
  960. model.is_associated_size = dataRow.c10;
  961. dataRow = datas[index + 3];
  962. if (dataRow.c10 != null && decimal.TryParse(dataRow.c10, out realValuel))
  963. {
  964. model.standard_value = realValuel;
  965. }
  966. dataRow = datas[index + 4];
  967. if (dataRow.c10 != null && decimal.TryParse(dataRow.c10, out realValuel))
  968. {
  969. model.delta_up = realValuel;
  970. }
  971. dataRow = datas[index + 5];
  972. if (dataRow.c10 != null && decimal.TryParse(dataRow.c10, out realValuel))
  973. {
  974. model.delta_down = realValuel;
  975. }
  976. dataRow = datas[index + 6];
  977. if (dataRow.c10 != null && decimal.TryParse(dataRow.c10, out realValuel))
  978. {
  979. model.standard_max = realValuel;
  980. }
  981. dataRow = datas[index + 7];
  982. if (dataRow.c10 != null && decimal.TryParse(dataRow.c10, out realValuel))
  983. {
  984. model.standard_min = realValuel;
  985. }
  986. }
  987. if (modelList.Count > 8)
  988. {
  989. sqe_cto_test_standard model = modelList[8];
  990. dataRow = datas[index + 1];
  991. model.sampling_count = int.Parse(dataRow.c11);
  992. dataRow = datas[index + 2];
  993. model.is_associated_size = dataRow.c11;
  994. dataRow = datas[index + 3];
  995. if (dataRow.c11 != null && decimal.TryParse(dataRow.c11, out realValuel))
  996. {
  997. model.standard_value = realValuel;
  998. }
  999. dataRow = datas[index + 4];
  1000. if (dataRow.c11 != null && decimal.TryParse(dataRow.c11, out realValuel))
  1001. {
  1002. model.delta_up = realValuel;
  1003. }
  1004. dataRow = datas[index + 5];
  1005. if (dataRow.c11 != null && decimal.TryParse(dataRow.c11, out realValuel))
  1006. {
  1007. model.delta_down = realValuel;
  1008. }
  1009. dataRow = datas[index + 6];
  1010. if (dataRow.c11 != null && decimal.TryParse(dataRow.c11, out realValuel))
  1011. {
  1012. model.standard_max = realValuel;
  1013. }
  1014. dataRow = datas[index + 7];
  1015. if (dataRow.c11 != null && decimal.TryParse(dataRow.c11, out realValuel))
  1016. {
  1017. model.standard_min = realValuel;
  1018. }
  1019. }
  1020. }
  1021. catch (Exception ex)
  1022. {
  1023. WLLog.Error("Excel数据解析问题:", ex);
  1024. }
  1025. errorMsg = stringBuilder.ToString();
  1026. return modelList;
  1027. }
  1028. else
  1029. {
  1030. errorMsg = stringBuilder.ToString();
  1031. return null;
  1032. }
  1033. }
  1034. public List<sqe_cto_test_data> File_data_ToModel_test_data(List<sqe_file_data> datas, sqe_cto_test test, List<sqe_cto_test_standard> standards, string create_by, DateTime create_date, string create_org, out string errorMsg)
  1035. {
  1036. StringBuilder stringBuilder = new StringBuilder();
  1037. List<sqe_cto_test_data> modelList = new List<sqe_cto_test_data>();
  1038. decimal realValuel;
  1039. if (datas != null && datas.Count >= 15)
  1040. {
  1041. for (int i = 14; i < datas.Count; i++)
  1042. {
  1043. sqe_file_data dataRow = datas[i];
  1044. if ((dataRow.c1 == null || dataRow.c1.Length == 0 || dataRow.c1 == "0") && (dataRow.c2 == null || dataRow.c2.Length == 0))
  1045. {
  1046. break;
  1047. }
  1048. //初始化每一层的数据集合
  1049. List<sqe_cto_test_data> test_datas = new List<sqe_cto_test_data>();
  1050. for (int j = 0; j < standards.Count; j++)
  1051. {
  1052. sqe_cto_test_data data = new sqe_cto_test_data();
  1053. data.test_id = standards[j].test_id;
  1054. data.standard_id = standards[j].id;
  1055. data.create_by = create_by;
  1056. data.create_date = create_date;
  1057. data.create_org = create_org;
  1058. test_datas.Add(data);
  1059. }
  1060. try
  1061. {
  1062. //将每一个检测标准的值从记录行中取出来
  1063. if (test_datas.Count > 0)
  1064. {
  1065. sqe_cto_test_data data = test_datas[0];
  1066. data.data_no = dataRow.c1;
  1067. if (dataRow.c2 != null)
  1068. {
  1069. String s = dataRow.c2.ToString();
  1070. if (s != null && s.Length > 9)
  1071. {
  1072. s = s.Substring(s.Length - 9);
  1073. }
  1074. DateTime date;
  1075. if (DateTime.TryParse(test.product_time.ToString("yyyy-MM-dd ") + s, out date))
  1076. {
  1077. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1078. }
  1079. }
  1080. if (dataRow.c3 != null && dataRow.c3.Length > 0 && decimal.TryParse(dataRow.c3, out realValuel))
  1081. {
  1082. data.data_value = realValuel;
  1083. }
  1084. else
  1085. {
  1086. data.data_value = null;
  1087. }
  1088. }
  1089. if (test_datas.Count > 1)
  1090. {
  1091. sqe_cto_test_data data = test_datas[1];
  1092. data.data_no = dataRow.c1;
  1093. if (dataRow.c2 != null)
  1094. {
  1095. String s = dataRow.c2.ToString();
  1096. DateTime date;
  1097. if (DateTime.TryParse(test.product_time.ToString("yyyy-MM-dd ") + s, out date))
  1098. {
  1099. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1100. }
  1101. }
  1102. if (dataRow.c4 != null && dataRow.c4.Length > 0 && decimal.TryParse(dataRow.c4, out realValuel))
  1103. {
  1104. data.data_value = realValuel;
  1105. }
  1106. else
  1107. {
  1108. data.data_value = null;
  1109. }
  1110. }
  1111. if (test_datas.Count > 2)
  1112. {
  1113. sqe_cto_test_data data = test_datas[1];
  1114. data.data_no = dataRow.c1;
  1115. if (dataRow.c2 != null)
  1116. {
  1117. String s = dataRow.c2.ToString();
  1118. DateTime date;
  1119. if (DateTime.TryParse(test.product_time.ToString("yyyy-MM-dd ") + s, out date))
  1120. {
  1121. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1122. }
  1123. }
  1124. if (dataRow.c5 != null && dataRow.c5.Length > 0 && decimal.TryParse(dataRow.c5, out realValuel))
  1125. {
  1126. data.data_value = realValuel;
  1127. }
  1128. else
  1129. {
  1130. data.data_value = null;
  1131. }
  1132. }
  1133. if (test_datas.Count > 3)
  1134. {
  1135. sqe_cto_test_data data = test_datas[1];
  1136. data.data_no = dataRow.c1;
  1137. if (dataRow.c2 != null)
  1138. {
  1139. String s = dataRow.c2.ToString();
  1140. DateTime date;
  1141. if (DateTime.TryParse(test.product_time.ToString("yyyy-MM-dd ") + s, out date))
  1142. {
  1143. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1144. }
  1145. }
  1146. if (dataRow.c6 != null && dataRow.c6.Length > 0 && decimal.TryParse(dataRow.c6, out realValuel))
  1147. {
  1148. data.data_value = realValuel;
  1149. }
  1150. else
  1151. {
  1152. data.data_value = null;
  1153. }
  1154. }
  1155. if (test_datas.Count > 4)
  1156. {
  1157. sqe_cto_test_data data = test_datas[1];
  1158. data.data_no = dataRow.c1;
  1159. if (dataRow.c2 != null)
  1160. {
  1161. String s = dataRow.c2.ToString();
  1162. DateTime date;
  1163. if (DateTime.TryParse(test.product_time.ToString("yyyy-MM-dd ") + s, out date))
  1164. {
  1165. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1166. }
  1167. }
  1168. if (dataRow.c7 != null && dataRow.c7.Length > 0 && decimal.TryParse(dataRow.c7, out realValuel))
  1169. {
  1170. data.data_value = realValuel;
  1171. }
  1172. else
  1173. {
  1174. data.data_value = null;
  1175. }
  1176. }
  1177. if (test_datas.Count > 5)
  1178. {
  1179. sqe_cto_test_data data = test_datas[1];
  1180. data.data_no = dataRow.c1;
  1181. if (dataRow.c2 != null)
  1182. {
  1183. String s = dataRow.c2.ToString();
  1184. DateTime date;
  1185. if (DateTime.TryParse(test.product_time.ToString("yyyy-MM-dd ") + s, out date))
  1186. {
  1187. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1188. }
  1189. }
  1190. if (dataRow.c8 != null && dataRow.c8.Length > 0 && decimal.TryParse(dataRow.c8, out realValuel))
  1191. {
  1192. data.data_value = realValuel;
  1193. }
  1194. else
  1195. {
  1196. data.data_value = null;
  1197. }
  1198. }
  1199. if (test_datas.Count > 6)
  1200. {
  1201. sqe_cto_test_data data = test_datas[1];
  1202. data.data_no = dataRow.c1;
  1203. if (dataRow.c2 != null)
  1204. {
  1205. String s = dataRow.c2.ToString();
  1206. DateTime date;
  1207. if (DateTime.TryParse(test.product_time.ToString("yyyy-MM-dd ") + s, out date))
  1208. {
  1209. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1210. }
  1211. }
  1212. if (dataRow.c9 != null && dataRow.c9.Length > 0 && decimal.TryParse(dataRow.c9, out realValuel))
  1213. {
  1214. data.data_value = realValuel;
  1215. }
  1216. else
  1217. {
  1218. data.data_value = null;
  1219. }
  1220. }
  1221. if (test_datas.Count > 7)
  1222. {
  1223. sqe_cto_test_data data = test_datas[1];
  1224. data.data_no = dataRow.c1;
  1225. if (dataRow.c2 != null)
  1226. {
  1227. String s = dataRow.c2.ToString();
  1228. DateTime date;
  1229. if (DateTime.TryParse(test.product_time.ToString("yyyy-MM-dd ") + s, out date))
  1230. {
  1231. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1232. }
  1233. }
  1234. if (dataRow.c10 != null && dataRow.c10.Length > 0 && decimal.TryParse(dataRow.c10, out realValuel))
  1235. {
  1236. data.data_value = realValuel;
  1237. }
  1238. else
  1239. {
  1240. data.data_value = null;
  1241. }
  1242. }
  1243. if (test_datas.Count > 8)
  1244. {
  1245. sqe_cto_test_data data = test_datas[1];
  1246. data.data_no = dataRow.c1;
  1247. if (dataRow.c2 != null)
  1248. {
  1249. String s = dataRow.c2.ToString();
  1250. DateTime date;
  1251. if (DateTime.TryParse(test.product_time.ToString("yyyy-MM-dd ") + s, out date))
  1252. {
  1253. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1254. }
  1255. }
  1256. if (dataRow.c11 != null && dataRow.c11.Length > 0 && decimal.TryParse(dataRow.c11, out realValuel))
  1257. {
  1258. data.data_value = realValuel;
  1259. }
  1260. else
  1261. {
  1262. data.data_value = null;
  1263. }
  1264. }
  1265. File_data_ToModel_test_data_Add(modelList, test_datas);
  1266. }
  1267. catch (Exception ex)
  1268. {
  1269. WLLog.Error("Excel数据解析_原始数据转换到对象实体的问题:", ex);
  1270. }
  1271. }
  1272. errorMsg = string.Empty;
  1273. return modelList;
  1274. }
  1275. else
  1276. {
  1277. errorMsg = stringBuilder.ToString();
  1278. return null;
  1279. }
  1280. }
  1281. /// <summary>
  1282. /// 将转换的数据插入到返回结果数据集中,处理掉异常数据
  1283. /// </summary>
  1284. /// <param name="dataDest"></param>
  1285. /// <param name="dataSource"></param>
  1286. private void File_data_ToModel_test_data_Add(List<sqe_cto_test_data> dataDest, List<sqe_cto_test_data> dataSource)
  1287. {
  1288. if (dataSource != null && dataSource.Count > 0)
  1289. {
  1290. for (int i = 0; i < dataSource.Count; i++)
  1291. {
  1292. sqe_cto_test_data data = dataSource[i];
  1293. if (data.data_no != null && data.data_no.Length > 0 && data.data_time != null && data.data_value != null)
  1294. {
  1295. dataDest.Add(data);
  1296. }
  1297. }
  1298. }
  1299. }
  1300. #endregion 产品特性
  1301. public string Import_Process_From_Data(int upload_id, string create_by, DateTime create_date, string create_org)
  1302. {
  1303. StringBuilder stringBuilder = new StringBuilder();
  1304. try
  1305. {
  1306. List<sqe_file_data> datas = LoadData_file_data(upload_id);
  1307. if (datas == null || datas.Count == 0)
  1308. {
  1309. stringBuilder.AppendLine("导入数据信息不存在!");
  1310. return stringBuilder.ToString();
  1311. }
  1312. //产品过程特性的文件格式校验
  1313. if (datas[0].c1.CompareTo("产品过程特性") != 0)
  1314. {
  1315. stringBuilder.AppendLine("文件不是【产品过程特性】要求的格式");
  1316. return stringBuilder.ToString();
  1317. }
  1318. if (datas[1].c1.CompareTo("生产时间") != 0
  1319. || datas[1].c3.CompareTo("生产班次") != 0
  1320. || datas[1].c5.CompareTo("物料名称") != 0
  1321. || datas[1].c7.CompareTo("物料号") != 0)
  1322. {
  1323. stringBuilder.AppendLine("文件不是【产品过程特性】要求的格式");
  1324. return stringBuilder.ToString();
  1325. }
  1326. if (datas[2].c1.CompareTo("对应原材料批次号") != 0
  1327. || datas[2].c3.CompareTo("原材料使用数量") != 0
  1328. || datas[2].c5.CompareTo("物料批次号") != 0
  1329. || datas[2].c7.CompareTo("物料数量") != 0)
  1330. {
  1331. stringBuilder.AppendLine("文件不是【产品过程特性】要求的格式");
  1332. return stringBuilder.ToString();
  1333. }
  1334. string errorMsg;
  1335. sqe_cto_process test = File_data_ToModel_process(datas, create_by, create_date, create_org, out errorMsg);
  1336. if (errorMsg != null && errorMsg.Length > 0)
  1337. {
  1338. stringBuilder.AppendLine(errorMsg);
  1339. return stringBuilder.ToString();
  1340. }
  1341. _sqe_cto_process.BeginTransaction();
  1342. _sqe_cto_process.Insert(test);
  1343. errorMsg = null;
  1344. List<sqe_cto_process_standard> standards = File_data_ToModel_process_standard(datas, test, create_by, create_date, create_org, out errorMsg);
  1345. if (errorMsg != null && errorMsg.Length > 0)
  1346. {
  1347. _sqe_cto_process.Rollback();
  1348. stringBuilder.AppendLine(errorMsg);
  1349. return stringBuilder.ToString();
  1350. }
  1351. _sqe_cto_process_standard.BeginTransaction();
  1352. _sqe_cto_process_standard.Insert(standards);
  1353. List<sqe_cto_process_data> test_Datas = File_data_ToModel_process_data(datas, test, standards, create_by, create_date, create_org, out errorMsg);
  1354. if (errorMsg != null && errorMsg.Length > 0)
  1355. {
  1356. _sqe_cto_process.Rollback();
  1357. _sqe_cto_process_standard.Rollback();
  1358. stringBuilder.AppendLine(errorMsg);
  1359. return stringBuilder.ToString();
  1360. }
  1361. _sqe_cto_process_data.Insert(test_Datas);
  1362. _sqe_cto_process.CommitTransaction();
  1363. _sqe_cto_process_standard.CommitTransaction();
  1364. }
  1365. catch (Exception ex)
  1366. {
  1367. stringBuilder.Append("数据导入失败!");
  1368. }
  1369. finally
  1370. {
  1371. }
  1372. return stringBuilder.ToString();
  1373. }
  1374. #region 产品过程特性
  1375. public sqe_cto_process File_data_ToModel_process(List<sqe_file_data> datas, string create_by, DateTime create_date, string create_org, out string errorMsg)
  1376. {
  1377. StringBuilder stringBuilder = new StringBuilder();
  1378. sqe_cto_process model = new sqe_cto_process();
  1379. DateTime timeValue;
  1380. decimal realValuel;
  1381. if (datas != null && datas.Count >= 5)
  1382. {
  1383. try
  1384. {
  1385. sqe_file_data data = datas[1];
  1386. if (DateTime.TryParse(data.c2, out timeValue))
  1387. {
  1388. model.product_time = timeValue;
  1389. }
  1390. else
  1391. {
  1392. //model.product_time = DateTime.Parse("2000-01-01");
  1393. model.product_time = DateTime.Now;
  1394. }
  1395. model.shift_no = data.c4;
  1396. model.item_no = data.c6;
  1397. model.item_name = data.c8;
  1398. data = datas[2];
  1399. model.material_batch = data.c2;
  1400. if (decimal.TryParse(data.c4, out realValuel))
  1401. {
  1402. model.material_used = realValuel;
  1403. }
  1404. model.item_batch = data.c6;
  1405. if (decimal.TryParse(data.c8, out realValuel))
  1406. {
  1407. model.item_qty = realValuel;
  1408. }
  1409. data = datas[3];
  1410. model.op_pre = data.c2;
  1411. model.op_pre_batch = data.c4;
  1412. model.op_current = data.c6;
  1413. model.op_batch = data.c8;
  1414. data = datas[4];
  1415. model.device_name = data.c2;
  1416. model.device_no = data.c4;
  1417. if (decimal.TryParse(data.c8, out realValuel))
  1418. {
  1419. model.sampling_number = realValuel;
  1420. }
  1421. }
  1422. catch (Exception ex)
  1423. {
  1424. WLLog.Error("Excel数据解析问题:", ex);
  1425. }
  1426. model.create_by = create_by;
  1427. model.create_date = create_date;
  1428. model.create_org = create_org;
  1429. errorMsg = string.Empty;
  1430. return model;
  1431. }
  1432. else
  1433. {
  1434. errorMsg = stringBuilder.ToString();
  1435. return null;
  1436. }
  1437. }
  1438. public List<sqe_cto_process_standard> File_data_ToModel_process_standard(List<sqe_file_data> datas, sqe_cto_process test, string create_by, DateTime create_date, string create_org, out string errorMsg)
  1439. {
  1440. StringBuilder stringBuilder = new StringBuilder();
  1441. List<sqe_cto_process_standard> modelList = new List<sqe_cto_process_standard>();
  1442. decimal realValuel;
  1443. if (datas != null && datas.Count >= 13)
  1444. {
  1445. try
  1446. {
  1447. //标准的起始位置
  1448. int index = 5;
  1449. sqe_file_data dataRow = datas[index];
  1450. #region 处理尺寸的表头
  1451. if (dataRow.c2 != null && dataRow.c2.Length > 0)
  1452. {
  1453. sqe_cto_process_standard model = new sqe_cto_process_standard();
  1454. model.standard_no = dataRow.c2;
  1455. model.create_by = create_by;
  1456. model.create_date = create_date;
  1457. model.create_org = create_org;
  1458. model.process_id = test.id;
  1459. modelList.Add(model);
  1460. }
  1461. if (dataRow.c3 != null && dataRow.c3.Length > 0)
  1462. {
  1463. sqe_cto_process_standard model = new sqe_cto_process_standard();
  1464. model.standard_no = dataRow.c3;
  1465. model.create_by = create_by;
  1466. model.create_date = create_date;
  1467. model.create_org = create_org;
  1468. model.process_id = test.id;
  1469. modelList.Add(model);
  1470. }
  1471. if (dataRow.c4 != null && dataRow.c4.Length > 0)
  1472. {
  1473. sqe_cto_process_standard model = new sqe_cto_process_standard();
  1474. model.standard_no = dataRow.c4;
  1475. model.create_by = create_by;
  1476. model.create_date = create_date;
  1477. model.create_org = create_org;
  1478. model.process_id = test.id;
  1479. modelList.Add(model);
  1480. }
  1481. if (dataRow.c5 != null && dataRow.c5.Length > 0)
  1482. {
  1483. sqe_cto_process_standard model = new sqe_cto_process_standard();
  1484. model.standard_no = dataRow.c5;
  1485. model.create_by = create_by;
  1486. model.create_date = create_date;
  1487. model.create_org = create_org;
  1488. model.process_id = test.id;
  1489. modelList.Add(model);
  1490. }
  1491. if (dataRow.c6 != null && dataRow.c6.Length > 0)
  1492. {
  1493. sqe_cto_process_standard model = new sqe_cto_process_standard();
  1494. model.standard_no = dataRow.c6;
  1495. model.create_by = create_by;
  1496. model.create_date = create_date;
  1497. model.create_org = create_org;
  1498. model.process_id = test.id;
  1499. modelList.Add(model);
  1500. }
  1501. if (dataRow.c7 != null && dataRow.c7.Length > 0)
  1502. {
  1503. sqe_cto_process_standard model = new sqe_cto_process_standard();
  1504. model.standard_no = dataRow.c7;
  1505. model.create_by = create_by;
  1506. model.create_date = create_date;
  1507. model.create_org = create_org;
  1508. model.process_id = test.id;
  1509. modelList.Add(model);
  1510. }
  1511. if (dataRow.c8 != null && dataRow.c8.Length > 0)
  1512. {
  1513. sqe_cto_process_standard model = new sqe_cto_process_standard();
  1514. model.standard_no = dataRow.c8;
  1515. model.create_by = create_by;
  1516. model.create_date = create_date;
  1517. model.create_org = create_org;
  1518. model.process_id = test.id;
  1519. modelList.Add(model);
  1520. }
  1521. if (dataRow.c9 != null && dataRow.c9.Length > 0)
  1522. {
  1523. sqe_cto_process_standard model = new sqe_cto_process_standard();
  1524. model.standard_no = dataRow.c9;
  1525. model.create_by = create_by;
  1526. model.create_date = create_date;
  1527. model.create_org = create_org;
  1528. model.process_id = test.id;
  1529. modelList.Add(model);
  1530. }
  1531. if (dataRow.c10 != null && dataRow.c10.Length > 0)
  1532. {
  1533. sqe_cto_process_standard model = new sqe_cto_process_standard();
  1534. model.standard_no = dataRow.c10;
  1535. model.create_by = create_by;
  1536. model.create_date = create_date;
  1537. model.create_org = create_org;
  1538. model.process_id = test.id;
  1539. modelList.Add(model);
  1540. }
  1541. #endregion 处理尺寸的表头
  1542. if (modelList.Count > 0)
  1543. {
  1544. sqe_cto_process_standard model = modelList[0];
  1545. dataRow = datas[index + 1];
  1546. if (dataRow.c2 != null && decimal.TryParse(dataRow.c2, out realValuel))
  1547. {
  1548. model.standard_value = realValuel;
  1549. }
  1550. dataRow = datas[index + 2];
  1551. if (dataRow.c2 != null && decimal.TryParse(dataRow.c2, out realValuel))
  1552. {
  1553. model.delta_up = realValuel;
  1554. }
  1555. dataRow = datas[index + 3];
  1556. if (dataRow.c2 != null && decimal.TryParse(dataRow.c2, out realValuel))
  1557. {
  1558. model.delta_down = realValuel;
  1559. }
  1560. dataRow = datas[index + 4];
  1561. if (dataRow.c2 != null && decimal.TryParse(dataRow.c2, out realValuel))
  1562. {
  1563. model.standard_max = realValuel;
  1564. }
  1565. dataRow = datas[index + 5];
  1566. if (dataRow.c2 != null && decimal.TryParse(dataRow.c2, out realValuel))
  1567. {
  1568. model.standard_min = realValuel;
  1569. }
  1570. }
  1571. if (modelList.Count > 1)
  1572. {
  1573. sqe_cto_process_standard model = modelList[1];
  1574. dataRow = datas[index + 1];
  1575. if (dataRow.c3 != null && decimal.TryParse(dataRow.c3, out realValuel))
  1576. {
  1577. model.standard_value = realValuel;
  1578. }
  1579. dataRow = datas[index + 2];
  1580. if (dataRow.c3 != null && decimal.TryParse(dataRow.c3, out realValuel))
  1581. {
  1582. model.delta_up = realValuel;
  1583. }
  1584. dataRow = datas[index + 3];
  1585. if (dataRow.c3 != null && decimal.TryParse(dataRow.c3, out realValuel))
  1586. {
  1587. model.delta_down = realValuel;
  1588. }
  1589. dataRow = datas[index + 4];
  1590. if (dataRow.c3 != null && decimal.TryParse(dataRow.c3, out realValuel))
  1591. {
  1592. model.standard_max = realValuel;
  1593. }
  1594. dataRow = datas[index + 5];
  1595. if (dataRow.c3 != null && decimal.TryParse(dataRow.c3, out realValuel))
  1596. {
  1597. model.standard_min = realValuel;
  1598. }
  1599. }
  1600. if (modelList.Count > 2)
  1601. {
  1602. sqe_cto_process_standard model = modelList[2];
  1603. dataRow = datas[index + 1];
  1604. if (dataRow.c4 != null && decimal.TryParse(dataRow.c4, out realValuel))
  1605. {
  1606. model.standard_value = realValuel;
  1607. }
  1608. dataRow = datas[index + 2];
  1609. if (dataRow.c4 != null && decimal.TryParse(dataRow.c4, out realValuel))
  1610. {
  1611. model.delta_up = realValuel;
  1612. }
  1613. dataRow = datas[index + 3];
  1614. if (dataRow.c4 != null && decimal.TryParse(dataRow.c4, out realValuel))
  1615. {
  1616. model.delta_down = realValuel;
  1617. }
  1618. dataRow = datas[index + 4];
  1619. if (dataRow.c4 != null && decimal.TryParse(dataRow.c4, out realValuel))
  1620. {
  1621. model.standard_max = realValuel;
  1622. }
  1623. dataRow = datas[index + 5];
  1624. if (dataRow.c4 != null && decimal.TryParse(dataRow.c4, out realValuel))
  1625. {
  1626. model.standard_min = realValuel;
  1627. }
  1628. }
  1629. if (modelList.Count > 3)
  1630. {
  1631. sqe_cto_process_standard model = modelList[3];
  1632. dataRow = datas[index + 1];
  1633. if (dataRow.c5 != null && decimal.TryParse(dataRow.c5, out realValuel))
  1634. {
  1635. model.standard_value = realValuel;
  1636. }
  1637. dataRow = datas[index + 2];
  1638. if (dataRow.c5 != null && decimal.TryParse(dataRow.c5, out realValuel))
  1639. {
  1640. model.delta_up = realValuel;
  1641. }
  1642. dataRow = datas[index + 3];
  1643. if (dataRow.c5 != null && decimal.TryParse(dataRow.c5, out realValuel))
  1644. {
  1645. model.delta_down = realValuel;
  1646. }
  1647. dataRow = datas[index + 4];
  1648. if (dataRow.c5 != null && decimal.TryParse(dataRow.c5, out realValuel))
  1649. {
  1650. model.standard_max = realValuel;
  1651. }
  1652. dataRow = datas[index + 5];
  1653. if (dataRow.c5 != null && decimal.TryParse(dataRow.c5, out realValuel))
  1654. {
  1655. model.standard_min = realValuel;
  1656. }
  1657. }
  1658. if (modelList.Count > 4)
  1659. {
  1660. sqe_cto_process_standard model = modelList[4];
  1661. dataRow = datas[index + 1];
  1662. if (dataRow.c6 != null && decimal.TryParse(dataRow.c6, out realValuel))
  1663. {
  1664. model.standard_value = realValuel;
  1665. }
  1666. dataRow = datas[index + 2];
  1667. if (dataRow.c6 != null && decimal.TryParse(dataRow.c6, out realValuel))
  1668. {
  1669. model.delta_up = realValuel;
  1670. }
  1671. dataRow = datas[index + 3];
  1672. if (dataRow.c6 != null && decimal.TryParse(dataRow.c6, out realValuel))
  1673. {
  1674. model.delta_down = realValuel;
  1675. }
  1676. dataRow = datas[index + 4];
  1677. if (dataRow.c6 != null && decimal.TryParse(dataRow.c6, out realValuel))
  1678. {
  1679. model.standard_max = realValuel;
  1680. }
  1681. dataRow = datas[index + 5];
  1682. if (dataRow.c6 != null && decimal.TryParse(dataRow.c6, out realValuel))
  1683. {
  1684. model.standard_min = realValuel;
  1685. }
  1686. }
  1687. if (modelList.Count > 5)
  1688. {
  1689. sqe_cto_process_standard model = modelList[5];
  1690. dataRow = datas[index + 1];
  1691. if (dataRow.c7 != null && decimal.TryParse(dataRow.c7, out realValuel))
  1692. {
  1693. model.standard_value = realValuel;
  1694. }
  1695. dataRow = datas[index + 2];
  1696. if (dataRow.c7 != null && decimal.TryParse(dataRow.c7, out realValuel))
  1697. {
  1698. model.delta_up = realValuel;
  1699. }
  1700. dataRow = datas[index + 3];
  1701. if (dataRow.c7 != null && decimal.TryParse(dataRow.c7, out realValuel))
  1702. {
  1703. model.delta_down = realValuel;
  1704. }
  1705. dataRow = datas[index + 4];
  1706. if (dataRow.c7 != null && decimal.TryParse(dataRow.c7, out realValuel))
  1707. {
  1708. model.standard_max = realValuel;
  1709. }
  1710. dataRow = datas[index + 5];
  1711. if (dataRow.c7 != null && decimal.TryParse(dataRow.c7, out realValuel))
  1712. {
  1713. model.standard_min = realValuel;
  1714. }
  1715. }
  1716. if (modelList.Count > 6)
  1717. {
  1718. sqe_cto_process_standard model = modelList[6];
  1719. dataRow = datas[index + 1];
  1720. if (dataRow.c8 != null && decimal.TryParse(dataRow.c8, out realValuel))
  1721. {
  1722. model.standard_value = realValuel;
  1723. }
  1724. dataRow = datas[index + 2];
  1725. if (dataRow.c8 != null && decimal.TryParse(dataRow.c8, out realValuel))
  1726. {
  1727. model.delta_up = realValuel;
  1728. }
  1729. dataRow = datas[index + 3];
  1730. if (dataRow.c8 != null && decimal.TryParse(dataRow.c8, out realValuel))
  1731. {
  1732. model.delta_down = realValuel;
  1733. }
  1734. dataRow = datas[index + 4];
  1735. if (dataRow.c8 != null && decimal.TryParse(dataRow.c8, out realValuel))
  1736. {
  1737. model.standard_max = realValuel;
  1738. }
  1739. dataRow = datas[index + 5];
  1740. if (dataRow.c8 != null && decimal.TryParse(dataRow.c8, out realValuel))
  1741. {
  1742. model.standard_min = realValuel;
  1743. }
  1744. }
  1745. if (modelList.Count > 7)
  1746. {
  1747. sqe_cto_process_standard model = modelList[7];
  1748. dataRow = datas[index + 1];
  1749. if (dataRow.c9 != null && decimal.TryParse(dataRow.c9, out realValuel))
  1750. {
  1751. model.standard_value = realValuel;
  1752. }
  1753. dataRow = datas[index + 2];
  1754. if (dataRow.c9 != null && decimal.TryParse(dataRow.c9, out realValuel))
  1755. {
  1756. model.delta_up = realValuel;
  1757. }
  1758. dataRow = datas[index + 3];
  1759. if (dataRow.c9 != null && decimal.TryParse(dataRow.c9, out realValuel))
  1760. {
  1761. model.delta_down = realValuel;
  1762. }
  1763. dataRow = datas[index + 4];
  1764. if (dataRow.c9 != null && decimal.TryParse(dataRow.c9, out realValuel))
  1765. {
  1766. model.standard_max = realValuel;
  1767. }
  1768. dataRow = datas[index + 5];
  1769. if (dataRow.c9 != null && decimal.TryParse(dataRow.c9, out realValuel))
  1770. {
  1771. model.standard_min = realValuel;
  1772. }
  1773. }
  1774. if (modelList.Count > 8)
  1775. {
  1776. sqe_cto_process_standard model = modelList[8];
  1777. dataRow = datas[index + 1];
  1778. if (dataRow.c10 != null && decimal.TryParse(dataRow.c10, out realValuel))
  1779. {
  1780. model.standard_value = realValuel;
  1781. }
  1782. dataRow = datas[index + 2];
  1783. if (dataRow.c10 != null && decimal.TryParse(dataRow.c10, out realValuel))
  1784. {
  1785. model.delta_up = realValuel;
  1786. }
  1787. dataRow = datas[index + 3];
  1788. if (dataRow.c10 != null && decimal.TryParse(dataRow.c10, out realValuel))
  1789. {
  1790. model.delta_down = realValuel;
  1791. }
  1792. dataRow = datas[index + 4];
  1793. if (dataRow.c10 != null && decimal.TryParse(dataRow.c10, out realValuel))
  1794. {
  1795. model.standard_max = realValuel;
  1796. }
  1797. dataRow = datas[index + 5];
  1798. if (dataRow.c10 != null && decimal.TryParse(dataRow.c10, out realValuel))
  1799. {
  1800. model.standard_min = realValuel;
  1801. }
  1802. }
  1803. }
  1804. catch (Exception ex)
  1805. {
  1806. WLLog.Error("Excel数据解析问题:", ex);
  1807. }
  1808. errorMsg = stringBuilder.ToString();
  1809. return modelList;
  1810. }
  1811. else
  1812. {
  1813. errorMsg = stringBuilder.ToString();
  1814. return null;
  1815. }
  1816. }
  1817. public List<sqe_cto_process_data> File_data_ToModel_process_data(List<sqe_file_data> datas, sqe_cto_process test, List<sqe_cto_process_standard> standards, string create_by, DateTime create_date, string create_org, out string errorMsg)
  1818. {
  1819. StringBuilder stringBuilder = new StringBuilder();
  1820. List<sqe_cto_process_data> modelList = new List<sqe_cto_process_data>();
  1821. decimal realValuel;
  1822. if (datas != null && datas.Count >= 12)
  1823. {
  1824. for (int i = 11; i < datas.Count; i++)
  1825. {
  1826. sqe_file_data dataRow = datas[i];
  1827. if ((dataRow.c1 == null || dataRow.c1.Length == 0 || dataRow.c1 == "0") && (dataRow.c2 == null || dataRow.c2.Length == 0))
  1828. {
  1829. break;
  1830. }
  1831. //初始化每一层的数据集合
  1832. List<sqe_cto_process_data> test_datas = new List<sqe_cto_process_data>();
  1833. for (int j = 0; j < standards.Count; j++)
  1834. {
  1835. sqe_cto_process_data data = new sqe_cto_process_data();
  1836. data.process_id = standards[j].process_id;
  1837. data.standard_id = standards[j].id;
  1838. data.create_by = create_by;
  1839. data.create_date = create_date;
  1840. data.create_org = create_org;
  1841. test_datas.Add(data);
  1842. }
  1843. try
  1844. {
  1845. //将每一个检测标准的值从记录行中取出来
  1846. if (test_datas.Count > 0)
  1847. {
  1848. sqe_cto_process_data data = test_datas[0];
  1849. if (dataRow.c1 != null)
  1850. {
  1851. String s = dataRow.c1.ToString();
  1852. if (s != null && s.Length > 9)
  1853. {
  1854. s = s.Substring(s.Length - 9);
  1855. }
  1856. DateTime date;
  1857. if (DateTime.TryParse(test.product_time.ToString("yyyy-MM-dd ") + s, out date))
  1858. {
  1859. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1860. }
  1861. }
  1862. if (dataRow.c2 != null && dataRow.c2.Length > 0 && decimal.TryParse(dataRow.c2, out realValuel))
  1863. {
  1864. data.data_value = realValuel;
  1865. }
  1866. else
  1867. {
  1868. data.data_value = null;
  1869. }
  1870. }
  1871. if (test_datas.Count > 1)
  1872. {
  1873. sqe_cto_process_data data = test_datas[1];
  1874. if (dataRow.c1 != null)
  1875. {
  1876. String s = dataRow.c1.ToString();
  1877. if (s != null && s.Length > 9)
  1878. {
  1879. s = s.Substring(s.Length - 9);
  1880. }
  1881. DateTime date;
  1882. if (DateTime.TryParse(test.product_time.ToString("yyyy-MM-dd ") + s, out date))
  1883. {
  1884. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1885. }
  1886. }
  1887. if (dataRow.c3 != null && dataRow.c3.Length > 0 && decimal.TryParse(dataRow.c3, out realValuel))
  1888. {
  1889. data.data_value = realValuel;
  1890. }
  1891. else
  1892. {
  1893. data.data_value = null;
  1894. }
  1895. }
  1896. if (test_datas.Count > 2)
  1897. {
  1898. sqe_cto_process_data data = test_datas[2];
  1899. if (dataRow.c1 != null)
  1900. {
  1901. String s = dataRow.c1.ToString();
  1902. if (s != null && s.Length > 9)
  1903. {
  1904. s = s.Substring(s.Length - 9);
  1905. }
  1906. DateTime date;
  1907. if (DateTime.TryParse(test.product_time.ToString("yyyy-MM-dd ") + s, out date))
  1908. {
  1909. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1910. }
  1911. }
  1912. if (dataRow.c4 != null && dataRow.c4.Length > 0 && decimal.TryParse(dataRow.c4, out realValuel))
  1913. {
  1914. data.data_value = realValuel;
  1915. }
  1916. else
  1917. {
  1918. data.data_value = null;
  1919. }
  1920. }
  1921. if (test_datas.Count > 3)
  1922. {
  1923. sqe_cto_process_data data = test_datas[3];
  1924. if (dataRow.c1 != null)
  1925. {
  1926. String s = dataRow.c1.ToString();
  1927. if (s != null && s.Length > 9)
  1928. {
  1929. s = s.Substring(s.Length - 9);
  1930. }
  1931. DateTime date;
  1932. if (DateTime.TryParse(test.product_time.ToString("yyyy-MM-dd ") + s, out date))
  1933. {
  1934. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1935. }
  1936. }
  1937. if (dataRow.c5 != null && dataRow.c5.Length > 0 && decimal.TryParse(dataRow.c5, out realValuel))
  1938. {
  1939. data.data_value = realValuel;
  1940. }
  1941. else
  1942. {
  1943. data.data_value = null;
  1944. }
  1945. }
  1946. if (test_datas.Count > 4)
  1947. {
  1948. sqe_cto_process_data data = test_datas[4];
  1949. if (dataRow.c1 != null)
  1950. {
  1951. String s = dataRow.c1.ToString();
  1952. if (s != null && s.Length > 9)
  1953. {
  1954. s = s.Substring(s.Length - 9);
  1955. }
  1956. DateTime date;
  1957. if (DateTime.TryParse(test.product_time.ToString("yyyy-MM-dd ") + s, out date))
  1958. {
  1959. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1960. }
  1961. }
  1962. if (dataRow.c6 != null && dataRow.c6.Length > 0 && decimal.TryParse(dataRow.c6, out realValuel))
  1963. {
  1964. data.data_value = realValuel;
  1965. }
  1966. else
  1967. {
  1968. data.data_value = null;
  1969. }
  1970. }
  1971. if (test_datas.Count > 5)
  1972. {
  1973. sqe_cto_process_data data = test_datas[5];
  1974. if (dataRow.c1 != null)
  1975. {
  1976. String s = dataRow.c1.ToString();
  1977. if (s != null && s.Length > 9)
  1978. {
  1979. s = s.Substring(s.Length - 9);
  1980. }
  1981. DateTime date;
  1982. if (DateTime.TryParse(test.product_time.ToString("yyyy-MM-dd ") + s, out date))
  1983. {
  1984. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1985. }
  1986. }
  1987. if (dataRow.c7 != null && dataRow.c7.Length > 0 && decimal.TryParse(dataRow.c7, out realValuel))
  1988. {
  1989. data.data_value = realValuel;
  1990. }
  1991. else
  1992. {
  1993. data.data_value = null;
  1994. }
  1995. }
  1996. if (test_datas.Count > 6)
  1997. {
  1998. sqe_cto_process_data data = test_datas[6];
  1999. if (dataRow.c1 != null)
  2000. {
  2001. String s = dataRow.c1.ToString();
  2002. if (s != null && s.Length > 9)
  2003. {
  2004. s = s.Substring(s.Length - 9);
  2005. }
  2006. DateTime date;
  2007. if (DateTime.TryParse(test.product_time.ToString("yyyy-MM-dd ") + s, out date))
  2008. {
  2009. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  2010. }
  2011. }
  2012. if (dataRow.c8 != null && dataRow.c8.Length > 0 && decimal.TryParse(dataRow.c8, out realValuel))
  2013. {
  2014. data.data_value = realValuel;
  2015. }
  2016. else
  2017. {
  2018. data.data_value = null;
  2019. }
  2020. }
  2021. if (test_datas.Count > 7)
  2022. {
  2023. sqe_cto_process_data data = test_datas[7];
  2024. if (dataRow.c1 != null)
  2025. {
  2026. String s = dataRow.c1.ToString();
  2027. if (s != null && s.Length > 9)
  2028. {
  2029. s = s.Substring(s.Length - 9);
  2030. }
  2031. DateTime date;
  2032. if (DateTime.TryParse(test.product_time.ToString("yyyy-MM-dd ") + s, out date))
  2033. {
  2034. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  2035. }
  2036. }
  2037. if (dataRow.c9 != null && dataRow.c9.Length > 0 && decimal.TryParse(dataRow.c9, out realValuel))
  2038. {
  2039. data.data_value = realValuel;
  2040. }
  2041. else
  2042. {
  2043. data.data_value = null;
  2044. }
  2045. }
  2046. if (test_datas.Count > 8)
  2047. {
  2048. sqe_cto_process_data data = test_datas[8];
  2049. if (dataRow.c1 != null)
  2050. {
  2051. String s = dataRow.c1.ToString();
  2052. if (s != null && s.Length > 9)
  2053. {
  2054. s = s.Substring(s.Length - 9);
  2055. }
  2056. DateTime date;
  2057. if (DateTime.TryParse(test.product_time.ToString("yyyy-MM-dd ") + s, out date))
  2058. {
  2059. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  2060. }
  2061. }
  2062. if (dataRow.c10 != null && dataRow.c10.Length > 0 && decimal.TryParse(dataRow.c10, out realValuel))
  2063. {
  2064. data.data_value = realValuel;
  2065. }
  2066. else
  2067. {
  2068. data.data_value = null;
  2069. }
  2070. }
  2071. File_data_ToModel_process_data_Add(modelList, test_datas);
  2072. }
  2073. catch (Exception ex)
  2074. {
  2075. WLLog.Error("Excel数据解析_原始数据转换到对象实体的问题:", ex);
  2076. }
  2077. }
  2078. errorMsg = string.Empty;
  2079. return modelList;
  2080. }
  2081. else
  2082. {
  2083. errorMsg = stringBuilder.ToString();
  2084. return null;
  2085. }
  2086. }
  2087. /// <summary>
  2088. /// 将转换的数据插入到返回结果数据集中,处理掉异常数据
  2089. /// </summary>
  2090. /// <param name="dataDest"></param>
  2091. /// <param name="dataSource"></param>
  2092. private void File_data_ToModel_process_data_Add(List<sqe_cto_process_data> dataDest, List<sqe_cto_process_data> dataSource)
  2093. {
  2094. if (dataSource != null && dataSource.Count > 0)
  2095. {
  2096. for (int i = 0; i < dataSource.Count; i++)
  2097. {
  2098. sqe_cto_process_data data = dataSource[i];
  2099. if (data.data_time != null && data.data_value != null)
  2100. {
  2101. dataDest.Add(data);
  2102. }
  2103. }
  2104. }
  2105. }
  2106. #endregion 产品过程特性
  2107. /// <summary>
  2108. /// 依据导入的数据行,生成OP的表头、检验标准和数据行
  2109. /// </summary>
  2110. /// <param name="upload_id"></param>
  2111. /// <param name="create_by"></param>
  2112. /// <param name="create_date"></param>
  2113. /// <param name="create_org"></param>
  2114. /// <returns></returns>
  2115. public string Import_Op_From_Data(int upload_id, string create_by, DateTime create_date, string create_org)
  2116. {
  2117. StringBuilder stringBuilder = new StringBuilder();
  2118. try
  2119. {
  2120. List<sqe_file_data> datas = LoadData_file_data(upload_id);
  2121. if (datas == null || datas.Count == 0)
  2122. {
  2123. stringBuilder.AppendLine("导入数据信息不存在!");
  2124. return stringBuilder.ToString();
  2125. }
  2126. //出货检验记录文件格式校验
  2127. if (datas[0].c1.CompareTo("供应商代码") != 0
  2128. || datas[0].c2.CompareTo("日期") != 0
  2129. || datas[0].c3.CompareTo("客户料号") != 0
  2130. || datas[0].c4.CompareTo("物料名称") != 0
  2131. || datas[0].c5.CompareTo("批次号") != 0
  2132. || datas[0].c6.CompareTo("工序") != 0
  2133. || datas[0].c7.CompareTo("总数量") != 0
  2134. || datas[0].c8.CompareTo("良品数") != 0
  2135. || datas[0].c9.CompareTo("不良品数") != 0
  2136. || datas[0].c10.CompareTo("合格率") != 0
  2137. || datas[0].c11.CompareTo("不良率") != 0)
  2138. {
  2139. stringBuilder.AppendLine("文件不是【全检工序】要求的格式");
  2140. return stringBuilder.ToString();
  2141. }
  2142. string errorMsg;
  2143. sqe_op test = File_data_ToModel_op(datas, create_by, create_date, create_org, out errorMsg);
  2144. if (errorMsg != null && errorMsg.Length > 0)
  2145. {
  2146. stringBuilder.AppendLine(errorMsg);
  2147. return stringBuilder.ToString();
  2148. }
  2149. _sqe_op.BeginTransaction();
  2150. _sqe_op.Insert(test);
  2151. errorMsg = null;
  2152. List<sqe_op_data> standards = File_data_ToModel_op_data(datas, test, create_by, create_date, create_org, out errorMsg);
  2153. if (errorMsg != null && errorMsg.Length > 0)
  2154. {
  2155. _sqe_op.Rollback();
  2156. stringBuilder.AppendLine(errorMsg);
  2157. return stringBuilder.ToString();
  2158. }
  2159. _sqe_op_data.BeginTransaction();
  2160. _sqe_op_data.Insert(standards);
  2161. List<sqe_op_data_detail> test_Datas = File_data_ToModel_op_data_detail(datas, test, standards, create_by, create_date, create_org, out errorMsg);
  2162. if (errorMsg != null && errorMsg.Length > 0)
  2163. {
  2164. _sqe_op.Rollback();
  2165. _sqe_op_data.Rollback();
  2166. stringBuilder.AppendLine(errorMsg);
  2167. return stringBuilder.ToString();
  2168. }
  2169. _sqe_op_data_detail.Insert(test_Datas);
  2170. _sqe_op.CommitTransaction();
  2171. _sqe_op_data.CommitTransaction();
  2172. }
  2173. catch (Exception ex)
  2174. {
  2175. stringBuilder.Append("数据导入失败!");
  2176. }
  2177. finally
  2178. {
  2179. }
  2180. return stringBuilder.ToString();
  2181. }
  2182. #region OP
  2183. /// <summary>
  2184. /// 从原始数据行生成OP的表头数据
  2185. /// </summary>
  2186. /// <param name="datas"></param>
  2187. /// <param name="create_by"></param>
  2188. /// <param name="create_date"></param>
  2189. /// <param name="create_org"></param>
  2190. /// <param name="errorMsg"></param>
  2191. /// <returns></returns>
  2192. public sqe_op File_data_ToModel_op(List<sqe_file_data> datas, string create_by, DateTime create_date, string create_org, out string errorMsg)
  2193. {
  2194. sqe_op model = new sqe_op();
  2195. model.create_by = create_by;
  2196. model.create_date = create_date;
  2197. model.create_org = create_org;
  2198. errorMsg = string.Empty;
  2199. errorMsg = "";
  2200. return model;
  2201. }
  2202. /// <summary>
  2203. /// 从原始数据行生成OP的检验标准
  2204. /// </summary>
  2205. /// <param name="datas"></param>
  2206. /// <param name="test"></param>
  2207. /// <param name="create_by"></param>
  2208. /// <param name="create_date"></param>
  2209. /// <param name="create_org"></param>
  2210. /// <param name="errorMsg"></param>
  2211. /// <returns></returns>
  2212. public List<sqe_op_data> File_data_ToModel_op_data(List<sqe_file_data> datas, sqe_op test, string create_by, DateTime create_date, string create_org, out string errorMsg)
  2213. {
  2214. StringBuilder stringBuilder = new StringBuilder();
  2215. List<sqe_op_data> modelList = new List<sqe_op_data>();
  2216. decimal realValuel;
  2217. if (datas != null && datas.Count > 1)
  2218. {
  2219. for (int i = 1; i < datas.Count; i++)
  2220. {
  2221. sqe_op_data model = new sqe_op_data();
  2222. sqe_file_data dataRow = datas[i];
  2223. if ((dataRow.c1 == null || dataRow.c1.Length == 0) && (dataRow.c2 == null || dataRow.c2.Length == 0))
  2224. {
  2225. break;
  2226. }
  2227. model.supp_no = dataRow.c1;
  2228. DateTime dt;
  2229. int dateLength;
  2230. if (DateTime.TryParse(dataRow.c2, out dt))
  2231. {
  2232. model.op_time = dt;
  2233. }
  2234. else
  2235. {
  2236. if (int.TryParse(dataRow.c2, out dateLength))
  2237. {
  2238. dt = DateTime.Parse("1900-01-01");
  2239. model.op_time = dt.AddDays(dateLength - 2);
  2240. }
  2241. }
  2242. //model.op_time = DateTime.Parse(dataRow.c2);
  2243. model.item_no = dataRow.c3;
  2244. model.item_name = dataRow.c4;
  2245. model.batch_no = dataRow.c5;
  2246. model.op_no = dataRow.c6;
  2247. Object obj = GetFieldValue(dataRow, "c7");
  2248. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2249. {
  2250. model.qty_all = realValuel;
  2251. }
  2252. obj = GetFieldValue(dataRow, "c8");
  2253. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2254. {
  2255. model.qty_ok = realValuel;
  2256. }
  2257. obj = GetFieldValue(dataRow, "c9");
  2258. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2259. {
  2260. model.qty_error = realValuel;
  2261. }
  2262. obj = GetFieldValue(dataRow, "c10");
  2263. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2264. {
  2265. model.percent_ok = realValuel;
  2266. }
  2267. obj = GetFieldValue(dataRow, "c11");
  2268. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2269. {
  2270. model.percent_error = realValuel;
  2271. }
  2272. //model.op_time = DateTime.Now;
  2273. model.create_by = create_by;
  2274. model.create_date = create_date;
  2275. model.create_org = create_org;
  2276. modelList.Add(model);
  2277. }
  2278. }
  2279. errorMsg = stringBuilder.ToString();
  2280. return modelList;
  2281. }
  2282. /// <summary>
  2283. /// 从原始数据行生成OP的数据
  2284. /// </summary>
  2285. /// <param name="datas"></param>
  2286. /// <param name="test"></param>
  2287. /// <param name="standards"></param>
  2288. /// <param name="create_by"></param>
  2289. /// <param name="create_date"></param>
  2290. /// <param name="create_org"></param>
  2291. /// <param name="errorMsg"></param>
  2292. /// <returns></returns>
  2293. public List<sqe_op_data_detail> File_data_ToModel_op_data_detail(List<sqe_file_data> datas, sqe_op test, List<sqe_op_data> standards, string create_by, DateTime create_date, string create_org, out string errorMsg)
  2294. {
  2295. StringBuilder stringBuilder = new StringBuilder();
  2296. List<sqe_op_data_detail> modelList = new List<sqe_op_data_detail>();
  2297. decimal realValuel;
  2298. if (datas != null && datas.Count > 1)
  2299. {
  2300. for (int i = 1; i < datas.Count && i - 1 < standards.Count; i++)
  2301. {
  2302. sqe_file_data dataRow = datas[i];
  2303. List<sqe_op_data_detail> testDatas = new List<sqe_op_data_detail>();
  2304. for (int j = 12; j < 50; j += 4)
  2305. {
  2306. Object obj = GetFieldValue(dataRow, "c" + j.ToString());
  2307. if (obj != null && obj.ToString().Length > 0)
  2308. {
  2309. sqe_op_data_detail data = new sqe_op_data_detail();
  2310. data.op_id = standards[i - 1].op_id;
  2311. data.op_data_id = standards[i - 1].id;
  2312. data.bad_type = obj.ToString();
  2313. obj = GetFieldValue(dataRow, "c" + (j + 1).ToString());
  2314. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2315. {
  2316. data.bad_qty = realValuel;
  2317. }
  2318. obj = GetFieldValue(dataRow, "c" + (j + 2).ToString());
  2319. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2320. {
  2321. data.percent_bad_all = realValuel;
  2322. }
  2323. obj = GetFieldValue(dataRow, "c" + (j + 3).ToString());
  2324. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2325. {
  2326. data.percent_bad = realValuel;
  2327. }
  2328. data.create_by = create_by;
  2329. data.create_date = create_date;
  2330. data.create_org = create_org;
  2331. testDatas.Add(data);
  2332. }
  2333. }
  2334. File_data_ToModel_op_data_detail_Add(modelList, testDatas);
  2335. }
  2336. errorMsg = string.Empty;
  2337. return modelList;
  2338. }
  2339. else
  2340. {
  2341. errorMsg = stringBuilder.ToString();
  2342. return null;
  2343. }
  2344. }
  2345. /// <summary>
  2346. /// 将转换的数据插入到返回结果数据集中,处理掉异常数据
  2347. /// </summary>
  2348. /// <param name="dataDest"></param>
  2349. /// <param name="dataSource"></param>
  2350. private void File_data_ToModel_op_data_detail_Add(List<sqe_op_data_detail> dataDest, List<sqe_op_data_detail> dataSource)
  2351. {
  2352. if (dataSource != null && dataSource.Count > 0)
  2353. {
  2354. for (int i = 0; i < dataSource.Count; i++)
  2355. {
  2356. sqe_op_data_detail data = dataSource[i];
  2357. if (data.bad_type != null && data.bad_type.Length > 0 && data.bad_qty != null)
  2358. {
  2359. dataDest.Add(data);
  2360. }
  2361. }
  2362. }
  2363. }
  2364. #endregion OP
  2365. /// <summary>
  2366. /// 依据导入的数据行,生成FPY的表头、检验标准和数据行
  2367. /// </summary>
  2368. /// <param name="upload_id"></param>
  2369. /// <param name="create_by"></param>
  2370. /// <param name="create_date"></param>
  2371. /// <param name="create_org"></param>
  2372. /// <returns></returns>
  2373. public string Import_Fpy_From_Data(int upload_id, string create_by, DateTime create_date, string create_org)
  2374. {
  2375. StringBuilder stringBuilder = new StringBuilder();
  2376. try
  2377. {
  2378. List<sqe_file_data> datas = LoadData_file_data(upload_id);
  2379. if (datas == null || datas.Count == 0)
  2380. {
  2381. stringBuilder.AppendLine("导入数据信息不存在!");
  2382. return stringBuilder.ToString();
  2383. }
  2384. //FPY的文件格式校验
  2385. //if (datas[0].c1.CompareTo("一、供应商上传报表模版") != 0)
  2386. //{
  2387. // stringBuilder.AppendLine("文件不是【FPY】要求的格式");
  2388. // return stringBuilder.ToString();
  2389. //}
  2390. if (datas[0].c1.CompareTo("生产各工序良率统计报表") != 0)
  2391. {
  2392. stringBuilder.AppendLine("文件不是【FPY】要求的格式");
  2393. return stringBuilder.ToString();
  2394. }
  2395. if (datas[1].c1.CompareTo("NO") != 0
  2396. || datas[1].c2.CompareTo("日期") != 0
  2397. || datas[1].c3.CompareTo("物料号") != 0
  2398. || datas[1].c4.CompareTo("物料名称") != 0
  2399. || datas[1].c5.CompareTo("工序") != 0
  2400. || datas[1].c6.CompareTo("投入数") != 0
  2401. || datas[1].c7.CompareTo("不良数") != 0
  2402. || datas[1].c8.CompareTo("良品率") != 0)
  2403. {
  2404. stringBuilder.AppendLine("文件不是【FPY】要求的格式");
  2405. return stringBuilder.ToString();
  2406. }
  2407. //if (datas[2].c1.CompareTo("对应原材料批次号") != 0
  2408. // || datas[2].c3.CompareTo("原材料使用数量") != 0
  2409. // || datas[2].c5.CompareTo("物料批次号") != 0
  2410. // || datas[2].c7.CompareTo("物料数量") != 0)
  2411. //{
  2412. // stringBuilder.AppendLine("文件不是【FPY】要求的格式式");
  2413. // return stringBuilder.ToString();
  2414. //}
  2415. string errorMsg;
  2416. sqe_fpy test = File_data_ToModel_fpy(datas, create_by, create_date, create_org, out errorMsg);
  2417. if (errorMsg != null && errorMsg.Length > 0)
  2418. {
  2419. stringBuilder.AppendLine(errorMsg);
  2420. return stringBuilder.ToString();
  2421. }
  2422. _sqe_fpy.BeginTransaction();
  2423. _sqe_fpy.Insert(test);
  2424. errorMsg = null;
  2425. List<sqe_fpy_data> standards = File_data_ToModel_fpy_data(datas, test, create_by, create_date, create_org, out errorMsg);
  2426. if (errorMsg != null && errorMsg.Length > 0)
  2427. {
  2428. _sqe_fpy.Rollback();
  2429. stringBuilder.AppendLine(errorMsg);
  2430. return stringBuilder.ToString();
  2431. }
  2432. _sqe_fpy_data.BeginTransaction();
  2433. _sqe_fpy_data.Insert(standards);
  2434. _sqe_fpy.CommitTransaction();
  2435. _sqe_fpy_data.CommitTransaction();
  2436. }
  2437. catch (Exception ex)
  2438. {
  2439. stringBuilder.Append("数据导入失败!");
  2440. }
  2441. finally
  2442. {
  2443. }
  2444. return stringBuilder.ToString();
  2445. }
  2446. #region FPY
  2447. /// <summary>
  2448. /// 从原始数据行生成FPY的表头数据
  2449. /// </summary>
  2450. /// <param name="datas"></param>
  2451. /// <param name="create_by"></param>
  2452. /// <param name="create_date"></param>
  2453. /// <param name="create_org"></param>
  2454. /// <param name="errorMsg"></param>
  2455. /// <returns></returns>
  2456. public sqe_fpy File_data_ToModel_fpy(List<sqe_file_data> datas, string create_by, DateTime create_date, string create_org, out string errorMsg)
  2457. {
  2458. sqe_fpy model = new sqe_fpy();
  2459. model.create_by = create_by;
  2460. model.create_date = create_date;
  2461. model.create_org = create_org;
  2462. errorMsg = string.Empty;
  2463. errorMsg = "";
  2464. return model;
  2465. }
  2466. /// <summary>
  2467. /// 从原始数据行生成FPY的检验标准
  2468. /// </summary>
  2469. /// <param name="datas"></param>
  2470. /// <param name="test"></param>
  2471. /// <param name="create_by"></param>
  2472. /// <param name="create_date"></param>
  2473. /// <param name="create_org"></param>
  2474. /// <param name="errorMsg"></param>
  2475. /// <returns></returns>
  2476. public List<sqe_fpy_data> File_data_ToModel_fpy_data(List<sqe_file_data> datas, sqe_fpy test, string create_by, DateTime create_date, string create_org, out string errorMsg)
  2477. {
  2478. StringBuilder stringBuilder = new StringBuilder();
  2479. List<sqe_fpy_data> modelList = new List<sqe_fpy_data>();
  2480. decimal realValuel;
  2481. if (datas != null && datas.Count > 2)
  2482. {
  2483. for (int i = 2; i < datas.Count; i++)
  2484. {
  2485. sqe_fpy_data model = new sqe_fpy_data();
  2486. sqe_file_data dataRow = datas[i];
  2487. if ((dataRow.c1 == null || dataRow.c1.Length == 0) && (dataRow.c3 == null || dataRow.c3.Length == 0))
  2488. {
  2489. break;
  2490. }
  2491. int dateLength;
  2492. DateTime dt;
  2493. if (DateTime.TryParse(dataRow.c2, out dt))
  2494. {
  2495. model.op_time = dt;
  2496. }
  2497. else
  2498. {
  2499. if (int.TryParse(dataRow.c2, out dateLength))
  2500. {
  2501. dt = DateTime.Parse("1900-01-01");
  2502. model.op_time = dt.AddDays(dateLength - 2);
  2503. }
  2504. }
  2505. model.item_no = dataRow.c3;
  2506. model.item_name = dataRow.c4;
  2507. model.op_no = dataRow.c5;
  2508. Object obj = GetFieldValue(dataRow, "c6");
  2509. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2510. {
  2511. model.qty_all = realValuel;
  2512. }
  2513. obj = GetFieldValue(dataRow, "c7");
  2514. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2515. {
  2516. model.qty_error = realValuel;
  2517. }
  2518. obj = GetFieldValue(dataRow, "c8");
  2519. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2520. {
  2521. model.percent_ok = realValuel;
  2522. }
  2523. model.fpy_id = test.id;
  2524. model.create_by = create_by;
  2525. model.create_date = create_date;
  2526. model.create_org = create_org;
  2527. modelList.Add(model);
  2528. }
  2529. }
  2530. errorMsg = stringBuilder.ToString();
  2531. return modelList;
  2532. }
  2533. #endregion FPY
  2534. /// <summary>
  2535. /// 依据导入的数据行,生成OQC的表头、检验标准和数据行
  2536. /// </summary>
  2537. /// <param name="upload_id"></param>
  2538. /// <param name="create_by"></param>
  2539. /// <param name="create_date"></param>
  2540. /// <param name="create_org"></param>
  2541. /// <returns></returns>
  2542. public string Import_Oqc_From_Data(int upload_id, string create_by, DateTime create_date, string create_org)
  2543. {
  2544. StringBuilder stringBuilder = new StringBuilder();
  2545. try
  2546. {
  2547. List<sqe_file_data> datas = LoadData_file_data(upload_id);
  2548. if (datas == null || datas.Count == 0)
  2549. {
  2550. stringBuilder.AppendLine("导入数据信息不存在!");
  2551. return stringBuilder.ToString();
  2552. }
  2553. //出货检验记录的文件格式校验
  2554. if (datas[0].c1.CompareTo("出货检验记录") != 0)
  2555. {
  2556. stringBuilder.AppendLine("文件不是【出货检验记录】要求的格式");
  2557. return stringBuilder.ToString();
  2558. }
  2559. if (datas[1].c1.CompareTo("供应商名称") != 0
  2560. || datas[1].c3.CompareTo("物料名称") != 0
  2561. || datas[1].c5.CompareTo("物料号") != 0
  2562. || datas[1].c7.CompareTo("物料版本号") != 0)
  2563. {
  2564. stringBuilder.AppendLine("文件不是【出货检验记录】要求的格式");
  2565. return stringBuilder.ToString();
  2566. }
  2567. if (datas[2].c1.CompareTo("日期") != 0
  2568. || datas[2].c3.CompareTo("批次号") != 0
  2569. || datas[2].c5.CompareTo("批次数量") != 0
  2570. || datas[2].c7.CompareTo("检验人员") != 0)
  2571. {
  2572. stringBuilder.AppendLine("文件不是【出货检验记录】要求的格式");
  2573. return stringBuilder.ToString();
  2574. }
  2575. string errorMsg;
  2576. sqe_oqc test = File_data_ToModel_oqc(datas, create_by, create_date, create_org, out errorMsg);
  2577. if (errorMsg != null && errorMsg.Length > 0)
  2578. {
  2579. stringBuilder.AppendLine(errorMsg);
  2580. return stringBuilder.ToString();
  2581. }
  2582. _sqe_oqc.BeginTransaction();
  2583. _sqe_oqc.Insert(test);
  2584. errorMsg = null;
  2585. List<sqe_oqc_standard> standards = File_data_ToModel_oqc_standard(datas, test, create_by, create_date, create_org, out errorMsg);
  2586. if (errorMsg != null && errorMsg.Length > 0)
  2587. {
  2588. _sqe_oqc.Rollback();
  2589. stringBuilder.AppendLine(errorMsg);
  2590. return stringBuilder.ToString();
  2591. }
  2592. _sqe_oqc_standard.BeginTransaction();
  2593. _sqe_oqc_standard.Insert(standards);
  2594. List<sqe_oqc_data> test_Datas = File_data_ToModel_oqc_data(datas, test, standards, create_by, create_date, create_org, out errorMsg);
  2595. if (errorMsg != null && errorMsg.Length > 0)
  2596. {
  2597. _sqe_oqc.Rollback();
  2598. _sqe_oqc_standard.Rollback();
  2599. stringBuilder.AppendLine(errorMsg);
  2600. return stringBuilder.ToString();
  2601. }
  2602. _sqe_oqc_data.Insert(test_Datas);
  2603. _sqe_oqc.CommitTransaction();
  2604. _sqe_oqc_standard.CommitTransaction();
  2605. }
  2606. catch (Exception ex)
  2607. {
  2608. stringBuilder.Append("数据导入失败!");
  2609. }
  2610. finally
  2611. {
  2612. }
  2613. return stringBuilder.ToString();
  2614. }
  2615. #region OQC
  2616. /// <summary>
  2617. /// 从原始数据行生成OQC的表头数据
  2618. /// </summary>
  2619. /// <param name="datas"></param>
  2620. /// <param name="create_by"></param>
  2621. /// <param name="create_date"></param>
  2622. /// <param name="create_org"></param>
  2623. /// <param name="errorMsg"></param>
  2624. /// <returns></returns>
  2625. public sqe_oqc File_data_ToModel_oqc(List<sqe_file_data> datas, string create_by, DateTime create_date, string create_org, out string errorMsg)
  2626. {
  2627. StringBuilder stringBuilder = new StringBuilder();
  2628. sqe_oqc model = new sqe_oqc();
  2629. DateTime timeValue;
  2630. decimal realValuel;
  2631. if (datas != null && datas.Count >= 4)
  2632. {
  2633. try
  2634. {
  2635. sqe_file_data data = datas[1];
  2636. model.supp_no = data.c2;
  2637. model.item_name = data.c4;
  2638. model.item_no = data.c6;
  2639. model.item_version = data.c8;
  2640. data = datas[2];
  2641. if (DateTime.TryParse(data.c2, out timeValue))
  2642. {
  2643. model.product_time = timeValue;
  2644. }
  2645. else
  2646. {
  2647. model.product_time = DateTime.Now;
  2648. }
  2649. model.batch_no = data.c4;
  2650. if (decimal.TryParse(data.c6, out realValuel))
  2651. {
  2652. model.batch_qty = realValuel;
  2653. }
  2654. model.test_person = data.c8;
  2655. data = datas[3];
  2656. model.sampling_standard = data.c2;
  2657. if (decimal.TryParse(data.c4, out realValuel))
  2658. {
  2659. model.sampling_number = realValuel;
  2660. }
  2661. model.test_result = data.c8;
  2662. }
  2663. catch (Exception ex)
  2664. {
  2665. WLLog.Error("Excel数据解析问题:", ex);
  2666. }
  2667. model.create_by = create_by;
  2668. model.create_date = create_date;
  2669. model.create_org = create_org;
  2670. errorMsg = string.Empty;
  2671. return model;
  2672. }
  2673. else
  2674. {
  2675. errorMsg = stringBuilder.ToString();
  2676. return null;
  2677. }
  2678. }
  2679. /// <summary>
  2680. /// 从原始数据行生成OQC的检验标准
  2681. /// </summary>
  2682. /// <param name="datas"></param>
  2683. /// <param name="test"></param>
  2684. /// <param name="create_by"></param>
  2685. /// <param name="create_date"></param>
  2686. /// <param name="create_org"></param>
  2687. /// <param name="errorMsg"></param>
  2688. /// <returns></returns>
  2689. public List<sqe_oqc_standard> File_data_ToModel_oqc_standard(List<sqe_file_data> datas, sqe_oqc test, string create_by, DateTime create_date, string create_org, out string errorMsg)
  2690. {
  2691. StringBuilder stringBuilder = new StringBuilder();
  2692. List<sqe_oqc_standard> modelList = new List<sqe_oqc_standard>();
  2693. decimal realValuel;
  2694. if (datas != null && datas.Count >= 13)
  2695. {
  2696. try
  2697. {
  2698. //标准的起始位置
  2699. int index = 4;
  2700. sqe_file_data dataRow = datas[index];
  2701. #region 处理尺寸的表头
  2702. for (int i = 2; i < 10; i++)
  2703. {
  2704. Object obj = GetFieldValue(dataRow, "c" + i.ToString());
  2705. if (obj != null)
  2706. {
  2707. sqe_oqc_standard model = new sqe_oqc_standard();
  2708. model.standard_no = obj.ToString();
  2709. model.create_by = create_by;
  2710. model.create_date = create_date;
  2711. model.create_org = create_org;
  2712. model.oqc_id = test.id;
  2713. modelList.Add(model);
  2714. }
  2715. else
  2716. {
  2717. break;
  2718. }
  2719. }
  2720. #endregion 处理尺寸的表头
  2721. //处理表头的具体值
  2722. for (int i = 0; i < 9 && i < modelList.Count; i++)
  2723. {
  2724. string fieldName = "c" + (i + 2).ToString();
  2725. sqe_oqc_standard model = modelList[i];
  2726. dataRow = datas[index + 1];
  2727. Object obj = GetFieldValue(dataRow, fieldName);
  2728. if (obj != null)
  2729. {
  2730. model.standard_no = obj.ToString();
  2731. }
  2732. dataRow = datas[index + 2];
  2733. obj = GetFieldValue(dataRow, fieldName);
  2734. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2735. {
  2736. model.standard_value = realValuel;
  2737. }
  2738. dataRow = datas[index + 3];
  2739. obj = GetFieldValue(dataRow, fieldName);
  2740. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2741. {
  2742. model.delta_up = realValuel;
  2743. }
  2744. dataRow = datas[index + 4];
  2745. obj = GetFieldValue(dataRow, fieldName);
  2746. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2747. {
  2748. model.delta_down = realValuel;
  2749. }
  2750. dataRow = datas[index + 5];
  2751. obj = GetFieldValue(dataRow, fieldName);
  2752. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2753. {
  2754. model.standard_max = realValuel;
  2755. }
  2756. dataRow = datas[index + 6];
  2757. obj = GetFieldValue(dataRow, fieldName);
  2758. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2759. {
  2760. model.standard_min = realValuel;
  2761. }
  2762. }
  2763. }
  2764. catch (Exception ex)
  2765. {
  2766. WLLog.Error("Excel数据解析问题:", ex);
  2767. }
  2768. errorMsg = stringBuilder.ToString();
  2769. return modelList;
  2770. }
  2771. else
  2772. {
  2773. errorMsg = stringBuilder.ToString();
  2774. return null;
  2775. }
  2776. }
  2777. /// <summary>
  2778. /// 获取某个对象的某个属性的值
  2779. /// </summary>
  2780. /// <param name="obj"></param>
  2781. /// <param name="fieldName"></param>
  2782. /// <returns></returns>
  2783. private Object GetFieldValue(Object obj, string fieldName)
  2784. {
  2785. //获得对象的所有public属性
  2786. PropertyInfo[] pis = obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
  2787. //如果获得了属性
  2788. if (pis != null)
  2789. {
  2790. foreach (PropertyInfo pi in pis)//针对每一个属性进行循环
  2791. {
  2792. if (pi.Name.CompareTo(fieldName) == 0)
  2793. {
  2794. Object objValue = pi.GetValue(obj);
  2795. if (objValue != null && objValue.ToString().Length > 0)
  2796. {
  2797. return objValue;
  2798. }
  2799. }
  2800. }
  2801. }
  2802. return null;
  2803. }
  2804. /// <summary>
  2805. /// 从原始数据行生成OQC的数据
  2806. /// </summary>
  2807. /// <param name="datas"></param>
  2808. /// <param name="test"></param>
  2809. /// <param name="standards"></param>
  2810. /// <param name="create_by"></param>
  2811. /// <param name="create_date"></param>
  2812. /// <param name="create_org"></param>
  2813. /// <param name="errorMsg"></param>
  2814. /// <returns></returns>
  2815. public List<sqe_oqc_data> File_data_ToModel_oqc_data(List<sqe_file_data> datas, sqe_oqc test, List<sqe_oqc_standard> standards, string create_by, DateTime create_date, string create_org, out string errorMsg)
  2816. {
  2817. StringBuilder stringBuilder = new StringBuilder();
  2818. List<sqe_oqc_data> modelList = new List<sqe_oqc_data>();
  2819. decimal realValuel;
  2820. if (datas != null && datas.Count >= 12)
  2821. {
  2822. for (int i = 11; i < datas.Count; i++)
  2823. {
  2824. sqe_file_data dataRow = datas[i];
  2825. if ((dataRow.c1 == null || dataRow.c1.Length == 0 || dataRow.c1 == "0") && (dataRow.c2 == null || dataRow.c2.Length == 0))
  2826. {
  2827. break;
  2828. }
  2829. //初始化每一层的数据集合
  2830. List<sqe_oqc_data> test_datas = new List<sqe_oqc_data>();
  2831. for (int j = 0; j < standards.Count; j++)
  2832. {
  2833. sqe_oqc_data data = new sqe_oqc_data();
  2834. data.oqc_id = standards[j].oqc_id;
  2835. data.standard_id = standards[j].id;
  2836. data.create_by = create_by;
  2837. data.create_date = create_date;
  2838. data.create_org = create_org;
  2839. test_datas.Add(data);
  2840. }
  2841. try
  2842. {
  2843. //将每一个检测标准的值从记录行中取出来
  2844. for (int j = 0; j < test_datas.Count; j++)
  2845. {
  2846. sqe_oqc_data data = test_datas[j];
  2847. data.data_no = dataRow.c1;
  2848. string fieldName = "c" + (j + 2).ToString();
  2849. Object obj = GetFieldValue(dataRow, fieldName);
  2850. if (obj != null && obj.ToString().Length > 0 && decimal.TryParse(obj.ToString(), out realValuel))
  2851. {
  2852. data.data_value = realValuel;
  2853. }
  2854. else
  2855. {
  2856. data.data_value = null;
  2857. }
  2858. }
  2859. File_data_ToModel_oqc_data_Add(modelList, test_datas);
  2860. }
  2861. catch (Exception ex)
  2862. {
  2863. WLLog.Error("Excel数据解析_原始数据转换到对象实体的问题:", ex);
  2864. }
  2865. }
  2866. errorMsg = string.Empty;
  2867. return modelList;
  2868. }
  2869. else
  2870. {
  2871. errorMsg = stringBuilder.ToString();
  2872. return null;
  2873. }
  2874. }
  2875. /// <summary>
  2876. /// 将转换的数据插入到返回结果数据集中,处理掉异常数据
  2877. /// </summary>
  2878. /// <param name="dataDest"></param>
  2879. /// <param name="dataSource"></param>
  2880. private void File_data_ToModel_oqc_data_Add(List<sqe_oqc_data> dataDest, List<sqe_oqc_data> dataSource)
  2881. {
  2882. if (dataSource != null && dataSource.Count > 0)
  2883. {
  2884. for (int i = 0; i < dataSource.Count; i++)
  2885. {
  2886. sqe_oqc_data data = dataSource[i];
  2887. if (data.data_no != null && data.data_no.Length > 0 && data.data_value != null)
  2888. {
  2889. dataDest.Add(data);
  2890. }
  2891. }
  2892. }
  2893. }
  2894. #endregion OQC
  2895. #region Fct
  2896. /// <summary>
  2897. /// 将字符串插入到数据库
  2898. /// </summary>
  2899. /// <param name="data"></param>
  2900. /// <param name="create_by"></param>
  2901. /// <param name="create_date"></param>
  2902. /// <param name="create_org"></param>
  2903. /// <returns></returns>
  2904. public string Import_Fct_From_Data(String data, string create_by, DateTime create_date, string create_org)
  2905. {
  2906. StringBuilder stringBuilder = new StringBuilder();
  2907. sqe_fct model = new sqe_fct();
  2908. List<sqe_fct_data> modelList = new List<sqe_fct_data>();
  2909. DateTime timeValue;
  2910. decimal realValuel;
  2911. try
  2912. {
  2913. JObject json = JObject.Parse(data);
  2914. model.SpID = json["SpID"].ToString();
  2915. model.WLID = json["WLID"].ToString();
  2916. model.WPID = json["WPID"].ToString();
  2917. model.op_side = json["OpSide"].ToString();
  2918. model.LineID = json["LineID"].ToString();
  2919. model.OpID = json["OpID"].ToString();
  2920. model.bar_code = json["BarCode"].ToString();
  2921. model.WONO = json["WONO"].ToString();
  2922. model.program = json["Program"].ToString();
  2923. model.pro_version = json["ProVersion"].ToString();
  2924. model.test_result = json["testResult"].ToString();
  2925. model.msg = json["Msg"].ToString();
  2926. model.create_by = create_by;
  2927. model.create_date = create_date;
  2928. model.create_org = create_org;
  2929. JArray array = JArray.Parse(json["testData"].ToString());
  2930. //将每一个检测标准的值从记录行中取出来
  2931. for (int j = 0; array != null && j < array.Count; j++)
  2932. {
  2933. sqe_fct_data data1 = new sqe_fct_data();
  2934. data1.name = array[j]["Name"].ToString();
  2935. data1.unit = array[j]["Unit"].ToString();
  2936. data1.lower = decimal.Parse(array[j]["Lower"].ToString());
  2937. data1.upper = decimal.Parse(array[j]["Upper"].ToString());
  2938. data1.actual = decimal.Parse(array[j]["Actual"].ToString());
  2939. data1.result = array[j]["result"].ToString();
  2940. data1.start_time = DateTime.Parse(array[j]["StartTime"].ToString());
  2941. data1.end_time = DateTime.Parse(array[j]["endTime"].ToString());
  2942. data1.detial = array[j]["Detial"].ToString();
  2943. data1.create_by = create_by;
  2944. data1.create_date = create_date;
  2945. data1.create_org = create_org;
  2946. modelList.Add(data1);
  2947. }
  2948. }
  2949. catch (Exception ex)
  2950. {
  2951. stringBuilder.Append(ex.ToString());
  2952. WLLog.Error("Fct上传数据解析_原始数据转换到对象实体的问题:", ex);
  2953. }
  2954. try
  2955. {
  2956. _sqe_fct.BeginTransaction();
  2957. _sqe_fct.Insert(model);
  2958. foreach (var item in modelList)
  2959. {
  2960. item.fct_id = model.id;
  2961. }
  2962. _sqe_fct_data.BeginTransaction();
  2963. _sqe_fct_data.Insert(modelList);
  2964. _sqe_fct_data.CommitTransaction();
  2965. _sqe_fct.CommitTransaction();
  2966. }
  2967. catch (Exception ex)
  2968. {
  2969. _sqe_fct_data.Rollback();
  2970. _sqe_fct.Rollback();
  2971. stringBuilder.Append(ex.ToString());
  2972. }
  2973. return stringBuilder.ToString();
  2974. }
  2975. #endregion Fct
  2976. }
  2977. }