2015年12月10日 星期四

Reset CSS – 重置歸零 – 網頁排版在各瀏覽器一致化

Reset CSS – 重置歸零 – 網頁排版在各瀏覽器一致化
只要在寫 CSS 前掛上這一段「Reset CSS」的語法,就可以解決各大瀏覽器初始化的差異


<style>
/* v1.0 | 20080212 */

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
    margin: 0;
    padding: 0;
    border: 0;
    outline: 0;
    font-size: 100%;
    vertical-align: baseline;
    background: transparent;
}
body {
    line-height: 1;
}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}

/* remember to define focus styles! */
:focus {
    outline: 0;
}

/* remember to highlight inserts somehow! */
ins {
    text-decoration: none;
}
del {
    text-decoration: line-through;
}

/* tables still need 'cellspacing="0"' in the markup */
table {
    border-collapse: collapse;
    border-spacing: 0;
}
</style>


DownLoad: http://meyerweb.com/eric/tools/css/reset/reset.css

Source: http://meyerweb.com/eric/tools/css/reset/

Reference: http://www.flycan.com/article/css/reset-css-562.html

ASP.NET 選擇性引數函式範例

ASP.NET 選擇性引數函式範例


cs
    /// 
    /// 選擇性引數函式範例
    /// 
    public partial class tsExampleMethod : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ExampleClass anExample = new ExampleClass();
            string a = anExample.ExampleMethod(1, "One", 1);
            string b = anExample.ExampleMethod(2, "Two");
            string c = anExample.ExampleMethod(3);

            Response.Write(a);
            Response.Write(b);
            Response.Write(c);
        }
    }


class ExampleClass
    {
        private string _name;

        // Because the parameter for the constructor, name, has a default 
        // value assigned to it, it is optional. 
        public ExampleClass(string name = "Default name")
        {
            _name = name;
        }

        // The first parameter, required, has no default value assigned 
        // to it. Therefore, it is not optional. Both optionalstr and  
        // optionalint have default values assigned to them. They are optional. 
        public string ExampleMethod(int required, string optionalstr = "default string",
            int optionalint = 10)
        {
            return string.Format("{0}: {1}, {2}, and {3}.", _name, required, optionalstr,
                optionalint);

        }
    }

2015年12月9日 星期三

Searching in SQL Multiple Keyword

SQL 多條件查詢

使用逗號間隔多關鍵字查詢及對多個欄位進行搜查,組合條件為"或"。
※逗號前後不可留空白,否則會查出全部的資料



SQL
DECLARE @strKeyword    VARCHAR(512);
SET @strKeyword = 'john,howard,lee';

SELECT * FROM v_HRM_Evaluation 
JOIN dbo.FN_SPLIT_TBL(@strKeyword,',') tblB 
ON name + batchnumber + jobtitles + 
CONVERT(varchar(30),joblevel) +  workingfunc + 
ogno + ogname + ouno + ouname + ename + status + 
CONVERT(varchar(30),cdt,120) LIKE '%'+tblB.Value+'%'  
WHERE 1=1 


FN_SPLIT_TBL
--註:字串切割,用在單一欄位多條件同時查詢,如:(Select * from Table Where name like '%張%' or name like '%陳%' or name like '%王%')
--引用範例(一):
--select tblA.* from t_HRM_Evaluation tblA join dbo.FN_SPLIT_TBL('張,陳,王',',') tblB on tblA.name like '%'+tblB.Value+'%'
--引用範例(二):
--SELECT dbo.[FN_SPLIT](Name.Value, 2, '=') as Name,
--dbo.[FN_SPLIT](Age.Value, 2, '=') as Age,
--dbo.[FN_SPLIT](Job.Value, 2, '=') as Job,
--dbo.[FN_SPLIT](Location.Value, 2, '=') as Location,
--dbo.[FN_SPLIT](Add_Date.Value, 2, '=') as Add_Date
--FROM HR data
--    CROSS APPLY FN_SPLIT_TBL(data.Details, '|') Name
--    CROSS APPLY FN_SPLIT_TBL(data.Details, '|') Age
--    CROSS APPLY FN_SPLIT_TBL(data.Details, '|') Job
--    CROSS APPLY FN_SPLIT_TBL(data.Details, '|') Location
--    CROSS APPLY FN_SPLIT_TBL(data.Details, '|') Add_Date
--WHERE Name.Pos = 1 AND Age.Pos = 2 AND Job.Pos = 3 AND Location.Pos = 4 AND Add_Date.Pos = 5

CREATE FUNCTION [dbo].[FN_SPLIT_TBL](@InExp varchar(8000), @Sep varchar(10)) --SELECT * FROM DBO.[FN_SPLIT_TBL]('TEST1,TEST2', ',')
RETURNS @Res    TABLE(
    Pos         int,
    Value       varchar(max))
AS
BEGIN
    WITH Pieces(pn, start, stop) AS (
        SELECT 1, 1, CHARINDEX(@Sep, @InExp)
        UNION ALL
        SELECT pn + 1, stop + 1, CHARINDEX(@sep, @InExp, stop + 1)
        FROM Pieces
        WHERE stop > 0
    )

    INSERT INTO @Res
    SELECT pn, SUBSTRING(@InExp, start, CASE WHEN stop > 0 THEN stop-start ELSE 512 END) AS s
    FROM Pieces OPTION (MAXRECURSION 0);

    RETURN;
