Browse Source

PTD003 作業查詢 優化 & MS DbConnection 釋放

PTD
vick_wang419@hotmail.com.tw 1 year ago
parent
commit
de258494a8
  1. 8
      AMESCoreStudio.Web/Controllers/PTDController.cs
  2. 4
      AMESCoreStudio.Web/Views/PTD/PTD003.cshtml
  3. 405
      AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs

8
AMESCoreStudio.Web/Controllers/PTDController.cs

@ -347,16 +347,16 @@ namespace AMESCoreStudio.Web.Controllers
SelectListItem.Add(new SelectListItem(RecordType.ID.ToString() + "-" + RecordType.TypeName, RecordType.ID.ToString())); SelectListItem.Add(new SelectListItem(RecordType.ID.ToString() + "-" + RecordType.TypeName, RecordType.ID.ToString()));
} }
ViewBag.RecordType = SelectListItem; ViewBag.RecordType = SelectListItem;
ViewBag.StartDate = System.DateTime.Now.AddDays(-7).ToString("yyyy/MM/dd"); //ViewBag.StartDate = System.DateTime.Now.AddDays(-7).ToString("yyyy/MM/dd");
ViewBag.EndDate = System.DateTime.Now.ToString("yyyy/MM/dd"); //ViewBag.EndDate = System.DateTime.Now.ToString("yyyy/MM/dd");
ViewBag.WorkCenter = "TWM0"; ViewBag.WorkCenter = "TWM0";
return View(); return View();
} }
public async Task<IActionResult> PTD003QueryAsync(string recordType, string recordNumber, string lineNo, string materialNo, string shippingSN, string dateStart, string dateEnd) public async Task<IActionResult> PTD003QueryAsync(string recordType, string recordNumber, string lineNo, string materialNo, string shippingSN, string dateStart, string dateEnd)
{ {
if (recordNumber == null || recordNumber == "") //if (recordNumber == null || recordNumber == "")
return Json(new Table() { count = 0, data = null }); // return Json(new Table() { count = 0, data = null });
var result = await _pcsApi.GetData4PTD003(recordType, recordNumber, lineNo, materialNo, shippingSN, dateStart, dateEnd); var result = await _pcsApi.GetData4PTD003(recordType, recordNumber, lineNo, materialNo, shippingSN, dateStart, dateEnd);
if (result.DataTotal > 0) if (result.DataTotal > 0)

4
AMESCoreStudio.Web/Views/PTD/PTD003.cshtml

@ -277,10 +277,10 @@
sort: true sort: true
}, },
{ {
field: 'createDate', field: 'recordDate',
title: '交易日', title: '交易日',
width: 120, width: 120,
templet: '<div>{{ layui.util.toDateString(d.createDate, "yyyy/MM/dd") }}</div>' templet: '<div>{{ layui.util.toDateString(d.recorddate, "yyyy/MM/dd") }}</div>'
}] }]
]; ];

405
AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs

