Ejemplo n.º 1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(DTcms.Model.StoreOutOrder model)
        {
            using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString))
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        StringBuilder strSql = new StringBuilder();
                        strSql.Append("update StoreOutOrder set ");
                        strSql.Append(" CustomerId = @CustomerId , ");
                        strSql.Append(" StoreInOrderId = @StoreInOrderId , ");
                        strSql.Append(" Admin = @Admin , ");
                        strSql.Append(" TotalMoney = @TotalMoney , ");
                        strSql.Append(" InvoiceMoney = @InvoiceMoney , ");
                        strSql.Append(" Status = @Status , ");
                        strSql.Append(" StoredOutTime = @StoredOutTime , ");
                        strSql.Append(" Count = @Count , ");
                        strSql.Append(" UnitPrice = @UnitPrice , ");
                        strSql.Append(" Remark = @Remark,  ");
                        strSql.Append(" BeginChargingTime = @BeginChargingTime , ");
                        strSql.Append(" EndChargingTime = @EndChargingTime , ");
                        strSql.Append(" UnitPriceDetails = @UnitPriceDetails  ");
                        strSql.Append(" where Id=@Id ");

                        SqlParameter[] parameters =
                        {
                            new SqlParameter("@Id",                SqlDbType.Int,         4),
                            new SqlParameter("@CustomerId",        SqlDbType.Int,         4),
                            new SqlParameter("@StoreInOrderId",    SqlDbType.Int,         4),
                            new SqlParameter("@Admin",             SqlDbType.VarChar,   254),
                            new SqlParameter("@TotalMoney",        SqlDbType.Decimal),
                            new SqlParameter("@InvoiceMoney",      SqlDbType.Decimal),
                            new SqlParameter("@Status",            SqlDbType.Int,         4),
                            new SqlParameter("@StoredOutTime",     SqlDbType.DateTime),
                            new SqlParameter("@Count",             SqlDbType.Decimal),
                            new SqlParameter("@UnitPrice",         SqlDbType.Decimal),
                            new SqlParameter("@Remark",            SqlDbType.VarChar,   254),
                            new SqlParameter("@BeginChargingTime", SqlDbType.DateTime),
                            new SqlParameter("@EndChargingTime",   SqlDbType.DateTime),
                            new SqlParameter("@UnitPriceDetails",  SqlDbType.VarChar, 1000)
                        };

                        parameters[0].Value  = model.Id;
                        parameters[1].Value  = model.CustomerId;
                        parameters[2].Value  = model.StoreInOrderId;
                        parameters[3].Value  = model.Admin;
                        parameters[4].Value  = model.TotalMoney;
                        parameters[5].Value  = model.InvoiceMoney;
                        parameters[6].Value  = model.Status;
                        parameters[7].Value  = model.StoredOutTime;
                        parameters[8].Value  = model.Count;
                        parameters[9].Value  = model.UnitPrice;
                        parameters[10].Value = model.Remark;
                        parameters[11].Value = model.BeginChargingTime;
                        parameters[12].Value = model.EndChargingTime;
                        parameters[13].Value = model.UnitPriceDetails;

                        DbHelperSQL.ExecuteSql(conn, trans, strSql.ToString(), parameters);

                        #region 费用====================

                        StoreOutCost storeOutCostDAL = new StoreOutCost();
                        storeOutCostDAL.Delete(conn, trans, model.Id);
                        if (model.StoreOutCosts.Count > 0)
                        {
                            foreach (Model.StoreOutCost storeInCost in model.StoreOutCosts)
                            {
                                storeInCost.StoreOutOrderId = model.Id;
                                storeOutCostDAL.Add(conn, trans, storeInCost);
                            }
                        }
                        #endregion

                        #region 出库货物====================
                        StoreOutGoods storeOutGoodsDAL = new StoreOutGoods();
                        storeOutGoodsDAL.Delete(conn, trans, model.Id);
                        if (model.StoreOutGoods.Count > 0)
                        {
                            foreach (Model.StoreOutGoods storeOutGoods in model.StoreOutGoods)
                            {
                                storeOutGoods.StoreOutOrderId = model.Id;
                                storeOutGoodsDAL.Add(conn, trans, storeOutGoods);
                            }
                        }
                        #endregion


                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        return(false);
                    }
                }
            }

            return(true);
        }