SqeExcelService.cs 204 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731
  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. ResultViewModel result = ResultHelper.CreateResult(ResultCode.Success, dateTimeNow.Ticks.ToString(), ResultCode.Success, null);
  3433. return JsonConvert.SerializeObject(result);
  3434. }
  3435. catch (Exception ex)
  3436. {
  3437. ResultViewModel resultError = ResultHelper.CreateResult(ResultCode.BusinessError, "您选择数据中的采样数有问题,请核对之后再进行操作!", ResultCode.BusinessError, null);
  3438. return JsonConvert.SerializeObject(resultError);
  3439. }
  3440. }
  3441. /// <summary>
  3442. /// 依据查询统计条件,生成该时间段内的均值和极差
  3443. /// 依据均值和极差,再次生成统计对象
  3444. /// </summary>
  3445. /// <param name="startDate"></param>
  3446. /// <param name="endDate"></param>
  3447. /// <param name="item_no"></param>
  3448. /// <param name="item_batch"></param>
  3449. /// <param name="org"></param>
  3450. /// <param name="standard_no"></param>
  3451. /// <param name="sample_count"></param>
  3452. /// <returns></returns>
  3453. public string Compute_Test(string startDate, string endDate, string item_no, string item_batch, string org, string standard_no, int sample_count)
  3454. {
  3455. try
  3456. {
  3457. // 依据查询条件,获取用户上传的CTO产品特性数据
  3458. List<v_sqe_cto_test_data> test_datas = Get_TestData(startDate, endDate, item_no, item_batch, org, standard_no);
  3459. if (test_datas == null || test_datas.Count == 0)
  3460. {
  3461. ResultViewModel resultError = ResultHelper.CreateResult(ResultCode.BusinessError, "您的查询条件没有查询到数据可能有问题,请核对之后再进行操作!", ResultCode.BusinessError, null);
  3462. return JsonConvert.SerializeObject(resultError);
  3463. }
  3464. //int sample_count = test_datas != null && test_datas.Count > 0 ? test_datas[0].sampling_count : -1;
  3465. //if (sample_count == -1)
  3466. //{
  3467. // ResultViewModel resultError = ResultHelper.CreateResult(ResultCode.BusinessError, "您选择数据中的采样数有问题,请核对之后再进行操作!", ResultCode.BusinessError, null);
  3468. // return JsonConvert.SerializeObject(resultError);
  3469. //}
  3470. //所有的检测数据,按照进行采样数进行归一
  3471. double[] dataAll = null;
  3472. //均值数据
  3473. double[] dataAvg = null;
  3474. //极差数据
  3475. double[] dataRange = null;
  3476. //计算均值与极差
  3477. Get_TestAvgRange(test_datas, sample_count, out dataAll, out dataAvg, out dataRange);
  3478. decimal a2 = (decimal)GetA2(sample_count);
  3479. decimal d2 = (decimal)GetD2(sample_count);
  3480. decimal d3 = (decimal)GetD3(sample_count);
  3481. decimal d4 = (decimal)GetD4(sample_count);
  3482. //开始计算统计结果
  3483. sqe_cto_test_statistics model = new sqe_cto_test_statistics();
  3484. model.standard_no = standard_no;
  3485. model.value_count = test_datas.Count;
  3486. model.standard_min = test_datas[0].standard_min;
  3487. model.standard_max = test_datas[0].standard_max;
  3488. model.standard_value = (model.standard_min + model.standard_max) / 2;
  3489. model.value_sum = (decimal)dataAll.Sum();
  3490. model.value_avg = (decimal)dataAll.Average();
  3491. model.value_max = (decimal)dataAll.Max();
  3492. model.value_min = (decimal)dataAll.Min();
  3493. model.value_below = dataAll.Count(x => x < (double)model.standard_min);
  3494. model.value_above = dataAll.Count(x => x > (double)model.standard_max);
  3495. model.avg_range = (decimal)dataRange.Average();
  3496. model.value_d2 = d2;
  3497. model.value_cpu = (model.standard_max - model.value_avg) / (3 * model.avg_range / model.value_d2);
  3498. model.value_cpl = (model.value_avg - model.standard_min) / (3 * model.avg_range / model.value_d2);
  3499. model.value_cp = (model.standard_max - model.standard_min) / (6 * model.avg_range / model.value_d2);
  3500. model.value_cpk = model.value_cpu < model.value_cpl ? model.value_cpu : model.value_cpl;
  3501. model.value_cr = (decimal)1.0 / model.value_cp;
  3502. model.value_stdev = (decimal)dataAll.StandardDeviation();
  3503. model.value_stdevp = (decimal)dataAll.PopulationStandardDeviation();
  3504. model.value_var = (decimal)dataAll.Variance();
  3505. model.value_varp = (decimal)dataAll.PopulationVariance();
  3506. model.value_pp = (model.standard_max - model.standard_min) / (6 * model.value_stdev);
  3507. model.value_ppu = (model.standard_max - model.value_avg) / (3 * model.value_stdev);
  3508. model.value_ppl = (model.value_avg - model.standard_min) / (3 * model.value_stdev);
  3509. model.value_ppk = model.value_ppu < model.value_ppl ? model.value_ppu : model.value_ppl;
  3510. ResultViewModel result = ResultHelper.CreateResult(ResultCode.Success, model, ResultCode.Success, null);
  3511. return JsonConvert.SerializeObject(result);
  3512. }
  3513. catch (Exception ex)
  3514. {
  3515. ResultViewModel resultError = ResultHelper.CreateResult(ResultCode.BusinessError, "您选择数据中的采样数有问题,请核对之后再进行操作!", ResultCode.BusinessError, null);
  3516. return JsonConvert.SerializeObject(resultError);
  3517. }
  3518. }
  3519. /// <summary>
  3520. /// 依据查询条件,查询用户上传的CTO产品特性数据
  3521. /// </summary>
  3522. /// <param name="startDate"></param>
  3523. /// <param name="endDate"></param>
  3524. /// <param name="item_no"></param>
  3525. /// <param name="item_batch"></param>
  3526. /// <param name="org"></param>
  3527. /// <param name="standard_no"></param>
  3528. /// <returns></returns>
  3529. public List<v_sqe_cto_test_data> Get_TestData(string startDate, string endDate,
  3530. string item_no, string item_batch,
  3531. string org, string standard_no)
  3532. {
  3533. try
  3534. {
  3535. #region 查询条件
  3536. // 动态条件
  3537. var conditions = new List<Expression<Func<v_sqe_cto_test_data, bool>>>();
  3538. conditions.Add(p => p.data_value != null);
  3539. if (!string.IsNullOrEmpty(startDate))
  3540. {
  3541. DateTime dateTime;
  3542. if (DateTime.TryParse(startDate, out dateTime))
  3543. {
  3544. // 添加条件1:Name 包含 "searchTerm"
  3545. conditions.Add(p => p.create_date >= dateTime);
  3546. }
  3547. }
  3548. if (!string.IsNullOrEmpty(endDate))
  3549. {
  3550. DateTime dateTime;
  3551. if (DateTime.TryParse(endDate, out dateTime))
  3552. {
  3553. // 添加条件1:Name 包含 "searchTerm"
  3554. conditions.Add(p => p.create_date <= dateTime);
  3555. }
  3556. }
  3557. if (!string.IsNullOrEmpty(item_no))
  3558. {
  3559. // 添加条件1:Name 包含 "searchTerm"
  3560. conditions.Add(p => p.item_no == item_no);
  3561. }
  3562. if (!string.IsNullOrEmpty(item_batch))
  3563. {
  3564. // 添加条件1:Name 包含 "searchTerm"
  3565. conditions.Add(p => p.item_batch == item_batch);
  3566. }
  3567. if (!string.IsNullOrEmpty(org))
  3568. {
  3569. // 添加条件1:Name 包含 "searchTerm"
  3570. conditions.Add(p => p.create_org == org);
  3571. }
  3572. if (!string.IsNullOrEmpty(standard_no))
  3573. {
  3574. // 添加条件1:Name 包含 "searchTerm"
  3575. conditions.Add(p => p.standard_no == standard_no);
  3576. }
  3577. // 组合条件
  3578. var combinedCondition = PredicateBuilder.New<v_sqe_cto_test_data>();
  3579. foreach (var condition in conditions)
  3580. {
  3581. combinedCondition = combinedCondition.And(condition);
  3582. }
  3583. var query = _v_sqe_cto_test_data.GetDbContext().v_sqe_cto_test_data.AsQueryable();
  3584. // 应用条件
  3585. if (combinedCondition.Body != null)
  3586. {
  3587. query = query.Where(combinedCondition);
  3588. }
  3589. #endregion 查询条件
  3590. // 执行查询
  3591. List<v_sqe_cto_test_data> test_datas = query.DefaultIfEmpty().ToList();
  3592. return test_datas;
  3593. }
  3594. catch (Exception ex)
  3595. {
  3596. return null;
  3597. }
  3598. }
  3599. /// <summary>
  3600. /// 依据CTO产品特性数据,采样数,统计均值与极差
  3601. /// </summary>
  3602. /// <param name="datas"></param>
  3603. /// <param name="sample_count"></param>
  3604. /// <param name="dataAll"></param>
  3605. /// <param name="dataAvg"></param>
  3606. /// <param name="dataRange"></param>
  3607. public void Get_TestAvgRange(List<v_sqe_cto_test_data> datas, int sample_count, out double[] dataAll, out double[] dataAvg, out double[] dataRange)
  3608. {
  3609. //所有的检测数据,按照进行采样数进行归一
  3610. dataAll = new double[datas.Count / sample_count * sample_count];
  3611. //均值数据
  3612. dataAvg = new double[datas.Count / sample_count];
  3613. //极差数据
  3614. dataRange = new double[datas.Count / sample_count];
  3615. //计算极差与均值时的临时数据
  3616. double[] data = new double[sample_count];
  3617. //计算所有的均值与极差
  3618. for (int i = 0; i <= datas.Count - sample_count; i += sample_count)
  3619. {
  3620. for (int j = 0; j < sample_count; j++)
  3621. {
  3622. data[j] = (double)datas[i + j].data_value.Value;
  3623. dataAll[i + j] = data[j];
  3624. }
  3625. dataRange[i / sample_count] = data.Max() - data.Min();
  3626. }
  3627. }
  3628. /// <summary>
  3629. /// 依据查询条件,统计工序的不良情况
  3630. /// </summary>
  3631. /// <param name="startDate"></param>
  3632. /// <param name="endDate"></param>
  3633. /// <param name="item_no"></param>
  3634. /// <param name="item_batch"></param>
  3635. /// <param name="org"></param>
  3636. /// <returns></returns>
  3637. public string Compute_op_query(string startDate, string endDate, string item_no, string item_batch, string org, string op, string bad_type)
  3638. {
  3639. try
  3640. {
  3641. #region 查询条件
  3642. // 动态条件
  3643. var conditions = new List<Expression<Func<v_sqe_op_data_detail, bool>>>();
  3644. if (!string.IsNullOrEmpty(startDate))
  3645. {
  3646. DateTime dateTime;
  3647. if (DateTime.TryParse(startDate, out dateTime))
  3648. {
  3649. // 添加条件1:Name 包含 "searchTerm"
  3650. conditions.Add(p => p.create_date >= dateTime);
  3651. }
  3652. }
  3653. if (!string.IsNullOrEmpty(endDate))
  3654. {
  3655. DateTime dateTime;
  3656. if (DateTime.TryParse(endDate, out dateTime))
  3657. {
  3658. // 添加条件1:Name 包含 "searchTerm"
  3659. conditions.Add(p => p.create_date <= dateTime);
  3660. }
  3661. }
  3662. if (!string.IsNullOrEmpty(item_no))
  3663. {
  3664. // 添加条件1:Name 包含 "searchTerm"
  3665. conditions.Add(p => p.item_no == item_no);
  3666. }
  3667. if (!string.IsNullOrEmpty(item_batch))
  3668. {
  3669. // 添加条件1:Name 包含 "searchTerm"
  3670. conditions.Add(p => p.batch_no == item_batch);
  3671. }
  3672. if (!string.IsNullOrEmpty(org))
  3673. {
  3674. // 添加条件1:Name 包含 "searchTerm"
  3675. conditions.Add(p => p.create_org == org);
  3676. }
  3677. if (!string.IsNullOrEmpty(op))
  3678. {
  3679. // 添加条件1:Name 包含 "searchTerm"
  3680. conditions.Add(p => p.op_no == op);
  3681. }
  3682. if (!string.IsNullOrEmpty(bad_type))
  3683. {
  3684. // 添加条件1:Name 包含 "searchTerm"
  3685. conditions.Add(p => p.bad_type == bad_type);
  3686. }
  3687. // 组合条件
  3688. var combinedCondition = PredicateBuilder.New<v_sqe_op_data_detail>();
  3689. //此处是所有的条件都and。
  3690. foreach (var condition in conditions)
  3691. {
  3692. combinedCondition = combinedCondition.And(condition);
  3693. }
  3694. var query = _v_sqe_op_data_detail.GetDbContext().v_sqe_op_data_detail.AsQueryable();
  3695. // 应用条件
  3696. if (conditions.Count > 0)
  3697. {
  3698. query = query.Where(combinedCondition);
  3699. }
  3700. #endregion 查询条件
  3701. // 分组统计,此处多个条件进行统计,p.bad_type, p.op_no
  3702. var groupBy = query.GroupBy(p => new { p.bad_type, p.op_no })
  3703. .Select(g => new
  3704. {
  3705. bad_type = g.Key.bad_type,
  3706. op_no = g.Key.op_no,
  3707. bad_qty = g.Sum(p => p.bad_qty)
  3708. });
  3709. //增加排序条件,此处多个条件,op_no,bad_type
  3710. var test_datas = groupBy.OrderBy(p => p.op_no).ThenBy(p => p.bad_type).ToList();
  3711. ResultViewModel result = ResultHelper.CreateResult(ResultCode.Success, test_datas, ResultCode.Success, null);
  3712. return JsonConvert.SerializeObject(result);
  3713. }
  3714. catch (Exception ex)
  3715. {
  3716. ResultViewModel resultError = ResultHelper.CreateResult(ResultCode.BusinessError, "您选择的数据在统计中出现问题,请核对之后再进行操作!", ResultCode.BusinessError, null);
  3717. return JsonConvert.SerializeObject(resultError);
  3718. }
  3719. return null;
  3720. }
  3721. /// <summary>
  3722. /// 工序统计图
  3723. /// </summary>
  3724. /// <param name="startDate"></param>
  3725. /// <param name="endDate"></param>
  3726. /// <param name="item_no"></param>
  3727. /// <param name="item_batch"></param>
  3728. /// <param name="org"></param>
  3729. /// <param name="op"></param>
  3730. /// <param name="bad_type"></param>
  3731. /// <returns></returns>
  3732. public string Compute_OpChartData(string startDate, string endDate, string item_no, string item_batch, string org, string op, string bad_type)
  3733. {
  3734. try
  3735. {
  3736. #region 查询条件
  3737. // 动态条件
  3738. var conditions = new List<Expression<Func<v_sqe_op_data_detail, bool>>>();
  3739. if (!string.IsNullOrEmpty(startDate))
  3740. {
  3741. DateTime dateTime;
  3742. if (DateTime.TryParse(startDate, out dateTime))
  3743. {
  3744. // 添加条件1:Name 包含 "searchTerm"
  3745. conditions.Add(p => p.create_date >= dateTime);
  3746. }
  3747. }
  3748. if (!string.IsNullOrEmpty(endDate))
  3749. {
  3750. DateTime dateTime;
  3751. if (DateTime.TryParse(endDate, out dateTime))
  3752. {
  3753. // 添加条件1:Name 包含 "searchTerm"
  3754. conditions.Add(p => p.create_date <= dateTime);
  3755. }
  3756. }
  3757. if (!string.IsNullOrEmpty(item_no))
  3758. {
  3759. // 添加条件1:Name 包含 "searchTerm"
  3760. conditions.Add(p => p.item_no == item_no);
  3761. }
  3762. if (!string.IsNullOrEmpty(item_batch))
  3763. {
  3764. // 添加条件1:Name 包含 "searchTerm"
  3765. conditions.Add(p => p.batch_no == item_batch);
  3766. }
  3767. if (!string.IsNullOrEmpty(org))
  3768. {
  3769. // 添加条件1:Name 包含 "searchTerm"
  3770. conditions.Add(p => p.create_org == org);
  3771. }
  3772. if (!string.IsNullOrEmpty(op))
  3773. {
  3774. // 添加条件1:Name 包含 "searchTerm"
  3775. conditions.Add(p => p.op_no == op);
  3776. }
  3777. if (!string.IsNullOrEmpty(bad_type))
  3778. {
  3779. // 添加条件1:Name 包含 "searchTerm"
  3780. conditions.Add(p => p.bad_type == bad_type);
  3781. }
  3782. // 组合条件
  3783. var combinedCondition = PredicateBuilder.New<v_sqe_op_data_detail>();
  3784. //此处是所有的条件都and。
  3785. foreach (var condition in conditions)
  3786. {
  3787. combinedCondition = combinedCondition.And(condition);
  3788. }
  3789. var query = _v_sqe_op_data_detail.GetDbContext().v_sqe_op_data_detail.AsQueryable();
  3790. // 应用条件
  3791. if (conditions.Count > 0)
  3792. {
  3793. query = query.Where(combinedCondition);
  3794. }
  3795. #endregion 查询条件
  3796. // 分组统计,此处多个条件进行统计,p.bad_type, p.op_no
  3797. var groupBy = query.GroupBy(p => new { p.bad_type, p.op_no })
  3798. .Select(g => new
  3799. {
  3800. bad_type = g.Key.bad_type,
  3801. op_no = g.Key.op_no,
  3802. bad_qty = g.Sum(p => p.bad_qty)
  3803. });
  3804. //增加排序条件,此处多个条件,op_no,bad_type
  3805. var test_datas = groupBy.OrderBy(p => p.op_no).ThenBy(p => p.bad_type).ToList();
  3806. //生成临时数据,插入数据库
  3807. List<sqe_chart_data_temp> models = new List<sqe_chart_data_temp>();
  3808. sqe_chart_data_temp model;
  3809. DateTime dateTimeNow = DateTime.Now;
  3810. for (int i = 0; i < test_datas.Count; i++)
  3811. {
  3812. model = new sqe_chart_data_temp();
  3813. model.data_id = dateTimeNow.Ticks;
  3814. model.sub_group = test_datas[i].bad_type;
  3815. model.type_name = test_datas[i].op_no;
  3816. model.type_value = test_datas[i].bad_qty;
  3817. model.data_time = dateTimeNow;
  3818. models.Add(model);
  3819. }
  3820. _sqe_chart_data_temp.Insert(models);
  3821. ResultViewModel result = ResultHelper.CreateResult(ResultCode.Success, dateTimeNow.Ticks.ToString(), ResultCode.Success, null);
  3822. return JsonConvert.SerializeObject(result);
  3823. }
  3824. catch (Exception ex)
  3825. {
  3826. ResultViewModel resultError = ResultHelper.CreateResult(ResultCode.BusinessError, "您选择的数据在统计中出现问题,请核对之后再进行操作!", ResultCode.BusinessError, null);
  3827. return JsonConvert.SerializeObject(resultError);
  3828. }
  3829. return null;
  3830. }
  3831. /// <summary>
  3832. /// 统计工序百分比
  3833. /// </summary>
  3834. /// <param name="startDate"></param>
  3835. /// <param name="endDate"></param>
  3836. /// <param name="item_no"></param>
  3837. /// <param name="item_batch"></param>
  3838. /// <param name="org"></param>
  3839. /// <param name="op"></param>
  3840. /// <returns></returns>
  3841. public string Compute_OpChartData_Date(string startDate, string endDate, string item_no, string item_batch, string org, string op)
  3842. {
  3843. try
  3844. {
  3845. #region 查询条件
  3846. // 动态条件
  3847. var conditions = new List<Expression<Func<v_sqe_op_data_detail, bool>>>();
  3848. if (!string.IsNullOrEmpty(startDate))
  3849. {
  3850. DateTime dateTime;
  3851. if (DateTime.TryParse(startDate, out dateTime))
  3852. {
  3853. // 添加条件1:Name 包含 "searchTerm"
  3854. conditions.Add(p => p.create_date >= dateTime);
  3855. }
  3856. }
  3857. if (!string.IsNullOrEmpty(endDate))
  3858. {
  3859. DateTime dateTime;
  3860. if (DateTime.TryParse(endDate, out dateTime))
  3861. {
  3862. // 添加条件1:Name 包含 "searchTerm"
  3863. conditions.Add(p => p.create_date <= dateTime);
  3864. }
  3865. }
  3866. if (!string.IsNullOrEmpty(item_no))
  3867. {
  3868. // 添加条件1:Name 包含 "searchTerm"
  3869. conditions.Add(p => p.item_no == item_no);
  3870. }
  3871. if (!string.IsNullOrEmpty(item_batch))
  3872. {
  3873. // 添加条件1:Name 包含 "searchTerm"
  3874. conditions.Add(p => p.batch_no == item_batch);
  3875. }
  3876. if (!string.IsNullOrEmpty(org))
  3877. {
  3878. // 添加条件1:Name 包含 "searchTerm"
  3879. conditions.Add(p => p.create_org == org);
  3880. }
  3881. if (!string.IsNullOrEmpty(op))
  3882. {
  3883. // 添加条件1:Name 包含 "searchTerm"
  3884. conditions.Add(p => p.op_no == op);
  3885. }
  3886. // 组合条件
  3887. var combinedCondition = PredicateBuilder.New<v_sqe_op_data_detail>();
  3888. //此处是所有的条件都and。
  3889. foreach (var condition in conditions)
  3890. {
  3891. combinedCondition = combinedCondition.And(condition);
  3892. }
  3893. var query = _v_sqe_op_data_detail.GetDbContext().v_sqe_op_data_detail.AsQueryable();
  3894. // 应用条件
  3895. if (conditions.Count > 0)
  3896. {
  3897. query = query.Where(combinedCondition);
  3898. }
  3899. #endregion 查询条件
  3900. // 分组统计,此处多个条件进行统计,p.bad_type, p.op_no
  3901. var groupBy = query.GroupBy(p => new { p.op_time, p.op_no })
  3902. .Select(g => new
  3903. {
  3904. op_time = g.Key.op_time,
  3905. op_no = g.Key.op_no,
  3906. qty_ok = g.Sum(p => p.qty_ok),
  3907. qty_all = g.Sum(p => p.qty_all),
  3908. percent = g.Sum(p => p.qty_ok) / g.Sum(p => p.qty_all)
  3909. });
  3910. //增加排序条件,此处多个条件,op_no,bad_type
  3911. var test_datas = groupBy.OrderBy(p => p.op_time).ThenBy(p => p.op_no).ToList();
  3912. //生成临时数据,插入数据库
  3913. List<sqe_chart_data_temp> models = new List<sqe_chart_data_temp>();
  3914. sqe_chart_data_temp model;
  3915. DateTime dateTimeNow = DateTime.Now;
  3916. for (int i = 0; i < test_datas.Count; i++)
  3917. {
  3918. model = new sqe_chart_data_temp();
  3919. model.data_id = dateTimeNow.Ticks;
  3920. model.sub_group = test_datas[i].op_time.Value.ToString("yyyy-MM-dd");
  3921. model.type_name = test_datas[i].op_no;
  3922. model.type_value = test_datas[i].percent;
  3923. model.data_time = dateTimeNow;
  3924. models.Add(model);
  3925. }
  3926. _sqe_chart_data_temp.Insert(models);
  3927. ResultViewModel result = ResultHelper.CreateResult(ResultCode.Success, dateTimeNow.Ticks.ToString(), ResultCode.Success, null);
  3928. return JsonConvert.SerializeObject(result);
  3929. }
  3930. catch (Exception ex)
  3931. {
  3932. ResultViewModel resultError = ResultHelper.CreateResult(ResultCode.BusinessError, "您选择的数据在统计中出现问题,请核对之后再进行操作!", ResultCode.BusinessError, null);
  3933. return JsonConvert.SerializeObject(resultError);
  3934. }
  3935. return null;
  3936. }
  3937. public string Compute_FpyChartData(string startDate, string endDate, string item_no, string org, string op)
  3938. {
  3939. try
  3940. {
  3941. #region 查询条件
  3942. // 动态条件
  3943. var conditions = new List<Expression<Func<v_sqe_fpy_data, bool>>>();
  3944. if (!string.IsNullOrEmpty(startDate))
  3945. {
  3946. DateTime dateTime;
  3947. if (DateTime.TryParse(startDate, out dateTime))
  3948. {
  3949. // 添加条件1:Name 包含 "searchTerm"
  3950. conditions.Add(p => p.create_date >= dateTime);
  3951. }
  3952. }
  3953. if (!string.IsNullOrEmpty(endDate))
  3954. {
  3955. DateTime dateTime;
  3956. if (DateTime.TryParse(endDate, out dateTime))
  3957. {
  3958. // 添加条件1:Name 包含 "searchTerm"
  3959. conditions.Add(p => p.create_date <= dateTime);
  3960. }
  3961. }
  3962. if (!string.IsNullOrEmpty(item_no))
  3963. {
  3964. // 添加条件1:Name 包含 "searchTerm"
  3965. conditions.Add(p => p.item_no == item_no);
  3966. }
  3967. if (!string.IsNullOrEmpty(org))
  3968. {
  3969. // 添加条件1:Name 包含 "searchTerm"
  3970. conditions.Add(p => p.create_org == org);
  3971. }
  3972. if (!string.IsNullOrEmpty(op))
  3973. {
  3974. // 添加条件1:Name 包含 "searchTerm"
  3975. conditions.Add(p => p.op_no == op);
  3976. }
  3977. // 组合条件
  3978. var combinedCondition = PredicateBuilder.New<v_sqe_fpy_data>();
  3979. //此处是所有的条件都and。
  3980. foreach (var condition in conditions)
  3981. {
  3982. combinedCondition = combinedCondition.And(condition);
  3983. }
  3984. var query = _v_sqe_fpy_data.GetDbContext().v_sqe_fpy_data.AsQueryable();
  3985. // 应用条件
  3986. if (conditions.Count > 0)
  3987. {
  3988. query = query.Where(combinedCondition);
  3989. }
  3990. #endregion 查询条件
  3991. // 分组统计,此处多个条件进行统计,p.bad_type, p.op_no
  3992. var groupBy = query.GroupBy(p => new { p.op_no })
  3993. .Select(g => new
  3994. {
  3995. op_no = g.Key.op_no,
  3996. qty_error = g.Sum(p => p.qty_error),
  3997. qty_all = g.Sum(p => p.qty_all),
  3998. });
  3999. //增加排序条件,此处多个条件,op_no,bad_type
  4000. var test_datas = groupBy.OrderBy(p => p.op_no).ToList();
  4001. //生成临时数据,插入数据库
  4002. List<sqe_chart_data_temp> models = new List<sqe_chart_data_temp>();
  4003. sqe_chart_data_temp model;
  4004. DateTime dateTimeNow = DateTime.Now;
  4005. for (int i = 0; i < test_datas.Count; i++)
  4006. {
  4007. model = new sqe_chart_data_temp();
  4008. model.data_id = dateTimeNow.Ticks;
  4009. model.sub_group = "期间投入总数";
  4010. model.type_name = test_datas[i].op_no;
  4011. model.type_value = test_datas[i].qty_all;
  4012. model.data_time = dateTimeNow;
  4013. models.Add(model);
  4014. model = new sqe_chart_data_temp();
  4015. model.data_id = dateTimeNow.Ticks;
  4016. model.sub_group = "期间不良总数";
  4017. model.type_name = test_datas[i].op_no;
  4018. model.type_value = test_datas[i].qty_error;
  4019. model.data_time = dateTimeNow;
  4020. models.Add(model);
  4021. model = new sqe_chart_data_temp();
  4022. model.data_id = dateTimeNow.Ticks;
  4023. model.sub_group = "良率";
  4024. model.type_name = test_datas[i].op_no;
  4025. model.type_value = (1 - test_datas[i].qty_error / test_datas[i].qty_all);
  4026. model.data_time = dateTimeNow;
  4027. models.Add(model);
  4028. }
  4029. _sqe_chart_data_temp.Insert(models);
  4030. ResultViewModel result = ResultHelper.CreateResult(ResultCode.Success, dateTimeNow.Ticks.ToString(), ResultCode.Success, null);
  4031. return JsonConvert.SerializeObject(result);
  4032. }
  4033. catch (Exception ex)
  4034. {
  4035. ResultViewModel resultError = ResultHelper.CreateResult(ResultCode.BusinessError, "您选择的数据在统计中出现问题,请核对之后再进行操作!", ResultCode.BusinessError, null);
  4036. return JsonConvert.SerializeObject(resultError);
  4037. }
  4038. return null;
  4039. }
  4040. public string Compute_FpyChartData_Date(string startDate, string endDate, string item_no, string org, string op)
  4041. {
  4042. try
  4043. {
  4044. #region 查询条件
  4045. // 动态条件
  4046. var conditions = new List<Expression<Func<v_sqe_fpy_data, bool>>>();
  4047. if (!string.IsNullOrEmpty(startDate))
  4048. {
  4049. DateTime dateTime;
  4050. if (DateTime.TryParse(startDate, out dateTime))
  4051. {
  4052. // 添加条件1:Name 包含 "searchTerm"
  4053. conditions.Add(p => p.create_date >= dateTime);
  4054. }
  4055. }
  4056. if (!string.IsNullOrEmpty(endDate))
  4057. {
  4058. DateTime dateTime;
  4059. if (DateTime.TryParse(endDate, out dateTime))
  4060. {
  4061. // 添加条件1:Name 包含 "searchTerm"
  4062. conditions.Add(p => p.create_date <= dateTime);
  4063. }
  4064. }
  4065. if (!string.IsNullOrEmpty(item_no))
  4066. {
  4067. // 添加条件1:Name 包含 "searchTerm"
  4068. conditions.Add(p => p.item_no == item_no);
  4069. }
  4070. if (!string.IsNullOrEmpty(org))
  4071. {
  4072. // 添加条件1:Name 包含 "searchTerm"
  4073. conditions.Add(p => p.create_org == org);
  4074. }
  4075. if (!string.IsNullOrEmpty(op))
  4076. {
  4077. // 添加条件1:Name 包含 "searchTerm"
  4078. conditions.Add(p => p.op_no == op);
  4079. }
  4080. // 组合条件
  4081. var combinedCondition = PredicateBuilder.New<v_sqe_fpy_data>();
  4082. //此处是所有的条件都and。
  4083. foreach (var condition in conditions)
  4084. {
  4085. combinedCondition = combinedCondition.And(condition);
  4086. }
  4087. var query = _v_sqe_fpy_data.GetDbContext().v_sqe_fpy_data.AsQueryable();
  4088. // 应用条件
  4089. if (conditions.Count > 0)
  4090. {
  4091. query = query.Where(combinedCondition);
  4092. }
  4093. #endregion 查询条件
  4094. // 分组统计,此处多个条件进行统计,p.bad_type, p.op_no
  4095. var groupBy = query.GroupBy(p => new { p.op_time })
  4096. .Select(g => new
  4097. {
  4098. op_time = g.Key.op_time,
  4099. qty_error = g.Sum(p => p.qty_error),
  4100. qty_all = g.Sum(p => p.qty_all)
  4101. });
  4102. //增加排序条件,此处多个条件,op_no,bad_type
  4103. var test_datas = groupBy.OrderBy(p => p.op_time).ToList();
  4104. //生成临时数据,插入数据库
  4105. List<sqe_chart_data_temp> models = new List<sqe_chart_data_temp>();
  4106. sqe_chart_data_temp model;
  4107. DateTime dateTimeNow = DateTime.Now;
  4108. for (int i = 0; i < test_datas.Count; i++)
  4109. {
  4110. model = new sqe_chart_data_temp();
  4111. model.data_id = dateTimeNow.Ticks;
  4112. model.sub_group = test_datas[i].op_time.Value.ToString("MM-dd");
  4113. model.type_name = "走势图";
  4114. model.type_value = (1 - test_datas[i].qty_error / test_datas[i].qty_all);
  4115. model.data_time = dateTimeNow;
  4116. models.Add(model);
  4117. }
  4118. _sqe_chart_data_temp.Insert(models);
  4119. ResultViewModel result = ResultHelper.CreateResult(ResultCode.Success, dateTimeNow.Ticks.ToString(), ResultCode.Success, null);
  4120. return JsonConvert.SerializeObject(result);
  4121. }
  4122. catch (Exception ex)
  4123. {
  4124. ResultViewModel resultError = ResultHelper.CreateResult(ResultCode.BusinessError, "您选择的数据在统计中出现问题,请核对之后再进行操作!", ResultCode.BusinessError, null);
  4125. return JsonConvert.SerializeObject(resultError);
  4126. }
  4127. return null;
  4128. }
  4129. /// <summary>
  4130. /// 已经查询条件,统计Oqc数据
  4131. /// </summary>
  4132. /// <param name="startDate"></param>
  4133. /// <param name="endDate"></param>
  4134. /// <param name="item_no"></param>
  4135. /// <param name="org"></param>
  4136. /// <returns></returns>
  4137. public string Compute_OqcChartData(string startDate, string endDate, string item_no, string org)
  4138. {
  4139. try
  4140. {
  4141. //增加排序条件,此处多个条件,op_no,bad_type
  4142. var test_datas = Get_OqcData(startDate, endDate, item_no, org, null);
  4143. //生成临时数据,插入数据库
  4144. List<sqe_chart_data_temp> models = new List<sqe_chart_data_temp>();
  4145. sqe_chart_data_temp model;
  4146. DateTime dateTimeNow = DateTime.Now;
  4147. //生成临时数据,插入数据库
  4148. sqe_oqc_statistics modelStatistics;
  4149. string standard_no = "";
  4150. for (int i = 0; i < test_datas.Count;)
  4151. {
  4152. standard_no = test_datas[i].standard_no;
  4153. if (standard_no == null)
  4154. {
  4155. i++;
  4156. continue;
  4157. }
  4158. List<Double> dataList = new List<double>();
  4159. int j = i;
  4160. for (; j < test_datas.Count; j++)
  4161. {
  4162. if (standard_no.CompareTo(test_datas[j].standard_no) == 0)
  4163. {
  4164. dataList.Add((double)test_datas[j].data_value);
  4165. }
  4166. else
  4167. {
  4168. break;
  4169. }
  4170. }
  4171. Double[] datas = dataList.ToArray();
  4172. modelStatistics = new sqe_oqc_statistics();
  4173. try
  4174. {
  4175. modelStatistics.standard_no = standard_no;
  4176. modelStatistics.value_avg = (decimal)datas.Average();
  4177. modelStatistics.value_std_range = (decimal)datas.StandardDeviation();
  4178. if (modelStatistics.value_std_range != 0)
  4179. {
  4180. modelStatistics.value_pp = (test_datas[i].standard_max - test_datas[i].standard_min) / modelStatistics.value_std_range;
  4181. if (modelStatistics.value_pp > 100000)
  4182. {
  4183. modelStatistics.value_pp = 100000;
  4184. }
  4185. }
  4186. else
  4187. {
  4188. i = j;
  4189. continue;
  4190. }
  4191. //=MIN((B10-Q53)/(3*R53),(Q53-B11)/(3*R53))
  4192. decimal d1, d2;
  4193. d1 = (test_datas[i].standard_max - modelStatistics.value_avg) / 3 * modelStatistics.value_std_range;
  4194. d2 = (modelStatistics.value_avg - test_datas[i].standard_min) / 3 * modelStatistics.value_std_range;
  4195. modelStatistics.value_ppk = d1 > d2 ? d2 : d1;
  4196. modelStatistics.value_max = (decimal)datas.Max();
  4197. modelStatistics.value_min = (decimal)datas.Min();
  4198. modelStatistics.value_range = modelStatistics.value_max - modelStatistics.value_min;
  4199. }
  4200. catch (Exception ex)
  4201. {
  4202. i = j;
  4203. continue;
  4204. }
  4205. model = new sqe_chart_data_temp();
  4206. model.data_id = dateTimeNow.Ticks;
  4207. model.sub_group = "均值";
  4208. model.type_name = standard_no;
  4209. model.type_value = modelStatistics.value_avg;
  4210. model.data_time = dateTimeNow;
  4211. models.Add(model);
  4212. Console.WriteLine(model.type_value);
  4213. model = new sqe_chart_data_temp();
  4214. model.data_id = dateTimeNow.Ticks;
  4215. model.sub_group = "西格玛(标准差)";
  4216. model.type_name = standard_no;
  4217. model.type_value = modelStatistics.value_std_range;
  4218. model.data_time = dateTimeNow;
  4219. models.Add(model);
  4220. Console.WriteLine(model.type_value);
  4221. model = new sqe_chart_data_temp();
  4222. model.data_id = dateTimeNow.Ticks;
  4223. model.sub_group = "PP";
  4224. model.type_name = standard_no;
  4225. model.type_value = modelStatistics.value_pp;
  4226. model.data_time = dateTimeNow;
  4227. models.Add(model);
  4228. Console.WriteLine(model.type_value);
  4229. model = new sqe_chart_data_temp();
  4230. model.data_id = dateTimeNow.Ticks;
  4231. model.sub_group = "PPK";
  4232. model.type_name = standard_no;
  4233. model.type_value = modelStatistics.value_ppk;
  4234. model.data_time = dateTimeNow;
  4235. models.Add(model);
  4236. Console.WriteLine(model.type_value);
  4237. model = new sqe_chart_data_temp();
  4238. model.data_id = dateTimeNow.Ticks;
  4239. model.sub_group = "Max";
  4240. model.type_name = standard_no;
  4241. model.type_value = modelStatistics.value_max;
  4242. model.data_time = dateTimeNow;
  4243. models.Add(model);
  4244. Console.WriteLine(model.type_value);
  4245. model = new sqe_chart_data_temp();
  4246. model.data_id = dateTimeNow.Ticks;
  4247. model.sub_group = "Min";
  4248. model.type_name = standard_no;
  4249. model.type_value = modelStatistics.value_min;
  4250. model.data_time = dateTimeNow;
  4251. models.Add(model);
  4252. Console.WriteLine(model.type_value);
  4253. model = new sqe_chart_data_temp();
  4254. model.data_id = dateTimeNow.Ticks;
  4255. model.sub_group = "极差(Max-Min)";
  4256. model.type_name = standard_no;
  4257. model.type_value = modelStatistics.value_range;
  4258. model.data_time = dateTimeNow;
  4259. models.Add(model);
  4260. Console.WriteLine(model.type_value);
  4261. i = j;
  4262. }
  4263. _sqe_chart_data_temp.Insert(models);
  4264. ResultViewModel result = ResultHelper.CreateResult(ResultCode.Success, dateTimeNow.Ticks.ToString(), ResultCode.Success, null);
  4265. return JsonConvert.SerializeObject(result);
  4266. }
  4267. catch (Exception ex)
  4268. {
  4269. ResultViewModel resultError = ResultHelper.CreateResult(ResultCode.BusinessError, "您选择的数据在统计中出现问题,请核对之后再进行操作!", ResultCode.BusinessError, null);
  4270. return JsonConvert.SerializeObject(resultError);
  4271. }
  4272. return null;
  4273. }
  4274. /// <summary>
  4275. /// 查询Oqc的数据信息
  4276. /// </summary>
  4277. /// <param name="startDate"></param>
  4278. /// <param name="endDate"></param>
  4279. /// <param name="item_no"></param>
  4280. /// <param name="org"></param>
  4281. /// <param name="standard_no"></param>
  4282. /// <returns></returns>
  4283. public List<v_sqe_oqc_data> Get_OqcData(string startDate, string endDate, string item_no, string org, string standard_no)
  4284. {
  4285. try
  4286. {
  4287. #region 查询条件
  4288. // 动态条件
  4289. var conditions = new List<Expression<Func<v_sqe_oqc_data, bool>>>();
  4290. if (!string.IsNullOrEmpty(startDate))
  4291. {
  4292. DateTime dateTime;
  4293. if (DateTime.TryParse(startDate, out dateTime))
  4294. {
  4295. // 添加条件1:Name 包含 "searchTerm"
  4296. conditions.Add(p => p.product_time >= dateTime);
  4297. }
  4298. }
  4299. if (!string.IsNullOrEmpty(endDate))
  4300. {
  4301. DateTime dateTime;
  4302. if (DateTime.TryParse(endDate, out dateTime))
  4303. {
  4304. // 添加条件1:Name 包含 "searchTerm"
  4305. conditions.Add(p => p.product_time <= dateTime);
  4306. }
  4307. }
  4308. if (!string.IsNullOrEmpty(item_no))
  4309. {
  4310. // 添加条件1:Name 包含 "searchTerm"
  4311. conditions.Add(p => p.item_no == item_no);
  4312. }
  4313. if (!string.IsNullOrEmpty(org))
  4314. {
  4315. // 添加条件1:Name 包含 "searchTerm"
  4316. conditions.Add(p => p.create_org == org);
  4317. }
  4318. if (!string.IsNullOrEmpty(standard_no))
  4319. {
  4320. // 添加条件1:Name 包含 "searchTerm"
  4321. conditions.Add(p => p.standard_no == standard_no);
  4322. }
  4323. // 组合条件
  4324. var combinedCondition = PredicateBuilder.New<v_sqe_oqc_data>();
  4325. //此处是所有的条件都and。
  4326. foreach (var condition in conditions)
  4327. {
  4328. combinedCondition = combinedCondition.And(condition);
  4329. }
  4330. var query = _v_sqe_oqc_data.GetDbContext().v_sqe_oqc_data.AsQueryable();
  4331. // 应用条件
  4332. if (conditions.Count > 0)
  4333. {
  4334. query = query.Where(combinedCondition);
  4335. }
  4336. #endregion 查询条件
  4337. //增加排序条件,此处多个条件,op_no,bad_type
  4338. var test_datas = query.OrderBy(p => p.standard_no).DefaultIfEmpty().ToList();
  4339. return test_datas;
  4340. }
  4341. catch (Exception ex)
  4342. {
  4343. }
  4344. return null;
  4345. }
  4346. }
  4347. }