2017年10月26日 星期四

利用SignalR實現遠端程式遙控功能

http://blog.darkthread.net/post-2012-07-10-signalr-remote-controller.aspx

利用SignalR實現遠端程式遙控功能

https://code.msdn.microsoft.com/windowsdesktop/Using-SignalR-in-WinForms-f1ec847b

https://kknews.cc/zh-tw/other/29xmog.html

2017年9月26日 星期二

Func 委派的用法

Func 委派的用法

https://dotblogs.com.tw/brooke/2014/08/02/146142

摘要:Func 委派的用法
一、
1.委派的範例為
using System;

//宣告一個委派型別為ConvertMethod,
//並規範入為string型別,輸出為string型別
delegate string ConvertMethod(string inString);

public class DelegateExample
{
   public static void Main()
   {
      // Instantiate delegate to reference UppercaseString method
      // 將委派型別ConvertMethod的實體去參考UppercaseString方法
      ConvertMethod aConvertMeth = UppercaseString;
      string name = "Dakota";
      // Use delegate instance to call UppercaseString method
      Console.WriteLine(aConvertMeth(name));
   }

   private static string UppercaseString(string inputString)
   {
      return inputString.ToUpper();
   }
}

2.不用明確定義委派方法,以Func來簡化程式碼為
using System;

public class GenericFunc
{
    public static void Main()
    {
        // Instantiate delegate to reference UppercaseString method
        //Func<in T, out TResult>
        Func<string, string> aConvertMethod = UppercaseString;
        string name = "Dakota";
        // Use delegate instance to call UppercaseString method
        Console.WriteLine(aConvertMethod(name));
        Console.ReadKey();
    }

    private static string UppercaseString(string inputString)
    {
        return inputString.ToUpper();
    }
}

3.使用匿名方法
using System;

public class Anonymous
{
   public static void Main()
   {
      Func<string, string> convert = delegate(string s){ return s.ToUpper();}; 

      string name = "Dakota";
      Console.WriteLine(convert(name));   
   }
}

4.使用Lambda運算式
using System;

public class Anonymous
{
   public static void Main()
   {
      Func<string, string> convert = s => s.ToUpper(); 

      string name = "Dakota";
      Console.WriteLine(convert(name));   
   }
}

二、
若要參考有一個參數並傳回 void (在 Visual Basic 中是宣告為 Sub 而非 Function) 的方法,
可使用泛型 Action<T> 委派代替。
using System;

public class GenericFunc
{
    public static void Main()
    {

        Action<string> aConvertMethod = UppercaseString;
        string name = "Dakota";

        aConvertMethod(name);
        Console.ReadKey();
    }

    private static void UppercaseString(string inputString)
    {
        Console.WriteLine(inputString.ToUpper());
    }
}

三、
Action<T>泛型的委派型別,也是跟Func一樣,只是回傳值為void。
每個Func委派型別的簽章,傳入的參數會是零到四,而最後一個的型別參數是代表回傳型別。
例如:Func<string,int>,代表傳入型別為string而回型別為int。

2017年9月25日 星期一

Visual Studio 2012 無法啟動IIS Express Web 伺服器

Visual Studio 2012 無法啟動IIS Express Web 伺服器

http://marco.easyusing.com/2012/12/visual-studio-2012-iis-express-web.html

字串_Replace用法

String s = "文字1 - Microsoft word";

//先將空格轉為$,再將"-"刪
s = s.Replace(" ", "$").Replace("-", "");
 
結果
文字1$$Microsoft$word



C#中的IntPtr類型

https://read01.com/zh-tw/DAOJK.html#.WcjooMgjFPY

C#中的IntPtr類型

問:
c#中無法將類型「int」隱式轉換為「System.IntPtr」
這個是我引用了一個api函數時出現的問題,我在聲明中把intptr換成了int還是不可以,這是為什麼呢?要如何處理呢?

答:
您好,C#中的IntPtr類型稱為「平台特定的整數類型」,它們用於本機資源,如窗口句柄。
資源的大小取決於使用的硬體和作業系統,但其大小總是足以包含系統的指針(因此也可以包含資源的名稱)。

所以,在您調用的API函數中一定有類似窗體句柄這樣的參數,那麼當您聲明這個函數時,您應該將它顯式地聲明為IntPtr類型。

例如,在一個C#程序中調用Win32API mciSendString函數控制光碟驅動器,這個函數的函數原型是:

MCIERROR mciSendString
(
LPCTSTR lpszCommand,
LPTSTR lpszReturnString,
UINT cchReturn,
HANDLE hwndCallback
);

首先在C#中聲明這個函數:

[DllImport("winmm.dll")]

private static extern long mciSendString(string a,string b,uint c,IntPtr d);

然後用這樣的方法調用:

mciSendString("set cdaudio door open", null, 0, this.Handle);

您也可以使用IntPtr.Zero將句柄設置為0;

或者使用類型強制轉換:

mciSendString("set cdaudio door open", null, 0, (IntPtr)0 );

或者,使用IntPtr構造函數:

IntPtr a = new IntPtr(2121);

這裡有兩點比較重要:

一是在C#中聲明Win32API時,一定要按照WinAPI的原型來聲明,不要改變它的數據類型;

二是儘量不要過多使用類型強制轉換或構造函數的方式初始化一個IntPtr類型的變量,這樣會使程序變得難於理解並容易出錯。

希望這些信息對您有幫助。



2017年9月24日 星期日

如何使用 CAST 與 CONVERT 格式化日期與時間資料

如何使用 CAST 與 CONVERT 格式化日期與時間資料


http://ithelp.ithome.com.tw/articles/10008820


SSMS--T-SQL偵錯工具教學


http://blog.kkbruce.net/2011/01/ssms-t-sql.html#.WcdyAMgjFPY

2017年9月15日 星期五

asp.net-ExecuteNonQuery-的回傳值

ExecuteNonQuery 方法不會返回任何資料庫的資料, 它只會返回整數值來表示成功或受影響的資料列數目.


  • create

If use ExecuteNonQuery to create or modify database structure, eg. create table, this method returns -1 if success, returns 0 if fail.

ExecuteNonQuery 用來創建或修改資料庫的結構,如建立table,成功回1,失敗回0


  •  INSERT, UPDATE, DELETE

If use ExecuteNonQuery to INSERT, UPDATE, DELETE, this method returns the Number of affected data row, but if fail, it returns 0.

如果用來新增修改刪除,成功它會返回受影響的列數,失敗回0.

WPF聊天室应用(ASP.NET Core SignalR)

  WPF聊天室应用(ASP.NET Core SignalR) https://www.bilibili.com/video/BV1Q741187Si?p=2 https://www.bilibili.com/video/BV1UV411e75T?from=search...