PAMModuleDAL.cs 533 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:PAMModuleDAL.cs
  5. * 2.功能描述:工资方案参数设定更新db逻辑处理
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 王鑫 2015/08/17 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Data;
  13. using System.Text;
  14. using Dongke.IBOSS.PRD.Basics.DataAccess;
  15. using Dongke.IBOSS.PRD.Service.DataModels;
  16. using Dongke.IBOSS.PRD.WCF.DataModels;
  17. using Dongke.IBOSS.PRD.Basics.BaseResources;
  18. using Oracle.ManagedDataAccess.Client;
  19. using Dongke.IBOSS.PRD.WCF.DataModels.PAMModule;
  20. using System.Collections;
  21. namespace Dongke.IBOSS.PRD.Service.PAMModuleService
  22. {
  23. public partial class PAMModuleDAL
  24. {
  25. /// <summary>
  26. /// 保存工资方案参数设定
  27. /// </summary>
  28. /// <param name="dataDefectPositionData">缺陷数据</param>
  29. /// <param name="sUserInfo">用户基本信息</param>
  30. /// <returns>int</returns>
  31. /// <remarks>
  32. /// 2014.09.11 冯雪 新建
  33. /// </remarks>
  34. public static int SavePayPlanSetting(DataTable dataPayPlanSetting, SUserInfo sUserInfo)
  35. {
  36. IDBTransaction oracleTrConn = ClsDbFactory.CreateDBTransaction(DataBaseType.ORACLE, DataManager.ConnectionString);
  37. try
  38. {
  39. // 检验参数的有效性
  40. if (dataPayPlanSetting == null && dataPayPlanSetting.Rows.Count == 0)
  41. {
  42. return -1;
  43. }
  44. int intResult = 0;
  45. oracleTrConn.Connect();
  46. foreach (DataRow dataRow in dataPayPlanSetting.Rows)
  47. {
  48. //if (dataRow.RowState == DataRowState.Modified)
  49. int orgValue = Convert.ToInt32(dataRow["SettingValueOrg"].ToString() == "" ? 0 : dataRow["SettingValueOrg"]);
  50. int Value = Convert.ToInt32(dataRow["SettingValue"].ToString() == "" ? 0 : dataRow["SettingValue"]);
  51. //if (dataRow.RowState == DataRowState.Modified)
  52. if (orgValue != Value)
  53. {
  54. #region 更新缺陷信息
  55. string sqlString = "UPDATE TP_PAS_PayPlanSetting SET "
  56. + " SettingValue = :SettingValue "
  57. + " WHERE SettingCode = :SettingCode";
  58. OracleParameter[] parmeters1 = new OracleParameter[]
  59. {
  60. new OracleParameter(":SettingValue",dataRow["SettingValue"].ToString()),
  61. new OracleParameter(":SettingCode",dataRow["SettingCode"].ToString())
  62. };
  63. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  64. #endregion
  65. }
  66. }
  67. oracleTrConn.Commit();
  68. oracleTrConn.Disconnect();
  69. return intResult;
  70. }
  71. catch (Exception ex)
  72. {
  73. if (oracleTrConn.ConnState == ConnectionState.Open)
  74. {
  75. oracleTrConn.Rollback();
  76. oracleTrConn.Disconnect();
  77. }
  78. throw ex;
  79. }
  80. finally
  81. {
  82. if (oracleTrConn.ConnState == ConnectionState.Open)
  83. {
  84. oracleTrConn.Rollback();
  85. oracleTrConn.Disconnect();
  86. }
  87. }
  88. }
  89. /// <summary>
  90. /// 保存工种工资方案
  91. /// </summary>
  92. /// <param name="IsEdit">false 新建 true 编辑</param>
  93. /// <param name="dtJobsPayPlan">数据源</param>
  94. /// <param name="sUserInfo"></param>
  95. /// <returns></returns>
  96. public static int SaveJobsPayPlan(bool IsEdit, DataTable dtJobsPayPlan, SUserInfo sUserInfo)
  97. {
  98. IDBTransaction oracleTrConn = ClsDbFactory.CreateDBTransaction(DataBaseType.ORACLE, DataManager.ConnectionString);
  99. try
  100. {
  101. // 检验参数的有效性
  102. if (dtJobsPayPlan == null && dtJobsPayPlan.Rows.Count == 0)
  103. {
  104. return -1;
  105. }
  106. int intResult = 0;
  107. oracleTrConn.Connect();
  108. OracleParameter[] parmeters1 = null;
  109. string sqlString = "";
  110. bool isError = false;
  111. foreach (DataRow dataRow in dtJobsPayPlan.Rows)
  112. {
  113. //if (!IsEdit) // 新建
  114. //{
  115. // if (dataRow["JobsID"].ToString() != string.Empty)
  116. // {
  117. // parmeters1 = new OracleParameter[]
  118. // {
  119. // new OracleParameter(":PayPlanID",dataRow["PayPlanID"].ToString()),
  120. // new OracleParameter(":JobsID",dataRow["JobsID"].ToString())
  121. // };
  122. // sqlString = "select 1 from TP_PAM_JobsPayPlan where jobsid=:JobsID and PayPlanID=:PayPlanID ";
  123. // DataSet ds = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  124. // if (ds != null && ds.Tables[0].Rows.Count > 0)
  125. // {
  126. // isError = true;
  127. // intResult = -3;//重复数据
  128. // break;
  129. // }
  130. // sqlString = "insert into TP_PAM_JobsPayPlan values(:JobsID,:PayPlanID) ";
  131. // intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  132. // }
  133. //}
  134. //else
  135. //{
  136. // 编辑
  137. if (dataRow.RowState == DataRowState.Added)
  138. {
  139. if (dataRow["JobsID"].ToString() != string.Empty)
  140. {
  141. parmeters1 = new OracleParameter[]
  142. {
  143. new OracleParameter(":PayPlanID",dataRow["PayPlanID"].ToString()),
  144. new OracleParameter(":JobsID",dataRow["JobsID"].ToString())
  145. };
  146. sqlString = "select 1 from TP_PAM_JobsPayPlan where jobsid=:JobsID and PayPlanID=:PayPlanID ";
  147. DataSet ds = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  148. if (ds != null && ds.Tables[0].Rows.Count > 0)
  149. {
  150. isError = true;
  151. intResult = -3;//重复数据
  152. break;
  153. }
  154. sqlString = "insert into TP_PAM_JobsPayPlan values(:JobsID,:PayPlanID) ";
  155. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  156. }
  157. }
  158. else if (dataRow.RowState == DataRowState.Modified)
  159. {
  160. parmeters1 = new OracleParameter[]
  161. {
  162. new OracleParameter(":PayPlanID",dataRow["PayPlanID"].ToString()),
  163. new OracleParameter(":JobsID",dataRow["JobsID"].ToString())
  164. };
  165. sqlString = "select 1 from TP_PAM_JobsPayPlan where jobsid=:JobsID and PayPlanID=:PayPlanID ";
  166. DataSet ds = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  167. if (ds != null && ds.Tables[0].Rows.Count > 0)
  168. {
  169. IsEdit = true;
  170. intResult = -3;//重复数据
  171. break;
  172. }
  173. sqlString = "update TP_PAM_JobsPayPlan set JobsID=:JobsID where PayPlanID=:PayPlanID ";
  174. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  175. }
  176. else if (dataRow.RowState == DataRowState.Deleted)
  177. {
  178. sqlString = "delete from TP_PAM_JobsPayPlan where PayPlanID=:PayPlanID and JobsID=:JobsID ";
  179. parmeters1 = new OracleParameter[]
  180. {
  181. new OracleParameter(":PayPlanID",dataRow["PayPlanID",DataRowVersion.Original].ToString()),
  182. new OracleParameter(":JobsID",dataRow["JobsID",DataRowVersion.Original].ToString())
  183. };
  184. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  185. }
  186. // }
  187. }
  188. if (isError)
  189. {
  190. oracleTrConn.Rollback();
  191. oracleTrConn.Disconnect();
  192. }
  193. else
  194. {
  195. oracleTrConn.Commit();
  196. oracleTrConn.Disconnect();
  197. }
  198. return intResult;
  199. }
  200. catch (Exception ex)
  201. {
  202. if (oracleTrConn.ConnState == ConnectionState.Open)
  203. {
  204. oracleTrConn.Rollback();
  205. oracleTrConn.Disconnect();
  206. }
  207. throw ex;
  208. }
  209. finally
  210. {
  211. if (oracleTrConn.ConnState == ConnectionState.Open)
  212. {
  213. oracleTrConn.Rollback();
  214. oracleTrConn.Disconnect();
  215. }
  216. }
  217. }
  218. /// <summary>
  219. /// 保存工价分类数据
  220. /// </summary>
  221. /// <param name="sUserInfo">用户基本信息</param>
  222. /// <param name="datatWagesTypeData">工价分类数据源</param>
  223. /// <returns>int</returns>
  224. /// <remarks>
  225. /// 2015.08.19 王鑫 新建
  226. /// </remarks>
  227. public static int SavetJobsData(DataTable datatWagesTypeData, SUserInfo sUserInfo)
  228. {
  229. IDBTransaction oracleTrConn = ClsDbFactory.CreateDBTransaction(DataBaseType.ORACLE, DataManager.ConnectionString);
  230. try
  231. {
  232. // 检验参数的有效性
  233. if (datatWagesTypeData == null && datatWagesTypeData.Rows.Count < Constant.INT_IS_ZERO)
  234. {
  235. return Constant.INT_IS_THREE;
  236. }
  237. int returnResult = Constant.INT_IS_TWO;
  238. oracleTrConn.Connect();
  239. #region 对要保存的工种数据进行必要的验证
  240. foreach (DataRow dataRow in datatWagesTypeData.Rows)
  241. {
  242. // 新建工种
  243. if (dataRow.RowState == DataRowState.Added)
  244. {
  245. #region 判断是否存在相同的工份名称
  246. string sqlString = "SELECT Count(*) FROM TP_PAM_WagesType WHERE AccountID = :AccountID and WagesTypeName =:WagesTypeName ";
  247. OracleParameter[] oracleParameter = new OracleParameter[]
  248. {
  249. new OracleParameter(":AccountID",sUserInfo.AccountID),
  250. new OracleParameter(":WagesTypeName",dataRow["WagesTypeName"].ToString())
  251. };
  252. string sqlReturnStr = oracleTrConn.GetSqlResultToStr(sqlString, oracleParameter);
  253. if (!Constant.INT_IS_ZERO.ToString().Equals(sqlReturnStr))
  254. {
  255. returnResult = Constant.INT_IS_ONE;
  256. break;
  257. }
  258. #endregion
  259. }
  260. else if (dataRow.RowState == DataRowState.Modified)
  261. {
  262. #region 判断是否存在相同的工种代码
  263. string sqlStrings = "SELECT Count(*) FROM TP_PAM_WagesType WHERE AccountID = :AccountID and WagesTypeName = :WagesTypeName and WagesTypeID <> :WagesTypeID";
  264. OracleParameter[] oracleParameters = new OracleParameter[]
  265. {
  266. new OracleParameter(":AccountID",sUserInfo.AccountID),
  267. new OracleParameter(":WagesTypeName",dataRow["WagesTypeName"]),
  268. new OracleParameter(":WagesTypeID",dataRow["WagesTypeID"])
  269. };
  270. string sqlReturnStr = oracleTrConn.GetSqlResultToStr(sqlStrings, oracleParameters);
  271. if (!Constant.INT_IS_ZERO.ToString().Equals(sqlReturnStr))
  272. {
  273. returnResult = Constant.INT_IS_ONE;
  274. break;
  275. }
  276. #endregion
  277. }
  278. }
  279. if (returnResult == Constant.INT_IS_ONE)
  280. {
  281. oracleTrConn.Rollback();
  282. oracleTrConn.Disconnect();
  283. return returnResult;
  284. }
  285. #endregion
  286. foreach (DataRow dataRow in datatWagesTypeData.Rows)
  287. {
  288. // 新建工种
  289. if (dataRow.RowState == DataRowState.Added)
  290. {
  291. #region 新增工种信息
  292. #region 向T_MST_Jobs插入数据
  293. string sqlInsertString = "INSERT INTO TP_PAM_WagesType "
  294. + "(WagesTypeName"
  295. + ",AccountID"
  296. + ",ValueFlag"
  297. + ",CreateTime"
  298. + ",UpdateTime"
  299. + ",UpdateUserID"
  300. + ",CreateUserID)"
  301. + " VALUES "
  302. + "(:WagesTypeName"
  303. + ",:AccountID"
  304. + ",:ValueFlag"
  305. + ",sysdate"
  306. + ",sysdate"
  307. + ",:UpdateUserID"
  308. + ",:CreateUserID)";
  309. OracleParameter[] oracleParameters = new OracleParameter[]
  310. {
  311. new OracleParameter(":WagesTypeName",dataRow["WagesTypeName"].ToString()),
  312. new OracleParameter(":AccountID",sUserInfo.AccountID),
  313. new OracleParameter(":ValueFlag",dataRow["ValueFlag"].ToString()),
  314. new OracleParameter(":UpdateUserID",sUserInfo.UserID),
  315. new OracleParameter(":CreateUserID",sUserInfo.UserID)
  316. };
  317. oracleTrConn.ExecuteNonQuery(sqlInsertString, oracleParameters);
  318. #endregion
  319. #endregion
  320. }
  321. else if (dataRow.RowState == DataRowState.Modified)
  322. {
  323. #region 更新工种信息
  324. string sqlUpdateString = "UPDATE TP_PAM_WagesType SET "
  325. + " WagesTypeName = :WagesTypeName,"
  326. + " AccountID = :AccountID,"
  327. + " ValueFlag = :ValueFlag,"
  328. + " UpdateUserID = :UpdateUserID,"
  329. + " UpdateTime = :UpdateTime"
  330. + " WHERE WagesTypeID = :WagesTypeID";
  331. OracleParameter[] oracleParametere = new OracleParameter[]
  332. {
  333. new OracleParameter(":WagesTypeName",dataRow["WagesTypeName"].ToString()),
  334. new OracleParameter(":AccountID",sUserInfo.AccountID),
  335. new OracleParameter(":ValueFlag",dataRow["ValueFlag"].ToString()),
  336. new OracleParameter(":UpdateUserID",sUserInfo.UserID),
  337. new OracleParameter(":UpdateTime",DateTime.Now),
  338. new OracleParameter(":WagesTypeID",dataRow["WagesTypeID"].ToString())
  339. };
  340. oracleTrConn.ExecuteNonQuery(sqlUpdateString, oracleParametere);
  341. #endregion
  342. }
  343. else if (dataRow.RowState == DataRowState.Deleted)
  344. {
  345. #region 删除工种信息
  346. string sqlDeleteString = "DELETE TP_PAM_WagesType WHERE WagesTypeID = :WagesTypeID";
  347. OracleParameter[] oracleParameter = new OracleParameter[]
  348. {
  349. new OracleParameter(":WagesTypeID",dataRow["WagesTypeID",DataRowVersion.Original].ToString())
  350. };
  351. oracleTrConn.ExecuteNonQuery(sqlDeleteString, oracleParameter);
  352. #endregion
  353. }
  354. }
  355. oracleTrConn.Commit();
  356. oracleTrConn.Disconnect();
  357. return returnResult;
  358. }
  359. catch (Exception ex)
  360. {
  361. if (oracleTrConn.ConnState == ConnectionState.Open)
  362. {
  363. oracleTrConn.Rollback();
  364. oracleTrConn.Disconnect();
  365. }
  366. throw ex;
  367. }
  368. finally
  369. {
  370. if (oracleTrConn.ConnState == ConnectionState.Open)
  371. {
  372. oracleTrConn.Rollback();
  373. oracleTrConn.Disconnect();
  374. }
  375. }
  376. }
  377. /// <summary>
  378. /// 保存产品工价分类
  379. /// </summary>
  380. /// <param name="IsEdit">false 新建 true 编辑</param>
  381. /// <param name="dtJobsPayPlan">数据源</param>
  382. /// <param name="sUserInfo"></param>
  383. /// <returns></returns>
  384. public static int SaveGoodsWagesTypeData(bool IsEdit, DataTable dtGoodsPayPlan, SUserInfo sUserInfo)
  385. {
  386. IDBTransaction oracleTrConn = ClsDbFactory.CreateDBTransaction(DataBaseType.ORACLE, DataManager.ConnectionString);
  387. try
  388. {
  389. // 检验参数的有效性
  390. if (dtGoodsPayPlan == null && dtGoodsPayPlan.Rows.Count == 0)
  391. {
  392. return -1;
  393. }
  394. int intResult = 0;
  395. oracleTrConn.Connect();
  396. OracleParameter[] parmeters1 = null;
  397. string sqlString = "";
  398. bool isError = false;
  399. foreach (DataRow dataRow in dtGoodsPayPlan.Rows)
  400. {
  401. if (dataRow.RowState == DataRowState.Added)
  402. {
  403. if (dataRow["GoodsID"].ToString() != string.Empty)
  404. {
  405. parmeters1 = new OracleParameter[]
  406. {
  407. new OracleParameter(":WagesTypeID",dataRow["WagesTypeID"].ToString()),
  408. new OracleParameter(":GoodsID",dataRow["GoodsID"].ToString())
  409. };
  410. sqlString = "select 1 from TP_PAM_GoodsWagesType where GoodsID=:GoodsID and :WagesTypeID=:WagesTypeID ";
  411. DataSet ds = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  412. if (ds != null && ds.Tables[0].Rows.Count > 0)
  413. {
  414. isError = true;
  415. intResult = -3;//重复数据
  416. break;
  417. }
  418. sqlString = "insert into TP_PAM_GoodsWagesType values(:GoodsID,:WagesTypeID) ";
  419. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  420. }
  421. }
  422. else if (dataRow.RowState == DataRowState.Modified)
  423. {
  424. parmeters1 = new OracleParameter[]
  425. {
  426. new OracleParameter(":WagesTypeID",dataRow["WagesTypeID"].ToString()),
  427. new OracleParameter(":GoodsID",dataRow["GoodsID"].ToString())
  428. };
  429. sqlString = "select 1 from TP_PAM_GoodsWagesType where GoodsID=:GoodsID and WagesTypeID=:WagesTypeID ";
  430. DataSet ds = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  431. if (ds != null && ds.Tables[0].Rows.Count > 0)
  432. {
  433. isError = true;
  434. intResult = -3;//重复数据
  435. break;
  436. }
  437. sqlString = "update TP_PAM_GoodsWagesType set GoodsID=:GoodsID where WagesTypeID=:WagesTypeID ";
  438. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  439. }
  440. else if (dataRow.RowState == DataRowState.Deleted)
  441. {
  442. sqlString = "delete from TP_PAM_GoodsWagesType where WagesTypeID=:WagesTypeID and GoodsID=:GoodsID ";
  443. parmeters1 = new OracleParameter[]
  444. {
  445. new OracleParameter(":WagesTypeID",dataRow["WagesTypeID",DataRowVersion.Original].ToString()),
  446. new OracleParameter(":GoodsID",dataRow["GoodsID",DataRowVersion.Original].ToString())
  447. };
  448. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  449. }
  450. }
  451. if (isError)
  452. {
  453. oracleTrConn.Rollback();
  454. oracleTrConn.Disconnect();
  455. }
  456. else
  457. {
  458. oracleTrConn.Commit();
  459. oracleTrConn.Disconnect();
  460. }
  461. return intResult;
  462. }
  463. catch (Exception ex)
  464. {
  465. if (oracleTrConn.ConnState == ConnectionState.Open)
  466. {
  467. oracleTrConn.Rollback();
  468. oracleTrConn.Disconnect();
  469. }
  470. throw ex;
  471. }
  472. finally
  473. {
  474. if (oracleTrConn.ConnState == ConnectionState.Open)
  475. {
  476. oracleTrConn.Rollback();
  477. oracleTrConn.Disconnect();
  478. }
  479. }
  480. }
  481. /// <summary>
  482. /// 保存计件工资策略
  483. /// </summary>
  484. /// <param name="IsEdit">false 新建 true 编辑</param>
  485. /// <param name="dtJobsPayPlan">数据源</param>
  486. /// <param name="sUserInfo"></param>
  487. /// <returns></returns>
  488. public static int SavePiecework(PieceworkEntity pieceworkendity, SUserInfo sUserInfo)
  489. {
  490. IDBTransaction oracleTrConn = ClsDbFactory.CreateDBTransaction(DataBaseType.ORACLE, DataManager.ConnectionString);
  491. try
  492. {
  493. int intResult = 0;
  494. oracleTrConn.Connect();
  495. string sqlString = "";
  496. OracleParameter[] parmeters1 = null;
  497. bool isError = false;
  498. if (pieceworkendity.PieceTacticsID == null) // 新增
  499. {
  500. //一个解决方案只能对应一个计件工资策略
  501. if (pieceworkendity.PayPlanID != null)
  502. {
  503. sqlString = "select 1 from TP_PAT_Piecework where PayPlanID=:PayPlanID and AccountID=:AccountID ";
  504. parmeters1 = new OracleParameter[]
  505. {
  506. new OracleParameter(":PayPlanID",pieceworkendity.PayPlanID),
  507. new OracleParameter(":AccountID",sUserInfo.AccountID),
  508. };
  509. DataSet ds = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  510. if (ds != null && ds.Tables[0].Rows.Count > 0)
  511. {
  512. isError = true;
  513. intResult = -1;//重复数据
  514. oracleTrConn.Rollback();
  515. oracleTrConn.Disconnect();
  516. return intResult;
  517. }
  518. }
  519. string sql = "select SEQ_PAT_Piecework_ID.nextval from dual";
  520. string idStr = oracleTrConn.GetSqlResultToStr(sql);
  521. sqlString = @"insert into TP_PAT_Piecework
  522. (
  523. PieceTacticsID,
  524. PayPlanID,
  525. PieceType,
  526. PieceCoefficient,
  527. DamageFlag,
  528. DamageCoefficient,
  529. UnqualifiedFlag,
  530. UnqualifiedCoefficient,
  531. QualifiedFlag,
  532. QualifiedCoefficient,
  533. AccountID,
  534. CreateUserID,
  535. UpdateUserID,
  536. PieceTacticsName
  537. ) values
  538. (
  539. :PieceTacticsID,
  540. :PayPlanID,
  541. :PieceType,
  542. :PieceCoefficient,
  543. :DamageFlag,
  544. :DamageCoefficient,
  545. :UnqualifiedFlag,
  546. :UnqualifiedCoefficient,
  547. :QualifiedFlag,
  548. :QualifiedCoefficient,
  549. :AccountID,
  550. :CreateUserID,
  551. :UpdateUserID,
  552. :PieceTacticsName
  553. )";
  554. parmeters1 = new OracleParameter[]
  555. {
  556. new OracleParameter(":PieceTacticsID",idStr),
  557. new OracleParameter(":PayPlanID",pieceworkendity.PayPlanID),
  558. new OracleParameter(":PieceType",pieceworkendity.PieceType),
  559. new OracleParameter(":PieceCoefficient",pieceworkendity.PieceCoefficient),
  560. new OracleParameter(":DamageFlag",pieceworkendity.DamageFlag),
  561. new OracleParameter(":DamageCoefficient",pieceworkendity.DamageCoefficient),
  562. new OracleParameter(":UnqualifiedFlag",pieceworkendity.UnqualifiedFlag),
  563. new OracleParameter(":UnqualifiedCoefficient",pieceworkendity.UnqualifiedCoefficient),
  564. new OracleParameter(":QualifiedFlag",pieceworkendity.QualifiedFlag),
  565. new OracleParameter(":QualifiedCoefficient",pieceworkendity.QualifiedCoefficient),
  566. new OracleParameter(":AccountID",sUserInfo.AccountID),
  567. new OracleParameter(":CreateUserID",sUserInfo.UserID),
  568. new OracleParameter(":UpdateUserID",sUserInfo.UserID),
  569. new OracleParameter(":PieceTacticsName",pieceworkendity.PayPlanName),
  570. };
  571. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  572. // 插入计件工序
  573. sqlString = @"insert into TP_PAT_PIECEPROCEDURE
  574. (
  575. PIECETACTICSID,
  576. PROCEDUREID,
  577. PROCEDUREFLAG
  578. ) values
  579. (
  580. :PIECETACTICSID,
  581. :PROCEDUREID,
  582. :PROCEDUREFLAG
  583. )";
  584. if (!string.IsNullOrEmpty(pieceworkendity.PieceProcedureIDS))
  585. {
  586. string[] sub = pieceworkendity.PieceProcedureIDS.Split(',');
  587. for (int i = 0; i < sub.Length; i++)
  588. {
  589. parmeters1 = new OracleParameter[]
  590. {
  591. new OracleParameter(":PieceTacticsID",idStr),
  592. new OracleParameter(":PROCEDUREID",sub[i]),
  593. new OracleParameter(":PROCEDUREFLAG",1),
  594. };
  595. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  596. }
  597. }
  598. // 插入质量工序
  599. sqlString = @"insert into TP_PAT_PIECEPROCEDURE
  600. (
  601. PIECETACTICSID,
  602. PROCEDUREID,
  603. PROCEDUREFLAG
  604. ) values
  605. (
  606. :PIECETACTICSID,
  607. :PROCEDUREID,
  608. :PROCEDUREFLAG
  609. )";
  610. if (!string.IsNullOrEmpty(pieceworkendity.PieceProcedureIDS))
  611. {
  612. string[] sub = pieceworkendity.QualityBaseProcedureIDS.Split(',');
  613. for (int i = 0; i < sub.Length; i++)
  614. {
  615. parmeters1 = new OracleParameter[]
  616. {
  617. new OracleParameter(":PieceTacticsID",idStr),
  618. new OracleParameter(":PROCEDUREID",sub[i]),
  619. new OracleParameter(":PROCEDUREFLAG",2),
  620. };
  621. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  622. }
  623. }
  624. if (pieceworkendity.wagesentity != null)
  625. {
  626. foreach (Dongke.IBOSS.PRD.WCF.DataModels.PAMModule.WagesEntity entity in pieceworkendity.wagesentity)
  627. {
  628. //sqlString = "select 1 from TP_PAT_Wages where WagesTypeID=:WagesTypeID ";
  629. //parmeters1 = new OracleParameter[]
  630. //{
  631. // new OracleParameter(":WagesTypeID",entity.WagesTypeID),
  632. //};
  633. //DataSet ds = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  634. //if (ds != null && ds.Tables[0].Rows.Count > 0)
  635. //{
  636. // isError = true;
  637. // intResult = -2;//重复数据
  638. // break;
  639. //}
  640. sqlString = @"insert into TP_PAT_Wages
  641. (
  642. PieceTacticsID,
  643. WagesTypeID,
  644. StandardWages,
  645. DamageSubsidyRate,
  646. DamageSubsidy,
  647. RSuperiorCoefficient,
  648. RQualifiedCoefficient,
  649. RepairSubsidyRate,
  650. RepairSubsidy
  651. ) values
  652. (
  653. :PieceTacticsID,
  654. :WagesTypeID,
  655. :StandardWages,
  656. :DamageSubsidyRate,
  657. :DamageSubsidy,
  658. :RSuperiorCoefficient,
  659. :RQualifiedCoefficient,
  660. :RepairSubsidyRate,
  661. :RepairSubsidy
  662. )
  663. ";
  664. parmeters1 = new OracleParameter[]
  665. {
  666. new OracleParameter(":PieceTacticsID",idStr),
  667. new OracleParameter(":WagesTypeID",entity.WagesTypeID),
  668. new OracleParameter(":StandardWages",entity.StandardWages),
  669. new OracleParameter(":DamageSubsidyRate",entity.DamageSubsidyRate),
  670. new OracleParameter(":DamageSubsidy",entity.DamageSubsidy),
  671. new OracleParameter(":RSuperiorCoefficient",entity.RSuperiorCoefficient),
  672. new OracleParameter(":RQualifiedCoefficient",entity.RQualifiedCoefficient),
  673. new OracleParameter(":RepairSubsidyRate",entity.RepairSubsidyRate),
  674. new OracleParameter(":RepairSubsidy",entity.RepairSubsidy),
  675. };
  676. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  677. //质量工价
  678. if (entity.qualitywagesentity != null)
  679. {
  680. foreach (QualityWagesEntity qualitywagesentity in entity.qualitywagesentity)
  681. {
  682. sqlString = "select 1 from TP_PAT_QualityWages where QualityRate=:QualityRate and WagesTypeID=:WagesTypeID and PieceTacticsID=:PieceTacticsID";
  683. parmeters1 = new OracleParameter[]
  684. {
  685. new OracleParameter(":QualityRate",qualitywagesentity.QualityRate),
  686. new OracleParameter(":WagesTypeID",qualitywagesentity.WagesTypeID),
  687. new OracleParameter(":PieceTacticsID",pieceworkendity.PieceTacticsID),
  688. };
  689. DataSet ds2 = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  690. if (ds2 != null && ds2.Tables[0].Rows.Count > 0)
  691. {
  692. isError = true;
  693. intResult = -3;//重复数据
  694. break;
  695. }
  696. sqlString = @"insert into TP_PAT_QualityWages
  697. (
  698. PieceTacticsID,
  699. WagesTypeID,
  700. QualityRate,
  701. Balance,
  702. QualityWages
  703. ) values
  704. (
  705. :PieceTacticsID,
  706. :WagesTypeID,
  707. :QualityRate,
  708. :Balance,
  709. :QualityWages
  710. )
  711. ";
  712. parmeters1 = new OracleParameter[]
  713. {
  714. new OracleParameter(":PieceTacticsID",idStr),
  715. new OracleParameter(":WagesTypeID",qualitywagesentity.WagesTypeID),
  716. new OracleParameter(":QualityRate",qualitywagesentity.QualityRate),
  717. new OracleParameter(":Balance",qualitywagesentity.Balance),
  718. new OracleParameter(":QualityWages",qualitywagesentity.QualityWages),
  719. };
  720. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  721. }
  722. }
  723. }
  724. }
  725. }
  726. else
  727. {
  728. //编辑
  729. //一个解决方案只能对应一个计件工资策略
  730. if (pieceworkendity.PayPlanID != null)
  731. {
  732. sqlString = "select 1 from TP_PAT_Piecework where PayPlanID=:PayPlanID and AccountID=:AccountID and PieceTacticsID<>:PieceTacticsID";
  733. parmeters1 = new OracleParameter[]
  734. {
  735. new OracleParameter(":PayPlanID",pieceworkendity.PayPlanID),
  736. new OracleParameter(":AccountID",sUserInfo.AccountID),
  737. new OracleParameter(":PieceTacticsID",pieceworkendity.PieceTacticsID),
  738. };
  739. DataSet ds = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  740. if (ds != null && ds.Tables[0].Rows.Count > 0)
  741. {
  742. isError = true;
  743. intResult = -1;//重复数据
  744. oracleTrConn.Rollback();
  745. oracleTrConn.Disconnect();
  746. return intResult;
  747. }
  748. }
  749. // 更新语句
  750. sqlString = @" update TP_PAT_Piecework
  751. set
  752. PieceTacticsID=:PieceTacticsID,
  753. PayPlanID=:PayPlanID,
  754. PieceType=:PieceType,
  755. PieceCoefficient=:PieceCoefficient,
  756. DamageFlag=:DamageFlag,
  757. DamageCoefficient=:DamageCoefficient,
  758. UnqualifiedFlag=:UnqualifiedFlag,
  759. UnqualifiedCoefficient=:UnqualifiedCoefficient,
  760. QualifiedFlag=:QualifiedFlag,
  761. QualifiedCoefficient=:QualifiedCoefficient,
  762. UpdateUserID=:UpdateUserID,
  763. PieceTacticsName=:PieceTacticsName
  764. where PieceTacticsID=:PieceTacticsID
  765. ";
  766. parmeters1 = new OracleParameter[]
  767. {
  768. new OracleParameter(":PieceTacticsID",pieceworkendity.PieceTacticsID),
  769. new OracleParameter(":PayPlanID",pieceworkendity.PayPlanID),
  770. new OracleParameter(":PieceType",pieceworkendity.PieceType),
  771. new OracleParameter(":PieceCoefficient",pieceworkendity.PieceCoefficient),
  772. new OracleParameter(":DamageFlag",pieceworkendity.DamageFlag),
  773. new OracleParameter(":DamageCoefficient",pieceworkendity.DamageCoefficient),
  774. new OracleParameter(":UnqualifiedFlag",pieceworkendity.UnqualifiedFlag),
  775. new OracleParameter(":UnqualifiedCoefficient",pieceworkendity.UnqualifiedCoefficient),
  776. new OracleParameter(":QualifiedFlag",pieceworkendity.QualifiedFlag),
  777. new OracleParameter(":QualifiedCoefficient",pieceworkendity.QualifiedCoefficient),
  778. new OracleParameter(":UpdateUserID",sUserInfo.UserID),
  779. new OracleParameter(":PieceTacticsName",pieceworkendity.PayPlanName),
  780. };
  781. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  782. //删除完事重新添加子表数据
  783. sqlString = "delete from TP_PAT_Wages where PieceTacticsID=" + pieceworkendity.PieceTacticsID;
  784. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  785. sqlString = "delete from TP_PAT_QualityWages where PieceTacticsID=" + pieceworkendity.PieceTacticsID;
  786. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  787. sqlString = "delete from TP_PAT_PIECEPROCEDURE where PieceTacticsID=" + pieceworkendity.PieceTacticsID;
  788. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  789. // 插入计件工序
  790. sqlString = @"insert into TP_PAT_PIECEPROCEDURE
  791. (
  792. PIECETACTICSID,
  793. PROCEDUREID,
  794. PROCEDUREFLAG
  795. ) values
  796. (
  797. :PIECETACTICSID,
  798. :PROCEDUREID,
  799. :PROCEDUREFLAG
  800. )";
  801. if (!string.IsNullOrEmpty(pieceworkendity.PieceProcedureIDS))
  802. {
  803. string[] sub = pieceworkendity.PieceProcedureIDS.Split(',');
  804. for (int i = 0; i < sub.Length; i++)
  805. {
  806. parmeters1 = new OracleParameter[]
  807. {
  808. new OracleParameter(":PieceTacticsID",pieceworkendity.PieceTacticsID),
  809. new OracleParameter(":PROCEDUREID",sub[i]),
  810. new OracleParameter(":PROCEDUREFLAG",1),
  811. };
  812. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  813. }
  814. }
  815. // 插入质量工序
  816. sqlString = @"insert into TP_PAT_PIECEPROCEDURE
  817. (
  818. PIECETACTICSID,
  819. PROCEDUREID,
  820. PROCEDUREFLAG
  821. ) values
  822. (
  823. :PIECETACTICSID,
  824. :PROCEDUREID,
  825. :PROCEDUREFLAG
  826. )";
  827. if (!string.IsNullOrEmpty(pieceworkendity.PieceProcedureIDS))
  828. {
  829. string[] sub = pieceworkendity.QualityBaseProcedureIDS.Split(',');
  830. for (int i = 0; i < sub.Length; i++)
  831. {
  832. parmeters1 = new OracleParameter[]
  833. {
  834. new OracleParameter(":PieceTacticsID",pieceworkendity.PieceTacticsID),
  835. new OracleParameter(":PROCEDUREID",sub[i]),
  836. new OracleParameter(":PROCEDUREFLAG",2),
  837. };
  838. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  839. }
  840. }
  841. if (pieceworkendity.wagesentity != null)
  842. {
  843. foreach (Dongke.IBOSS.PRD.WCF.DataModels.PAMModule.WagesEntity entity in pieceworkendity.wagesentity)
  844. {
  845. //sqlString = "select 1 from TP_PAT_Wages where WagesTypeID=:WagesTypeID ";
  846. //parmeters1 = new OracleParameter[]
  847. //{
  848. // new OracleParameter(":WagesTypeID",entity.WagesTypeID),
  849. //};
  850. //DataSet ds3 = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  851. //if (ds3 != null && ds3.Tables[0].Rows.Count > 0)
  852. //{
  853. // isError = true;
  854. // intResult = -2;//重复数据
  855. // break;
  856. //}
  857. sqlString = @"insert into TP_PAT_Wages
  858. (
  859. PieceTacticsID,
  860. WagesTypeID,
  861. StandardWages,
  862. DamageSubsidyRate,
  863. DamageSubsidy,
  864. RSuperiorCoefficient,
  865. RQualifiedCoefficient,
  866. RepairSubsidyRate,
  867. RepairSubsidy
  868. ) values
  869. (
  870. :PieceTacticsID,
  871. :WagesTypeID,
  872. :StandardWages,
  873. :DamageSubsidyRate,
  874. :DamageSubsidy,
  875. :RSuperiorCoefficient,
  876. :RQualifiedCoefficient,
  877. :RepairSubsidyRate,
  878. :RepairSubsidy
  879. )
  880. ";
  881. parmeters1 = new OracleParameter[]
  882. {
  883. new OracleParameter(":PieceTacticsID",pieceworkendity.PieceTacticsID),
  884. new OracleParameter(":WagesTypeID",entity.WagesTypeID),
  885. new OracleParameter(":StandardWages",entity.StandardWages),
  886. new OracleParameter(":DamageSubsidyRate",entity.DamageSubsidyRate),
  887. new OracleParameter(":DamageSubsidy",entity.DamageSubsidy),
  888. new OracleParameter(":RSuperiorCoefficient",entity.RSuperiorCoefficient),
  889. new OracleParameter(":RQualifiedCoefficient",entity.RQualifiedCoefficient),
  890. new OracleParameter(":RepairSubsidyRate",entity.RepairSubsidyRate),
  891. new OracleParameter(":RepairSubsidy",entity.RepairSubsidy),
  892. };
  893. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  894. //质量工价
  895. if (entity.qualitywagesentity != null)
  896. {
  897. foreach (QualityWagesEntity qualitywagesentity in entity.qualitywagesentity)
  898. {
  899. sqlString = "select 1 from TP_PAT_QualityWages where QualityRate=:QualityRate and WagesTypeID=:WagesTypeID and PieceTacticsID=:PieceTacticsID";
  900. parmeters1 = new OracleParameter[]
  901. {
  902. new OracleParameter(":QualityRate",qualitywagesentity.QualityRate),
  903. new OracleParameter(":WagesTypeID",qualitywagesentity.WagesTypeID),
  904. new OracleParameter(":PieceTacticsID",pieceworkendity.PieceTacticsID),
  905. };
  906. DataSet ds2 = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  907. if (ds2 != null && ds2.Tables[0].Rows.Count > 0)
  908. {
  909. isError = true;
  910. intResult = -3;//重复数据
  911. break;
  912. }
  913. sqlString = @"insert into TP_PAT_QualityWages
  914. (
  915. PieceTacticsID,
  916. WagesTypeID,
  917. QualityRate,
  918. Balance,
  919. QualityWages
  920. ) values
  921. (
  922. :PieceTacticsID,
  923. :WagesTypeID,
  924. :QualityRate,
  925. :Balance,
  926. :QualityWages
  927. )
  928. ";
  929. parmeters1 = new OracleParameter[]
  930. {
  931. new OracleParameter(":PieceTacticsID",pieceworkendity.PieceTacticsID),
  932. new OracleParameter(":WagesTypeID",qualitywagesentity.WagesTypeID),
  933. new OracleParameter(":QualityRate",qualitywagesentity.QualityRate),
  934. new OracleParameter(":Balance",qualitywagesentity.Balance),
  935. new OracleParameter(":QualityWages",qualitywagesentity.QualityWages),
  936. };
  937. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  938. }
  939. }
  940. }
  941. }
  942. }
  943. if (isError)
  944. {
  945. oracleTrConn.Rollback();
  946. oracleTrConn.Disconnect();
  947. }
  948. else
  949. {
  950. oracleTrConn.Commit();
  951. oracleTrConn.Disconnect();
  952. }
  953. return intResult;
  954. }
  955. catch (Exception ex)
  956. {
  957. if (oracleTrConn.ConnState == ConnectionState.Open)
  958. {
  959. oracleTrConn.Rollback();
  960. oracleTrConn.Disconnect();
  961. }
  962. throw ex;
  963. }
  964. }
  965. /// <summary>
  966. /// 保存品质考核策略
  967. /// </summary>
  968. /// <param name="IsEdit">false 新建 true 编辑</param>
  969. /// <param name="dtJobsPayPlan">数据源</param>
  970. /// <param name="sUserInfo"></param>
  971. /// <returns></returns>
  972. public static int SaveQualityASS(QualityASS qualityASS, SUserInfo sUserInfo)
  973. {
  974. IDBTransaction oracleTrConn = ClsDbFactory.CreateDBTransaction(DataBaseType.ORACLE, DataManager.ConnectionString);
  975. try
  976. {
  977. int intResult = 0;
  978. oracleTrConn.Connect();
  979. string sqlString = "";
  980. OracleParameter[] parmeters1 = null;
  981. bool isError = false;
  982. if (qualityASS.QualityASSTacticsID == 0) // 新增
  983. {
  984. //一个解决方案只能对应一个计件工资策略
  985. //if (qualityASS.PayPlanID != null)
  986. //{
  987. // sqlString = "select 1 from TP_PAT_QualityASS where PayPlanID=:PayPlanID and AccountID=:AccountID ";
  988. // parmeters1 = new OracleParameter[]
  989. // {
  990. // new OracleParameter(":PayPlanID",qualityASS.PayPlanID),
  991. // new OracleParameter(":AccountID",sUserInfo.AccountID),
  992. // };
  993. // DataSet ds = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  994. // if (ds != null && ds.Tables[0].Rows.Count > 0)
  995. // {
  996. // isError = true;
  997. // intResult = -1;//重复数据
  998. // oracleTrConn.Rollback();
  999. // oracleTrConn.Disconnect();
  1000. // return intResult;
  1001. // }
  1002. //}
  1003. string sql = "select SEQ_PAT_QualityASS_ID.nextval from dual";
  1004. string idStr = oracleTrConn.GetSqlResultToStr(sql);
  1005. sqlString = @"insert into TP_PAT_QualityASS
  1006. (
  1007. QualityASSTacticsID,
  1008. QualityTacticsName,
  1009. PayPlanID,
  1010. DefectFine,
  1011. AccountID,
  1012. CreateUserID,
  1013. UpdateUserID
  1014. ) values
  1015. (
  1016. :QualityASSTacticsID,
  1017. :QualityTacticsName,
  1018. :PayPlanID,
  1019. :DefectFine,
  1020. :AccountID,
  1021. :CreateUserID,
  1022. :UpdateUserID
  1023. )";
  1024. parmeters1 = new OracleParameter[]
  1025. {
  1026. new OracleParameter(":QualityASSTacticsID",idStr),
  1027. new OracleParameter(":PayPlanID",qualityASS.PayPlanID),
  1028. new OracleParameter(":QualityTacticsName",qualityASS.QualityTacticsName),
  1029. new OracleParameter(":DefectFine",qualityASS.DefectFine),
  1030. new OracleParameter(":AccountID",sUserInfo.AccountID),
  1031. new OracleParameter(":CreateUserID",sUserInfo.UserID),
  1032. new OracleParameter(":UpdateUserID",sUserInfo.UserID),
  1033. };
  1034. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  1035. // // 插入质量工序
  1036. // sqlString = @"insert into TP_PAT_QualityProcedure
  1037. // (
  1038. // QualityASSTacticsID,
  1039. // PROCEDUREID
  1040. // ) values
  1041. // (
  1042. // :QualityASSTacticsID,
  1043. // :PROCEDUREID
  1044. // )";
  1045. // if (!string.IsNullOrEmpty(qualityASS.QualityBaseProcedureIDS))
  1046. // {
  1047. // string[] sub = qualityASS.QualityBaseProcedureIDS.Split(',');
  1048. // for (int i = 0; i < sub.Length; i++)
  1049. // {
  1050. // parmeters1 = new OracleParameter[]
  1051. // {
  1052. // new OracleParameter(":QualityASSTacticsID",idStr),
  1053. // new OracleParameter(":PROCEDUREID",sub[i]),
  1054. // };
  1055. // intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  1056. // }
  1057. // }
  1058. if (qualityASS.qualityGoods != null)
  1059. {
  1060. foreach (Dongke.IBOSS.PRD.WCF.DataModels.PAMModule.QualityGoods entity in qualityASS.qualityGoods)
  1061. {
  1062. //sqlString = "select 1 from TP_PAT_QualityGoods where WagesTypeID=:WagesTypeID ";
  1063. //parmeters1 = new OracleParameter[]
  1064. //{
  1065. // new OracleParameter(":WagesTypeID",entity.WagesTypeID),
  1066. //};
  1067. //DataSet ds = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  1068. //if (ds != null && ds.Tables[0].Rows.Count > 0)
  1069. //{
  1070. // isError = true;
  1071. // intResult = -2;//重复数据
  1072. // break;
  1073. //}
  1074. sqlString = @"insert into TP_PAT_QualityGoods
  1075. (
  1076. QualityASSTacticsID,
  1077. WagesTypeID
  1078. ) values
  1079. (
  1080. :PieceTacticsID,
  1081. :WagesTypeID
  1082. )
  1083. ";
  1084. parmeters1 = new OracleParameter[]
  1085. {
  1086. new OracleParameter(":PieceTacticsID",idStr),
  1087. new OracleParameter(":WagesTypeID",entity.WagesTypeID),
  1088. };
  1089. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  1090. //质量工价
  1091. if (entity.qualityReward != null)
  1092. {
  1093. foreach (QualityReward qualitywagesentity in entity.qualityReward)
  1094. {
  1095. sqlString = "select 1 from TP_PAT_QualityReward where QualityRate=:QualityRate and WagesTypeID=:WagesTypeID and QualityASSTacticsID=:QualityASSTacticsID";
  1096. parmeters1 = new OracleParameter[]
  1097. {
  1098. new OracleParameter(":QualityRate",qualitywagesentity.QualityRate),
  1099. new OracleParameter(":WagesTypeID",qualitywagesentity.WagesTypeID),
  1100. new OracleParameter(":QualityASSTacticsID",qualitywagesentity.QualityASSTacticsID),
  1101. };
  1102. DataSet ds2 = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  1103. if (ds2 != null && ds2.Tables[0].Rows.Count > 0)
  1104. {
  1105. isError = true;
  1106. intResult = -3;//重复数据
  1107. break;
  1108. }
  1109. sqlString = @"insert into TP_PAT_QualityReward
  1110. (
  1111. QualityASSTacticsID,
  1112. WagesTypeID,
  1113. QualityRate,
  1114. QualityReward
  1115. ) values
  1116. (
  1117. :QualityASSTacticsID,
  1118. :WagesTypeID,
  1119. :QualityRate,
  1120. :QualityReward
  1121. )
  1122. ";
  1123. parmeters1 = new OracleParameter[]
  1124. {
  1125. new OracleParameter(":QualityASSTacticsID",idStr),
  1126. new OracleParameter(":WagesTypeID",qualitywagesentity.WagesTypeID),
  1127. new OracleParameter(":QualityRate",qualitywagesentity.QualityRate),
  1128. new OracleParameter(":QualityReward",qualitywagesentity.QualityReward2),
  1129. };
  1130. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  1131. }
  1132. }
  1133. }
  1134. }
  1135. }
  1136. else
  1137. {
  1138. //编辑
  1139. //一个解决方案只能对应一个计件工资策略
  1140. //if (qualityASS.PayPlanID != null)
  1141. //{
  1142. // sqlString = "select 1 from TP_PAT_QualityASS where PayPlanID=:PayPlanID and AccountID=:AccountID ";
  1143. // parmeters1 = new OracleParameter[]
  1144. // {
  1145. // new OracleParameter(":PayPlanID",qualityASS.PayPlanID),
  1146. // new OracleParameter(":AccountID",sUserInfo.AccountID),
  1147. // };
  1148. // DataSet ds = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  1149. // if (ds != null && ds.Tables[0].Rows.Count > 0)
  1150. // {
  1151. // isError = true;
  1152. // intResult = -1;//重复数据
  1153. // oracleTrConn.Rollback();
  1154. // oracleTrConn.Disconnect();
  1155. // return intResult;
  1156. // }
  1157. //}
  1158. // 更新语句
  1159. sqlString = @" update TP_PAT_QualityASS
  1160. set
  1161. PayPlanID=:PayPlanID,
  1162. DefectFine=:DefectFine,
  1163. QualityTacticsName=:QualityTacticsName,
  1164. UpdateUserID=:UpdateUserID
  1165. where QualityASSTacticsID=:QualityASSTacticsID
  1166. ";
  1167. parmeters1 = new OracleParameter[]
  1168. {
  1169. new OracleParameter(":QualityASSTacticsID",qualityASS.QualityASSTacticsID),
  1170. new OracleParameter(":PayPlanID",qualityASS.PayPlanID),
  1171. new OracleParameter(":DefectFine",qualityASS.DefectFine),
  1172. new OracleParameter(":QualityTacticsName",qualityASS.QualityTacticsName),
  1173. new OracleParameter(":UpdateUserID",sUserInfo.UserID),
  1174. };
  1175. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  1176. //删除完事重新添加子表数据
  1177. sqlString = "delete from TP_PAT_QualityGoods where QualityASSTacticsID=" + qualityASS.QualityASSTacticsID;
  1178. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  1179. sqlString = "delete from TP_PAT_QualityReward where QualityASSTacticsID=" + qualityASS.QualityASSTacticsID;
  1180. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  1181. //sqlString = "delete from TP_PAT_QualityProcedure where QualityASSTacticsID=" + qualityASS.QualityASSTacticsID;
  1182. //intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  1183. // // 插入质量工序
  1184. // sqlString = @"insert into TP_PAT_QualityProcedure
  1185. // (
  1186. // QualityASSTacticsID,
  1187. // PROCEDUREID
  1188. // ) values
  1189. // (
  1190. // :QualityASSTacticsID,
  1191. // :PROCEDUREID
  1192. // )";
  1193. // if (!string.IsNullOrEmpty(qualityASS.QualityBaseProcedureIDS))
  1194. // {
  1195. // string[] sub = qualityASS.QualityBaseProcedureIDS.Split(',');
  1196. // for (int i = 0; i < sub.Length; i++)
  1197. // {
  1198. // parmeters1 = new OracleParameter[]
  1199. // {
  1200. // new OracleParameter(":QualityASSTacticsID", qualityASS.QualityASSTacticsID),
  1201. // new OracleParameter(":PROCEDUREID",sub[i]),
  1202. // };
  1203. // intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  1204. // }
  1205. // }
  1206. if (qualityASS.qualityGoods != null)
  1207. {
  1208. foreach (Dongke.IBOSS.PRD.WCF.DataModels.PAMModule.QualityGoods entity in qualityASS.qualityGoods)
  1209. {
  1210. //sqlString = "select 1 from TP_PAT_QualityGoods where WagesTypeID=:WagesTypeID ";
  1211. //parmeters1 = new OracleParameter[]
  1212. //{
  1213. // new OracleParameter(":WagesTypeID",entity.WagesTypeID),
  1214. //};
  1215. //DataSet ds3 = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  1216. //if (ds3 != null && ds3.Tables[0].Rows.Count > 0)
  1217. //{
  1218. // isError = true;
  1219. // intResult = -2;//重复数据
  1220. // break;
  1221. //}
  1222. sqlString = @"insert into TP_PAT_QualityGoods
  1223. (
  1224. QualityASSTacticsID,
  1225. WagesTypeID
  1226. ) values
  1227. (
  1228. :QualityASSTacticsID,
  1229. :WagesTypeID
  1230. )
  1231. ";
  1232. parmeters1 = new OracleParameter[]
  1233. {
  1234. new OracleParameter(":QualityASSTacticsID",qualityASS.QualityASSTacticsID),
  1235. new OracleParameter(":WagesTypeID",entity.WagesTypeID),
  1236. };
  1237. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  1238. //质量工价
  1239. if (entity.qualityReward != null)
  1240. {
  1241. foreach (QualityReward qualitywagesentity in entity.qualityReward)
  1242. {
  1243. sqlString = "select 1 from TP_PAT_QualityReward where QualityRate=:QualityRate and WagesTypeID=:WagesTypeID and QualityASSTacticsID=:QualityASSTacticsID";
  1244. parmeters1 = new OracleParameter[]
  1245. {
  1246. new OracleParameter(":QualityRate",qualitywagesentity.QualityRate),
  1247. new OracleParameter(":WagesTypeID",qualitywagesentity.WagesTypeID),
  1248. new OracleParameter(":QualityASSTacticsID",qualityASS.QualityASSTacticsID),
  1249. };
  1250. DataSet ds2 = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  1251. if (ds2 != null && ds2.Tables[0].Rows.Count > 0)
  1252. {
  1253. isError = true;
  1254. intResult = -3;//重复数据
  1255. break;
  1256. }
  1257. sqlString = @"insert into TP_PAT_QualityReward
  1258. (
  1259. QualityASSTacticsID,
  1260. WagesTypeID,
  1261. QualityRate,
  1262. QualityReward
  1263. ) values
  1264. (
  1265. :QualityASSTacticsID,
  1266. :WagesTypeID,
  1267. :QualityRate,
  1268. :QualityReward
  1269. )
  1270. ";
  1271. parmeters1 = new OracleParameter[]
  1272. {
  1273. new OracleParameter(":QualityASSTacticsID",qualityASS.QualityASSTacticsID),
  1274. new OracleParameter(":WagesTypeID",qualitywagesentity.WagesTypeID),
  1275. new OracleParameter(":QualityRate",qualitywagesentity.QualityRate),
  1276. new OracleParameter(":QualityReward",qualitywagesentity.QualityReward2),
  1277. };
  1278. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  1279. }
  1280. }
  1281. }
  1282. }
  1283. }
  1284. if (isError)
  1285. {
  1286. oracleTrConn.Rollback();
  1287. oracleTrConn.Disconnect();
  1288. }
  1289. else
  1290. {
  1291. oracleTrConn.Commit();
  1292. oracleTrConn.Disconnect();
  1293. }
  1294. return intResult;
  1295. }
  1296. catch (Exception ex)
  1297. {
  1298. if (oracleTrConn.ConnState == ConnectionState.Open)
  1299. {
  1300. oracleTrConn.Rollback();
  1301. oracleTrConn.Disconnect();
  1302. }
  1303. throw ex;
  1304. }
  1305. finally
  1306. {
  1307. if (oracleTrConn.ConnState == ConnectionState.Open)
  1308. {
  1309. oracleTrConn.Rollback();
  1310. oracleTrConn.Disconnect();
  1311. }
  1312. }
  1313. }
  1314. #region 工资结算
  1315. /// <summary>
  1316. /// 结算工资
  1317. /// </summary>
  1318. /// <param name="IsEdit">false 新建 true 编辑</param>
  1319. /// <param name="dtJobsPayPlan">数据源</param>
  1320. /// <param name="sUserInfo"></param>
  1321. /// <returns></returns>
  1322. public static int SavePayPiecework(int Month, int Year, SUserInfo sUserInfo)
  1323. {
  1324. IDBTransaction oracleTrConn = ClsDbFactory.CreateDBTransaction(DataBaseType.ORACLE, DataManager.ConnectionString);
  1325. try
  1326. {
  1327. DataTable dtExistUserID = new DataTable();
  1328. dtExistUserID.Columns.Add("staffid", typeof(int));
  1329. dtExistUserID.Columns.Add("userid", typeof(int));
  1330. int intResult = 0;
  1331. bool UpdateSettlementFlag = false;
  1332. oracleTrConn.Connect();
  1333. oracleTrConn.IsCommandTimeout = false;
  1334. #region 判断是否已经结算此月
  1335. string sqlExist = "select 1 from TP_PAR_PayrollAccount where YYYYMM=:YYYYMM";
  1336. OracleParameter[] parmetersExist = new OracleParameter[]
  1337. {
  1338. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  1339. };
  1340. DataSet dsExist = oracleTrConn.GetSqlResultToDs(sqlExist, parmetersExist);
  1341. if (dsExist != null && dsExist.Tables[0].Rows.Count > 0)
  1342. {
  1343. oracleTrConn.Rollback();
  1344. oracleTrConn.Disconnect();
  1345. return -99;
  1346. }
  1347. #endregion
  1348. #region 查询系统参数设定值,用来结算工资范围取值
  1349. DateTime? dateStartTime = null;
  1350. DateTime? dateEndTime = null;
  1351. string sqlString = "select SettingValue from TP_MST_SystemSetting where accountid=:accountid and SettingCode='S_CMN_0003'";
  1352. OracleParameter[] parmeters1 = new OracleParameter[]
  1353. {
  1354. new OracleParameter(":accountid",sUserInfo.AccountID),
  1355. };
  1356. DataSet dsSystemSettings = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  1357. if (dsSystemSettings != null && dsSystemSettings.Tables[0].Rows.Count > 0)
  1358. {
  1359. // 算出此月一共多少天,防止设置的值,大于当月的天数
  1360. int daysCount = DateTime.DaysInMonth(Year, Month);
  1361. if (dsSystemSettings.Tables[0].Rows[0]["SettingValue"].ToString() == "月末" ||
  1362. dsSystemSettings.Tables[0].Rows[0]["SettingValue"].ToString() == "0")
  1363. {
  1364. dateStartTime = new DateTime(Year, Month, 1);
  1365. dateEndTime = new DateTime(Year, Month, daysCount, 23, 59, 59);
  1366. }
  1367. else
  1368. {
  1369. // 选择的值,大于当月的天数
  1370. if (Convert.ToInt32(dsSystemSettings.Tables[0].Rows[0]["SettingValue"]) > daysCount)
  1371. {
  1372. dateEndTime = new DateTime(Year, Month, daysCount, 23, 59, 59);
  1373. dateStartTime = dateEndTime.Value.AddMonths(-1).AddDays(1);
  1374. }
  1375. else
  1376. {
  1377. dateEndTime = new DateTime(Year, Month, Convert.ToInt32(dsSystemSettings.Tables[0].Rows[0]["SettingValue"]), 23, 59, 59);
  1378. dateStartTime = dateEndTime.Value.AddMonths(-1).AddDays(1);
  1379. }
  1380. }
  1381. }
  1382. //dateStartTime = new DateTime(2015, 9, 8);
  1383. //dateEndTime = new DateTime(2015,9, 8, 23, 59, 59);
  1384. //dateEndTime = dateStartTime.Value.AddDays(10);
  1385. #endregion
  1386. #region 根据筛选日期往临时表里插入数据
  1387. parmeters1 = new OracleParameter[]
  1388. {
  1389. new OracleParameter(":dateStartTime",OracleDbType.Date,dateStartTime,ParameterDirection.Input),
  1390. new OracleParameter(":dateEndTime",OracleDbType.Date,dateEndTime,ParameterDirection.Input),
  1391. new OracleParameter(":accountid",sUserInfo.AccountID),
  1392. };
  1393. // 生产数据临时表
  1394. // sqlString = @"insert into TMP_PAM_ProductionData
  1395. // select
  1396. // ProductionDataID,
  1397. // BarCode,
  1398. // CentralizedBatchNo,
  1399. // ProductionLineID,
  1400. // ProductionLineCode,
  1401. // ProductionLineName,
  1402. // ProcedureID,
  1403. // ProcedureCode,
  1404. // ProcedureName,
  1405. // ProcedureModel,
  1406. // ModelType,
  1407. // PieceType,
  1408. // IsReworked,
  1409. // NodeType,
  1410. // IsPublicBody,
  1411. // IsReFire,
  1412. // GoodsLevelID,
  1413. // GoodsLevelTypeID,
  1414. // SpecialRepairFlag,
  1415. // OrganizationID,
  1416. // GoodsID,
  1417. // GoodsCode,
  1418. // GoodsName,
  1419. // UserID,
  1420. // UserCode,
  1421. // UserName,
  1422. // ClassesSettingID,
  1423. // KilnID,
  1424. // KilnCode,
  1425. // KilnName,
  1426. // KilnCarID,
  1427. // KilnCarCode,
  1428. // KilnCarName,
  1429. // KilnCarBatchNo,
  1430. // KilnCarPosition,
  1431. // ReworkProcedureID,
  1432. // ReworkProcedureCode,
  1433. // ReworkProcedureName,
  1434. // GroutingDailyID,
  1435. // GroutingDailyDetailID,
  1436. // GroutingLineID,
  1437. // GroutingLineCode,
  1438. // GroutingLineName,
  1439. // GMouldTypeID,
  1440. // CanManyTimes,
  1441. // GroutingLineDetailID,
  1442. // GroutingDate,
  1443. // GroutingMouldCode,
  1444. // MouldCode,
  1445. // GroutingUserID,
  1446. // GroutingUserCode,
  1447. // GroutingNum,
  1448. // Remarks,
  1449. // AccountDate,
  1450. // SettlementFlag,
  1451. // AccountID,
  1452. // ValueFlag,
  1453. // CreateTime,
  1454. // CreateUserID,
  1455. // UpdateTime,
  1456. // UpdateUserID,
  1457. // OPTimeStamp
  1458. // from TP_PM_ProductionData where CreateTime >=:dateStartTime and CreateTime<=:dateEndTime and accountid=:accountid and valueflag=1 ";//and SettlementFlag=0
  1459. // intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  1460. //#region 根据筛选日期更新生产数据结算标识
  1461. //// 更新生产数据结算标识
  1462. //sqlString = @"update TP_PM_ProductionData set SettlementFlag=1 where CreateTime >=:dateStartTime and CreateTime<=:dateEndTime and accountid=:accountid and valueflag=1 and SettlementFlag=0";
  1463. //intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  1464. //#endregion
  1465. // 生产缺陷
  1466. sqlString = @"insert into TMP_PAM_Defect
  1467. select
  1468. ProductionDefectID,
  1469. ProductionDataID,
  1470. BarCode,
  1471. ProductionLineID,
  1472. ProductionLineCode,
  1473. ProductionLineName,
  1474. ProcedureID,
  1475. ProcedureCode,
  1476. ProcedureName,
  1477. UserID,
  1478. UserCode,
  1479. UserName,
  1480. GoodsID,
  1481. GoodsCode,
  1482. GoodsName,
  1483. DefectID,
  1484. DefectCode,
  1485. DefectName,
  1486. DefectPositionID,
  1487. DefectPositionCode,
  1488. DefectPositionName,
  1489. ScrapResponFlag,
  1490. DefectProductionDataID,
  1491. DefectProcedureID,
  1492. DefectProcedureCode,
  1493. DefectProcedureName,
  1494. DefectUserID,
  1495. DefectUserCode,
  1496. DefectUserName,
  1497. DefectJobs,
  1498. DefectFine,
  1499. MissedUserID,
  1500. MissedUserCode,
  1501. MissedUserName,
  1502. Remarks,
  1503. AccountID,
  1504. ValueFlag,
  1505. CreateTime,
  1506. CreateUserID,
  1507. UpdateTime,
  1508. UpdateUserID,
  1509. OPTimeStamp
  1510. from TP_PM_Defect where CreateTime >=:dateStartTime and CreateTime<=:dateEndTime and accountid=:accountid and valueflag=1";
  1511. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  1512. //生产缺陷责任者
  1513. sqlString = @"insert into TMP_PAM_DefectResponsible
  1514. select
  1515. ProductionDefectID,
  1516. StaffID,
  1517. StaffStatus,
  1518. UserID,
  1519. UserCode,
  1520. UJobsID,
  1521. SJobsID,
  1522. AccountID,
  1523. ValueFlag,
  1524. CreateTime,
  1525. CreateUserID,
  1526. UpdateTime,
  1527. UpdateUserID,
  1528. OPTimeStamp
  1529. from TP_PM_DefectResponsible where CreateTime >=:dateStartTime and CreateTime<=:dateEndTime and accountid=:accountid and valueflag=1";
  1530. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  1531. // //缺陷漏检责任者
  1532. // sqlString = @"insert into TP_PAM_DefectMissedResponsible
  1533. // select * from TP_PM_DefectMissedResponsible where CreateTime >=:dateStartTime and CreateTime<=:dateEndTime and accountid=:accountid and valueflag=1";
  1534. // intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  1535. //废弃产品
  1536. sqlString = @"insert into TMP_PAM_ScrapProduct
  1537. select
  1538. ScrapProductID,
  1539. BarCode,
  1540. ProductionLineID,
  1541. ProductionLineCode,
  1542. ProductionLineName,
  1543. ProcedureID,
  1544. ProcedureCode,
  1545. ProcedureName,
  1546. GoodsID,
  1547. GoodsCode,
  1548. GoodsName,
  1549. GroutingDailyID,
  1550. GroutingDailyDetailID,
  1551. GroutingDate,
  1552. GroutingLineID,
  1553. GroutingLineCode,
  1554. GroutingLineName,
  1555. GMouldTypeID,
  1556. GroutingLineDetailID,
  1557. GroutingMouldCode,
  1558. MouldCode,
  1559. GroutingUserID,
  1560. GroutingUserCode,
  1561. GroutingNum,
  1562. IsPublicBody,
  1563. IsReFire,
  1564. SpecialRepairFlag,
  1565. GoodsLevelID,
  1566. GoodsLevelTypeID,
  1567. ResponType,
  1568. ScrapFine,
  1569. ScrapDate,
  1570. Rreason,
  1571. Remarks,
  1572. AuditStatus,
  1573. Auditor,
  1574. AuditDate,
  1575. AuditOpinion,
  1576. AccountDate,
  1577. KilnID,
  1578. KilnCode,
  1579. KilnName,
  1580. KilnCarID,
  1581. KilnCarCode,
  1582. KilnCarName,
  1583. KilnCarBatchNo,
  1584. KilnCarPosition,
  1585. AccountID,
  1586. ValueFlag,
  1587. CreateTime,
  1588. CreateUserID,
  1589. UpdateTime,
  1590. UpdateUserID,
  1591. OPTimeStamp
  1592. from TP_PM_ScrapProduct where CreateTime >=:dateStartTime and CreateTime<=:dateEndTime and accountid=:accountid and valueflag=1 and AuditStatus=1";
  1593. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  1594. //产品废弃责任工序
  1595. sqlString = @"insert into TMP_PAM_ResponProcedure
  1596. select
  1597. ResponProcedureID,
  1598. ScrapProductID,
  1599. BarCode,
  1600. ProductionDataID,
  1601. ProductionLineID,
  1602. ProductionLineCode,
  1603. ProductionLineName,
  1604. ProcedureID,
  1605. ProcedureCode,
  1606. ProcedureName,
  1607. UserID,
  1608. UserCode,
  1609. UserName,
  1610. Remarks,
  1611. AccountID,
  1612. ValueFlag,
  1613. CreateTime,
  1614. CreateUserID,
  1615. UpdateTime,
  1616. UpdateUserID,
  1617. OPTimeStamp
  1618. from TP_PM_ResponProcedure
  1619. where CreateTime >=:dateStartTime and CreateTime<=:dateEndTime and accountid=:accountid and valueflag=1 ";
  1620. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  1621. //产品废弃责任者
  1622. sqlString = @"insert into TMP_PAM_ScrapResponsible
  1623. select
  1624. ResponsibleID,
  1625. ScrapProductID,
  1626. BarCode,
  1627. ResponType,
  1628. ResponProcedureID,
  1629. ScrapFine,
  1630. StaffID,
  1631. StaffStatus,
  1632. UserID,
  1633. UserCode,
  1634. UJobsID,
  1635. SJobsID,
  1636. AccountID,
  1637. CreateTime,
  1638. CreateUserID,
  1639. UpdateTime,
  1640. UpdateUserID,
  1641. OPTimeStamp
  1642. from TP_PM_ScrapResponsible where CreateTime >=:dateStartTime and CreateTime<=:dateEndTime and accountid=:accountid ";
  1643. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  1644. //成品 (干补补贴用)
  1645. sqlString = @"insert into TMP_PAM_FinishedProduct
  1646. select
  1647. BarCode,
  1648. ProductionLineID,
  1649. ProductionLineCode,
  1650. ProductionLineName,
  1651. IsPublicBody,
  1652. IsReFire,
  1653. SpecialRepairFlag,
  1654. GoodsLevelID,
  1655. GoodsLevelTypeID,
  1656. GoodsID,
  1657. GoodsCode,
  1658. GoodsName,
  1659. GroutingDailyID,
  1660. GroutingDailyDetailID,
  1661. GroutingDate,
  1662. GroutingLineID,
  1663. GroutingLineCode,
  1664. GroutingLineName,
  1665. GMouldTypeID,
  1666. GroutingLineDetailID,
  1667. GroutingMouldCode,
  1668. MouldCode,
  1669. GroutingUserID,
  1670. GroutingUserCode,
  1671. GroutingNum,
  1672. Remarks,
  1673. AccountDate,
  1674. SettlementFlag,
  1675. KilnID,
  1676. KilnCode,
  1677. KilnName,
  1678. KilnCarID,
  1679. KilnCarCode,
  1680. KilnCarName,
  1681. KilnCarBatchNo,
  1682. KilnCarPosition,
  1683. AccountID,
  1684. ValueFlag,
  1685. CreateTime,
  1686. CreateUserID,
  1687. UpdateTime,
  1688. UpdateUserID,
  1689. OPTimeStamp
  1690. from TP_PM_FinishedProduct where CreateTime >=:dateStartTime and CreateTime<=:dateEndTime and accountid=:accountid and valueflag=1";
  1691. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  1692. #endregion
  1693. #region 读取工资方案,用来最外层循环,以后可以是多个方法,目前只有一个工资方案
  1694. sqlString = "select PayPlanID from TP_PAS_PayPlan where AccountID=:AccountID and ValueFlag=1";
  1695. parmeters1 = new OracleParameter[]
  1696. {
  1697. new OracleParameter(":AccountID",sUserInfo.AccountID),
  1698. };
  1699. DataSet dsPayPlan = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  1700. #endregion
  1701. // dsPayPlan为工资方案数据集
  1702. if (dsPayPlan != null && dsPayPlan.Tables[0].Rows.Count > 0)
  1703. {
  1704. // 进入循环,
  1705. for (int i = 0; i < dsPayPlan.Tables[0].Rows.Count; i++)
  1706. {
  1707. #region 查出计件工资策略
  1708. sqlString = @"select * from TP_PAT_Piecework where accountid=:accountid and valueflag=1 and PayPlanID=:PayPlanID";
  1709. parmeters1 = new OracleParameter[]
  1710. {
  1711. new OracleParameter(":accountid",sUserInfo.AccountID),
  1712. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  1713. };
  1714. DataSet dsPiecework = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  1715. int PieceTacticsID = 0; //计件工资策略ID
  1716. string PieceType = ""; // 工序类型
  1717. decimal PieceCoefficient = 1; // 计件系数
  1718. string DamageFlag = ""; //损坯计算标识
  1719. decimal? DamageCoefficient = null; //损坯系数
  1720. string UnqualifiedFlag = ""; //次品计算标识
  1721. decimal? UnqualifiedCoefficient = null; //次品系数
  1722. string QualifiedFlag = ""; //副品计算标识
  1723. decimal? QualifiedCoefficient = null; //副品系数
  1724. if (dsPiecework != null && dsPiecework.Tables[0].Rows.Count > 0)
  1725. {
  1726. // 有且只能一个对应的工资方案,直接取table0行,如果取出多行,此数据不对,因为有且只能一行
  1727. // 赋值代码
  1728. PieceTacticsID = Convert.ToInt32(dsPiecework.Tables[0].Rows[0]["PieceTacticsID"].ToString());
  1729. PieceType = dsPiecework.Tables[0].Rows[0]["PieceType"].ToString();
  1730. //PieceProcedureID = Convert.ToInt32(dsPiecework.Tables[0].Rows[0]["PieceProcedureID"]);
  1731. PieceCoefficient = Convert.ToDecimal(dsPiecework.Tables[0].Rows[0]["PieceCoefficient"]);
  1732. DamageFlag = dsPiecework.Tables[0].Rows[0]["DamageFlag"].ToString();
  1733. DamageCoefficient = Convert.ToDecimal(dsPiecework.Tables[0].Rows[0]["DamageCoefficient"]);
  1734. UnqualifiedFlag = dsPiecework.Tables[0].Rows[0]["UnqualifiedFlag"].ToString();
  1735. UnqualifiedCoefficient = Convert.ToDecimal(dsPiecework.Tables[0].Rows[0]["UnqualifiedCoefficient"]);
  1736. QualifiedFlag = dsPiecework.Tables[0].Rows[0]["QualifiedFlag"].ToString();
  1737. QualifiedCoefficient = Convert.ToDecimal(dsPiecework.Tables[0].Rows[0]["QualifiedCoefficient"]);
  1738. //QualityBaseProcedureID = Convert.ToInt32(dsPiecework.Tables[0].Rows[0]["QualityBaseProcedureID"]);
  1739. }
  1740. #endregion
  1741. #region 查出计件工资策略(计件工序)
  1742. sqlString = "select PieceTacticsID,ProcedureID,ProcedureFlag from TP_PAT_PieceProcedure where PieceTacticsID=:PieceTacticsID and ProcedureFlag=1";
  1743. parmeters1 = new OracleParameter[]
  1744. {
  1745. new OracleParameter(":PieceTacticsID",PieceTacticsID),
  1746. };
  1747. DataSet dsPieceProcedure_1 = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  1748. sqlString = "select PieceTacticsID,ProcedureID,ProcedureFlag from TP_PAT_PieceProcedure where PieceTacticsID=:PieceTacticsID and ProcedureFlag=2";
  1749. parmeters1 = new OracleParameter[]
  1750. {
  1751. new OracleParameter(":PieceTacticsID",PieceTacticsID),
  1752. };
  1753. DataSet dsPieceProcedure_2 = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  1754. #endregion
  1755. string ProcedureIDS_Delete = "0"; //默认给个0,怕没有些去进行筛选出现错误
  1756. for (int p1 = 0; p1 < dsPieceProcedure_1.Tables[0].Rows.Count; p1++)
  1757. {
  1758. if(p1==0)
  1759. {
  1760. ProcedureIDS_Delete = "";
  1761. }
  1762. ProcedureIDS_Delete = ProcedureIDS_Delete + dsPieceProcedure_1.Tables[0].Rows[p1]["ProcedureID"].ToString() + ",";
  1763. }
  1764. ProcedureIDS_Delete = ProcedureIDS_Delete.Trim(',');
  1765. dsPieceProcedure_1.Tables[0].Merge(dsPieceProcedure_2.Tables[0]);
  1766. string ProcedureIDS_New = "";
  1767. for (int a1 = 0; a1 < dsPieceProcedure_1.Tables[0].Rows.Count; a1++)
  1768. {
  1769. ProcedureIDS_New += dsPieceProcedure_1.Tables[0].Rows[a1]["ProcedureID"].ToString() + ",";
  1770. }
  1771. ProcedureIDS_New = ProcedureIDS_New.Trim(',');
  1772. //modify wangx 20150917
  1773. parmeters1 = new OracleParameter[]
  1774. {
  1775. new OracleParameter(":dateStartTime",OracleDbType.Date,dateStartTime,ParameterDirection.Input),
  1776. new OracleParameter(":dateEndTime",OracleDbType.Date,dateEndTime,ParameterDirection.Input),
  1777. new OracleParameter(":accountid",sUserInfo.AccountID),
  1778. new OracleParameter(":PieceTacticsID",PieceTacticsID),
  1779. };
  1780. // 生产数据临时表
  1781. sqlString = @"insert into TMP_PAM_ProductionData
  1782. select
  1783. ProductionDataID,
  1784. BarCode,
  1785. CentralizedBatchNo,
  1786. ProductionLineID,
  1787. ProductionLineCode,
  1788. ProductionLineName,
  1789. ProcedureID,
  1790. ProcedureCode,
  1791. ProcedureName,
  1792. ProcedureModel,
  1793. ModelType,
  1794. PieceType,
  1795. IsReworked,
  1796. NodeType,
  1797. IsPublicBody,
  1798. IsReFire,
  1799. GoodsLevelID,
  1800. GoodsLevelTypeID,
  1801. SpecialRepairFlag,
  1802. OrganizationID,
  1803. GoodsID,
  1804. GoodsCode,
  1805. GoodsName,
  1806. UserID,
  1807. UserCode,
  1808. UserName,
  1809. ClassesSettingID,
  1810. KilnID,
  1811. KilnCode,
  1812. KilnName,
  1813. KilnCarID,
  1814. KilnCarCode,
  1815. KilnCarName,
  1816. KilnCarBatchNo,
  1817. KilnCarPosition,
  1818. ReworkProcedureID,
  1819. ReworkProcedureCode,
  1820. ReworkProcedureName,
  1821. GroutingDailyID,
  1822. GroutingDailyDetailID,
  1823. GroutingLineID,
  1824. GroutingLineCode,
  1825. GroutingLineName,
  1826. GMouldTypeID,
  1827. CanManyTimes,
  1828. GroutingLineDetailID,
  1829. GroutingDate,
  1830. GroutingMouldCode,
  1831. MouldCode,
  1832. GroutingUserID,
  1833. GroutingUserCode,
  1834. GroutingNum,
  1835. Remarks,
  1836. AccountDate,
  1837. SettlementFlag,
  1838. AccountID,
  1839. ValueFlag,
  1840. CreateTime,
  1841. CreateUserID,
  1842. UpdateTime,
  1843. UpdateUserID,
  1844. OPTimeStamp
  1845. from TP_PM_ProductionData where CreateTime >=:dateStartTime and CreateTime<=:dateEndTime and accountid=:accountid and valueflag=1
  1846. and (TP_PM_ProductionData.ProcedureID in(select ProcedureID from TP_PAT_PieceProcedure where PieceTacticsID=:PieceTacticsID )
  1847. or TP_PM_ProductionData.ModelType=-1)";
  1848. //and (TP_PM_ProductionData.ProcedureID in(select ProcedureID from TP_PAT_PieceProcedure where PieceTacticsID=:PieceTacticsID )
  1849. // or TP_PM_ProductionData.ModelType=-1)
  1850. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  1851. #region 根据筛选日期更新生产数据结算标识
  1852. if (UpdateSettlementFlag)
  1853. {
  1854. // 更新生产数据结算标识
  1855. sqlString = @"update TP_PM_ProductionData set SettlementFlag=1 where CreateTime >=:dateStartTime and CreateTime<=:dateEndTime and accountid=:accountid and valueflag=1 and SettlementFlag=0 and (TP_PM_ProductionData.ProcedureID in(select ProcedureID from TP_PAT_PieceProcedure where PieceTacticsID=:PieceTacticsID ) or TP_PM_ProductionData.ModelType=-1)";
  1856. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  1857. }
  1858. #endregion
  1859. //modify wangx 20150917 end
  1860. #region 查出工资方案参数设定
  1861. sqlString = "select SettingCode,SettingName,PayPlanID,SettingValue from TP_PAS_PayPlanSetting where PayPlanID=:PayPlanID";
  1862. parmeters1 = new OracleParameter[]
  1863. {
  1864. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  1865. };
  1866. DataSet dsPayPlanSetting = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  1867. #endregion
  1868. // 1.算出是否有新品,还是老品
  1869. DataRow[] drMonth = dsPayPlanSetting.Tables[0].Select("SettingCode='01001'");
  1870. int newGoodsMonth = Convert.ToInt32(drMonth[0]["SettingValue"]); //新产品适应周期(月)
  1871. #region 查出工资临时生产数据表数据,用于计算工资
  1872. //查出在产品工介分类中的生产数据,用于计算每个人的工资
  1873. sqlString = @"select
  1874. TMP_PAM_ProductionData.ProductionDataID,
  1875. TMP_PAM_ProductionData.BarCode,
  1876. TMP_PAM_ProductionData.ProcedureID,
  1877. TMP_PAM_ProductionData.GoodsID,
  1878. TMP_PAM_ProductionData.UserID,
  1879. TP_MST_Goods.StartingDate,
  1880. TP_PAM_GoodsWagesType.WagesTypeID,
  1881. TMP_PAM_ProductionData.GoodsLevelTypeID,
  1882. case
  1883. when add_months(TP_MST_Goods.StartingDate, :month)>TMP_PAM_ProductionData.Groutingdate
  1884. then 1 else 3 end as GoodsFlag,
  1885. TMP_PAM_ProductionData.ModelType
  1886. from
  1887. TMP_PAM_ProductionData
  1888. inner join TP_PAM_GoodsWagesType
  1889. on TMP_PAM_ProductionData.GoodsID=TP_PAM_GoodsWagesType.GoodsID
  1890. left join TP_MST_Goods
  1891. on TP_PAM_GoodsWagesType.GoodsID=TP_MST_Goods.GoodsID order by TMP_PAM_ProductionData.UserID ";
  1892. parmeters1 = new OracleParameter[]
  1893. {
  1894. new OracleParameter(":month",newGoodsMonth),
  1895. };
  1896. DataSet dsTMPProductionData = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  1897. #endregion
  1898. #region 查出工资方案对应工种的员工,用于给每个员工结算工资
  1899. sqlString = @"select TP_HR_Staff.StaffID,TP_HR_Staff.StaffStatus
  1900. ,TP_HR_Staff.EntryDate,TP_HR_Staff.TurnoverDate,TP_HR_Staff.ExProbationEndDate, TP_MST_UserStaff.UserID
  1901. from TP_HR_Staff
  1902. inner join TP_MST_UserStaff on TP_HR_Staff.StaffID=TP_MST_UserStaff.StaffID
  1903. where TP_HR_Staff.Jobs in
  1904. (
  1905. select JobsID from TP_PAM_JobsPayPlan where PayPlanID=:PayPlanID
  1906. )
  1907. and TP_HR_Staff.accountid=:accountid and TP_HR_Staff.valueflag=1 order by TP_MST_UserStaff.UserID
  1908. ";//and userid=547
  1909. parmeters1 = new OracleParameter[]
  1910. {
  1911. new OracleParameter(":accountid",sUserInfo.AccountID),
  1912. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  1913. };
  1914. DataSet dsJobsPayPlan = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  1915. #endregion
  1916. #region 查出全部废弃产品表数据,用于计算工资
  1917. sqlString = @"select TMP_PAM_ResponProcedure.UserID,TP_PAM_GoodsWagesType.WagesTypeID,TP_MST_Goods.StartingDate,TMP_PAM_ScrapProduct.barcode,TMP_PAM_ScrapProduct.AuditStatus,
  1918. case
  1919. when add_months(TP_MST_Goods.StartingDate, :month)>TMP_PAM_ScrapProduct.Groutingdate
  1920. then 1 else 3 end as GoodsFlag
  1921. from TMP_PAM_ScrapProduct left join TMP_PAM_ResponProcedure
  1922. on TMP_PAM_ScrapProduct.ScrapProductID=TMP_PAM_ResponProcedure.ScrapProductID
  1923. left join TP_PAM_GoodsWagesType on TMP_PAM_ScrapProduct.GoodsID=TP_PAM_GoodsWagesType.GoodsID
  1924. left join TP_MST_Goods
  1925. on TP_PAM_GoodsWagesType.GoodsID=TP_MST_Goods.GoodsID";
  1926. parmeters1 = new OracleParameter[]
  1927. {
  1928. new OracleParameter(":month",newGoodsMonth),
  1929. };
  1930. DataSet dsTMPResponProcedure = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  1931. #endregion
  1932. #region 查出产品工价分类
  1933. sqlString = @"select WagesTypeID,GoodsID from TP_PAM_GoodsWagesType ";
  1934. DataSet dsGoodsWagesType = oracleTrConn.GetSqlResultToDs(sqlString);
  1935. #endregion
  1936. #region 查出产品工价
  1937. sqlString = @"select * from TP_PAT_Wages ";
  1938. DataSet dsWages = oracleTrConn.GetSqlResultToDs(sqlString);
  1939. #endregion
  1940. #region 查出质量工价
  1941. sqlString = @"select PieceTacticsID,WagesTypeID,QualityRate,Balance,QualityWages from TP_PAT_QualityWages order by QualityRate desc ";
  1942. DataSet dsQualityWages = oracleTrConn.GetSqlResultToDs(sqlString);
  1943. #endregion
  1944. #region 查出临时成品表,用于计算干补补贴,这些数据肯定配置了产品工价
  1945. sqlString = @"select TMP_PAM_FinishedProduct.BarCode,
  1946. TMP_PAM_FinishedProduct.SpecialRepairFlag,
  1947. TMP_PAM_FinishedProduct.GoodsLevelID,
  1948. TMP_PAM_FinishedProduct.GoodsLevelTypeID,
  1949. TMP_PAM_FinishedProduct.GoodsID,
  1950. TP_PAM_GoodsWagesType.GoodsID,
  1951. TP_PAM_GoodsWagesType.WagesTypeID
  1952. from TMP_PAM_FinishedProduct inner join TP_PAM_GoodsWagesType
  1953. on TMP_PAM_FinishedProduct.GoodsID=TP_PAM_GoodsWagesType.GoodsID ";
  1954. DataSet dsFinishedProduct = oracleTrConn.GetSqlResultToDs(sqlString);
  1955. #endregion
  1956. #region 读出对应解决方案品质考核策略,可以存在多个
  1957. sqlString = @"select TP_PAT_QualityASS.QualityASSTacticsID,
  1958. TP_PAT_QualityASS.PayPlanID,
  1959. TP_PAT_QualityASS.DefectFine,
  1960. TP_MST_DataDictionary.Dictionaryvalue
  1961. from TP_PAT_QualityASS
  1962. left join TP_MST_DataDictionary on TP_PAT_QualityASS.DefectFine=TP_MST_DataDictionary.DictionaryID
  1963. where PayPlanID=:PayPlanID";
  1964. parmeters1 = new OracleParameter[]
  1965. {
  1966. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  1967. };
  1968. DataSet dsQualityASS = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  1969. #endregion
  1970. #region 读出对应解决方案品质考核策略工序
  1971. //sqlString = "select * from TP_PAT_QualityProcedure";
  1972. //DataSet dsQualityProcedure = oracleTrConn.GetSqlResultToDs(sqlString);
  1973. #endregion
  1974. #region 查出生产缺陷数据表(暂时未用)
  1975. sqlString = @"select
  1976. TMP_PAM_Defect.ProductionDataID,
  1977. TMP_PAM_Defect.BarCode,
  1978. TMP_PAM_Defect.ProcedureID,
  1979. TMP_PAM_Defect.UserID,
  1980. TMP_PAM_Defect.DefectProcedureID,
  1981. TMP_PAM_Defect.DefectUserID,
  1982. TMP_PAM_Defect.DefectFine,
  1983. TP_PAM_GoodsWagesType.GoodsID,
  1984. TP_PAM_GoodsWagesType.WagesTypeID
  1985. from TMP_PAM_Defect inner join TP_PAM_GoodsWagesType
  1986. on TMP_PAM_Defect.GoodsID=TP_PAM_GoodsWagesType.GoodsID ";
  1987. DataSet dsDefect = oracleTrConn.GetSqlResultToDs(sqlString);
  1988. #endregion
  1989. #region 损坯补贴(用到的数据源)
  1990. string sql = @"select TMP_PAM_ScrapProduct.barcode from TMP_PAM_ScrapProduct left join TMP_PAM_ResponProcedure
  1991. on TMP_PAM_ScrapProduct.ScrapProductID=TMP_PAM_ResponProcedure.ScrapProductID ";
  1992. sql = sql + " where TMP_PAM_ResponProcedure.UserID is null ";
  1993. DataSet dsScrap_New = oracleTrConn.GetSqlResultToDs(sql);
  1994. #endregion
  1995. #region 缺陷数量用到的数据源
  1996. // 求出缺陷数
  1997. sqlString = @"select distinct TMP_PAM_ProductionData.barcode,TP_PAM_GoodsWagesType.WagesTypeID,TMP_PAM_Defect.goodsid,TMP_PAM_Defect.DefectFine,TMP_PAM_ProductionData.UserID,TMP_PAM_Defect.defectuserid from TMP_PAM_Defect
  1998. inner join TP_PAM_GoodsWagesType
  1999. on TMP_PAM_Defect.goodsID=TP_PAM_GoodsWagesType.goodsID
  2000. left join TMP_PAM_ProductionData on TMP_PAM_Defect.ProductionDataID=TMP_PAM_ProductionData.ProductionDataID
  2001. ";
  2002. DataSet ds_w = oracleTrConn.GetSqlResultToDs(sqlString);
  2003. #endregion
  2004. // 读取计件工资策略
  2005. int PieceTacticsID_Insert = 0;
  2006. int PieceTacticsID_Insert2 = 0;
  2007. int PieceTacticsID_Insert3 = 0;
  2008. sqlString = "select PieceTacticsID from TP_PAT_Piecework where PayPlanID=:PayPlanID";
  2009. parmeters1 = new OracleParameter[]
  2010. {
  2011. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  2012. };
  2013. DataSet dss = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  2014. if (dss != null && dss.Tables[0].Rows.Count > 0)
  2015. {
  2016. PieceTacticsID_Insert = Convert.ToInt32(dss.Tables[0].Rows[0]["PieceTacticsID"]);
  2017. PieceTacticsID_Insert2 = Convert.ToInt32(dss.Tables[0].Rows[0]["PieceTacticsID"]);
  2018. PieceTacticsID_Insert3 = Convert.ToInt32(dss.Tables[0].Rows[0]["PieceTacticsID"]);
  2019. }
  2020. // 读取计件工资策略
  2021. int PieceTacticsID_Insert4 = 0;
  2022. sqlString = "select QualityASSTacticsID from TP_PAT_QualityASS where PayPlanID=:PayPlanID";
  2023. parmeters1 = new OracleParameter[]
  2024. {
  2025. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  2026. };
  2027. DataSet dss3 = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  2028. if (dss3 != null && dss3.Tables[0].Rows.Count > 0)
  2029. {
  2030. PieceTacticsID_Insert4 = Convert.ToInt32(dss3.Tables[0].Rows[0]["QualityASSTacticsID"]);
  2031. }
  2032. // 变量集
  2033. DataSet dsExistPiecework = null;
  2034. // 用于插入工资单各类数值
  2035. decimal? totalcount_Piecegiework = 0; //计件工资
  2036. decimal? totalcount_Scrap = 0; //损坯补贴
  2037. decimal? totalcount_RepairSubsidy = 0; //干补补贴
  2038. decimal temp_Repair = 0;
  2039. DataRow[] drPieceProcedureCount = null;
  2040. DataRow[] dr2 = null;
  2041. DataRow[] rt = null;
  2042. DataRow[] drQualityBaseProcedure = null;
  2043. DataRow[] r7 = null;
  2044. DataSet dsTemp = null;
  2045. DataRow[] r17 = null;
  2046. DataRow[] r18 = null;
  2047. DataRow[] rr6 = null;
  2048. // 缺陷数量
  2049. DataRow[] drDefect = null;
  2050. DataSet ds3 = null;
  2051. DataSet dsUserStaffCount = null;
  2052. DataRow[] drGoodsCount = null;
  2053. DataTable dtWagesType = null;
  2054. DataTable dtGoodsFlag = null;
  2055. int PieceProcedureCount = 0; //计件数量
  2056. int UnqualifiedCount = 0; //次品数量
  2057. int QualifiedCount = 0; //副品数量
  2058. int QualityBaseProcedureCount = 0; //出窑数量
  2059. string FinishedProduct_BarCode = ""; //成品过滤条码集
  2060. DataSet ds = null;
  2061. DataRow[] drUnqualifiedCount = null;
  2062. DataRow[] drQualified = null;
  2063. decimal QualityBaseProcedureTotal = 0;//只是算出优等品率,还有和产品质量区间进行匹配
  2064. decimal QualityWages = 0; //质量工价 ,用于最后计算相乘
  2065. decimal Quality = 0; //质量
  2066. DataRow[] drQualityWages = null;
  2067. int scrapcount_1 = 0; //损坯数量
  2068. decimal scrap_StandardWages = 0; //损坯标准工价
  2069. decimal scrap_DamageSubsidyRate = 0; //损坯补贴系数
  2070. decimal scrap_DamageSubsidy = 0; //损坯补贴
  2071. decimal temp_Scrap = 0;// //最后损坯补贴钱
  2072. decimal? totalcount_AdminEXA2 = 0;// 行政工资
  2073. DataSet dsAdminEXA2 = null;
  2074. DataSet ds44 = null;
  2075. // 变量集结束
  2076. // 遍历工种数据集,统计每个员工的工资
  2077. //dsJobsPayPlan.Tables[0].Rows.Count
  2078. for (int j = 0; j < dsJobsPayPlan.Tables[0].Rows.Count; j++)
  2079. {
  2080. // #region 查出工资临时生产数据表数据,用于计算工资
  2081. // //查出在产品工介分类中的生产数据,用于计算每个人的工资
  2082. // sqlString = @"select
  2083. // TMP_PAM_ProductionData.ProductionDataID,
  2084. // TMP_PAM_ProductionData.BarCode,
  2085. // TMP_PAM_ProductionData.ProcedureID,
  2086. // TMP_PAM_ProductionData.GoodsID,
  2087. // TMP_PAM_ProductionData.UserID,
  2088. // TP_MST_Goods.StartingDate,
  2089. // TP_PAM_GoodsWagesType.WagesTypeID,
  2090. // TMP_PAM_ProductionData.GoodsLevelTypeID,
  2091. // case
  2092. // when add_months(TP_MST_Goods.StartingDate, :month)>TMP_PAM_ProductionData.Groutingdate
  2093. // then 3 else 1 end as GoodsFlag
  2094. // from
  2095. // TMP_PAM_ProductionData
  2096. // inner join TP_PAM_GoodsWagesType
  2097. // on TMP_PAM_ProductionData.GoodsID=TP_PAM_GoodsWagesType.GoodsID
  2098. // left join TP_MST_Goods
  2099. // on TP_PAM_GoodsWagesType.GoodsID=TP_MST_Goods.GoodsID where TMP_PAM_ProductionData.userid=" + dsJobsPayPlan.Tables[0].Rows[j]["UserID"];
  2100. // parmeters1 = new OracleParameter[]
  2101. // {
  2102. // new OracleParameter(":month",newGoodsMonth),
  2103. // };
  2104. // DataSet dsTMPProductionData = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  2105. // #endregion
  2106. //string ProcedureIDS_Delete = "0"; //默认给个0,怕没有些去进行筛选出现错误
  2107. //for (int p1 = 0; p1 < dsPieceProcedure_1.Tables[0].Rows.Count; p1++)
  2108. //{
  2109. // ProcedureIDS_Delete = ProcedureIDS_Delete + dsPieceProcedure_1.Tables[0].Rows[p1]["ProcedureID"].ToString() + ",";
  2110. //}
  2111. //ProcedureIDS_Delete = ProcedureIDS_Delete.Trim(',');
  2112. // modify wangx 20150911
  2113. //1.查出此员在是否存在计件工资
  2114. DataRow[] r_UserID = dtExistUserID.Select("userid=" + dsJobsPayPlan.Tables[0].Rows[j]["UserID"]);
  2115. if (r_UserID.Length > 0)
  2116. {
  2117. //已经存在
  2118. #region (1)插入计件工资
  2119. sqlString = "select 1 from TP_PAR_Piecework where YYYYMM=:YYYYMM and StaffID=:StaffID and PayPlanID=:PayPlanID";
  2120. parmeters1 = new OracleParameter[]
  2121. {
  2122. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  2123. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  2124. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  2125. };
  2126. dsExistPiecework = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  2127. if (dsExistPiecework != null && dsExistPiecework.Tables[0].Rows.Count == 0)
  2128. {
  2129. sqlString = @"insert into TP_PAR_Piecework
  2130. (
  2131. YYYYMM,
  2132. StaffID,
  2133. PayPlanID,
  2134. StaffFlag,
  2135. GoodsFlag,
  2136. WagesTypeID,
  2137. PieceworkNum,
  2138. PieceCoefficient,
  2139. DamageNum,
  2140. DamageCoefficient,
  2141. UnqualifiedNum,
  2142. UnqualifiedCoefficient,
  2143. QualifiedNum,
  2144. QualifiedCoefficient,
  2145. QualityBaseNum,
  2146. QualityRate,
  2147. QualityWages,
  2148. Amount,
  2149. PieceTacticsID
  2150. )
  2151. select
  2152. YYYYMM,
  2153. :StaffID_New,
  2154. PayPlanID,
  2155. StaffFlag,
  2156. GoodsFlag,
  2157. WagesTypeID,
  2158. PieceworkNum,
  2159. PieceCoefficient,
  2160. DamageNum,
  2161. DamageCoefficient,
  2162. UnqualifiedNum,
  2163. UnqualifiedCoefficient,
  2164. QualifiedNum,
  2165. QualifiedCoefficient,
  2166. QualityBaseNum,
  2167. QualityRate,
  2168. QualityWages,
  2169. Amount,
  2170. PieceTacticsID
  2171. from TP_PAR_Piecework
  2172. where YYYYMM=:YYYYMM and StaffID=:StaffID and PayPlanID=:PayPlanID
  2173. ";
  2174. parmeters1 = new OracleParameter[]
  2175. {
  2176. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  2177. new OracleParameter(":StaffID_New",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  2178. new OracleParameter(":StaffID",r_UserID[0]["StaffID"]),
  2179. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  2180. };
  2181. intResult = oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  2182. }
  2183. #endregion
  2184. #region (2)插入损坏补贴
  2185. sqlString = @"insert into TP_PAR_DamageSubsidy
  2186. (
  2187. YYYYMM,
  2188. StaffID,
  2189. PayPlanID,
  2190. WagesTypeID,
  2191. DamageNum,
  2192. StandardWages,
  2193. DamageSubsidyRate,
  2194. DamageSubsidy,
  2195. Amount,
  2196. PieceTacticsID
  2197. )
  2198. select
  2199. YYYYMM,
  2200. :StaffID_New,
  2201. PayPlanID,
  2202. WagesTypeID,
  2203. DamageNum,
  2204. StandardWages,
  2205. DamageSubsidyRate,
  2206. DamageSubsidy,
  2207. Amount,
  2208. PieceTacticsID
  2209. from TP_PAR_DamageSubsidy
  2210. where YYYYMM=:YYYYMM and StaffID=:StaffID and PayPlanID=:PayPlanID";
  2211. parmeters1 = new OracleParameter[]
  2212. {
  2213. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  2214. new OracleParameter(":StaffID_New",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  2215. new OracleParameter(":StaffID",r_UserID[0]["StaffID"]),
  2216. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  2217. };
  2218. intResult = oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  2219. #endregion
  2220. #region (3)插入干补补贴
  2221. sqlString = @"insert into TP_PAR_RepairSubsidy
  2222. (
  2223. YYYYMM,
  2224. StaffID,
  2225. PayPlanID,
  2226. WagesTypeID,
  2227. RSuperioNum,
  2228. RSuperiorCoefficient,
  2229. RQualifiedNum,
  2230. RQualifiedCoefficient,
  2231. StandardWages,
  2232. RepairSubsidyRate,
  2233. RepairSubsidy,
  2234. Amount,
  2235. PieceTacticsID
  2236. )
  2237. select
  2238. YYYYMM,
  2239. :StaffID_New,
  2240. PayPlanID,
  2241. WagesTypeID,
  2242. RSuperioNum,
  2243. RSuperiorCoefficient,
  2244. RQualifiedNum,
  2245. RQualifiedCoefficient,
  2246. StandardWages,
  2247. RepairSubsidyRate,
  2248. RepairSubsidy,
  2249. Amount,
  2250. PieceTacticsID
  2251. from TP_PAR_RepairSubsidy
  2252. where YYYYMM=:YYYYMM and StaffID=:StaffID and PayPlanID=:PayPlanID
  2253. ";
  2254. parmeters1 = new OracleParameter[]
  2255. {
  2256. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  2257. new OracleParameter(":StaffID_New",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  2258. new OracleParameter(":StaffID",r_UserID[0]["StaffID"]),
  2259. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  2260. };
  2261. intResult = oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  2262. #endregion
  2263. #region (4)插入品质考核
  2264. sqlString = @"insert into TP_PAR_QualityASS
  2265. (
  2266. YYYYMM,
  2267. StaffID,
  2268. PayPlanID,
  2269. WagesTypeID,
  2270. DefectFine,
  2271. DefectNum,
  2272. QualityBaseNum,
  2273. QualityRate,
  2274. Amount,
  2275. QualityASSTacticsID
  2276. ) select
  2277. YYYYMM,
  2278. :StaffID_New,
  2279. PayPlanID,
  2280. WagesTypeID,
  2281. DefectFine,
  2282. DefectNum,
  2283. QualityBaseNum,
  2284. QualityRate,
  2285. Amount,
  2286. QualityASSTacticsID
  2287. from TP_PAR_QualityASS
  2288. where YYYYMM=:YYYYMM and StaffID=:StaffID and PayPlanID=:PayPlanID
  2289. ";
  2290. parmeters1 = new OracleParameter[]
  2291. {
  2292. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  2293. new OracleParameter(":StaffID_New",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  2294. new OracleParameter(":StaffID",r_UserID[0]["StaffID"]),
  2295. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  2296. };
  2297. intResult = oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  2298. #endregion
  2299. totalcount_AdminEXA2 = 0;// 行政工资
  2300. #region (5)插入行政考核
  2301. sqlString = "select Amount from TP_PAD_AdminEXA where StaffID=:StaffID and AuditStatus=1 and AuditlDate >=:dateStartTime and AuditlDate<=:dateEndTime";//
  2302. parmeters1 = new OracleParameter[]
  2303. {
  2304. //new OracleParameter(":UserID",dsJobsPayPlan.Tables[0].Rows[i]["UserID"]),
  2305. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  2306. new OracleParameter(":dateStartTime",dateStartTime),
  2307. new OracleParameter(":dateEndTime",dateEndTime),
  2308. };
  2309. dsAdminEXA2 = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  2310. if (dsAdminEXA2 != null && dsAdminEXA2.Tables[0].Rows.Count > 0)
  2311. {
  2312. for (int y = 0; y < dsAdminEXA2.Tables[0].Rows.Count; y++)
  2313. {
  2314. totalcount_AdminEXA2 += Convert.ToDecimal(dsAdminEXA2.Tables[0].Rows[y]["Amount"]);
  2315. }
  2316. sqlString = "update TP_PAD_AdminEXA set SettlementFlag=1 where SettlementFlag=0 and StaffID=:StaffID and AuditStatus=1 and AuditlDate >=:dateStartTime and AuditlDate<=:dateEndTime";
  2317. parmeters1 = new OracleParameter[]
  2318. {
  2319. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  2320. new OracleParameter(":dateStartTime",dateStartTime),
  2321. new OracleParameter(":dateEndTime",dateEndTime),
  2322. };
  2323. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  2324. }
  2325. #endregion
  2326. // 防止一个员工在多个工号下面
  2327. sqlString = "select Piecework,DamageSubsidy,RepairSubsidy,QualityEXA,AdminEXA,ADAmount,TotalAmount from TP_PAR_Payroll where YYYYMM=:YYYYMM and StaffID=:StaffID ";
  2328. parmeters1 = new OracleParameter[]
  2329. {
  2330. new OracleParameter(":YYYYMM",OracleDbType.Varchar2,(Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),ParameterDirection.Input),
  2331. new OracleParameter(":StaffID",OracleDbType.Int32,dsJobsPayPlan.Tables[0].Rows[j]["StaffID"],ParameterDirection.Input),
  2332. };
  2333. ds44 = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  2334. if (ds44 != null && ds44.Tables[0].Rows.Count == 0)
  2335. {
  2336. sqlString = @"insert into TP_PAR_Payroll
  2337. (
  2338. YYYYMM,
  2339. StaffID,
  2340. Piecework,
  2341. DamageSubsidy,
  2342. RepairSubsidy,
  2343. QualityEXA,
  2344. AdminEXA,
  2345. ADAmount,
  2346. TotalAmount,
  2347. AuditStatus,
  2348. AccountID,
  2349. CreateUserID,
  2350. UpdateUserID
  2351. )
  2352. select
  2353. YYYYMM,
  2354. :StaffID_New,
  2355. Piecework,
  2356. DamageSubsidy,
  2357. RepairSubsidy,
  2358. QualityEXA,
  2359. :AdminEXA,
  2360. 0,
  2361. Piecework+DamageSubsidy+RepairSubsidy+QualityEXA+:AdminEXA,
  2362. 0,
  2363. AccountID,
  2364. CreateUserID,
  2365. UpdateUserID
  2366. from TP_PAR_Payroll
  2367. where YYYYMM=:YYYYMM and StaffID=:StaffID ";
  2368. parmeters1 = new OracleParameter[]
  2369. {
  2370. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  2371. new OracleParameter(":StaffID_New",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  2372. new OracleParameter(":StaffID",r_UserID[0]["StaffID"]),
  2373. new OracleParameter(":AdminEXA",totalcount_AdminEXA2),
  2374. };
  2375. intResult = oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  2376. }
  2377. else
  2378. {
  2379. sqlString = @"update TP_PAR_Payroll
  2380. set Piecework=Piecework+:Piecework,
  2381. DamageSubsidy=DamageSubsidy+:DamageSubsidy,
  2382. RepairSubsidy=RepairSubsidy+:RepairSubsidy,
  2383. QualityEXA=QualityEXA+:QualityEXA,
  2384. AdminEXA=AdminEXA+:AdminEXA,
  2385. ADAmount=AdminEXA+:ADAmount,
  2386. TotalAmount=TotalAmount+:TotalAmount
  2387. where YYYYMM=:YYYYMM and StaffID=:StaffID
  2388. ";
  2389. decimal? a = (Convert.ToDecimal(ds44.Tables[0].Rows[0]["Piecework"]) + Convert.ToDecimal(ds44.Tables[0].Rows[0]["DamageSubsidy"])
  2390. + Convert.ToDecimal(ds44.Tables[0].Rows[0]["RepairSubsidy"]) + Convert.ToDecimal(ds44.Tables[0].Rows[0]["QualityEXA"]) + Convert.ToDecimal(ds44.Tables[0].Rows[0]["AdminEXA"]));
  2391. parmeters1 = new OracleParameter[]
  2392. {
  2393. new OracleParameter(":YYYYMM",OracleDbType.Varchar2,(Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),ParameterDirection.Input),
  2394. new OracleParameter(":StaffID",OracleDbType.Int32,dsJobsPayPlan.Tables[0].Rows[j]["StaffID"],ParameterDirection.Input),
  2395. //new OracleParameter(":PayPlanID",OracleDbType.Int32,dsPayPlan.Tables[0].Rows[i]["PayPlanID"],ParameterDirection.Input),
  2396. new OracleParameter(":Piecework",OracleDbType.Decimal,Convert.ToDecimal(ds44.Tables[0].Rows[0]["Piecework"]),ParameterDirection.Input),
  2397. new OracleParameter(":DamageSubsidy",OracleDbType.Decimal,Convert.ToDecimal(ds44.Tables[0].Rows[0]["DamageSubsidy"]),ParameterDirection.Input),
  2398. new OracleParameter(":RepairSubsidy",OracleDbType.Decimal,Convert.ToDecimal(ds44.Tables[0].Rows[0]["RepairSubsidy"]),ParameterDirection.Input),
  2399. new OracleParameter(":QualityEXA",OracleDbType.Decimal,Convert.ToDecimal(ds44.Tables[0].Rows[0]["QualityEXA"]),ParameterDirection.Input),
  2400. new OracleParameter(":AdminEXA",OracleDbType.Decimal,Convert.ToDecimal(ds44.Tables[0].Rows[0]["AdminEXA"]),ParameterDirection.Input),
  2401. new OracleParameter(":ADAmount",OracleDbType.Decimal,0,ParameterDirection.Input),
  2402. new OracleParameter(":TotalAmount",OracleDbType.Decimal,a,ParameterDirection.Input),
  2403. };
  2404. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  2405. }
  2406. continue;//继续循环
  2407. }
  2408. else
  2409. {
  2410. DataRow dr_NEW = dtExistUserID.NewRow();
  2411. dr_NEW["staffid"] = dsJobsPayPlan.Tables[0].Rows[j]["StaffID"];
  2412. dr_NEW["userid"] = dsJobsPayPlan.Tables[0].Rows[j]["UserID"];
  2413. dtExistUserID.Rows.Add(dr_NEW);
  2414. }
  2415. // modify wangx 20150911 end
  2416. // 用于插入工资单各类数值
  2417. totalcount_Piecegiework = 0; //计件工资
  2418. totalcount_Scrap = 0; //损坯补贴
  2419. totalcount_RepairSubsidy = 0; //干补补贴
  2420. temp_Repair = 0;
  2421. #region 查出这个工号下有多少员工,计件工资进行平分
  2422. sqlString = "select 1 from tp_mst_userstaff where userid=" + dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString();
  2423. int userstaffcount = 1;
  2424. dsUserStaffCount = oracleTrConn.GetSqlResultToDs(sqlString);
  2425. if (dsUserStaffCount != null && dsUserStaffCount.Tables[0].Rows.Count > 0)
  2426. {
  2427. userstaffcount = dsUserStaffCount.Tables[0].Rows.Count;
  2428. }
  2429. #endregion
  2430. #region 计件工资整体累计
  2431. if (PieceType == "0") // 工序计件
  2432. {
  2433. // 查出这个工号,在此计件工序,有多少产品
  2434. drGoodsCount = dsTMPProductionData.Tables[0]
  2435. .Select(string.Format("UserID={0}", dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString()));
  2436. if (drGoodsCount.Length > 0) // 此工号下代表有产品
  2437. {
  2438. // 接下来在过滤产品分类有多少种,用来分别计算各分类的工资
  2439. // 以下表有多少行,去掉重复算出有多少个分类
  2440. dtWagesType = drGoodsCount.CopyToDataTable().DefaultView.ToTable(true, "WagesTypeID");
  2441. // 有多少产品标识
  2442. dtGoodsFlag = drGoodsCount.CopyToDataTable().DefaultView.ToTable(true, "GoodsFlag");
  2443. PieceProcedureCount = 0; //计件数量
  2444. UnqualifiedCount = 0; //次品数量
  2445. QualifiedCount = 0; //副品数量
  2446. QualityBaseProcedureCount = 0; //出窑数量
  2447. FinishedProduct_BarCode = ""; //成品过滤条码集
  2448. for (int wagestype = 0; wagestype < dtWagesType.Rows.Count; wagestype++)
  2449. {
  2450. for (int vv = 0; vv < dtGoodsFlag.Rows.Count; vv++)
  2451. {
  2452. decimal? temp_Piecegiework = 0;
  2453. #region 1.求出各分类计件工序数量
  2454. PieceProcedureCount = 0; //每个分类之前置空
  2455. decimal PieceProcedureTotal = 0;//系数*数量
  2456. //下面开始计算每个分类的计件工资
  2457. for (int p1 = 0; p1 < dsPieceProcedure_1.Tables[0].Rows.Count; p1++)
  2458. {
  2459. drPieceProcedureCount = dsTMPProductionData.Tables[0]
  2460. .Select(string.Format("UserID={0} and ProcedureID={1} and WagesTypeID={2} and GoodsFlag={3}", dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString(), dsPieceProcedure_1.Tables[0].Rows[p1]["ProcedureID"], dtWagesType.Rows[wagestype]["WagesTypeID"], dtGoodsFlag.Rows[vv]["GoodsFlag"]));
  2461. foreach (DataRow r in drPieceProcedureCount)
  2462. {
  2463. if (!FinishedProduct_BarCode.Contains(r["barcode"].ToString()))
  2464. FinishedProduct_BarCode = FinishedProduct_BarCode + r["barcode"].ToString() + ",";
  2465. }
  2466. PieceProcedureCount += drPieceProcedureCount.Length; //工序数量
  2467. }
  2468. PieceProcedureTotal = PieceProcedureCount * PieceCoefficient; //工序数量*系数
  2469. #endregion 1.求出计件工序数量
  2470. #region 2.求出各工价分类损坯数量
  2471. int ScrapCount = 0; //损坯数量
  2472. decimal? Scrap = 0; //每个类别损坯的值
  2473. if (DamageFlag == "1") //计算损坯数量
  2474. {
  2475. // 查出此人在计件工序的条码,完事关联报损表存在多少报损条码
  2476. string ProcedureIDS = "0"; //默认给个0,怕没有些去进行筛选出现错误
  2477. for (int p1 = 0; p1 < dsPieceProcedure_1.Tables[0].Rows.Count; p1++)
  2478. {
  2479. if(p1==0)
  2480. {
  2481. ProcedureIDS = "";
  2482. }
  2483. ProcedureIDS = ProcedureIDS + dsPieceProcedure_1.Tables[0].Rows[p1]["ProcedureID"].ToString() + ",";
  2484. }
  2485. ProcedureIDS = ProcedureIDS.Trim(',');
  2486. //if (dsJobsPayPlan.Tables[0].Rows[j]["Staffid"].ToString() == "1955")
  2487. //{
  2488. // int a = 0;
  2489. //}
  2490. // 筛选出生产数据这几个工序所用的条码
  2491. DataRow[] dr_BarCode = dsTMPProductionData.Tables[0].Select(string.Format("UserID={0} and ProcedureID in ({1}) and WagesTypeID={2} and GoodsFlag={3}", dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString(), ProcedureIDS, dtWagesType.Rows[wagestype]["WagesTypeID"], dtGoodsFlag.Rows[vv]["GoodsFlag"]));
  2492. if (dr_BarCode.Length > 0)
  2493. {
  2494. string temp_barcode = "";
  2495. foreach (DataRow r3 in dr_BarCode) //有可能出现重复barcode
  2496. {
  2497. dr2 = dsTMPResponProcedure.Tables[0].Select("barcode='" + r3["barcode"] + "' and AuditStatus=1 and UserID=" + dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString());
  2498. if (dr2.Length > 0)
  2499. {
  2500. if (!temp_barcode.Contains(r3["barcode"].ToString()))
  2501. {
  2502. // 有损坯数据
  2503. ScrapCount = ScrapCount + 1;
  2504. }
  2505. temp_barcode += r3["barcode"].ToString() + ",";
  2506. }
  2507. }
  2508. }
  2509. // end
  2510. Scrap = ScrapCount * DamageCoefficient; //DamageCoefficient为损坯系数
  2511. }
  2512. #endregion 2.求出损坯数量 end
  2513. #region 3.求出各工价分类次品数
  2514. // 筛出产品分级为次品的生产数据,完事一个一个去查对应责任工号的,进行累加
  2515. drUnqualifiedCount = dsTMPProductionData.Tables[0]
  2516. .Select(string.Format("WagesTypeID={0} and GoodsLevelTypeID=7 and GoodsFlag={1} ", dtWagesType.Rows[wagestype]["WagesTypeID"], dtGoodsFlag.Rows[vv]["GoodsFlag"]));
  2517. UnqualifiedCount = 0; //次品数量
  2518. decimal? UnqualifiedTotal = 0;//系数*数量
  2519. if (drUnqualifiedCount.Length > 0)
  2520. {
  2521. // 表示有次品,但是得对应责任工号,进行累加
  2522. foreach (DataRow row in drUnqualifiedCount)
  2523. {
  2524. rt = dsDefect.Tables[0].Select("DefectUserID=" + dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString() + " and ProductionDataID=" + row["ProductionDataID"]);
  2525. if (rt.Length > 0)
  2526. {
  2527. // 多个缺陷也算一个数,所以直接+1
  2528. UnqualifiedCount = UnqualifiedCount + 1;
  2529. }
  2530. }
  2531. UnqualifiedTotal = UnqualifiedCount * UnqualifiedCoefficient;
  2532. }
  2533. #endregion
  2534. #region 4.求出各工价分类副品数
  2535. // 筛出产品分级为副品的生产数据,完事一个一个去查对应责任工号的,进行累加
  2536. drQualified = dsTMPProductionData.Tables[0]
  2537. .Select(string.Format("WagesTypeID={0} and GoodsLevelTypeID=5 and GoodsFlag={1}", dtWagesType.Rows[wagestype]["WagesTypeID"], dtGoodsFlag.Rows[vv]["GoodsFlag"]));
  2538. QualifiedCount = 0; //副品数量
  2539. decimal? QualifiedTotal = 0;//系数*数量
  2540. if (drQualified.Length > 0)
  2541. {
  2542. // 表示有副品,但是得对应责任工号,进行累加
  2543. foreach (DataRow row in drQualified)
  2544. {
  2545. rt = dsDefect.Tables[0].Select("DefectUserID=" + dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString() + " and ProductionDataID=" + row["ProductionDataID"]);
  2546. if (rt.Length > 0)
  2547. {
  2548. // 多个缺陷也算一个数,所以直接+1
  2549. QualifiedCount = QualifiedCount + 1;
  2550. }
  2551. }
  2552. QualifiedTotal = QualifiedCount * QualifiedCoefficient;
  2553. }
  2554. #endregion 求出各工价分类副品数
  2555. #region 5.求出质量工价
  2556. string barcodes_Procedure = "";
  2557. QualityBaseProcedureCount = 0;
  2558. for (int p1 = 0; p1 < dsPieceProcedure_2.Tables[0].Rows.Count; p1++)
  2559. {
  2560. drQualityBaseProcedure = dsTMPProductionData.Tables[0]
  2561. .Select(string.Format("ProcedureID={0} and WagesTypeID={1}", dsPieceProcedure_2.Tables[0].Rows[p1]["ProcedureID"], dtWagesType.Rows[wagestype]["WagesTypeID"]));
  2562. if (drQualityBaseProcedure.Length > 0)
  2563. {
  2564. foreach (DataRow r4 in drQualityBaseProcedure)
  2565. {
  2566. if (!barcodes_Procedure.Contains(r4["barcode"].ToString()))
  2567. {
  2568. QualityBaseProcedureCount += 1; // 质量工序数量
  2569. }
  2570. barcodes_Procedure = barcodes_Procedure + r4["barcode"].ToString() + ",";
  2571. }
  2572. }
  2573. }
  2574. //if (dsJobsPayPlan.Tables[0].Rows[j]["Staffid"].ToString() == "1955")
  2575. //{
  2576. // int a = 0;
  2577. //}
  2578. QualityBaseProcedureTotal = 0;//只是算出优等品率,还有和产品质量区间进行匹配
  2579. QualityWages = 0; //质量工价 ,用于最后计算相乘
  2580. Quality = 0; //质量
  2581. if (QualityBaseProcedureCount != 0)
  2582. {
  2583. QualityBaseProcedureTotal = Convert.ToDecimal((QualityBaseProcedureCount - UnqualifiedCount)) / Convert.ToDecimal(QualityBaseProcedureCount);
  2584. }
  2585. //查看此员工是否为正式员工还是试用员工,如果试用取工价类别的标准工价
  2586. // 1取出此工类下的产品工价区间
  2587. DataRow[] drWages = dsWages.Tables[0].Select("WagesTypeID=" + dtWagesType.Rows[wagestype]["WagesTypeID"]);
  2588. decimal StandardWages = 0;
  2589. if (drWages.Length > 0)
  2590. {
  2591. StandardWages = Convert.ToDecimal(drWages[0]["StandardWages"]); //标准工价
  2592. }
  2593. if (dsJobsPayPlan.Tables[0].Rows[j]["ExProbationEndDate"].ToString() == "") //表示正式员工
  2594. {
  2595. // 2取出此工类下的质量区间
  2596. drQualityWages = dsQualityWages.Tables[0].Select("WagesTypeID=" + dtWagesType.Rows[wagestype]["WagesTypeID"] + " and QualityRate<=" + QualityBaseProcedureTotal, "QualityRate desc");
  2597. if (drQualityWages.Length > 0)
  2598. {
  2599. //表示质量区间设置没有比优品率大的
  2600. QualityWages = Convert.ToDecimal(drQualityWages[0]["QualityWages"]);
  2601. Quality = Convert.ToDecimal(drQualityWages[0]["QualityRate"]);
  2602. }
  2603. else
  2604. {
  2605. QualityWages = 0;// Convert.ToDecimal(drQualityWages[0]["QualityWages"]);
  2606. }
  2607. }
  2608. else
  2609. {
  2610. if (Convert.ToDateTime(dsJobsPayPlan.Tables[0].Rows[j]["ExProbationEndDate"]) < DateTime.Now)
  2611. {
  2612. // 试用结束结束
  2613. // 2取出此工类下的质量区间
  2614. drQualityWages = dsQualityWages.Tables[0].Select("WagesTypeID=" + dtWagesType.Rows[wagestype]["WagesTypeID"] + " and QualityRate<=" + QualityBaseProcedureTotal);
  2615. if (drQualityWages.Length > 0)
  2616. {
  2617. //表示质量区间设置没有比优品率大的
  2618. QualityWages = Convert.ToDecimal(drQualityWages[0]["QualityWages"]);
  2619. Quality = Convert.ToDecimal(drQualityWages[0]["QualityRate"]);
  2620. }
  2621. else
  2622. {
  2623. QualityWages = 0;// Convert.ToDecimal(drQualityWages[0]["QualityWages"]);
  2624. }
  2625. }
  2626. }
  2627. #endregion
  2628. //#region 查出这个工号下有多少员工,计件工资进行平分
  2629. //sqlString = "select 1 from tp_mst_userstaff where userid=" + dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString();
  2630. //userstaffcount = 1;
  2631. //dsUserStaffCount = oracleTrConn.GetSqlResultToDs(sqlString);
  2632. //if (dsUserStaffCount != null && dsUserStaffCount.Tables[0].Rows.Count > 0)
  2633. //{
  2634. // userstaffcount = dsUserStaffCount.Tables[0].Rows.Count;
  2635. //}
  2636. //#endregion
  2637. totalcount_Piecegiework += ((PieceProcedureTotal - Scrap - UnqualifiedTotal - QualifiedTotal) * QualityWages) < 0 ? 0 : ((PieceProcedureTotal - Scrap - UnqualifiedTotal - QualifiedTotal) * QualityWages) / userstaffcount;
  2638. temp_Piecegiework += ((PieceProcedureTotal - Scrap - UnqualifiedTotal - QualifiedTotal) * QualityWages) < 0 ? 0 : ((PieceProcedureTotal - Scrap - UnqualifiedTotal - QualifiedTotal) * QualityWages);// / userstaffcount
  2639. // }
  2640. #region 插入计件工资
  2641. sqlString = "select 1 from TP_PAR_Piecework where YYYYMM=:YYYYMM and StaffID=:StaffID and PayPlanID=:PayPlanID and WagesTypeID=:WagesTypeID";
  2642. parmeters1 = new OracleParameter[]
  2643. {
  2644. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  2645. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  2646. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  2647. new OracleParameter(":WagesTypeID",dtWagesType.Rows[wagestype]["WagesTypeID"]),
  2648. };
  2649. dsExistPiecework = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  2650. if (dsExistPiecework != null && dsExistPiecework.Tables[0].Rows.Count == 0)
  2651. {
  2652. sqlString = @"insert into TP_PAR_Piecework
  2653. (
  2654. YYYYMM,
  2655. StaffID,
  2656. PayPlanID,
  2657. StaffFlag,
  2658. GoodsFlag,
  2659. WagesTypeID,
  2660. PieceworkNum,
  2661. PieceCoefficient,
  2662. DamageNum,
  2663. DamageCoefficient,
  2664. UnqualifiedNum,
  2665. UnqualifiedCoefficient,
  2666. QualifiedNum,
  2667. QualifiedCoefficient,
  2668. QualityBaseNum,
  2669. QualityRate,
  2670. QualityWages,
  2671. Amount,
  2672. PieceTacticsID
  2673. ) values
  2674. (
  2675. :YYYYMM,
  2676. :StaffID,
  2677. :PayPlanID,
  2678. :StaffFlag,
  2679. :GoodsFlag,
  2680. :WagesTypeID,
  2681. :PieceworkNum,
  2682. :PieceCoefficient,
  2683. :DamageNum,
  2684. :DamageCoefficient,
  2685. :UnqualifiedNum,
  2686. :UnqualifiedCoefficient,
  2687. :QualifiedNum,
  2688. :QualifiedCoefficient,
  2689. :QualityBaseNum,
  2690. :QualityRate,
  2691. :QualityWages,
  2692. :Amount,
  2693. :PieceTacticsID
  2694. )";
  2695. }
  2696. else
  2697. {
  2698. sqlString = @"update TP_PAR_Piecework
  2699. set
  2700. YYYYMM=:YYYYMM,
  2701. StaffID=:StaffID,
  2702. PayPlanID=:PayPlanID,
  2703. StaffFlag=:StaffFlag,
  2704. PieceTacticsID=:PieceTacticsID,
  2705. GoodsFlag=:GoodsFlag,
  2706. WagesTypeID=:WagesTypeID,
  2707. PieceworkNum=PieceworkNum+:PieceworkNum,
  2708. PieceCoefficient=PieceCoefficient+:PieceCoefficient,
  2709. DamageNum=DamageNum+:DamageNum,
  2710. DamageCoefficient=DamageCoefficient+:DamageCoefficient,
  2711. UnqualifiedNum=UnqualifiedNum+:UnqualifiedNum,
  2712. UnqualifiedCoefficient=UnqualifiedCoefficient+:UnqualifiedCoefficient,
  2713. QualifiedNum=QualifiedNum+:QualifiedNum,
  2714. QualifiedCoefficient=QualifiedCoefficient+:QualifiedCoefficient,
  2715. QualityBaseNum=QualityBaseNum+:QualityBaseNum,
  2716. QualityRate=QualityRate+:QualityRate,
  2717. QualityWages=QualityWages+:QualityWages,
  2718. Amount=Amount+:Amount
  2719. where YYYYMM=:YYYYMM and StaffID=:StaffID and PayPlanID=:PayPlanID and WagesTypeID=:WagesTypeID
  2720. ";
  2721. }
  2722. parmeters1 = new OracleParameter[]
  2723. {
  2724. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  2725. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  2726. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  2727. new OracleParameter(":StaffFlag",dsJobsPayPlan.Tables[0].Rows[j]["StaffStatus"]),
  2728. //new OracleParameter(":BeginDate",dateStartTime),
  2729. //new OracleParameter(":EndDate",dateEndTime),
  2730. new OracleParameter(":GoodsFlag", dtGoodsFlag.Rows[vv]["GoodsFlag"]),
  2731. new OracleParameter(":WagesTypeID",dtWagesType.Rows[wagestype]["WagesTypeID"]),
  2732. //new OracleParameter(":GoodsID",null),
  2733. new OracleParameter(":PieceworkNum",PieceProcedureCount),
  2734. new OracleParameter(":PieceCoefficient",PieceCoefficient),
  2735. new OracleParameter(":DamageNum",ScrapCount),
  2736. new OracleParameter(":DamageCoefficient",DamageCoefficient),
  2737. new OracleParameter(":UnqualifiedNum",UnqualifiedCount),
  2738. new OracleParameter(":UnqualifiedCoefficient",UnqualifiedCoefficient),
  2739. new OracleParameter(":QualifiedNum",QualifiedCount),
  2740. new OracleParameter(":QualifiedCoefficient",QualifiedCoefficient),
  2741. new OracleParameter(":QualityBaseNum",QualityBaseProcedureCount),
  2742. new OracleParameter(":QualifiedCoefficient",QualifiedCoefficient),
  2743. new OracleParameter(":QualityRate",QualityBaseProcedureTotal),
  2744. new OracleParameter(":QualityWages",QualityWages),
  2745. new OracleParameter(":Amount",temp_Piecegiework),
  2746. new OracleParameter(":PieceTacticsID",PieceTacticsID_Insert),
  2747. };
  2748. intResult = oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  2749. #endregion
  2750. }
  2751. FinishedProduct_BarCode = FinishedProduct_BarCode.Trim(',');
  2752. #region 损坯补贴
  2753. scrapcount_1 = 0; //损坯数量
  2754. scrap_StandardWages = 0; //损坯标准工价
  2755. scrap_DamageSubsidyRate = 0; //损坯补贴系数
  2756. scrap_DamageSubsidy = 0; //损坯补贴
  2757. temp_Scrap = 0;// //最后损坯补贴钱
  2758. //1.查出此员工工号下所生产数据,即做过哪此产品条码
  2759. DataRow[] drScrapProduction = dsTMPProductionData.Tables[0].Select("UserID=" + dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString() + " and WagesTypeID=" + dtWagesType.Rows[wagestype]["WagesTypeID"]);
  2760. if (drScrapProduction.Length > 0)
  2761. {
  2762. string inPro = "";
  2763. if (dsPieceProcedure_1 != null && dsPieceProcedure_1.Tables[0].Rows.Count > 0)
  2764. {
  2765. for (int zz = 0; zz < dsPieceProcedure_1.Tables[0].Rows.Count; zz++)
  2766. {
  2767. inPro = inPro + dsPieceProcedure_1.Tables[0].Rows[zz]["ProcedureID"].ToString() + ",";
  2768. }
  2769. inPro = inPro.Trim(',');
  2770. }
  2771. if (inPro == "")
  2772. inPro = "0";
  2773. // 1. 查出此人计工序的条码
  2774. DataRow[] r5 = dsTMPProductionData.Tables[0].Select("UserID=" + dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString() + " and ProcedureID in (" + inPro + ")");
  2775. string a1 = "";
  2776. int scrapcount = 0;
  2777. string sqlInsertDamageSubsidy = "insert into TP_PAD_DamageSubsidy(Barcode,userID) values(:Barcode,:UserID)";
  2778. string sqladd = "select 1 from TP_PAD_DamageSubsidy where barcode=:barcode and userid=:userid";
  2779. if (r5.Length > 0)
  2780. {
  2781. // 有条码
  2782. foreach (DataRow rr in r5)
  2783. {
  2784. r7 = dsScrap_New.Tables[0].Select("barcode='" + rr["barcode"] + "'");
  2785. if (r7.Length > 0 && !a1.Contains(rr["barcode"].ToString()))
  2786. {
  2787. scrapcount = scrapcount + 1;
  2788. a1 = a1 + rr["barcode"].ToString();
  2789. parmeters1 = new OracleParameter[]
  2790. {
  2791. new OracleParameter(":Barcode",rr["Barcode"]),
  2792. new OracleParameter(":UserID",dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString()),
  2793. };
  2794. ds3 = oracleTrConn.GetSqlResultToDs(sqladd, parmeters1);
  2795. if (ds3 != null && ds3.Tables[0].Rows.Count == 0)
  2796. oracleTrConn.ExecuteNonQuery(sqlInsertDamageSubsidy, parmeters1);
  2797. }
  2798. }
  2799. }
  2800. //算出此工号,此工价分类存在条码,拼出条码,进而去报损查出非自身损坯的数量,进而计算
  2801. // sql = @"select TMP_PAM_ScrapProduct.barcode from TMP_PAM_ScrapProduct left join TMP_PAM_ResponProcedure
  2802. // on TMP_PAM_ScrapProduct.ScrapProductID=TMP_PAM_ResponProcedure.ScrapProductID ";
  2803. // sql = sql + " where TMP_PAM_ScrapProduct.barcode in (select barcode from TMP_PAM_ProductionData where UserID=:UserID and ProcedureID in (select TP_PAT_PieceProcedure.ProcedureID from TP_PAT_Piecework left join TP_PAT_PieceProcedure on TP_PAT_Piecework.PieceTacticsID=TP_PAT_PieceProcedure.PieceTacticsID and TP_PAT_PieceProcedure.ProcedureFlag=1 where TP_PAT_Piecework.PayPlanID=:PayPlanID)) ";
  2804. // sql = sql + " and TMP_PAM_ResponProcedure.UserID is null";
  2805. // parmeters1 = new OracleParameter[]
  2806. // {
  2807. // //new OracleParameter(":barcodes",barcodes),
  2808. // new OracleParameter(":UserID",dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString()),
  2809. // new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  2810. // };
  2811. // DataSet dsTemp = oracleTrConn.GetSqlResultToDs(sql, parmeters1);
  2812. //if (dsTemp.Tables[0].Rows.Count > 0)
  2813. if (scrapcount > 0)
  2814. {
  2815. // 大于零遍历此表,插入损坯补贴记录表中,过滤给报损补贴后就不能给干补补贴
  2816. //string sqlInsertDamageSubsidy = "insert into TP_PAD_DamageSubsidy(Barcode,userID) values(:Barcode,:UserID)";
  2817. //for (int insert = 0; insert < dsTemp.Tables[0].Rows.Count; insert++)
  2818. //{
  2819. // string sqladd = "select 1 from TP_PAD_DamageSubsidy where barcode=:barcode and userid=:userid";
  2820. // parmeters1 = new OracleParameter[]
  2821. // {
  2822. // new OracleParameter(":Barcode",dsTemp.Tables[0].Rows[insert]["Barcode"]),
  2823. // new OracleParameter(":UserID",dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString()),
  2824. // };
  2825. // DataSet ds3 = oracleTrConn.GetSqlResultToDs(sqladd, parmeters1);
  2826. // if (ds3 != null && ds3.Tables[0].Rows.Count == 0)
  2827. // oracleTrConn.ExecuteNonQuery(sqlInsertDamageSubsidy, parmeters1);
  2828. //}
  2829. scrapcount_1 = scrapcount;// dsTemp.Tables[0].Rows.Count; //非自身损坯数量
  2830. // 求出损坯对应系数
  2831. DataRow[] drScrapWages = dsWages.Tables[0].Select("WagesTypeID=" + dtWagesType.Rows[wagestype]["WagesTypeID"]);
  2832. //decimal? scrapDamageSubsidy = 0; //损坯补贴
  2833. if (drScrapWages.Length > 0)
  2834. {
  2835. //scrapDamageSubsidy += Convert.ToDecimal(drScrapWages[0]["DamageSubsidy"]);
  2836. scrap_StandardWages = Convert.ToDecimal(drScrapWages[0]["StandardWages"]); //标准工价
  2837. scrap_DamageSubsidyRate = Convert.ToDecimal(drScrapWages[0]["DamageSubsidyRate"]);//损坯补贴系数
  2838. // scrap_DamageSubsidy = Convert.ToDecimal(drScrapWages[0]["DamageSubsidy"]); //损坯补贴
  2839. scrap_DamageSubsidy = Convert.ToDecimal(scrap_StandardWages) * scrap_DamageSubsidyRate; //损坯补贴
  2840. }
  2841. //totalcount_Scrap += scrapDamageSubsidy;
  2842. temp_Scrap = Convert.ToDecimal(scrapcount_1 * scrap_StandardWages * scrap_DamageSubsidyRate);
  2843. totalcount_Scrap += temp_Scrap / userstaffcount;
  2844. }
  2845. }
  2846. #endregion
  2847. #region 插入损坯补贴
  2848. sqlString = "select 1 from TP_PAR_DamageSubsidy where YYYYMM=:YYYYMM and StaffID=:StaffID and PayPlanID=:PayPlanID and WagesTypeID=:WagesTypeID";
  2849. parmeters1 = new OracleParameter[]
  2850. {
  2851. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  2852. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  2853. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  2854. new OracleParameter(":WagesTypeID",dtWagesType.Rows[wagestype]["WagesTypeID"]),
  2855. };
  2856. DataSet dsExistDamageSubsidy = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  2857. if (dsExistDamageSubsidy != null && dsExistDamageSubsidy.Tables[0].Rows.Count == 0)
  2858. {
  2859. sqlString = @"insert into TP_PAR_DamageSubsidy
  2860. (
  2861. YYYYMM,
  2862. StaffID,
  2863. PayPlanID,
  2864. WagesTypeID,
  2865. DamageNum,
  2866. StandardWages,
  2867. DamageSubsidyRate,
  2868. DamageSubsidy,
  2869. Amount,
  2870. PieceTacticsID
  2871. ) values
  2872. (
  2873. :YYYYMM,
  2874. :StaffID,
  2875. :PayPlanID,
  2876. :WagesTypeID,
  2877. :DamageNum,
  2878. :StandardWages,
  2879. :DamageSubsidyRate,
  2880. :DamageSubsidy,
  2881. :Amount,
  2882. :PieceTacticsID
  2883. )";
  2884. }
  2885. else
  2886. {
  2887. sqlString = @"update TP_PAR_DamageSubsidy
  2888. set YYYYMM=:YYYYMM,
  2889. StaffID=StaffID,
  2890. PayPlanID=:PayPlanID,
  2891. WagesTypeID=:WagesTypeID,
  2892. DamageNum=DamageNum+:DamageNum,
  2893. StandardWages=StandardWages+:StandardWages,
  2894. DamageSubsidyRate=DamageSubsidyRate+:DamageSubsidyRate,
  2895. DamageSubsidy=DamageSubsidy+:DamageSubsidy,
  2896. Amount=Amount+:Amount,
  2897. PieceTacticsID=:PieceTacticsID
  2898. where YYYYMM=:YYYYMM and StaffID=:StaffID and PayPlanID=:PayPlanID and WagesTypeID=:WagesTypeID
  2899. ";
  2900. }
  2901. parmeters1 = new OracleParameter[]
  2902. {
  2903. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  2904. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  2905. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  2906. new OracleParameter(":WagesTypeID",dtWagesType.Rows[wagestype]["WagesTypeID"]),
  2907. new OracleParameter(":DamageNum",scrapcount_1),
  2908. new OracleParameter(":StandardWages",scrap_StandardWages),
  2909. new OracleParameter(":DamageSubsidyRate",scrap_DamageSubsidyRate),
  2910. new OracleParameter(":DamageSubsidy",scrap_DamageSubsidy),
  2911. new OracleParameter(":Amount",temp_Scrap),
  2912. new OracleParameter(":PieceTacticsID",PieceTacticsID_Insert2),
  2913. };
  2914. intResult = oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  2915. #endregion
  2916. #region 干补补贴,从成品表时读取数据来计算干补数量
  2917. // 1 查出这个工号的,这个分类的,下一面在去过滤正品,还是副品
  2918. int RepairSubsidy_RSuperioNum = 0;//干补正品数
  2919. // 干补正品数
  2920. if (!string.IsNullOrEmpty(FinishedProduct_BarCode))
  2921. {
  2922. DataRow[] drRepairSubsidy_RSuperioNum = dsFinishedProduct.Tables[0].Select("SpecialRepairFlag=1 and GoodsLevelTypeID=4 and WagesTypeID=" + dtWagesType.Rows[wagestype]["WagesTypeID"] + " and barcode in(" + FinishedProduct_BarCode + ")");
  2923. if (drRepairSubsidy_RSuperioNum.Length > 0)
  2924. {
  2925. RepairSubsidy_RSuperioNum = drRepairSubsidy_RSuperioNum.Length;
  2926. // 尽管有干补,但是有可能在损坯补贴给了,此处得查询一下干补补贴表,如果存在就不给此补贴
  2927. foreach (DataRow mm in drRepairSubsidy_RSuperioNum)
  2928. {
  2929. sqlString = "select 1 from TP_PAD_DamageSubsidy where Barcode=:Barcode and UserID=:UserID";
  2930. parmeters1 = new OracleParameter[]
  2931. {
  2932. new OracleParameter(":Barcode",mm["barcode"].ToString()),
  2933. new OracleParameter(":UserID",dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString()),
  2934. };
  2935. dsTemp = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  2936. if (dsTemp.Tables[0].Rows.Count > 0)
  2937. {
  2938. RepairSubsidy_RSuperioNum = RepairSubsidy_RSuperioNum - 1;
  2939. }
  2940. }
  2941. }
  2942. }
  2943. int RepairSubsidy_RQualifiedNum = 0;//干补副品数
  2944. // 干补正品数
  2945. if (!string.IsNullOrEmpty(FinishedProduct_BarCode))
  2946. {
  2947. DataRow[] drRepairSubsidy_RQualifiedNum = dsFinishedProduct.Tables[0].Select("SpecialRepairFlag=1 and GoodsLevelTypeID=5 and WagesTypeID=" + dtWagesType.Rows[wagestype]["WagesTypeID"] + " and barcode in(" + FinishedProduct_BarCode + ")");
  2948. if (drRepairSubsidy_RQualifiedNum.Length > 0)
  2949. {
  2950. RepairSubsidy_RQualifiedNum = drRepairSubsidy_RQualifiedNum.Length;
  2951. // 尽管有干补,但是有可能在损坯补贴给了,此处得查询一下干补补贴表,如果存在就不给此补贴
  2952. foreach (DataRow mm in drRepairSubsidy_RQualifiedNum)
  2953. {
  2954. sqlString = "select 1 from TP_PAD_DamageSubsidy where Barcode=:Barcode and UserID=:UserID";
  2955. parmeters1 = new OracleParameter[]
  2956. {
  2957. new OracleParameter(":Barcode",mm["barcode"].ToString()),
  2958. new OracleParameter(":UserID",dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString()),
  2959. };
  2960. dsTemp = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  2961. if (dsTemp.Tables[0].Rows.Count > 0)
  2962. {
  2963. RepairSubsidy_RQualifiedNum = RepairSubsidy_RQualifiedNum - 1;
  2964. }
  2965. }
  2966. }
  2967. }
  2968. // 查出此分类干补正负品补贴
  2969. // 求出损坯对应系数
  2970. DataRow[] drRepairSubsidy = dsWages.Tables[0].Select("WagesTypeID=" + dtWagesType.Rows[wagestype]["WagesTypeID"]);
  2971. decimal RSuperiorCoefficient = 0;//干补正品系数
  2972. decimal RQualifiedCoefficient = 0;//干补副品系数
  2973. decimal RepairSubsidyRate = 0;//干补补贴系数
  2974. decimal RepairStandardWages = 0;//标准工价
  2975. decimal RepairTotalCount = 0; //
  2976. decimal RepairSubsidy = 0;
  2977. temp_Repair = 0;
  2978. if (drRepairSubsidy.Length > 0)
  2979. {
  2980. RSuperiorCoefficient = Convert.ToDecimal(drRepairSubsidy[0]["RSuperiorCoefficient"]);
  2981. RQualifiedCoefficient = Convert.ToDecimal(drRepairSubsidy[0]["RQualifiedCoefficient"]);
  2982. RepairSubsidyRate = Convert.ToDecimal(drRepairSubsidy[0]["RepairSubsidyRate"]);
  2983. RepairStandardWages = Convert.ToDecimal(drRepairSubsidy[0]["StandardWages"]);
  2984. RepairSubsidy = Convert.ToDecimal(drRepairSubsidy[0]["RepairSubsidy"]);
  2985. RepairTotalCount = (RepairSubsidy_RSuperioNum * RSuperiorCoefficient + RepairSubsidy_RQualifiedNum * RQualifiedCoefficient) * RepairStandardWages * RepairSubsidyRate;
  2986. totalcount_RepairSubsidy += RepairTotalCount / userstaffcount;
  2987. temp_Repair = RepairTotalCount;
  2988. }
  2989. #endregion
  2990. #region 插入干补补贴
  2991. sqlString = "select 1 from TP_PAR_RepairSubsidy where YYYYMM=:YYYYMM and StaffID=:StaffID and PayPlanID=:PayPlanID and WagesTypeID=:WagesTypeID";
  2992. parmeters1 = new OracleParameter[]
  2993. {
  2994. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  2995. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  2996. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  2997. new OracleParameter(":WagesTypeID",dtWagesType.Rows[wagestype]["WagesTypeID"]),
  2998. };
  2999. DataSet dsExistRepairSubsidy = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  3000. if (dsExistRepairSubsidy != null && dsExistRepairSubsidy.Tables[0].Rows.Count == 0)
  3001. {
  3002. sqlString = @"insert into TP_PAR_RepairSubsidy
  3003. (
  3004. YYYYMM,
  3005. StaffID,
  3006. PayPlanID,
  3007. WagesTypeID,
  3008. RSuperioNum,
  3009. RSuperiorCoefficient,
  3010. RQualifiedNum,
  3011. RQualifiedCoefficient,
  3012. StandardWages,
  3013. RepairSubsidyRate,
  3014. RepairSubsidy,
  3015. Amount,
  3016. PieceTacticsID
  3017. ) values
  3018. (
  3019. :YYYYMM,
  3020. :StaffID,
  3021. :PayPlanID,
  3022. :WagesTypeID,
  3023. :RSuperioNum,
  3024. :RSuperiorCoefficient,
  3025. :RQualifiedNum,
  3026. :RQualifiedCoefficient,
  3027. :StandardWages,
  3028. :RepairSubsidyRate,
  3029. :RepairSubsidy,
  3030. :Amount,
  3031. :PieceTacticsID
  3032. )";
  3033. }
  3034. else
  3035. {
  3036. sqlString = @"update TP_PAR_RepairSubsidy
  3037. set
  3038. YYYYMM=:YYYYMM,
  3039. StaffID=:StaffID,
  3040. PayPlanID=:PayPlanID,
  3041. WagesTypeID=:WagesTypeID,
  3042. RSuperioNum=RSuperioNum+:RSuperioNum,
  3043. RSuperiorCoefficient=RSuperiorCoefficient+:RSuperiorCoefficient,
  3044. RQualifiedNum=RQualifiedNum+:RQualifiedNum,
  3045. RQualifiedCoefficient=RQualifiedCoefficient+:RQualifiedCoefficient,
  3046. StandardWages=StandardWages+:StandardWages,
  3047. RepairSubsidyRate=RepairSubsidyRate+:RepairSubsidyRate,
  3048. RepairSubsidy=RepairSubsidy+:RepairSubsidy,
  3049. Amount=Amount+:Amount,
  3050. PieceTacticsID=:PieceTacticsID
  3051. where YYYYMM=:YYYYMM and StaffID=:StaffID and PayPlanID=:PayPlanID and WagesTypeID=:WagesTypeID
  3052. ";
  3053. }
  3054. parmeters1 = new OracleParameter[]
  3055. {
  3056. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  3057. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  3058. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  3059. new OracleParameter(":WagesTypeID",dtWagesType.Rows[wagestype]["WagesTypeID"]),
  3060. new OracleParameter(":RSuperioNum",RepairSubsidy_RSuperioNum),
  3061. new OracleParameter(":RSuperiorCoefficient",RSuperiorCoefficient),
  3062. new OracleParameter(":RQualifiedNum",RepairSubsidy_RQualifiedNum),
  3063. new OracleParameter(":RQualifiedCoefficient",RQualifiedCoefficient),
  3064. new OracleParameter(":StandardWages",RepairStandardWages),
  3065. new OracleParameter(":RepairSubsidyRate",RepairSubsidyRate),
  3066. new OracleParameter(":RepairSubsidy",RepairSubsidy),
  3067. new OracleParameter(":Amount",temp_Repair),
  3068. new OracleParameter(":PieceTacticsID",PieceTacticsID_Insert3),
  3069. };
  3070. intResult = oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  3071. #endregion
  3072. }
  3073. }
  3074. }
  3075. else
  3076. {
  3077. // 经过该计件工序
  3078. // 先找出此工序的所有条码.用于筛选条码前的数据
  3079. //dsPieceProcedure_1.Tables[0].Merge(dsPieceProcedure_2.Tables[0]);
  3080. string ProcedureIDS = "";
  3081. //for (int a1 = 0; a1 < dsPieceProcedure_1.Tables[0].Rows.Count; a1++)
  3082. //{
  3083. // ProcedureIDS += dsPieceProcedure_1.Tables[0].Rows[a1]["ProcedureID"].ToString() + ",";
  3084. //}
  3085. ProcedureIDS = ProcedureIDS_New.Trim(',');
  3086. //DataRow[] drBarCode = dsTMPProductionData.Tables[0].Select("(ProcedureID=" + PieceProcedureID + " or ProcedureID=" + QualityBaseProcedureID + ") and UserID=" + dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString());
  3087. DataRow[] drBarCode = dsTMPProductionData.Tables[0].Select("ProcedureID in (" + ProcedureIDS + " )" + " and UserID=" + dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString());
  3088. DataTable dtTemp = new DataTable();
  3089. dtTemp.Columns.Add("ProcedureID"); //工序ID,用于有哪些分类
  3090. dtTemp.Columns.Add("BarCode"); //产品条码
  3091. dtTemp.Columns.Add("WagesTypeID"); // 工价分类
  3092. dtTemp.Columns.Add("GoodsFlag"); //产品标识
  3093. //DataRow[] drMonth = dsPayPlanSetting.Tables[0].Select("SettingCode='01001'");
  3094. //int newGoodsMonth = Convert.ToInt32(drMonth[0]["SettingValue"]); //新产品适应周期(月)
  3095. if (drBarCode.Length > 0)
  3096. {
  3097. DataTable dtTemp_TMPProductionData = drBarCode.CopyToDataTable();
  3098. foreach (DataRow r in drBarCode)
  3099. {
  3100. DataRow[] drFirst = dtTemp_TMPProductionData.Select("barcode='" + r["barcode"] + "' and ProductionDataID<" + r["ProductionDataID"] + " and UserID=" + dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString());
  3101. if (drFirst.Length > 0)
  3102. {
  3103. foreach (DataRow rr in drFirst)//可能会多行,
  3104. {
  3105. DataRow drNew = dtTemp.NewRow();
  3106. drNew["ProcedureID"] = rr["ProcedureID"];
  3107. drNew["BarCode"] = rr["BarCode"];
  3108. drNew["WagesTypeID"] = rr["WagesTypeID"];
  3109. if (Convert.ToDateTime(rr["StartingDate"]).AddMonths(newGoodsMonth) > DateTime.Now)
  3110. {
  3111. drNew["GoodsFlag"] = 3; //正常
  3112. }
  3113. else
  3114. {
  3115. drNew["GoodsFlag"] = 1; //新品
  3116. }
  3117. dtTemp.Rows.Add(drNew);
  3118. }
  3119. }
  3120. }
  3121. }
  3122. if (dtTemp.Rows.Count > 0)
  3123. {
  3124. //-----------------------------------
  3125. // 1.算出是否有新品,还是老品
  3126. //3 报损责任工序
  3127. //if (!dsTMPResponProcedure.Tables[0].Columns.Contains("GoodsFlag"))
  3128. //{
  3129. // dsTMPResponProcedure.Tables[0].Columns.Add("GoodsFlag");
  3130. // for (int bb = 0; bb < dsTMPResponProcedure.Tables[0].Rows.Count; bb++)
  3131. // {
  3132. // if (dsTMPResponProcedure.Tables[0].Rows[bb]["StartingDate"].ToString() != "")
  3133. // {
  3134. // if (Convert.ToDateTime(dsTMPResponProcedure.Tables[0].Rows[bb]["StartingDate"]).AddMonths(newGoodsMonth) > DateTime.Now)
  3135. // {
  3136. // dsTMPResponProcedure.Tables[0].Rows[bb]["GoodsFlag"] = 3; //正常
  3137. // }
  3138. // else
  3139. // {
  3140. // dsTMPResponProcedure.Tables[0].Rows[bb]["GoodsFlag"] = 1; //新品
  3141. // }
  3142. // }
  3143. // else
  3144. // {
  3145. // dsTMPResponProcedure.Tables[0].Rows[bb]["GoodsFlag"] = 3; //正常
  3146. // }
  3147. // }
  3148. //}
  3149. //for (int bb = 0; bb < dsTMPResponProcedure.Tables[0].Rows.Count; bb++)
  3150. //{
  3151. // if (dsTMPResponProcedure.Tables[0].Rows[bb]["StartingDate"].ToString() != "")
  3152. // {
  3153. // if (Convert.ToDateTime(dsTMPResponProcedure.Tables[0].Rows[bb]["StartingDate"]).AddMonths(newGoodsMonth) > DateTime.Now)
  3154. // {
  3155. // dsTMPResponProcedure.Tables[0].Rows[bb]["GoodsFlag"] = 3; //正常
  3156. // }
  3157. // else
  3158. // {
  3159. // dsTMPResponProcedure.Tables[0].Rows[bb]["GoodsFlag"] = 1; //新品
  3160. // }
  3161. // }
  3162. // else
  3163. // {
  3164. // dsTMPResponProcedure.Tables[0].Rows[bb]["GoodsFlag"] = 3; //正常
  3165. // }
  3166. //}
  3167. //-----------------------------------
  3168. // 重新排序,把生产数据ID大的排在上面,便于下面进行筛选
  3169. DataView dv = dtTemp.DefaultView;
  3170. dv.Sort = "ProductionDataID desc";
  3171. dtTemp = dv.ToTable();
  3172. // 此时dtTemp有产品分类,同时也可能有多个工序
  3173. // 1看有多少个分类
  3174. dtWagesType = dtTemp.DefaultView.ToTable(true, "WagesTypeID");
  3175. // 2看有多少个工序
  3176. DataTable dtProcedure = dtTemp.DefaultView.ToTable(true, "ProcedureID");
  3177. // 有多少产品标识
  3178. dtGoodsFlag = dtTemp.DefaultView.ToTable(true, "GoodsFlag");
  3179. int PieceProcedureCount2 = 0;
  3180. int UnqualifiedCount2 = 0;
  3181. int QualifiedCount2 = 0;
  3182. int QualityBaseProcedureCount2 = 0;
  3183. FinishedProduct_BarCode = "";
  3184. for (int ii = 0; ii < dtWagesType.Rows.Count; ii++)
  3185. {
  3186. for (int vv = 0; vv < dtGoodsFlag.Rows.Count; vv++)
  3187. {
  3188. decimal? temp_Piecegiework = 0;
  3189. #region 1.求出各分类计件工序数量
  3190. PieceProcedureCount2 = 0;
  3191. QualityBaseProcedureCount2 = 0;
  3192. decimal PieceProcedureTotal = 0; //系数*数量
  3193. //for (int jj = 0; jj < dtProcedure.Rows.Count; jj++)
  3194. //{
  3195. for (int p1 = 0; p1 < dsPieceProcedure_1.Tables[0].Rows.Count; p1++)
  3196. {
  3197. DataRow[] datarow = dtTemp.Select("WagesTypeID=" + dtWagesType.Rows[ii]["WagesTypeID"] + " and ProcedureID=" + dsPieceProcedure_1.Tables[0].Rows[p1]["ProcedureID"]);
  3198. if (datarow.Length > 0)
  3199. {
  3200. foreach (DataRow r in datarow)
  3201. {
  3202. if (!FinishedProduct_BarCode.Contains(r["barcode"].ToString()))
  3203. FinishedProduct_BarCode = FinishedProduct_BarCode + r["barcode"].ToString() + ",";
  3204. }
  3205. PieceProcedureCount2 += datarow.Length;
  3206. break;
  3207. }
  3208. else
  3209. {
  3210. continue;
  3211. }
  3212. }
  3213. //}
  3214. PieceProcedureTotal = PieceProcedureCount2 * PieceCoefficient;
  3215. #endregion 1.求出各分类计件工序数量
  3216. #region 2.求出各工价分类损坯数量
  3217. int ScrapCount = 0; //损坯数量
  3218. decimal? Scrap = 0; //每个类别损坯的值
  3219. if (DamageFlag == "1") //计算损坯数量
  3220. {
  3221. // 查出此人在计件工序的条码,完事关联报损表存在多少报损条码
  3222. string ProcedureIDS2 = "0"; //默认给个0,怕没有些去进行筛选出现错误
  3223. for (int p1 = 0; p1 < dsPieceProcedure_1.Tables[0].Rows.Count; p1++)
  3224. {
  3225. if(p1==0)
  3226. {
  3227. ProcedureIDS2 = "";
  3228. }
  3229. ProcedureIDS2 = ProcedureIDS2 + dsPieceProcedure_1.Tables[0].Rows[p1]["ProcedureID"].ToString() + ",";
  3230. }
  3231. ProcedureIDS2 = ProcedureIDS2.Trim(',');
  3232. // 筛选出生产数据这几个工序所用的条码
  3233. // DataRow[] dr_BarCode = dsTMPProductionData.Tables[0].Select(string.Format("UserID={0} and ProcedureID in ({1}) and WagesTypeID={2} and GoodsFlag={3}", dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString(), ProcedureIDS2, dtWagesType.Rows[ii]["WagesTypeID"], dtGoodsFlag.Rows[vv]["GoodsFlag"]));
  3234. DataRow[] dr_BarCode = dsTMPProductionData.Tables[0].Select(string.Format("UserID={0} and ProcedureID in ({1}) and WagesTypeID={2} and GoodsFlag={3}", dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString(), ProcedureIDS, dtWagesType.Rows[ii]["WagesTypeID"], dtGoodsFlag.Rows[vv]["GoodsFlag"]));
  3235. if (dr_BarCode.Length > 0)
  3236. {
  3237. string temp_barcode = "";
  3238. foreach (DataRow r3 in dr_BarCode) //有可能出现重复barcode
  3239. {
  3240. dr2 = dsTMPResponProcedure.Tables[0].Select("barcode='" + r3["barcode"] + "' and AuditStatus=1 and UserID=" + dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString());
  3241. if (dr2.Length > 0)
  3242. {
  3243. if (!temp_barcode.Contains(r3["barcode"].ToString()))
  3244. {
  3245. // 有损坯数据
  3246. ScrapCount = ScrapCount + 1;
  3247. }
  3248. temp_barcode += r3["barcode"].ToString() + ",";
  3249. }
  3250. }
  3251. }
  3252. // end
  3253. Scrap = ScrapCount * DamageCoefficient; //DamageCoefficient为损坯系数
  3254. }
  3255. #endregion 2.求出损坯数量 end
  3256. #region 3.求出各工价分类次品数
  3257. // 筛出产品分级为次品的生产数据,完事一个一个去查对应责任工号的,进行累加
  3258. drUnqualifiedCount = dsTMPProductionData.Tables[0]
  3259. .Select(string.Format("WagesTypeID={0} and GoodsLevelTypeID=7 and GoodsFlag={1} ", dtWagesType.Rows[ii]["WagesTypeID"], dtGoodsFlag.Rows[vv]["GoodsFlag"]));
  3260. UnqualifiedCount2 = 0; //次品数量
  3261. decimal? UnqualifiedTotal = 0;//系数*数量
  3262. if (drUnqualifiedCount.Length > 0)
  3263. {
  3264. // 表示有次品,但是得对应责任工号,进行累加
  3265. foreach (DataRow row in drUnqualifiedCount)
  3266. {
  3267. //string sqlView = "select 1 from TMP_PAM_Defect where DefectUserID=" + dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString() + " and ProductionDataID=" + row["ProductionDataID"];
  3268. //DataSet ds = oracleTrConn.GetSqlResultToDs(sqlView);
  3269. //if (ds != null && ds.Tables[0].Rows.Count > 0)
  3270. //{
  3271. // // 多个缺陷也算一个数,所以直接+1
  3272. // UnqualifiedCount2 = UnqualifiedCount2 + 1;
  3273. //}
  3274. rt = dsDefect.Tables[0].Select("DefectUserID=" + dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString() + " and ProductionDataID=" + row["ProductionDataID"]);
  3275. if (rt.Length > 0)
  3276. {
  3277. // 多个缺陷也算一个数,所以直接+1
  3278. UnqualifiedCount2 = UnqualifiedCount2 + 1;
  3279. }
  3280. }
  3281. UnqualifiedTotal = UnqualifiedCount2 * UnqualifiedCoefficient;
  3282. }
  3283. #endregion
  3284. #region 4.求出各工价分类副品数
  3285. // 筛出产品分级为副品的生产数据,完事一个一个去查对应责任工号的,进行累加
  3286. drQualified = dsTMPProductionData.Tables[0]
  3287. .Select(string.Format("WagesTypeID={0} and GoodsLevelTypeID=5 and GoodsFlag={1}", dtWagesType.Rows[ii]["WagesTypeID"], dtGoodsFlag.Rows[vv]["GoodsFlag"]));
  3288. QualifiedCount2 = 0; //副品数量
  3289. decimal? QualifiedTotal = 0;//系数*数量
  3290. if (drQualified.Length > 0)
  3291. {
  3292. // 表示有副品,但是得对应责任工号,进行累加
  3293. foreach (DataRow row in drQualified)
  3294. {
  3295. //string sqlView = "select 1 from TMP_PAM_Defect where DefectUserID=" + dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString() + " and ProductionDataID=" + row["ProductionDataID"];
  3296. //DataSet ds = oracleTrConn.GetSqlResultToDs(sqlView);
  3297. //if (ds != null && ds.Tables[0].Rows.Count > 0)
  3298. //{
  3299. // // 多个缺陷也算一个数,所以直接+1
  3300. // QualifiedCount2 = QualifiedCount2 + 1;
  3301. //}
  3302. rt = dsDefect.Tables[0].Select("DefectUserID=" + dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString() + " and ProductionDataID=" + row["ProductionDataID"]);
  3303. if (rt.Length > 0)
  3304. {
  3305. // 多个缺陷也算一个数,所以直接+1
  3306. QualifiedCount2 = QualifiedCount2 + 1;
  3307. }
  3308. }
  3309. QualifiedTotal = QualifiedCount2 * QualifiedCoefficient;
  3310. }
  3311. #endregion 求出各工价分类副品数
  3312. #region 5.求出质量工价
  3313. string barcodes_Procedure = "";
  3314. QualityBaseProcedureCount2 = 0;
  3315. for (int p1 = 0; p1 < dsPieceProcedure_2.Tables[0].Rows.Count; p1++)
  3316. {
  3317. //DataRow[] drQualityBaseProcedure = dsTMPProductionData.Tables[0]
  3318. // .Select(string.Format("UserID={0} and ProcedureID={1} and WagesTypeID={2} and GoodsFlag={3}", dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString(), dsPieceProcedure_2.Tables[0].Rows[p1]["ProcedureID"], dtWagesType.Rows[wagestype]["WagesTypeID"], dtGoodsFlag.Rows[vv]["GoodsFlag"]));
  3319. //QualityBaseProcedureCount += drQualityBaseProcedure.Length; // 质量工序数量
  3320. //DataRow[] drQualityBaseProcedure = dsTMPProductionData.Tables[0]
  3321. // .Select(string.Format("ProcedureID={0} and WagesTypeID={1} and GoodsFlag={2}", dsPieceProcedure_2.Tables[0].Rows[p1]["ProcedureID"], dtWagesType.Rows[wagestype]["WagesTypeID"], dtGoodsFlag.Rows[vv]["GoodsFlag"]));
  3322. drQualityBaseProcedure = dsTMPProductionData.Tables[0]
  3323. .Select(string.Format("ProcedureID={0} and WagesTypeID={1}", dsPieceProcedure_2.Tables[0].Rows[p1]["ProcedureID"], dtWagesType.Rows[ii]["WagesTypeID"]));
  3324. if (drQualityBaseProcedure.Length > 0)
  3325. {
  3326. foreach (DataRow r4 in drQualityBaseProcedure)
  3327. {
  3328. if (!barcodes_Procedure.Contains(r4["barcode"].ToString()))
  3329. {
  3330. QualityBaseProcedureCount2 += 1; // 质量工序数量
  3331. }
  3332. barcodes_Procedure = barcodes_Procedure + r4["barcode"].ToString() + ",";
  3333. }
  3334. }
  3335. }
  3336. QualityBaseProcedureTotal = 0;//只是算出优等品率,还有和产品质量区间进行匹配
  3337. QualityWages = 0; //质量工价 ,用于最后计算相乘
  3338. Quality = 0; //质量
  3339. if (QualityBaseProcedureCount2 != 0)
  3340. {
  3341. QualityBaseProcedureTotal = Convert.ToDecimal((QualityBaseProcedureCount2 - UnqualifiedCount2)) / Convert.ToDecimal(QualityBaseProcedureCount2);
  3342. }
  3343. //查看此员工是否为正式员工还是试用员工,如果试用取工价类别的标准工价
  3344. // 1取出此工类下的产品工价区间
  3345. DataRow[] drWages = dsWages.Tables[0].Select("WagesTypeID=" + dtWagesType.Rows[ii]["WagesTypeID"]);
  3346. decimal StandardWages = 0;
  3347. if (drWages.Length > 0)
  3348. {
  3349. StandardWages = Convert.ToDecimal(drWages[0]["StandardWages"]); //标准工价
  3350. }
  3351. if (dsJobsPayPlan.Tables[0].Rows[j]["ExProbationEndDate"].ToString() == "") //表示正式员工
  3352. {
  3353. // 2取出此工类下的质量区间
  3354. drQualityWages = dsQualityWages.Tables[0].Select("WagesTypeID=" + dtWagesType.Rows[ii]["WagesTypeID"] + " and QualityRate>=" + QualityBaseProcedureTotal, "QualityRate desc");
  3355. if (drQualityWages.Length > 0)
  3356. {
  3357. //表示质量区间设置没有比优品率大的
  3358. QualityWages = Convert.ToDecimal(drQualityWages[0]["QualityWages"]);
  3359. Quality = Convert.ToDecimal(drQualityWages[0]["QualityRate"]);
  3360. }
  3361. else
  3362. {
  3363. QualityWages = 0;// Convert.ToDecimal(drQualityWages[0]["QualityWages"]);
  3364. }
  3365. }
  3366. else
  3367. {
  3368. if (Convert.ToDateTime(dsJobsPayPlan.Tables[0].Rows[j]["ExProbationEndDate"]) < DateTime.Now)
  3369. {
  3370. // 试用结束结束
  3371. // 2取出此工类下的质量区间
  3372. drQualityWages = dsQualityWages.Tables[0].Select("WagesTypeID=" + dtWagesType.Rows[ii]["WagesTypeID"] + " and QualityRate>=" + QualityBaseProcedureTotal);
  3373. if (drQualityWages.Length > 0)
  3374. {
  3375. //表示质量区间设置没有比优品率大的
  3376. QualityWages = Convert.ToDecimal(drQualityWages[0]["QualityWages"]);
  3377. Quality = Convert.ToDecimal(drQualityWages[0]["QualityRate"]);
  3378. }
  3379. else
  3380. {
  3381. QualityWages = 0;// Convert.ToDecimal(drQualityWages[0]["QualityWages"]);
  3382. }
  3383. }
  3384. }
  3385. #endregion
  3386. //#region 查出这个工号下有多少员工,计件工资进行平分
  3387. //sqlString = "select 1 from tp_mst_userstaff where userid=" + dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString();
  3388. //userstaffcount = 1;
  3389. //dsUserStaffCount = oracleTrConn.GetSqlResultToDs(sqlString);
  3390. //if (dsUserStaffCount != null && dsUserStaffCount.Tables[0].Rows.Count > 0)
  3391. //{
  3392. // userstaffcount = dsUserStaffCount.Tables[0].Rows.Count;
  3393. //}
  3394. //#endregion
  3395. totalcount_Piecegiework += ((PieceProcedureTotal - Scrap - UnqualifiedTotal - QualifiedTotal) * QualityWages) < 0 ? 0 : ((PieceProcedureTotal - Scrap - UnqualifiedTotal - QualifiedTotal) * QualityWages) / userstaffcount;
  3396. temp_Piecegiework = ((PieceProcedureTotal - Scrap - UnqualifiedTotal - QualifiedTotal) * QualityWages) < 0 ? 0 : ((PieceProcedureTotal - Scrap - UnqualifiedTotal - QualifiedTotal) * QualityWages);// userstaffcount;
  3397. #region 插入计件工资
  3398. sqlString = "select 1 from TP_PAR_Piecework where YYYYMM=:YYYYMM and StaffID=:StaffID and PayPlanID=:PayPlanID and WagesTypeID=:WagesTypeID";
  3399. parmeters1 = new OracleParameter[]
  3400. {
  3401. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  3402. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  3403. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  3404. new OracleParameter(":WagesTypeID",dtWagesType.Rows[ii]["WagesTypeID"]),
  3405. };
  3406. dsExistPiecework = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  3407. //// 读取计件工资策略
  3408. //int PieceTacticsID_Insert = 0;
  3409. //sqlString = "select PieceTacticsID from TP_PAT_Piecework where PayPlanID=:PayPlanID";
  3410. //parmeters1 = new OracleParameter[]
  3411. //{
  3412. // new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  3413. //};
  3414. //DataSet dss = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  3415. //if (dss != null && dss.Tables[0].Rows.Count > 0)
  3416. //{
  3417. // PieceTacticsID_Insert = Convert.ToInt32(dss.Tables[0].Rows[0]["PieceTacticsID"]);
  3418. //}
  3419. ////-------------------------------------
  3420. if (dsExistPiecework != null && dsExistPiecework.Tables[0].Rows.Count == 0)
  3421. {
  3422. sqlString = @"insert into TP_PAR_Piecework
  3423. (
  3424. YYYYMM,
  3425. StaffID,
  3426. PayPlanID,
  3427. StaffFlag,
  3428. GoodsFlag,
  3429. WagesTypeID,
  3430. PieceworkNum,
  3431. PieceCoefficient,
  3432. DamageNum,
  3433. DamageCoefficient,
  3434. UnqualifiedNum,
  3435. UnqualifiedCoefficient,
  3436. QualifiedNum,
  3437. QualifiedCoefficient,
  3438. QualityBaseNum,
  3439. QualityRate,
  3440. QualityWages,
  3441. Amount,
  3442. PieceTacticsID
  3443. ) values
  3444. (
  3445. :YYYYMM,
  3446. :StaffID,
  3447. :PayPlanID,
  3448. :StaffFlag,
  3449. :GoodsFlag,
  3450. :WagesTypeID,
  3451. :PieceworkNum,
  3452. :PieceCoefficient,
  3453. :DamageNum,
  3454. :DamageCoefficient,
  3455. :UnqualifiedNum,
  3456. :UnqualifiedCoefficient,
  3457. :QualifiedNum,
  3458. :QualifiedCoefficient,
  3459. :QualityBaseNum,
  3460. :QualityRate,
  3461. :QualityWages,
  3462. :Amount,
  3463. :PieceTacticsID
  3464. )";
  3465. }
  3466. else
  3467. {
  3468. sqlString = @"update TP_PAR_Piecework
  3469. set
  3470. YYYYMM=:YYYYMM,
  3471. StaffID=:StaffID,
  3472. PayPlanID=:PayPlanID,
  3473. StaffFlag=:StaffFlag,
  3474. PieceTacticsID=:PieceTacticsID,
  3475. GoodsFlag=:GoodsFlag,
  3476. WagesTypeID=:WagesTypeID,
  3477. PieceworkNum=PieceworkNum+:PieceworkNum,
  3478. PieceCoefficient=PieceCoefficient+:PieceCoefficient,
  3479. DamageNum=DamageNum+:DamageNum,
  3480. DamageCoefficient=DamageCoefficient+:DamageCoefficient,
  3481. UnqualifiedNum=UnqualifiedNum+:UnqualifiedNum,
  3482. UnqualifiedCoefficient=UnqualifiedCoefficient+:UnqualifiedCoefficient,
  3483. QualifiedNum=QualifiedNum+:QualifiedNum,
  3484. QualifiedCoefficient=QualifiedCoefficient+:QualifiedCoefficient,
  3485. QualityBaseNum=QualityBaseNum+:QualityBaseNum,
  3486. QualityRate=QualityRate+:QualityRate,
  3487. QualityWages=QualityWages+:QualityWages,
  3488. Amount=Amount+:Amount
  3489. where YYYYMM=:YYYYMM and StaffID=:StaffID and PayPlanID=:PayPlanID and WagesTypeID=:WagesTypeID
  3490. ";
  3491. }
  3492. parmeters1 = new OracleParameter[]
  3493. {
  3494. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  3495. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  3496. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  3497. new OracleParameter(":StaffFlag",dsJobsPayPlan.Tables[0].Rows[j]["StaffStatus"]),
  3498. //new OracleParameter(":BeginDate",dateStartTime),
  3499. //new OracleParameter(":EndDate",dateEndTime),
  3500. new OracleParameter(":GoodsFlag", dtGoodsFlag.Rows[vv]["GoodsFlag"]),
  3501. new OracleParameter(":WagesTypeID",dtWagesType.Rows[ii]["WagesTypeID"]),
  3502. //new OracleParameter(":GoodsID",null),
  3503. new OracleParameter(":PieceworkNum",PieceProcedureCount2),
  3504. new OracleParameter(":PieceCoefficient",PieceCoefficient),
  3505. new OracleParameter(":DamageNum",ScrapCount),
  3506. new OracleParameter(":DamageCoefficient",DamageCoefficient),
  3507. new OracleParameter(":UnqualifiedNum",UnqualifiedCount2),
  3508. new OracleParameter(":UnqualifiedCoefficient",UnqualifiedCoefficient),
  3509. new OracleParameter(":QualifiedNum",QualifiedCount2),
  3510. new OracleParameter(":QualifiedCoefficient",QualifiedCoefficient),
  3511. new OracleParameter(":QualityBaseNum",QualityBaseProcedureCount2),
  3512. new OracleParameter(":QualifiedCoefficient",QualifiedCoefficient),
  3513. new OracleParameter(":QualityRate",QualityBaseProcedureTotal),
  3514. new OracleParameter(":QualityWages",QualityWages),
  3515. new OracleParameter(":Amount",temp_Piecegiework),
  3516. new OracleParameter(":PieceTacticsID",PieceTacticsID_Insert),
  3517. };
  3518. intResult = oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  3519. #endregion
  3520. }
  3521. FinishedProduct_BarCode = FinishedProduct_BarCode.Trim(',');
  3522. #region 损坯补贴
  3523. scrapcount_1 = 0; //损坯数量
  3524. scrap_StandardWages = 0; //损坯标准工价
  3525. scrap_DamageSubsidyRate = 0; //损坯补贴系数
  3526. scrap_DamageSubsidy = 0; //损坯补贴
  3527. temp_Scrap = 0;// //最后损坯补贴钱
  3528. //1.查出此员工工号下所生产数据,即做过哪此产品条码
  3529. DataRow[] drScrapProduction = dsTMPProductionData.Tables[0].Select("UserID=" + dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString() + " and WagesTypeID=" + dtWagesType.Rows[ii]["WagesTypeID"]);
  3530. if (drScrapProduction.Length > 0)
  3531. {
  3532. //算出此工号,此工价分类存在条码,拼出条码,进而去报损查出非自身损坯的数量,进而计算
  3533. //string barcodes = "";
  3534. //foreach (DataRow rbarcode in drScrapProduction)
  3535. //{
  3536. // barcodes += rbarcode["barcode"].ToString() + ",";
  3537. //}
  3538. //barcodes = barcodes.Trim(',');
  3539. // string sql = @"select TMP_PAM_ScrapProduct.barcode,TMP_PAM_ResponProcedure.UserID from TMP_PAM_ScrapProduct left join TMP_PAM_ResponProcedure
  3540. // on TMP_PAM_ScrapProduct.ScrapProductID=TMP_PAM_ResponProcedure.ScrapProductID ";
  3541. // sql = sql + " where instr(','||:barcodes||',',','||TMP_PAM_ScrapProduct.BarCode||',')>0 ";
  3542. // sql = sql + " and TMP_PAM_ResponProcedure.UserID<>:UserID";
  3543. // sql = @"select distinct TMP_PAM_ScrapProduct.barcode,TMP_PAM_ResponProcedure.UserID from TMP_PAM_ScrapProduct left join TMP_PAM_ResponProcedure
  3544. // on TMP_PAM_ScrapProduct.ScrapProductID=TMP_PAM_ResponProcedure.ScrapProductID ";
  3545. // sql = sql + " where TMP_PAM_ScrapProduct.barcode in (select barcode from TMP_PAM_ProductionData where UserID=:UserID and ProcedureID in (select TP_PAT_PieceProcedure.ProcedureID from TP_PAT_Piecework left join TP_PAT_PieceProcedure on TP_PAT_Piecework.PieceTacticsID=TP_PAT_PieceProcedure.PieceTacticsID and TP_PAT_PieceProcedure.ProcedureFlag=1 where TP_PAT_Piecework.PayPlanID=:PayPlanID)) ";
  3546. // sql = sql + " and TMP_PAM_ResponProcedure.UserID<>:UserID";
  3547. // parmeters1 = new OracleParameter[]
  3548. // {
  3549. // //new OracleParameter(":barcodes",barcodes),
  3550. // new OracleParameter(":UserID",dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString()),
  3551. // new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  3552. // };
  3553. // DataSet dsTemp = oracleTrConn.GetSqlResultToDs(sql, parmeters1);
  3554. string inPro = "";
  3555. if (dsPieceProcedure_1 != null && dsPieceProcedure_1.Tables[0].Rows.Count > 0)
  3556. {
  3557. for (int zz = 0; zz < dsPieceProcedure_1.Tables[0].Rows.Count; zz++)
  3558. {
  3559. inPro = inPro + dsPieceProcedure_1.Tables[0].Rows[zz]["ProcedureID"].ToString() + ",";
  3560. }
  3561. inPro = inPro.Trim(',');
  3562. }
  3563. if (inPro == "")
  3564. inPro = "0";
  3565. // 1. 查出此人计工序的条码
  3566. DataRow[] r5 = dsTMPProductionData.Tables[0].Select("UserID=" + dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString() + " and ProcedureID in (" + inPro + ")");
  3567. string a1 = "";
  3568. int scrapcount = 0;
  3569. string sqlInsertDamageSubsidy = "insert into TP_PAD_DamageSubsidy(Barcode,userID) values(:Barcode,:UserID)";
  3570. string sqladd = "select 1 from TP_PAD_DamageSubsidy where barcode=:barcode and userid=:userid";
  3571. if (r5.Length > 0)
  3572. {
  3573. // 有条码
  3574. foreach (DataRow rr in r5)
  3575. {
  3576. r7 = dsScrap_New.Tables[0].Select("barcode='" + rr["barcode"] + "'");
  3577. if (r7.Length > 0 && !a1.Contains(rr["barcode"].ToString()))
  3578. {
  3579. scrapcount = scrapcount + 1;
  3580. a1 = a1 + rr["barcode"].ToString();
  3581. parmeters1 = new OracleParameter[]
  3582. {
  3583. new OracleParameter(":Barcode",rr["Barcode"]),
  3584. new OracleParameter(":UserID",dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString()),
  3585. };
  3586. ds3 = oracleTrConn.GetSqlResultToDs(sqladd, parmeters1);
  3587. if (ds3 != null && ds3.Tables[0].Rows.Count == 0)
  3588. oracleTrConn.ExecuteNonQuery(sqlInsertDamageSubsidy, parmeters1);
  3589. }
  3590. }
  3591. }
  3592. //if (dsTemp.Tables[0].Rows.Count > 0)
  3593. if (scrapcount > 0)
  3594. {
  3595. //// 大于零遍历此表,插入损坯补贴记录表中,过滤给报损补贴后就不能给干补补贴
  3596. //string sqlInsertDamageSubsidy = "insert into TP_PAD_DamageSubsidy(Barcode,userID) values(:Barcode,:UserID)";
  3597. //for (int insert = 0; insert < dsTemp.Tables[0].Rows.Count; insert++)
  3598. //{
  3599. // string sqladd = "select 1 from TP_PAD_DamageSubsidy where barcode=:barcode and userid=:userid";
  3600. // parmeters1 = new OracleParameter[]
  3601. // {
  3602. // new OracleParameter(":Barcode",dsTemp.Tables[0].Rows[insert]["Barcode"]),
  3603. // new OracleParameter(":UserID",dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString()),
  3604. // };
  3605. // DataSet ds3 = oracleTrConn.GetSqlResultToDs(sqladd, parmeters1);
  3606. // if (ds3 != null && ds3.Tables[0].Rows.Count == 0)
  3607. // oracleTrConn.ExecuteNonQuery(sqlInsertDamageSubsidy, parmeters1);
  3608. //}
  3609. scrapcount_1 = scrapcount;// dsTemp.Tables[0].Rows.Count; //非自身损坯数量
  3610. // 求出损坯对应系数
  3611. DataRow[] drScrapWages = dsWages.Tables[0].Select("WagesTypeID=" + dtWagesType.Rows[ii]["WagesTypeID"]);
  3612. //decimal? scrapDamageSubsidy = 0; //损坯补贴
  3613. if (drScrapWages.Length > 0)
  3614. {
  3615. //scrapDamageSubsidy += Convert.ToDecimal(drScrapWages[0]["DamageSubsidy"]);
  3616. scrap_StandardWages = Convert.ToDecimal(drScrapWages[0]["StandardWages"]); //标准工价
  3617. scrap_DamageSubsidyRate = Convert.ToDecimal(drScrapWages[0]["DamageSubsidyRate"]);//损坯补贴系数
  3618. //scrap_DamageSubsidy = Convert.ToDecimal(drScrapWages[0]["DamageSubsidy"]); //损坯补贴
  3619. scrap_DamageSubsidy = Convert.ToDecimal(scrap_StandardWages) * scrap_DamageSubsidyRate; //损坯补贴
  3620. }
  3621. //totalcount_Scrap += scrapDamageSubsidy;
  3622. temp_Scrap = Convert.ToDecimal(scrapcount_1 * scrap_StandardWages * scrap_DamageSubsidyRate);
  3623. totalcount_Scrap += temp_Scrap / userstaffcount;
  3624. }
  3625. }
  3626. #endregion
  3627. #region 插入损坯补贴
  3628. //// 读取计件工资策略
  3629. //int PieceTacticsID_Insert2 = 0;
  3630. //sqlString = "select PieceTacticsID from TP_PAT_Piecework where PayPlanID=:PayPlanID";
  3631. //parmeters1 = new OracleParameter[]
  3632. // {
  3633. // new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  3634. // };
  3635. //DataSet dss2 = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  3636. //if (dss2 != null && dss2.Tables[0].Rows.Count > 0)
  3637. //{
  3638. // PieceTacticsID_Insert2 = Convert.ToInt32(dss2.Tables[0].Rows[0]["PieceTacticsID"]);
  3639. //}
  3640. ////-------------------------------------
  3641. sqlString = "select 1 from TP_PAR_DamageSubsidy where YYYYMM=:YYYYMM and StaffID=:StaffID and PayPlanID=:PayPlanID and WagesTypeID=:WagesTypeID";
  3642. parmeters1 = new OracleParameter[]
  3643. {
  3644. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  3645. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  3646. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  3647. new OracleParameter(":WagesTypeID",dtWagesType.Rows[ii]["WagesTypeID"]),
  3648. };
  3649. DataSet dsExistDamageSubsidy = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  3650. if (dsExistDamageSubsidy != null && dsExistDamageSubsidy.Tables[0].Rows.Count == 0)
  3651. {
  3652. sqlString = @"insert into TP_PAR_DamageSubsidy
  3653. (
  3654. YYYYMM,
  3655. StaffID,
  3656. PayPlanID,
  3657. WagesTypeID,
  3658. DamageNum,
  3659. StandardWages,
  3660. DamageSubsidyRate,
  3661. DamageSubsidy,
  3662. Amount,
  3663. PieceTacticsID
  3664. ) values
  3665. (
  3666. :YYYYMM,
  3667. :StaffID,
  3668. :PayPlanID,
  3669. :WagesTypeID,
  3670. :DamageNum,
  3671. :StandardWages,
  3672. :DamageSubsidyRate,
  3673. :DamageSubsidy,
  3674. :Amount,
  3675. :PieceTacticsID
  3676. )";
  3677. }
  3678. else
  3679. {
  3680. sqlString = @"update TP_PAR_DamageSubsidy
  3681. set YYYYMM=:YYYYMM,
  3682. StaffID=StaffID,
  3683. PayPlanID=:PayPlanID,
  3684. WagesTypeID=:WagesTypeID,
  3685. DamageNum=DamageNum+:DamageNum,
  3686. StandardWages=StandardWages+:StandardWages,
  3687. DamageSubsidyRate=DamageSubsidyRate+:DamageSubsidyRate,
  3688. DamageSubsidy=DamageSubsidy+:DamageSubsidy,
  3689. Amount=Amount+:Amount,
  3690. PieceTacticsID=:PieceTacticsID
  3691. where YYYYMM=:YYYYMM and StaffID=:StaffID and PayPlanID=:PayPlanID and WagesTypeID=:WagesTypeID
  3692. ";
  3693. }
  3694. parmeters1 = new OracleParameter[]
  3695. {
  3696. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  3697. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  3698. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  3699. new OracleParameter(":WagesTypeID",dtWagesType.Rows[ii]["WagesTypeID"]),
  3700. new OracleParameter(":DamageNum",scrapcount_1),
  3701. new OracleParameter(":StandardWages",scrap_StandardWages),
  3702. new OracleParameter(":DamageSubsidyRate",scrap_DamageSubsidyRate),
  3703. new OracleParameter(":DamageSubsidy",scrap_DamageSubsidy),
  3704. new OracleParameter(":Amount",temp_Scrap),
  3705. new OracleParameter(":PieceTacticsID",PieceTacticsID_Insert2),
  3706. };
  3707. intResult = oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  3708. #endregion
  3709. #region 干补补贴,从成品表时读取数据来计算干补数量
  3710. // 1 查出这个工号的,这个分类的,下一面在去过滤正品,还是副品
  3711. int RepairSubsidy_RSuperioNum = 0;//干补正品数
  3712. // 干补正品数
  3713. if (!string.IsNullOrEmpty(FinishedProduct_BarCode))
  3714. {
  3715. DataRow[] drRepairSubsidy_RSuperioNum = dsFinishedProduct.Tables[0].Select("SpecialRepairFlag=1 and GoodsLevelTypeID=4 and WagesTypeID=" + dtWagesType.Rows[ii]["WagesTypeID"] + " and barcode in(" + FinishedProduct_BarCode + ")");
  3716. if (drRepairSubsidy_RSuperioNum.Length > 0)
  3717. {
  3718. RepairSubsidy_RSuperioNum = drRepairSubsidy_RSuperioNum.Length;
  3719. // 尽管有干补,但是有可能在损坯补贴给了,此处得查询一下干补补贴表,如果存在就不给此补贴
  3720. sqlString = "select 1 from TP_PAD_DamageSubsidy where Barcode=:Barcode and UserID=:UserID";
  3721. foreach (DataRow mm in drRepairSubsidy_RSuperioNum)
  3722. {
  3723. parmeters1 = new OracleParameter[]
  3724. {
  3725. new OracleParameter(":Barcode",mm["barcode"].ToString()),
  3726. new OracleParameter(":UserID",dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString()),
  3727. };
  3728. dsTemp = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  3729. if (dsTemp.Tables[0].Rows.Count > 0)
  3730. {
  3731. RepairSubsidy_RSuperioNum = RepairSubsidy_RSuperioNum - 1;
  3732. }
  3733. }
  3734. }
  3735. }
  3736. int RepairSubsidy_RQualifiedNum = 0;//干补副品数
  3737. // 干补正品数
  3738. if (!string.IsNullOrEmpty(FinishedProduct_BarCode))
  3739. {
  3740. DataRow[] drRepairSubsidy_RQualifiedNum = dsFinishedProduct.Tables[0].Select("SpecialRepairFlag=1 and GoodsLevelTypeID=5 and WagesTypeID=" + dtWagesType.Rows[ii]["WagesTypeID"] + " and barcode in(" + FinishedProduct_BarCode + ")");
  3741. if (drRepairSubsidy_RQualifiedNum.Length > 0)
  3742. {
  3743. RepairSubsidy_RQualifiedNum = drRepairSubsidy_RQualifiedNum.Length;
  3744. // 尽管有干补,但是有可能在损坯补贴给了,此处得查询一下干补补贴表,如果存在就不给此补贴
  3745. sqlString = "select 1 from TP_PAD_DamageSubsidy where Barcode=:Barcode and UserID=:UserID";
  3746. foreach (DataRow mm in drRepairSubsidy_RQualifiedNum)
  3747. {
  3748. parmeters1 = new OracleParameter[]
  3749. {
  3750. new OracleParameter(":Barcode",mm["barcode"].ToString()),
  3751. new OracleParameter(":UserID",dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString()),
  3752. };
  3753. dsTemp = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  3754. if (dsTemp.Tables[0].Rows.Count > 0)
  3755. {
  3756. RepairSubsidy_RQualifiedNum = RepairSubsidy_RQualifiedNum - 1;
  3757. }
  3758. }
  3759. }
  3760. }
  3761. // 查出此分类干补正负品补贴
  3762. // 求出损坯对应系数
  3763. DataRow[] drRepairSubsidy = dsWages.Tables[0].Select("WagesTypeID=" + dtWagesType.Rows[ii]["WagesTypeID"]);
  3764. decimal RSuperiorCoefficient = 0;//干补正品系数
  3765. decimal RQualifiedCoefficient = 0;//干补副品系数
  3766. decimal RepairSubsidyRate = 0;//干补补贴系数
  3767. decimal RepairStandardWages = 0;//标准工价
  3768. decimal RepairTotalCount = 0; //
  3769. decimal RepairSubsidy = 0;
  3770. temp_Repair = 0;
  3771. if (drRepairSubsidy.Length > 0)
  3772. {
  3773. RSuperiorCoefficient = Convert.ToDecimal(drRepairSubsidy[0]["RSuperiorCoefficient"]);
  3774. RQualifiedCoefficient = Convert.ToDecimal(drRepairSubsidy[0]["RQualifiedCoefficient"]);
  3775. RepairSubsidyRate = Convert.ToDecimal(drRepairSubsidy[0]["RepairSubsidyRate"]);
  3776. RepairStandardWages = Convert.ToDecimal(drRepairSubsidy[0]["RepairStandardWages"]);
  3777. RepairTotalCount = (RepairSubsidy_RQualifiedNum * RSuperiorCoefficient + RepairSubsidy_RQualifiedNum * RQualifiedCoefficient) * RepairStandardWages * RepairSubsidyRate;
  3778. totalcount_RepairSubsidy += RepairTotalCount / userstaffcount;
  3779. temp_Repair += RepairTotalCount;
  3780. }
  3781. #endregion
  3782. #region 插入干补补贴
  3783. sqlString = "select 1 from TP_PAR_RepairSubsidy where YYYYMM=:YYYYMM and StaffID=:StaffID and PayPlanID=:PayPlanID and WagesTypeID=:WagesTypeID";
  3784. parmeters1 = new OracleParameter[]
  3785. {
  3786. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  3787. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  3788. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  3789. new OracleParameter(":WagesTypeID",dtWagesType.Rows[ii]["WagesTypeID"]),
  3790. };
  3791. DataSet dsExistRepairSubsidy = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  3792. if (dsExistRepairSubsidy != null && dsExistRepairSubsidy.Tables[0].Rows.Count == 0)
  3793. {
  3794. sqlString = @"insert into TP_PAR_RepairSubsidy
  3795. (
  3796. YYYYMM,
  3797. StaffID,
  3798. PayPlanID,
  3799. WagesTypeID,
  3800. RSuperioNum,
  3801. RSuperiorCoefficient,
  3802. RQualifiedNum,
  3803. RQualifiedCoefficient,
  3804. StandardWages,
  3805. RepairSubsidyRate,
  3806. RepairSubsidy,
  3807. Amount,
  3808. PieceTacticsID
  3809. ) values
  3810. (
  3811. :YYYYMM,
  3812. :StaffID,
  3813. :PayPlanID,
  3814. :WagesTypeID,
  3815. :RSuperioNum,
  3816. :RSuperiorCoefficient,
  3817. :RQualifiedNum,
  3818. :RQualifiedCoefficient,
  3819. :StandardWages,
  3820. :RepairSubsidyRate,
  3821. :RepairSubsidy,
  3822. :Amount,
  3823. :PieceTacticsID
  3824. )";
  3825. }
  3826. else
  3827. {
  3828. sqlString = @"update TP_PAR_RepairSubsidy
  3829. set
  3830. YYYYMM=:YYYYMM,
  3831. StaffID=:StaffID,
  3832. PayPlanID=:PayPlanID,
  3833. WagesTypeID=:WagesTypeID,
  3834. RSuperioNum=RSuperioNum+:RSuperioNum,
  3835. RSuperiorCoefficient=RSuperiorCoefficient+:RSuperiorCoefficient,
  3836. RQualifiedNum=RQualifiedNum+:RQualifiedNum,
  3837. RQualifiedCoefficient=RQualifiedCoefficient+:RQualifiedCoefficient,
  3838. StandardWages=StandardWages+:StandardWages,
  3839. RepairSubsidyRate=RepairSubsidyRate+:RepairSubsidyRate,
  3840. RepairSubsidy=RepairSubsidy+:RepairSubsidy,
  3841. Amount=Amount+:Amount,
  3842. PieceTacticsID=:PieceTacticsID
  3843. where YYYYMM=:YYYYMM and StaffID=:StaffID and PayPlanID=:PayPlanID and WagesTypeID=:WagesTypeID
  3844. ";
  3845. }
  3846. parmeters1 = new OracleParameter[]
  3847. {
  3848. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  3849. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  3850. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  3851. new OracleParameter(":WagesTypeID",dtWagesType.Rows[ii]["WagesTypeID"]),
  3852. new OracleParameter(":RSuperioNum",RepairSubsidy_RSuperioNum),
  3853. new OracleParameter(":RSuperiorCoefficient",RSuperiorCoefficient),
  3854. new OracleParameter(":RQualifiedNum",RepairSubsidy_RQualifiedNum),
  3855. new OracleParameter(":RQualifiedCoefficient",RQualifiedCoefficient),
  3856. new OracleParameter(":StandardWages",RepairStandardWages),
  3857. new OracleParameter(":RepairSubsidyRate",RepairSubsidyRate),
  3858. new OracleParameter(":RepairSubsidy",RepairSubsidy),
  3859. new OracleParameter(":Amount",temp_Repair),
  3860. new OracleParameter(":PieceTacticsID",PieceTacticsID_Insert3),
  3861. };
  3862. intResult = oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  3863. #endregion
  3864. }
  3865. }
  3866. }
  3867. #endregion
  3868. decimal? totalcount_QualityASS = 0;// 品质工资
  3869. #region 品质考核策略
  3870. decimal min_TotalCount = 0; //dsQualityASS 已经是此工资策略的解决方案
  3871. for (int h = 0; h < dsQualityASS.Tables[0].Rows.Count; h++)
  3872. {
  3873. min_TotalCount = 0;
  3874. ////// // 求出缺陷数
  3875. ////// sqlString = @"select distinct TMP_PAM_ProductionData.barcode,TP_PAM_GoodsWagesType.WagesTypeID,TMP_PAM_Defect.goodsid,TMP_PAM_Defect.DefectFine,TMP_PAM_ProductionData.UserID from TMP_PAM_Defect
  3876. ////// inner join TP_PAM_GoodsWagesType
  3877. ////// on TMP_PAM_Defect.goodsID=TP_PAM_GoodsWagesType.goodsID
  3878. //////
  3879. ////// left join TMP_PAM_ProductionData on TMP_PAM_Defect.ProductionDataID=TMP_PAM_ProductionData.ProductionDataID
  3880. ////// and TMP_PAM_ProductionData.barcode in
  3881. ////// (
  3882. ////// select barcode from TP_PAT_QualityASS left join TP_PAT_Piecework on TP_PAT_QualityASS.PayPlanID=TP_PAT_Piecework.PayPlanID
  3883. ////// left join TP_PAT_PieceProcedure on TP_PAT_Piecework.PieceTacticsID=TP_PAT_PieceProcedure.PieceTacticsID and TP_PAT_PieceProcedure.ProcedureFlag=1
  3884. ////// left join TMP_PAM_ProductionData on TMP_PAM_ProductionData.ProcedureID=TP_PAT_PieceProcedure.ProcedureID
  3885. ////// where TP_PAT_QualityASS.QualityASSTacticsID=:QualityASSTacticsID
  3886. ////// )
  3887. ////// where TMP_PAM_Defect.DefectUserID=" + dsJobsPayPlan.Tables[0].Rows[j]["userID"]
  3888. ////// + " and TMP_PAM_Defect.DefectFine=" + dsQualityASS.Tables[0].Rows[h]["DefectFine"]
  3889. ////// + " and TMP_PAM_ProductionData.barcode in "
  3890. ////// + "("
  3891. ////// + " select barcode from TP_PAT_QualityASS left join TP_PAT_Piecework on TP_PAT_QualityASS.PayPlanID=TP_PAT_Piecework.PayPlanID"
  3892. ////// + " left join TP_PAT_PieceProcedure on TP_PAT_Piecework.PieceTacticsID=TP_PAT_PieceProcedure.PieceTacticsID and TP_PAT_PieceProcedure.ProcedureFlag=1"
  3893. ////// + " left join TMP_PAM_ProductionData on TMP_PAM_ProductionData.ProcedureID=TP_PAT_PieceProcedure.ProcedureID"
  3894. ////// + " where TMP_PAM_ProductionData.UserID=:UserID and TP_PAT_QualityASS.QualityASSTacticsID=:QualityASSTacticsID"
  3895. ////// + ")";
  3896. ////// parmeters1 = new OracleParameter[]
  3897. ////// {
  3898. ////// new OracleParameter(":QualityASSTacticsID",dsQualityASS.Tables[0].Rows[h]["QualityASSTacticsID"]),
  3899. ////// new OracleParameter(":UserID", dsJobsPayPlan.Tables[0].Rows[j]["userID"] ),
  3900. ////// //new OracleParameter(":QualityASSTacticsID", dsQualityASS.Tables[0].Rows[h]["QualityASSTacticsID"] ),
  3901. ////// };
  3902. ////// DataSet ds = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);//查询出有多少分类,进行计算
  3903. // modify wangx
  3904. // 求出缺陷数
  3905. //// sqlString = @"select distinct TMP_PAM_ProductionData.barcode,TP_PAM_GoodsWagesType.WagesTypeID,TMP_PAM_Defect.goodsid,TMP_PAM_Defect.DefectFine,TMP_PAM_ProductionData.UserID from TMP_PAM_Defect
  3906. //// inner join TP_PAM_GoodsWagesType
  3907. //// on TMP_PAM_Defect.goodsID=TP_PAM_GoodsWagesType.goodsID
  3908. ////
  3909. //// left join TMP_PAM_ProductionData on TMP_PAM_Defect.ProductionDataID=TMP_PAM_ProductionData.ProductionDataID
  3910. //// and TMP_PAM_ProductionData.barcode in
  3911. //// (
  3912. //// select barcode from TP_PAT_QualityASS left join TP_PAT_Piecework on TP_PAT_QualityASS.PayPlanID=TP_PAT_Piecework.PayPlanID
  3913. //// left join TP_PAT_PieceProcedure on TP_PAT_Piecework.PieceTacticsID=TP_PAT_PieceProcedure.PieceTacticsID and TP_PAT_PieceProcedure.ProcedureFlag=1
  3914. //// left join TMP_PAM_ProductionData on TMP_PAM_ProductionData.ProcedureID=TP_PAT_PieceProcedure.ProcedureID
  3915. //// where TP_PAT_QualityASS.QualityASSTacticsID=:QualityASSTacticsID
  3916. //// )
  3917. //// where TMP_PAM_Defect.DefectUserID=" + dsJobsPayPlan.Tables[0].Rows[j]["userID"]
  3918. //// + " and TMP_PAM_Defect.DefectFine=" + dsQualityASS.Tables[0].Rows[h]["DefectFine"]
  3919. //// + " and TMP_PAM_ProductionData.barcode in "
  3920. //// + "("
  3921. //// + " select barcode from TP_PAT_QualityASS left join TP_PAT_Piecework on TP_PAT_QualityASS.PayPlanID=TP_PAT_Piecework.PayPlanID"
  3922. //// + " left join TP_PAT_PieceProcedure on TP_PAT_Piecework.PieceTacticsID=TP_PAT_PieceProcedure.PieceTacticsID and TP_PAT_PieceProcedure.ProcedureFlag=1"
  3923. //// + " left join TMP_PAM_ProductionData on TMP_PAM_ProductionData.ProcedureID=TP_PAT_PieceProcedure.ProcedureID"
  3924. //// + " where TMP_PAM_ProductionData.UserID=:UserID and TP_PAT_QualityASS.QualityASSTacticsID=:QualityASSTacticsID"
  3925. //// + ")";
  3926. //// parmeters1 = new OracleParameter[]
  3927. //// {
  3928. //// new OracleParameter(":QualityASSTacticsID",dsQualityASS.Tables[0].Rows[h]["QualityASSTacticsID"]),
  3929. //// new OracleParameter(":UserID", dsJobsPayPlan.Tables[0].Rows[j]["userID"] ),
  3930. //// //new OracleParameter(":QualityASSTacticsID", dsQualityASS.Tables[0].Rows[h]["QualityASSTacticsID"] ),
  3931. //// };
  3932. //// DataSet ds = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);//查询出有多少分类,进行计算
  3933. // 1查出此品质工资方案对应的计件工序与品质工序集
  3934. sqlString = @"select distinct TP_PAT_PieceProcedure.ProcedureID,TP_PAT_PieceProcedure.Procedureflag
  3935. from TP_PAT_QualityASS
  3936. inner join TP_PAT_Piecework on TP_PAT_QualityASS.PayPlanID =
  3937. TP_PAT_Piecework.PayPlanID
  3938. inner join TP_PAT_PieceProcedure on TP_PAT_Piecework.PieceTacticsID =
  3939. TP_PAT_PieceProcedure.PieceTacticsID
  3940. where TP_PAT_QualityASS.QualityASSTacticsID=:QualityASSTacticsID";
  3941. parmeters1 = new OracleParameter[]
  3942. {
  3943. new OracleParameter(":QualityASSTacticsID",dsQualityASS.Tables[0].Rows[h]["QualityASSTacticsID"]),
  3944. };
  3945. string jisian_ids = "";
  3946. string pinzhi_ids = "";
  3947. DataSet dsjieguo = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  3948. if (dsjieguo != null && dsjieguo.Tables[0].Rows.Count > 0)
  3949. {
  3950. foreach (DataRow r10 in dsjieguo.Tables[0].Rows)
  3951. {
  3952. if (r10["Procedureflag"].ToString() == "1")
  3953. {
  3954. jisian_ids = jisian_ids + r10["ProcedureID"].ToString() + ",";
  3955. }
  3956. else if (r10["Procedureflag"].ToString() == "2")
  3957. {
  3958. pinzhi_ids = pinzhi_ids + r10["ProcedureID"].ToString() + ",";
  3959. }
  3960. }
  3961. jisian_ids = jisian_ids.Trim(',');
  3962. pinzhi_ids = pinzhi_ids.Trim(',');
  3963. }
  3964. DataRow[] r12 = ds_w.Tables[0].Select("DefectUserID=" + dsJobsPayPlan.Tables[0].Rows[j]["userID"] + " and DefectFine=" + dsQualityASS.Tables[0].Rows[h]["DefectFine"]);
  3965. ds = new DataSet();
  3966. if (r12.Length > 0)
  3967. {
  3968. string deletebarcode = "";
  3969. foreach (DataRow r15 in r12)
  3970. {
  3971. r17 = dsTMPProductionData.Tables[0].Select("barcode =" + r15["barcode"] + " " + " and ( ProcedureID in(" + pinzhi_ids + "))");
  3972. r18 = dsTMPProductionData.Tables[0].Select("barcode =" + r15["barcode"] + " " + " and ( ProcedureID in(" + jisian_ids + ")) and userID=" + dsJobsPayPlan.Tables[0].Rows[j]["userID"]);
  3973. if (r17.Length == 0 || r18.Length == 0)
  3974. {
  3975. deletebarcode = deletebarcode + r15["barcode"].ToString() + ",";
  3976. }
  3977. }
  3978. deletebarcode = deletebarcode.Trim(',');
  3979. if (deletebarcode == "")
  3980. {
  3981. deletebarcode = "0";
  3982. }
  3983. r12 = ds_w.Tables[0].Select("DefectUserID=" + dsJobsPayPlan.Tables[0].Rows[j]["userID"] + " and DefectFine=" + dsQualityASS.Tables[0].Rows[h]["DefectFine"] + " and barcode not in(" + deletebarcode + ")");
  3984. if (r12.Length > 0)
  3985. ds.Tables.Add(r12.CopyToDataTable().Copy());
  3986. }
  3987. // DataRow[] r12 = ds_w.Tables[0].Select("DefectUserID=" + dsJobsPayPlan.Tables[0].Rows[j]["userID"] + " and DefectFine=" + dsQualityASS.Tables[0].Rows[h]["DefectFine"] + " and ProcedureID in(" + pinzhi_ids + ") and ( ProcedureID in(" + jisian_ids + ")" + " and userID=" + dsJobsPayPlan.Tables[0].Rows[j]["userID"] + ")");
  3988. //DataSet ds = new DataSet();
  3989. //if (r12.Length > 0)
  3990. //{
  3991. // ds.Tables.Add(r12.CopyToDataTable().Copy());
  3992. //}
  3993. string barcodes_Procedure = "";
  3994. int drCount_Total = 0;
  3995. for (int p1 = 0; p1 < dsPieceProcedure_2.Tables[0].Rows.Count; p1++)
  3996. {
  3997. drQualityBaseProcedure = dsTMPProductionData.Tables[0]
  3998. .Select(string.Format("ProcedureID={0}", dsPieceProcedure_2.Tables[0].Rows[p1]["ProcedureID"]));
  3999. if (drQualityBaseProcedure.Length > 0)
  4000. {
  4001. foreach (DataRow r4 in drQualityBaseProcedure)
  4002. {
  4003. rr6 = dsTMPProductionData.Tables[0].Select("barcode='" + r4["barcode"] + "' and userid=" + dsJobsPayPlan.Tables[0].Rows[j]["userID"]);
  4004. if (rr6.Length > 0)
  4005. {
  4006. if (!barcodes_Procedure.Contains(r4["barcode"].ToString()))
  4007. {
  4008. drCount_Total += 1; // 质量工序数量
  4009. }
  4010. barcodes_Procedure = barcodes_Procedure + r4["barcode"].ToString() + ",";
  4011. }
  4012. }
  4013. }
  4014. }
  4015. //if (ds != null && ds.Tables[0].Rows.Count > 0)
  4016. if (ds != null && ds.Tables.Count > 0)
  4017. {
  4018. // 此工号有对应的缺陷扣罚
  4019. DataTable dt2 = ds.Tables[0].DefaultView.ToTable(true, "WagesTypeID");//有多少行,就有多少分类
  4020. for (int p = 0; p < dt2.Rows.Count; p++)
  4021. {
  4022. decimal temp_QualityReward = 0;
  4023. // 读取质量基数工序
  4024. // 缺陷数量
  4025. drDefect = ds.Tables[0].Select("DefectFine=" + dsQualityASS.Tables[0].Rows[h]["DefectFine"] + " and WagesTypeID=" + dt2.Rows[p]["WagesTypeID"]);
  4026. // temp 为品质率,真正的价格在区间取
  4027. decimal temp = 0;
  4028. if (drCount_Total != 0)
  4029. {
  4030. //temp = Convert.ToDecimal(dsQualityASS.Tables[0].Rows[h]["DictionaryValue"]) * drDefect.Length / drCount_Total;
  4031. temp = Convert.ToDecimal(drDefect.Length) / Convert.ToDecimal(drCount_Total);
  4032. }
  4033. // 查出对应分类品质奖励
  4034. sqlString = "select QualityReward,QualityRate from TP_PAT_QualityReward where WagesTypeID=" + dt2.Rows[p]["WagesTypeID"] + " and QualityRate<=" + temp + " and QualityASSTacticsID=" + dsQualityASS.Tables[0].Rows[h]["QualityASSTacticsID"] + " order by QualityRate desc";
  4035. DataSet dsQualityReward_Temp = oracleTrConn.GetSqlResultToDs(sqlString);
  4036. decimal QualityRate = 0;
  4037. if (dsQualityReward_Temp != null && dsQualityReward_Temp.Tables[0].Rows.Count > 0)
  4038. {
  4039. //表示有对应的品质价格,结果集如有多个,取第一个对应的金额即可
  4040. min_TotalCount = Convert.ToDecimal(dsQualityReward_Temp.Tables[0].Rows[0]["QualityReward"]);
  4041. temp_QualityReward = Convert.ToDecimal(dsQualityReward_Temp.Tables[0].Rows[0]["QualityReward"]);//品质奖励金额
  4042. QualityRate = Convert.ToDecimal(dsQualityReward_Temp.Tables[0].Rows[0]["QualityRate"]);
  4043. }
  4044. #region 插入品质考核
  4045. sqlString = @"select 1 from TP_PAR_QualityASS where YYYYMM=:YYYYMM and StaffID=:StaffID
  4046. and PayPlanID=:PayPlanID and WagesTypeID=:WagesTypeID and DefectFine=:DefectFine";
  4047. parmeters1 = new OracleParameter[]
  4048. {
  4049. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  4050. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  4051. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  4052. new OracleParameter(":WagesTypeID",dt2.Rows[p]["WagesTypeID"]),
  4053. new OracleParameter(":DefectFine",dsQualityASS.Tables[0].Rows[h]["DefectFine"]),
  4054. };
  4055. DataSet dsExistDefectFine = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  4056. if (dsExistDefectFine != null && dsExistDefectFine.Tables[0].Rows.Count == 0)
  4057. {
  4058. sqlString = @"insert into TP_PAR_QualityASS
  4059. (
  4060. YYYYMM,
  4061. StaffID,
  4062. PayPlanID,
  4063. WagesTypeID,
  4064. DefectFine,
  4065. DefectNum,
  4066. QualityBaseNum,
  4067. QualityRate,
  4068. Amount,
  4069. QualityASSTacticsID
  4070. ) values
  4071. (
  4072. :YYYYMM,
  4073. :StaffID,
  4074. :PayPlanID,
  4075. :WagesTypeID,
  4076. :DefectFine,
  4077. :DefectNum,
  4078. :QualityBaseNum,
  4079. :QualityRate,
  4080. :Amount,
  4081. :QualityASSTacticsID
  4082. )";
  4083. parmeters1 = new OracleParameter[]
  4084. {
  4085. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  4086. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  4087. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  4088. new OracleParameter(":WagesTypeID",dt2.Rows[p]["WagesTypeID"]),
  4089. new OracleParameter(":DefectFine",dsQualityASS.Tables[0].Rows[h]["DefectFine"]),
  4090. new OracleParameter(":DefectNum",drDefect.Length),
  4091. new OracleParameter(":QualityBaseNum",drCount_Total),
  4092. new OracleParameter(":QualityRate",temp),
  4093. new OracleParameter(":Amount",min_TotalCount),
  4094. new OracleParameter(":QualityASSTacticsID",PieceTacticsID_Insert4),
  4095. };
  4096. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  4097. }
  4098. #endregion
  4099. }
  4100. }
  4101. else
  4102. {
  4103. //此工号没有缺陷扣罚
  4104. decimal temp_QualityReward = 0;
  4105. //int drCount_Total = 0;
  4106. //string QualityProcedureIDS = "";
  4107. //DataRow[] drCount = null;
  4108. //////// sqlString = @"select distinct TMP_PAM_ProductionData.barcode,TP_PAM_GoodsWagesType.WagesTypeID,TMP_PAM_Defect.goodsid,TMP_PAM_Defect.DefectFine,TMP_PAM_ProductionData.UserID from TMP_PAM_Defect
  4109. //////// inner join TP_PAM_GoodsWagesType
  4110. //////// on TMP_PAM_Defect.goodsID=TP_PAM_GoodsWagesType.goodsID
  4111. ////////
  4112. //////// left join TMP_PAM_ProductionData on TMP_PAM_Defect.ProductionDataID=TMP_PAM_ProductionData.ProductionDataID
  4113. //////// and TMP_PAM_ProductionData.barcode in
  4114. //////// (
  4115. //////// select barcode from TP_PAT_QualityASS left join TP_PAT_Piecework on TP_PAT_QualityASS.PayPlanID=TP_PAT_Piecework.PayPlanID
  4116. //////// left join TP_PAT_PieceProcedure on TP_PAT_Piecework.PieceTacticsID=TP_PAT_PieceProcedure.PieceTacticsID and TP_PAT_PieceProcedure.ProcedureFlag=1
  4117. //////// left join TMP_PAM_ProductionData on TMP_PAM_ProductionData.ProcedureID=TP_PAT_PieceProcedure.ProcedureID
  4118. //////// where TP_PAT_QualityASS.QualityASSTacticsID=:QualityASSTacticsID
  4119. //////// )
  4120. //////// where TMP_PAM_Defect.DefectUserID=" + dsJobsPayPlan.Tables[0].Rows[j]["userID"]
  4121. //////// // + " and TMP_PAM_Defect.DefectFine=" + dsQualityASS.Tables[0].Rows[h]["DefectFine"]
  4122. //////// + " and TMP_PAM_ProductionData.barcode in "
  4123. //////// + "("
  4124. //////// + " select barcode from TP_PAT_QualityASS left join TP_PAT_Piecework on TP_PAT_QualityASS.PayPlanID=TP_PAT_Piecework.PayPlanID"
  4125. //////// + " left join TP_PAT_PieceProcedure on TP_PAT_Piecework.PieceTacticsID=TP_PAT_PieceProcedure.PieceTacticsID and TP_PAT_PieceProcedure.ProcedureFlag=1"
  4126. //////// + " left join TMP_PAM_ProductionData on TMP_PAM_ProductionData.ProcedureID=TP_PAT_PieceProcedure.ProcedureID"
  4127. //////// + " where TMP_PAM_ProductionData.UserID=:UserID and TP_PAT_QualityASS.QualityASSTacticsID=:QualityASSTacticsID"
  4128. //////// + ")";
  4129. //////// parmeters1 = new OracleParameter[]
  4130. //////// {
  4131. //////// new OracleParameter(":QualityASSTacticsID",dsQualityASS.Tables[0].Rows[h]["QualityASSTacticsID"]),
  4132. //////// new OracleParameter(":UserID", dsJobsPayPlan.Tables[0].Rows[j]["userID"] ),
  4133. //////// //new OracleParameter(":QualityASSTacticsID", dsQualityASS.Tables[0].Rows[h]["QualityASSTacticsID"] ),
  4134. //////// };
  4135. //////// DataSet ds7 = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  4136. // 1查出此品质工资方案对应的计件工序与品质工序集
  4137. sqlString = @"select distinct TP_PAT_PieceProcedure.ProcedureID,TP_PAT_PieceProcedure.Procedureflag
  4138. from TP_PAT_QualityASS
  4139. inner join TP_PAT_Piecework on TP_PAT_QualityASS.PayPlanID =
  4140. TP_PAT_Piecework.PayPlanID
  4141. inner join TP_PAT_PieceProcedure on TP_PAT_Piecework.PieceTacticsID =
  4142. TP_PAT_PieceProcedure.PieceTacticsID
  4143. where TP_PAT_QualityASS.QualityASSTacticsID=:QualityASSTacticsID";
  4144. parmeters1 = new OracleParameter[]
  4145. {
  4146. new OracleParameter(":QualityASSTacticsID",dsQualityASS.Tables[0].Rows[h]["QualityASSTacticsID"]),
  4147. };
  4148. string jisian_ids_1 = "";
  4149. string pinzhi_ids_1 = "";
  4150. DataSet dsjieguo_1 = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  4151. if (dsjieguo_1 != null && dsjieguo_1.Tables[0].Rows.Count > 0)
  4152. {
  4153. foreach (DataRow r10 in dsjieguo_1.Tables[0].Rows)
  4154. {
  4155. if (r10["Procedureflag"].ToString() == "1")
  4156. {
  4157. jisian_ids_1 = jisian_ids_1 + r10["ProcedureID"].ToString() + ",";
  4158. }
  4159. else if (r10["Procedureflag"].ToString() == "2")
  4160. {
  4161. pinzhi_ids_1 = pinzhi_ids_1 + r10["ProcedureID"].ToString() + ",";
  4162. }
  4163. }
  4164. jisian_ids_1 = jisian_ids_1.Trim(',');
  4165. pinzhi_ids_1 = pinzhi_ids_1.Trim(',');
  4166. }
  4167. //DataRow[] r13 = ds_w.Tables[0].Select("DefectUserID=" + dsJobsPayPlan.Tables[0].Rows[j]["userID"] + " and ProcedureID in(" + pinzhi_ids_1 + ") and ( ProcedureID in(" + jisian_ids_1 + ")" + ")");//nd userID=" + dsJobsPayPlan.Tables[0].Rows[j]["userID"] +
  4168. DataRow[] r13 = ds_w.Tables[0].Select("DefectUserID=" + dsJobsPayPlan.Tables[0].Rows[j]["userID"]);
  4169. DataSet ds7 = new DataSet();
  4170. if (r13.Length > 0)
  4171. {
  4172. string deletebarcode = "";
  4173. foreach (DataRow r15 in r13)
  4174. {
  4175. r17 = dsTMPProductionData.Tables[0].Select("barcode =" + r15["barcode"] + " " + " and ( ProcedureID in(" + pinzhi_ids_1 + "))");
  4176. r18 = dsTMPProductionData.Tables[0].Select("barcode =" + r15["barcode"] + " " + " and ( ProcedureID in(" + jisian_ids_1 + ")) and userID=" + dsJobsPayPlan.Tables[0].Rows[j]["userID"]);
  4177. if (r17.Length == 0 || r18.Length == 0)
  4178. {
  4179. deletebarcode = deletebarcode + r15["barcode"].ToString() + ",";
  4180. //ds_w.Tables[0].AcceptChanges();
  4181. }
  4182. }
  4183. deletebarcode = deletebarcode.Trim(',');
  4184. if (deletebarcode == "")
  4185. {
  4186. deletebarcode = "0";
  4187. }
  4188. r13 = ds_w.Tables[0].Select("DefectUserID=" + dsJobsPayPlan.Tables[0].Rows[j]["userID"] + " and barcode not in(" + deletebarcode + ")");
  4189. if (r13.Length > 0)
  4190. ds7.Tables.Add(r13.CopyToDataTable().Copy());
  4191. }
  4192. //drCount_Total = ds7.Tables[0].Rows.Count;
  4193. //
  4194. //for (int yy = 0; yy < dsQualityProcedure.Tables[0].Rows.Count; yy++)
  4195. //{
  4196. // //drCount = dsTMPProductionData.Tables[0].Select("ProcedureID=" + dsQualityProcedure.Tables[0].Rows[yy]["ProcedureID"] + " and userID=" + dsJobsPayPlan.Tables[0].Rows[j]["userID"]);
  4197. // //QualityProcedureIDS += dsQualityProcedure.Tables[0].Rows[yy]["ProcedureID"].ToString() + ",";
  4198. // drCount_Total += drCount.Length;
  4199. //}
  4200. //QualityProcedureIDS = QualityProcedureIDS.Trim(',');
  4201. //drCount = dsTMPProductionData.Tables[0].Select("ProcedureID in (" + QualityProcedureIDS + ") and userID=" + dsJobsPayPlan.Tables[0].Rows[j]["userID"]);//有多少行,就有多少分类
  4202. //if (drCount.Length > 0)
  4203. //{
  4204. if (ds7 != null && ds7.Tables.Count > 0)
  4205. {
  4206. DataTable dt2 = ds7.Tables[0].DefaultView.ToTable(true, "WagesTypeID");//有多少行,就有多少分类
  4207. for (int p = 0; p < dt2.Rows.Count; p++)
  4208. {
  4209. // 读取质量基数工序
  4210. // 缺陷数量
  4211. drDefect = ds7.Tables[0].Select("DefectFine=" + dsQualityASS.Tables[0].Rows[h]["DefectFine"] + " and WagesTypeID=" + dt2.Rows[p]["WagesTypeID"]);
  4212. // temp 为品质率,真正的价格在区间取
  4213. decimal temp = 0 / drCount_Total;
  4214. // 查出对应分类品质奖励
  4215. sqlString = "select QualityReward,QualityRate from TP_PAT_QualityReward where WagesTypeID=" + dt2.Rows[p]["WagesTypeID"] + " and QualityRate<=" + temp + " and QualityASSTacticsID=" + dsQualityASS.Tables[0].Rows[h]["QualityASSTacticsID"] + " order by QualityRate";
  4216. DataSet dsQualityReward_Temp = oracleTrConn.GetSqlResultToDs(sqlString);
  4217. decimal QualityRate = 0;
  4218. if (dsQualityReward_Temp != null && dsQualityReward_Temp.Tables[0].Rows.Count > 0)
  4219. {
  4220. //表示有对应的品质价格,结果集如有多个,取第一个对应的金额即可
  4221. min_TotalCount = Convert.ToDecimal(dsQualityReward_Temp.Tables[0].Rows[0]["QualityReward"]);
  4222. temp_QualityReward = Convert.ToDecimal(dsQualityReward_Temp.Tables[0].Rows[0]["QualityReward"]);//品质奖励金额
  4223. QualityRate = Convert.ToDecimal(dsQualityReward_Temp.Tables[0].Rows[0]["QualityRate"]);
  4224. }
  4225. //// 读取计件工资策略
  4226. //int PieceTacticsID_Insert4 = 0;
  4227. //sqlString = "select QualityASSTacticsID from TP_PAT_QualityASS where PayPlanID=:PayPlanID";
  4228. //parmeters1 = new OracleParameter[]
  4229. //{
  4230. // new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  4231. //};
  4232. //DataSet dss3 = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  4233. //if (dss3 != null && dss3.Tables[0].Rows.Count > 0)
  4234. //{
  4235. // PieceTacticsID_Insert4 = Convert.ToInt32(dss3.Tables[0].Rows[0]["QualityASSTacticsID"]);
  4236. //}
  4237. #region 插入品质考核
  4238. sqlString = @"select 1 from TP_PAR_QualityASS where YYYYMM=:YYYYMM and StaffID=:StaffID
  4239. and PayPlanID=:PayPlanID and WagesTypeID=:WagesTypeID and DefectFine=:DefectFine";
  4240. parmeters1 = new OracleParameter[]
  4241. {
  4242. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  4243. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  4244. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  4245. new OracleParameter(":WagesTypeID",dt2.Rows[p]["WagesTypeID"]),
  4246. new OracleParameter(":DefectFine",dsQualityASS.Tables[0].Rows[h]["DefectFine"]),
  4247. };
  4248. DataSet dsExistDefectFine = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  4249. if (dsExistDefectFine != null && dsExistDefectFine.Tables[0].Rows.Count == 0)
  4250. {
  4251. sqlString = @"insert into TP_PAR_QualityASS
  4252. (
  4253. YYYYMM,
  4254. StaffID,
  4255. PayPlanID,
  4256. WagesTypeID,
  4257. DefectFine,
  4258. DefectNum,
  4259. QualityBaseNum,
  4260. QualityRate,
  4261. Amount,
  4262. QualityASSTacticsID
  4263. ) values
  4264. (
  4265. :YYYYMM,
  4266. :StaffID,
  4267. :PayPlanID,
  4268. :WagesTypeID,
  4269. :DefectFine,
  4270. :DefectNum,
  4271. :QualityBaseNum,
  4272. :QualityRate,
  4273. :Amount,
  4274. :QualityASSTacticsID
  4275. )";
  4276. parmeters1 = new OracleParameter[]
  4277. {
  4278. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  4279. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  4280. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  4281. new OracleParameter(":WagesTypeID",dt2.Rows[p]["WagesTypeID"]),
  4282. new OracleParameter(":DefectFine",dsQualityASS.Tables[0].Rows[h]["DefectFine"]),
  4283. new OracleParameter(":DefectNum",drDefect.Length),
  4284. new OracleParameter(":QualityBaseNum",drCount_Total),
  4285. new OracleParameter(":QualityRate",temp),
  4286. new OracleParameter(":Amount",min_TotalCount),
  4287. new OracleParameter(":QualityASSTacticsID",PieceTacticsID_Insert4),
  4288. };
  4289. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  4290. }
  4291. #endregion
  4292. }// for 外层循环
  4293. }
  4294. // }
  4295. }
  4296. // modify wangx end
  4297. totalcount_QualityASS += min_TotalCount;
  4298. }
  4299. #endregion
  4300. decimal? totalcount_AdminEXA = 0;// 行政工资
  4301. #region 行政考核
  4302. //sqlString = "select Amount from TP_PAD_AdminEXA where SettlementFlag=0 and StaffID=:StaffID and AuditStatus=1 and AuditlDate >=:dateStartTime and AuditlDate<=:dateEndTime";//
  4303. sqlString = "select Amount from TP_PAD_AdminEXA where StaffID=:StaffID and AuditStatus=1 and AuditlDate >=:dateStartTime and AuditlDate<=:dateEndTime";//
  4304. parmeters1 = new OracleParameter[]
  4305. {
  4306. //new OracleParameter(":UserID",dsJobsPayPlan.Tables[0].Rows[i]["UserID"]),
  4307. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  4308. new OracleParameter(":dateStartTime",dateStartTime),
  4309. new OracleParameter(":dateEndTime",dateEndTime),
  4310. };
  4311. DataSet dsAdminEXA = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  4312. if (dsAdminEXA != null && dsAdminEXA.Tables[0].Rows.Count > 0)
  4313. {
  4314. for (int y = 0; y < dsAdminEXA.Tables[0].Rows.Count; y++)
  4315. {
  4316. totalcount_AdminEXA += Convert.ToDecimal(dsAdminEXA.Tables[0].Rows[y]["Amount"]);
  4317. }
  4318. sqlString = "update TP_PAD_AdminEXA set SettlementFlag=1 where SettlementFlag=0 and StaffID=:StaffID and AuditStatus=1 and AuditlDate >=:dateStartTime and AuditlDate<=:dateEndTime";
  4319. parmeters1 = new OracleParameter[]
  4320. {
  4321. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  4322. new OracleParameter(":dateStartTime",dateStartTime),
  4323. new OracleParameter(":dateEndTime",dateEndTime),
  4324. };
  4325. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  4326. }
  4327. #endregion
  4328. #region 插入工资单
  4329. // 防止一个员工在多个工号下面
  4330. sqlString = "select 1 from TP_PAR_Payroll where YYYYMM=:YYYYMM and StaffID=:StaffID ";
  4331. parmeters1 = new OracleParameter[]
  4332. {
  4333. new OracleParameter(":YYYYMM",OracleDbType.Varchar2,(Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),ParameterDirection.Input),
  4334. new OracleParameter(":StaffID",OracleDbType.Int32,dsJobsPayPlan.Tables[0].Rows[j]["StaffID"],ParameterDirection.Input),
  4335. };
  4336. DataSet ds4 = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  4337. if (ds4 != null && ds4.Tables[0].Rows.Count == 0)
  4338. {
  4339. sqlString = @"insert into TP_PAR_Payroll
  4340. (
  4341. YYYYMM,
  4342. StaffID,
  4343. Piecework,
  4344. DamageSubsidy,
  4345. RepairSubsidy,
  4346. QualityEXA,
  4347. AdminEXA,
  4348. ADAmount,
  4349. TotalAmount,
  4350. AuditStatus,
  4351. AccountID,
  4352. CreateUserID,
  4353. UpdateUserID
  4354. ) values
  4355. (
  4356. :YYYYMM,
  4357. :StaffID,
  4358. :Piecework,
  4359. :DamageSubsidy,
  4360. :RepairSubsidy,
  4361. :QualityEXA,
  4362. :AdminEXA,
  4363. :ADAmount,
  4364. :TotalAmount,
  4365. :AuditStatus,
  4366. :AccountID,
  4367. :CreateUserID,
  4368. :UpdateUserID
  4369. )";
  4370. decimal? a = (totalcount_Piecegiework + totalcount_Scrap + totalcount_RepairSubsidy + totalcount_QualityASS / userstaffcount + totalcount_AdminEXA);
  4371. parmeters1 = new OracleParameter[]
  4372. {
  4373. new OracleParameter(":YYYYMM",OracleDbType.Varchar2,(Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),ParameterDirection.Input),
  4374. new OracleParameter(":StaffID",OracleDbType.Int32,dsJobsPayPlan.Tables[0].Rows[j]["StaffID"],ParameterDirection.Input),
  4375. //new OracleParameter(":PayPlanID",OracleDbType.Int32,dsPayPlan.Tables[0].Rows[i]["PayPlanID"],ParameterDirection.Input),
  4376. new OracleParameter(":Piecework",OracleDbType.Decimal,totalcount_Piecegiework,ParameterDirection.Input),
  4377. new OracleParameter(":DamageSubsidy",OracleDbType.Decimal,totalcount_Scrap,ParameterDirection.Input),
  4378. new OracleParameter(":RepairSubsidy",OracleDbType.Decimal,totalcount_RepairSubsidy,ParameterDirection.Input),
  4379. new OracleParameter(":QualityEXA",OracleDbType.Decimal,totalcount_QualityASS/userstaffcount,ParameterDirection.Input),
  4380. new OracleParameter(":AdminEXA",OracleDbType.Decimal,totalcount_AdminEXA,ParameterDirection.Input),
  4381. new OracleParameter(":ADAmount",OracleDbType.Decimal,0,ParameterDirection.Input),
  4382. new OracleParameter(":TotalAmount",OracleDbType.Decimal,a,ParameterDirection.Input),
  4383. new OracleParameter(":CreateUserID",OracleDbType.Int32,sUserInfo.UserID,ParameterDirection.Input),
  4384. new OracleParameter(":UpdateUserID",OracleDbType.Int32,sUserInfo.UserID,ParameterDirection.Input),
  4385. new OracleParameter(":AccountID",OracleDbType.Int32,sUserInfo.AccountID,ParameterDirection.Input),
  4386. new OracleParameter(":AuditStatus",OracleDbType.Int32,0,ParameterDirection.Input),
  4387. };
  4388. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  4389. }
  4390. else
  4391. {
  4392. sqlString = @"update TP_PAR_Payroll
  4393. set Piecework=Piecework+:Piecework,
  4394. DamageSubsidy=DamageSubsidy+:DamageSubsidy,
  4395. RepairSubsidy=RepairSubsidy+:RepairSubsidy,
  4396. QualityEXA=QualityEXA+:QualityEXA,
  4397. AdminEXA=AdminEXA+:AdminEXA,
  4398. ADAmount=AdminEXA+:ADAmount,
  4399. TotalAmount=TotalAmount+:TotalAmount
  4400. where YYYYMM=:YYYYMM and StaffID=:StaffID
  4401. ";
  4402. decimal? a = (totalcount_Piecegiework + totalcount_Scrap + totalcount_RepairSubsidy + totalcount_QualityASS + totalcount_AdminEXA);
  4403. parmeters1 = new OracleParameter[]
  4404. {
  4405. new OracleParameter(":YYYYMM",OracleDbType.Varchar2,(Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),ParameterDirection.Input),
  4406. new OracleParameter(":StaffID",OracleDbType.Int32,dsJobsPayPlan.Tables[0].Rows[j]["StaffID"],ParameterDirection.Input),
  4407. //new OracleParameter(":PayPlanID",OracleDbType.Int32,dsPayPlan.Tables[0].Rows[i]["PayPlanID"],ParameterDirection.Input),
  4408. new OracleParameter(":Piecework",OracleDbType.Decimal,totalcount_Piecegiework,ParameterDirection.Input),
  4409. new OracleParameter(":DamageSubsidy",OracleDbType.Decimal,totalcount_Scrap,ParameterDirection.Input),
  4410. new OracleParameter(":RepairSubsidy",OracleDbType.Decimal,totalcount_RepairSubsidy,ParameterDirection.Input),
  4411. new OracleParameter(":QualityEXA",OracleDbType.Decimal,totalcount_QualityASS,ParameterDirection.Input),
  4412. new OracleParameter(":AdminEXA",OracleDbType.Decimal,totalcount_AdminEXA,ParameterDirection.Input),
  4413. new OracleParameter(":ADAmount",OracleDbType.Decimal,0,ParameterDirection.Input),
  4414. new OracleParameter(":TotalAmount",OracleDbType.Decimal,a,ParameterDirection.Input),
  4415. };
  4416. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  4417. }
  4418. #endregion
  4419. #region 删除临时数据表(工号)
  4420. DataRow[] drDeleteUserID = dsTMPProductionData.Tables[0]
  4421. .Select(string.Format("UserID={0} and ProcedureID in({1})", dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString(), ProcedureIDS_Delete));
  4422. //int aaaa = dsTMPProductionData.Tables[0].Rows.Count;
  4423. foreach (DataRow r in drDeleteUserID)
  4424. {
  4425. r.Delete();
  4426. //dsTMPProductionData.Tables[0].Rows.Remove(r);
  4427. }
  4428. dsTMPProductionData.Tables[0].AcceptChanges();
  4429. //int aaaaaa = dsTMPProductionData.Tables[0].Rows.Count;
  4430. #endregion
  4431. }
  4432. if (intResult > 0)
  4433. {
  4434. sqlString = @"insert into TP_PAR_PayrollAccount
  4435. (
  4436. YYYYMM,
  4437. BeginDate,
  4438. EndDate,
  4439. AccountID,
  4440. CreateUserID
  4441. ) values
  4442. (
  4443. :YYYYMM,
  4444. :BeginDate,
  4445. :EndDate,
  4446. :AccountID,
  4447. :CreateUserID
  4448. )";
  4449. parmeters1 = new OracleParameter[]
  4450. {
  4451. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  4452. new OracleParameter(":BeginDate",dateStartTime),
  4453. new OracleParameter(":EndDate",dateEndTime),
  4454. new OracleParameter(":AccountID",sUserInfo.AccountID),
  4455. new OracleParameter(":CreateUserID",sUserInfo.UserID),
  4456. };
  4457. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  4458. // 更新系统结算月
  4459. sqlString = "update TP_MST_SystemDate set datevalue=sysdate where systemdatetype=2";
  4460. intResult += oracleTrConn.ExecuteNonQuery(sqlString);
  4461. sqlString = "update TP_MST_SystemDate set datevalue=:datevalue where systemdatetype=5";
  4462. parmeters1 = new OracleParameter[]
  4463. {
  4464. new OracleParameter(":datevalue",dateEndTime),
  4465. };
  4466. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  4467. oracleTrConn.Commit();
  4468. oracleTrConn.Disconnect();
  4469. }
  4470. else
  4471. {
  4472. oracleTrConn.Rollback();
  4473. oracleTrConn.Disconnect();
  4474. }
  4475. }
  4476. }
  4477. return intResult;
  4478. }
  4479. catch (Exception ex)
  4480. {
  4481. if (oracleTrConn.ConnState == ConnectionState.Open)
  4482. {
  4483. oracleTrConn.Rollback();
  4484. oracleTrConn.Disconnect();
  4485. }
  4486. throw ex;
  4487. }
  4488. finally
  4489. {
  4490. if (oracleTrConn.ConnState == ConnectionState.Open)
  4491. {
  4492. oracleTrConn.Rollback();
  4493. oracleTrConn.Disconnect();
  4494. }
  4495. }
  4496. }
  4497. #endregion
  4498. #region 工资结算历史记录查询
  4499. /// <summary>
  4500. /// 获取工资结算历史记录
  4501. /// </summary>
  4502. /// <param name="YYYYMM"></param>
  4503. /// <param name="sUserInfo"></param>
  4504. /// <returns></returns>
  4505. public static DataSet GetPayroll(string YYYYMM, SUserInfo sUserInfo)
  4506. {
  4507. IDBConnection con = ClsDbFactory.CreateDBConnection(DataBaseType.ORACLE, DataManager.ConnectionString);
  4508. try
  4509. {
  4510. con.Open();
  4511. string sqlString = @"select
  4512. 0 as Sel,
  4513. TP_PAR_Payroll.Yyyymm,
  4514. TP_HR_Staff.StaffName,
  4515. TP_HR_Staff.StaffCode,
  4516. TP_PAR_Payroll.StaffID,
  4517. TP_PAR_Payroll.Piecework,
  4518. TP_PAR_Payroll.DamageSubsidy,
  4519. TP_PAR_Payroll.RepairSubsidy,
  4520. TP_PAR_Payroll.QualityEXA,
  4521. TP_PAR_Payroll.AdminEXA,
  4522. TP_PAR_Payroll.ADAmount,
  4523. TP_PAR_Payroll.TotalAmount,
  4524. TP_PAR_Payroll.Remarks,
  4525. TP_PAR_Payroll.AuditStatus,
  4526. decode(TP_PAR_Payroll.AuditStatus,0,'待审核','1','审核通过','审核未通过') as AuditStatusName,
  4527. TP_PAR_Payroll.AuditlDate,
  4528. TP_PAR_Payroll.Auditor,
  4529. (
  4530. select
  4531. wmsys.wm_concat(to_char(tp_mst_user.usercode)) as usercode
  4532. from tp_mst_userstaff
  4533. left join tp_mst_user
  4534. on tp_mst_userstaff.userid=tp_mst_user.userid
  4535. where tp_mst_userstaff.staffid=TP_PAR_Payroll.Staffid
  4536. ) as usercode
  4537. from TP_PAR_Payroll left join TP_HR_Staff
  4538. on TP_PAR_Payroll.StaffID=TP_HR_Staff.StaffID
  4539. where TP_PAR_Payroll.YYYYMM=:YYYYMM";
  4540. OracleParameter[] paras = new OracleParameter[]{
  4541. new OracleParameter("YYYYMM",OracleDbType.Varchar2, YYYYMM,ParameterDirection.Input),
  4542. };
  4543. DataSet ds = con.GetSqlResultToDs(sqlString, paras);
  4544. return ds;
  4545. }
  4546. catch (Exception ex)
  4547. {
  4548. throw ex;
  4549. }
  4550. finally
  4551. {
  4552. if (con.ConnState == ConnectionState.Open)
  4553. {
  4554. con.Close();
  4555. }
  4556. }
  4557. }
  4558. /// <summary>
  4559. /// 获取工资结算历史记录详情
  4560. /// </summary>
  4561. /// <param name="YYYYMM"></param>
  4562. /// <param name="staffid"></param>
  4563. /// <param name="sUserInfo"></param>
  4564. /// <returns></returns>
  4565. public static DataSet GetPayrollInfo(string YYYYMM, int staffid, SUserInfo sUserInfo)
  4566. {
  4567. IDBConnection con = ClsDbFactory.CreateDBConnection(DataBaseType.ORACLE, DataManager.ConnectionString);
  4568. try
  4569. {
  4570. con.Open();
  4571. DataSet dsReturn = new DataSet();
  4572. string sqlString = @"select
  4573. TP_HR_Staff.StaffName,
  4574. TP_HR_Staff.StaffCode,
  4575. decode(StaffFlag,'1','试用','正式') as StaffFlag,
  4576. YYYYMM,
  4577. decode(GoodsFlag,'1','新品','2','变产','正常') as GoodsFlag ,
  4578. PieceworkNum,
  4579. PieceCoefficient,
  4580. DamageNum,
  4581. DamageCoefficient,
  4582. UnqualifiedNum,
  4583. UnqualifiedCoefficient,
  4584. QualifiedNum,
  4585. QualifiedCoefficient,
  4586. QualityBaseNum,
  4587. QualityRate*100 as QualityRate,
  4588. QualityWages,
  4589. Amount,
  4590. TP_PAS_PayPlan.PayPlanName,
  4591. TP_PAT_Piecework.PieceTacticsName,
  4592. TP_PAM_WagesType.WagesTypeName
  4593. from TP_PAR_Piecework left join TP_HR_Staff
  4594. on TP_PAR_Piecework.StaffID=TP_HR_Staff.StaffID
  4595. left join TP_PAS_PayPlan on TP_PAS_PayPlan.PayPlanID=TP_PAR_Piecework.PayPlanID
  4596. left join TP_PAM_WagesType on TP_PAM_WagesType.WagesTypeID=TP_PAR_Piecework.WagesTypeID
  4597. left join TP_PAT_Piecework on TP_PAR_Piecework.PieceTacticsID=TP_PAT_Piecework.PieceTacticsID
  4598. where TP_PAR_Piecework.YYYYMM=:YYYYMM and TP_PAR_Piecework.staffid=:staffid";
  4599. OracleParameter[] paras = new OracleParameter[]{
  4600. new OracleParameter(":YYYYMM",OracleDbType.Varchar2, YYYYMM,ParameterDirection.Input),
  4601. new OracleParameter(":staffid",OracleDbType.Int32, staffid,ParameterDirection.Input),
  4602. };
  4603. DataSet ds = con.GetSqlResultToDs(sqlString, paras);
  4604. ds.Tables[0].TableName = "TP_PAR_Piecework";
  4605. string sqlString2 = @"select
  4606. TP_HR_Staff.StaffName,
  4607. TP_HR_Staff.StaffCode,
  4608. DamageNum,
  4609. YYYYMM,
  4610. StandardWages,
  4611. DamageSubsidyRate,
  4612. DamageSubsidy,
  4613. Amount,
  4614. TP_PAS_PayPlan.PayPlanName,
  4615. TP_PAT_Piecework.PieceTacticsName,
  4616. TP_PAM_WagesType.WagesTypeName
  4617. from TP_PAR_DamageSubsidy left join TP_HR_Staff
  4618. on TP_PAR_DamageSubsidy.StaffID=TP_HR_Staff.StaffID
  4619. left join TP_PAS_PayPlan on TP_PAS_PayPlan.PayPlanID=TP_PAR_DamageSubsidy.PayPlanID
  4620. left join TP_PAM_WagesType on TP_PAM_WagesType.WagesTypeID=TP_PAR_DamageSubsidy.WagesTypeID
  4621. left join TP_PAT_Piecework on TP_PAR_DamageSubsidy.PieceTacticsID=TP_PAT_Piecework.PieceTacticsID
  4622. where TP_PAR_DamageSubsidy.YYYYMM=:YYYYMM and TP_PAR_DamageSubsidy.staffid=:staffid";
  4623. DataSet ds2 = con.GetSqlResultToDs(sqlString2, paras);
  4624. ds2.Tables[0].TableName = "TP_PAR_DamageSubsidy";
  4625. string sqlString3 = @"select
  4626. TP_HR_Staff.StaffName,
  4627. TP_HR_Staff.StaffCode,
  4628. RSuperioNum,
  4629. YYYYMM,
  4630. RSuperiorCoefficient,
  4631. RQualifiedNum,
  4632. RQualifiedCoefficient,
  4633. StandardWages,
  4634. RepairSubsidyRate,
  4635. RepairSubsidy,
  4636. Amount,
  4637. TP_PAS_PayPlan.PayPlanName,
  4638. TP_PAT_Piecework.PieceTacticsName,
  4639. TP_PAM_WagesType.WagesTypeName
  4640. from TP_PAR_RepairSubsidy left join TP_HR_Staff
  4641. on TP_PAR_RepairSubsidy.StaffID=TP_HR_Staff.StaffID
  4642. left join TP_PAS_PayPlan on TP_PAS_PayPlan.PayPlanID=TP_PAR_RepairSubsidy.PayPlanID
  4643. left join TP_PAM_WagesType on TP_PAM_WagesType.WagesTypeID=TP_PAR_RepairSubsidy.WagesTypeID
  4644. left join TP_PAT_Piecework on TP_PAR_RepairSubsidy.PieceTacticsID=TP_PAT_Piecework.PieceTacticsID
  4645. where TP_PAR_RepairSubsidy.YYYYMM=:YYYYMM and TP_PAR_RepairSubsidy.staffid=:staffid";
  4646. DataSet ds3 = con.GetSqlResultToDs(sqlString3, paras);
  4647. ds3.Tables[0].TableName = "TP_PAR_RepairSubsidy";
  4648. string sqlString4 = @"select
  4649. TP_HR_Staff.StaffName,
  4650. TP_HR_Staff.StaffCode,
  4651. TP_MST_DataDictionary.DictionaryValue as DefectFine,
  4652. DefectNum,
  4653. YYYYMM,
  4654. QualityBaseNum,
  4655. QualityRate*100 as QualityRate,
  4656. Amount,
  4657. TP_PAS_PayPlan.PayPlanName,
  4658. TP_PAT_QualityASS.QualityTacticsName,
  4659. TP_PAM_WagesType.WagesTypeName
  4660. from TP_PAR_QualityASS left join TP_HR_Staff
  4661. on TP_PAR_QualityASS.StaffID=TP_HR_Staff.StaffID
  4662. left join TP_MST_DataDictionary
  4663. on TP_MST_DataDictionary.DictionaryID=TP_PAR_QualityASS.DefectFine and TP_MST_DataDictionary.DictionaryType='ASE002'
  4664. left join TP_PAS_PayPlan on TP_PAS_PayPlan.PayPlanID=TP_PAR_QualityASS.PayPlanID
  4665. left join TP_PAM_WagesType on TP_PAM_WagesType.WagesTypeID=TP_PAR_QualityASS.WagesTypeID
  4666. left join TP_PAT_QualityASS on TP_PAR_QualityASS.QualityASSTacticsID=TP_PAT_QualityASS.QualityASSTacticsID
  4667. where TP_PAR_QualityASS.YYYYMM=:YYYYMM and TP_PAR_QualityASS.staffid=:staffid";
  4668. DataSet ds4 = con.GetSqlResultToDs(sqlString4, paras);
  4669. ds4.Tables[0].TableName = "TP_PAR_QualityASS";
  4670. dsReturn.Tables.Add(ds.Tables[0].Copy());
  4671. dsReturn.Tables.Add(ds2.Tables[0].Copy());
  4672. dsReturn.Tables.Add(ds3.Tables[0].Copy());
  4673. dsReturn.Tables.Add(ds4.Tables[0].Copy());
  4674. return dsReturn;
  4675. }
  4676. catch (Exception ex)
  4677. {
  4678. throw ex;
  4679. }
  4680. finally
  4681. {
  4682. if (con.ConnState == ConnectionState.Open)
  4683. {
  4684. con.Close();
  4685. }
  4686. }
  4687. }
  4688. /// <summary>
  4689. /// 工资单调整
  4690. /// </summary>
  4691. /// <param name="dataPayroll">工资单数据</param>
  4692. /// <param name="sUserInfo">用户基本信息</param>
  4693. /// <returns>int</returns>
  4694. /// <remarks>
  4695. /// 2014.09.11 冯雪 新建
  4696. /// </remarks>
  4697. public static int SavePayrollChange(DataTable dataPayroll, SUserInfo sUserInfo)
  4698. {
  4699. IDBTransaction oracleTrConn = ClsDbFactory.CreateDBTransaction(DataBaseType.ORACLE, DataManager.ConnectionString);
  4700. try
  4701. {
  4702. // 检验参数的有效性
  4703. if (dataPayroll == null && dataPayroll.Rows.Count == 0)
  4704. {
  4705. return -1;
  4706. }
  4707. int intResult = 0;
  4708. oracleTrConn.Connect();
  4709. foreach (DataRow dataRow in dataPayroll.Rows)
  4710. {
  4711. if (dataRow.RowState == DataRowState.Modified)
  4712. {
  4713. #region 工资单对应金额
  4714. string sqlString = "UPDATE TP_PAR_Payroll SET "
  4715. + " ADAmount = :ADAmount, "
  4716. + " TotalAmount =TotalAmount+:ADAmount, "
  4717. + " Remarks = :Remarks "
  4718. + " WHERE YYYYMM = :YYYYMM"
  4719. + " and StaffID = :StaffID"
  4720. + " and AuditStatus=0";
  4721. OracleParameter[] parmeters1 = new OracleParameter[]
  4722. {
  4723. new OracleParameter(":ADAmount",dataRow["ADAmount"].ToString()),
  4724. new OracleParameter(":YYYYMM",dataRow["YYYYMM"].ToString()),
  4725. new OracleParameter(":StaffID",dataRow["StaffID"].ToString()),
  4726. new OracleParameter(":Remarks",dataRow["Remarks"].ToString())
  4727. };
  4728. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  4729. #endregion
  4730. }
  4731. }
  4732. oracleTrConn.Commit();
  4733. oracleTrConn.Disconnect();
  4734. return intResult;
  4735. }
  4736. catch (Exception ex)
  4737. {
  4738. if (oracleTrConn.ConnState == ConnectionState.Open)
  4739. {
  4740. oracleTrConn.Rollback();
  4741. oracleTrConn.Disconnect();
  4742. }
  4743. throw ex;
  4744. }
  4745. finally
  4746. {
  4747. if (oracleTrConn.ConnState == ConnectionState.Open)
  4748. {
  4749. oracleTrConn.Rollback();
  4750. oracleTrConn.Disconnect();
  4751. }
  4752. }
  4753. }
  4754. /// <summary>
  4755. /// 工资单审批
  4756. /// </summary>
  4757. /// <param name="dataPayroll">工资单数据</param>
  4758. /// <param name="sUserInfo">用户基本信息</param>
  4759. /// <returns>int</returns>
  4760. /// <remarks>
  4761. /// 2014.09.11 冯雪 新建
  4762. /// </remarks>
  4763. public static int SavePayrollAuditStatus(DataTable dataPayrollAuditStatus, SUserInfo sUserInfo)
  4764. {
  4765. IDBTransaction oracleTrConn = ClsDbFactory.CreateDBTransaction(DataBaseType.ORACLE, DataManager.ConnectionString);
  4766. try
  4767. {
  4768. int intResult = 0;
  4769. oracleTrConn.Connect();
  4770. foreach (DataRow dataRow in dataPayrollAuditStatus.Rows)
  4771. {
  4772. #region 工资单对应审核
  4773. string sqlString = "UPDATE TP_PAR_Payroll SET "
  4774. + " AuditStatus = :AuditStatus, "
  4775. + " Auditor =:Auditor, "
  4776. + " AuditlDate =sysdate "
  4777. + " WHERE YYYYMM = :YYYYMM"
  4778. + " and StaffID = :StaffID";
  4779. OracleParameter[] parmeters1 = new OracleParameter[]
  4780. {
  4781. new OracleParameter(":AuditStatus",dataRow["sel"].ToString()=="1"?"1":"0"),
  4782. new OracleParameter(":Auditor",sUserInfo.UserID),
  4783. new OracleParameter(":YYYYMM",dataRow["YYYYMM"].ToString()),
  4784. new OracleParameter(":StaffID",dataRow["StaffID"].ToString()),
  4785. };
  4786. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  4787. #endregion
  4788. }
  4789. oracleTrConn.Commit();
  4790. oracleTrConn.Disconnect();
  4791. return intResult;
  4792. }
  4793. catch (Exception ex)
  4794. {
  4795. if (oracleTrConn.ConnState == ConnectionState.Open)
  4796. {
  4797. oracleTrConn.Rollback();
  4798. oracleTrConn.Disconnect();
  4799. }
  4800. throw ex;
  4801. }
  4802. finally
  4803. {
  4804. if (oracleTrConn.ConnState == ConnectionState.Open)
  4805. {
  4806. oracleTrConn.Rollback();
  4807. oracleTrConn.Disconnect();
  4808. }
  4809. }
  4810. }
  4811. #endregion
  4812. /// <summary>
  4813. /// 结算工资
  4814. /// </summary>
  4815. /// <param name="IsEdit">false 新建 true 编辑</param>
  4816. /// <param name="dtJobsPayPlan">数据源</param>
  4817. /// <param name="sUserInfo"></param>
  4818. /// <returns></returns>
  4819. public static int SavePayPiecework2(int Month, int Year, DateTime start, DateTime end, SUserInfo sUserInfo)
  4820. {
  4821. IDBTransaction oracleTrConn = ClsDbFactory.CreateDBTransaction(DataBaseType.ORACLE, DataManager.ConnectionString);
  4822. try
  4823. {
  4824. int intResult = 0;
  4825. oracleTrConn.Connect();
  4826. oracleTrConn.IsCommandTimeout = false;
  4827. #region 判断是否已经结算此月
  4828. string sqlExist = "select 1 from TP_PAR_PayrollAccount where YYYYMM=:YYYYMM";
  4829. OracleParameter[] parmetersExist = new OracleParameter[]
  4830. {
  4831. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  4832. };
  4833. DataSet dsExist = oracleTrConn.GetSqlResultToDs(sqlExist, parmetersExist);
  4834. if (dsExist != null && dsExist.Tables[0].Rows.Count > 0)
  4835. {
  4836. oracleTrConn.Rollback();
  4837. oracleTrConn.Disconnect();
  4838. return -99;
  4839. }
  4840. #endregion
  4841. #region 查询系统参数设定值,用来结算工资范围取值
  4842. DateTime? dateStartTime = null;
  4843. DateTime? dateEndTime = null;
  4844. string sqlString = "select SettingValue from TP_MST_SystemSetting where accountid=:accountid and SettingCode='S_CMN_0003'";
  4845. OracleParameter[] parmeters1 = new OracleParameter[]
  4846. {
  4847. new OracleParameter(":accountid",sUserInfo.AccountID),
  4848. };
  4849. DataSet dsSystemSettings = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  4850. if (dsSystemSettings != null && dsSystemSettings.Tables[0].Rows.Count > 0)
  4851. {
  4852. // 算出此月一共多少天,防止设置的值,大于当月的天数
  4853. int daysCount = DateTime.DaysInMonth(Year, Month);
  4854. if (dsSystemSettings.Tables[0].Rows[0]["SettingValue"].ToString() == "月末")
  4855. {
  4856. dateStartTime = new DateTime(Year, Month, 1);
  4857. dateEndTime = new DateTime(Year, Month, daysCount, 23, 59, 59);
  4858. }
  4859. else
  4860. {
  4861. // 选择的值,大于当月的天数
  4862. if (Convert.ToInt32(dsSystemSettings.Tables[0].Rows[0]["SettingValue"]) > daysCount)
  4863. {
  4864. dateEndTime = new DateTime(Year, Month, daysCount, 23, 59, 59);
  4865. dateStartTime = dateEndTime.Value.AddMonths(-1).AddDays(1);
  4866. }
  4867. else
  4868. {
  4869. dateEndTime = new DateTime(Year, Month, Convert.ToInt32(dsSystemSettings.Tables[0].Rows[0]["SettingValue"]), 23, 59, 59);
  4870. dateStartTime = dateEndTime.Value.AddMonths(-1).AddDays(1);
  4871. }
  4872. }
  4873. }
  4874. dateStartTime = start;
  4875. //dateEndTime = new DateTime(DateTime.Now.Year, DateTime.Now.AddMonths(-2).Month, 27, 23, 59, 59);
  4876. dateEndTime = end;
  4877. #endregion
  4878. #region 根据筛选日期往临时表里插入数据
  4879. parmeters1 = new OracleParameter[]
  4880. {
  4881. new OracleParameter(":dateStartTime",OracleDbType.Date,dateStartTime,ParameterDirection.Input),
  4882. new OracleParameter(":dateEndTime",OracleDbType.Date,dateEndTime,ParameterDirection.Input),
  4883. new OracleParameter(":accountid",sUserInfo.AccountID),
  4884. };
  4885. // 生产数据临时表
  4886. sqlString = @"insert into TMP_PAM_ProductionData
  4887. select
  4888. ProductionDataID,
  4889. BarCode,
  4890. CentralizedBatchNo,
  4891. ProductionLineID,
  4892. ProductionLineCode,
  4893. ProductionLineName,
  4894. ProcedureID,
  4895. ProcedureCode,
  4896. ProcedureName,
  4897. ProcedureModel,
  4898. ModelType,
  4899. PieceType,
  4900. IsReworked,
  4901. NodeType,
  4902. IsPublicBody,
  4903. IsReFire,
  4904. GoodsLevelID,
  4905. GoodsLevelTypeID,
  4906. SpecialRepairFlag,
  4907. OrganizationID,
  4908. GoodsID,
  4909. GoodsCode,
  4910. GoodsName,
  4911. UserID,
  4912. UserCode,
  4913. UserName,
  4914. ClassesSettingID,
  4915. KilnID,
  4916. KilnCode,
  4917. KilnName,
  4918. KilnCarID,
  4919. KilnCarCode,
  4920. KilnCarName,
  4921. KilnCarBatchNo,
  4922. KilnCarPosition,
  4923. ReworkProcedureID,
  4924. ReworkProcedureCode,
  4925. ReworkProcedureName,
  4926. GroutingDailyID,
  4927. GroutingDailyDetailID,
  4928. GroutingLineID,
  4929. GroutingLineCode,
  4930. GroutingLineName,
  4931. GMouldTypeID,
  4932. CanManyTimes,
  4933. GroutingLineDetailID,
  4934. GroutingDate,
  4935. GroutingMouldCode,
  4936. MouldCode,
  4937. GroutingUserID,
  4938. GroutingUserCode,
  4939. GroutingNum,
  4940. Remarks,
  4941. AccountDate,
  4942. SettlementFlag,
  4943. AccountID,
  4944. ValueFlag,
  4945. CreateTime,
  4946. CreateUserID,
  4947. UpdateTime,
  4948. UpdateUserID,
  4949. OPTimeStamp
  4950. from TP_PM_ProductionData where CreateTime >=:dateStartTime and CreateTime<=:dateEndTime and accountid=:accountid and valueflag=1";
  4951. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  4952. // 生产缺陷
  4953. sqlString = @"insert into TMP_PAM_Defect
  4954. select
  4955. ProductionDefectID,
  4956. ProductionDataID,
  4957. BarCode,
  4958. ProductionLineID,
  4959. ProductionLineCode,
  4960. ProductionLineName,
  4961. ProcedureID,
  4962. ProcedureCode,
  4963. ProcedureName,
  4964. UserID,
  4965. UserCode,
  4966. UserName,
  4967. GoodsID,
  4968. GoodsCode,
  4969. GoodsName,
  4970. DefectID,
  4971. DefectCode,
  4972. DefectName,
  4973. DefectPositionID,
  4974. DefectPositionCode,
  4975. DefectPositionName,
  4976. ScrapResponFlag,
  4977. DefectProductionDataID,
  4978. DefectProcedureID,
  4979. DefectProcedureCode,
  4980. DefectProcedureName,
  4981. DefectUserID,
  4982. DefectUserCode,
  4983. DefectUserName,
  4984. DefectJobs,
  4985. DefectFine,
  4986. MissedUserID,
  4987. MissedUserCode,
  4988. MissedUserName,
  4989. Remarks,
  4990. AccountID,
  4991. ValueFlag,
  4992. CreateTime,
  4993. CreateUserID,
  4994. UpdateTime,
  4995. UpdateUserID,
  4996. OPTimeStamp
  4997. from TP_PM_Defect where CreateTime >=:dateStartTime and CreateTime<=:dateEndTime and accountid=:accountid and valueflag=1";
  4998. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  4999. //生产缺陷责任者
  5000. sqlString = @"insert into TMP_PAM_DefectResponsible
  5001. select
  5002. ProductionDefectID,
  5003. StaffID,
  5004. StaffStatus,
  5005. UserID,
  5006. UserCode,
  5007. UJobsID,
  5008. SJobsID,
  5009. AccountID,
  5010. ValueFlag,
  5011. CreateTime,
  5012. CreateUserID,
  5013. UpdateTime,
  5014. UpdateUserID,
  5015. OPTimeStamp
  5016. from TP_PM_DefectResponsible where CreateTime >=:dateStartTime and CreateTime<=:dateEndTime and accountid=:accountid and valueflag=1";
  5017. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  5018. // //缺陷漏检责任者
  5019. // sqlString = @"insert into TP_PAM_DefectMissedResponsible
  5020. // select * from TP_PM_DefectMissedResponsible where CreateTime >=:dateStartTime and CreateTime<=:dateEndTime and accountid=:accountid and valueflag=1";
  5021. // intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  5022. //废弃产品
  5023. sqlString = @"insert into TMP_PAM_ScrapProduct
  5024. select
  5025. ScrapProductID,
  5026. BarCode,
  5027. ProductionLineID,
  5028. ProductionLineCode,
  5029. ProductionLineName,
  5030. ProcedureID,
  5031. ProcedureCode,
  5032. ProcedureName,
  5033. GoodsID,
  5034. GoodsCode,
  5035. GoodsName,
  5036. GroutingDailyID,
  5037. GroutingDailyDetailID,
  5038. GroutingDate,
  5039. GroutingLineID,
  5040. GroutingLineCode,
  5041. GroutingLineName,
  5042. GMouldTypeID,
  5043. GroutingLineDetailID,
  5044. GroutingMouldCode,
  5045. MouldCode,
  5046. GroutingUserID,
  5047. GroutingUserCode,
  5048. GroutingNum,
  5049. IsPublicBody,
  5050. IsReFire,
  5051. SpecialRepairFlag,
  5052. GoodsLevelID,
  5053. GoodsLevelTypeID,
  5054. ResponType,
  5055. ScrapFine,
  5056. ScrapDate,
  5057. Rreason,
  5058. Remarks,
  5059. AuditStatus,
  5060. Auditor,
  5061. AuditDate,
  5062. AuditOpinion,
  5063. AccountDate,
  5064. KilnID,
  5065. KilnCode,
  5066. KilnName,
  5067. KilnCarID,
  5068. KilnCarCode,
  5069. KilnCarName,
  5070. KilnCarBatchNo,
  5071. KilnCarPosition,
  5072. AccountID,
  5073. ValueFlag,
  5074. CreateTime,
  5075. CreateUserID,
  5076. UpdateTime,
  5077. UpdateUserID,
  5078. OPTimeStamp
  5079. from TP_PM_ScrapProduct where CreateTime >=:dateStartTime and CreateTime<=:dateEndTime and accountid=:accountid and valueflag=1 and AuditStatus=1";
  5080. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  5081. //产品废弃责任工序
  5082. sqlString = @"insert into TMP_PAM_ResponProcedure
  5083. select
  5084. ResponProcedureID,
  5085. ScrapProductID,
  5086. BarCode,
  5087. ProductionDataID,
  5088. ProductionLineID,
  5089. ProductionLineCode,
  5090. ProductionLineName,
  5091. ProcedureID,
  5092. ProcedureCode,
  5093. ProcedureName,
  5094. UserID,
  5095. UserCode,
  5096. UserName,
  5097. Remarks,
  5098. AccountID,
  5099. ValueFlag,
  5100. CreateTime,
  5101. CreateUserID,
  5102. UpdateTime,
  5103. UpdateUserID,
  5104. OPTimeStamp
  5105. from TP_PM_ResponProcedure
  5106. where CreateTime >=:dateStartTime and CreateTime<=:dateEndTime and accountid=:accountid and valueflag=1 ";
  5107. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  5108. //产品废弃责任者
  5109. sqlString = @"insert into TMP_PAM_ScrapResponsible
  5110. select
  5111. ResponsibleID,
  5112. ScrapProductID,
  5113. BarCode,
  5114. ResponType,
  5115. ResponProcedureID,
  5116. ScrapFine,
  5117. StaffID,
  5118. StaffStatus,
  5119. UserID,
  5120. UserCode,
  5121. UJobsID,
  5122. SJobsID,
  5123. AccountID,
  5124. CreateTime,
  5125. CreateUserID,
  5126. UpdateTime,
  5127. UpdateUserID,
  5128. OPTimeStamp
  5129. from TP_PM_ScrapResponsible where CreateTime >=:dateStartTime and CreateTime<=:dateEndTime and accountid=:accountid ";
  5130. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  5131. //成品 (干补补贴用)
  5132. sqlString = @"insert into TMP_PAM_FinishedProduct
  5133. select
  5134. BarCode,
  5135. ProductionLineID,
  5136. ProductionLineCode,
  5137. ProductionLineName,
  5138. IsPublicBody,
  5139. IsReFire,
  5140. SpecialRepairFlag,
  5141. GoodsLevelID,
  5142. GoodsLevelTypeID,
  5143. GoodsID,
  5144. GoodsCode,
  5145. GoodsName,
  5146. GroutingDailyID,
  5147. GroutingDailyDetailID,
  5148. GroutingDate,
  5149. GroutingLineID,
  5150. GroutingLineCode,
  5151. GroutingLineName,
  5152. GMouldTypeID,
  5153. GroutingLineDetailID,
  5154. GroutingMouldCode,
  5155. MouldCode,
  5156. GroutingUserID,
  5157. GroutingUserCode,
  5158. GroutingNum,
  5159. Remarks,
  5160. AccountDate,
  5161. SettlementFlag,
  5162. KilnID,
  5163. KilnCode,
  5164. KilnName,
  5165. KilnCarID,
  5166. KilnCarCode,
  5167. KilnCarName,
  5168. KilnCarBatchNo,
  5169. KilnCarPosition,
  5170. AccountID,
  5171. ValueFlag,
  5172. CreateTime,
  5173. CreateUserID,
  5174. UpdateTime,
  5175. UpdateUserID,
  5176. OPTimeStamp
  5177. from TP_PM_FinishedProduct where CreateTime >=:dateStartTime and CreateTime<=:dateEndTime and accountid=:accountid and valueflag=1";
  5178. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  5179. #endregion
  5180. #region 读取工资方案,用来最外层循环,以后可以是多个方法,目前只有一个工资方案
  5181. sqlString = "select PayPlanID from TP_PAS_PayPlan where AccountID=:AccountID and ValueFlag=1";
  5182. parmeters1 = new OracleParameter[]
  5183. {
  5184. new OracleParameter(":AccountID",sUserInfo.AccountID),
  5185. };
  5186. DataSet dsPayPlan = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  5187. #endregion
  5188. // dsPayPlan为工资方案数据集
  5189. if (dsPayPlan != null && dsPayPlan.Tables[0].Rows.Count > 0)
  5190. {
  5191. // 进入循环,
  5192. for (int i = 0; i < dsPayPlan.Tables[0].Rows.Count; i++)
  5193. {
  5194. #region 查出工资临时生产数据表数据,用于计算工资
  5195. //查出在产品工介分类中的生产数据,用于计算每个人的工资
  5196. sqlString = @"select
  5197. TMP_PAM_ProductionData.ProductionDataID,
  5198. TMP_PAM_ProductionData.BarCode,
  5199. TMP_PAM_ProductionData.ProcedureID,
  5200. TMP_PAM_ProductionData.GoodsID,
  5201. TMP_PAM_ProductionData.GoodsCode,
  5202. TMP_PAM_ProductionData.GoodsName,
  5203. TMP_PAM_ProductionData.UserID,
  5204. TMP_PAM_ProductionData.UserCode,
  5205. TMP_PAM_ProductionData.UserName,
  5206. TP_MST_Goods.StartingDate,
  5207. TP_PAM_GoodsWagesType.WagesTypeID,
  5208. TMP_PAM_ProductionData.GoodsLevelTypeID
  5209. from
  5210. TMP_PAM_ProductionData
  5211. inner join TP_PAM_GoodsWagesType
  5212. on TMP_PAM_ProductionData.GoodsID=TP_PAM_GoodsWagesType.GoodsID
  5213. left join TP_MST_Goods
  5214. on TP_PAM_GoodsWagesType.GoodsID=TP_MST_Goods.GoodsID
  5215. where TMP_PAM_ProductionData.CreateTime >=:dateStartTime and TMP_PAM_ProductionData.CreateTime<=:dateEndTime and accountid=:accountid
  5216. order by TMP_PAM_ProductionData.ProductionDataID desc";
  5217. parmeters1 = new OracleParameter[]
  5218. {
  5219. new OracleParameter(":accountid",sUserInfo.AccountID),
  5220. new OracleParameter(":dateStartTime",dateStartTime),
  5221. new OracleParameter(":dateEndTime",dateEndTime),
  5222. };
  5223. DataSet dsTMPProductionData = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  5224. #endregion
  5225. #region 查出工资方案对应工种的员工,用于给每个员工结算工资
  5226. sqlString = @"select TP_HR_Staff.StaffID,TP_HR_Staff.StaffCode,TP_HR_Staff.StaffName,TP_HR_Staff.Jobs,TP_HR_Staff.StaffStatus
  5227. ,TP_HR_Staff.EntryDate,TP_HR_Staff.TurnoverDate,TP_HR_Staff.ExProbationEndDate, TP_MST_UserStaff.UserID
  5228. from TP_HR_Staff
  5229. inner join TP_MST_UserStaff on TP_HR_Staff.StaffID=TP_MST_UserStaff.StaffID
  5230. where TP_HR_Staff.Jobs in
  5231. (
  5232. select JobsID from TP_PAM_JobsPayPlan where PayPlanID=:PayPlanID
  5233. )
  5234. and TP_HR_Staff.accountid=:accountid and TP_HR_Staff.valueflag=1
  5235. ";
  5236. parmeters1 = new OracleParameter[]
  5237. {
  5238. new OracleParameter(":accountid",sUserInfo.AccountID),
  5239. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  5240. };
  5241. DataSet dsJobsPayPlan = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  5242. #endregion
  5243. #region 查出计件工资策略
  5244. sqlString = @"select * from TP_PAT_Piecework where accountid=:accountid and valueflag=1 and PayPlanID=:PayPlanID";
  5245. parmeters1 = new OracleParameter[]
  5246. {
  5247. new OracleParameter(":accountid",sUserInfo.AccountID),
  5248. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  5249. };
  5250. DataSet dsPiecework = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  5251. int PieceTacticsID = 0; //计件工资策略ID
  5252. //int PieceworkValue = 0; //计件工资策略,如果未配置工资方案计件策略,计件工资为0
  5253. string PieceType = ""; // 工序类型
  5254. //int? PieceProcedureID = null; //计件工序
  5255. decimal PieceCoefficient = 1; // 计件系数
  5256. string DamageFlag = ""; //损坯计算标识
  5257. decimal? DamageCoefficient = null; //损坯系数
  5258. string UnqualifiedFlag = ""; //次品计算标识
  5259. decimal? UnqualifiedCoefficient = null; //次品系数
  5260. string QualifiedFlag = ""; //副品计算标识
  5261. decimal? QualifiedCoefficient = null; //副品系数
  5262. //int? QualityBaseProcedureID = null; //质量基数工序
  5263. if (dsPiecework != null && dsPiecework.Tables[0].Rows.Count > 0)
  5264. {
  5265. // 有且只能一个对应的工资方案,直接取table0行,如果取出多行,此数据不对,因为有且只能一行
  5266. // 赋值代码
  5267. PieceTacticsID = Convert.ToInt32(dsPiecework.Tables[0].Rows[0]["PieceTacticsID"].ToString());
  5268. PieceType = dsPiecework.Tables[0].Rows[0]["PieceType"].ToString();
  5269. //PieceProcedureID = Convert.ToInt32(dsPiecework.Tables[0].Rows[0]["PieceProcedureID"]);
  5270. PieceCoefficient = Convert.ToDecimal(dsPiecework.Tables[0].Rows[0]["PieceCoefficient"]);
  5271. DamageFlag = dsPiecework.Tables[0].Rows[0]["DamageFlag"].ToString();
  5272. DamageCoefficient = Convert.ToDecimal(dsPiecework.Tables[0].Rows[0]["DamageCoefficient"]);
  5273. UnqualifiedFlag = dsPiecework.Tables[0].Rows[0]["UnqualifiedFlag"].ToString();
  5274. UnqualifiedCoefficient = Convert.ToDecimal(dsPiecework.Tables[0].Rows[0]["UnqualifiedCoefficient"]);
  5275. QualifiedFlag = dsPiecework.Tables[0].Rows[0]["QualifiedFlag"].ToString();
  5276. QualifiedCoefficient = Convert.ToDecimal(dsPiecework.Tables[0].Rows[0]["QualifiedCoefficient"]);
  5277. //QualityBaseProcedureID = Convert.ToInt32(dsPiecework.Tables[0].Rows[0]["QualityBaseProcedureID"]);
  5278. }
  5279. #endregion
  5280. #region 查出计件工资策略(计件工序)
  5281. sqlString = "select * from TP_PAT_PieceProcedure where PieceTacticsID=:PieceTacticsID and ProcedureFlag=1";
  5282. parmeters1 = new OracleParameter[]
  5283. {
  5284. new OracleParameter(":PieceTacticsID",PieceTacticsID),
  5285. };
  5286. DataSet dsPieceProcedure_1 = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  5287. sqlString = "select * from TP_PAT_PieceProcedure where PieceTacticsID=:PieceTacticsID and ProcedureFlag=2";
  5288. parmeters1 = new OracleParameter[]
  5289. {
  5290. new OracleParameter(":PieceTacticsID",PieceTacticsID),
  5291. };
  5292. DataSet dsPieceProcedure_2 = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  5293. #endregion
  5294. #region 查出全部废弃产品表数据,用于计算工资
  5295. sqlString = @"select TMP_PAM_ResponProcedure.UserID,TP_PAM_GoodsWagesType.WagesTypeID,TP_MST_Goods.StartingDate,TMP_PAM_ScrapProduct.barcode, from TMP_PAM_ScrapProduct left join TMP_PAM_ResponProcedure
  5296. on TMP_PAM_ScrapProduct.ScrapProductID=TMP_PAM_ResponProcedure.ScrapProductID
  5297. left join TP_PAM_GoodsWagesType on TMP_PAM_ScrapProduct.GoodsID=TP_PAM_GoodsWagesType.GoodsID
  5298. left join TP_MST_Goods
  5299. on TP_PAM_GoodsWagesType.GoodsID=TP_MST_Goods.GoodsID
  5300. where TMP_PAM_ScrapProduct.CreateTime >=:dateStartTime and TMP_PAM_ScrapProduct.CreateTime<=:dateEndTime
  5301. and TMP_PAM_ScrapProduct.accountid=:accountid and TMP_PAM_ScrapProduct.AuditStatus=1
  5302. ";
  5303. parmeters1 = new OracleParameter[]
  5304. {
  5305. new OracleParameter(":accountid",sUserInfo.AccountID),
  5306. new OracleParameter(":dateStartTime",dateStartTime),
  5307. new OracleParameter(":dateEndTime",dateEndTime),
  5308. };
  5309. DataSet dsTMPResponProcedure = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  5310. #endregion
  5311. #region 查出产品工价分类
  5312. sqlString = @"select * from TP_PAM_GoodsWagesType ";
  5313. DataSet dsGoodsWagesType = oracleTrConn.GetSqlResultToDs(sqlString);
  5314. #endregion
  5315. #region 查出产品工价
  5316. sqlString = @"select * from TP_PAT_Wages ";
  5317. DataSet dsWages = oracleTrConn.GetSqlResultToDs(sqlString);
  5318. #endregion
  5319. #region 查出质量工价
  5320. sqlString = @"select * from TP_PAT_QualityWages order by WagesTypeID,QualityRate ";
  5321. DataSet dsQualityWages = oracleTrConn.GetSqlResultToDs(sqlString);
  5322. #endregion
  5323. #region 查出工资方案参数设定
  5324. sqlString = "select * from TP_PAS_PayPlanSetting where PayPlanID=:PayPlanID";
  5325. parmeters1 = new OracleParameter[]
  5326. {
  5327. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  5328. };
  5329. DataSet dsPayPlanSetting = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  5330. #endregion
  5331. #region 查出临时成品表,用于计算干补补贴,这些数据肯定配置了产品工价
  5332. sqlString = @"select * from TMP_PAM_FinishedProduct inner join TP_PAM_GoodsWagesType
  5333. on TMP_PAM_FinishedProduct.GoodsID=TP_PAM_GoodsWagesType.GoodsID
  5334. where TMP_PAM_FinishedProduct.CreateTime >=:dateStartTime and TMP_PAM_FinishedProduct.CreateTime<=:dateEndTime
  5335. and TMP_PAM_FinishedProduct.accountid=:accountid
  5336. ";
  5337. parmeters1 = new OracleParameter[]
  5338. {
  5339. new OracleParameter(":accountid",sUserInfo.AccountID),
  5340. new OracleParameter(":dateStartTime",dateStartTime),
  5341. new OracleParameter(":dateEndTime",dateEndTime),
  5342. };
  5343. DataSet dsFinishedProduct = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  5344. #endregion
  5345. #region 读出对应解决方案品质考核策略,可以存在多个
  5346. sqlString = "select * from TP_PAT_QualityASS where PayPlanID=:PayPlanID";
  5347. parmeters1 = new OracleParameter[]
  5348. {
  5349. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  5350. };
  5351. DataSet dsQualityASS = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  5352. #endregion
  5353. #region 读出对应解决方案品质考核策略工序
  5354. //sqlString = "select * from TP_PAT_QualityProcedure";
  5355. //DataSet dsQualityProcedure = oracleTrConn.GetSqlResultToDs(sqlString);
  5356. #endregion
  5357. #region 查出生产缺陷数据表(暂时未用)
  5358. // sqlString = @"select * from TMP_PAM_Defect inner join TP_PAM_GoodsWagesType
  5359. // on TMP_PAM_Defect.GoodsID=TP_PAM_GoodsWagesType.GoodsID
  5360. // where TMP_PAM_Defect.CreateTime >=:dateStartTime and TMP_PAM_Defect.CreateTime<=:dateEndTime
  5361. // and TMP_PAM_Defect.accountid=:accountid
  5362. // ";
  5363. // parmeters1 = new OracleParameter[]
  5364. // {
  5365. // new OracleParameter(":accountid",sUserInfo.AccountID),
  5366. // new OracleParameter(":dateStartTime",dateStartTime),
  5367. // new OracleParameter(":dateEndTime",dateEndTime),
  5368. // };
  5369. // DataSet dsDefect = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  5370. #endregion
  5371. // 遍历工种数据集,统计每个员工的工资
  5372. //dsJobsPayPlan.Tables[0].Rows.Count
  5373. for (int j = 0; j < dsJobsPayPlan.Tables[0].Rows.Count; j++)
  5374. {
  5375. // 用于插入工资单各类数值
  5376. decimal? totalcount_Piecegiework = 0; //计件工资
  5377. decimal? totalcount_Scrap = 0; //损坯补贴
  5378. decimal? totalcount_RepairSubsidy = 0; //干补补贴
  5379. #region 计件工资整体累计
  5380. if (PieceType == "0") // 工序计件
  5381. {
  5382. // 查出这个工号,在此计件工序,有多少产品
  5383. DataRow[] drGoodsCount = dsTMPProductionData.Tables[0]
  5384. .Select(string.Format("UserID={0}", dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString()));
  5385. if (drGoodsCount.Length > 0) // 此工号下代表有产品
  5386. {
  5387. //-----------------------------------
  5388. // 1.算出是否有新品,还是老品
  5389. DataRow[] drMonth = dsPayPlanSetting.Tables[0].Select("SettingCode='01001'");
  5390. int newGoodsMonth = Convert.ToInt32(drMonth[0]["SettingValue"]); //新产品适应周期(月)
  5391. // 2.添加一列,产品标识,是否新品,还是旧品,遍历数据集,并一个一个更改
  5392. if (!dsTMPProductionData.Tables[0].Columns.Contains("GoodsFlag"))
  5393. {
  5394. dsTMPProductionData.Tables[0].Columns.Add("GoodsFlag");
  5395. for (int bb = 0; bb < dsTMPProductionData.Tables[0].Rows.Count; bb++)
  5396. {
  5397. if (Convert.ToDateTime(dsTMPProductionData.Tables[0].Rows[bb]["StartingDate"]).AddMonths(newGoodsMonth) > DateTime.Now)
  5398. {
  5399. dsTMPProductionData.Tables[0].Rows[bb]["GoodsFlag"] = 3; //正常
  5400. }
  5401. else
  5402. {
  5403. dsTMPProductionData.Tables[0].Rows[bb]["GoodsFlag"] = 1; //新品
  5404. }
  5405. }
  5406. }
  5407. //for (int bb = 0; bb < dsTMPProductionData.Tables[0].Rows.Count; bb++)
  5408. //{
  5409. // if (Convert.ToDateTime(dsTMPProductionData.Tables[0].Rows[bb]["StartingDate"]).AddMonths(newGoodsMonth) > DateTime.Now)
  5410. // {
  5411. // dsTMPProductionData.Tables[0].Rows[bb]["GoodsFlag"] = 3; //正常
  5412. // }
  5413. // else
  5414. // {
  5415. // dsTMPProductionData.Tables[0].Rows[bb]["GoodsFlag"] = 1; //新品
  5416. // }
  5417. //}
  5418. //3 报损责任工序
  5419. if (!dsTMPResponProcedure.Tables[0].Columns.Contains("GoodsFlag"))
  5420. {
  5421. dsTMPResponProcedure.Tables[0].Columns.Add("GoodsFlag");
  5422. for (int bb = 0; bb < dsTMPResponProcedure.Tables[0].Rows.Count; bb++)
  5423. {
  5424. if (dsTMPResponProcedure.Tables[0].Rows[bb]["StartingDate"].ToString() != "")
  5425. {
  5426. if (Convert.ToDateTime(dsTMPResponProcedure.Tables[0].Rows[bb]["StartingDate"]).AddMonths(newGoodsMonth) > DateTime.Now)
  5427. {
  5428. dsTMPResponProcedure.Tables[0].Rows[bb]["GoodsFlag"] = 3; //正常
  5429. }
  5430. else
  5431. {
  5432. dsTMPResponProcedure.Tables[0].Rows[bb]["GoodsFlag"] = 1; //新品
  5433. }
  5434. }
  5435. else
  5436. {
  5437. dsTMPResponProcedure.Tables[0].Rows[bb]["GoodsFlag"] = 3; //正常
  5438. }
  5439. }
  5440. }
  5441. //for (int bb = 0; bb < dsTMPResponProcedure.Tables[0].Rows.Count; bb++)
  5442. //{
  5443. // if (dsTMPResponProcedure.Tables[0].Rows[bb]["StartingDate"].ToString() != "")
  5444. // {
  5445. // if (Convert.ToDateTime(dsTMPResponProcedure.Tables[0].Rows[bb]["StartingDate"]).AddMonths(newGoodsMonth) > DateTime.Now)
  5446. // {
  5447. // dsTMPResponProcedure.Tables[0].Rows[bb]["GoodsFlag"] = 3; //正常
  5448. // }
  5449. // else
  5450. // {
  5451. // dsTMPResponProcedure.Tables[0].Rows[bb]["GoodsFlag"] = 1; //新品
  5452. // }
  5453. // }
  5454. // else
  5455. // {
  5456. // dsTMPResponProcedure.Tables[0].Rows[bb]["GoodsFlag"] = 3; //正常
  5457. // }
  5458. //}
  5459. //-----------------------------------
  5460. // 接下来在过滤产品分类有多少种,用来分别计算各分类的工资
  5461. // 以下表有多少行,去掉重复算出有多少个分类
  5462. DataTable dtWagesType = drGoodsCount.CopyToDataTable().DefaultView.ToTable(true, "WagesTypeID");
  5463. // 有多少产品标识
  5464. DataTable dtGoodsFlag = drGoodsCount.CopyToDataTable().DefaultView.ToTable(true, "GoodsFlag");
  5465. int PieceProcedureCount = 0; //计件数量
  5466. int UnqualifiedCount = 0; //次品数量
  5467. int QualifiedCount = 0; //副品数量
  5468. int QualityBaseProcedureCount = 0; //出窑数量
  5469. for (int wagestype = 0; wagestype < dtWagesType.Rows.Count; wagestype++)
  5470. {
  5471. for (int vv = 0; vv < dtGoodsFlag.Rows.Count; vv++)
  5472. {
  5473. decimal? temp_Piecegiework = 0;
  5474. #region 1.求出各分类计件工序数量
  5475. PieceProcedureCount = 0; //每个分类之前置空
  5476. decimal PieceProcedureTotal = 0;//系数*数量
  5477. //下面开始计算每个分类的计件工资
  5478. for (int p1 = 0; p1 < dsPieceProcedure_1.Tables[0].Rows.Count; p1++)
  5479. {
  5480. DataRow[] drPieceProcedureCount = dsTMPProductionData.Tables[0]
  5481. .Select(string.Format("UserID={0} and ProcedureID={1} and WagesTypeID={2} and GoodsFlag={3}", dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString(), dsPieceProcedure_1.Tables[0].Rows[p1]["ProcedureID"], dtWagesType.Rows[wagestype]["WagesTypeID"], dtGoodsFlag.Rows[vv]["GoodsFlag"]));
  5482. PieceProcedureCount += drPieceProcedureCount.Length; //工序数量
  5483. }
  5484. PieceProcedureTotal = PieceProcedureCount * PieceCoefficient; //工序数量*系数
  5485. #endregion 1.求出计件工序数量
  5486. #region 2.求出各工价分类损坯数量
  5487. int ScrapCount = 0; //损坯数量
  5488. decimal? Scrap = 0; //每个类别损坯的值
  5489. if (DamageFlag == "1") //计算损坯数量
  5490. {
  5491. // 查出此人在计件工序的条码,完事关联报损表存在多少报损条码
  5492. string ProcedureIDS = "0"; //默认给个0,怕没有些去进行筛选出现错误
  5493. for (int p1 = 0; p1 < dsPieceProcedure_1.Tables[0].Rows.Count; p1++)
  5494. {
  5495. ProcedureIDS = ProcedureIDS + dsPieceProcedure_1.Tables[0].Rows[p1]["ProcedureID"].ToString() + ",";
  5496. }
  5497. ProcedureIDS = ProcedureIDS.Trim(',');
  5498. // 筛选出生产数据这几个工序所用的条码
  5499. DataRow[] dr_BarCode = dsTMPProductionData.Tables[0].Select(string.Format("UserID={0} and ProcedureID in ({1}) and WagesTypeID={2} and GoodsFlag={3}", dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString(), ProcedureIDS, dtWagesType.Rows[wagestype]["WagesTypeID"], dtGoodsFlag.Rows[vv]["GoodsFlag"]));
  5500. if (dr_BarCode.Length > 0)
  5501. {
  5502. string temp_barcode = "";
  5503. foreach (DataRow r3 in dr_BarCode)
  5504. {
  5505. DataRow[] dr2 = dsTMPResponProcedure.Tables[0].Select("barcode='" + r3["barcode"] + "'");
  5506. if (dr2.Length > 0)
  5507. {
  5508. if (!temp_barcode.Contains(r3["barcode"].ToString()))
  5509. {
  5510. // 有损坯数据
  5511. ScrapCount = ScrapCount + 1;
  5512. }
  5513. temp_barcode += r3["barcode"].ToString() + ",";
  5514. }
  5515. }
  5516. }
  5517. // end
  5518. Scrap = ScrapCount * DamageCoefficient; //DamageCoefficient为损坯系数
  5519. }
  5520. #endregion 2.求出损坯数量 end
  5521. #region 3.求出各工价分类次品数
  5522. // 筛出产品分级为次品的生产数据,完事一个一个去查对应责任工号的,进行累加
  5523. DataRow[] drUnqualifiedCount = dsTMPProductionData.Tables[0]
  5524. .Select(string.Format("WagesTypeID={0} and GoodsLevelTypeID=7 and GoodsFlag={1} ", dtWagesType.Rows[wagestype]["WagesTypeID"], dtGoodsFlag.Rows[vv]["GoodsFlag"]));
  5525. UnqualifiedCount = 0; //次品数量
  5526. decimal? UnqualifiedTotal = 0;//系数*数量
  5527. if (drUnqualifiedCount.Length > 0)
  5528. {
  5529. // 表示有次品,但是得对应责任工号,进行累加
  5530. foreach (DataRow row in drUnqualifiedCount)
  5531. {
  5532. string sqlView = "select 1 from TMP_PAM_Defect where DefectUserID=" + dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString() + " and ProductionDataID=" + row["ProductionDataID"];
  5533. DataSet ds = oracleTrConn.GetSqlResultToDs(sqlView);
  5534. if (ds != null && ds.Tables[0].Rows.Count > 0)
  5535. {
  5536. // 多个缺陷也算一个数,所以直接+1
  5537. UnqualifiedCount = UnqualifiedCount + 1;
  5538. }
  5539. }
  5540. UnqualifiedTotal = UnqualifiedCount * UnqualifiedCoefficient;
  5541. }
  5542. #endregion
  5543. #region 4.求出各工价分类副品数
  5544. // 筛出产品分级为副品的生产数据,完事一个一个去查对应责任工号的,进行累加
  5545. DataRow[] drQualified = dsTMPProductionData.Tables[0]
  5546. .Select(string.Format("WagesTypeID={0} and GoodsLevelTypeID=5 and GoodsFlag={1}", dtWagesType.Rows[wagestype]["WagesTypeID"], dtGoodsFlag.Rows[vv]["GoodsFlag"]));
  5547. QualifiedCount = 0; //副品数量
  5548. decimal? QualifiedTotal = 0;//系数*数量
  5549. if (drQualified.Length > 0)
  5550. {
  5551. // 表示有副品,但是得对应责任工号,进行累加
  5552. foreach (DataRow row in drQualified)
  5553. {
  5554. string sqlView = "select 1 from TMP_PAM_Defect where DefectUserID=" + dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString() + " and ProductionDataID=" + row["ProductionDataID"];
  5555. DataSet ds = oracleTrConn.GetSqlResultToDs(sqlView);
  5556. if (ds != null && ds.Tables[0].Rows.Count > 0)
  5557. {
  5558. // 多个缺陷也算一个数,所以直接+1
  5559. QualifiedCount = QualifiedCount + 1;
  5560. }
  5561. }
  5562. QualifiedTotal = QualifiedCount * QualifiedCoefficient;
  5563. }
  5564. #endregion 求出各工价分类副品数
  5565. #region 5.求出质量工价
  5566. string barcodes_Procedure = "";
  5567. QualityBaseProcedureCount = 0;
  5568. for (int p1 = 0; p1 < dsPieceProcedure_2.Tables[0].Rows.Count; p1++)
  5569. {
  5570. //DataRow[] drQualityBaseProcedure = dsTMPProductionData.Tables[0]
  5571. // .Select(string.Format("UserID={0} and ProcedureID={1} and WagesTypeID={2} and GoodsFlag={3}", dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString(), dsPieceProcedure_2.Tables[0].Rows[p1]["ProcedureID"], dtWagesType.Rows[wagestype]["WagesTypeID"], dtGoodsFlag.Rows[vv]["GoodsFlag"]));
  5572. //QualityBaseProcedureCount += drQualityBaseProcedure.Length; // 质量工序数量
  5573. //DataRow[] drQualityBaseProcedure = dsTMPProductionData.Tables[0]
  5574. // .Select(string.Format("ProcedureID={0} and WagesTypeID={1} and GoodsFlag={2}", dsPieceProcedure_2.Tables[0].Rows[p1]["ProcedureID"], dtWagesType.Rows[wagestype]["WagesTypeID"], dtGoodsFlag.Rows[vv]["GoodsFlag"]));
  5575. DataRow[] drQualityBaseProcedure = dsTMPProductionData.Tables[0]
  5576. .Select(string.Format("ProcedureID={0} and WagesTypeID={1}", dsPieceProcedure_2.Tables[0].Rows[p1]["ProcedureID"], dtWagesType.Rows[wagestype]["WagesTypeID"]));
  5577. if (drQualityBaseProcedure.Length > 0)
  5578. {
  5579. foreach (DataRow r4 in drQualityBaseProcedure)
  5580. {
  5581. if (!barcodes_Procedure.Contains(r4["barcode"].ToString()))
  5582. {
  5583. QualityBaseProcedureCount += 1; // 质量工序数量
  5584. }
  5585. barcodes_Procedure = barcodes_Procedure + r4["barcode"].ToString() + ",";
  5586. }
  5587. }
  5588. }
  5589. decimal QualityBaseProcedureTotal = 0;//只是算出优等品率,还有和产品质量区间进行匹配
  5590. decimal QualityWages = 0; //质量工价 ,用于最后计算相乘
  5591. decimal Quality = 0; //质量
  5592. if (QualityBaseProcedureCount != 0)
  5593. {
  5594. QualityBaseProcedureTotal = (QualityBaseProcedureCount - UnqualifiedCount) / QualityBaseProcedureCount;
  5595. }
  5596. //查看此员工是否为正式员工还是试用员工,如果试用取工价类别的标准工价
  5597. // 1取出此工类下的产品工价区间
  5598. DataRow[] drWages = dsWages.Tables[0].Select("WagesTypeID=" + dtWagesType.Rows[wagestype]["WagesTypeID"]);
  5599. decimal StandardWages = 0;
  5600. if (drWages.Length > 0)
  5601. {
  5602. StandardWages = Convert.ToDecimal(drWages[0]["StandardWages"]); //标准工价
  5603. }
  5604. if (dsJobsPayPlan.Tables[0].Rows[j]["ExProbationEndDate"].ToString() == "") //表示正式员工
  5605. {
  5606. // 2取出此工类下的质量区间
  5607. DataRow[] drQualityWages = dsQualityWages.Tables[0].Select("WagesTypeID=" + dtWagesType.Rows[wagestype]["WagesTypeID"] + " and QualityRate>=" + QualityBaseProcedureTotal);
  5608. if (drQualityWages.Length > 0)
  5609. {
  5610. //表示质量区间设置没有比优品率大的
  5611. QualityWages = StandardWages;
  5612. Quality = Convert.ToDecimal(drQualityWages[0]["QualityRate"]);
  5613. }
  5614. else
  5615. {
  5616. QualityWages = 0;// Convert.ToDecimal(drQualityWages[0]["QualityWages"]);
  5617. }
  5618. }
  5619. else
  5620. {
  5621. if (Convert.ToDateTime(dsJobsPayPlan.Tables[0].Rows[j]["ExProbationEndDate"]) < DateTime.Now)
  5622. {
  5623. // 试用结束结束
  5624. // 2取出此工类下的质量区间
  5625. DataRow[] drQualityWages = dsQualityWages.Tables[0].Select("WagesTypeID=" + dtWagesType.Rows[wagestype]["WagesTypeID"] + " and QualityRate>=" + QualityBaseProcedureTotal);
  5626. if (drQualityWages.Length > 0)
  5627. {
  5628. //表示质量区间设置没有比优品率大的
  5629. QualityWages = StandardWages;
  5630. Quality = Convert.ToDecimal(drQualityWages[0]["QualityRate"]);
  5631. }
  5632. else
  5633. {
  5634. QualityWages = 0;// Convert.ToDecimal(drQualityWages[0]["QualityWages"]);
  5635. }
  5636. }
  5637. }
  5638. #endregion
  5639. totalcount_Piecegiework += (PieceProcedureTotal - Scrap - UnqualifiedTotal - QualifiedTotal) * QualityWages;
  5640. temp_Piecegiework += (PieceProcedureTotal - Scrap - UnqualifiedTotal - QualifiedTotal) * QualityWages;
  5641. // }
  5642. #region 插入计件工资
  5643. sqlString = "select 1 from TP_PAR_Piecework where YYYYMM=:YYYYMM and StaffID=:StaffID and PayPlanID=:PayPlanID and WagesTypeID=:WagesTypeID";
  5644. parmeters1 = new OracleParameter[]
  5645. {
  5646. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  5647. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  5648. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  5649. new OracleParameter(":WagesTypeID",dtWagesType.Rows[wagestype]["WagesTypeID"]),
  5650. };
  5651. DataSet dsExistPiecework = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  5652. // 读取计件工资策略
  5653. int PieceTacticsID_Insert = 0;
  5654. sqlString = "select PieceTacticsID from TP_PAT_Piecework where PayPlanID=:PayPlanID";
  5655. parmeters1 = new OracleParameter[]
  5656. {
  5657. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  5658. };
  5659. DataSet dss = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  5660. if (dss != null && dss.Tables[0].Rows.Count > 0)
  5661. {
  5662. PieceTacticsID_Insert = Convert.ToInt32(dss.Tables[0].Rows[0]["PieceTacticsID"]);
  5663. }
  5664. //-------------------------------------
  5665. if (dsExistPiecework != null && dsExistPiecework.Tables[0].Rows.Count == 0)
  5666. {
  5667. sqlString = @"insert into TP_PAR_Piecework
  5668. (
  5669. YYYYMM,
  5670. StaffID,
  5671. PayPlanID,
  5672. StaffFlag,
  5673. GoodsFlag,
  5674. WagesTypeID,
  5675. PieceworkNum,
  5676. PieceCoefficient,
  5677. DamageNum,
  5678. DamageCoefficient,
  5679. UnqualifiedNum,
  5680. UnqualifiedCoefficient,
  5681. QualifiedNum,
  5682. QualifiedCoefficient,
  5683. QualityBaseNum,
  5684. QualityRate,
  5685. QualityWages,
  5686. Amount,
  5687. PieceTacticsID
  5688. ) values
  5689. (
  5690. :YYYYMM,
  5691. :StaffID,
  5692. :PayPlanID,
  5693. :StaffFlag,
  5694. :GoodsFlag,
  5695. :WagesTypeID,
  5696. :PieceworkNum,
  5697. :PieceCoefficient,
  5698. :DamageNum,
  5699. :DamageCoefficient,
  5700. :UnqualifiedNum,
  5701. :UnqualifiedCoefficient,
  5702. :QualifiedNum,
  5703. :QualifiedCoefficient,
  5704. :QualityBaseNum,
  5705. :QualityRate,
  5706. :QualityWages,
  5707. :Amount,
  5708. :PieceTacticsID
  5709. )";
  5710. }
  5711. else
  5712. {
  5713. sqlString = @"update TP_PAR_Piecework
  5714. set
  5715. YYYYMM=:YYYYMM,
  5716. StaffID=:StaffID,
  5717. PayPlanID=:PayPlanID,
  5718. StaffFlag=:StaffFlag,
  5719. PieceTacticsID=:PieceTacticsID,
  5720. GoodsFlag=:GoodsFlag,
  5721. WagesTypeID=:WagesTypeID,
  5722. PieceworkNum=PieceworkNum+:PieceworkNum,
  5723. PieceCoefficient=PieceCoefficient+:PieceCoefficient,
  5724. DamageNum=DamageNum+:DamageNum,
  5725. DamageCoefficient=DamageCoefficient+:DamageCoefficient,
  5726. UnqualifiedNum=UnqualifiedNum+:UnqualifiedNum,
  5727. UnqualifiedCoefficient=UnqualifiedCoefficient+:UnqualifiedCoefficient,
  5728. QualifiedNum=QualifiedNum+:QualifiedNum,
  5729. QualifiedCoefficient=QualifiedCoefficient+:QualifiedCoefficient,
  5730. QualityBaseNum=QualityBaseNum+:QualityBaseNum,
  5731. QualityRate=QualityRate+:QualityRate,
  5732. QualityWages=QualityWages+:QualityWages,
  5733. Amount=Amount+:Amount
  5734. where YYYYMM=:YYYYMM and StaffID=:StaffID and PayPlanID=:PayPlanID and WagesTypeID=:WagesTypeID
  5735. ";
  5736. }
  5737. parmeters1 = new OracleParameter[]
  5738. {
  5739. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  5740. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  5741. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  5742. new OracleParameter(":StaffFlag",dsJobsPayPlan.Tables[0].Rows[j]["StaffStatus"]),
  5743. //new OracleParameter(":BeginDate",dateStartTime),
  5744. //new OracleParameter(":EndDate",dateEndTime),
  5745. new OracleParameter(":GoodsFlag", dtGoodsFlag.Rows[vv]["GoodsFlag"]),
  5746. new OracleParameter(":WagesTypeID",dtWagesType.Rows[wagestype]["WagesTypeID"]),
  5747. //new OracleParameter(":GoodsID",null),
  5748. new OracleParameter(":PieceworkNum",PieceProcedureCount),
  5749. new OracleParameter(":PieceCoefficient",PieceCoefficient),
  5750. new OracleParameter(":DamageNum",ScrapCount),
  5751. new OracleParameter(":DamageCoefficient",DamageCoefficient),
  5752. new OracleParameter(":UnqualifiedNum",UnqualifiedCount),
  5753. new OracleParameter(":UnqualifiedCoefficient",UnqualifiedCoefficient),
  5754. new OracleParameter(":QualifiedNum",QualifiedCount),
  5755. new OracleParameter(":QualifiedCoefficient",QualifiedCoefficient),
  5756. new OracleParameter(":QualityBaseNum",QualityBaseProcedureCount),
  5757. new OracleParameter(":QualifiedCoefficient",QualifiedCoefficient),
  5758. new OracleParameter(":QualityRate",QualityBaseProcedureTotal),
  5759. new OracleParameter(":QualityWages",QualityWages),
  5760. new OracleParameter(":Amount",temp_Piecegiework),
  5761. new OracleParameter(":PieceTacticsID",PieceTacticsID_Insert),
  5762. };
  5763. intResult = oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  5764. #endregion
  5765. }
  5766. #region 损坯补贴
  5767. int scrapcount_1 = 0; //损坯数量
  5768. decimal scrap_StandardWages = 0; //损坯标准工价
  5769. decimal scrap_DamageSubsidyRate = 0; //损坯补贴系数
  5770. decimal scrap_DamageSubsidy = 0; //损坯补贴
  5771. decimal temp_Scrap = 0;// //最后损坯补贴钱
  5772. //1.查出此员工工号下所生产数据,即做过哪此产品条码
  5773. DataRow[] drScrapProduction = dsTMPProductionData.Tables[0].Select("UserID=" + dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString() + " and WagesTypeID=" + dtWagesType.Rows[wagestype]["WagesTypeID"]);
  5774. if (drScrapProduction.Length > 0)
  5775. {
  5776. //算出此工号,此工价分类存在条码,拼出条码,进而去报损查出非自身损坯的数量,进而计算
  5777. //string barcodes = "";
  5778. //foreach (DataRow rbarcode in drScrapProduction)
  5779. //{
  5780. // barcodes += rbarcode["barcode"].ToString() + ",";
  5781. //}
  5782. //barcodes = barcodes.Trim(',');
  5783. // string sql = @"select TMP_PAM_ScrapProduct.barcode,TMP_PAM_ResponProcedure.UserID from TMP_PAM_ScrapProduct left join TMP_PAM_ResponProcedure
  5784. // on TMP_PAM_ScrapProduct.ScrapProductID=TMP_PAM_ResponProcedure.ScrapProductID ";
  5785. // sql = sql + " where instr(','||:barcodes||',',','||TMP_PAM_ScrapProduct.BarCode||',')>0 ";
  5786. // sql = sql + " and TMP_PAM_ResponProcedure.UserID<>:UserID";
  5787. string sql = @"select distinct TMP_PAM_ScrapProduct.barcode,TMP_PAM_ResponProcedure.UserID from TMP_PAM_ScrapProduct left join TMP_PAM_ResponProcedure
  5788. on TMP_PAM_ScrapProduct.ScrapProductID=TMP_PAM_ResponProcedure.ScrapProductID ";
  5789. sql = sql + " where TMP_PAM_ScrapProduct.barcode in (select barcode from TMP_PAM_ProductionData where UserID=:UserID and ProcedureID in (select TP_PAT_PieceProcedure.ProcedureID from TP_PAT_Piecework left join TP_PAT_PieceProcedure on TP_PAT_Piecework.PieceTacticsID=TP_PAT_PieceProcedure.PieceTacticsID and TP_PAT_PieceProcedure.ProcedureFlag=1 where TP_PAT_Piecework.PayPlanID=:PayPlanID)) ";
  5790. sql = sql + " and TMP_PAM_ResponProcedure.UserID<>:UserID";
  5791. parmeters1 = new OracleParameter[]
  5792. {
  5793. //new OracleParameter(":barcodes",barcodes),
  5794. new OracleParameter(":UserID",dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString()),
  5795. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  5796. };
  5797. DataSet dsTemp = oracleTrConn.GetSqlResultToDs(sql, parmeters1);
  5798. if (dsTemp.Tables[0].Rows.Count > 0)
  5799. {
  5800. // 大于零遍历此表,插入损坯补贴记录表中,过滤给报损补贴后就不能给干补补贴
  5801. string sqlInsertDamageSubsidy = "insert into TP_PAD_DamageSubsidy(Barcode,userID) values(:Barcode,:UserID)";
  5802. for (int insert = 0; insert < dsTemp.Tables[0].Rows.Count; insert++)
  5803. {
  5804. string sqladd = "select 1 from TP_PAD_DamageSubsidy where barcode=:barcode and userid=:userid";
  5805. parmeters1 = new OracleParameter[]
  5806. {
  5807. new OracleParameter(":Barcode",dsTemp.Tables[0].Rows[insert]["Barcode"]),
  5808. new OracleParameter(":UserID",dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString()),
  5809. };
  5810. DataSet ds3 = oracleTrConn.GetSqlResultToDs(sqladd, parmeters1);
  5811. if (ds3 != null && ds3.Tables[0].Rows.Count == 0)
  5812. oracleTrConn.ExecuteNonQuery(sqlInsertDamageSubsidy, parmeters1);
  5813. }
  5814. scrapcount_1 = dsTemp.Tables[0].Rows.Count; //非自身损坯数量
  5815. // 求出损坯对应系数
  5816. DataRow[] drScrapWages = dsWages.Tables[0].Select("WagesTypeID=" + dtWagesType.Rows[wagestype]["WagesTypeID"]);
  5817. //decimal? scrapDamageSubsidy = 0; //损坯补贴
  5818. if (drScrapWages.Length > 0)
  5819. {
  5820. //scrapDamageSubsidy += Convert.ToDecimal(drScrapWages[0]["DamageSubsidy"]);
  5821. scrap_StandardWages = Convert.ToDecimal(drScrapWages[0]["StandardWages"]); //标准工价
  5822. scrap_DamageSubsidyRate = Convert.ToDecimal(drScrapWages[0]["DamageSubsidyRate"]);//损坯补贴系数
  5823. // scrap_DamageSubsidy = Convert.ToDecimal(drScrapWages[0]["DamageSubsidy"]); //损坯补贴
  5824. scrap_DamageSubsidy = Convert.ToDecimal(scrap_StandardWages) * scrap_DamageSubsidyRate; //损坯补贴
  5825. }
  5826. //totalcount_Scrap += scrapDamageSubsidy;
  5827. temp_Scrap = Convert.ToDecimal(scrapcount_1 * scrap_StandardWages * scrap_DamageSubsidyRate);
  5828. totalcount_Scrap += temp_Scrap;
  5829. }
  5830. }
  5831. #endregion
  5832. #region 插入损坯补贴
  5833. sqlString = "select 1 from TP_PAR_DamageSubsidy where YYYYMM=:YYYYMM and StaffID=:StaffID and PayPlanID=:PayPlanID and WagesTypeID=:WagesTypeID";
  5834. parmeters1 = new OracleParameter[]
  5835. {
  5836. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  5837. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  5838. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  5839. new OracleParameter(":WagesTypeID",dtWagesType.Rows[wagestype]["WagesTypeID"]),
  5840. };
  5841. // 读取计件工资策略
  5842. int PieceTacticsID_Insert2 = 0;
  5843. sqlString = "select PieceTacticsID from TP_PAT_Piecework where PayPlanID=:PayPlanID";
  5844. parmeters1 = new OracleParameter[]
  5845. {
  5846. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  5847. };
  5848. DataSet dss2 = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  5849. if (dss2 != null && dss2.Tables[0].Rows.Count > 0)
  5850. {
  5851. PieceTacticsID_Insert2 = Convert.ToInt32(dss2.Tables[0].Rows[0]["PieceTacticsID"]);
  5852. }
  5853. //-------------------------------------
  5854. DataSet dsExistDamageSubsidy = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  5855. if (dsExistDamageSubsidy != null && dsExistDamageSubsidy.Tables[0].Rows.Count == 0)
  5856. {
  5857. sqlString = @"insert into TP_PAR_DamageSubsidy
  5858. (
  5859. YYYYMM,
  5860. StaffID,
  5861. PayPlanID,
  5862. WagesTypeID,
  5863. DamageNum,
  5864. StandardWages,
  5865. DamageSubsidyRate,
  5866. DamageSubsidy,
  5867. Amount,
  5868. PieceTacticsID
  5869. ) values
  5870. (
  5871. :YYYYMM,
  5872. :StaffID,
  5873. :PayPlanID,
  5874. :WagesTypeID,
  5875. :DamageNum,
  5876. :StandardWages,
  5877. :DamageSubsidyRate,
  5878. :DamageSubsidy,
  5879. :Amount,
  5880. :PieceTacticsID
  5881. )";
  5882. }
  5883. else
  5884. {
  5885. sqlString = @"update TP_PAR_DamageSubsidy
  5886. set YYYYMM=:YYYYMM,
  5887. StaffID=StaffID,
  5888. PayPlanID=:PayPlanID,
  5889. WagesTypeID=:WagesTypeID,
  5890. DamageNum=DamageNum+:DamageNum,
  5891. StandardWages=StandardWages+:StandardWages,
  5892. DamageSubsidyRate=DamageSubsidyRate+:DamageSubsidyRate,
  5893. DamageSubsidy=DamageSubsidy+:DamageSubsidy,
  5894. Amount=Amount+:Amount,
  5895. PieceTacticsID=:PieceTacticsID
  5896. where YYYYMM=:YYYYMM and StaffID=:StaffID and PayPlanID=:PayPlanID and WagesTypeID=:WagesTypeID
  5897. ";
  5898. }
  5899. parmeters1 = new OracleParameter[]
  5900. {
  5901. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  5902. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  5903. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  5904. new OracleParameter(":WagesTypeID",dtWagesType.Rows[wagestype]["WagesTypeID"]),
  5905. new OracleParameter(":DamageNum",scrapcount_1),
  5906. new OracleParameter(":StandardWages",scrap_StandardWages),
  5907. new OracleParameter(":DamageSubsidyRate",scrap_DamageSubsidyRate),
  5908. new OracleParameter(":DamageSubsidy",scrap_DamageSubsidy),
  5909. new OracleParameter(":Amount",temp_Scrap),
  5910. new OracleParameter(":PieceTacticsID",PieceTacticsID_Insert2),
  5911. };
  5912. intResult = oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  5913. #endregion
  5914. #region 干补补贴,从成品表时读取数据来计算干补数量
  5915. // 1 查出这个工号的,这个分类的,下一面在去过滤正品,还是副品
  5916. int RepairSubsidy_RSuperioNum = 0;//干补正品数
  5917. // 干补正品数
  5918. DataRow[] drRepairSubsidy_RSuperioNum = dsFinishedProduct.Tables[0].Select("SpecialRepairFlag=1 and GoodsLevelTypeID=4 and WagesTypeID=" + dtWagesType.Rows[wagestype]["WagesTypeID"]);
  5919. if (drRepairSubsidy_RSuperioNum.Length > 0)
  5920. {
  5921. RepairSubsidy_RSuperioNum = drRepairSubsidy_RSuperioNum.Length;
  5922. // 尽管有干补,但是有可能在损坯补贴给了,此处得查询一下干补补贴表,如果存在就不给此补贴
  5923. foreach (DataRow mm in drRepairSubsidy_RSuperioNum)
  5924. {
  5925. sqlString = "select 1 from TP_PAD_DamageSubsidy where Barcode=:Barcode and UserID=:UserID";
  5926. parmeters1 = new OracleParameter[]
  5927. {
  5928. new OracleParameter(":Barcode",mm["barcode"].ToString()),
  5929. new OracleParameter(":UserID",dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString()),
  5930. };
  5931. DataSet dsTemp = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  5932. if (dsTemp.Tables[0].Rows.Count > 0)
  5933. {
  5934. RepairSubsidy_RSuperioNum = RepairSubsidy_RSuperioNum - 1;
  5935. }
  5936. }
  5937. }
  5938. int RepairSubsidy_RQualifiedNum = 0;//干补副品数
  5939. // 干补正品数
  5940. DataRow[] drRepairSubsidy_RQualifiedNum = dsFinishedProduct.Tables[0].Select("SpecialRepairFlag=1 and GoodsLevelTypeID=5 and WagesTypeID=" + dtWagesType.Rows[wagestype]["WagesTypeID"]);
  5941. if (drRepairSubsidy_RQualifiedNum.Length > 0)
  5942. {
  5943. RepairSubsidy_RQualifiedNum = drRepairSubsidy_RQualifiedNum.Length;
  5944. // 尽管有干补,但是有可能在损坯补贴给了,此处得查询一下干补补贴表,如果存在就不给此补贴
  5945. foreach (DataRow mm in drRepairSubsidy_RQualifiedNum)
  5946. {
  5947. sqlString = "select 1 from TP_PAD_DamageSubsidy where Barcode=:Barcode and UserID=:UserID";
  5948. parmeters1 = new OracleParameter[]
  5949. {
  5950. new OracleParameter(":Barcode",mm["barcode"].ToString()),
  5951. new OracleParameter(":UserID",dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString()),
  5952. };
  5953. DataSet dsTemp = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  5954. if (dsTemp.Tables[0].Rows.Count > 0)
  5955. {
  5956. RepairSubsidy_RQualifiedNum = RepairSubsidy_RQualifiedNum - 1;
  5957. }
  5958. }
  5959. }
  5960. // 查出此分类干补正负品补贴
  5961. // 求出损坯对应系数
  5962. DataRow[] drRepairSubsidy = dsWages.Tables[0].Select("WagesTypeID=" + dtWagesType.Rows[wagestype]["WagesTypeID"]);
  5963. decimal RSuperiorCoefficient = 0;//干补正品系数
  5964. decimal RQualifiedCoefficient = 0;//干补副品系数
  5965. decimal RepairSubsidyRate = 0;//干补补贴系数
  5966. decimal RepairStandardWages = 0;//标准工价
  5967. decimal RepairTotalCount = 0; //
  5968. decimal RepairSubsidy = 0;
  5969. decimal temp_Repair = 0;
  5970. if (drRepairSubsidy.Length > 0)
  5971. {
  5972. RSuperiorCoefficient = Convert.ToDecimal(drRepairSubsidy[0]["RSuperiorCoefficient"]);
  5973. RQualifiedCoefficient = Convert.ToDecimal(drRepairSubsidy[0]["RQualifiedCoefficient"]);
  5974. RepairSubsidyRate = Convert.ToDecimal(drRepairSubsidy[0]["RepairSubsidyRate"]);
  5975. RepairStandardWages = Convert.ToDecimal(drRepairSubsidy[0]["StandardWages"]);
  5976. RepairSubsidy = Convert.ToDecimal(drRepairSubsidy[0]["RepairSubsidy"]);
  5977. RepairTotalCount = (RepairSubsidy_RSuperioNum * RSuperiorCoefficient - RepairSubsidy_RQualifiedNum * RQualifiedCoefficient) * RepairStandardWages * RepairSubsidyRate;
  5978. totalcount_RepairSubsidy += RepairTotalCount;
  5979. temp_Repair = RepairTotalCount;
  5980. }
  5981. #endregion
  5982. #region 插入干补补贴
  5983. sqlString = "select 1 from TP_PAR_RepairSubsidy where YYYYMM=:YYYYMM and StaffID=:StaffID and PayPlanID=:PayPlanID and WagesTypeID=:WagesTypeID";
  5984. parmeters1 = new OracleParameter[]
  5985. {
  5986. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  5987. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  5988. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  5989. new OracleParameter(":WagesTypeID",dtWagesType.Rows[wagestype]["WagesTypeID"]),
  5990. };
  5991. // 读取计件工资策略
  5992. int PieceTacticsID_Insert3 = 0;
  5993. sqlString = "select PieceTacticsID from TP_PAT_Piecework where PayPlanID=:PayPlanID";
  5994. parmeters1 = new OracleParameter[]
  5995. {
  5996. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  5997. };
  5998. DataSet dss3 = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  5999. if (dss3 != null && dss3.Tables[0].Rows.Count > 0)
  6000. {
  6001. PieceTacticsID_Insert3 = Convert.ToInt32(dss3.Tables[0].Rows[0]["PieceTacticsID"]);
  6002. }
  6003. //-------------------------------------
  6004. DataSet dsExistRepairSubsidy = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  6005. if (dsExistRepairSubsidy != null && dsExistRepairSubsidy.Tables[0].Rows.Count == 0)
  6006. {
  6007. sqlString = @"insert into TP_PAR_RepairSubsidy
  6008. (
  6009. YYYYMM,
  6010. StaffID,
  6011. PayPlanID,
  6012. WagesTypeID,
  6013. RSuperioNum,
  6014. RSuperiorCoefficient,
  6015. RQualifiedNum,
  6016. RQualifiedCoefficient,
  6017. StandardWages,
  6018. RepairSubsidyRate,
  6019. RepairSubsidy,
  6020. Amount,
  6021. PieceTacticsID
  6022. ) values
  6023. (
  6024. :YYYYMM,
  6025. :StaffID,
  6026. :PayPlanID,
  6027. :WagesTypeID,
  6028. :RSuperioNum,
  6029. :RSuperiorCoefficient,
  6030. :RQualifiedNum,
  6031. :RQualifiedCoefficient,
  6032. :StandardWages,
  6033. :RepairSubsidyRate,
  6034. :RepairSubsidy,
  6035. :Amount,
  6036. :PieceTacticsID
  6037. )";
  6038. }
  6039. else
  6040. {
  6041. sqlString = @"update TP_PAR_RepairSubsidy
  6042. set
  6043. YYYYMM=:YYYYMM,
  6044. StaffID=:StaffID,
  6045. PayPlanID=:PayPlanID,
  6046. WagesTypeID=:WagesTypeID,
  6047. RSuperioNum=RSuperioNum+:RSuperioNum,
  6048. RSuperiorCoefficient=RSuperiorCoefficient+:RSuperiorCoefficient,
  6049. RQualifiedNum=RQualifiedNum+:RQualifiedNum,
  6050. RQualifiedCoefficient=RQualifiedCoefficient+:RQualifiedCoefficient,
  6051. StandardWages=StandardWages+:StandardWages,
  6052. RepairSubsidyRate=RepairSubsidyRate+:RepairSubsidyRate,
  6053. RepairSubsidy=RepairSubsidy+:RepairSubsidy,
  6054. Amount=Amount+:Amount,
  6055. PieceTacticsID=:PieceTacticsID
  6056. where YYYYMM=:YYYYMM and StaffID=:StaffID and PayPlanID=:PayPlanID and WagesTypeID=:WagesTypeID
  6057. ";
  6058. }
  6059. parmeters1 = new OracleParameter[]
  6060. {
  6061. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  6062. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  6063. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  6064. new OracleParameter(":WagesTypeID",dtWagesType.Rows[wagestype]["WagesTypeID"]),
  6065. new OracleParameter(":RSuperioNum",RepairSubsidy_RSuperioNum),
  6066. new OracleParameter(":RSuperiorCoefficient",RSuperiorCoefficient),
  6067. new OracleParameter(":RQualifiedNum",RepairSubsidy_RQualifiedNum),
  6068. new OracleParameter(":RQualifiedCoefficient",RQualifiedCoefficient),
  6069. new OracleParameter(":StandardWages",RepairStandardWages),
  6070. new OracleParameter(":RepairSubsidyRate",RepairSubsidyRate),
  6071. new OracleParameter(":RepairSubsidy",RepairSubsidy),
  6072. new OracleParameter(":Amount",temp_Repair),
  6073. new OracleParameter(":PieceTacticsID",PieceTacticsID_Insert3),
  6074. };
  6075. intResult = oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  6076. #endregion
  6077. }
  6078. }
  6079. }
  6080. else
  6081. {
  6082. // 经过该计件工序
  6083. // 先找出此工序的所有条码.用于筛选条码前的数据
  6084. dsPieceProcedure_1.Tables[0].Merge(dsPieceProcedure_2.Tables[0]);
  6085. string ProcedureIDS = "";
  6086. for (int a1 = 0; a1 < dsPieceProcedure_1.Tables[0].Rows.Count; a1++)
  6087. {
  6088. ProcedureIDS += dsPieceProcedure_1.Tables[0].Rows[a1]["ProcedureID"].ToString() + ",";
  6089. }
  6090. ProcedureIDS = ProcedureIDS.Trim(',');
  6091. //DataRow[] drBarCode = dsTMPProductionData.Tables[0].Select("(ProcedureID=" + PieceProcedureID + " or ProcedureID=" + QualityBaseProcedureID + ") and UserID=" + dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString());
  6092. DataRow[] drBarCode = dsTMPProductionData.Tables[0].Select("ProcedureID in (" + ProcedureIDS + " )" + " and UserID=" + dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString());
  6093. DataTable dtTemp = new DataTable();
  6094. dtTemp.Columns.Add("ProcedureID"); //工序ID,用于有哪些分类
  6095. dtTemp.Columns.Add("BarCode"); //产品条码
  6096. dtTemp.Columns.Add("WagesTypeID"); // 工价分类
  6097. dtTemp.Columns.Add("GoodsFlag"); //产品标识
  6098. DataRow[] drMonth = dsPayPlanSetting.Tables[0].Select("SettingCode='01001'");
  6099. int newGoodsMonth = Convert.ToInt32(drMonth[0]["SettingValue"]); //新产品适应周期(月)
  6100. if (drBarCode.Length > 0)
  6101. {
  6102. DataTable dtTemp_TMPProductionData = drBarCode.CopyToDataTable();
  6103. foreach (DataRow r in drBarCode)
  6104. {
  6105. DataRow[] drFirst = dtTemp_TMPProductionData.Select("barcode='" + r["barcode"] + "' and ProductionDataID<" + r["ProductionDataID"] + " and UserID=" + dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString());
  6106. if (drFirst.Length > 0)
  6107. {
  6108. foreach (DataRow rr in drFirst)//可能会多行,
  6109. {
  6110. DataRow drNew = dtTemp.NewRow();
  6111. drNew["ProcedureID"] = rr["ProcedureID"];
  6112. drNew["BarCode"] = rr["BarCode"];
  6113. drNew["WagesTypeID"] = rr["WagesTypeID"];
  6114. if (Convert.ToDateTime(rr["StartingDate"]).AddMonths(newGoodsMonth) > DateTime.Now)
  6115. {
  6116. drNew["GoodsFlag"] = 3; //正常
  6117. }
  6118. else
  6119. {
  6120. drNew["GoodsFlag"] = 1; //新品
  6121. }
  6122. dtTemp.Rows.Add(drNew);
  6123. }
  6124. }
  6125. }
  6126. }
  6127. if (dtTemp.Rows.Count > 0)
  6128. {
  6129. //-----------------------------------
  6130. // 1.算出是否有新品,还是老品
  6131. //3 报损责任工序
  6132. if (!dsTMPResponProcedure.Tables[0].Columns.Contains("GoodsFlag"))
  6133. {
  6134. dsTMPResponProcedure.Tables[0].Columns.Add("GoodsFlag");
  6135. for (int bb = 0; bb < dsTMPResponProcedure.Tables[0].Rows.Count; bb++)
  6136. {
  6137. if (dsTMPResponProcedure.Tables[0].Rows[bb]["StartingDate"].ToString() != "")
  6138. {
  6139. if (Convert.ToDateTime(dsTMPResponProcedure.Tables[0].Rows[bb]["StartingDate"]).AddMonths(newGoodsMonth) > DateTime.Now)
  6140. {
  6141. dsTMPResponProcedure.Tables[0].Rows[bb]["GoodsFlag"] = 3; //正常
  6142. }
  6143. else
  6144. {
  6145. dsTMPResponProcedure.Tables[0].Rows[bb]["GoodsFlag"] = 1; //新品
  6146. }
  6147. }
  6148. else
  6149. {
  6150. dsTMPResponProcedure.Tables[0].Rows[bb]["GoodsFlag"] = 3; //正常
  6151. }
  6152. }
  6153. }
  6154. //for (int bb = 0; bb < dsTMPResponProcedure.Tables[0].Rows.Count; bb++)
  6155. //{
  6156. // if (dsTMPResponProcedure.Tables[0].Rows[bb]["StartingDate"].ToString() != "")
  6157. // {
  6158. // if (Convert.ToDateTime(dsTMPResponProcedure.Tables[0].Rows[bb]["StartingDate"]).AddMonths(newGoodsMonth) > DateTime.Now)
  6159. // {
  6160. // dsTMPResponProcedure.Tables[0].Rows[bb]["GoodsFlag"] = 3; //正常
  6161. // }
  6162. // else
  6163. // {
  6164. // dsTMPResponProcedure.Tables[0].Rows[bb]["GoodsFlag"] = 1; //新品
  6165. // }
  6166. // }
  6167. // else
  6168. // {
  6169. // dsTMPResponProcedure.Tables[0].Rows[bb]["GoodsFlag"] = 3; //正常
  6170. // }
  6171. //}
  6172. //-----------------------------------
  6173. // 重新排序,把生产数据ID大的排在上面,便于下面进行筛选
  6174. DataView dv = dtTemp.DefaultView;
  6175. dv.Sort = "ProductionDataID desc";
  6176. dtTemp = dv.ToTable();
  6177. // 此时dtTemp有产品分类,同时也可能有多个工序
  6178. // 1看有多少个分类
  6179. DataTable dtWagesType = dtTemp.DefaultView.ToTable(true, "WagesTypeID");
  6180. // 2看有多少个工序
  6181. DataTable dtProcedure = dtTemp.DefaultView.ToTable(true, "ProcedureID");
  6182. // 有多少产品标识
  6183. DataTable dtGoodsFlag = dtTemp.DefaultView.ToTable(true, "GoodsFlag");
  6184. int PieceProcedureCount2 = 0;
  6185. int UnqualifiedCount2 = 0;
  6186. int QualifiedCount2 = 0;
  6187. int QualityBaseProcedureCount2 = 0;
  6188. for (int ii = 0; ii < dtWagesType.Rows.Count; ii++)
  6189. {
  6190. for (int vv = 0; vv < dtGoodsFlag.Rows.Count; vv++)
  6191. {
  6192. decimal? temp_Piecegiework = 0;
  6193. #region 1.求出各分类计件工序数量
  6194. PieceProcedureCount2 = 0;
  6195. QualityBaseProcedureCount2 = 0;
  6196. decimal PieceProcedureTotal = 0; //系数*数量
  6197. //for (int jj = 0; jj < dtProcedure.Rows.Count; jj++)
  6198. //{
  6199. for (int p1 = 0; p1 < dsPieceProcedure_1.Tables[0].Rows.Count; p1++)
  6200. {
  6201. DataRow[] datarow = dtTemp.Select("WagesTypeID=" + dtWagesType.Rows[ii]["WagesTypeID"] + " and ProcedureID=" + dsPieceProcedure_1.Tables[0].Rows[p1]["ProcedureID"]);
  6202. if (datarow.Length > 0)
  6203. {
  6204. PieceProcedureCount2 += datarow.Length;
  6205. break;
  6206. }
  6207. else
  6208. {
  6209. continue;
  6210. }
  6211. }
  6212. //}
  6213. PieceProcedureTotal = PieceProcedureCount2 * PieceCoefficient;
  6214. #endregion 1.求出各分类计件工序数量
  6215. #region 2.求出各工价分类损坯数量
  6216. int ScrapCount = 0; //损坯数量
  6217. decimal? Scrap = 0; //每个类别损坯的值
  6218. if (DamageFlag == "1") //计算损坯数量
  6219. {
  6220. // 查出此人在计件工序的条码,完事关联报损表存在多少报损条码
  6221. string ProcedureIDS2 = "0"; //默认给个0,怕没有些去进行筛选出现错误
  6222. for (int p1 = 0; p1 < dsPieceProcedure_1.Tables[0].Rows.Count; p1++)
  6223. {
  6224. ProcedureIDS2 = ProcedureIDS2 + dsPieceProcedure_1.Tables[0].Rows[p1]["ProcedureID"].ToString() + ",";
  6225. }
  6226. ProcedureIDS2 = ProcedureIDS2.Trim(',');
  6227. // 筛选出生产数据这几个工序所用的条码
  6228. DataRow[] dr_BarCode = dsTMPProductionData.Tables[0].Select(string.Format("UserID={0} and ProcedureID in ({1}) and WagesTypeID={2} and GoodsFlag={3}", dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString(), ProcedureIDS2, dtWagesType.Rows[ii]["WagesTypeID"], dtGoodsFlag.Rows[vv]["GoodsFlag"]));
  6229. if (dr_BarCode.Length > 0)
  6230. {
  6231. string temp_barcode = "";
  6232. foreach (DataRow r3 in dr_BarCode)
  6233. {
  6234. DataRow[] dr2 = dsTMPResponProcedure.Tables[0].Select("barcode='" + r3["barcode"] + "'");
  6235. if (dr2.Length > 0)
  6236. {
  6237. if (!temp_barcode.Contains(r3["barcode"].ToString()))
  6238. {
  6239. // 有损坯数据
  6240. ScrapCount = ScrapCount + 1;
  6241. }
  6242. temp_barcode += r3["barcode"].ToString() + ",";
  6243. }
  6244. }
  6245. }
  6246. // end
  6247. Scrap = ScrapCount * DamageCoefficient; //DamageCoefficient为损坯系数
  6248. }
  6249. #endregion 2.求出损坯数量 end
  6250. #region 3.求出各工价分类次品数
  6251. // 筛出产品分级为次品的生产数据,完事一个一个去查对应责任工号的,进行累加
  6252. DataRow[] drUnqualifiedCount = dsTMPProductionData.Tables[0]
  6253. .Select(string.Format("WagesTypeID={0} and GoodsLevelTypeID=7 and GoodsFlag={1} ", dtWagesType.Rows[ii]["WagesTypeID"], dtGoodsFlag.Rows[vv]["GoodsFlag"]));
  6254. UnqualifiedCount2 = 0; //次品数量
  6255. decimal? UnqualifiedTotal = 0;//系数*数量
  6256. if (drUnqualifiedCount.Length > 0)
  6257. {
  6258. // 表示有次品,但是得对应责任工号,进行累加
  6259. foreach (DataRow row in drUnqualifiedCount)
  6260. {
  6261. string sqlView = "select 1 from TMP_PAM_Defect where DefectUserID=" + dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString() + " and ProductionDataID=" + row["ProductionDataID"];
  6262. DataSet ds = oracleTrConn.GetSqlResultToDs(sqlView);
  6263. if (ds != null && ds.Tables[0].Rows.Count > 0)
  6264. {
  6265. // 多个缺陷也算一个数,所以直接+1
  6266. UnqualifiedCount2 = UnqualifiedCount2 + 1;
  6267. }
  6268. }
  6269. UnqualifiedTotal = UnqualifiedCount2 * UnqualifiedCoefficient;
  6270. }
  6271. #endregion
  6272. #region 4.求出各工价分类副品数
  6273. // 筛出产品分级为副品的生产数据,完事一个一个去查对应责任工号的,进行累加
  6274. DataRow[] drQualified = dsTMPProductionData.Tables[0]
  6275. .Select(string.Format("WagesTypeID={0} and GoodsLevelTypeID=5 and GoodsFlag={1}", dtWagesType.Rows[ii]["WagesTypeID"], dtGoodsFlag.Rows[vv]["GoodsFlag"]));
  6276. QualifiedCount2 = 0; //副品数量
  6277. decimal? QualifiedTotal = 0;//系数*数量
  6278. if (drQualified.Length > 0)
  6279. {
  6280. // 表示有副品,但是得对应责任工号,进行累加
  6281. foreach (DataRow row in drQualified)
  6282. {
  6283. string sqlView = "select 1 from TMP_PAM_Defect where DefectUserID=" + dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString() + " and ProductionDataID=" + row["ProductionDataID"];
  6284. DataSet ds = oracleTrConn.GetSqlResultToDs(sqlView);
  6285. if (ds != null && ds.Tables[0].Rows.Count > 0)
  6286. {
  6287. // 多个缺陷也算一个数,所以直接+1
  6288. QualifiedCount2 = QualifiedCount2 + 1;
  6289. }
  6290. }
  6291. QualifiedTotal = QualifiedCount2 * QualifiedCoefficient;
  6292. }
  6293. #endregion 求出各工价分类副品数
  6294. #region 5.求出质量工价
  6295. string barcodes_Procedure = "";
  6296. QualityBaseProcedureCount2 = 0;
  6297. for (int p1 = 0; p1 < dsPieceProcedure_2.Tables[0].Rows.Count; p1++)
  6298. {
  6299. //DataRow[] drQualityBaseProcedure = dsTMPProductionData.Tables[0]
  6300. // .Select(string.Format("UserID={0} and ProcedureID={1} and WagesTypeID={2} and GoodsFlag={3}", dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString(), dsPieceProcedure_2.Tables[0].Rows[p1]["ProcedureID"], dtWagesType.Rows[wagestype]["WagesTypeID"], dtGoodsFlag.Rows[vv]["GoodsFlag"]));
  6301. //QualityBaseProcedureCount += drQualityBaseProcedure.Length; // 质量工序数量
  6302. //DataRow[] drQualityBaseProcedure = dsTMPProductionData.Tables[0]
  6303. // .Select(string.Format("ProcedureID={0} and WagesTypeID={1} and GoodsFlag={2}", dsPieceProcedure_2.Tables[0].Rows[p1]["ProcedureID"], dtWagesType.Rows[wagestype]["WagesTypeID"], dtGoodsFlag.Rows[vv]["GoodsFlag"]));
  6304. DataRow[] drQualityBaseProcedure = dsTMPProductionData.Tables[0]
  6305. .Select(string.Format("ProcedureID={0} and WagesTypeID={1}", dsPieceProcedure_2.Tables[0].Rows[p1]["ProcedureID"], dtWagesType.Rows[ii]["WagesTypeID"]));
  6306. if (drQualityBaseProcedure.Length > 0)
  6307. {
  6308. foreach (DataRow r4 in drQualityBaseProcedure)
  6309. {
  6310. if (!barcodes_Procedure.Contains(r4["barcode"].ToString()))
  6311. {
  6312. QualityBaseProcedureCount2 += 1; // 质量工序数量
  6313. }
  6314. barcodes_Procedure = barcodes_Procedure + r4["barcode"].ToString() + ",";
  6315. }
  6316. }
  6317. }
  6318. decimal QualityBaseProcedureTotal = 0;//只是算出优等品率,还有和产品质量区间进行匹配
  6319. decimal QualityWages = 0; //质量工价 ,用于最后计算相乘
  6320. decimal Quality = 0; //质量
  6321. if (QualityBaseProcedureCount2 != 0)
  6322. {
  6323. QualityBaseProcedureTotal = (QualityBaseProcedureCount2 - UnqualifiedCount2) / QualityBaseProcedureCount2;
  6324. }
  6325. //查看此员工是否为正式员工还是试用员工,如果试用取工价类别的标准工价
  6326. // 1取出此工类下的产品工价区间
  6327. DataRow[] drWages = dsWages.Tables[0].Select("WagesTypeID=" + dtWagesType.Rows[ii]["WagesTypeID"]);
  6328. decimal StandardWages = 0;
  6329. if (drWages.Length > 0)
  6330. {
  6331. StandardWages = Convert.ToDecimal(drWages[0]["StandardWages"]); //标准工价
  6332. }
  6333. if (dsJobsPayPlan.Tables[0].Rows[j]["ExProbationEndDate"].ToString() == "") //表示正式员工
  6334. {
  6335. // 2取出此工类下的质量区间
  6336. DataRow[] drQualityWages = dsQualityWages.Tables[0].Select("WagesTypeID=" + dtWagesType.Rows[ii]["WagesTypeID"] + " and QualityRate>=" + QualityBaseProcedureTotal);
  6337. if (drQualityWages.Length > 0)
  6338. {
  6339. //表示质量区间设置没有比优品率大的
  6340. QualityWages = StandardWages;
  6341. Quality = Convert.ToDecimal(drQualityWages[0]["QualityRate"]);
  6342. }
  6343. else
  6344. {
  6345. QualityWages = 0;// Convert.ToDecimal(drQualityWages[0]["QualityWages"]);
  6346. }
  6347. }
  6348. else
  6349. {
  6350. if (Convert.ToDateTime(dsJobsPayPlan.Tables[0].Rows[j]["ExProbationEndDate"]) < DateTime.Now)
  6351. {
  6352. // 试用结束结束
  6353. // 2取出此工类下的质量区间
  6354. DataRow[] drQualityWages = dsQualityWages.Tables[0].Select("WagesTypeID=" + dtWagesType.Rows[ii]["WagesTypeID"] + " and QualityRate>=" + QualityBaseProcedureTotal);
  6355. if (drQualityWages.Length > 0)
  6356. {
  6357. //表示质量区间设置没有比优品率大的
  6358. QualityWages = StandardWages;
  6359. Quality = Convert.ToDecimal(drQualityWages[0]["QualityRate"]);
  6360. }
  6361. else
  6362. {
  6363. QualityWages = 0;// Convert.ToDecimal(drQualityWages[0]["QualityWages"]);
  6364. }
  6365. }
  6366. }
  6367. #endregion
  6368. totalcount_Piecegiework += (PieceProcedureTotal - Scrap - UnqualifiedTotal - QualifiedTotal) * QualityWages;
  6369. temp_Piecegiework = (PieceProcedureTotal - Scrap - UnqualifiedTotal - QualifiedTotal) * QualityWages;
  6370. #region 插入计件工资
  6371. sqlString = "select 1 from TP_PAR_Piecework where YYYYMM=:YYYYMM and StaffID=:StaffID and PayPlanID=:PayPlanID and WagesTypeID=:WagesTypeID";
  6372. parmeters1 = new OracleParameter[]
  6373. {
  6374. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  6375. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  6376. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  6377. new OracleParameter(":WagesTypeID",dtWagesType.Rows[ii]["WagesTypeID"]),
  6378. };
  6379. DataSet dsExistPiecework = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  6380. // 读取计件工资策略
  6381. int PieceTacticsID_Insert = 0;
  6382. sqlString = "select PieceTacticsID from TP_PAT_Piecework where PayPlanID=:PayPlanID";
  6383. parmeters1 = new OracleParameter[]
  6384. {
  6385. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  6386. };
  6387. DataSet dss = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  6388. if (dss != null && dss.Tables[0].Rows.Count > 0)
  6389. {
  6390. PieceTacticsID_Insert = Convert.ToInt32(dss.Tables[0].Rows[0]["PieceTacticsID"]);
  6391. }
  6392. //-------------------------------------
  6393. if (dsExistPiecework != null && dsExistPiecework.Tables[0].Rows.Count == 0)
  6394. {
  6395. sqlString = @"insert into TP_PAR_Piecework
  6396. (
  6397. YYYYMM,
  6398. StaffID,
  6399. PayPlanID,
  6400. StaffFlag,
  6401. GoodsFlag,
  6402. WagesTypeID,
  6403. PieceworkNum,
  6404. PieceCoefficient,
  6405. DamageNum,
  6406. DamageCoefficient,
  6407. UnqualifiedNum,
  6408. UnqualifiedCoefficient,
  6409. QualifiedNum,
  6410. QualifiedCoefficient,
  6411. QualityBaseNum,
  6412. QualityRate,
  6413. QualityWages,
  6414. Amount,
  6415. PieceTacticsID
  6416. ) values
  6417. (
  6418. :YYYYMM,
  6419. :StaffID,
  6420. :PayPlanID,
  6421. :StaffFlag,
  6422. :GoodsFlag,
  6423. :WagesTypeID,
  6424. :PieceworkNum,
  6425. :PieceCoefficient,
  6426. :DamageNum,
  6427. :DamageCoefficient,
  6428. :UnqualifiedNum,
  6429. :UnqualifiedCoefficient,
  6430. :QualifiedNum,
  6431. :QualifiedCoefficient,
  6432. :QualityBaseNum,
  6433. :QualityRate,
  6434. :QualityWages,
  6435. :Amount,
  6436. :PieceTacticsID
  6437. )";
  6438. }
  6439. else
  6440. {
  6441. sqlString = @"update TP_PAR_Piecework
  6442. set
  6443. YYYYMM=:YYYYMM,
  6444. StaffID=:StaffID,
  6445. PayPlanID=:PayPlanID,
  6446. StaffFlag=:StaffFlag,
  6447. PieceTacticsID=:PieceTacticsID,
  6448. GoodsFlag=:GoodsFlag,
  6449. WagesTypeID=:WagesTypeID,
  6450. PieceworkNum=PieceworkNum+:PieceworkNum,
  6451. PieceCoefficient=PieceCoefficient+:PieceCoefficient,
  6452. DamageNum=DamageNum+:DamageNum,
  6453. DamageCoefficient=DamageCoefficient+:DamageCoefficient,
  6454. UnqualifiedNum=UnqualifiedNum+:UnqualifiedNum,
  6455. UnqualifiedCoefficient=UnqualifiedCoefficient+:UnqualifiedCoefficient,
  6456. QualifiedNum=QualifiedNum+:QualifiedNum,
  6457. QualifiedCoefficient=QualifiedCoefficient+:QualifiedCoefficient,
  6458. QualityBaseNum=QualityBaseNum+:QualityBaseNum,
  6459. QualityRate=QualityRate+:QualityRate,
  6460. QualityWages=QualityWages+:QualityWages,
  6461. Amount=Amount+:Amount
  6462. where YYYYMM=:YYYYMM and StaffID=:StaffID and PayPlanID=:PayPlanID and WagesTypeID=:WagesTypeID
  6463. ";
  6464. }
  6465. parmeters1 = new OracleParameter[]
  6466. {
  6467. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  6468. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  6469. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  6470. new OracleParameter(":StaffFlag",dsJobsPayPlan.Tables[0].Rows[j]["StaffStatus"]),
  6471. //new OracleParameter(":BeginDate",dateStartTime),
  6472. //new OracleParameter(":EndDate",dateEndTime),
  6473. new OracleParameter(":GoodsFlag", dtGoodsFlag.Rows[vv]["GoodsFlag"]),
  6474. new OracleParameter(":WagesTypeID",dtWagesType.Rows[ii]["WagesTypeID"]),
  6475. //new OracleParameter(":GoodsID",null),
  6476. new OracleParameter(":PieceworkNum",PieceProcedureCount2),
  6477. new OracleParameter(":PieceCoefficient",PieceCoefficient),
  6478. new OracleParameter(":DamageNum",ScrapCount),
  6479. new OracleParameter(":DamageCoefficient",DamageCoefficient),
  6480. new OracleParameter(":UnqualifiedNum",UnqualifiedCount2),
  6481. new OracleParameter(":UnqualifiedCoefficient",UnqualifiedCoefficient),
  6482. new OracleParameter(":QualifiedNum",QualifiedCount2),
  6483. new OracleParameter(":QualifiedCoefficient",QualifiedCoefficient),
  6484. new OracleParameter(":QualityBaseNum",QualityBaseProcedureCount2),
  6485. new OracleParameter(":QualifiedCoefficient",QualifiedCoefficient),
  6486. new OracleParameter(":QualityRate",QualityBaseProcedureTotal),
  6487. new OracleParameter(":QualityWages",QualityWages),
  6488. new OracleParameter(":Amount",temp_Piecegiework),
  6489. new OracleParameter(":PieceTacticsID",PieceTacticsID_Insert),
  6490. };
  6491. intResult = oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  6492. #endregion
  6493. }
  6494. #region 损坯补贴
  6495. int scrapcount_1 = 0; //损坯数量
  6496. decimal scrap_StandardWages = 0; //损坯标准工价
  6497. decimal scrap_DamageSubsidyRate = 0; //损坯补贴系数
  6498. decimal scrap_DamageSubsidy = 0; //损坯补贴
  6499. decimal temp_Scrap = 0;// //最后损坯补贴钱
  6500. //1.查出此员工工号下所生产数据,即做过哪此产品条码
  6501. DataRow[] drScrapProduction = dsTMPProductionData.Tables[0].Select("UserID=" + dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString() + " and WagesTypeID=" + dtWagesType.Rows[ii]["WagesTypeID"]);
  6502. if (drScrapProduction.Length > 0)
  6503. {
  6504. //算出此工号,此工价分类存在条码,拼出条码,进而去报损查出非自身损坯的数量,进而计算
  6505. string barcodes = "";
  6506. foreach (DataRow rbarcode in drScrapProduction)
  6507. {
  6508. barcodes += rbarcode["barcode"].ToString() + ",";
  6509. }
  6510. barcodes = barcodes.Trim(',');
  6511. // string sql = @"select TMP_PAM_ScrapProduct.barcode,TMP_PAM_ResponProcedure.UserID from TMP_PAM_ScrapProduct left join TMP_PAM_ResponProcedure
  6512. // on TMP_PAM_ScrapProduct.ScrapProductID=TMP_PAM_ResponProcedure.ScrapProductID ";
  6513. // sql = sql + " where instr(','||:barcodes||',',','||TMP_PAM_ScrapProduct.BarCode||',')>0 ";
  6514. // sql = sql + " and TMP_PAM_ResponProcedure.UserID<>:UserID";
  6515. string sql = @"select distinct TMP_PAM_ScrapProduct.barcode,TMP_PAM_ResponProcedure.UserID from TMP_PAM_ScrapProduct left join TMP_PAM_ResponProcedure
  6516. on TMP_PAM_ScrapProduct.ScrapProductID=TMP_PAM_ResponProcedure.ScrapProductID ";
  6517. sql = sql + " where TMP_PAM_ScrapProduct.barcode in (select barcode from TMP_PAM_ProductionData where UserID=:UserID and ProcedureID in (select TP_PAT_PieceProcedure.ProcedureID from TP_PAT_Piecework left join TP_PAT_PieceProcedure on TP_PAT_Piecework.PieceTacticsID=TP_PAT_PieceProcedure.PieceTacticsID and TP_PAT_PieceProcedure.ProcedureFlag=1 where TP_PAT_Piecework.PayPlanID=:PayPlanID)) ";
  6518. sql = sql + " and TMP_PAM_ResponProcedure.UserID<>:UserID";
  6519. parmeters1 = new OracleParameter[]
  6520. {
  6521. //new OracleParameter(":barcodes",barcodes),
  6522. new OracleParameter(":UserID",dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString()),
  6523. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  6524. };
  6525. DataSet dsTemp = oracleTrConn.GetSqlResultToDs(sql, parmeters1);
  6526. if (dsTemp.Tables[0].Rows.Count > 0)
  6527. {
  6528. // 大于零遍历此表,插入损坯补贴记录表中,过滤给报损补贴后就不能给干补补贴
  6529. string sqlInsertDamageSubsidy = "insert into TP_PAD_DamageSubsidy(Barcode,userID) values(:Barcode,:UserID)";
  6530. for (int insert = 0; insert < dsTemp.Tables[0].Rows.Count; insert++)
  6531. {
  6532. string sqladd = "select 1 from TP_PAD_DamageSubsidy where barcode=:barcode and userid=:userid";
  6533. parmeters1 = new OracleParameter[]
  6534. {
  6535. new OracleParameter(":Barcode",dsTemp.Tables[0].Rows[insert]["Barcode"]),
  6536. new OracleParameter(":UserID",dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString()),
  6537. };
  6538. DataSet ds3 = oracleTrConn.GetSqlResultToDs(sqladd, parmeters1);
  6539. if (ds3 != null && ds3.Tables[0].Rows.Count == 0)
  6540. oracleTrConn.ExecuteNonQuery(sqlInsertDamageSubsidy, parmeters1);
  6541. }
  6542. scrapcount_1 = dsTemp.Tables[0].Rows.Count; //非自身损坯数量
  6543. // 求出损坯对应系数
  6544. DataRow[] drScrapWages = dsWages.Tables[0].Select("WagesTypeID=" + dtWagesType.Rows[ii]["WagesTypeID"]);
  6545. //decimal? scrapDamageSubsidy = 0; //损坯补贴
  6546. if (drScrapWages.Length > 0)
  6547. {
  6548. //scrapDamageSubsidy += Convert.ToDecimal(drScrapWages[0]["DamageSubsidy"]);
  6549. scrap_StandardWages = Convert.ToDecimal(drScrapWages[0]["StandardWages"]); //标准工价
  6550. scrap_DamageSubsidyRate = Convert.ToDecimal(drScrapWages[0]["DamageSubsidyRate"]);//损坯补贴系数
  6551. //scrap_DamageSubsidy = Convert.ToDecimal(drScrapWages[0]["DamageSubsidy"]); //损坯补贴
  6552. scrap_DamageSubsidy = Convert.ToDecimal(scrap_StandardWages) * scrap_DamageSubsidyRate; //损坯补贴
  6553. }
  6554. //totalcount_Scrap += scrapDamageSubsidy;
  6555. temp_Scrap = Convert.ToDecimal(scrapcount_1 * scrap_StandardWages * scrap_DamageSubsidyRate);
  6556. totalcount_Scrap += temp_Scrap;
  6557. }
  6558. }
  6559. #endregion
  6560. #region 插入损坯补贴
  6561. sqlString = "select 1 from TP_PAR_DamageSubsidy where YYYYMM=:YYYYMM and StaffID=:StaffID and PayPlanID=:PayPlanID and WagesTypeID=:WagesTypeID";
  6562. parmeters1 = new OracleParameter[]
  6563. {
  6564. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  6565. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  6566. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  6567. new OracleParameter(":WagesTypeID",dtWagesType.Rows[ii]["WagesTypeID"]),
  6568. };
  6569. // 读取计件工资策略
  6570. int PieceTacticsID_Insert2 = 0;
  6571. sqlString = "select PieceTacticsID from TP_PAT_Piecework where PayPlanID=:PayPlanID";
  6572. parmeters1 = new OracleParameter[]
  6573. {
  6574. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  6575. };
  6576. DataSet dss2 = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  6577. if (dss2 != null && dss2.Tables[0].Rows.Count > 0)
  6578. {
  6579. PieceTacticsID_Insert2 = Convert.ToInt32(dss2.Tables[0].Rows[0]["PieceTacticsID"]);
  6580. }
  6581. //-------------------------------------
  6582. DataSet dsExistDamageSubsidy = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  6583. if (dsExistDamageSubsidy != null && dsExistDamageSubsidy.Tables[0].Rows.Count == 0)
  6584. {
  6585. sqlString = @"insert into TP_PAR_DamageSubsidy
  6586. (
  6587. YYYYMM,
  6588. StaffID,
  6589. PayPlanID,
  6590. WagesTypeID,
  6591. DamageNum,
  6592. StandardWages,
  6593. DamageSubsidyRate,
  6594. DamageSubsidy,
  6595. Amount,
  6596. PieceTacticsID
  6597. ) values
  6598. (
  6599. :YYYYMM,
  6600. :StaffID,
  6601. :PayPlanID,
  6602. :WagesTypeID,
  6603. :DamageNum,
  6604. :StandardWages,
  6605. :DamageSubsidyRate,
  6606. :DamageSubsidy,
  6607. :Amount,
  6608. :PieceTacticsID
  6609. )";
  6610. }
  6611. else
  6612. {
  6613. sqlString = @"update TP_PAR_DamageSubsidy
  6614. set YYYYMM=:YYYYMM,
  6615. StaffID=StaffID,
  6616. PayPlanID=:PayPlanID,
  6617. WagesTypeID=:WagesTypeID,
  6618. DamageNum=DamageNum+:DamageNum,
  6619. StandardWages=StandardWages+:StandardWages,
  6620. DamageSubsidyRate=DamageSubsidyRate+:DamageSubsidyRate,
  6621. DamageSubsidy=DamageSubsidy+:DamageSubsidy,
  6622. Amount=Amount+:Amount,
  6623. PieceTacticsID=:PieceTacticsID
  6624. where YYYYMM=:YYYYMM and StaffID=:StaffID and PayPlanID=:PayPlanID and WagesTypeID=:WagesTypeID
  6625. ";
  6626. }
  6627. parmeters1 = new OracleParameter[]
  6628. {
  6629. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  6630. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  6631. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  6632. new OracleParameter(":WagesTypeID",dtWagesType.Rows[ii]["WagesTypeID"]),
  6633. new OracleParameter(":DamageNum",scrapcount_1),
  6634. new OracleParameter(":StandardWages",scrap_StandardWages),
  6635. new OracleParameter(":DamageSubsidyRate",scrap_DamageSubsidyRate),
  6636. new OracleParameter(":DamageSubsidy",scrap_DamageSubsidy),
  6637. new OracleParameter(":Amount",temp_Scrap),
  6638. new OracleParameter(":PieceTacticsID",PieceTacticsID_Insert2),
  6639. };
  6640. intResult = oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  6641. #endregion
  6642. #region 干补补贴,从成品表时读取数据来计算干补数量
  6643. // 1 查出这个工号的,这个分类的,下一面在去过滤正品,还是副品
  6644. int RepairSubsidy_RSuperioNum = 0;//干补正品数
  6645. // 干补正品数
  6646. DataRow[] drRepairSubsidy_RSuperioNum = dsFinishedProduct.Tables[0].Select("SpecialRepairFlag=1 and GoodsLevelTypeID=4 and WagesTypeID=" + dtWagesType.Rows[ii]["WagesTypeID"]);
  6647. if (drRepairSubsidy_RSuperioNum.Length > 0)
  6648. {
  6649. RepairSubsidy_RSuperioNum = drRepairSubsidy_RSuperioNum.Length;
  6650. // 尽管有干补,但是有可能在损坯补贴给了,此处得查询一下干补补贴表,如果存在就不给此补贴
  6651. foreach (DataRow mm in drRepairSubsidy_RSuperioNum)
  6652. {
  6653. sqlString = "select 1 from TP_PAD_DamageSubsidy where Barcode=:Barcode and UserID=:UserID";
  6654. parmeters1 = new OracleParameter[]
  6655. {
  6656. new OracleParameter(":Barcode",mm["barcode"].ToString()),
  6657. new OracleParameter(":UserID",dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString()),
  6658. };
  6659. DataSet dsTemp = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  6660. if (dsTemp.Tables[0].Rows.Count > 0)
  6661. {
  6662. RepairSubsidy_RSuperioNum = RepairSubsidy_RSuperioNum - 1;
  6663. }
  6664. }
  6665. }
  6666. int RepairSubsidy_RQualifiedNum = 0;//干补副品数
  6667. // 干补正品数
  6668. DataRow[] drRepairSubsidy_RQualifiedNum = dsFinishedProduct.Tables[0].Select("SpecialRepairFlag=1 and GoodsLevelTypeID=5 and WagesTypeID=" + dtWagesType.Rows[ii]["WagesTypeID"]);
  6669. if (drRepairSubsidy_RQualifiedNum.Length > 0)
  6670. {
  6671. RepairSubsidy_RQualifiedNum = drRepairSubsidy_RQualifiedNum.Length;
  6672. // 尽管有干补,但是有可能在损坯补贴给了,此处得查询一下干补补贴表,如果存在就不给此补贴
  6673. foreach (DataRow mm in drRepairSubsidy_RQualifiedNum)
  6674. {
  6675. sqlString = "select 1 from TP_PAD_DamageSubsidy where Barcode=:Barcode and UserID=:UserID";
  6676. parmeters1 = new OracleParameter[]
  6677. {
  6678. new OracleParameter(":Barcode",mm["barcode"].ToString()),
  6679. new OracleParameter(":UserID",dsJobsPayPlan.Tables[0].Rows[j]["UserID"].ToString()),
  6680. };
  6681. DataSet dsTemp = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  6682. if (dsTemp.Tables[0].Rows.Count > 0)
  6683. {
  6684. RepairSubsidy_RQualifiedNum = RepairSubsidy_RQualifiedNum - 1;
  6685. }
  6686. }
  6687. }
  6688. // 查出此分类干补正负品补贴
  6689. // 求出损坯对应系数
  6690. DataRow[] drRepairSubsidy = dsWages.Tables[0].Select("WagesTypeID=" + dtWagesType.Rows[ii]["WagesTypeID"]);
  6691. decimal RSuperiorCoefficient = 0;//干补正品系数
  6692. decimal RQualifiedCoefficient = 0;//干补副品系数
  6693. decimal RepairSubsidyRate = 0;//干补补贴系数
  6694. decimal RepairStandardWages = 0;//标准工价
  6695. decimal RepairTotalCount = 0; //
  6696. decimal RepairSubsidy = 0;
  6697. decimal temp_Repair = 0;
  6698. if (drRepairSubsidy.Length > 0)
  6699. {
  6700. RSuperiorCoefficient = Convert.ToDecimal(drRepairSubsidy[0]["RSuperiorCoefficient"]);
  6701. RQualifiedCoefficient = Convert.ToDecimal(drRepairSubsidy[0]["RQualifiedCoefficient"]);
  6702. RepairSubsidyRate = Convert.ToDecimal(drRepairSubsidy[0]["RepairSubsidyRate"]);
  6703. RepairStandardWages = Convert.ToDecimal(drRepairSubsidy[0]["RepairStandardWages"]);
  6704. RepairTotalCount = (RepairSubsidy_RQualifiedNum * RSuperiorCoefficient - RepairSubsidy_RQualifiedNum * RQualifiedCoefficient) * RepairStandardWages * RepairSubsidyRate;
  6705. totalcount_RepairSubsidy += RepairTotalCount;
  6706. }
  6707. #endregion
  6708. #region 插入干补补贴
  6709. sqlString = "select 1 from TP_PAR_RepairSubsidy where YYYYMM=:YYYYMM and StaffID=:StaffID and PayPlanID=:PayPlanID and WagesTypeID=:WagesTypeID";
  6710. parmeters1 = new OracleParameter[]
  6711. {
  6712. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  6713. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  6714. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  6715. new OracleParameter(":WagesTypeID",dtWagesType.Rows[ii]["WagesTypeID"]),
  6716. };
  6717. // 读取计件工资策略
  6718. int PieceTacticsID_Insert3 = 0;
  6719. sqlString = "select PieceTacticsID from TP_PAT_Piecework where PayPlanID=:PayPlanID";
  6720. parmeters1 = new OracleParameter[]
  6721. {
  6722. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  6723. };
  6724. DataSet dss3 = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  6725. if (dss3 != null && dss3.Tables[0].Rows.Count > 0)
  6726. {
  6727. PieceTacticsID_Insert3 = Convert.ToInt32(dss3.Tables[0].Rows[0]["PieceTacticsID"]);
  6728. }
  6729. //-------------------------------------
  6730. DataSet dsExistRepairSubsidy = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  6731. if (dsExistRepairSubsidy != null && dsExistRepairSubsidy.Tables[0].Rows.Count == 0)
  6732. {
  6733. sqlString = @"insert into TP_PAR_RepairSubsidy
  6734. (
  6735. YYYYMM,
  6736. StaffID,
  6737. PayPlanID,
  6738. WagesTypeID,
  6739. RSuperioNum,
  6740. RSuperiorCoefficient,
  6741. RQualifiedNum,
  6742. RQualifiedCoefficient,
  6743. StandardWages,
  6744. RepairSubsidyRate,
  6745. RepairSubsidy,
  6746. Amount,
  6747. PieceTacticsID
  6748. ) values
  6749. (
  6750. :YYYYMM,
  6751. :StaffID,
  6752. :PayPlanID,
  6753. :WagesTypeID,
  6754. :RSuperioNum,
  6755. :RSuperiorCoefficient,
  6756. :RQualifiedNum,
  6757. :RQualifiedCoefficient,
  6758. :StandardWages,
  6759. :RepairSubsidyRate,
  6760. :RepairSubsidy,
  6761. :Amount,
  6762. :PieceTacticsID
  6763. )";
  6764. }
  6765. else
  6766. {
  6767. sqlString = @"update TP_PAR_RepairSubsidy
  6768. set
  6769. YYYYMM=:YYYYMM,
  6770. StaffID=:StaffID,
  6771. PayPlanID=:PayPlanID,
  6772. WagesTypeID=:WagesTypeID,
  6773. RSuperioNum=RSuperioNum+:RSuperioNum,
  6774. RSuperiorCoefficient=RSuperiorCoefficient+:RSuperiorCoefficient,
  6775. RQualifiedNum=RQualifiedNum+:RQualifiedNum,
  6776. RQualifiedCoefficient=RQualifiedCoefficient+:RQualifiedCoefficient,
  6777. StandardWages=StandardWages+:StandardWages,
  6778. RepairSubsidyRate=RepairSubsidyRate+:RepairSubsidyRate,
  6779. RepairSubsidy=RepairSubsidy+:RepairSubsidy,
  6780. Amount=Amount+:Amount,
  6781. PieceTacticsID=:PieceTacticsID
  6782. where YYYYMM=:YYYYMM and StaffID=:StaffID and PayPlanID=:PayPlanID and WagesTypeID=:WagesTypeID
  6783. ";
  6784. }
  6785. parmeters1 = new OracleParameter[]
  6786. {
  6787. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  6788. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  6789. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  6790. new OracleParameter(":WagesTypeID",dtWagesType.Rows[ii]["WagesTypeID"]),
  6791. new OracleParameter(":RSuperioNum",RepairSubsidy_RSuperioNum),
  6792. new OracleParameter(":RSuperiorCoefficient",RSuperiorCoefficient),
  6793. new OracleParameter(":RQualifiedNum",RepairSubsidy_RQualifiedNum),
  6794. new OracleParameter(":RQualifiedCoefficient",RQualifiedCoefficient),
  6795. new OracleParameter(":StandardWages",RepairStandardWages),
  6796. new OracleParameter(":RepairSubsidyRate",RepairSubsidyRate),
  6797. new OracleParameter(":RepairSubsidy",RepairSubsidy),
  6798. new OracleParameter(":Amount",temp_Repair),
  6799. new OracleParameter(":PieceTacticsID",PieceTacticsID_Insert3),
  6800. };
  6801. intResult = oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  6802. #endregion
  6803. }
  6804. }
  6805. }
  6806. #endregion
  6807. decimal? totalcount_QualityASS = 0;// 品质工资
  6808. #region 品质考核策略
  6809. decimal min_TotalCount = 0;
  6810. for (int h = 0; h < dsQualityASS.Tables[0].Rows.Count; h++)
  6811. {
  6812. min_TotalCount = 0;
  6813. // 求出缺陷数
  6814. sqlString = @"select TP_PAM_GoodsWagesType.WagesTypeID,TMP_PAM_Defect.goodsid,TMP_PAM_Defect.DefectFine from TMP_PAM_Defect
  6815. inner join TP_PAM_GoodsWagesType
  6816. on TMP_PAM_Defect.goodsID=TP_PAM_GoodsWagesType.goodsID
  6817. where TMP_PAM_Defect.DefectUserID=" + dsJobsPayPlan.Tables[0].Rows[j]["userID"] + " and TMP_PAM_Defect.DefectFine=" + dsQualityASS.Tables[0].Rows[h]["DefectFine"];
  6818. DataSet ds = oracleTrConn.GetSqlResultToDs(sqlString);//查询出有多少分类,进行计算
  6819. DataTable dt2 = ds.Tables[0].DefaultView.ToTable(true, "WagesTypeID");//有多少行,就有多少分类
  6820. for (int p = 0; p < dt2.Rows.Count; p++)
  6821. {
  6822. decimal temp_QualityReward = 0;
  6823. int drCount_Total = 0;
  6824. // modify
  6825. string barcodes_Procedure = "";
  6826. drCount_Total = 0;
  6827. for (int p1 = 0; p1 < dsPieceProcedure_2.Tables[0].Rows.Count; p1++)
  6828. {
  6829. DataRow[] drQualityBaseProcedure = dsTMPProductionData.Tables[0]
  6830. .Select(string.Format("ProcedureID={0} and WagesTypeID={1}", dsPieceProcedure_2.Tables[0].Rows[p1]["ProcedureID"], dt2.Rows[p]["WagesTypeID"]));
  6831. if (drQualityBaseProcedure.Length > 0)
  6832. {
  6833. foreach (DataRow r4 in drQualityBaseProcedure)
  6834. {
  6835. if (!barcodes_Procedure.Contains(r4["barcode"].ToString()))
  6836. {
  6837. drCount_Total += 1; // 质量工序数量
  6838. }
  6839. barcodes_Procedure = barcodes_Procedure + r4["barcode"].ToString() + ",";
  6840. }
  6841. }
  6842. }
  6843. //// modify en
  6844. //for (int yy = 0; yy < dsQualityProcedure.Tables[0].Rows.Count; yy++)
  6845. //{
  6846. // DataRow[] drCount = dsTMPProductionData.Tables[0].Select("ProcedureID=" + dsQualityProcedure.Tables[0].Rows[yy]["ProcedureID"] + " and userID=" + dsJobsPayPlan.Tables[0].Rows[j]["userID"] + " and WagesTypeID=" + dt2.Rows[p]["WagesTypeID"]);
  6847. // drCount_Total += drCount.Length;
  6848. //}
  6849. // 读取质量基数工序
  6850. // 缺陷数量
  6851. DataRow[] drDefect = ds.Tables[0].Select("DefectFine=" + dsQualityASS.Tables[0].Rows[h]["DefectFine"] + " and WagesTypeID=" + dt2.Rows[p]["WagesTypeID"]);
  6852. // temp 为品质率,真正的价格在区间取
  6853. decimal temp = 0;
  6854. if (drCount_Total != 0)
  6855. {
  6856. temp = Convert.ToDecimal(dsQualityASS.Tables[0].Rows[h]["DefectFine"]) * drDefect.Length / drCount_Total;
  6857. }
  6858. // 查出对应分类品质奖励
  6859. sqlString = "select * from TP_PAT_QualityReward where WagesTypeID=" + dt2.Rows[p]["WagesTypeID"] + " and QualityRate>=" + temp + " order by QualityRate";
  6860. DataSet dsQualityReward_Temp = oracleTrConn.GetSqlResultToDs(sqlString);
  6861. decimal QualityRate = 0;
  6862. if (dsQualityReward_Temp != null && dsQualityReward_Temp.Tables[0].Rows.Count > 0)
  6863. {
  6864. //表示有对应的品质价格,结果集如有多个,取第一个对应的金额即可
  6865. min_TotalCount = Convert.ToDecimal(dsQualityReward_Temp.Tables[0].Rows[0]["QualityReward"]);
  6866. temp_QualityReward = Convert.ToDecimal(dsQualityReward_Temp.Tables[0].Rows[0]["QualityReward"]);//品质奖励金额
  6867. QualityRate = Convert.ToDecimal(dsQualityReward_Temp.Tables[0].Rows[0]["QualityRate"]);
  6868. }
  6869. // 读取品质考核策略
  6870. int PieceTacticsID_Insert3 = 0;
  6871. sqlString = "select QualityASSTacticsID from TP_PAT_QualityASS where PayPlanID=:PayPlanID";
  6872. parmeters1 = new OracleParameter[]
  6873. {
  6874. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  6875. };
  6876. DataSet dss3 = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  6877. if (dss3 != null && dss3.Tables[0].Rows.Count > 0)
  6878. {
  6879. PieceTacticsID_Insert3 = Convert.ToInt32(dss3.Tables[0].Rows[0]["QualityASSTacticsID"]);
  6880. }
  6881. #region 插入品质考核
  6882. sqlString = @"insert into TP_PAR_QualityASS
  6883. (
  6884. YYYYMM,
  6885. StaffID,
  6886. PayPlanID,
  6887. WagesTypeID,
  6888. DefectFine,
  6889. DefectNum,
  6890. QualityBaseNum,
  6891. QualityRate,
  6892. Amount,
  6893. QualityASSTacticsID
  6894. ) values
  6895. (
  6896. :YYYYMM,
  6897. :StaffID,
  6898. :PayPlanID,
  6899. :WagesTypeID,
  6900. :DefectFine,
  6901. :DefectNum,
  6902. :QualityBaseNum,
  6903. :QualityRate,
  6904. :Amount,
  6905. :QualityASSTacticsID
  6906. )";
  6907. parmeters1 = new OracleParameter[]
  6908. {
  6909. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  6910. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[j]["StaffID"]),
  6911. new OracleParameter(":PayPlanID",dsPayPlan.Tables[0].Rows[i]["PayPlanID"]),
  6912. new OracleParameter(":WagesTypeID",dt2.Rows[p]["WagesTypeID"]),
  6913. new OracleParameter(":DefectFine",dsQualityASS.Tables[0].Rows[h]["DefectFine"]),
  6914. new OracleParameter(":DefectNum",drDefect.Length),
  6915. new OracleParameter(":QualityBaseNum",drCount_Total),
  6916. new OracleParameter(":QualityRate",QualityRate),
  6917. new OracleParameter(":Amount",min_TotalCount),
  6918. new OracleParameter(":QualityASSTacticsID",PieceTacticsID_Insert3),
  6919. };
  6920. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  6921. #endregion
  6922. }
  6923. totalcount_QualityASS += min_TotalCount;
  6924. }
  6925. #endregion
  6926. decimal? totalcount_AdminEXA = 0;// 行政工资
  6927. #region 行政考核
  6928. sqlString = "select Amount from TP_PAD_AdminEXA where SettlementFlag=0 and StaffID=:StaffID";
  6929. parmeters1 = new OracleParameter[]
  6930. {
  6931. //new OracleParameter(":UserID",dsJobsPayPlan.Tables[0].Rows[i]["UserID"]),
  6932. new OracleParameter(":StaffID",dsJobsPayPlan.Tables[0].Rows[i]["StaffID"]),
  6933. };
  6934. DataSet dsAdminEXA = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  6935. if (dsAdminEXA != null && dsAdminEXA.Tables[0].Rows.Count > 0)
  6936. {
  6937. for (int y = 0; y < dsAdminEXA.Tables[0].Rows.Count; y++)
  6938. {
  6939. totalcount_AdminEXA += Convert.ToDecimal(dsAdminEXA.Tables[0].Rows[y]["Amount"]);
  6940. }
  6941. }
  6942. #endregion
  6943. #region 插入工资单
  6944. // 防止一个员工在多个工号下面
  6945. sqlString = "select 1 from TP_PAR_Payroll where YYYYMM=:YYYYMM and StaffID=:StaffID ";
  6946. parmeters1 = new OracleParameter[]
  6947. {
  6948. new OracleParameter(":YYYYMM",OracleDbType.Varchar2,(Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),ParameterDirection.Input),
  6949. new OracleParameter(":StaffID",OracleDbType.Int32,dsJobsPayPlan.Tables[0].Rows[j]["StaffID"],ParameterDirection.Input),
  6950. };
  6951. DataSet ds4 = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  6952. if (ds4 != null && ds4.Tables[0].Rows.Count == 0)
  6953. {
  6954. sqlString = @"insert into TP_PAR_Payroll
  6955. (
  6956. YYYYMM,
  6957. StaffID,
  6958. Piecework,
  6959. DamageSubsidy,
  6960. RepairSubsidy,
  6961. QualityEXA,
  6962. AdminEXA,
  6963. ADAmount,
  6964. TotalAmount,
  6965. AuditStatus,
  6966. AccountID,
  6967. CreateUserID,
  6968. UpdateUserID
  6969. ) values
  6970. (
  6971. :YYYYMM,
  6972. :StaffID,
  6973. :Piecework,
  6974. :DamageSubsidy,
  6975. :RepairSubsidy,
  6976. :QualityEXA,
  6977. :AdminEXA,
  6978. :ADAmount,
  6979. :TotalAmount,
  6980. :AuditStatus,
  6981. :AccountID,
  6982. :CreateUserID,
  6983. :UpdateUserID
  6984. )";
  6985. decimal? a = (totalcount_Piecegiework + totalcount_Scrap + totalcount_RepairSubsidy + totalcount_QualityASS + totalcount_AdminEXA);
  6986. parmeters1 = new OracleParameter[]
  6987. {
  6988. new OracleParameter(":YYYYMM",OracleDbType.Varchar2,(Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),ParameterDirection.Input),
  6989. new OracleParameter(":StaffID",OracleDbType.Int32,dsJobsPayPlan.Tables[0].Rows[j]["StaffID"],ParameterDirection.Input),
  6990. //new OracleParameter(":PayPlanID",OracleDbType.Int32,dsPayPlan.Tables[0].Rows[i]["PayPlanID"],ParameterDirection.Input),
  6991. new OracleParameter(":Piecework",OracleDbType.Decimal,totalcount_Piecegiework,ParameterDirection.Input),
  6992. new OracleParameter(":DamageSubsidy",OracleDbType.Decimal,totalcount_Scrap,ParameterDirection.Input),
  6993. new OracleParameter(":RepairSubsidy",OracleDbType.Decimal,totalcount_RepairSubsidy,ParameterDirection.Input),
  6994. new OracleParameter(":QualityEXA",OracleDbType.Decimal,totalcount_QualityASS,ParameterDirection.Input),
  6995. new OracleParameter(":AdminEXA",OracleDbType.Decimal,totalcount_AdminEXA,ParameterDirection.Input),
  6996. new OracleParameter(":ADAmount",OracleDbType.Decimal,0,ParameterDirection.Input),
  6997. new OracleParameter(":TotalAmount",OracleDbType.Decimal,a,ParameterDirection.Input),
  6998. new OracleParameter(":CreateUserID",OracleDbType.Int32,sUserInfo.UserID,ParameterDirection.Input),
  6999. new OracleParameter(":UpdateUserID",OracleDbType.Int32,sUserInfo.UserID,ParameterDirection.Input),
  7000. new OracleParameter(":AccountID",OracleDbType.Int32,sUserInfo.AccountID,ParameterDirection.Input),
  7001. new OracleParameter(":AuditStatus",OracleDbType.Int32,0,ParameterDirection.Input),
  7002. };
  7003. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  7004. }
  7005. else
  7006. {
  7007. sqlString = @"update TP_PAR_Payroll
  7008. set Piecework=Piecework+:Piecework,
  7009. DamageSubsidy=DamageSubsidy+:DamageSubsidy,
  7010. RepairSubsidy=RepairSubsidy+:RepairSubsidy,
  7011. QualityEXA=QualityEXA+:QualityEXA,
  7012. AdminEXA=AdminEXA+:AdminEXA,
  7013. ADAmount=AdminEXA+:ADAmount,
  7014. TotalAmount=TotalAmount+:TotalAmount
  7015. where YYYYMM=:YYYYMM and StaffID=:StaffID
  7016. ";
  7017. decimal? a = (totalcount_Piecegiework + totalcount_Scrap + totalcount_RepairSubsidy + totalcount_QualityASS + totalcount_AdminEXA);
  7018. parmeters1 = new OracleParameter[]
  7019. {
  7020. new OracleParameter(":YYYYMM",OracleDbType.Varchar2,(Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),ParameterDirection.Input),
  7021. new OracleParameter(":StaffID",OracleDbType.Int32,dsJobsPayPlan.Tables[0].Rows[j]["StaffID"],ParameterDirection.Input),
  7022. //new OracleParameter(":PayPlanID",OracleDbType.Int32,dsPayPlan.Tables[0].Rows[i]["PayPlanID"],ParameterDirection.Input),
  7023. new OracleParameter(":Piecework",OracleDbType.Decimal,totalcount_Piecegiework,ParameterDirection.Input),
  7024. new OracleParameter(":DamageSubsidy",OracleDbType.Decimal,totalcount_Scrap,ParameterDirection.Input),
  7025. new OracleParameter(":RepairSubsidy",OracleDbType.Decimal,totalcount_RepairSubsidy,ParameterDirection.Input),
  7026. new OracleParameter(":QualityEXA",OracleDbType.Decimal,totalcount_QualityASS,ParameterDirection.Input),
  7027. new OracleParameter(":AdminEXA",OracleDbType.Decimal,totalcount_AdminEXA,ParameterDirection.Input),
  7028. new OracleParameter(":ADAmount",OracleDbType.Decimal,0,ParameterDirection.Input),
  7029. new OracleParameter(":TotalAmount",OracleDbType.Decimal,a,ParameterDirection.Input),
  7030. };
  7031. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  7032. }
  7033. #endregion
  7034. }
  7035. if (intResult > 0)
  7036. {
  7037. sqlString = @"insert into TP_PAR_PayrollAccount
  7038. (
  7039. YYYYMM,
  7040. BeginDate,
  7041. EndDate,
  7042. AccountID,
  7043. CreateUserID
  7044. ) values
  7045. (
  7046. :YYYYMM,
  7047. :BeginDate,
  7048. :EndDate,
  7049. :AccountID,
  7050. :CreateUserID
  7051. )";
  7052. parmeters1 = new OracleParameter[]
  7053. {
  7054. new OracleParameter(":YYYYMM",Year.ToString()+(Month.ToString().Length<2?"0"+Month.ToString():Month.ToString())),
  7055. new OracleParameter(":BeginDate",dateStartTime),
  7056. new OracleParameter(":EndDate",dateEndTime),
  7057. new OracleParameter(":AccountID",sUserInfo.AccountID),
  7058. new OracleParameter(":CreateUserID",sUserInfo.UserID),
  7059. };
  7060. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  7061. // 更新系统结算月
  7062. sqlString = "update TP_MST_SystemDate set datevalue=sysdate where systemdatetype=2";
  7063. intResult += oracleTrConn.ExecuteNonQuery(sqlString);
  7064. sqlString = "update TP_MST_SystemDate set datevalue=:datevalue where systemdatetype=5";
  7065. parmeters1 = new OracleParameter[]
  7066. {
  7067. new OracleParameter(":datevalue",dateEndTime),
  7068. };
  7069. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  7070. oracleTrConn.Commit();
  7071. oracleTrConn.Disconnect();
  7072. }
  7073. else
  7074. {
  7075. oracleTrConn.Rollback();
  7076. oracleTrConn.Disconnect();
  7077. }
  7078. }
  7079. }
  7080. return intResult;
  7081. }
  7082. catch (Exception ex)
  7083. {
  7084. if (oracleTrConn.ConnState == ConnectionState.Open)
  7085. {
  7086. oracleTrConn.Rollback();
  7087. oracleTrConn.Disconnect();
  7088. }
  7089. throw ex;
  7090. }
  7091. finally
  7092. {
  7093. if (oracleTrConn.ConnState == ConnectionState.Open)
  7094. {
  7095. oracleTrConn.Rollback();
  7096. oracleTrConn.Disconnect();
  7097. }
  7098. }
  7099. }
  7100. /// <summary>
  7101. /// 保存产品工价分类
  7102. /// </summary>
  7103. /// <param name="IsEdit">false 新建 true 编辑</param>
  7104. /// <param name="dtJobsPayPlan">数据源</param>
  7105. /// <param name="sUserInfo"></param>
  7106. /// <returns></returns>
  7107. public static int ChangePayPiecework(string YYYYMM, SUserInfo sUserInfo)
  7108. {
  7109. IDBTransaction oracleTrConn = ClsDbFactory.CreateDBTransaction(DataBaseType.ORACLE, DataManager.ConnectionString);
  7110. try
  7111. {
  7112. int intResult = 0;
  7113. oracleTrConn.Connect();
  7114. OracleParameter[] parmeters1 = null;
  7115. string sqlString = "";
  7116. sqlString = "delete from TP_PAR_PayrollAccount where YYYYMM=:YYYYMM ";
  7117. parmeters1 = new OracleParameter[]
  7118. {
  7119. new OracleParameter(":YYYYMM",YYYYMM),
  7120. };
  7121. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  7122. sqlString = "delete from TP_PAR_Payroll where YYYYMM=:YYYYMM ";
  7123. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  7124. sqlString = "delete from TP_PAR_Piecework where YYYYMM=:YYYYMM ";
  7125. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  7126. sqlString = "delete from TP_PAR_DamageSubsidy where YYYYMM=:YYYYMM ";
  7127. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  7128. sqlString = "delete from TP_PAR_RepairSubsidy where YYYYMM=:YYYYMM ";
  7129. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  7130. sqlString = "delete from TP_PAR_QualityASS where YYYYMM=:YYYYMM ";
  7131. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  7132. sqlString = "select * from TP_PAR_PayrollAccount where AccountID=:AccountID order by CreateTime desc";
  7133. parmeters1 = new OracleParameter[]
  7134. {
  7135. new OracleParameter(":AccountID",sUserInfo.AccountID),
  7136. };
  7137. DataSet ds = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  7138. if (ds != null && ds.Tables[0].Rows.Count > 0)
  7139. {
  7140. //反结算,更新生产数据与行政考核数据标识
  7141. int Year = Convert.ToInt32(YYYYMM.Substring(0, 4));
  7142. int Month = Convert.ToInt32(YYYYMM.Substring(5));
  7143. #region 查询系统参数设定值,用来结算工资范围取值
  7144. DateTime? dateStartTime = null;
  7145. DateTime? dateEndTime = null;
  7146. sqlString = "select SettingValue from TP_MST_SystemSetting where accountid=:accountid and SettingCode='S_CMN_0003'";
  7147. parmeters1 = new OracleParameter[]
  7148. {
  7149. new OracleParameter(":accountid",sUserInfo.AccountID),
  7150. };
  7151. DataSet dsSystemSettings = oracleTrConn.GetSqlResultToDs(sqlString, parmeters1);
  7152. if (dsSystemSettings != null && dsSystemSettings.Tables[0].Rows.Count > 0)
  7153. {
  7154. // 算出此月一共多少天,防止设置的值,大于当月的天数
  7155. int daysCount = DateTime.DaysInMonth(Year, Month);
  7156. if (dsSystemSettings.Tables[0].Rows[0]["SettingValue"].ToString() == "月末")
  7157. {
  7158. dateStartTime = new DateTime(Year, Month, 1);
  7159. dateEndTime = new DateTime(Year, Month, daysCount, 23, 59, 59);
  7160. }
  7161. else
  7162. {
  7163. // 选择的值,大于当月的天数
  7164. if (Convert.ToInt32(dsSystemSettings.Tables[0].Rows[0]["SettingValue"]) > daysCount)
  7165. {
  7166. dateEndTime = new DateTime(Year, Month, daysCount, 23, 59, 59);
  7167. dateStartTime = dateEndTime.Value.AddMonths(-1).AddDays(1);
  7168. }
  7169. else
  7170. {
  7171. dateEndTime = new DateTime(Year, Month, Convert.ToInt32(dsSystemSettings.Tables[0].Rows[0]["SettingValue"]), 23, 59, 59);
  7172. dateStartTime = dateEndTime.Value.AddMonths(-1).AddDays(1);
  7173. }
  7174. }
  7175. }
  7176. #endregion
  7177. #region 根据筛选日期更新生产数据结算标识
  7178. parmeters1 = new OracleParameter[]
  7179. {
  7180. new OracleParameter(":dateStartTime",OracleDbType.Date,dateStartTime,ParameterDirection.Input),
  7181. new OracleParameter(":dateEndTime",OracleDbType.Date,dateEndTime,ParameterDirection.Input),
  7182. new OracleParameter(":accountid",sUserInfo.AccountID),
  7183. };
  7184. // 更新生产数据结算标识
  7185. sqlString = @"update TP_PM_ProductionData set SettlementFlag=0 where SettlementFlag=1 and CreateTime >=:dateStartTime and CreateTime<=:dateEndTime and accountid=:accountid and valueflag=1";
  7186. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  7187. #endregion
  7188. //
  7189. sqlString = "update TP_PAD_AdminEXA set SettlementFlag=0 where SettlementFlag=1 and AuditStatus=1 and AuditlDate >=:dateStartTime and AuditlDate<=:dateEndTime and accountid=:accountid";
  7190. parmeters1 = new OracleParameter[]
  7191. {
  7192. new OracleParameter(":dateStartTime",dateStartTime),
  7193. new OracleParameter(":dateEndTime",dateEndTime),
  7194. new OracleParameter(":accountid",sUserInfo.AccountID),
  7195. };
  7196. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  7197. sqlString = "update TP_MST_SystemDate set datevalue=:datevalue where systemdatetype=2";
  7198. parmeters1 = new OracleParameter[]
  7199. {
  7200. new OracleParameter(":datevalue",ds.Tables[0].Rows[0]["CreateTime"]),
  7201. };
  7202. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  7203. sqlString = "update TP_MST_SystemDate set datevalue=:datevalue where systemdatetype=5";
  7204. string yyyy_mm = ds.Tables[0].Rows[0]["YYYYMM"].ToString();
  7205. int year = Convert.ToInt32(yyyy_mm.Substring(0, 4));
  7206. int month = Convert.ToInt32(yyyy_mm.Substring(4));
  7207. DateTime updatetime = new DateTime(year, month, 1, 23, 59, 59);
  7208. parmeters1 = new OracleParameter[]
  7209. {
  7210. new OracleParameter(":datevalue",updatetime),
  7211. };
  7212. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  7213. }
  7214. else
  7215. {
  7216. sqlString = "update TP_MST_SystemDate set datevalue=:datevalue where systemdatetype=2";
  7217. parmeters1 = new OracleParameter[]
  7218. {
  7219. new OracleParameter(":datevalue",new DateTime(2000,1,1)),
  7220. };
  7221. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  7222. sqlString = "update TP_MST_SystemDate set datevalue=:datevalue where systemdatetype=5";
  7223. DateTime updatetime = new DateTime(2000, 1, 1, 23, 59, 59);
  7224. parmeters1 = new OracleParameter[]
  7225. {
  7226. new OracleParameter(":datevalue",updatetime),
  7227. };
  7228. intResult += oracleTrConn.ExecuteNonQuery(sqlString, parmeters1);
  7229. }
  7230. if (intResult == 0)
  7231. {
  7232. oracleTrConn.Rollback();
  7233. oracleTrConn.Disconnect();
  7234. }
  7235. else
  7236. {
  7237. oracleTrConn.Commit();
  7238. oracleTrConn.Disconnect();
  7239. }
  7240. return intResult;
  7241. }
  7242. catch (Exception ex)
  7243. {
  7244. if (oracleTrConn.ConnState == ConnectionState.Open)
  7245. {
  7246. oracleTrConn.Rollback();
  7247. oracleTrConn.Disconnect();
  7248. }
  7249. throw ex;
  7250. }
  7251. }
  7252. }
  7253. }