public BAT_Class_Library.Buffer GetPaletteInfoByProductId(int productID)
        {
            BAT_Class_Library.Buffer buffer;

            using (var conn = new SqlConnection(conStr))
            {
                conn.Open();
                buffer = conn.QuerySingleOrDefault <BAT_Class_Library.Buffer>(
                    @"SELECT * 
	                    FROM Buffers a(NOLOCK)
	                    WHERE LastPaletteInfo = @ProductId;"    ,
                    new { ProductId = productID },
                    commandType: System.Data.CommandType.Text);
                conn.Close();
            }

            return(buffer);
        }
        public Address GetFirstRowIsEmpty(string addressCode)
        {
            Address address;

            using (var conn = new SqlConnection(conStr))
            {
                conn.Open();
                address = conn.QuerySingleOrDefault <Address>(
                    @"SELECT * 
	                    FROM Addresses a(NOLOCK)
	                    WHERE Direction ='WH_IN' 
	                    AND Code = @Code;"    ,
                    new { Code = addressCode },
                    commandType: System.Data.CommandType.Text);
                conn.Close();
            }

            return(address);
        }
        public Address GetFirstRowIsEmptyByProductId(int productID)
        {
            Address address;

            using (var conn = new SqlConnection(conStr))
            {
                conn.Open();
                address = conn.QuerySingleOrDefault <Address>(
                    @"SELECT * 
	                    FROM Addresses a(NOLOCK)
	                    WHERE Direction ='WH_IN' 
	                    AND DependedProductId = @ProductId;"    ,
                    new { ProductId = productID },
                    commandType: System.Data.CommandType.Text);
                conn.Close();
            }

            return(address);
        }
        public bool GetFirstRowIsEmptyByAddressCode(string code, string location)
        {
            //task başlamadan(assign etmeden) önce ki kontrolleri yapmayı amaçlar
            bool IsEmpty;

            using (var conn = new SqlConnection(conStr))
            {
                conn.Open();
                IsEmpty = conn.QuerySingleOrDefault <bool>(
                    @"SELECT FirstRowIsEmpty FROM Addresses a(NOLOCK)
	                    WHERE Direction = @Direction 
	                    AND Code = @Code;"    ,
                    new { Direction = location, Code = code },
                    commandType: System.Data.CommandType.Text);
                conn.Close();
            }

            return(IsEmpty);
        }
        public Shuttle GetMoveableShuttleByAddress(string code)
        {
            Shuttle shuttle;


            //TODO: sp ye çevir, adrese göre ayarla
            using (var conn = new SqlConnection(conStr))
            {
                conn.Open();
                shuttle = conn.QuerySingleOrDefault <Shuttle>(
                    @"  SELECT TOP 1 s.* 
                        FROM Shuttles s(NOLOCK)
                        LEFT OUTER JOIN Addresses a(NOLOCK) ON s.LastAddress = a.Code
                        WHERE a.Direction = 'WH_OUT'
                          AND s.IsActive = 1
                          and s.Status = 'WAITING'
                          and s.Id NOT IN (SELECT ShuttleId FROM AddressDedicatedShuttles)",
                    new { Code = code }, //code parametresi mesafeye göre seçim için eklenecek
                    commandType: System.Data.CommandType.Text);
                conn.Close();
            }

            return(shuttle);
        }