■NuGetでインストール
https://www.nuget.org/packages/NLog/2.1.0
PM> Install-Package NLog -Version 2.1.0
プロジェクトにNLog.dllとNlog.config を追加し、Nlog.configのプロパティで「出力ディレクトリにコピー」を「常にコピーする」にしておくこと!!
■一定期間がたったログを削除する場合
※現在のログは/logs/log.txtに保存され、昨日から120日前のログは/logs/archives/log.yyyyMMdd.txtに格納し、それ以前のは削除される。
<target name="f" xsi:type="File"
fileName="${basedir}/logs/log.txt"
layout="${longdate} ${uppercase:${level}} ${message}"
archiveFileName="${basedir}/logs/archives/log.{#}.txt"
archiveEvery="Day"
archiveNumbering="Date"
maxArchiveFiles="120"
/>
カテゴリー: 未分類
クラス名でインスタンスを生成
Shared関数などで、自クラスのインスタンスを生成
Public Shared Sub Create(ByVal opeNo As String)
Dim m As System.Reflection.MethodBase = System.Reflection.MethodBase.GetCurrentMethod()
Dim t As Type = Type.GetType(m.DeclaringType.FullName)
Dim oAs Object = Activator.CreateInstance(t)
End Sub
Oracle.DataAccess.Client を参照設定しない
Imports System.Data.Common
' プロバイダファクトリ作成
Dim fact As DbProviderFactory = DbProviderFactories.GetFactory("Oracle.DataAccess.Client")
' ファクトリにて DbConnection へ固有プロバイダのインスタンス化
Using cnn As DbConnection = fact.CreateConnection()
cnn.ConnectionString = TextBox2.Text
cnn.Open()
' ファクトリにて DbCommand へ固有プロバイダのインスタンス化
Dim cmd As DbCommand = fact.CreateCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT COUNT(*) FROM Production.Product"
MessageBox.Show(cnn.ToString() & " / " & cmd.ToString())
MessageBox.Show("行数 = " & cmd.ExecuteScalar().ToString())
End Using
http://se.ykysd.com/2015/06/26/dbproviderfactories/
https://code.msdn.microsoft.com/windowsdesktop/10-VB-64b532ff
○動的アセンブリロード
http://shinshu.fm/MHz/88.44/archives/0000437259.html
Form Load内の例外
Form.Show()したときのForm_Load内で発生した例外は、親フォームでキャッチできないのは、親フォームと異なるスレッドの為。Form.ShowDialog()であれば、親フォームでキャッチできる。
仕方が無いのでInitForm()を作成し、Form_Loadでは基本的には何もしないこととした。
C++ DLLの情報を見る
○依存関係を出力 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\dependents.exe /exports test.dll C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\dumpbin.exe /exports test.dll
DataAdapter
SqlDataAdapter da = new SqlDataAdapter(); da.FillSchema(ds, SchemaType.Source, key); ・・・これがあるとMaxLength等が取得できる da.Fill(ds, key);
関数名を取得
Public Shared Sub Main() Dim Nm As String = GetType(ClsMain).ToString & " : " & System.Reflection.MethodInfo.GetCurrentMethod.Name Dim Nm As String = Me.GetType.ToString & " : " & System.Reflection.MethodInfo.GetCurrentMethod.Name
DesignModeを判定する
フォームのコンストラクタはデザイン時でも実行されるらしく、存在しないファイルへアクセスなどしているとトラブルになるので、デザイン時かどうか判定する。
bool ret = false;
if (System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime) ret = true;
if (System.Diagnostics.Process.GetCurrentProcess().ProcessName.ToUpper().Equals("DEVENV")) ret = true;
return ret;
ActiveReports
○ReportStartイベント内でコントロールを動的に追加できるが、その後のイベントで追加すると、問題が発生する
コントロールの表示を変更する
Me.txtDate.Text += “年”
コントロールの色を変える
Me.txtItem.ForeColor = Color.Blue
改ページ制御をする
Me.Detail1.NewPage = NewPage.After
1行ごとに色を変える
Me.Detail1.BackColor = Color.Blue
ページに直接描画をする
Private Sub ProductList_ReportEnd(sender As System.Object, e As System.EventArgs) Handles MyBase.ReportEnd
For i As Integer = 0 To Me.Document.Pages.Count - 1
Dim p As GrapeCity.ActiveReports.Document.Section.Page
p = Me.Document.Pages(i)
' 描画する領域
Dim rect As New RectangleF(0.5, 0.5, 1, 0.2)
' 描画に必要な設定をしておく
p.BackColor = Drawing.Color.Transparent
p.PenStyle = GrapeCity.ActiveReports.Document.Section.PenStyles.Solid
p.TextAlignment = GrapeCity.ActiveReports.Document.Section.TextAlignment.Center
' ページ数を描画する
p.DrawText((i + 1) & "ページ", rect)
' 枠を描画する
p.DrawRect(rect)
Next
End Sub
アンバウンドレポート
次の出力位置へ移動し、同じレコードのままでデータを出力 (C#)this.LayoutAction = GrapeCity.ActiveReports.LayoutAction.LayoutAction.MoveLayout|GrapeCity.ActiveReports.LayoutAction.LayoutAction.PrintSection; (VB.Net)Me.LayoutAction = 3 次の出力位置へ移動し、次のレコードを取得してデータを出力(デフォルト) (C#)this.LayoutAction = GrapeCity.ActiveReports.LayoutAction.LayoutAction.MoveLayout|GrapeCity.ActiveReports.LayoutAction.LayoutAction.NextRecord|GrapeCity.ActiveReports.LayoutAction.LayoutAction.PrintSection; (VB.Net)Me.LayoutAction = 7
アンバウンドフィールド
○任意のレコード数ごとにレポートで空白行を表示させる方法(Access)
VC++
○CArray
ウォッチ式に m_pData, 10 で10個分の内容が確認できる。