星期日, 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;


           
        }
    }
}