CSS 圓角技術

CSS 圓角技術 « 就是愛程式

CSS 圓角技術
Posted on November 1, 2007 by Ate

CSS 圓角,可以說是一個相當煩人的東西,雖然圖檔比較容易,但是這篇文章不討論使用圖檔製作圓角的方法,而是使用純粹的CSS。

之所以說他煩人,是因為為了弄圓角而搞出一堆垃圾標籤,實在是非常不符合HTML結構化和語意化的精神,不過短期間,還沒有相當簡潔又完美的處理方式,忍耐一下吧!

Table Valued Function

SQL SERVER – Insert Values of Stored Procedure in Table – Use Table Valued Function « Journey to SQL Authority with Pinal Dave

Alternate Method: Table Valued Function

/* Create table valued function*/
CREATE FUNCTION dbo.TestFn()
RETURNS @retTestFn TABLE
(
MyDate SMALLDATETIME,
IntValue INT
)
AS
BEGIN
DECLARE @MyDate SMALLDATETIME
DECLARE @IntValue INT
INSERT INTO @retTestFn
SELECT GETDATE() AS MyDate, 1 AS IntValue
UNION ALL
SELECT GETDATE()+1 AS MyDate, 2 AS IntValue
RETURN;
END
GO
/* Select data from Table Valued Function */
SELECT *
FROM dbo.TestFn()
GO

SQL SERVER – Find Stored Procedure Related to Table in Database – Search in All Stored Procedure

SQL SERVER – Find Stored Procedure Related to Table in Database – Search in All Stored Procedure « Journey to SQL Authority with Pinal Dave

SQL SERVER – Find Stored Procedure Related to Table in Database – Search in All Stored Procedure

December 10, 2006 by pinaldave

Following code will help to find all the Stored Procedures (SP) which are related to one or more specific tables. sp_help and sp_depends does not always return accurate results.

—-Option 1
SELECT DISTINCT so.name
FROM syscomments sc
INNER JOIN sysobjects so ON sc.id=so.id
WHERE sc.TEXT LIKE ‘%tablename%’
—-Option 2
SELECT DISTINCT o.name, o.xtype
FROM syscomments c
INNER JOIN sysobjects o ON c.id=o.id
WHERE c.TEXT LIKE ‘%tablename%’

Creator Tip: Setting table column or row style

Winston Prakash’s Weblog : weblog

Creator Tip: Setting table column or row style

During a meeting with Dick Wall of New Energy at Sun Executive Briefing Center, a question came up. How do I flag (set the colors of the text) of a particular cell in the Table Component based on some predefined condition. Here is a tip on how to do this.

Let’s start with a Creator project with single Page and a table component. Drag and drop the person table on to table component. Assume we should color the text of the names column with a light blue background, if the name matches “Black" or “Chen" and the job title with light red background if it matches “VP".

Here is how to do this.

Add two methods “getNameStyleClass" and “GetJobStyleClass"

