2018年3月19日 星期一

SQL ROW_NUMBER() 用法

語法:ROW_NUMBER() OVER(PARTITION BY COLUMN ORDER BY COLUMN)

row_number()從1開始,PARTITION BY COLUMN 以群組給序號,ORDER BY COLUMN DESC 降冪,ASC升冪
SELECT ROW_NUMBER() OVER(ORDER BY flex_value) row,flex_value
FROM dbo.[APP_FND_FLEX_VALUES]
--某些程式一定要key,又找不到主key時,可以用這個方式處理
row flex_value
1 000
2 000
3 001
4 001
5 001
6 001
7 001
8 001
9 001
10 001

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)
            {
            }
        }