SVN-Revision: r742
This commit is contained in:
wyf
2025-06-15 04:29:08 +00:00
parent 702d945d5c
commit 82b1254ad8
2 changed files with 188 additions and 9 deletions
@@ -72,6 +72,10 @@ namespace Lskj.PubBomImportNew
/// 终止条件 /// 终止条件
/// </summary> /// </summary>
public string endRowHand = ""; public string endRowHand = "";
/// <summary>
/// 附件节点
/// </summary>
public string speciesNo = "";
public DynamicBomImportNew(string[] args) public DynamicBomImportNew(string[] args)
: base(args) : base(args)
@@ -84,4 +88,8 @@ namespace Lskj.PubBomImportNew
{ {
primkey = args[6] + ""; primkey = args[6] + "";
} }
if (args.Length > 7 && !string.IsNull if (args.Length > 7 && !string.IsNullOrWhiteSpace(args[7]))
{
keyvalue = args[7] + "";
}
if (args.Length > 8 && !string.IsNullOrWh
+179 -8
View File
@@ -42,6 +42,11 @@ using Lskj.Control;
using NPOI.XSSF.UserModel; using NPOI.XSSF.UserModel;
using NPOI.HSSF.UserModel; using NPOI.HSSF.UserModel;
using DevExpress.XtraGrid.Views.Grid; 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 namespace Lskj.PubBomImportNew
{ {
@@ -120,6 +125,10 @@ namespace Lskj.PubBomImportNew
/// </summary> /// </summary>
public List<string> ImportReturnValue = new List<string>(); public List<string> ImportReturnValue = new List<string>();
public int FirstRowIndex = 0; public int FirstRowIndex = 0;
/// <summary>
/// 选择的文件
/// </summary>
public string FilePath;
protected override void OnLoad(EventArgs e) protected override void OnLoad(EventArgs e)
{ {
this.Opacity = 1; this.Opacity = 1;
@@ -557,7 +566,16 @@ namespace Lskj.PubBomImportNew
//if (mainKeyField != "") //if (mainKeyField != "")
// tmpRow[mainKeyField] = mainKeyValue; // 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) //if (this.concatenatedPrefix)
//{ //{
@@ -643,10 +661,12 @@ namespace Lskj.PubBomImportNew
if (failed > 0) if (failed > 0)
gcMain.gridControl.DataSource = failedData; gcMain.gridControl.DataSource = failedData;
LogUtil.WriteDebug(_menuCode, "导入数据", SysModel.MenuText, "数据导入,成功" + success.ToString() + "条,失败" + failed.ToString() + "条"); 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) catch (Exception ex)
{ {
@@ -788,14 +808,33 @@ namespace Lskj.PubBomImportNew
if (result == DialogResult.OK) if (result == DialogResult.OK)
{ {
//this.btnImport.Enabled = true; //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(','); string colFields = this.gcMain.GridView.Columns.ToString(',');
//this.gcMain.GridControl.DataSource = this._gridEx.GridView.ToExcelDataTable(fileName, colFields); //this.gcMain.GridControl.DataSource = this._gridEx.GridView.ToExcelDataTable(fileName, colFields);
//bool isMultipleHeader = false; //bool isMultipleHeader = false;
//if (this._gridEx is BandedGridControlEx) isMultipleHeader = true; //if (this._gridEx is BandedGridControlEx) isMultipleHeader = true;
//this.gcMain.GridView.Tag = isMultipleHeader; //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); string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message); MessageUtil.Show(Message, ex.Message);
} }
} }
/// <summary> /// <summary>
/// <para>说明:导入Excel</para> /// <para>说明:导入Excel</para>
@@ -1834,4 +1872,137 @@ namespace Lskj.PubBomImportNew
} }
return sourceTable; return sourceTable;
} }
/// <summary>
/// 获取数据源
/// </summary>
/// <returns></returns>
private DataTable GetSourceTable(List<string> 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;
}
/// <summary>
/// 上传文件
/// </summary>
/// <param name="filePath"></param>
/// <param name="idValue"></param>
/// <param name="speciesno"></param>
/// <param name="msg"></param>
/// <param name="outFileId"></param>
/// <returns></returns>
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<string, string> loginPmsDic = new Dictionary<string, string>();
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<JObject>(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<string, string> headerDic = new Dictionary<string, string>();
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