using System; using System.Collections.Generic; using System.Linq; using System.Text; //Ref: using System.Data; using QMAPP.BoraUpgrade.Common; using QMAPP.BoraUpgrade.Entity; namespace QMAPP.BoraUpgrade.DAL { /// /// 门板种子数据-数据访问类 /// CreateTime:2018.10.31 /// Author :陈冲 /// Mail :22367340@qq.com /// public class ProductDataAccess { #region 新增产品信息 /// /// 新增产品信息 /// /// 产品信息实例 /// 成功 True 否则 False public static bool Insert(T_AW_PRODUCT eProduct) { bool returnVal = false; string sqlScriptTemp = @" Insert Into T_AW_Product (PID,ProductType,ProductCode,ProductSource,MachineCodde,Material_Code,[Status],IsParent,CurrentProcess,PRODUCELINE,PRODUCESHIFTNAME,PRODUCESHIFTTCODE, OutFlag,UsingState,Capacity,UsingCount,CreateUser,UpdateUser,WorkCell_Code,WorkLoc_Code,WorkCenter_Code, Team_code,EndofLine,MATERIAL_TYPE,CreateDate,UpdateDate,PLAN_NO) Values ( '{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}', '{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}', '{20}','{21}','{22}','{23}',getdate(),getdate(),'{24}' )"; string sqlScript = string.Format(sqlScriptTemp, eProduct.PID, eProduct.PRODUCTTYPE, eProduct.PRODUCTCODE, eProduct.PRODUCTSOURCE, eProduct.MACHINECODDE, eProduct.MATERIAL_CODE, eProduct.STATUS, eProduct.ISPARENT, eProduct.CURRENTPROCESS, eProduct.PRODUCELINE, eProduct.PRODUCESHIFTNAME, eProduct.PRODUCESHIFTTCODE, eProduct.OUTFLAG, eProduct.USINGSTATE, eProduct.CAPACITY, eProduct.USINGCOUNT, eProduct.CREATEUSER, eProduct.UPDATEUSER, eProduct.WORKCELL_CODE, eProduct.WORKLOC_CODE, eProduct.WORKCENTER_CODE, eProduct.TEAM_CODE, eProduct.ENDOFLINE, eProduct.MATERIAL_TYPE, eProduct.PLAN_NO ); try { //执行SQL int count = SqlHelper.ExecuteNonQuery(Config.maindbConnectionString, CommandType.Text, sqlScript); if (count > 0) { returnVal = true; } } catch (Exception) { //后续加入日志 throw; } return returnVal; } #endregion #region wrx /// /// 是否铣削过 /// /// /// 1:已铣削 0:未铣削 public static int GetIsMilling(string productCode) { string sqlScript = @"Select Top 1 * From [dbo].[T_AW_MillingRecord] Where BarCode = '{0}' Order By AddTime Desc"; DataSet dataSet = SqlHelper.ExecuteDataset(Config.maindbConnectionString, CommandType.Text, string.Format(sqlScript, productCode)); if (dataSet.Tables.Count > 0) { if(dataSet.Tables[0].Rows.Count > 0) return 1; } return 0; } #endregion #region 根据ProductCode提取产品实例 /// /// 根据ProductCode提取产品实例 /// /// 产品编号 /// public static DataTable GetProductByProductCode(string productCode) { DataTable returnVal = new DataTable(); string sqlScript = @"Select Top 1 * From [dbo].[T_AW_PRODUCT] Where USINGSTATE<> 2 and PRODUCTCODE = '{0}' Order By CREATEDATE Desc"; DataSet dataSet = SqlHelper.ExecuteDataset(Config.maindbConnectionString, CommandType.Text, string.Format(sqlScript, productCode)); if (dataSet.Tables.Count > 0) { returnVal = dataSet.Tables[0]; } return returnVal; } /// /// 根据产品条码以及工位查询 /// /// /// /// public static DataTable GetProductByLocCode(string productCode, string locCode) { DataTable returnVal = new DataTable(); string sqlScript = @"Select Top 1 * From [dbo].[T_AW_PRODUCT] Where PRODUCTCODE = '{0}' and WORKLOC_CODE='{1}' Order By UPDATEDATE Desc,CREATEDATE Desc "; DataSet dataSet = SqlHelper.ExecuteDataset(Config.maindbConnectionString, CommandType.Text, string.Format(sqlScript, productCode, locCode)); if (dataSet.Tables.Count > 0) { returnVal = dataSet.Tables[0]; } return returnVal; } public static DateTime GetServiceDateTime() { StringBuilder sql = new StringBuilder(); try { string sqlScript = @"select GetDATE() as time "; DataSet dataSet = SqlHelper.ExecuteDataset(Config.maindbConnectionString, CommandType.Text, string.Format(sqlScript)); if (dataSet.Tables.Count > 0) { string datetimestr = dataSet.Tables[0].Rows[0]["time"].ToString() ; return DateTime.Parse(datetimestr); } return DateTime.Now; } catch (Exception ex) { throw ex; } } public static DataTable GetBora3MCodes(string pMaterialCode) { DataTable table = null; List list = new List(); string sqlScript = $" select * from T_BD_Bora3Materials where Bora3MCode ='{pMaterialCode}'"; DataSet dataSet = SqlHelper.ExecuteDataset(Config.maindbConnectionString, CommandType.Text, sqlScript); if (dataSet.Tables.Count > 0) { table = dataSet.Tables[0]; //foreach (DataRow dataRow in table.Rows) //{ // string pbom = dataRow["Bora3MCode"].ToString(); // if (!list.Contains(pbom) && !string.IsNullOrEmpty(pbom)) // { // list.Add(pbom); // } //} } return table; } public static bool UpdateProductMaterialCode(string productCode, string mCode, string bora3MCode) { bool returnVal = false; string sqlScriptTemp = @"Update T_AW_Product Set MATERIAL_CODE = '{0}' Where PRODUCTCODE = '{1}' "; string sqlScript = string.Format(sqlScriptTemp, mCode, productCode); try { //执行SQL int count = SqlHelper.ExecuteNonQuery(Config.maindbConnectionString, CommandType.Text, sqlScript); if (count > 0) { returnVal = true; } } catch (Exception) { //后续加入日志 throw; } return returnVal; } #endregion #region 修改产品信息 /// /// 修改产品信息 /// /// 产品信息实例 /// 成功 True 否则 False public static bool Update(T_AW_PRODUCT eProduct) { bool returnVal = false; string sqlScriptTemp = @" Update T_AW_Product Set PLAN_NO = '{0}' Where PID = '{1}' "; string sqlScript = string.Format(sqlScriptTemp,eProduct.PLAN_NO,eProduct.PID ); try { //执行SQL int count = SqlHelper.ExecuteNonQuery(Config.maindbConnectionString, CommandType.Text, sqlScript); if (count > 0) { returnVal = true; } } catch (Exception) { //后续加入日志 throw; } return returnVal; } #endregion #region 修改产品信息 /// /// 修改产品信息 /// /// 产品信息实例 /// 成功 True 否则 False public static bool Modify(T_AW_PRODUCT eProduct) { bool returnVal = false; string sqlScriptTemp = @" Update T_AW_Product Set WORKCELL_CODE = '{0}',WORKLOC_CODE = '{1}',WORKCENTER_CODE='{2}',MATERIAL_TYPE='{3}' Where PID = '{4}' "; string sqlScript = string.Format(sqlScriptTemp, eProduct.WORKCELL_CODE,eProduct.WORKLOC_CODE,eProduct.WORKCENTER_CODE, eProduct.MATERIAL_TYPE,eProduct.PID ); try { //执行SQL int count = SqlHelper.ExecuteNonQuery(Config.maindbConnectionString, CommandType.Text, sqlScript); if (count > 0) { returnVal = true; } } catch (Exception) { //后续加入日志 throw; } return returnVal; } #endregion } }