星期一, 12月 17, 2018

筆記-C# 擷取某區間字串

string aa = abc(a b c)aaa
 int firstIndex = 0;
 int endIndex = 0;
 firstIndex = aa.IndexOf("(");//定位(位置
 endIndex = aa.IndexOf(")");//定位)位置
 string tmpStr = "";
 string ReportTmpStr = "";
 ReportTmpStr = aa;
 if (firstIndex >= 0 && endIndex >= 0)
 {
       tmpStr = ReportTmpStr.Substring(firstIndex, endIndex + 1);//擷取出(a b c)

       string ReportTmpStr2 = tmpStr.Replace(" ", "");//取代空格
       ReportTmpStr = ReportTmpStr.Replace(tmpStr, ReportTmpStr2);
 }

星期日, 11月 05, 2017

筆記 C# DataGridView 建立全選項目與全選之方法

private void Form1_Load(object sender, EventArgs e)
        {
         
           
            DataGridViewColumn dgvc = new DataGridViewCheckBoxColumn();
            dgvc.Width = 40;
            dgvc.Name = " ";
            this.dataGridView1.AllowUserToAddRows = false;
            dataGridView1.Columns.Insert(0, dgvc);

            Rectangle rect = dataGridView1.GetCellDisplayRectangle(0, -1, true);
            rect.X = rect.Location.X + rect.Width / 4 - 9;
            rect.Y = rect.Location.Y + (rect.Height / 2 - 9);

            CheckBox cbHeader = new CheckBox();
            cbHeader.Name = "checkboxHeader";
            cbHeader.Size = new Size(18, 18);
            cbHeader.Location = rect.Location;
            //全選要設定的事件
            cbHeader.CheckedChanged += new EventHandler(cbHeader_CheckedChanged);

            //將 CheckBox 加入到 dataGridView
            dataGridView1.Controls.Add(cbHeader);

        }
        private void cbHeader_CheckedChanged(object sender, EventArgs e)
        {
            // 避免編輯的資料因為 EditMode 狀態,不能正常勾選
            dataGridView1.EndEdit(); 

            foreach (DataGridViewRow dr in dataGridView1.Rows)
                dr.Cells[0].Value = ((CheckBox)dataGridView1.Controls.Find("checkboxHeader", true)[0]).Checked;
        }



參考資料:
http://jengting.blogspot.tw/2016/07/DataGridView-DataGridViewCheckBoxColumn-HeaderCell-CheckBox-SelectAll.html
https://dotblogs.com.tw/shunnien/2013/07/22/111941

星期日, 10月 18, 2015

關於MBP kernel_task CPU飆破100%解決方案

一直以來我的MBP都有個問題困擾著,那就是只要系統更新完kernel_task CPU都會飆破100%甚至到達1050%,之前幾個版本都可以直接到/System/Library/Extensions/IOPlatformPluginFamily.kext/Contents/Plugins/ACPI_SMC_PlatformPlugin.kext/Contents/Resources刪除"機號識別碼的Plist"檔即可解決
但最新版10.11  El Capitan卻發現刪除時會出現 rm macbookpro8_1.plist operation not permitted的錯誤訊息
上網搜尋後發現原來OSX 從10.11版起啟用了新的所"系統完整性保護"機制導致無法刪除
詳細解決步驟如下
 1. 重新啟動系統 並且同時按下"Command+R"鍵 進入還原模式
 2.開啟工具選單中的"終端機"
 3.輸入"csrutil disable; reboot"並按下"Enter" 此時電腦會重開機
以上即可關閉 "系統完整性保護"機制"

要刪除Plist檔步驟如下:
1.點選左上角"蘋果"按鈕
2.點擊"系統報告"
3.在系統報告中找到機型識別碼 (先記錄下來)
4.開啟終端機並進入路徑( /System/Library/Extensions/IOPlatformPluginFamily.kext/Contents/Plugins/ACPI_SMC_PlatformPlugin.kext/Contents/Resources)
5.#sudo rm 機型識別碼.plist
6.輸入使用者密碼
7.重開機
以上即可刪除,重開機後即可解決問題

 參考來源:
