public WLPsOrderEntity GetWLPsOrderByOrderCode(string ordercode) { string sql = @"SELECT [Id],[OrderCode],[ConsignCode],[TransferCode],[PsBillCode],[OutTime],[PsResult],[CreateManId] FROM dbo.[WLPsOrder] WITH(NOLOCK) WHERE [OrderCode]=@OrderCode" ; DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@OrderCode", DbType.String, ordercode); WLPsOrderEntity entity = new WLPsOrderEntity(); using (IDataReader reader = db.ExecuteReader(cmd)) { if (reader.Read()) { entity.Id = StringUtils.GetDbInt(reader["Id"]); entity.OrderCode = StringUtils.GetDbLong(reader["OrderCode"]); entity.ConsignCode = StringUtils.GetDbString(reader["ConsignCode"]); entity.TransferCode = StringUtils.GetDbString(reader["TransferCode"]); entity.PsBillCode = StringUtils.GetDbString(reader["PsBillCode"]); entity.OutTime = StringUtils.GetDbDateTime(reader["OutTime"]); entity.PsResult = StringUtils.GetDbInt(reader["PsResult"]); entity.CreateManId = StringUtils.GetDbInt(reader["CreateManId"]); } } return(entity); }
/// <summary> /// 判断当前节点是否已存在相同的 /// </summary> /// <param name="entity"></param> /// <returns></returns> public int ExistNum(WLPsOrderEntity entity) { ///id=0,判断总数,ID>0判断除自己之外的总数 string sql = @"Select count(1) from dbo.[WLPsOrder] WITH(NOLOCK) "; string where = "where "; if (entity.Id == 0) { where += " OrderId=@OrderId"; } else { where += " OrderId=@OrderId and Id<>@Id"; } sql = sql + where; DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, entity.OrderId); if (entity.Id > 0) { db.AddInParameter(cmd, "@Id", DbType.Int32, entity.Id); } object identity = db.ExecuteScalar(cmd); if (identity == null || identity == DBNull.Value) { return(0); } return(Convert.ToInt32(identity)); }
/// <summary> /// 插入一条记录到表WLPsOrder,如果表中存在自增字段,则返回值为新记录的自增字段值,否则返回0。 /// 该方法提供给界面等UI层调用 /// </summary> /// <param name="wLPsOrder">要添加的WLPsOrder数据实体对象</param> public int AddWLPsOrder(WLPsOrderEntity wLPsOrder) { if (wLPsOrder.Id > 0) { return(UpdateWLPsOrder(wLPsOrder)); } else if (WLPsOrderBLL.Instance.IsExist(wLPsOrder)) { return((int)CommonStatus.ADD_Fail_Exist); } else { return(WLPsOrderDA.Instance.AddWLPsOrder(wLPsOrder)); } }
/// <summary> /// 根据主键值更新记录的全部字段(注意:该方法不会对自增字段、timestamp类型字段以及主键字段更新!如果要更新主键字段,请使用Update方法)。 /// 如果数据库有数据被更新了则返回True,否则返回False /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="wLPsOrder">待更新的实体对象</param> public int UpdateWLPsOrder(WLPsOrderEntity entity) { string sql = @" UPDATE dbo.[WLPsOrder] SET [OrderCode]=@OrderCode,[ConsignCode]=@ConsignCode,[TransferCode]=@TransferCode,[PsBillCode]=@PsBillCode,[OutTime]=@OutTime,[PsResult]=@PsResult,[CreateManId]=@CreateManId WHERE [Id]=@id"; DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@Id", DbType.Int32, entity.Id); db.AddInParameter(cmd, "@OrderCode", DbType.String, entity.OrderCode); db.AddInParameter(cmd, "@ConsignCode", DbType.String, entity.ConsignCode); db.AddInParameter(cmd, "@TransferCode", DbType.String, entity.TransferCode); db.AddInParameter(cmd, "@PsBillCode", DbType.String, entity.PsBillCode); db.AddInParameter(cmd, "@OutTime", DbType.DateTime, entity.OutTime); db.AddInParameter(cmd, "@PsResult", DbType.Int32, entity.PsResult); db.AddInParameter(cmd, "@CreateManId", DbType.Int32, entity.CreateManId); return(db.ExecuteNonQuery(cmd)); }
/// <summary> /// 读取记录列表。 /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param> public IList <WLPsOrderEntity> GetWLPsOrderList(int pagesize, int pageindex, ref int recordCount) { string sql = @"SELECT [Id], [OrderCode],[ConsignCode],[TransferCode],[PsBillCode],[OutTime],[PsResult],[CreateManId] FROM (SELECT ROW_NUMBER() OVER (ORDER BY Id desc) AS ROWNUMBER, [Id], [OrderCode],[ConsignCode],[TransferCode],[PsBillCode],[OutTime],[PsResult],[CreateManId] from dbo.[WLPsOrder] WITH(NOLOCK) WHERE 1=1 ) as temp where rownumber BETWEEN ((@PageIndex - 1) * @PageSize + 1) AND @PageIndex * @PageSize" ; string sql2 = @"Select count(1) from dbo.[WLPsOrder] with (nolock) "; IList <WLPsOrderEntity> entityList = new List <WLPsOrderEntity>(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@PageIndex", DbType.Int32, pageindex); db.AddInParameter(cmd, "@PageSize", DbType.Int32, pagesize); using (IDataReader reader = db.ExecuteReader(cmd)) { while (reader.Read()) { WLPsOrderEntity entity = new WLPsOrderEntity(); entity.Id = StringUtils.GetDbInt(reader["Id"]); entity.OrderCode = StringUtils.GetDbLong(reader["OrderCode"]); entity.ConsignCode = StringUtils.GetDbString(reader["ConsignCode"]); entity.TransferCode = StringUtils.GetDbString(reader["TransferCode"]); entity.PsBillCode = StringUtils.GetDbString(reader["PsBillCode"]); entity.OutTime = StringUtils.GetDbDateTime(reader["OutTime"]); entity.PsResult = StringUtils.GetDbInt(reader["PsResult"]); entity.CreateManId = StringUtils.GetDbInt(reader["CreateManId"]); entityList.Add(entity); } } cmd = db.GetSqlStringCommand(sql2); using (IDataReader reader = db.ExecuteReader(cmd)) { if (reader.Read()) { recordCount = StringUtils.GetDbInt(reader[0]); } else { recordCount = 0; } } return(entityList); }
/// <summary> /// 插入一条记录到表WLPsOrder,如果表中存在自增字段,则返回值为新记录的自增字段值,否则返回0 /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="wLPsOrder">待插入的实体对象</param> public int AddWLPsOrder(WLPsOrderEntity entity) { string sql = @"insert into WLPsOrder( [OrderId],[OrderCode],[ConsignCode],[TransferCode],[PsBillCode],[OutTime],[PsResult],[CreateManId])VALUES (@OrderId,@OrderCode,@ConsignCode,@TransferCode,@PsBillCode,@OutTime,@PsResult,@CreateManId); SELECT SCOPE_IDENTITY();" ; DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, entity.OrderId); db.AddInParameter(cmd, "@OrderCode", DbType.Int64, entity.OrderCode); db.AddInParameter(cmd, "@ConsignCode", DbType.String, entity.ConsignCode); db.AddInParameter(cmd, "@TransferCode", DbType.String, entity.TransferCode); db.AddInParameter(cmd, "@PsBillCode", DbType.String, entity.PsBillCode); db.AddInParameter(cmd, "@OutTime", DbType.DateTime, entity.OutTime); db.AddInParameter(cmd, "@PsResult", DbType.Int32, entity.PsResult); db.AddInParameter(cmd, "@CreateManId", DbType.Int32, entity.CreateManId); object identity = db.ExecuteScalar(cmd); if (identity == null || identity == DBNull.Value) { return(0); } return(Convert.ToInt32(identity)); }
/// <summary> /// 读取记录列表。 /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param> public IList <WLPsOrderEntity> GetWLPsOrderAll() { string sql = @"SELECT [Id], [OrderCode],[ConsignCode],[TransferCode],[PsBillCode],[OutTime],[PsResult],[CreateManId] from dbo.[WLPsOrder] WITH(NOLOCK) "; IList <WLPsOrderEntity> entityList = new List <WLPsOrderEntity>(); DbCommand cmd = db.GetSqlStringCommand(sql); using (IDataReader reader = db.ExecuteReader(cmd)) { while (reader.Read()) { WLPsOrderEntity entity = new WLPsOrderEntity(); entity.Id = StringUtils.GetDbInt(reader["Id"]); entity.OrderCode = StringUtils.GetDbLong(reader["OrderCode"]); entity.ConsignCode = StringUtils.GetDbString(reader["ConsignCode"]); entity.TransferCode = StringUtils.GetDbString(reader["TransferCode"]); entity.PsBillCode = StringUtils.GetDbString(reader["PsBillCode"]); entity.OutTime = StringUtils.GetDbDateTime(reader["OutTime"]); entity.PsResult = StringUtils.GetDbInt(reader["PsResult"]); entity.CreateManId = StringUtils.GetDbInt(reader["CreateManId"]); entityList.Add(entity); } } return(entityList); }
/// <summary> /// 更新一条WLPsOrder记录。 /// 该方法提供给界面等UI层调用 /// </summary> /// <param name="wLPsOrder">待更新的实体对象</param> /// <param name="columns">要更新的列名,不提供任何列名时默认将更新主键之外的所有列</param> public int UpdateWLPsOrder(WLPsOrderEntity wLPsOrder) { return(WLPsOrderDA.Instance.UpdateWLPsOrder(wLPsOrder)); }
/// <summary> /// 判断对象是否存在 /// </summary> /// <param name="dicEnum"></param> /// <returns></returns> public bool IsExist(WLPsOrderEntity wLPsOrder) { return(WLPsOrderDA.Instance.ExistNum(wLPsOrder) > 0); }