0

ページ スクリプトは引き続き実行されますが、以下で説明するように、「リクエストが正常に送信されました」というメッセージは表示されません。ここで私が欠けているものを誰か助けてもらえますか?

protected void Button1_Click1(object sender, EventArgs e)
{
    string constring = System.Configuration.ConfigurationManager.ConnectionStrings["GerpConnStr"].ConnectionString;
    SqlConnection con = new SqlConnection(constring);
    string name = System.Web.HttpContext.Current.User.Identity.Name;  
    string domain = name.Substring(+13);
    try
    {
        con.Open();
        SqlCommand cmd = con.CreateCommand();
        SqlCommand cmd1 = new SqlCommand("SELECT max(ID) as maxReq FROM request", con);
        cmd1.CommandType = CommandType.Text;
        int result = ((int)cmd1.ExecuteScalar());
        int req = result + 1;
        if (FileUpload1.HasFile)
        {
            string extension1 = Path.GetExtension(FileUpload1.PostedFile.FileName);
            string attachment = (FileUpload1.FileName + '_' + req + extension1);
            cmd.CommandType = CommandType.Text;
            string dt2 = DateTime.Now.ToString("yyyyMMddHHmmss");
            DateTime time = DateTime.Now;
            cmd.CommandText = "insert into request (request_type,request_area,subject,description,requestor,req_status,attachment,request_time) values('" + DropDownList1.SelectedValue + "','" + DropDownList2.SelectedValue + "','" + TextBox1.Text + "','" + TextArea1.InnerText + "','" + Label3.Text + "','" + "Open" + "','" + attachment + "','" + time + "')";

            string saveDir = @"\upload\" + Server.HtmlEncode(FileUpload1.FileName);          
            string dt = DateTime.Now.ToString("MM_dd_yyyy_hh_mm_ss") + "_";
            string appPath = Request.PhysicalApplicationPath;
            string extension = Path.GetExtension(FileUpload1.PostedFile.FileName);
            string savePath = appPath + saveDir +
            Server.HtmlEncode(FileUpload1.FileName);
            string saveSess = saveDir + dt +
            Server.HtmlEncode(FileUpload1.FileName);
            FileUpload1.SaveAs(saveDir + '_' + req + extension);
            // Label4.Text = "Your request has been submitted successfully";
            string message = "Your request has been submitted successfully";
            string script = "window.onload = function(){ alert('";
            script += message;
            script += "');";
            script += "window.location = '";
            script += Request.Url.AbsoluteUri;
            script += "'; }";
            ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true);
            Session["sessimage1"] = saveSess;

             //   CreateMailItem();
        } //if
        else
        {

            // string extension1 = Path.GetExtension(FileUpload1.PostedFile.FileName);
            // string attachment = (FileUpload1.FileName + '_' + req + extension1);
            // SqlCommand cmd1 = con.CreateCommand();
            cmd.CommandType = CommandType.Text;
            DateTime time = DateTime.Now;
            // string dt1 = DateTime.Now.ToString("yyyyMMddHHmmss");
            cmd.CommandText = "insert into request (request_type,request_area,subject,description,requestor,req_status,request_time) values('" + DropDownList1.SelectedValue + "','" + DropDownList2.SelectedValue + "','" + TextBox1.Text + "','" + TextArea1.InnerText + "','" + Label3.Text + "','" + "Open" + "','" + time + "')";
            // Label4.Text = "Your request has been submitted successfully";               
            string message = "Your request has been submitted successfully";
            string script = "window.onload = function(){ alert('";
            script += message;
            script += "');";
            script += "window.location = '";
            script += Request.Url.AbsoluteUri;
            script += "'; }";
            ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true);
            //  Response.Redirect(Request.Url.AbsoluteUri);

            // EmptyTextBoxes(TextBox1.Text);
            // this.Controls.Clear();
            // this.InitializeComponent();

        } //else

        //  SaveFile(FileUpload1.PostedFile);
        cmd.ExecuteNonQuery();
        cmd1.ExecuteNonQuery();
        con.Close();           
    } //try
    catch
    {
        Console.WriteLine("Insert failed");
        Console.Read();
    }
    finally
    {
        con.Close();
    }
    CreateMailItem();
} //button1
4

1 に答える 1

0

その解決しました。CreateMailItem() の Console.Read() でエラーが発生していました。そのため、送信成功のメッセージを送信するために Button1_Click1(オブジェクト送信者、EventArgs e) に戻ることはありませんでした。Console.Read() を省略したので、CreateMailItem() の実行が完了し、制御が Button1_Click1(オブジェクト送信者、EventArgs e) に戻って送信成功のメッセージが投稿されます。

更新部分:

catch { Console.WriteLine("挿入に失敗しました"); //Console.Read();

            }
于 2016-12-15T02:12:39.963 に答える