http://0123456789.tw/?p=261
http://osxdaily.com/2015/10/05/disable-rootless-system-integrity-protection-mac-os-x/ 

星期二, 4月 21, 2015

筆記-C#設定DateTimePicker顯示空白

判斷資料庫內容是否為 "1990/1/1 上午 12:00:00"
if (myReader.GetString(21) == "" || myReader.GetString(21) == "1990/1/1 上午 12:00:00")
 {
      設定為空白
      UrlTimePicker.CustomFormat = " ";
      UrlTimePicker.Format = DateTimePickerFormat.Custom;
 }
 else
 {
      設為預設
      UrlTimePicker.Format = DateTimePickerFormat.Long;
      UrlTimePicker.Text = myReader.GetString(21);  
  }

星期二, 2月 10, 2015

筆記-C# 刪除DATASET 資料列

DataSet ds = new DataSet();//宣告DataSet ds
                    
//**********開啟EXCEL檔**********
OpenFileDialog openfile = new OpenFileDialog();//開啟檔案資料夾視窗

openfile.Filter = "Excel files(*.xls)|*.xls";//設定開啟EXCEL格式
if (openfile.ShowDialog() == DialogResult.OK)
    {
                          
        string text = openfile.FileName;//開啟的檔案名稱
                       
                          
        // 設定EXCEL連線字串
         string ExcelCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + text + ";Extended Properties='Excel 8.0;HDR=No;IMEX=1;TypeGuessRows=0;ImportMixedTypes=Text'";
        /*說明
        Provider:
        Microsoft.Jet.OLEDB.4.0用於2003以前版本 Microsoft.Jet.OLEDB.12.0用於2007以後版本
        Data Source: 檔案位置
        Extended Properties:Excel版本 97~2003都適用
        HDR:Yes-首欄為標題列,No-首欄為資料列
        IMEX:IMEX=0-匯出模式,IMEX=1-匯入模式,IMEX=2-連結模式
        TypeGuessRows=0:預設為8 代表會先讀取前8列資料,判斷格式是否固定,0會將所有資料讀出在判斷
        ImportMixedTypes=Text:當每一列格式不同預設將自動轉為文字格式
        p.s.經過測試 TypeGuessRows設為8或0在我的客戶這邊都會出現資料格式判斷有問題,所以第一行本來應該是標題列在此還是把他設定成資料列以利後面格式判斷
                */            
        OleDbConnection GetXLS = new OleDbConnection(ExcelCon);
        GetXLS.Open();//開啟EXCEL連線
        DataTable Sheet = GetXLS.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,null);
        string SelectSheet = "";
                          
        //讀取每個SHEET內容至DATASET
foreach (DataRow row in Sheet.Rows)
{
                                SelectSheet = (string)row["TABLE_NAME"].ToString();

    if (SelectSheet.Substring(SelectSheet.Length - 2) != "$'")
    {
    }
    else
    {
        //MessageBox.Show(SelectSheet.ToString());
        OleDbCommand excel_cmd = new OleDbCommand("SELECT * FROM [" + SelectSheet + "];", GetXLS);
        OleDbDataAdapter xlsDa = new OleDbDataAdapter(excel_cmd);
        xlsDa.Fill(ds, "data");
    }
}
GetXLS.Close();//關閉EXCEL連線
                          
//因為客戶端檔案資料格式無法統一故在此下判斷標題列並刪除
for (int x = 0; x < ds.Tables["data"].Rows.Count; x++)
{
    if (ds.Tables["data"].Rows[x].ItemArray[0].ToString() == "idno")
    {
        ds.Tables["data"].Rows[x].Delete();//刪除DATASET資料行
        ds.Tables["data"].AcceptChanges();//允許DATASET資料變更
        da.Update(ds, "data");//更新DATASET
                                  
    }
}

