123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- Imports System.Data.SqlClient
- Imports System.Net
- Imports System.Reflection
- Imports Microsfot.Office.Interop.Excel
-
- Public Class FrmInProcess
- Dim cmd As New SqlCommand
- Dim da As New SqlDataAdapter
- Dim sql As String
- Dim colorArray(10) As Color
- Dim conn As New SqlConnection
- Dim xlApp As Microsoft.Office.Interop.Excel.Application
- Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
- Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
- Dim xlRange As Microsoft.Office.Interop.Excel.Range
- Dim PTCache As Microsoft.Office.Interop.Excel.PivotCache
- Dim PT As Microsoft.Office.Interop.Excel.PivotTable
- Private Sub FrmInProcess_Load(sender As Object, e As EventArgs) Handles MyBase.Load
-
-
-
-
- Dim dText As Decimal
-
- Dim DT1 As New DataTable
- Dim DT2 As New DataTable
- Dim DT3 As New DataTable
-
- conn.ConnectionString = connstring
- conn.Open()
-
- cmd.Connection = conn
-
-
- Me.MdiParent = FrmMDI
-
- DTP1.Value = "2023/02/28"
-
-
- Dim type As Type = dgv1.GetType()
- Dim pi As PropertyInfo = type.GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.NonPublic)
- pi.SetValue(dgv1, True, Nothing)
-
-
- sql = "delete from rt_inprocess_crust where type is null"
- cmd.CommandText = sql
- cmd.ExecuteNonQuery()
-
-
- sql = "select date,card,cust,color,weight,tech,source,w_begin from RT_Inprocess_crust where date='" & DTP1.Value & "' and w_begin is not null"
-
- cmd.CommandText = sql
- cmd.ExecuteNonQuery()
-
- da.SelectCommand = cmd
- da.Fill(DT1)
- dgv1.DataSource = DT1
-
-
- sql = "select source,cast(sum(w_begin) as numeric(10,0)) as 心皮重 from RT_Inprocess_crust where date='" & DTP1.Value & "' and w_begin is not null group by source order by sum(w_begin) desc"
- DT1 = New DataTable
- cmd.CommandText = sql
- cmd.ExecuteNonQuery()
-
- da.SelectCommand = cmd
- da.Fill(DT1)
- dgv2.DataSource = DT1
-
-
- sql = "select cast(sum(w_begin)/2 as numeric(10,0)) as 心皮重 from RT_Inprocess_crust where date='" & DTP1.Value & "' and w_begin is not null "
- cmd.CommandText = sql
- txt_begin.Text = cmd.ExecuteScalar.ToString
-
- dText = Convert.ToDecimal(txt_begin.Text)
- txt_begin.Text = dText.ToString("###,###,###")
-
-
-
- sql = "select cast(sum(w_begin)/2 as numeric(10,0)) as 心皮重 from RT_Inprocess_crust where date='" & DTP1.Value & "' and w_begin is not null and type=N'反绒' "
- cmd.CommandText = sql
- TextBox1.Text = cmd.ExecuteScalar.ToString
- dText = Convert.ToDecimal(TextBox1.Text)
- TextBox1.Text = dText.ToString("###,###,###")
- sql = "select cast(sum(w_begin)/2 as numeric(10,0)) as 心皮重 from RT_Inprocess_crust where date='" & DTP1.Value & "' and w_begin is not null and type=N'反绒' and color like N'%黑色%' "
- cmd.CommandText = sql
- TextBox2.Text = cmd.ExecuteScalar.ToString
- dText = Convert.ToDecimal(TextBox2.Text)
- TextBox2.Text = dText.ToString("###,###,###")
- sql = "select cast(sum(w_begin)/2 as numeric(10,0)) as 心皮重 from RT_Inprocess_crust where date='" & DTP1.Value & "' and w_begin is not null and type=N'反绒' and color not like N'%黑色%' "
- cmd.CommandText = sql
- TextBox3.Text = cmd.ExecuteScalar.ToString
- dText = Convert.ToDecimal(TextBox3.Text)
- TextBox3.Text = dText.ToString("###,###,###")
-
-
- sql = "select cast(sum(w_begin)/2 as numeric(10,0)) as 心皮重 from RT_Inprocess_crust where date='" & DTP1.Value & "' and w_begin is not null and type=N'PU' "
- cmd.CommandText = sql
- TextBox4.Text = cmd.ExecuteScalar.ToString
- dText = Convert.ToDecimal(TextBox4.Text)
- TextBox4.Text = dText.ToString("###,###,###")
- sql = "select cast(sum(w_begin)/2 as numeric(10,0)) as 心皮重 from RT_Inprocess_crust where date='" & DTP1.Value & "' and w_begin is not null and type=N'PU' and color like N'%黑%' "
- cmd.CommandText = sql
- TextBox5.Text = cmd.ExecuteScalar.ToString
- dText = Convert.ToDecimal(TextBox5.Text)
- TextBox5.Text = dText.ToString("###,###,###")
- sql = "select cast(sum(w_begin)/2 as numeric(10,0)) as 心皮重 from RT_Inprocess_crust where date='" & DTP1.Value & "' and w_begin is not null and type=N'PU' and color not like N'%黑%' "
- cmd.CommandText = sql
- TextBox6.Text = cmd.ExecuteScalar.ToString
- dText = Convert.ToDecimal(TextBox6.Text)
- TextBox6.Text = dText.ToString("###,###,###")
-
-
- sql = "select cast(sum(bal_weight)/2 as numeric(10,0)) as bal_weight from (select card,cast(avg(bal_weight) as numeric(10,1)) as bal_weight from(SELECT RT_Inprocess_crust.date, RT_Inprocess_crust.type, RT_Inprocess_crust.card, RT_Inprocess_crust.card1,
- RT_Inprocess_crust.cust, RT_Inprocess_crust.color, RT_Inprocess_crust.weight, RT_Inprocess_crust.tech,
- RT_Inprocess_crust.source, RT_Inprocess_crust.thick, RT_Inprocess_crust.total_weight, RT_Inprocess_crust.bal_weight,
- Rt_spray_daily.date AS spray_date, RT_Inprocess_crust.w_begin
- FROM RT_Inprocess_crust LEFT OUTER JOIN
- Rt_spray_daily ON RT_Inprocess_crust.card = Rt_spray_daily.card where Rt_spray_daily.date is not null and RT_Inprocess_crust.date='" & DTP1.Value & "') as p group by card) as q"
- cmd.CommandText = sql
- TextBox13.Text = cmd.ExecuteScalar
-
-
-
-
-
-
-
- ' dim sText As String = textBox13.Text.Replace (",","")
- dText = Convert.ToDecimal(TextBox13.Text)
- TextBox13.Text = dText.ToString("###,###,###")
-
-
-
- 'Dim dr As SqlDataReader
-
- 'dgv1.RowTemplate.Height = 30
- 'dgv1.AllowUserToAddRows = False
-
-
- 'sql = "delete from rt_inprocess"
- 'cmd.CommandText = sql
- 'cmd.ExecuteNonQuery()
-
-
- 'sql = "insert into rt_inprocess(date,serial,card,word,cust,color,weight,tech,source,coma,comb,comc,comd) select date,serial,card,word,cust,color,weight,tech,source,coma,comb,comc,comd from rt_tm_month"
- 'cmd.CommandText = sql
- 'Dim a As Integer = cmd.ExecuteNonQuery()
-
-
- 'MsgBox(a)
-
- 'sql = "update rt_inprocess set io='start'"
- 'cmd.CommandText = sql
- 'cmd.ExecuteNonQuery()
-
-
- 'sql = "select * from rt_inprocess"
- 'cmd.CommandText = sql
- 'da.SelectCommand = cmd
- 'da.Fill(DT1)
-
- 'For x As Integer = 0 To DT1.Rows.Count - 1
-
- ' sql = "select * from "
-
- 'Next
-
-
-
-
-
- End Sub
-
- Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click '---导入期初
-
-
-
- Dim dt As New DataTable
- Dim file_name As String = ""
-
- Dim a As Integer = 0
- Dim my_count As Integer = 0
- If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
-
- file_name = OpenFileDialog1.FileName
- Else
- Exit Sub
-
- End If
-
-
-
- xlApp = CreateObject("Excel.Application")
-
-
-
- xlBook = xlApp.Workbooks.Open(file_name)
-
- xlApp.Visible = True
- 'xlApp.DisplayAlerts = False
-
- xlBook.Activate()
- xlBook.Parent.Windows(1).Visible = True
-
-
- If (xlApp.Cells(1, 1).value.ToString = "已修改") Then
- ' MsgBox("已修改过了,不用再修改")
-
-
-
- Else
- xlBook.ActiveSheet.rows("1:11").delete
-
- xlApp.Cells(1, 1) = "已修改"
- xlBook.Save()
- End If
-
-
- xlBook.Close()
- xlApp.Quit()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Dim filepath As String = "k3/在制品"
-
- Dim sourceFileName As String = file_name
-
-
- Dim address2 As String = "ftp://" & my_ip & ":7788/" & filepath & "/" & OpenFileDialog1.SafeFileName
-
- Dim address3() As String
-
- address3 = Split(address2, "ftp://" & my_ip & ":7788/")
- Dim add4 As String
-
- add4 = "d:\k3\在制品\" & OpenFileDialog1.SafeFileName
-
-
- Dim userName As String = "matchy3c"
- Dim password As String = "Lafayette11"
- Dim showUI As Boolean = True
- Dim connectionTimeout As Integer = 500
-
-
- Dim client As WebClient = New WebClient
- client.Credentials = New NetworkCredential(userName, password)
- client.Proxy = GlobalProxySelection.GetEmptyWebProxy()
- client.UploadFile(address2, sourceFileName)
-
-
- sql = "delete from rt_inprocess_crust"
- cmd.CommandText = sql
- cmd.ExecuteScalar()
-
-
-
- sql = "Select * FROM OPENDATASOURCE ('Microsoft.ACE.OLEDB.12.0','Excel 12.0;HDR=Yes;IMEX=1;Database=" & add4 & "')... ['2022年10月 $']"
- cmd.CommandText = sql
-
- da.SelectCommand = cmd
- da.Fill(dt)
- ' dgv1.DataSource = dt
-
-
- Dim my_sqlbulk As New SqlBulkCopy(conn)
-
- my_sqlbulk.DestinationTableName = "dbo.rt_inprocess_crust"
- my_sqlbulk.WriteToServer(dt)
-
-
- MsgBox("导入完成")
-
-
-
-
-
-
- End Sub
-
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
-
- End Sub
-
- Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
-
- Dim file_name As String
-
- If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
-
- file_name = OpenFileDialog1.FileName
- Else
- Exit Sub
-
- End If
-
-
-
-
-
-
-
-
-
-
- End Sub
- End Class
|