public void create_tod_repair_test_file(DataTable dt, string file_type, EDA_FILE_TOD _EDA_FILE_TOD)
    {
        DataTable dt_chip = new DataTable();



        DataView dv_south_step = new DataView();

        dv_south_step = dt.DefaultView;


        dt_todr_south_step = dv_south_step.ToTable(true, "SOUTH_SHOP", "SOUTH_STEP");

        DataView dv = new DataView();



        dv = dt.DefaultView;

        dt_chip = dv.ToTable(true, "SOUTH_STEP", "CODE", "SOUTH_SHOP", "CHIP_ID", "DATA", "GATE");



        //DataColumn REPR_STARTTIME = dt_chip.Columns["REPR_STARTTIME"];
        //DataColumn CHIP_ID = dt_chip.Columns["CHIP_ID"];
        //DataColumn SOUTH_STEP = dt_chip.Columns["SOUTH_STEP"];

        //DataColumn SOUTH_SHOP = dt_chip.Columns["SOUTH_SHOP"];


        //dt_chip.PrimaryKey = new DataColumn[] { REPR_STARTTIME, CHIP_ID, SOUTH_STEP, SOUTH_SHOP };



        DataTable dt_index_chip_id = new DataTable();


        for (int i = 0; i <= dt_chip.Rows.Count - 1; i++)
        {
            // add send dir
            di_send = new DirectoryInfo(HttpContext.Current.Server.MapPath(".") + "//FILE//SEND//" + dt_chip.Rows[i]["SOUTH_SHOP"].ToString()); //DateTime.Now.ToString("yyyyMMdd")

            //di = new DirectoryInfo(Server.MapPath(".") + "\\RUN_LOG\\" ); //DateTime.Now.ToString("yyyyMMdd")
            di = new DirectoryInfo(HttpContext.Current.Server.MapPath(".") + "//FILE//TODR//" + DateTime.Now.ToString("yyyyMMdd") + "//" + dt_chip.Rows[i]["SOUTH_SHOP"].ToString() + "//" + dt_chip.Rows[i]["SOUTH_STEP"].ToString() + "//" + dt_chip.Rows[i]["CHIP_ID"].ToString().Substring(0, 5) + "//" + dt_chip.Rows[i]["CHIP_ID"].ToString().Substring(0, 8)); //DateTime.Now.ToString("yyyyMMdd")
            //fi = new FileInfo(Server.MapPath(".") + "\\RUN_LOG\\" + DateTime.Now.ToString("yyyyMMdd") + "\\" + DateTime.Now.ToString("yyyyMMdd") + ".log");
            fi = new FileInfo(HttpContext.Current.Server.MapPath(".") + "//FILE//TODR//" + DateTime.Now.ToString("yyyyMMdd") + "//" + dt_chip.Rows[i]["SOUTH_SHOP"].ToString() + "//" + dt_chip.Rows[i]["SOUTH_STEP"].ToString() + "//" + dt_chip.Rows[i]["CHIP_ID"].ToString().Substring(0, 5) + "//" + dt_chip.Rows[i]["CHIP_ID"].ToString().Substring(0, 8) + "//" + dt_chip.Rows[i]["CHIP_ID"].ToString() + "." + file_type);

            if (!di_send.Exists)
            {
                di_send.Create();//目錄不存在 產生目錄
            }



            if (!di.Exists)
            {
                di.Create();//目錄不存在 產生目錄
            }
            if (fi.Exists == true)
            {
                //檔案存在 寫檔案
                //sw = File.AppendText(Server.MapPath(".") + "\\RUN_LOG\\" + DateTime.Now.ToString("yyyyMMdd") + ".log");
                fi.Delete();
                sw = File.AppendText(HttpContext.Current.Server.MapPath(".") + "//FILE//TODR//" + DateTime.Now.ToString("yyyyMMdd") + "//" + dt_chip.Rows[i]["SOUTH_SHOP"].ToString() + "//" + dt_chip.Rows[i]["SOUTH_STEP"].ToString() + "//" + dt_chip.Rows[i]["CHIP_ID"].ToString().Substring(0, 5) + "//" + dt_chip.Rows[i]["CHIP_ID"].ToString().Substring(0, 8) + "//" + dt_chip.Rows[i]["CHIP_ID"].ToString() + "." + file_type);

                //fi.Delete();
            }
            else
            {
                sw = fi.CreateText(); //檔案不存在 產生檔案
            }


            dv.RowFilter = "CHIP_ID='" + dt_chip.Rows[i]["CHIP_ID"].ToString() + "'";

            // dv.RowFilter = "CHIP_ID='" + dt_chip.Rows[i]["CHIP_ID"].ToString() + "' and SOUTH_STEP='" + dt_chip.Rows[i]["SOUTH_STEP"].ToString() + "' and SOUTH_SHOP='" + dt_chip.Rows[i]["SOUTH_SHOP"].ToString() + "'";
            dv.Sort = "GLASS_START_TIME";

            dt_index_chip_id = dv.ToTable();


            //  First Row
            sw.WriteLine("Code Data  Gate");

            // Second Row   2~N

            for (int j = 0; j <= dt_index_chip_id.Rows.Count - 1; j++)
            {
                #region initial data

                _EDA_FILE_TOD.SOUTH_STEP = dt_index_chip_id.Rows[j]["SOUTH_STEP"].ToString();
                _EDA_FILE_TOD.CODE       = dt_index_chip_id.Rows[j]["CODE"].ToString();
                _EDA_FILE_TOD.SOUTH_SHOP = dt_index_chip_id.Rows[j]["SOUTH_SHOP"].ToString();  //C2M
                _EDA_FILE_TOD.GATE       = dt_index_chip_id.Rows[j]["GATE"].ToString();

                _EDA_FILE_TOD.DATA = dt_index_chip_id.Rows[j]["DATA"].ToString();

                _EDA_FILE_TOD.CHIP_ID = dt_index_chip_id.Rows[j]["CHIP_ID"].ToString();



                #endregion


                // Second Row   2~N
                sw.WriteLine(_EDA_FILE_TOD.CODE + " " + _EDA_FILE_TOD.DATA + " " + _EDA_FILE_TOD.GATE);


                // last Row  Add  Finished symbol  '@'
                //if (j == dt_index_chip_id.Rows.Count - 1)
                //{
                //    sw.WriteLine(_EDA_FILE_LCM.SPEC4_FLAG);

                //}
            }
            sw.Close();
        }
    }
    public void create_tod_repair_test_file_ini()
    {
        string AOI_step = "'T1A13WS'";

        //string AOI_step = "'1930','T1A13WS','1378B','S478B','P378B'";
        //string repair_step = "'T1A13WS'";

        // add verify sites
        // string sites = "'NGB','NH','TN'";

        EDA_FILE_TOD _EDA_FILE_TOD = new EDA_FILE_TOD();



        sql_temp1 = @"

select 'TODR' as SOUTH_STEP,
       'CLC1' as CODE,
       'C2M' as SOUTH_SHOP,
       'Y' || substr(tt.chip_id, 7, 12) as CHIP_ID,
        LPAD(RTRIM(tt.s), 5, '0') as DATA,
        LPAD(RTRIM(tt.g), 5, '0') as GATE,
       tt.STEP_ID,
       tt.glass_start_time
       
  from lcdsys.array_defect_t tt
 where 1 = 1
  
   and tt.step_id in ({2})
  
   and tt.item3 = '3'
   and tt.glass_start_time >=
       to_date('{0}', 'yyyyMMdd hh24mi')
   and tt.glass_start_time <
       to_date('{1}', 'yyyyMMdd hh24mi')
   order by tt.chip_id,tt.glass_start_time



";



        // sql_temp1 = string.Format(sql_temp1, test_step, repair_step, yesturday_shiftday,today_shiftday);


        sql_temp1 = string.Format(sql_temp1, tod_yesturday + " 0700", tod_today + " 0700", AOI_step);



        //OracleCommand cmd = new OracleCommand(sql_temp1, orcn);
        //OracleDataAdapter da=new OracleDataAdapter(cmd);
        //DataSet ds=new DataSet();
        //da.Fill(ds,"test");

        // check  if file exits
        if (get_dataSet_access_oracle_client(sql_temp1, conn).Tables[0].Rows.Count > 0)
        {
            create_tod_repair_test_file(get_dataSet_access_oracle_client(sql_temp1, conn).Tables[0], "txt", _EDA_FILE_TOD);

            GridView1.DataSource = get_dataSet_access_oracle_client(sql_temp1, conn);
            GridView1.DataBind();
            for (int k = 0; k <= dt_todr_south_step.Rows.Count - 1; k++)
            {
                System.Diagnostics.Process.Start(Server.MapPath("7z.exe"), " a -tzip " + Server.MapPath(".") + "//FILE//TODR//" + DateTime.Now.ToString("yyyyMMdd") + "//" + dt_todr_south_step.Rows[k]["SOUTH_SHOP"].ToString() + "//" + "T1_" + dt_todr_south_step.Rows[k]["SOUTH_STEP"].ToString() + "_" + today_detail1 + ".zip" + " " + Server.MapPath(".") + "//FILE//TODR//" + DateTime.Now.ToString("yyyyMMdd") + "//" + dt_todr_south_step.Rows[k]["SOUTH_SHOP"].ToString() + "//" + dt_todr_south_step.Rows[k]["SOUTH_STEP"].ToString() + "//*").WaitForExit();
                System.Diagnostics.Process.Start(Server.MapPath("7z.exe"), " a -tzip " + Server.MapPath(".") + "//FILE//SEND//" + dt_todr_south_step.Rows[k]["SOUTH_SHOP"].ToString() + "//" + "T1_" + dt_todr_south_step.Rows[k]["SOUTH_STEP"].ToString() + "_" + today_detail1 + ".zip" + " " + Server.MapPath(".") + "//FILE//TODR//" + DateTime.Now.ToString("yyyyMMdd") + "//" + dt_todr_south_step.Rows[k]["SOUTH_SHOP"].ToString() + "//" + dt_todr_south_step.Rows[k]["SOUTH_STEP"].ToString() + "//*").WaitForExit();
            }
        }


        SendEmail("*****@*****.**", "*****@*****.**", "[CIM 電子報系統] " + tod_today_format + " T1 TOD File 傳輸 Daily Check OK !", "程式執行成功", "", "");
    }