2023年11月15日 星期三

Excel 敏感資料遮蔽處理

參考資料:[Excel] 個資隱碼篇-例身分證G123***456

有時候Excel中有些欄位資料是很敏感的,例如姓名、身分證字號、電話、信箱等,遇到這些欄位我們就必須作敏感資料的遮蔽處理。

1-1. 身分證字號,從第幾碼之後將敏感資料用*號替代

=REPLACE(A2,D2,(LEN(A2)-D2)+1,REPT("*",(LEN(A2)-D2)+1))


1-2.信箱,從第幾碼之後將敏感資料用*號替代,但只保留@之後的資訊

=REPLACE(A5,D5,(FIND("@",A5)-D5),REPT("*",(FIND("@",A5)-D5)))


畫面如下



2023年7月19日 星期三

MS SQL 計算字串中的全形、半形,各佔幾個字

計算字串中的全形、半形,各佔幾個字。

DECLARE @MSG nvarchar(500),@OrderNo int,@x1 int,@s1 int;

--假設@MSG為要計算的字串內容
Set @MSG=N'零壹貳參肆伍陸柒捌玖拾零壹貳參肆伍陸柒捌玖拾零壹貳參肆伍陸柒捌玖拾零壹貳參肆伍陸柒捌玖拾零壹貳參肆伍陸柒捌玖拾零壹貳參肆伍陸柒捌玖ab,cdA。';

Set @x1=LEN(@MSG);
Set @s1=1;

DECLARE @fullWidthCount INT,@halfWidthCount INT;
Set @fullWidthCount=0;
Set @halfWidthCount=0;

WHILE (@s1<=@x1)
BEGIN
IF (UNICODE(SUBSTRING(@MSG, @s1, 1)) > 255)
Begin
Set @fullWidthCount=@fullWidthCount+1;
End
ELSE
Begin
Set @halfWidthCount=@halfWidthCount+1;
End
--加1
Set @s1=@s1+1
END

print DATALENGTH(@MSG);
print LEN(@MSG);
print 'fullWidthCount='+Convert(varchar,@fullWidthCount)+';halfWidthCount='+Convert(varchar,@halfWidthCount);

2023年6月20日 星期二

Windows 修改Apache port,瀏覽器強制導回localhost

本篇記錄當我修改完Apache port後,在瀏覽器的網址列輸入localhost:8081,瀏覽器就會自動強制導回localhost。

參考資料:Apache Virtual Host 多網域網站放置在同一台主機

2023/06/20 

一般修改Apache Port只需要修改httpd.conf檔即可,檔案的位置位在apache/conf目錄底下,並找到以下兩行代碼,如下。

Listen 80
.....
ServerName localhost:80

將上方的80 Port改為你想要的Port即可,我是將80改為8081,改完後請重新啟動Apache。

重點來了,當我重啟Apache後,只要我在瀏覽器的網址列輸入localhost:8081(預設的80是我本機的IIS),瀏覽器就會自動強制導回localhost(也就是IIS),因為我公司專案是委外開發的,後來我在httpd.conf看到了這一行代碼,如下。

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

原來我的專案中是有設定了Virtual hosts,其目的是為了可以在同一個伺服器架設多個網站。

於是我試著修改conf/extra/httpd-vhosts.conf檔,將原本有80的地方改為8081,如下。

<VirtualHost _default_:8081>
DocumentRoot "${WEBROOT}"
<Directory "${WEBROOT}">
Options FollowSymLinks
AllowOverride All
Require all granted
AddDefaultCharset utf-8
</Directory>
</VirtualHost>

修改完後一樣重新啟動Apache,就可以正常執行localhost:8081

2020年6月8日 星期一

ASP.NET WebForm RadioButtonList 使用JQuery取得使用者所選擇的項目

參考資料1:[jQuery] RadioButtonList 取值


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <script src="js/jquery-1.11.3.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('input[type="radio"][name="<%=RBL1.UniqueID %>"]').change(function () {
                var SelectVal = $(this).val();
                var SelectText = $(this).closest('td').find('label').text(); //用closest取得radio上一層的td,並取得label的text
                $('#<%=Label1.ClientID%>').text(SelectText+':');

            });
//法1.請看參考資料1
            //$('#<%=Label1.ClientID%>').text($('input:radio[name="<%=RBL1.UniqueID %>"]:checked + label').text()+':');
