2010年6月22日 星期二

[Other] 嚇一跳阿

 

昨天內人打了一通電話過來,說是 帶小朋友去醫院 看醫生,可能是醫院生意太好了 ..

所以要等很久。。

於是跑到附近 M 用餐(主要是為了 萬惡的溜滑梯),突然 一下子小孩不見了!!

各個地方都找過了,就是找不到 寶貝兒子。。

 

最後經過附近的店家告知,有個小孩子過馬路 跑回去醫院了。

 

!!天阿!!

見到面的第一句話是 『媽媽 我在等你喔』  。  真是嚇死人了。

2010年6月17日 星期四

[C#] DateTime 加一天, String to DateTime

--
--

        private string GET_ADD1_DAY(string DT)
        {
            DateTime BF = new DateTime();
            BF = (DateTime.Parse(DT)).AddDays(1);
            string NEW_DATE = BF.ToString("yyyy-MM-dd");
            return NEW_DATE;
        }
--
--

2010年6月15日 星期二

[C# ASP.NET] LABEL To PH

                 Label lb = new Label();
                lb.Text = "請正確輸入日期格式 Example:2010-05-01";
                lb.Font.Size = 20;
                lb.ForeColor = System.Drawing.Color.Yellow;
                lb.BackColor = System.Drawing.Color.Black;
                PlaceHolder1.Controls.Add(lb);

2010年6月11日 星期五

[C# ASP.NET] DataTABLE TO CSV

1.)首先 所在頁面的 命名空間請加入 Using 內.
2.)CLASS

   public static class DataTABLE_TO_CSV_CLASS
    {
        public static string DT_TO_CSV(this DataTable dt)
        {
            StringBuilder sb = new StringBuilder();
            for (int x = 0; x < dt.Columns.Count; x++)
            {
                if (x != 0)
                    sb.Append(",");
                sb.Append(dt.Columns[x].ColumnName);
            }
            sb.AppendLine();
            foreach (DataRow row in dt.Rows)
            {
                for (int x = 0; x < dt.Columns.Count; x++)
                {
                    if (x != 0)
                        sb.Append(",");
                    sb.Append(row[dt.Columns[x]].ToString());
                }
                sb.AppendLine();
            }
            return sb.ToString();

        }
    }



使用時:

                //將 Datatable 存成 CSV
                string ds_string = DataTABLE_TO_CSV_CLASS.DT_TO_CSV(ds._DT_ReturnValue);
                ds_string = ds_string.Replace("\r\n","\n").Trim();
                string[] ds_string_array=ds_string.Split(new char[] { '\n'});
                File.WriteAllLines(System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory).ToString()+"\\"+txtStartDate.Text+"-OQC.csv", ds_string_array, Encoding.Default); 

