public static bool IsPhone(this string phone)
{
return Regex.IsMatch(phone, @"^\+?[0-9\-() ]{5,19}$");
}
пʼятниця, 27 серпня 2010 р.
Метод для провірки телефона
субота, 21 серпня 2010 р.
Custom css for IE 6
<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" href="ie6.css" />
<![endif]-->
вівторок, 27 липня 2010 р.
ExtJS grid wrap column
Добавляєм в наше апп метод:
потім використовуємо:
App.Globals.wrapRenderer = function(val) {
return '<div style="white-space:normal !important;">' + val + '</div>';
}
потім використовуємо:
...
{
header: "Описание",
dataIndex: "DESCRIPTION",
renderer: App.Globals.wrapRenderer,
width: 200
},
...
середа, 21 липня 2010 р.
ExtJS app errors handling
Для того щоб будь-які помилки від сервера виводились в спеціальному вікні
можна зробити override метода request:
можна зробити override метода request:
Ext.override(Ext.data.Connection, {
request: Ext.data.Connection.prototype.request.createSequence(function(o) {
if (!o.failure) {
o.failure = function(response) {
var msg = "Unknown server error";
var resp = Ext.decode(response.responseText);
if (resp && resp.Message) {
msg = resp.Message;
}
Ext.Msg.show({
title: "Server Error",
msg: msg,
minWidth: 300,
buttons: Ext.Msg.OK,
icon: Ext.Msg.ERROR
});
}
}
})
});
пʼятниця, 16 липня 2010 р.
MSSQL paging + sorting + filtering
CREATE PROCEDURE [TestTable_GetPagedAndSortedAndFiltered]
(
@startRowIndex int,
@maximumRows int,
@order nvarchar(50),
@ID int = null,
@Name nvarchar(50) = null,
@Size int = null,
@From datetime = null,
@To datetime = null
)
AS
BEGIN
declare @lastKey int
declare @lastAsc sql_variant
declare @lastDesc sql_variant
set rowcount @startRowIndex
select
@lastAsc = OrderAsc,
@lastDesc = OrderDesc,
@lastKey = OrderKey
from
(
select *,
ID as OrderKey,
case @order
when 'ID' then cast(ID as sql_variant)
when 'Name' then cast(Name as sql_variant)
when 'Size' then cast(Size as sql_variant)
when 'Created' then cast(Created as sql_variant)
else ID
END as OrderAsc,
case @order
when 'ID DESC' then cast(ID as sql_variant)
when 'Name DESC' then cast(Name as sql_variant)
when 'Size DESC' then cast(Size as sql_variant)
when 'Created DESC' then cast(Created as sql_variant)
END as OrderDesc
from TestTable
where
((@ID is null) or (@ID = ID))
and
((@Name is null) or (Name like @Name))
and
((@Size is null) or (@Size = Size))
and
((@From is null) or (@From < Created))
and
((@To is null) or (dateadd(day,1,@To) > Created))
) as T
order by OrderAsc,OrderDesc desc,OrderKey
set rowcount @maximumRows
select *
from
(
select *,
ID as OrderKey,
case @order
when 'ID' then cast(ID as sql_variant)
when 'Name' then cast(Name as sql_variant)
when 'Size' then cast(Size as sql_variant)
when 'Created' then cast(Created as sql_variant)
else ID
END as OrderAsc,
case @order
when 'ID DESC' then cast(ID as sql_variant)
when 'Name DESC' then cast(Name as sql_variant)
when 'Size DESC' then cast(Size as sql_variant)
when 'Created DESC' then cast(Created as sql_variant)
END as OrderDesc
from TestTable
where
((@ID is null) or (@ID = ID))
and
((@Name is null) or (Name like @Name))
and
((@Size is null) or (@Size = Size))
and
((@From is null) or (@From < Created))
and
((@To is null) or (dateadd(day,1,@To) > Created))
)as T
where
(
@lastAsc is null
and
@lastDesc is null
and
@lastKey is null
)
or
(
@lastAsc is not null
and
(
OrderAsc > @lastAsc
or
OrderAsc = @lastAsc
and
OrderKey >= @lastKey
)
)
or
(
@lastDesc is not null
and
(
OrderDesc < @lastDesc
or
OrderDesc = @lastDesc
and
OrderKey >= @lastKey
)
)
order by OrderAsc,OrderDesc desc,OrderKey
set rowcount 0
END
MSSQL sort and filter procedure
Припустимо в нас є табличка:
Для сортування і фільтрації по всіх полях можна використати процедуру:
CREATE TABLE [TestTable](
[ID] [int] PRIMARY KEY IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NULL,
[Size] [int] NULL,
[Created] [datetime] NULL
)
Для сортування і фільтрації по всіх полях можна використати процедуру:
CREATE PROCEDURE [TestTable_GetPagedAndSorted]
(
@startRowIndex int,
@maximumRows int,
@order nvarchar(50)
)
AS
BEGIN
declare @lastKey int
declare @lastAsc sql_variant
declare @lastDesc sql_variant
set rowcount @startRowIndex
select
@lastAsc = OrderAsc,
@lastDesc = OrderDesc,
@lastKey = OrderKey
from
(
select *,
ID as OrderKey,
case @order
when 'ID' then cast(ID as sql_variant)
when 'Name' then cast(Name as sql_variant)
when 'Size' then cast(Size as sql_variant)
when 'Created' then cast(Created as sql_variant)
else ID
END as OrderAsc,
case @order
when 'ID DESC' then cast(ID as sql_variant)
when 'Name DESC' then cast(Name as sql_variant)
when 'Size DESC' then cast(Size as sql_variant)
when 'Created DESC' then cast(Created as sql_variant)
END as OrderDesc
from TestTable
) as T
order by OrderAsc,OrderDesc desc,OrderKey
set rowcount @maximumRows
select *
from
(
select *,
ID as OrderKey,
case @order
when 'ID' then cast(ID as sql_variant)
when 'Name' then cast(Name as sql_variant)
when 'Size' then cast(Size as sql_variant)
when 'Created' then cast(Created as sql_variant)
else ID
END as OrderAsc,
case @order
when 'ID DESC' then cast(ID as sql_variant)
when 'Name DESC' then cast(Name as sql_variant)
when 'Size DESC' then cast(Size as sql_variant)
when 'Created DESC' then cast(Created as sql_variant)
END as OrderDesc
from TestTable
)as T
where
(
@lastAsc is null
and
@lastDesc is null
and
@lastKey is null
)
or
(
@lastAsc is not null
and
(
OrderAsc > @lastAsc
or
OrderAsc = @lastAsc
and
OrderKey > @lastKey
)
)
or
(
@lastDesc is not null
and
(
OrderDesc < @lastDesc
or
OrderDesc = @lastDesc
and
OrderKey > @lastKey
)
)
order by OrderAsc,OrderDesc desc,OrderKey
set rowcount 0
END
MSSQL ORDER BY CASE
Припустимо в нас є табличка:
Сортувати її за значення певного параметра можна так:
CREATE TABLE [TestTable](
[ID] [int] PRIMARY KEY IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NULL,
[Size] [int] NULL,
[Created] [datetime] NULL
)
Сортувати її за значення певного параметра можна так:
declare @order nvarchar(50)
set @order = 'Created DESC'
select *
from TestTable
order by
case @order
when 'ID' then cast(ID as sql_variant)
when 'Name' then cast(Name as sql_variant)
when 'Size' then cast(Size as sql_variant)
when 'Created' then cast(Created as sql_variant)
END,
case @order
when 'ID DESC' then cast(ID as sql_variant)
when 'Name DESC' then cast(Name as sql_variant)
when 'Size DESC' then cast(Size as sql_variant)
when 'Created DESC' then cast(Created as sql_variant)
END desc
Підписатися на:
Дописи (Atom)