Merged PR 13298: Added just one approval back in after removing the method call from bug 239935
Added just one approval back in after removing the method call from bug 239935 Added IExcelDataReader support into MK Project Changed instructions below the ECN Title field to align with Windchill Related work items: #225480, #244087
This commit is contained in:
@ -1,104 +1,109 @@
|
||||
#if !NET8
|
||||
#if NET8
|
||||
|
||||
using ExcelDataReader;
|
||||
|
||||
#else
|
||||
|
||||
using Excel;
|
||||
|
||||
#endif
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace Fab2ApprovalSystem.Misc {
|
||||
namespace Fab2ApprovalSystem.Misc;
|
||||
|
||||
public class ExcelData {
|
||||
string _path;
|
||||
public ExcelData(string path) {
|
||||
_path = path;
|
||||
}
|
||||
public class ExcelData {
|
||||
|
||||
public IExcelDataReader getExcelReader() {
|
||||
// ExcelDataReader works with the binary Excel file, so it needs a FileStream
|
||||
// to get started. This is how we avoid dependencies on ACE or Interop:
|
||||
|
||||
FileStream stream = File.Open(_path, FileMode.Open, FileAccess.Read);
|
||||
// We return the interface, so that
|
||||
IExcelDataReader reader = null;
|
||||
|
||||
try {
|
||||
if (_path.EndsWith(".xls")) {
|
||||
reader = ExcelReaderFactory.CreateBinaryReader(stream);
|
||||
}
|
||||
if (_path.EndsWith(".xlsx")) {
|
||||
reader = ExcelReaderFactory.CreateOpenXmlReader(stream);
|
||||
}
|
||||
return reader;
|
||||
} catch (Exception) {
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ExcelLotInfo {
|
||||
public string LotNo { get; set; }
|
||||
public string LotDispo { get; set; }
|
||||
}
|
||||
|
||||
public IEnumerable<ExcelLotInfo> ReadData() {
|
||||
var r = new List<ExcelLotInfo>();
|
||||
var excelData = new ExcelData(_path);
|
||||
var lots = excelData.getData().ToList();
|
||||
|
||||
int lotDispoColumnIndex = -1;
|
||||
foreach (DataColumn col in lots[0].Table.Columns) {
|
||||
if (col.ColumnName.ToLower().Contains("dispo")) {
|
||||
lotDispoColumnIndex = col.Ordinal;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var row in lots) {
|
||||
string temValue = row[0].ToString();
|
||||
if (temValue.Trim().Length > 0 && temValue.Trim().Length <= 10) {
|
||||
r.Add(new ExcelLotInfo() {
|
||||
LotNo = row[0].ToString(),
|
||||
LotDispo = (lotDispoColumnIndex >= 0 ? row[lotDispoColumnIndex].ToString() : "")
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
public IEnumerable<string> ReadQDBFlagData() {
|
||||
List<string> s = new List<string>();
|
||||
// We return the interface, so that
|
||||
var excelData = new ExcelData(_path);
|
||||
var lotNos = excelData.getData();
|
||||
foreach (var row in lotNos) {
|
||||
string temValue = row[0].ToString();
|
||||
if (temValue.Trim().Length > 0 && temValue.Trim().Length == 9) {
|
||||
if (row[2].ToString().ToUpper() != "YES" && row[2].ToString().ToUpper() != "NO") {
|
||||
throw new Exception("Invalid data in the file");
|
||||
} else {
|
||||
s.Add(row[0].ToString() + "~" + row[1] + "~" + row[2]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public IEnumerable<DataRow> getData(bool firstRowIsColumnNames = true) {
|
||||
var reader = this.getExcelReader();
|
||||
reader.IsFirstRowAsColumnNames = firstRowIsColumnNames;
|
||||
var workSheet = reader.AsDataSet().Tables[0];
|
||||
var rows = from DataRow a in workSheet.Rows select a;
|
||||
return rows;
|
||||
|
||||
}
|
||||
private readonly string _Path;
|
||||
|
||||
public ExcelData(string path) {
|
||||
_Path = path;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
public IExcelDataReader getExcelReader() {
|
||||
FileStream stream = File.Open(_Path, FileMode.Open, FileAccess.Read);
|
||||
IExcelDataReader reader = null;
|
||||
try {
|
||||
if (_Path.EndsWith(".xls")) {
|
||||
reader = ExcelReaderFactory.CreateBinaryReader(stream);
|
||||
}
|
||||
if (_Path.EndsWith(".xlsx")) {
|
||||
reader = ExcelReaderFactory.CreateOpenXmlReader(stream);
|
||||
}
|
||||
return reader;
|
||||
} catch (Exception) {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public class ExcelLotInfo {
|
||||
public string? LotNo { get; set; }
|
||||
public string? LotDispo { get; set; }
|
||||
}
|
||||
|
||||
public IEnumerable<ExcelLotInfo> ReadData() {
|
||||
List<ExcelLotInfo> r = new();
|
||||
ExcelData excelData = new(_Path);
|
||||
List<DataRow> lots = excelData.getData().ToList();
|
||||
|
||||
int lotDispoColumnIndex = -1;
|
||||
foreach (DataColumn col in lots[0].Table.Columns) {
|
||||
if (col.ColumnName.ToLower().Contains("dispo")) {
|
||||
lotDispoColumnIndex = col.Ordinal;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (DataRow row in lots) {
|
||||
string temValue = row[0].ToString();
|
||||
if (temValue.Trim().Length > 0 && temValue.Trim().Length <= 10) {
|
||||
r.Add(new ExcelLotInfo() {
|
||||
LotNo = row[0].ToString(),
|
||||
LotDispo = (lotDispoColumnIndex >= 0 ? row[lotDispoColumnIndex].ToString() : "")
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
public IEnumerable<string> ReadQDBFlagData() {
|
||||
List<string> s = new();
|
||||
ExcelData excelData = new(_Path);
|
||||
IEnumerable<DataRow> lotNos = excelData.getData();
|
||||
foreach (DataRow row in lotNos) {
|
||||
string temValue = row[0].ToString();
|
||||
if (temValue.Trim().Length > 0 && temValue.Trim().Length == 9) {
|
||||
if (row[2].ToString().ToUpper() != "YES" && row[2].ToString().ToUpper() != "NO") {
|
||||
throw new Exception("Invalid data in the file");
|
||||
} else {
|
||||
s.Add(row[0].ToString() + "~" + row[1] + "~" + row[2]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
#if NET8
|
||||
|
||||
public IEnumerable<DataRow> getData(bool firstRowIsColumnNames = true) =>
|
||||
throw new NotImplementedException();
|
||||
|
||||
#else
|
||||
|
||||
public IEnumerable<DataRow> getData(bool firstRowIsColumnNames = true) {
|
||||
IExcelDataReader reader = getExcelReader();
|
||||
reader.IsFirstRowAsColumnNames = firstRowIsColumnNames;
|
||||
var workSheet = reader.AsDataSet().Tables[0];
|
||||
var rows = from DataRow a in workSheet.Rows select a;
|
||||
return rows;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
@ -117,8 +117,8 @@ public class LotDispositionHelper {
|
||||
public static void AttachSave(AppSettings appSettings, LotDispositionDMO lotDispositionDMO, int issueID, int userId, string fullFileName, Stream stream) {
|
||||
// Some browsers send file names with full path.
|
||||
// We are only interested in the file name.
|
||||
var fileName = Path.GetFileName(fullFileName);
|
||||
var physicalPath = Path.Combine(appSettings.AttachmentFolder + "LotDisposition", fileName);
|
||||
string fileName = Path.GetFileName(fullFileName);
|
||||
string physicalPath = Path.Combine(appSettings.AttachmentFolder + "LotDisposition", fileName);
|
||||
|
||||
using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) {
|
||||
stream.CopyTo(fileStream);
|
||||
@ -134,7 +134,7 @@ public class LotDispositionHelper {
|
||||
public static string ExcelLotOpen(LotDispositionDMO lotDispositionDMO, int issueID, string userIdentityName, string lotTempPipeLine, string fullFileName, Stream stream) {
|
||||
string physicalPath;
|
||||
|
||||
var fileExtension = Path.GetExtension(fullFileName);
|
||||
string fileExtension = Path.GetExtension(fullFileName);
|
||||
string fName = userIdentityName + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();
|
||||
|
||||
physicalPath = Path.Combine(lotTempPipeLine, fName + "." + fileExtension);
|
||||
@ -142,20 +142,18 @@ public class LotDispositionHelper {
|
||||
stream.CopyTo(fileStream);
|
||||
}
|
||||
|
||||
#if !NET8
|
||||
ExcelData x = new ExcelData(physicalPath);
|
||||
var lotNumbers = x.ReadData();
|
||||
ExcelData x = new (physicalPath);
|
||||
IEnumerable<ExcelData.ExcelLotInfo> lotNumbers = x.ReadData();
|
||||
|
||||
foreach (var lotInfo in lotNumbers) {
|
||||
Lot l = new Lot();
|
||||
l.LotNumber = lotInfo.LotNo;
|
||||
foreach (ExcelData.ExcelLotInfo lotInfo in lotNumbers) {
|
||||
Lot l = new();
|
||||
l.LotNumber = lotInfo.LotNo ?? string.Empty;
|
||||
l.IssueID = issueID;
|
||||
if (l.LotStatusOptionID == 0)
|
||||
l.LotStatusOption.LotStatusOptionID = (int)GlobalVars.LotStatusOption.Release;
|
||||
|
||||
lotDispositionDMO.InsertLot(l, true);
|
||||
}
|
||||
#endif
|
||||
|
||||
FileInfo f = new(physicalPath);
|
||||
if (f.Exists)
|
||||
|
@ -46,14 +46,12 @@ public class MRBHelper {
|
||||
stream.CopyTo(fileStream);
|
||||
}
|
||||
|
||||
#if !NET8
|
||||
ExcelData x = new ExcelData(physicalPath);
|
||||
ExcelData x = new(physicalPath);
|
||||
lotDataList = x.ReadQDBFlagData();
|
||||
|
||||
foreach (string lotData in lotDataList) {
|
||||
mrbDMO.InsertMRB_QDB_HoldFlag(guid, lotData, operation);
|
||||
}
|
||||
#endif
|
||||
|
||||
FileInfo f = new(physicalPath);
|
||||
if (f.Exists)
|
||||
@ -170,14 +168,12 @@ public class MRBHelper {
|
||||
stream.CopyTo(fileStream);
|
||||
}
|
||||
|
||||
#if !NET8
|
||||
ExcelData x = new ExcelData(physicalPath);
|
||||
ExcelData x = new(physicalPath);
|
||||
lotDataList = x.ReadQDBFlagData();
|
||||
|
||||
foreach (string lotData in lotDataList) {
|
||||
mrbDMO.InsertMRB_QDB_HoldFlag(guid, lotData, operation);
|
||||
}
|
||||
#endif
|
||||
|
||||
FileInfo f = new(physicalPath);
|
||||
if (f.Exists)
|
||||
@ -246,17 +242,16 @@ public class MRBHelper {
|
||||
string fName = userIdentityName + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();
|
||||
string physicalPath = Path.Combine(lotTempPipeLine, fName + "." + fileExtension);
|
||||
|
||||
#if !NET8
|
||||
IEnumerable<ExcelData.ExcelLotInfo> lotNumbers;
|
||||
|
||||
try {
|
||||
using (var fileStream = new FileStream(physicalPath, FileMode.Create, FileAccess.Write)) {
|
||||
using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) {
|
||||
stream.CopyTo(fileStream);
|
||||
}
|
||||
ExcelData x = new ExcelData(physicalPath);
|
||||
ExcelData x = new(physicalPath);
|
||||
lotNumbers = x.ReadData();
|
||||
} catch (Exception ex) {
|
||||
throw new Exception(String.Format("Invalid file format for {0}: {1}", fileName, ex.Message));
|
||||
throw new Exception(string.Format("Invalid file format for {0}: {1}", fileName, ex.Message));
|
||||
}
|
||||
|
||||
// Get Tool, Issue Start and End Date
|
||||
@ -266,7 +261,7 @@ public class MRBHelper {
|
||||
foreach (var lotInfo in lotNumbers) {
|
||||
if (lotInfo.LotDispo.Length == 1) {
|
||||
if (dispos.Count(d => d.DispositionType.Trim().ToUpper() == lotInfo.LotDispo.Trim().ToUpper()) == 0) {
|
||||
throw new Exception(String.Format("Invalid lot disposition {0} for lot no {1}",
|
||||
throw new Exception(string.Format("Invalid lot disposition {0} for lot no {1}",
|
||||
lotInfo.LotDispo, lotInfo.LotNo));
|
||||
}
|
||||
}
|
||||
@ -276,8 +271,8 @@ public class MRBHelper {
|
||||
if (!mrbInfo.ToolCSV.ToUpper().Equals("NA")) {
|
||||
foreach (var lotInfo in lotNumbers) {
|
||||
bool existingLotUpdated;
|
||||
Lot l = new Lot();
|
||||
l.LotNumber = lotInfo.LotNo;
|
||||
Lot l = new();
|
||||
l.LotNumber = lotInfo.LotNo ?? string.Empty;
|
||||
if (lotInfo.LotDispo.Length == 1) {
|
||||
l.DispoType = lotInfo.LotDispo[0];
|
||||
}
|
||||
@ -298,8 +293,8 @@ public class MRBHelper {
|
||||
// Only find the child Splits when a Tool or a list of Tools is provided
|
||||
foreach (var lotInfo in lotNumbers) {
|
||||
bool existingLotUpdated;
|
||||
Lot l = new Lot();
|
||||
l.LotNumber = lotInfo.LotNo;
|
||||
Lot l = new();
|
||||
l.LotNumber = lotInfo.LotNo ?? string.Empty;
|
||||
if (lotInfo.LotDispo.Length == 1) {
|
||||
l.DispoType = lotInfo.LotDispo[0];
|
||||
}
|
||||
@ -308,7 +303,6 @@ public class MRBHelper {
|
||||
mrbDMO.InsertLot(l, true, out existingLotUpdated);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
FileInfo f = new(physicalPath);
|
||||
if (f.Exists)
|
||||
|
Reference in New Issue
Block a user