SMTPサーバない時、テスト環境メール送信サンプル

  '''
    ''' テスト環境でメール保存
    ''' 参照サイト:http://keicode.com/dotnet/how-to-test-smtp.php
    '''
    Public Sub SendEmail()
        Dim mailFrom As String = "fromMailAddress@gmail.com"
        '送信先アドレス
        Dim toAddr As String = "toMailAddress@gmail.com"
        Dim subject As String = "メール件名"
        Dim body As String = "メール本文"
        Try

            Dim msg As MailMessage = New MailMessage(mailFrom, toAddr)
            'タイトル名
            msg.SubjectEncoding = System.Text.Encoding.GetEncoding("iso-2022-jp") '文字コードを設定 
            msg.Subject = subject

            '本文
            msg.BodyEncoding = System.Text.Encoding.GetEncoding("iso-2022-jp") '文字コードを設定
            msg.Body = body

            Dim sc As New System.Net.Mail.SmtpClient()
            'SMTPサーバーなどを設定する
            sc.Host = "smtp.test.co.jp" ''テスト環境
            sc.Port = 25

            If sc.Host = "smtp.test.co.jp" Then
                ''テスト環境にemlメール保存
                sc.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.SpecifiedPickupDirectory
                sc.PickupDirectoryLocation = "E:\temp"
            Else
                ''本番環境からメール送信
                sc.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network
            End If

            'メッセージを送信する
            sc.Send(msg)

            '後始末
            msg.Dispose()
            '後始末(.NET Framework 4.0以降)
            sc.Dispose()

        Catch ex As Exception
            ''エラー取得
        End Try
    End Sub


''----------------------------
''OUTPUT
''E:\tempフォルダを確認

C# Date count exclude saturday and sunday (土日以外の日付を計算する)

営業日の計算したいとき、UIからカレンダーの開始日と終了日を選択すると、土日含めて選択されるので、何営業日になっているかは判断できない。以下のサンプルでは土日以外の営業日を計算することができます。

-------------------------------------------------------------------------------------------------------


 private int DateRangeCountExcludeSaturdayAndSunday(DateTime startDate, DateTime endDate)
        {
            int totDateCount = 0;
            TimeSpan diff = endDate - startDate;

            int days = diff.Days;

            for (int i = 0; i < days; i++)
            {
                var testDate = startDate.AddDays(i);

                if (testDate.DayOfWeek != DayOfWeek.Saturday || testDate.DayOfWeek != DayOfWeek.Sunday)
                {
                    totDateCount += 1;
                }
            }

            return totDateCount;

}

iTextSharp PdfCell add original size image

     public void MyTestCreatePDF()
        {
            Document doc = null;

            try
            {
                //ドキュメントを作成
                doc = new Document();

                //ファイルの出力先を設定
                PdfWriter.GetInstance(doc, new FileStream("C:\\temp\\test.pdf", FileMode.Create));

                //ドキュメントを開く
                doc.Open();

                //Document.Add(new Paragraph("フォントを適用させたい文字列", Fontオブジェクト));
                string fontPath = Path.Combine(Environment.GetEnvironmentVariable("windir"), "fonts", "msgothic.ttc");

                //1 MSゴシック
                Font fnt1 = new Font(BaseFont.CreateFont(string.Format(@"{0},0", fontPath), BaseFont.IDENTITY_H, true), 10);

                // Image file path
                string noImage = Path.Combine(Application.StartupPath, "C:\\temp\\No_Image.jpg");

                //2列になるテーブルを作成
                iTextSharp.text.pdf.PdfPTable tbl = new PdfPTable(2);

                //各列の幅
                float[] colWidths = { 45, 95 };
                tbl.SetWidths(colWidths);

                //全体の幅(パーセンテージ)
                tbl.WidthPercentage = (100.0f);
                tbl.DefaultCell.Padding = 5;
                tbl.DefaultCell.Border = (PdfPCell.BOTTOM_BORDER);
               
                PdfPCell cell1 = new PdfPCell(new Phrase("Text1", fnt1));
                cell1.Colspan = 2;
                cell1.PaddingBottom = 5;
                tbl.AddCell(cell1);

                //[画像]
                Image pic = Image.GetInstance(noImage);

                //Image property setting
                pic.ScaleAbsolute(120, 140);
                pic.Border = Rectangle.BOX;
                pic.BorderColor = iTextSharp.text.BaseColor.BLACK;
                pic.BorderWidth = 5f;

                //the second parameter of the constructor is explicity passed for
                //clarity, and ensures the ScalePercent() call is honored
                //if you try and add the image directly, ScalePercent() is ignored
                //Cellの二つ目のプロパティ=falseにすると画像サイズ自動でセルと同じサイズに無視することができる
                //その後自分の指定サイズ設定できる
                PdfPCell cell2 = new PdfPCell(pic, false);
                cell2.Rowspan = 3;
                cell2.PaddingTop = 5;
                cell2.PaddingBottom = 5;
                cell2.HorizontalAlignment = Element.ALIGN_CENTER;
                //cell2.VerticalAlignment = Element.ALIGN_MIDDLE;
                tbl.AddCell(cell2);

                PdfPCell cell3 = new PdfPCell(new Phrase("Text2", fnt1));
                cell3.PaddingBottom = 5;
                tbl.AddCell(cell3);

                PdfPCell cell4 = new PdfPCell(new Phrase("Text3", fnt1));
                cell4.PaddingBottom = 5;
                tbl.AddCell(cell4);

                PdfPCell cell5 = new PdfPCell(new Phrase("Text4", fnt1));
                cell5.PaddingBottom = 5;
                tbl.AddCell(cell5);


                PdfPCell cell6 = new PdfPCell(new Phrase("Text5", fnt1));
                cell6.PaddingBottom = 5;
                tbl.AddCell(cell6);

                PdfPCell cell7 = new PdfPCell(new Phrase("Text6", fnt1));
                cell7.PaddingBottom = 5;
                tbl.AddCell(cell7);

                doc.Add(tbl);

            }
            catch (Exception ex)
            {

                throw ex;
            }
            finally
            {
                //ドキュメントを閉じる
                doc.Close();
                doc = null;
            }

        }


//==============================================================

How to get next or previous record in T-SQL

SELECT
     id AS SP_ID
   , desc AS DESCRIPTION
   , part_no AS PART_NO
   , order AS ORDER_NO
   , updts AS UPDATE_DATE
 FROM  Table1 
 ORDER BY  id

        OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY 

MergeCells

Imports NPOI.SS.UserModel
Imports NPOI.HSSF.Util  
''---------------------------------- 
Public Sub MergeCells()
        Dim srcWB As HSSFWorkbook = Nothing
        Dim filePath = "C:\test.xls"
        Using fs As New FileStream(filePath, FileMode.Open, FileAccess.Read)
            srcWB = New HSSFWorkbook(fs)
        End Using

        Dim sheet As HSSFSheet = srcWB.GetSheetAt(0)
      
        'Set row number
        Dim startRow = 2
        Dim endRow = 4

        'Set column number
        Dim startColumn = 2
        Dim endColumn = 2

        sheet.AddMergedRegion(New CellRangeAddress(startRow, endRow, startColumn, endColumn))

        Dim savePath As String"C:\test1.xls"
        Using fs As New FileStream(savePath, FileMode.Create, FileAccess.Write)
            srcWB.Write(fs)
        End Using

        MsgBox("done")

    End Sub