2018年9月13日 星期四

[學習][RDLC] 報表頁數 依照群組分頁 Reset Page Number in RDLC Report by group


It can be done actually, but not without adding some custom code to the report:
Shared reportGroup as String
Shared newPage  as Integer

Public Function ResetPageNumber(newGroup as String)
  If Not (reportGroup = newGroup)
    reportGroup = newGroup 
    newPage  = 1
  Else
    newPage  = newPage  + 1
  End If
  Return newPage
End Function
Then in the footer, add text box for page number and make it's value:
= Code.ResetPageNumber(ReportItems!TextBoxWithYourGroupNameOrID.Value)

參考:
https://stackoverflow.com/questions/23300494/reset-page-number-in-rdlc-report-by-group
https://www.codeproject.com/Questions/1195280/Resetting-page-number-if-group-changes-in-RDLC-rep

注意:
頁尾一次只能參考一個欄位,如需多欄位的話,可以在最內的群組做組合即可。
或者資料群已做好排序,只要按最內的群組做分頁也可以,因為會重新RESET。

2017年12月4日 星期一

【除錯】Double 資料行的預設值無法使用,而消費者尚未設定新 Double 值。


問題:
1.提供者無法決定 Double 值。例如,剛建立資料列,Double 資料行的預設值無法使用,而消費者尚未設定新 Double 值。

2.提供者無法決定 Int16 值。例如,剛建立資料列,Int16 資料行的預設值無法使用,而消費者尚未設定新 Int16 值

解決:
當你看到類似的句子時,沒有錯不要懷疑,就是你的SQL要修改。

1.造成此次問題的原因為ACCESS中,SQL將數值除以零時所導致。SQL在ACCESS可正常執行,但除以零的欄位會顯示【錯誤】,而在程式介面CRUD撈完資料要塞入DataTable時,此時便會產生如問題所述之警告文字,因而程式中斷。

只要將SQL語法判斷零的字數,並依自己的程式需求改為正確的語法即可。
例如:將會導致錯誤的零改為正一或負一即可。

2.double 轉 int 精準度問題,CInt會直接報錯誤

2015年6月10日 星期三

[除錯] DataGridView RowValidating事件, 當按Escape取消時, 不要引發該事件...

as title...

參考:
Escaping DataGridView Row creation fires RowValidating. How to avoid this?

1)
private void dataGridView1_KeyDown(object sender, KeyEventArgs e) 
     if (e.KeyCode == Keys.Escape) 
          this.dataGridView1.RowValidating -= 
               new System.Windows.Forms.DataGridViewCellCancelEventHandler(this.dataGridView1_RowValidating); 

     this.dataGridView1.RowValidating += 
          new System.Windows.Forms.DataGridViewCellCancelEventHandler(this.dataGridView1_RowValidating); 
}


2)
if (!view.IsCurrentRowDirty ) return; 


2015年2月12日 星期四

[學習] 在C#實現VB函式【IsNumeric】

【CODE】
        static bool IsNumeric(object Expression)
        {
            // Variable to collect the Return value of the TryParse method.
            bool isNum;
            // Define variable to collect out parameter of the TryParse method. If the conversion fails, the out parameter is zero.
            double retNum;
            // The TryParse method converts a string in a specified style and culture-specific format to its double-precision floating point number equivalent.
            // The TryParse method does not generate an exception if the conversion fails. If the conversion passes, True is returned. If it does not, False is returned.
            isNum = Double.TryParse(Convert.ToString(Expression), System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out retNum);
            return isNum;
        }

【CODE】
        public static bool IsNum(String str)
        {
            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] < '0' || str[i] > '9')
                    return false;
            }
            return true;
        }

參考:
判断一个字符串是否全是数字的多种方法及其性能比较(C#实现)
[C#]IsNumeric 判斷是否為數值
[C#]數值驗證 IsNumeric
C# Equivalent of VB's IsNumeric()
C# IsNumeric
C#的判斷是否為數字,難道只能用Try、Catch嗎?..沒有VB.NET的IsNumeric可用嗎