2013年11月25日 星期一

Select Into & Insert Into

Select Into & Insert Into

下列指令會先創建newTable欄位與sourceTable一致,再將sourceTable的資料全部複製到newTable, newTable事先必須不存在
--select * into newTable from sourceTable

下列指令會將sourceTale的資料全部複製到newTable, newTable事先必須存在, 兩者欄位必須相同
--Insert into newTable select * from sourceTable

2013年11月21日 星期四

CRM2011 Outlook Track

Microsoft Dynamics CRM 2011 Outlook Track

The owner of this queue does not have sufficient privileges to work with the queue.

Please go to settings=>customizations=>customize the system=>Entities=>Email, then uncheck "Automatically move records to the owner's default queue when a record is created or assigned", publish all customizations and try again.

Open the appropriate Security Role, Find Queue in the list and apply Read permissions



Reference: http://social.microsoft.com/Forums/en-US/b35ad118-ac41-4aab-8a08-969737bbff2b/outlook-tracking-error-the-owner-of-this-queue-does-not-have-sufficient-privileges-to-work-with?forum=crm

http://msdynamicswiki.com/2011/11/01/error-message-when-attempting-to-send-tracked-email-message-to-another-user-in-microsoft-dynamics-crm-2011/

2013年11月14日 星期四

EnableEventValidation

無效的回傳或回呼引數。已在組態中使用 <pages enableEventValidation="true"/> 或在網頁中使用 <%@ Page EnableEventValidation="true" %> 啟用事件驗證。基於安全性理由,這項功能驗證回傳或回呼引數是來自原本呈現它們的伺服器控制項。如果資料為有效並且是必須的,請使用 ClientScriptManager.RegisterForEventValidation 方法註冊回傳或回呼資料,以進行驗證

解決方法:
在.aspx的@Page標籤內加入一行EnableEventValidation="false"即可

HyperLink按右鍵執行Script

HyperLink按右鍵執行Script
















----------------------------------------------------------------------------------------------------
.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="tsHyperLink.aspx.cs" Inherits="Test_tsHyperLink" EnableEventValidation="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script language="javascript" type="text/javascript">

        function deleteFile(arg1) {
            if (confirm("Are you sure want to delete?")) {
                alert(arg1); //出現警示視窗
                window.open("/deletefile.aspx?filename=" + arg1); //開另一個新視窗
                __doPostBack('LinkButton1', '') //執行一個onClick / onChange Event //必須在<$@Page />加入EnableEventValidation="false"
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/default.aspx" >HyperLink按右鍵執行Script</asp:HyperLink><br />
        <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click" Visible="false">LinkButton</asp:LinkButton><br />
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
</body>
</html>

----------------------------------------------------------------------------------------------------
.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Test_tsHyperLink : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        HyperLink hpl = (HyperLink)this.form1.FindControl("HyperLink1");
        hpl.Attributes["oncontextmenu"] = "deleteFile('test.xls')";

        //關閉form1內的右鍵功能,避免干擾
        this.form1.Attributes.Add("oncontextmenu", "return false");
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        // Do to...
        Label1.Text = "test";
    }
}

Panel區塊內防止右鍵

Panel區塊內防止右鍵

.aspx

<asp:Panel ID="pan_fileslist" runat="server">
</asp:Panel>


.cs

protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            //防右鍵
            this.pan_fileslist.Attributes.Add("oncontextmenu", "return false");

            //防選取
            this.pan_fileslist.Attributes.Add("onSelectStart", "return false");
            this.pan_fileslist.Attributes.Add("onDragStart", "return false");
        }
        catch (Exception)
        {

            throw;
        }
    }

2013年11月11日 星期一

取得PostBack Control

取得PostBack Control

C#

public Control GetPostBackControl(Page page)
        {
            Control control = null;
            string ctrlname = page.Request.Params.Get("__EVENTTARGET");
            if (ctrlname != null && ctrlname != string.Empty)
            {
                control = page.FindControl(ctrlname);
            }
            else
            {
                foreach (string ctl in page.Request.Form)
                {
                    Control mycontrol = page.FindControl(ctl);
                    if (mycontrol is System.Web.UI.WebControls.Button)
                    {
                        control = mycontrol;
                        // This gives you ID of which button caused postback
                        Response.Write(mycontrol.ID);
                        break;
                    }
                }
            }
            return control;
        }


protected void Page_Load(object sender, EventArgs e)
{
            Control a = GetPostBackControl(this.Page);
}
Reference: http://www.codeproject.com/Questions/123490/_EVENTTARGET-empty

CuteEditor 上傳中文檔名

CuteEditor 上傳中文檔名

File name not supported!  Please keep the file name one word with no spaces or special characters.

1. Edit security policy file.

CuteSoft_Client\CuteEditor\Configuration\Security\Default.config

<security name="filenamePattern">^[a-zA-Z0-9\._\s-\#]+$</security>

Please change it to:

<security name="filenamePattern">^[a-zA-Z0-9\._\s-\u4e00-\u9fa5]+$</security>

2. or Programmatically define the image name filter

C#: Page_Load
Editor1.Setting["security:filenamePattern"]= "^[a-zA-Z0-9\._\s-\u4e00-\u9fa5]+$";

2013年11月1日 星期五

自訂檢查日期欄位格式

自訂檢查日期欄位格式

.aspx

<form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="送出" />
         <asp:CustomValidator ID="CustomValidator1" runat="server"
             ControlToValidate="TextBox1" ErrorMessage="CustomValidator"
             onservervalidate="CustomValidator1_ServerValidate" ValidateEmptyText="True"></asp:CustomValidator>
    </div>
    </form>


.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Test_tsValidatorDate : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
     {
         if (CustomValidator1.IsValid)
         {
             Response.Write("送出成功!");
         }
     }
     protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
     {
         DateTime dt;

         if (string.IsNullOrEmpty(args.Value))
         {
             CustomValidator1.ErrorMessage = "該欄位必填";
             args.IsValid = false;
         }

         else if (DateTime.TryParseExact(args.Value, "yyyy/MM/dd", null,System.Globalization.DateTimeStyles.AllowWhiteSpaces, out dt) == false)
         {
             CustomValidator1.ErrorMessage = "日期格式為 yyyy/MM/dd";
             args.IsValid = false;
         }
         else
         {
             args.IsValid = true;
         }
     }
}