No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Frm_01HF_RetanRcp.vb 145KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978
  1. 'Imports System.Data.SqlClient
  2. 'Imports Microsoft.Office.Interop.Excel
  3. 'Imports Microsoft.Office.Interop.Excel.XlBordersIndex
  4. 'Imports Microsoft.Office.Interop.Excel.Constants.xlConstants
  5. 'Imports Microsoft.Office.Interop.Excel.XlLineStyle
  6. 'Imports Microsoft.Office.Core.XlBorderWeight
  7. 'Imports Microsoft.Office.Core.XlUnderlineStyle
  8. 'Imports Microsoft.Office.Interop.Excel.XlPageOrientation
  9. Imports NPOI.XSSF.UserModel
  10. Imports NPOI.SS.UserModel
  11. Imports NPOI.POIFS.FileSystem
  12. Imports System.IO
  13. Imports System.Data.SqlClient
  14. 'Imports Microsoft.Office.Core.XlConstants
  15. Imports Microsoft.Office.Interop.Excel.XlUnderlineStyle
  16. Imports Microsoft.Office.Interop.Excel.Constants
  17. Imports Microsoft.Office.Interop.Excel.XlBordersIndex
  18. Imports Microsoft.Office.Interop.Excel.XlLineStyle
  19. Imports Microsoft.Office.Interop.Excel.XlBorderWeight
  20. Imports Microsoft.Office.Interop.Excel.XlPrintLocation
  21. Imports Microsoft.Office.Interop.Excel.XlPageOrientation
  22. Imports Microsoft.Office.Interop.Excel.XlPaperSize
  23. Imports Microsoft.Office.Interop.Excel.XlOrder
  24. Imports Microsoft.Office.Interop.Excel.XlPrintErrors
  25. 'Imports Excel = Microsoft.Office.Interop.Excel
  26. Imports Microsoft.Office.Core
  27. Imports System.Reflection
  28. Imports System.ComponentModel
  29. Imports Microsoft.Office.Interop
  30. Imports ThoughtWorks.QRCode.Codec.Data
  31. Imports System.Drawing.Imaging
  32. Imports NPOI.SS.Formula.Functions
  33. Imports System.Windows.Forms.VisualStyles.VisualStyleElement
  34. Public Class Frm_01HF_RetanRcp
  35. Dim dt1 As New DataTable
  36. Dim gWeight() As Double
  37. Dim gCoin() As String
  38. Dim gPrice() As Double
  39. Dim rr As String = ""
  40. Dim rcp_name As String = ""
  41. Dim gAddfromOther As Boolean = False
  42. Dim da As New SqlDataAdapter()
  43. Dim dr As SqlDataReader
  44. Dim conn As New SqlConnection
  45. Dim dt As New System.Data.DataTable
  46. Dim ds As New DataSet()
  47. Dim cmd As New SqlCommand
  48. Dim sql_rcp As String
  49. Dim sql_print As String
  50. Dim con As New SqlConnection
  51. 'Dim msg As String = ""
  52. Dim colorArray(10) As Color
  53. Dim card As String = ""
  54. Dim cust As String = ""
  55. Dim wb_weight As Double = 0
  56. Dim thickness As String = ""
  57. Dim r_type As String = ""
  58. Dim source As String = ""
  59. Dim comment As String = ""
  60. Dim dt_print As DataTable
  61. Dim color1 As String = ""
  62. Dim DT2 As New DataTable
  63. Sub ExportToExcel()
  64. ' 获取输入信息
  65. Dim my_card As String = InputBox("请输入卡号:", "查询")
  66. If my_card = "" Then
  67. MsgBox("操作已取消。", vbInformation, "退出")
  68. Exit Sub
  69. End If
  70. Dim my_weight As Double = 0
  71. Dim weightInput As String = InputBox("请输入重量:", "查询")
  72. If weightInput = "" OrElse Not IsNumeric(weightInput) OrElse CDbl(weightInput) <= 0 Then
  73. MsgBox("请输入有效的重量!", vbExclamation, "错误")
  74. Exit Sub
  75. Else
  76. my_weight = CDbl(weightInput)
  77. End If
  78. Dim d_no As String = InputBox("请输入编号:", "查询")
  79. If d_no = "" Then
  80. MsgBox("操作已取消。", vbInformation, "退出")
  81. Exit Sub
  82. End If
  83. ' 创建一个新的工作簿
  84. Dim workbook As New XSSFWorkbook()
  85. Dim sheet As ISheet = workbook.CreateSheet("Sheet1")
  86. ' 数据示例(例如 DataGridView1 的行数据)
  87. Dim rowIndex As Integer = 0
  88. For x As Integer = 0 To DataGridView1.Rows.Count - 2
  89. If DataGridView1.Rows(x).Cells("类别").Value <> "不列印" Then
  90. Dim row As IRow = sheet.CreateRow(rowIndex)
  91. row.CreateCell(0).SetCellValue("卡号: " & my_card)
  92. row.CreateCell(1).SetCellValue("编号: " & d_no)
  93. row.CreateCell(2).SetCellValue("重量: " & my_weight)
  94. rowIndex += 1
  95. ' 插入图片(假设图片路径在 p 数组中)
  96. Dim pictureData As Byte() = File.ReadAllBytes("c:\GHS\1.jpg")
  97. Dim pictureIndex As Integer = workbook.AddPicture(pictureData, PictureType.JPEG)
  98. ' 创建 DrawingPatriarch
  99. ' Dim drawing As IDrawingPatriarch = sheet.CreateDrawingPatriarch()
  100. Dim drawing As XSSFDrawing = CType(sheet.CreateDrawingPatriarch(), XSSFDrawing)
  101. Dim anchor As IClientAnchor = workbook.GetCreationHelper().CreateClientAnchor()
  102. anchor.Col1 = 3 ' 图片插入列
  103. anchor.Row1 = rowIndex ' 图片插入行
  104. ' 插入图片
  105. drawing.CreatePicture(anchor, pictureIndex)
  106. rowIndex += 1
  107. End If
  108. Next
  109. ' 设置输出文件路径
  110. Dim outputPath As String = "C:\path\to\your\output.xlsx"
  111. Using fs As New FileStream(outputPath, FileMode.Create, FileAccess.Write)
  112. workbook.Write(fs)
  113. End Using
  114. MsgBox("输出完成")
  115. End Sub
  116. Private Sub frm_01hf_RetanRcp_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  117. Dim type1 As Type = dgv2.GetType()
  118. Dim pi1 As PropertyInfo = type1.GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.NonPublic)
  119. pi1.SetValue(dgv2, True, Nothing)
  120. dgv2.CausesValidation = False
  121. DGV1.ReadOnly = True
  122. 'Me.MdiParent = mdiForm
  123. colorArray(0) = Color.FromName("Aquamarine")
  124. colorArray(1) = Color.FromName("azure")
  125. colorArray(2) = Color.FromName("beige")
  126. colorArray(3) = Color.FromName("gainsboro")
  127. colorArray(4) = Color.FromName("LightBlue")
  128. colorArray(5) = Color.FromName("LightSalmon")
  129. Button17.Visible = False
  130. dgv2.RowTemplate.Height = 30
  131. conn.ConnectionString = connstring
  132. con.ConnectionString = connstring
  133. con.Open()
  134. DGV1.RowTemplate.Height = 30
  135. DataGridView1.RowTemplate.Height = 30
  136. DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
  137. DataGridView1.AutoResizeRows(DataGridViewAutoSizeRowsMode.AllCells)
  138. ' DataGridView1.RowTemplate.Height = 30
  139. cmd.Connection = conn
  140. sql_rcp = "select top(200) date as 日期,name as 品名,selection as 选级,avg(weight) as 重量,no as 流程卡号,rcp_no as 表格编号 from ht_retanrcp group by name,date,selection,rcp_no,no order by date desc"
  141. cmd.Connection = conn
  142. cmd.CommandText = sql_rcp
  143. da.SelectCommand = cmd
  144. da.Fill(ds)
  145. DGV1.DataSource = ds.Tables(0)
  146. set_grid()
  147. dgv2.GridColor = Color.White
  148. dgv2.AllowUserToAddRows = False
  149. dgv2.SelectionMode = DataGridViewSelectionMode.FullRowSelect
  150. con.Close()
  151. dgv_record.GridColor = Color.White
  152. dgv_record.AllowUserToAddRows = False
  153. dgv_record.SelectionMode = DataGridViewSelectionMode.FullRowSelect
  154. ' dgv2.Columns(2).Visible = False
  155. ' dgv2.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
  156. Dim c As Integer = 1
  157. Dim p(250) As Integer
  158. Dim x As Integer
  159. p(1) = 0
  160. For x = 1 To DGV1.Rows.Count - 2
  161. If DGV1.Rows(x).Cells(0).Value.ToString <> DGV1.Rows(x - 1).Cells(0).Value.ToString Then
  162. p(c + 1) = x
  163. c = c + 1
  164. End If
  165. Next
  166. p(c + 1) = x
  167. ReDim Preserve p(x)
  168. If c = 1 Then
  169. For z As Integer = 0 To x - 1
  170. DGV1.Rows(z).DefaultCellStyle.BackColor = colorArray(1)
  171. Next
  172. Else
  173. For cc As Integer = 1 To c
  174. For z As Integer = p(cc) To p(cc + 1) - 1
  175. DGV1.Rows(z).DefaultCellStyle.BackColor = colorArray(cc Mod 5)
  176. Next
  177. Next
  178. End If
  179. DGV1.Columns(0).Width = 150
  180. DGV1.Columns(1).Width = 220
  181. DGV1.Columns(2).Width = 160
  182. DGV1.Columns(3).Width = 100
  183. DGV1.Columns(4).Width = 190
  184. DGV1.Columns(5).Width = 200
  185. DGV1.RowHeadersWidth = 30
  186. DataGridView1.RowHeadersWidth = 30
  187. DataGridView1.RowTemplate.Height = 35
  188. End Sub
  189. Private Sub ini_content()
  190. 'card = FrmWB_OUT.DGV1.Rows(FrmWB_OUT.DGV1.CurrentRow.Index).Cells("卡号").Value
  191. 'cust = FrmWB_OUT.DGV1.Rows(FrmWB_OUT.DGV1.CurrentRow.Index).Cells("客户").Value
  192. 'wb_weight = FrmWB_OUT.DGV1.Rows(FrmWB_OUT.DGV1.CurrentRow.Index).Cells("皮重").Value
  193. 'thickness = FrmWB_OUT.DGV1.Rows(FrmWB_OUT.DGV1.CurrentRow.Index).Cells("厚度").Value
  194. 'source = FrmWB_OUT.DGV1.Rows(FrmWB_OUT.DGV1.CurrentRow.Index).Cells("皮源").Value
  195. 'comment = FrmWB_OUT.DGV1.Rows(FrmWB_OUT.DGV1.CurrentRow.Index).Cells("备注").Value.ToString
  196. 'color1 = FrmWB_OUT.DGV1.Rows(FrmWB_OUT.DGV1.CurrentRow.Index).Cells("颜色").Value
  197. End Sub
  198. Private Sub Button22_Click(sender As Object, e As EventArgs) Handles Button22.Click
  199. ini_content()
  200. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  201. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  202. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  203. Dim my_card As String = InputBox("请输入卡号", "询问")
  204. Dim my_weight As Double = InputBox("请输入重量", "询问")
  205. my_card = my_card
  206. 'frm_01hf_RetanRcp_WB.ShowDialog()
  207. Dim d_no As Double = InputBox("请输入鼓号", "询问")
  208. 'frm_01hf_RetanRcp_WB.ShowDialog()
  209. xlApp = CreateObject("Excel.Application")
  210. xlBook = xlApp.Workbooks.Add
  211. xlApp.DisplayAlerts = False
  212. xlBook.Activate()
  213. xlBook.Parent.Windows(1).Visible = True
  214. xlSheet = xlBook.Worksheets.Add
  215. xlSheet.Activate()
  216. xlApp.Visible = True
  217. xlApp.Application.ScreenUpdating = False
  218. editFormat(xlApp, xlSheet)
  219. xlApp.Visible = False
  220. xlSheet.Cells(1, 1) = "流程卡号"
  221. xlSheet.Cells(2, 1) = "打印日期"
  222. xlSheet.Cells(3, 1) = "皮源"
  223. xlSheet.Cells(1, 7) = "工艺名稱"
  224. xlSheet.Cells(2, 6) = "規格"
  225. xlSheet.Cells(2, 10) = "鼓号"
  226. xlSheet.Cells(1, 12) = "染色日期"
  227. xlSheet.Cells(2, 12) = "重量"
  228. xlSheet.Cells(3, 7) = "备注"
  229. xlSheet.Cells(2, 12) = "重量"
  230. xlSheet.Cells(3, 4) = comment
  231. ' xlSheet.Cells(1, 4) = DGV1.Rows(DGV1.CurrentRow.Index).Cells("處方編號").Value
  232. xlSheet.Cells(2, 4) = String.Format("{0:d}", DateTime.Now)
  233. xlSheet.Cells(1, 10) = cust & " " & color1 & "--" & DGV1.Rows(DGV1.CurrentRow.Index).Cells("品名").Value
  234. 'xlSheet.Cells(2, 10) = frm_01hf_RetanRcp_WB.ListBox6.SelectedItem
  235. 'xlSheet.Cells(2, 11) = frm_01hf_RetanRcp_WB.ListBox5.SelectedItem
  236. xlSheet.Cells(2, 7) = thickness
  237. xlSheet.Cells(2, 11) = d_no
  238. xlSheet.Cells(2, 14) = my_weight & " 公斤"
  239. xlSheet.Cells(1, 4) = my_card
  240. xlSheet.Cells(3, 4) = source
  241. xlSheet.Cells(3, 10) = comment
  242. xlSheet.Cells(5, 3) = "百分比"
  243. xlSheet.Cells(5, 5) = "用量(Kgs)"
  244. xlSheet.Cells(5, 6) = "化 料 名 稱"
  245. xlSheet.Cells(5, 9) = "时间"
  246. xlSheet.Cells(5, 10) = "備註"
  247. xlSheet.Rows("5:5").Select()
  248. xlApp.Selection.Font.Underline = xlUnderlineStyleSingle
  249. For i As Integer = 0 To DataGridView1.Rows.Count - 1
  250. xlSheet.Cells(i + 6, 3) = Math.Round(Val(DataGridView1.Rows(i).Cells("百分比").Value), 2)
  251. xlSheet.Cells(i + 6, 4) = "%"
  252. xlSheet.Cells(i + 6, 5) = Math.Round(DataGridView1.Rows(i).Cells("百分比").Value * my_weight / 2 / 100, 2)
  253. xlSheet.Cells(i + 6, 6) = DataGridView1.Rows(i).Cells("化料名称").Value
  254. xlSheet.Cells(i + 6, 9) = DataGridView1.Rows(i).Cells("时间").Value
  255. xlSheet.Cells(i + 6, 10) = DataGridView1.Rows(i).Cells("备注").Value
  256. xlSheet.Cells(i + 6, 10).Select()
  257. With xlApp.Selection
  258. .Font.Bold = True
  259. End With
  260. 'xlSheet.Cells(i + 6, 11) = datagridview1.Rows(i).Cells("幣別").Value
  261. 'xlSheet.Cells(i + 6, 12) = datagridview1.Rows(i).Cells("單價").Value
  262. If DataGridView1.Rows(i).Cells("化料名称").Value = "流水洗" Or DataGridView1.Rows(i).Cells("化料名称").Value = "洗水" Or DataGridView1.Rows(i).Cells("化料名称").Value = "排水" Or DataGridView1.Rows(i).Cells("化料名称").Value = "轉動" Or DataGridView1.Rows(i).Cells("化料名称").Value = "自動過夜" Or DataGridView1.Rows(i).Cells("化料名称").Value = "停止" Then
  263. xlSheet.Rows(i + 5 & ":" & i + 5).Select()
  264. With xlApp.Selection.Borders(xlEdgeBottom)
  265. .LineStyle = xlNone
  266. End With
  267. xlSheet.Rows(i + 6 & ":" & i + 6).Select()
  268. With xlApp.Selection.Borders(xlEdgeBottom)
  269. .LineStyle = xlDash
  270. .Weight = xlHairline
  271. End With
  272. xlSheet.Cells(i + 6, 3) = ""
  273. xlSheet.Cells(i + 6, 4) = ""
  274. xlSheet.Cells(i + 6, 5) = ""
  275. End If
  276. If DataGridView1.Rows(i).Cells("时间").Value <> "" Then
  277. xlSheet.Rows(i + 6 & ":" & i + 6).Select()
  278. With xlApp.Selection.Borders(xlEdgeBottom)
  279. .LineStyle = xlContinuous
  280. .Weight = xlMaximum
  281. End With
  282. End If
  283. Next i
  284. Dim a As Integer = xlApp.Workbooks(1).Worksheets(1).UsedRange.Rows.Count
  285. Dim b As Integer = xlApp.Workbooks(1).Worksheets(1).UsedRange.Columns.Count
  286. Dim area As String = "A4" & ":" & Chr(b + 64) & a
  287. xlSheet.Range(area).Font.Size = 10
  288. xlSheet.Range(area).Font.Name = "Times New Roman"
  289. xlApp.Selection.Font.Name = "Times New Roman"
  290. 'xlSheet.Columns("A:O").Select()
  291. 'With xlApp.Selection
  292. ' .HorizontalAlignment = Microsoft.Office.Interop.Excel.Constants.xlCenter
  293. ' .VerticalAlignment = Microsoft.Office.Interop.Excel.Constants.xlCenter
  294. ' .WrapText = False
  295. ' .Orientation = 0
  296. ' .AddIndent = False
  297. ' .IndentLevel = 0
  298. ' .ShrinkToFit = False
  299. ' .ReadingOrder = Microsoft.Office.Core.XlReadingOrder.xlContext
  300. 'End With
  301. xlSheet.Cells(3, 4).Select()
  302. With xlApp.Selection
  303. .HorizontalAlignment = Microsoft.Office.Interop.Excel.Constants.xlLeft
  304. End With
  305. For x As Integer = 6 To a
  306. If xlSheet.Cells(x, 9).value Is Nothing And xlSheet.Cells(x, 6).value Is Nothing Then
  307. xlSheet.Rows(x).RowHeight = 3
  308. ' aa = aa + 1
  309. Else
  310. xlSheet.Rows(x).RowHeight = 18
  311. End If
  312. Next x
  313. xlSheet.Range("a:a").HorizontalAlignment = Microsoft.Office.Interop.Excel.Constants.xlCenter
  314. xlSheet.Range("c:c").HorizontalAlignment = Microsoft.Office.Interop.Excel.Constants.xlRight
  315. xlSheet.Range("e:e ").HorizontalAlignment = Microsoft.Office.Interop.Excel.Constants.xlCenter
  316. xlSheet.Range("g:g").HorizontalAlignment = Microsoft.Office.Interop.Excel.Constants.xlCenter
  317. xlSheet.Range("c:c").NumberFormatLocal = "G/通用格式"
  318. With xlApp.ActiveSheet.PageSetup
  319. .PrintTitleRows = ""
  320. .PrintTitleColumns = ""
  321. End With
  322. xlSheet.PageSetup.PrintArea = ""
  323. With xlApp.ActiveSheet.PageSetup
  324. .TopMargin = xlApp.InchesToPoints(0.2)
  325. .BottomMargin = xlApp.InchesToPoints(0)
  326. .LeftMargin = xlApp.InchesToPoints(0)
  327. .RightMargin = xlApp.InchesToPoints(0)
  328. .HeaderMargin = xlApp.InchesToPoints(0.511811023622047)
  329. .FooterMargin = xlApp.InchesToPoints(0.511811023622047)
  330. '.PaperSize = Microsoft.Office.Interop.Excel.XlPaperSize.xlPaperA4
  331. .Zoom = False
  332. .FitToPagesWide = 1
  333. .FitToPagesTall = 1
  334. .PrintErrors = Microsoft.Office.Interop.Excel.XlPrintErrors.xlPrintErrorsDisplayed
  335. End With
  336. xlApp.Cells.Select()
  337. With xlApp.Selection.Font
  338. .Name = "Times New Roman"
  339. End With
  340. xlSheet.Range("f:f").HorizontalAlignment = Microsoft.Office.Interop.Excel.Constants.xlLeft
  341. xlSheet.Range("j:j").HorizontalAlignment = Microsoft.Office.Interop.Excel.Constants.xlLeft
  342. xlSheet.Range("a1:o3").HorizontalAlignment = Microsoft.Office.Interop.Excel.Constants.xlCenter
  343. xlApp.Visible = True
  344. xlApp.Application.ScreenUpdating = True
  345. MsgBox("打印完成")
  346. End Sub
  347. Private Sub DGV1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGV1.CellClick
  348. Label1.Text = ""
  349. Timer1.Enabled = False
  350. cmdSaveEdit.Visible = False
  351. cmdCancelEdit.Visible = False
  352. If gAddfromOther = True Then
  353. Dim msg As MsgBoxResult = MsgBox("確定要從處方 '" & DGV1.Rows(e.RowIndex).Cells("品名").Value & "' 新增? ", MsgBoxStyle.YesNoCancel)
  354. If msg = MsgBoxResult.Yes Then
  355. gAddfromOther = False
  356. Dim ds As New DataSet
  357. con.Open()
  358. sql_rcp = "select RCP_NO as 處方編號, RCP_NAME as 品名, CREAT_D, LAST_EDITED, LAST_USED from " & rcp & " where rcp_no like '%" & rr & "%' or rcp_name like '%" & rcp_name & "%'"
  359. cmd.Connection = con
  360. cmd.CommandText = sql_rcp
  361. da.SelectCommand = cmd
  362. da.Fill(ds)
  363. DGV1.DataSource = ds.Tables(0)
  364. con.Close()
  365. dgv2.Visible = True
  366. ListBox2.Visible = False
  367. ListBox3.Visible = False
  368. ListBox4.Visible = False
  369. TextBox2.Visible = False
  370. TextBox3.Visible = False
  371. TextBox4.Visible = False
  372. Button11.Visible = False
  373. Button12.Visible = False
  374. Button13.Visible = False
  375. Button14.Visible = False
  376. Button15.Visible = False
  377. cmdAddrcp.Visible = True
  378. cmdcanceladd.Visible = True
  379. ElseIf msg = MsgBoxResult.No Then
  380. Exit Sub
  381. Else
  382. gAddfromOther = False
  383. End If
  384. End If
  385. End Sub
  386. 'Private Sub dgv2_RowPostPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs)
  387. ' Dim linePen As New Pen(Color.SkyBlue, 2)
  388. ' If e.RowIndex = dgv2.Rows.Count - 1 Then
  389. ' dgv2.Rows(e.RowIndex).Cells("百分比").Style.ForeColor = Color.White
  390. ' Dim startX As Integer = IIf(dgv2.RowHeadersVisible, dgv2.RowHeadersWidth, 0)
  391. ' Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  392. ' Dim endX As Integer = startX + dgv2.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - dgv2.HorizontalScrollingOffset - 50
  393. ' e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
  394. ' Exit Sub
  395. ' End If
  396. ' If dgv2.Rows(e.RowIndex).Cells("时间").Value.ToString <> "" And (dgv2.Rows(e.RowIndex + 1).Cells("化料名称").Value.ToString = "流水洗" Or dgv2.Rows(e.RowIndex + 1).Cells("化料名称").Value.ToString = "洗水" Or dgv2.Rows(e.RowIndex + 1).Cells("化料名称").Value = "排水") Then
  397. ' ElseIf dgv2.Rows(e.RowIndex).Cells("时间").Value.ToString <> "" Then
  398. ' Dim startX As Integer = IIf(dgv2.RowHeadersVisible, dgv2.RowHeadersWidth, 0)
  399. ' Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  400. ' Dim endX As Integer = startX + dgv2.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - dgv2.HorizontalScrollingOffset - 50
  401. ' e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
  402. ' End If
  403. ' If (dgv2.Rows(e.RowIndex).Cells("化料名称").Value.ToString = "流水洗" Or dgv2.Rows(e.RowIndex).Cells("化料名称").Value.ToString = "洗水" Or dgv2.Rows(e.RowIndex).Cells("化料名称").Value = "排水") Then
  404. ' dgv2.Rows(e.RowIndex).Cells("百分比").Style.ForeColor = Color.White
  405. ' Dim startX As Integer = IIf(dgv2.RowHeadersVisible, dgv2.RowHeadersWidth, 0)
  406. ' Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  407. ' Dim endX As Integer = startX + dgv2.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - dgv2.HorizontalScrollingOffset - 50
  408. ' e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
  409. ' End If
  410. 'End Sub
  411. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  412. gMsg = MsgBox("要插入前方列請按--是" & vbCrLf & "要插入後方列請按--否" & vbCrLf & "或按取消離開", MsgBoxStyle.YesNoCancel)
  413. If gMsg <> MsgBoxResult.Cancel Then
  414. FrmEditChem_Choose.ShowDialog()
  415. End If
  416. End Sub
  417. Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  418. If Not (DataGridView1.Rows(DataGridView1.CurrentRow.Index).DefaultCellStyle.Font Is Nothing) Then
  419. If DataGridView1.Rows(DataGridView1.CurrentRow.Index).DefaultCellStyle.Font.Style = FontStyle.Strikeout Then
  420. DataGridView1.Rows(DataGridView1.CurrentRow.Index).DefaultCellStyle.Font = New Font(DataGridView1.DefaultCellStyle.Font, FontStyle.Regular)
  421. Else
  422. DataGridView1.Rows(DataGridView1.CurrentRow.Index).DefaultCellStyle.Font = New Font(DataGridView1.DefaultCellStyle.Font, FontStyle.Strikeout)
  423. End If
  424. Else
  425. DataGridView1.Rows(DataGridView1.CurrentRow.Index).DefaultCellStyle.Font = New Font(DataGridView1.DefaultCellStyle.Font, FontStyle.Strikeout)
  426. End If
  427. Label1.Text = "修改模式"
  428. Timer1.Enabled = True
  429. cmdSaveEdit.Visible = True
  430. cmdCancelEdit.Visible = True
  431. End Sub
  432. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  433. If DataGridView1.SelectedRows.Count = 0 Then
  434. MsgBox("請先選擇要修改的項目")
  435. Exit Sub
  436. End If
  437. Label1.Text = "修改模式"
  438. Timer1.Enabled = True
  439. Dim f2 As New FrmEditChem_Choose
  440. f2.Owner = Me
  441. f2.ShowDialog()
  442. ' FrmEditChem_Choose.ShowDialog()
  443. cmdSaveEdit.Visible = True
  444. cmdCancelEdit.Visible = True
  445. DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells("化料名称").Value = my_chem
  446. DataGridView1.Focus()
  447. End Sub
  448. Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
  449. Dim rmb As Double = 0
  450. Dim usd As Double = 0
  451. Dim euro As Double = 0
  452. Dim hkd As Double = 0
  453. Dim dye As Double = 0
  454. Dim oil As Double = 0
  455. Dim tan As Double = 0
  456. Dim x As Double = 0
  457. Dim kj As Double = 0
  458. Dim xx As Double = 0
  459. If con.State = ConnectionState.Closed Then
  460. con.Open()
  461. End If
  462. If e.KeyCode <> Keys.Enter Then
  463. Exit Sub
  464. End If
  465. Dim sql As String = ""
  466. sql = "select * from tblcurrency where year='" & Year(DateTime.Now) & "' and month='" & Month(DateTime.Now) & "'"
  467. cmd.CommandText = sql
  468. cmd.Connection = con
  469. dr = cmd.ExecuteReader
  470. If dr.Read Then
  471. rmb = dr("rmb")
  472. usd = dr("usd")
  473. hkd = dr("hkd")
  474. euro = dr("euro")
  475. dr.Close()
  476. Else
  477. dr.Close()
  478. sql = "select * from tblcurrency order by year desc,month desc"
  479. cmd.CommandText = sql
  480. ' dr.Read()
  481. dr = cmd.ExecuteReader
  482. dr.Read()
  483. rmb = dr("rmb")
  484. usd = dr("usd")
  485. hkd = dr("hkd")
  486. euro = dr("euro")
  487. dr.Close()
  488. End If
  489. sql = " SELECT MATLKIND.MATLKIND,SUM(rcp_content.percents / 100 * " & TextBox1.Text & ") as retan,tblMaterial.COIN,SUM(tblMaterial.PUR_UNIT * rcp_content.percents / 100 * " & TextBox1.Text & ") AS retan_cost FROM rcp_content INNER JOIN tblMaterial ON rcp_content.MATL_NO = tblMaterial.MATL_NO INNER JOIN MATLKIND ON tblMaterial.MATL_ID = MATLKIND.MATL_ID WHERE (rcp_content.RCP_NO = '" & DGV1.Rows(DGV1.CurrentRow.Index).Cells("處方編號").Value & "') AND (tblMaterial.COIN IS NOT NULL) GROUP BY tblMaterial.MATL_ID, tblMaterial.COIN, tblMaterial.MATL_ID, MATLKIND.MATLKIND ORDER BY tblMaterial.MATL_ID"
  490. cmd.CommandText = sql
  491. dr = cmd.ExecuteReader
  492. While dr.Read
  493. Select Case dr("matlkind")
  494. Case "染料"
  495. Select Case dr("coin")
  496. Case "RMB"
  497. dye += dr("retan_cost") * rmb
  498. Case "USD"
  499. dye += dr("retan_cost") * usd
  500. Case "歐元"
  501. dye += dr("retan_cost") * euro
  502. Case "港幣"
  503. dye += dr("retan_cost") * hkd
  504. Case "台幣"
  505. dye += dr("retan_cost")
  506. End Select
  507. Case "植物鞣剂"
  508. Select Case dr("coin")
  509. Case "RMB"
  510. kj += dr("retan_cost") * rmb
  511. Case "USD"
  512. kj += dr("retan_cost") * usd
  513. Case "歐元"
  514. kj += dr("retan_cost") * euro
  515. Case "港幣"
  516. kj += dr("retan_cost") * hkd
  517. Case "台幣"
  518. kj += dr("retan_cost")
  519. End Select
  520. Case "油脂"
  521. Select Case dr("coin")
  522. Case "RMB"
  523. oil += dr("retan_cost") * rmb
  524. Case "USD"
  525. oil += dr("retan_cost") * usd
  526. Case "歐元"
  527. oil += dr("retan_cost") * euro
  528. Case "港幣"
  529. oil += dr("retan_cost") * hkd
  530. Case "台幣"
  531. oil += dr("retan_cost")
  532. End Select
  533. Case "單寧", "樹脂", "铬粉"
  534. Select Case dr("coin")
  535. Case "RMB"
  536. tan += dr("retan_cost") * rmb
  537. Case "USD"
  538. tan += dr("retan_cost") * usd
  539. Case "歐元"
  540. tan += dr("retan_cost") * euro
  541. Case "港幣"
  542. tan += dr("retan_cost") * hkd
  543. Case "台幣"
  544. tan += dr("retan_cost")
  545. End Select
  546. Case "中和剂", "一般化料"
  547. Select Case dr("coin")
  548. Case "RMB"
  549. x += dr("retan_cost") * rmb
  550. Case "USD"
  551. x += dr("retan_cost") * usd
  552. Case "歐元"
  553. x += dr("retan_cost") * euro
  554. Case "港幣"
  555. x += dr("retan_cost") * hkd
  556. Case "台幣"
  557. x += dr("retan_cost")
  558. End Select
  559. Case Else
  560. Select Case dr("coin")
  561. Case "RMB"
  562. xx += dr("retan_cost") * rmb
  563. Case "USD"
  564. xx += dr("retan_cost") * usd
  565. Case "歐元"
  566. xx += dr("retan_cost") * euro
  567. Case "港幣"
  568. xx += dr("retan_cost") * hkd
  569. Case "台幣"
  570. xx += dr("retan_cost")
  571. End Select
  572. End Select
  573. End While
  574. txttan.Text = Math.Round(tan, 3)
  575. txtKJ.Text = Math.Round(kj, 3)
  576. txtoil.Text = Math.Round(oil, 3)
  577. txtdye.Text = Math.Round(dye, 3)
  578. txtx.Text = Math.Round(x, 3)
  579. txtxx.Text = Math.Round(xx, 3)
  580. txtsum.Text = Math.Round(tan + oil + kj + dye + x + xx, 3)
  581. txtsize.Focus()
  582. con.Close()
  583. End Sub
  584. Private Sub txtsize_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtsize.KeyUp
  585. If e.KeyCode <> Keys.Enter Then
  586. Exit Sub
  587. End If
  588. txttan.Text = Math.Round(txttan.Text / txtsize.Text, 3)
  589. txtoil.Text = Math.Round(txtoil.Text / txtsize.Text, 3)
  590. txtdye.Text = Math.Round(txtdye.Text / txtsize.Text, 3)
  591. txtx.Text = Math.Round(txtx.Text / txtsize.Text, 3)
  592. txtxx.Text = Math.Round(txtxx.Text / txtsize.Text, 3)
  593. txtKJ.Text = Math.Round(txtKJ.Text / txtsize.Text, 3)
  594. txtsum.Text = Math.Round(txtsum.Text / txtsize.Text, 3)
  595. End Sub
  596. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  597. If con.State = ConnectionState.Closed Then
  598. con.Open()
  599. End If
  600. Dim rcp1 As String = ""
  601. rcp1 = TextBox18.Text
  602. ' rcp1 = InputBox("請輸入要查詢的處方編號或處方名稱")
  603. If rcp1 = "" Then Exit Sub
  604. sql_rcp = "select NAME as 品名, date as 日期,selection,no from ht_retanrcp where name like N'%" & rcp1 & "%' group by name,date,selection,no order by name,date desc"
  605. sql_rcp = "select top(200) name as 品名,date as 日期,selection as 选级,avg(weight) as 重量,no as 流程卡号,rcp_no as 表格编号 from ht_retanrcp where name like N'%" & rcp1 & "%' group by name,date,selection,rcp_no,no order by date desc"
  606. cmd.Connection = con
  607. cmd.CommandText = sql_rcp
  608. da.SelectCommand = cmd
  609. Dim dt As New DataTable
  610. da.Fill(dt)
  611. DGV1.DataSource = dt
  612. con.Close()
  613. 'DGV1.Columns(0).Width = 280
  614. 'DGV1.Columns(1).Width = 140
  615. Dim c As Integer = 1
  616. Dim p(200) As Integer
  617. Dim x As Integer
  618. p(1) = 0
  619. For x = 1 To DGV1.Rows.Count - 2
  620. If DGV1.Rows(x).Cells(0).Value.ToString <> DGV1.Rows(x - 1).Cells(0).Value.ToString Then
  621. p(c + 1) = x
  622. c = c + 1
  623. End If
  624. Next
  625. p(c + 1) = x
  626. ReDim Preserve p(x)
  627. If c = 1 Then
  628. For z As Integer = 0 To x - 1
  629. DGV1.Rows(z).DefaultCellStyle.BackColor = colorArray(1)
  630. Next
  631. Else
  632. For cc As Integer = 1 To c
  633. For z As Integer = p(cc) To p(cc + 1) - 1
  634. DGV1.Rows(z).DefaultCellStyle.BackColor = colorArray(cc Mod 5)
  635. Next
  636. Next
  637. End If
  638. DGV1.Columns(0).Width = 170
  639. DGV1.Columns(1).Width = 100
  640. DGV1.Columns(3).Width = 70
  641. DGV1.Columns(4).Width = 150
  642. DGV1.RowHeadersWidth = 30
  643. DataGridView1.RowHeadersWidth = 30
  644. DataGridView1.RowTemplate.Height = 26
  645. End Sub
  646. Private Sub DGV1_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGV1.CellEnter
  647. 'Dim ds1 As New DataSet
  648. 'Dim ds2 As New DataSet
  649. 'Dim cn As New SqlConnection
  650. 'cn.ConnectionString = connstring
  651. 'cn.Open()
  652. 'cmd.Connection = cn
  653. 'txttan.Text = ""
  654. 'txtKJ.Text = ""
  655. 'txtoil.Text = ""
  656. 'txtdye.Text = ""
  657. 'txtx.Text = ""
  658. 'txtxx.Text = ""
  659. 'txtsum.Text = ""
  660. 'Dim dt As New DataTable
  661. 'sql_rcp = "SELECT serial AS 项目, CHEM AS 化料名称, PERCENTAGE AS 百分比, time AS 时间, WEIGHT AS 重量,comment AS 备注 from rt_retan_rcp_detail where rcp_name =N'" & DGV1.Rows(DGV1.CurrentRow.Index).Cells("处方编号").Value & "' order by serial"
  662. 'cmd.CommandText = sql_rcp
  663. 'da.SelectCommand = cmd
  664. 'da.Fill(dt)
  665. 'dgv2.DataSource = dt
  666. 'set_grid1()
  667. 'rcp = "rt_retan_rcp"
  668. 'sql_rcp = "select creat_d from " & rcp & " where RCP_NO='" & DGV1.Rows(DGV1.CurrentRow.Index).Cells(0).Value & "'"
  669. 'cmd.CommandText = sql_rcp
  670. 'If cmd.ExecuteScalar Is Nothing Then
  671. 'Else
  672. ' txtcreate.Text = cmd.ExecuteScalar.ToString
  673. 'End If
  674. 'sql_rcp = "select last_used from " & rcp & " where RCP_NO='" & DGV1.Rows(DGV1.CurrentRow.Index).Cells(0).Value & "'"
  675. 'cmd.CommandText = sql_rcp
  676. 'If cmd.ExecuteScalar Is Nothing Then
  677. 'Else
  678. ' txtuse.Text = cmd.ExecuteScalar.ToString
  679. 'End If
  680. 'sql_rcp = "select last_edited from " & rcp & " where RCP_NO='" & DGV1.Rows(DGV1.CurrentRow.Index).Cells(0).Value & "'"
  681. 'cmd.CommandText = sql_rcp
  682. 'If cmd.ExecuteScalar Is Nothing Then
  683. 'Else
  684. ' txtedit.Text = cmd.ExecuteScalar.ToString
  685. 'End If
  686. 'sql_rcp = "select editor from " & rcp & " where RCP_NO='" & DGV1.Rows(DGV1.CurrentRow.Index).Cells(0).Value & "'"
  687. 'cmd.CommandText = sql_rcp
  688. 'If cmd.ExecuteScalar Is Nothing Then
  689. 'Else
  690. ' ' txteditor.Text = cmd.ExecuteScalar.ToString
  691. ' 'End If
  692. ' txteditor.Text = cmd.ExecuteScalar.ToString
  693. 'End If
  694. ' sql_rcp = "SELECT rcp_content.ITEM AS 項目, rcp_content.MATL_NO AS 化料編號, tblMaterial.MATL_NAME AS 化料名称, rcp_content.percents AS 百分比, " &
  695. '" rcp_content.time AS 时间, rcp_content.comment AS 備註, tblMaterial.COIN AS 幣別, tblMaterial.PUR_UNIT AS 單價 " &
  696. '" FROM " & rcp & " INNER JOIN " &
  697. '" rcp_content ON " & rcp & ".RCP_NO = rcp_content.RCP_NO INNER JOIN " &
  698. '" tblMaterial ON rcp_content.MATL_NO = tblMaterial.MATL_NO " &
  699. '" WHERE rcp_content.RCP_NO='" & DGV1.Rows(DGV1.CurrentRow.Index).Cells(0).Value & "edit' ORDER BY 項目"
  700. ' sql_rcp = "SELECT rcp_content.ITEM AS 項目, rcp_content.MATL_NO AS 化料編號, tblMaterial.MATL_NAME AS 化料名称, rcp_content.percents AS 百分比, " &
  701. ' " rcp_content.time AS 时间, rcp_content.comment AS 備註, tblMaterial.COIN AS 幣別, tblMaterial.PUR_UNIT AS 單價 " &
  702. '"FROM rcp_content INNER JOIN " &
  703. ' " tblMaterial ON rcp_content.MATL_NO = tblMaterial.MATL_NO " &
  704. '"WHERE (rcp_content.RCP_NO='" & DGV1.Rows(DGV1.CurrentRow.Index).Cells(0).Value & "edit') " &
  705. '" ORDER BY 項目"
  706. ' cmd.CommandText = sql_rcp
  707. ' da.SelectCommand = cmd
  708. ' da.Fill(ds2)
  709. ' dgv_record.DataSource = ds2.Tables(0)
  710. ' set_grid2()
  711. ' sql_rcp = "SELECT MATLKIND.MATLKIND as 類別, tblMaterial.MATL_id as 代號,round(SUM(rcp_content.percents),1) AS 比例 FROM rcp_content INNER JOIN" &
  712. ' " tblMaterial ON rcp_content.MATL_NO = tblMaterial.MATL_NO INNER JOIN " &
  713. ' " MATLKIND ON tblMaterial.MATL_ID = MATLKIND.MATL_ID" &
  714. '" WHERE (rcp_content.RCP_NO='" & DGV1.Rows(DGV1.CurrentRow.Index).Cells(0).Value & "') AND (tblMaterial.COIN IS NOT NULL)" &
  715. '" GROUP BY tblMaterial.MATL_ID, MATLKIND.MATLKIND" &
  716. '" ORDER BY tblMaterial.MATL_ID"
  717. ' Dim ds3 As New DataSet
  718. ' cmd.CommandText = sql_rcp
  719. ' da.SelectCommand = cmd
  720. ' da.Fill(ds3)
  721. ' dgv_cost.DataSource = ds3.Tables(0)
  722. ' set_grid3()
  723. ' cn.Close()
  724. End Sub
  725. Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
  726. Dim con As New SqlConnection
  727. Dim sql As String
  728. Dim dr As SqlDataReader
  729. con.ConnectionString = connstring
  730. con.Open()
  731. cmd.Connection = con
  732. dgv2.Visible = False
  733. ListBox2.Visible = True
  734. ListBox3.Visible = True
  735. ListBox4.Visible = True
  736. TextBox2.Visible = True
  737. TextBox3.Visible = True
  738. TextBox4.Visible = True
  739. Button11.Visible = True
  740. Button12.Visible = True
  741. Button13.Visible = True
  742. Button14.Visible = True
  743. Button15.Visible = True
  744. sql = "select cust_name from customer order by cust_name"
  745. cmd.CommandText = sql
  746. dr = cmd.ExecuteReader
  747. While dr.Read
  748. ListBox2.Items.Add(dr("cust_name"))
  749. End While
  750. dr.Close()
  751. sql = "select prod_name from tblproduct order by prod_name"
  752. cmd.CommandText = sql
  753. dr = cmd.ExecuteReader
  754. While dr.Read
  755. ListBox3.Items.Add(dr("prod_name"))
  756. End While
  757. dr.Close()
  758. sql = "select color_name from color order by color_name"
  759. cmd.CommandText = sql
  760. dr = cmd.ExecuteReader
  761. While dr.Read
  762. ListBox4.Items.Add(dr("color_name"))
  763. End While
  764. dr.Close()
  765. Timer1.Enabled = True
  766. End Sub
  767. Private Sub TextBox2_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
  768. Dim con As New SqlConnection
  769. Dim sql As String
  770. Dim dr As SqlDataReader
  771. con.ConnectionString = connstring
  772. con.Open()
  773. cmd.Connection = con
  774. ListBox2.Items.Clear()
  775. sql = "select cust_name from customer where cust_name like '%" & TextBox2.Text & "%'"
  776. cmd.CommandText = sql
  777. dr = cmd.ExecuteReader
  778. While dr.Read
  779. ListBox2.Items.Add(dr("cust_name"))
  780. End While
  781. dr.Close()
  782. If e.KeyCode = Keys.Enter Then
  783. If ListBox2.Items.Count = 0 Then Exit Sub
  784. ListBox2.Focus()
  785. ListBox2.SelectedIndex = 1
  786. End If
  787. End Sub
  788. Private Sub TextBox3_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
  789. Dim con As New SqlConnection
  790. Dim sql As String
  791. Dim dr As SqlDataReader
  792. con.ConnectionString = connstring
  793. con.Open()
  794. cmd.Connection = con
  795. ListBox3.Items.Clear()
  796. sql = "select prod_name from tblproduct where prod_name like '%" & TextBox3.Text & "%'"
  797. cmd.CommandText = sql
  798. dr = cmd.ExecuteReader
  799. While dr.Read
  800. ListBox3.Items.Add(dr("prod_name"))
  801. End While
  802. dr.Close()
  803. If e.KeyCode = Keys.Enter Then
  804. If ListBox3.Items.Count = 0 Then Exit Sub
  805. ListBox3.Focus()
  806. ListBox3.SelectedIndex = 1
  807. End If
  808. End Sub
  809. Private Sub TextBox4_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
  810. Dim con As New SqlConnection
  811. Dim sql As String
  812. Dim dr As SqlDataReader
  813. con.ConnectionString = connstring
  814. con.Open()
  815. cmd.Connection = con
  816. ListBox4.Items.Clear()
  817. sql = "select color_name from color where color_name like '%" & TextBox4.Text & "%'"
  818. cmd.CommandText = sql
  819. dr = cmd.ExecuteReader
  820. While dr.Read
  821. ListBox4.Items.Add(dr("color_name"))
  822. End While
  823. dr.Close()
  824. If e.KeyCode = Keys.Enter Then
  825. If ListBox3.Items.Count = 0 Then Exit Sub
  826. ListBox4.Focus()
  827. ListBox4.SelectedIndex = 1
  828. End If
  829. End Sub
  830. Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  831. If ListBox2.SelectedIndex = -1 Or ListBox2.SelectedIndex = -1 Or ListBox2.SelectedIndex = -1 Then
  832. MsgBox("請先選擇客戶產品顏色", , "錯誤")
  833. Exit Sub
  834. End If
  835. Dim sql As String = ""
  836. Dim con As New SqlConnection
  837. Dim rcp_no As String = ""
  838. Dim cust_no As String = ""
  839. Dim prod_id As String = ""
  840. Dim color_no As String = ""
  841. con.ConnectionString = connstring
  842. con.Open()
  843. cmd.Connection = con
  844. sql = "select id from customer where cust_name='" & ListBox2.SelectedItem & "'"
  845. cmd.CommandText = sql
  846. cust_no = cmd.ExecuteScalar
  847. sql = "select prod_id from tblproduct where prod_name='" & ListBox3.SelectedItem & "'"
  848. cmd.CommandText = sql
  849. prod_id = cmd.ExecuteScalar
  850. sql = "select color_no from color where color_name='" & ListBox4.SelectedItem & "'"
  851. cmd.CommandText = sql
  852. color_no = cmd.ExecuteScalar
  853. sql = "select count(*) from " & rcp & " where substring(rcp_no,4,3)='" & cust_no & "' and substring(rcp_no,1,1)='" & prod_id & "' and substring(rcp_no,7,2)='" & color_no & "'"
  854. cmd.CommandText = sql
  855. Dim c As Integer = cmd.ExecuteScalar
  856. If c = 0 Then
  857. rr = prod_id & String.Format("{0:D2}", c) & String.Format("{0:D3}", cust_no) & color_no
  858. Else
  859. rr = prod_id & String.Format("{0:D2}", c + 1) & String.Format("{0:D3}", cust_no) & color_no
  860. End If
  861. sql = "select count(*) from " & rcp & " where rcp_no='" & rr & "'"
  862. cmd.CommandText = sql
  863. c = cmd.ExecuteScalar
  864. rcp_name = ListBox2.SelectedItem & ListBox4.SelectedItem & ListBox3.SelectedItem
  865. rcp_name = InputBox("處方名稱", "詢問", rcp_name)
  866. sql = "select count(*) from " & rcp & " where rcp_no='" & rr & "'"
  867. cmd.CommandText = sql
  868. Dim a As Integer = cmd.ExecuteScalar
  869. If a = 0 Then
  870. 'sql = "insert into " & rcp & " (rcp_no,rcp_name,creat_d) values ( '" & rcp_no & "','" & rcp_name & "','" & Now & "')"
  871. 'cmd.CommandText = sql
  872. 'Dim b As Integer = cmd.ExecuteScalar()
  873. 'If b <> 0 Then
  874. ' MsgBox("新增處方完成")
  875. ' Exit Sub
  876. 'End If
  877. Else
  878. MsgBox("處方編號重覆")
  879. gAddfromOther = False
  880. Exit Sub
  881. End If
  882. Dim msg As MsgBoxResult
  883. msg = MsgBox("是否要由其他處方修改?", vbYesNoCancel, "詢問")
  884. gAddfromOther = True
  885. Dim my_rcp As String = ""
  886. my_rcp = InputBox("請輸入處方編號")
  887. If my_rcp = "" Then Exit Sub
  888. sql_rcp = "select RCP_NO as 處方編號, RCP_NAME as 品名, CREAT_D, LAST_EDITED, LAST_USED from " & rcp & " where rcp_no like '%" & my_rcp & "%' or rcp_name like '%" & my_rcp & "%'"
  889. cmd.CommandText = sql_rcp
  890. da.SelectCommand = cmd
  891. Dim ds As New DataSet
  892. da.Fill(ds)
  893. DGV1.DataSource = ds.Tables(0)
  894. Timer1.Enabled = True
  895. con.Close()
  896. End Sub
  897. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  898. If Label1.Visible = True Then
  899. Label1.Visible = False
  900. Else
  901. Label1.Visible = True
  902. End If
  903. End Sub
  904. Private Sub cmdAddrcp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddrcp.Click
  905. If conn.State = ConnectionState.Closed Then
  906. conn.Open()
  907. End If
  908. Dim sql As String = ""
  909. sql = "insert into " & rcp & " (rcp_no,rcp_name,creat_d) values ( '" & rr & "','" & rcp_name & "','" & String.Format("{0:d}", DateTime.Now) & "')"
  910. cmd.CommandText = sql
  911. cmd.Connection = conn
  912. Dim b As Integer = cmd.ExecuteNonQuery
  913. If b <> 0 Then
  914. MsgBox("已新增處方編號:" & rr & vbCrLf & " 處方名稱:" & rcp_name)
  915. Else
  916. MsgBox("新增處方失敗")
  917. End If
  918. Dim dt As DataTable
  919. dt = dgv2.DataSource
  920. 'For x As Integer = 0 To dt.Rows.Count - 1
  921. ' cmd.CommandText = "insert into rcp_content (item,matl_no,percents,rcp_no,time,comment) values ('" & dt.Rows(x).Item("項目").ToString & "','" & dt.Rows(x).Item("化料編號").ToString & "','" & dt.Rows(x).Item("百分比").ToString & "','" & rr & "','" & dt.Rows(x).Item("时间").ToString & "','" & dt.Rows(x).Item("備註").ToString & "')"
  922. ' cmd.ExecuteNonQuery()
  923. 'Next
  924. For x As Integer = 0 To dt.Rows.Count - 1
  925. cmd.CommandText = "insert into rcp_content (item,matl_no,percents,rcp_no,time,comment) values ('" & dt.Rows(x).Item("項目").ToString & "','" & dt.Rows(x).Item("化料編號").ToString & "','" & dt.Rows(x).Item("百分比").ToString & "','" & rr & "','" & dt.Rows(x).Item("时间").ToString & "','" & dt.Rows(x).Item("備註").ToString & "')"
  926. cmd.ExecuteNonQuery()
  927. 'cmd.CommandText = "insert into rcp_content (item,matl_no,percents,rcp_no,time,comment) values ('03','X613','1','E00250WD','20','停40轉20停40')"
  928. 'cmd.ExecuteNonQuery()
  929. Next
  930. cmdAddrcp.Visible = False
  931. cmdcanceladd.Visible = False
  932. Timer1.Enabled = False
  933. Label1.Visible = False
  934. conn.Close()
  935. End Sub
  936. Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  937. dgv2.Visible = True
  938. ListBox2.Visible = False
  939. ListBox3.Visible = False
  940. ListBox4.Visible = False
  941. TextBox2.Visible = False
  942. TextBox3.Visible = False
  943. TextBox4.Visible = False
  944. Button11.Visible = False
  945. Button12.Visible = False
  946. Button13.Visible = False
  947. Button14.Visible = False
  948. Button15.Visible = False
  949. Button17.Visible = False
  950. cmdAddrcp.Visible = False
  951. cmdcanceladd.Visible = False
  952. Timer1.Enabled = False
  953. Label1.Visible = False
  954. End Sub
  955. Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click '打印标签
  956. ' ini_content() '取得卡号等相关资讯
  957. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  958. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  959. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  960. Dim folderPath As String = "\\DS920plus\华峰业务\AA化料文件资料\2024年整理MSDS和ZDHC\MSDS\MSDS总表"
  961. Dim my_card As String
  962. Dim my_weight As Double
  963. Dim d_no As String
  964. Do
  965. my_card = InputBox("请输入卡号:", "查询")
  966. If my_card = "" Then
  967. MsgBox("操作已取消。", vbInformation, "退出")
  968. Exit Sub ' 立即退出子程序
  969. ElseIf my_card = "" Then
  970. MsgBox("请重新输入!", vbExclamation, "错误")
  971. Else
  972. Exit Do
  973. End If
  974. Loop
  975. ' 验证重量输入
  976. Do
  977. Dim weightInput As String
  978. weightInput = InputBox("请输入重量:", "查询")
  979. If weightInput = "" Then
  980. MsgBox("操作已取消。", vbInformation, "退出")
  981. Exit Sub
  982. ElseIf Not IsNumeric(weightInput) Then
  983. MsgBox("重量必须是数字,请重新输入!", vbExclamation, "错误")
  984. ElseIf CDbl(weightInput) <= 0 Then
  985. MsgBox("重量必须大于0,请重新输入!", vbExclamation, "错误")
  986. Else
  987. my_weight = CDbl(weightInput)
  988. Exit Do
  989. End If
  990. Loop
  991. ' 验证编号输入
  992. Do
  993. d_no = InputBox("请输入编号:", "查询")
  994. If d_no = "" Then
  995. MsgBox("操作已取消。", vbInformation, "退出")
  996. Exit Sub
  997. ElseIf d_no Like "*-*" Then
  998. ' MsgBox("编号格式不正确,请输入类似 'P241129-4' 的编号!", vbExclamation, "错误")
  999. Else
  1000. Exit Do
  1001. End If
  1002. Loop
  1003. 'frm_01hf_RetanRcp_WB.ShowDialog()
  1004. xlApp = CreateObject("Excel.Application")
  1005. xlBook = xlApp.Workbooks.Add
  1006. xlApp.DisplayAlerts = False
  1007. xlBook.Activate()
  1008. xlBook.Parent.Windows(1).Visible = True
  1009. xlSheet = xlBook.Worksheets.Add
  1010. xlSheet.Activate()
  1011. xlApp.Visible = True
  1012. ' DT2.DefaultView.Sort = "分类 "
  1013. 'dt = dt.DefaultView.ToTable()
  1014. Dim xx As Integer = 0
  1015. Dim y As Integer = 0
  1016. Dim p(10) As String
  1017. p(1) = "c:\GHS\1.jpg"
  1018. p(2) = "c:\GHS\2.jpg"
  1019. p(3) = "c:\GHS\3.jpg"
  1020. p(4) = "c:\GHS\4.jpg"
  1021. p(5) = "c:\GHS\5.jpg"
  1022. p(6) = "c:\GHS\6.jpg"
  1023. p(7) = "c:\GHS\7.jpg"
  1024. p(8) = "c:\GHS\8.jpg"
  1025. p(9) = "c:\GHS\9.jpg"
  1026. Dim FILE_NAME As String
  1027. Dim FILE_NAME1 As String
  1028. 'Dim obj As New FolderBrowserDialog
  1029. Dim sPath As String
  1030. sPath = "c:\GHS\"
  1031. Dim dt As DataTable = CType(DataGridView1.DataSource, DataTable)
  1032. Dim dv As DataView = dt.DefaultView
  1033. dv.Sort = "类别 ASC, 项次 ASC"
  1034. ' 重新绑定排序后的 DataView
  1035. DataGridView1.DataSource = dv
  1036. ' DataGridView1.Sort(DataGridView1.Columns("类别"), ListSortDirection.Ascending)
  1037. Dim zzz As Integer = 0
  1038. For x As Integer = 0 To DataGridView1.Rows.Count - 2 '---迴圈
  1039. If (DataGridView1.Rows(x).Cells("类别").Value <> "不列印") Then
  1040. If Not (DataGridView1.Rows(x).DefaultCellStyle.Font Is Nothing) Then
  1041. GoTo ok11
  1042. End If
  1043. ' PictureBox1.Image = MakeQrCode(DGV1.Rows(DGV1.CurrentCell.RowIndex).Cells("品名").Value & vbCrLf & my_card & vbCrLf & color1 & vbCrLf & DataGridView1.Rows(x).Cells("化料名称").Value & vbCrLf & Math.Round(DataGridView1.Rows(x).Cells("百分比").Value * my_weight, 1))
  1044. PictureBox1.Image = MakeQrCode("http://192.168.110.164:8888/" & DataGridView1.Rows(x).Cells("filename").Value)
  1045. System.Windows.Forms.Clipboard.SetDataObject(PictureBox1.Image, True) '---------------------------------------复制到剪贴板 二维码
  1046. If System.Windows.Forms.Clipboard.ContainsImage() Then
  1047. Console.WriteLine("剪贴板包含有效的图片数据")
  1048. Else
  1049. Console.WriteLine("剪贴板中没有图片数据")
  1050. End If
  1051. System.Threading.Thread.Sleep(200)
  1052. Dim range2 As Excel.Range = xlSheet.Range(xlApp.Cells(y * 13 + 9, 4), xlApp.Cells(y * 13 + 9, 4)) '粘贴图片的位置 二维码
  1053. xlSheet.Paste(range2, PictureBox1.Image)
  1054. Dim shape As Excel.Shape = xlApp.Selection.ShapeRange.Item(1)
  1055. shape.ScaleWidth(0.29, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoScaleFrom.msoScaleFromTopLeft)
  1056. shape.IncrementLeft(45)
  1057. shape.IncrementTop(-14)
  1058. 'PictureBox1.Select()
  1059. 'xlApp.Selection.ShapeRange.ScaleWidth(0.29, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoScaleFrom.msoScaleFromTopLeft)
  1060. 'xlApp.Selection.ShapeRange.Incrementleft(45)
  1061. 'xlApp.Selection.ShapeRange.Incrementtop(-14)
  1062. ' zzz = zzz + 1
  1063. Dim z1 As Integer = 0
  1064. For z As Integer = 1 To 9
  1065. If DataGridView1.Rows(x).Cells("d" & z).Value.ToString <> "" Then
  1066. System.Windows.Forms.Clipboard.SetDataObject(p(z), True) '复制到剪贴板
  1067. If z1 < 3 Then
  1068. Dim range1 As Excel.Range = xlSheet.Range(xlApp.Cells(y * 13 + 4, z1 + 1), xlApp.Cells(y * 13 + 4, z1 + 1)) '粘贴图片的位置
  1069. range1.Select()
  1070. ' xlApp.ActiveSheet.Pictures.Insert(p(z))
  1071. ' xlSheet.Paste(range1, p(z))
  1072. With xlApp.ActiveSheet.Pictures.Insert(p(z))
  1073. With .ShapeRange
  1074. .LockAspectRatio = Microsoft.Office.Core.MsoTriState.msoTrue
  1075. '.Width = 75
  1076. '.Height = 100
  1077. .ScaleWidth(0.09, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoScaleFrom.msoScaleFromTopLeft)
  1078. End With
  1079. '.Left = xlApp.ActiveSheet.Cells(i, 20).Left
  1080. '.Top = xlApp.ActiveSheet.Cells(i, 20).Top
  1081. '.Placement = 1
  1082. '.PrintObject = True
  1083. End With
  1084. Else
  1085. Dim range1 As Excel.Range = xlSheet.Range(xlApp.Cells(y * 13 + 9, (z1 Mod 3) + 1), xlApp.Cells(y * 13 + 9, (z1 Mod 3) + 1)) '粘贴图片的位置
  1086. range1.Select()
  1087. ' xlApp.ActiveSheet.Pictures.Insert(p(z))
  1088. 'xlSheet.Paste(range1, p(z))
  1089. With xlApp.ActiveSheet.Pictures.Insert(p(z))
  1090. With .ShapeRange
  1091. .LockAspectRatio = Microsoft.Office.Core.MsoTriState.msoTrue
  1092. ' .Width = 75
  1093. '.Height = 100
  1094. .ScaleWidth(0.09, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoScaleFrom.msoScaleFromTopLeft)
  1095. End With
  1096. '.Left = xlApp.ActiveSheet.Cells(i, 20).Left
  1097. '.Top = xlApp.ActiveSheet.Cells(i, 20).Top
  1098. '.Placement = 1
  1099. '.PrintObject = True
  1100. End With
  1101. End If
  1102. 'Dim pic1 As String
  1103. 'pic1 = "圖片 " & zzz + 3
  1104. 'xlApp.ActiveSheet.Shapes.Range(pic1).Select
  1105. 'xlApp.Selection.ShapeRange.ScaleWidth(0.09, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoScaleFrom.msoScaleFromTopLeft)
  1106. ' xlApp.Selection.ShapeRange.Incrementtop(-1)
  1107. ' y = y + 1
  1108. zzz = zzz + 1
  1109. z1 = z1 + 1
  1110. End If
  1111. Next
  1112. xlSheet.Cells(y * 13 + 1, 5).select
  1113. xlSheet.Cells(y * 13 + 1, 5) = "序号:" & DataGridView1.Rows(x).Cells("项次").Value
  1114. xlSheet.Cells(y * 13 + 1, 4).font.bold = True
  1115. xlSheet.Cells(y * 13 + 1, 1) = "卡号:" & my_card
  1116. xlSheet.Cells(y * 13 + 1, 1).font.bold = True
  1117. xlSheet.Cells(y * 13 + 1, 1).font.bold = True
  1118. xlSheet.Cells(y * 13 + 4, 5) = "鼓号"
  1119. xlSheet.Cells(y * 13 + 5, 5) = d_no
  1120. xlSheet.Cells(y * 13 + 4, 5).font.bold = True
  1121. xlSheet.Cells(y * 13 + 5, 5).font.bold = True
  1122. xlSheet.Cells(y * 13 + 6, 5) = "下鼓重"
  1123. xlSheet.Cells(y * 13 + 7, 5) = my_weight
  1124. xlSheet.Cells(y * 13 + 6, 5).font.bold = True
  1125. xlSheet.Cells(y * 13 + 7, 5).font.bold = True
  1126. xlSheet.Cells(y * 13 + 6, 4) = "百分比"
  1127. xlSheet.Cells(y * 13 + 7, 4) = DataGridView1.Rows(x).Cells("百分比").Value
  1128. xlSheet.Cells(y * 13 + 6, 4).font.bold = True
  1129. xlSheet.Cells(y * 13 + 7, 4).font.bold = True
  1130. ' xlSheet.Cells(y * 13 + 3, 3) = "客户: " & cust
  1131. 'xlSheet.Cells(y * 13 + 4, 3) = "颜色: " & color1
  1132. 'xlSheet.Cells(y * 13 + 5, 3) = "皮源: " & source
  1133. 'xlSheet.Cells(y * 13 + 6, 3) = "皮重: " & wb_weight & "斤"
  1134. ' xlSheet.Cells(y * 12 + 6, 3) = "备注: " & comment
  1135. xlSheet.Cells(y * 13 + 2, 1) = "名称: " & DataGridView1.Rows(x).Cells("化料名称").Value
  1136. xlSheet.Cells(y * 13 + 2, 1).Font.bold = True
  1137. xlSheet.Cells(y * 13 + 2, 1).Font.SIZE = 18
  1138. xlSheet.Cells(y * 13 + 3, 1) = "重量: " & Math.Round(DataGridView1.Rows(x).Cells("百分比").Value * my_weight / 100, 2) & " 公斤"
  1139. xlSheet.Cells(y * 13 + 3, 1).font.bold = True
  1140. xlSheet.Cells(y * 13 + 3, 1).font.SIZE = 18
  1141. xlSheet.Cells(y * 13 + 3, 4) = DataGridView1.Rows(x).Cells("化工分类").Value.ToString
  1142. xlSheet.Cells(y * 13 + 3, 4).font.bold = True
  1143. xlSheet.Cells(y * 13 + 3, 4).font.SIZE = 18
  1144. With xlSheet.Range(xlApp.Cells(y * 13 + 2, 1), xlApp.Cells(y * 13 + 3, 5)).Borders(xlEdgeLeft)
  1145. .LineStyle = xlContinuous
  1146. '.ColorIndex = 0
  1147. '.TintAndShade = 0
  1148. .Weight = xlMedium
  1149. End With
  1150. With xlSheet.Range(xlApp.Cells(y * 13 + 2, 1), xlApp.Cells(y * 13 + 3, 5)).Borders(xlEdgeRight)
  1151. .LineStyle = xlContinuous
  1152. '.ColorIndex = 0
  1153. '.TintAndShade = 0
  1154. .Weight = xlMedium
  1155. End With
  1156. With xlSheet.Range(xlApp.Cells(y * 13 + 2, 1), xlApp.Cells(y * 13 + 3, 5)).Borders(xlEdgeTop)
  1157. .LineStyle = xlContinuous
  1158. '.ColorIndex = 0
  1159. '.TintAndShade = 0
  1160. .Weight = xlMedium
  1161. End With
  1162. With xlSheet.Range(xlApp.Cells(y * 13 + 2, 1), xlApp.Cells(y * 13 + 3, 5)).Borders(xlEdgeBottom)
  1163. .LineStyle = xlContinuous
  1164. '.ColorIndex = 0
  1165. '.TintAndShade = 0
  1166. .Weight = xlMedium
  1167. End With
  1168. xlApp.Range(xlSheet.Cells(y * 13 + 2, 1), xlSheet.Cells(y * 13 + 2, 5)).Select()
  1169. ' xlApp.Range("E2").Activate()
  1170. xlApp.Selection.Merge
  1171. 'xlApp.Range(xlSheet.Cells(y * 13 + 13, 2), xlSheet.Cells(y * 13 + 13, 3)).Select()
  1172. '' xlApp.Range("E2").Activate()
  1173. 'xlApp.Selection.Merge
  1174. 'With xlApp.Selection
  1175. ' .HorizontalAlignment = xlLeft
  1176. ' .VerticalAlignment = xlCenter
  1177. ' .WrapText = False
  1178. ' .Orientation = 0
  1179. ' .AddIndent = False
  1180. ' .IndentLevel = 0
  1181. ' .ShrinkToFit = True
  1182. ' .ReadingOrder = xlContext
  1183. ' .MergeCells = True
  1184. 'End With
  1185. 'With xlApp.Selection
  1186. ' .HorizontalAlignment = xlLeft
  1187. ' .VerticalAlignment = xlCenter
  1188. ' .WrapText = False
  1189. ' .Orientation = 0
  1190. ' .AddIndent = False
  1191. ' .IndentLevel = 0
  1192. ' .ShrinkToFit = False
  1193. ' .ReadingOrder = xlContext
  1194. ' .MergeCells = True
  1195. 'End With
  1196. 'With xlApp.Selection
  1197. ' .HorizontalAlignment = xlLeft
  1198. ' .VerticalAlignment = xlCenter
  1199. ' .WrapText = False
  1200. ' .Orientation = 0
  1201. ' .AddIndent = False
  1202. ' .IndentLevel = 0
  1203. ' .ShrinkToFit = True
  1204. ' .ReadingOrder = xlContext
  1205. ' .MergeCells = True
  1206. 'End With
  1207. 'xlSheet.Range(xlApp.Cells(y * 13 + 10, 1), xlApp.Cells(y * 13 + 10, 4)).Borders(xlInsideVertical).LineStyle = xlNone
  1208. 'xlSheet.Range(xlApp.Cells(y * 13 + 10, 1), xlApp.Cells(y * 13 + 10, 4)).Borders(xlInsideHorizontal).LineStyle = xlNone
  1209. xlSheet.Cells(y * 13 + 11, 2) = DGV1.Rows(DGV1.CurrentCell.RowIndex).Cells("品名").Value
  1210. xlSheet.Cells(y * 13 + 13, 2) = "打印时间: " & DateTime.Now
  1211. xlSheet.Cells(y * 13 + 12, 2) = "打印人员: " & "小甘"
  1212. 'Dim range As Excel.Range = xlSheet.Range(xlApp.Cells(y * 13 + 2, 1), xlApp.Cells(y * 13 + 2, 1)) '粘贴图片的位置
  1213. 'xlSheet.Paste(range, PictureBox1.Image)
  1214. 'Dim pic As String
  1215. 'pic = "picture " & y + 1
  1216. 'xlApp.ActiveSheet.Shapes.Range(pic).Select
  1217. 'xlApp.Selection.ShapeRange.ScaleWidth(0.5, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoScaleFrom.msoScaleFromTopLeft)
  1218. 'xlApp.Selection.ShapeRange.IncrementTop(2.2553543307)
  1219. y = y + 1
  1220. Else
  1221. ok11:
  1222. End If
  1223. Next
  1224. 'xlApp.ActiveSheet.PageSetup.PrintArea = "$A$1:$E$660"
  1225. xlApp.ActiveSheet.PageSetup.PrintArea = "$a$1:$E$" & y * 13
  1226. ' xlSheet.Columns("C:C").ColumnWidth = 10.75
  1227. Dim yy As Integer = 0
  1228. xlApp.ActiveWindow.View = Microsoft.Office.Interop.Excel.XlWindowView.xlPageBreakPreview
  1229. For x As Integer = 0 To DataGridView1.Rows.Count - 2
  1230. If DataGridView1.Rows(x).Cells("化料名称").Value <> "水" And DataGridView1.Rows(x).Cells("化料名称").Value <> "甲酸  1200kg/桶" And DataGridView1.Rows(x).Cells("化料名称").Value <> "Eusapon OC liq 1000kg/桶" Then
  1231. If yy <> 0 Then
  1232. Dim r As String
  1233. r = "A" & yy * 13 + 1
  1234. xlApp.ActiveSheet.HPageBreaks.Add(xlApp.Range(r))
  1235. 'xlApp.ActiveSheet.HPageBreaks(yy).Location = xlSheet.Range(r)
  1236. 'xlApp.ActiveSheet.HPageBreaks.Add.Range(r)
  1237. End If
  1238. yy = yy + 1
  1239. End If
  1240. Next x
  1241. 'For Each shp In xlApp.ActiveSheet.shapes
  1242. ' shp.select
  1243. ' xlApp.Selection.ShapeRange.ScaleWidth(0.1, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoScaleFrom.msoScaleFromTopLeft)
  1244. 'Next
  1245. With xlApp.ActiveSheet.PageSetup
  1246. '.LeftHeader = ""
  1247. '.CenterHeader = ""
  1248. '.RightHeader = ""
  1249. '.LeftFooter = ""
  1250. '.CenterFooter = ""
  1251. '.RightFooter = ""
  1252. .LeftMargin = xlApp.Application.InchesToPoints(0.4)
  1253. .RightMargin = xlApp.Application.InchesToPoints(0.4)
  1254. .TopMargin = xlApp.Application.InchesToPoints(0.5)
  1255. .BottomMargin = xlApp.Application.InchesToPoints(0.5)
  1256. .HeaderMargin = xlApp.Application.InchesToPoints(0)
  1257. .FooterMargin = xlApp.Application.InchesToPoints(0)
  1258. .PrintHeadings = False
  1259. .PrintGridlines = False
  1260. .PrintComments = xlPrintNoComments
  1261. .CenterHorizontally = False
  1262. .CenterVertically = False
  1263. .Orientation = xlLandscape
  1264. .Draft = False
  1265. ' .PaperSize = xlPaperA4
  1266. .FirstPageNumber = xlAutomatic
  1267. .Order = xlDownThenOver
  1268. .BlackAndWhite = False
  1269. .Zoom = 85
  1270. .PrintErrors = xlPrintErrorsDisplayed
  1271. .OddAndEvenPagesHeaderFooter = False
  1272. .DifferentFirstPageHeaderFooter = False
  1273. .ScaleWithDocHeaderFooter = True
  1274. .AlignMarginsHeaderFooter = True
  1275. End With
  1276. DataGridView1.Sort(DataGridView1.Columns("项次"), ListSortDirection.Ascending)
  1277. ' DT2.DefaultView.Sort = "项次 "
  1278. MsgBox("输出完成")
  1279. End Sub
  1280. Private Sub editFormat(ByVal myExcel As Microsoft.Office.Interop.Excel.Application, ByVal xlSheet As Microsoft.Office.Interop.Excel.Worksheet)
  1281. xlSheet.Columns("A:A").ColumnWidth = 1
  1282. xlSheet.Columns("B:B").ColumnWidth = 1
  1283. xlSheet.Columns("C:C").ColumnWidth = 8
  1284. xlSheet.Columns("D:D").ColumnWidth = 1.5
  1285. xlSheet.Columns("e:e").ColumnWidth = 9.63
  1286. xlSheet.Columns("f:f").ColumnWidth = 14.25
  1287. xlSheet.Columns("g:g").ColumnWidth = 3
  1288. xlSheet.Columns("h:h").ColumnWidth = 3
  1289. xlSheet.Columns("i:i").ColumnWidth = 3
  1290. xlSheet.Columns("j:j").ColumnWidth = 10
  1291. xlSheet.Columns("k:k").ColumnWidth = 10
  1292. xlSheet.Columns("l:l").ColumnWidth = 4.5
  1293. xlSheet.Columns("m:m").ColumnWidth = 4.5
  1294. xlSheet.Columns("n:n").ColumnWidth = 8.25
  1295. xlSheet.Columns("o:o").ColumnWidth = 6
  1296. xlSheet.Range("A1:C1").Merge() '----流程卡号
  1297. xlSheet.Range("A1:C1").Borders(xlDiagonalDown).LineStyle = xlNone
  1298. xlSheet.Range("A1:C1").Borders(xlDiagonalUp).LineStyle = xlNone
  1299. With xlSheet.Range("A1:C1").Borders(xlEdgeLeft)
  1300. .LineStyle = xlContinuous
  1301. .Weight = xlMedium
  1302. .ColorIndex = xlAutomatic
  1303. End With
  1304. With xlSheet.Range("A1:C1").Borders(xlEdgeTop)
  1305. .LineStyle = xlContinuous
  1306. .Weight = xlMedium
  1307. .ColorIndex = xlAutomatic
  1308. End With
  1309. With xlSheet.Range("A1:C1").Borders(xlEdgeBottom)
  1310. .LineStyle = xlContinuous
  1311. .Weight = xlMedium
  1312. .ColorIndex = xlAutomatic
  1313. End With
  1314. With xlSheet.Range("A1:C1").Borders(xlEdgeRight)
  1315. .LineStyle = xlContinuous
  1316. .Weight = xlMedium
  1317. .ColorIndex = xlAutomatic
  1318. End With
  1319. xlSheet.Range("A2:C2").Select() '-------打印日期
  1320. myExcel.Selection.Merge()
  1321. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  1322. myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  1323. With myExcel.Selection.Borders(xlEdgeLeft)
  1324. .LineStyle = xlContinuous
  1325. .Weight = xlMedium
  1326. .ColorIndex = xlAutomatic
  1327. End With
  1328. With myExcel.Selection.Borders(xlEdgeTop)
  1329. .LineStyle = xlContinuous
  1330. .Weight = xlMedium
  1331. .ColorIndex = xlAutomatic
  1332. End With
  1333. With myExcel.Selection.Borders(xlEdgeBottom)
  1334. .LineStyle = xlContinuous
  1335. .Weight = xlMedium
  1336. .ColorIndex = xlAutomatic
  1337. End With
  1338. With myExcel.Selection.Borders(xlEdgeRight)
  1339. .LineStyle = xlContinuous
  1340. .Weight = xlMedium
  1341. .ColorIndex = xlAutomatic
  1342. End With
  1343. xlSheet.Range("A3:C3").Select() '-----皮源
  1344. myExcel.Selection.Merge()
  1345. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  1346. myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  1347. With myExcel.Selection.Borders(xlEdgeLeft)
  1348. .LineStyle = xlContinuous
  1349. .Weight = xlMedium
  1350. .ColorIndex = xlAutomatic
  1351. End With
  1352. With myExcel.Selection.Borders(xlEdgeTop)
  1353. .LineStyle = xlContinuous
  1354. .Weight = xlMedium
  1355. .ColorIndex = xlAutomatic
  1356. End With
  1357. With myExcel.Selection.Borders(xlEdgeBottom)
  1358. .LineStyle = xlContinuous
  1359. .Weight = xlMedium
  1360. .ColorIndex = xlAutomatic
  1361. End With
  1362. With myExcel.Selection.Borders(xlEdgeRight)
  1363. .LineStyle = xlContinuous
  1364. .Weight = xlMedium
  1365. .ColorIndex = xlAutomatic
  1366. End With
  1367. xlSheet.Range("d1:f1").Select() '-------流程卡号1
  1368. myExcel.Selection.Merge()
  1369. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  1370. myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  1371. With myExcel.Selection.Borders(xlEdgeLeft)
  1372. .LineStyle = xlContinuous
  1373. .Weight = xlMedium
  1374. .ColorIndex = xlAutomatic
  1375. End With
  1376. With myExcel.Selection.Borders(xlEdgeTop)
  1377. .LineStyle = xlContinuous
  1378. .Weight = xlMedium
  1379. .ColorIndex = xlAutomatic
  1380. End With
  1381. With myExcel.Selection.Borders(xlEdgeBottom)
  1382. .LineStyle = xlContinuous
  1383. .Weight = xlMedium
  1384. .ColorIndex = xlAutomatic
  1385. End With
  1386. With myExcel.Selection.Borders(xlEdgeRight)
  1387. .LineStyle = xlContinuous
  1388. .Weight = xlMedium
  1389. .ColorIndex = xlAutomatic
  1390. End With
  1391. xlSheet.Range("d2:e2").Select() '--------打印日期1
  1392. myExcel.Selection.Merge()
  1393. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  1394. myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  1395. With myExcel.Selection.Borders(xlEdgeLeft)
  1396. .LineStyle = xlContinuous
  1397. .Weight = xlMedium
  1398. .ColorIndex = xlAutomatic
  1399. End With
  1400. With myExcel.Selection.Borders(xlEdgeTop)
  1401. .LineStyle = xlContinuous
  1402. .Weight = xlMedium
  1403. .ColorIndex = xlAutomatic
  1404. End With
  1405. With myExcel.Selection.Borders(xlEdgeBottom)
  1406. .LineStyle = xlContinuous
  1407. .Weight = xlMedium
  1408. .ColorIndex = xlAutomatic
  1409. End With
  1410. With myExcel.Selection.Borders(xlEdgeRight)
  1411. .LineStyle = xlContinuous
  1412. .Weight = xlMedium
  1413. .ColorIndex = xlAutomatic
  1414. End With
  1415. xlSheet.Range("f2:f2").Select() '--------规格1
  1416. myExcel.Selection.Merge()
  1417. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  1418. myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  1419. With myExcel.Selection.Borders(xlEdgeLeft)
  1420. .LineStyle = xlContinuous
  1421. .Weight = xlMedium
  1422. .ColorIndex = xlAutomatic
  1423. End With
  1424. With myExcel.Selection.Borders(xlEdgeTop)
  1425. .LineStyle = xlContinuous
  1426. .Weight = xlMedium
  1427. .ColorIndex = xlAutomatic
  1428. End With
  1429. With myExcel.Selection.Borders(xlEdgeBottom)
  1430. .LineStyle = xlContinuous
  1431. .Weight = xlMedium
  1432. .ColorIndex = xlAutomatic
  1433. End With
  1434. With myExcel.Selection.Borders(xlEdgeRight)
  1435. .LineStyle = xlContinuous
  1436. .Weight = xlMedium
  1437. .ColorIndex = xlAutomatic
  1438. End With
  1439. xlSheet.Range("j2:j2").Select() '--------鼓号1
  1440. myExcel.Selection.Merge()
  1441. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  1442. myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  1443. With myExcel.Selection.Borders(xlEdgeLeft)
  1444. .LineStyle = xlContinuous
  1445. .Weight = xlMedium
  1446. .ColorIndex = xlAutomatic
  1447. End With
  1448. With myExcel.Selection.Borders(xlEdgeTop)
  1449. .LineStyle = xlContinuous
  1450. .Weight = xlMedium
  1451. .ColorIndex = xlAutomatic
  1452. End With
  1453. With myExcel.Selection.Borders(xlEdgeBottom)
  1454. .LineStyle = xlContinuous
  1455. .Weight = xlMedium
  1456. .ColorIndex = xlAutomatic
  1457. End With
  1458. With myExcel.Selection.Borders(xlEdgeRight)
  1459. .LineStyle = xlContinuous
  1460. .Weight = xlMedium
  1461. .ColorIndex = xlAutomatic
  1462. End With
  1463. xlSheet.Range("d3:f3").Select() '-------皮源
  1464. myExcel.Selection.Merge()
  1465. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  1466. myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  1467. With myExcel.Selection.Borders(xlEdgeLeft)
  1468. .LineStyle = xlContinuous
  1469. .Weight = xlMedium
  1470. .ColorIndex = xlAutomatic
  1471. End With
  1472. With myExcel.Selection.Borders(xlEdgeTop)
  1473. .LineStyle = xlContinuous
  1474. .Weight = xlMedium
  1475. .ColorIndex = xlAutomatic
  1476. End With
  1477. With myExcel.Selection.Borders(xlEdgeBottom)
  1478. .LineStyle = xlContinuous
  1479. .Weight = xlMedium
  1480. .ColorIndex = xlAutomatic
  1481. End With
  1482. With myExcel.Selection.Borders(xlEdgeRight)
  1483. .LineStyle = xlContinuous
  1484. .Weight = xlMedium
  1485. .ColorIndex = xlAutomatic
  1486. End With
  1487. xlSheet.Range("g3:i3").Select() '-------备注
  1488. myExcel.Selection.Merge()
  1489. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  1490. myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  1491. With myExcel.Selection.Borders(xlEdgeLeft)
  1492. .LineStyle = xlContinuous
  1493. .Weight = xlMedium
  1494. .ColorIndex = xlAutomatic
  1495. End With
  1496. With myExcel.Selection.Borders(xlEdgeTop)
  1497. .LineStyle = xlContinuous
  1498. .Weight = xlMedium
  1499. .ColorIndex = xlAutomatic
  1500. End With
  1501. With myExcel.Selection.Borders(xlEdgeBottom)
  1502. .LineStyle = xlContinuous
  1503. .Weight = xlMedium
  1504. .ColorIndex = xlAutomatic
  1505. End With
  1506. With myExcel.Selection.Borders(xlEdgeRight)
  1507. .LineStyle = xlContinuous
  1508. .Weight = xlMedium
  1509. .ColorIndex = xlAutomatic
  1510. End With
  1511. xlSheet.Range("j3:o3").Select() '-------备注
  1512. myExcel.Selection.Merge()
  1513. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  1514. myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  1515. With myExcel.Selection.Borders(xlEdgeLeft)
  1516. .LineStyle = xlContinuous
  1517. .Weight = xlMedium
  1518. .ColorIndex = xlAutomatic
  1519. End With
  1520. With myExcel.Selection.Borders(xlEdgeTop)
  1521. .LineStyle = xlContinuous
  1522. .Weight = xlMedium
  1523. .ColorIndex = xlAutomatic
  1524. End With
  1525. With myExcel.Selection.Borders(xlEdgeBottom)
  1526. .LineStyle = xlContinuous
  1527. .Weight = xlMedium
  1528. .ColorIndex = xlAutomatic
  1529. End With
  1530. With myExcel.Selection.Borders(xlEdgeRight)
  1531. .LineStyle = xlContinuous
  1532. .Weight = xlMedium
  1533. .ColorIndex = xlAutomatic
  1534. End With
  1535. xlSheet.Range("g1:i1").Select() '--------工艺名称
  1536. myExcel.Selection.Merge()
  1537. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  1538. myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  1539. With myExcel.Selection.Borders(xlEdgeLeft)
  1540. .LineStyle = xlContinuous
  1541. .Weight = xlMedium
  1542. .ColorIndex = xlAutomatic
  1543. End With
  1544. With myExcel.Selection.Borders(xlEdgeTop)
  1545. .LineStyle = xlContinuous
  1546. .Weight = xlMedium
  1547. .ColorIndex = xlAutomatic
  1548. End With
  1549. With myExcel.Selection.Borders(xlEdgeBottom)
  1550. .LineStyle = xlContinuous
  1551. .Weight = xlMedium
  1552. .ColorIndex = xlAutomatic
  1553. End With
  1554. With myExcel.Selection.Borders(xlEdgeRight)
  1555. .LineStyle = xlContinuous
  1556. .Weight = xlMedium
  1557. .ColorIndex = xlAutomatic
  1558. End With
  1559. xlSheet.Range("g2:i2").Select() '-------规格1
  1560. myExcel.Selection.Merge()
  1561. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  1562. myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  1563. With myExcel.Selection.Borders(xlEdgeLeft)
  1564. .LineStyle = xlContinuous
  1565. .Weight = xlMedium
  1566. .ColorIndex = xlAutomatic
  1567. End With
  1568. With myExcel.Selection.Borders(xlEdgeTop)
  1569. .LineStyle = xlContinuous
  1570. .Weight = xlMedium
  1571. .ColorIndex = xlAutomatic
  1572. End With
  1573. With myExcel.Selection.Borders(xlEdgeBottom)
  1574. .LineStyle = xlContinuous
  1575. .Weight = xlMedium
  1576. .ColorIndex = xlAutomatic
  1577. End With
  1578. With myExcel.Selection.Borders(xlEdgeRight)
  1579. .LineStyle = xlContinuous
  1580. .Weight = xlMedium
  1581. .ColorIndex = xlAutomatic
  1582. End With
  1583. xlSheet.Range("j1:o1").Select() '------工艺名称1
  1584. myExcel.Selection.Merge()
  1585. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  1586. myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  1587. With myExcel.Selection.Borders(xlEdgeLeft)
  1588. .LineStyle = xlContinuous
  1589. .Weight = xlMedium
  1590. .ColorIndex = xlAutomatic
  1591. End With
  1592. With myExcel.Selection.Borders(xlEdgeTop)
  1593. .LineStyle = xlContinuous
  1594. .Weight = xlMedium
  1595. .ColorIndex = xlAutomatic
  1596. End With
  1597. With myExcel.Selection.Borders(xlEdgeBottom)
  1598. .LineStyle = xlContinuous
  1599. .Weight = xlMedium
  1600. .ColorIndex = xlAutomatic
  1601. End With
  1602. With myExcel.Selection.Borders(xlEdgeRight)
  1603. .LineStyle = xlContinuous
  1604. .Weight = xlMedium
  1605. .ColorIndex = xlAutomatic
  1606. End With
  1607. xlSheet.Range("J2:j2").Select() '------
  1608. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  1609. myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  1610. With myExcel.Selection.Borders(xlEdgeLeft)
  1611. .LineStyle = xlContinuous
  1612. .Weight = xlMedium
  1613. .ColorIndex = xlAutomatic
  1614. End With
  1615. With myExcel.Selection.Borders(xlEdgeTop)
  1616. .LineStyle = xlContinuous
  1617. .Weight = xlMedium
  1618. .ColorIndex = xlAutomatic
  1619. End With
  1620. With myExcel.Selection.Borders(xlEdgeBottom)
  1621. .LineStyle = xlContinuous
  1622. .Weight = xlMedium
  1623. .ColorIndex = xlAutomatic
  1624. End With
  1625. With myExcel.Selection.Borders(xlEdgeRight)
  1626. .LineStyle = xlContinuous
  1627. .Weight = xlMedium
  1628. .ColorIndex = xlAutomatic
  1629. End With
  1630. With myExcel.Selection.Borders(xlInsideVertical)
  1631. .LineStyle = xlContinuous
  1632. .Weight = xlMedium
  1633. .ColorIndex = xlAutomatic
  1634. End With
  1635. xlSheet.Range("k2:K2").Select() '------
  1636. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  1637. myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  1638. With myExcel.Selection.Borders(xlEdgeLeft)
  1639. .LineStyle = xlContinuous
  1640. .Weight = xlMedium
  1641. .ColorIndex = xlAutomatic
  1642. End With
  1643. With myExcel.Selection.Borders(xlEdgeTop)
  1644. .LineStyle = xlContinuous
  1645. .Weight = xlMedium
  1646. .ColorIndex = xlAutomatic
  1647. End With
  1648. With myExcel.Selection.Borders(xlEdgeBottom)
  1649. .LineStyle = xlContinuous
  1650. .Weight = xlMedium
  1651. .ColorIndex = xlAutomatic
  1652. End With
  1653. With myExcel.Selection.Borders(xlEdgeRight)
  1654. .LineStyle = xlContinuous
  1655. .Weight = xlMedium
  1656. .ColorIndex = xlAutomatic
  1657. End With
  1658. With myExcel.Selection.Borders(xlInsideVertical)
  1659. .LineStyle = xlContinuous
  1660. .Weight = xlMedium
  1661. .ColorIndex = xlAutomatic
  1662. End With
  1663. xlSheet.Range("l2:m2").Select() '----------重量
  1664. myExcel.Selection.Merge()
  1665. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  1666. myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  1667. With myExcel.Selection.Borders(xlEdgeLeft)
  1668. .LineStyle = xlContinuous
  1669. .Weight = xlMedium
  1670. .ColorIndex = xlAutomatic
  1671. End With
  1672. With myExcel.Selection.Borders(xlEdgeTop)
  1673. .LineStyle = xlContinuous
  1674. .Weight = xlMedium
  1675. .ColorIndex = xlAutomatic
  1676. End With
  1677. With myExcel.Selection.Borders(xlEdgeBottom)
  1678. .LineStyle = xlContinuous
  1679. .Weight = xlMedium
  1680. .ColorIndex = xlAutomatic
  1681. End With
  1682. With myExcel.Selection.Borders(xlEdgeRight)
  1683. .LineStyle = xlContinuous
  1684. .Weight = xlMedium
  1685. .ColorIndex = xlAutomatic
  1686. End With
  1687. xlSheet.Range("n1:o1").Select() '--------
  1688. myExcel.Selection.Merge()
  1689. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  1690. myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  1691. With myExcel.Selection.Borders(xlEdgeLeft)
  1692. .LineStyle = xlContinuous
  1693. .Weight = xlMedium
  1694. .ColorIndex = xlAutomatic
  1695. End With
  1696. With myExcel.Selection.Borders(xlEdgeTop)
  1697. .LineStyle = xlContinuous
  1698. .Weight = xlMedium
  1699. .ColorIndex = xlAutomatic
  1700. End With
  1701. With myExcel.Selection.Borders(xlEdgeBottom)
  1702. .LineStyle = xlContinuous
  1703. .Weight = xlMedium
  1704. .ColorIndex = xlAutomatic
  1705. End With
  1706. With myExcel.Selection.Borders(xlEdgeRight)
  1707. .LineStyle = xlContinuous
  1708. .Weight = xlMedium
  1709. .ColorIndex = xlAutomatic
  1710. End With
  1711. xlSheet.Range("n2:o2").Select() '-------重量
  1712. myExcel.Selection.Merge()
  1713. myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  1714. myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  1715. With myExcel.Selection.Borders(xlEdgeLeft)
  1716. .LineStyle = xlContinuous
  1717. .Weight = xlMedium
  1718. .ColorIndex = xlAutomatic
  1719. End With
  1720. With myExcel.Selection.Borders(xlEdgeTop)
  1721. .LineStyle = xlContinuous
  1722. .Weight = xlMedium
  1723. .ColorIndex = xlAutomatic
  1724. End With
  1725. With myExcel.Selection.Borders(xlEdgeBottom)
  1726. .LineStyle = xlContinuous
  1727. .Weight = xlMedium
  1728. .ColorIndex = xlAutomatic
  1729. End With
  1730. With myExcel.Selection.Borders(xlEdgeRight)
  1731. .LineStyle = xlContinuous
  1732. .Weight = xlMedium
  1733. .ColorIndex = xlAutomatic
  1734. End With
  1735. End Sub
  1736. Private Sub cmdCancelEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancelEdit.Click
  1737. 'For x As Integer = 0 To dgv2.Rows.Count - 1
  1738. ' dgv2.Rows(x).DefaultCellStyle.Font = New Font(dgv2.DefaultCellStyle.Font, FontStyle.Regular)
  1739. ' dgv2.Rows(x).Cells("百分比").Style.BackColor = Color.White
  1740. ' dgv2.Rows(x).Cells("化料編號").Style.BackColor = Color.White
  1741. ' dgv2.Rows(x).Cells("化料名称").Style.BackColor = Color.White
  1742. ' dgv2.Rows(x).Cells("时间").Style.BackColor = Color.White
  1743. ' dgv2.Rows(x).Cells("備註").Style.BackColor = Color.White
  1744. 'Next
  1745. cmdSaveEdit.Visible = False
  1746. cmdCancelEdit.Visible = False
  1747. Timer1.Enabled = False
  1748. Label1.Visible = False
  1749. End Sub
  1750. Private Sub cmdSaveEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSaveEdit.Click
  1751. ' dgv2.Rows(dgv2.SelectedRows(0).Index).Selected = False
  1752. Dim edited As Boolean = False
  1753. Dim cmd1 As New SqlCommand
  1754. cmd1.Connection = con
  1755. If con.State = ConnectionState.Closed Then
  1756. con.Open()
  1757. End If
  1758. '----------判斷是否修改
  1759. For x As Integer = 0 To dgv2.Rows.Count - 1
  1760. If DataGridView1.Rows(x).Cells("项次").Style.BackColor.Name <> "0" Or Not (DataGridView1.Rows(x).DefaultCellStyle.Font Is Nothing) Then
  1761. edited = True
  1762. Exit For
  1763. End If
  1764. If DataGridView1.Rows(x).Cells("百分比").Style.BackColor.Name <> "0" Or Not (DataGridView1.Rows(x).DefaultCellStyle.Font Is Nothing) Then
  1765. edited = True
  1766. Exit For
  1767. End If
  1768. If DataGridView1.Rows(x).Cells("化料名称").Style.BackColor.Name <> "0" Or Not (DataGridView1.Rows(x).DefaultCellStyle.Font Is Nothing) Then
  1769. edited = True
  1770. Exit For
  1771. End If
  1772. If DataGridView1.Rows(x).Cells("时间").Style.BackColor.Name <> "0" Or Not (DataGridView1.Rows(x).DefaultCellStyle.Font Is Nothing) Then
  1773. edited = True
  1774. Exit For
  1775. End If
  1776. If DataGridView1.Rows(x).Cells("备注").Style.BackColor.Name <> "0" Or Not (DataGridView1.Rows(x).DefaultCellStyle.Font Is Nothing) Then
  1777. edited = True
  1778. Exit For
  1779. End If
  1780. Next
  1781. '-------------------------------------------------
  1782. If edited = True Then
  1783. 'sql_rcp = "delete from rt_retan_rcp where tech=N'" & DGV1.Rows(DGV1.CurrentRow.Index).Cells(0).Value & "' and rcp_name='" & DGV1.Rows(DGV1.CurrentRow.Index).Cells(1).Value & "'"
  1784. 'cmd.CommandText = sql_rcp
  1785. 'cmd.Connection = conn
  1786. 'If conn.State = ConnectionState.Closed Then
  1787. ' conn.Open()
  1788. 'End If
  1789. 'cmd.ExecuteNonQuery()
  1790. '''sql_rcp = "delete from ht_retanrcp where rcp_no=N'" & DGV1.Rows(DGV1.CurrentRow.Index).Cells(5).Value & "'"
  1791. '''cmd.CommandText = sql_rcp
  1792. '''cmd.Connection = conn
  1793. '''If conn.State = ConnectionState.Closed Then
  1794. ''' conn.Open()
  1795. '''End If
  1796. '''dr = cmd.ExecuteReader
  1797. ''-----------舊記錄存檔
  1798. 'While dr.Read()
  1799. ' sql_rcp = "insert into rcp_content (item,matl_no,percents,rcp_no,time,comment) values('" & dr("item") & "','" & dr("matl_no") & "','" & dr("percents") & "','" & dr("rcp_no") & "edit','" & dr("time") & "',N'" & dr("comment") & "')"
  1800. ' cmd1.CommandText = sql_rcp
  1801. ' cmd1.ExecuteNonQuery()
  1802. 'End While
  1803. 'Dim gUserName As String = "matchy"
  1804. 'sql_rcp = "update " & rcp & " set last_edited ='" & Now.ToString & "',editor='" & gUserName & "' where rcp_no='" & DGV1.Rows(DGV1.CurrentRow.Index).Cells(0).Value & "'"
  1805. 'cmd1.CommandText = sql_rcp
  1806. 'cmd1.ExecuteNonQuery()
  1807. End If
  1808. '-----------將現有處方明細先刪除
  1809. 'sql_rcp = "delete from rcp_content where rcp_no='" & DGV1.Rows(DGV1.CurrentRow.Index).Cells(0).Value & "'"
  1810. 'cmd1.CommandText = sql_rcp
  1811. 'cmd1.ExecuteNonQuery()
  1812. '-----------加入新修改之處方明細
  1813. Dim y As Integer = 1
  1814. For x As Integer = 0 To DataGridView1.Rows.Count - 1
  1815. If (DataGridView1.Rows(x).DefaultCellStyle.Font Is Nothing) Then
  1816. sql_rcp = "insert into ht_retanrcp1 (item,name,chem,percents,time,comment) values('" & y & "',N'" & DGV1.Rows(DGV1.CurrentCell.RowIndex).Cells("品名").Value & "',N'" & DataGridView1.Rows(x).Cells("化料名称").Value & "','" & DataGridView1.Rows(x).Cells("百分比").Value & "','" & DataGridView1.Rows(x).Cells("时间").Value & "',N'" & DataGridView1.Rows(x).Cells("备注").Value & "')"
  1817. cmd1.CommandText = sql_rcp
  1818. cmd1.ExecuteNonQuery()
  1819. y = y + 1
  1820. End If
  1821. Next
  1822. MsgBox("修改完成")
  1823. cmdSaveEdit.Visible = False
  1824. cmdCancelEdit.Visible = False
  1825. Timer1.Enabled = False
  1826. Label1.Visible = False
  1827. conn.Close()
  1828. con.Close()
  1829. End Sub
  1830. Private Sub cmdcanceladd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdcanceladd.Click
  1831. End Sub
  1832. Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
  1833. If dgv_record.Visible = False Then
  1834. dgv_record.BringToFront()
  1835. dgv_record.Visible = True
  1836. Else
  1837. dgv_record.Visible = False
  1838. End If
  1839. End Sub
  1840. Private Sub dgv_record_RowPostPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles dgv_record.RowPostPaint
  1841. Dim linePen As New Pen(Color.SkyBlue, 2)
  1842. If e.RowIndex = dgv_record.Rows.Count - 1 Then
  1843. dgv_record.Rows(e.RowIndex).Cells("百分比").Style.ForeColor = Color.White
  1844. Dim startX As Integer = IIf(dgv_record.RowHeadersVisible, dgv_record.RowHeadersWidth, 0)
  1845. Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  1846. Dim endX As Integer = startX + dgv2.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - dgv_record.HorizontalScrollingOffset
  1847. e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
  1848. Exit Sub
  1849. End If
  1850. If dgv_record.Rows(e.RowIndex).Cells("時间").Value.ToString <> "" And (dgv_record.Rows(e.RowIndex + 1).Cells("化料名称").Value.ToString = "流水洗" Or dgv_record.Rows(e.RowIndex + 1).Cells("化料名称").Value.ToString = "洗水" Or dgv_record.Rows(e.RowIndex + 1).Cells("化料名称").Value = "排水") Then
  1851. ElseIf dgv_record.Rows(e.RowIndex).Cells("時间").Value.ToString <> "" Then
  1852. Dim startX As Integer = IIf(dgv2.RowHeadersVisible, dgv_record.RowHeadersWidth, 0)
  1853. Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  1854. Dim endX As Integer = startX + dgv_record.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - dgv_record.HorizontalScrollingOffset
  1855. e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
  1856. End If
  1857. If (dgv_record.Rows(e.RowIndex).Cells("化料名称").Value.ToString = "流水洗" Or dgv_record.Rows(e.RowIndex).Cells("化料名称").Value.ToString = "洗水" Or dgv_record.Rows(e.RowIndex).Cells("化料名称").Value = "排水") Then
  1858. dgv_record.Rows(e.RowIndex).Cells("百分比").Style.ForeColor = Color.White
  1859. Dim startX As Integer = IIf(dgv_record.RowHeadersVisible, dgv_record.RowHeadersWidth, 0)
  1860. Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  1861. Dim endX As Integer = startX + dgv_record.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - dgv_record.HorizontalScrollingOffset
  1862. e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
  1863. End If
  1864. End Sub
  1865. Private Sub GroupBox2_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox2.Enter
  1866. End Sub
  1867. Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
  1868. TextBox9.Text = ""
  1869. TextBox6.Text = ""
  1870. TextBox8.Text = ""
  1871. TextBox7.Text = ""
  1872. TextBox10.Text = ""
  1873. TextBox5.Text = ""
  1874. If conn.State = ConnectionState.Closed Then
  1875. conn.ConnectionString = connstring
  1876. conn.Open()
  1877. End If
  1878. cmd.Connection = conn
  1879. Dim sql As String
  1880. sql = "select * from retan_cost where pid='" & TXT_PID.Text & "'"
  1881. cmd.CommandText = sql
  1882. dr = cmd.ExecuteReader()
  1883. If dr.Read Then
  1884. Dim my_msg As MsgBoxResult
  1885. my_msg = MsgBox("資料已存在,是否繼續?", MsgBoxStyle.YesNo)
  1886. If my_msg = MsgBoxResult.No Then
  1887. dr.Close()
  1888. Exit Sub
  1889. End If
  1890. Else
  1891. End If
  1892. dr.Close()
  1893. Dim io_no As String = ""
  1894. Dim io_count As Integer = 0
  1895. Dim my_weight As Integer = 0
  1896. Dim my_piece As Integer = 0
  1897. Dim matl_id As String
  1898. sql = "select weight,piece from production where production_id='" & TXT_PID.Text & "'"
  1899. cmd.CommandText = sql
  1900. dr = cmd.ExecuteReader
  1901. dr.Read()
  1902. my_piece = dr("piece")
  1903. dr.Close()
  1904. sql = "select count(*) as my_count from material_io where left(io_no,1)='w' and substring(io_no,2,6)='" & String.Format("{0:yyMMdd}", DateTimePicker1.Value) & "'"
  1905. cmd.CommandText = sql
  1906. io_count = cmd.ExecuteScalar
  1907. io_no = "W" & String.Format("{0:yyMMdd}", DateTimePicker1.Value) & Chr(io_count + 65)
  1908. sql = "insert into material_io (io_no,rcp_no,weight,pieces,department) values ('" & io_no & "','" & DGV1.Rows(DGV1.CurrentRow.Index).Cells(0).Value & "','" & Math.Round(Double.Parse(TextBox1.Text) * my_piece, 0) & "','" & my_piece & "','染色')"
  1909. cmd.CommandText = sql
  1910. cmd.ExecuteNonQuery()
  1911. For x As Integer = 0 To dgv2.RowCount - 1
  1912. sql = "select matl_id from tblmaterial where matl_no='" & dgv2.Rows(x).Cells(2).Value & "'"
  1913. cmd.CommandText = sql
  1914. dr = cmd.ExecuteReader
  1915. dr.Read()
  1916. matl_id = dr("matl_id").ToString
  1917. dr.Close()
  1918. If (dgv2.Rows(x).DefaultCellStyle.Font Is Nothing) Then
  1919. sql = "insert into retan_cost (pid,item,matl_no,percents,time,comment,coin,price,weight,tannie,oil,dye,aux,other,date,rcp_no,w_no) values ('" & TXT_PID.Text & "','" & x + 1 & "','" & dgv2.Rows(x).Cells(2).Value & "','" & dgv2.Rows(x).Cells(1).Value & "','" & dgv2.Rows(x).Cells(4).Value & "','" & dgv2.Rows(x).Cells(5).Value & "','" & dgv2.Rows(x).Cells(6).Value & "','" & dgv2.Rows(x).Cells(7).Value & "','" & TextBox1.Text & "','" & txttan.Text & "','" & txtoil.Text & "','" & txtdye.Text & "','" & txtx.Text & "','" & txtxx.Text & "','" & String.Format("{0:d}", DateTimePicker1.Value) & "','" & DGV1.Rows(DGV1.CurrentRow.Index).Cells(0).Value & "','" & io_no & "')"
  1920. cmd.CommandText = sql
  1921. cmd.ExecuteNonQuery()
  1922. If matl_id <> "" Then
  1923. Dim id As Integer = 0
  1924. sql = "select top (1) id from retan_cost order by id desc "
  1925. cmd.CommandText = sql
  1926. id = cmd.ExecuteScalar
  1927. sql = "insert into matl_io_detail (io_no,matl_no,quantity,id1) values ('" & io_no & "','" & dgv2.Rows(x).Cells(2).Value & "','" & Double.Parse(TextBox1.Text) * my_piece * dgv2.Rows(x).Cells(1).Value / 100 & "','" & id & "')"
  1928. cmd.CommandText = sql
  1929. cmd.ExecuteNonQuery()
  1930. chem_balance(dgv2.Rows(x).Cells(2).Value, Double.Parse(TextBox1.Text) * my_piece * dgv2.Rows(x).Cells(1).Value / 100, x, id)
  1931. End If
  1932. Else
  1933. If dgv2.Rows(x).DefaultCellStyle.Font.Style <> FontStyle.Strikeout Then
  1934. sql = "insert into retan_cost (pid,item,matl_no,percents,time,comment,coin,price,weight,tannie,oil,dye,aux,other,date,rcp_no,w_no) values ('" & TXT_PID.Text & "','" & x + 1 & "','" & dgv2.Rows(x).Cells(2).Value & "','" & dgv2.Rows(x).Cells(1).Value & "','" & dgv2.Rows(x).Cells(4).Value & "','" & dgv2.Rows(x).Cells(5).Value & "','" & dgv2.Rows(x).Cells(6).Value & "','" & dgv2.Rows(x).Cells(7).Value & "','" & TextBox1.Text & "','" & txttan.Text & "','" & txtoil.Text & "','" & txtdye.Text & "','" & txtx.Text & "','" & txtxx.Text & "','" & String.Format("{0:d}", DateTimePicker1.Value) & "','" & DGV1.Rows(DGV1.CurrentRow.Index).Cells(0).Value & "','" & io_no & "')"
  1935. cmd.CommandText = sql
  1936. cmd.ExecuteNonQuery()
  1937. If matl_id <> "" Then
  1938. Dim id As Integer = 0
  1939. sql = "select top (1) id from retan_cost "
  1940. cmd.CommandText = sql
  1941. id = cmd.ExecuteScalar
  1942. sql = "insert into matl_io_detail (io_no,matl_no,quantity,id1) values ('" & io_no & "','" & dgv2.Rows(x).Cells(2).Value & "','" & Double.Parse(TextBox1.Text) * my_piece * dgv2.Rows(x).Cells(1).Value / 100 & "','" & id & "')"
  1943. cmd.CommandText = sql
  1944. cmd.ExecuteNonQuery()
  1945. chem_balance(dgv2.Rows(x).Cells(2).Value, Double.Parse(TextBox1.Text) * my_piece * dgv2.Rows(x).Cells(1).Value / 100, x, id)
  1946. End If
  1947. End If
  1948. End If
  1949. Next
  1950. conn.Close()
  1951. save_cost()
  1952. MsgBox("作業完成")
  1953. End Sub
  1954. Private Function chem_balance(ByVal matl_no As String, ByVal quantity As Double, ByVal x As Integer, ByVal id As Integer)
  1955. Dim conn5 As New SqlConnection
  1956. Dim dt1 As New DataTable
  1957. Dim sql As String = ""
  1958. sql = "select top (1) lot_no,coin,price,quantity, w from tblchem_lot where matl_no='" & matl_no & "' and quantity-w<>0"
  1959. cmd.CommandText = sql
  1960. da.Fill(dt1)
  1961. If dt1.Rows.Count = 0 Then
  1962. Dim dt2 As New DataTable
  1963. sql = "select top (1) lot_no,coin,price,quantity, w from tblchem_lot where matl_no='" & matl_no & "'"
  1964. cmd.CommandText = sql
  1965. da.Fill(dt2)
  1966. If dt2.Rows.Count = 0 Then
  1967. sql = "insert into tblchem_lot (matl_no,lot_no,quantity,coin,price) values ('" & matl_no & "','120229','" & 0 & "','" & "NTD" & "','" & 0 & "')"
  1968. cmd.CommandText = sql
  1969. cmd.ExecuteScalar()
  1970. sql = "insert into tblchem_lot_io (lot_no,matl_no,quantity,io_type,coin,price,id) values ('" & dt2.Rows(0).Item("lot_no") & "','" & matl_no & "','" & quantity & "','" & "領料" & "','" & dt2.Rows(0).Item("coin") & "','" & dt2.Rows(0).Item("price") & "','" & id & "')"
  1971. cmd.CommandText = sql
  1972. dr = cmd.ExecuteScalar
  1973. sql = "update tblchem_lot set w=w+'" & quantity & "' where lot_no='" & dt2.Rows(0).Item("lot_no") & "' and quantity ='" & dt2.Rows(0).Item("quantity") & "' and matl_no='" & matl_no & "'"
  1974. cmd.CommandText = sql
  1975. dr = cmd.ExecuteScalar
  1976. Else
  1977. sql = "insert into tblchem_lot_io (lot_no,matl_no,quantity,io_type,coin,price,id) values ('" & dt2.Rows(0).Item("lot_no") & "','" & matl_no & "','" & quantity & "','" & "領料" & "','" & dt2.Rows(0).Item("coin") & "','" & dt2.Rows(0).Item("price") & "','" & id & "')"
  1978. cmd.CommandText = sql
  1979. dr = cmd.ExecuteScalar
  1980. sql = "update tblchem_lot set w=w+'" & quantity & "' where lot_no='" & dt2.Rows(0).Item("lot_no") & "' and quantity ='" & dt2.Rows(0).Item("quantity") & "' and matl_no='" & matl_no & "'"
  1981. cmd.CommandText = sql
  1982. dr = cmd.ExecuteScalar
  1983. End If
  1984. '
  1985. End If
  1986. If dt1.Rows(0).Item("quantity") - dt1.Rows(0).Item("w") - quantity > 0 Then
  1987. sql = "insert into tblchem_lot_io (lot_no,matl_no,quantity,io_type,coin,price,id) values ('" & dt1.Rows(0).Item("lot_no") & "','" & matl_no & "','" & quantity & "','" & "領料" & "','" & dt1.Rows(0).Item("coin") & "','" & dt1.Rows(0).Item("price") & "','" & id & "')"
  1988. cmd.CommandText = sql
  1989. dr = cmd.ExecuteScalar
  1990. sql = "update tblchem_lot set w=w+'" & quantity & "' where lot_no='" & dt1.Rows(0).Item("lot_no") & "' and quantity ='" & dt1.Rows(0).Item("quantity") & "' and matl_no='" & matl_no & "'"
  1991. cmd.CommandText = sql
  1992. dr = cmd.ExecuteScalar
  1993. Else
  1994. If dt1.Rows(0).Item("quantity") - dt1.Rows(0).Item("w") > 0 Then
  1995. sql = "insert into tblchem_lot_io (lot_no,matl_no,quantity,io_type,coin,price,id) values ('" & dt1.Rows(0).Item("lot_no") & "','" & matl_no & "','" & dt1.Rows(0).Item("quantity") - dt1.Rows(0).Item("w") & "','" & "領料" & "','" & dt1.Rows(0).Item("coin") & "','" & dt1.Rows(0).Item("price") & "','" & id & "')"
  1996. cmd.CommandText = sql
  1997. dr = cmd.ExecuteScalar
  1998. sql = "update tblchem_lot set w=w+'" & dt1.Rows(0).Item("quantity") - dt1.Rows(0).Item("w") & "' where lot_no='" & dt1.Rows(0).Item("lot_no") & "' and quantity ='" & dt1.Rows(0).Item("quantity") & "'"
  1999. cmd.CommandText = sql
  2000. dr = cmd.ExecuteScalar
  2001. chem_balance(matl_no, quantity - (dt1.Rows(0).Item("quantity") - dt1.Rows(0).Item("w")), x + 1, id)
  2002. Else
  2003. sql = "insert into tblchem_lot_io (lot_no,matl_no,quantity,io_type,coin,price,id) values ('" & dt1.Rows(0).Item("lot_no") & "','" & matl_no & "','" & dt1.Rows(0).Item("quantity") - dt1.Rows(0).Item("w") & "','" & "領料" & "','" & dt1.Rows(0).Item("coin") & "','" & dt1.Rows(0).Item("price") & "','" & id & "')"
  2004. cmd.CommandText = sql
  2005. dr = cmd.ExecuteScalar
  2006. sql = "update tblchem_lot set w=w+'" & dt1.Rows(0).Item("quantity") - dt1.Rows(0).Item("w") & "' where lot_no='" & dt1.Rows(0).Item("lot_no") & "' and quantity ='" & dt1.Rows(0).Item("quantity") & "'"
  2007. cmd.CommandText = sql
  2008. dr = cmd.ExecuteScalar
  2009. End If
  2010. End If
  2011. End Function
  2012. Private Sub save_cost()
  2013. If conn.State = ConnectionState.Closed Then
  2014. conn.ConnectionString = connstring
  2015. conn.Open()
  2016. End If
  2017. cmd.Connection = conn
  2018. Dim sql As String
  2019. sql = "SELECT SUM(cost) AS cost, MATL_ID FROM (SELECT TOP (100) PERCENT tblMaterial.MATL_ID, CASE WHEN retan_cost.coin = '台幣' THEN SUM(tblMaterial.PUR_UNIT * retan_cost.percents / 100 * " & TextBox1.Text & ") WHEN retan_cost.coin = '美金' THEN SUM(tblMaterial.PUR_UNIT * retan_cost.percents / 100 * " & TextBox1.Text & ") * 29.15 WHEN retan_cost.coin = '人民幣' THEN SUM(tblMaterial.PUR_UNIT * retan_cost.percents / 100 * " & TextBox1.Text & ") * 4.4 WHEN retan_cost.coin = '歐元' THEN SUM(tblMaterial.PUR_UNIT * retan_cost.percents / 100 * " & TextBox1.Text & ") * 38.97 END AS cost FROM RETAN_COST INNER JOIN tblMaterial ON RETAN_COST.MATL_NO = tblMaterial.MATL_NO WHERE (RETAN_COST.PID = '" & TXT_PID.Text & "') AND (tblMaterial.MATL_ID IS NOT NULL) GROUP BY tblMaterial.MATL_ID, RETAN_COST.COIN ORDER BY tblMaterial.MATL_ID) AS derivedtbl_1 GROUP BY MATL_ID"
  2020. cmd.CommandText = sql
  2021. dr = cmd.ExecuteReader
  2022. Dim t As Double = 0
  2023. Dim x As Double = 0
  2024. Dim f As Double = 0
  2025. Dim d As Double = 0
  2026. Dim xx As Double = 0
  2027. While dr.Read()
  2028. Select Case dr("matl_id")
  2029. Case "T"
  2030. t = dr("cost")
  2031. Case "X"
  2032. x = dr("cost")
  2033. Case "D"
  2034. d = dr("cost")
  2035. Case "F"
  2036. f = dr("cost")
  2037. Case Else
  2038. xx = dr("cost")
  2039. End Select
  2040. End While
  2041. dr.Close()
  2042. Dim total As Double = t + x + f + d + xx
  2043. TextBox9.Text = t
  2044. TextBox6.Text = f
  2045. TextBox8.Text = d
  2046. TextBox7.Text = x
  2047. TextBox10.Text = xx
  2048. TextBox5.Text = total
  2049. End Sub
  2050. Private Sub TXT_PID_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TXT_PID.KeyUp
  2051. Dim sql As String = ""
  2052. Dim dr2 As SqlDataReader
  2053. sql = "select article from leather_io where production_id='" & TXT_PID.Text & "'"
  2054. cmd.CommandText = sql
  2055. cmd.Connection = conn
  2056. If conn.State = ConnectionState.Closed Then
  2057. conn.Open()
  2058. End If
  2059. dr2 = cmd.ExecuteReader
  2060. If dr2.Read Then
  2061. TextBox11.Text = dr2("article")
  2062. End If
  2063. dr2.Close()
  2064. conn.Close()
  2065. sql = "select weight/piece as my_avg from production where production_id='" & TXT_PID.Text & "'"
  2066. cmd.CommandText = sql
  2067. cmd.Connection = conn
  2068. If conn.State = ConnectionState.Closed Then
  2069. conn.Open()
  2070. End If
  2071. dr2 = cmd.ExecuteReader
  2072. If dr2.Read Then
  2073. TextBox1.Text = dr2("my_avg")
  2074. End If
  2075. dr2.Close()
  2076. conn.Close()
  2077. End Sub
  2078. Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
  2079. Dim sql As String = ""
  2080. cmd.Connection = conn
  2081. If conn.State = ConnectionState.Closed Then
  2082. conn.Open()
  2083. End If
  2084. ListBox2.Visible = True
  2085. ListBox3.Visible = True
  2086. ListBox4.Visible = True
  2087. TextBox2.Visible = True
  2088. TextBox3.Visible = True
  2089. TextBox4.Visible = True
  2090. 'Button11.Visible = True
  2091. 'Button12.Visible = True
  2092. 'Button13.Visible = True
  2093. 'Button14.Visible = True
  2094. Button15.Visible = True
  2095. sql = "select cust_name from customer order by cust_name"
  2096. cmd.CommandText = sql
  2097. dr = cmd.ExecuteReader
  2098. While dr.Read
  2099. ListBox2.Items.Add(dr("cust_name"))
  2100. End While
  2101. dr.Close()
  2102. sql = "select prod_name from tblproduct order by prod_name"
  2103. cmd.CommandText = sql
  2104. dr = cmd.ExecuteReader
  2105. While dr.Read
  2106. ListBox3.Items.Add(dr("prod_name"))
  2107. End While
  2108. dr.Close()
  2109. sql = "select color_name from color order by color_name"
  2110. cmd.CommandText = sql
  2111. dr = cmd.ExecuteReader
  2112. While dr.Read
  2113. ListBox4.Items.Add(dr("color_name"))
  2114. End While
  2115. dr.Close()
  2116. Button17.Visible = True
  2117. conn.Close()
  2118. End Sub
  2119. Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
  2120. Dim sql As String = ""
  2121. Dim cust_no As String = ""
  2122. Dim prod_id As String = ""
  2123. Dim color_no As String = ""
  2124. If cmd.Connection.State = ConnectionState.Closed Then
  2125. conn.Open()
  2126. End If
  2127. sql = "select id from customer where cust_name='" & ListBox2.SelectedItem & "'"
  2128. cmd.CommandText = sql
  2129. cust_no = cmd.ExecuteScalar
  2130. sql = "select prod_id from tblproduct where prod_name='" & ListBox3.SelectedItem & "'"
  2131. cmd.CommandText = sql
  2132. prod_id = cmd.ExecuteScalar
  2133. sql = "select color_no from color where color_name='" & ListBox4.SelectedItem & "'"
  2134. cmd.CommandText = sql
  2135. color_no = cmd.ExecuteScalar
  2136. sql = "select count(*) from " & rcp & " where substring(rcp_no,4,3)='" & cust_no & "' and substring(rcp_no,1,1)='" & prod_id & "' and substring(rcp_no,7,2)='" & color_no & "'"
  2137. cmd.CommandText = sql
  2138. Dim c As Integer = cmd.ExecuteScalar
  2139. If c = 0 Then
  2140. rr = prod_id & String.Format("{0:D2}", c) & String.Format("{0:D3}", cust_no) & color_no
  2141. Else
  2142. rr = prod_id & String.Format("{0:D2}", c + 1) & String.Format("{0:D3}", cust_no) & color_no
  2143. End If
  2144. sql = "select count(*) from " & rcp & " where rcp_no='" & rr & "'"
  2145. cmd.CommandText = sql
  2146. c = cmd.ExecuteScalar
  2147. If c <> 0 Then
  2148. MsgBox("重覆")
  2149. Exit Sub
  2150. End If
  2151. rcp_name = ListBox2.SelectedItem & ListBox4.SelectedItem & ListBox3.SelectedItem
  2152. rcp_name = InputBox("處方名稱", "詢問", rcp_name)
  2153. sql = "insert into " & rcp & " (rcp_no,rcp_name,creat_d) values ( '" & rr & "',N'" & rcp_name & "','" & String.Format("{0:d}", DateTime.Now) & "')"
  2154. cmd.CommandText = sql
  2155. cmd.ExecuteNonQuery()
  2156. For x As Integer = 0 To dgv2.RowCount - 1
  2157. If (dgv2.Rows(x).DefaultCellStyle.Font Is Nothing) Then
  2158. Dim item As String = ""
  2159. If x <= 8 Then
  2160. item = "0" & x + 1
  2161. Else
  2162. item = x + 1
  2163. End If
  2164. sql = "insert into rcp_content (item,matl_no,percents,time,comment,rcp_no) values ('" & item & "','" & dgv2.Rows(x).Cells(2).Value & "','" & dgv2.Rows(x).Cells(1).Value & "','" & dgv2.Rows(x).Cells(4).Value & "',N'" & dgv2.Rows(x).Cells(5).Value & "','" & rr & "')"
  2165. cmd.CommandText = sql
  2166. cmd.ExecuteNonQuery()
  2167. Else
  2168. If dgv2.Rows(x).DefaultCellStyle.Font.Style <> FontStyle.Strikeout Then
  2169. Dim item As String = ""
  2170. If Microsoft.VisualBasic.Len(x) = 1 Then
  2171. item = "0" & x + 1
  2172. Else
  2173. item = x + 1
  2174. End If
  2175. sql = "insert into rcp_content (item,matl_no,percents,time,comment,rcp_no) values ('" & item & "','" & dgv2.Rows(x).Cells(2).Value & "','" & dgv2.Rows(x).Cells(1).Value & "','" & dgv2.Rows(x).Cells(4).Value & "',N'" & dgv2.Rows(x).Cells(5).Value & "','" & rr & "')"
  2176. cmd.CommandText = sql
  2177. cmd.ExecuteNonQuery()
  2178. End If
  2179. End If
  2180. Next
  2181. MsgBox("處方" & rr & rcp_name & "新增完成")
  2182. conn.Close()
  2183. Button17.Visible = False
  2184. ListBox2.Visible = False
  2185. ListBox3.Visible = False
  2186. ListBox4.Visible = False
  2187. TextBox2.Visible = False
  2188. TextBox3.Visible = False
  2189. TextBox4.Visible = False
  2190. End Sub
  2191. Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click
  2192. Dim rcp_name As String = ""
  2193. Dim sql As String = ""
  2194. If conn.State = ConnectionState.Closed Then
  2195. conn.Open()
  2196. End If
  2197. rcp_name = InputBox("輸入新的處方名", DGV1.Rows(DGV1.CurrentRow.Index).Cells(1).Value)
  2198. sql = "update " & rcp & " set rcp_name=N'" & rcp_name & "' where rcp_no='" & DGV1.Rows(DGV1.CurrentRow.Index).Cells(0).Value & "'"
  2199. cmd.Connection = conn
  2200. cmd.CommandText = sql
  2201. cmd.ExecuteScalar()
  2202. conn.Close()
  2203. End Sub
  2204. Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
  2205. 'If RadioButton2.Checked = True Then
  2206. ' rcp = "rcp_main"
  2207. ' rcp1 = "rcp_content"
  2208. 'Else
  2209. ' rcp = "prescription_main"
  2210. ' rcp1 = "prescription_content"
  2211. 'End If
  2212. End Sub
  2213. Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button19.Click
  2214. TextBox9.Text = ""
  2215. TextBox6.Text = ""
  2216. TextBox8.Text = ""
  2217. TextBox7.Text = ""
  2218. TextBox10.Text = ""
  2219. TextBox5.Text = ""
  2220. save_cost()
  2221. ' ''Dim conn5 As New SqlConnection
  2222. ' ''Dim dt1 As New DataTable
  2223. ' ''If matl_no = "G300" Then
  2224. ' '' Dim aa As String = ""
  2225. ' '' aa = "asdfasf"
  2226. ' ''End If
  2227. ' ''Sql = "select top (1) lot_no,coin,price,quantity, w from tblchem_lot where matl_no='" & matl_no & "' and quantity-w>0 order by lot_no"
  2228. ' ''cmd.CommandText = Sql
  2229. ' ''da.Fill(dt1)
  2230. ' ''If dt1.Rows.Count = 0 Then
  2231. ' '' ListBox1.Items.Add(matl_no)
  2232. ' '' Dim dt2 As New DataTable
  2233. ' '' Sql = "select top (1) lot_no,coin,price,quantity, w from tblchem_lot where matl_no='" & matl_no & "' order by lot_no desc"
  2234. ' '' cmd.CommandText = Sql
  2235. ' '' da.Fill(dt2)
  2236. ' '' If dt2.Rows.Count = 0 Then
  2237. ' '' Sql = "insert into tblchem_lot (matl_no,lot_no,quantity,coin,price) values ('" & matl_no & "','120229','" & "0" & "','" & "NTD" & "','" & 0 & "')"
  2238. ' '' cmd.CommandText = Sql
  2239. ' '' cmd.ExecuteScalar()
  2240. ' '' Sql = "insert into tblchem_lot_io (lot_no,matl_no,quantity,io_type,coin,price,id) values ('120229'" & ",'" & matl_no & "','" & quantity & "','" & "領料" & "','ntd','0','" & id & "')"
  2241. ' '' cmd.CommandText = Sql
  2242. ' '' dr = cmd.ExecuteScalar
  2243. ' '' Sql = "update tblchem_lot set w=w+'" & quantity & "' where lot_no='120229' and matl_no='" & matl_no & "'"
  2244. ' '' cmd.CommandText = Sql
  2245. ' '' dr = cmd.ExecuteScalar
  2246. ' '' Else
  2247. ' '' Sql = "insert into tblchem_lot_io (lot_no,matl_no,quantity,io_type,coin,price,id) values ('" & dt2.Rows(0).Item("lot_no") & "','" & matl_no & "','" & quantity & "','" & "領料" & "','" & dt2.Rows(0).Item("coin") & "','" & dt2.Rows(0).Item("price") & "','" & id & "')"
  2248. ' '' cmd.CommandText = Sql
  2249. ' '' dr = cmd.ExecuteScalar
  2250. ' '' Sql = "update tblchem_lot set w=w+'" & quantity & "' where lot_no='" & dt2.Rows(0).Item("lot_no") & "' and quantity ='" & dt2.Rows(0).Item("quantity") & "' and matl_no='" & matl_no & "'"
  2251. ' '' cmd.CommandText = Sql
  2252. ' '' dr = cmd.ExecuteScalar
  2253. ' '' End If
  2254. ' '' Exit Sub
  2255. ' ''End If
  2256. ' ''If dt1.Rows(0).Item("quantity") - dt1.Rows(0).Item("w") - quantity > 0 Then
  2257. ' '' Sql = "insert into tblchem_lot_io (lot_no,matl_no,quantity,io_type,coin,price,id) values ('" & dt1.Rows(0).Item("lot_no") & "','" & matl_no & "','" & quantity & "','" & "領料" & "','" & dt1.Rows(0).Item("coin") & "','" & dt1.Rows(0).Item("price") & "','" & id & "')"
  2258. ' '' cmd.CommandText = Sql
  2259. ' '' dr = cmd.ExecuteScalar
  2260. ' '' Sql = "update tblchem_lot set w=w+'" & quantity & "' where lot_no='" & dt1.Rows(0).Item("lot_no") & "' and quantity ='" & dt1.Rows(0).Item("quantity") & "' and matl_no='" & matl_no & "'"
  2261. ' '' cmd.CommandText = Sql
  2262. ' '' dr = cmd.ExecuteScalar
  2263. ' ''Else
  2264. ' '' If dt1.Rows(0).Item("quantity") - dt1.Rows(0).Item("w") > 0 Then
  2265. ' '' Sql = "insert into tblchem_lot_io (lot_no,matl_no,quantity,io_type,coin,price,id) values ('" & dt1.Rows(0).Item("lot_no") & "','" & matl_no & "','" & dt1.Rows(0).Item("quantity") - dt1.Rows(0).Item("w") & "','" & "領料" & "','" & dt1.Rows(0).Item("coin") & "','" & dt1.Rows(0).Item("price") & "','" & id & "')"
  2266. ' '' cmd.CommandText = Sql
  2267. ' '' dr = cmd.ExecuteScalar
  2268. ' '' Sql = "update tblchem_lot set w=w+'" & dt1.Rows(0).Item("quantity") - dt1.Rows(0).Item("w") & "' where lot_no='" & dt1.Rows(0).Item("lot_no") & "' and quantity ='" & dt1.Rows(0).Item("quantity") & "'"
  2269. ' '' cmd.CommandText = Sql
  2270. ' '' dr = cmd.ExecuteScalar
  2271. ' '' chem_balance(matl_no, quantity - (dt1.Rows(0).Item("quantity") - dt1.Rows(0).Item("w")), x + 1, id)
  2272. ' '' Else
  2273. ' '' Sql = "insert into tblchem_lot_io (lot_no,matl_no,quantity,io_type,coin,price,id) values ('" & dt1.Rows(0).Item("lot_no") & "','" & matl_no & "','" & dt1.Rows(0).Item("quantity") - dt1.Rows(0).Item("w") & "','" & "領料" & "','" & dt1.Rows(0).Item("coin") & "','" & dt1.Rows(0).Item("price") & "','" & id & "')"
  2274. ' '' cmd.CommandText = Sql
  2275. ' '' dr = cmd.ExecuteScalar
  2276. ' '' Sql = "update tblchem_lot set w=w+'" & dt1.Rows(0).Item("quantity") - dt1.Rows(0).Item("w") & "' where lot_no='" & dt1.Rows(0).Item("lot_no") & "' and quantity ='" & dt1.Rows(0).Item("quantity") & "'"
  2277. ' '' cmd.CommandText = Sql
  2278. ' '' dr = cmd.ExecuteScalar
  2279. ' '' End If
  2280. ' ''End If
  2281. End Sub
  2282. Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.Click
  2283. Dim rcp_name As String = ""
  2284. Dim sql As String = ""
  2285. If conn.State = ConnectionState.Closed Then
  2286. conn.Open()
  2287. End If
  2288. sql = "delete from " & rcp & " where rcp_no='" & DGV1.Rows(DGV1.CurrentRow.Index).Cells(0).Value & "'"
  2289. cmd.Connection = conn
  2290. cmd.CommandText = sql
  2291. cmd.ExecuteScalar()
  2292. 'sql = "delete from " & rcp1 & " where rcp_no='" & DGV1.Rows(DGV1.CurrentRow.Index).Cells(0).Value & "'"
  2293. 'cmd.Connection = conn
  2294. 'cmd.CommandText = sql
  2295. 'cmd.ExecuteScalar()
  2296. conn.Close()
  2297. End Sub
  2298. Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
  2299. End Sub
  2300. Private Sub Button14_Click_1(sender As Object, e As EventArgs) Handles Button14.Click
  2301. If ListBox2.SelectedIndex = -1 Or ListBox2.SelectedIndex = -1 Or ListBox2.SelectedIndex = -1 Then
  2302. MsgBox("請先選擇客戶產品顏色", , "錯誤")
  2303. Exit Sub
  2304. End If
  2305. Dim sql As String = ""
  2306. Dim con As New SqlConnection
  2307. Dim rcp_no As String = ""
  2308. Dim cust_no As String = ""
  2309. Dim prod_id As String = ""
  2310. Dim color_no As String = ""
  2311. con.ConnectionString = connstring
  2312. con.Open()
  2313. cmd.Connection = con
  2314. sql = "select id from customer where cust_name='" & ListBox2.SelectedItem & "'"
  2315. cmd.CommandText = sql
  2316. cust_no = cmd.ExecuteScalar
  2317. sql = "select prod_id from tblproduct where prod_name='" & ListBox3.SelectedItem & "'"
  2318. cmd.CommandText = sql
  2319. prod_id = cmd.ExecuteScalar
  2320. sql = "select color_no from color where color_name='" & ListBox4.SelectedItem & "'"
  2321. cmd.CommandText = sql
  2322. color_no = cmd.ExecuteScalar
  2323. sql = "select count(*) from prescription_main where substring(rcp_no,4,3)='" & cust_no & "' and substring(rcp_no,1,1)='" & prod_id & "' and substring(rcp_no,7,2)='" & color_no & "'"
  2324. cmd.CommandText = sql
  2325. Dim c As Integer = cmd.ExecuteScalar
  2326. If c = 0 Then
  2327. rr = prod_id & String.Format("{0:D2}", c) & String.Format("{0:D3}", cust_no) & color_no
  2328. Else
  2329. rr = prod_id & String.Format("{0:D2}", c + 1) & String.Format("{0:D3}", cust_no) & color_no
  2330. End If
  2331. sql = "select count(*) from prescription_main where rcp_no='" & rr & "'"
  2332. cmd.CommandText = sql
  2333. c = cmd.ExecuteScalar
  2334. rcp_name = ListBox2.SelectedItem & ListBox4.SelectedItem & ListBox3.SelectedItem
  2335. rcp_name = InputBox("處方名稱", "詢問", rcp_name)
  2336. sql = "select count(*) from prescription_main where rcp_no='" & rr & "'"
  2337. cmd.CommandText = sql
  2338. Dim a As Integer = cmd.ExecuteScalar
  2339. If a = 0 Then
  2340. 'sql = "insert into prescription_main (rcp_no,rcp_name,creat_d) values ( '" & rcp_no & "','" & rcp_name & "','" & Now & "')"
  2341. 'cmd.CommandText = sql
  2342. 'Dim b As Integer = cmd.ExecuteScalar()
  2343. 'If b <> 0 Then
  2344. ' MsgBox("新增處方完成")
  2345. ' Exit Sub
  2346. 'End If
  2347. Else
  2348. MsgBox("處方編號重覆")
  2349. gAddfromOther = False
  2350. Exit Sub
  2351. End If
  2352. Dim msg As MsgBoxResult
  2353. msg = MsgBox("是否要由其他處方修改?", vbYesNoCancel, "詢問")
  2354. gAddfromOther = True
  2355. Dim my_rcp As String = ""
  2356. my_rcp = InputBox("請輸入處方編號")
  2357. If my_rcp = "" Then Exit Sub
  2358. sql_rcp = "select RCP_NO as 處方編號, RCP_NAME as 品名, CREAT_D, LAST_EDITED, LAST_USED from prescription_main where rcp_no like '%" & my_rcp & "%' or rcp_name like '%" & my_rcp & "%'"
  2359. cmd.CommandText = sql_rcp
  2360. da.SelectCommand = cmd
  2361. Dim ds As New DataSet
  2362. da.Fill(ds)
  2363. DGV1.DataSource = ds.Tables(0)
  2364. Timer1.Enabled = True
  2365. con.Close()
  2366. End Sub
  2367. Private Sub dgv_cost_CellEnter(sender As Object, e As DataGridViewCellEventArgs) Handles dgv_cost.CellEnter
  2368. Dim ds1 As New DataSet
  2369. Dim ds2 As New DataSet
  2370. Dim cn As New SqlConnection
  2371. cn.ConnectionString = connstring
  2372. cn.Open()
  2373. cmd.Connection = cn
  2374. sql_rcp = "select rcp_content.ITEM AS 項目,rcp_content.MATL_NO AS 編號,tblMaterial.MATL_NAME AS 品名,rcp_content.percents AS 比例 " &
  2375. " FROM " & rcp & " INNER JOIN rcp_content ON " & rcp & ".RCP_NO = rcp_content.RCP_NO INNER JOIN " &
  2376. " tblMaterial ON rcp_content.MATL_NO = tblMaterial.MATL_NO WHERE rcp_content.RCP_NO='" & DGV1.Rows(DGV1.CurrentRow.Index).Cells(0).Value & "' and tblMaterial.MATL_ID='" & dgv_cost.Rows(dgv_cost.CurrentRow.Index).Cells(1).Value & "' order by rcp_content.item"
  2377. cmd.CommandText = sql_rcp
  2378. da.SelectCommand = cmd
  2379. da.Fill(ds2)
  2380. dgv_chem_detail.DataSource = ds2.Tables(0)
  2381. dgv_chem_detail.Columns(0).Width = 38
  2382. dgv_chem_detail.Columns(1).Width = 50
  2383. dgv_chem_detail.Columns(2).Width = 80
  2384. dgv_chem_detail.Columns(3).Width = 50
  2385. End Sub
  2386. Private Sub set_grid()
  2387. DGV1.Columns(0).Width = 280
  2388. DGV1.Columns(1).Width = 140
  2389. 'DGV1.Columns(2).Visible = False
  2390. 'DGV1.Columns(3).Visible = False
  2391. 'DGV1.Columns(4).Visible = False
  2392. 'DGV1.RowHeadersVisible = False
  2393. 'If gUserName <> "matchy" Then
  2394. ' dgv2.Columns(6).Visible = False
  2395. ' dgv2.Columns(7).Visible = False
  2396. 'End If
  2397. End Sub
  2398. Private Sub set_grid1()
  2399. 'dgv2.Columns(0).Width = 70
  2400. 'dgv2.Columns(1).Width = 350
  2401. 'dgv2.Columns(2).Width = 80
  2402. 'dgv2.Columns(3).Width = 80
  2403. 'dgv2.Columns(4).Width = 300
  2404. ' dgv2.Columns(5).Visible = False
  2405. 'dgv2.Columns(5).Width = 150
  2406. 'dgv2.Columns(6).Width = 59
  2407. 'dgv2.Columns(7).Width = 60
  2408. 'dgv2.Columns(8).Width = 50
  2409. 'dgv2.Columns(9).Width = 200
  2410. 'If gUserName <> "matchy" Then
  2411. ' dgv2.Columns(5).Width = 207
  2412. ' dgv2.Columns(6).Visible = False
  2413. ' dgv2.Columns(7).Visible = False
  2414. 'End If
  2415. DataGridView1.Columns(0).Width = 70
  2416. DataGridView1.Columns(1).Width = 150
  2417. DataGridView1.Columns(2).Width = 150
  2418. DataGridView1.Columns(3).Width = 80
  2419. DataGridView1.Columns(4).Width = 100
  2420. DataGridView1.Columns(5).Width = 100
  2421. DataGridView1.Columns(6).Width = 240
  2422. End Sub
  2423. Private Sub set_grid2()
  2424. dgv_record.Columns(0).Width = 38
  2425. dgv_record.Columns(1).Width = 58
  2426. dgv_record.Columns(2).Width = 150
  2427. dgv_record.Columns(3).Width = 50
  2428. dgv_record.Columns(4).Width = 44
  2429. dgv_record.Columns(5).Width = 87
  2430. dgv_record.Columns(6).Width = 59
  2431. dgv_record.Columns(7).Width = 60
  2432. 'If gUserName <> "matchy" Then
  2433. ' dgv_record.Columns(6).Visible = False
  2434. ' dgv_record.Columns(7).Visible = False
  2435. 'End If
  2436. End Sub
  2437. Private Sub set_grid3()
  2438. dgv_cost.Columns(0).Width = 60
  2439. dgv_cost.Columns(1).Width = 60
  2440. 'dgv_cost.Columns(2).Width = 60
  2441. 'dgv_cost.Columns(3).Width = 60
  2442. End Sub
  2443. Private Sub DGV1_CellMouseUp(sender As Object, e As DataGridViewCellMouseEventArgs) Handles DGV1.CellMouseUp
  2444. Dim ds1 As New DataSet
  2445. Dim ds2 As New DataSet
  2446. Dim cn As New SqlConnection
  2447. DT2.Clear()
  2448. cn.ConnectionString = connstring
  2449. cn.Open()
  2450. cmd.Connection = cn
  2451. txttan.Text = ""
  2452. txtKJ.Text = ""
  2453. txtoil.Text = ""
  2454. txtdye.Text = ""
  2455. txtx.Text = ""
  2456. txtxx.Text = ""
  2457. txtsum.Text = ""
  2458. sql_rcp = "SELECT HT_RetanRcp.item AS 项次, HT_RetanRcp.chem AS 化料名称, CASE WHEN type1 IS NULL THEN '' ELSE HT_Chem_Main.type1 END AS 化工分类, CASE WHEN type2 IS NULL THEN N'不列印' ELSE HT_Chem_Main.type2 END AS 类别, HT_RetanRcp.percents AS 百分比, HT_RetanRcp.time AS 时间, HT_RetanRcp.comment AS 备注 FROM HT_Chem_Main RIGHT OUTER JOIN HT_Rcp_ChemName_table ON HT_Chem_Main.sys_name = HT_Rcp_ChemName_table.sys_chem_name RIGHT OUTER JOIN HT_RetanRcp ON HT_Rcp_ChemName_table.rcp_chem_name = HT_RetanRcp.chem where HT_RetanRcp.name =N'" & DGV1.Rows(DGV1.CurrentRow.Index).Cells("品名").Value & "' and HT_RetanRcp.date =N'" & DGV1.Rows(DGV1.CurrentRow.Index).Cells("日期").Value & "'and HT_RetanRcp.selection =N'" & DGV1.Rows(DGV1.CurrentRow.Index).Cells("选级").Value & "'and HT_RetanRcp.no =N'" & DGV1.Rows(DGV1.CurrentRow.Index).Cells("流程卡号").Value & "' and HT_RetanRcp.chem<>'' ORDER BY HT_RetanRcp.rcp_no DESC, 项次"
  2459. sql_rcp = "SELECT HT_RetanRcp.item AS 项次, HT_RetanRcp.chem AS 化料名称, CASE WHEN type1 IS NULL THEN '' ELSE HT_Chem_Main.type1 END AS 化工分类, CASE WHEN type2 IS NULL THEN N'不列印' ELSE HT_Chem_Main.type2 END AS 类别, HT_RetanRcp.percents AS 百分比, HT_RetanRcp.time AS 时间, HT_RetanRcp.comment AS 备注, HT_Chem_Main.d1, HT_Chem_Main.d2,
  2460. HT_Chem_Main.d3, HT_Chem_Main.d4, HT_Chem_Main.d5, HT_Chem_Main.d6, HT_Chem_Main.d7, HT_Chem_Main.d8, HT_Chem_Main.d9 FROM HT_Chem_Main RIGHT OUTER JOIN HT_Rcp_ChemName_table ON HT_Chem_Main.sys_name = HT_Rcp_ChemName_table.sys_chem_name RIGHT OUTER JOIN
  2461. HT_RetanRcp ON HT_Rcp_ChemName_table.rcp_chem_name = HT_RetanRcp.chem WHERE HT_RetanRcp.name =N'" & DGV1.Rows(DGV1.CurrentRow.Index).Cells("品名").Value & "' and HT_RetanRcp.date =N'" & DGV1.Rows(DGV1.CurrentRow.Index).Cells("日期").Value & "'and HT_RetanRcp.selection =N'" & DGV1.Rows(DGV1.CurrentRow.Index).Cells("选级").Value & "'and HT_RetanRcp.no =N'" & DGV1.Rows(DGV1.CurrentRow.Index).Cells("流程卡号").Value & "' and (HT_RetanRcp.chem <> '')
  2462. ORDER BY HT_RetanRcp.rcp_no DESC, 项次"
  2463. 'sql_rcp = "SELECT TOP (200) RT_RETAN_RCP_DETAIL.serial AS 项次, RT_RETAN_RCP_DETAIL.CHEM AS 化料名称, RT_RETAN_RCP_DETAIL.PERCENTAGE AS 百分比, RT_RETAN_RCP_DETAIL.time AS 时间, RT_RETAN_RCP_DETAIL.comment AS 备注, RT_RETAN_RCP_DETAIL.CLASS AS 分类, RT_CHEM_MSDS.D1, RT_CHEM_MSDS.D2, RT_CHEM_MSDS.D3, RT_CHEM_MSDS.D4, RT_CHEM_MSDS.D5, RT_CHEM_MSDS.D6, RT_CHEM_MSDS.D7, RT_CHEM_MSDS.D8, RT_CHEM_MSDS.D9,RT_CHEM_MSDS.type as class FROM RT_RETAN_RCP_DETAIL LEFT OUTER JOIN RT_CHEM_MSDS ON RT_RETAN_RCP_DETAIL.CHEM = RT_CHEM_MSDS.SYS_NAME where rcp_name =N'" & DGV1.Rows(DGV1.CurrentRow.Index).Cells("处方名称").Value & "' ORDER BY 项次"
  2464. 'sql_print = "SELECT TOP (200) RT_RETAN_RCP_DETAIL.serial AS 项次, RT_RETAN_RCP_DETAIL.CHEM AS 化料名称, RT_RETAN_RCP_DETAIL.PERCENTAGE AS 百分比, RT_RETAN_RCP_DETAIL.time AS 时间, RT_RETAN_RCP_DETAIL.comment AS 备注, RT_RETAN_RCP_DETAIL.CLASS AS 分类, RT_CHEM_MSDS.D1, RT_CHEM_MSDS.D2, RT_CHEM_MSDS.D3, RT_CHEM_MSDS.D4, RT_CHEM_MSDS.D5, RT_CHEM_MSDS.D6, RT_CHEM_MSDS.D7, RT_CHEM_MSDS.D8, RT_CHEM_MSDS.D9,RT_CHEM_MSDS.type as class FROM RT_RETAN_RCP_DETAIL LEFT OUTER JOIN RT_CHEM_MSDS ON RT_RETAN_RCP_DETAIL.CHEM = RT_CHEM_MSDS.SYS_NAME where rcp_name =N'" & DGV1.Rows(DGV1.CurrentRow.Index).Cells("处方名称").Value & "' and comment<>'' and comment<>N'自打' ORDER BY 备注,项次,化料名称"
  2465. 'cmd.CommandText = sql_print
  2466. 'dt_print = New DataTable
  2467. 'da.SelectCommand = cmd
  2468. 'da.Fill(dt_print)
  2469. sql_rcp = "SELECT HT_RetanRcp.item AS 项次, HT_RetanRcp.chem AS 化料名称, CASE WHEN type1 IS NULL THEN '' ELSE HT_Chem_Main.type1 END AS 化工分类, CASE WHEN type2 IS NULL THEN N'不列印' ELSE HT_Chem_Main.type2 END AS 类别,
  2470. HT_RetanRcp.percents AS 百分比, HT_RetanRcp.time AS 时间, HT_RetanRcp.comment AS 备注, HT_Chem_Main.d1, HT_Chem_Main.d2, HT_Chem_Main.d3, HT_Chem_Main.d4, HT_Chem_Main.d5, HT_Chem_Main.d6, HT_Chem_Main.d7,
  2471. HT_Chem_Main.d8, HT_Chem_Main.d9, HT_MSDS_File_1.filename
  2472. FROM HT_Chem_Main LEFT OUTER JOIN
  2473. (SELECT filename, SUBSTRING(filename, 1, CHARINDEX('_', filename) - 1) AS no
  2474. FROM HT_MSDS_File) AS HT_MSDS_File_1 ON HT_Chem_Main.no = HT_MSDS_File_1.no RIGHT OUTER JOIN
  2475. HT_Rcp_ChemName_table ON HT_Chem_Main.sys_name = HT_Rcp_ChemName_table.sys_chem_name RIGHT OUTER JOIN
  2476. HT_RetanRcp ON HT_Rcp_ChemName_table.rcp_chem_name = HT_RetanRcp.chem
  2477. WHERE HT_RetanRcp.name =N'" & DGV1.Rows(DGV1.CurrentRow.Index).Cells("品名").Value & "' and HT_RetanRcp.date =N'" & DGV1.Rows(DGV1.CurrentRow.Index).Cells("日期").Value & "'and HT_RetanRcp.selection =N'" & DGV1.Rows(DGV1.CurrentRow.Index).Cells("选级").Value & "'and HT_RetanRcp.no =N'" & DGV1.Rows(DGV1.CurrentRow.Index).Cells("流程卡号").Value & "' and (HT_RetanRcp.chem <> '')
  2478. ORDER BY HT_RetanRcp.rcp_no DESC, 项次"
  2479. Label20.Text = DGV1.Rows(DGV1.CurrentRow.Index).Cells("品名").Value.ToString
  2480. cmd.CommandText = sql_rcp
  2481. da.SelectCommand = cmd
  2482. da.Fill(DT2)
  2483. ' dgv2.DataSource = dt_print
  2484. DataGridView1.DataSource = DT2
  2485. DataGridView1.RowTemplate.Height = 24
  2486. set_grid1()
  2487. End Sub
  2488. Private Sub dgv2_RowPostPaint(sender As Object, e As DataGridViewRowPostPaintEventArgs) Handles dgv2.RowPostPaint
  2489. Dim linePen As New Pen(Color.Aquamarine, 2)
  2490. If e.RowIndex = dgv2.Rows.Count - 1 Then
  2491. dgv2.Rows(e.RowIndex).Cells("百分比").Style.ForeColor = Color.White
  2492. Dim startX As Integer = IIf(dgv2.RowHeadersVisible, dgv2.RowHeadersWidth, 0)
  2493. Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  2494. Dim endX As Integer = startX + dgv2.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - dgv2.HorizontalScrollingOffset - 100
  2495. e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
  2496. Exit Sub
  2497. End If
  2498. If dgv2.Rows(e.RowIndex).Cells("时间").Value.ToString <> "" And (dgv2.Rows(e.RowIndex + 1).Cells("化料名称").Value.ToString = "流水洗" Or dgv2.Rows(e.RowIndex + 1).Cells("化料名称").Value.ToString = "洗水" Or dgv2.Rows(e.RowIndex + 1).Cells("化料名称").Value = "排水") Then
  2499. ElseIf dgv2.Rows(e.RowIndex).Cells("时间").Value.ToString <> "" Then
  2500. Dim startX As Integer = IIf(dgv2.RowHeadersVisible, dgv2.RowHeadersWidth, 0)
  2501. Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  2502. Dim endX As Integer = startX + dgv2.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - dgv2.HorizontalScrollingOffset - 100
  2503. e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
  2504. End If
  2505. If (dgv2.Rows(e.RowIndex).Cells("化料名称").Value.ToString = "流水洗" Or dgv2.Rows(e.RowIndex).Cells("化料名称").Value.ToString = "洗水" Or dgv2.Rows(e.RowIndex).Cells("化料名称").Value = "排水") Then
  2506. dgv2.Rows(e.RowIndex).Cells("百分比").Style.ForeColor = Color.White
  2507. Dim startX As Integer = IIf(dgv2.RowHeadersVisible, dgv2.RowHeadersWidth, 0)
  2508. Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  2509. Dim endX As Integer = startX + dgv2.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - dgv2.HorizontalScrollingOffset - 100
  2510. e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
  2511. End If
  2512. End Sub
  2513. Private Sub DataGridView1_RowPostPaint(sender As Object, e As DataGridViewRowPostPaintEventArgs) Handles DataGridView1.RowPostPaint
  2514. If e.RowIndex + 1 > DataGridView1.Rows.Count - 1 Then Exit Sub
  2515. If DataGridView1.Rows(e.RowIndex + 1).Cells("化料名称").Value Is Nothing Then Exit Sub
  2516. Dim linePen As New Pen(Color.Red, 2)
  2517. If e.RowIndex = DataGridView1.Rows.Count - 1 Then
  2518. DataGridView1.Rows(e.RowIndex).Cells("百分比").Style.ForeColor = Color.White
  2519. Dim startX As Integer = IIf(DataGridView1.RowHeadersVisible, DataGridView1.RowHeadersWidth, 0)
  2520. Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  2521. Dim endX As Integer = startX + DataGridView1.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - DataGridView1.HorizontalScrollingOffset - 10
  2522. e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
  2523. Exit Sub
  2524. End If
  2525. If DataGridView1.Rows(e.RowIndex).Cells("时间").Value.ToString <> "" Then
  2526. Dim startX As Integer = IIf(DataGridView1.RowHeadersVisible, DataGridView1.RowHeadersWidth, 0)
  2527. Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  2528. Dim endX As Integer = startX + DataGridView1.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - DataGridView1.HorizontalScrollingOffset - 10
  2529. e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
  2530. End If
  2531. 'If (DataGridView1.Rows(e.RowIndex).Cells("化料名称").Value.ToString = "流水洗" Or DataGridView1.Rows(e.RowIndex).Cells("化料名称").Value.ToString = "洗水" Or DataGridView1.Rows(e.RowIndex).Cells("化料名称").Value = "排水") Then
  2532. ' DataGridView1.Rows(e.RowIndex).Cells("百分比").Style.ForeColor = Color.White
  2533. ' Dim startX As Integer = IIf(DataGridView1.RowHeadersVisible, DataGridView1.RowHeadersWidth, 0)
  2534. ' Dim startY As Integer = e.RowBounds.Top + e.RowBounds.Height - 1
  2535. ' Dim endX As Integer = startX + DataGridView1.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - DataGridView1.HorizontalScrollingOffset - 10
  2536. ' e.Graphics.DrawLine(linePen, startX, startY, endX, startY)
  2537. 'End If
  2538. End Sub
  2539. Private Sub Button24_Click(sender As Object, e As EventArgs) Handles Button24.Click 'msds
  2540. cmd.Connection = conn
  2541. If conn.State = ConnectionState.Closed Then
  2542. conn.Open()
  2543. End If
  2544. Dim sql As String
  2545. Dim folderPath As String = "\\DS920plus\华峰业务\AA化料文件资料\2024年整理MSDS和ZDHC\MSDS\MSDS总表"
  2546. ' 检查文件夹是否存在
  2547. If Directory.Exists(folderPath) Then
  2548. ' 获取文件夹内所有文件的路径
  2549. Dim files As String() = Directory.GetFiles(folderPath)
  2550. ' 遍历文件数组并输出文件名
  2551. For Each file As String In files
  2552. ' 输出文件名
  2553. Console.WriteLine(Path.GetFileName(file))
  2554. sql = "insert into ht_msds_file (filename) values (N'" & Path.GetFileName(file) & "')"
  2555. cmd.CommandText = sql
  2556. cmd.ExecuteScalar()
  2557. Next
  2558. Else
  2559. Console.WriteLine("目录不存在!")
  2560. End If
  2561. MsgBox("")
  2562. End Sub
  2563. Private Sub DGV1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DGV1.CellContentClick
  2564. End Sub
  2565. Sub InsertImageWithNPOI(start_row As Integer, start_column As Integer)
  2566. ' 创建 NPOI 工作簿和工作表
  2567. Dim workbook As New XSSFWorkbook()
  2568. Dim sheet As XSSFSheet = workbook.CreateSheet("Sheet1")
  2569. ' 图片数据
  2570. Dim pictureData As Byte() = Nothing
  2571. Using ms As New MemoryStream()
  2572. ' 从 PictureBox1 中获取图片
  2573. PictureBox1.Image.Save(ms, Imaging.ImageFormat.Png)
  2574. pictureData = ms.ToArray()
  2575. End Using
  2576. ' 将图片添加到工作簿中
  2577. Dim pictureIndex As Integer = workbook.AddPicture(pictureData, PictureType.PNG)
  2578. ' 创建绘图对象
  2579. Dim drawing As XSSFDrawing = sheet.CreateDrawingPatriarch()
  2580. ' 创建图片锚点
  2581. Dim anchor As IClientAnchor = workbook.GetCreationHelper().CreateClientAnchor()
  2582. anchor.Col1 = start_column ' 起始列(从 0 开始计数)
  2583. anchor.Row1 = start_row ' 起始行(从 0 开始计数)
  2584. anchor.Col2 = start_column ' 结束列
  2585. anchor.Row2 = start_row ' 结束行
  2586. ' 插入图片
  2587. Dim picture As IPicture = drawing.CreatePicture(anchor, pictureIndex)
  2588. ' 调整图片大小
  2589. picture.Resize(0.29) ' 设置缩放比例,例如 0.29 表示缩放为原大小的 29%
  2590. ' 保存文件
  2591. Dim saveFilePath As String = "c:\GHS\output.xlsx"
  2592. Using fs As New FileStream(saveFilePath, FileMode.Create, FileAccess.Write)
  2593. workbook.Write(fs)
  2594. End Using
  2595. ' MsgBox("图片插入完成!")
  2596. End Sub
  2597. Private Sub Button25_Click(sender As Object, e As EventArgs) Handles Button25.Click
  2598. End Sub
  2599. Function ImageToByteArray(image As Image) As Byte()
  2600. Using ms As New MemoryStream()
  2601. image.Save(ms, ImageFormat.Png)
  2602. Return ms.ToArray()
  2603. End Using
  2604. End Function
  2605. Private Sub Button26_Click(sender As Object, e As EventArgs) Handles Button26.Click
  2606. Dim my_card As String
  2607. Dim my_weight As Double
  2608. Dim d_no As String
  2609. Do
  2610. my_card = InputBox("请输入卡号:", "查询", DGV1.Rows(DGV1.CurrentCell.RowIndex).Cells(4).Value)
  2611. If my_card = "" Then
  2612. MsgBox("操作已取消。", vbInformation, "退出")
  2613. Exit Sub ' 立即退出子程序
  2614. ElseIf my_card = "" Then
  2615. MsgBox("请重新输入!", vbExclamation, "错误")
  2616. Else
  2617. Exit Do
  2618. End If
  2619. Loop
  2620. ' 验证重量输入
  2621. Do
  2622. Dim weightInput As String
  2623. weightInput = InputBox("请输入重量:", "查询", DGV1.Rows(DGV1.CurrentCell.RowIndex).Cells(3).Value)
  2624. If weightInput = "" Then
  2625. MsgBox("操作已取消。", vbInformation, "退出")
  2626. Exit Sub
  2627. ElseIf Not IsNumeric(weightInput) Then
  2628. MsgBox("重量必须是数字,请重新输入!", vbExclamation, "错误")
  2629. ElseIf CDbl(weightInput) <= 0 Then
  2630. MsgBox("重量必须大于0,请重新输入!", vbExclamation, "错误")
  2631. Else
  2632. my_weight = CDbl(weightInput)
  2633. Exit Do
  2634. End If
  2635. Loop
  2636. ' 验证编号输入
  2637. Do
  2638. d_no = InputBox("请输入编号:", "查询", 10)
  2639. If d_no = "" Then
  2640. MsgBox("操作已取消。", vbInformation, "退出")
  2641. Exit Sub
  2642. ElseIf d_no Like "*-*" Then
  2643. ' MsgBox("编号格式不正确,请输入类似 'P241129-4' 的编号!", vbExclamation, "错误")
  2644. Else
  2645. Exit Do
  2646. End If
  2647. Loop
  2648. ' 图片路径(假设图片名为 1.jpg 到 9.jpg)
  2649. Dim imagePaths As String() = {
  2650. "C:\GHS\1.jpg", "C:\GHS\2.jpg", "C:\GHS\3.jpg",
  2651. "C:\GHS\4.jpg", "C:\GHS\5.jpg", "C:\GHS\6.jpg",
  2652. "C:\GHS\7.jpg", "C:\GHS\8.jpg", "C:\GHS\9.jpg"
  2653. }
  2654. Dim dataTable As New DataTable()
  2655. dataTable = DataGridView1.DataSource
  2656. ' 创建 Excel 工作簿
  2657. Dim workbook As IWorkbook = New XSSFWorkbook()
  2658. Dim sheet As ISheet = workbook.CreateSheet("Chemicals")
  2659. ' 创建隐藏的图片库工作表
  2660. Dim imageSheet As ISheet = workbook.CreateSheet("ImageLibrary")
  2661. '' workbook.SetSheetHidden(workbook.GetSheetIndex("ImageLibrary"), SheetState.Hidden)
  2662. ' 加载图片到图片库
  2663. Dim drawing As IDrawing = imageSheet.CreateDrawingPatriarch()
  2664. For i As Integer = 0 To imagePaths.Length - 1
  2665. Dim imagePath As String = imagePaths(i)
  2666. If File.Exists(imagePath) Then
  2667. Dim bytes As Byte() = File.ReadAllBytes(imagePath)
  2668. Dim pictureIdx As Integer = workbook.AddPicture(bytes, PictureType.JPEG)
  2669. ' 插入图片到隐藏工作表
  2670. Dim anchor As IClientAnchor = workbook.GetCreationHelper().CreateClientAnchor()
  2671. anchor.Col1 = i + 2 ' 每张图片占一列
  2672. anchor.Row1 = 0
  2673. anchor.AnchorType = AnchorType.DontMoveAndResize
  2674. Dim picture As IPicture = drawing.CreatePicture(anchor, pictureIdx)
  2675. picture.Resize(1)
  2676. End If
  2677. Next
  2678. For col As Integer = 0 To 5
  2679. sheet.SetColumnWidth(col, 10 * 256) ' 图片列宽度
  2680. Next
  2681. ' 初始行位置
  2682. Dim currentRow As Integer = 0
  2683. Dim my_item As Integer
  2684. dataTable.DefaultView.Sort = "类别 ASC, 项次 ASC"
  2685. Dim sortedTable As DataTable = dataTable.DefaultView.ToTable()
  2686. ProgressBar1.Visible = True
  2687. ProgressBar1.Minimum = 0
  2688. ProgressBar1.Maximum = sortedTable.Rows.Count ' 假设 dt 是一个 DataTable
  2689. ProgressBar1.Value = 0 ' 初始进度为 0
  2690. ' 遍历 DataTable 的每一行
  2691. For Each row As DataRow In sortedTable.Rows
  2692. ProgressBar1.Value += 1
  2693. Application.DoEvents()
  2694. If row("类别") <> "不列印" Then
  2695. '生成二维码图片
  2696. Dim qrCodeImage As Image = MakeQrCode("http://192.168.110.164:8888/" & row("filename"))
  2697. Dim imageBytes As Byte() = ImageToByteArray(qrCodeImage)
  2698. ' 插入二维码图片到第4列
  2699. Dim drawingQrCode As IDrawing = sheet.CreateDrawingPatriarch()
  2700. Dim anchorQrCode As IClientAnchor = workbook.GetCreationHelper().CreateClientAnchor()
  2701. anchorQrCode.Col1 = 4 ' 第4列
  2702. anchorQrCode.Row1 = currentRow + 7 ' 当前行
  2703. anchorQrCode.Col2 = 5 ' 跨1列
  2704. anchorQrCode.Row2 = currentRow + 11 ' 占用4行
  2705. Dim qrPictureIdx As Integer = workbook.AddPicture(imageBytes, PictureType.PNG)
  2706. Dim qrPicture As IPicture = drawingQrCode.CreatePicture(anchorQrCode, qrPictureIdx)
  2707. qrPicture.Resize(1) ' 缩放二维码
  2708. ' 写入化工信息
  2709. 'sheet.CreateRow(currentRow).CreateCell(3).SetCellValue($"卡号:{my_card}")
  2710. 'sheet.CreateRow(currentRow).CreateCell(7).SetCellValue($"项次:{row("项次")}")
  2711. ' 创建行并插入数据
  2712. Dim rowToInsert = sheet.CreateRow(currentRow) ' 只创建一行
  2713. ' 在第 4 列插入卡号
  2714. rowToInsert.CreateCell(0).SetCellValue($"卡号:{my_card}")
  2715. ' 在第 8 列插入项次
  2716. rowToInsert.CreateCell(4).SetCellValue($"项次:{row("项次")}")
  2717. Dim cellStyle As ICellStyle = workbook.CreateCellStyle()
  2718. Dim font As IFont = workbook.CreateFont()
  2719. font.FontHeightInPoints = 18 ' 设置字体大小为 18
  2720. cellStyle.SetFont(font) ' 将字体应用到样式
  2721. 'sheet.CreateRow(currentRow + 1).CreateCell(0).SetCellValue($"化料名称:{row("化料名称")}")
  2722. Dim row1 = sheet.CreateRow(currentRow + 1)
  2723. row1.CreateCell(0).SetCellValue($"化料名称:{row("化料名称")}")
  2724. row1.Cells(0).CellStyle = cellStyle ' 应用样式
  2725. sheet.AddMergedRegion(New NPOI.SS.Util.CellRangeAddress(currentRow + 1, currentRow + 1, 0, 4))
  2726. Dim row2 = sheet.CreateRow(currentRow + 2)
  2727. row2.CreateCell(0).SetCellValue($"重量:{row("百分比") * my_weight / 100}")
  2728. row2.CreateCell(3).SetCellValue($"{row("化工分类")}")
  2729. row2.Cells(0).CellStyle = cellStyle ' 应用样式
  2730. row2.Cells(1).CellStyle = cellStyle ' 应用样式
  2731. Dim row3 = sheet.CreateRow(currentRow + 3)
  2732. row3.CreateCell(4).SetCellValue($"鼓号")
  2733. Dim row4 = sheet.CreateRow(currentRow + 4)
  2734. row4.CreateCell(4).SetCellValue($"{d_no}")
  2735. Dim row5 = sheet.CreateRow(currentRow + 5)
  2736. row5.CreateCell(3).SetCellValue("百分比")
  2737. row5.CreateCell(4).SetCellValue("下鼓重")
  2738. Dim row6 = sheet.CreateRow(currentRow + 6)
  2739. row6.CreateCell(3).SetCellValue($"{row("百分比")}")
  2740. row6.CreateCell(4).SetCellValue($"{my_weight}")
  2741. Dim row7 = sheet.CreateRow(currentRow + 10)
  2742. row7.CreateCell(1).SetCellValue($"{DGV1.Rows(DGV1.CurrentCell.RowIndex).Cells(1).Value}")
  2743. 'Dim row8 = sheet.CreateRow(currentRow + 11)
  2744. 'row8.CreateCell(3).SetCellValue($"{row("百分比")}")
  2745. Dim row9 = sheet.CreateRow(currentRow + 12)
  2746. row9.CreateCell(1).SetCellValue($"打印时间:{DateTime.Now}")
  2747. sheet.AddMergedRegion(New NPOI.SS.Util.CellRangeAddress(currentRow + 2, currentRow + 2, 0, 2))
  2748. sheet.AddMergedRegion(New NPOI.SS.Util.CellRangeAddress(currentRow + 2, currentRow + 2, 3, 4))
  2749. ' 创建一个字体和边框样式
  2750. Dim cellStyle1 As ICellStyle = workbook.CreateCellStyle()
  2751. ' 设置外边框为粗线
  2752. cellStyle.BorderTop = BorderStyle.Double
  2753. cellStyle.BorderRight = BorderStyle.Double
  2754. cellStyle.BorderBottom = BorderStyle.Double
  2755. cellStyle.BorderLeft = BorderStyle.Double
  2756. ' 为 A2:E3 区域设置边框
  2757. ' 设置粗外框
  2758. For rowX As Integer = currentRow + 1 To currentRow + 2 ' 行索引从 1 开始
  2759. For col As Integer = 0 To 4 ' 列索引从 0 到 4 (A 到 E)
  2760. Dim cell As ICell = sheet.GetRow(rowX).GetCell(col)
  2761. If cell Is Nothing Then
  2762. cell = sheet.GetRow(rowX).CreateCell(col)
  2763. End If
  2764. cell.CellStyle = cellStyle ' 应用样式
  2765. Next
  2766. Next
  2767. ' 插入 d1-d9 对应的图片
  2768. Dim rowStart As Integer = currentRow ' 图片从当前行开始
  2769. Dim colStart1 As Integer = 0
  2770. Dim colStart As Integer = 0 ' d1-d9 的起始列
  2771. Dim imgPerRow As Integer = 3 ' 每行放3张图片
  2772. Dim row_start As Integer = 0
  2773. For i As Integer = 1 To 9
  2774. Dim colName As String = "d" & i
  2775. If row(colName).ToString() = "√" Then
  2776. row_start += 1
  2777. Dim imagePath As String = $"C:\GHS\{i}.jpg" ' 假设图片路径为 C:\GHS\1.jpg 到 C:\GHS\9.jpg
  2778. If File.Exists(imagePath) Then
  2779. Dim bytes As Byte() = File.ReadAllBytes(imagePath)
  2780. Dim pictureIdx As Integer = workbook.AddPicture(bytes, PictureType.JPEG)
  2781. Dim drawingMain As IDrawing = sheet.CreateDrawingPatriarch()
  2782. Dim anchor As IClientAnchor = workbook.GetCreationHelper().CreateClientAnchor()
  2783. anchor.Col1 = colStart
  2784. anchor.Row1 = rowStart + 3 ' 图片放在二维码下方,开始于第5行
  2785. anchor.Col2 = colStart + 1 ' 图片跨2列
  2786. anchor.Row2 = rowStart + 8 ' 图片占用5行
  2787. ' 设置偏移量(像素)
  2788. anchor.Dx1 = 200 ' 左上角水平偏移(单位:EMU)
  2789. anchor.Dy1 = 0 ' 左上角垂直偏移
  2790. anchor.Dx2 = 500 ' 右下角水平偏移
  2791. anchor.Dy2 = 0 ' 右下角垂直偏移
  2792. ' 设置锚点类型,图片不随单元格变化
  2793. anchor.AnchorType = AnchorType.DontMoveAndResize
  2794. Dim picture As IPicture = drawingMain.CreatePicture(anchor, pictureIdx)
  2795. picture.Resize(1) ' 缩放比例
  2796. ' 更新列位置
  2797. colStart += 1
  2798. If colStart >= imgPerRow Then
  2799. colStart1 = 1
  2800. colStart = 0 ' 回到第一列
  2801. rowStart += 5 ' 换行后行数增加5
  2802. End If
  2803. End If
  2804. End If
  2805. Next
  2806. If colStart1 = 1 Then rowStart -= 5
  2807. ' 更新当前行位置,确保下一个化工占用新行
  2808. currentRow = rowStart + 13 ' 增加行数以容纳二维码和图片
  2809. ' 插入换页符
  2810. sheet.SetRowBreak(currentRow - 1)
  2811. End If
  2812. Next
  2813. ' 保存文件
  2814. ' Dim filePath As String = $"卡号标签_{DateTime.Now.ToString("yyyyMMdd_HHmmss")}.xlsx"
  2815. Dim filePath As String = $"卡号标签_{my_card}.xlsx"
  2816. Using fs As New FileStream(filePath, FileMode.Create, FileAccess.Write)
  2817. workbook.Write(fs)
  2818. End Using
  2819. ' 打开文件
  2820. If File.Exists(filePath) Then
  2821. Process.Start(New ProcessStartInfo With {
  2822. .FileName = filePath,
  2823. .UseShellExecute = True
  2824. })
  2825. End If
  2826. ProgressBar1.Visible = False
  2827. End Sub
  2828. Private Sub DGV1_SelectionChanged(sender As Object, e As EventArgs) Handles DGV1.SelectionChanged
  2829. End Sub
  2830. End Class