public bool AddProductStore(ProductStoreME m) { if (_productStoreDAL.Exists(m.productID)) { return false; } return _productStoreDAL.Add(m); }
// <summary> /// 增加一条数据 /// </summary> public bool Add(ProductStoreME model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into productStore("); strSql.Append("productID,productType)"); strSql.Append(" values ("); strSql.Append("@productID,@productType)"); SqlParameter[] parameters = { new SqlParameter("@productID", SqlDbType.NVarChar,50), new SqlParameter("@productType", SqlDbType.NVarChar,50)}; parameters[0].Value = model.productID; parameters[1].Value = model.productType; int rows = _dbAssist.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } }
/// <summary> /// 得到一个对象实体 /// </summary> public ProductStoreME GetModel(string productID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 productID,productType from productStore "); strSql.Append(" where productID=@productID "); SqlParameter[] parameters = { new SqlParameter("@productID", SqlDbType.NVarChar,50) }; parameters[0].Value = productID; ProductStoreME model = new ProductStoreME(); DataSet ds = _dbAssist.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["productID"] != null && ds.Tables[0].Rows[0]["productID"].ToString() != "") { model.productID = ds.Tables[0].Rows[0]["productID"].ToString(); } if (ds.Tables[0].Rows[0]["productType"] != null && ds.Tables[0].Rows[0]["productType"].ToString() != "") { model.productType = ds.Tables[0].Rows[0]["productType"].ToString(); } return model; } else { return null; } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(ProductStoreME model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update productStore set "); strSql.Append("productType=@productType"); strSql.Append(" where productID=@productID "); SqlParameter[] parameters = { new SqlParameter("@productType", SqlDbType.NVarChar,50), new SqlParameter("@productID", SqlDbType.NVarChar,50)}; parameters[0].Value = model.productType; parameters[1].Value = model.productID; int rows = _dbAssist.ExecuteSql(strSql.ToString(), parameters); if(rows>0) { return true; } else { return false; } }
private void AutoTimerHandler(object source, ElapsedEventArgs e) { if (_WorkMode != ModeEnum.MODE_AUTO) return; lock(this) { if (_bEnableIn) { _rfidObj.id = DateTime.UtcNow.ToString(); //产品记录到数据库 ProductStoreME m = new ProductStoreME(); string s; if (_rfidObj.id.Length >= 20) { s = _rfidObj.id.Substring(0, 20); } else { s = _rfidObj.id.PadLeft(20, '0'); } m.productID = s; Random rdm = new Random(); int i=rdm.Next(0, _productCateArray.Length); m.productType = _productCateArray[i]; _productBll.AddProductStore(m); _rfidObj.bScaned = false; _bEnableIn = false; } } }