Hello
My code working well saves data into sql perfect
The problem when i add export to pdf code
1- Insert data not display in GridView
2- The code duplicates not working, it’s like silent
protected void Insert2(object sender, EventArgs e)
{
if (txtUsername.Text == String.Empty)
{
ClientScript.RegisterStartupScript(this.GetType(), "randomtext", " alertmecheck()", true);
}
else if (ddlCountries.SelectedItem.Text == String.Empty)
{
ClientScript.RegisterStartupScript(this.GetType(), "randomtext", " alertmecheck1()", true);
}
else if (ddlStates.SelectedItem.Text == String.Empty)
{
ClientScript.RegisterStartupScript(this.GetType(), "randomtext", " alertmecheck2()", true);
}
else if (ddlCities.SelectedItem.Text == String.Empty)
{
ClientScript.RegisterStartupScript(this.GetType(), "randomtext", " alertmecheck3()", true);
}
else
{
ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/repotfolder/ReportVback.rdlc");
ReportParameter[] param = new ReportParameter[13];
param[0] = new ReportParameter("Reportbackname", txtUsername.Text);
param[1] = new ReportParameter("Reportbackjoptitil", joptitel.Text);
param[3] = new ReportParameter("Reportbackeldarajah", eldarajah.Text);
param[4] = new ReportParameter("Reportbackfileid", filenumber.Text);
param[5] = new ReportParameter("Reportbackcivilid", civilid.Text);
param[6] = new ReportParameter("Reportbackdatestart", txtBoxDate8.Text);
param[7] = new ReportParameter("Reportbackdateend", txtBoxDate10.Text);
param[8] = new ReportParameter("Reportbackdateorderfromstart", txtBoxDate7.Text);
param[11] = new ReportParameter("Reportbackdateorderfromback1", txtBoxDate11.Text);
param[9] = new ReportParameter("Reportbackvacationback", ddlPC.Text);
param[10] = new ReportParameter("Reportbacknote", textmsg.Text);
param[2] = new ReportParameter("Reportbackqsem", ddlCities.SelectedItem.Text);
param[12] = new ReportParameter("ReportbackStates", ddlStates.SelectedItem.Text);
ReportViewer1.LocalReport.SetParameters(param);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.Refresh();
int recordsInserted = 0;
string sql = "IF NOT EXISTS(SELECT * FROM Table_vacation WHERE idnamev = @idnamev and idcivilv = @idcivilv and datestart = @datestart and dateend = @dateend) ";
sql += "BEGIN ";
sql += "insert into Table_vacation (note,vacationdataback,States,idnamev,jop,eldarajah,el3malv,datesp10,idcivilv,datestart,dateend,vacationdata,totalva,infovacation,namevacation,iPAddress,dataaddtime,edit) VALUES (@note,@vacationdataback,@States,@idnamev,@jop,@eldarajah,@el3malv,@datesp10,@idcivilv,@datestart,@dateend,@vacationdata,@totalva,@infovacation,@namevacation,@iPAddress,@dataaddtime,@edit) ";
sql += "END";
string usernamemove = this.Page.User.Identity.Name;
string constr = ConfigurationManager.ConnectionStrings["cmConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(sql))
{
cmd.Connection = con;
cmd.Parameters.AddWithValue("@idnamev", txtUsername.Text);
cmd.Parameters.AddWithValue("@jop", joptitel.Text);
cmd.Parameters.AddWithValue("@eldarajah", eldarajah.Text);
cmd.Parameters.AddWithValue("@el3malv", ddlCities.SelectedItem.Text);
cmd.Parameters.AddWithValue("@datesp10", filenumber.Text);
cmd.Parameters.AddWithValue("@idcivilv", civilid.Text);
cmd.Parameters.AddWithValue("@datestart", txtBoxDate8.Text);
cmd.Parameters.AddWithValue("@dateend", txtBoxDate10.Text);
cmd.Parameters.AddWithValue("@vacationdata", txtBoxDate7.Text);
cmd.Parameters.AddWithValue("@vacationdataback", txtBoxDate11.Text);
cmd.Parameters.AddWithValue("@totalva", lblLabel2.Text);
cmd.Parameters.AddWithValue("@infovacation", ddlPC.Text);
cmd.Parameters.AddWithValue("@namevacation", "اقرار عودة");
cmd.Parameters.AddWithValue("@States", ddlStates.SelectedItem.Text);
cmd.Parameters.AddWithValue("@iPAddress", usernamemove);
cmd.Parameters.AddWithValue("@dataaddtime", Convert.ToDateTime(DateTime.Now.ToLongTimeString()));
cmd.Parameters.AddWithValue("@edit", "(جديد)");
cmd.Parameters.AddWithValue("@note", textmsg.Text);
cmd.Connection = con;
con.Open();
recordsInserted = cmd.ExecuteNonQuery();
this.BindGridView();
con.Close();
}
}
if (recordsInserted == -1)
{
ClientScript.RegisterStartupScript(this.GetType(), "randomtext", " duplicate()", true);
}
//insert date vacation into user data start date vacation to end date vacation
using (con = new SqlConnection(constr))
{
string query = "UPDATE Table_infoname SET DateTimePicker1 = @DateTimePicker1,DateTimePicker2 = @DateTimePicker2 WHERE civilid = @Civilid";
using (cmd = new SqlCommand(query))
{
cmd.Connection = con;
cmd.Parameters.AddWithValue("@civilid", civilid.Text.ToString());
cmd.Parameters.AddWithValue("@DateTimePicker1", txtBoxDate8.Text.ToString());
cmd.Parameters.AddWithValue("@DateTimePicker2", txtBoxDate10.Text.ToString());
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
Warning[] warnings;
string[] streamIds;
string contentType;
string encoding;
string extension;
//Export the RDLC Report to Byte Array.
byte[] bytes = ReportViewer1.LocalReport.Render(rbFormat.SelectedItem.Value, null, out contentType, out encoding, out extension, out streamIds, out warnings);
//Download the RDLC Report in Word, Excel, PDF and Image formats.
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = contentType;
Response.AppendHeader("Content-Disposition", "attachment; filename=اقرار عودة - " + DateTime.Now.ToString("dd/MM/yyy - ") + txtUsername.Text + "." + extension);
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
}
}