public String getNameStyleClass() {
String name = (String) getValue(“#{currentRow.value[‘PERSON.NAME’]}");
if ((name != null) && (name.startsWith(“Black") || name.startsWith(“Chen"))){
return “nameStyleClass";
}else{
return “noStyleClass";
}
}

public String getJobStyleClass() {
String name = (String) getValue(“#{currentRow.value[‘PERSON.JOBTITLE’]}");
if ((name != null) && (name.startsWith(“VP") )){
return “jobStyleClass";
}else{
return “noStyleClass";
}
}

Tip: “#{currentRow.value[‘PERSON.JOBTITLE’]}" is same as what is set to the text property of the StaticText in the Column of the Table Component in the JSP page. You could simple copy and paste it here.

Add three CSS style classes to the resources/stylesheet.css

.noStyleClass{
}

.nameStyleClass {
background-color: #ccccff;
border-color: #0000ff;
border-style: solid;
border-width: 1px
}

.jobStyleClass {
background-color: #ffcccc;
border-color: #0000ff;
border-style: solid;
border-width: 1px
}

Select the StaticText component corresponding to the “Name" TableColumn in the Outline View. Click the Custom Property Editor ([…] button) of the styleclass. From the “Use binding" panel select the getNameStyleClass. Similarly bind getJobStyleClass to styleclass property of StaticText component of “Job Title" Table Column.

After executing the project the table component should display like
Table with Column Styles

Another trick is to make the table to display odd and even rows with different styles. Add the following method to your Page1.java

public String getColumnStyle(){
TableRowDataProvider trdp = (TableRowDataProvider) getBean(“currentRow");
RowKey rowKey = trdp.getTableRow();
if ((Integer.parseInt(rowKey.getRowId()) % 2) == 0){
return " “;
}else{
return “background-color: #eeeeee";
}
}

Now select each table column in the outline and click on the […] of the “style" property in the property sheet. Using the “Use Binding panel -> Bind to Object" dialog, bind the “style" to the Page1.columnStyle property.

The result may not be visible at design time. But at run time you should see something like
Table with Alternate row Styles

[譯文] 為什麼我們不好意思承認,我們不知道如何寫測試?

fcamel’s blog » [譯文] 為什麼我們不好意思承認,我們不知道如何寫測試?

原文見:《Why are we embarrassed to admit that we don’t know how to write tests?》。
前言

這篇帶給我很大的影響。對我來說,明白「可測性是最重要的」是一大里程碑。隨著經驗累積,了解得愈深,愈明白 Miško Hevery 寫得多有道理。就當我打算寫篇心得時,才發覺很容易變成用我的話重說 Miško Hevery 說過的東西,而且還很容易漏講。轉念一想,乾脆翻譯他的文章好了。二月底時徵得他的同意,沒想到一拖就拖了一個月半,真不好意思。

Joomla! 1.5 与 Dokuwiki 的完全整合方案

Joomla! 1.5 与 Dokuwiki 的完全整合方案 – Joomla! 1.5 教程 – Joomla之门

Joomla! 1.5 与 Dokuwiki 的完全整合方案 E-mail
作者:白建鹏
2009-04-07

在 Joomla! 网站上搭建 Wiki 知识库,实现多人在线联编(译)功能是无法回避的一个实际需求。我们已经实现了 通过自定义页头 + CSS 实现 Joomla! 与 Tikiwiki 的外观整合。不过,萝卜白菜、各有所爱,尽管从“架设多语种联合翻译平台”的角度讲,Tikiwiki 是最合适的选择;但是如果仅仅需要一个小型的、单语种的资料库式 wiki,那么 Tiki 的体积就过于庞大了。况且,到目前为止,还没有实现 Joomla! 与 Tikiwiki 的用户整合。而另一个维基程序 Dokuwiki 则已经拥有了与 Joomla! 用户同步的功能。因此,对于后一种简单维基需求,我推荐安装 Dokuwiki。本文将演示 Joomla! 1.5.10 与 Dokuwiki 2009-02-14 版本之间的整合过程。

— Triggers 2 – Creating Audit Trails Author Nigel Rivett

Sql Server. Triggers 2 – Creating Audit Trails – Author Nigel Rivett

— Triggers 2 – Creating Audit Trails
Author Nigel Rivett

Creating Audit Trails
Author: Nigel Rivett

Objective
The objective of an audit trail is to log changes to data in tables.

This article deals with two ways of creating an audit trail:

1. Audit trail table for each table to be audit trailed

Create a copy of the table and write copies of the rows to it.
For this method it is usual to write the old data only as the new data is in the main table and to write an entry whether or not anything is actaully changed.
This can be implemented in triggers or in the stored procedures that update the data.
This method also does not require a primary key as it is just saving the before versions of rows updated.

2. Single audit trail table

Create a table to log the table name, field name abd old and new versions of the data.
For this method it is usual to log both old and new versions of the data and only those fields that have changed.
To implement this in triggeres it is a requirement that either there is a primary key on the table or only single rows are updated.

Note that text and image columns are not available in the insertd/deleted tables to after triggers so these cannot be saved by this method.

Test table to be audit trailed.
if exists (select * from sysobjects where id = object_id(N'[dbo].[trigtest]’) and OBJECTPROPERTY(id, N’IsUserTable’) = 1)
drop table [dbo].[trigtest]
go
create table trigtest (i_int_key int not null, j_int_key int not null, s_varchar varchar(10), t_char varchar(10), d_date datetime)
go
alter table trigtest add constraint pk primary key (i_int_key, j_int_key)
go

Test updates
insert trigtest (i_int_key, j_int_key, s_varchar, t_char, d_date)
select 1, 1, ‘hello’, ‘goodbye’, ‘20000101’
insert trigtest (i_int_key, j_int_key, s_varchar, t_char, d_date)
select 2, 1, ‘hello’, ‘goodbye’, ‘20000101’
update trigtest set s_varchar = ‘helloupd’ where i_int_key = 1
update trigtest set t_char = ‘goodbyeupd’, d_date = ‘20000102’ where i_int_key = 1
update trigtest set t_char = null, d_date = null where i_int_key = 1
update trigtest set t_char = ‘good’, d_date = ‘20000103’ where i_int_key = 1
delete trigtest where i_int_key = 1

1. Audit trail table for each table to be audited

Audit trail table

if exists (select * from sysobjects where id = object_id(N'[dbo].[trigtest_au]’) and OBJECTPROPERTY(id, N’IsUserTable’) = 1)
drop table [dbo].[trigtest_au]
go
create table trigtest_au (i_int_key int not null, j_int_key int not null, s_varchar varchar(10), t_char varchar(10), d_date datetime, UpdateDate datetime, UserName varchar(128), type varchar(10))
go

Trigger to create the audit trail for the table

To only save only the old copy of the data

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tr_au_trigtest]’) and OBJECTPROPERTY(id, N’IsTrigger’) = 1)
drop trigger [dbo].[tr_au_trigtest]
go
create trigger tr_au_trigtest on trigtest for update, delete
as
declare @type varchar(1) ,
@UpdateDate datetime ,
@UserName varchar(128)
if exists (select * from inserted)
select @type = ‘U’
else
select @type = ‘D’

select @UpdateDate = getdate() ,
@UserName = system_user

insert trigtest_au (i_int_key, j_int_key, s_varchar, t_char, d_date, UpdateDate, UserName, type)
select i_int_key, j_int_key, s_varchar, t_char, d_date, @UpdateDate, @UserName, @type + ‘_old’
from deleted
go

To save the old and new copy of the data

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tr_au_trigtest]’) and OBJECTPROPERTY(id, N’IsTrigger’) = 1)
drop trigger [dbo].[tr_au_trigtest]
go
create trigger tr_au_trigtest on trigtest for insert, update, delete
as
declare @type varchar(1) ,
@UpdateDate datetime ,
@UserName varchar(128)
if exists (select * from inserted) and exists (select * from deleted)
select @type = ‘U’
else if exists (select * from inserted)
select @type = ‘I’
else
select @type = ‘D’

select @UpdateDate = getdate() ,
@UserName = system_user

insert trigtest_au (i_int_key, j_int_key, s_varchar, t_char, d_date, UpdateDate, UserName, type)
select i_int_key, j_int_key, s_varchar, t_char, d_date, @UpdateDate, @UserName, @type + ‘_old’
from deleted
insert trigtest_au (i_int_key, j_int_key, s_varchar, t_char, d_date, UpdateDate, UserName, type)
select i_int_key, j_int_key, s_varchar, t_char, d_date, @UpdateDate, @UserName, @type + ‘_new’
from inserted
go

2. Single Audit Trail table.

Audit trail table
if exists (select * from sysobjects where id = object_id(N'[dbo].[trigtest_au]’) and OBJECTPROPERTY(id, N’IsUserTable’) = 1)
drop table [dbo].[trigtest_au]
go
create table trigtest_au (TableName varchar(128), FieldName varchar(128), OldValue varchar(1000), NewValue varchar(1000), UpdateDate datetime, UserName varchar(128), type varchar(1))
go

Trigger to save old and new values of fields that have changed

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tr_au_trigtest]’) and OBJECTPROPERTY(id, N’IsTrigger’) = 1)
drop trigger [dbo].[tr_au_trigtest]
go
create trigger tr_au_trigtest on trigtest for insert, update, delete
as
declare @type varchar(1) ,
@UpdateDate datetime ,
@UserName varchar(128)
if exists (select * from inserted) and exists (select * from deleted)
select @type = ‘U’
else if exists (select * from inserted)
select @type = ‘I’
else
select @type = ‘D’

select @UpdateDate = getdate() ,
@UserName = system_user

if update (i_int_key) or @type = ‘D’
insert trigtest_au (TableName, PK, FieldName, OldValue, NewValue, UpdateDate, UserName, type)
select ‘trigtest’, convert(varchar(20),coalesce(d.i_int_key,i.i_int_key)) + ‘|’ + convert(varchar(20),coalesce(d.j_int_key,i.j_int_key)), ‘i_int_key’, convert(varchar(1000),d.i_int_key), convert(varchar(1000),i.i_int_key), @UpdateDate, @UserName, @type
from inserted i
full outer join deleted d
on i.i_int_key = d.i_int_key
and i.j_int_key = d.j_int_key
where (i.i_int_key <> d.i_int_key or (i.i_int_key is null and d.i_int_key is not null) or (i.i_int_key is not null and d.i_int_key is null))
if update (j_int_key) or @type = ‘D’
insert trigtest_au (TableName, PK, FieldName, OldValue, NewValue, UpdateDate, UserName, type)
select ‘trigtest’, convert(varchar(20),coalesce(d.i_int_key,i.i_int_key)) + ‘|’ + convert(varchar(20),coalesce(d.j_int_key,i.j_int_key)), ‘j_int_key’, convert(varchar(1000),d.j_int_key), convert(varchar(1000),i.j_int_key), @UpdateDate, @UserName, @type
from inserted i
full outer join deleted d
on i.i_int_key = d.i_int_key
and i.j_int_key = d.j_int_key
where (i.j_int_key <> d.j_int_key or (i.j_int_key is null and d.j_int_key is not null) or (i.j_int_key is not null and d.j_int_key is null))
if update (s_varchar) or @type = ‘D’
insert trigtest_au (TableName, PK, FieldName, OldValue, NewValue, UpdateDate, UserName, type)
select ‘trigtest’, convert(varchar(20),coalesce(d.i_int_key,i.i_int_key)) + ‘|’ + convert(varchar(20),coalesce(d.j_int_key,i.j_int_key)), ‘s_varchar’, convert(varchar(1000),d.s_varchar), convert(varchar(1000),i.s_varchar), @UpdateDate, @UserName, @type
from inserted i
full outer join deleted d
on i.i_int_key = d.i_int_key
and i.j_int_key = d.j_int_key
where (i.s_varchar <> d.s_varchar or (i.s_varchar is null and d.s_varchar is not null) or (i.s_varchar is not null and d.s_varchar is null))
if update (t_char) or @type = ‘D’
insert trigtest_au (TableName, PK, FieldName, OldValue, NewValue, UpdateDate, UserName, type)
select ‘trigtest’, convert(varchar(20),coalesce(d.i_int_key,i.i_int_key)) + ‘|’ + convert(varchar(20),coalesce(d.j_int_key,i.j_int_key)), ‘t_char’, convert(varchar(1000),d.t_char), convert(varchar(1000),i.t_char), @UpdateDate, @UserName, @type
from inserted i
full outer join deleted d
on i.i_int_key = d.i_int_key
and i.j_int_key = d.j_int_key
where (i.t_char <> d.t_char or (i.t_char is null and d.t_char is not null) or (i.t_char is not null and d.t_char is null))
if update (d_date) or @type = ‘D’
insert trigtest_au (TableName, PK, FieldName, OldValue, NewValue, UpdateDate, UserName, type)
select ‘trigtest’, convert(varchar(20),coalesce(d.i_int_key,i.i_int_key)) + ‘|’ + convert(varchar(20),coalesce(d.j_int_key,i.j_int_key)), ‘d_date’, convert(char(9),d.d_date,112) + convert(char(8),d.d_date,8), convert(char(9),i.d_date,112) + convert(char(8),i.d_date,8), @UpdateDate, @UserName, @type
from inserted i
full outer join deleted d
on i.i_int_key = d.i_int_key
and i.j_int_key = d.j_int_key
where (i.d_date <> d.d_date or (i.d_date is null and d.d_date is not null) or (i.d_date is not null and d.d_date is null))
go

This gives the following result

select TableName = convert(char(12),TableName), PK = convert(char(6),PK), FieldName = convert(char(16),FieldName),
OldValue = convert(char(20),OldValue), NewValue = convert(char(20), NewValue),
UpdateDate = convert(char(9),UpdateDate,112)+convert(char(10),UpdateDate,8), UserName = convert(char(10),UserName), type
from trigtest_au

TableName PK FieldName OldValue NewValue UpdateDate UserName type
———— —— —————- ——————– ——————– ——————- ———- —-
trigtest 1|1 i_int_key NULL 1 20030330 04:00:14 sa I
trigtest 1|1 j_int_key NULL 1 20030330 04:00:14 sa I
trigtest 1|1 s_varchar NULL hello 20030330 04:00:14 sa I
trigtest 1|1 t_char NULL goodbye 20030330 04:00:14 sa I
trigtest 1|1 d_date NULL 20000101 00:00:00 20030330 04:00:14 sa I
trigtest 2|1 i_int_key NULL 2 20030330 04:00:14 sa I
trigtest 2|1 j_int_key NULL 1 20030330 04:00:14 sa I
trigtest 2|1 s_varchar NULL hello 20030330 04:00:14 sa I
trigtest 2|1 t_char NULL goodbye 20030330 04:00:14 sa I
trigtest 2|1 d_date NULL 20000101 00:00:00 20030330 04:00:14 sa I
trigtest 1|1 s_varchar hello helloupd 20030330 04:00:14 sa U
trigtest 1|1 t_char goodbye goodbyeupd 20030330 04:00:14 sa U
trigtest 1|1 d_date 20000101 00:00:00 20000102 00:00:00 20030330 04:00:14 sa U
trigtest 1|1 t_char goodbyeupd NULL 20030330 04:00:14 sa U
trigtest 1|1 d_date 20000102 00:00:00 NULL 20030330 04:00:14 sa U
trigtest 1|1 t_char NULL good 20030330 04:00:14 sa U
trigtest 1|1 d_date NULL 20000103 00:00:00 20030330 04:00:14 sa U
trigtest 1|1 i_int_key 1 NULL 20030330 04:00:14 sa D
trigtest 1|1 j_int_key 1 NULL 20030330 04:00:14 sa D
trigtest 1|1 s_varchar helloupd NULL 20030330 04:00:14 sa D
trigtest 1|1 t_char good NULL 20030330 04:00:14 sa D
trigtest 1|1 d_date 20000103 00:00:00 NULL 20030330 04:00:14 sa D

Generic audit trail trigger Author Nigel Rivett

Sql Server. Generic audit trail trigger – Author Nigel Rivett

Generic audit trail trigger
Author Nigel Rivett

/*
This trigger audit trails all changes made to a table.
It will place in the table Audit all inserted, deleted, changed columns in the table on which it is placed.
It will put out an error message if there is no primary key on the table
You will need to change @TableName to match the table to be audit trailed
*/

–Set up the tables
if exists (select * from sysobjects where id = object_id(N'[dbo].[Audit]’) and OBJECTPROPERTY(id, N’IsUserTable’) = 1)
drop table [dbo].[Audit]
go
create table Audit (Type char(1), TableName varchar(128), PK varchar(1000), FieldName varchar(128), OldValue varchar(1000), NewValue varchar(1000), UpdateDate datetime, UserName varchar(128))
go
if exists (select * from sysobjects where id = object_id(N'[dbo].[trigtest]’) and OBJECTPROPERTY(id, N’IsUserTable’) = 1)
drop table [dbo].[trigtest]
go
create table trigtest (i int not null, j int not null, s varchar(10), t varchar(10))
go
alter table trigtest add constraint pk primary key (i, j)
go

create trigger tr_trigtest on trigtest for insert, update, delete
as

declare @bit int ,
@field int ,
@maxfield int ,
@char int ,
@fieldname varchar(128) ,
@TableName varchar(128) ,
@PKCols varchar(1000) ,
@sql varchar(2000),
@UpdateDate varchar(21) ,
@UserName varchar(128) ,
@Type char(1) ,
@PKSelect varchar(1000)

select @TableName = ‘trigtest’

— date and user
select @UserName = system_user ,
@UpdateDate = convert(varchar(8), getdate(), 112) + ‘ ‘ + convert(varchar(12), getdate(), 114)

— Action
if exists (select * from inserted)
if exists (select * from deleted)
select @Type = ‘U’
else
select @Type = ‘I’
else
select @Type = ‘D’

— get list of columns
select * into #ins from inserted
select * into #del from deleted

— Get primary key columns for full outer join
select @PKCols = coalesce(@PKCols + ‘ and’, ‘ on’) + ‘ i.’ + c.COLUMN_NAME + ‘ = d.’ + c.COLUMN_NAME
from INFORMATION_SCHEMA.TABLE_CONSTRAINTS pk ,
INFORMATION_SCHEMA.KEY_COLUMN_USAGE c
where pk.TABLE_NAME = @TableName
and CONSTRAINT_TYPE = ‘PRIMARY KEY’
and c.TABLE_NAME = pk.TABLE_NAME
and c.CONSTRAINT_NAME = pk.CONSTRAINT_NAME

— Get primary key select for insert
select @PKSelect = coalesce(@PKSelect+’+’,") + “‘<‘ + COLUMN_NAME + ‘="+convert(varchar(100),coalesce(i.’ + COLUMN_NAME +’,d.’ + COLUMN_NAME + ‘))+">"‘
from INFORMATION_SCHEMA.TABLE_CONSTRAINTS pk ,
INFORMATION_SCHEMA.KEY_COLUMN_USAGE c
where pk.TABLE_NAME = @TableName
and CONSTRAINT_TYPE = ‘PRIMARY KEY’
and c.TABLE_NAME = pk.TABLE_NAME
and c.CONSTRAINT_NAME = pk.CONSTRAINT_NAME

if @PKCols is null
begin
raiserror(‘no PK on table %s’, 16, -1, @TableName)
return
end

select @field = 0, @maxfield = max(ORDINAL_POSITION) from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = @TableName
while @field < @maxfield
begin
select @field = min(ORDINAL_POSITION) from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = @TableName and ORDINAL_POSITION > @field
select @bit = (@field – 1 )% 8 + 1
select @bit = power(2,@bit – 1)
select @char = ((@field – 1) / 8) + 1
if substring(COLUMNS_UPDATED(),@char, 1) & @bit > 0 or @Type in (‘I’,’D’)
begin
select @fieldname = COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = @TableName and ORDINAL_POSITION = @field
select @sql = ‘insert Audit (Type, TableName, PK, FieldName, OldValue, NewValue, UpdateDate, UserName)’
select @sql = @sql + ‘ select “‘ + @Type + “"
select @sql = @sql + ‘,"‘ + @TableName + “"
select @sql = @sql + ‘,’ + @PKSelect
select @sql = @sql + ‘,"‘ + @fieldname + “"
select @sql = @sql + ‘,convert(varchar(1000),d.’ + @fieldname + ‘)’
select @sql = @sql + ‘,convert(varchar(1000),i.’ + @fieldname + ‘)’
select @sql = @sql + ‘,"‘ + @UpdateDate + “"
select @sql = @sql + ‘,"‘ + @UserName + “"
select @sql = @sql + ‘ from #ins i full outer join #del d’
select @sql = @sql + @PKCols
select @sql = @sql + ‘ where i.’ + @fieldname + ‘ <> d.’ + @fieldname
select @sql = @sql + ‘ or (i.’ + @fieldname + ‘ is null and d.’ + @fieldname + ‘ is not null)’
select @sql = @sql + ‘ or (i.’ + @fieldname + ‘ is not null and d.’ + @fieldname + ‘ is null)’
exec (@sql)
end
end
go

insert trigtest select 1,1,’hi’, ‘bye’
insert trigtest select 2,2,’hi’, ‘bye’
insert trigtest select 3,3,’hi’, ‘bye’
select * from Audit
select * from trigtest
update trigtest set s = ‘hibye’ where i <> 1
update trigtest set s = ‘bye’ where i = 1
update trigtest set s = ‘bye’ where i = 1
update trigtest set t = ‘hi’ where i = 1
select * from Audit
select * from trigtest
delete trigtest
select * from Audit
select * from trigtest

go
drop table Audit
go
drop table trigtest
go