以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 从APP post数据上来,保存,优化~ (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=121613) |
-- 作者:fubblyc -- 发布时间:2018/7/10 14:20:00 -- 从APP post数据上来,保存,优化~ 甜老师,我开发了一个APP,ajax post 数据到服务器,保存到表,会有一定的并发量。我目前的代码是可以用,但是有时候会出问题。你帮我看下看能怎么优化更好,是不是要做多线程的~ app提交数据的代码: api.ajax({ url: \'http://www.yijisoft.net:838899/pandian3.htm\', method: \'post\', dataType: \'text\', data: { values: { "username": username.value, //店铺编号 "dy": dy.value, //店铺编号 "txm": document.getElementById("txm").value, //这是一个多行文本,数据量挺大的,多的有上千行 } }, } FT服务器接收代码: Dim cmd As new SQLCommand cmd.C cmd.CommandTimeOut = 600 Dim wjm As String = Date.Today.year & Date.Today.Month & Date.Today.Day & Date.now.Hour & Date.now.Minute & Date.now.Second Dim wjlj As String = fl1 & "盘点\\" & wjm & ".txt" FileSys.CopyFile(fl1 & "wj\\pd.txt", wjlj ,True) FileSys.WriteAllText(wjlj , e.PostValues("txm"), True) Dim strs As String = FileSys.ReadAllText(wjlj,Encoding.Default) Dim h As String Dim m As String Dim kw As String Dim djbh As String //从txt合并数据到表格 strs = strs.Trim() Dim rs() As String = strs.Split("#") For i As Integer = 0 To rs.Length - 1 Dim cs() As String = rs(i).Split(",") If cs.Length = 6 Then Dim dr2 As DataRow = DataTables("明细表导入").Addnew() dr2("首列") = cs(0) dr2("门店名称") = e.PostValues("username") dr2("姓名") = e.PostValues("dy") dr2("库位") = cs(1) dr2("条码") = cs(3) dr2("数量") = cs(4) dr2("扫码时间") = cs(5) dr2("盘点日期") = Date.Today dr2("上传时间") = Date.now End If Next If Date.now.Hour < 10 Then h = "0" & Date.now.Hour Else h = Date.now.Hour End If If Date.now.Minute < 10 Then m = "0" & Date.now.Minute Else m = Date.now.Minute End If //从明细表导入 插入保存到 盘点明细表 ,其实表结构是一样的,当初这样设计是怕并发,多个用户同时上传,也不知道对不对~ For Each dr3 As DataRow In DataTables("明细表导入").DataRows dr3("单据编号") = dr3("库位") & h & m dr3("扫码时间条码") = dr3("库位") & h & m & dr3("扫码时间") & dr3("条码") //多做这一列是为了做是否重复上传的判断 cmd.CommandText =" insert into 盘点明细表(首列,门店名称,姓名,条码,扫码时间,数量,盘点日期,库位,上传时间,单据编号,扫码时间条码) values (\'" & dr3("首列") & "\' , \'" & dr3("门店名称") & "\' , \'" & dr3("姓名") & "\' , \'" & dr3("条码") & "\', \'" & dr3("扫码时间") & "\' , \'" & dr3("数量") & "\',\'" & dr3("盘点日期") & "\',\'" & dr3("库位") & "\',\'" & dr3("上传时间") & "\' ,\'" & dr3("单据编号") & "\' ,\'" & dr3("扫码时间条码") & "\' )" cmd.ExecuteNonQuery() dr3.Delete //插入一条,从明细表导入就删除一条 Next e.WriteString("服务器接收数据成功") [此贴子已经被作者于2018/7/10 14:21:57编辑过]
|
-- 作者:有点甜 -- 发布时间:2018/7/10 14:33:00 -- 参考
http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&Id=121537
用异步函数
http://www.foxtable.com/mobilehelp/scr/3269.htm
http://www.foxtable.com/mobilehelp/scr/277.htm
|