2016年7月25日 星期一

字串與數字轉換,currency and string

1.字串型態的數字轉為整數,currency string to int
ex:
string sNN = 100,200,300
int iNN = int.Parse(Regex.Replace(sNN, @",", "")); (iNN=100200300)

2.從sql 取出來的數字(Numeric)轉為有千分位的字串

2016年7月20日 星期三

ReportViewer相關應用-換頁保留標題


一、換頁後,表頭顯示標題列

1.於RDLC設計畫面,開啟進階模式
2.點選 '靜態'(最上層那ㄧ個)
3.屬性 KeepWithGroup -> After
            RepeatOnNewPage -> True


二、不換頁,全部資料在同一頁

1.ReportViewer屬性 ShowPageNavigatiorControls -> False
2.打開RDLC檔,屬性下拉選擇'報表'(Report),或是報表設計範圍外部灰色區域點一下,
找到InteractiveSize項目,高度設為 0cm。

2016年7月1日 星期五

字串應用

1.有小數點的數字字串,四捨五入取整數且加千分位
ex:string gg1 = 123456.78

decimal dgg = Convert.ToDecimal(gg1);
sting gg2 = dgg.ToString("#,#");
結果: 123,457

2016年5月19日 星期四

DataGridView塞入CheckBox、Button,Insert CheckBox、Button into DataGridView

1.塞入CheckBox:
  1.1 在Form_Load裡面:
            int iColumnCount = dataGridView1.ColumnCount;
            if (iColumnCount == 0)
            {
                DataGridViewCheckBoxColumn col = new DataGridViewCheckBoxColumn()
                {
                    Name = "選擇",
                    FalseValue = 0,
                    TrueValue = 1,
                    Visible = true
                };
                dataGridView1.Columns.Add(col);
            }
 
 1.2 檢視有被勾選的項目:
 foreach (DataGridViewRow row in dataGridView1.Rows)
 {
      DataGridViewCheckBoxCell chk = row.Cells[0] as DataGridViewCheckBoxCell;
      if(Convert.ToBoolean(chk.Value))
      {
          string data= row.Cells[1].Value.ToString() ;//取出第1欄位資料
      }
 }

2.塞入Button:
  2.1  在Form_Load裡面:
            int iColumnCount = dataGridView1.ColumnCount;
            if (iColumnCount == 0)
            {
                DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
                dataGridView1.Columns.Add(btn);
                btn.Name = "btn";
                btn.HeaderText = "標題";
                btn.Text = "執行";
                btn.UseColumnTextForButtonValue = true;
            }
  2.2 執行被按下的Button:
        在dataGridView1_CellClick裡面,
         if (e.ColumnIndex == 0)
         {
              ... do something...
              .
           }

2016年1月8日 星期五

開啟新的Form且定時自動關閉

1.Create new Form, name Form2
2.At Form1:
private void btn_Buttin1_Click(object sender, EventArgs e)
{
    Form2 FM2 = new Form2();
    FM2.ShowDialog();
}
3.At Form2:
private void Form2_Shown(object sender, EventArgs e)
{
    this.timer1.Start();
}

private void timer1_Tick(object sender, EventArgs e)
{
    this.timer1.Interval = 1000; //1秒
    this.Close();
}