using System;
using XYY.Core.Standard.Data.Infrastructure;
using XYY.Model.Standard.Channel;

namespace XYY.Data.Standard.Channel
{
    public interface ILogistics_ChannelRepository : IBaseRepository<Logistics_Channel>
    {
        [NonTrans]
        int GetPackagePrintQty(string key);
    }

    public class Logistics_ChannelRepository : BaseRepository<Logistics_Channel>, ILogistics_ChannelRepository
    {
        public Logistics_ChannelRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
        {

        }

        [NonTrans]
        public int GetPackagePrintQty(string key)
        {
            using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(_unitOfWork.ConnectionAddress))
            {
                conn.Open();
                using (System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand("GetPackagePrintQty", conn))
                {
                    try
                    {

                        command.CommandType = System.Data.CommandType.StoredProcedure;
                        command.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CustomerOcrderNo", key));
                        var val = command.ExecuteScalar();
                        if (val == null || val == DBNull.Value)
                            throw new Exception("数据服务出错");
                        else
                            return (int)val;
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        conn.Close();

                    }
                }
            };
        }
    }
}