星期一, 2月 02, 2015

筆記-C# Timer使用筆記

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 DB_Backup
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            //設定觸發時間
            timer1.Interval = 1000;
            //啟動Timer
            timer1.Enabled = true;
        
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            //取的當前時間
            DateTime DT_now = DateTime.Now;
            //設定tbTime textBox text顯示當前日期時間
            tbTime.Text = DT_now.Year + "/" + DT_now.Month + "/" + DT_now.Day + "  " + DT_now.Hour + ":" + DT_now.Minute + ":" + DT_now.Second;


           
        }
    }
}

星期四, 10月 31, 2013

SPFDISK使用筆記

本篇以建立選單為例
使用DOS開機片進入SPFDISK
Photobucket

進入SPFDISK之後首先選擇"P.硬碟分割工具"確認有多少分割區
Photobucket

若要退出請按鍵盤按鈕ESC


接下來準備開始建立選單
在此會以四個選單為例
1.首先選擇"建立開機選單"的選項
Photobucket

2.選擇欲建立選單的磁碟機
Photobucket

3.選擇選單的分割區
在此地順序可以自行更換(選單順序需要自行編排)
Photobucket

4.自行鍵入選單的名稱
Photobucket

已完成第一個選單建立
其餘三個重複以上步驟即可


其他控制
建立完後可以於"M. 編輯開機選單"選項
進行選單設定
Photobucket

或者進行"進階設定"
Photobucket

進階設定裡面
可以設定 計時開機-可以設定開機選單等待時間
通行密碼-設定某一選項進入需要密碼

全部完成後
最後則使用"進行安裝"將選單結果存檔
在此會有三個選項一般選擇"MBR"
Photobucket

星期六, 4月 30, 2011

2011.04.30 SL100-1,2

//JDK-編輯java程式使用
//JRE-跑JAVA程式使用
//編輯語法軟體JCreator
//以建立專案Project 管理java原始檔
// Basic JAVA Application 針對程式
// Basic JAVA Applet針對網頁
// Empty Project空白專案

//JAVA中JAVA File 檔名很重要(分大小寫)
//*.java==>原始程式
//*.class==>編譯後的class檔

//物件導向中重要觀念 "Encapsultion 封裝"


public class Test
//定義class java語法須有一個public class,public class Name 須與檔名依樣
//public class Name 即是編譯後產生的"*.class" 檔名
{
public static void main(String[] args)
//設定function物件導向
{
System.out.println("Hello"); //輸出字串
//println 輸出字串至螢幕斷行 print輸出字串至螢幕不斷行
System.out.println('1'); //輸出字元

int a=100; //指定變數
System.out.println(a);

a=200; //重新指定變數內容
System.out.println(a);

System.out.println(1+1); //運算式
System.out.println(7/2); //結果會為3,若兩數皆為整數則除出來會是整數
System.out.println(7.0/2);//若要算出結果為3.5須使使用7.0/2才會是浮點數
System.out.println("aaa" + a); //字元運算可加邊數
System.out.println("aaa" + "bbb"); //字元運算串雙字串

}
}


//資料表示方法;
/*常數Consof-程式執行中不能被改變的資料,直接將資料內容寫入程式
("Hello")字串常數以雙引號表示*/

//type 資料型別(常數)
//文字
//字元-'a' 'b' '中'
//字串-"abc"
//數字
//整數- 125
//浮點數- 125.0
//布林boolean
//true
//false


