Example #1
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (DropDownList_ENGINEER.Text.Equals("請選擇"))
        {
            Response.Write("<script language='javascript'>" + "\n");
            Response.Write("alert('請選擇 值班工程師!!!');");
            Response.Write("</script>");
            return;
        }



        if (DropDownList1_FAB.Text.Equals("請選擇"))
        {
            Response.Write("<script language='javascript'>" + "\n");
            Response.Write("alert('請選擇 FAB!!!');");
            Response.Write("</script>");
            return;
        }

        if (DropDownList_SYSTEM.SelectedValue.Equals("請選擇"))
        {
            Response.Write("<script language='javascript'>" + "\n");
            Response.Write("alert('請選擇 SYSTEM!!!');");
            Response.Write("</script>");
            return;
        }

        if (DropDownList_TYPE.SelectedValue.Equals("請選擇"))
        {
            Response.Write("<script language='javascript'>" + "\n");
            Response.Write("alert('請選擇 TYPE!!! ');");
            Response.Write("</script>");
            return;
        }
        if (DropDownList_PRODUCT_IMPACT.SelectedValue.Equals("請選擇"))
        {
            Response.Write("<script language='javascript'>" + "\n");
            Response.Write("alert('請輸入 生產影響!!! ');");
            Response.Write("</script>");
            return;
        }

        if (TextBox_PRODUCT_IMPACT_INFO.Text.Equals(""))
        {
            Response.Write("<script language='javascript'>" + "\n");
            Response.Write("alert('請輸入 生產影響敘述!!!');");
            Response.Write("</script>");
            return;
        }

        if (TextBox_QUESTION.Text.Equals(""))
        {
            Response.Write("<script language='javascript'>" + "\n");
            Response.Write("alert('請輸入 來電問題!!!');");
            Response.Write("</script>");
            return;
        }

        if (DropDownList_BY_WHOM.SelectedValue.Equals("請選擇"))
        {
            Response.Write("<script language='javascript'>" + "\n");
            Response.Write("alert('請選擇 處理者!!!');");
            Response.Write("</script>");
            return;
        }
        if (TextBox_DESCRIPTION.Text.Equals(""))
        {
            Response.Write("<script language='javascript'>" + "\n");
            Response.Write("alert('請輸入 異常描述!!!');");
            Response.Write("</script>");
            return;
        }

        if (TextBox_REASON.Text.Equals(""))
        {
            Response.Write("<script language='javascript'>" + "\n");
            Response.Write("alert('請輸入 異常原因!!!');");
            Response.Write("</script>");
            return;
        }

        if (TextBox_METHOD.Text.Equals(""))
        {
            Response.Write("<script language='javascript'>" + "\n");
            Response.Write("alert('請輸入 排除方法!!!');");
            Response.Write("</script>");
            return;
        }



        string sql_max_sn = " select max(t.seq)as seq  from onduty t ";

        dsTemp1 = func.get_dataSet_access(sql_max_sn, conn);

        Int32 max_sn = Convert.ToInt32(dsTemp1.Tables[0].Rows[0]["seq"]);

        max_sn++;

        sql = " insert into onduty        " +
              "   (seq,                   " +
              "    calltime,              " +
              "    endtime,               " +
              "    caller,                " +
              "    extension,             " +
              "    engineer,              " +
              "    fab,                   " +
              "    system,                " +
              "    offday,                " +
              "    type,                  " +
              "    cassette,              " +
              "    lot_id,                " +
              "    eq_id,                 " +
              "    question,              " +
              "    bywhom,                " +
              "    description,           " +
              "    insert_time,           " +
              "    close_flag,            " +
              "    mobile,                " +
              "    area,                  " +
              "    starttime,             " +
              "    reason,                " +
              "    method,                " +
              "    assign_owner,          " +
              "    additional_info,       " +
              "    ars_flag,              " +
              "    ars_link,              " +
              "    due_time,              " +
              "    alarm_flag,            " +
              "    product_impact,        " +
              "    org_flag,              " +
              "    product_impact_info,   " +
              "    finaltime,             " +
              "    recharge_flag,         " +
              "    modify_count)          " +
              " values                    " +
              "   (onduty_seq.nextval,                 " +
              "to_date('" + txtEstimateCALLTIME.SelectedDate.Value.ToString("yyyy/MM/dd") + " " + DropDownList1.SelectedValue + ":" + DropDownList2.SelectedValue + "','YYYY/MM/DD HH24:MI'),     " +
              "        to_date('" + txtEstimateEndTime.SelectedDate.Value.ToString("yyyy/MM/dd") + " " + DropDownList5.SelectedValue + ":" + DropDownList6.SelectedValue + "','YYYY/MM/DD HH24:MI'),     " +
              "       '" + TextBox_CALLER.Text.Trim().Replace("'", "''") + "',                           " +
              "        '" + TextBox_EXTENTION.Text.Trim().Replace("'", "''") + "',                     " +
              "        '" + DropDownList_ENGINEER.SelectedValue + "',                       " +
              "      '" + DropDownList1_FAB.SelectedValue + "',                                 " +
              "        '" + DropDownList_SYSTEM.SelectedValue + "',                           " +
              "        '" + RadioButtonList_OFFDAY.SelectedValue + "',                           " +
              "       '" + DropDownList_TYPE.SelectedValue + "',                               " +
              "        '" + TextBox_CASSETTE.Text.Trim().Replace("'", "''") + "',                       " +
              "        '" + TextBox_LOT_ID.Text.Trim().Replace("'", "''") + "',                           " +
              "         '" + TextBox_EQ_ID.Text.Trim().Replace("'", "''") + "',                             " +
              "         '" + TextBox_QUESTION.Text.Trim().Replace("'", "''") + "',                       " +
              "         '" + DropDownList_BY_WHOM.SelectedValue + "',                           " +
              "       '" + TextBox_DESCRIPTION.Text.Trim().Replace("'", "''") + "',                 " +
              "    sysdate,         " +
              "   '" + RadioButtonList_CLOSE_FLAG.SelectedValue + "',                   " +
              "       '" + TextBox_MOBILE.Text.Trim().Replace("'", "''") + "',                           " +
              "      '" + DropDownList_AREA.Text + "',                               " +
              "        to_date('" + txtEstimateSTARTTIME.SelectedDate.Value.ToString("yyyy/MM/dd") + " " + DropDownList3.SelectedValue + ":" + DropDownList4.SelectedValue + "','YYYY/MM/DD HH24:MI'),     " +
              "      '" + TextBox_REASON.Text.Trim().Replace("'", "''") + "',                           " +
              "      '" + TextBox_METHOD.Text.Trim().Replace("'", "''") + "',                           " +
              "      '" + DropDownList_ASSIGN_OWNER.SelectedValue + "',               " +
              "    '" + TextBox_ADDITION_INFO.Text.Trim().Replace("'", "''") + "',         " +
              "     '" + RadioButtonList_ARS_FLAG.SelectedValue + "',                       " +
              "       '" + TextBox_ARS_LINK.Text.Trim().Replace("'", "''") + "',                       " +
              "       round((to_date('" + txtEstimateEndTime.SelectedDate.Value.ToString("yyyy/MM/dd") + " " + DropDownList5.SelectedValue + ":" + DropDownList6.SelectedValue + "','YYYY/MM/DD HH24:MI')-" + "to_date('" + txtEstimateSTARTTIME.SelectedDate.Value.ToString("yyyy/MM/dd") + " " + DropDownList3.SelectedValue + ":" + DropDownList4.SelectedValue + "','YYYY/MM/DD HH24:MI') )*24*60,0) ," +
              "      '" + RadioButtonList_ALARM_FLAG.SelectedValue + "',                   " +
              "     '" + DropDownList_PRODUCT_IMPACT.SelectedValue + "',           " +
              "    '" + RadioButtonList_CLOSE_FLAG.SelectedValue + "',            " +
              "       '" + TextBox_PRODUCT_IMPACT_INFO.Text.Trim().Replace("'", "''") + "', " +
              "    sysdate,           " +
              " '" + RadioButtonList1.SelectedValue + "',             " +
              "    0)        ";

        func.get_sql_execute(sql, conn);

        if (!DropDownList_ASSIGN_OWNER.SelectedValue.Equals("請選擇"))
        {
            call_mail(max_sn.ToString(), DropDownList_ASSIGN_OWNER.SelectedValue);
        }


        #region Add UploadFile


        NetworkDrive oNetDrive1 = new NetworkDrive();
        oNetDrive1.LocalDrive      = "M:";
        oNetDrive1.Persistent      = true;
        oNetDrive1.SaveCredentials = true;
        oNetDrive1.ShareName       = @"\\172.16.12.62\ams";

        try
        {
            oNetDrive1.MapDrive(@"T1FAB\t1eda", "CIMabc123");



            for (int i = 1; i <= Request.Files.Count; i++)
            {
                FileUpload         myFL = new FileUpload();
                ContentPlaceHolder c    = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
                myFL = (FileUpload)c.FindControl("FileUpload" + i);
                //myFL = (FileUpload)Page.FindControl("FileUpload" + i);
                if (myFL.PostedFile.ContentLength < 15360000)
                {
                    if ((myFL.PostedFile != null) && (myFL.PostedFile.ContentLength > 0))
                    {
                        string fn = System.IO.Path.GetFileName(myFL.PostedFile.FileName);
                        // string saveLocation = Server.MapPath("../") + "\\upload_file\\" + fn;
                        //string saveLocation = Server.MapPath("FileList/") + fn;
                        string saveLocation = oNetDrive1.LocalDrive + @"\" + fn;


                        //Session["file_path"] = "FileList/" + fn;
                        int    file_size = myFL.PostedFile.ContentLength;
                        string file_type = myFL.PostedFile.ContentType;
                        try
                        {
                            myFL.PostedFile.SaveAs(saveLocation);

                            //OleDbConnection myConnection = new OleDbConnection(ConfigurationSettings.AppSettings["dsnn"]);

                            //string strClientIP;

                            string strClientIP = Request.ServerVariables["remote_host"].ToString();

                            string sql_insert = @"insert into onduty_file
                                             (seq, file_name, dttm)
                                             values
                                            ('{0}', '{1}', sysdate)";

                            FileHandle cfilehandle = new FileHandle();
                            cfilehandle.GetMaxSeq();
                            //cfilehandle.Seq = Session["seq"].ToString();
                            sql_insert = string.Format(sql_insert, cfilehandle.Seq, fn);

                            func.get_sql_execute(sql_insert, conn);
                        }
                        catch (Exception ex)
                        {
                            Response.Write("上傳檔案失敗");
                        }
                    }
                }

                else
                {
                    //Label3.Visible = true;
                    //Label3.Text = "上傳檔案超過15MB...";
                }
            }
            // Parser_tmp_directory_file(oNetDrive.LocalDrive + "\\T1\\" + DropDownList1.SelectedValue.ToString() + "\\EDANG\\", "*.TXT", -360);
            // Delete_tmp_directory_file(HttpContext.Current.Server.MapPath(".") + "\\File\\", "*", -3);


            oNetDrive1.UnMapDrive(oNetDrive1.LocalDrive, true);
        }
        catch (Exception)
        {
            oNetDrive1.UnMapDrive(oNetDrive1.LocalDrive, true);
        }
        finally
        {
            //oNetDrive.UnMapDrive();
        }


        //oNetDrive.MapDrive(@"T1FAB\t1eda", "CIMabc123");

        #endregion
        Response.Write("<script language='javascript' type='text/JavaScript'>\n");
        Response.Write("alert('新增成功!!');\n");
        Response.Write("location = 'onduty_query.aspx';\n");
        //Response.Write("setTimeout(\"window.opener=null; window.close();\",null)");
        Response.Write("</script>");
        //Response.Write("<script language=\"javascript\">setTimeout(\"window.opener=null; window.close();\",null)</script>");

        //Response.Redirect("onduty_add.aspx");

        //Page_Load(null, null);
    }