@ -2544,6 +2544,12 @@ FROM [SFIS].[dbo].[ZPDKeyPart] B WHERE B.[IsActive] = 1 AND B.[ProductSN] = (S
} }
} }
if (connPTD.State == ConnectionState.Open)
{
connPTD.Close();
connPTD.Dispose();
}
List<dynamic> list = new List<dynamic>(); List<dynamic> list = new List<dynamic>();
foreach (DataRow row in dtZDNDetail.Rows) foreach (DataRow row in dtZDNDetail.Rows)
{ {
@ -2937,6 +2943,13 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
} }
} }
if (connPTD.State == ConnectionState.Open)
{
connPTD.Close();
connPTD.Dispose();
}
if (dtBarcode.Rows.Count > 0) if (dtBarcode.Rows.Count > 0)
{ {
//整理欄位 //整理欄位
@ -2986,6 +2999,15 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
ResultModel<dynamic> result = new ResultModel<dynamic>(); ResultModel<dynamic> result = new ResultModel<dynamic>();
List<string> SNList = new List<string>(); List<string> SNList = new List<string>();
Collection<string> colSQL = new Collection<string>(); Collection<string> colSQL = new Collection<string>();
//安勤連線
PTDContext _ptd_context = new PTDContext();
DbConnection connPTD = _ptd_context.Database.GetDbConnection();
if (connPTD.State != ConnectionState.Open)
{
await connPTD.OpenAsync();
}
try try
{ {
string strSQL = ""; string strSQL = "";
@ -3014,14 +3036,6 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
throw new Exception("RMANo 不得為空!"); throw new Exception("RMANo 不得為空!");
} }
//安勤連線
PTDContext _ptd_context = new PTDContext();
DbConnection connPTD = _ptd_context.Database.GetDbConnection();
if (connPTD.State != ConnectionState.Open)
{
await connPTD.OpenAsync();
}
//Mail Body Html //Mail Body Html
StringBuilder htmlTable = new StringBuilder(); StringBuilder htmlTable = new StringBuilder();
htmlTable.AppendLine("<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">"); htmlTable.AppendLine("<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">");
@ -3169,14 +3183,21 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
result.Success = false; result.Success = false;
result.Msg = ex.Message; result.Msg = ex.Message;
} }
finally
{
if (connPTD.State == ConnectionState.Open)
{
connPTD.Close();
connPTD.Dispose();
}
}
return result; return result;
} }
private bool CheckShipQty(string recordNumber, string lineNo, int addQty) private bool CheckShipQty(string recordNumber, string lineNo, int addQty)
{ {
ResultModel<dynamic> result = new ResultModel<dynamic>(); ResultModel<dynamic> result = new ResultModel<dynamic>();
try
{
//安勤連線 //安勤連線
PTDContext _ptd_context = new PTDContext(); PTDContext _ptd_context = new PTDContext();
DbConnection connPTD = _ptd_context.Database.GetDbConnection(); DbConnection connPTD = _ptd_context.Database.GetDbConnection();
@ -3184,6 +3205,9 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{ {
connPTD.Open(); connPTD.Open();
} }
try
{
//查剩餘數 //查剩餘數
string strSQL = $@"select ShipQty - string strSQL = $@"select ShipQty -
(SELECT count(1) (SELECT count(1)
@ -3209,13 +3233,19 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{ {
throw ex; throw ex;
} }
finally
{
if (connPTD.State == ConnectionState.Open)
{
connPTD.Close();
connPTD.Dispose();
}
}
return true; return true;
} }
private bool CheckFlowRules(string recordType, string serialNumber) private bool CheckFlowRules(string recordType, string serialNumber)
{ {
ResultModel<dynamic> result = new ResultModel<dynamic>(); ResultModel<dynamic> result = new ResultModel<dynamic>();
try
{
//安勤連線 //安勤連線
PTDContext _ptd_context = new PTDContext(); PTDContext _ptd_context = new PTDContext();
DbConnection connPTD = _ptd_context.Database.GetDbConnection(); DbConnection connPTD = _ptd_context.Database.GetDbConnection();
@ -3223,6 +3253,8 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{ {
connPTD.Open(); connPTD.Open();
} }
try
{
//用ZProductTrans最新RecordType 檢查PTDFlowRules邏輯 //用ZProductTrans最新RecordType 檢查PTDFlowRules邏輯
bool bolChkFlow = false; bool bolChkFlow = false;
string strSQL = $@"Select [FormID] FROM [SFIS_PTD].[dbo].[PTDFlowRules] string strSQL = $@"Select [FormID] FROM [SFIS_PTD].[dbo].[PTDFlowRules]
@ -3275,6 +3307,14 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{ {
throw ex; throw ex;
} }
finally
{
if (connPTD.State == ConnectionState.Open)
{
connPTD.Close();
connPTD.Dispose();
}
}
return true; return true;
} }
@ -3396,8 +3436,6 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
[Route("[action]")] [Route("[action]")]
[HttpGet] [HttpGet]
public async Task<List<RecordTypeInfo>> GetRecordTypes() public async Task<List<RecordTypeInfo>> GetRecordTypes()
{
try
{ {
//安勤連線 //安勤連線
PTDContext _ptd_context = new PTDContext(); PTDContext _ptd_context = new PTDContext();
@ -3406,6 +3444,8 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{ {
await connPTD.OpenAsync(); await connPTD.OpenAsync();
} }
try
{
string strSQL = $@"select a.RecordTypeID,(select TypeName from SFIS_PTD.dbo.RecordTypeInfo where ID = a.RecordTypeID ) as TypeName string strSQL = $@"select a.RecordTypeID,(select TypeName from SFIS_PTD.dbo.RecordTypeInfo where ID = a.RecordTypeID ) as TypeName
from SFIS_PTD.dbo.ZProductTrans a group by a.RecordTypeID"; from SFIS_PTD.dbo.ZProductTrans a group by a.RecordTypeID";
DataTable dtRecordTypes = new DataTable(); DataTable dtRecordTypes = new DataTable();
@ -3437,13 +3477,19 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{ {
throw e; throw e;
} }
finally
{
if (connPTD.State == ConnectionState.Open)
{
connPTD.Close();
connPTD.Dispose();
}
}
} }
[Route("[action]")] [Route("[action]")]
[HttpGet] [HttpGet]
public async Task<ResultModel<dynamic>> GetData4PTD003(string recordType, string recordNumber, string lineNo, string materialNo, string shippingSN, string dateStart, string dateEnd) public async Task<ResultModel<dynamic>> GetData4PTD003(string recordType, string recordNumber, string lineNo, string materialNo, string shippingSN, string dateStart, string dateEnd)
{
try
{ {
ResultModel<dynamic> result = new ResultModel<dynamic>(); ResultModel<dynamic> result = new ResultModel<dynamic>();
//安勤連線 //安勤連線
@ -3453,9 +3499,12 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{ {
await connPTD.OpenAsync(); await connPTD.OpenAsync();
} }
try
{
string strSQL = $@"SELECT a.RecordTypeID ,a.RecordNumber ,a.RCLineNO 'LineNo', string strSQL = $@"SELECT a.RecordTypeID ,a.RecordNumber ,a.RCLineNO 'LineNo',
a.SerialNumber 'SN',a.ProductID ,a.EmplID 'Customer',a.LocationID 'Location', a.SerialNumber 'SN',a.ProductID ,a.EmplID 'Customer',a.LocationID 'Location',
a.CreatorID ,a.CreateDate a.CreatorID ,a.RecordDate
FROM SFIS_PTD.dbo.ZProductTrans a where 1=1 "; FROM SFIS_PTD.dbo.ZProductTrans a where 1=1 ";
if (recordType != null && recordType != "" && recordType != "全部") if (recordType != null && recordType != "" && recordType != "全部")
{ {
@ -3490,11 +3539,11 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
result.Success = false; result.Success = false;
return result; return result;
} }
strSQL += $" And a.CreateDate Between '{dateStart.Replace("/","-") + " 00:00:00"}' And '{dateEnd.Replace("/", "-") + " 23:59:59"}'"; strSQL += $" And a.RecordDate Between '{dateStart.Replace("/","-") + " 00:00:00"}' And '{dateEnd.Replace("/", "-") + " 23:59:59"}'";
} }
//排序:ZProductTrans.CreateDate DESC //排序:ZProductTrans.CreateDate DESC
strSQL += " Order by a.CreateDate DESC"; strSQL += " Order by a.RecordDate DESC";
DataTable dtZProductTrans = new DataTable(); DataTable dtZProductTrans = new DataTable();
using (var cmd = connPTD.CreateCommand()) using (var cmd = connPTD.CreateCommand())
@ -3540,12 +3589,18 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{ {
throw e; throw e;
} }
finally
{
if (connPTD.State == ConnectionState.Open)
{
connPTD.Close();
connPTD.Dispose();
}
}
} }
[HttpGet("GetCustomer/{recordNumber}")] [HttpGet("GetCustomer/{recordNumber}")]
public async Task<string> GetCustomer(string recordNumber) public async Task<string> GetCustomer(string recordNumber)
{
try
{ {
//安勤連線 //安勤連線
PTDContext _ptd_context = new PTDContext(); PTDContext _ptd_context = new PTDContext();
@ -3554,6 +3609,8 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{ {
await connPTD.OpenAsync(); await connPTD.OpenAsync();
} }
try
{
string strSQL = $@"Select top 1 SoldCustomerID 'Customer' from SFIS_PTD.dbo.ZDNDetail where DNNo ='{recordNumber}'"; string strSQL = $@"Select top 1 SoldCustomerID 'Customer' from SFIS_PTD.dbo.ZDNDetail where DNNo ='{recordNumber}'";
string strCustomer = ""; string strCustomer = "";
@ -3577,6 +3634,14 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{ {
throw e; throw e;
} }
finally
{
if (connPTD.State == ConnectionState.Open)
{
connPTD.Close();
connPTD.Dispose();
}
}
} }
#endregion #endregion
@ -3584,8 +3649,6 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
[Route("[action]")] [Route("[action]")]
[HttpGet] [HttpGet]
public async Task<ActionResult<IEnumerable<RecordTypeInfo>>> GetRecordTypeInfo() public async Task<ActionResult<IEnumerable<RecordTypeInfo>>> GetRecordTypeInfo()
{
try
{ {
//安勤連線 //安勤連線
PTDContext _ptd_context = new PTDContext(); PTDContext _ptd_context = new PTDContext();
@ -3594,6 +3657,8 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{ {
await connPTD.OpenAsync(); await connPTD.OpenAsync();
} }
try
{
string strSQL = $@"select * from SFIS_PTD.dbo.RecordTypeInfo"; string strSQL = $@"select * from SFIS_PTD.dbo.RecordTypeInfo";
DataTable dtRecordTypeInfo = new DataTable(); DataTable dtRecordTypeInfo = new DataTable();
@ -3629,12 +3694,18 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{ {
throw e; throw e;
} }
finally
{
if (connPTD.State == ConnectionState.Open)
{
connPTD.Close();
connPTD.Dispose();
}
}
} }
[HttpGet("GetRecordTypeInfo/{id}")] [HttpGet("GetRecordTypeInfo/{id}")]
public async Task<ActionResult<IEnumerable<RecordTypeInfo>>> GetRecordTypeInfo(string id) public async Task<ActionResult<IEnumerable<RecordTypeInfo>>> GetRecordTypeInfo(string id)
{
try
{ {
//安勤連線 //安勤連線
PTDContext _ptd_context = new PTDContext(); PTDContext _ptd_context = new PTDContext();
@ -3643,6 +3714,8 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{ {
await connPTD.OpenAsync(); await connPTD.OpenAsync();
} }
try
{
string strSQL = $@"select * from SFIS_PTD.dbo.RecordTypeInfo"; string strSQL = $@"select * from SFIS_PTD.dbo.RecordTypeInfo";
if (id != null && id != "") if (id != null && id != "")
{ {
@ -3682,6 +3755,14 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{ {
throw e; throw e;
} }
finally
{
if (connPTD.State == ConnectionState.Open)
{
connPTD.Close();
connPTD.Dispose();
}
}
} }
[Route("[action]")] [Route("[action]")]
@ -3689,11 +3770,6 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
public async Task<ResultModel<RecordTypeInfo>> PostRecordTypeInfo(RecordTypeInfo RecordTypeInfo) public async Task<ResultModel<RecordTypeInfo>> PostRecordTypeInfo(RecordTypeInfo RecordTypeInfo)
{ {
ResultModel<RecordTypeInfo> result = new ResultModel<RecordTypeInfo>(); ResultModel<RecordTypeInfo> result = new ResultModel<RecordTypeInfo>();
try
{
string strSQL = $@"INSERT INTO SFIS_PTD.dbo.RecordTypeInfo (ID, RBU, TypeName, TypeDesc, Source, PrefixCode, Length)
VALUES ('{RecordTypeInfo.ID}','{RecordTypeInfo.RBU}', '{RecordTypeInfo.TypeName}', '{RecordTypeInfo.TypeDesc}',
'{RecordTypeInfo.Source}', '{RecordTypeInfo.PrefixCode}', {RecordTypeInfo.Length})";
//安勤連線 //安勤連線
PTDContext _ptd_context = new PTDContext(); PTDContext _ptd_context = new PTDContext();
DbConnection connPTD = _ptd_context.Database.GetDbConnection(); DbConnection connPTD = _ptd_context.Database.GetDbConnection();
@ -3701,7 +3777,11 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{ {
await connPTD.OpenAsync(); await connPTD.OpenAsync();
} }
try
{
string strSQL = $@"INSERT INTO SFIS_PTD.dbo.RecordTypeInfo (ID, RBU, TypeName, TypeDesc, Source, PrefixCode, Length)
VALUES ('{RecordTypeInfo.ID}','{RecordTypeInfo.RBU}', '{RecordTypeInfo.TypeName}', '{RecordTypeInfo.TypeDesc}',
'{RecordTypeInfo.Source}', '{RecordTypeInfo.PrefixCode}', {RecordTypeInfo.Length})";
using (var cmd = connPTD.CreateCommand()) using (var cmd = connPTD.CreateCommand())
{ {
cmd.CommandText = strSQL; cmd.CommandText = strSQL;
@ -3715,6 +3795,14 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
result.Success = false; result.Success = false;
result.Msg = ex.InnerException.Message; result.Msg = ex.InnerException.Message;
} }
finally
{
if (connPTD.State == ConnectionState.Open)
{
connPTD.Close();
connPTD.Dispose();
}
}
return result; return result;
} }
@ -3723,6 +3811,7 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
public async Task<ResultModel<RecordTypeInfo>> PutRecordTypeInfo(string id, [FromBody] RecordTypeInfo RecordTypeInfo) public async Task<ResultModel<RecordTypeInfo>> PutRecordTypeInfo(string id, [FromBody] RecordTypeInfo RecordTypeInfo)
{ {
ResultModel<RecordTypeInfo> result = new ResultModel<RecordTypeInfo>(); ResultModel<RecordTypeInfo> result = new ResultModel<RecordTypeInfo>();
if (id != RecordTypeInfo.ID) if (id != RecordTypeInfo.ID)
{ {
result.Success = false; result.Success = false;
@ -3730,6 +3819,14 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
return result; return result;
} }
//安勤連線
PTDContext _ptd_context = new PTDContext();
DbConnection connPTD = _ptd_context.Database.GetDbConnection();
if (connPTD.State != ConnectionState.Open)
{
await connPTD.OpenAsync();
}
try try
{ {
string strSQL = $@"UPDATE SFIS_PTD.dbo.RecordTypeInfo string strSQL = $@"UPDATE SFIS_PTD.dbo.RecordTypeInfo
@ -3740,13 +3837,6 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
PrefixCode = '{RecordTypeInfo.PrefixCode}', PrefixCode = '{RecordTypeInfo.PrefixCode}',
Length = {RecordTypeInfo.Length} Length = {RecordTypeInfo.Length}
WHERE ID = '{id}'"; WHERE ID = '{id}'";
//安勤連線
PTDContext _ptd_context = new PTDContext();
DbConnection connPTD = _ptd_context.Database.GetDbConnection();
if (connPTD.State != ConnectionState.Open)
{
await connPTD.OpenAsync();
}
using (var cmd = connPTD.CreateCommand()) using (var cmd = connPTD.CreateCommand())
{ {
@ -3761,6 +3851,14 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
result.Success = false; result.Success = false;
result.Msg = ex.InnerException.Message; result.Msg = ex.InnerException.Message;
} }
finally
{
if (connPTD.State == ConnectionState.Open)
{
connPTD.Close();
connPTD.Dispose();
}
}
return result; return result;
} }
@ -3769,11 +3867,6 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
public async Task<ResultModel<RecordTypeInfo>> DeleteRecordTypeInfo(int id) public async Task<ResultModel<RecordTypeInfo>> DeleteRecordTypeInfo(int id)
{ {
ResultModel<RecordTypeInfo> result = new ResultModel<RecordTypeInfo>(); ResultModel<RecordTypeInfo> result = new ResultModel<RecordTypeInfo>();
try
{
string strSQL = $@"DELETE FROM SFIS_PTD.dbo.RecordTypeInfo
WHERE ID = '{id}'";
//安勤連線 //安勤連線
PTDContext _ptd_context = new PTDContext(); PTDContext _ptd_context = new PTDContext();
DbConnection connPTD = _ptd_context.Database.GetDbConnection(); DbConnection connPTD = _ptd_context.Database.GetDbConnection();
@ -3781,6 +3874,10 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{ {
await connPTD.OpenAsync(); await connPTD.OpenAsync();
} }
try
{
string strSQL = $@"DELETE FROM SFIS_PTD.dbo.RecordTypeInfo
WHERE ID = '{id}'";
using (var cmd = connPTD.CreateCommand()) using (var cmd = connPTD.CreateCommand())
{ {
@ -3796,6 +3893,14 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
result.Success = false; result.Success = false;
result.Msg = ex.InnerException.Message; result.Msg = ex.InnerException.Message;
} }
finally
{
if (connPTD.State == ConnectionState.Open)
{
connPTD.Close();
connPTD.Dispose();
}
}
return result; return result;
} }
@ -3805,8 +3910,6 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
[Route("[action]")] [Route("[action]")]
[HttpGet] [HttpGet]
public async Task<ActionResult<IEnumerable<CustomerItemMailGroupModel>>> GetCustomerItemMailGroup() public async Task<ActionResult<IEnumerable<CustomerItemMailGroupModel>>> GetCustomerItemMailGroup()
{
try
{ {
//安勤連線 //安勤連線
PTDContext _ptd_context = new PTDContext(); PTDContext _ptd_context = new PTDContext();
@ -3815,6 +3918,8 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{ {
await connPTD.OpenAsync(); await connPTD.OpenAsync();
} }
try
{
string strSQL = $@"select * from SFIS_PTD.dbo.CustomerItemMailGroup"; string strSQL = $@"select * from SFIS_PTD.dbo.CustomerItemMailGroup";
DataTable dtCustomerItemMailGroup = new DataTable(); DataTable dtCustomerItemMailGroup = new DataTable();
using (var cmd = connPTD.CreateCommand()) using (var cmd = connPTD.CreateCommand())
@ -3846,11 +3951,17 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{ {
throw e; throw e;
} }
finally
{
if (connPTD.State == ConnectionState.Open)
{
connPTD.Close();
connPTD.Dispose();
}
}
} }
[HttpGet("GetCustomerItemMailGroup/{id}")] [HttpGet("GetCustomerItemMailGroup/{id}")]
public async Task<ActionResult<IEnumerable<CustomerItemMailGroupModel>>> GetCustomerItemMailGroup(string id) public async Task<ActionResult<IEnumerable<CustomerItemMailGroupModel>>> GetCustomerItemMailGroup(string id)
{
try
{ {
//安勤連線 //安勤連線
PTDContext _ptd_context = new PTDContext(); PTDContext _ptd_context = new PTDContext();
@ -3859,6 +3970,9 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{ {
await connPTD.OpenAsync(); await connPTD.OpenAsync();
} }
try
{
string strSQL = $@"select * from SFIS_PTD.dbo.CustomerItemMailGroup Where 1=1"; string strSQL = $@"select * from SFIS_PTD.dbo.CustomerItemMailGroup Where 1=1";
if (id != null && id != "") if (id != null && id != "")
{ {
@ -3894,17 +4008,20 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{ {
throw e; throw e;
} }
finally
{
if (connPTD.State == ConnectionState.Open)
{
connPTD.Close();
connPTD.Dispose();
}
}
} }
[Route("[action]")] [Route("[action]")]
[HttpPost] [HttpPost]
public async Task<ResultModel<CustomerItemMailGroupModel>> PostCustomerItemMailGroup(CustomerItemMailGroupModel CustomerItemMailGroup) public async Task<ResultModel<CustomerItemMailGroupModel>> PostCustomerItemMailGroup(CustomerItemMailGroupModel CustomerItemMailGroup)
{ {
ResultModel<CustomerItemMailGroupModel> result = new ResultModel<CustomerItemMailGroupModel>(); ResultModel<CustomerItemMailGroupModel> result = new ResultModel<CustomerItemMailGroupModel>();
try
{
string strSQL = $@"INSERT INTO SFIS_PTD.dbo.[CustomerItemMailGroup] ([ItemNumber],[CustomerCode],[MailGroup],[StatusNo])
VALUES ('{CustomerItemMailGroup.ItemNumber}','{CustomerItemMailGroup.CustomerCode}',
'{CustomerItemMailGroup.MailGroup}', '{CustomerItemMailGroup.StatusNo}')";
//安勤連線 //安勤連線
PTDContext _ptd_context = new PTDContext(); PTDContext _ptd_context = new PTDContext();
DbConnection connPTD = _ptd_context.Database.GetDbConnection(); DbConnection connPTD = _ptd_context.Database.GetDbConnection();
@ -3912,7 +4029,11 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{ {
await connPTD.OpenAsync(); await connPTD.OpenAsync();
} }
try
{
string strSQL = $@"INSERT INTO SFIS_PTD.dbo.[CustomerItemMailGroup] ([ItemNumber],[CustomerCode],[MailGroup],[StatusNo])
VALUES ('{CustomerItemMailGroup.ItemNumber}','{CustomerItemMailGroup.CustomerCode}',
'{CustomerItemMailGroup.MailGroup}', '{CustomerItemMailGroup.StatusNo}')";
using (var cmd = connPTD.CreateCommand()) using (var cmd = connPTD.CreateCommand())
{ {
cmd.CommandText = strSQL; cmd.CommandText = strSQL;
@ -3926,6 +4047,14 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
result.Success = false; result.Success = false;
result.Msg = ex.InnerException.Message; result.Msg = ex.InnerException.Message;
} }
finally
{
if (connPTD.State == ConnectionState.Open)
{
connPTD.Close();
connPTD.Dispose();
}
}
return result; return result;
} }
@ -3941,12 +4070,6 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
return result; return result;
} }
try
{
string strSQL = $@"UPDATE SFIS_PTD.dbo.CustomerItemMailGroup
SET CustomerCode = '{CustomerItemMailGroup.CustomerCode}',
MailGroup = '{CustomerItemMailGroup.MailGroup}'
WHERE ItemNumber = '{id}'";
//安勤連線 //安勤連線
PTDContext _ptd_context = new PTDContext(); PTDContext _ptd_context = new PTDContext();
DbConnection connPTD = _ptd_context.Database.GetDbConnection(); DbConnection connPTD = _ptd_context.Database.GetDbConnection();
@ -3955,6 +4078,13 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
await connPTD.OpenAsync(); await connPTD.OpenAsync();
} }
try
{
string strSQL = $@"UPDATE SFIS_PTD.dbo.CustomerItemMailGroup
SET CustomerCode = '{CustomerItemMailGroup.CustomerCode}',
MailGroup = '{CustomerItemMailGroup.MailGroup}'
WHERE ItemNumber = '{id}'";
using (var cmd = connPTD.CreateCommand()) using (var cmd = connPTD.CreateCommand())
{ {
cmd.CommandText = strSQL; cmd.CommandText = strSQL;
@ -3968,6 +4098,14 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
result.Success = false; result.Success = false;
result.Msg = ex.InnerException.Message; result.Msg = ex.InnerException.Message;
} }
finally
{
if (connPTD.State == ConnectionState.Open)
{
connPTD.Close();
connPTD.Dispose();
}
}
return result; return result;
} }
@ -3976,7 +4114,13 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
public async Task<ResultModel<CustomerItemMailGroupModel>> DeleteCustomerItemMailGroup(string id) public async Task<ResultModel<CustomerItemMailGroupModel>> DeleteCustomerItemMailGroup(string id)
{ {
ResultModel<CustomerItemMailGroupModel> result = new ResultModel<CustomerItemMailGroupModel>(); ResultModel<CustomerItemMailGroupModel> result = new ResultModel<CustomerItemMailGroupModel>();
//安勤連線
PTDContext _ptd_context = new PTDContext();
DbConnection connPTD = _ptd_context.Database.GetDbConnection();
if (connPTD.State != ConnectionState.Open)
{
await connPTD.OpenAsync();
}
try try
{ {
string strSQL = $@"UPDATE SFIS_PTD.dbo.CustomerItemMailGroup string strSQL = $@"UPDATE SFIS_PTD.dbo.CustomerItemMailGroup
@ -3987,13 +4131,6 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
ELSE 'A' ELSE 'A'
END END
WHERE ItemNumber = '{id}'"; WHERE ItemNumber = '{id}'";
//安勤連線
PTDContext _ptd_context = new PTDContext();
DbConnection connPTD = _ptd_context.Database.GetDbConnection();
if (connPTD.State != ConnectionState.Open)
{
await connPTD.OpenAsync();
}
using (var cmd = connPTD.CreateCommand()) using (var cmd = connPTD.CreateCommand())
{ {
@ -4009,6 +4146,14 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
result.Success = false; result.Success = false;
result.Msg = ex.InnerException.Message; result.Msg = ex.InnerException.Message;
} }
finally
{
if (connPTD.State == ConnectionState.Open)
{
connPTD.Close();
connPTD.Dispose();
}
}
return result; return result;
} }
@ -4028,6 +4173,10 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{ {
await connPTD.OpenAsync(); await connPTD.OpenAsync();
} }
try
{
string strSQL = $@"select [RecordTypeID] as 'recordType', string strSQL = $@"select [RecordTypeID] as 'recordType',
[RecordNumber] as 'dnNo', [RecordNumber] as 'dnNo',
[RCLineNO] as 'lineNo', [RCLineNO] as 'lineNo',
@ -4067,6 +4216,21 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
result.DataTotal = list.Count(); result.DataTotal = list.Count();
result.Data = list; result.Data = list;
}
catch (Exception ex)
{
result.Success = false;
result.Msg = ex.InnerException.Message;
}
finally
{
if (connPTD.State == ConnectionState.Open)
{
connPTD.Close();
connPTD.Dispose();
}
}
if (result == null) if (result == null)
{ {
result.Msg = "查無資料"; result.Msg = "查無資料";
@ -4086,10 +4250,6 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
ResultModel<dynamic> result = new ResultModel<dynamic>(); ResultModel<dynamic> result = new ResultModel<dynamic>();
List<string> SNList = new List<string>(); List<string> SNList = new List<string>();
Collection<string> colSQL = new Collection<string>(); Collection<string> colSQL = new Collection<string>();
try
{
string strSQL = "";
string strCreateDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss");
//安勤連線 //安勤連線
PTDContext _ptd_context = new PTDContext(); PTDContext _ptd_context = new PTDContext();
@ -4099,6 +4259,11 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
await connPTD.OpenAsync(); await connPTD.OpenAsync();
} }
try
{
string strSQL = "";
string strCreateDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss");
CheckShipQty(Data.RecordNumber, Data.RCLineNO, 1); CheckShipQty(Data.RecordNumber, Data.RCLineNO, 1);
//用ZProductTrans最新RecordType 檢查PTDFlowRules邏輯 //用ZProductTrans最新RecordType 檢查PTDFlowRules邏輯
@ -4169,6 +4334,14 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
result.Success = false; result.Success = false;
result.Msg = ex.Message; result.Msg = ex.Message;
} }
finally
{
if (connPTD.State == ConnectionState.Open)
{
connPTD.Close();
connPTD.Dispose();
}
}
return result; return result;
} }
@ -4177,10 +4350,6 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{ {
ResultModel<RecordTypeInfo> result = new ResultModel<RecordTypeInfo>(); ResultModel<RecordTypeInfo> result = new ResultModel<RecordTypeInfo>();
try
{
string strSQL = $@"DELETE FROM SFIS_PTD.dbo.[ZWHPickListDetail]
WHERE [TaskStatus] = 'Picked' And [ShipmentSN] ='{sn}'";
//安勤連線 //安勤連線
PTDContext _ptd_context = new PTDContext(); PTDContext _ptd_context = new PTDContext();
DbConnection connPTD = _ptd_context.Database.GetDbConnection(); DbConnection connPTD = _ptd_context.Database.GetDbConnection();
@ -4188,7 +4357,10 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{ {
await connPTD.OpenAsync(); await connPTD.OpenAsync();
} }
try
{
string strSQL = $@"DELETE FROM SFIS_PTD.dbo.[ZWHPickListDetail]
WHERE [TaskStatus] = 'Picked' And [ShipmentSN] ='{sn}'";
using (var cmd = connPTD.CreateCommand()) using (var cmd = connPTD.CreateCommand())
{ {
cmd.CommandText = strSQL; cmd.CommandText = strSQL;
@ -4203,6 +4375,14 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
result.Success = false; result.Success = false;
result.Msg = ex.InnerException.Message; result.Msg = ex.InnerException.Message;
} }
finally
{
if (connPTD.State == ConnectionState.Open)
{
connPTD.Close();
connPTD.Dispose();
}
}
return result; return result;
} }
#endregion #endregion
@ -4221,6 +4401,9 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{ {
await connPTD.OpenAsync(); await connPTD.OpenAsync();
} }
try
{
string strSQL = $@"SELECT b.RecordNumber as DNNO string strSQL = $@"SELECT b.RecordNumber as DNNO
,b.RCLineNO as DNLineNO ,b.RCLineNO as DNLineNO
,b.ProductID ,b.ProductID
@ -4260,6 +4443,20 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
result.DataTotal = list.Count(); result.DataTotal = list.Count();
result.Data = list; result.Data = list;
}
catch (Exception ex)
{
result.Success = false;
result.Msg = ex.InnerException.Message;
}
finally
{
if (connPTD.State == ConnectionState.Open)
{
connPTD.Close();
connPTD.Dispose();
}
}
if (result == null) if (result == null)
{ {
@ -4279,6 +4476,13 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
ResultModel<dynamic> result = new ResultModel<dynamic>(); ResultModel<dynamic> result = new ResultModel<dynamic>();
List<string> SNList = new List<string>(); List<string> SNList = new List<string>();
Collection<string> colSQL = new Collection<string>(); Collection<string> colSQL = new Collection<string>();
//安勤連線
PTDContext _ptd_context = new PTDContext();
DbConnection connPTD = _ptd_context.Database.GetDbConnection();
if (connPTD.State != ConnectionState.Open)
{
await connPTD.OpenAsync();
}
try try
{ {
string strSQL = ""; string strSQL = "";
@ -4288,14 +4492,6 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
string strRecordDate = Data.RecordDate; string strRecordDate = Data.RecordDate;
string strCreateDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); string strCreateDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss");
//安勤連線
PTDContext _ptd_context = new PTDContext();
DbConnection connPTD = _ptd_context.Database.GetDbConnection();
if (connPTD.State != ConnectionState.Open)
{
await connPTD.OpenAsync();
}
foreach (PTD007TableDataModel SNData in Data.TableData) foreach (PTD007TableDataModel SNData in Data.TableData)
{ {
//ZWHPickListDetail查SN資訊 //ZWHPickListDetail查SN資訊
@ -4415,6 +4611,14 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
result.Success = false; result.Success = false;
result.Msg = ex.Message; result.Msg = ex.Message;
} }
finally
{
if (connPTD.State == ConnectionState.Open)
{
connPTD.Close();
connPTD.Dispose();
}
}
return result; return result;
} }
@ -4425,9 +4629,6 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
[HttpGet] [HttpGet]
public async Task<ResultModel<dynamic>> GetData4PTD008( string recordNumber, string lineNo, string materialNo, string shippingSN) public async Task<ResultModel<dynamic>> GetData4PTD008( string recordNumber, string lineNo, string materialNo, string shippingSN)
{ {
try
{
ResultModel<dynamic> result = new ResultModel<dynamic>();
//安勤連線 //安勤連線
PTDContext _ptd_context = new PTDContext(); PTDContext _ptd_context = new PTDContext();
DbConnection connPTD = _ptd_context.Database.GetDbConnection(); DbConnection connPTD = _ptd_context.Database.GetDbConnection();
@ -4435,6 +4636,10 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{ {
await connPTD.OpenAsync(); await connPTD.OpenAsync();
} }
try
{
ResultModel<dynamic> result = new ResultModel<dynamic>();
string strSQL = $@"SELECT RecordTypeID,RecordNumber,RCLineNO 'LineNo', string strSQL = $@"SELECT RecordTypeID,RecordNumber,RCLineNO 'LineNo',
SerialNumber 'SN',ProductID SerialNumber 'SN',ProductID
FROM SFIS_PTD.dbo.ZProductTrans where RecordNumber ='{recordNumber}' And RCLineNO ='{lineNo}' FROM SFIS_PTD.dbo.ZProductTrans where RecordNumber ='{recordNumber}' And RCLineNO ='{lineNo}'
@ -4488,6 +4693,14 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{ {
throw e; throw e;
} }
finally
{
if (connPTD.State == ConnectionState.Open)
{
connPTD.Close();
connPTD.Dispose();
}
}
} }
[Route("[action]")] [Route("[action]")]
[HttpPost] [HttpPost]
@ -4495,11 +4708,6 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{ {
ResultModel<dynamic> result = new ResultModel<dynamic>(); ResultModel<dynamic> result = new ResultModel<dynamic>();
Collection<string> colSQL = new Collection<string>(); Collection<string> colSQL = new Collection<string>();
try
{
string strSQL = "";
string strCreateDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss");
//安勤連線 //安勤連線
PTDContext _ptd_context = new PTDContext(); PTDContext _ptd_context = new PTDContext();
DbConnection connPTD = _ptd_context.Database.GetDbConnection(); DbConnection connPTD = _ptd_context.Database.GetDbConnection();
@ -4507,6 +4715,11 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
{ {
await connPTD.OpenAsync(); await connPTD.OpenAsync();
} }
try
{
string strSQL = "";
string strCreateDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss");
foreach (PTD008TableDataModel SNData in Data.tableData) foreach (PTD008TableDataModel SNData in Data.tableData)
{ {
@ -4581,6 +4794,14 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no);
result.Success = false; result.Success = false;
result.Msg = ex.Message; result.Msg = ex.Message;
} }
finally
{
if (connPTD.State == ConnectionState.Open)
{
connPTD.Close();
connPTD.Dispose();
}
}
return result; return result;
} }
#endregion #endregion

Loading…
Cancel
Save