SqeExcelService.cs 128 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032
  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. string errorMsg;
  487. sqe_cto_test test = File_data_ToModel_test(datas, create_by, create_date, create_org, out errorMsg);
  488. if (errorMsg != null && errorMsg.Length > 0)
  489. {
  490. stringBuilder.AppendLine(errorMsg);
  491. return stringBuilder.ToString();
  492. }
  493. _sqe_cto_test.BeginTransaction();
  494. _sqe_cto_test.Insert(test);
  495. errorMsg = null;
  496. List<sqe_cto_test_standard> standards = File_data_ToModel_test_standard(datas, test, create_by, create_date, create_org, out errorMsg);
  497. if (errorMsg != null && errorMsg.Length > 0)
  498. {
  499. _sqe_cto_test.Rollback();
  500. stringBuilder.AppendLine(errorMsg);
  501. return stringBuilder.ToString();
  502. }
  503. _sqe_cto_test_standard.BeginTransaction();
  504. _sqe_cto_test_standard.Insert(standards);
  505. List<sqe_cto_test_data> test_Datas = File_data_ToModel_test_data(datas, test, standards, create_by, create_date, create_org, out errorMsg);
  506. if (errorMsg != null && errorMsg.Length > 0)
  507. {
  508. _sqe_cto_test.Rollback();
  509. _sqe_cto_test_standard.Rollback();
  510. stringBuilder.AppendLine(errorMsg);
  511. return stringBuilder.ToString();
  512. }
  513. _sqe_cto_test_data.Insert(test_Datas);
  514. _sqe_cto_test.CommitTransaction();
  515. _sqe_cto_test_standard.CommitTransaction();
  516. }
  517. catch (Exception ex)
  518. {
  519. stringBuilder.Append("数据导入失败!");
  520. }
  521. finally
  522. {
  523. }
  524. return stringBuilder.ToString();
  525. }
  526. /// <summary>
  527. /// 依据id,从sqe_file_upload和sqe_file_data,加载数据
  528. /// </summary>
  529. /// <param name="upload_id"></param>
  530. /// <returns></returns>
  531. public List<sqe_file_data> LoadData_file_data(int upload_id)
  532. {
  533. List<sqe_file_data> datas = _sqe_file_data.Select(a => a.file_id == upload_id).OrderBy(a => a.id).ToList();
  534. return datas;
  535. }
  536. #region 产品特性
  537. 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)
  538. {
  539. StringBuilder stringBuilder = new StringBuilder();
  540. sqe_cto_test model = new sqe_cto_test();
  541. DateTime timeValue;
  542. decimal realValuel;
  543. if (datas != null && datas.Count >= 5)
  544. {
  545. try
  546. {
  547. sqe_file_data data = datas[1];
  548. if (DateTime.TryParse(data.c2, out timeValue))
  549. {
  550. model.product_time = timeValue;
  551. }
  552. else
  553. {
  554. //model.product_time = DateTime.Parse("2000-01-01");
  555. model.product_time = DateTime.Now;
  556. }
  557. model.shift_no = data.c4;
  558. model.item_no = data.c6;
  559. model.item_name = data.c8;
  560. data = datas[2];
  561. model.material_batch = data.c2;
  562. if (decimal.TryParse(data.c4, out realValuel))
  563. {
  564. model.material_used = realValuel;
  565. }
  566. model.item_batch = data.c6;
  567. if (decimal.TryParse(data.c8, out realValuel))
  568. {
  569. model.item_qty = realValuel;
  570. }
  571. data = datas[3];
  572. model.op_pre = data.c2;
  573. model.op_pre_batch = data.c4;
  574. model.op_current = data.c6;
  575. model.op_batch = data.c8;
  576. data = datas[4];
  577. model.device_name = data.c2;
  578. model.device_no = data.c4;
  579. if (decimal.TryParse(data.c8, out realValuel))
  580. {
  581. model.sampling_number = realValuel;
  582. }
  583. }
  584. catch (Exception ex)
  585. {
  586. WLLog.Error("Excel数据解析问题:", ex);
  587. }
  588. model.create_by = create_by;
  589. model.create_date = create_date;
  590. model.create_org = create_org;
  591. errorMsg = string.Empty;
  592. return model;
  593. }
  594. else
  595. {
  596. errorMsg = stringBuilder.ToString();
  597. return null;
  598. }
  599. }
  600. 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)
  601. {
  602. StringBuilder stringBuilder = new StringBuilder();
  603. List<sqe_cto_test_standard> modelList = new List<sqe_cto_test_standard>();
  604. decimal realValuel;
  605. if (datas != null && datas.Count >= 13)
  606. {
  607. try
  608. {
  609. //标准的起始位置
  610. int index = 5;
  611. sqe_file_data dataRow = datas[index];
  612. #region 处理尺寸的表头
  613. if (dataRow.c3 != null && dataRow.c3.Length > 0)
  614. {
  615. sqe_cto_test_standard model = new sqe_cto_test_standard();
  616. model.standard_no = dataRow.c3;
  617. model.create_by = create_by;
  618. model.create_date = create_date;
  619. model.create_org = create_org;
  620. model.test_id = test.id;
  621. modelList.Add(model);
  622. }
  623. if (dataRow.c4 != null && dataRow.c4.Length > 0)
  624. {
  625. sqe_cto_test_standard model = new sqe_cto_test_standard();
  626. model.standard_no = dataRow.c4;
  627. model.create_by = create_by;
  628. model.create_date = create_date;
  629. model.create_org = create_org;
  630. model.test_id = test.id;
  631. modelList.Add(model);
  632. }
  633. if (dataRow.c5 != null && dataRow.c5.Length > 0)
  634. {
  635. sqe_cto_test_standard model = new sqe_cto_test_standard();
  636. model.standard_no = dataRow.c5;
  637. model.create_by = create_by;
  638. model.create_date = create_date;
  639. model.create_org = create_org;
  640. model.test_id = test.id;
  641. modelList.Add(model);
  642. }
  643. if (dataRow.c6 != null && dataRow.c6.Length > 0)
  644. {
  645. sqe_cto_test_standard model = new sqe_cto_test_standard();
  646. model.standard_no = dataRow.c6;
  647. model.create_by = create_by;
  648. model.create_date = create_date;
  649. model.create_org = create_org;
  650. model.test_id = test.id;
  651. modelList.Add(model);
  652. }
  653. if (dataRow.c7 != null && dataRow.c7.Length > 0)
  654. {
  655. sqe_cto_test_standard model = new sqe_cto_test_standard();
  656. model.standard_no = dataRow.c7;
  657. model.create_by = create_by;
  658. model.create_date = create_date;
  659. model.create_org = create_org;
  660. model.test_id = test.id;
  661. modelList.Add(model);
  662. }
  663. if (dataRow.c8 != null && dataRow.c8.Length > 0)
  664. {
  665. sqe_cto_test_standard model = new sqe_cto_test_standard();
  666. model.standard_no = dataRow.c8;
  667. model.create_by = create_by;
  668. model.create_date = create_date;
  669. model.create_org = create_org;
  670. model.test_id = test.id;
  671. modelList.Add(model);
  672. }
  673. if (dataRow.c9 != null && dataRow.c9.Length > 0)
  674. {
  675. sqe_cto_test_standard model = new sqe_cto_test_standard();
  676. model.standard_no = dataRow.c9;
  677. model.create_by = create_by;
  678. model.create_date = create_date;
  679. model.create_org = create_org;
  680. model.test_id = test.id;
  681. modelList.Add(model);
  682. }
  683. if (dataRow.c10 != null && dataRow.c10.Length > 0)
  684. {
  685. sqe_cto_test_standard model = new sqe_cto_test_standard();
  686. model.standard_no = dataRow.c10;
  687. model.create_by = create_by;
  688. model.create_date = create_date;
  689. model.create_org = create_org;
  690. model.test_id = test.id;
  691. modelList.Add(model);
  692. }
  693. if (dataRow.c11 != null && dataRow.c11.Length > 0)
  694. {
  695. sqe_cto_test_standard model = new sqe_cto_test_standard();
  696. model.standard_no = dataRow.c11;
  697. model.create_by = create_by;
  698. model.create_date = create_date;
  699. model.create_org = create_org;
  700. model.test_id = test.id;
  701. modelList.Add(model);
  702. }
  703. #endregion 处理尺寸的表头
  704. if (modelList.Count > 0)
  705. {
  706. sqe_cto_test_standard model = modelList[0];
  707. dataRow = datas[index + 1];
  708. model.sampling_count = int.Parse(dataRow.c3);
  709. dataRow = datas[index + 2];
  710. model.is_associated_size = dataRow.c3;
  711. dataRow = datas[index + 3];
  712. if (dataRow.c3 != null && decimal.TryParse(dataRow.c3, out realValuel))
  713. {
  714. model.standard_value = realValuel;
  715. }
  716. dataRow = datas[index + 4];
  717. if (dataRow.c3 != null && decimal.TryParse(dataRow.c3, out realValuel))
  718. {
  719. model.delta_up = realValuel;
  720. }
  721. dataRow = datas[index + 5];
  722. if (dataRow.c3 != null && decimal.TryParse(dataRow.c3, out realValuel))
  723. {
  724. model.delta_down = realValuel;
  725. }
  726. dataRow = datas[index + 6];
  727. if (dataRow.c3 != null && decimal.TryParse(dataRow.c3, out realValuel))
  728. {
  729. model.standard_max = realValuel;
  730. }
  731. dataRow = datas[index + 7];
  732. if (dataRow.c3 != null && decimal.TryParse(dataRow.c3, out realValuel))
  733. {
  734. model.standard_min = realValuel;
  735. }
  736. }
  737. if (modelList.Count > 1)
  738. {
  739. sqe_cto_test_standard model = modelList[1];
  740. dataRow = datas[index + 1];
  741. model.sampling_count = int.Parse(dataRow.c4);
  742. dataRow = datas[index + 2];
  743. model.is_associated_size = dataRow.c4;
  744. dataRow = datas[index + 3];
  745. if (dataRow.c4 != null && decimal.TryParse(dataRow.c4, out realValuel))
  746. {
  747. model.standard_value = realValuel;
  748. }
  749. dataRow = datas[index + 4];
  750. if (dataRow.c4 != null && decimal.TryParse(dataRow.c4, out realValuel))
  751. {
  752. model.delta_up = realValuel;
  753. }
  754. dataRow = datas[index + 5];
  755. if (dataRow.c4 != null && decimal.TryParse(dataRow.c4, out realValuel))
  756. {
  757. model.delta_down = realValuel;
  758. }
  759. dataRow = datas[index + 6];
  760. if (dataRow.c4 != null && decimal.TryParse(dataRow.c4, out realValuel))
  761. {
  762. model.standard_max = realValuel;
  763. }
  764. dataRow = datas[index + 7];
  765. if (dataRow.c4 != null && decimal.TryParse(dataRow.c4, out realValuel))
  766. {
  767. model.standard_min = realValuel;
  768. }
  769. }
  770. if (modelList.Count > 2)
  771. {
  772. sqe_cto_test_standard model = modelList[2];
  773. dataRow = datas[index + 1];
  774. model.sampling_count = int.Parse(dataRow.c5);
  775. dataRow = datas[index + 2];
  776. model.is_associated_size = dataRow.c5;
  777. dataRow = datas[index + 3];
  778. if (dataRow.c5 != null && decimal.TryParse(dataRow.c5, out realValuel))
  779. {
  780. model.standard_value = realValuel;
  781. }
  782. dataRow = datas[index + 4];
  783. if (dataRow.c5 != null && decimal.TryParse(dataRow.c5, out realValuel))
  784. {
  785. model.delta_up = realValuel;
  786. }
  787. dataRow = datas[index + 5];
  788. if (dataRow.c5 != null && decimal.TryParse(dataRow.c5, out realValuel))
  789. {
  790. model.delta_down = realValuel;
  791. }
  792. dataRow = datas[index + 6];
  793. if (dataRow.c5 != null && decimal.TryParse(dataRow.c5, out realValuel))
  794. {
  795. model.standard_max = realValuel;
  796. }
  797. dataRow = datas[index + 7];
  798. if (dataRow.c5 != null && decimal.TryParse(dataRow.c5, out realValuel))
  799. {
  800. model.standard_min = realValuel;
  801. }
  802. }
  803. if (modelList.Count > 3)
  804. {
  805. sqe_cto_test_standard model = modelList[3];
  806. dataRow = datas[index + 1];
  807. model.sampling_count = int.Parse(dataRow.c6);
  808. dataRow = datas[index + 2];
  809. model.is_associated_size = dataRow.c6;
  810. dataRow = datas[index + 3];
  811. if (dataRow.c6 != null && decimal.TryParse(dataRow.c6, out realValuel))
  812. {
  813. model.standard_value = realValuel;
  814. }
  815. dataRow = datas[index + 4];
  816. if (dataRow.c6 != null && decimal.TryParse(dataRow.c6, out realValuel))
  817. {
  818. model.delta_up = realValuel;
  819. }
  820. dataRow = datas[index + 5];
  821. if (dataRow.c6 != null && decimal.TryParse(dataRow.c6, out realValuel))
  822. {
  823. model.delta_down = realValuel;
  824. }
  825. dataRow = datas[index + 6];
  826. if (dataRow.c6 != null && decimal.TryParse(dataRow.c6, out realValuel))
  827. {
  828. model.standard_max = realValuel;
  829. }
  830. dataRow = datas[index + 7];
  831. if (dataRow.c6 != null && decimal.TryParse(dataRow.c6, out realValuel))
  832. {
  833. model.standard_min = realValuel;
  834. }
  835. }
  836. if (modelList.Count > 4)
  837. {
  838. sqe_cto_test_standard model = modelList[4];
  839. dataRow = datas[index + 1];
  840. model.sampling_count = int.Parse(dataRow.c7);
  841. dataRow = datas[index + 2];
  842. model.is_associated_size = dataRow.c7;
  843. dataRow = datas[index + 3];
  844. if (dataRow.c7 != null && decimal.TryParse(dataRow.c7, out realValuel))
  845. {
  846. model.standard_value = realValuel;
  847. }
  848. dataRow = datas[index + 4];
  849. if (dataRow.c7 != null && decimal.TryParse(dataRow.c7, out realValuel))
  850. {
  851. model.delta_up = realValuel;
  852. }
  853. dataRow = datas[index + 5];
  854. if (dataRow.c7 != null && decimal.TryParse(dataRow.c7, out realValuel))
  855. {
  856. model.delta_down = realValuel;
  857. }
  858. dataRow = datas[index + 6];
  859. if (dataRow.c7 != null && decimal.TryParse(dataRow.c7, out realValuel))
  860. {
  861. model.standard_max = realValuel;
  862. }
  863. dataRow = datas[index + 7];
  864. if (dataRow.c7 != null && decimal.TryParse(dataRow.c7, out realValuel))
  865. {
  866. model.standard_min = realValuel;
  867. }
  868. }
  869. if (modelList.Count > 5)
  870. {
  871. sqe_cto_test_standard model = modelList[5];
  872. dataRow = datas[index + 1];
  873. model.sampling_count = int.Parse(dataRow.c8);
  874. dataRow = datas[index + 2];
  875. model.is_associated_size = dataRow.c8;
  876. dataRow = datas[index + 3];
  877. if (dataRow.c8 != null && decimal.TryParse(dataRow.c8, out realValuel))
  878. {
  879. model.standard_value = realValuel;
  880. }
  881. dataRow = datas[index + 4];
  882. if (dataRow.c8 != null && decimal.TryParse(dataRow.c8, out realValuel))
  883. {
  884. model.delta_up = realValuel;
  885. }
  886. dataRow = datas[index + 5];
  887. if (dataRow.c8 != null && decimal.TryParse(dataRow.c8, out realValuel))
  888. {
  889. model.delta_down = realValuel;
  890. }
  891. dataRow = datas[index + 6];
  892. if (dataRow.c8 != null && decimal.TryParse(dataRow.c8, out realValuel))
  893. {
  894. model.standard_max = realValuel;
  895. }
  896. dataRow = datas[index + 7];
  897. if (dataRow.c8 != null && decimal.TryParse(dataRow.c8, out realValuel))
  898. {
  899. model.standard_min = realValuel;
  900. }
  901. }
  902. if (modelList.Count > 6)
  903. {
  904. sqe_cto_test_standard model = modelList[6];
  905. dataRow = datas[index + 1];
  906. model.sampling_count = int.Parse(dataRow.c9);
  907. dataRow = datas[index + 2];
  908. model.is_associated_size = dataRow.c9;
  909. dataRow = datas[index + 3];
  910. if (dataRow.c9 != null && decimal.TryParse(dataRow.c9, out realValuel))
  911. {
  912. model.standard_value = realValuel;
  913. }
  914. dataRow = datas[index + 4];
  915. if (dataRow.c9 != null && decimal.TryParse(dataRow.c9, out realValuel))
  916. {
  917. model.delta_up = realValuel;
  918. }
  919. dataRow = datas[index + 5];
  920. if (dataRow.c9 != null && decimal.TryParse(dataRow.c9, out realValuel))
  921. {
  922. model.delta_down = realValuel;
  923. }
  924. dataRow = datas[index + 6];
  925. if (dataRow.c9 != null && decimal.TryParse(dataRow.c9, out realValuel))
  926. {
  927. model.standard_max = realValuel;
  928. }
  929. dataRow = datas[index + 7];
  930. if (dataRow.c9 != null && decimal.TryParse(dataRow.c9, out realValuel))
  931. {
  932. model.standard_min = realValuel;
  933. }
  934. }
  935. if (modelList.Count > 7)
  936. {
  937. sqe_cto_test_standard model = modelList[7];
  938. dataRow = datas[index + 1];
  939. model.sampling_count = int.Parse(dataRow.c10);
  940. dataRow = datas[index + 2];
  941. model.is_associated_size = dataRow.c10;
  942. dataRow = datas[index + 3];
  943. if (dataRow.c10 != null && decimal.TryParse(dataRow.c10, out realValuel))
  944. {
  945. model.standard_value = realValuel;
  946. }
  947. dataRow = datas[index + 4];
  948. if (dataRow.c10 != null && decimal.TryParse(dataRow.c10, out realValuel))
  949. {
  950. model.delta_up = realValuel;
  951. }
  952. dataRow = datas[index + 5];
  953. if (dataRow.c10 != null && decimal.TryParse(dataRow.c10, out realValuel))
  954. {
  955. model.delta_down = realValuel;
  956. }
  957. dataRow = datas[index + 6];
  958. if (dataRow.c10 != null && decimal.TryParse(dataRow.c10, out realValuel))
  959. {
  960. model.standard_max = realValuel;
  961. }
  962. dataRow = datas[index + 7];
  963. if (dataRow.c10 != null && decimal.TryParse(dataRow.c10, out realValuel))
  964. {
  965. model.standard_min = realValuel;
  966. }
  967. }
  968. if (modelList.Count > 8)
  969. {
  970. sqe_cto_test_standard model = modelList[8];
  971. dataRow = datas[index + 1];
  972. model.sampling_count = int.Parse(dataRow.c11);
  973. dataRow = datas[index + 2];
  974. model.is_associated_size = dataRow.c11;
  975. dataRow = datas[index + 3];
  976. if (dataRow.c11 != null && decimal.TryParse(dataRow.c11, out realValuel))
  977. {
  978. model.standard_value = realValuel;
  979. }
  980. dataRow = datas[index + 4];
  981. if (dataRow.c11 != null && decimal.TryParse(dataRow.c11, out realValuel))
  982. {
  983. model.delta_up = realValuel;
  984. }
  985. dataRow = datas[index + 5];
  986. if (dataRow.c11 != null && decimal.TryParse(dataRow.c11, out realValuel))
  987. {
  988. model.delta_down = realValuel;
  989. }
  990. dataRow = datas[index + 6];
  991. if (dataRow.c11 != null && decimal.TryParse(dataRow.c11, out realValuel))
  992. {
  993. model.standard_max = realValuel;
  994. }
  995. dataRow = datas[index + 7];
  996. if (dataRow.c11 != null && decimal.TryParse(dataRow.c11, out realValuel))
  997. {
  998. model.standard_min = realValuel;
  999. }
  1000. }
  1001. }
  1002. catch (Exception ex)
  1003. {
  1004. WLLog.Error("Excel数据解析问题:", ex);
  1005. }
  1006. errorMsg = stringBuilder.ToString();
  1007. return modelList;
  1008. }
  1009. else
  1010. {
  1011. errorMsg = stringBuilder.ToString();
  1012. return null;
  1013. }
  1014. }
  1015. 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)
  1016. {
  1017. StringBuilder stringBuilder = new StringBuilder();
  1018. List<sqe_cto_test_data> modelList = new List<sqe_cto_test_data>();
  1019. decimal realValuel;
  1020. if (datas != null && datas.Count >= 15)
  1021. {
  1022. for (int i = 14; i < datas.Count; i++)
  1023. {
  1024. sqe_file_data dataRow = datas[i];
  1025. if ((dataRow.c1 == null || dataRow.c1.Length == 0 || dataRow.c1 == "0") && (dataRow.c2 == null || dataRow.c2.Length == 0))
  1026. {
  1027. break;
  1028. }
  1029. //初始化每一层的数据集合
  1030. List<sqe_cto_test_data> test_datas = new List<sqe_cto_test_data>();
  1031. for (int j = 0; j < standards.Count; j++)
  1032. {
  1033. sqe_cto_test_data data = new sqe_cto_test_data();
  1034. data.test_id = standards[j].test_id;
  1035. data.standard_id = standards[j].id;
  1036. data.create_by = create_by;
  1037. data.create_date = create_date;
  1038. data.create_org = create_org;
  1039. test_datas.Add(data);
  1040. }
  1041. try
  1042. {
  1043. //将每一个检测标准的值从记录行中取出来
  1044. if (test_datas.Count > 0)
  1045. {
  1046. sqe_cto_test_data data = test_datas[0];
  1047. data.data_no = dataRow.c1;
  1048. if (dataRow.c2 != null)
  1049. {
  1050. String s = dataRow.c2.ToString();
  1051. if (s != null && s.Length > 9)
  1052. {
  1053. s = s.Substring(s.Length - 9);
  1054. }
  1055. DateTime date;
  1056. if (DateTime.TryParse(test.product_time.ToString("yyyy-MM-dd ") + s, out date))
  1057. {
  1058. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1059. }
  1060. }
  1061. if (dataRow.c3 != null && dataRow.c3.Length > 0 && decimal.TryParse(dataRow.c3, out realValuel))
  1062. {
  1063. data.data_value = realValuel;
  1064. }
  1065. else
  1066. {
  1067. data.data_value = null;
  1068. }
  1069. }
  1070. if (test_datas.Count > 1)
  1071. {
  1072. sqe_cto_test_data data = test_datas[1];
  1073. data.data_no = dataRow.c1;
  1074. if (dataRow.c2 != null)
  1075. {
  1076. String s = dataRow.c2.ToString();
  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.c4 != null && dataRow.c4.Length > 0 && decimal.TryParse(dataRow.c4, out realValuel))
  1084. {
  1085. data.data_value = realValuel;
  1086. }
  1087. else
  1088. {
  1089. data.data_value = null;
  1090. }
  1091. }
  1092. if (test_datas.Count > 2)
  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.c5 != null && dataRow.c5.Length > 0 && decimal.TryParse(dataRow.c5, out realValuel))
  1106. {
  1107. data.data_value = realValuel;
  1108. }
  1109. else
  1110. {
  1111. data.data_value = null;
  1112. }
  1113. }
  1114. if (test_datas.Count > 3)
  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.c6 != null && dataRow.c6.Length > 0 && decimal.TryParse(dataRow.c6, out realValuel))
  1128. {
  1129. data.data_value = realValuel;
  1130. }
  1131. else
  1132. {
  1133. data.data_value = null;
  1134. }
  1135. }
  1136. if (test_datas.Count > 4)
  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.c7 != null && dataRow.c7.Length > 0 && decimal.TryParse(dataRow.c7, out realValuel))
  1150. {
  1151. data.data_value = realValuel;
  1152. }
  1153. else
  1154. {
  1155. data.data_value = null;
  1156. }
  1157. }
  1158. if (test_datas.Count > 5)
  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.c8 != null && dataRow.c8.Length > 0 && decimal.TryParse(dataRow.c8, out realValuel))
  1172. {
  1173. data.data_value = realValuel;
  1174. }
  1175. else
  1176. {
  1177. data.data_value = null;
  1178. }
  1179. }
  1180. if (test_datas.Count > 6)
  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.c9 != null && dataRow.c9.Length > 0 && decimal.TryParse(dataRow.c9, out realValuel))
  1194. {
  1195. data.data_value = realValuel;
  1196. }
  1197. else
  1198. {
  1199. data.data_value = null;
  1200. }
  1201. }
  1202. if (test_datas.Count > 7)
  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.c10 != null && dataRow.c10.Length > 0 && decimal.TryParse(dataRow.c10, out realValuel))
  1216. {
  1217. data.data_value = realValuel;
  1218. }
  1219. else
  1220. {
  1221. data.data_value = null;
  1222. }
  1223. }
  1224. if (test_datas.Count > 8)
  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.c11 != null && dataRow.c11.Length > 0 && decimal.TryParse(dataRow.c11, out realValuel))
  1238. {
  1239. data.data_value = realValuel;
  1240. }
  1241. else
  1242. {
  1243. data.data_value = null;
  1244. }
  1245. }
  1246. File_data_ToModel_test_data_Add(modelList, test_datas);
  1247. }
  1248. catch (Exception ex)
  1249. {
  1250. WLLog.Error("Excel数据解析_原始数据转换到对象实体的问题:", ex);
  1251. }
  1252. }
  1253. errorMsg = string.Empty;
  1254. return modelList;
  1255. }
  1256. else
  1257. {
  1258. errorMsg = stringBuilder.ToString();
  1259. return null;
  1260. }
  1261. }
  1262. /// <summary>
  1263. /// 将转换的数据插入到返回结果数据集中,处理掉异常数据
  1264. /// </summary>
  1265. /// <param name="dataDest"></param>
  1266. /// <param name="dataSource"></param>
  1267. private void File_data_ToModel_test_data_Add(List<sqe_cto_test_data> dataDest, List<sqe_cto_test_data> dataSource)
  1268. {
  1269. if (dataSource != null && dataSource.Count > 0)
  1270. {
  1271. for (int i = 0; i < dataSource.Count; i++)
  1272. {
  1273. sqe_cto_test_data data = dataSource[i];
  1274. if (data.data_no != null && data.data_no.Length > 0 && data.data_time != null && data.data_value != null)
  1275. {
  1276. dataDest.Add(data);
  1277. }
  1278. }
  1279. }
  1280. }
  1281. #endregion 产品特性
  1282. public string Import_Process_From_Data(int upload_id, string create_by, DateTime create_date, string create_org)
  1283. {
  1284. StringBuilder stringBuilder = new StringBuilder();
  1285. try
  1286. {
  1287. List<sqe_file_data> datas = LoadData_file_data(upload_id);
  1288. if (datas == null || datas.Count == 0)
  1289. {
  1290. stringBuilder.AppendLine("导入数据信息不存在!");
  1291. return stringBuilder.ToString();
  1292. }
  1293. string errorMsg;
  1294. sqe_cto_process test = File_data_ToModel_process(datas, create_by, create_date, create_org, out errorMsg);
  1295. if (errorMsg != null && errorMsg.Length > 0)
  1296. {
  1297. stringBuilder.AppendLine(errorMsg);
  1298. return stringBuilder.ToString();
  1299. }
  1300. _sqe_cto_process.BeginTransaction();
  1301. _sqe_cto_process.Insert(test);
  1302. errorMsg = null;
  1303. List<sqe_cto_process_standard> standards = File_data_ToModel_process_standard(datas, test, create_by, create_date, create_org, out errorMsg);
  1304. if (errorMsg != null && errorMsg.Length > 0)
  1305. {
  1306. _sqe_cto_process.Rollback();
  1307. stringBuilder.AppendLine(errorMsg);
  1308. return stringBuilder.ToString();
  1309. }
  1310. _sqe_cto_process_standard.BeginTransaction();
  1311. _sqe_cto_process_standard.Insert(standards);
  1312. List<sqe_cto_process_data> test_Datas = File_data_ToModel_process_data(datas, test, standards, create_by, create_date, create_org, out errorMsg);
  1313. if (errorMsg != null && errorMsg.Length > 0)
  1314. {
  1315. _sqe_cto_process.Rollback();
  1316. _sqe_cto_process_standard.Rollback();
  1317. stringBuilder.AppendLine(errorMsg);
  1318. return stringBuilder.ToString();
  1319. }
  1320. _sqe_cto_process_data.Insert(test_Datas);
  1321. _sqe_cto_process.CommitTransaction();
  1322. _sqe_cto_process_standard.CommitTransaction();
  1323. }
  1324. catch (Exception ex)
  1325. {
  1326. stringBuilder.Append("数据导入失败!");
  1327. }
  1328. finally
  1329. {
  1330. }
  1331. return stringBuilder.ToString();
  1332. }
  1333. #region 产品过程特性
  1334. 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)
  1335. {
  1336. StringBuilder stringBuilder = new StringBuilder();
  1337. sqe_cto_process model = new sqe_cto_process();
  1338. DateTime timeValue;
  1339. decimal realValuel;
  1340. if (datas != null && datas.Count >= 5)
  1341. {
  1342. try
  1343. {
  1344. sqe_file_data data = datas[1];
  1345. if (DateTime.TryParse(data.c2, out timeValue))
  1346. {
  1347. model.product_time = timeValue;
  1348. }
  1349. else
  1350. {
  1351. //model.product_time = DateTime.Parse("2000-01-01");
  1352. model.product_time = DateTime.Now;
  1353. }
  1354. model.shift_no = data.c4;
  1355. model.item_no = data.c6;
  1356. model.item_name = data.c8;
  1357. data = datas[2];
  1358. model.material_batch = data.c2;
  1359. if (decimal.TryParse(data.c4, out realValuel))
  1360. {
  1361. model.material_used = realValuel;
  1362. }
  1363. model.item_batch = data.c6;
  1364. if (decimal.TryParse(data.c8, out realValuel))
  1365. {
  1366. model.item_qty = realValuel;
  1367. }
  1368. data = datas[3];
  1369. model.op_pre = data.c2;
  1370. model.op_pre_batch = data.c4;
  1371. model.op_current = data.c6;
  1372. model.op_batch = data.c8;
  1373. data = datas[4];
  1374. model.device_name = data.c2;
  1375. model.device_no = data.c4;
  1376. if (decimal.TryParse(data.c8, out realValuel))
  1377. {
  1378. model.sampling_number = realValuel;
  1379. }
  1380. }
  1381. catch (Exception ex)
  1382. {
  1383. WLLog.Error("Excel数据解析问题:", ex);
  1384. }
  1385. model.create_by = create_by;
  1386. model.create_date = create_date;
  1387. model.create_org = create_org;
  1388. errorMsg = string.Empty;
  1389. return model;
  1390. }
  1391. else
  1392. {
  1393. errorMsg = stringBuilder.ToString();
  1394. return null;
  1395. }
  1396. }
  1397. 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)
  1398. {
  1399. StringBuilder stringBuilder = new StringBuilder();
  1400. List<sqe_cto_process_standard> modelList = new List<sqe_cto_process_standard>();
  1401. decimal realValuel;
  1402. if (datas != null && datas.Count >= 13)
  1403. {
  1404. try
  1405. {
  1406. //标准的起始位置
  1407. int index = 5;
  1408. sqe_file_data dataRow = datas[index];
  1409. #region 处理尺寸的表头
  1410. if (dataRow.c2 != null && dataRow.c2.Length > 0)
  1411. {
  1412. sqe_cto_process_standard model = new sqe_cto_process_standard();
  1413. model.standard_no = dataRow.c2;
  1414. model.create_by = create_by;
  1415. model.create_date = create_date;
  1416. model.create_org = create_org;
  1417. model.process_id = test.id;
  1418. modelList.Add(model);
  1419. }
  1420. if (dataRow.c3 != null && dataRow.c3.Length > 0)
  1421. {
  1422. sqe_cto_process_standard model = new sqe_cto_process_standard();
  1423. model.standard_no = dataRow.c3;
  1424. model.create_by = create_by;
  1425. model.create_date = create_date;
  1426. model.create_org = create_org;
  1427. model.process_id = test.id;
  1428. modelList.Add(model);
  1429. }
  1430. if (dataRow.c4 != null && dataRow.c4.Length > 0)
  1431. {
  1432. sqe_cto_process_standard model = new sqe_cto_process_standard();
  1433. model.standard_no = dataRow.c4;
  1434. model.create_by = create_by;
  1435. model.create_date = create_date;
  1436. model.create_org = create_org;
  1437. model.process_id = test.id;
  1438. modelList.Add(model);
  1439. }
  1440. if (dataRow.c5 != null && dataRow.c5.Length > 0)
  1441. {
  1442. sqe_cto_process_standard model = new sqe_cto_process_standard();
  1443. model.standard_no = dataRow.c5;
  1444. model.create_by = create_by;
  1445. model.create_date = create_date;
  1446. model.create_org = create_org;
  1447. model.process_id = test.id;
  1448. modelList.Add(model);
  1449. }
  1450. if (dataRow.c6 != null && dataRow.c6.Length > 0)
  1451. {
  1452. sqe_cto_process_standard model = new sqe_cto_process_standard();
  1453. model.standard_no = dataRow.c6;
  1454. model.create_by = create_by;
  1455. model.create_date = create_date;
  1456. model.create_org = create_org;
  1457. model.process_id = test.id;
  1458. modelList.Add(model);
  1459. }
  1460. if (dataRow.c7 != null && dataRow.c7.Length > 0)
  1461. {
  1462. sqe_cto_process_standard model = new sqe_cto_process_standard();
  1463. model.standard_no = dataRow.c7;
  1464. model.create_by = create_by;
  1465. model.create_date = create_date;
  1466. model.create_org = create_org;
  1467. model.process_id = test.id;
  1468. modelList.Add(model);
  1469. }
  1470. if (dataRow.c8 != null && dataRow.c8.Length > 0)
  1471. {
  1472. sqe_cto_process_standard model = new sqe_cto_process_standard();
  1473. model.standard_no = dataRow.c8;
  1474. model.create_by = create_by;
  1475. model.create_date = create_date;
  1476. model.create_org = create_org;
  1477. model.process_id = test.id;
  1478. modelList.Add(model);
  1479. }
  1480. if (dataRow.c9 != null && dataRow.c9.Length > 0)
  1481. {
  1482. sqe_cto_process_standard model = new sqe_cto_process_standard();
  1483. model.standard_no = dataRow.c9;
  1484. model.create_by = create_by;
  1485. model.create_date = create_date;
  1486. model.create_org = create_org;
  1487. model.process_id = test.id;
  1488. modelList.Add(model);
  1489. }
  1490. if (dataRow.c10 != null && dataRow.c10.Length > 0)
  1491. {
  1492. sqe_cto_process_standard model = new sqe_cto_process_standard();
  1493. model.standard_no = dataRow.c10;
  1494. model.create_by = create_by;
  1495. model.create_date = create_date;
  1496. model.create_org = create_org;
  1497. model.process_id = test.id;
  1498. modelList.Add(model);
  1499. }
  1500. #endregion 处理尺寸的表头
  1501. if (modelList.Count > 0)
  1502. {
  1503. sqe_cto_process_standard model = modelList[0];
  1504. dataRow = datas[index + 1];
  1505. if (dataRow.c2 != null && decimal.TryParse(dataRow.c2, out realValuel))
  1506. {
  1507. model.standard_value = realValuel;
  1508. }
  1509. dataRow = datas[index + 2];
  1510. if (dataRow.c2 != null && decimal.TryParse(dataRow.c2, out realValuel))
  1511. {
  1512. model.delta_up = realValuel;
  1513. }
  1514. dataRow = datas[index + 3];
  1515. if (dataRow.c2 != null && decimal.TryParse(dataRow.c2, out realValuel))
  1516. {
  1517. model.delta_down = realValuel;
  1518. }
  1519. dataRow = datas[index + 4];
  1520. if (dataRow.c2 != null && decimal.TryParse(dataRow.c2, out realValuel))
  1521. {
  1522. model.standard_max = realValuel;
  1523. }
  1524. dataRow = datas[index + 5];
  1525. if (dataRow.c2 != null && decimal.TryParse(dataRow.c2, out realValuel))
  1526. {
  1527. model.standard_min = realValuel;
  1528. }
  1529. }
  1530. if (modelList.Count > 1)
  1531. {
  1532. sqe_cto_process_standard model = modelList[1];
  1533. dataRow = datas[index + 1];
  1534. if (dataRow.c3 != null && decimal.TryParse(dataRow.c3, out realValuel))
  1535. {
  1536. model.standard_value = realValuel;
  1537. }
  1538. dataRow = datas[index + 2];
  1539. if (dataRow.c3 != null && decimal.TryParse(dataRow.c3, out realValuel))
  1540. {
  1541. model.delta_up = realValuel;
  1542. }
  1543. dataRow = datas[index + 3];
  1544. if (dataRow.c3 != null && decimal.TryParse(dataRow.c3, out realValuel))
  1545. {
  1546. model.delta_down = realValuel;
  1547. }
  1548. dataRow = datas[index + 4];
  1549. if (dataRow.c3 != null && decimal.TryParse(dataRow.c3, out realValuel))
  1550. {
  1551. model.standard_max = realValuel;
  1552. }
  1553. dataRow = datas[index + 5];
  1554. if (dataRow.c3 != null && decimal.TryParse(dataRow.c3, out realValuel))
  1555. {
  1556. model.standard_min = realValuel;
  1557. }
  1558. }
  1559. if (modelList.Count > 2)
  1560. {
  1561. sqe_cto_process_standard model = modelList[2];
  1562. dataRow = datas[index + 1];
  1563. if (dataRow.c4 != null && decimal.TryParse(dataRow.c4, out realValuel))
  1564. {
  1565. model.standard_value = realValuel;
  1566. }
  1567. dataRow = datas[index + 2];
  1568. if (dataRow.c4 != null && decimal.TryParse(dataRow.c4, out realValuel))
  1569. {
  1570. model.delta_up = realValuel;
  1571. }
  1572. dataRow = datas[index + 3];
  1573. if (dataRow.c4 != null && decimal.TryParse(dataRow.c4, out realValuel))
  1574. {
  1575. model.delta_down = realValuel;
  1576. }
  1577. dataRow = datas[index + 4];
  1578. if (dataRow.c4 != null && decimal.TryParse(dataRow.c4, out realValuel))
  1579. {
  1580. model.standard_max = realValuel;
  1581. }
  1582. dataRow = datas[index + 5];
  1583. if (dataRow.c4 != null && decimal.TryParse(dataRow.c4, out realValuel))
  1584. {
  1585. model.standard_min = realValuel;
  1586. }
  1587. }
  1588. if (modelList.Count > 3)
  1589. {
  1590. sqe_cto_process_standard model = modelList[3];
  1591. dataRow = datas[index + 1];
  1592. if (dataRow.c5 != null && decimal.TryParse(dataRow.c5, out realValuel))
  1593. {
  1594. model.standard_value = realValuel;
  1595. }
  1596. dataRow = datas[index + 2];
  1597. if (dataRow.c5 != null && decimal.TryParse(dataRow.c5, out realValuel))
  1598. {
  1599. model.delta_up = realValuel;
  1600. }
  1601. dataRow = datas[index + 3];
  1602. if (dataRow.c5 != null && decimal.TryParse(dataRow.c5, out realValuel))
  1603. {
  1604. model.delta_down = realValuel;
  1605. }
  1606. dataRow = datas[index + 4];
  1607. if (dataRow.c5 != null && decimal.TryParse(dataRow.c5, out realValuel))
  1608. {
  1609. model.standard_max = realValuel;
  1610. }
  1611. dataRow = datas[index + 5];
  1612. if (dataRow.c5 != null && decimal.TryParse(dataRow.c5, out realValuel))
  1613. {
  1614. model.standard_min = realValuel;
  1615. }
  1616. }
  1617. if (modelList.Count > 4)
  1618. {
  1619. sqe_cto_process_standard model = modelList[4];
  1620. dataRow = datas[index + 1];
  1621. if (dataRow.c6 != null && decimal.TryParse(dataRow.c6, out realValuel))
  1622. {
  1623. model.standard_value = realValuel;
  1624. }
  1625. dataRow = datas[index + 2];
  1626. if (dataRow.c6 != null && decimal.TryParse(dataRow.c6, out realValuel))
  1627. {
  1628. model.delta_up = realValuel;
  1629. }
  1630. dataRow = datas[index + 3];
  1631. if (dataRow.c6 != null && decimal.TryParse(dataRow.c6, out realValuel))
  1632. {
  1633. model.delta_down = realValuel;
  1634. }
  1635. dataRow = datas[index + 4];
  1636. if (dataRow.c6 != null && decimal.TryParse(dataRow.c6, out realValuel))
  1637. {
  1638. model.standard_max = realValuel;
  1639. }
  1640. dataRow = datas[index + 5];
  1641. if (dataRow.c6 != null && decimal.TryParse(dataRow.c6, out realValuel))
  1642. {
  1643. model.standard_min = realValuel;
  1644. }
  1645. }
  1646. if (modelList.Count > 5)
  1647. {
  1648. sqe_cto_process_standard model = modelList[5];
  1649. dataRow = datas[index + 1];
  1650. if (dataRow.c7 != null && decimal.TryParse(dataRow.c7, out realValuel))
  1651. {
  1652. model.standard_value = realValuel;
  1653. }
  1654. dataRow = datas[index + 2];
  1655. if (dataRow.c7 != null && decimal.TryParse(dataRow.c7, out realValuel))
  1656. {
  1657. model.delta_up = realValuel;
  1658. }
  1659. dataRow = datas[index + 3];
  1660. if (dataRow.c7 != null && decimal.TryParse(dataRow.c7, out realValuel))
  1661. {
  1662. model.delta_down = realValuel;
  1663. }
  1664. dataRow = datas[index + 4];
  1665. if (dataRow.c7 != null && decimal.TryParse(dataRow.c7, out realValuel))
  1666. {
  1667. model.standard_max = realValuel;
  1668. }
  1669. dataRow = datas[index + 5];
  1670. if (dataRow.c7 != null && decimal.TryParse(dataRow.c7, out realValuel))
  1671. {
  1672. model.standard_min = realValuel;
  1673. }
  1674. }
  1675. if (modelList.Count > 6)
  1676. {
  1677. sqe_cto_process_standard model = modelList[6];
  1678. dataRow = datas[index + 1];
  1679. if (dataRow.c8 != null && decimal.TryParse(dataRow.c8, out realValuel))
  1680. {
  1681. model.standard_value = realValuel;
  1682. }
  1683. dataRow = datas[index + 2];
  1684. if (dataRow.c8 != null && decimal.TryParse(dataRow.c8, out realValuel))
  1685. {
  1686. model.delta_up = realValuel;
  1687. }
  1688. dataRow = datas[index + 3];
  1689. if (dataRow.c8 != null && decimal.TryParse(dataRow.c8, out realValuel))
  1690. {
  1691. model.delta_down = realValuel;
  1692. }
  1693. dataRow = datas[index + 4];
  1694. if (dataRow.c8 != null && decimal.TryParse(dataRow.c8, out realValuel))
  1695. {
  1696. model.standard_max = realValuel;
  1697. }
  1698. dataRow = datas[index + 5];
  1699. if (dataRow.c8 != null && decimal.TryParse(dataRow.c8, out realValuel))
  1700. {
  1701. model.standard_min = realValuel;
  1702. }
  1703. }
  1704. if (modelList.Count > 7)
  1705. {
  1706. sqe_cto_process_standard model = modelList[7];
  1707. dataRow = datas[index + 1];
  1708. if (dataRow.c9 != null && decimal.TryParse(dataRow.c9, out realValuel))
  1709. {
  1710. model.standard_value = realValuel;
  1711. }
  1712. dataRow = datas[index + 2];
  1713. if (dataRow.c9 != null && decimal.TryParse(dataRow.c9, out realValuel))
  1714. {
  1715. model.delta_up = realValuel;
  1716. }
  1717. dataRow = datas[index + 3];
  1718. if (dataRow.c9 != null && decimal.TryParse(dataRow.c9, out realValuel))
  1719. {
  1720. model.delta_down = realValuel;
  1721. }
  1722. dataRow = datas[index + 4];
  1723. if (dataRow.c9 != null && decimal.TryParse(dataRow.c9, out realValuel))
  1724. {
  1725. model.standard_max = realValuel;
  1726. }
  1727. dataRow = datas[index + 5];
  1728. if (dataRow.c9 != null && decimal.TryParse(dataRow.c9, out realValuel))
  1729. {
  1730. model.standard_min = realValuel;
  1731. }
  1732. }
  1733. if (modelList.Count > 8)
  1734. {
  1735. sqe_cto_process_standard model = modelList[8];
  1736. dataRow = datas[index + 1];
  1737. if (dataRow.c10 != null && decimal.TryParse(dataRow.c10, out realValuel))
  1738. {
  1739. model.standard_value = realValuel;
  1740. }
  1741. dataRow = datas[index + 2];
  1742. if (dataRow.c10 != null && decimal.TryParse(dataRow.c10, out realValuel))
  1743. {
  1744. model.delta_up = realValuel;
  1745. }
  1746. dataRow = datas[index + 3];
  1747. if (dataRow.c10 != null && decimal.TryParse(dataRow.c10, out realValuel))
  1748. {
  1749. model.delta_down = realValuel;
  1750. }
  1751. dataRow = datas[index + 4];
  1752. if (dataRow.c10 != null && decimal.TryParse(dataRow.c10, out realValuel))
  1753. {
  1754. model.standard_max = realValuel;
  1755. }
  1756. dataRow = datas[index + 5];
  1757. if (dataRow.c10 != null && decimal.TryParse(dataRow.c10, out realValuel))
  1758. {
  1759. model.standard_min = realValuel;
  1760. }
  1761. }
  1762. }
  1763. catch (Exception ex)
  1764. {
  1765. WLLog.Error("Excel数据解析问题:", ex);
  1766. }
  1767. errorMsg = stringBuilder.ToString();
  1768. return modelList;
  1769. }
  1770. else
  1771. {
  1772. errorMsg = stringBuilder.ToString();
  1773. return null;
  1774. }
  1775. }
  1776. 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)
  1777. {
  1778. StringBuilder stringBuilder = new StringBuilder();
  1779. List<sqe_cto_process_data> modelList = new List<sqe_cto_process_data>();
  1780. decimal realValuel;
  1781. if (datas != null && datas.Count >= 12)
  1782. {
  1783. for (int i = 11; i < datas.Count; i++)
  1784. {
  1785. sqe_file_data dataRow = datas[i];
  1786. if ((dataRow.c1 == null || dataRow.c1.Length == 0 || dataRow.c1 == "0") && (dataRow.c2 == null || dataRow.c2.Length == 0))
  1787. {
  1788. break;
  1789. }
  1790. //初始化每一层的数据集合
  1791. List<sqe_cto_process_data> test_datas = new List<sqe_cto_process_data>();
  1792. for (int j = 0; j < standards.Count; j++)
  1793. {
  1794. sqe_cto_process_data data = new sqe_cto_process_data();
  1795. data.process_id = standards[j].process_id;
  1796. data.standard_id = standards[j].id;
  1797. data.create_by = create_by;
  1798. data.create_date = create_date;
  1799. data.create_org = create_org;
  1800. test_datas.Add(data);
  1801. }
  1802. try
  1803. {
  1804. //将每一个检测标准的值从记录行中取出来
  1805. if (test_datas.Count > 0)
  1806. {
  1807. sqe_cto_process_data data = test_datas[0];
  1808. if (dataRow.c1 != null)
  1809. {
  1810. String s = dataRow.c1.ToString();
  1811. if (s != null && s.Length > 9)
  1812. {
  1813. s = s.Substring(s.Length - 9);
  1814. }
  1815. DateTime date;
  1816. if (DateTime.TryParse(test.product_time.ToString("yyyy-MM-dd ") + s, out date))
  1817. {
  1818. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1819. }
  1820. }
  1821. if (dataRow.c2 != null && dataRow.c2.Length > 0 && decimal.TryParse(dataRow.c2, out realValuel))
  1822. {
  1823. data.data_value = realValuel;
  1824. }
  1825. else
  1826. {
  1827. data.data_value = null;
  1828. }
  1829. }
  1830. if (test_datas.Count > 1)
  1831. {
  1832. sqe_cto_process_data data = test_datas[1];
  1833. if (dataRow.c1 != null)
  1834. {
  1835. String s = dataRow.c1.ToString();
  1836. if (s != null && s.Length > 9)
  1837. {
  1838. s = s.Substring(s.Length - 9);
  1839. }
  1840. DateTime date;
  1841. if (DateTime.TryParse(test.product_time.ToString("yyyy-MM-dd ") + s, out date))
  1842. {
  1843. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1844. }
  1845. }
  1846. if (dataRow.c3 != null && dataRow.c3.Length > 0 && decimal.TryParse(dataRow.c3, out realValuel))
  1847. {
  1848. data.data_value = realValuel;
  1849. }
  1850. else
  1851. {
  1852. data.data_value = null;
  1853. }
  1854. }
  1855. if (test_datas.Count > 2)
  1856. {
  1857. sqe_cto_process_data data = test_datas[2];
  1858. if (dataRow.c1 != null)
  1859. {
  1860. String s = dataRow.c1.ToString();
  1861. if (s != null && s.Length > 9)
  1862. {
  1863. s = s.Substring(s.Length - 9);
  1864. }
  1865. DateTime date;
  1866. if (DateTime.TryParse(test.product_time.ToString("yyyy-MM-dd ") + s, out date))
  1867. {
  1868. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1869. }
  1870. }
  1871. if (dataRow.c4 != null && dataRow.c4.Length > 0 && decimal.TryParse(dataRow.c4, out realValuel))
  1872. {
  1873. data.data_value = realValuel;
  1874. }
  1875. else
  1876. {
  1877. data.data_value = null;
  1878. }
  1879. }
  1880. if (test_datas.Count > 3)
  1881. {
  1882. sqe_cto_process_data data = test_datas[3];
  1883. if (dataRow.c1 != null)
  1884. {
  1885. String s = dataRow.c1.ToString();
  1886. if (s != null && s.Length > 9)
  1887. {
  1888. s = s.Substring(s.Length - 9);
  1889. }
  1890. DateTime date;
  1891. if (DateTime.TryParse(test.product_time.ToString("yyyy-MM-dd ") + s, out date))
  1892. {
  1893. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1894. }
  1895. }
  1896. if (dataRow.c5 != null && dataRow.c5.Length > 0 && decimal.TryParse(dataRow.c5, out realValuel))
  1897. {
  1898. data.data_value = realValuel;
  1899. }
  1900. else
  1901. {
  1902. data.data_value = null;
  1903. }
  1904. }
  1905. if (test_datas.Count > 4)
  1906. {
  1907. sqe_cto_process_data data = test_datas[4];
  1908. if (dataRow.c1 != null)
  1909. {
  1910. String s = dataRow.c1.ToString();
  1911. if (s != null && s.Length > 9)
  1912. {
  1913. s = s.Substring(s.Length - 9);
  1914. }
  1915. DateTime date;
  1916. if (DateTime.TryParse(test.product_time.ToString("yyyy-MM-dd ") + s, out date))
  1917. {
  1918. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1919. }
  1920. }
  1921. if (dataRow.c6 != null && dataRow.c6.Length > 0 && decimal.TryParse(dataRow.c6, out realValuel))
  1922. {
  1923. data.data_value = realValuel;
  1924. }
  1925. else
  1926. {
  1927. data.data_value = null;
  1928. }
  1929. }
  1930. if (test_datas.Count > 5)
  1931. {
  1932. sqe_cto_process_data data = test_datas[5];
  1933. if (dataRow.c1 != null)
  1934. {
  1935. String s = dataRow.c1.ToString();
  1936. if (s != null && s.Length > 9)
  1937. {
  1938. s = s.Substring(s.Length - 9);
  1939. }
  1940. DateTime date;
  1941. if (DateTime.TryParse(test.product_time.ToString("yyyy-MM-dd ") + s, out date))
  1942. {
  1943. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1944. }
  1945. }
  1946. if (dataRow.c7 != null && dataRow.c7.Length > 0 && decimal.TryParse(dataRow.c7, out realValuel))
  1947. {
  1948. data.data_value = realValuel;
  1949. }
  1950. else
  1951. {
  1952. data.data_value = null;
  1953. }
  1954. }
  1955. if (test_datas.Count > 6)
  1956. {
  1957. sqe_cto_process_data data = test_datas[6];
  1958. if (dataRow.c1 != null)
  1959. {
  1960. String s = dataRow.c1.ToString();
  1961. if (s != null && s.Length > 9)
  1962. {
  1963. s = s.Substring(s.Length - 9);
  1964. }
  1965. DateTime date;
  1966. if (DateTime.TryParse(test.product_time.ToString("yyyy-MM-dd ") + s, out date))
  1967. {
  1968. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1969. }
  1970. }
  1971. if (dataRow.c8 != null && dataRow.c8.Length > 0 && decimal.TryParse(dataRow.c8, out realValuel))
  1972. {
  1973. data.data_value = realValuel;
  1974. }
  1975. else
  1976. {
  1977. data.data_value = null;
  1978. }
  1979. }
  1980. if (test_datas.Count > 7)
  1981. {
  1982. sqe_cto_process_data data = test_datas[7];
  1983. if (dataRow.c1 != null)
  1984. {
  1985. String s = dataRow.c1.ToString();
  1986. if (s != null && s.Length > 9)
  1987. {
  1988. s = s.Substring(s.Length - 9);
  1989. }
  1990. DateTime date;
  1991. if (DateTime.TryParse(test.product_time.ToString("yyyy-MM-dd ") + s, out date))
  1992. {
  1993. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1994. }
  1995. }
  1996. if (dataRow.c9 != null && dataRow.c9.Length > 0 && decimal.TryParse(dataRow.c9, out realValuel))
  1997. {
  1998. data.data_value = realValuel;
  1999. }
  2000. else
  2001. {
  2002. data.data_value = null;
  2003. }
  2004. }
  2005. if (test_datas.Count > 8)
  2006. {
  2007. sqe_cto_process_data data = test_datas[8];
  2008. if (dataRow.c1 != null)
  2009. {
  2010. String s = dataRow.c1.ToString();
  2011. if (s != null && s.Length > 9)
  2012. {
  2013. s = s.Substring(s.Length - 9);
  2014. }
  2015. DateTime date;
  2016. if (DateTime.TryParse(test.product_time.ToString("yyyy-MM-dd ") + s, out date))
  2017. {
  2018. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  2019. }
  2020. }
  2021. if (dataRow.c10 != null && dataRow.c10.Length > 0 && decimal.TryParse(dataRow.c10, out realValuel))
  2022. {
  2023. data.data_value = realValuel;
  2024. }
  2025. else
  2026. {
  2027. data.data_value = null;
  2028. }
  2029. }
  2030. File_data_ToModel_process_data_Add(modelList, test_datas);
  2031. }
  2032. catch (Exception ex)
  2033. {
  2034. WLLog.Error("Excel数据解析_原始数据转换到对象实体的问题:", ex);
  2035. }
  2036. }
  2037. errorMsg = string.Empty;
  2038. return modelList;
  2039. }
  2040. else
  2041. {
  2042. errorMsg = stringBuilder.ToString();
  2043. return null;
  2044. }
  2045. }
  2046. /// <summary>
  2047. /// 将转换的数据插入到返回结果数据集中,处理掉异常数据
  2048. /// </summary>
  2049. /// <param name="dataDest"></param>
  2050. /// <param name="dataSource"></param>
  2051. private void File_data_ToModel_process_data_Add(List<sqe_cto_process_data> dataDest, List<sqe_cto_process_data> dataSource)
  2052. {
  2053. if (dataSource != null && dataSource.Count > 0)
  2054. {
  2055. for (int i = 0; i < dataSource.Count; i++)
  2056. {
  2057. sqe_cto_process_data data = dataSource[i];
  2058. if (data.data_time != null && data.data_value != null)
  2059. {
  2060. dataDest.Add(data);
  2061. }
  2062. }
  2063. }
  2064. }
  2065. #endregion 产品过程特性
  2066. /// <summary>
  2067. /// 依据导入的数据行,生成OQC的表头、检验标准和数据行
  2068. /// </summary>
  2069. /// <param name="upload_id"></param>
  2070. /// <param name="create_by"></param>
  2071. /// <param name="create_date"></param>
  2072. /// <param name="create_org"></param>
  2073. /// <returns></returns>
  2074. public string Import_Oqc_From_Data(int upload_id, string create_by, DateTime create_date, string create_org)
  2075. {
  2076. StringBuilder stringBuilder = new StringBuilder();
  2077. try
  2078. {
  2079. List<sqe_file_data> datas = LoadData_file_data(upload_id);
  2080. if (datas == null || datas.Count == 0)
  2081. {
  2082. stringBuilder.AppendLine("导入数据信息不存在!");
  2083. return stringBuilder.ToString();
  2084. }
  2085. string errorMsg;
  2086. sqe_oqc test = File_data_ToModel_oqc(datas, create_by, create_date, create_org, out errorMsg);
  2087. if (errorMsg != null && errorMsg.Length > 0)
  2088. {
  2089. stringBuilder.AppendLine(errorMsg);
  2090. return stringBuilder.ToString();
  2091. }
  2092. _sqe_oqc.BeginTransaction();
  2093. _sqe_oqc.Insert(test);
  2094. errorMsg = null;
  2095. List<sqe_oqc_standard> standards = File_data_ToModel_oqc_standard(datas, test, create_by, create_date, create_org, out errorMsg);
  2096. if (errorMsg != null && errorMsg.Length > 0)
  2097. {
  2098. _sqe_oqc.Rollback();
  2099. stringBuilder.AppendLine(errorMsg);
  2100. return stringBuilder.ToString();
  2101. }
  2102. _sqe_oqc_standard.BeginTransaction();
  2103. _sqe_oqc_standard.Insert(standards);
  2104. List<sqe_oqc_data> test_Datas = File_data_ToModel_oqc_data(datas, test, standards, create_by, create_date, create_org, out errorMsg);
  2105. if (errorMsg != null && errorMsg.Length > 0)
  2106. {
  2107. _sqe_oqc.Rollback();
  2108. _sqe_oqc_standard.Rollback();
  2109. stringBuilder.AppendLine(errorMsg);
  2110. return stringBuilder.ToString();
  2111. }
  2112. _sqe_oqc_data.Insert(test_Datas);
  2113. _sqe_oqc.CommitTransaction();
  2114. _sqe_oqc_standard.CommitTransaction();
  2115. }
  2116. catch (Exception ex)
  2117. {
  2118. stringBuilder.Append("数据导入失败!");
  2119. }
  2120. finally
  2121. {
  2122. }
  2123. return stringBuilder.ToString();
  2124. }
  2125. #region OQC
  2126. /// <summary>
  2127. /// 从原始数据行生成OQC的表头数据
  2128. /// </summary>
  2129. /// <param name="datas"></param>
  2130. /// <param name="create_by"></param>
  2131. /// <param name="create_date"></param>
  2132. /// <param name="create_org"></param>
  2133. /// <param name="errorMsg"></param>
  2134. /// <returns></returns>
  2135. public sqe_oqc File_data_ToModel_oqc(List<sqe_file_data> datas, string create_by, DateTime create_date, string create_org, out string errorMsg)
  2136. {
  2137. StringBuilder stringBuilder = new StringBuilder();
  2138. sqe_oqc model = new sqe_oqc();
  2139. DateTime timeValue;
  2140. decimal realValuel;
  2141. if (datas != null && datas.Count >= 4)
  2142. {
  2143. try
  2144. {
  2145. sqe_file_data data = datas[1];
  2146. model.supp_no = data.c2;
  2147. model.item_name = data.c4;
  2148. model.item_no = data.c6;
  2149. model.item_version = data.c8;
  2150. data = datas[2];
  2151. if (DateTime.TryParse(data.c2, out timeValue))
  2152. {
  2153. model.product_time = timeValue;
  2154. }
  2155. else
  2156. {
  2157. model.product_time = DateTime.Now;
  2158. }
  2159. model.batch_no = data.c4;
  2160. if (decimal.TryParse(data.c6, out realValuel))
  2161. {
  2162. model.batch_qty = realValuel;
  2163. }
  2164. model.test_person = data.c8;
  2165. data = datas[3];
  2166. model.sampling_standard = data.c2;
  2167. if (decimal.TryParse(data.c4, out realValuel))
  2168. {
  2169. model.sampling_number = realValuel;
  2170. }
  2171. model.test_result = data.c8;
  2172. }
  2173. catch (Exception ex)
  2174. {
  2175. WLLog.Error("Excel数据解析问题:", ex);
  2176. }
  2177. model.create_by = create_by;
  2178. model.create_date = create_date;
  2179. model.create_org = create_org;
  2180. errorMsg = string.Empty;
  2181. return model;
  2182. }
  2183. else
  2184. {
  2185. errorMsg = stringBuilder.ToString();
  2186. return null;
  2187. }
  2188. }
  2189. /// <summary>
  2190. /// 从原始数据行生成OQC的检验标准
  2191. /// </summary>
  2192. /// <param name="datas"></param>
  2193. /// <param name="test"></param>
  2194. /// <param name="create_by"></param>
  2195. /// <param name="create_date"></param>
  2196. /// <param name="create_org"></param>
  2197. /// <param name="errorMsg"></param>
  2198. /// <returns></returns>
  2199. 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)
  2200. {
  2201. StringBuilder stringBuilder = new StringBuilder();
  2202. List<sqe_oqc_standard> modelList = new List<sqe_oqc_standard>();
  2203. decimal realValuel;
  2204. if (datas != null && datas.Count >= 13)
  2205. {
  2206. try
  2207. {
  2208. //标准的起始位置
  2209. int index = 4;
  2210. sqe_file_data dataRow = datas[index];
  2211. #region 处理尺寸的表头
  2212. for (int i = 2; i < 10; i++)
  2213. {
  2214. Object obj = GetFieldValue(dataRow, "c" + i.ToString());
  2215. if (obj != null)
  2216. {
  2217. sqe_oqc_standard model = new sqe_oqc_standard();
  2218. model.standard_no = obj.ToString();
  2219. model.create_by = create_by;
  2220. model.create_date = create_date;
  2221. model.create_org = create_org;
  2222. model.oqc_id = test.id;
  2223. modelList.Add(model);
  2224. }
  2225. else
  2226. {
  2227. break;
  2228. }
  2229. }
  2230. #endregion 处理尺寸的表头
  2231. //处理表头的具体值
  2232. for (int i = 0; i < 9 && i < modelList.Count; i++)
  2233. {
  2234. string fieldName = "c" + (i + 2).ToString();
  2235. sqe_oqc_standard model = modelList[i];
  2236. dataRow = datas[index + 1];
  2237. Object obj = GetFieldValue(dataRow, fieldName);
  2238. if (obj != null)
  2239. {
  2240. model.standard_no = obj.ToString();
  2241. }
  2242. dataRow = datas[index + 2];
  2243. obj = GetFieldValue(dataRow, fieldName);
  2244. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2245. {
  2246. model.standard_value = realValuel;
  2247. }
  2248. dataRow = datas[index + 3];
  2249. obj = GetFieldValue(dataRow, fieldName);
  2250. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2251. {
  2252. model.delta_up = realValuel;
  2253. }
  2254. dataRow = datas[index + 4];
  2255. obj = GetFieldValue(dataRow, fieldName);
  2256. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2257. {
  2258. model.delta_down = realValuel;
  2259. }
  2260. dataRow = datas[index + 5];
  2261. obj = GetFieldValue(dataRow, fieldName);
  2262. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2263. {
  2264. model.standard_max = realValuel;
  2265. }
  2266. dataRow = datas[index + 6];
  2267. obj = GetFieldValue(dataRow, fieldName);
  2268. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2269. {
  2270. model.standard_min = realValuel;
  2271. }
  2272. }
  2273. }
  2274. catch (Exception ex)
  2275. {
  2276. WLLog.Error("Excel数据解析问题:", ex);
  2277. }
  2278. errorMsg = stringBuilder.ToString();
  2279. return modelList;
  2280. }
  2281. else
  2282. {
  2283. errorMsg = stringBuilder.ToString();
  2284. return null;
  2285. }
  2286. }
  2287. /// <summary>
  2288. /// 获取某个对象的某个属性的值
  2289. /// </summary>
  2290. /// <param name="obj"></param>
  2291. /// <param name="fieldName"></param>
  2292. /// <returns></returns>
  2293. private Object GetFieldValue(Object obj, string fieldName)
  2294. {
  2295. //获得对象的所有public属性
  2296. PropertyInfo[] pis = obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
  2297. //如果获得了属性
  2298. if (pis != null)
  2299. {
  2300. foreach (PropertyInfo pi in pis)//针对每一个属性进行循环
  2301. {
  2302. if (pi.Name.CompareTo(fieldName) == 0)
  2303. {
  2304. Object objValue = pi.GetValue(obj);
  2305. if (objValue != null && objValue.ToString().Length > 0)
  2306. {
  2307. return objValue;
  2308. }
  2309. }
  2310. }
  2311. }
  2312. return null;
  2313. }
  2314. /// <summary>
  2315. /// 从原始数据行生成OQC的数据
  2316. /// </summary>
  2317. /// <param name="datas"></param>
  2318. /// <param name="test"></param>
  2319. /// <param name="standards"></param>
  2320. /// <param name="create_by"></param>
  2321. /// <param name="create_date"></param>
  2322. /// <param name="create_org"></param>
  2323. /// <param name="errorMsg"></param>
  2324. /// <returns></returns>
  2325. 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)
  2326. {
  2327. StringBuilder stringBuilder = new StringBuilder();
  2328. List<sqe_oqc_data> modelList = new List<sqe_oqc_data>();
  2329. decimal realValuel;
  2330. if (datas != null && datas.Count >= 12)
  2331. {
  2332. for (int i = 11; i < datas.Count; i++)
  2333. {
  2334. sqe_file_data dataRow = datas[i];
  2335. if ((dataRow.c1 == null || dataRow.c1.Length == 0 || dataRow.c1 == "0") && (dataRow.c2 == null || dataRow.c2.Length == 0))
  2336. {
  2337. break;
  2338. }
  2339. //初始化每一层的数据集合
  2340. List<sqe_oqc_data> test_datas = new List<sqe_oqc_data>();
  2341. for (int j = 0; j < standards.Count; j++)
  2342. {
  2343. sqe_oqc_data data = new sqe_oqc_data();
  2344. data.oqc_id = standards[j].oqc_id;
  2345. data.standard_id = standards[j].id;
  2346. data.create_by = create_by;
  2347. data.create_date = create_date;
  2348. data.create_org = create_org;
  2349. test_datas.Add(data);
  2350. }
  2351. try
  2352. {
  2353. //将每一个检测标准的值从记录行中取出来
  2354. for (int j = 0; j < test_datas.Count; j++)
  2355. {
  2356. sqe_oqc_data data = test_datas[j];
  2357. data.data_no = dataRow.c1;
  2358. string fieldName = "c" + (j + 2).ToString();
  2359. Object obj = GetFieldValue(dataRow, fieldName);
  2360. if (obj != null && obj.ToString().Length > 0 && decimal.TryParse(obj.ToString(), out realValuel))
  2361. {
  2362. data.data_value = realValuel;
  2363. }
  2364. else
  2365. {
  2366. data.data_value = null;
  2367. }
  2368. }
  2369. File_data_ToModel_oqc_data_Add(modelList, test_datas);
  2370. }
  2371. catch (Exception ex)
  2372. {
  2373. WLLog.Error("Excel数据解析_原始数据转换到对象实体的问题:", ex);
  2374. }
  2375. }
  2376. errorMsg = string.Empty;
  2377. return modelList;
  2378. }
  2379. else
  2380. {
  2381. errorMsg = stringBuilder.ToString();
  2382. return null;
  2383. }
  2384. }
  2385. /// <summary>
  2386. /// 将转换的数据插入到返回结果数据集中,处理掉异常数据
  2387. /// </summary>
  2388. /// <param name="dataDest"></param>
  2389. /// <param name="dataSource"></param>
  2390. private void File_data_ToModel_oqc_data_Add(List<sqe_oqc_data> dataDest, List<sqe_oqc_data> dataSource)
  2391. {
  2392. if (dataSource != null && dataSource.Count > 0)
  2393. {
  2394. for (int i = 0; i < dataSource.Count; i++)
  2395. {
  2396. sqe_oqc_data data = dataSource[i];
  2397. if (data.data_no != null && data.data_no.Length > 0 && data.data_value != null)
  2398. {
  2399. dataDest.Add(data);
  2400. }
  2401. }
  2402. }
  2403. }
  2404. #endregion OQC
  2405. /// <summary>
  2406. /// 依据导入的数据行,生成OP的表头、检验标准和数据行
  2407. /// </summary>
  2408. /// <param name="upload_id"></param>
  2409. /// <param name="create_by"></param>
  2410. /// <param name="create_date"></param>
  2411. /// <param name="create_org"></param>
  2412. /// <returns></returns>
  2413. public string Import_Op_From_Data(int upload_id, string create_by, DateTime create_date, string create_org)
  2414. {
  2415. StringBuilder stringBuilder = new StringBuilder();
  2416. try
  2417. {
  2418. List<sqe_file_data> datas = LoadData_file_data(upload_id);
  2419. if (datas == null || datas.Count == 0)
  2420. {
  2421. stringBuilder.AppendLine("导入数据信息不存在!");
  2422. return stringBuilder.ToString();
  2423. }
  2424. string errorMsg;
  2425. sqe_op test = File_data_ToModel_op(datas, create_by, create_date, create_org, out errorMsg);
  2426. if (errorMsg != null && errorMsg.Length > 0)
  2427. {
  2428. stringBuilder.AppendLine(errorMsg);
  2429. return stringBuilder.ToString();
  2430. }
  2431. _sqe_op.BeginTransaction();
  2432. _sqe_op.Insert(test);
  2433. errorMsg = null;
  2434. List<sqe_op_data> standards = File_data_ToModel_op_data(datas, test, create_by, create_date, create_org, out errorMsg);
  2435. if (errorMsg != null && errorMsg.Length > 0)
  2436. {
  2437. _sqe_op.Rollback();
  2438. stringBuilder.AppendLine(errorMsg);
  2439. return stringBuilder.ToString();
  2440. }
  2441. _sqe_op_data.BeginTransaction();
  2442. _sqe_op_data.Insert(standards);
  2443. List<sqe_op_data_detail> test_Datas = File_data_ToModel_op_data_detail(datas, test, standards, create_by, create_date, create_org, out errorMsg);
  2444. if (errorMsg != null && errorMsg.Length > 0)
  2445. {
  2446. _sqe_op.Rollback();
  2447. _sqe_op_data.Rollback();
  2448. stringBuilder.AppendLine(errorMsg);
  2449. return stringBuilder.ToString();
  2450. }
  2451. _sqe_op_data_detail.Insert(test_Datas);
  2452. _sqe_op.CommitTransaction();
  2453. _sqe_op_data.CommitTransaction();
  2454. }
  2455. catch (Exception ex)
  2456. {
  2457. stringBuilder.Append("数据导入失败!");
  2458. }
  2459. finally
  2460. {
  2461. }
  2462. return stringBuilder.ToString();
  2463. }
  2464. #region OP
  2465. /// <summary>
  2466. /// 从原始数据行生成OP的表头数据
  2467. /// </summary>
  2468. /// <param name="datas"></param>
  2469. /// <param name="create_by"></param>
  2470. /// <param name="create_date"></param>
  2471. /// <param name="create_org"></param>
  2472. /// <param name="errorMsg"></param>
  2473. /// <returns></returns>
  2474. public sqe_op File_data_ToModel_op(List<sqe_file_data> datas, string create_by, DateTime create_date, string create_org, out string errorMsg)
  2475. {
  2476. sqe_op model = new sqe_op();
  2477. model.create_by = create_by;
  2478. model.create_date = create_date;
  2479. model.create_org = create_org;
  2480. errorMsg = string.Empty;
  2481. errorMsg = "";
  2482. return model;
  2483. }
  2484. /// <summary>
  2485. /// 从原始数据行生成OP的检验标准
  2486. /// </summary>
  2487. /// <param name="datas"></param>
  2488. /// <param name="test"></param>
  2489. /// <param name="create_by"></param>
  2490. /// <param name="create_date"></param>
  2491. /// <param name="create_org"></param>
  2492. /// <param name="errorMsg"></param>
  2493. /// <returns></returns>
  2494. 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)
  2495. {
  2496. StringBuilder stringBuilder = new StringBuilder();
  2497. List<sqe_op_data> modelList = new List<sqe_op_data>();
  2498. decimal realValuel;
  2499. if (datas != null && datas.Count > 1)
  2500. {
  2501. for (int i = 1; i < datas.Count; i++)
  2502. {
  2503. sqe_op_data model = new sqe_op_data();
  2504. sqe_file_data dataRow = datas[i];
  2505. if ((dataRow.c1 == null || dataRow.c1.Length == 0) && (dataRow.c2 == null || dataRow.c2.Length == 0))
  2506. {
  2507. break;
  2508. }
  2509. model.item_name = dataRow.c1;
  2510. model.batch_no = dataRow.c2;
  2511. model.op_no = dataRow.c3;
  2512. Object obj = GetFieldValue(dataRow, "c4");
  2513. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2514. {
  2515. model.qty_all = realValuel;
  2516. }
  2517. obj = GetFieldValue(dataRow, "c5");
  2518. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2519. {
  2520. model.qty_ok = realValuel;
  2521. }
  2522. obj = GetFieldValue(dataRow, "c6");
  2523. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2524. {
  2525. model.qty_error = realValuel;
  2526. }
  2527. obj = GetFieldValue(dataRow, "c7");
  2528. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2529. {
  2530. model.percent_ok = realValuel;
  2531. }
  2532. obj = GetFieldValue(dataRow, "c8");
  2533. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2534. {
  2535. model.percent_error = realValuel;
  2536. }
  2537. model.op_time = DateTime.Now;
  2538. model.create_by = create_by;
  2539. model.create_date = create_date;
  2540. model.create_org = create_org;
  2541. modelList.Add(model);
  2542. }
  2543. }
  2544. errorMsg = stringBuilder.ToString();
  2545. return modelList;
  2546. }
  2547. /// <summary>
  2548. /// 从原始数据行生成OP的数据
  2549. /// </summary>
  2550. /// <param name="datas"></param>
  2551. /// <param name="test"></param>
  2552. /// <param name="standards"></param>
  2553. /// <param name="create_by"></param>
  2554. /// <param name="create_date"></param>
  2555. /// <param name="create_org"></param>
  2556. /// <param name="errorMsg"></param>
  2557. /// <returns></returns>
  2558. 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)
  2559. {
  2560. StringBuilder stringBuilder = new StringBuilder();
  2561. List<sqe_op_data_detail> modelList = new List<sqe_op_data_detail>();
  2562. decimal realValuel;
  2563. if (datas != null && datas.Count > 1)
  2564. {
  2565. for (int i = 1; i < datas.Count && i - 1 < standards.Count; i++)
  2566. {
  2567. sqe_file_data dataRow = datas[i];
  2568. List<sqe_op_data_detail> testDatas = new List<sqe_op_data_detail>();
  2569. for (int j = 9; j < 50; j += 4)
  2570. {
  2571. Object obj = GetFieldValue(dataRow, "c" + j.ToString());
  2572. if (obj != null && obj.ToString().Length > 0)
  2573. {
  2574. sqe_op_data_detail data = new sqe_op_data_detail();
  2575. data.op_id = standards[i - 1].op_id;
  2576. data.op_data_id = standards[i - 1].id;
  2577. data.bad_type = obj.ToString();
  2578. obj = GetFieldValue(dataRow, "c" + (j + 1).ToString());
  2579. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2580. {
  2581. data.bad_qty = realValuel;
  2582. }
  2583. obj = GetFieldValue(dataRow, "c" + (j + 2).ToString());
  2584. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2585. {
  2586. data.percent_bad_all = realValuel;
  2587. }
  2588. obj = GetFieldValue(dataRow, "c" + (j + 3).ToString());
  2589. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2590. {
  2591. data.percent_bad = realValuel;
  2592. }
  2593. data.create_by = create_by;
  2594. data.create_date = create_date;
  2595. data.create_org = create_org;
  2596. testDatas.Add(data);
  2597. }
  2598. }
  2599. File_data_ToModel_op_data_detail_Add(modelList, testDatas);
  2600. }
  2601. errorMsg = string.Empty;
  2602. return modelList;
  2603. }
  2604. else
  2605. {
  2606. errorMsg = stringBuilder.ToString();
  2607. return null;
  2608. }
  2609. }
  2610. /// <summary>
  2611. /// 将转换的数据插入到返回结果数据集中,处理掉异常数据
  2612. /// </summary>
  2613. /// <param name="dataDest"></param>
  2614. /// <param name="dataSource"></param>
  2615. private void File_data_ToModel_op_data_detail_Add(List<sqe_op_data_detail> dataDest, List<sqe_op_data_detail> dataSource)
  2616. {
  2617. if (dataSource != null && dataSource.Count > 0)
  2618. {
  2619. for (int i = 0; i < dataSource.Count; i++)
  2620. {
  2621. sqe_op_data_detail data = dataSource[i];
  2622. if (data.bad_type != null && data.bad_type.Length > 0 && data.bad_qty != null)
  2623. {
  2624. dataDest.Add(data);
  2625. }
  2626. }
  2627. }
  2628. }
  2629. #endregion OP
  2630. /// <summary>
  2631. /// 依据导入的数据行,生成FPY的表头、检验标准和数据行
  2632. /// </summary>
  2633. /// <param name="upload_id"></param>
  2634. /// <param name="create_by"></param>
  2635. /// <param name="create_date"></param>
  2636. /// <param name="create_org"></param>
  2637. /// <returns></returns>
  2638. public string Import_Fpy_From_Data(int upload_id, string create_by, DateTime create_date, string create_org)
  2639. {
  2640. StringBuilder stringBuilder = new StringBuilder();
  2641. try
  2642. {
  2643. List<sqe_file_data> datas = LoadData_file_data(upload_id);
  2644. if (datas == null || datas.Count == 0)
  2645. {
  2646. stringBuilder.AppendLine("导入数据信息不存在!");
  2647. return stringBuilder.ToString();
  2648. }
  2649. string errorMsg;
  2650. sqe_fpy test = File_data_ToModel_fpy(datas, create_by, create_date, create_org, out errorMsg);
  2651. if (errorMsg != null && errorMsg.Length > 0)
  2652. {
  2653. stringBuilder.AppendLine(errorMsg);
  2654. return stringBuilder.ToString();
  2655. }
  2656. _sqe_fpy.BeginTransaction();
  2657. _sqe_fpy.Insert(test);
  2658. errorMsg = null;
  2659. List<sqe_fpy_data> standards = File_data_ToModel_fpy_data(datas, test, create_by, create_date, create_org, out errorMsg);
  2660. if (errorMsg != null && errorMsg.Length > 0)
  2661. {
  2662. _sqe_fpy.Rollback();
  2663. stringBuilder.AppendLine(errorMsg);
  2664. return stringBuilder.ToString();
  2665. }
  2666. _sqe_fpy_data.BeginTransaction();
  2667. _sqe_fpy_data.Insert(standards);
  2668. _sqe_fpy.CommitTransaction();
  2669. _sqe_fpy_data.CommitTransaction();
  2670. }
  2671. catch (Exception ex)
  2672. {
  2673. stringBuilder.Append("数据导入失败!");
  2674. }
  2675. finally
  2676. {
  2677. }
  2678. return stringBuilder.ToString();
  2679. }
  2680. #region FPY
  2681. /// <summary>
  2682. /// 从原始数据行生成FPY的表头数据
  2683. /// </summary>
  2684. /// <param name="datas"></param>
  2685. /// <param name="create_by"></param>
  2686. /// <param name="create_date"></param>
  2687. /// <param name="create_org"></param>
  2688. /// <param name="errorMsg"></param>
  2689. /// <returns></returns>
  2690. public sqe_fpy File_data_ToModel_fpy(List<sqe_file_data> datas, string create_by, DateTime create_date, string create_org, out string errorMsg)
  2691. {
  2692. sqe_fpy model = new sqe_fpy();
  2693. model.create_by = create_by;
  2694. model.create_date = create_date;
  2695. model.create_org = create_org;
  2696. errorMsg = string.Empty;
  2697. errorMsg = "";
  2698. return model;
  2699. }
  2700. /// <summary>
  2701. /// 从原始数据行生成FPY的检验标准
  2702. /// </summary>
  2703. /// <param name="datas"></param>
  2704. /// <param name="test"></param>
  2705. /// <param name="create_by"></param>
  2706. /// <param name="create_date"></param>
  2707. /// <param name="create_org"></param>
  2708. /// <param name="errorMsg"></param>
  2709. /// <returns></returns>
  2710. 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)
  2711. {
  2712. StringBuilder stringBuilder = new StringBuilder();
  2713. List<sqe_fpy_data> modelList = new List<sqe_fpy_data>();
  2714. decimal realValuel;
  2715. if (datas != null && datas.Count > 3)
  2716. {
  2717. for (int i = 3; i < datas.Count; i++)
  2718. {
  2719. sqe_fpy_data model = new sqe_fpy_data();
  2720. sqe_file_data dataRow = datas[i];
  2721. if ((dataRow.c1 == null || dataRow.c1.Length == 0) && (dataRow.c3 == null || dataRow.c3.Length == 0))
  2722. {
  2723. break;
  2724. }
  2725. int dateLength;
  2726. DateTime dt;
  2727. if (DateTime.TryParse(dataRow.c2, out dt))
  2728. {
  2729. model.op_time = dt;
  2730. }
  2731. else
  2732. {
  2733. if (int.TryParse(dataRow.c2, out dateLength))
  2734. {
  2735. dt = DateTime.Parse("1900-01-01");
  2736. model.op_time = dt.AddDays(dateLength - 2);
  2737. }
  2738. }
  2739. model.item_no = dataRow.c3;
  2740. model.item_name = dataRow.c4;
  2741. model.op_no = dataRow.c5;
  2742. Object obj = GetFieldValue(dataRow, "c6");
  2743. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2744. {
  2745. model.qty_all = realValuel;
  2746. }
  2747. obj = GetFieldValue(dataRow, "c7");
  2748. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2749. {
  2750. model.qty_error = realValuel;
  2751. }
  2752. obj = GetFieldValue(dataRow, "c8");
  2753. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2754. {
  2755. model.percent_ok = realValuel;
  2756. }
  2757. model.fpy_id = test.id;
  2758. model.create_by = create_by;
  2759. model.create_date = create_date;
  2760. model.create_org = create_org;
  2761. modelList.Add(model);
  2762. }
  2763. }
  2764. errorMsg = stringBuilder.ToString();
  2765. return modelList;
  2766. }
  2767. #endregion FPY
  2768. }
  2769. }