SqeExcelService.cs 204 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757
  1. using Business.EntityFrameworkCore.SqlRepositories;
  2. using Business.StructuredDB;
  3. using Business.StructuredDB.Sqe;
  4. using MathNet.Numerics.Statistics;
  5. using Microsoft.EntityFrameworkCore;
  6. using Microsoft.EntityFrameworkCore.Metadata.Internal;
  7. using Newtonsoft.Json;
  8. using Newtonsoft.Json.Linq;
  9. using NPOI.POIFS.Crypt.Dsig;
  10. using NPOI.SS.Formula.Functions;
  11. using NPOI.XWPF.UserModel;
  12. using RazorEngine.Compilation.ImpromptuInterface.Optimization;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Data;
  16. using System.Linq;
  17. using System.Linq.Expressions;
  18. using System.Reflection;
  19. using System.Runtime.Intrinsics.X86;
  20. using System.Text;
  21. using Volo.Abp.Application.Services;
  22. using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
  23. using static NPOI.POIFS.Crypt.CryptoFunctions;
  24. namespace Business.VSM
  25. {
  26. /// <summary>
  27. /// Sqe数据导入接口实现
  28. /// </summary>
  29. public class SqeExcelService : ApplicationService, ISqeExcelService
  30. {
  31. LoggerHelper WLLog;
  32. private readonly ISqeRepository<sqe_chart_data_temp> _sqe_chart_data_temp;
  33. private readonly ISqeRepository<sqe_cto_process> _sqe_cto_process;
  34. private readonly ISqeRepository<sqe_cto_process_data> _sqe_cto_process_data;
  35. private readonly ISqeRepository<sqe_cto_process_standard> _sqe_cto_process_standard;
  36. private readonly ISqeRepository<sqe_cto_test> _sqe_cto_test;
  37. private readonly ISqeRepository<sqe_cto_test_avg> _sqe_cto_test_avg;
  38. private readonly ISqeRepository<sqe_cto_test_data> _sqe_cto_test_data;
  39. private readonly ISqeRepository<sqe_cto_test_standard> _sqe_cto_test_standard;
  40. private readonly ISqeRepository<sqe_cto_test_statistics> _sqe_cto_test_statistics;
  41. private readonly ISqeRepository<sqe_fct> _sqe_fct;
  42. private readonly ISqeRepository<sqe_fct_data> _sqe_fct_data;
  43. private readonly ISqeRepository<sqe_file_data> _sqe_file_data;
  44. private readonly ISqeRepository<sqe_file_upload> _sqe_file_upload;
  45. private readonly ISqeRepository<sqe_fpy> _sqe_fpy;
  46. private readonly ISqeRepository<sqe_fpy_data> _sqe_fpy_data;
  47. private readonly ISqeRepository<sqe_op> _sqe_op;
  48. private readonly ISqeRepository<sqe_op_data> _sqe_op_data;
  49. private readonly ISqeRepository<sqe_op_data_detail> _sqe_op_data_detail;
  50. private readonly ISqeRepository<sqe_oqc> _sqe_oqc;
  51. private readonly ISqeRepository<sqe_oqc_data> _sqe_oqc_data;
  52. private readonly ISqeRepository<sqe_oqc_standard> _sqe_oqc_standard;
  53. private readonly ISqeRepository<sqe_oqc_statistics> _sqe_oqc_statistics;
  54. private readonly ISqeRepository<v_sqe_cto_process_data> _v_sqe_cto_process_data;
  55. private readonly ISqeRepository<v_sqe_cto_test_avg> _v_sqe_cto_test_avg;
  56. private readonly ISqeRepository<v_sqe_cto_test_data> _v_sqe_cto_test_data;
  57. private readonly ISqeRepository<v_sqe_fpy_data> _v_sqe_fpy_data;
  58. private readonly ISqeRepository<v_sqe_op_data_detail> _v_sqe_op_data_detail;
  59. private readonly ISqeRepository<v_sqe_oqc_data> _v_sqe_oqc_data;
  60. public SqeExcelService(
  61. ISqeRepository<sqe_chart_data_temp> sqe_chart_data_temp,
  62. ISqeRepository<sqe_cto_process> sqe_cto_process,
  63. ISqeRepository<sqe_cto_process_data> sqe_cto_process_data,
  64. ISqeRepository<sqe_cto_process_standard> sqe_cto_process_standard,
  65. ISqeRepository<sqe_cto_test> sqe_cto_test,
  66. ISqeRepository<sqe_cto_test_avg> sqe_cto_test_avg,
  67. ISqeRepository<sqe_cto_test_data> sqe_cto_test_data,
  68. ISqeRepository<sqe_cto_test_standard> sqe_cto_test_standard,
  69. ISqeRepository<sqe_cto_test_statistics> sqe_cto_test_statistics,
  70. ISqeRepository<sqe_fct> sqe_fct,
  71. ISqeRepository<sqe_fct_data> sqe_fct_data,
  72. ISqeRepository<sqe_file_data> sqe_file_data,
  73. ISqeRepository<sqe_file_upload> sqe_file_upload,
  74. ISqeRepository<sqe_fpy> sqe_fpy,
  75. ISqeRepository<sqe_fpy_data> sqe_fpy_data,
  76. ISqeRepository<sqe_op> sqe_op,
  77. ISqeRepository<sqe_op_data> sqe_op_data,
  78. ISqeRepository<sqe_op_data_detail> sqe_op_data_detail,
  79. ISqeRepository<sqe_oqc> sqe_oqc,
  80. ISqeRepository<sqe_oqc_data> sqe_oqc_data,
  81. ISqeRepository<sqe_oqc_standard> sqe_oqc_standard,
  82. ISqeRepository<sqe_oqc_statistics> sqe_oqc_statistics,
  83. ISqeRepository<v_sqe_cto_process_data> v_sqe_cto_process_data,
  84. ISqeRepository<v_sqe_cto_test_avg> v_sqe_cto_test_avg,
  85. ISqeRepository<v_sqe_cto_test_data> v_sqe_cto_test_data,
  86. ISqeRepository<v_sqe_fpy_data> v_sqe_fpy_data,
  87. ISqeRepository<v_sqe_op_data_detail> v_sqe_op_data_detail,
  88. ISqeRepository<v_sqe_oqc_data> v_sqe_oqc_data
  89. )
  90. {
  91. WLLog = new LoggerHelper();
  92. _sqe_chart_data_temp = sqe_chart_data_temp;
  93. _sqe_cto_process = sqe_cto_process;
  94. _sqe_cto_process_data = sqe_cto_process_data;
  95. _sqe_cto_process_standard = sqe_cto_process_standard;
  96. _sqe_cto_test = sqe_cto_test;
  97. _sqe_cto_test_avg = sqe_cto_test_avg;
  98. _sqe_cto_test_data = sqe_cto_test_data;
  99. _sqe_cto_test_standard = sqe_cto_test_standard;
  100. _sqe_cto_test_statistics = sqe_cto_test_statistics;
  101. _sqe_fct = sqe_fct;
  102. _sqe_fct_data = sqe_fct_data;
  103. _sqe_file_data = sqe_file_data;
  104. _sqe_file_upload = sqe_file_upload;
  105. _sqe_fpy = sqe_fpy;
  106. _sqe_fpy_data = sqe_fpy_data;
  107. _sqe_op = sqe_op;
  108. _sqe_op_data = sqe_op_data;
  109. _sqe_op_data_detail = sqe_op_data_detail;
  110. _sqe_oqc = sqe_oqc;
  111. _sqe_oqc_data = sqe_oqc_data;
  112. _sqe_oqc_standard = sqe_oqc_standard;
  113. _sqe_oqc_statistics = sqe_oqc_statistics;
  114. _v_sqe_cto_process_data = v_sqe_cto_process_data;
  115. _v_sqe_cto_test_avg = v_sqe_cto_test_avg;
  116. _v_sqe_cto_test_data = v_sqe_cto_test_data;
  117. _v_sqe_fpy_data = v_sqe_fpy_data;
  118. _v_sqe_op_data_detail = v_sqe_op_data_detail;
  119. _v_sqe_oqc_data = v_sqe_oqc_data;
  120. }
  121. ///// <summary>
  122. ///// 导入Excel文件的sheetName的sheet页面到数据表
  123. ///// </summary>
  124. ///// <param name="filePath"></param>
  125. ///// <param name="sheetName"></param>
  126. ///// <returns></returns>
  127. //public DataTable ImportExcelSheetToDataTable_test(string filePath, string sheetName)
  128. //{
  129. // FileStream file = null;
  130. // DataTable dt = new DataTable();
  131. // int index = 0;
  132. // try
  133. // {
  134. // file = new FileStream(filePath, FileMode.Open, FileAccess.Read);
  135. // //打开Excel对象
  136. // IWorkbook workbook;
  137. // IRow row;
  138. // string fileExt = Path.GetExtension(filePath).ToLower();
  139. // workbook = null;
  140. // if (fileExt == ".xlsx")
  141. // {
  142. // workbook = new XSSFWorkbook(file);
  143. // }
  144. // else
  145. // {
  146. // if (fileExt == ".xls")
  147. // {
  148. // workbook = new HSSFWorkbook(file);
  149. // }
  150. // else
  151. // {
  152. // workbook = null;
  153. // }
  154. // }
  155. // if (workbook == null) { return null; }
  156. // //Excel的Sheet对象
  157. // NPOI.SS.UserModel.ISheet sheet = workbook.GetSheet(sheetName);
  158. // //获取Sheet的所有的行
  159. // System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
  160. // //int colCountMax = 0;
  161. // dt.TableName = sheetName;
  162. // //判断是否拥有首行
  163. // bool firstLine = true;
  164. // //if (!haveColumnName)
  165. // //{
  166. // // firstLine = false;
  167. // //}
  168. // bool bDate = false;
  169. // while (rows.MoveNext())
  170. // {
  171. // index++;
  172. // bDate = false;
  173. // if (fileExt == ".xlsx")
  174. // {
  175. // row = (XSSFRow)rows.Current;
  176. // }
  177. // else
  178. // {
  179. // row = (HSSFRow)rows.Current;
  180. // }
  181. // if (!firstLine)
  182. // {
  183. // //生成表结构
  184. // //仅当首次调用时会进行循环生成
  185. // for (int i = dt.Columns.Count; i < row.Cells.Count; i++)
  186. // {
  187. // dt.Columns.Add(Convert.ToChar(((int)'A') + i).ToString());
  188. // }
  189. // }
  190. // else
  191. // {
  192. // //依据首行进行字段生成
  193. // for (int i = dt.Columns.Count; i < row.Cells.Count; i++)
  194. // {
  195. // dt.Columns.Add(row.Cells[i].ToString());
  196. // }
  197. // }
  198. // //没有首行,生成数据
  199. // if (!firstLine)
  200. // {
  201. // DataRow dr = dt.NewRow();
  202. // for (int i = 0; i < row.LastCellNum - 1; i++)
  203. // {
  204. // NPOI.SS.UserModel.ICell cell = row.GetCell(i);
  205. // String s = "";
  206. // if (cell != null)
  207. // {
  208. // switch (cell.CellType)
  209. // {
  210. // case NPOI.SS.UserModel.CellType.Unknown:
  211. // break;
  212. // case NPOI.SS.UserModel.CellType.Numeric:
  213. // if (HSSFDateUtil.IsCellDateFormatted(cell))
  214. // {
  215. // if (index < 6)
  216. // {
  217. // s = cell.DateCellValue.ToString();
  218. // }
  219. // else
  220. // {
  221. // s = cell.ToString();
  222. // }
  223. // }
  224. // else
  225. // {
  226. // s = cell.NumericCellValue.ToString();
  227. // }
  228. // break;
  229. // case NPOI.SS.UserModel.CellType.String:
  230. // s = cell.StringCellValue;
  231. // break;
  232. // case NPOI.SS.UserModel.CellType.Formula:
  233. // if (i == 0 || i == 1)
  234. // {
  235. // s = cell.StringCellValue;
  236. // }
  237. // else
  238. // {
  239. // try
  240. // {
  241. // if (cell.CellFormula == "序号")
  242. // {
  243. // s = cell.ToString();
  244. // }
  245. // else
  246. // {
  247. // s = cell.NumericCellValue != null ? cell.NumericCellValue.ToString() : null;
  248. // }
  249. // }
  250. // catch (Exception ex)
  251. // {
  252. // WLLog.Error("Excel导入问题:", ex);
  253. // }
  254. // }
  255. // break;
  256. // case NPOI.SS.UserModel.CellType.Blank:
  257. // if (bDate)
  258. // {
  259. // //对于日期的特殊处理
  260. // s = dr[i - 1].ToString();
  261. // }
  262. // else
  263. // {
  264. // s = cell.StringCellValue;
  265. // }
  266. // break;
  267. // case NPOI.SS.UserModel.CellType.Boolean:
  268. // break;
  269. // case NPOI.SS.UserModel.CellType.Error:
  270. // break;
  271. // default:
  272. // break;
  273. // }
  274. // }
  275. // dr[i] = s;
  276. // }
  277. // dt.Rows.Add(dr);
  278. // }
  279. // firstLine = false;
  280. // }
  281. // return dt;
  282. // }
  283. // catch (Exception ex)
  284. // {
  285. // WLLog.Error("Excel导入问题:", ex);
  286. // }
  287. // finally
  288. // {
  289. // if (file != null)
  290. // {
  291. // file.Close();
  292. // }
  293. // }
  294. // return dt;
  295. //}
  296. //public DataTable ImportExcelSheetToDataTable_process(string filePath, string sheetName)
  297. //{
  298. // FileStream file = null;
  299. // DataTable dt = new DataTable();
  300. // int index = 0;
  301. // try
  302. // {
  303. // file = new FileStream(filePath, FileMode.Open, FileAccess.Read);
  304. // //打开Excel对象
  305. // IWorkbook workbook;
  306. // IRow row;
  307. // string fileExt = Path.GetExtension(filePath).ToLower();
  308. // workbook = null;
  309. // if (fileExt == ".xlsx")
  310. // {
  311. // workbook = new XSSFWorkbook(file);
  312. // }
  313. // else
  314. // {
  315. // if (fileExt == ".xls")
  316. // {
  317. // workbook = new HSSFWorkbook(file);
  318. // }
  319. // else
  320. // {
  321. // workbook = null;
  322. // }
  323. // }
  324. // if (workbook == null) { return null; }
  325. // //Excel的Sheet对象
  326. // NPOI.SS.UserModel.ISheet sheet = workbook.GetSheet(sheetName);
  327. // //获取Sheet的所有的行
  328. // System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
  329. // //int colCountMax = 0;
  330. // dt.TableName = sheetName;
  331. // //判断是否拥有首行
  332. // bool firstLine = true;
  333. // //if (!haveColumnName)
  334. // //{
  335. // // firstLine = false;
  336. // //}
  337. // bool bDate = false;
  338. // while (rows.MoveNext())
  339. // {
  340. // index++;
  341. // bDate = false;
  342. // if (fileExt == ".xlsx")
  343. // {
  344. // row = (XSSFRow)rows.Current;
  345. // }
  346. // else
  347. // {
  348. // row = (HSSFRow)rows.Current;
  349. // }
  350. // if (!firstLine)
  351. // {
  352. // //生成表结构
  353. // //仅当首次调用时会进行循环生成
  354. // for (int i = dt.Columns.Count; i < row.Cells.Count; i++)
  355. // {
  356. // dt.Columns.Add(Convert.ToChar(((int)'A') + i).ToString());
  357. // }
  358. // }
  359. // else
  360. // {
  361. // //依据首行进行字段生成
  362. // for (int i = dt.Columns.Count; i < row.Cells.Count; i++)
  363. // {
  364. // dt.Columns.Add(row.Cells[i].ToString());
  365. // }
  366. // }
  367. // //没有首行,生成数据
  368. // if (!firstLine)
  369. // {
  370. // DataRow dr = dt.NewRow();
  371. // for (int i = 0; i < row.LastCellNum - 1; i++)
  372. // {
  373. // NPOI.SS.UserModel.ICell cell = row.GetCell(i);
  374. // String s = "";
  375. // if (cell != null)
  376. // {
  377. // switch (cell.CellType)
  378. // {
  379. // case NPOI.SS.UserModel.CellType.Unknown:
  380. // break;
  381. // case NPOI.SS.UserModel.CellType.Numeric:
  382. // if (HSSFDateUtil.IsCellDateFormatted(cell))
  383. // {
  384. // if (index < 6)
  385. // {
  386. // s = cell.DateCellValue.ToString();
  387. // }
  388. // else
  389. // {
  390. // s = cell.ToString();
  391. // }
  392. // }
  393. // else
  394. // {
  395. // s = cell.NumericCellValue.ToString();
  396. // }
  397. // break;
  398. // case NPOI.SS.UserModel.CellType.String:
  399. // s = cell.StringCellValue;
  400. // break;
  401. // case NPOI.SS.UserModel.CellType.Formula:
  402. // try
  403. // {
  404. // if (cell.CellFormula == "序号")
  405. // {
  406. // s = cell.ToString();
  407. // }
  408. // else
  409. // {
  410. // s = cell.NumericCellValue != null ? cell.NumericCellValue.ToString() : null;
  411. // }
  412. // }
  413. // catch (Exception ex)
  414. // {
  415. // WLLog.Error("Excel导入问题:", ex);
  416. // }
  417. // break;
  418. // case NPOI.SS.UserModel.CellType.Blank:
  419. // if (bDate)
  420. // {
  421. // //对于日期的特殊处理
  422. // s = dr[i - 1].ToString();
  423. // }
  424. // else
  425. // {
  426. // s = cell.StringCellValue;
  427. // }
  428. // break;
  429. // case NPOI.SS.UserModel.CellType.Boolean:
  430. // break;
  431. // case NPOI.SS.UserModel.CellType.Error:
  432. // break;
  433. // default:
  434. // break;
  435. // }
  436. // }
  437. // dr[i] = s;
  438. // }
  439. // dt.Rows.Add(dr);
  440. // }
  441. // firstLine = false;
  442. // }
  443. // return dt;
  444. // }
  445. // catch (Exception ex)
  446. // {
  447. // WLLog.Error("Excel导入问题:", ex);
  448. // }
  449. // finally
  450. // {
  451. // if (file != null)
  452. // {
  453. // file.Close();
  454. // }
  455. // }
  456. // return dt;
  457. //}
  458. ///// <summary>
  459. ///// 获取Excel文件Sheet名称列表,与Jet引擎不一致,获取的时候没有$多余字符。
  460. ///// </summary>
  461. ///// <param name="filePath"></param>
  462. ///// <returns></returns>
  463. //public List<String> GetSheetNames(string filePath)
  464. //{
  465. // List<String> tables = null;
  466. // FileStream file = null;
  467. // try
  468. // {
  469. // tables = new List<string>();
  470. // file = new FileStream(filePath, FileMode.Open, FileAccess.Read);
  471. // HSSFWorkbook hssfworkbook = new HSSFWorkbook(file);
  472. // int i = 0;
  473. // while (true)
  474. // {
  475. // try
  476. // {
  477. // String s = hssfworkbook.GetSheetName(i);
  478. // if (s != null)
  479. // {
  480. // tables.Add(s);
  481. // i++;
  482. // }
  483. // else
  484. // {
  485. // break;
  486. // }
  487. // }
  488. // catch (Exception ex)
  489. // {
  490. // break;
  491. // }
  492. // }
  493. // }
  494. // catch (Exception ex)
  495. // {
  496. // WLLog.Error("Excel导入问题:", ex);
  497. // }
  498. // finally
  499. // {
  500. // if (file != null)
  501. // {
  502. // file.Close();
  503. // }
  504. // }
  505. // return tables;
  506. //}
  507. /// <summary>
  508. /// 依据上传文件标识,获取上传文件对象
  509. /// </summary>
  510. /// <param name="upload_id"></param>
  511. /// <returns></returns>
  512. public sqe_file_upload Get_Sqe_file_upload(int upload_id)
  513. {
  514. try
  515. {
  516. List<sqe_file_upload> uploads = _sqe_file_upload.Select(a => a.id == upload_id);
  517. sqe_file_upload _Upload = _sqe_file_upload.Select(a => a.id == upload_id).First();
  518. return _Upload;
  519. }
  520. catch (Exception ex)
  521. {
  522. return null;
  523. }
  524. }
  525. /// <summary>
  526. /// 导入数据到检验表 sqe_cto_test、sqe_cto_test_standard、sqe_cto_test_data
  527. /// </summary>
  528. /// <param name="upload_id"></param>
  529. /// <param name="create_by"></param>
  530. /// <param name="create_date"></param>
  531. /// <param name="create_org"></param>
  532. /// <returns></returns>
  533. public string Import_Test_From_Data(int upload_id, string create_by, DateTime create_date, string create_org)
  534. {
  535. StringBuilder stringBuilder = new StringBuilder();
  536. try
  537. {
  538. sqe_file_upload sqe_File_Upload = Get_Sqe_file_upload(upload_id);
  539. List<sqe_file_data> datas = LoadData_file_data(upload_id);
  540. if (datas == null || datas.Count == 0)
  541. {
  542. stringBuilder.AppendLine("导入数据信息不存在!");
  543. return stringBuilder.ToString();
  544. }
  545. //产品特性的文件格式校验
  546. if (datas[0].c1.CompareTo("产品过程检验记录") != 0)
  547. {
  548. stringBuilder.AppendLine("文件不是【产品过程检验记录】要求的格式");
  549. return stringBuilder.ToString();
  550. }
  551. if (datas[1].c1.CompareTo("生产时间") != 0
  552. || datas[1].c3.CompareTo("生产班次") != 0
  553. || datas[1].c5.CompareTo("物料号") != 0
  554. || datas[1].c7.CompareTo("物料名称") != 0)
  555. {
  556. stringBuilder.AppendLine("文件不是【产品过程检验记录】要求的格式");
  557. return stringBuilder.ToString();
  558. }
  559. if (datas[2].c1.CompareTo("对应原材料批次号") != 0
  560. || datas[2].c3.CompareTo("原材料使用数量") != 0
  561. || datas[2].c5.CompareTo("物料批次号") != 0
  562. || datas[2].c7.CompareTo("物料数量") != 0)
  563. {
  564. stringBuilder.AppendLine("文件不是【产品过程检验记录】要求的格式");
  565. return stringBuilder.ToString();
  566. }
  567. string errorMsg;
  568. sqe_cto_test test = File_data_ToModel_test(datas, create_by, create_date, create_org, out errorMsg);
  569. if (errorMsg != null && errorMsg.Length > 0)
  570. {
  571. stringBuilder.AppendLine(errorMsg);
  572. return stringBuilder.ToString();
  573. }
  574. _sqe_cto_test.BeginTransaction();
  575. _sqe_cto_test.Insert(test);
  576. errorMsg = null;
  577. List<sqe_cto_test_standard> standards = File_data_ToModel_test_standard(datas, test, create_by, create_date, create_org, out errorMsg);
  578. if (errorMsg != null && errorMsg.Length > 0)
  579. {
  580. _sqe_cto_test.Rollback();
  581. stringBuilder.AppendLine(errorMsg);
  582. return stringBuilder.ToString();
  583. }
  584. _sqe_cto_test_standard.BeginTransaction();
  585. _sqe_cto_test_standard.Insert(standards);
  586. List<sqe_cto_test_data> test_Datas = File_data_ToModel_test_data(datas, test, standards, create_by, create_date, create_org, out errorMsg);
  587. if (errorMsg != null && errorMsg.Length > 0)
  588. {
  589. _sqe_cto_test.Rollback();
  590. _sqe_cto_test_standard.Rollback();
  591. stringBuilder.AppendLine(errorMsg);
  592. return stringBuilder.ToString();
  593. }
  594. _sqe_cto_test_data.Insert(test_Datas);
  595. sqe_File_Upload.item_no = test.item_no;
  596. sqe_File_Upload.item_name = test.item_name;
  597. _sqe_file_upload.Update(sqe_File_Upload);
  598. _sqe_cto_test.CommitTransaction();
  599. _sqe_cto_test_standard.CommitTransaction();
  600. }
  601. catch (Exception ex)
  602. {
  603. stringBuilder.Append("数据导入失败!");
  604. }
  605. finally
  606. {
  607. }
  608. return stringBuilder.ToString();
  609. }
  610. /// <summary>
  611. /// 依据id,从sqe_file_upload和sqe_file_data,加载数据
  612. /// </summary>
  613. /// <param name="upload_id"></param>
  614. /// <returns></returns>
  615. public List<sqe_file_data> LoadData_file_data(int upload_id)
  616. {
  617. List<sqe_file_data> datas = _sqe_file_data.Select(a => a.file_id == upload_id).OrderBy(a => a.id).ToList();
  618. return datas;
  619. }
  620. #region 产品特性
  621. 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)
  622. {
  623. StringBuilder stringBuilder = new StringBuilder();
  624. sqe_cto_test model = new sqe_cto_test();
  625. DateTime timeValue;
  626. decimal realValuel;
  627. int intValue;
  628. if (datas != null && datas.Count >= 5)
  629. {
  630. try
  631. {
  632. model.file_id = datas[0].file_id;
  633. sqe_file_data data = datas[1];
  634. if (DateTime.TryParse(data.c2, out timeValue))
  635. {
  636. model.product_time = timeValue;
  637. }
  638. else
  639. {
  640. //model.product_time = DateTime.Parse("2000-01-01");
  641. model.product_time = DateTime.Now;
  642. }
  643. model.shift_no = data.c4;
  644. model.item_no = data.c6;
  645. model.item_name = data.c8;
  646. data = datas[2];
  647. model.material_batch = data.c2;
  648. if (decimal.TryParse(data.c4, out realValuel))
  649. {
  650. model.material_used = realValuel;
  651. }
  652. model.item_batch = data.c6;
  653. if (decimal.TryParse(data.c8, out realValuel))
  654. {
  655. model.item_qty = realValuel;
  656. }
  657. data = datas[3];
  658. model.op_pre = data.c2;
  659. model.op_pre_batch = data.c4;
  660. model.op_current = data.c6;
  661. model.op_batch = data.c8;
  662. data = datas[4];
  663. model.device_name = data.c2;
  664. model.device_no = data.c4;
  665. if (int.TryParse(data.c8, out intValue))
  666. {
  667. model.sampling_number = intValue;
  668. }
  669. }
  670. catch (Exception ex)
  671. {
  672. WLLog.Error("Excel数据解析问题:", ex);
  673. }
  674. model.create_by = create_by;
  675. model.create_date = create_date;
  676. model.create_org = create_org;
  677. errorMsg = string.Empty;
  678. return model;
  679. }
  680. else
  681. {
  682. errorMsg = stringBuilder.ToString();
  683. return null;
  684. }
  685. }
  686. 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)
  687. {
  688. StringBuilder stringBuilder = new StringBuilder();
  689. List<sqe_cto_test_standard> modelList = new List<sqe_cto_test_standard>();
  690. decimal realValuel;
  691. if (datas != null && datas.Count >= 13)
  692. {
  693. try
  694. {
  695. //标准的起始位置
  696. int index = 5;
  697. sqe_file_data dataRow = datas[index];
  698. #region 处理尺寸的表头
  699. if (dataRow.c3 != null && dataRow.c3.Length > 0)
  700. {
  701. sqe_cto_test_standard model = new sqe_cto_test_standard();
  702. model.standard_no = dataRow.c3;
  703. model.create_by = create_by;
  704. model.create_date = create_date;
  705. model.create_org = create_org;
  706. model.test_id = test.id;
  707. modelList.Add(model);
  708. }
  709. if (dataRow.c4 != null && dataRow.c4.Length > 0)
  710. {
  711. sqe_cto_test_standard model = new sqe_cto_test_standard();
  712. model.standard_no = dataRow.c4;
  713. model.create_by = create_by;
  714. model.create_date = create_date;
  715. model.create_org = create_org;
  716. model.test_id = test.id;
  717. modelList.Add(model);
  718. }
  719. if (dataRow.c5 != null && dataRow.c5.Length > 0)
  720. {
  721. sqe_cto_test_standard model = new sqe_cto_test_standard();
  722. model.standard_no = dataRow.c5;
  723. model.create_by = create_by;
  724. model.create_date = create_date;
  725. model.create_org = create_org;
  726. model.test_id = test.id;
  727. modelList.Add(model);
  728. }
  729. if (dataRow.c6 != null && dataRow.c6.Length > 0)
  730. {
  731. sqe_cto_test_standard model = new sqe_cto_test_standard();
  732. model.standard_no = dataRow.c6;
  733. model.create_by = create_by;
  734. model.create_date = create_date;
  735. model.create_org = create_org;
  736. model.test_id = test.id;
  737. modelList.Add(model);
  738. }
  739. if (dataRow.c7 != null && dataRow.c7.Length > 0)
  740. {
  741. sqe_cto_test_standard model = new sqe_cto_test_standard();
  742. model.standard_no = dataRow.c7;
  743. model.create_by = create_by;
  744. model.create_date = create_date;
  745. model.create_org = create_org;
  746. model.test_id = test.id;
  747. modelList.Add(model);
  748. }
  749. if (dataRow.c8 != null && dataRow.c8.Length > 0)
  750. {
  751. sqe_cto_test_standard model = new sqe_cto_test_standard();
  752. model.standard_no = dataRow.c8;
  753. model.create_by = create_by;
  754. model.create_date = create_date;
  755. model.create_org = create_org;
  756. model.test_id = test.id;
  757. modelList.Add(model);
  758. }
  759. if (dataRow.c9 != null && dataRow.c9.Length > 0)
  760. {
  761. sqe_cto_test_standard model = new sqe_cto_test_standard();
  762. model.standard_no = dataRow.c9;
  763. model.create_by = create_by;
  764. model.create_date = create_date;
  765. model.create_org = create_org;
  766. model.test_id = test.id;
  767. modelList.Add(model);
  768. }
  769. if (dataRow.c10 != null && dataRow.c10.Length > 0)
  770. {
  771. sqe_cto_test_standard model = new sqe_cto_test_standard();
  772. model.standard_no = dataRow.c10;
  773. model.create_by = create_by;
  774. model.create_date = create_date;
  775. model.create_org = create_org;
  776. model.test_id = test.id;
  777. modelList.Add(model);
  778. }
  779. if (dataRow.c11 != null && dataRow.c11.Length > 0)
  780. {
  781. sqe_cto_test_standard model = new sqe_cto_test_standard();
  782. model.standard_no = dataRow.c11;
  783. model.create_by = create_by;
  784. model.create_date = create_date;
  785. model.create_org = create_org;
  786. model.test_id = test.id;
  787. modelList.Add(model);
  788. }
  789. #endregion 处理尺寸的表头
  790. if (modelList.Count > 0)
  791. {
  792. sqe_cto_test_standard model = modelList[0];
  793. dataRow = datas[index + 1];
  794. model.sampling_count = int.Parse(dataRow.c3);
  795. dataRow = datas[index + 2];
  796. model.is_associated_size = dataRow.c3;
  797. dataRow = datas[index + 3];
  798. if (dataRow.c3 != null && decimal.TryParse(dataRow.c3, out realValuel))
  799. {
  800. model.standard_value = realValuel;
  801. }
  802. dataRow = datas[index + 4];
  803. if (dataRow.c3 != null && decimal.TryParse(dataRow.c3, out realValuel))
  804. {
  805. model.delta_up = realValuel;
  806. }
  807. dataRow = datas[index + 5];
  808. if (dataRow.c3 != null && decimal.TryParse(dataRow.c3, out realValuel))
  809. {
  810. model.delta_down = realValuel;
  811. }
  812. dataRow = datas[index + 6];
  813. if (dataRow.c3 != null && decimal.TryParse(dataRow.c3, out realValuel))
  814. {
  815. model.standard_max = realValuel;
  816. }
  817. dataRow = datas[index + 7];
  818. if (dataRow.c3 != null && decimal.TryParse(dataRow.c3, out realValuel))
  819. {
  820. model.standard_min = realValuel;
  821. }
  822. }
  823. if (modelList.Count > 1)
  824. {
  825. sqe_cto_test_standard model = modelList[1];
  826. dataRow = datas[index + 1];
  827. model.sampling_count = int.Parse(dataRow.c4);
  828. dataRow = datas[index + 2];
  829. model.is_associated_size = dataRow.c4;
  830. dataRow = datas[index + 3];
  831. if (dataRow.c4 != null && decimal.TryParse(dataRow.c4, out realValuel))
  832. {
  833. model.standard_value = realValuel;
  834. }
  835. dataRow = datas[index + 4];
  836. if (dataRow.c4 != null && decimal.TryParse(dataRow.c4, out realValuel))
  837. {
  838. model.delta_up = realValuel;
  839. }
  840. dataRow = datas[index + 5];
  841. if (dataRow.c4 != null && decimal.TryParse(dataRow.c4, out realValuel))
  842. {
  843. model.delta_down = realValuel;
  844. }
  845. dataRow = datas[index + 6];
  846. if (dataRow.c4 != null && decimal.TryParse(dataRow.c4, out realValuel))
  847. {
  848. model.standard_max = realValuel;
  849. }
  850. dataRow = datas[index + 7];
  851. if (dataRow.c4 != null && decimal.TryParse(dataRow.c4, out realValuel))
  852. {
  853. model.standard_min = realValuel;
  854. }
  855. }
  856. if (modelList.Count > 2)
  857. {
  858. sqe_cto_test_standard model = modelList[2];
  859. dataRow = datas[index + 1];
  860. model.sampling_count = int.Parse(dataRow.c5);
  861. dataRow = datas[index + 2];
  862. model.is_associated_size = dataRow.c5;
  863. dataRow = datas[index + 3];
  864. if (dataRow.c5 != null && decimal.TryParse(dataRow.c5, out realValuel))
  865. {
  866. model.standard_value = realValuel;
  867. }
  868. dataRow = datas[index + 4];
  869. if (dataRow.c5 != null && decimal.TryParse(dataRow.c5, out realValuel))
  870. {
  871. model.delta_up = realValuel;
  872. }
  873. dataRow = datas[index + 5];
  874. if (dataRow.c5 != null && decimal.TryParse(dataRow.c5, out realValuel))
  875. {
  876. model.delta_down = realValuel;
  877. }
  878. dataRow = datas[index + 6];
  879. if (dataRow.c5 != null && decimal.TryParse(dataRow.c5, out realValuel))
  880. {
  881. model.standard_max = realValuel;
  882. }
  883. dataRow = datas[index + 7];
  884. if (dataRow.c5 != null && decimal.TryParse(dataRow.c5, out realValuel))
  885. {
  886. model.standard_min = realValuel;
  887. }
  888. }
  889. if (modelList.Count > 3)
  890. {
  891. sqe_cto_test_standard model = modelList[3];
  892. dataRow = datas[index + 1];
  893. model.sampling_count = int.Parse(dataRow.c6);
  894. dataRow = datas[index + 2];
  895. model.is_associated_size = dataRow.c6;
  896. dataRow = datas[index + 3];
  897. if (dataRow.c6 != null && decimal.TryParse(dataRow.c6, out realValuel))
  898. {
  899. model.standard_value = realValuel;
  900. }
  901. dataRow = datas[index + 4];
  902. if (dataRow.c6 != null && decimal.TryParse(dataRow.c6, out realValuel))
  903. {
  904. model.delta_up = realValuel;
  905. }
  906. dataRow = datas[index + 5];
  907. if (dataRow.c6 != null && decimal.TryParse(dataRow.c6, out realValuel))
  908. {
  909. model.delta_down = realValuel;
  910. }
  911. dataRow = datas[index + 6];
  912. if (dataRow.c6 != null && decimal.TryParse(dataRow.c6, out realValuel))
  913. {
  914. model.standard_max = realValuel;
  915. }
  916. dataRow = datas[index + 7];
  917. if (dataRow.c6 != null && decimal.TryParse(dataRow.c6, out realValuel))
  918. {
  919. model.standard_min = realValuel;
  920. }
  921. }
  922. if (modelList.Count > 4)
  923. {
  924. sqe_cto_test_standard model = modelList[4];
  925. dataRow = datas[index + 1];
  926. model.sampling_count = int.Parse(dataRow.c7);
  927. dataRow = datas[index + 2];
  928. model.is_associated_size = dataRow.c7;
  929. dataRow = datas[index + 3];
  930. if (dataRow.c7 != null && decimal.TryParse(dataRow.c7, out realValuel))
  931. {
  932. model.standard_value = realValuel;
  933. }
  934. dataRow = datas[index + 4];
  935. if (dataRow.c7 != null && decimal.TryParse(dataRow.c7, out realValuel))
  936. {
  937. model.delta_up = realValuel;
  938. }
  939. dataRow = datas[index + 5];
  940. if (dataRow.c7 != null && decimal.TryParse(dataRow.c7, out realValuel))
  941. {
  942. model.delta_down = realValuel;
  943. }
  944. dataRow = datas[index + 6];
  945. if (dataRow.c7 != null && decimal.TryParse(dataRow.c7, out realValuel))
  946. {
  947. model.standard_max = realValuel;
  948. }
  949. dataRow = datas[index + 7];
  950. if (dataRow.c7 != null && decimal.TryParse(dataRow.c7, out realValuel))
  951. {
  952. model.standard_min = realValuel;
  953. }
  954. }
  955. if (modelList.Count > 5)
  956. {
  957. sqe_cto_test_standard model = modelList[5];
  958. dataRow = datas[index + 1];
  959. model.sampling_count = int.Parse(dataRow.c8);
  960. dataRow = datas[index + 2];
  961. model.is_associated_size = dataRow.c8;
  962. dataRow = datas[index + 3];
  963. if (dataRow.c8 != null && decimal.TryParse(dataRow.c8, out realValuel))
  964. {
  965. model.standard_value = realValuel;
  966. }
  967. dataRow = datas[index + 4];
  968. if (dataRow.c8 != null && decimal.TryParse(dataRow.c8, out realValuel))
  969. {
  970. model.delta_up = realValuel;
  971. }
  972. dataRow = datas[index + 5];
  973. if (dataRow.c8 != null && decimal.TryParse(dataRow.c8, out realValuel))
  974. {
  975. model.delta_down = realValuel;
  976. }
  977. dataRow = datas[index + 6];
  978. if (dataRow.c8 != null && decimal.TryParse(dataRow.c8, out realValuel))
  979. {
  980. model.standard_max = realValuel;
  981. }
  982. dataRow = datas[index + 7];
  983. if (dataRow.c8 != null && decimal.TryParse(dataRow.c8, out realValuel))
  984. {
  985. model.standard_min = realValuel;
  986. }
  987. }
  988. if (modelList.Count > 6)
  989. {
  990. sqe_cto_test_standard model = modelList[6];
  991. dataRow = datas[index + 1];
  992. model.sampling_count = int.Parse(dataRow.c9);
  993. dataRow = datas[index + 2];
  994. model.is_associated_size = dataRow.c9;
  995. dataRow = datas[index + 3];
  996. if (dataRow.c9 != null && decimal.TryParse(dataRow.c9, out realValuel))
  997. {
  998. model.standard_value = realValuel;
  999. }
  1000. dataRow = datas[index + 4];
  1001. if (dataRow.c9 != null && decimal.TryParse(dataRow.c9, out realValuel))
  1002. {
  1003. model.delta_up = realValuel;
  1004. }
  1005. dataRow = datas[index + 5];
  1006. if (dataRow.c9 != null && decimal.TryParse(dataRow.c9, out realValuel))
  1007. {
  1008. model.delta_down = realValuel;
  1009. }
  1010. dataRow = datas[index + 6];
  1011. if (dataRow.c9 != null && decimal.TryParse(dataRow.c9, out realValuel))
  1012. {
  1013. model.standard_max = realValuel;
  1014. }
  1015. dataRow = datas[index + 7];
  1016. if (dataRow.c9 != null && decimal.TryParse(dataRow.c9, out realValuel))
  1017. {
  1018. model.standard_min = realValuel;
  1019. }
  1020. }
  1021. if (modelList.Count > 7)
  1022. {
  1023. sqe_cto_test_standard model = modelList[7];
  1024. dataRow = datas[index + 1];
  1025. model.sampling_count = int.Parse(dataRow.c10);
  1026. dataRow = datas[index + 2];
  1027. model.is_associated_size = dataRow.c10;
  1028. dataRow = datas[index + 3];
  1029. if (dataRow.c10 != null && decimal.TryParse(dataRow.c10, out realValuel))
  1030. {
  1031. model.standard_value = realValuel;
  1032. }
  1033. dataRow = datas[index + 4];
  1034. if (dataRow.c10 != null && decimal.TryParse(dataRow.c10, out realValuel))
  1035. {
  1036. model.delta_up = realValuel;
  1037. }
  1038. dataRow = datas[index + 5];
  1039. if (dataRow.c10 != null && decimal.TryParse(dataRow.c10, out realValuel))
  1040. {
  1041. model.delta_down = realValuel;
  1042. }
  1043. dataRow = datas[index + 6];
  1044. if (dataRow.c10 != null && decimal.TryParse(dataRow.c10, out realValuel))
  1045. {
  1046. model.standard_max = realValuel;
  1047. }
  1048. dataRow = datas[index + 7];
  1049. if (dataRow.c10 != null && decimal.TryParse(dataRow.c10, out realValuel))
  1050. {
  1051. model.standard_min = realValuel;
  1052. }
  1053. }
  1054. if (modelList.Count > 8)
  1055. {
  1056. sqe_cto_test_standard model = modelList[8];
  1057. dataRow = datas[index + 1];
  1058. model.sampling_count = int.Parse(dataRow.c11);
  1059. dataRow = datas[index + 2];
  1060. model.is_associated_size = dataRow.c11;
  1061. dataRow = datas[index + 3];
  1062. if (dataRow.c11 != null && decimal.TryParse(dataRow.c11, out realValuel))
  1063. {
  1064. model.standard_value = realValuel;
  1065. }
  1066. dataRow = datas[index + 4];
  1067. if (dataRow.c11 != null && decimal.TryParse(dataRow.c11, out realValuel))
  1068. {
  1069. model.delta_up = realValuel;
  1070. }
  1071. dataRow = datas[index + 5];
  1072. if (dataRow.c11 != null && decimal.TryParse(dataRow.c11, out realValuel))
  1073. {
  1074. model.delta_down = realValuel;
  1075. }
  1076. dataRow = datas[index + 6];
  1077. if (dataRow.c11 != null && decimal.TryParse(dataRow.c11, out realValuel))
  1078. {
  1079. model.standard_max = realValuel;
  1080. }
  1081. dataRow = datas[index + 7];
  1082. if (dataRow.c11 != null && decimal.TryParse(dataRow.c11, out realValuel))
  1083. {
  1084. model.standard_min = realValuel;
  1085. }
  1086. }
  1087. }
  1088. catch (Exception ex)
  1089. {
  1090. WLLog.Error("Excel数据解析问题:", ex);
  1091. }
  1092. errorMsg = stringBuilder.ToString();
  1093. return modelList;
  1094. }
  1095. else
  1096. {
  1097. errorMsg = stringBuilder.ToString();
  1098. return null;
  1099. }
  1100. }
  1101. 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)
  1102. {
  1103. StringBuilder stringBuilder = new StringBuilder();
  1104. List<sqe_cto_test_data> modelList = new List<sqe_cto_test_data>();
  1105. decimal realValuel;
  1106. if (datas != null && datas.Count >= 15)
  1107. {
  1108. for (int i = 14; i < datas.Count; i++)
  1109. {
  1110. sqe_file_data dataRow = datas[i];
  1111. if ((dataRow.c1 == null || dataRow.c1.Length == 0 || dataRow.c1 == "0") && (dataRow.c2 == null || dataRow.c2.Length == 0))
  1112. {
  1113. break;
  1114. }
  1115. //初始化每一层的数据集合
  1116. List<sqe_cto_test_data> test_datas = new List<sqe_cto_test_data>();
  1117. for (int j = 0; j < standards.Count; j++)
  1118. {
  1119. sqe_cto_test_data data = new sqe_cto_test_data();
  1120. data.test_id = standards[j].test_id;
  1121. data.standard_id = standards[j].id;
  1122. data.create_by = create_by;
  1123. data.create_date = create_date;
  1124. data.create_org = create_org;
  1125. test_datas.Add(data);
  1126. }
  1127. try
  1128. {
  1129. //将每一个检测标准的值从记录行中取出来
  1130. if (test_datas.Count > 0)
  1131. {
  1132. sqe_cto_test_data data = test_datas[0];
  1133. data.data_no = dataRow.c1;
  1134. if (dataRow.c2 != null)
  1135. {
  1136. String s = dataRow.c2.ToString();
  1137. if (s != null && s.Length > 9)
  1138. {
  1139. s = s.Substring(s.Length - 9);
  1140. }
  1141. DateTime date;
  1142. if (DateTime.TryParse(test.product_time.Value.ToString("yyyy-MM-dd ") + s, out date))
  1143. {
  1144. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1145. }
  1146. }
  1147. if (dataRow.c3 != null && dataRow.c3.Length > 0 && decimal.TryParse(dataRow.c3, out realValuel))
  1148. {
  1149. data.data_value = realValuel;
  1150. }
  1151. else
  1152. {
  1153. data.data_value = null;
  1154. }
  1155. }
  1156. if (test_datas.Count > 1)
  1157. {
  1158. sqe_cto_test_data data = test_datas[1];
  1159. data.data_no = dataRow.c1;
  1160. if (dataRow.c2 != null)
  1161. {
  1162. String s = dataRow.c2.ToString();
  1163. DateTime date;
  1164. if (DateTime.TryParse(test.product_time.Value.ToString("yyyy-MM-dd ") + s, out date))
  1165. {
  1166. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1167. }
  1168. }
  1169. if (dataRow.c4 != null && dataRow.c4.Length > 0 && decimal.TryParse(dataRow.c4, out realValuel))
  1170. {
  1171. data.data_value = realValuel;
  1172. }
  1173. else
  1174. {
  1175. data.data_value = null;
  1176. }
  1177. }
  1178. if (test_datas.Count > 2)
  1179. {
  1180. sqe_cto_test_data data = test_datas[1];
  1181. data.data_no = dataRow.c1;
  1182. if (dataRow.c2 != null)
  1183. {
  1184. String s = dataRow.c2.ToString();
  1185. DateTime date;
  1186. if (DateTime.TryParse(test.product_time.Value.ToString("yyyy-MM-dd ") + s, out date))
  1187. {
  1188. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1189. }
  1190. }
  1191. if (dataRow.c5 != null && dataRow.c5.Length > 0 && decimal.TryParse(dataRow.c5, out realValuel))
  1192. {
  1193. data.data_value = realValuel;
  1194. }
  1195. else
  1196. {
  1197. data.data_value = null;
  1198. }
  1199. }
  1200. if (test_datas.Count > 3)
  1201. {
  1202. sqe_cto_test_data data = test_datas[1];
  1203. data.data_no = dataRow.c1;
  1204. if (dataRow.c2 != null)
  1205. {
  1206. String s = dataRow.c2.ToString();
  1207. DateTime date;
  1208. if (DateTime.TryParse(test.product_time.Value.ToString("yyyy-MM-dd ") + s, out date))
  1209. {
  1210. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1211. }
  1212. }
  1213. if (dataRow.c6 != null && dataRow.c6.Length > 0 && decimal.TryParse(dataRow.c6, out realValuel))
  1214. {
  1215. data.data_value = realValuel;
  1216. }
  1217. else
  1218. {
  1219. data.data_value = null;
  1220. }
  1221. }
  1222. if (test_datas.Count > 4)
  1223. {
  1224. sqe_cto_test_data data = test_datas[1];
  1225. data.data_no = dataRow.c1;
  1226. if (dataRow.c2 != null)
  1227. {
  1228. String s = dataRow.c2.ToString();
  1229. DateTime date;
  1230. if (DateTime.TryParse(test.product_time.Value.ToString("yyyy-MM-dd ") + s, out date))
  1231. {
  1232. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1233. }
  1234. }
  1235. if (dataRow.c7 != null && dataRow.c7.Length > 0 && decimal.TryParse(dataRow.c7, out realValuel))
  1236. {
  1237. data.data_value = realValuel;
  1238. }
  1239. else
  1240. {
  1241. data.data_value = null;
  1242. }
  1243. }
  1244. if (test_datas.Count > 5)
  1245. {
  1246. sqe_cto_test_data data = test_datas[1];
  1247. data.data_no = dataRow.c1;
  1248. if (dataRow.c2 != null)
  1249. {
  1250. String s = dataRow.c2.ToString();
  1251. DateTime date;
  1252. if (DateTime.TryParse(test.product_time.Value.ToString("yyyy-MM-dd ") + s, out date))
  1253. {
  1254. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1255. }
  1256. }
  1257. if (dataRow.c8 != null && dataRow.c8.Length > 0 && decimal.TryParse(dataRow.c8, out realValuel))
  1258. {
  1259. data.data_value = realValuel;
  1260. }
  1261. else
  1262. {
  1263. data.data_value = null;
  1264. }
  1265. }
  1266. if (test_datas.Count > 6)
  1267. {
  1268. sqe_cto_test_data data = test_datas[1];
  1269. data.data_no = dataRow.c1;
  1270. if (dataRow.c2 != null)
  1271. {
  1272. String s = dataRow.c2.ToString();
  1273. DateTime date;
  1274. if (DateTime.TryParse(test.product_time.Value.ToString("yyyy-MM-dd ") + s, out date))
  1275. {
  1276. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1277. }
  1278. }
  1279. if (dataRow.c9 != null && dataRow.c9.Length > 0 && decimal.TryParse(dataRow.c9, out realValuel))
  1280. {
  1281. data.data_value = realValuel;
  1282. }
  1283. else
  1284. {
  1285. data.data_value = null;
  1286. }
  1287. }
  1288. if (test_datas.Count > 7)
  1289. {
  1290. sqe_cto_test_data data = test_datas[1];
  1291. data.data_no = dataRow.c1;
  1292. if (dataRow.c2 != null)
  1293. {
  1294. String s = dataRow.c2.ToString();
  1295. DateTime date;
  1296. if (DateTime.TryParse(test.product_time.Value.ToString("yyyy-MM-dd ") + s, out date))
  1297. {
  1298. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1299. }
  1300. }
  1301. if (dataRow.c10 != null && dataRow.c10.Length > 0 && decimal.TryParse(dataRow.c10, out realValuel))
  1302. {
  1303. data.data_value = realValuel;
  1304. }
  1305. else
  1306. {
  1307. data.data_value = null;
  1308. }
  1309. }
  1310. if (test_datas.Count > 8)
  1311. {
  1312. sqe_cto_test_data data = test_datas[1];
  1313. data.data_no = dataRow.c1;
  1314. if (dataRow.c2 != null)
  1315. {
  1316. String s = dataRow.c2.ToString();
  1317. DateTime date;
  1318. if (DateTime.TryParse(test.product_time.Value.ToString("yyyy-MM-dd ") + s, out date))
  1319. {
  1320. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1321. }
  1322. }
  1323. if (dataRow.c11 != null && dataRow.c11.Length > 0 && decimal.TryParse(dataRow.c11, out realValuel))
  1324. {
  1325. data.data_value = realValuel;
  1326. }
  1327. else
  1328. {
  1329. data.data_value = null;
  1330. }
  1331. }
  1332. File_data_ToModel_test_data_Add(modelList, test_datas);
  1333. }
  1334. catch (Exception ex)
  1335. {
  1336. WLLog.Error("Excel数据解析_原始数据转换到对象实体的问题:", ex);
  1337. }
  1338. }
  1339. errorMsg = string.Empty;
  1340. return modelList;
  1341. }
  1342. else
  1343. {
  1344. errorMsg = stringBuilder.ToString();
  1345. return null;
  1346. }
  1347. }
  1348. /// <summary>
  1349. /// 将转换的数据插入到返回结果数据集中,处理掉异常数据
  1350. /// </summary>
  1351. /// <param name="dataDest"></param>
  1352. /// <param name="dataSource"></param>
  1353. private void File_data_ToModel_test_data_Add(List<sqe_cto_test_data> dataDest, List<sqe_cto_test_data> dataSource)
  1354. {
  1355. if (dataSource != null && dataSource.Count > 0)
  1356. {
  1357. for (int i = 0; i < dataSource.Count; i++)
  1358. {
  1359. sqe_cto_test_data data = dataSource[i];
  1360. if (data.data_no != null && data.data_no.Length > 0 && data.data_time != null && data.data_value != null)
  1361. {
  1362. dataDest.Add(data);
  1363. }
  1364. }
  1365. }
  1366. }
  1367. #endregion 产品特性
  1368. public string Import_Process_From_Data(int upload_id, string create_by, DateTime create_date, string create_org)
  1369. {
  1370. StringBuilder stringBuilder = new StringBuilder();
  1371. try
  1372. {
  1373. sqe_file_upload sqe_File_Upload = Get_Sqe_file_upload(upload_id);
  1374. List<sqe_file_data> datas = LoadData_file_data(upload_id);
  1375. if (datas == null || datas.Count == 0)
  1376. {
  1377. stringBuilder.AppendLine("导入数据信息不存在!");
  1378. return stringBuilder.ToString();
  1379. }
  1380. //产品过程特性的文件格式校验
  1381. if (datas[0].c1.CompareTo("产品过程特性") != 0)
  1382. {
  1383. stringBuilder.AppendLine("文件不是【产品过程特性】要求的格式");
  1384. return stringBuilder.ToString();
  1385. }
  1386. if (datas[1].c1.CompareTo("生产时间") != 0
  1387. || datas[1].c3.CompareTo("生产班次") != 0
  1388. || datas[1].c5.CompareTo("物料名称") != 0
  1389. || datas[1].c7.CompareTo("物料号") != 0)
  1390. {
  1391. stringBuilder.AppendLine("文件不是【产品过程特性】要求的格式");
  1392. return stringBuilder.ToString();
  1393. }
  1394. if (datas[2].c1.CompareTo("对应原材料批次号") != 0
  1395. || datas[2].c3.CompareTo("原材料使用数量") != 0
  1396. || datas[2].c5.CompareTo("物料批次号") != 0
  1397. || datas[2].c7.CompareTo("物料数量") != 0)
  1398. {
  1399. stringBuilder.AppendLine("文件不是【产品过程特性】要求的格式");
  1400. return stringBuilder.ToString();
  1401. }
  1402. string errorMsg;
  1403. sqe_cto_process test = File_data_ToModel_process(datas, create_by, create_date, create_org, out errorMsg);
  1404. if (errorMsg != null && errorMsg.Length > 0)
  1405. {
  1406. stringBuilder.AppendLine(errorMsg);
  1407. return stringBuilder.ToString();
  1408. }
  1409. _sqe_cto_process.BeginTransaction();
  1410. _sqe_cto_process.Insert(test);
  1411. errorMsg = null;
  1412. List<sqe_cto_process_standard> standards = File_data_ToModel_process_standard(datas, test, create_by, create_date, create_org, out errorMsg);
  1413. if (errorMsg != null && errorMsg.Length > 0)
  1414. {
  1415. _sqe_cto_process.Rollback();
  1416. stringBuilder.AppendLine(errorMsg);
  1417. return stringBuilder.ToString();
  1418. }
  1419. _sqe_cto_process_standard.BeginTransaction();
  1420. _sqe_cto_process_standard.Insert(standards);
  1421. List<sqe_cto_process_data> test_Datas = File_data_ToModel_process_data(datas, test, standards, create_by, create_date, create_org, out errorMsg);
  1422. if (errorMsg != null && errorMsg.Length > 0)
  1423. {
  1424. _sqe_cto_process.Rollback();
  1425. _sqe_cto_process_standard.Rollback();
  1426. stringBuilder.AppendLine(errorMsg);
  1427. return stringBuilder.ToString();
  1428. }
  1429. _sqe_cto_process_data.Insert(test_Datas);
  1430. sqe_File_Upload.item_no = test.item_no;
  1431. sqe_File_Upload.item_name = test.item_name;
  1432. _sqe_file_upload.Update(sqe_File_Upload);
  1433. _sqe_cto_process.CommitTransaction();
  1434. _sqe_cto_process_standard.CommitTransaction();
  1435. }
  1436. catch (Exception ex)
  1437. {
  1438. stringBuilder.Append("数据导入失败!");
  1439. }
  1440. finally
  1441. {
  1442. }
  1443. return stringBuilder.ToString();
  1444. }
  1445. #region 产品过程特性
  1446. 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)
  1447. {
  1448. StringBuilder stringBuilder = new StringBuilder();
  1449. sqe_cto_process model = new sqe_cto_process();
  1450. DateTime timeValue;
  1451. decimal realValuel;
  1452. if (datas != null && datas.Count >= 5)
  1453. {
  1454. try
  1455. {
  1456. model.file_id = datas[0].file_id;
  1457. sqe_file_data data = datas[1];
  1458. if (DateTime.TryParse(data.c2, out timeValue))
  1459. {
  1460. model.product_time = timeValue;
  1461. }
  1462. else
  1463. {
  1464. //model.product_time = DateTime.Parse("2000-01-01");
  1465. model.product_time = DateTime.Now;
  1466. }
  1467. model.shift_no = data.c4;
  1468. model.item_no = data.c6;
  1469. model.item_name = data.c8;
  1470. data = datas[2];
  1471. model.material_batch = data.c2;
  1472. if (decimal.TryParse(data.c4, out realValuel))
  1473. {
  1474. model.material_used = realValuel;
  1475. }
  1476. model.item_batch = data.c6;
  1477. if (decimal.TryParse(data.c8, out realValuel))
  1478. {
  1479. model.item_qty = realValuel;
  1480. }
  1481. data = datas[3];
  1482. model.op_pre = data.c2;
  1483. model.op_pre_batch = data.c4;
  1484. model.op_current = data.c6;
  1485. model.op_batch = data.c8;
  1486. data = datas[4];
  1487. model.device_name = data.c2;
  1488. model.device_no = data.c4;
  1489. if (decimal.TryParse(data.c8, out realValuel))
  1490. {
  1491. model.sampling_number = realValuel;
  1492. }
  1493. }
  1494. catch (Exception ex)
  1495. {
  1496. WLLog.Error("Excel数据解析问题:", ex);
  1497. }
  1498. model.create_by = create_by;
  1499. model.create_date = create_date;
  1500. model.create_org = create_org;
  1501. errorMsg = string.Empty;
  1502. return model;
  1503. }
  1504. else
  1505. {
  1506. errorMsg = stringBuilder.ToString();
  1507. return null;
  1508. }
  1509. }
  1510. 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)
  1511. {
  1512. StringBuilder stringBuilder = new StringBuilder();
  1513. List<sqe_cto_process_standard> modelList = new List<sqe_cto_process_standard>();
  1514. decimal realValuel;
  1515. if (datas != null && datas.Count >= 13)
  1516. {
  1517. try
  1518. {
  1519. //标准的起始位置
  1520. int index = 5;
  1521. sqe_file_data dataRow = datas[index];
  1522. #region 处理尺寸的表头
  1523. if (dataRow.c2 != null && dataRow.c2.Length > 0)
  1524. {
  1525. sqe_cto_process_standard model = new sqe_cto_process_standard();
  1526. model.standard_no = dataRow.c2;
  1527. model.create_by = create_by;
  1528. model.create_date = create_date;
  1529. model.create_org = create_org;
  1530. model.process_id = test.id;
  1531. modelList.Add(model);
  1532. }
  1533. if (dataRow.c3 != null && dataRow.c3.Length > 0)
  1534. {
  1535. sqe_cto_process_standard model = new sqe_cto_process_standard();
  1536. model.standard_no = dataRow.c3;
  1537. model.create_by = create_by;
  1538. model.create_date = create_date;
  1539. model.create_org = create_org;
  1540. model.process_id = test.id;
  1541. modelList.Add(model);
  1542. }
  1543. if (dataRow.c4 != null && dataRow.c4.Length > 0)
  1544. {
  1545. sqe_cto_process_standard model = new sqe_cto_process_standard();
  1546. model.standard_no = dataRow.c4;
  1547. model.create_by = create_by;
  1548. model.create_date = create_date;
  1549. model.create_org = create_org;
  1550. model.process_id = test.id;
  1551. modelList.Add(model);
  1552. }
  1553. if (dataRow.c5 != null && dataRow.c5.Length > 0)
  1554. {
  1555. sqe_cto_process_standard model = new sqe_cto_process_standard();
  1556. model.standard_no = dataRow.c5;
  1557. model.create_by = create_by;
  1558. model.create_date = create_date;
  1559. model.create_org = create_org;
  1560. model.process_id = test.id;
  1561. modelList.Add(model);
  1562. }
  1563. if (dataRow.c6 != null && dataRow.c6.Length > 0)
  1564. {
  1565. sqe_cto_process_standard model = new sqe_cto_process_standard();
  1566. model.standard_no = dataRow.c6;
  1567. model.create_by = create_by;
  1568. model.create_date = create_date;
  1569. model.create_org = create_org;
  1570. model.process_id = test.id;
  1571. modelList.Add(model);
  1572. }
  1573. if (dataRow.c7 != null && dataRow.c7.Length > 0)
  1574. {
  1575. sqe_cto_process_standard model = new sqe_cto_process_standard();
  1576. model.standard_no = dataRow.c7;
  1577. model.create_by = create_by;
  1578. model.create_date = create_date;
  1579. model.create_org = create_org;
  1580. model.process_id = test.id;
  1581. modelList.Add(model);
  1582. }
  1583. if (dataRow.c8 != null && dataRow.c8.Length > 0)
  1584. {
  1585. sqe_cto_process_standard model = new sqe_cto_process_standard();
  1586. model.standard_no = dataRow.c8;
  1587. model.create_by = create_by;
  1588. model.create_date = create_date;
  1589. model.create_org = create_org;
  1590. model.process_id = test.id;
  1591. modelList.Add(model);
  1592. }
  1593. if (dataRow.c9 != null && dataRow.c9.Length > 0)
  1594. {
  1595. sqe_cto_process_standard model = new sqe_cto_process_standard();
  1596. model.standard_no = dataRow.c9;
  1597. model.create_by = create_by;
  1598. model.create_date = create_date;
  1599. model.create_org = create_org;
  1600. model.process_id = test.id;
  1601. modelList.Add(model);
  1602. }
  1603. if (dataRow.c10 != null && dataRow.c10.Length > 0)
  1604. {
  1605. sqe_cto_process_standard model = new sqe_cto_process_standard();
  1606. model.standard_no = dataRow.c10;
  1607. model.create_by = create_by;
  1608. model.create_date = create_date;
  1609. model.create_org = create_org;
  1610. model.process_id = test.id;
  1611. modelList.Add(model);
  1612. }
  1613. #endregion 处理尺寸的表头
  1614. if (modelList.Count > 0)
  1615. {
  1616. sqe_cto_process_standard model = modelList[0];
  1617. dataRow = datas[index + 1];
  1618. if (dataRow.c2 != null && decimal.TryParse(dataRow.c2, out realValuel))
  1619. {
  1620. model.standard_value = realValuel;
  1621. }
  1622. dataRow = datas[index + 2];
  1623. if (dataRow.c2 != null && decimal.TryParse(dataRow.c2, out realValuel))
  1624. {
  1625. model.delta_up = realValuel;
  1626. }
  1627. dataRow = datas[index + 3];
  1628. if (dataRow.c2 != null && decimal.TryParse(dataRow.c2, out realValuel))
  1629. {
  1630. model.delta_down = realValuel;
  1631. }
  1632. dataRow = datas[index + 4];
  1633. if (dataRow.c2 != null && decimal.TryParse(dataRow.c2, out realValuel))
  1634. {
  1635. model.standard_max = realValuel;
  1636. }
  1637. dataRow = datas[index + 5];
  1638. if (dataRow.c2 != null && decimal.TryParse(dataRow.c2, out realValuel))
  1639. {
  1640. model.standard_min = realValuel;
  1641. }
  1642. }
  1643. if (modelList.Count > 1)
  1644. {
  1645. sqe_cto_process_standard model = modelList[1];
  1646. dataRow = datas[index + 1];
  1647. if (dataRow.c3 != null && decimal.TryParse(dataRow.c3, out realValuel))
  1648. {
  1649. model.standard_value = realValuel;
  1650. }
  1651. dataRow = datas[index + 2];
  1652. if (dataRow.c3 != null && decimal.TryParse(dataRow.c3, out realValuel))
  1653. {
  1654. model.delta_up = realValuel;
  1655. }
  1656. dataRow = datas[index + 3];
  1657. if (dataRow.c3 != null && decimal.TryParse(dataRow.c3, out realValuel))
  1658. {
  1659. model.delta_down = realValuel;
  1660. }
  1661. dataRow = datas[index + 4];
  1662. if (dataRow.c3 != null && decimal.TryParse(dataRow.c3, out realValuel))
  1663. {
  1664. model.standard_max = realValuel;
  1665. }
  1666. dataRow = datas[index + 5];
  1667. if (dataRow.c3 != null && decimal.TryParse(dataRow.c3, out realValuel))
  1668. {
  1669. model.standard_min = realValuel;
  1670. }
  1671. }
  1672. if (modelList.Count > 2)
  1673. {
  1674. sqe_cto_process_standard model = modelList[2];
  1675. dataRow = datas[index + 1];
  1676. if (dataRow.c4 != null && decimal.TryParse(dataRow.c4, out realValuel))
  1677. {
  1678. model.standard_value = realValuel;
  1679. }
  1680. dataRow = datas[index + 2];
  1681. if (dataRow.c4 != null && decimal.TryParse(dataRow.c4, out realValuel))
  1682. {
  1683. model.delta_up = realValuel;
  1684. }
  1685. dataRow = datas[index + 3];
  1686. if (dataRow.c4 != null && decimal.TryParse(dataRow.c4, out realValuel))
  1687. {
  1688. model.delta_down = realValuel;
  1689. }
  1690. dataRow = datas[index + 4];
  1691. if (dataRow.c4 != null && decimal.TryParse(dataRow.c4, out realValuel))
  1692. {
  1693. model.standard_max = realValuel;
  1694. }
  1695. dataRow = datas[index + 5];
  1696. if (dataRow.c4 != null && decimal.TryParse(dataRow.c4, out realValuel))
  1697. {
  1698. model.standard_min = realValuel;
  1699. }
  1700. }
  1701. if (modelList.Count > 3)
  1702. {
  1703. sqe_cto_process_standard model = modelList[3];
  1704. dataRow = datas[index + 1];
  1705. if (dataRow.c5 != null && decimal.TryParse(dataRow.c5, out realValuel))
  1706. {
  1707. model.standard_value = realValuel;
  1708. }
  1709. dataRow = datas[index + 2];
  1710. if (dataRow.c5 != null && decimal.TryParse(dataRow.c5, out realValuel))
  1711. {
  1712. model.delta_up = realValuel;
  1713. }
  1714. dataRow = datas[index + 3];
  1715. if (dataRow.c5 != null && decimal.TryParse(dataRow.c5, out realValuel))
  1716. {
  1717. model.delta_down = realValuel;
  1718. }
  1719. dataRow = datas[index + 4];
  1720. if (dataRow.c5 != null && decimal.TryParse(dataRow.c5, out realValuel))
  1721. {
  1722. model.standard_max = realValuel;
  1723. }
  1724. dataRow = datas[index + 5];
  1725. if (dataRow.c5 != null && decimal.TryParse(dataRow.c5, out realValuel))
  1726. {
  1727. model.standard_min = realValuel;
  1728. }
  1729. }
  1730. if (modelList.Count > 4)
  1731. {
  1732. sqe_cto_process_standard model = modelList[4];
  1733. dataRow = datas[index + 1];
  1734. if (dataRow.c6 != null && decimal.TryParse(dataRow.c6, out realValuel))
  1735. {
  1736. model.standard_value = realValuel;
  1737. }
  1738. dataRow = datas[index + 2];
  1739. if (dataRow.c6 != null && decimal.TryParse(dataRow.c6, out realValuel))
  1740. {
  1741. model.delta_up = realValuel;
  1742. }
  1743. dataRow = datas[index + 3];
  1744. if (dataRow.c6 != null && decimal.TryParse(dataRow.c6, out realValuel))
  1745. {
  1746. model.delta_down = realValuel;
  1747. }
  1748. dataRow = datas[index + 4];
  1749. if (dataRow.c6 != null && decimal.TryParse(dataRow.c6, out realValuel))
  1750. {
  1751. model.standard_max = realValuel;
  1752. }
  1753. dataRow = datas[index + 5];
  1754. if (dataRow.c6 != null && decimal.TryParse(dataRow.c6, out realValuel))
  1755. {
  1756. model.standard_min = realValuel;
  1757. }
  1758. }
  1759. if (modelList.Count > 5)
  1760. {
  1761. sqe_cto_process_standard model = modelList[5];
  1762. dataRow = datas[index + 1];
  1763. if (dataRow.c7 != null && decimal.TryParse(dataRow.c7, out realValuel))
  1764. {
  1765. model.standard_value = realValuel;
  1766. }
  1767. dataRow = datas[index + 2];
  1768. if (dataRow.c7 != null && decimal.TryParse(dataRow.c7, out realValuel))
  1769. {
  1770. model.delta_up = realValuel;
  1771. }
  1772. dataRow = datas[index + 3];
  1773. if (dataRow.c7 != null && decimal.TryParse(dataRow.c7, out realValuel))
  1774. {
  1775. model.delta_down = realValuel;
  1776. }
  1777. dataRow = datas[index + 4];
  1778. if (dataRow.c7 != null && decimal.TryParse(dataRow.c7, out realValuel))
  1779. {
  1780. model.standard_max = realValuel;
  1781. }
  1782. dataRow = datas[index + 5];
  1783. if (dataRow.c7 != null && decimal.TryParse(dataRow.c7, out realValuel))
  1784. {
  1785. model.standard_min = realValuel;
  1786. }
  1787. }
  1788. if (modelList.Count > 6)
  1789. {
  1790. sqe_cto_process_standard model = modelList[6];
  1791. dataRow = datas[index + 1];
  1792. if (dataRow.c8 != null && decimal.TryParse(dataRow.c8, out realValuel))
  1793. {
  1794. model.standard_value = realValuel;
  1795. }
  1796. dataRow = datas[index + 2];
  1797. if (dataRow.c8 != null && decimal.TryParse(dataRow.c8, out realValuel))
  1798. {
  1799. model.delta_up = realValuel;
  1800. }
  1801. dataRow = datas[index + 3];
  1802. if (dataRow.c8 != null && decimal.TryParse(dataRow.c8, out realValuel))
  1803. {
  1804. model.delta_down = realValuel;
  1805. }
  1806. dataRow = datas[index + 4];
  1807. if (dataRow.c8 != null && decimal.TryParse(dataRow.c8, out realValuel))
  1808. {
  1809. model.standard_max = realValuel;
  1810. }
  1811. dataRow = datas[index + 5];
  1812. if (dataRow.c8 != null && decimal.TryParse(dataRow.c8, out realValuel))
  1813. {
  1814. model.standard_min = realValuel;
  1815. }
  1816. }
  1817. if (modelList.Count > 7)
  1818. {
  1819. sqe_cto_process_standard model = modelList[7];
  1820. dataRow = datas[index + 1];
  1821. if (dataRow.c9 != null && decimal.TryParse(dataRow.c9, out realValuel))
  1822. {
  1823. model.standard_value = realValuel;
  1824. }
  1825. dataRow = datas[index + 2];
  1826. if (dataRow.c9 != null && decimal.TryParse(dataRow.c9, out realValuel))
  1827. {
  1828. model.delta_up = realValuel;
  1829. }
  1830. dataRow = datas[index + 3];
  1831. if (dataRow.c9 != null && decimal.TryParse(dataRow.c9, out realValuel))
  1832. {
  1833. model.delta_down = realValuel;
  1834. }
  1835. dataRow = datas[index + 4];
  1836. if (dataRow.c9 != null && decimal.TryParse(dataRow.c9, out realValuel))
  1837. {
  1838. model.standard_max = realValuel;
  1839. }
  1840. dataRow = datas[index + 5];
  1841. if (dataRow.c9 != null && decimal.TryParse(dataRow.c9, out realValuel))
  1842. {
  1843. model.standard_min = realValuel;
  1844. }
  1845. }
  1846. if (modelList.Count > 8)
  1847. {
  1848. sqe_cto_process_standard model = modelList[8];
  1849. dataRow = datas[index + 1];
  1850. if (dataRow.c10 != null && decimal.TryParse(dataRow.c10, out realValuel))
  1851. {
  1852. model.standard_value = realValuel;
  1853. }
  1854. dataRow = datas[index + 2];
  1855. if (dataRow.c10 != null && decimal.TryParse(dataRow.c10, out realValuel))
  1856. {
  1857. model.delta_up = realValuel;
  1858. }
  1859. dataRow = datas[index + 3];
  1860. if (dataRow.c10 != null && decimal.TryParse(dataRow.c10, out realValuel))
  1861. {
  1862. model.delta_down = realValuel;
  1863. }
  1864. dataRow = datas[index + 4];
  1865. if (dataRow.c10 != null && decimal.TryParse(dataRow.c10, out realValuel))
  1866. {
  1867. model.standard_max = realValuel;
  1868. }
  1869. dataRow = datas[index + 5];
  1870. if (dataRow.c10 != null && decimal.TryParse(dataRow.c10, out realValuel))
  1871. {
  1872. model.standard_min = realValuel;
  1873. }
  1874. }
  1875. }
  1876. catch (Exception ex)
  1877. {
  1878. WLLog.Error("Excel数据解析问题:", ex);
  1879. }
  1880. errorMsg = stringBuilder.ToString();
  1881. return modelList;
  1882. }
  1883. else
  1884. {
  1885. errorMsg = stringBuilder.ToString();
  1886. return null;
  1887. }
  1888. }
  1889. 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)
  1890. {
  1891. StringBuilder stringBuilder = new StringBuilder();
  1892. List<sqe_cto_process_data> modelList = new List<sqe_cto_process_data>();
  1893. decimal realValuel;
  1894. if (datas != null && datas.Count >= 12)
  1895. {
  1896. for (int i = 11; i < datas.Count; i++)
  1897. {
  1898. sqe_file_data dataRow = datas[i];
  1899. if ((dataRow.c1 == null || dataRow.c1.Length == 0 || dataRow.c1 == "0") && (dataRow.c2 == null || dataRow.c2.Length == 0))
  1900. {
  1901. break;
  1902. }
  1903. //初始化每一层的数据集合
  1904. List<sqe_cto_process_data> test_datas = new List<sqe_cto_process_data>();
  1905. for (int j = 0; j < standards.Count; j++)
  1906. {
  1907. sqe_cto_process_data data = new sqe_cto_process_data();
  1908. data.process_id = standards[j].process_id;
  1909. data.standard_id = standards[j].id;
  1910. data.create_by = create_by;
  1911. data.create_date = create_date;
  1912. data.create_org = create_org;
  1913. test_datas.Add(data);
  1914. }
  1915. try
  1916. {
  1917. //将每一个检测标准的值从记录行中取出来
  1918. if (test_datas.Count > 0)
  1919. {
  1920. sqe_cto_process_data data = test_datas[0];
  1921. if (dataRow.c1 != null)
  1922. {
  1923. String s = dataRow.c1.ToString();
  1924. if (s != null && s.Length > 9)
  1925. {
  1926. s = s.Substring(s.Length - 9);
  1927. }
  1928. DateTime date;
  1929. if (DateTime.TryParse(test.product_time.Value.ToString("yyyy-MM-dd ") + s, out date))
  1930. {
  1931. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1932. }
  1933. }
  1934. if (dataRow.c2 != null && dataRow.c2.Length > 0 && decimal.TryParse(dataRow.c2, out realValuel))
  1935. {
  1936. data.data_value = realValuel;
  1937. }
  1938. else
  1939. {
  1940. data.data_value = null;
  1941. }
  1942. }
  1943. if (test_datas.Count > 1)
  1944. {
  1945. sqe_cto_process_data data = test_datas[1];
  1946. if (dataRow.c1 != null)
  1947. {
  1948. String s = dataRow.c1.ToString();
  1949. if (s != null && s.Length > 9)
  1950. {
  1951. s = s.Substring(s.Length - 9);
  1952. }
  1953. DateTime date;
  1954. if (DateTime.TryParse(test.product_time.Value.ToString("yyyy-MM-dd ") + s, out date))
  1955. {
  1956. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1957. }
  1958. }
  1959. if (dataRow.c3 != null && dataRow.c3.Length > 0 && decimal.TryParse(dataRow.c3, out realValuel))
  1960. {
  1961. data.data_value = realValuel;
  1962. }
  1963. else
  1964. {
  1965. data.data_value = null;
  1966. }
  1967. }
  1968. if (test_datas.Count > 2)
  1969. {
  1970. sqe_cto_process_data data = test_datas[2];
  1971. if (dataRow.c1 != null)
  1972. {
  1973. String s = dataRow.c1.ToString();
  1974. if (s != null && s.Length > 9)
  1975. {
  1976. s = s.Substring(s.Length - 9);
  1977. }
  1978. DateTime date;
  1979. if (DateTime.TryParse(test.product_time.Value.ToString("yyyy-MM-dd ") + s, out date))
  1980. {
  1981. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  1982. }
  1983. }
  1984. if (dataRow.c4 != null && dataRow.c4.Length > 0 && decimal.TryParse(dataRow.c4, out realValuel))
  1985. {
  1986. data.data_value = realValuel;
  1987. }
  1988. else
  1989. {
  1990. data.data_value = null;
  1991. }
  1992. }
  1993. if (test_datas.Count > 3)
  1994. {
  1995. sqe_cto_process_data data = test_datas[3];
  1996. if (dataRow.c1 != null)
  1997. {
  1998. String s = dataRow.c1.ToString();
  1999. if (s != null && s.Length > 9)
  2000. {
  2001. s = s.Substring(s.Length - 9);
  2002. }
  2003. DateTime date;
  2004. if (DateTime.TryParse(test.product_time.Value.ToString("yyyy-MM-dd ") + s, out date))
  2005. {
  2006. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  2007. }
  2008. }
  2009. if (dataRow.c5 != null && dataRow.c5.Length > 0 && decimal.TryParse(dataRow.c5, out realValuel))
  2010. {
  2011. data.data_value = realValuel;
  2012. }
  2013. else
  2014. {
  2015. data.data_value = null;
  2016. }
  2017. }
  2018. if (test_datas.Count > 4)
  2019. {
  2020. sqe_cto_process_data data = test_datas[4];
  2021. if (dataRow.c1 != null)
  2022. {
  2023. String s = dataRow.c1.ToString();
  2024. if (s != null && s.Length > 9)
  2025. {
  2026. s = s.Substring(s.Length - 9);
  2027. }
  2028. DateTime date;
  2029. if (DateTime.TryParse(test.product_time.Value.ToString("yyyy-MM-dd ") + s, out date))
  2030. {
  2031. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  2032. }
  2033. }
  2034. if (dataRow.c6 != null && dataRow.c6.Length > 0 && decimal.TryParse(dataRow.c6, out realValuel))
  2035. {
  2036. data.data_value = realValuel;
  2037. }
  2038. else
  2039. {
  2040. data.data_value = null;
  2041. }
  2042. }
  2043. if (test_datas.Count > 5)
  2044. {
  2045. sqe_cto_process_data data = test_datas[5];
  2046. if (dataRow.c1 != null)
  2047. {
  2048. String s = dataRow.c1.ToString();
  2049. if (s != null && s.Length > 9)
  2050. {
  2051. s = s.Substring(s.Length - 9);
  2052. }
  2053. DateTime date;
  2054. if (DateTime.TryParse(test.product_time.Value.ToString("yyyy-MM-dd ") + s, out date))
  2055. {
  2056. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  2057. }
  2058. }
  2059. if (dataRow.c7 != null && dataRow.c7.Length > 0 && decimal.TryParse(dataRow.c7, out realValuel))
  2060. {
  2061. data.data_value = realValuel;
  2062. }
  2063. else
  2064. {
  2065. data.data_value = null;
  2066. }
  2067. }
  2068. if (test_datas.Count > 6)
  2069. {
  2070. sqe_cto_process_data data = test_datas[6];
  2071. if (dataRow.c1 != null)
  2072. {
  2073. String s = dataRow.c1.ToString();
  2074. if (s != null && s.Length > 9)
  2075. {
  2076. s = s.Substring(s.Length - 9);
  2077. }
  2078. DateTime date;
  2079. if (DateTime.TryParse(test.product_time.Value.ToString("yyyy-MM-dd ") + s, out date))
  2080. {
  2081. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  2082. }
  2083. }
  2084. if (dataRow.c8 != null && dataRow.c8.Length > 0 && decimal.TryParse(dataRow.c8, out realValuel))
  2085. {
  2086. data.data_value = realValuel;
  2087. }
  2088. else
  2089. {
  2090. data.data_value = null;
  2091. }
  2092. }
  2093. if (test_datas.Count > 7)
  2094. {
  2095. sqe_cto_process_data data = test_datas[7];
  2096. if (dataRow.c1 != null)
  2097. {
  2098. String s = dataRow.c1.ToString();
  2099. if (s != null && s.Length > 9)
  2100. {
  2101. s = s.Substring(s.Length - 9);
  2102. }
  2103. DateTime date;
  2104. if (DateTime.TryParse(test.product_time.Value.ToString("yyyy-MM-dd ") + s, out date))
  2105. {
  2106. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  2107. }
  2108. }
  2109. if (dataRow.c9 != null && dataRow.c9.Length > 0 && decimal.TryParse(dataRow.c9, out realValuel))
  2110. {
  2111. data.data_value = realValuel;
  2112. }
  2113. else
  2114. {
  2115. data.data_value = null;
  2116. }
  2117. }
  2118. if (test_datas.Count > 8)
  2119. {
  2120. sqe_cto_process_data data = test_datas[8];
  2121. if (dataRow.c1 != null)
  2122. {
  2123. String s = dataRow.c1.ToString();
  2124. if (s != null && s.Length > 9)
  2125. {
  2126. s = s.Substring(s.Length - 9);
  2127. }
  2128. DateTime date;
  2129. if (DateTime.TryParse(test.product_time.Value.ToString("yyyy-MM-dd ") + s, out date))
  2130. {
  2131. data.data_time = date.ToString("yyyy-MM-dd HH:mm");
  2132. }
  2133. }
  2134. if (dataRow.c10 != null && dataRow.c10.Length > 0 && decimal.TryParse(dataRow.c10, out realValuel))
  2135. {
  2136. data.data_value = realValuel;
  2137. }
  2138. else
  2139. {
  2140. data.data_value = null;
  2141. }
  2142. }
  2143. File_data_ToModel_process_data_Add(modelList, test_datas);
  2144. }
  2145. catch (Exception ex)
  2146. {
  2147. WLLog.Error("Excel数据解析_原始数据转换到对象实体的问题:", ex);
  2148. }
  2149. }
  2150. errorMsg = string.Empty;
  2151. return modelList;
  2152. }
  2153. else
  2154. {
  2155. errorMsg = stringBuilder.ToString();
  2156. return null;
  2157. }
  2158. }
  2159. /// <summary>
  2160. /// 将转换的数据插入到返回结果数据集中,处理掉异常数据
  2161. /// </summary>
  2162. /// <param name="dataDest"></param>
  2163. /// <param name="dataSource"></param>
  2164. private void File_data_ToModel_process_data_Add(List<sqe_cto_process_data> dataDest, List<sqe_cto_process_data> dataSource)
  2165. {
  2166. if (dataSource != null && dataSource.Count > 0)
  2167. {
  2168. for (int i = 0; i < dataSource.Count; i++)
  2169. {
  2170. sqe_cto_process_data data = dataSource[i];
  2171. if (data.data_time != null && data.data_value != null)
  2172. {
  2173. dataDest.Add(data);
  2174. }
  2175. }
  2176. }
  2177. }
  2178. #endregion 产品过程特性
  2179. /// <summary>
  2180. /// 依据导入的数据行,生成OP的表头、检验标准和数据行
  2181. /// </summary>
  2182. /// <param name="upload_id"></param>
  2183. /// <param name="create_by"></param>
  2184. /// <param name="create_date"></param>
  2185. /// <param name="create_org"></param>
  2186. /// <returns></returns>
  2187. public string Import_Op_From_Data(int upload_id, string create_by, DateTime create_date, string create_org)
  2188. {
  2189. StringBuilder stringBuilder = new StringBuilder();
  2190. try
  2191. {
  2192. sqe_file_upload sqe_File_Upload = Get_Sqe_file_upload(upload_id);
  2193. List<sqe_file_data> datas = LoadData_file_data(upload_id);
  2194. if (datas == null || datas.Count == 0)
  2195. {
  2196. stringBuilder.AppendLine("导入数据信息不存在!");
  2197. return stringBuilder.ToString();
  2198. }
  2199. //出货检验记录文件格式校验
  2200. if (datas[0].c1.CompareTo("供应商代码") != 0
  2201. || datas[0].c2.CompareTo("日期") != 0
  2202. || datas[0].c3.CompareTo("客户料号") != 0
  2203. || datas[0].c4.CompareTo("物料名称") != 0
  2204. || datas[0].c5.CompareTo("批次号") != 0
  2205. || datas[0].c6.CompareTo("工序") != 0
  2206. || datas[0].c7.CompareTo("总数量") != 0
  2207. || datas[0].c8.CompareTo("良品数") != 0
  2208. || datas[0].c9.CompareTo("不良品数") != 0
  2209. || datas[0].c10.CompareTo("合格率") != 0
  2210. || datas[0].c11.CompareTo("不良率") != 0)
  2211. {
  2212. stringBuilder.AppendLine("文件不是【全检工序】要求的格式");
  2213. return stringBuilder.ToString();
  2214. }
  2215. string errorMsg;
  2216. sqe_op test = File_data_ToModel_op(datas, create_by, create_date, create_org, out errorMsg);
  2217. if (errorMsg != null && errorMsg.Length > 0)
  2218. {
  2219. stringBuilder.AppendLine(errorMsg);
  2220. return stringBuilder.ToString();
  2221. }
  2222. _sqe_op.BeginTransaction();
  2223. _sqe_op.Insert(test);
  2224. errorMsg = null;
  2225. List<sqe_op_data> standards = File_data_ToModel_op_data(datas, test, create_by, create_date, create_org, out errorMsg);
  2226. if (errorMsg != null && errorMsg.Length > 0)
  2227. {
  2228. _sqe_op.Rollback();
  2229. stringBuilder.AppendLine(errorMsg);
  2230. return stringBuilder.ToString();
  2231. }
  2232. _sqe_op_data.BeginTransaction();
  2233. _sqe_op_data.Insert(standards);
  2234. List<sqe_op_data_detail> test_Datas = File_data_ToModel_op_data_detail(datas, test, standards, create_by, create_date, create_org, out errorMsg);
  2235. if (errorMsg != null && errorMsg.Length > 0)
  2236. {
  2237. _sqe_op.Rollback();
  2238. _sqe_op_data.Rollback();
  2239. stringBuilder.AppendLine(errorMsg);
  2240. return stringBuilder.ToString();
  2241. }
  2242. _sqe_op_data_detail.Insert(test_Datas);
  2243. sqe_File_Upload.item_no = standards[0].item_no;
  2244. sqe_File_Upload.item_name = standards[0].item_name;
  2245. _sqe_file_upload.Update(sqe_File_Upload);
  2246. _sqe_op.CommitTransaction();
  2247. _sqe_op_data.CommitTransaction();
  2248. }
  2249. catch (Exception ex)
  2250. {
  2251. stringBuilder.Append("数据导入失败!");
  2252. }
  2253. finally
  2254. {
  2255. }
  2256. return stringBuilder.ToString();
  2257. }
  2258. #region OP
  2259. /// <summary>
  2260. /// 从原始数据行生成OP的表头数据
  2261. /// </summary>
  2262. /// <param name="datas"></param>
  2263. /// <param name="create_by"></param>
  2264. /// <param name="create_date"></param>
  2265. /// <param name="create_org"></param>
  2266. /// <param name="errorMsg"></param>
  2267. /// <returns></returns>
  2268. public sqe_op File_data_ToModel_op(List<sqe_file_data> datas, string create_by, DateTime create_date, string create_org, out string errorMsg)
  2269. {
  2270. sqe_op model = new sqe_op();
  2271. model.create_by = create_by;
  2272. model.create_date = create_date;
  2273. model.create_org = create_org;
  2274. if (datas != null && datas.Count > 0)
  2275. {
  2276. model.file_id = datas[0].file_id;
  2277. }
  2278. errorMsg = string.Empty;
  2279. errorMsg = "";
  2280. return model;
  2281. }
  2282. /// <summary>
  2283. /// 从原始数据行生成OP的检验标准
  2284. /// </summary>
  2285. /// <param name="datas"></param>
  2286. /// <param name="test"></param>
  2287. /// <param name="create_by"></param>
  2288. /// <param name="create_date"></param>
  2289. /// <param name="create_org"></param>
  2290. /// <param name="errorMsg"></param>
  2291. /// <returns></returns>
  2292. 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)
  2293. {
  2294. StringBuilder stringBuilder = new StringBuilder();
  2295. List<sqe_op_data> modelList = new List<sqe_op_data>();
  2296. decimal realValuel;
  2297. if (datas != null && datas.Count > 1)
  2298. {
  2299. for (int i = 1; i < datas.Count; i++)
  2300. {
  2301. sqe_op_data model = new sqe_op_data();
  2302. model.op_id = test.id;
  2303. sqe_file_data dataRow = datas[i];
  2304. if ((dataRow.c1 == null || dataRow.c1.Length == 0) && (dataRow.c2 == null || dataRow.c2.Length == 0))
  2305. {
  2306. break;
  2307. }
  2308. model.supp_no = dataRow.c1;
  2309. DateTime dt;
  2310. int dateLength;
  2311. if (DateTime.TryParse(dataRow.c2, out dt))
  2312. {
  2313. model.op_time = dt;
  2314. }
  2315. else
  2316. {
  2317. if (int.TryParse(dataRow.c2, out dateLength))
  2318. {
  2319. dt = DateTime.Parse("1900-01-01");
  2320. model.op_time = dt.AddDays(dateLength - 2);
  2321. }
  2322. }
  2323. //model.op_time = DateTime.Parse(dataRow.c2);
  2324. model.item_no = dataRow.c3;
  2325. model.item_name = dataRow.c4;
  2326. model.batch_no = dataRow.c5;
  2327. model.op_no = dataRow.c6;
  2328. Object obj = GetFieldValue(dataRow, "c7");
  2329. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2330. {
  2331. model.qty_all = realValuel;
  2332. }
  2333. obj = GetFieldValue(dataRow, "c8");
  2334. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2335. {
  2336. model.qty_ok = realValuel;
  2337. }
  2338. obj = GetFieldValue(dataRow, "c9");
  2339. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2340. {
  2341. model.qty_error = realValuel;
  2342. }
  2343. obj = GetFieldValue(dataRow, "c10");
  2344. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2345. {
  2346. model.percent_ok = realValuel;
  2347. }
  2348. obj = GetFieldValue(dataRow, "c11");
  2349. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2350. {
  2351. model.percent_error = realValuel;
  2352. }
  2353. //model.op_time = DateTime.Now;
  2354. model.create_by = create_by;
  2355. model.create_date = create_date;
  2356. model.create_org = create_org;
  2357. modelList.Add(model);
  2358. }
  2359. }
  2360. errorMsg = stringBuilder.ToString();
  2361. return modelList;
  2362. }
  2363. /// <summary>
  2364. /// 从原始数据行生成OP的数据
  2365. /// </summary>
  2366. /// <param name="datas"></param>
  2367. /// <param name="test"></param>
  2368. /// <param name="standards"></param>
  2369. /// <param name="create_by"></param>
  2370. /// <param name="create_date"></param>
  2371. /// <param name="create_org"></param>
  2372. /// <param name="errorMsg"></param>
  2373. /// <returns></returns>
  2374. 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)
  2375. {
  2376. StringBuilder stringBuilder = new StringBuilder();
  2377. List<sqe_op_data_detail> modelList = new List<sqe_op_data_detail>();
  2378. decimal realValuel;
  2379. if (datas != null && datas.Count > 1)
  2380. {
  2381. for (int i = 1; i < datas.Count && i - 1 < standards.Count; i++)
  2382. {
  2383. sqe_file_data dataRow = datas[i];
  2384. List<sqe_op_data_detail> testDatas = new List<sqe_op_data_detail>();
  2385. for (int j = 12; j < 50; j += 4)
  2386. {
  2387. Object obj = GetFieldValue(dataRow, "c" + j.ToString());
  2388. if (obj != null && obj.ToString().Length > 0)
  2389. {
  2390. sqe_op_data_detail data = new sqe_op_data_detail();
  2391. data.op_id = standards[i - 1].op_id;
  2392. data.op_data_id = standards[i - 1].id;
  2393. data.bad_type = obj.ToString();
  2394. obj = GetFieldValue(dataRow, "c" + (j + 1).ToString());
  2395. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2396. {
  2397. data.bad_qty = realValuel;
  2398. }
  2399. obj = GetFieldValue(dataRow, "c" + (j + 2).ToString());
  2400. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2401. {
  2402. data.percent_bad_all = realValuel;
  2403. }
  2404. obj = GetFieldValue(dataRow, "c" + (j + 3).ToString());
  2405. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2406. {
  2407. data.percent_bad = realValuel;
  2408. }
  2409. data.create_by = create_by;
  2410. data.create_date = create_date;
  2411. data.create_org = create_org;
  2412. testDatas.Add(data);
  2413. }
  2414. }
  2415. File_data_ToModel_op_data_detail_Add(modelList, testDatas);
  2416. }
  2417. errorMsg = string.Empty;
  2418. return modelList;
  2419. }
  2420. else
  2421. {
  2422. errorMsg = stringBuilder.ToString();
  2423. return null;
  2424. }
  2425. }
  2426. /// <summary>
  2427. /// 将转换的数据插入到返回结果数据集中,处理掉异常数据
  2428. /// </summary>
  2429. /// <param name="dataDest"></param>
  2430. /// <param name="dataSource"></param>
  2431. private void File_data_ToModel_op_data_detail_Add(List<sqe_op_data_detail> dataDest, List<sqe_op_data_detail> dataSource)
  2432. {
  2433. if (dataSource != null && dataSource.Count > 0)
  2434. {
  2435. for (int i = 0; i < dataSource.Count; i++)
  2436. {
  2437. sqe_op_data_detail data = dataSource[i];
  2438. if (data.bad_type != null && data.bad_type.Length > 0 && data.bad_qty != null)
  2439. {
  2440. dataDest.Add(data);
  2441. }
  2442. }
  2443. }
  2444. }
  2445. #endregion OP
  2446. /// <summary>
  2447. /// 依据导入的数据行,生成FPY的表头、检验标准和数据行
  2448. /// </summary>
  2449. /// <param name="upload_id"></param>
  2450. /// <param name="create_by"></param>
  2451. /// <param name="create_date"></param>
  2452. /// <param name="create_org"></param>
  2453. /// <returns></returns>
  2454. public string Import_Fpy_From_Data(int upload_id, string create_by, DateTime create_date, string create_org)
  2455. {
  2456. StringBuilder stringBuilder = new StringBuilder();
  2457. try
  2458. {
  2459. sqe_file_upload sqe_File_Upload = Get_Sqe_file_upload(upload_id);
  2460. List<sqe_file_data> datas = LoadData_file_data(upload_id);
  2461. if (datas == null || datas.Count == 0)
  2462. {
  2463. stringBuilder.AppendLine("导入数据信息不存在!");
  2464. return stringBuilder.ToString();
  2465. }
  2466. //FPY的文件格式校验
  2467. //if (datas[0].c1.CompareTo("一、供应商上传报表模版") != 0)
  2468. //{
  2469. // stringBuilder.AppendLine("文件不是【FPY】要求的格式");
  2470. // return stringBuilder.ToString();
  2471. //}
  2472. if (datas[0].c1.CompareTo("生产各工序良率统计报表") != 0)
  2473. {
  2474. stringBuilder.AppendLine("文件不是【FPY】要求的格式");
  2475. return stringBuilder.ToString();
  2476. }
  2477. if (datas[1].c1.CompareTo("NO") != 0
  2478. || datas[1].c2.CompareTo("日期") != 0
  2479. || datas[1].c3.CompareTo("物料号") != 0
  2480. || datas[1].c4.CompareTo("物料名称") != 0
  2481. || datas[1].c5.CompareTo("工序") != 0
  2482. || datas[1].c6.CompareTo("投入数") != 0
  2483. || datas[1].c7.CompareTo("不良数") != 0
  2484. || datas[1].c8.CompareTo("良品率") != 0)
  2485. {
  2486. stringBuilder.AppendLine("文件不是【FPY】要求的格式");
  2487. return stringBuilder.ToString();
  2488. }
  2489. //if (datas[2].c1.CompareTo("对应原材料批次号") != 0
  2490. // || datas[2].c3.CompareTo("原材料使用数量") != 0
  2491. // || datas[2].c5.CompareTo("物料批次号") != 0
  2492. // || datas[2].c7.CompareTo("物料数量") != 0)
  2493. //{
  2494. // stringBuilder.AppendLine("文件不是【FPY】要求的格式式");
  2495. // return stringBuilder.ToString();
  2496. //}
  2497. string errorMsg;
  2498. sqe_fpy test = File_data_ToModel_fpy(datas, create_by, create_date, create_org, out errorMsg);
  2499. if (errorMsg != null && errorMsg.Length > 0)
  2500. {
  2501. stringBuilder.AppendLine(errorMsg);
  2502. return stringBuilder.ToString();
  2503. }
  2504. _sqe_fpy.BeginTransaction();
  2505. _sqe_fpy.Insert(test);
  2506. errorMsg = null;
  2507. List<sqe_fpy_data> standards = File_data_ToModel_fpy_data(datas, test, create_by, create_date, create_org, out errorMsg);
  2508. if (errorMsg != null && errorMsg.Length > 0)
  2509. {
  2510. _sqe_fpy.Rollback();
  2511. stringBuilder.AppendLine(errorMsg);
  2512. return stringBuilder.ToString();
  2513. }
  2514. _sqe_fpy_data.BeginTransaction();
  2515. _sqe_fpy_data.Insert(standards);
  2516. sqe_File_Upload.item_no = standards[0].item_no;
  2517. sqe_File_Upload.item_name = standards[0].item_name;
  2518. _sqe_file_upload.Update(sqe_File_Upload);
  2519. _sqe_fpy.CommitTransaction();
  2520. _sqe_fpy_data.CommitTransaction();
  2521. }
  2522. catch (Exception ex)
  2523. {
  2524. stringBuilder.Append("数据导入失败!");
  2525. }
  2526. finally
  2527. {
  2528. }
  2529. return stringBuilder.ToString();
  2530. }
  2531. #region FPY
  2532. /// <summary>
  2533. /// 从原始数据行生成FPY的表头数据
  2534. /// </summary>
  2535. /// <param name="datas"></param>
  2536. /// <param name="create_by"></param>
  2537. /// <param name="create_date"></param>
  2538. /// <param name="create_org"></param>
  2539. /// <param name="errorMsg"></param>
  2540. /// <returns></returns>
  2541. public sqe_fpy File_data_ToModel_fpy(List<sqe_file_data> datas, string create_by, DateTime create_date, string create_org, out string errorMsg)
  2542. {
  2543. sqe_fpy model = new sqe_fpy();
  2544. model.create_by = create_by;
  2545. model.create_date = create_date;
  2546. model.create_org = create_org;
  2547. if (datas != null && datas.Count > 0)
  2548. {
  2549. model.file_id = datas[0].file_id;
  2550. }
  2551. errorMsg = string.Empty;
  2552. errorMsg = "";
  2553. return model;
  2554. }
  2555. /// <summary>
  2556. /// 从原始数据行生成FPY的检验标准
  2557. /// </summary>
  2558. /// <param name="datas"></param>
  2559. /// <param name="test"></param>
  2560. /// <param name="create_by"></param>
  2561. /// <param name="create_date"></param>
  2562. /// <param name="create_org"></param>
  2563. /// <param name="errorMsg"></param>
  2564. /// <returns></returns>
  2565. 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)
  2566. {
  2567. StringBuilder stringBuilder = new StringBuilder();
  2568. List<sqe_fpy_data> modelList = new List<sqe_fpy_data>();
  2569. decimal realValuel;
  2570. if (datas != null && datas.Count > 2)
  2571. {
  2572. for (int i = 2; i < datas.Count; i++)
  2573. {
  2574. sqe_fpy_data model = new sqe_fpy_data();
  2575. sqe_file_data dataRow = datas[i];
  2576. if ((dataRow.c1 == null || dataRow.c1.Length == 0) && (dataRow.c3 == null || dataRow.c3.Length == 0))
  2577. {
  2578. break;
  2579. }
  2580. int dateLength;
  2581. DateTime dt;
  2582. if (DateTime.TryParse(dataRow.c2, out dt))
  2583. {
  2584. model.op_time = dt;
  2585. }
  2586. else
  2587. {
  2588. if (int.TryParse(dataRow.c2, out dateLength))
  2589. {
  2590. dt = DateTime.Parse("1900-01-01");
  2591. model.op_time = dt.AddDays(dateLength - 2);
  2592. }
  2593. }
  2594. model.item_no = dataRow.c3;
  2595. model.item_name = dataRow.c4;
  2596. model.op_no = dataRow.c5;
  2597. Object obj = GetFieldValue(dataRow, "c6");
  2598. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2599. {
  2600. model.qty_all = realValuel;
  2601. }
  2602. obj = GetFieldValue(dataRow, "c7");
  2603. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2604. {
  2605. model.qty_error = realValuel;
  2606. }
  2607. obj = GetFieldValue(dataRow, "c8");
  2608. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2609. {
  2610. model.percent_ok = realValuel;
  2611. }
  2612. model.fpy_id = test.id;
  2613. model.create_by = create_by;
  2614. model.create_date = create_date;
  2615. model.create_org = create_org;
  2616. modelList.Add(model);
  2617. }
  2618. }
  2619. errorMsg = stringBuilder.ToString();
  2620. return modelList;
  2621. }
  2622. #endregion FPY
  2623. /// <summary>
  2624. /// 依据导入的数据行,生成OQC的表头、检验标准和数据行
  2625. /// </summary>
  2626. /// <param name="upload_id"></param>
  2627. /// <param name="create_by"></param>
  2628. /// <param name="create_date"></param>
  2629. /// <param name="create_org"></param>
  2630. /// <returns></returns>
  2631. public string Import_Oqc_From_Data(int upload_id, string create_by, DateTime create_date, string create_org)
  2632. {
  2633. StringBuilder stringBuilder = new StringBuilder();
  2634. try
  2635. {
  2636. sqe_file_upload sqe_File_Upload = Get_Sqe_file_upload(upload_id);
  2637. List<sqe_file_data> datas = LoadData_file_data(upload_id);
  2638. if (datas == null || datas.Count == 0)
  2639. {
  2640. stringBuilder.AppendLine("导入数据信息不存在!");
  2641. return stringBuilder.ToString();
  2642. }
  2643. //出货检验记录的文件格式校验
  2644. if (datas[0].c1.CompareTo("出货检验记录") != 0)
  2645. {
  2646. stringBuilder.AppendLine("文件不是【出货检验记录】要求的格式");
  2647. return stringBuilder.ToString();
  2648. }
  2649. if (datas[1].c1.CompareTo("供应商名称") != 0
  2650. || datas[1].c3.CompareTo("物料名称") != 0
  2651. || datas[1].c5.CompareTo("物料号") != 0
  2652. || datas[1].c7.CompareTo("物料版本号") != 0)
  2653. {
  2654. stringBuilder.AppendLine("文件不是【出货检验记录】要求的格式");
  2655. return stringBuilder.ToString();
  2656. }
  2657. if (datas[2].c1.CompareTo("日期") != 0
  2658. || datas[2].c3.CompareTo("批次号") != 0
  2659. || datas[2].c5.CompareTo("批次数量") != 0
  2660. || datas[2].c7.CompareTo("检验人员") != 0)
  2661. {
  2662. stringBuilder.AppendLine("文件不是【出货检验记录】要求的格式");
  2663. return stringBuilder.ToString();
  2664. }
  2665. string errorMsg;
  2666. sqe_oqc test = File_data_ToModel_oqc(datas, create_by, create_date, create_org, out errorMsg);
  2667. if (errorMsg != null && errorMsg.Length > 0)
  2668. {
  2669. stringBuilder.AppendLine(errorMsg);
  2670. return stringBuilder.ToString();
  2671. }
  2672. _sqe_oqc.BeginTransaction();
  2673. _sqe_oqc.Insert(test);
  2674. errorMsg = null;
  2675. List<sqe_oqc_standard> standards = File_data_ToModel_oqc_standard(datas, test, create_by, create_date, create_org, out errorMsg);
  2676. if (errorMsg != null && errorMsg.Length > 0)
  2677. {
  2678. _sqe_oqc.Rollback();
  2679. stringBuilder.AppendLine(errorMsg);
  2680. return stringBuilder.ToString();
  2681. }
  2682. _sqe_oqc_standard.BeginTransaction();
  2683. _sqe_oqc_standard.Insert(standards);
  2684. List<sqe_oqc_data> test_Datas = File_data_ToModel_oqc_data(datas, test, standards, create_by, create_date, create_org, out errorMsg);
  2685. if (errorMsg != null && errorMsg.Length > 0)
  2686. {
  2687. _sqe_oqc.Rollback();
  2688. _sqe_oqc_standard.Rollback();
  2689. stringBuilder.AppendLine(errorMsg);
  2690. return stringBuilder.ToString();
  2691. }
  2692. _sqe_oqc_data.Insert(test_Datas);
  2693. sqe_File_Upload.item_no = test.item_no;
  2694. sqe_File_Upload.item_name = test.item_name;
  2695. _sqe_file_upload.Update(sqe_File_Upload);
  2696. _sqe_oqc.CommitTransaction();
  2697. _sqe_oqc_standard.CommitTransaction();
  2698. }
  2699. catch (Exception ex)
  2700. {
  2701. stringBuilder.Append("数据导入失败!");
  2702. }
  2703. finally
  2704. {
  2705. }
  2706. return stringBuilder.ToString();
  2707. }
  2708. #region OQC
  2709. /// <summary>
  2710. /// 从原始数据行生成OQC的表头数据
  2711. /// </summary>
  2712. /// <param name="datas"></param>
  2713. /// <param name="create_by"></param>
  2714. /// <param name="create_date"></param>
  2715. /// <param name="create_org"></param>
  2716. /// <param name="errorMsg"></param>
  2717. /// <returns></returns>
  2718. public sqe_oqc File_data_ToModel_oqc(List<sqe_file_data> datas, string create_by, DateTime create_date, string create_org, out string errorMsg)
  2719. {
  2720. StringBuilder stringBuilder = new StringBuilder();
  2721. sqe_oqc model = new sqe_oqc();
  2722. DateTime timeValue;
  2723. decimal realValuel;
  2724. if (datas != null && datas.Count >= 4)
  2725. {
  2726. try
  2727. {
  2728. model.file_id = datas[0].file_id;
  2729. sqe_file_data data = datas[1];
  2730. model.supp_no = data.c2;
  2731. model.item_name = data.c4;
  2732. model.item_no = data.c6;
  2733. model.item_version = data.c8;
  2734. data = datas[2];
  2735. if (DateTime.TryParse(data.c2, out timeValue))
  2736. {
  2737. model.product_time = timeValue;
  2738. }
  2739. else
  2740. {
  2741. model.product_time = DateTime.Now;
  2742. }
  2743. model.batch_no = data.c4;
  2744. if (decimal.TryParse(data.c6, out realValuel))
  2745. {
  2746. model.batch_qty = realValuel;
  2747. }
  2748. model.test_person = data.c8;
  2749. data = datas[3];
  2750. model.sampling_standard = data.c2;
  2751. if (decimal.TryParse(data.c4, out realValuel))
  2752. {
  2753. model.sampling_number = realValuel;
  2754. }
  2755. model.test_result = data.c8;
  2756. }
  2757. catch (Exception ex)
  2758. {
  2759. WLLog.Error("Excel数据解析问题:", ex);
  2760. }
  2761. model.create_by = create_by;
  2762. model.create_date = create_date;
  2763. model.create_org = create_org;
  2764. errorMsg = string.Empty;
  2765. return model;
  2766. }
  2767. else
  2768. {
  2769. errorMsg = stringBuilder.ToString();
  2770. return null;
  2771. }
  2772. }
  2773. /// <summary>
  2774. /// 从原始数据行生成OQC的检验标准
  2775. /// </summary>
  2776. /// <param name="datas"></param>
  2777. /// <param name="test"></param>
  2778. /// <param name="create_by"></param>
  2779. /// <param name="create_date"></param>
  2780. /// <param name="create_org"></param>
  2781. /// <param name="errorMsg"></param>
  2782. /// <returns></returns>
  2783. 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)
  2784. {
  2785. StringBuilder stringBuilder = new StringBuilder();
  2786. List<sqe_oqc_standard> modelList = new List<sqe_oqc_standard>();
  2787. decimal realValuel;
  2788. if (datas != null && datas.Count >= 13)
  2789. {
  2790. try
  2791. {
  2792. //标准的起始位置
  2793. int index = 4;
  2794. sqe_file_data dataRow = datas[index];
  2795. #region 处理尺寸的表头
  2796. for (int i = 2; i < 10; i++)
  2797. {
  2798. Object obj = GetFieldValue(dataRow, "c" + i.ToString());
  2799. if (obj != null)
  2800. {
  2801. sqe_oqc_standard model = new sqe_oqc_standard();
  2802. model.standard_no = obj.ToString();
  2803. model.create_by = create_by;
  2804. model.create_date = create_date;
  2805. model.create_org = create_org;
  2806. model.oqc_id = test.id;
  2807. modelList.Add(model);
  2808. }
  2809. else
  2810. {
  2811. break;
  2812. }
  2813. }
  2814. #endregion 处理尺寸的表头
  2815. //处理表头的具体值
  2816. for (int i = 0; i < 9 && i < modelList.Count; i++)
  2817. {
  2818. string fieldName = "c" + (i + 2).ToString();
  2819. sqe_oqc_standard model = modelList[i];
  2820. dataRow = datas[index + 1];
  2821. Object obj = GetFieldValue(dataRow, fieldName);
  2822. if (obj != null)
  2823. {
  2824. model.standard_no = obj.ToString();
  2825. }
  2826. dataRow = datas[index + 2];
  2827. obj = GetFieldValue(dataRow, fieldName);
  2828. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2829. {
  2830. model.standard_value = realValuel;
  2831. }
  2832. dataRow = datas[index + 3];
  2833. obj = GetFieldValue(dataRow, fieldName);
  2834. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2835. {
  2836. model.delta_up = realValuel;
  2837. }
  2838. dataRow = datas[index + 4];
  2839. obj = GetFieldValue(dataRow, fieldName);
  2840. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2841. {
  2842. model.delta_down = realValuel;
  2843. }
  2844. dataRow = datas[index + 5];
  2845. obj = GetFieldValue(dataRow, fieldName);
  2846. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2847. {
  2848. model.standard_max = realValuel;
  2849. }
  2850. dataRow = datas[index + 6];
  2851. obj = GetFieldValue(dataRow, fieldName);
  2852. if (obj != null && decimal.TryParse(obj.ToString(), out realValuel))
  2853. {
  2854. model.standard_min = realValuel;
  2855. }
  2856. }
  2857. }
  2858. catch (Exception ex)
  2859. {
  2860. WLLog.Error("Excel数据解析问题:", ex);
  2861. }
  2862. errorMsg = stringBuilder.ToString();
  2863. return modelList;
  2864. }
  2865. else
  2866. {
  2867. errorMsg = stringBuilder.ToString();
  2868. return null;
  2869. }
  2870. }
  2871. /// <summary>
  2872. /// 获取某个对象的某个属性的值
  2873. /// </summary>
  2874. /// <param name="obj"></param>
  2875. /// <param name="fieldName"></param>
  2876. /// <returns></returns>
  2877. private Object GetFieldValue(Object obj, string fieldName)
  2878. {
  2879. //获得对象的所有public属性
  2880. PropertyInfo[] pis = obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
  2881. //如果获得了属性
  2882. if (pis != null)
  2883. {
  2884. foreach (PropertyInfo pi in pis)//针对每一个属性进行循环
  2885. {
  2886. if (pi.Name.CompareTo(fieldName) == 0)
  2887. {
  2888. Object objValue = pi.GetValue(obj);
  2889. if (objValue != null && objValue.ToString().Length > 0)
  2890. {
  2891. return objValue;
  2892. }
  2893. }
  2894. }
  2895. }
  2896. return null;
  2897. }
  2898. /// <summary>
  2899. /// 从原始数据行生成OQC的数据
  2900. /// </summary>
  2901. /// <param name="datas"></param>
  2902. /// <param name="test"></param>
  2903. /// <param name="standards"></param>
  2904. /// <param name="create_by"></param>
  2905. /// <param name="create_date"></param>
  2906. /// <param name="create_org"></param>
  2907. /// <param name="errorMsg"></param>
  2908. /// <returns></returns>
  2909. 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)
  2910. {
  2911. StringBuilder stringBuilder = new StringBuilder();
  2912. List<sqe_oqc_data> modelList = new List<sqe_oqc_data>();
  2913. decimal realValuel;
  2914. if (datas != null && datas.Count >= 12)
  2915. {
  2916. for (int i = 11; i < datas.Count; i++)
  2917. {
  2918. sqe_file_data dataRow = datas[i];
  2919. if ((dataRow.c1 == null || dataRow.c1.Length == 0 || dataRow.c1 == "0") && (dataRow.c2 == null || dataRow.c2.Length == 0))
  2920. {
  2921. break;
  2922. }
  2923. //初始化每一层的数据集合
  2924. List<sqe_oqc_data> test_datas = new List<sqe_oqc_data>();
  2925. for (int j = 0; j < standards.Count; j++)
  2926. {
  2927. sqe_oqc_data data = new sqe_oqc_data();
  2928. data.oqc_id = standards[j].oqc_id;
  2929. data.standard_id = standards[j].id;
  2930. data.create_by = create_by;
  2931. data.create_date = create_date;
  2932. data.create_org = create_org;
  2933. test_datas.Add(data);
  2934. }
  2935. try
  2936. {
  2937. //将每一个检测标准的值从记录行中取出来
  2938. for (int j = 0; j < test_datas.Count; j++)
  2939. {
  2940. sqe_oqc_data data = test_datas[j];
  2941. data.data_no = dataRow.c1;
  2942. string fieldName = "c" + (j + 2).ToString();
  2943. Object obj = GetFieldValue(dataRow, fieldName);
  2944. if (obj != null && obj.ToString().Length > 0 && decimal.TryParse(obj.ToString(), out realValuel))
  2945. {
  2946. data.data_value = realValuel;
  2947. }
  2948. else
  2949. {
  2950. data.data_value = null;
  2951. }
  2952. }
  2953. File_data_ToModel_oqc_data_Add(modelList, test_datas);
  2954. }
  2955. catch (Exception ex)
  2956. {
  2957. WLLog.Error("Excel数据解析_原始数据转换到对象实体的问题:", ex);
  2958. }
  2959. }
  2960. errorMsg = string.Empty;
  2961. return modelList;
  2962. }
  2963. else
  2964. {
  2965. errorMsg = stringBuilder.ToString();
  2966. return null;
  2967. }
  2968. }
  2969. /// <summary>
  2970. /// 将转换的数据插入到返回结果数据集中,处理掉异常数据
  2971. /// </summary>
  2972. /// <param name="dataDest"></param>
  2973. /// <param name="dataSource"></param>
  2974. private void File_data_ToModel_oqc_data_Add(List<sqe_oqc_data> dataDest, List<sqe_oqc_data> dataSource)
  2975. {
  2976. if (dataSource != null && dataSource.Count > 0)
  2977. {
  2978. for (int i = 0; i < dataSource.Count; i++)
  2979. {
  2980. sqe_oqc_data data = dataSource[i];
  2981. if (data.data_no != null && data.data_no.Length > 0 && data.data_value != null)
  2982. {
  2983. dataDest.Add(data);
  2984. }
  2985. }
  2986. }
  2987. }
  2988. #endregion OQC
  2989. #region Fct
  2990. /// <summary>
  2991. /// 将字符串插入到数据库
  2992. /// </summary>
  2993. /// <param name="data"></param>
  2994. /// <param name="create_by"></param>
  2995. /// <param name="create_date"></param>
  2996. /// <param name="create_org"></param>
  2997. /// <returns></returns>
  2998. public string Import_Fct_From_Data(String data, string create_by, DateTime create_date, string create_org)
  2999. {
  3000. StringBuilder stringBuilder = new StringBuilder();
  3001. sqe_fct model = new sqe_fct();
  3002. List<sqe_fct_data> modelList = new List<sqe_fct_data>();
  3003. DateTime timeValue;
  3004. decimal realValuel;
  3005. try
  3006. {
  3007. JObject json = JObject.Parse(data);
  3008. model.SpID = json["SpID"].ToString();
  3009. model.WLID = json["WLID"].ToString();
  3010. model.WPID = json["WPID"].ToString();
  3011. model.op_side = json["OpSide"].ToString();
  3012. model.LineID = json["LineID"].ToString();
  3013. model.OpID = json["OpID"].ToString();
  3014. model.bar_code = json["BarCode"].ToString();
  3015. model.SerialNO = json["SerialNO"].ToString();
  3016. model.WONO = json["WONO"].ToString();
  3017. model.program = json["Program"].ToString();
  3018. model.pro_version = json["ProVersion"].ToString();
  3019. model.test_date = DateTime.Parse(json["TestDate"].ToString());
  3020. model.test_result = json["testResult"].ToString();
  3021. model.msg = json["Msg"].ToString();
  3022. model.create_by = create_by;
  3023. model.create_date = create_date;
  3024. model.create_org = create_org;
  3025. JArray array = JArray.Parse(json["testData"].ToString());
  3026. //将每一个检测标准的值从记录行中取出来
  3027. for (int j = 0; array != null && j < array.Count; j++)
  3028. {
  3029. sqe_fct_data data1 = new sqe_fct_data();
  3030. data1.name = array[j]["Name"].ToString();
  3031. data1.unit = array[j]["Unit"].ToString();
  3032. data1.lower = decimal.Parse(array[j]["Lower"].ToString());
  3033. data1.upper = decimal.Parse(array[j]["Upper"].ToString());
  3034. data1.actual = decimal.Parse(array[j]["Actual"].ToString());
  3035. data1.result = array[j]["result"].ToString();
  3036. data1.start_time = DateTime.Parse(array[j]["StartTime"].ToString());
  3037. data1.end_time = DateTime.Parse(array[j]["endTime"].ToString());
  3038. data1.detial = array[j]["Detial"].ToString();
  3039. data1.create_by = create_by;
  3040. data1.create_date = create_date;
  3041. data1.create_org = create_org;
  3042. modelList.Add(data1);
  3043. }
  3044. }
  3045. catch (Exception ex)
  3046. {
  3047. stringBuilder.Append(ex.ToString());
  3048. WLLog.Error("Fct上传数据解析_原始数据转换到对象实体的问题:", ex);
  3049. }
  3050. try
  3051. {
  3052. _sqe_fct.BeginTransaction();
  3053. _sqe_fct.Insert(model);
  3054. foreach (var item in modelList)
  3055. {
  3056. item.fct_id = model.id;
  3057. }
  3058. _sqe_fct_data.BeginTransaction();
  3059. _sqe_fct_data.Insert(modelList);
  3060. _sqe_fct_data.CommitTransaction();
  3061. _sqe_fct.CommitTransaction();
  3062. }
  3063. catch (Exception ex)
  3064. {
  3065. _sqe_fct_data.Rollback();
  3066. _sqe_fct.Rollback();
  3067. stringBuilder.Append(ex.ToString());
  3068. }
  3069. return stringBuilder.ToString();
  3070. }
  3071. #endregion Fct
  3072. /// <summary>
  3073. /// 依据上传文件id,生成该文件上传的数据统计
  3074. /// </summary>
  3075. /// <param name="upload_id"></param>
  3076. /// <param name="create_by"></param>
  3077. /// <param name="create_date"></param>
  3078. /// <param name="create_org"></param>
  3079. /// <returns></returns>
  3080. public string Compute_Test(int upload_id, string create_by, DateTime create_date, string create_org)
  3081. {
  3082. StringBuilder stringBuilder = new StringBuilder();
  3083. //查询原始记录
  3084. List<sqe_cto_test> tests = _sqe_cto_test.Select(a => a.file_id == upload_id).OrderBy(a => a.id).ToList();
  3085. if (tests == null || tests.Count == 0)
  3086. {
  3087. stringBuilder.AppendLine("该id对应的上传数据记录不存在!");
  3088. return stringBuilder.ToString();
  3089. }
  3090. sqe_cto_test test = tests[0];
  3091. List<sqe_cto_test_standard> test_standards = _sqe_cto_test_standard.Select(a => a.test_id == test.id).OrderBy(a => a.id).ToList();
  3092. if (test_standards == null || test_standards.Count == 0)
  3093. {
  3094. stringBuilder.AppendLine("该id对应的检验标准数据记录不存在!");
  3095. return stringBuilder.ToString();
  3096. }
  3097. //Compute_Test_id(upload_id, "1号尺寸", create_by, create_date, create_org);
  3098. Compute_Test_id(upload_id, test_standards[0].standard_no, create_by, create_date, create_org);
  3099. List<sqe_cto_test_data> test_datas = _sqe_cto_test_data.Select(a => a.test_id == test.id).OrderBy(a => a.id).ToList();
  3100. //生成统计信息
  3101. List<sqe_cto_test_avg> test_avgs = _sqe_cto_test_avg.Select(a => a.cto_test_id == test.id).OrderBy(a => a.id).ToList();
  3102. if (test_avgs != null && test_avgs.Count > 0)
  3103. {
  3104. stringBuilder.AppendLine("该id的数据统计已经完成!");
  3105. return stringBuilder.ToString();
  3106. }
  3107. int sample_count = test.sampling_number;
  3108. for (int i = 0; i <= test_datas.Count - sample_count; i += sample_count)
  3109. {
  3110. }
  3111. return stringBuilder.ToString();
  3112. }
  3113. /// <summary>
  3114. /// 依据test_id,生成该对象的均值和极差,保存到数据库表sqe_cto_test_avg
  3115. /// 依据均值和极差,再次生成该数据的统计值对象,并且保存到数据库表sqe_cto_test_statistics
  3116. /// </summary>
  3117. /// <param name="test_id"></param>
  3118. /// <param name="standard_no"></param>
  3119. /// <param name="create_by"></param>
  3120. /// <param name="create_date"></param>
  3121. /// <param name="create_org"></param>
  3122. /// <returns></returns>
  3123. public string Compute_Test_id(int test_id, string standard_no, string create_by, DateTime create_date, string create_org)
  3124. {
  3125. StringBuilder stringBuilder = new StringBuilder();
  3126. //查询原始记录
  3127. List<sqe_cto_test> tests = _sqe_cto_test.Select(a => a.id == test_id).OrderBy(a => a.id).ToList();
  3128. if (tests == null || tests.Count == 0)
  3129. {
  3130. stringBuilder.AppendLine("该id对应的上传数据记录不存在!");
  3131. return stringBuilder.ToString();
  3132. }
  3133. sqe_cto_test test = tests[0];
  3134. //查看该CTO的产品特性数据,查询统计信息是否已经生成
  3135. List<sqe_cto_test_avg> test_avgs = _sqe_cto_test_avg.Select(a => a.cto_test_id == test.id).OrderBy(a => a.id).ToList();
  3136. if (test_avgs != null && test_avgs.Count > 0)
  3137. {
  3138. stringBuilder.AppendLine("该id的数据统计已经完成!");
  3139. return stringBuilder.ToString();
  3140. }
  3141. // 依据ID条件,获取用户上传的CTO产品特性数据
  3142. List<v_sqe_cto_test_data> test_datas = _v_sqe_cto_test_data.Select(a => a.test_id == test.id && a.standard_no == standard_no && a.data_value != null).OrderBy(a => a.id).ToList();
  3143. if (test_datas == null || test_datas.Count == 0)
  3144. {
  3145. ResultViewModel resultError = ResultHelper.CreateResult(ResultCode.BusinessError, "您的查询条件没有查询到数据可能有问题,请核对之后再进行操作!", ResultCode.BusinessError, null);
  3146. return JsonConvert.SerializeObject(resultError);
  3147. }
  3148. //int sample_count = test_datas != null && test_datas.Count > 0 ? test_datas[0].sampling_count : -1;
  3149. //if (sample_count == -1)
  3150. //{
  3151. // ResultViewModel resultError = ResultHelper.CreateResult(ResultCode.BusinessError, "您选择数据中的采样数有问题,请核对之后再进行操作!", ResultCode.BusinessError, null);
  3152. // return JsonConvert.SerializeObject(resultError);
  3153. //}
  3154. int sample_count = test.sampling_number;
  3155. double[] data = new double[sample_count];
  3156. //所有的检测数据,按照进行采样数进行归一
  3157. double[] dataAll = new double[test_datas.Count / sample_count * sample_count];
  3158. //极差数据
  3159. double[] dataRange = new double[test_datas.Count / sample_count];
  3160. for (int i = 0; i <= test_datas.Count - sample_count; i += sample_count)
  3161. {
  3162. sqe_cto_test_avg obj = new sqe_cto_test_avg();
  3163. for (int j = 0; j < sample_count; j++)
  3164. {
  3165. data[j] = (double)test_datas[i + j].data_value.Value;
  3166. dataAll[i + j] = data[j];
  3167. }
  3168. obj.create_by = create_by;
  3169. obj.create_date = create_date;
  3170. obj.create_org = create_org;
  3171. obj.standard_no = standard_no;
  3172. obj.sampling_number = sample_count;
  3173. obj.mean_value = (decimal)data.Average();
  3174. obj.range_value = (decimal)(data.Max() - data.Min());
  3175. dataRange[i / sample_count] = (double)obj.range_value;
  3176. obj.cto_test_id = test_id;
  3177. test_avgs.Add(obj);
  3178. }
  3179. decimal a2 = (decimal)GetA2(sample_count);
  3180. decimal d2 = (decimal)GetD2(sample_count);
  3181. decimal d3 = (decimal)GetD3(sample_count);
  3182. decimal d4 = (decimal)GetD4(sample_count);
  3183. //开始计算统计结果
  3184. sqe_cto_test_statistics model = new sqe_cto_test_statistics();
  3185. model.create_by = create_by;
  3186. model.create_date = create_date;
  3187. model.create_org = create_org;
  3188. model.cto_test_id = test.id;
  3189. model.standard_no = standard_no;
  3190. model.value_count = test_datas.Count;
  3191. model.standard_min = test_datas[0].standard_min;
  3192. model.standard_max = test_datas[0].standard_max;
  3193. model.standard_value = (model.standard_min + model.standard_max) / 2;
  3194. model.value_sum = (decimal)dataAll.Sum();
  3195. model.value_avg = (decimal)dataAll.Average();
  3196. model.value_max = (decimal)dataAll.Max();
  3197. model.value_min = (decimal)dataAll.Min();
  3198. model.value_below = dataAll.Count(x => x < (double)model.standard_min);
  3199. model.value_above = dataAll.Count(x => x > (double)model.standard_max);
  3200. model.avg_range = (decimal)dataRange.Average();
  3201. model.value_d2 = d2;
  3202. model.value_cpu = (model.standard_max - model.value_avg) / (3 * model.avg_range / model.value_d2);
  3203. model.value_cpl = (model.value_avg - model.standard_min) / (3 * model.avg_range / model.value_d2);
  3204. model.value_cp = (model.standard_max - model.standard_min) / (6 * model.avg_range / model.value_d2);
  3205. model.value_cpk = model.value_cpu < model.value_cpl ? model.value_cpu : model.value_cpl;
  3206. model.value_cr = (decimal)1.0 / model.value_cp;
  3207. model.value_stdev = (decimal)dataAll.StandardDeviation();
  3208. model.value_stdevp = (decimal)dataAll.PopulationStandardDeviation();
  3209. model.value_var = (decimal)dataAll.Variance();
  3210. model.value_varp = (decimal)dataAll.PopulationVariance();
  3211. model.value_pp = (model.standard_max - model.standard_min) / (6 * model.value_stdev);
  3212. model.value_ppu = (model.standard_max - model.value_avg) / (3 * model.value_stdev);
  3213. model.value_ppl = (model.value_avg - model.standard_min) / (3 * model.value_stdev);
  3214. model.value_ppk = model.value_ppu < model.value_ppl ? model.value_ppu : model.value_ppl;
  3215. //更新均值方差数据表信息
  3216. foreach (var item in test_avgs)
  3217. {
  3218. item.mean_value_all = model.value_avg;
  3219. item.range_value_all = model.avg_range;
  3220. item.value_uclx = item.mean_value_all + item.range_value_all * a2;
  3221. item.value_lclx = item.mean_value_all - item.range_value_all * a2;
  3222. item.value_uclr = item.range_value_all * d4;
  3223. item.value_lclr = item.range_value_all * d3;
  3224. }
  3225. _sqe_cto_test_avg.Update(test_avgs);
  3226. _sqe_cto_test_statistics.Update(model);
  3227. return stringBuilder.ToString();
  3228. }
  3229. #region 计算系数
  3230. /// <summary>
  3231. /// 计算A2系数
  3232. /// </summary>
  3233. /// <param name="sample_count"></param>
  3234. /// <returns></returns>
  3235. public double GetA2(int sample_count)
  3236. {
  3237. switch (sample_count)
  3238. {
  3239. case 1:
  3240. return 2.659574468;
  3241. break;
  3242. case 2:
  3243. return 1.88;
  3244. break;
  3245. case 3:
  3246. return 1.023;
  3247. break;
  3248. case 4:
  3249. return 0.729;
  3250. break;
  3251. case 5:
  3252. return 0.577;
  3253. break;
  3254. }
  3255. return 1;
  3256. }
  3257. /// <summary>
  3258. /// 计算系数D2
  3259. /// </summary>
  3260. /// <param name="sample_count"></param>
  3261. /// <returns></returns>
  3262. public double GetD2(int sample_count)
  3263. {
  3264. switch (sample_count)
  3265. {
  3266. case 1:
  3267. return 1.128;
  3268. break;
  3269. case 2:
  3270. return 1.128;
  3271. break;
  3272. case 3:
  3273. return 1.693;
  3274. break;
  3275. case 4:
  3276. return 2.059;
  3277. break;
  3278. case 5:
  3279. return 2.326;
  3280. break;
  3281. }
  3282. return 1;
  3283. }
  3284. /// <summary>
  3285. /// 计算系数D4
  3286. /// </summary>
  3287. /// <param name="sample_count"></param>
  3288. /// <returns></returns>
  3289. public double GetD4(int sample_count)
  3290. {
  3291. switch (sample_count)
  3292. {
  3293. case 1:
  3294. return 3.267;
  3295. break;
  3296. case 2:
  3297. return 3.267;
  3298. break;
  3299. case 3:
  3300. return 2.574;
  3301. break;
  3302. case 4:
  3303. return 2.282;
  3304. break;
  3305. case 5:
  3306. return 2.114;
  3307. break;
  3308. }
  3309. return 1;
  3310. }
  3311. /// <summary>
  3312. /// 计算系数D3
  3313. /// </summary>
  3314. /// <param name="sample_count"></param>
  3315. /// <returns></returns>
  3316. public double GetD3(int sample_count)
  3317. {
  3318. return 0;
  3319. //switch (sample_count)
  3320. //{
  3321. // case 1:
  3322. // return 1.128;
  3323. // break;
  3324. // case 2:
  3325. // return 1.128;
  3326. // break;
  3327. // case 3:
  3328. // return 1.693;
  3329. // break;
  3330. // case 4:
  3331. // return 2.059;
  3332. // break;
  3333. // case 5:
  3334. // return 2.326;
  3335. // break;
  3336. //}
  3337. //return 1;
  3338. }
  3339. #endregion 计算系数
  3340. /// <summary>
  3341. /// 通过查询条件,查询统计Chart的数据的标识信息
  3342. /// </summary>
  3343. /// <param name="startDate"></param>
  3344. /// <param name="endDate"></param>
  3345. /// <param name="item_no"></param>
  3346. /// <param name="item_batch"></param>
  3347. /// <param name="org"></param>
  3348. /// <param name="standard_no"></param>
  3349. /// <param name="sample_count"></param>
  3350. /// <returns></returns>
  3351. public string Compute_TestChartData(string startDate, string endDate, string item_no, string item_batch, string org, string standard_no, int sample_count)
  3352. {
  3353. try
  3354. {
  3355. // 依据查询条件,获取用户上传的CTO产品特性数据
  3356. List<v_sqe_cto_test_data> test_datas = Get_TestData(startDate, endDate, item_no, item_batch, org, standard_no);
  3357. if (test_datas == null || test_datas.Count == 0)
  3358. {
  3359. ResultViewModel resultError = ResultHelper.CreateResult(ResultCode.BusinessError, "您的查询条件没有查询到数据可能有问题,请核对之后再进行操作!", ResultCode.BusinessError, null);
  3360. return JsonConvert.SerializeObject(resultError);
  3361. }
  3362. //所有的检测数据,按照进行采样数进行归一
  3363. double[] dataAll = null;
  3364. //均值数据
  3365. double[] dataAvg = null;
  3366. //极差数据
  3367. double[] dataRange = null;
  3368. //计算均值与极差
  3369. Get_TestAvgRange(test_datas, sample_count, out dataAll, out dataAvg, out dataRange);
  3370. double a2 = GetA2(sample_count);
  3371. double d2 = GetD2(sample_count);
  3372. double d3 = GetD3(sample_count);
  3373. double d4 = GetD4(sample_count);
  3374. //开始计算统计结果
  3375. double UCLx = 0, AveX = 0, LCLx = 0, UCLr = 0, AveR = 0, LCLr = 0;
  3376. AveX = dataAvg.Average();
  3377. AveR = dataRange.Average();
  3378. UCLx = AveX + a2 * AveR;
  3379. LCLx = AveX - a2 * AveR;
  3380. UCLr = d4 * AveR;
  3381. LCLr = d3 * AveR;
  3382. //生成临时数据,插入数据库
  3383. List<sqe_chart_data_temp> models = new List<sqe_chart_data_temp>();
  3384. sqe_chart_data_temp model;
  3385. DateTime dateTimeNow = DateTime.Now;
  3386. for (int i = 0; i < dataAvg.Length; i++)
  3387. {
  3388. model = new sqe_chart_data_temp();
  3389. model.data_id = dateTimeNow.Ticks;
  3390. model.sub_group = "sub" + (i + 1).ToString();
  3391. model.type_name = "均值";
  3392. model.type_value = (decimal)AveX;
  3393. model.data_time = dateTimeNow;
  3394. models.Add(model);
  3395. model = new sqe_chart_data_temp();
  3396. model.data_id = dateTimeNow.Ticks;
  3397. model.sub_group = "sub" + (i + 1).ToString();
  3398. model.type_name = "极差";
  3399. model.type_value = (decimal)AveR;
  3400. model.data_time = dateTimeNow;
  3401. models.Add(model);
  3402. model = new sqe_chart_data_temp();
  3403. model.data_id = dateTimeNow.Ticks;
  3404. model.sub_group = "sub" + (i + 1).ToString();
  3405. model.type_name = "UCLx";
  3406. model.type_value = (decimal)UCLx;
  3407. model.data_time = dateTimeNow;
  3408. models.Add(model);
  3409. model = new sqe_chart_data_temp();
  3410. model.data_id = dateTimeNow.Ticks;
  3411. model.sub_group = "sub" + (i + 1).ToString();
  3412. model.type_name = "LCLx";
  3413. model.type_value = (decimal)LCLx;
  3414. model.data_time = dateTimeNow;
  3415. models.Add(model);
  3416. model = new sqe_chart_data_temp();
  3417. model.data_id = dateTimeNow.Ticks;
  3418. model.sub_group = "sub" + (i + 1).ToString();
  3419. model.type_name = "UCLr";
  3420. model.type_value = (decimal)UCLr;
  3421. model.data_time = dateTimeNow;
  3422. models.Add(model);
  3423. model = new sqe_chart_data_temp();
  3424. model.data_id = dateTimeNow.Ticks;
  3425. model.sub_group = "sub" + (i + 1).ToString();
  3426. model.type_name = "LCLr";
  3427. model.type_value = (decimal)LCLr;
  3428. model.data_time = dateTimeNow;
  3429. models.Add(model);
  3430. }
  3431. _sqe_chart_data_temp.Insert(models);
  3432. String dataID = "";
  3433. if (models.Count > 0)
  3434. {
  3435. dataID = dateTimeNow.Ticks.ToString();
  3436. }
  3437. ResultViewModel result = ResultHelper.CreateResult(ResultCode.Success, dataID, ResultCode.Success, null);
  3438. return JsonConvert.SerializeObject(result);
  3439. }
  3440. catch (Exception ex)
  3441. {
  3442. ResultViewModel resultError = ResultHelper.CreateResult(ResultCode.BusinessError, "您选择数据中的采样数有问题,请核对之后再进行操作!", ResultCode.BusinessError, null);
  3443. return JsonConvert.SerializeObject(resultError);
  3444. }
  3445. }
  3446. /// <summary>
  3447. /// 依据查询统计条件,生成该时间段内的均值和极差
  3448. /// 依据均值和极差,再次生成统计对象
  3449. /// </summary>
  3450. /// <param name="startDate"></param>
  3451. /// <param name="endDate"></param>
  3452. /// <param name="item_no"></param>
  3453. /// <param name="item_batch"></param>
  3454. /// <param name="org"></param>
  3455. /// <param name="standard_no"></param>
  3456. /// <param name="sample_count"></param>
  3457. /// <returns></returns>
  3458. public string Compute_Test(string startDate, string endDate, string item_no, string item_batch, string org, string standard_no, int sample_count)
  3459. {
  3460. try
  3461. {
  3462. // 依据查询条件,获取用户上传的CTO产品特性数据
  3463. List<v_sqe_cto_test_data> test_datas = Get_TestData(startDate, endDate, item_no, item_batch, org, standard_no);
  3464. if (test_datas == null || test_datas.Count == 0)
  3465. {
  3466. ResultViewModel resultError = ResultHelper.CreateResult(ResultCode.BusinessError, "您的查询条件没有查询到数据可能有问题,请核对之后再进行操作!", ResultCode.BusinessError, null);
  3467. return JsonConvert.SerializeObject(resultError);
  3468. }
  3469. //int sample_count = test_datas != null && test_datas.Count > 0 ? test_datas[0].sampling_count : -1;
  3470. //if (sample_count == -1)
  3471. //{
  3472. // ResultViewModel resultError = ResultHelper.CreateResult(ResultCode.BusinessError, "您选择数据中的采样数有问题,请核对之后再进行操作!", ResultCode.BusinessError, null);
  3473. // return JsonConvert.SerializeObject(resultError);
  3474. //}
  3475. //所有的检测数据,按照进行采样数进行归一
  3476. double[] dataAll = null;
  3477. //均值数据
  3478. double[] dataAvg = null;
  3479. //极差数据
  3480. double[] dataRange = null;
  3481. //计算均值与极差
  3482. Get_TestAvgRange(test_datas, sample_count, out dataAll, out dataAvg, out dataRange);
  3483. decimal a2 = (decimal)GetA2(sample_count);
  3484. decimal d2 = (decimal)GetD2(sample_count);
  3485. decimal d3 = (decimal)GetD3(sample_count);
  3486. decimal d4 = (decimal)GetD4(sample_count);
  3487. //开始计算统计结果
  3488. sqe_cto_test_statistics model = new sqe_cto_test_statistics();
  3489. model.standard_no = standard_no;
  3490. model.value_count = test_datas.Count;
  3491. model.standard_min = test_datas[0].standard_min;
  3492. model.standard_max = test_datas[0].standard_max;
  3493. model.standard_value = (model.standard_min + model.standard_max) / 2;
  3494. model.value_sum = (decimal)dataAll.Sum();
  3495. model.value_avg = (decimal)dataAll.Average();
  3496. model.value_max = (decimal)dataAll.Max();
  3497. model.value_min = (decimal)dataAll.Min();
  3498. model.value_below = dataAll.Count(x => x < (double)model.standard_min);
  3499. model.value_above = dataAll.Count(x => x > (double)model.standard_max);
  3500. model.avg_range = (decimal)dataRange.Average();
  3501. model.value_d2 = d2;
  3502. model.value_cpu = (model.standard_max - model.value_avg) / (3 * model.avg_range / model.value_d2);
  3503. model.value_cpl = (model.value_avg - model.standard_min) / (3 * model.avg_range / model.value_d2);
  3504. model.value_cp = (model.standard_max - model.standard_min) / (6 * model.avg_range / model.value_d2);
  3505. model.value_cpk = model.value_cpu < model.value_cpl ? model.value_cpu : model.value_cpl;
  3506. model.value_cr = (decimal)1.0 / model.value_cp;
  3507. model.value_stdev = (decimal)dataAll.StandardDeviation();
  3508. model.value_stdevp = (decimal)dataAll.PopulationStandardDeviation();
  3509. model.value_var = (decimal)dataAll.Variance();
  3510. model.value_varp = (decimal)dataAll.PopulationVariance();
  3511. model.value_pp = (model.standard_max - model.standard_min) / (6 * model.value_stdev);
  3512. model.value_ppu = (model.standard_max - model.value_avg) / (3 * model.value_stdev);
  3513. model.value_ppl = (model.value_avg - model.standard_min) / (3 * model.value_stdev);
  3514. model.value_ppk = model.value_ppu < model.value_ppl ? model.value_ppu : model.value_ppl;
  3515. ResultViewModel result = ResultHelper.CreateResult(ResultCode.Success, model, ResultCode.Success, null);
  3516. return JsonConvert.SerializeObject(result);
  3517. }
  3518. catch (Exception ex)
  3519. {
  3520. ResultViewModel resultError = ResultHelper.CreateResult(ResultCode.BusinessError, "您选择数据中的采样数有问题,请核对之后再进行操作!", ResultCode.BusinessError, null);
  3521. return JsonConvert.SerializeObject(resultError);
  3522. }
  3523. }
  3524. /// <summary>
  3525. /// 依据查询条件,查询用户上传的CTO产品特性数据
  3526. /// </summary>
  3527. /// <param name="startDate"></param>
  3528. /// <param name="endDate"></param>
  3529. /// <param name="item_no"></param>
  3530. /// <param name="item_batch"></param>
  3531. /// <param name="org"></param>
  3532. /// <param name="standard_no"></param>
  3533. /// <returns></returns>
  3534. public List<v_sqe_cto_test_data> Get_TestData(string startDate, string endDate,
  3535. string item_no, string item_batch,
  3536. string org, string standard_no)
  3537. {
  3538. try
  3539. {
  3540. #region 查询条件
  3541. // 动态条件
  3542. var conditions = new List<Expression<Func<v_sqe_cto_test_data, bool>>>();
  3543. conditions.Add(p => p.data_value != null);
  3544. if (!string.IsNullOrEmpty(startDate))
  3545. {
  3546. DateTime dateTime;
  3547. if (DateTime.TryParse(startDate, out dateTime))
  3548. {
  3549. // 添加条件1:Name 包含 "searchTerm"
  3550. conditions.Add(p => p.create_date >= dateTime);
  3551. }
  3552. }
  3553. if (!string.IsNullOrEmpty(endDate))
  3554. {
  3555. DateTime dateTime;
  3556. if (DateTime.TryParse(endDate, out dateTime))
  3557. {
  3558. // 添加条件1:Name 包含 "searchTerm"
  3559. conditions.Add(p => p.create_date <= dateTime);
  3560. }
  3561. }
  3562. if (!string.IsNullOrEmpty(item_no))
  3563. {
  3564. // 添加条件1:Name 包含 "searchTerm"
  3565. conditions.Add(p => p.item_no == item_no);
  3566. }
  3567. if (!string.IsNullOrEmpty(item_batch))
  3568. {
  3569. // 添加条件1:Name 包含 "searchTerm"
  3570. conditions.Add(p => p.item_batch == item_batch);
  3571. }
  3572. if (!string.IsNullOrEmpty(org))
  3573. {
  3574. // 添加条件1:Name 包含 "searchTerm"
  3575. conditions.Add(p => p.create_org == org);
  3576. }
  3577. if (!string.IsNullOrEmpty(standard_no))
  3578. {
  3579. // 添加条件1:Name 包含 "searchTerm"
  3580. conditions.Add(p => p.standard_no == standard_no);
  3581. }
  3582. // 组合条件
  3583. var combinedCondition = PredicateBuilder.New<v_sqe_cto_test_data>();
  3584. foreach (var condition in conditions)
  3585. {
  3586. combinedCondition = combinedCondition.And(condition);
  3587. }
  3588. var query = _v_sqe_cto_test_data.GetDbContext().v_sqe_cto_test_data.AsQueryable();
  3589. // 应用条件
  3590. if (combinedCondition.Body != null)
  3591. {
  3592. query = query.Where(combinedCondition);
  3593. }
  3594. #endregion 查询条件
  3595. // 执行查询
  3596. List<v_sqe_cto_test_data> test_datas = query.DefaultIfEmpty().ToList();
  3597. return test_datas;
  3598. }
  3599. catch (Exception ex)
  3600. {
  3601. return null;
  3602. }
  3603. }
  3604. /// <summary>
  3605. /// 依据CTO产品特性数据,采样数,统计均值与极差
  3606. /// </summary>
  3607. /// <param name="datas"></param>
  3608. /// <param name="sample_count"></param>
  3609. /// <param name="dataAll"></param>
  3610. /// <param name="dataAvg"></param>
  3611. /// <param name="dataRange"></param>
  3612. public void Get_TestAvgRange(List<v_sqe_cto_test_data> datas, int sample_count, out double[] dataAll, out double[] dataAvg, out double[] dataRange)
  3613. {
  3614. //所有的检测数据,按照进行采样数进行归一
  3615. dataAll = new double[datas.Count / sample_count * sample_count];
  3616. //均值数据
  3617. dataAvg = new double[datas.Count / sample_count];
  3618. //极差数据
  3619. dataRange = new double[datas.Count / sample_count];
  3620. //计算极差与均值时的临时数据
  3621. double[] data = new double[sample_count];
  3622. //计算所有的均值与极差
  3623. for (int i = 0; i <= datas.Count - sample_count; i += sample_count)
  3624. {
  3625. for (int j = 0; j < sample_count; j++)
  3626. {
  3627. data[j] = (double)datas[i + j].data_value.Value;
  3628. dataAll[i + j] = data[j];
  3629. }
  3630. dataRange[i / sample_count] = data.Max() - data.Min();
  3631. }
  3632. }
  3633. /// <summary>
  3634. /// 依据查询条件,统计工序的不良情况
  3635. /// </summary>
  3636. /// <param name="startDate"></param>
  3637. /// <param name="endDate"></param>
  3638. /// <param name="item_no"></param>
  3639. /// <param name="item_batch"></param>
  3640. /// <param name="org"></param>
  3641. /// <returns></returns>
  3642. public string Compute_op_query(string startDate, string endDate, string item_no, string item_batch, string org, string op, string bad_type)
  3643. {
  3644. try
  3645. {
  3646. #region 查询条件
  3647. // 动态条件
  3648. var conditions = new List<Expression<Func<v_sqe_op_data_detail, bool>>>();
  3649. if (!string.IsNullOrEmpty(startDate))
  3650. {
  3651. DateTime dateTime;
  3652. if (DateTime.TryParse(startDate, out dateTime))
  3653. {
  3654. // 添加条件1:Name 包含 "searchTerm"
  3655. conditions.Add(p => p.create_date >= dateTime);
  3656. }
  3657. }
  3658. if (!string.IsNullOrEmpty(endDate))
  3659. {
  3660. DateTime dateTime;
  3661. if (DateTime.TryParse(endDate, out dateTime))
  3662. {
  3663. // 添加条件1:Name 包含 "searchTerm"
  3664. conditions.Add(p => p.create_date <= dateTime);
  3665. }
  3666. }
  3667. if (!string.IsNullOrEmpty(item_no))
  3668. {
  3669. // 添加条件1:Name 包含 "searchTerm"
  3670. conditions.Add(p => p.item_no == item_no);
  3671. }
  3672. if (!string.IsNullOrEmpty(item_batch))
  3673. {
  3674. // 添加条件1:Name 包含 "searchTerm"
  3675. conditions.Add(p => p.batch_no == item_batch);
  3676. }
  3677. if (!string.IsNullOrEmpty(org))
  3678. {
  3679. // 添加条件1:Name 包含 "searchTerm"
  3680. conditions.Add(p => p.create_org == org);
  3681. }
  3682. if (!string.IsNullOrEmpty(op))
  3683. {
  3684. // 添加条件1:Name 包含 "searchTerm"
  3685. conditions.Add(p => p.op_no == op);
  3686. }
  3687. if (!string.IsNullOrEmpty(bad_type))
  3688. {
  3689. // 添加条件1:Name 包含 "searchTerm"
  3690. conditions.Add(p => p.bad_type == bad_type);
  3691. }
  3692. // 组合条件
  3693. var combinedCondition = PredicateBuilder.New<v_sqe_op_data_detail>();
  3694. //此处是所有的条件都and。
  3695. foreach (var condition in conditions)
  3696. {
  3697. combinedCondition = combinedCondition.And(condition);
  3698. }
  3699. var query = _v_sqe_op_data_detail.GetDbContext().v_sqe_op_data_detail.AsQueryable();
  3700. // 应用条件
  3701. if (conditions.Count > 0)
  3702. {
  3703. query = query.Where(combinedCondition);
  3704. }
  3705. #endregion 查询条件
  3706. // 分组统计,此处多个条件进行统计,p.bad_type, p.op_no
  3707. var groupBy = query.GroupBy(p => new { p.bad_type, p.op_no })
  3708. .Select(g => new
  3709. {
  3710. bad_type = g.Key.bad_type,
  3711. op_no = g.Key.op_no,
  3712. bad_qty = g.Sum(p => p.bad_qty)
  3713. });
  3714. //增加排序条件,此处多个条件,op_no,bad_type
  3715. var test_datas = groupBy.OrderBy(p => p.op_no).ThenBy(p => p.bad_type).ToList();
  3716. ResultViewModel result = ResultHelper.CreateResult(ResultCode.Success, test_datas, ResultCode.Success, null);
  3717. return JsonConvert.SerializeObject(result);
  3718. }
  3719. catch (Exception ex)
  3720. {
  3721. ResultViewModel resultError = ResultHelper.CreateResult(ResultCode.BusinessError, "您选择的数据在统计中出现问题,请核对之后再进行操作!", ResultCode.BusinessError, null);
  3722. return JsonConvert.SerializeObject(resultError);
  3723. }
  3724. return null;
  3725. }
  3726. /// <summary>
  3727. /// 工序统计图
  3728. /// </summary>
  3729. /// <param name="startDate"></param>
  3730. /// <param name="endDate"></param>
  3731. /// <param name="item_no"></param>
  3732. /// <param name="item_batch"></param>
  3733. /// <param name="org"></param>
  3734. /// <param name="op"></param>
  3735. /// <param name="bad_type"></param>
  3736. /// <returns></returns>
  3737. public string Compute_OpChartData(string startDate, string endDate, string item_no, string item_batch, string org, string op, string bad_type)
  3738. {
  3739. try
  3740. {
  3741. #region 查询条件
  3742. // 动态条件
  3743. var conditions = new List<Expression<Func<v_sqe_op_data_detail, bool>>>();
  3744. if (!string.IsNullOrEmpty(startDate))
  3745. {
  3746. DateTime dateTime;
  3747. if (DateTime.TryParse(startDate, out dateTime))
  3748. {
  3749. // 添加条件1:Name 包含 "searchTerm"
  3750. conditions.Add(p => p.create_date >= dateTime);
  3751. }
  3752. }
  3753. if (!string.IsNullOrEmpty(endDate))
  3754. {
  3755. DateTime dateTime;
  3756. if (DateTime.TryParse(endDate, out dateTime))
  3757. {
  3758. // 添加条件1:Name 包含 "searchTerm"
  3759. conditions.Add(p => p.create_date <= dateTime);
  3760. }
  3761. }
  3762. if (!string.IsNullOrEmpty(item_no))
  3763. {
  3764. // 添加条件1:Name 包含 "searchTerm"
  3765. conditions.Add(p => p.item_no == item_no);
  3766. }
  3767. if (!string.IsNullOrEmpty(item_batch))
  3768. {
  3769. // 添加条件1:Name 包含 "searchTerm"
  3770. conditions.Add(p => p.batch_no == item_batch);
  3771. }
  3772. if (!string.IsNullOrEmpty(org))
  3773. {
  3774. // 添加条件1:Name 包含 "searchTerm"
  3775. conditions.Add(p => p.create_org == org);
  3776. }
  3777. if (!string.IsNullOrEmpty(op))
  3778. {
  3779. // 添加条件1:Name 包含 "searchTerm"
  3780. conditions.Add(p => p.op_no == op);
  3781. }
  3782. if (!string.IsNullOrEmpty(bad_type))
  3783. {
  3784. // 添加条件1:Name 包含 "searchTerm"
  3785. conditions.Add(p => p.bad_type == bad_type);
  3786. }
  3787. // 组合条件
  3788. var combinedCondition = PredicateBuilder.New<v_sqe_op_data_detail>();
  3789. //此处是所有的条件都and。
  3790. foreach (var condition in conditions)
  3791. {
  3792. combinedCondition = combinedCondition.And(condition);
  3793. }
  3794. var query = _v_sqe_op_data_detail.GetDbContext().v_sqe_op_data_detail.AsQueryable();
  3795. // 应用条件
  3796. if (conditions.Count > 0)
  3797. {
  3798. query = query.Where(combinedCondition);
  3799. }
  3800. #endregion 查询条件
  3801. // 分组统计,此处多个条件进行统计,p.bad_type, p.op_no
  3802. var groupBy = query.GroupBy(p => new { p.bad_type, p.op_no })
  3803. .Select(g => new
  3804. {
  3805. bad_type = g.Key.bad_type,
  3806. op_no = g.Key.op_no,
  3807. bad_qty = g.Sum(p => p.bad_qty)
  3808. });
  3809. //增加排序条件,此处多个条件,op_no,bad_type
  3810. var test_datas = groupBy.OrderBy(p => p.op_no).ThenBy(p => p.bad_type).ToList();
  3811. //生成临时数据,插入数据库
  3812. List<sqe_chart_data_temp> models = new List<sqe_chart_data_temp>();
  3813. sqe_chart_data_temp model;
  3814. DateTime dateTimeNow = DateTime.Now;
  3815. for (int i = 0; i < test_datas.Count; i++)
  3816. {
  3817. model = new sqe_chart_data_temp();
  3818. model.data_id = dateTimeNow.Ticks;
  3819. model.sub_group = test_datas[i].bad_type;
  3820. model.type_name = test_datas[i].op_no;
  3821. model.type_value = test_datas[i].bad_qty;
  3822. model.data_time = dateTimeNow;
  3823. models.Add(model);
  3824. }
  3825. _sqe_chart_data_temp.Insert(models);
  3826. String dataID = "";
  3827. if (models.Count > 0)
  3828. {
  3829. dataID = dateTimeNow.Ticks.ToString();
  3830. }
  3831. ResultViewModel result = ResultHelper.CreateResult(ResultCode.Success, dataID, ResultCode.Success, null);
  3832. return JsonConvert.SerializeObject(result);
  3833. }
  3834. catch (Exception ex)
  3835. {
  3836. ResultViewModel resultError = ResultHelper.CreateResult(ResultCode.BusinessError, "您选择的数据在统计中出现问题,请核对之后再进行操作!", ResultCode.BusinessError, null);
  3837. return JsonConvert.SerializeObject(resultError);
  3838. }
  3839. return null;
  3840. }
  3841. /// <summary>
  3842. /// 统计工序百分比
  3843. /// </summary>
  3844. /// <param name="startDate"></param>
  3845. /// <param name="endDate"></param>
  3846. /// <param name="item_no"></param>
  3847. /// <param name="item_batch"></param>
  3848. /// <param name="org"></param>
  3849. /// <param name="op"></param>
  3850. /// <returns></returns>
  3851. public string Compute_OpChartData_Date(string startDate, string endDate, string item_no, string item_batch, string org, string op)
  3852. {
  3853. try
  3854. {
  3855. #region 查询条件
  3856. // 动态条件
  3857. var conditions = new List<Expression<Func<v_sqe_op_data_detail, bool>>>();
  3858. if (!string.IsNullOrEmpty(startDate))
  3859. {
  3860. DateTime dateTime;
  3861. if (DateTime.TryParse(startDate, out dateTime))
  3862. {
  3863. // 添加条件1:Name 包含 "searchTerm"
  3864. conditions.Add(p => p.create_date >= dateTime);
  3865. }
  3866. }
  3867. if (!string.IsNullOrEmpty(endDate))
  3868. {
  3869. DateTime dateTime;
  3870. if (DateTime.TryParse(endDate, out dateTime))
  3871. {
  3872. // 添加条件1:Name 包含 "searchTerm"
  3873. conditions.Add(p => p.create_date <= dateTime);
  3874. }
  3875. }
  3876. if (!string.IsNullOrEmpty(item_no))
  3877. {
  3878. // 添加条件1:Name 包含 "searchTerm"
  3879. conditions.Add(p => p.item_no == item_no);
  3880. }
  3881. if (!string.IsNullOrEmpty(item_batch))
  3882. {
  3883. // 添加条件1:Name 包含 "searchTerm"
  3884. conditions.Add(p => p.batch_no == item_batch);
  3885. }
  3886. if (!string.IsNullOrEmpty(org))
  3887. {
  3888. // 添加条件1:Name 包含 "searchTerm"
  3889. conditions.Add(p => p.create_org == org);
  3890. }
  3891. if (!string.IsNullOrEmpty(op))
  3892. {
  3893. // 添加条件1:Name 包含 "searchTerm"
  3894. conditions.Add(p => p.op_no == op);
  3895. }
  3896. // 组合条件
  3897. var combinedCondition = PredicateBuilder.New<v_sqe_op_data_detail>();
  3898. //此处是所有的条件都and。
  3899. foreach (var condition in conditions)
  3900. {
  3901. combinedCondition = combinedCondition.And(condition);
  3902. }
  3903. var query = _v_sqe_op_data_detail.GetDbContext().v_sqe_op_data_detail.AsQueryable();
  3904. // 应用条件
  3905. if (conditions.Count > 0)
  3906. {
  3907. query = query.Where(combinedCondition);
  3908. }
  3909. #endregion 查询条件
  3910. // 分组统计,此处多个条件进行统计,p.bad_type, p.op_no
  3911. var groupBy = query.GroupBy(p => new { p.op_time, p.op_no })
  3912. .Select(g => new
  3913. {
  3914. op_time = g.Key.op_time,
  3915. op_no = g.Key.op_no,
  3916. qty_ok = g.Sum(p => p.qty_ok),
  3917. qty_all = g.Sum(p => p.qty_all),
  3918. percent = g.Sum(p => p.qty_ok) / g.Sum(p => p.qty_all)
  3919. });
  3920. //增加排序条件,此处多个条件,op_no,bad_type
  3921. var test_datas = groupBy.OrderBy(p => p.op_time).ThenBy(p => p.op_no).ToList();
  3922. //生成临时数据,插入数据库
  3923. List<sqe_chart_data_temp> models = new List<sqe_chart_data_temp>();
  3924. sqe_chart_data_temp model;
  3925. DateTime dateTimeNow = DateTime.Now;
  3926. for (int i = 0; i < test_datas.Count; i++)
  3927. {
  3928. model = new sqe_chart_data_temp();
  3929. model.data_id = dateTimeNow.Ticks;
  3930. model.sub_group = test_datas[i].op_time.Value.ToString("yyyy-MM-dd");
  3931. model.type_name = test_datas[i].op_no;
  3932. model.type_value = test_datas[i].percent;
  3933. model.data_time = dateTimeNow;
  3934. models.Add(model);
  3935. }
  3936. _sqe_chart_data_temp.Insert(models);
  3937. String dataID = "";
  3938. if (models.Count > 0)
  3939. {
  3940. dataID = dateTimeNow.Ticks.ToString();
  3941. }
  3942. ResultViewModel result = ResultHelper.CreateResult(ResultCode.Success, dataID, ResultCode.Success, null);
  3943. return JsonConvert.SerializeObject(result);
  3944. }
  3945. catch (Exception ex)
  3946. {
  3947. ResultViewModel resultError = ResultHelper.CreateResult(ResultCode.BusinessError, "您选择的数据在统计中出现问题,请核对之后再进行操作!", ResultCode.BusinessError, null);
  3948. return JsonConvert.SerializeObject(resultError);
  3949. }
  3950. return null;
  3951. }
  3952. public string Compute_FpyChartData(string startDate, string endDate, string item_no, string org, string op)
  3953. {
  3954. try
  3955. {
  3956. #region 查询条件
  3957. // 动态条件
  3958. var conditions = new List<Expression<Func<v_sqe_fpy_data, bool>>>();
  3959. if (!string.IsNullOrEmpty(startDate))
  3960. {
  3961. DateTime dateTime;
  3962. if (DateTime.TryParse(startDate, out dateTime))
  3963. {
  3964. // 添加条件1:Name 包含 "searchTerm"
  3965. conditions.Add(p => p.create_date >= dateTime);
  3966. }
  3967. }
  3968. if (!string.IsNullOrEmpty(endDate))
  3969. {
  3970. DateTime dateTime;
  3971. if (DateTime.TryParse(endDate, out dateTime))
  3972. {
  3973. // 添加条件1:Name 包含 "searchTerm"
  3974. conditions.Add(p => p.create_date <= dateTime);
  3975. }
  3976. }
  3977. if (!string.IsNullOrEmpty(item_no))
  3978. {
  3979. // 添加条件1:Name 包含 "searchTerm"
  3980. conditions.Add(p => p.item_no == item_no);
  3981. }
  3982. if (!string.IsNullOrEmpty(org))
  3983. {
  3984. // 添加条件1:Name 包含 "searchTerm"
  3985. conditions.Add(p => p.create_org == org);
  3986. }
  3987. if (!string.IsNullOrEmpty(op))
  3988. {
  3989. // 添加条件1:Name 包含 "searchTerm"
  3990. conditions.Add(p => p.op_no == op);
  3991. }
  3992. // 组合条件
  3993. var combinedCondition = PredicateBuilder.New<v_sqe_fpy_data>();
  3994. //此处是所有的条件都and。
  3995. foreach (var condition in conditions)
  3996. {
  3997. combinedCondition = combinedCondition.And(condition);
  3998. }
  3999. var query = _v_sqe_fpy_data.GetDbContext().v_sqe_fpy_data.AsQueryable();
  4000. // 应用条件
  4001. if (conditions.Count > 0)
  4002. {
  4003. query = query.Where(combinedCondition);
  4004. }
  4005. #endregion 查询条件
  4006. // 分组统计,此处多个条件进行统计,p.bad_type, p.op_no
  4007. var groupBy = query.GroupBy(p => new { p.op_no })
  4008. .Select(g => new
  4009. {
  4010. op_no = g.Key.op_no,
  4011. qty_error = g.Sum(p => p.qty_error),
  4012. qty_all = g.Sum(p => p.qty_all),
  4013. });
  4014. //增加排序条件,此处多个条件,op_no,bad_type
  4015. var test_datas = groupBy.OrderBy(p => p.op_no).ToList();
  4016. //生成临时数据,插入数据库
  4017. List<sqe_chart_data_temp> models = new List<sqe_chart_data_temp>();
  4018. sqe_chart_data_temp model;
  4019. DateTime dateTimeNow = DateTime.Now;
  4020. for (int i = 0; i < test_datas.Count; i++)
  4021. {
  4022. model = new sqe_chart_data_temp();
  4023. model.data_id = dateTimeNow.Ticks;
  4024. model.sub_group = "期间投入总数";
  4025. model.type_name = test_datas[i].op_no;
  4026. model.type_value = test_datas[i].qty_all;
  4027. model.data_time = dateTimeNow;
  4028. models.Add(model);
  4029. model = new sqe_chart_data_temp();
  4030. model.data_id = dateTimeNow.Ticks;
  4031. model.sub_group = "期间不良总数";
  4032. model.type_name = test_datas[i].op_no;
  4033. model.type_value = test_datas[i].qty_error;
  4034. model.data_time = dateTimeNow;
  4035. models.Add(model);
  4036. model = new sqe_chart_data_temp();
  4037. model.data_id = dateTimeNow.Ticks;
  4038. model.sub_group = "良率";
  4039. model.type_name = test_datas[i].op_no;
  4040. model.type_value = (1 - test_datas[i].qty_error / test_datas[i].qty_all);
  4041. model.data_time = dateTimeNow;
  4042. models.Add(model);
  4043. }
  4044. _sqe_chart_data_temp.Insert(models);
  4045. String dataID = "";
  4046. if (models.Count > 0)
  4047. {
  4048. dataID = dateTimeNow.Ticks.ToString();
  4049. }
  4050. ResultViewModel result = ResultHelper.CreateResult(ResultCode.Success, dataID, ResultCode.Success, null);
  4051. return JsonConvert.SerializeObject(result);
  4052. }
  4053. catch (Exception ex)
  4054. {
  4055. ResultViewModel resultError = ResultHelper.CreateResult(ResultCode.BusinessError, "您选择的数据在统计中出现问题,请核对之后再进行操作!", ResultCode.BusinessError, null);
  4056. return JsonConvert.SerializeObject(resultError);
  4057. }
  4058. return null;
  4059. }
  4060. public string Compute_FpyChartData_Date(string startDate, string endDate, string item_no, string org, string op)
  4061. {
  4062. try
  4063. {
  4064. #region 查询条件
  4065. // 动态条件
  4066. var conditions = new List<Expression<Func<v_sqe_fpy_data, bool>>>();
  4067. if (!string.IsNullOrEmpty(startDate))
  4068. {
  4069. DateTime dateTime;
  4070. if (DateTime.TryParse(startDate, out dateTime))
  4071. {
  4072. // 添加条件1:Name 包含 "searchTerm"
  4073. conditions.Add(p => p.create_date >= dateTime);
  4074. }
  4075. }
  4076. if (!string.IsNullOrEmpty(endDate))
  4077. {
  4078. DateTime dateTime;
  4079. if (DateTime.TryParse(endDate, out dateTime))
  4080. {
  4081. // 添加条件1:Name 包含 "searchTerm"
  4082. conditions.Add(p => p.create_date <= dateTime);
  4083. }
  4084. }
  4085. if (!string.IsNullOrEmpty(item_no))
  4086. {
  4087. // 添加条件1:Name 包含 "searchTerm"
  4088. conditions.Add(p => p.item_no == item_no);
  4089. }
  4090. if (!string.IsNullOrEmpty(org))
  4091. {
  4092. // 添加条件1:Name 包含 "searchTerm"
  4093. conditions.Add(p => p.create_org == org);
  4094. }
  4095. if (!string.IsNullOrEmpty(op))
  4096. {
  4097. // 添加条件1:Name 包含 "searchTerm"
  4098. conditions.Add(p => p.op_no == op);
  4099. }
  4100. // 组合条件
  4101. var combinedCondition = PredicateBuilder.New<v_sqe_fpy_data>();
  4102. //此处是所有的条件都and。
  4103. foreach (var condition in conditions)
  4104. {
  4105. combinedCondition = combinedCondition.And(condition);
  4106. }
  4107. var query = _v_sqe_fpy_data.GetDbContext().v_sqe_fpy_data.AsQueryable();
  4108. // 应用条件
  4109. if (conditions.Count > 0)
  4110. {
  4111. query = query.Where(combinedCondition);
  4112. }
  4113. #endregion 查询条件
  4114. // 分组统计,此处多个条件进行统计,p.bad_type, p.op_no
  4115. var groupBy = query.GroupBy(p => new { p.op_time })
  4116. .Select(g => new
  4117. {
  4118. op_time = g.Key.op_time,
  4119. qty_error = g.Sum(p => p.qty_error),
  4120. qty_all = g.Sum(p => p.qty_all)
  4121. });
  4122. //增加排序条件,此处多个条件,op_no,bad_type
  4123. var test_datas = groupBy.OrderBy(p => p.op_time).ToList();
  4124. //生成临时数据,插入数据库
  4125. List<sqe_chart_data_temp> models = new List<sqe_chart_data_temp>();
  4126. sqe_chart_data_temp model;
  4127. DateTime dateTimeNow = DateTime.Now;
  4128. for (int i = 0; i < test_datas.Count; i++)
  4129. {
  4130. model = new sqe_chart_data_temp();
  4131. model.data_id = dateTimeNow.Ticks;
  4132. model.sub_group = test_datas[i].op_time.Value.ToString("MM-dd");
  4133. model.type_name = "走势图";
  4134. model.type_value = (1 - test_datas[i].qty_error / test_datas[i].qty_all);
  4135. model.data_time = dateTimeNow;
  4136. models.Add(model);
  4137. }
  4138. _sqe_chart_data_temp.Insert(models);
  4139. String dataID = "";
  4140. if (models.Count > 0)
  4141. {
  4142. dataID = dateTimeNow.Ticks.ToString();
  4143. }
  4144. ResultViewModel result = ResultHelper.CreateResult(ResultCode.Success, dataID, ResultCode.Success, null);
  4145. return JsonConvert.SerializeObject(result);
  4146. }
  4147. catch (Exception ex)
  4148. {
  4149. ResultViewModel resultError = ResultHelper.CreateResult(ResultCode.BusinessError, "您选择的数据在统计中出现问题,请核对之后再进行操作!", ResultCode.BusinessError, null);
  4150. return JsonConvert.SerializeObject(resultError);
  4151. }
  4152. return null;
  4153. }
  4154. /// <summary>
  4155. /// 已经查询条件,统计Oqc数据
  4156. /// </summary>
  4157. /// <param name="startDate"></param>
  4158. /// <param name="endDate"></param>
  4159. /// <param name="item_no"></param>
  4160. /// <param name="org"></param>
  4161. /// <returns></returns>
  4162. public string Compute_OqcChartData(string startDate, string endDate, string item_no, string org)
  4163. {
  4164. try
  4165. {
  4166. //增加排序条件,此处多个条件,op_no,bad_type
  4167. var test_datas = Get_OqcData(startDate, endDate, item_no, org, null);
  4168. //生成临时数据,插入数据库
  4169. List<sqe_chart_data_temp> models = new List<sqe_chart_data_temp>();
  4170. sqe_chart_data_temp model;
  4171. DateTime dateTimeNow = DateTime.Now;
  4172. //生成临时数据,插入数据库
  4173. sqe_oqc_statistics modelStatistics;
  4174. string standard_no = "";
  4175. for (int i = 0; i < test_datas.Count;)
  4176. {
  4177. standard_no = test_datas[i].standard_no;
  4178. if (standard_no == null)
  4179. {
  4180. i++;
  4181. continue;
  4182. }
  4183. List<Double> dataList = new List<double>();
  4184. int j = i;
  4185. for (; j < test_datas.Count; j++)
  4186. {
  4187. if (standard_no.CompareTo(test_datas[j].standard_no) == 0)
  4188. {
  4189. dataList.Add((double)test_datas[j].data_value);
  4190. }
  4191. else
  4192. {
  4193. break;
  4194. }
  4195. }
  4196. Double[] datas = dataList.ToArray();
  4197. modelStatistics = new sqe_oqc_statistics();
  4198. try
  4199. {
  4200. modelStatistics.standard_no = standard_no;
  4201. modelStatistics.value_avg = (decimal)datas.Average();
  4202. modelStatistics.value_std_range = (decimal)datas.StandardDeviation();
  4203. if (modelStatistics.value_std_range != 0)
  4204. {
  4205. modelStatistics.value_pp = (test_datas[i].standard_max - test_datas[i].standard_min) / modelStatistics.value_std_range;
  4206. if (modelStatistics.value_pp > 100000)
  4207. {
  4208. modelStatistics.value_pp = 100000;
  4209. }
  4210. }
  4211. else
  4212. {
  4213. i = j;
  4214. continue;
  4215. }
  4216. //=MIN((B10-Q53)/(3*R53),(Q53-B11)/(3*R53))
  4217. decimal d1, d2;
  4218. d1 = (test_datas[i].standard_max - modelStatistics.value_avg) / 3 * modelStatistics.value_std_range;
  4219. d2 = (modelStatistics.value_avg - test_datas[i].standard_min) / 3 * modelStatistics.value_std_range;
  4220. modelStatistics.value_ppk = d1 > d2 ? d2 : d1;
  4221. modelStatistics.value_max = (decimal)datas.Max();
  4222. modelStatistics.value_min = (decimal)datas.Min();
  4223. modelStatistics.value_range = modelStatistics.value_max - modelStatistics.value_min;
  4224. }
  4225. catch (Exception ex)
  4226. {
  4227. i = j;
  4228. continue;
  4229. }
  4230. model = new sqe_chart_data_temp();
  4231. model.data_id = dateTimeNow.Ticks;
  4232. model.sub_group = "均值";
  4233. model.type_name = standard_no;
  4234. model.type_value = modelStatistics.value_avg;
  4235. model.data_time = dateTimeNow;
  4236. models.Add(model);
  4237. Console.WriteLine(model.type_value);
  4238. model = new sqe_chart_data_temp();
  4239. model.data_id = dateTimeNow.Ticks;
  4240. model.sub_group = "西格玛(标准差)";
  4241. model.type_name = standard_no;
  4242. model.type_value = modelStatistics.value_std_range;
  4243. model.data_time = dateTimeNow;
  4244. models.Add(model);
  4245. Console.WriteLine(model.type_value);
  4246. model = new sqe_chart_data_temp();
  4247. model.data_id = dateTimeNow.Ticks;
  4248. model.sub_group = "PP";
  4249. model.type_name = standard_no;
  4250. model.type_value = modelStatistics.value_pp;
  4251. model.data_time = dateTimeNow;
  4252. models.Add(model);
  4253. Console.WriteLine(model.type_value);
  4254. model = new sqe_chart_data_temp();
  4255. model.data_id = dateTimeNow.Ticks;
  4256. model.sub_group = "PPK";
  4257. model.type_name = standard_no;
  4258. model.type_value = modelStatistics.value_ppk;
  4259. model.data_time = dateTimeNow;
  4260. models.Add(model);
  4261. Console.WriteLine(model.type_value);
  4262. model = new sqe_chart_data_temp();
  4263. model.data_id = dateTimeNow.Ticks;
  4264. model.sub_group = "Max";
  4265. model.type_name = standard_no;
  4266. model.type_value = modelStatistics.value_max;
  4267. model.data_time = dateTimeNow;
  4268. models.Add(model);
  4269. Console.WriteLine(model.type_value);
  4270. model = new sqe_chart_data_temp();
  4271. model.data_id = dateTimeNow.Ticks;
  4272. model.sub_group = "Min";
  4273. model.type_name = standard_no;
  4274. model.type_value = modelStatistics.value_min;
  4275. model.data_time = dateTimeNow;
  4276. models.Add(model);
  4277. Console.WriteLine(model.type_value);
  4278. model = new sqe_chart_data_temp();
  4279. model.data_id = dateTimeNow.Ticks;
  4280. model.sub_group = "极差(Max-Min)";
  4281. model.type_name = standard_no;
  4282. model.type_value = modelStatistics.value_range;
  4283. model.data_time = dateTimeNow;
  4284. models.Add(model);
  4285. Console.WriteLine(model.type_value);
  4286. i = j;
  4287. }
  4288. _sqe_chart_data_temp.Insert(models);
  4289. String dataID = "";
  4290. if (models.Count > 0)
  4291. {
  4292. dataID = dateTimeNow.Ticks.ToString();
  4293. }
  4294. ResultViewModel result = ResultHelper.CreateResult(ResultCode.Success, dataID, ResultCode.Success, null);
  4295. return JsonConvert.SerializeObject(result);
  4296. }
  4297. catch (Exception ex)
  4298. {
  4299. ResultViewModel resultError = ResultHelper.CreateResult(ResultCode.BusinessError, "您选择的数据在统计中出现问题,请核对之后再进行操作!", ResultCode.BusinessError, null);
  4300. return JsonConvert.SerializeObject(resultError);
  4301. }
  4302. return null;
  4303. }
  4304. /// <summary>
  4305. /// 查询Oqc的数据信息
  4306. /// </summary>
  4307. /// <param name="startDate"></param>
  4308. /// <param name="endDate"></param>
  4309. /// <param name="item_no"></param>
  4310. /// <param name="org"></param>
  4311. /// <param name="standard_no"></param>
  4312. /// <returns></returns>
  4313. public List<v_sqe_oqc_data> Get_OqcData(string startDate, string endDate, string item_no, string org, string standard_no)
  4314. {
  4315. try
  4316. {
  4317. #region 查询条件
  4318. // 动态条件
  4319. var conditions = new List<Expression<Func<v_sqe_oqc_data, bool>>>();
  4320. if (!string.IsNullOrEmpty(startDate))
  4321. {
  4322. DateTime dateTime;
  4323. if (DateTime.TryParse(startDate, out dateTime))
  4324. {
  4325. // 添加条件1:Name 包含 "searchTerm"
  4326. conditions.Add(p => p.product_time >= dateTime);
  4327. }
  4328. }
  4329. if (!string.IsNullOrEmpty(endDate))
  4330. {
  4331. DateTime dateTime;
  4332. if (DateTime.TryParse(endDate, out dateTime))
  4333. {
  4334. // 添加条件1:Name 包含 "searchTerm"
  4335. conditions.Add(p => p.product_time <= dateTime);
  4336. }
  4337. }
  4338. if (!string.IsNullOrEmpty(item_no))
  4339. {
  4340. // 添加条件1:Name 包含 "searchTerm"
  4341. conditions.Add(p => p.item_no == item_no);
  4342. }
  4343. if (!string.IsNullOrEmpty(org))
  4344. {
  4345. // 添加条件1:Name 包含 "searchTerm"
  4346. conditions.Add(p => p.create_org == org);
  4347. }
  4348. if (!string.IsNullOrEmpty(standard_no))
  4349. {
  4350. // 添加条件1:Name 包含 "searchTerm"
  4351. conditions.Add(p => p.standard_no == standard_no);
  4352. }
  4353. // 组合条件
  4354. var combinedCondition = PredicateBuilder.New<v_sqe_oqc_data>();
  4355. //此处是所有的条件都and。
  4356. foreach (var condition in conditions)
  4357. {
  4358. combinedCondition = combinedCondition.And(condition);
  4359. }
  4360. var query = _v_sqe_oqc_data.GetDbContext().v_sqe_oqc_data.AsQueryable();
  4361. // 应用条件
  4362. if (conditions.Count > 0)
  4363. {
  4364. query = query.Where(combinedCondition);
  4365. }
  4366. #endregion 查询条件
  4367. //增加排序条件,此处多个条件,op_no,bad_type
  4368. var test_datas = query.OrderBy(p => p.standard_no).DefaultIfEmpty().ToList();
  4369. return test_datas;
  4370. }
  4371. catch (Exception ex)
  4372. {
  4373. }
  4374. return null;
  4375. }
  4376. }
  4377. }