|
|
@ -8,6 +8,9 @@ using Microsoft.EntityFrameworkCore; |
|
|
|
using AMESCoreStudio.WebApi.Models.AMES; |
|
|
|
using AMESCoreStudio.WebApi.DTO.AMES; |
|
|
|
using AMESCoreStudio.CommonTools.Result; |
|
|
|
using System.Data.Common; |
|
|
|
using System.Data; |
|
|
|
using System.Dynamic; |
|
|
|
|
|
|
|
namespace AMESCoreStudio.WebApi.Controllers.AMES |
|
|
|
{ |
|
|
@ -221,6 +224,42 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
///
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="reader"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public static DataTable DataReaderToDataTable(DbDataReader reader) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
DataTable dt = new DataTable(); |
|
|
|
int fieldCount = reader.FieldCount; |
|
|
|
for (int fieldIndex = 0; fieldIndex < fieldCount; ++fieldIndex) |
|
|
|
{ |
|
|
|
dt.Columns.Add(reader.GetName(fieldIndex), reader.GetFieldType(fieldIndex)); |
|
|
|
} |
|
|
|
|
|
|
|
dt.BeginLoadData(); |
|
|
|
|
|
|
|
object[] rowValues = new object[fieldCount]; |
|
|
|
while (reader.Read()) |
|
|
|
{ |
|
|
|
reader.GetValues(rowValues); |
|
|
|
dt.LoadDataRow(rowValues, true); |
|
|
|
} |
|
|
|
reader.Close(); |
|
|
|
dt.EndLoadData(); |
|
|
|
|
|
|
|
return dt; |
|
|
|
|
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
throw new Exception("DataReader Convert DataTable Error!", ex); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 查詢工單KeyParts資料QRS013
|
|
|
|
/// </summary>
|
|
|
@ -236,6 +275,94 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES |
|
|
|
ResultModel<dynamic> result = new ResultModel<dynamic>(); |
|
|
|
Helper helper = new Helper(_context); |
|
|
|
|
|
|
|
var wip_kp = await _context.WipKps.FromSqlRaw("SELECT * FROM JHAMES.WIP_KP WHERE WIP_NO = '" + wipNO + "' ORDER BY KP_NO").ToListAsync(); |
|
|
|
|
|
|
|
string sql = @" select c.wip_no as WipNo,b.barcode_no as BarcodeNo,b.extra_barcode_no as ExtraBarcodeNo,d.model_no as ModelNO,d.item_no as ItemNO"; |
|
|
|
string sql1 = "", sql2 = "", sql3 = ""; |
|
|
|
if (wip_kp.Count > 0) |
|
|
|
{ |
|
|
|
for (int i = 0; i < wip_kp.Count; i++) |
|
|
|
{ |
|
|
|
sql1 = sql1 + ",k" + (i + 1).ToString() + ".part_no as KP_" + wip_kp[i].KpNo; |
|
|
|
sql2 = sql2 + ",(select barcode_id,part_no from jhames.barcode_item where item_no = '" + wip_kp[i].KpNo + "') k" + (i + 1).ToString(); |
|
|
|
sql3 = sql3 + " and b.barcode_id = k" + (i + 1).ToString() + ".barcode_id"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
sql = sql + sql1; |
|
|
|
sql = sql + " from jhames.barcode_info b,jhames.wip_info c,jhames.wip_att d"; |
|
|
|
sql = sql + sql2; |
|
|
|
|
|
|
|
sql = sql + " where b.wip_id = c.wip_id and c.wip_no = d.wip_no"; |
|
|
|
|
|
|
|
sql = sql + sql3; |
|
|
|
|
|
|
|
sql = sql + " and c.wip_no = '" + wipNO + "'"; |
|
|
|
|
|
|
|
string tempName = string.Empty; |
|
|
|
DbConnection conn = _context.Database.GetDbConnection(); |
|
|
|
if (conn.State != System.Data.ConnectionState.Open) |
|
|
|
{ |
|
|
|
await conn.OpenAsync(); |
|
|
|
} |
|
|
|
|
|
|
|
using (var cmd = conn.CreateCommand()) |
|
|
|
{ |
|
|
|
cmd.CommandText = sql; |
|
|
|
|
|
|
|
using (var reader = await cmd.ExecuteReaderAsync()) |
|
|
|
{ |
|
|
|
if (reader.HasRows) |
|
|
|
{ |
|
|
|
List<dynamic> list = new List<dynamic>(); |
|
|
|
DataTable table = new DataTable(); |
|
|
|
|
|
|
|
table = DataReaderToDataTable(reader); |
|
|
|
|
|
|
|
foreach (DataRow row in table.Rows) |
|
|
|
{ |
|
|
|
dynamic dyn = new ExpandoObject(); |
|
|
|
list.Add(dyn); |
|
|
|
foreach (DataColumn column in table.Columns) |
|
|
|
{ |
|
|
|
var dic = (IDictionary<string, object>)dyn; |
|
|
|
dic[column.ColumnName] = row[column]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
result.DataTotal = list.Count(); |
|
|
|
result.Data = list; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (result == null) |
|
|
|
{ |
|
|
|
result.Msg = "查無資料"; |
|
|
|
result.Success = false; |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
result.Success = true; |
|
|
|
result.Msg = "OK"; |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 查詢工單KeyParts資料QRS013
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="wipNO"></param>
|
|
|
|
/// <param name="factoryNo"></param>
|
|
|
|
/// <param name="page"></param>
|
|
|
|
/// <param name="limit"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[Route("[action]")]
|
|
|
|
[HttpGet] |
|
|
|
public async Task<ResultModel<dynamic>> GetWipInfo4QRS013Old(string wipNO, string factoryNo, int page, int limit) |
|
|
|
{ |
|
|
|
ResultModel<dynamic> result = new ResultModel<dynamic>(); |
|
|
|
Helper helper = new Helper(_context); |
|
|
|
|
|
|
|
var q = from q1 in _context.WipInfos |
|
|
|
join q2 in _context.BarcodeInfoes on q1.WipID equals q2.WipID |
|
|
|
join q3 in _context.BarcodeItems on q2.BarcodeID equals q3.BarcodeID into item_data |
|
|
|