//變數Variable-程式執行中可以被改變的資料,需要經過宣告
//型別名稱 變數名稱1,2,....; (語法)
//#int a;
//#a=100;
//#a=75 >int 需要使用正確型別-整數=int
//#a=75.2 >double 需要使用正確型別-浮點數=double
//#a=75.2f >float 需要使用正確型別-浮點數加上才等於float
//#int a=100;
//型別名稱可用名稱
//整數;
//byte 1byte -128至127
//short 2byte -32768至32767
//int 4byte
//long 8byte
//浮點數
//float 4byte
//double 8byte
//字元
//char 2byte
//布林
//boolean 2byte
//變數名稱規則
//首字必須為英文字或$或 _ 且不可以使用保留字
//同一變數不可再同一區塊被宣告兩次
//變數為一記憶體空間
//變數資料可以隨時被重新利用

//運算元operator
//1.算數運算元 (1+1)
// +
// -
// *
// / 求商
// % 求餘數

//2.字串運算 ("123"+"123") 字串相加
// + 字串相加 只須有一端為字串

//3.指定運算元 =左邊一定要是變數,且只能有一變數,指定變數專用
// =
// += a += b; > a=a+b;
// -=
// *=
// /=
// %=

//強制轉型
//int a,b;
//double c;
//a=7;
//b=2;
//c=a/b; 原先算出為3.0
//c=(double)a/b;利用強制轉行在運算事前加入(型別)即可算處3.5
//強制轉型lab
public class Test2
{
public static void main(String[] args)
{
int a,b;
double c;
a=7;
b=2;
c=(double)a/b; //運算式前加入型態

System.out.println("c=" + c);
}
}

//累加運算 ++ a++/++a > a=a+1 a++ 為後加 ++a為先加
//累減運算 --

//累加運算lab
public class Test3
{
public static void main(String[] args)
{
int a,b,c;
a=7;
b=5;
//c=a+++b;語法不能這樣下
c=a+ ++b; //可以改為此
//c=++a+b; 或改為此
//c=a+b++;

System.out.println("a=" + a);
System.out.println("b=" + b);
System.out.println("c=" + c);
}
}


//關係運算元 true or false 判斷左右是否符合條件
// >
// >=
// <
// <=
// != 不等於
// ==
//邏輯運算
// ! Not
// &&(短路) 而且 &(非短路)
// ||(短路) 或者 |(非短路)
//短路-當前面以運算以不成立則不執行後面運算
//非短路-不管前面運算成不成立後面運算皆會執行

//lab
public class Test4
{
public static void main(String[] args)
{
System.out.println(true && false); //
System.out.println(true & false);
System.out.println(true || false);
System.out.println(true | false);

int a=1,b=2;
//System.out.println(a++ > 1 && b++ <2);
使用&&為短路,故前段運算是式等於false則不會執行後段運算式
System.out.println(a++ > 1 & b++ <2);
//使用&為不短路,則不論前段運算式是否為ture皆會執行後段運算式
System.out.println("a=" +a);
System.out.println("b=" +b);
}
}

星期二, 3月 23, 2010

製作DOS開機碟

一般來說電腦管理比較好的方式
應該就是要有一個還原機制
所以電腦工程師都會在磁碟區域留一個磁區放置還原檔
但是考量到還要拿開機片~
就有點麻煩了~
故可以這樣做
使用DOS開機磁片或光碟片開機
進入DOS
使用format指令製作開機磁碟
format c: /s /q
就可以製作開機磁碟
完成後只需要再將該磁碟加入開機選單
即可~

意外的發現DOS開機光碟

最近因為想要來製作上課用的DOS開機光碟
無奈家裡的所有電腦都早就不配備3.5磁碟機
本來想說做不成了~
後來無意間在網路上發現
有製作好的DOS開機光碟的ISO可以下載
載點位於
http://pchome.drj.com.tw/download/index.php
是由PCHOME電腦雜誌所提供的檔案下載網站
可以在硬體王裡面找到98開機片ISO
http://pchome.drj.com.tw/download/files/200503_advance/BOOT.ISO
可以直接下載使用
若需要增加自己需要工具可以使用Winiso之類的工具修改