Ejemplo n.º 1
0
 /// <summary>
 /// 添加订单详细信息
 /// </summary>
 /// <param name="name"></param>
 /// <param name="goods"></param>
 /// <param name="gcnt"></param>
 /// <returns></returns>
 public static bool AddOrderDetail(string name, List <Goods> goods, List <int> gcnt)
 {
     try
     {
         string                  sql   = "select orderID from tb_order where customerName=?name order by orderDate limit 0,1;";
         MySqlParameter          para  = new MySqlParameter("?name", name);
         string                  id    = DAL_MysqlHelper.ExecuteDataSet(sql, para).Tables[0].Rows[0][0].ToString();
         List <string>           sqls  = new List <string>();
         List <MySqlParameter[]> paras = new List <MySqlParameter[]>();
         for (int i = 0; i < goods.Count; i++)
         {
             var              _goods = goods.ElementAt(i);
             string           _sql   = "insert into tb_orderdetail values(?orderID,?goodsID,?count);";
             MySqlParameter[] _para  = { new MySqlParameter("?orderID", id), new MySqlParameter("?goodsID", _goods.Id), new MySqlParameter("?count", gcnt.ElementAt(i)) };
             sqls.Add(_sql);
             paras.Add(_para);
         }
         bool ret = DAL_MysqlHelper.ExecuteNoQueryTran(sqls, paras);
         return(ret);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 一次删除多个商品,中途失败自动回滚(删除大量商品的情况,多次调用DeleteGood需要多次连接数据库)
 /// </summary>
 /// <param name="ids"></param>
 /// <returns></returns>
 public static bool DeleteGoods(List <string> ids)
 {
     try
     {
         List <String>           sqls  = new List <string>();
         List <MySqlParameter[]> paras = new List <MySqlParameter[]>();
         foreach (string id in ids)
         {
             string           sql  = "delete from tb_goods where goodsID=?id;";
             MySqlParameter[] para = { new MySqlParameter("?id", id) };
             sqls.Add(sql);
             paras.Add(para);
         }
         bool ret = DAL_MysqlHelper.ExecuteNoQueryTran(sqls, paras);
         return(ret);
     }
     catch (Exception e)
     {
         throw e;
     }
 }