2013年7月31日 星期三

[除錯] IIS(FTP)伺服器(繁體XP系統),無法上傳簡體檔案之解決!

原因:
繁體系統的IIS(FTP)伺服器,無法支援簡體中文!

解決:
1.改用支援簡體中文的FTP SERVER來架設!
2.限制檔案名稱僅可為「繁中」、「英數」!
3.將簡體轉為繁體,再上傳至FTP!
4.將FTP檔案存為(sn)-Guid,
而資料庫則存為 sn, 檔名+Guid as 檔名,
程式顯示時取檔名, 下載時則取(sn)-Guid...

Path.GetFileName(txbPath.Text.Trim).ToString & "+" & BitConverter.ToInt64(Guid.NewGuid().ToByteArray(), 0).ToString
傳回不重覆的長度 19 GUID 數字

 參考:
Directory 類別
DirectoryInfo 類別
HOW TO:列舉目錄和檔案
HOW TO:逐一查看目錄樹狀結構 (C# 程式設計手冊)
C#-批次處理目錄下所有檔案的方法
[C#]使用 Path 類別取得檔案或目錄路徑資訊
[C#]Winform選擇目錄路徑(FolderBrowserDialog)與選擇檔案名稱(OpenFileDialog)的用法
[programming-c#]把目錄下的檔案列出來, DirectoryInfo, StreamWriter
C#資料夾選擇框的實現(C#選擇資料夾,C# 打開資料夾,C# 流覽資料夾,C#怎麼選擇資料夾)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
//需加入參考 Microsoft.VisualBasic
using Microsoft.VisualBasic;

namespace trans2zhtw
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (!System.IO.Directory.Exists(this.txtDirectoryPath.Text))
            {
                //throw new ArgumentException();
                MessageBox.Show("請選擇目錄!!");
                return;
            }
               
            foreach (FileInfo file in RootDirs.GetFiles())
            {
                //MessageBox.Show(file.FullName);
                //MessageBox.Show(file.Directory.FullName); = MessageBox.Show(file.DirectoryName);
                FileSystem.Rename(file.FullName, file.DirectoryName + @"\" + Strings.StrConv(file.Name, VbStrConv.TraditionalChinese, 2052));
            }
        }

        DirectoryInfo RootDirs;
        DirectoryInfo[] SubDirs;
        FileInfo[] RootFiles;
        FileInfo[] SubFiles;
        private void button3_Click(object sender, EventArgs e)
        {
            richTextBox1.Clear();
            txtDirectoryPath.Clear();

            //選擇目錄
            FolderBrowserDialog path = new FolderBrowserDialog();
            //MessageBox.Show(path.ShowDialog().ToString());

            //if (System.IO.Directory.Exists(path.SelectedPath))
            if(path.ShowDialog()==DialogResult.OK)
            {
                this.txtDirectoryPath.Text = path.SelectedPath;

                //System.IO.DirectoryInfo
                RootDirs = new DirectoryInfo(txtDirectoryPath.Text);

                //取得所有檔案(含子目錄)
                RootFiles = RootDirs.GetFiles();

                //取得所有目錄(含子目錄)
                SubDirs = RootDirs.GetDirectories();

                richTextBox1.Text += "[主目錄][" + RootDirs.Name + "]" + "\n";
                foreach (FileInfo file in RootDirs.GetFiles())
                    richTextBox1.Text += file.Name + "\n";

                richTextBox1.Text += "\n";

                //取得主目錄下的子目錄, 不包含子目錄下的子目錄...
                foreach (DirectoryInfo sdir in SubDirs)
                {
                    richTextBox1.Text += "[子目錄][" + sdir.Name + "]" + "\n";

                    //取得目各子目錄下所有檔案
                    SubFiles = sdir.GetFiles();
                    foreach (FileInfo file in SubFiles)
                        richTextBox1.Text += file.Name + "\n";
                }
            }
        }
    }
}


[C#] 簡體亂碼轉換
繁體的IIS FTP 不能上傳簡體文件

請教簡體XP顯示繁體中文問題!
怎样才能是繁体和简体的操作系统都能看到简体FTP服务器里面的数据

[VB.NET]中文繁簡體轉換
在 VB.Net 中使用 StrConv 函數進行繁簡字體轉換

如何判断用户在Textbox输入的字符是否为繁体字
VB.NET判断字符是否是GB2312-80的汉字
简体繁体判断

FileSystem.Rename 方法
【VB.Net】使用rename修改檔名
如何使用FileInfo修改檔名

不同語系的轉碼、編碼 / HttpUtility.UrlEncode,Server.UrlEncode兩者差異
如何用 VB 或 VB.Net 來撰寫 ASP 的 Server.URLencode 函數

[SQL] 簡體字存入亂碼解決方式

參考:C#
How can I rename a file in C#?
C# 繁簡轉換效能大車拚
[C#]繁簡轉換好用的類別庫-Microsoft Visual Studio International Pack
C#簡繁轉換
C#中汉字的繁体和简体的相互转换的两个方法!

2013年7月30日 星期二

[除錯] TabControl 內的控制項 與 資料繫結 DataBindings, 卻檢查出空白值!

原因:
1.



控制項(TextBox、ComboBox, etc...) 在TabControl時, 且有資料繫結DataBinding(確實有值)
當儲存(檢查控制項是否空白)時, 卻會檢查出此控制項為空白!

2.
tabPage1有DataGridView綁定 bindingsource
當tabPage2為顯示頁時,此時執行 bindingsource.CancelEdit()
則會引發錯誤:
System.ArgumentOutOfRangeException 未處理
  Message=提供的資料列索引超出範圍。
參數名稱: rowIndex
  Source=System.Windows.Forms
  ParamName=rowIndex
  StackTrace:
       於 System.Windows.Forms.DataGridViewRowCollection.GetRowState(Int32 rowIndex)


解決:how to force all controls on all tab pages of a tab control to load/createhandle at once?
1.
//讓不同的tabPage的Control可以load DataBinding資料
foreach (var v in tabControl1.Controls.OfType<TabPage>())
     v.Show();

2.
執行程式時, 需每個TABPAGE都(手動)點過!

3.
        TabPage1.Show()
        TabPage2.Show()
        TabPage3.Show()
        TabPage4.Show()

4.
dgvM.DataSource = null;
bdNavi.BindingSource.RemoveCurrent();(或 bdNavi.BindingSource.CancelEdit();)  <--- 出錯點
bdNavi.BindingSource.ResetBindings(false);
dgvM.DataSource = bs;

2013年7月22日 星期一

[技巧] ReportViewer 動態改變TableRow是否顯示(或隱藏)

目的:
當某些欄位的值為0(或空白, 或其它條件)時, 則將此TableRow隱藏

解決:
「透過動態改變TableRow的Visibility」
選擇某個TableRow -> 屬性 -> Visibility -> 運算式
1) 一個欄位來決定Visibility
=iif(Fields!加班補貼.Value=0,true,false)

2) 二個欄位來決定Visibility
=iif(Fields!效率獎金.Value=0,iif(Fields!所得稅.Value=0,true,false),false)

3) N個欄位來決定Visibility
......

參考:

[學習] ReportViewer SubReport 子報表

CODE:使用 自定義事件 DemoSubreportProcessingEventHandler

[除錯] 無法在 System.Int32 和 System.String 上執行 Like 作業

1.你的ID欄位是數值並無法使用Like
2.在SQL語法可用"CAST(ID AS varchar) Like '" & FilterTextBox.Text & "%'"
3.PID的书籍类型修改为varchar后问题解决
4.bigDT.DefaultView.RowFilter = "CONVERT(SUBSTRING(CONVERT(date_posted, 'System.String'), 5, 4), 'System.Int32')=2012";


參考:
[MSDN]CAST 和 CONVERT (Transact-SQL)
[MSDN]DataColumn.Expression 属性
SQL函數 查詢SQL資料欄位相符的字串
MSSql 中Charindex ,Substring的使用
CHARINDEX (Transact-SQL)

DataView RowFilter遇到要篩選日期的方法 (空白或非空)
求助?无法在System.int32和System.string上执行“like”操作
无法在 System.Int32 和 System.String 上执行 Like 操作
問一個資料轉型的問題?
C#断开式数据库连接的DataView数据筛选的问题
DataTable使用方法
[SQL]數值轉字串
How to use LIKE operator in Dataview.RowFilter for Date Time or Numaric Fields using CONVERT


2013年7月10日 星期三

[SQL] 找出最新日期, 最舊日期, 最大值, 最小值

select e.*,f.姓名,f.部門,f.name from salary_month as e left join (select c.staff_sn,c.zhFname+c.zhName as 姓名,c.部門,d.name from employee as c left join (select a.* from employeePosition as a ,(select staff_sn,max(createDate) as createDate from employeePosition GROUP BY staff_sn) as b where a.staff_sn = b.staff_sn and a.createDate = b.createDate) as d on d.staff_sn = c.staff_sn) as f on e.emp_sn = f.staff_sn where e.日期 = '201306';

加入(身份2)
select e.*,f.姓名,f.部門,f.name,z.身份2 from salary_month as e left join (select a.emp_sn,a.身份2  from salary_basic as a, (select emp_sn,max(調整日期) as 調整日期 from salary_basic GROUP BY emp_sn) as b where a.emp_sn = b.emp_sn and a.調整日期 = b.調整日期 and a.身份2=1) as z on z.emp_sn = e.emp_sn  left join (select c.staff_sn,c.zhFname+c.zhName as 姓名,c.部門,d.name from employee as c left join (select a.* from employeePosition as a ,(select staff_sn,max(createDate) as createDate from employeePosition GROUP BY staff_sn) as b where a.staff_sn = b.staff_sn and a.createDate = b.createDate) as d on d.staff_sn = c.staff_sn) as f on e.emp_sn = f.staff_sn where e.日期 = '201306' and z.身份2 = 1;

參考:
[SQL] 找出職員最新一筆薪資調整紀錄並取得其職務名稱與任職日
SQL_找出最新日期、最舊日期、最大值、最小值
SQL的使用技巧_MAX()、MIN()與Group By、HAVING
請教一個麻煩的 SQL 語法?要找出每個會員的最新一筆訂單資料
請問如何在多個客戶下,找出每一個客戶跟我交易最近的日期
只抓取日期最大的單據資料
SELECT only the rows with MAX(DATE)
Need a little help, SQL Server 2000, having and max(date)
SQL语句练习实例之一——找出最近的两次晋升日期与工资额
Linq小技巧:日期處理
多個各自count之後還要join成一張表

2013年7月8日 星期一

[除錯] 大表(表頭)從小表(明細)取得計算的資料(sum,count,max,min,etc...), 並join到大表(表頭)

ERROR:
因為它並未包含在彙總函數或 GROUP BY


解決:
        Dim dt_month = staffDB.DataTable("select a.*,isnull(b.行政費用總計,0) as 行政費用總計 from [salary_month] a left join ( select salary_month_sn,sum(金額) as 行政費用總計 from [salary_month_others] Group by salary_month_sn ) b on a.sn = b.salary_month_sn where a.emp_sn = " & staffarr(0) & ";", Nothing, Nothing)


(可略)
        Dim dt_month_others = staffDB.DataTable("SELECT * FROM [salary_month_others] WHERE emp_sn =" & staffarr(0) & " and salary_month_sn = " & If(dt_month.Rows.Count > 0, dt_month.Rows(0)("sn").ToString, "0") & "", Nothing, Nothing)


參考:
EXISTS (Transact-SQL)
order by后有多个条件怎么写?
最近在使用Microsoft SQL Server Management Studio
SQL語法問題
請問group群組然後select
mssql group by的問題
grouping 排序的問題 (解決處)
sum left join 多次引发的问题
急..Help..Join 無明細資料時怎麼顯示主檔,且sum欄位
SQL group by 詳細用法
SQL group by用法
SQL::GROUP BY, COUNT and HAVING
多個各自count之後還要join成一張表