using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XYY.Core.Standard.Data.Infrastructure;
using XYY.Model.Standard.Order;
using Dapper;

namespace XYY.Data.Standard.Order
{
    public interface IOrder_OrderPrintQtyRepository : IBaseRepository<Order_OrderPrintQty>
    {
        int GetPackagePrintQty(string customerOrderNo);
        List<string> FindAUArea(string zipCode, string state);
    }
    public class Order_OrderPrintQtyRepository : BaseRepository<Order_OrderPrintQty>, IOrder_OrderPrintQtyRepository
    {
        public Order_OrderPrintQtyRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
        {
        }

        public int GetPackagePrintQty(string customerOrderNo)
        {

            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("@CustomerOcrderNo", System.Data.SqlDbType.NVarChar).Value = customerOrderNo;
                        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();

                    }
                }
            };
        }
        public List<string> FindAUArea(string zipCode, string state)
        {
            string sql = $"select AreaCode from Au_Areas(nolock) where zipCode='{zipCode}'";
            return _unitOfWork.Connection.Query<string>(sql).ToList();
        }

    }
}
