2025年3月3日 星期一

2025年2月17日 星期一

WebClient Download json

 參考引用:How To Display JSON Data Into GridView

----

using Newtonsoft.Json;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;


namespace _5M_Solution

{

  public partial class Harqat_Maqbozat_Grid : System.Web.UI.Page

  {

    protected void Page_Load(object sender, EventArgs e)

    {

      if (!this.IsPostBack)

      {

        this.GetJsonData();

      }

    }


    public void GetJsonData()

    {

      ServicePointManager.Expect100Continue = true;

      ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;

      string json = (new WebClient()).DownloadString("https://receipt-voucher-default-rtdb.firebaseio.com/receipts.json");

      Dictionary<string, object> values = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);

      List<Receipt> receipts = new List<Receipt>();

      foreach (var entry in values)

      {

        receipts.Add(JsonConvert.DeserializeObject<Receipt>(entry.Value.ToString()));

      }

      gvDetails.DataSource = receipts;

      gvDetails.DataBind();

    }


    public class Receipt

    {

      public string amount { get; set; }

      public string branch_num { get; set; }

      public string machineID { get; set; }

      public string shift { get; set; }

      public string userID { get; set; }

      public string voucher_date { get; set; }

      public string voucher_number { get; set; }

    }


    public void ExportExcel()

    {

      try

      {

        Response.Clear();

        Response.Buffer = true;

        Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "5M_MaqbozatDetails.xls"));

        Response.ContentType = "application/ms-excel";

        Response.Charset = "";

        this.EnableViewState = false;

        System.IO.StringWriter writer = new System.IO.StringWriter();

        System.Web.UI.HtmlTextWriter html = new System.Web.UI.HtmlTextWriter(writer);

        GetJsonData();

        //dl_JsonDetails.DataBind();

        gvDetails.RenderControl(html);

        Response.Write(writer.ToString());

        Response.Flush();

        Response.End();

      }

      catch (Exception ex)

      {

      }

    }


    protected void btn_ExportExcel_Click(object sender, EventArgs e)

    {

      ExportExcel();

    }


    protected void gvDetails_PageIndexChanging(object sender, GridViewPageEventArgs e)

    {

      gvDetails.PageIndex = e.NewPageIndex;

      this.GetJsonData();

    }


    protected void dd_SearchByBranchNo_SelectedIndexChanged(object sender, EventArgs e)

    {


    }

  }

}


How To Display JSON Data Into GridView

 參考引用:How To Display JSON Data Into GridView

---

"-MuPh0RFdkXA6Jw5wYxp": {

        "amount": "10000.0",

        "branch_num": "001",

        "machineID": "VB12213C20156",

        "shift": 2,

        "userID": "7",

        "voucher_date": "2022-01-27T11:42:56",

        "voucher_number": "156202200017"

    }

public DataTable jsonDataDiplay()  

{  

    StreamReader sr = new StreamReader(Server.MapPath("TrainServiceAlerts.json"));  

    string json = sr.ReadToEnd();  

    dynamic table = JsonConvert.DeserializeObject(json);  

    DataTable newTable = new DataTable();  

    newTable.Columns.Add("amount", typeof(string));  

    newTable.Columns.Add("branch_num", typeof(string));  

    newTable.Columns.Add("machineID", typeof(string));  

    newTable.Columns.Add("shift", typeof(string));  

    newTable.Columns.Add("userID", typeof(string));  

    newTable.Columns.Add("voucher_date", typeof(string));  

    newTable.Columns.Add("voucher_number", typeof(string));  

  

    foreach (var row in table.value.data)  

    {  

        newTable.Rows.Add(row.amount, row.branch_num, row.machineID, row.shift,row.userID,row.voucher_date,row.voucher_number);  

    }  

    return newTable;  

}  

GridView.DataSource = newTable ;  

GridView.DataBind();  


2025年2月15日 星期六

使用 HttpClient 類別提出 HTTP 要求

 請參考來源:使用 HttpClient 類別提出 HTTP 要求

---

HttpClient

提出 HTTP 要求

若要提出 HTTP 要求,您可以呼叫下列任何 API:


HTTP 方法 API

GET HttpClient.GetAsync

GET HttpClient.GetByteArrayAsync

GET HttpClient.GetStreamAsync

GET HttpClient.GetStringAsync

POST HttpClient.PostAsync

PUT HttpClient.PutAsync

PATCH HttpClient.PatchAsync

DELETE HttpClient.DeleteAsync

HttpClient.SendAsync  USER SPECIFIED 要求表示 SendAsync 方法接受任何有效的 HttpMethod


2025年2月10日 星期一

清除 mstsc 记录

 Win10怎么删除远程桌面连接记录?(3种方法)

---

方法2. 通过命令提示符删除记录

在方法1中我们可以手动将远程桌面连接历史删除,如果觉得太麻烦或太费时间,我们也可以通过命令提示符删除远程桌面连接记录。

步骤1. 按“Win + R”键,然后输入“CMD”打开命令提示符。

步骤2. 然后依次输入以下命令,并在每个命令输入完成按下回车键。

reg delete “HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\Default” /va /f

reg delete “HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\Servers” /f

reg add “HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\Servers”

del /ah %homepath%\documents\default.rdp


TcpClient port

 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


iis localhost 建立 SSL (https) 連線

 參考:How can I create a self-signed cert for localhost?

參考:Enabling SSL on localhost IIS

----



2025年2月7日 星期五

安裝WordPress到Windows

 6步輕鬆安裝WordPress到Windows和Mac電腦上

https://loyseo.com/zh-hant/tutorial/wordpress/install-wordpress/pc-local/



zh-tw:安裝WordPress

https://codex.wordpress.org/zh-tw:%E5%AE%89%E8%A3%9DWordPress



********

如何下載安裝 WordPress 站台,設定資料庫連線,建立全新部落格 (適用 IIS 架站)

https://ithelp.ithome.com.tw/m/articles/10260063

Windows Server IIS 如何安裝 PHP 網頁伺服器

https://blog.hungwin.com.tw/windows-server-iis-php-install/

********


wordpress自己架設網站,快速架站wordpress教學

https://www.koc.com.tw/archives/165785




WordPress教學-20分鐘新手網站架設流程

https://jclassroom.net/20-minutes-create-wordpress-website/


WordPress 後台教學:給新手的操作教學(全指南)

https://frankknow.com/wordpress-build-teach/


2025年2月4日 星期二

MSSQL stored procedure TRY...CATCH

參考來源:TRY...CATCH (Transact-SQL)


 BEGIN TRY

SELECT  aa/0 FROM DEMO

END TRY


BEGIN CATCH

    SELECT ERROR_NUMBER() AS ErrorNumber,ERROR_MESSAGE() AS ErrorMessage;

END CATCH