END


FN_SPLIT
--註:無
--引用範例(一):
--SELECT 
--dbo.[FN_SPLIT](data.Name, 2, '=') as Name,
--dbo.[FN_SPLIT](data.Age, 2, '=') as Age,
--dbo.[FN_SPLIT](data.Job, 2, '=') as Job,
--dbo.[FN_SPLIT](data.Location, 2, '=') as Location,
--dbo.[FN_SPLIT](data.Add_Date, 2, '=') as Add_Date
--FROM (
--    SELECT 
--    dbo.[FN_SPLIT](Details, 1, '|') as Name,
--    dbo.[FN_SPLIT](Details, 2, '|') as Age,
--    dbo.[FN_SPLIT](Details, 3, '|') as Job,
--    dbo.[FN_SPLIT](Details, 4, '|') as Location,
--    dbo.[FN_SPLIT](Details, 5, '|') as Add_Date
--    FROM HR) data



CREATE FUNCTION [dbo].[FN_SPLIT] ( --SELECT DBO.FN_SPLIT('TEST1 , TEST2', 2, ',')
    @s varchar(512),
    @i int,
    @sep char(1) = ',')
RETURNS varchar(512)
AS
BEGIN
    DECLARE @Ret    VARCHAR(512);

    WITH Pieces(pn, start, stop) AS (
      SELECT 1, 1, CHARINDEX(@sep, @s)
      UNION ALL
      SELECT pn + 1, stop + 1, CHARINDEX(@sep, @s, stop + 1)
      FROM Pieces
      WHERE stop > 0
    )
    SELECT @Ret =
    RTRIM(SUBSTRING(@s, start, CASE WHEN stop > 0 THEN stop-start ELSE 512 END))
    FROM Pieces
    WHERE pn = @i

    RETURN @Ret;
END

Searching in ASP.Net GridView Multiple Parameters

Searching in ASP.Net GridView Multiple Parameters

cs
private void BindData()
{
    string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    string query = "select * from customers where (name like '%' + @name + '%' or @name = '') and (age = @age or @age= 0) and (mobile = @mobile or @mobile= '') and (city = @city or @city= '')";
    SqlCommand cmd = new SqlCommand(query);
    cmd.Parameters.AddWithValue("@name", txtName.Text.Trim());
    cmd.Parameters.AddWithValue("@age", txtAge.Text.Trim() == "" ? 0 txtAge.Text.Trim());
    cmd.Parameters.AddWithValue("@mobile", txtMobile.Text.Trim());
    cmd.Parameters.AddWithValue("@city", ddlCity.SelectedIndex > 0 ? ddlCity.SelectedValue : "");
    using (SqlConnection con = new SqlConnection(conString))
    {
        using (SqlDataAdapter sda = new SqlDataAdapter())
        {
            cmd.Connection = con; sda.SelectCommand = cmd;
            using (DataSet ds = new DataSet())
            {
                sda.Fill(ds);
                GridView1.DataSource = ds;
                GridView1.DataBind();
            }
        }
    }
}



ref url:

CRM2011 How to get Options Set Value in DataBase?

CRM2011 How to get Options Set Value in DataBase?



StringMap table
SELECT AttributeValue, Value
FROM StringMap
WHERE ObjectTypeCode = 1 -- entity type code 1 = account
AND AttributeName = 'statecode' --fieldname


Entity Type Code
SELECT EntityId, Name, ObjectTypeCode
FROM [MetadataSchema].[Entity]
ORDER BY Name

2015年12月8日 星期二

CRM2011 Get Entity/Attribute's Display Name from CRM database

CRM2011 Get Entity/Attribute's Display Name from CRM database
從資料庫取得CRM2011 Attribute Display Name







SELECT  EntityView.Name AS EntityName, LocalizedLabelView_1.Label AS EntityDisplayName,
       AttributeView.Name AS AttributeName, LocalizedLabelView_2.Label AS AttributeDisplayName
FROM    LocalizedLabelView AS LocalizedLabelView_2 INNER JOIN
       AttributeView ON LocalizedLabelView_2.ObjectId = AttributeView.AttributeId RIGHT OUTER JOIN
       EntityView INNER JOIN
       LocalizedLabelView AS LocalizedLabelView_1 ON EntityView.EntityId = LocalizedLabelView_1.ObjectId ON
       AttributeView.EntityId = EntityView.EntityId
WHERE   LocalizedLabelView_1.ObjectColumnName = 'LocalizedName'
 AND LocalizedLabelView_2.ObjectColumnName = 'DisplayName'
 AND LocalizedLabelView_1.LanguageId = '1033'
 AND LocalizedLabelView_2.LanguageId = '1033'
 AND EntityView.Name IN ('Account','Contact')
ORDER BY EntityName, AttributeName


reference from: http://jianwang.blogspot.tw/2009/03/get-entityattributes-display-name-from.html