[C# ASP.NET] Web DataTABLE to TABLE

  public Table CreateTableByDatatable(DataTable ds)
        {
            Table tb = new Table();  //主表
            TableRow tr = null;      //列
            TableCell tc = null;     //行
            Label lb = null;
            HyperLink lk = null;

            //=========================================================設定 Table 參數
            tb = new Table();
            //tb.Width = 1000;
            tb.Font.Name = "Courier New";
            tb.CellPadding = 1;
            tb.CellSpacing = 1;
            tb.BorderStyle = BorderStyle.Solid;
            tb.BorderWidth = 0;
            tb.BorderColor = System.Drawing.Color.FromName("#C0C0C0");
            //tb.GridLines = GridLines.Both;
            //=========================================================設定 標題
            tr = new TableRow();
            lb = new Label();
            tb.Rows.Add(tr);
            tc = new TableCell();
            tc.Attributes.Add("Style", "border-width:1px;border-color:#006699;border-style:solid");
            tc.ColumnSpan = ds.Columns.Count + 1;          //合併儲存格
            tc.HorizontalAlign = HorizontalAlign.Center;
            //lb.Width = ds.Columns.Count  * 70 + 140;
            lb.Text = "Raw Data";
            lb.BackColor = System.Drawing.Color.FromName("#17375D");
            lb.ForeColor = System.Drawing.Color.FromName("#FFFFFF");
            tc.BackColor = lb.BackColor;
            tc.Controls.Add(lb);
            tr.Cells.Add(tc);
            //=========================================================
            tr = new TableRow();
            for (int i = 0; i < ds.Columns.Count; i++)
            {
                lb = new Label();
                tb.Rows.Add(tr);
                tc = new TableCell();
                tc.Attributes.Add("Style", "border-width:1px;border-color:#006699;border-style:solid");
                tc.HorizontalAlign = HorizontalAlign.Center;
                //lb.Width = ds.Columns.Count * 70 + 140;
                lb.Text = ds.Columns[i].ColumnName;
                lb.BackColor = System.Drawing.Color.FromName("#F5FF8E");
                lb.ForeColor = System.Drawing.Color.FromName("#000000");
                tc.BackColor = lb.BackColor;
                tc.Controls.Add(lb);
                tr.Cells.Add(tc);
            }
            //========================================================
            for (int j = 0; j < ds.Rows.Count; j++)
            {
                if (cmbFunction.SelectedValue != "SELECT")
                {
                    if (cmbFunction.SelectedValue == ds.Rows[j].ItemArray[3].ToString())
                    {
                        tr = new TableRow();
                        tb.Rows.Add(tr);
                        for (int i = 0; i < ds.Columns.Count; i++)
                        {
                            lb = new Label();
                            tc = new TableCell();
                            tc.Attributes.Add("Style", "border-width:1px;border-color:#006699;border-style:solid");
                            tc.HorizontalAlign = HorizontalAlign.Center;
                            //lb.Width = ds.Columns.Count * 70 + 140;
                            lb.Text = ds.Rows[j].ItemArray[i].ToString();
                            lb.BackColor = System.Drawing.Color.FromName("#FFFFFF");
                            lb.ForeColor = System.Drawing.Color.FromName("#000000");
                            tc.BackColor = lb.BackColor;
                            tc.Controls.Add(lb);
                            tr.Cells.Add(tc);

                        }

                    }
                }
                else
                {
                    tr = new TableRow();
                    tb.Rows.Add(tr);
                    for (int i = 0; i < ds.Columns.Count; i++)
                    {
                        if (ds.Columns[i].ColumnName == "FAIL" & int.Parse(ds.Rows[j].ItemArray[7].ToString ())>0)
                        {
                            lk = new HyperLink();
                            tc = new TableCell();
                            tc.Attributes.Add("Style", "border-width:1px;border-color:#006699;border-style:solid");
                            tc.HorizontalAlign = HorizontalAlign.Center;
                            lk.Text = ds.Rows[j].ItemArray[i].ToString();
                            lk.NavigateUrl = "DefectDetail.aspx?date=" + ds.Rows[j].ItemArray[4].ToString() + "&" +
                                                               "fc=" + ds.Rows[j].ItemArray[3].ToString() + "&" +
                                                               "model=" + ds.Rows[j].ItemArray[2].ToString();
                            lk.Target = "_blank";
                            lk.BackColor = System.Drawing.Color.FromName("#FFFFFF");
                            lk.ForeColor = System.Drawing.Color.FromName("#0000FF");
                            tc.BackColor = lk.BackColor;
                            tc.Controls.Add(lk);
                            tr.Cells.Add(tc);
                        }
                        else
                        {
                            lb = new Label();
                            tc = new TableCell();
                            tc.Attributes.Add("Style", "border-width:1px;border-color:#006699;border-style:solid");
                            tc.HorizontalAlign = HorizontalAlign.Center;
                            //lb.Width = ds.Columns.Count * 70 + 140;
                            lb.Text = ds.Rows[j].ItemArray[i].ToString();
                            lb.BackColor = System.Drawing.Color.FromName("#FFFFFF");
                            lb.ForeColor = System.Drawing.Color.FromName("#000000");
                            tc.BackColor = lb.BackColor;
                            tc.Controls.Add(lb);
                            tr.Cells.Add(tc);
                        }

                    }

                }
               

            }

            return tb;


        }