Index: trunk/SQL/StoredProcedures/sp_GetClientsWithNoContact.txt
===================================================================
--- trunk/SQL/StoredProcedures/sp_GetClientsWithNoContact.txt (revision 669)
+++ trunk/SQL/StoredProcedures/sp_GetClientsWithNoContact.txt (revision 669)
@@ -0,0 +1,43 @@
+-- ================================================
+-- Template generated from Template Explorer using:
+-- Create Procedure (New Menu).SQL
+--
+-- Use the Specify Values for Template Parameters 
+-- command (Ctrl-Shift-M) to fill in the parameter 
+-- values below.
+--
+-- This block of comments will not be included in
+-- the definition of the procedure.
+-- ================================================
+SET ANSI_NULLS ON
+GO
+SET QUOTED_IDENTIFIER ON
+GO
+-- =============================================
+-- Author:		<Author,,Name>
+-- Create date: <Create Date,,>
+-- Description:	<Description,,>
+-- =============================================
+CREATE PROCEDURE  sp_GetClientsWithNoContact
+	-- Add the parameters for the stored procedure here
+	@agencyId int,
+	@numberOfDaysStart int, 
+	@numberOfDaysEnd int
+AS
+BEGIN
+	-- SET NOCOUNT ON added to prevent extra result sets from
+	-- interfering with SELECT statements.
+	SET NOCOUNT ON;
+
+	select top 2000 K.* from KLIENCI K 
+    left join dbo.KONTAKTY K2 on K.CustomerId = K2.CustomerID 
+    left join dbo.AGENCI A on K.UserName = A.Symbol 
+    group by K.NameInMagazine, K.AgentExpo, K.kodKlienta, K.CustomerID, K.FirstName, K.LastName, K.OrganizationName, 
+    K.Address, K.City, K.State, K.PostalCode, K.Country, K.Nip, K.ContactName, K.PhoneNumber, K.FaxNumber, 
+    K.Note, K.data, K.Adres_Fkatura, K.Adres_Kor, K.Platnik_VAT, K.Aktywny,  
+    K.Email, K.UserName, K.Last_Modify, K.Modify_User, K.http, K.VIES, K.regon, K.krs, K.osw_nr,K.osw_wazne_do,K.Old_ID, K.NipKraj, A.Id_agencji 
+    HAVING datediff(day,max(K2.data),getdate()) > @numberOfDaysStart AND datediff(day,max(K2.data),getdate()) < @numberOfDaysEnd 
+    AND A.Id_agencji = @agencyId order by datediff(day,max(K2.data),getdate()) desc
+
+END
+GO
Index: trunk/BazaReklam/ClientsForm.cs
===================================================================
--- trunk/BazaReklam/ClientsForm.cs (revision 614)
+++ trunk/BazaReklam/ClientsForm.cs (revision 669)
@@ -7,5 +7,4 @@
 using System.IO;
 using System.Text.RegularExpressions;
-using Baza_Reklam.Classes;
 using Baza_Reklam.Classes.Helpers;
 using Baza_Reklam.Classes.Interfaces;
@@ -467,4 +466,5 @@
                                 command.CommandText += " where K.UserName=@agent order by data desc";
                                 command.Parameters.AddWithValue("@agent", User.Instance().Symbol_agenta);
+                                command.CommandType = CommandType.Text;
                                 sqlDataAdapter.Fill(rEKLAMADataSet.KLIENCI);
                                 clientsDataGridView.Refresh();
@@ -489,4 +489,5 @@
                                         command.CommandText += " where K.UserName=@agent AND K.Aktywny=1 order by K.data desc";
                                         command.Parameters.AddWithValue("@agent", User.Instance().Symbol_agenta);
+                                        command.CommandType = CommandType.Text;
                                         sqlDataAdapter.Fill(rEKLAMADataSet.KLIENCI);
                                         clientsDataGridView.Refresh();
@@ -501,4 +502,5 @@
                                         command.CommandText += " where K.AgentExpo=@agent AND K.Aktywny=1 order by K.data desc";
                                         command.Parameters.AddWithValue("@agent", User.Instance().Symbol_agenta);
+                                        command.CommandType = CommandType.Text;
                                         sqlDataAdapter.Fill(rEKLAMADataSet.KLIENCI);
                                         clientsDataGridView.Refresh();
@@ -513,4 +515,5 @@
                                         command.CommandText += " where K.UserName=@agent AND K.Aktywny=0 order by K.data desc";
                                         command.Parameters.AddWithValue("@agent", User.Instance().Symbol_agenta);
+                                        command.CommandType = CommandType.Text;
                                         sqlDataAdapter.Fill(rEKLAMADataSet.KLIENCI);
                                         clientsDataGridView.Refresh();
@@ -525,4 +528,5 @@
                                         command.CommandText += " where K.AgentExpo=@agent AND K.Aktywny=0 order by K.data desc";
                                         command.Parameters.AddWithValue("@agent", User.Instance().Symbol_agenta);
+                                        command.CommandType = CommandType.Text;
                                         sqlDataAdapter.Fill(rEKLAMADataSet.KLIENCI);
                                         clientsDataGridView.Refresh();
