分類
Programming Font

請更改 IDE 字型(建議使用JetBrains Mono)

曾經被 “O0″和”Il” 這種眼殘問題搞了2~3個小時的經驗,更換字型就是我安裝IDE後的第二件事。(安裝vim套件是No.1 !!)

VS預設為細明體(不要用這個!! 否則容易誤會自己眼包)

至於要用哪種字型,最好是經過一些推薦再加上自己看得順眼。也有聽過有些Team會把字型當作Coding Standard強迫大家統一(個人感覺有點too over)。

經過一些試用及挑選,目前選擇 JetBrains Mono 作為 IDE font 。

主要原因有幾個,首先必須明顯可以區別0O, lI這種討厭的小東西(其實是自己眼包)。

其次該字型是根據開發者的閱讀感受和習慣經過強化設計。提供了許多特性,如下

  1. 增加字型高度以提供更好的閱讀體驗
  2. 提高閱讀程式碼的適應性
  3. 對於 “連字” 進行調整
  4. 支援145種語言
  5. 提供7種不同權重的斜體
  6. 開源且完全授權

至於特性的詳細內容就煩請移駕官網

導入JetBrains Mono的畫面如下(建議可以放大看看)。

JetBrains Mono font

1.字型會變粗一些,拉高一些以增加辨識度
2.橢圓會調整成更矩形一些以增加清晰度
3.移除不必要的細節,減輕閱讀的疲勞程度。

當然讓人容易眼包的O0 和 lI 也有明顯的區別

最後安裝方式也相當簡單。
1.到官網下載 JetBrains Mono 壓縮檔
2.解壓縮 JetBrains Mono 壓縮檔
3.全選解壓縮目錄中的ttf檔案(解壓縮目錄/fonts/ttf/)
4.點右鍵 -> 安裝 -> 完成(系統的字型安裝)
5.到你的IDE選擇你想要的JetBrains Mono font -> 套用
6.完成(IDE的字型更改)

分類
SQL Server 資料庫

複製資料表-SQL Server

SELECT * INTO 新資料表名稱 FROM 舊資料表名稱;

分類
ASP.NET git 使用紀錄 Web 前端

在ASP.NET Webform專案中加入專屬的 gitignore file

不用到處搜尋 .gitignore 檔案啦,先移動到專案的根目錄再輸入以下指令


dotnet new gitignore

就會在根目錄產生 .gitignore file,內容如下


## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# Tye
.tye/
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Coverlet is a free, cross platform Code Coverage Tool
coverage*[.json, .xml, .info]
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# Ionide - VsCode extension for F# Support
.ionide/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
##
## Visual studio for Mac
##
# globs
Makefile.in
*.userprefs
*.usertasks
config.make
config.status
aclocal.m4
install-sh
autom4te.cache/
*.tar.gz
tarballs/
test-results/
# Mac bundle stuff
*.dmg
*.app
# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
# JetBrains Rider
.idea/
*.sln.iml
##
## Visual Studio Code
##
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

至於 dotnet 只是啥
請參考 https://docs.microsoft.com/zh-tw/dotnet/core/tools/dotnet

分類
ASP.NET

找不到類型或命名空間名稱 using OfficeOpenXml

xxx.aspx.cs 使用 using OfficeOpenXml 出現找不到類型或命名空間名稱錯誤。

請使用 Nuget 安裝 EPPlus。

分類
Visual Studio

在 VS2019 使用 ctrl+/ 快速註解 Source Code

之前在 Android Studio 可以直接使用ctrl+/ 快速註解。
在VS2019的對應項目為”切換行註解”(可以從編輯->進階->切換行註解看到)。

VS2019設定 ctrl + / 為註解的快捷鍵方式如下:

VS上方的工具 -> 選項 -> 環境 -> 鍵盤

就會出現設定鍵盤快捷鍵的畫面啦,接著

1.在”顯示包含下列的命令”中輸入”切換行註解”
2.點擊”按快捷鍵”並輸入你想設定的快捷鍵(ctrl+/)
3.在”新的快捷鍵用於”選擇”文字編輯器”
4.點擊”指定”
5.點擊”確定”

設定”Ctrl + /”為”切換行註解”

完成後就可直接使用 ctrl + / 來註解 source code。

看起來有一陣子無法離開Visual Studio了@@

分類
Web 前端

ASP.NET 如何套用 CSS檔

在想引入的.cs 檔的 <asp:Content ID=”Content1″ ContentPlaceHolderID=”MainContent” runat=”server”>下方加入

<link rel=”stylesheet” href=”Content/CommonStyle.css”>

如下:


<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
      <link rel="stylesheet" href="Content/CommonStyle.css">

分類
Web 前端

BootStrap form-inline 水平排列 範例

以下為使用 form-inline 來達到水平排列內容的範例。


