SqeExcelService.cs 134 KB

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