public bool Delete(SqlConnection conn, SqlTransaction trans, int allotOrderId) { DataTable allotGoodsDT = GetList(0, "AllotOrderId = " + allotOrderId + "", "Id desc").Tables[0]; if (allotGoodsDT.Rows.Count > 0) { StoreInGoods storeInGoodsDAL = new StoreInGoods(); foreach (DataRow dr in allotGoodsDT.Rows) { int storeInOrderId = Convert.ToInt32(dr["StoreInOrderId"]); int storeInGoodsId = Convert.ToInt32(dr["StoreInGoodsId"]); int status = Convert.ToInt32(dr["Status"]); decimal count = Convert.ToInt32(dr["Count"]); storeInGoodsDAL.UpdateField(conn, trans, storeInGoodsId, "Count = Count + " + count + ""); storeInGoodsDAL.Delete(conn, trans, " StoreInOrderId = " + storeInOrderId + " and Status = 1 "); } } StringBuilder strSql = new StringBuilder(); strSql.Append("delete from AllotGoods "); strSql.Append(" where AllotOrderId=@AllotOrderId"); SqlParameter[] parameters = { new SqlParameter("@AllotOrderId", SqlDbType.Int, 4) }; parameters[0].Value = allotOrderId; int rows = DbHelperSQL.ExecuteSql(conn, trans, strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
public bool Delete(SqlConnection conn, SqlTransaction trans, int allotOrderId) { DataTable allotGoodsDT = GetList(0, "AllotOrderId = " + allotOrderId + "", "Id desc").Tables[0]; if (allotGoodsDT.Rows.Count > 0) { StoreInGoods storeInGoodsDAL = new StoreInGoods(); foreach (DataRow dr in allotGoodsDT.Rows) { int storeInOrderId = Convert.ToInt32(dr["StoreInOrderId"]); int storeInGoodsId = Convert.ToInt32(dr["StoreInGoodsId"]); int status = Convert.ToInt32(dr["Status"]); decimal count = Convert.ToInt32(dr["Count"]); storeInGoodsDAL.UpdateField(conn, trans, storeInGoodsId, "Count = Count + " + count + ""); storeInGoodsDAL.Delete(conn, trans, " StoreInOrderId = " + storeInOrderId + " and Status = 1 "); } } StringBuilder strSql = new StringBuilder(); strSql.Append("delete from AllotGoods "); strSql.Append(" where AllotOrderId=@AllotOrderId"); SqlParameter[] parameters = { new SqlParameter("@AllotOrderId", SqlDbType.Int,4) }; parameters[0].Value = allotOrderId; int rows = DbHelperSQL.ExecuteSql(conn, trans, strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(DTcms.Model.StoreInOrder model) { using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { StringBuilder strSql = new StringBuilder(); strSql.Append("update StoreInOrder set "); strSql.Append(" CustomerId = @CustomerId , "); strSql.Append(" BeginChargingTime = @BeginChargingTime , "); strSql.Append(" ChargingTime = @ChargingTime , "); strSql.Append(" Admin = @Admin , "); strSql.Append(" ChargingCount = @ChargingCount , "); strSql.Append(" InspectionNumber = @InspectionNumber , "); strSql.Append(" AccountNumber = @AccountNumber , "); strSql.Append(" SuttleWeight = @SuttleWeight , "); strSql.Append(" Remark = @Remark "); strSql.Append(" where Id=@Id "); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int,4) , new SqlParameter("@CustomerId", SqlDbType.Int,4) , new SqlParameter("@BeginChargingTime", SqlDbType.DateTime) , new SqlParameter("@ChargingTime", SqlDbType.DateTime) , new SqlParameter("@Admin", SqlDbType.VarChar,254) , new SqlParameter("@ChargingCount", SqlDbType.Decimal,9) , new SqlParameter("@InspectionNumber", SqlDbType.VarChar,254) , new SqlParameter("@AccountNumber", SqlDbType.VarChar,254) , new SqlParameter("@SuttleWeight", SqlDbType.Decimal,9) , new SqlParameter("@Remark", SqlDbType.VarChar,254) }; parameters[0].Value = model.Id; parameters[1].Value = model.CustomerId; parameters[2].Value = model.BeginChargingTime; parameters[3].Value = model.ChargingTime; parameters[4].Value = model.Admin; parameters[5].Value = model.ChargingCount; parameters[6].Value = model.InspectionNumber; parameters[7].Value = model.AccountNumber; parameters[8].Value = model.SuttleWeight; parameters[9].Value = model.Remark; DbHelperSQL.ExecuteSql(conn, trans, strSql.ToString(), parameters); #region 单价 StoreInUnitPrice unitPriceDAL = new StoreInUnitPrice(); unitPriceDAL.Delete(conn, trans, model.Id); if (model.UnitPrices.Count > 0) { foreach (Model.StoreInUnitPrice unitPrice in model.UnitPrices) { unitPrice.StoreInOrderId = model.Id; unitPriceDAL.Add(conn, trans, unitPrice); } } #endregion #region 费用 StoreInCost costDAL = new StoreInCost(); costDAL.Delete(conn, trans, model.Id); if (model.StoreInCosts.Count > 0) { foreach (Model.StoreInCost cost in model.StoreInCosts) { cost.StoreInOrderId = model.Id; costDAL.Add(conn, trans, cost); } } #endregion #region 入库货物==================== StoreInGoods storeInGoodsDAL = new StoreInGoods(); storeInGoodsDAL.Delete(conn, trans, model.Id); if (model.StoreInGoods.Count > 0) { StoreWaitingGoods waitingGoodsDAL = new StoreWaitingGoods(); foreach (Model.StoreInGoods storeInGoods in model.StoreInGoods) { storeInGoods.StoreInOrderId = model.Id; storeInGoodsDAL.Add(conn, trans, storeInGoods); waitingGoodsDAL.UpdateStatus(conn, trans, storeInGoods.StoreWaitingGoodsId, 1); } } #endregion trans.Commit(); } catch { trans.Rollback(); return false; } } } return true; }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(DTcms.Model.StoreInOrder model) { using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { StringBuilder strSql = new StringBuilder(); strSql.Append("update StoreInOrder set "); strSql.Append(" CustomerId = @CustomerId , "); strSql.Append(" BeginChargingTime = @BeginChargingTime , "); strSql.Append(" ChargingTime = @ChargingTime , "); strSql.Append(" Admin = @Admin , "); strSql.Append(" ChargingCount = @ChargingCount , "); strSql.Append(" InspectionNumber = @InspectionNumber , "); strSql.Append(" AccountNumber = @AccountNumber , "); strSql.Append(" SuttleWeight = @SuttleWeight , "); strSql.Append(" Remark = @Remark "); strSql.Append(" where Id=@Id "); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4), new SqlParameter("@CustomerId", SqlDbType.Int, 4), new SqlParameter("@BeginChargingTime", SqlDbType.DateTime), new SqlParameter("@ChargingTime", SqlDbType.DateTime), new SqlParameter("@Admin", SqlDbType.VarChar, 254), new SqlParameter("@ChargingCount", SqlDbType.Decimal, 9), new SqlParameter("@InspectionNumber", SqlDbType.VarChar, 254), new SqlParameter("@AccountNumber", SqlDbType.VarChar, 254), new SqlParameter("@SuttleWeight", SqlDbType.Decimal, 9), new SqlParameter("@Remark", SqlDbType.VarChar, 254) }; parameters[0].Value = model.Id; parameters[1].Value = model.CustomerId; parameters[2].Value = model.BeginChargingTime; parameters[3].Value = model.ChargingTime; parameters[4].Value = model.Admin; parameters[5].Value = model.ChargingCount; parameters[6].Value = model.InspectionNumber; parameters[7].Value = model.AccountNumber; parameters[8].Value = model.SuttleWeight; parameters[9].Value = model.Remark; DbHelperSQL.ExecuteSql(conn, trans, strSql.ToString(), parameters); #region 单价 StoreInUnitPrice unitPriceDAL = new StoreInUnitPrice(); unitPriceDAL.Delete(conn, trans, model.Id); if (model.UnitPrices.Count > 0) { foreach (Model.StoreInUnitPrice unitPrice in model.UnitPrices) { unitPrice.StoreInOrderId = model.Id; unitPriceDAL.Add(conn, trans, unitPrice); } } #endregion #region 费用 StoreInCost costDAL = new StoreInCost(); costDAL.Delete(conn, trans, model.Id); if (model.StoreInCosts.Count > 0) { foreach (Model.StoreInCost cost in model.StoreInCosts) { cost.StoreInOrderId = model.Id; costDAL.Add(conn, trans, cost); } } #endregion #region 入库货物==================== StoreInGoods storeInGoodsDAL = new StoreInGoods(); storeInGoodsDAL.Delete(conn, trans, model.Id); if (model.StoreInGoods.Count > 0) { StoreWaitingGoods waitingGoodsDAL = new StoreWaitingGoods(); foreach (Model.StoreInGoods storeInGoods in model.StoreInGoods) { storeInGoods.StoreInOrderId = model.Id; storeInGoodsDAL.Add(conn, trans, storeInGoods); waitingGoodsDAL.UpdateStatus(conn, trans, storeInGoods.StoreWaitingGoodsId, 1); } } #endregion trans.Commit(); } catch { trans.Rollback(); return(false); } } } return(true); }