CMFly.Web.Operation.dll 我们用vs2005这个版本生成出来
首先先是搞代码,包的调用以后再说可以看一下
Namespace WanH
Public Class RQHandle
Inherits System.Web.UI.Page
'==================声明开始==================
'以下代码在各个页面中统一调用,请不要修改
Private mo_logon As TApplogon = Nothing '登陆对象
'==================声明结束==================
#Region " Web 窗体设计器生成的代码 "
'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
'注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Load
'以下代码在各个页面中统一调用,请不要修改
On Error GoTo l_Err
'该函数参数为本窗口对象
mo_logon = New TApplogon(Me,"",TApplogon.enumApplogonFlag.logonOnModuleAdmin,True,TApplogon.enumRecordType.NotRecordLog,"")
'==================声明结束==================
'在此处放置初始化页的用户代码
Dim lo_XML As New System.Xml.XmlDocument,ls_Result As String
lo_XML.Load(Request.InputStream)
Select Case lo_XML.DocumentElement.GetAttribute("Handle")
Case "ExcelInRQG0050" '钢板信息
ls_Result = ExcelInRQG0050(lo_XML.DocumentElement)
Case "ExcelInRQG0060" '焊缝信息
ls_Result = ExcelInRQG0060(lo_XML.DocumentElement)
End Select
'记录日志
mo_logon.logon.SysError.RecordLog(TypeName(Me),"Handle:" & lo_XML.DocumentElement.GetAttribute("Handle"))
lo_XML = Nothing
'==================声明开始==================
'以下代码在各个页面中统一调用,请不要修改
mo_logon.ClearUp()
mo_logon = Nothing
Response.Write(ls_Result)
Return
l_Err:
If mo_logon Is Nothing Then mo_logon = New TApplogon(Me,CShort(0))
mo_logon.ErrorMsgToWeb(Err.Number,Err.Description,TypeName(Me) & "::Page_Load() Event")
mo_logon = Nothing
'==================声明结束==================
End Sub
'执行时间很长的大行的sql语句的时候调用,比如存储过程
Private Function UpdateBigDate(ByVal ao_Node As System.Xml.XmlElement) As String
On Error GoTo ls_err
Dim ls_sql As String = ao_Node.GetAttribute("ls_sql")
Dim ls_Connet As String = ao_Node.GetAttribute("ls_Connet")
Dim lo_sqlHandle As TsqlHandle
Dim lo_sqlComm As New sqlClient.sqlCommand
If ls_Connet = "" Then
lo_sqlHandle = mo_logon.logon.AppsqlHandle
Else
lo_sqlHandle = mo_logon.logon.GetOthersqlHandle(ls_Connet)
End If
lo_sqlComm.CommandTimeout = 1000
lo_sqlComm.Connection = lo_sqlHandle.Connection
lo_sqlComm.CommandText = ls_sql
lo_sqlComm.ExecuteNonQuery()
lo_sqlComm.Dispose()
lo_sqlComm = Nothing
Return "<Root Value=""1"" ResultValue=""成功"" />"
ls_err:
lo_sqlComm.Dispose()
lo_sqlComm = Nothing
Return "<Root Value=""0"" ResultValue=""失败,请与管理员联系"" />"
End Function
'钢板信息导入
Private Function ExcelInRQG0050(ByVal ao_Node As System.Xml.XmlElement) As String
On Error GoTo ls_err
'基础定义
Dim ls_sql As String,lo_sqlHandle As TsqlHandle
Dim ls_File As String = mo_logon.logon.GetParameterValue("NET_TEMP_DATA_PATH") & ao_Node.GetAttribute("ExcelFile")
Dim lo_Excel As New Excel.Application
Dim lo_Workbook As Excel.Workbook = lo_Excel.Workbooks.Open(ls_File)
Dim lo_sheet As Excel.Worksheet = lo_Workbook.Sheets(1)
lo_sqlHandle = mo_logon.logon.GetOthersqlHandle("CQG_DATACOLL")
'需求定义
Dim ls_TypeID As Integer,ls_PBNum As String,ls_MBNum As String,ls_MBLNum As String,ls_Len As Double,ls_WI As Double,ls_Hou As Double
Dim ls_FJBack As String,ls_CreateUserID As Integer,ls_CreateUserName As String,ls_CreateDate As DateTime
Dim ls_ParentID As Integer,ls_IsCheck As String,ls_JLRemake As String
Dim ls_QualityInspector As String,ls_YZRemake As String
Dim ls_Num As Integer,ls_sql1 As String,ls_Num01 As Integer,ls_Value01 As String,ls_PID As String
ls_ParentID = ao_Node.GetAttribute("ParentID")
If lo_sheet.Cells(2,1).value = "钢板编号" And lo_sheet.Cells(2,2).value = "钢板位置" And lo_sheet.Cells(2,3).value = "母板炉批号" And lo_sheet.Cells(2,4).value = "母板编号" And lo_sheet.Cells(2,5).value = "长" And lo_sheet.Cells(2,6).value = "宽" And lo_sheet.Cells(2,7).value = "板厚" And lo_sheet.Cells(2,8).value = "复检记录" Then ls_PID = "1"
'随机查看是否为正确模板
If ls_PID <> "1" Then
Call ExitExcelIn(lo_Excel,lo_Workbook,lo_sheet,ls_File)
Return "<Root Value=""0"" ResultValue=""导入失败,请确认导入模板,谢谢!"" />"
Exit Function
End If
'这里就是导入了
ls_Num = 0
For i As Integer = 3 To lo_sheet.Rows.Count
If IsDBNull(lo_sheet.Cells(i,1).value) Or CStr(lo_sheet.Cells(i,1).value) = "" Then
'============出现空的=============
ls_Num = ls_Num + 1
If ls_Num > 2 Then
Exit For
End If
Else
'列值
'钢板编号不为空
If CStr(lo_sheet.Cells(i,1).value) = "" Then
Call gcExcel(lo_Excel,lo_sheet)
Return "<Root Value=""0"" ResultValue=""导入第" & i & "行时失败,钢板编号不能为空!"" />"
Exit Function
Else
ls_PBNum = CStr(lo_sheet.Cells(i,1).value)
End If
'钢板位置不为空
If CStr(lo_sheet.Cells(i,2).value) = "" Then
Call gcExcel(lo_Excel,钢板位置不能为空!"" />"
Exit Function
Else
Select Case Replace(Replace(lo_sheet.Cells(i,2).value," ","")," ","")
Case "外罐底板"
ls_TypeID = 1
Case "外罐壁板"
ls_TypeID = 2
Case "穹顶"
ls_TypeID = 3
Case "内罐底板"
ls_TypeID = 4
Case "内罐壁板"
ls_TypeID = 5
Case "内罐浮顶"
ls_TypeID = 6
End Select
End If
ls_MBNum = CStr(lo_sheet.Cells(i,3).value)
ls_MBLNum = CStr(lo_sheet.Cells(i,4).value)
ls_Len = CStr(lo_sheet.Cells(i,5).value)
ls_WI = CStr(lo_sheet.Cells(i,6).value)
ls_Hou = CStr(lo_sheet.Cells(i,7).value)
ls_FJBack = CStr(lo_sheet.Cells(i,8).value)
ls_CreateUserID = mo_logon.logon.UserID
ls_CreateUserName = mo_logon.logon.UserName
ls_IsCheck = ""
ls_JLRemake = " "
ls_QualityInspector = " "
ls_YZRemake = " "
'数据重复
ls_sql1 = "Select Count(*) from G0050 where PBNum ='" & ls_PBNum & "' and TypeID = " & ls_TypeID & ""
ls_Num01 = lo_sqlHandle.GetValueBysql(ls_sql1)
If ls_Num01 > 0 Then
ls_Value01 = ls_Value01 & "---第" & i & "行数据重复,请检查" & Chr(13) + Chr(10)
Return "<Root Value=""1"" ResultValue=""导入失败" & ls_Value01 & """ />"
Exit Function
End If
'开始插入
ls_sql = "INSERT INTO G0050 (PBNum,TypeID,MBNum,MBLNum,Len,WI,Hou,FJBack,IsCheck,JLRemake,QualityInspector,YZRemake,ParentID,CreateUserID,CreateUserName,CreateDate) values ("
ls_sql = ls_sql & "'" & ls_PBNum & "'," & ls_TypeID & ",'" & ls_MBNum & "','" & ls_MBLNum & "'," & ls_Len & "," & ls_WI & "," & ls_Hou & ",'" & ls_FJBack & "','" & ls_IsCheck & "','" & ls_JLRemake & "','" & ls_QualityInspector & "','" & ls_YZRemake & "','" & ls_ParentID & "','" & ls_CreateUserID & "','" & ls_CreateUserName & "'," & "GetDate())"
Call lo_sqlHandle.Updatesql(ls_sql)
'sql调试的时候拷贝出来检查他的准确性@H_403_210@
End If
Next
'退出Excel,并且释放调用的COM资源
lo_Excel.DisplayAlerts = False
lo_Workbook.Save()
lo_Excel.DisplayAlerts = True
lo_Workbook.Close()
lo_Excel.Quit()
ReleaseComObject(lo_sheet)
ReleaseComObject(lo_Workbook)
ReleaseComObject(lo_Excel)
lo_Excel = Nothing : lo_Workbook = Nothing : lo_sheet = Nothing
'删除上传的Excel
Call System.IO.File.Delete(ls_File)
System.GC.Collect()
Return "<Root Value=""1"" ResultValue=""导入成功"" />"
ls_err:
lo_Excel.DisplayAlerts = False
lo_Workbook.Save()
lo_Excel.DisplayAlerts = True
lo_Workbook.Close()
lo_Excel.Quit()
ReleaseComObject(lo_sheet)
ReleaseComObject(lo_Workbook)
ReleaseComObject(lo_Excel)
lo_Excel = Nothing : lo_Workbook = Nothing : lo_sheet = Nothing
'删除上传的Excel
Call System.IO.File.Delete(ls_File)
System.GC.Collect()
Return "<Root Value=""0"" ResultValue=err.Description />"
End Function
' 当然最重要的是excel的那些东西,不经常接触,比较陌生
'退出Excel,并且释放调用的COM资源
Private Function ExitExcelIn(ByVal lo_Excel As Excel.Application,ByVal lo_Workbook As Excel.Workbook,ByVal lo_sheet As Excel.Worksheet,ByVal ls_File As String) As String
lo_Excel.DisplayAlerts = False
lo_Workbook.Save()
lo_Excel.DisplayAlerts = True
lo_Workbook.Close()
lo_Excel.Quit()
ReleaseComObject(lo_sheet)
ReleaseComObject(lo_Workbook)
ReleaseComObject(lo_Excel)
lo_Excel = Nothing : lo_Workbook = Nothing : lo_sheet = Nothing
'删除上传的Excel
Call System.IO.File.Delete(ls_File)
System.GC.Collect()
End Function
其实东西就是这些了
附件是代码
这个东西就这样了,不要深究
原文链接:https://www.f2er.com/vb/257264.html