Ejemplo n.º 1
0
        /// <summary>
        /// 创建单据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static string CreateStorageDoc(StorageDoc model, string userid, string operateip, string clientid)
        {
            string        docid = Guid.NewGuid().ToString();
            SqlConnection conn  = new SqlConnection(OrdersDAL.ConnectionString);

            conn.Open();
            SqlTransaction tran = conn.BeginTransaction();

            try
            {
                bool bl = OrdersDAL.AddStorageDoc(docid, model.DocType, model.TotalMoney, model.CityCode, model.Address, model.Remark, userid, operateip, clientid, tran);
                if (bl)
                {
                    //单据明细
                    foreach (var detail in model.Details)
                    {
                        if (!OrdersDAL.AddStorageDocDetail(docid, detail.AutoID, detail.ProductDetailID, detail.Quantity, detail.Price, detail.TotalMoney, detail.BatchCode, clientid, tran))
                        {
                            tran.Rollback();
                            conn.Dispose();
                            return("");
                        }
                    }
                    tran.Commit();
                    conn.Dispose();
                    return(docid);
                }
                else
                {
                    tran.Rollback();
                    conn.Dispose();
                    return("");
                }
            }
            catch (Exception ex)
            {
                tran.Rollback();
                conn.Dispose();
                return("");
            }
        }