Ejemplo n.º 1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(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("insert into StoreOutOrder(");
                        strSql.Append("CustomerId,StoreInOrderId,CreateTime,Admin,TotalMoney,InvoiceMoney,HasBeenInvoiced,Status,Remark,StoredOutTime,Count,UnitPrice,BeginChargingTime,EndChargingTime,UnitPriceDetails");
                        strSql.Append(") values (");
                        strSql.Append("@CustomerId,@StoreInUnitPriceStoreInOrderId,@CreateTime,@Admin,@TotalMoney,@InvoiceMoney,@HasBeenInvoiced,@Status,@Remark,@StoredOutTime,@Count,@UnitPrice,@BeginChargingTime,@EndChargingTime,@UnitPriceDetails");
                        strSql.Append(") ");
                        strSql.Append(";select @@IDENTITY");
                        SqlParameter[] parameters =
                        {
                            new SqlParameter("@CustomerId",                     SqlDbType.Int,         4),
                            new SqlParameter("@StoreInUnitPriceStoreInOrderId", SqlDbType.Int,         4),
                            new SqlParameter("@CreateTime",                     SqlDbType.DateTime),
                            new SqlParameter("@Admin",                          SqlDbType.VarChar,   254),
                            new SqlParameter("@TotalMoney",                     SqlDbType.Decimal),
                            new SqlParameter("@InvoiceMoney",                   SqlDbType.Decimal),
                            new SqlParameter("@HasBeenInvoiced",                SqlDbType.Bit,         1),
                            new SqlParameter("@Status",                         SqlDbType.Int,         4),
                            new SqlParameter("@Remark",                         SqlDbType.VarChar,   254),
                            new SqlParameter("@StoredOutTime",                  SqlDbType.DateTime),
                            new SqlParameter("@Count",                          SqlDbType.Decimal),
                            new SqlParameter("@UnitPrice",                      SqlDbType.Decimal),
                            new SqlParameter("@BeginChargingTime",              SqlDbType.DateTime),
                            new SqlParameter("@EndChargingTime",                SqlDbType.DateTime),
                            new SqlParameter("@UnitPriceDetails",               SqlDbType.VarChar, 1000)
                        };

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

                        object obj = DbHelperSQL.GetSingle(conn, trans, strSql.ToString(), parameters); //带事务
                        model.Id = Convert.ToInt32(obj);

                        new StoreInOrder().UpdateField(model.StoreInOrderId, "ChargingCount = ChargingCount - " + model.Count + "");


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

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

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

                        return(false);
                    }
                }
            }

            return(model.Id > 0);
        }
Ejemplo n.º 2
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);
        }