非常棒的程式範例網站
2024年12月23日 星期一
2024年12月16日 星期一
使用net time指令,設定自動與內部主機時間同步
參考引用來源:使用net time指令,設定自動與內部主機時間同步
---
有些電腦或主機因無法對外連線,所以不能跟外部做時間校正,利用此方法與可對外同步時間的電腦或主機同步時間。
可對外同步時間主機:server_A;192.168.1.1
無法透過外網同步時間的主機:server_B;192.168.1.2
server_B操作
1.開啟命令提示字元
2.使用net use指令跟server_A建立連線:net use \\192.168.1.1 or net use \\server_A
3.接著輸入使用者名稱與密碼
4.然後執行net time \\192.168.1.1 /set /y,server_A的時間就會與server_B同步。
步驟2.如果是使用IP的方式連線server_B,則步驟4.也要使用IP,
反之,步驟2.如果是使用主機名稱的方式連線server_B,則步驟4.也要使用主機名稱,
寫成批次檔再透過工作排程設定為開機時執行,
則每次開機時就會自動作時間校正。
批次檔內容
net use \\IP或主機名稱 密碼 /user:使用者名稱 --->連線對時主機
net time \\IP或主機名稱 /set /y --->校正時間
net use \\IP或主機名稱 /del --->中斷連線
kotlin 教學
Kotlin android 30天開發不間斷
https://ithelp.ithome.com.tw/2020ironman/articles/1482
Kotlin 官方網站
https://kotlinlang.org/docs/reference/
https://sinadarvi.gitbooks.io/kotlin-for-android-developers/
Kotlin 中文網站
https://huanglizhuo.gitbooks.io/kotlin-in-chinese/content/GettingStarted/Basic-Syntax.html
從零開始學 Kotlin 程式設計
http://tw-hkt.blogspot.com/2018/11/kotlin_57.html
2024年12月14日 星期六
Visual Studio 2022 用戶權限
參考引用 用户权限与 Visual Studio
---
修改快捷方式
此外,還可以透過快捷應用程式以利於始終利用。
Windows 10
開啟「開始」功能表,捲動到您正在使用的 Visual Studio 版本,然後按一下「更多」 >「開啟檔案位置」。
在檔案總管中,找到你使用的版本的 Visual Studio 捷徑。
在 Windows 10 桌面上,您可以使用 Visual Studio 捷徑,然後進入「屬性」。
選擇「進階」按鈕,來到「以管理員身分執行」的地方。
選擇“確定”,然後再選擇“確定”。
Windows 11
選擇“開始”按鈕,然後在“搜尋”框中輸入“Visual Studio”。
在搜尋結果中,您可在「開啟檔案位置」中找到「Visual Studio 2019」或「Visual Studio 2022」。
在檔案總管中,找到你使用的版本的 Visual Studio 捷徑。
在 Windows 11 桌面上,您可以快速使用 Visual Studio,然後進行「屬性」。
接下來,選擇「進階」按鈕,前往「以管理員身分執行」所在地。
選擇“確定”並關閉該對話框。
2024年12月11日 星期三
2024年12月9日 星期一
2024年12月8日 星期日
asp.net可输入下拉框
<asp:TextBox ID="TextBox1" runat="server" style="width: 200px; position: absolute"></asp:TextBox>
<asp:DropDownList ID="DropDownList1" runat="server" onchange="document.getElementById('TextBox1').value=this.options[this.selectedIndex].value" style="width: 217px; clip: rect(auto auto auto 198px); position: absolute">
<asp:ListItem Value="0"></asp:ListItem>
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
</asp:DropDownList>
DropDownList實現可輸入可選擇
来源:http://www.cnblogs.com/lengzhan/archive/2016/11/24/6097593.html
1、js版本
<div style="z-index: 0; visibility: visible; clip: rect(0px 105px 80px 85px); position: absolute">
<asp:DropDownList ID="ddlModel" runat="server" Style="z-index: -1" Width="105px"
onchange="getModelTo(this)">
<asp:ListItem Value="1">SSM-001</asp:ListItem>
<asp:ListItem Value="2">DDW-523</asp:ListItem>
<asp:ListItem Value="3">QSD-009</asp:ListItem>
</asp:DropDownList>
</div>
<asp:TextBox ID="txtModel" runat="server" Style="z-index: 1px; position: absolute"
Font-Size="9pt" Width="95px" Height="16px" MaxLength="50"></asp:TextBox>
<script type="text/javascript">
function getModelTo(e) {
document.getElementById("txtModel").value = e.options[e.selectedIndex].innerText;
document.getElementById("txtModel").select();
}
</script>
2、jquery版本
<div style="z-index: 0; visibility: visible; clip: rect(0px 105px 80px 85px); position: absolute">
<asp:DropDownList ID="ddlModel" runat="server" Style="z-index: -1" Width="105px"
onchange="getModelTo(this)">
<asp:ListItem Value="1">SSM-001</asp:ListItem>
<asp:ListItem Value="2">DDW-523</asp:ListItem>
<asp:ListItem Value="3">QSD-009</asp:ListItem>
</asp:DropDownList>
</div>
<asp:TextBox ID="txtModel" runat="server" Style="z-index: 1px; position: absolute"
Font-Size="9pt" Width="95px" Height="16px" MaxLength="50"></asp:TextBox>
<script type="text/javascript">
function getModelTo(e) {
$("#txtModel").val($("#ddlModel").find("option:selected").text());
$("#txtModel").select();
}
</script>
2024年11月26日 星期二
C#-DataGridView控件中增加合计和平均值
參考引用來源 C#-DataGridView控件中增加合计和平均值
統計採用: ds.Tables[tablename].Compute("SUM(當月金額)", "").ToString();
---
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SumAndAverage
{
public partial class Frm_Main : Form
{
public Frm_Main()
{
InitializeComponent();
}
private List<Fruit> G_Fruit;
private void Frm_Main_Load(object sender, EventArgs e)
{
G_Fruit = new List<Fruit>() {//创建集合并添加元素
new Fruit(){Name="苹果",Price=30},
new Fruit(){Name="橘子",Price=40},
new Fruit(){Name="鸭梨",Price=33},
new Fruit(){Name="水蜜桃",Price=31}};
dgv_Message.Columns.Add("Fruit", "水果");//添加列
dgv_Message.Columns.Add("Pric", "价格");//添加列
foreach (Fruit f in G_Fruit)//添加元素
{
dgv_Message.Rows.Add(new string[]
{
f.Name,
f.Price.ToString()
});
}
dgv_Message.Columns[0].Width = 200;//设置列宽度
dgv_Message.Columns[1].Width = 170;//设置列宽度
float sum = 0;//定义float类型变量
G_Fruit.ForEach(
(pp) =>
{
sum += pp.Price;//求和
});
dgv_Message.Rows.Add(new string[] //在新列中显示平均值及合计信息
{
"合计: "+sum.ToString()+" 元",
"平均价格: "+(sum/G_Fruit.Count).ToString()+" 元"
});
}
}
}
2024年11月15日 星期五
使用FOR XML PATH將多筆資料組合成一個字串
--
在SQL 結尾加入 FOR XML PATH('')
SELECT ',' + NAME FROM TEAMLIST WHERE TEAMID = 1
FOR XML PATH('')
2024年11月10日 星期日
2024年11月6日 星期三
2024年10月7日 星期一
MS-SQL while
declare @go_qty int
set @go_qty=1
while (@go_qty<=2)
begin
print @go_qty
set @go_qty+=1
end
2024年9月11日 星期三
windows 11 基於安全性考量,使用者帳號已被封鎖
--
windows 11 基於安全性考量,使用者帳號已被封鎖
使用Windows 鍵+ R 開啟執行視窗,並輸入gpedit.msc。 依序點開,
電腦設定=>Windows 設定=>安全性設定=>帳戶原則=>帳戶鎖定原則,並點擊『帳戶鎖定閾值』。 將設定值調整為0 即可。
2024年9月9日 星期一
2024年9月8日 星期日
2024年8月20日 星期二
快速檢查Sql Server是否可以連線
--
Imports System.Diagnostics
Imports System.Net.Sockets
Imports System.Threading
Public Class Form4
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim ip = "192.168.1.10" 'SQL Server主機的IP位址。
Dim port = 1433 'SQL Server的port預設是1433。
Dim sw As Stopwatch = New Stopwatch()
sw.Start()
Dim isConnection = TestConn(ip, port)
sw.[Stop]()
Dim message = String.Empty
If isConnection Then
message = "連線成功。 經過{0}秒。"
Else
message = "連線失敗了! 經過{0}秒!"
End If
Dim t = sw.ElapsedMilliseconds / 1000.0
MessageBox.Show(String.Format(message, t))
End Sub
Public Function TestConn(ip As String, port As Integer) As Boolean
Try
Using tc As TcpClient = New TcpClient()
Dim result As IAsyncResult = tc.BeginConnect(ip, port, Nothing, Nothing)
Dim start = Date.Now
Do
SpinWait.SpinUntil(Function() False, 100)
If result.IsCompleted Then Exit Do
Loop While Date.Now.Subtract(start).TotalSeconds < 0.3
If result.IsCompleted Then
tc.EndConnect(result)
Return True
End If
tc.Close()
If Not result.IsCompleted Then
Return False
End If
End Using
Catch ex As Exception
Console.WriteLine(ex.Message)
Throw
End Try
Return False
End Function
End Class
2024年8月19日 星期一
2024年8月18日 星期日
SqlConnection.ConnectionTimeout Property
參考引用:SqlConnection.ConnectionTimeout
---
private static void OpenSqlConnection()
{
string connectionString = GetConnectionString();
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
Console.WriteLine("State: {0}", connection.State);
Console.WriteLine("ConnectionTimeout: {0}",
connection.ConnectionTimeout);
}
}
static private string GetConnectionString()
{
// To avoid storing the connection string in your code,
// you can retrieve it from a configuration file, using the
// System.Configuration.ConfigurationSettings.AppSettings property
return "Data Source=(local);Initial Catalog=AdventureWorks;"
+ "Integrated Security=SSPI;Connection Timeout=30";
}
2024年8月15日 星期四
C# (vb) read Paradox DB code
win7 x64 C# 讀取 delphi Paradox db
Paradox 4 database connect and edit inside c#
##
C# Application to import paradox data to SQL Server
----------------
C# code:
var strPath = @"D:\Test\4#新程序全兼容\4#新程序全兼容\Data";
string myConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strPath + ";Extended Properties=Paradox 5.x;";
string mySelectQuery = "select * from TD2002002;";
OleDbConnection myConnection = new OleDbConnection(myConnectionString);
myConnection.Open();
OleDbDataAdapter da = new OleDbDataAdapter(mySelectQuery, myConnection);
DataSet ds = new DataSet();
da.Fill(ds);
----------
VB code:
Dim strPath As Object = "D:\Test\4#新程序全兼容\4#新程序全兼容\Data"
Dim myConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strPath + ";Extended Properties=Paradox 5.x;"
Dim mySelectQuery As String = "select * from TD2002002;"
Dim myConnection As New OleDbConnection(myConnectionString)
myConnection.Open()
Dim da As New OleDbDataAdapter(mySelectQuery, myConnection)
Dim ds As New DataSet()
da.Fill(ds)
2024年8月14日 星期三
2024年8月6日 星期二
2024年7月31日 星期三
撰寫Stored Procedure小細節
參考引用:[SQL SERVER]撰寫Stored Procedure小細節
---
撰寫Stored Procedure小細節
EXEC AssetLibrary_AssetDeleteAttributes @AssetID
declare @myquery nvarchar(4000);
set @myquery = 'SELECT * from dbo.test2 where c1 = @id';
--第一次
execute sp_executesql @myquery,N'@id int', @id = 1;
--第二次
execute sp_executesql @myquery,N'@id int', @id = 2;
--查看執行計畫
SELECT cap.usecounts as '使用次數',objtype as '快取類型',st.text
FROM sys.dm_exec_cached_plans cap
CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS st
WHERE st.text not like '%sys%'
and st.text like '%dbo.test2%'
DECLARE @myquery VARCHAR(8000)
,@myid int;
set @myid = 5;
set @myquery = 'select * from dbo.test2 where c1 = '+ CAST( @myid as varchar);
--第一次
exec (@myquery)
set @myid = 6;
set @myquery = 'select * from dbo.test2 where c1 = '+ CAST(@myid as varchar );
--第二次
exec (@myquery)
SELECT cap.usecounts as '使用次數',objtype as '快取類型',st.text
FROM sys.dm_exec_cached_plans cap
CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS st
WHERE st.text not like '%sys%'
and st.text like '%dbo.test2%'
2024年7月30日 星期二
VB.net Thread 執行序
建立一個Class用來執行新的Thread:
Imports System.Threading
Namespace Classes
Public Class Worker
Delegate Sub WorkerDelegate(ByVal Params As Object)
Private m_Thread As Thread = Nothing
Private m_Controler As Control = Nothing
Private m_Params As Object = Nothing
Public Event WorkerToDo(ByRef Params As Object)
Public Event WorkerInvoke(ByVal Params As Object)
Dim CallBackInvoke As New WorkerDelegate(AddressOf Worker_Invoke)
Public Sub New(ByVal ctrl As Control)
m_Controler = ctrl
End Sub
Public Sub Start()
Dim ThreadBegin As New ThreadStart(AddressOf Worker_ToDo)
Me.m_Thread = New Thread(ThreadBegin)
Me.m_Thread.IsBackground = True
Me.m_Thread.Name = "WorkerThread" + Now.ToShortTimeString()
Me.m_Thread.Start()
End Sub
Private Sub Worker_ToDo()
RaiseEvent WorkerToDo(m_Params)
m_Controler.Invoke(CallBackInvoke, m_Params)
End Sub
Private Sub Worker_Invoke(ByVal Params As Object)
RaiseEvent WorkerInvoke(Params)
End Sub
End Class
End Namespace
使用方式:
Private Sub LoadData()
Dim wk As New Worker(Me)
Try
'連結要丟到背景工作的副程式
AddHandler wk.WorkerToDo, AddressOf DoQueryDataBase
'工作完畢後, 所要處理資料(與UI互動)
AddHandler wk.WorkerInvoke, AddressOf BindData
wk.Start()
Finally
wk = Nothing
End Try
End Sub
Private Sub DoQueryDataBase(ByRef Params As Object)
'執行的程式, 結果可由 Params 代傳
'1: Params = modADO.Query(...)
'2: Params = New Object() {data1, data2, ...}
End Sub
Private Sub BindData(ByVal Params As Object)
'背景工作完畢後, 與 UI 互動
TextBox1.Text = CInt(Params)
End Sub
2024年6月1日 星期六
ASP.Net 的Cookie簡介及用法
ASP.Net 的Cookie簡介及用法
Cookie(餅乾)是一個在網頁應用程式上拿來儲存瀏覽者資料的做法之一‧ 例如,當一個瀏覽者參觀您的網站時,您就可用Cookie把對方的一些資料儲存起來,並且下一次再使用‧ 另外,如果您有學習過ASP, PHP這類語言的話,相信Cookie對你絕對不陌生‧ 假設您是學習VB, C++的設計師的話,用Cookie就好比是寫資料到使用者的Registry裡一樣‧ 只是用Cookie比較簡單,而且對初學者而言,Cookie也比Registry還容易瞭解!
Cookie事實上是以純文字方式儲存在使用者電腦某資料夾裡面的,以Microsoft Windows NT (2000, XP)的使用者來說,每一個使用者都有一個自己個人的資料夾來放Cookie檔案,而這資料夾通常都會在『C:\Documents and Settings\使用者\Cookies\』這邊‧ 每一個Cookie都儲存著每一個不同網站所存的資料,而每一項所擁有的資料都會不同,這會看網站程式編寫者而定‧ 有時候Cookie會儲存您在某一網站的帳號或密碼、會員身份、登入/登出日期等等‧ 甚至Cookie也可以拿來做是防治瀏覽者重覆投票的防範方法之一!
在使用Cookie上,注意cookie使用也是有一些限制的! 例如一般瀏覽器至少都會支援4096 Bytes的Cookie,允許20個(各網站‧如果您嘗試使用超過更多的Cookie,那麼小心舊的Cookie就會莫名其妙消失!),也許看起來很少,不過基本上卻已經足夠儲存你純文字的資料了! 另外也有一些瀏覽器會有只允許儲存共300 Cookies的限制(所有網站的加起來)‧ 還有,每一個Cookie都會有它的存活時間! 基本上來說,Cookie除了靠網站程式結束外,如果您自己關閉了瀏覽器,那麼Cookie也會自動消失‧ 不過值得慶幸的是您可以自由的設定Cookie的過期時間,這我將會說明!
『筆記:剛才提到了Cookie是儲存在瀏覽者電腦裡面的,所以身為網頁程式編寫者的您,也必須留意到瀏覽者也是會隨意的刪除或想辦法亂修改的! 有時太過相信Cookie的資料內容的話,也可能會導致一些人為問題喔!』
用ASP.Net 寫入一個Cookie資料
假設您是純ASP (Active Server Pages)的學習者,也許在剛開始接觸ASP.Net時可能會有點不習慣! 以Cookie做例子,要閱讀或寫Cookie絕對不是像ASP這樣:
閱讀Cookie資料(ASP):
Dim mycookie : mycookie = Request.Cookies("eat_cookie")
寫入Cookie資料(ASP):
Response.Cookies("eat_cookie") = "C is a cookie!"
在ASP.Net,跟ASP一樣,要寫Cookie都會要使用Response property,要讀用Request‧ 就先講寫入Cookie吧! 如果您想要建立一個Cookie資料,您可以創造單一個Cookie,或在同一時間建多重也是可以(Sub Cookies)‧ 單一的話:
Response.Cookies("mycookie").Value = "C is a cookie!"
要建立一個Sub cookie的話:
Response.Cookies("mycookie")("flavor") = "Coffee"
剛才我有提到Cookie過期的話題,如果要另外加長的話,那麼(假設存活時間設一年):
Response.Cookies("mycookie").Value = "C is a cookie"
Response.Cookies("mycookie").Expires = DateTime.Now().AddDays(365)
註:用Sub cookie也是用類似的方法來設定存活時間
假如我的網站有Sub domain的話,您也可以設定Domain property來分享Cookie:
(例如我的網站叫www.tekcyberspace.com,然後我有一個Sub domain叫forum.tekcyberspace.com)
Response.Cookies("mycookie").Value = "C is a cookie"
Response.Cookies("mycookie").Expires = DateTime.Now().AddDays(365)
Response.Cookies("mycookie").Domain = "forum.tekcyberspace.com"
閱讀Cookie資料
讀Cookie就比較簡單了‧ 我就直接講吧! 假設要讀單一Cookie的話:
Dim get_mycookie As HTTPCookie = Request.Cookies("mycookie")
寫出一個Cookie資料:
Dim get_mycookie As HTTPCookie = Request.Cookies("mycookie")
If Not get_mycookie Is Nothing Then
Response.Write(get_mycookie.Value)
End If
注意如果沒有Cookie在的話,你接受到的會是 Nothing‧
讀取並寫出Sub cookie資料:
Dim get_mycookie As String = Request.Cookies("my_cookie")("flavor")
If not get_mycookie = "" Then
Response.Write(get_mycookie)
End If
Cookie怎麼寫就怎麼讀
Cookie怎麼寫就怎麼讀
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class B : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//產生一個Cookie
HttpCookie cookie = new HttpCookie("test");
//設定單值
cookie.Value = Server.UrlEncode("Hello!!世界");
//設定過期日
cookie.Expires = DateTime.Now.AddDays(2);
//寫到用戶端
Response.Cookies.Add(cookie);
}
}
//讀取cookie(以多值的方式)
protected void btn_test_Click(object sender, EventArgs e)
{
HttpCookie cookie = Request.Cookies["test"];
foreach (string value in cookie.Values)
{
Response.Write("Null?"+(value==null)+"<br/>");/*順便測試看看是否為null還是空字串*/
Response.Write("空字串?"+(value=="")+"<br/>");
Response.Write("foreach迴圈中撈出Request.Cookies['test']所有的Value:" + Server.UrlDecode(value)+"<hr/>");
}
Response.Write("Null?"+(cookie["test"]==null)+"<br/>");
Response.Write("空字串?" + (cookie["test"]=="")+"<br/>");
Response.Write("cookie['test'](HttpCookie物件裡索引名為test的值):"+Server.UrlDecode(cookie["test"])+"<hr/>");
}
}
2024年5月6日 星期一
vbnet TLS1.2
Using TLS1.2 in .Net 2.0, .Net 3.0, .Net 3.5 and .Net 4.0
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
ServicePointManager.Expect100Continue = True
ServicePointManager.SecurityProtocol = CType(3072, SecurityProtocolType)
Dim json As String = (New WebClient).DownloadString("https://raw.githubusercontent.com/aspsnippets/test/master/Customers.json")
Response.Write(json)
End If
End Sub
2024年4月29日 星期一
word無法建立工作檔,檢查暫存環境變數
word無法建立工作檔,檢查暫存環境變數
找到這個位置
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders->Cache
原值--->%USERPROFILE%\AppData\Local\Microsoft\Windows\INetCache
把Cache改回
%USERPROFILE%\AppData\Local\Microsoft\Windows\Temporary Internet Files
2024年4月26日 星期五
Windows11超簡易修改完整右鍵選單
第二個 ( 使用CMD命令方式)
複製 – 貼上
打開Windows Terminal / PowerShell / CMD.
2 複製以下你想要的命令貼上, 之後拍Enter
(WIN11右鍵顯示更多)
reg add "HKCU\Software\Classes\CLSID{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32" /f /ve
或
(還原WIN11預設右鍵)
reg delete "HKCU\Software\Classes\CLSID{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}" /f
3 關閉Windows Terminal / PowerShell / CMD
4 重新啟動電腦, 就變回Win10 熟悉的右鍵選單
2024年4月18日 星期四
Fleck開發的多人網頁版即時聊天室
Asp.Net Mvc基於Fleck開發的多人網頁版即時聊天室
1、最簡單、最常用的調用方法:(ws://172.10.3.4:8111改成您的伺服器本地IP和埠)
//控制台代碼
var server = new WebSocketServer("ws://172.10.3.4:8111");
server.Start(socket =>
{
socket.OnOpen = () => Console.WriteLine("產生連接處理");
socket.OnClose = () => Console.WriteLine("連接斷開處理");
socket.OnMessage = (message) => {
//1、此方法用於接收客戶端發送來的消息
//2、可以做一些自己的操作,例如存入資料庫
//3、為了響應客戶端,一般會使用下麵的send函數,返迴響應結果。
socket.Send(message);
}
});
2、Fleck本身只負責幫你單線聯繫。也就是客戶端A和伺服器建立連接後,會產生一個IWebSocketConnection,也就是上面代碼中socket變數的類型,它包含了接收方法、發送方法,但是都僅限於單一連接內。至於客戶端A想發送消息給客戶端B、C、D亦或者想群發,不好意思Fleck本身不Care。。。當然了那並不是這個功能就不能實現了,只是要開發者自己去把每一個IWebSocketConnection存儲起來,並管理他們的生存周期,通過自己的代碼去實現客戶端A給B發信息或者群發。
3、Fleck不需要額外的容器或進程來運行,它隨著IIS網站運行,也就是在w3wp.exe。至於它是怎麼運行的,目前我還沒有去看源碼,後期有時間再瞧瞧。
三、聊天室源碼位置
1、GitHub:https://github.com/DisSunRestart2020/DisSunChat
2024年4月6日 星期六
ASP.NET內抓取網址的方式一覽表(Request)
Request.ApplicationPath /
Request.Url.Host my.url.com
Request.Url.Port 8080
Request.Url.Scheme https
Request.Url.Authority my.url.com:8080
Request.Path /Detail/Page/List.aspx/showmore
Request.Url.LocalPath /Detail/Page/List.aspx/showmore
Request.PathInfo /showmore
Request.Url.Query ?mid=20
Request.CurrentExecutionFilePath /Detail/Page/List.aspx
Request.FilePath /Detail/Page/List.aspx
Request.RawUrl /Detail/Page/List.aspx/showmore?mid=20
Request.Url.PathAndQuery /Detail/Page/List.aspx/showmore?mid=20
Request.Url.AbsoluteUri https://my.url.com:8080/Detail/Page/List.aspx/showmore?mid=20
Request.Url.AbsolutePath /Detail/Page/List.aspx/showmore
-----------
Request.ApplicationPath
//output:/
Request.PhysicalPath
//output:磁碟機代號:\父目錄\子目錄\Default3.aspx
System.IO.Path.GetDirectoryName(Request.PhysicalPath)
//output:磁碟機代號:\父目錄\子目錄
Request.PhysicalApplicationPath
//output:磁碟機代號:\父目錄\子目錄\
System.IO.Path.GetFileName(Request.PhysicalPath)
//output:Default3.aspx
Request.CurrentExecutionFilePath
//output:/Default3.aspx
Request.FilePath
//output:/Default3.aspx
Request.Path
//output:/Default3.aspx
Request.RawUrl
//output:/Default3.aspx?id=1019&uu=77
Request.Url.AbsolutePath
//output:/Default3.aspx
Request.Url.AbsoluteUri
//output:http://demo.tc/Default3.aspx?id=1019(這是上一頁的網址)
Request.Url.Scheme
//output:http
Request.Url.Host
//output:demo.tc
Request.Url.Port
//output:80
Request.Url.Authority
//output:demo.tc
Request.Url.LocalPath
//output:/Default3.aspx
Request.PathInfo
//output:
Request.Url.PathAndQuery
//output:/Default3.aspx?id=1019&uu=77
Request.Url.Query
//output:?id=1019&uu=77
Request.Url.Fragment
//output:
Request.Url.Segments[0]
//output:/
Request.Url.Segments[1]
//output:Default3.aspx
2024年4月5日 星期五
bootstrap modal submit form
Should be pretty simple. Just give your form an id
Copy
<form id="the-form" method="POST" action="{{ route('sms.store') }}">
Give the submit button an id
Copy
<button id="the-submit" type="submit" class="btn btn-primary">Save changes</button>
Then use jquery (since you're using bootstrap) to submit the form when the submit button is clicked.
Copy
$(function() {
$('#the-submit').on('click', function(e) {
$('#the-form').submit();
});
});
2024年4月2日 星期二
民國年轉換
民國年轉換
使用DotNet TaiwanCalendar類別轉換民國年,只要簡單的將西元年日期做為參數傳入,即可取得民國年的相關數值,例如,年/月/日…,如下:
System.Globalization.TaiwanCalendar tc = new System.Globalization.TaiwanCalendar();
DateTime d = DateTime.Now;
string salesDate = String.Format(“民國{0}年{1}月{2}日”, tc.GetYear(d), tc.GetMonth(d), tc.GetDayOfMonth(d));
可惜的是,ToString()沒有支援Format參數指定輸出格式,不然就更加方便了,省掉自行組字串的步驟。另外要特別注意的是,指定小於西元1912/01/01的日期,會拋出超出日期範圍的例外,因為年份沒有負數的表示法。
如果不想用上述的方式,在每個輸出的地方都寫日期轉換的程式碼,有沒有更簡單的方式?
有的,可以在程式開始執行時,指定執行序的文化與曆法:
Thread.CurrentThread.CurrentCulture = new CultureInfo("zh-TW");
Thread.CurrentThread.CurrentCulture.DateTimeFormat.Calendar = new TaiwanCalendar();
當使用DateTime.Now.ToString()時,得到的就是民國年日期,而且是整個系統範圍皆適用。
若需要用到台灣陰陽曆(農民曆)處理,也可使用TaiwanLunisolarCalendar類別來做轉換,使用方式相同。
2024年3月19日 星期二
2024年3月18日 星期一
2024年3月6日 星期三
Hiding and Showing TabPages in tabControl
If Me.chkShowTab1.Checked = True Then
Me.tabsShown.TabPages.Add(Me.tabsHidden.TabPages("Tab1"))
Me.tabsHidden.TabPages.RemoveByKey("Tab1")
Else
Me.tabsHidden.TabPages.Add(Me.tabsShown.TabPages("Tab1"))
Me.tabsShown.TabPages.RemoveByKey("Tab1")
End If
2024年3月2日 星期六
2024年3月1日 星期五
C# TabControl 隱藏(hide)/顯示(show) TabPage的方法
private void button2_Click(object sender, EventArgs e)
{
this.tabPage2.Parent = null; // hide
this.tabPage1.Parent = this.tabControl1; //show
}
private void button1_Click(object sender, EventArgs e)
{
this.tabPage1.Parent = null; // hide
this.tabPage2.Parent = this.tabControl1; //show
}