using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Linq;
using MercatorApi;
using MercatorExtensions;
using MercatorUi;
using MercatorDatabase;
namespace SigXlead
{
public class Customizer : MercatorUi.ICustomizers.IStringUpdater, MercatorUi.ICustomizers.ISqlCommandUpdaterWithContextInfo
{
public string StringUpdate(string s)
{
if (MercatorUi.Globals.IsMercatorPenguinServer)
{
s = @"declare @t_nom1 char(50),@t_nom2 char(50),@t_nom3 char(50)
declare @t_email1 char(50),@t_email2 char(50),@t_email3 char(50)
select top 1 @t_nom1=isnull(t_nom,''),@t_email1=isnull(t_email,'') from TACT inner join TACTSIG on (module='XLEAD') and (id_tact=t_id) where (id_sig=@idSig) order by t_nom
select @t_nom2=isnull(t_nom,''),@t_email2=isnull(t_email,'') from TACT inner join TACTSIG on (module='XLEAD') and (id_tact=t_id) where (id_sig=@idSig) order by t_nom OFFSET 1 ROWS FETCH NEXT 1 ROWS ONLY
select @t_nom3=isnull(t_nom,''),@t_email3=isnull(t_email,'') from TACT inner join TACTSIG on (module='XLEAD') and (id_tact=t_id) where (id_sig=@idSig) order by t_nom OFFSET 2 ROWS FETCH NEXT 1 ROWS ONLY
"
+ s.Replace(" from ", ",@t_nom1 as t_nom1,@t_email1 as t_email1,@t_nom2 as t_nom2,@t_email2 as t_email2,@t_nom3 as t_nom3,@t_email3 as t_email3 from ");
}
return s;
}
public void SqlCommandUpdateWithContextInfo(System.Data.SqlClient.SqlCommand cmd, object contextInfo)
{
if (MercatorUi.Globals.IsMercatorPenguinServer)
{
DataRow drSig = (DataRow)contextInfo;
cmd.CommandText += @"
if @isNew=0 delete TACT from TACTSIG where (module='XLEAD') and (id_tact=t_id) and (id_sig=@x_id)
if @t_nom1<>''
begin
declare @t_id1 char(10)
set @t_id1=right(newid(),10)
insert into TACT (t_id,t_nom,t_email,t_langue) values (@t_id1,@t_nom1,@t_email1,'F')
insert into TACTSIG (id_tactsig,module,id_tact,id_sig) values (right(newid(),10),'XLEAD',@t_id1,@x_id)
end
if @t_nom2<>''
begin
declare @t_id2 char(10)
set @t_id2=right(newid(),10)
insert into TACT (t_id,t_nom,t_email,t_langue) values (@t_id2,@t_nom2,@t_email2,'F')
insert into TACTSIG (id_tactsig,module,id_tact,id_sig) values (right(newid(),10),'XLEAD',@t_id2,@x_id)
end
if @t_nom3<>''
begin
declare @t_id3 char(10)
set @t_id3=right(newid(),10)
insert into TACT (t_id,t_nom,t_email,t_langue) values (@t_id3,@t_nom3,@t_email3,'F')
insert into TACTSIG (id_tactsig,module,id_tact,id_sig) values (right(newid(),10),'XLEAD',@t_id3,@x_id)
end";
}
}
}
}