diff --git a/supplierBuildFile.aspx.cs b/supplierBuildFile.aspx.cs index 5beb50a..275fbd3 100644 --- a/supplierBuildFile.aspx.cs +++ b/supplierBuildFile.aspx.cs @@ -206,6 +206,14 @@ public partial class supplierBuildFile : System.Web.UI.Page upStatus = 2; updateSql += string.Format("insert into CE_ErpTradeLog(tid,orderstate,userid,operatetime,con) select ctid,{1},{2},getdate(),'{3}' from ce_erptradecell where ctid in ({0}) ;", string.Join(",", tids), (int)OrderState.下单完成, 0, "下载设计文件"); updateSql += string.Format("update ce_erptradecell set UpdateTime=getdate() where ctid in ({0}) ;", string.Join(",", tids)); + try + { + File.Delete(zipFilePath); + } + catch (Exception delEx) + { + writeLog("删除临时文件失败: " + delEx.Message); + } } } diff --git a/xhyOrderFile.aspx.cs b/xhyOrderFile.aspx.cs index a2ca853..d0647fb 100644 --- a/xhyOrderFile.aspx.cs +++ b/xhyOrderFile.aspx.cs @@ -87,6 +87,8 @@ public partial class xhyOrderFile : System.Web.UI.Page static string pCheckUrl = "http://test.new-only.com:54444/shopPlat/front/needlogin/erp/checkOrderParam.do"; static string userName = "18959023975"; static string passWord = "lt50510"; + + private static string tempUpPath = ConfigurationManager.AppSettings["curPath"] + "\\tempUp"; private void downloadMore() { if (running) @@ -115,26 +117,26 @@ public partial class xhyOrderFile : System.Web.UI.Page string ctid = dr["ctid"].ToString(); string post_url = dr["url"].ToString(); string id = dr["id"].ToString(); - + string filePath = ""; try { CeErpTradeCell itemData = CeErpTradeCell.GetByCtid(ctid); List files = new List(); List tids = new List(); - string filePath = ""; + string finishDesignTime = getDesignTime(itemData.FinishDesignTime); string df_name = upPath + "\\" + finishDesignTime + "\\" + formatMemo(itemData.seller_memo); string ext = getCanDownFile(df_name); if (string.IsNullOrEmpty(ext)) { - updateSql = string.Format("update CE_ErpXhyOrderInfo set message = '文件不存在!',type=2,sendtime = GETDATE() where id= {0};", id); + updateSql = string.Format("update CE_ErpXhyOrderInfo set message = '文件不存在!{1}',type=2,sendtime = GETDATE() where id= {0};", id, df_name); CeErpTradeLog.ExecuteNonQuery(updateSql); continue; } string fname = df_name + ext; string rname = formatMemo(itemData.seller_memo) + ext; - if (itemData.OrderState != 6) + if (itemData.OrderState != 5) { updateSql = string.Format("update CE_ErpXhyOrderInfo set message = '订单状态不正确!',type=2,sendtime = GETDATE() where id= {0};", id); CeErpTradeLog.ExecuteNonQuery(updateSql); @@ -185,6 +187,7 @@ public partial class xhyOrderFile : System.Web.UI.Page string url = pUrl + "?" + ToUrlParams(param); filePath = copyFile(getDesignDate(itemData.FinishDesignTime), "XHY", fname, rname); + // filePath = copyTempFile(fname, rname); writeLog("XHY复制文件!:" + fname); writeLog("XHY复制文件!地址:" + filePath); @@ -195,7 +198,16 @@ public partial class xhyOrderFile : System.Web.UI.Page postVars.Add(new StringContent(json), "json"); if (filePath != null) { - postVars.Add(new ByteArrayContent(File.ReadAllBytes(filePath)), "file", Path.GetFileName(filePath)); + // 使用 FileStream 打开文件,并包装为 StreamContent + var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); + var streamContent = new StreamContent(fileStream); + // 设置 Content-Disposition,需要手动指定文件名 + streamContent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("form-data") + { + Name = "file", + FileName = Path.GetFileName(filePath) + }; + postVars.Add(streamContent); } var request = new HttpRequestMessage { @@ -208,7 +220,7 @@ public partial class xhyOrderFile : System.Web.UI.Page }; request.Content = postVars; - using (var response = await client.SendAsync(request)) + using (var response = client.SendAsync(request).GetAwaiter().GetResult()) { string responseBody = await response.Content.ReadAsStringAsync(); @@ -218,7 +230,7 @@ public partial class xhyOrderFile : System.Web.UI.Page if (xhyResponse.code == 200) { updateSql = string.Format("update CE_ErpXhyOrderInfo set message = '{1}',type=1,sendtime = GETDATE() where id= {0};", id, xhyResponse.message); - updateSql += string.Format("update CE_ErpTradeCell set OrderState=6,IsVerifyToSupplier=0 where ctid ='{0}' and OrderState=5 and IsVerifyToSupplier=2;", itemData.ctid); + // updateSql += string.Format("update CE_ErpTradeCell set OrderState=6,IsHaveNewOrder=0 where ctid ='{0}' and OrderState=5 and IsHaveNewOrder=3;", itemData.ctid); } else { @@ -231,10 +243,24 @@ public partial class xhyOrderFile : System.Web.UI.Page } catch (Exception ex) { - writeLog("Xh复制文件出错!" + ex.Message); + writeLog("Xh复制文件出错!" + ex); updateSql = string.Format("update CE_ErpXhyOrderInfo set message = '复制文件出错!{1}' ,type=2,sendtime = GETDATE() where id= {0};", id, ex.Message); CeErpTradeLog.ExecuteNonQuery(updateSql); } + finally + { + if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath)) + { + try + { + // File.Delete(filePath); + } + catch (Exception delEx) + { + writeLog("删除临时文件失败: " + delEx.Message); + } + } + } } catch (Exception ex) @@ -305,6 +331,18 @@ public partial class xhyOrderFile : System.Web.UI.Page } return path + "\\" + rname; } + private string copyTempFile(string file, string rname) + { + + if (!Directory.Exists(tempUpPath)) Directory.CreateDirectory(tempUpPath); + string fname = Path.GetFileName(file); + File.Copy(file, tempUpPath + "\\" + rname, true); + if (!File.Exists(tempUpPath + "\\" + rname)) + { + File.Copy(file, tempUpPath + "\\" + rname, true); + } + return tempUpPath + "\\" + rname; + } private string getCopyPath(string date, string supplier, string zipName = "") {