From 63f50e27d4dfdf7bcd35be8af4c28ca6bc82e500 Mon Sep 17 00:00:00 2001 From: Marvin Date: Fri, 6 Jan 2023 01:14:33 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E5=B7=A5=E5=8D=95KeyParts?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=201.1.=E5=A2=9E=E5=8A=A0MB=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=AF=B9=E5=BA=94MAC=E6=9F=A5=E8=AF=A2=EF=BC=88=E4=BB=8E?= =?UTF-8?q?=E6=98=B6=E4=BA=A8=E6=95=B0=E6=8D=AE=E5=BA=93=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AMESCoreStudio.Web/Views/QRS/QRS013.cshtml | 11 ++- .../Controllers/AMES/WipInfosController.cs | 92 ++++++++++++++++++- AMESCoreStudio.WebApi/Models/ESUNContext.cs | 27 ++++++ AMESCoreStudio.WebApi/appsettings.json | 1 + 4 files changed, 128 insertions(+), 3 deletions(-) create mode 100644 AMESCoreStudio.WebApi/Models/ESUNContext.cs diff --git a/AMESCoreStudio.Web/Views/QRS/QRS013.cshtml b/AMESCoreStudio.Web/Views/QRS/QRS013.cshtml index db5faba3..40e69606 100644 --- a/AMESCoreStudio.Web/Views/QRS/QRS013.cshtml +++ b/AMESCoreStudio.Web/Views/QRS/QRS013.cshtml @@ -147,8 +147,7 @@ { field: 'kP_98', title: '組件98' - } - , + } , { field: 'kP_BA', title: '組件BA' @@ -156,6 +155,14 @@ { field: 'kP_CPU', title: '組件CPU' + }, + { + field: 'kP_MB', + title: '組件MB' + }, + { + field: 'kP_MAC', + title: '組件MAC' } ] ]; diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs index 211ac5b7..1253ca19 100644 --- a/AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs +++ b/AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs @@ -11,6 +11,8 @@ using AMESCoreStudio.CommonTools.Result; using System.Data.Common; using System.Data; using System.Dynamic; +using Microsoft.Extensions.Configuration; +using Microsoft.EntityFrameworkCore.SqlServer; namespace AMESCoreStudio.WebApi.Controllers.AMES { @@ -22,6 +24,8 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES public class WipInfosController : Controller { private readonly AMESContext _context; + private readonly ESUNContext _esun_context; + private readonly IConfiguration _config; /// /// @@ -29,6 +33,7 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES /// public WipInfosController(AMESContext context) { + _config = new ConfigurationBuilder().SetBasePath(Environment.CurrentDirectory).AddJsonFile("appsettings.json").Build(); _context = context; } @@ -299,7 +304,6 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES sql = sql + " and c.wip_no = '" + wipNO + "'"; - string tempName = string.Empty; DbConnection conn = _context.Database.GetDbConnection(); if (conn.State != System.Data.ConnectionState.Open) { @@ -319,6 +323,92 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES table = DataReaderToDataTable(reader); + table.Columns.Add("KP_MAC"); + table.AcceptChanges(); + + //判断MB组件增加查询MAC + try + { + if (wip_kp.Count > 0) + { + /* + for (int i = 0; i < wip_kp.Count; i++) + { + if (wip_kp[i].KpNo.StartsWith("MB")) + { + table.Columns.Add("MAC"); + table.AcceptChanges(); + break; + } + } + */ + + ESUNContext _esun_context = new ESUNContext(); + + //读取MAC + DbConnection esun_conn = _esun_context.Database.GetDbConnection(); + if (esun_conn.State != System.Data.ConnectionState.Open) + { + await esun_conn.OpenAsync(); + } + + for (int j = 0; j < table.Rows.Count; j++) + { + string barcode_no = table.Rows[j]["BarcodeNo"].ToString(); + //barcode_no = "92000044790655"; + string mac_sql = string.Format(@"select distinct a.工單編號 as mo_id,e.客戶工單編號 as customer_moid,a.工單序號 as product_sn, + case substring(f.avalue_kp_typeid, 1, 3) when 'MAC' then isnull(z.item_prefix,'')+b.SUB_ITEM_SN else b.SUB_ITEM_SN end as part_barcode, + f.avalue_kp_typeid as class,c.material_id,d.r_stn as routeid,'' as workerid,rtrim(g.sn_date) + ' ' + rtrim(g.sn_time) as create_date + from or_sn_story a + left join sub_item_db b on a.工單編號 = b.or_sn and a.工單序號 = b.or_sal + left join jh_sub_item c on a.工單編號 = c.mo_id and b.class = c.part_typeid + left join jh_sub_item_prefix z on c.mo_id = z.mo_id + left join or_sub_db d on a.工單編號 = d.or_sn and b.class = d.class + join or_list e on a.工單編號 = e.工單編號 and e.[客戶] = 'EV' + left join jh_sub_item_mapping f on b.class = f.eversun_kp_typeid + join jh_sn_list g on a.工單序號 = g.sn + where g.sn_result = 'OK' + AND a.工單序號 = '{0}' + AND c.material_id LIKE 'MAC%'", barcode_no); + + using (var esun_cmd = esun_conn.CreateCommand()) + { + esun_cmd.CommandText = mac_sql; + + using (var esun_reader = await esun_cmd.ExecuteReaderAsync()) + { + if (esun_reader.HasRows) + { + List esun_list = new List(); + DataTable esun_table = new DataTable(); + + esun_table = DataReaderToDataTable(esun_reader); + + if (esun_table.Rows.Count > 0) + { + string mac_list = ""; + for (int k = 0; k < esun_table.Rows.Count; k++) + { + mac_list = mac_list + esun_table.Rows[k]["part_barcode"].ToString().Trim() + ","; + } + + if (mac_list != "") + { + string mac = mac_list.Substring(0, mac_list.Length - 1); + table.Rows[j]["KP_MAC"] = mac; + table.AcceptChanges(); + } + } + } + } + } + + } + } + } + catch { } + + foreach (DataRow row in table.Rows) { dynamic dyn = new ExpandoObject(); diff --git a/AMESCoreStudio.WebApi/Models/ESUNContext.cs b/AMESCoreStudio.WebApi/Models/ESUNContext.cs new file mode 100644 index 00000000..127ae654 --- /dev/null +++ b/AMESCoreStudio.WebApi/Models/ESUNContext.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; + +namespace AMESCoreStudio.WebApi +{ + /// + /// + /// + public class ESUNContext : DbContext + { + /// + /// + /// + /// + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + IConfiguration _config; + _config = new ConfigurationBuilder().SetBasePath(Environment.CurrentDirectory).AddJsonFile("appsettings.json").Build(); + optionsBuilder.UseSqlServer(_config.GetConnectionString("ESUNContext")); + base.OnConfiguring(optionsBuilder); + } + } +} diff --git a/AMESCoreStudio.WebApi/appsettings.json b/AMESCoreStudio.WebApi/appsettings.json index d13695a2..ca210a21 100644 --- a/AMESCoreStudio.WebApi/appsettings.json +++ b/AMESCoreStudio.WebApi/appsettings.json @@ -8,6 +8,7 @@ }, "ConnectionStrings": { "AMESContext2": "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=gdb)));User Id=JHAMES;Password=AMES666;", + "ESUNContext": "Data Source=localhost;Initial Catalog=SFIS_ESUN;User Id=sa;Password=20000123;", "AMESContext": "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=61.216.68.18)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=jhdb)));User Id=JHSYS;Password=ASYS666;" //"AMESContext": "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=61.216.68.18)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=jhdb)));User Id=system;Password=admin;" //"AMESContextO": "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=61.216.68.18)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=cpadb)));User Id=JHSYS;Password=ASYS666;"