Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a strange problem in asp . net that couldn't find any solution over internet. i have a page that print a Letter for user and insert the info of user in DB. i put the code in the bottom. when user click insert button it write-in the data to Db then create a pdf file for downloading and send to client. but if user download it with browser, everything going well but if download with internet download manager(i test with IDM) the insert in DB Method Repeat for 2-3 or 4 times. can you HELP me?!!!

C#
protected void VacationInserted()
    {
        R1.Load(Server.MapPath("~/App_Data/Report.mrt"));
        ATA.Fill(ADT, User.Identity.Name);
        R1.Dictionary.Variables["Automobile"].Value = ADT.Rows[0]["Model"].ToString();
        R1.Dictionary.Variables["No"].Value = ADT.Rows[0]["No_"].ToString();
        UTA.Fill(UDT, User.Identity.Name);

        R1.Dictionary.Variables["Name"].Value = UDT.Rows[0]["FirstName"].ToString() + " " + UDT.Rows[0]["LastName"].ToString();
        R1.Dictionary.Variables["StartDate"].Value = StartVacationDate.Text;
        R1.Dictionary.Variables["EndDate"].Value = EndVacationDate.Text;
        R1.Dictionary.Variables["Period"].Value = Diff.ToString();
        R1.Dictionary.Variables["Destination"].Value = TxtDestination.Text;
        R1.Dictionary.Variables["LetterNumber"].Value = LDT.Rows[0]["LetterNumber"].ToString();
        R1.Dictionary.Variables["InsertDate"].Value = Converter.Today();
        LTA.Update((((double)LDT.Rows[0]["LetterNumber"]) + 0.01), ((int)LDT.Rows[0]["LetterCount"]) + 1);
        Update_VacRemain();
        if (PrintSelect.SelectedValue == "pdf")
        {
            pdfexport();
        }
    }


    protected void pdfexport()
    {

        MemoryStream ms = new MemoryStream();
        R1.Render();
        Stimulsoft.Report.Export.StiBitmapExportSettings s = new Stimulsoft.Report.Export.StiBitmapExportSettings();
        Stimulsoft.Report.Export.StiPdfExportSettings s1 = new Stimulsoft.Report.Export.StiPdfExportSettings();
        Stimulsoft.Report.Export.StiPdfExportService pdfservice = new Stimulsoft.Report.Export.StiPdfExportService();
        s1.Compressed = true;
        s1.EmbeddedFonts = true;
        s1.ImageCompressionMethod = Stimulsoft.Report.Export.StiPdfImageCompressionMethod.Jpeg;
        s1.ImageQuality = 100;
        s1.SubjectNameString = "Vacation";
        pdfservice.ExportPdf(R1, ms, s1);

        Response.ClearContent();
        Response.ClearHeaders();
        Response.Buffer = true;
        Response.ContentType = "Application/PDF";
        Response.AddHeader("Content-Disposition", "attachment;filename=Print_Vac.pdf");

        ms.Position = 0;
        ms.WriteTo(Response.OutputStream);
        ms.Dispose();


        //// I test this three line in bottom and without them but don't change anything
        Page.Response.End();
        //Response.End();
        //Response.Flush();
    }

    protected void InsertVacation_Click(object sender, EventArgs e)
    {
        LTA.Fill(LDT);
        Start = (DateTime)StartVacationDate.DateValue;
        End = (DateTime)EndVacationDate.DateValue;
        Diff = ((End - Start).TotalDays) + 1;
        TextBox Txt_VacRemainder = (TextBox)DetailsView2.FindControl("Txt_VacRemainder");
        Remain = Convert.ToInt32(Txt_VacRemainder.Text) - Convert.ToInt32(Diff);
        if (Remain < 0)
        {
            Page.ClientScript.RegisterStartupScript(GetType(), "hwa", "a()", true);
        }
        else
        {
            if (Diff < 0)
            {
                Page.ClientScript.RegisterStartupScript(GetType(), "hwa", "alert('...');", true);
            }
            else
            {
                NationalNumber = User.Identity.Name;
                InsertDate = DateTime.Now;
                LetterNumber = Math.Round(float.Parse(LDT.Rows[0]["LetterNumber"].ToString()), 2).ToString();
                VTA.Insert(NationalNumber, InsertDate, Start, End, Remain, true, TxtDestination.Text, Math.Round(float.Parse(LDT.Rows[0]["LetterNumber"].ToString()), 2));
                VacationInserted();
                //TxtDestination.Text = "";
                //Page.ClientScript.RegisterStartupScript(GetType(), "hwa", "alert('...');", true);
            }
        }
    }
Posted

Hi,
I think your code / event is getting called / triggered multiple times due to download manager (it could be any download manager). You can check for duplicate entry and if entry exists, then just allow downloading PDF file.
 
Share this answer
 
Comments
MohammadAmin94 10-Nov-13 4:41am    
thanks for answer,my friend;
but can explanation more.
if you could put code snippet here...
thanks again!
thanks for answer,my friend;
but can explanation more.
if you could put code snippet here...
thanks again!
 
Share this answer
 
Comments
Prashant. B. Chavan 11-Nov-13 12:28pm    
I meant check for combination of values exists in database table

objDatabatable = Select <primary Key> from table where <here your="" conditions="" will="" come="">

If objDatabatable.rows.count > 0
//it means duplicate record
//then only export pdf for <primary Key>
Else
//Insert data into database

This is temporary solution, which you can try till the time you get proper solution for you problem.
I have same problem with my project that the idm download 3 or more times from my app and I will have to fix it because we want download limitation count for our customers
can anybody help ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900