//法2.先取得RadioButtonList預設選取哪一個項目,並用closest取得radio上一層的td,並取得label的text
            $('#<%=Label1.ClientID%>').text($('input:radio[name="<%=RBL1.UniqueID %>"]:checked').closest('td').find('label').text()+':');
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
    查詢方式:
            <asp:RadioButtonList ID="RBL1" runat="server" RepeatDirection="Horizontal">
                <asp:ListItem Selected="True" Value="0">姓名</asp:ListItem>
                <asp:ListItem Value="1">學號</asp:ListItem>
            </asp:RadioButtonList>
            <br/>
            <asp:Label ID="Label1" runat="server"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        </div>
    </form>
</body>
</html>

2019年10月1日 星期二

Delphi TADOQuery 查詢資料

參考資料1:[delphi]Delphi ADOQuery連接數據庫的查詢、插入、刪除、修改
參考資料2:請問有關動態建立ADOQuery的方法

uses ...., ADODB; //要使用TADOQuery必須在uses這裡先引用ADODB

procedure TForm1.ButIfClick(Sender: TObject);
var tmp: string;
var DMODULE:TDATAMODULE;
    ADOQueryTmp1:TADOQuery;
begin

  tmp:='';
  InputQuery('查詢', '請輸入學號或姓名:', tmp);
  tmp:=trim(tmp);
  if tmp='' then
  begin
    ShowMessage('要查詢的資料不能為空白');
    Exit;
  end;

  DMODULE := TDATAMODULE.Create(Application);
  ADOQueryTmp1 := TADOQuery.Create(DMODULE);
  ADOQueryTmp1.ConnectionString :='資料庫的連線字串';
  with ADOQueryTmp1 do
  begin
      ADOQueryTmp1.Close;
      ADOQueryTmp1.SQL.Clear;
      {
      //法1 開始==========================
      //法1.用字串串字串的方式組合出SQL指令
      ADOQueryTmp1.SQL.Text:='Select StudentID,StudentName from Student where StudentID=' + quotedstr(tmp) + ' or StudentName=' + quotedstr(tmp);
      //法1 結束==========================
      }

      //法2 開始==========================
      //建議使用法2
      ADOQueryTmp1.SQL.Text:='Select StudentID,StudentName from Student where StudentID=:D1 or StudentName=:D2';
      ADOQueryTmp1.Parameters.ParamByName('D1').Value:=tmp;
      ADOQueryTmp1.Parameters.ParamByName('D2').Value:=tmp;
      //法2 結束==========================

      //ADOQuery.Open與ADOQuery.ExecSQL不同之處在於ADOQuery.Open一般用在Select查詢;而ADOQuery.ExecSQL用在insert、delete、update等。
      ADOQueryTmp1.Open;

      if ADOQueryTmp1.isempty=false then
      begin
         ShowMessage('有資料,姓名:' + ADOQueryTmp1.FieldByName('StudentName').AsString);
      end;
      ADOQueryTmp1.Close;
  end;

end;

Delphi 字串切割

我所使用的環境是Delphi 7

以下是字串切割的程式碼:

var str_data: string;a: TStringList;
str_data := '0001 王小明'; //假如這是我的資料,0001是職員編號

a := TStringList.Create;
a.Delimiter := ' '; // 指定分割字元
a.DelimitedText := str_data; // 要被分割的字串


然後只要抓取a[0]就可以取得0001

2019年3月13日 星期三

Delphi 備忘錄


Chr(13) 代表換行;有時候在程式碼中,會有些字串希望可以換行,就可以使用Chr(13);也可以在程式碼中直接加上#13#10可以換行,例如:'ABCD'+#13#10+'EFGH'。
Chr(9) 代表Tab鍵,也可以輸入#9。

如果想在一個字串中加入單引號,必須打上兩個單引號,例如:'Hello~ 我是''王小明'''。

內建函數
1. IntToStr 數字轉字串;範例:IntToStr('2019') + 'Hello~'。
2. quotedstr 在字串前後加上單引號;範例:quotedstr('Hello~')。
3. Format 字串格式化;範例:Format('Hello 我是%s,我的專長是%s',['王小明','程式設計']),輸出的結果:Hello 我是王小明,我的專長是程式設計。
4. Exit 中斷執行。

快捷鍵
Delphi 7開發環境
Shift + Ctrl + U或 I   選取程式碼在按下快捷鍵,可增減縮排。



2019/10/02
InputQuery函數的提示文字有缺字
參考資料:inputbox的提示字字數會少SHOW出來
在程式碼中使用InputQuery函數,只要提示的字數到一定的長度,中文字就會有缺字的情況發生,要解決這個問題只要在FormCreate事件中設定DefFontData.Name為新細明體即可,程式碼如下。
procedure TfrmTEST1.FormCreate(Sender: TObject);
begin
  ....
  DefFontData.Name := '新細明體';
  ....
end;