@@ -540,4 +544,5 @@
                                 command.CommandText += " left join dbo.AGENCI A on K.UserName = A.Symbol where A.Id_agencji = @idAgencji";
                                 command.Parameters.AddWithValue("@idAgencji", e.Node.Name);
+                                command.CommandType = CommandType.Text;
                                 sqlDataAdapter.Fill(rEKLAMADataSet.KLIENCI);
                                 clientsDataGridView.Refresh();
@@ -552,4 +557,5 @@
                                 command.CommandText += " on K.UserName = A.Symbol where K2.ID_KL_KLIENCI is null  AND A.Id_agencji = @idAgencji";
                                 command.Parameters.AddWithValue("@idAgencji", e.Node.Name);
+                                command.CommandType = CommandType.Text;
                                 sqlDataAdapter.Fill(rEKLAMADataSet.KLIENCI);
                                 clientsDataGridView.Refresh();
@@ -564,4 +570,5 @@
                                 command.CommandText += " on K.UserName = A.Symbol where K.aktywny=1 AND KT.id_klienci_tytul is null  AND A.Id_agencji = @idAgencji";
                                 command.Parameters.AddWithValue("@idAgencji", e.Node.Name);
+                                command.CommandType = CommandType.Text;
                                 sqlDataAdapter.Fill(rEKLAMADataSet.KLIENCI);
                                 clientsDataGridView.Refresh();
@@ -592,4 +599,5 @@
                                     command.CommandText += " on K.UserName = A.Symbol where K2.ID_KL_KLIENCI is null  AND A.Symbol = @symAgenta";
                                     command.Parameters.AddWithValue("@symAgenta", e.Node.Name);
+                                    command.CommandType = CommandType.Text;
                                     sqlDataAdapter.Fill(rEKLAMADataSet.KLIENCI);
                                     clientsDataGridView.Refresh();
@@ -604,4 +612,5 @@
                                     command.CommandText += " on K.UserName = A.Symbol where K.aktywny=1 AND KT.id_klienci_tytul is null  AND A.Symbol = @symAgenta";
                                     command.Parameters.AddWithValue("@symAgenta", e.Node.Name);
+                                    command.CommandType = CommandType.Text;
                                     sqlDataAdapter.Fill(rEKLAMADataSet.KLIENCI);
                                     clientsDataGridView.Refresh();
@@ -627,4 +636,5 @@
                                     command.CommandText += " where UserName=@agent";
                                     command.Parameters.AddWithValue("@agent", e.Node.Name);
+                                    command.CommandType = CommandType.Text;
                                     sqlDataAdapter.Fill(rEKLAMADataSet.KLIENCI);
                                     clientsDataGridView.Refresh();
@@ -636,23 +646,14 @@
 
                                     rEKLAMADataSet.KLIENCI.Clear();
-                                    command.CommandText += "left join dbo.KONTAKTY K2 on K.CustomerId = K2.CustomerID " +
-                                        "left join dbo.AGENCI A on K.UserName = A.Symbol " +
-                                        "group by K.AgentExpo, K.kodKlienta, K.CustomerID, K.FirstName, K.LastName, K.OrganizationName, " +
-                                        "K.Address, K.City, K.State, K.PostalCode, K.Country, K.Nip, K.ContactName, K.PhoneNumber, K.FaxNumber," +
-                                        "K.Note, K.data, K.Adres_Fkatura, K.Adres_Kor, K.Platnik_VAT, K.Aktywny,  " +
-                                        "K.Email, K.UserName, K.Last_Modify, K.Modify_User, K.http, K.VIES, K.regon, K.krs, K.osw_nr,K.osw_wazne_do,K.Old_ID, K.NipKraj, A.Id_agencji " +
-                                        "HAVING datediff(day,max(K2.data),getdate()) > @param1 AND datediff(day,max(K2.data),getdate()) <@param2 " +
-                                        "AND A.Id_agencji = @idAgencji order by datediff(day,max(K2.data),getdate()) desc";
-                                    command.Parameters.AddWithValue("@idAgencji", e.Node.Parent.Parent.Name);
-                                    command.Parameters.AddWithValue("@param1", e.Node.Name);
-
+                                    
+                                    command.CommandText = "sp_GetClientsWithNoContact";
+                                    command.CommandType = CommandType.StoredProcedure;
+
+                                    command.Parameters.AddWithValue("@agencyId", e.Node.Parent.Parent.Name);
+                                    command.Parameters.AddWithValue("@numberOfDaysStart", e.Node.Name);
                                     if (e.Node.NextNode != null)
-                                    {
-                                        command.Parameters.AddWithValue("@param2", e.Node.NextNode.Name);
-                                    }
+                                        command.Parameters.AddWithValue("@numberOfDaysEnd", e.Node.NextNode.Name);
                                     else
-                                    {
-                                        command.Parameters.AddWithValue("@param2", "9999");
-                                    }
+                                        command.Parameters.AddWithValue("@numberOfDaysEnd", 9999);
 
                                     sqlDataAdapter.Fill(rEKLAMADataSet.KLIENCI);
@@ -760,4 +761,5 @@
 
             rEKLAMADataSet.KLIENCI.Clear();
+            command.CommandType = CommandType.Text;
 
             sqlDataAdapter.Fill(rEKLAMADataSet.KLIENCI);
