Step1:插入 => 連結
Step2:輸入 [要顯示的文字] 並在 [網址] 內輸入網址
Step3:以上兩步驟即完成超連結設定,如果要在 Word 內點擊並進行網頁連結,要按 Ctrl + 滑鼠左鍵
萬一已經有文字說明的話,可以直接按右鍵,選單內有 [連結] 選項
- 參考文章
- 網頁版 Word 中的超連結
using System.Text;
namespace FileSystemWatcherSample
{
internal class Program
{
static void Main(string[] args)
{
using var watcher = new FileSystemWatcher();
// 預設值為空值
watcher.Path = @"D:\FileSystemWatcherDir";
// 預設值為 NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName
watcher.NotifyFilter = NotifyFilters.Attributes
| NotifyFilters.CreationTime
| NotifyFilters.DirectoryName
| NotifyFilters.FileName
| NotifyFilters.LastAccess
| NotifyFilters.LastWrite
| NotifyFilters.Security
| NotifyFilters.Size;
// 預設值為 false
watcher.EnableRaisingEvents = true;
// 預設值為 "*.*" (監看全部檔案)
watcher.Filter = "*.txt";
// 預設值為 false
watcher.IncludeSubdirectories = true;
// 預設值為 8,192 (8k)
watcher.InternalBufferSize = 8192;
// Changed、Created 和 Deleted 皆為 FileSystemEventArgs,可以共用
watcher.Changed += OnChanged;
watcher.Created += OnChanged;
watcher.Deleted += OnChanged;
// Renamed 為 RenamedEventArgs
watcher.Renamed += OnRenamed;
// Error 為 ErrorEventArgs
watcher.Error += OnError;
Console.WriteLine("Press enter to exit.");
Console.ReadLine();
}
private static void OnChanged(object sender, FileSystemEventArgs e)
{
Console.WriteLine($"{e.ChangeType}: {e.FullPath}");
}
private static void OnRenamed(object sender, RenamedEventArgs e)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine($"{e.ChangeType}:");
sb.AppendLine($" Old: {e.OldFullPath}");
sb.AppendLine($" New: {e.FullPath}");
Console.WriteLine(sb.ToString());
}
private static void OnError(object sender, ErrorEventArgs e)
{
PrintException(e.GetException());
}
private static void PrintException(Exception? ex)
{
if (ex == null)
return;
StringBuilder sb = new StringBuilder();
// This can happen if Windows is reporting many file system events quickly
// and internal buffer of the FileSystemWatcher is not large enough to handle this
// rate of events. The InternalBufferOverflowException error informs the application
// that some of the file system events are being lost.
if (ex.GetType() == typeof(InternalBufferOverflowException))
sb.AppendLine("Error 事件觸發,Internal Buffer Overflow 發生");
else
sb.AppendLine("Error 事件觸發,錯誤訊息如下");
sb.AppendLine(ex.ToString());
Console.WriteLine(sb.ToString());
PrintException(ex.InnerException);
}
}
}
When a directory is renamed, the FileSystemWatcher automatically reattaches itself to the newly renamed item. For example, if you set the Path property to "C:\My Documents" and then manually rename the directory to "C:\Your Documents", the component continues listening for change notifications on the newly renamed directory. However, when you ask for the Path property, it contains the old path. This happens because the component determines what directory watches based on the handle, rather than the name of the directory. Renaming does not affect the handle. So, if you destroy the component, and then recreate it without updating the Path property, your application will fail because the directory no longer exists.
You can set the buffer to 4 KB or larger, but it must not exceed 64 KB. If you try to set the InternalBufferSize property to less than 4096 bytes, your value is discarded and the InternalBufferSize property is set to 4096 bytes. For best performance, use a multiple of 4 KB on Intel-based computers.
The system notifies the component of file changes, and it stores those changes in a buffer the component creates and passes to the APIs. Each event can use up to 16 bytes of memory, not including the file name. If there are many changes in a short time, the buffer can overflow. This causes the component to lose track of changes in the directory, and it will only provide blanket notification. Increasing the size of the buffer can prevent missing file system change events. However, increasing buffer size is expensive, because it comes from non-paged memory that cannot be swapped out to disk, so keep the buffer as small as possible. To avoid a buffer overflow, use the NotifyFilter and IncludeSubdirectories properties to filter out unwanted change notifications.
using System.ComponentModel.DataAnnotations.Schema;
namespace EFCoreMigration.Models
{
public class Clothes
{
public int ClothesID { get; set; }
public string ClothesName { get; set; }
public int StatusID { get; set; }
[ForeignKey("StatusID")]
public Status Status { get; set; }
public ICollection<ClothesDetail> ClothesDetail { get; set; }
}
public class ClothesDetail
{
public int ClothesDetailID { get; set; }
public int ClothesID { get; set; }
public int StatusID { get; set; }
[ForeignKey("StatusID")]
public Status Status { get; set; }
public Clothes Clothes { get; set; }
}
public class Status
{
public int StatusID { get; set; }
public string StatusName { get; set; }
}
}
namespace EFCoreMigration.Models
{
public class Clothes
{
public int ClothesID { get; set; }
public string ClothesName { get; set; }
public int StatusID { get; set; }
[ForeignKey("StatusID")]
public Status Status { get; set; }
}
}
using System.ComponentModel.DataAnnotations.Schema;
namespace EFCoreMigration.Models
{
public class Clothes
{
public int ClothesID { get; set; }
public string ClothesName { get; set; }
public ICollection<ClothesDetail> ClothesDetail { get; set; }
}
public class ClothesDetail
{
public int ClothesDetailID { get; set; }
public int ClothesID { get; set; }
public Clothes Clothes { get; set; }
}
public class MigrationDbContext : DbContext
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Clothes>()
.HasMany(c => c.ClothesDetail)
.WithOne(cd => cd.Clothes)
// 關閉 Delete Cascade
.OnDelete(DeleteBehavior.NoAction);
base.OnModelCreating(modelBuilder);
}
}
}
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EFCoreMigration.Migrations
{
/// <inheritdoc />
public partial class AddFKLab : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "ClothesDetail",
columns: table => new
{
ClothesDetailID = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ClothesID = table.Column<int>(type: "int", nullable: false),
StatusID = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ClothesDetail", x => x.ClothesDetailID);
table.ForeignKey(
name: "FK_ClothesDetail_Clothes_ClothesID",
column: x => x.ClothesID,
principalTable: "Clothes",
principalColumn: "ClothesID");
table.ForeignKey(
name: "FK_ClothesDetail_Status_StatusID",
column: x => x.StatusID,
principalTable: "Status",
principalColumn: "StatusID",
// 開啟 Cascade Delete 功能
onDelete: ReferentialAction.Cascade);
});
// 建立 Index
migrationBuilder.CreateIndex(
name: "IX_ClothesDetail_StatusID",
table: "ClothesDetail",
column: "StatusID");
}
}
}
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace EFCoreMigration.Models
{
public class Blog
{
// 透過 Data Annotations 來設定 BlogID 和 PostDate
[Key]
public int BlogID { get; set; }
public string BlogName { get; set; }
[Required]
[Column(TypeName = "date")]
public DateTime PostDate { get; set; }
}
}
手動建立 MigrationDbContext,MigrationDbContext 繼承 DbContext,並在 OnModelCreating() 內使用 Fluent API 指定 Blog.BlogName 資料型態,連線字串部分理論上不該寫死在 Code 內,該筆記重點放在熟悉 Migration 使用,就不理會它囉using Microsoft.EntityFrameworkCore;
namespace EFCoreMigration.Models
{
public class MigrationDbContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("Server=.;Database=EFCoreMigration;Trusted_Connection=True;TrustServerCertificate=true;");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// 透過 FluentAPI 來設定資料型態
modelBuilder.Entity<Blog>()
.Property(p => p.BlogName)
.HasColumnType("nvarchar")
.HasMaxLength(100);
base.OnModelCreating(modelBuilder);
}
}
}
Add-Migration InitDB
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EFCoreMigration.Migrations
{
/// <inheritdoc />
public partial class InitDB : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Blogs",
columns: table => new
{
BlogID = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
BlogName = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
PostDate = table.Column<DateTime>(type: "date", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Blogs", x => x.BlogID);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Blogs");
}
}
}
update-database
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace EFCoreMigration.Models
{
public class Blog
{
[Key]
public int BlogID { get; set; }
public string BlogName { get; set; }
[Required]
[Column(TypeName = "date")]
public DateTime PostDate { get; set; }
// 新增該 Property
public DateTime CreatedTimestamp { get; set; }
}
}
進行 Migration 操作並更新至 DB 去Add-Migration AddCreatedTimestamp
update-database
Migration 設定檔內容using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EFCoreMigration.Migrations
{
/// <inheritdoc />
public partial class AddCreatedTimestamp : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<DateTime>(
name: "CreatedTimestamp",
table: "Blogs",
type: "datetime2",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "CreatedTimestamp",
table: "Blogs");
}
}
}
在 SSMS 內就可以看見 CreateTimestamp 欄位Application.EnableVisualStyles();
而 DataGridView 內的 Header 也有該設定,要把該 Visual Styles 設定關閉後,才能變更 ColumnHeader、RowHeader 背景顏色namespace CellHeaderColor
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// 關閉 Headers Visual Styles
dataGridView1.EnableHeadersVisualStyles = false;
// 設定 ColumnHeader 預設背景顏色
dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.LightGray;
// 設定 RowHeader 預設背景顏色
dataGridView1.RowHeadersDefaultCellStyle.BackColor = Color.Yellow;
// 設定欄位背景顏色 1
dataGridView1.Columns[Column2.Index].HeaderCell.Style.BackColor = Color.LightBlue;
// 設定欄位背景顏色 2
Column4.HeaderCell.Style.BackColor = Color.LightPink;
}
}
}
CREATE TABLE Temp (
menu smallint ,
option_type char(1) ,
option_val char(1));
INSERT INTO Temp VALUES
(1, 'A', '1') , (1, 'A', '2'),
(2, 'A', '1') , (2, 'A', '2'), (2, 'B', '1'), (2, 'B', '2'),
(3, 'A', '1') , (3, 'A', '2') , (3, 'B', '1') , (3, 'B', '2') , (3, 'C', '1') , (3, 'C', '2');
;
WITH CTE AS
(
SELECT
menu ,
option_type ,
option_val ,
CAST(option_type + option_val AS varchar(8000)) AS Memo ,
CAST(1 as int) AS Stat
FROM Temp
UNION ALL
SELECT
T2.menu ,
T2.option_type ,
T2.option_val ,
T1.Memo + '_' + T2.option_type + T2.option_val ,
CAST(Stat + 1 as int) AS Stat
FROM Temp AS T2
JOIN CTE AS T1 ON T2.menu = T1.menu
AND T2.option_type > T1.option_type
)
SELECT
F1.*
FROM CTE AS F1
JOIN
(
SELECT
menu ,
COUNT(DISTINCT option_type) AS Stat
FROM Temp
GROUP BY menu
) AS F2 ON F1.menu = F2.menu
AND F1.stat = F2.stat
ORDER BY menu , memo