using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection; using System.Text; using MESClassLibrary.BLL.Log; using MESClassLibrary.DAL; using MESClassLibrary.DAL.PunchAndWeld; using MESClassLibrary.EFModel; using MESClassLibrary.Model; namespace MESClassLibrary.BLL.PunchAndWeld { public class PunchAndStationBLL { BasicBLL db = new BasicBLL(); public bool AddInfo(tb_PunchAndStation md) { try { BBMPTEntities ef = new BBMPTEntities(); List list = ef.tb_PunchAndStation.Where(p => p.StationID == md.StationID && p.AddressNo == md.AddressNo && p.PortName==md.PortName) .ToList(); if (list.Any()) { return false; } List list1 = ef.tb_PunchAndStation.Where(p => p.StationID == md.StationID && p.ProductID1 == md.ProductID1 && p.ProductID2 == md.ProductID2) .ToList(); if (list1.Any()) { return false; } return db.AddInfo(md); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } public string SearchInfoAll(string page, string pagesize, string partNo1) { try { string jsonStr = "[]"; int total = 0;//总行数 List list = new List(); string sql = @"SELECT top 50 dbo.tb_PunchAndStation.ID, dbo.tb_Station.StationNo, tb_Product_1.PartNo AS PartNo1, tb_Product_1.ProductName AS ProductName1, tb_Product_2.PartNo AS PartNo2, tb_Product_2.ProductName AS ProductName2, tb_Product_3.PartNo AS PartNo3, tb_Product_3.ProductName AS ProductName3, tb_Product_4.PartNo AS PartNo4, tb_Product_4.ProductName AS ProductName4, tb_Product_5.PartNo AS PartNo5, tb_Product_5.ProductName AS ProductName5, dbo.tb_PunchAndStation.IsCheck, dbo.tb_PunchAndStation.AddressNo, dbo.tb_PunchAndStation.PortName, tb_Product_6.PartNo AS PartNo6, tb_Product_6.ProductName AS ProductName6, tb_Product_7.PartNo AS PartNo7, tb_Product_7.ProductName AS ProductName7, tb_Product_8.PartNo AS PartNo8, tb_Product_8.ProductName AS ProductName8, tb_Product_9.PartNo AS PartNo9, tb_Product_9.ProductName AS ProductName9, tb_Product_10.PartNo AS PartNo10, tb_Product_10.ProductName AS ProductName10, tb_Product_11.PartNo AS PartNo11, tb_Product_11.ProductName AS ProductName11, tb_Product_12.PartNo AS PartNo12, tb_Product_12.ProductName AS ProductName12, tb_Product_13.PartNo AS PartNo13, tb_Product_13.ProductName AS ProductName13, dbo.tb_Product.PartNo AS PartNo14, dbo.tb_Product.ProductName AS ProductName14 FROM dbo.tb_Product AS tb_Product_12 RIGHT OUTER JOIN dbo.tb_PunchAndStation LEFT OUTER JOIN dbo.tb_Product ON dbo.tb_PunchAndStation.ProductID14 = dbo.tb_Product.ProductID LEFT OUTER JOIN dbo.tb_Product AS tb_Product_13 ON dbo.tb_PunchAndStation.ProductID13 = tb_Product_13.ProductID ON tb_Product_12.ProductID = dbo.tb_PunchAndStation.ProductID12 LEFT OUTER JOIN dbo.tb_Product AS tb_Product_11 ON dbo.tb_PunchAndStation.ProductID11 = tb_Product_11.ProductID LEFT OUTER JOIN dbo.tb_Product AS tb_Product_10 ON dbo.tb_PunchAndStation.ProductID10 = tb_Product_10.ProductID LEFT OUTER JOIN dbo.tb_Product AS tb_Product_9 ON dbo.tb_PunchAndStation.ProductID9 = tb_Product_9.ProductID LEFT OUTER JOIN dbo.tb_Product AS tb_Product_8 ON dbo.tb_PunchAndStation.ProductID8 = tb_Product_8.ProductID LEFT OUTER JOIN dbo.tb_Product AS tb_Product_7 ON dbo.tb_PunchAndStation.ProductID7 = tb_Product_7.ProductID LEFT OUTER JOIN dbo.tb_Product AS tb_Product_6 ON dbo.tb_PunchAndStation.ProductID6 = tb_Product_6.ProductID LEFT OUTER JOIN dbo.tb_Product AS tb_Product_5 ON dbo.tb_PunchAndStation.ProductID5 = tb_Product_5.ProductID LEFT OUTER JOIN dbo.tb_Product AS tb_Product_4 ON dbo.tb_PunchAndStation.ProductID4 = tb_Product_4.ProductID LEFT OUTER JOIN dbo.tb_Product AS tb_Product_3 ON dbo.tb_PunchAndStation.ProductID3 = tb_Product_3.ProductID LEFT OUTER JOIN dbo.tb_Product AS tb_Product_2 ON dbo.tb_PunchAndStation.ProductID2 = tb_Product_2.ProductID LEFT OUTER JOIN dbo.tb_Station ON dbo.tb_PunchAndStation.StationID = dbo.tb_Station.StationID LEFT OUTER JOIN dbo.tb_Product AS tb_Product_1 ON dbo.tb_PunchAndStation.ProductID1 = tb_Product_1.ProductID WHERE 1=1 "; if (!string.IsNullOrWhiteSpace(partNo1)) { sql += " And tb_Product_1.PartNo like '%" + partNo1 + "%' "; } DataTable dt = SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql).Tables[0]; if (dt != null && dt.Rows.Count > 0) { list = Tool.ConvertTo(dt).ToList(); } if (list.Count > 0) { total = list.Count; int Skipcount = (Convert.ToInt32(page) - 1) * Convert.ToInt32(pagesize); list = list.Skip(Skipcount).Take(Convert.ToInt32(pagesize)).ToList(); JsonDataModel md = new JsonDataModel(); md.total = total.ToString(); md.rows = list; jsonStr = JSONTools.ScriptSerialize>(md); } return jsonStr; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public bool UpdateInfo(tb_PunchAndStation md) { try { List list = new List(); string sql = @"SELECT dbo.tb_PunchAndStation.ID, dbo.tb_PunchAndStation.ProductID1, dbo.tb_PunchAndStation.ProductID2, dbo.tb_PunchAndStation.ProductID3, dbo.tb_PunchAndStation.ProductID4, dbo.tb_PunchAndStation.ProductID5, dbo.tb_PunchAndStation.ProductID6, dbo.tb_PunchAndStation.ProductID7, dbo.tb_PunchAndStation.ProductID8, dbo.tb_PunchAndStation.ProductID9, dbo.tb_PunchAndStation.ProductID10, dbo.tb_PunchAndStation.ProductID11, dbo.tb_PunchAndStation.ProductID12, dbo.tb_PunchAndStation.ProductID13, dbo.tb_PunchAndStation.ProductID14 FROM dbo.tb_PunchAndStation where 1=1 and ProductID1='" + md.ProductID1 + "' and ProductID2='" + md.ProductID2 + "' and ProductID3='" + md.ProductID3 + "' and ProductID4='" + md.ProductID4 + "' and ProductID5='" + md.ProductID5 + "' and ProductID6='" + md.ProductID6 + "'and ProductID7='" + md.ProductID7 + "' and ProductID8='" + md.ProductID8 + "'and ProductID9='" + md.ProductID9 + "'" + " and ProductID10='" + md.ProductID10 + "' and ProductID11='" + md.ProductID11 + "' and ProductID12='" + md.ProductID12 + "' " + " and ProductID13='" + md.ProductID13 + "' and ProductID14='" + md.ProductID14 + "' and ID <> '" + md.ID + "' "; DataTable dt = SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql).Tables[0]; if (dt != null && dt.Rows.Count > 0) { return false; } BBMPTEntities ef = new BBMPTEntities(); List list1 = ef.tb_PunchAndStation.Where(p => p.StationID == md.StationID && p.AddressNo == md.AddressNo && p.PortName==md.PortName && p.ID!=md.ID) .ToList(); if (list1.Any()) { return false; } //初始化要更新的字段 string[] proNames = new string[19]; proNames[0] = "StationID"; proNames[1] = "ProductID1"; proNames[2] = "ProductID2"; proNames[3] = "ProductID3"; proNames[4] = "ProductID4"; proNames[5] = "ProductID5"; proNames[6] = "IsCheck"; proNames[7] = "AddressNo"; proNames[8] = "PortName"; proNames[9] = "CheckDone"; proNames[10] = "ProductID6"; proNames[11] = "ProductID7"; proNames[12] = "ProductID8"; proNames[13] = "ProductID9"; proNames[14] = "ProductID10"; proNames[15] = "ProductID11"; proNames[16] = "ProductID12"; proNames[17] = "ProductID13"; proNames[18] = "ProductID14"; //必填字段初始化,如果不需要更新必填字段则设置为空即可,时间类型无需初始化 //如果没有初始化必填字段,更新会报错 return db.UpdateInfo(md, proNames); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } public bool DeleteInfo(tb_PunchAndStation md) { try { return db.DelInfo(md); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } public DataTable IsMath(string partNo1, string partNo2) { try { PunchAndStationDAL da=new PunchAndStationDAL(); return da.IsMath(partNo1, partNo2); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public DataTable IsMath1(string partNo, string stationNo) { try { PunchAndStationDAL da = new PunchAndStationDAL(); return da.IsMath1(partNo, stationNo); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public string GetComboboxData(string stationNo) { try { string jsonStr = "[]"; List list = new List(); string sql = @"SELECT p.PartNo FROM dbo.tb_PunchAndStation ps LEFT OUTER JOIN dbo.tb_Product p ON ps.ProductID1=p.ProductID LEFT OUTER JOIN dbo.tb_Station s ON ps.StationID=s.StationID WHERE s.StationNo='" + stationNo + @"'"; DataTable dt = SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, null).Tables[0]; if (dt != null && dt.Rows.Count > 0) { list = Tool.ConvertTo(dt).ToList(); } jsonStr = JSONTools.ScriptSerialize(list); return jsonStr; } catch (Exception) { return ""; } } } }