新增行必须先保存,才能提取或设置后台数据,麻烦老师看看 谢谢!
窗体加载前代码:
Dim cmd As new SQ LCommand
cmd.Connect i
cmd.CommandText = "Se ect 文件名,类型,id,CRC值,登记时间,信息 From {文件附件} "
Dim dt As DataTable = cmd.ExecuteReader()
Tables("主窗口_Table1").DataSource = dt
Tables("主窗口_Table1").SetColVisibleWidth("文件名|230|类型|50")
Dim cmd1 As new SQ LCommand
cmd1.Connec ti
cmd1.CommandText = "Sel ect * From {文件信息} "
Dim dt1 As DataTable = cmd1.ExecuteReader()
Tables("主窗口_Table2").DataSource = dt1
Tables("主窗口_Table2").SetColVisibleWidth("时间|90|作者|80|分类|80|对象|150|主题|200|备注|400")
新增文件信息代码:
Dim r As Row = Tables("主窗口_table2").Current
If r IsNot Nothing Then
r.Locked = False
Dim id As WinForm.TextBox = e.Form.Controls("TextBox1")
Dim dw As WinForm.ComboBox = e.Form.Controls("ComboBox1")
Dim zz As WinForm.ComboBox = e.Form.Controls("ComboBox2")
Dim sj As WinForm.DateTimePicker = e.Form.Controls("DateTimePicker1")
Dim dx As WinForm.ComboBox = e.Form.Controls("ComboBox3")
Dim zt As WinForm.ComboBox = e.Form.Controls("ComboBox4")
Dim fl As WinForm.ComboBox = e.Form.Controls("ComboBox5")
Dim bz As WinForm.TextBox = e.Form.Controls("TextBox2")
r("ID")=id.Text
r("单位")=dw.Text
r("作者")=zz.text
r("时间")=sj.Value
r("对象")=dx.Text
r("主题")=zt.text
r("分类")=fl.text
r("备注")=bz.text
r.Save
r.Table.AllowEdit=False
End If
Tables("主窗口_table2").DataTable.Save
Tables("主窗口_table2").save
DataTables("文件信息").save
后台都没有数据写入
新增文件附件代码:
Dim r1 As Row = Tables("主窗口_table2").Current
If r1 IsNot Nothing Then
Dim BC As WinForm.Button = e.Form.Controls("保存信息")
BC.PerformClick
Dim dlg As New OpenFileDialog
dlg.Filter = "所有文件|*.*"
If dlg.ShowDialog =DialogResult.OK Then
Dim fl As String = dlg.FileName
Dim ifo As new FileInfo(fl)
Dim sj As Double
Dim Multi As String = (ifo.Length)
Dim Values() As String
Values = Multi.split(".")
sj=Values(0)
'If sj > 1073741824 Then '文件大于1gb
If sj > 524288000 Then '文件大于500mb
MessageBox.Show("文件"& Format(Values(0)/1024/1024,"0.00") &"MB" &"过大,只能上传小于500MB的文件!","温馨提示")
Else
MessageBox.Show("文件"& Format(Values(0)/1024/1024,"0.00") &"MB" &"小于500MB,支持上传!","温馨提示")
Dim r As Row = Tables("主窗口_table1").AddNew()
r("文件名") ="[" & format(Date.now,"yyyyMdHms") & "]" & FileSys.GetName(fl) '写入文件名
If fl.EndsWith(".jpg") OrElse fl.EndsWith(".png") OrElse fl.EndsWith(".bmp") OrElse fl.EndsWith(".ico") OrElse fl.EndsWith(".gif") Then
r("类型")="图片"
Else If fl.EndsWith(".mp4") OrElse fl.EndsWith(".wmv") OrElse fl.EndsWith(".mpg") OrElse fl.EndsWith(".avi") OrElse fl.EndsWith(".m2ts") OrElse fl.EndsWith(".mp3") Then
r("类型")="音视频"
Else If fl.EndsWith(".zip") OrElse fl.EndsWith(".rar") OrElse fl.EndsWith(".exe") Then 'fl.EndsWith(".txt") OrElse fl.EndsWith(".pdf") OrElse
r("类型")="文件"
Else
r("类型")="文档"
End If
r("id")=Tables("主窗口_table2").Current("ID")
r("登记时间")=Date.today
r("信息")=Tables("主窗口_table2").Current("分类")
r.Save '必须先保存
r.DataRow.SQLInsertFile("附件",fl) '插入文件
r.DataRow.SQLSetValue("CRC值", CRCCheckFile(fl)) '保存crc检验值
End If
End If
Tables("主窗口_table1").Filter="id= '" & Tables("主窗口_table2").Current("id") & "'"
Else
MessageBox.Show("请先【新增信息】记录,方可【上传文件】.","温馨提示!")
End If
[此贴子已经被作者于2021/7/3 11:41:36编辑过]