<div class="container">
  <div class="row">
    <div class='col-sm-6'>
      <div class="form-group">
        <label>手機</label>
	  <div class="form-inline">
	     <asp:TextBox runat="server" class="form-control input-sm required" ID="userPhoneNumberFirstSection" Width="55px" MaxLength="4" placeholder="0000" en />
	     <asp:Label runat="server" Style="font-size: larger" class="text">-</asp:Label>
	     <asp:TextBox runat="server" class="form-control input-sm required" ID="userPhoneNumberSecondSection" Width="45px" MaxLength="3" placeholder="000" />
	     <asp:Label runat="server" Style="font-size: larger" class="text">-</asp:Label>
	     <asp:TextBox runat="server" class="form-control input-sm required" ID="userPhoneNumberThirdSection" Width="45px" MaxLength="3" placeholder="000" />
	   </div>
	 </div>
       </div>
     </div>
  <div class="row">
    <div class='col-sm-6'>
      <div class="form-group">
        <label>生日</label>
	  <div class="form-inline">
	    <asp:TextBox runat="server" class="form-control input-sm required" ID="userBirthdayYear" Width="55px" MaxLength="4" placeholder="YYYY" />
	    <asp:Label runat="server" Style="font-size: larger" class="text">-</asp:Label>
	    <asp:TextBox runat="server" class="form-control input-sm required" ID="userBirthdayMonth" Width="45px" MaxLength="2" placeholder="MM" />
            <asp:Label runat="server" Style="font-size: larger" class="text">-</asp:Label>
	    <asp:TextBox runat="server" class="form-control input-sm required" ID="userBirthdayDay" Width="45px" MaxLength="2" placeholder="DD" />
	   </div>
	 </div>
       </div>
     </div>
   </div>

效果如下

使用form-inline達到水平排列
分類
Web 前端

form role= "form" 導致 TextBox 內容被清空

當網頁上的某個伺服器控制項被設定為 AutoPostBack = true 時,代表該控制項的資料或內容改變時就會自動觸發 PostBack

預設的情況下其他控制項並不會受到影響,也就是說其內容值不會改變

若其他控制項是被<form role = “form”>包圍住,只要觸發 PostBack 就會導致其值被清空。如下

<form role="form">
  <div class="form-group">
    <label>ID</label>
      <div class="form-inline">
	<asp:TextBox runat="server" class="required" ID="userPhoneNumber"/>
      </div>
  </div>
</form>

最外層是 <form role = “form”> 導致只要觸發 PostBack 其中的 userPhoneNumber 的值就會清空。

如果在PostBack時發現某些控制項會自動清空,但又找不到其他邏輯。
不妨找找是不是外層被<form role = “form”> 包住了。

分類
Web 前端

Bootstrap.v3.Datetimepicker 簡單紀錄

因為BootStrap預設沒有日期或時間的UI元件,搜尋一下發現其他開發者提供的好用外掛

Bootstrap.v3.Datetimepicker!!


首先我的環境是ASP.NET和最原始的WebForm專案

1.安裝Bootstrap.v3.Datetimepicker

直接使用NuGet套件管理員安裝,如下

2.使用 Bootstrap.v3.Datetimepicker

2.1在Site.Master的 <head> 區塊輸入


<link rel="stylesheet" href="Content/bootstrap-datetimepicker.css" />

2.2在Site.Master 的<body> 區塊輸入


<script src="Scripts/jquery-3.4.1.min.js"></script>
<script src="Scripts/moment.min.js"></script>
<script src="Scripts/bootstrap.min.js"></script>
<script src="Scripts/bootstrap-datetimepicker.js"></script>

3. Bootstrap.v3.Datetimepicker 的宣告和使用

Datetimepicker可同時使用日期和時間,也可以單獨使用日期或時間。

3.1 同時使用日期和時間


<div class="container">
   <div class="row">
      <div class='col-sm-6'>
         <div class="form-group">
            <div class='input-group date' id='datetimepicker1'>
               <input type='text' class="form-control" />
               <span class="input-group-addon">
               <span class="glyphicon glyphicon-calendar"></span>
               </span>
            </div>
         </div>
      </div>
      <script type="text/javascript">
         $(function () {
             $('#datetimepicker1').datetimepicker();
         });
      </script>
   </div>
</div>

畫面如下

日期和時間

3.2 只有時間


    <div class="container">
        <div class="row">
            <div class='col-sm-3'>
                <div class="form-group">
                    <div class='input-group date' id='dateAndtime'>
                        <input type='text' class="form-control" />
                        <span class="input-group-addon">
                            <span class="glyphicon glyphicon-time"></span>
                        </span>
                    </div>
                </div>
            </div>
            <script type="text/javascript">
                $(function () {
                    $('#dateAndtime').datetimepicker({
                        format: 'LT'
                    });
                });
            </script>
        </div>
    </div>

畫面如下

只有時間

3.3 只有日期


    <div class="container">
        <div class="row">
            <div class='col-sm-3'>
                <div class="form-group">
                    <div class='input-group date' id='dateAndtime'>
                        <input type='text' class="form-control" />
                        <span class="input-group-addon">
                            <span class="glyphicon glyphicon-calendar"></span>
                        </span>
                    </div>
                </div>
            </div>
            <script type="text/javascript">
                $(function () {
                    $('#dateAndtime').datetimepicker({
                    format: 'DD/MM/YYYY'
                    });
                });
            </script>
        </div>
    </div>

只有日期

可以看到差異只在選擇哪個icon和在js中呼叫datetimepicker的格式

參考官網 https://getdatepicker.com/4/

分類
git 錯誤紀錄

[GitLab Issue] You are not allowed to push code to protected branches on this project

Scenario

Local 端在 master branch 上執行 git push origin master 後出現以下 Error

remote: GitLab: You are not allowed to push code to protected branches on this project.
To http://xxx.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to ‘http://xxx.git’

Root Cause

關鍵字為
You are not allowed to push code to protected branches on this project

從 Google 得知為 GitLab 預設專案的 master branch 為 Protected,無法直接push commit 到 remote 的 master branch。

Solution

A. 透過GitLab的管理者權限將該專案的protected branch關閉。
GitLab->點擊該傳案->左方最下面的settings -> Repository ->點擊 Protected Branch的Expand -> 點擊 Unproject

B. 先git push 到其他branch上,再到GitLab將該branch merged到master(待測)