diff --git a/插件库/Lskj.PubBomImportNew/DllBaseClass.cs b/插件库/Lskj.PubBomImportNew/DllBaseClass.cs
index 43afd75..2350115 100644
--- a/插件库/Lskj.PubBomImportNew/DllBaseClass.cs
+++ b/插件库/Lskj.PubBomImportNew/DllBaseClass.cs
@@ -72,6 +72,10 @@ namespace Lskj.PubBomImportNew
/// 终止条件
///
public string endRowHand = "";
+ ///
+ /// 附件节点
+ ///
+ public string speciesNo = "";
public DynamicBomImportNew(string[] args)
: base(args)
@@ -84,4 +88,8 @@ namespace Lskj.PubBomImportNew
{
primkey = args[6] + "";
}
- if (args.Length > 7 && !string.IsNull
\ No newline at end of file
+ if (args.Length > 7 && !string.IsNullOrWhiteSpace(args[7]))
+ {
+ keyvalue = args[7] + "";
+ }
+ if (args.Length > 8 && !string.IsNullOrWh
\ No newline at end of file
diff --git a/插件库/Lskj.PubBomImportNew/FrmMain2.cs b/插件库/Lskj.PubBomImportNew/FrmMain2.cs
index 3e48653..0689599 100644
--- a/插件库/Lskj.PubBomImportNew/FrmMain2.cs
+++ b/插件库/Lskj.PubBomImportNew/FrmMain2.cs
@@ -42,6 +42,11 @@ using Lskj.Control;
using NPOI.XSSF.UserModel;
using NPOI.HSSF.UserModel;
using DevExpress.XtraGrid.Views.Grid;
+using Newtonsoft.Json.Linq;
+using System.Web;
+using Lskj.Control.BrowserSetting;
+using System.Net;
+using Newtonsoft.Json;
namespace Lskj.PubBomImportNew
{
@@ -120,6 +125,10 @@ namespace Lskj.PubBomImportNew
///
public List ImportReturnValue = new List();
public int FirstRowIndex = 0;
+ ///
+ /// 选择的文件
+ ///
+ public string FilePath;
protected override void OnLoad(EventArgs e)
{
this.Opacity = 1;
@@ -557,7 +566,16 @@ namespace Lskj.PubBomImportNew
//if (mainKeyField != "")
// tmpRow[mainKeyField] = mainKeyValue;
-
+ if (!string.IsNullOrEmpty(this._primkey))
+ {
+ if (datatb.Columns.Contains(_primkey) && !string.IsNullOrWhiteSpace(_keyvalue))
+ {
+ if (string.IsNullOrEmpty(tmpRow[_primkey] + "") || (tmpRow[_keyvalue] + "").Equals("0"))
+ {
+ tmpRow[_primkey] = _keyvalue;
+ }
+ }
+ }
//if (this.concatenatedPrefix)
//{
@@ -643,10 +661,12 @@ namespace Lskj.PubBomImportNew
if (failed > 0)
gcMain.gridControl.DataSource = failedData;
-
-
-
LogUtil.WriteDebug(_menuCode, "导入数据", SysModel.MenuText, "数据导入,成功" + success.ToString() + "条,失败" + failed.ToString() + "条");
+ bool isUpload = UploadFileToAudit(FilePath, Model.keyvalue, Model.speciesNo, out string msg, out string fileId);
+ if (!isUpload)
+ {
+ MessageUtil.Show($"附件上传失败\r\n{msg}");
+ }
}
catch (Exception ex)
{
@@ -788,14 +808,33 @@ namespace Lskj.PubBomImportNew
if (result == DialogResult.OK)
{
//this.btnImport.Enabled = true;
- string fileName = dialog.FileName;
+ FilePath = dialog.FileName;
+ try
+ {
+ using (var stream = new FileStream(FilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
+ {
+ // 文件成功打开,说明没被占用
+ }
+ }
+ catch (Exception ex)
+ {
+ if (ex.Message.Contains("正由另一进程使用"))
+ {
+ MessageUtil.Show(ex.Message);
+ return;
+ }
+ else
+ {
+ throw;
+ }
+ }
string colFields = this.gcMain.GridView.Columns.ToString(',');
//this.gcMain.GridControl.DataSource = this._gridEx.GridView.ToExcelDataTable(fileName, colFields);
//bool isMultipleHeader = false;
//if (this._gridEx is BandedGridControlEx) isMultipleHeader = true;
//this.gcMain.GridView.Tag = isMultipleHeader;
- gcData = ToExcelDataTable(fileName, out int count, out int errorCount, true);
+ gcData = ToExcelDataTable(FilePath, out int count, out int errorCount, true);
@@ -856,7 +895,6 @@ namespace Lskj.PubBomImportNew
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
-
}
///
/// 说明:导入Excel
@@ -1834,4 +1872,137 @@ namespace Lskj.PubBomImportNew
}
return sourceTable;
}
-
\ No newline at end of file
+ ///
+ /// 获取数据源
+ ///
+ ///
+ private DataTable GetSourceTable(List unionColumnList)
+ {
+ DataTable sourceTable = new DataTable();
+ sourceTable.Columns.Add("excelFieldName");
+ sourceTable.Columns.Add("clientFieldName");
+ if (unionColumnList != null)
+ {
+ foreach (string unionColumn in unionColumnList)
+ {
+ string[] unionCilumnArray = unionColumn.Split('^');
+ if (unionCilumnArray.Length == 2)
+ {
+ DataRow dataRow = sourceTable.NewRow();
+ dataRow["excelFieldName"] = unionCilumnArray[0];
+ dataRow["clientFieldName"] = unionCilumnArray[1];
+ sourceTable.Rows.Add(dataRow);
+ }
+ }
+ }
+ return sourceTable;
+ }
+ ///
+ /// 上传文件
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ private bool UploadFileToAudit(string filePath, string idValue, string speciesno, out string msg, out string outFileId)
+ {
+ bool isUpload = false;
+ string File = filePath;
+ string returnMsg = "";
+ string fileId = "";
+ string postUrl = "";
+ try
+ {
+ //获取文件信息
+ FileInfo fileInfo = new FileInfo(File);
+ string suffix = Path.GetExtension(File);
+ string name = fileInfo.Name;
+ DateTime creationTime = fileInfo.CreationTime;
+ byte[] fileBytes = ConvertFileToBytes(File);
+ string fileStream = Convert.ToBase64String(fileBytes);
+ string userId = ERPInfo.Instance.UserId;
+ DateTime uploadTime = DateTime.Now;
+ //上传文件到服务器目录
+ postUrl = "{0}Api/FileUploadApi.ashx?moduleId={1}&idValue={2}&speciesno={8}&folder={3}&totsize={4}&position={5}&filename={6}&method={7}&confirm=1";
+ if (!string.IsNullOrEmpty(idValue))
+ {
+ string token = "";
+ string loginUrl = $"{SystemInfo.Instance.OAUrl}/Api/SysUserAjaxApi.ashx";
+ HttpTools.setting("application/x-www-form-urlencoded", null, null, HttpTools.Encode.UTF8);
+ Dictionary loginPmsDic = new Dictionary();
+ loginPmsDic.Add("method", "Login");
+ loginPmsDic.Add("username", HttpUtility.UrlEncode(ERPInfo.Instance.UserName));
+ loginPmsDic.Add("password", HttpUtility.UrlEncode(ERPInfo.Instance.InPassWord));
+ HttpWebResponse loginResponse = HttpTools.Post(loginUrl, "", loginPmsDic, HttpTools.Method.POST, out CookieCollection loginCookie, out string loginResult);
+ if (loginResponse != null && !string.IsNullOrEmpty(loginResult))
+ {
+ JObject jObject = JsonConvert.DeserializeObject(loginResult);
+ if (jObject.ContainsKey("success"))
+ {
+ if ((jObject["success"] + "").Equals("True"))
+ {
+ if (jObject.ContainsKey("token"))
+ {
+ token = jObject["token"] + "";
+ }
+ }
+ }
+ }
+ if (!string.IsNullOrEmpty(token))
+ {
+ postUrl = string.Format(postUrl, SystemInfo.Instance.OAUrl, Model.UnionModelCode, HttpUtility.UrlEncode(idValue), "file", fileBytes.Length, 0, HttpUtility.UrlEncode(name), "DoWebUpload", speciesno);
+ HttpTools.setting("application/x-www-form-urlencoded", null, null);
+ string result = "";
+ CookieCollection cookieCollection = null;
+ Dictionary headerDic = new Dictionary();
+ headerDic.Add("Authorization", $"Bearer {token}");
+ HttpWebResponse webResponse = HttpTools.Post(postUrl, fileStream, null, headerDic, HttpTools.Method.POST, out cookieCollection, out result);
+ if (webResponse != null && !string.IsNullOrEmpty(result))
+ {
+ JObject jsonObject = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(result);
+ string isSuccess = jsonObject["success"] + "";
+ if (isSuccess.Equals("True", StringComparison.CurrentCultureIgnoreCase))
+ {
+ if (jsonObject.ContainsKey("other"))
+ {
+ fileId = jsonObject["other"] + "";
+ //BaseImpl.ExecSqlValue($"update p_fm_filetab set isdisabled = 2 where fileid = '{fileId}'");
+ }
+ isUpload = true;
+ }
+ else
+ {
+ if (jsonObject.ContainsKey("msg"))
+ {
+ returnMsg = jsonObject["msg"] + "";
+ }
+ isUpload = false;
+ }
+ }
+ else
+ {
+ returnMsg = "上传请求失败";
+ isUpload = false;
+ }
+ }
+ else
+ {
+ returnMsg = loginResult;
+ isUpload = false;
+ }
+ }
+ else
+ {
+ returnMsg = "上传节点值不能为空";
+ isUpload = false;
+ }
+ }
+ catch (Exception ex)
+ {
+ returnMsg = ex.Message;
+ throw new Exception($"文件{Path.GetFileName(filePath)}上传失败\r\n{ex.Message}");
+ isUpload = false;
+ }
+ msg = retur
\ No newline at end of file