顯示具有 C sharp 標籤的文章。 顯示所有文章
顯示具有 C sharp 標籤的文章。 顯示所有文章

2018年2月13日 星期二

Winform直接列印pdf

 [DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern bool SetDefaultPrinter(string Name);
        private void Print_Click(object sender, EventArgs e)
        {
            try
            {


                //設定針測的檔案類型,如不指定可設定*.*
                string strFilePath = @"C:\inetpub\wwwroot\TEST\Report\PdfPrint\";
                FileSystemWatcher watch = new FileSystemWatcher(strFilePath, "*.pdf");
                //開啟監聽
                watch.EnableRaisingEvents = true;
                //新增時觸發事件
                watch.Created += watch_Created;
                Print.Enabled = false;


            }
            catch (Exception ex)
            {

            }
        }

        private void watch_Created(object sender, FileSystemEventArgs e)
        {
            try
            {
                string DirectPath = e.FullPath;

                //如果偵測到為檔案,則依路徑對此料夾做檔案處理
                if (File.Exists(DirectPath))
                {
                    //string s = @"C:\inetpub\wwwroot\SalesAppTest\Report\PdfPrint\07031_CEM20180100569_JENNY.pdf";
                    int intIndex = DirectPath.IndexOf("_");
                    string strPrintName = DirectPath.Substring(48, intIndex - 48);//string s = @"C:\inetpub\wwwroot\SalesAppTest\Report\PdfPrint\
                    string strFileName = DirectPath.Substring(48, DirectPath.Length - 48);
                    SetDefaultPrinter(strPrintName);

                    //begin
                    System.Diagnostics.ProcessStartInfo info = new ProcessStartInfo();
                    info.Verb = "print";
                    info.FileName = @"C:\Users\Administrator\Documents\visual studio 2012\Projects\WinDirectPrint\WinDirectPrint\FoxitReaderPortable\FoxitReaderPortable.exe";
                    info.CreateNoWindow = true;
                    info.UseShellExecute = false;
                    info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                    info.Arguments = @"/p /h " + DirectPath;

                    Process p = new Process();
                    p.StartInfo = info;
                    p.Start();
                    //end   

                }
            }
            catch (Exception ex)
            {
            }
        }

2017年6月11日 星期日

所有基態null處理(泛型+擴充方法)

    ///
    /// 擴充方法ObjectIsNullOrEmpty
    /// 適用於所有型態有null值時直接回傳DBNull.Value
    ///
    public static class Extension
    {
        public static object ObjectIsNullOrEmpty(this T value)
        {
            if (value == null || string.IsNullOrEmpty(value.ToString()))
            { return DBNull.Value; }
            else
                return value;

        }

    }

2016年10月16日 星期日

Visual Studio 快速鍵

Visual Studio 快速鍵

多了這些快速鍵就可以加快開發腳步了
編輯快捷鍵
CTRL + F4                         關閉程式頁籤
SHIFT + ALT + ENTER       切換全螢幕顯示
CTRL + F                           尋找
CTRL + SHIFT + F              在檔案中尋找
CTRL + H                           取代
CTRL + SHIFT + H              在檔案中取代
CTRL + 左右方向鍵             一次移動一個單詞
CTRL + 上下方向鍵             滾動程式編輯區,但不移動游標位置
CTRL + Page Up                游標移動到目前程式編輯區的最上方
CTRL + Page Down            游標移動到目前程式編輯區的最下方
CTRL + SHIFT + 左右方向鍵       一次移動多選取一個單詞
SHIFT + 上下方向鍵                   上下移動選取區塊
CTRL + M M                  隱藏或展開游標所在的 region 的折疊狀態
CTRL + M L                   將所有過程設置為相同的隱藏或展開狀態
CTRL + G                      移動到指定行號位置
CTRL + A                      全選
CTRL + C                      複製
CTRL + V                      貼上
CTRL + Z                      復原
CTRL + Y                      取消復原
CTRL + SHIFT + Z          復原關閉的程式編輯視窗(Undo Close)
SHIFT + ALT + 方向鍵      選擇矩形區塊
ALT + 滑鼠左鍵                選擇矩形區塊
CTRL + SHIFT + U         反白區塊文字變為大寫
CTRL + U                      反白區塊文字變為小寫
CTRL + SHIFT + L         刪除目前行
CTRL + X                      刪除目前行
CTRL + K C               註解選定內容
CTRL + K U               取消註解選定內容
CTRL + K X               插入程式區段
CTRL + K S               插入外側代碼
Tab                      增加縮排
SHIFT + Tab         減少縮排
F12                      移到定義
SHIFT + F12         尋找所有參考
CTRL + K T           檢視呼叫階層
SHIFT  + F7           切換「設計檢視」以及「原始檔」顯示
CTRL + ALT + L           檢視方案總管
CTRL + ALT + X           檢視工具列
F4                               檢視屬性(Properties)
CTRL + ALT + O           檢視輸出
CTRL + \ E                   檢視錯誤清單 (Error List)
CTRL + \ T                    檢視工作清單(Task List)
CTRL + SHIFT + J         更新JScript Intellisense (於網頁設計畫面或JavaScript中使用才會更新)

建置
F6                         建置方案
Shift + F6               建置當前的專案
ALT + B, B             建置方案(Build Solution)
ALT + B, U             建置所選的專案(build selected Project), 
ALT + B, R             重建方案(rebuild Solution)
ALT + B, C             清除方案

偵錯
F5                           開始偵錯 / 繼續
Ctrl + F5                  開始執行(不調試)
Shift + F5                 停止偵錯
Ctrl + Shift + F5        重新啟動偵錯
Ctrl + Alt + Break      全部中斷(暫停)
Ctrl + Alt + P             顯示「附加至處理序」視窗
F10                          不進入函式
Ctrl + F10                 執行到游標處
F11                          逐步執行
Shift + F11                跳離函式
F9                            切換中斷點
Ctrl + F9                   啟用/停止中斷點
Ctrl + Shift + F9        刪除所有中斷點
Ctrl + D + Q              快速監看式
F7                            於Visual Studio的偵錯環境下,如果Focus為非程式編輯區,按下F7就會Focus到程式編輯區

參考
http://kevintsengtw.blogspot.tw/2011/09/visual-studio_18.html

2011年2月28日 星期一

可為 Null 的型別概觀

http://msdn.microsoft.com/zh-tw/library/1t3y8s4s.aspx

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//20110218 jenny 法院解交
if (cmb_TrxTypeCode.SelectedItem.ToString() == "一般過戶" || cmb_TrxTypeCode.SelectedItem.ToString() == "法院解交")
{
if (frm_ReciverQ.cmb_ExcAcc.SelectedIndex != -1)//null處理
{
txt_ExcAccId.Tag = frm_ReciverQ.cmb_ExcAcc.SelectedValue.ToString();
txt_ExcAccId.Text = frm_ReciverQ.cmb_ExcAcc.SelectedText.ToString();
}
}

2011年2月17日 星期四

正式環境將某模組copy至測試環境無法發行

正式環境將某模組copy至測試環境無法發行
=>因正式環境金鑰和測試環境金鑰不同
簽署-->建立測試憑證(R)後,再發行就OK了

2009年10月1日 星期四

測試CurrencyNegativePattern

核心程式設計畢業考看不懂的題目,挖出來看看怎麼做
題目:大致上是如果給貨幣加上一個負號。
關鍵在這兩行設定…就這麼簡單
nfi.CurrencyNegativePattern = 1
listBox1.Items.Add("pattern # " + i + ":" + num.ToString("C", nfi));

=====================================================
實作範例
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Globalization;

namespace M_70536
{
public partial class frm_CurrencyNegativePattern : Form
{
public frm_CurrencyNegativePattern()
{
InitializeComponent();
}

private void btn_OK_Click(object sender, EventArgs e)
{
NumberFormatInfo nfi = new NumberFormatInfo();
decimal num = -9999.00m;
for(int i=0;i<=15;i++){ nfi.CurrencyNegativePattern = i;
nfi.CurrencySymbol = "$";
listBox1.Items.Add("pattern # " + i + ":" + num.ToString("C", nfi));

}
}
}
}

2009年9月30日 星期三

命名空間(M01)

using關鍵字與命名空間
使用命名空間分類及避免命名衝突
  • 直接使用命名空間
System.Console.WriteLine("AAA");
  • 使用using關鍵字引用命名空間
using System;
Console.WriteLine("AAA");
==============================
常用命名空間
System:基本程式所需要物件類別定義
System.Xml:提供處理XML資料時所需要的物件類別定義
System.Net:提供處理網路存取所需的物件類別定義
System.Data:提供ADO.NET存取資料所需要的物件類別定義
==============================
編譯應用程式
  • .NET Framework所提供C#編輯器
檔名:csc.exe
路徑:%WindowDir%\Microsoft.NET\Framework\v2.0.50727
cmd編譯
=>csc /out:HelloWorld.exe HelloWorld.cs
=>/out:用來設定編譯後輸出編件的檔名