function printbyid(sId) {
var oPrn = document.getElementById(sId);
var oWin = window.open('', "quickprint");
oWin.document.writeln(oPrn.innerHTML);
oWin.document.close();
oWin.focus();
oWin.print();
oWin.close();
}
< div id="sprint" >
....
< / div >
< input type="button" value="Printeaza Raport" onclick="printbyid('sprint');" / >
Thursday, December 30, 2010
Search stored procedures with some words
select object_name(id),* from syscomments where text like '%IBAN%'
cautare fisiere pe hard-disk
create table #Exista (Id int, Filepath varchar(512), Exista bit)
insert into #Exista(ID,FilePath)
select Id, replace(FilePath,'/','') from Document where TipDocumentaFK = 16 and DocTemplateFK <>21
create table #Res (ExistaFis bit, EsteDir bit,ExistaParinte bit)
declare @Id int, @filePath varchar(512), @res bit
declare crs cursor for select Id, FilePath from #Exista
open crs
fetch next from crs into @Id, @filePath
while @@fetch_status = 0
begin
set @res = -1
truncate table #Res
insert into #Res exec master..xp_fileexist @filePath
select @res = ExistaFis from #Res
if @res <> - 1
update #Exista set Exista = @res where Id = @Id
fetch next from crs into @Id, @filePath
end
close crs
deallocate crs
select * from #Exista where Exista = 0
insert into #Exista(ID,FilePath)
select Id, replace(FilePath,'/','') from Document where TipDocumentaFK = 16 and DocTemplateFK <>21
create table #Res (ExistaFis bit, EsteDir bit,ExistaParinte bit)
declare @Id int, @filePath varchar(512), @res bit
declare crs cursor for select Id, FilePath from #Exista
open crs
fetch next from crs into @Id, @filePath
while @@fetch_status = 0
begin
set @res = -1
truncate table #Res
insert into #Res exec master..xp_fileexist @filePath
select @res = ExistaFis from #Res
if @res <> - 1
update #Exista set Exista = @res where Id = @Id
fetch next from crs into @Id, @filePath
end
close crs
deallocate crs
select * from #Exista where Exista = 0
Foreach printre baze de date
create table #tmpUse (
ProcName varchar(128),
DBName varchar(128)
)
EXEC master.sys.sp_MSforeachdb "USE [?];insert #tmpUse select object_name(id),db_name() from syscomments where lower(text) like '%opendatasource%'"
select object_name(id), * from syscomments where lower(text) like '%opendatasource%'
select object_name(id), * from syscomments where lower(text) like '%openrowset%'
select object_name(id), * from syscomments where lower(text) like '%openquery%'
ProcName varchar(128),
DBName varchar(128)
)
EXEC master.sys.sp_MSforeachdb "USE [?];insert #tmpUse select object_name(id),db_name() from syscomments where lower(text) like '%opendatasource%'"
select object_name(id), * from syscomments where lower(text) like '%opendatasource%'
select object_name(id), * from syscomments where lower(text) like '%openrowset%'
select object_name(id), * from syscomments where lower(text) like '%openquery%'
Sunday, December 19, 2010
Saturday, December 18, 2010
c# format date
using System.Globalization;
Thursday, December 16, 2010
Force connection to remote server
Force connection to remote server when the maximum allowed number of users was exceeded:
mstsc /admin -v:192.163.1.1 /f -console
mstsc /admin -v:192.163.1.1 /f -console
Tuesday, December 14, 2010
Thursday, December 9, 2010
Print the content of a DIV using javascript
<head>
<style type="text/css">
@media print
{
#non-printable { display: none; }
#printable { display: block; }
}
</style>
</head>
<body>
<div id="printable">
The content of the page that needs to be printed.
</div>
<div id="non-printable">
<a href="javascript:void(0);" onclick="javascript:window.print();">Print Content</a>
</div>
</body>
<style type="text/css">
@media print
{
#non-printable { display: none; }
#printable { display: block; }
}
</style>
</head>
<body>
<div id="printable">
The content of the page that needs to be printed.
</div>
<div id="non-printable">
<a href="javascript:void(0);" onclick="javascript:window.print();">Print Content</a>
</div>
</body>
Friday, December 3, 2010
CNP validation
CNP - Cod Numeric Personal
Codul Numeric Personal constituie numarul de ordine atribuit de Evidenta Populatiei unui individ la nastere.Conform articolului 5 din Legea nr.105 din 25 septembrie 1996 privind evidenta populatiei si cartea de identitate, fiecarei persoane fizice i se atribuie, incepand de la nastere, un cod numeric personal care se inscrie in actele si certificatele de stare civila si se preia in celelalte acte cu caracter oficial, emise pe numele persoanei respective, precum si in Registrul permanent de evidenta a populatiei.
Codul numeric personal reprezinta un numar semnificativ ce individualizeaza o persoana fizica si constituie singurul identificator pentru toate sistemele informatice care prelucreaza date nominale privind persoana fizica.
Gestionarea si verificarea atribuirii codului numeric personal revine Ministerului de Interne, prin formatiunile de evidenta a populatiei.
Pentru persoanele fizice romane cu domiciliul in Romania codul de identificare fiscala este codul numeric personal atribuit de Ministerul de Interne.Persoanele fizice straine si persoanele fizice romane fara domiciliu in Romania vor beneficia de numar de identificare fiscala (NIF).
Un CNP este alcatuit astfel :
|S| |AA| |LL| |ZZ| |JJ| |ZZZ| |C|
|_| |__| |__| |__| |__| |___| |_|
: : : : : : :
: : : : : : :
: : : : : : --> Cifra de control
: : : : : :
: : : : : --> Numarul de ordine atribuit persoanei
: : : : :
: : : : --> Codul judetului
: : : :
: : : --> Ziua nasterii
: : :
: : --> Luna nasterii
: :
: --> Anul nasterii
:
--> Cifra sexului (M/F) pentru:
1/2 - cetateni romani nascuti intre 1 ian 1900 si 31 dec 1999
3/4 - cetateni romani nascuti intre 1 ian 1800 si 31 dec 1899
5/6 - cetateni romani nascuti intre 1 ian 2000 si 31 dec 2099
7/8 - rezidenti
Persoanele de cetatenie straina se identifica cu cifra "9"
Algoritmul de validare al unui cod CNP
Pas preliminar: Se testeaza daca codul respecta formatul unui cod CNP. Adica prima cifra sa fie cuprinsa in intervalul 1 - 6 sau sa fie 9 pentru straini. Urmatoarele sase cifre trebuie sa constituie o data calendaristica valida in formatul AALLZZ.Pas 1: Se foloseste cheia de testare "279146358279". Primele douasprezece cifre se inmultesc pe rand de la stanga spre dreapta cu cifra corespunzatoare din cheia de testare.
Pas 2: Cele douasprezece produse obtinute se aduna si suma obtinuta se imparte la 11.
- Daca restul impartirii la 11 este mai mic ca 10, atunci acesta va reprezenta cifra de control.
- Daca restul impartirii este 10 atunci cifra de control este 1.
public static bool isValidCNP(string cnp)
{
bool result = true;
try
{
#region CNP
if (cnp.Replace(" ", "").Length != 13)
{
result &= false;
}
else
{
#region AlgoritmVerificareCNP
string tempNumber = "1234567890";
if ((tempNumber.IndexOf(cnp[0]) < 0) ||
(tempNumber.IndexOf(cnp[1]) < 0) ||
(tempNumber.IndexOf(cnp[2]) < 0) ||
(tempNumber.IndexOf(cnp[3]) < 0) ||
(tempNumber.IndexOf(cnp[4]) < 0) ||
(tempNumber.IndexOf(cnp[5]) < 0) ||
(tempNumber.IndexOf(cnp[6]) < 0) ||
(tempNumber.IndexOf(cnp[7]) < 0) ||
(tempNumber.IndexOf(cnp[8]) < 0) ||
(tempNumber.IndexOf(cnp[9]) < 0) ||
(tempNumber.IndexOf(cnp[10]) < 0) ||
(tempNumber.IndexOf(cnp[11]) < 0) ||
(tempNumber.IndexOf(cnp[12]) < 0)
)
{
result &= false;
return result;
}
int s = Int32.Parse(cnp[0].ToString()) * 2 +
Int32.Parse(cnp[1].ToString()) * 7 +
Int32.Parse(cnp[2].ToString()) * 9 +
Int32.Parse(cnp[3].ToString()) * 1 +
Int32.Parse(cnp[4].ToString()) * 4 +
Int32.Parse(cnp[5].ToString()) * 6 +
Int32.Parse(cnp[6].ToString()) * 3 +
Int32.Parse(cnp[7].ToString()) * 5 +
Int32.Parse(cnp[8].ToString()) * 8 +
Int32.Parse(cnp[9].ToString()) * 2 +
Int32.Parse(cnp[10].ToString()) * 7 +
Int32.Parse(cnp[11].ToString()) * 9;
int r = s % 11;
if (r == 10)
r = 1;
if (Int32.Parse(cnp[12].ToString()) != r)
{
result &= false;
}
#endregion
}
#endregion
return result;
}
catch (Exception)
{
return false;
}
}
Thursday, December 2, 2010
MS SQL - script stored procedures modiffied in the last n days
--modiffied sp
SELECT name
FROM sys.objects
WHERE type = 'P'
AND DATEDIFF(D,modify_date, GETDATE())
---------------------------
--modiffied sp, tables, views:
SELECT name, type_desc
FROM sys.objects
WHERE (type = 'P' or type='U' or type='V')
AND DATEDIFF(D,modify_date, GETDATE())
order by name asc
MS SQL - Kill DB connections
declare @execSql varchar(1000), @databaseName varchar(100)
-- Set the database name for which to kill the connections
set @databaseName = 'WBE_SAAS'
set @execSql = ''
select @execSql = @execSql + 'kill ' + convert(char(10), spid) + ' '
from master.dbo.sysprocesses
where db_name(dbid) = @databaseName
and
DBID <> 0
and
spid <> @@spid
exec(@execSql)
Subscribe to:
Posts (Atom)