protected void HomeSliderUploadBtn_Click(object sender, EventArgs e) { if (HomeSliderImageUpload.HasFile) { try { string filename = Path.GetFileName(HomeSliderImageUpload.FileName); string query = "Insert Into FileList(FileName) Values('" + filename + "') Select SCOPE_IDENTITY()"; string query2 = "Select count(*) From FileList Where FileName = '" + filename + "'"; string query3 = "Select count(*) From FileList Where FileName = '" + filename + "' And RecordState = 1"; SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLConnectionString"].ConnectionString); sqlConnection.Open(); SqlCommand cmd = new SqlCommand(query2, sqlConnection); int count = Convert.ToInt32(cmd.ExecuteScalar()); if (count > 0) { SqlCommand cmd1 = new SqlCommand(query3, sqlConnection); int count1 = Convert.ToInt32(cmd1.ExecuteScalar()); if (count1 > 0) { LabelUploadState.Visible = true; LabelUploadState.Text = "This Image Has Been Exist..!"; } else { Util.ExecuteQuery("Update FileList Set RecordState = 1 Where FileName = '" + filename + "'"); HomeSliderImageUpload.SaveAs(Server.MapPath("~/Images/home_slider/") + filename); LabelUploadState.Visible = true; LabelUploadState.Text = "Upload status: File uploaded!"; } } else { HomeSliderImageUpload.SaveAs(Server.MapPath("~/Images/home_slider/") + filename); /*---------------------------------Start Store file name into database-----------------------------------*/ SqlCommand cmd2 = new SqlCommand(query, sqlConnection); SqlDataReader reader2 = cmd2.ExecuteReader(); reader2.Read(); int FileListID = Convert.ToInt32(reader2[0]); reader2.Close(); string query1 = "Select SectionListID From SectionList Where SectionName = 'Home_Slider'"; SqlCommand cmd3 = new SqlCommand(query1, sqlConnection); SqlDataReader reader3 = cmd3.ExecuteReader(); reader3.Read(); string SectionListID = reader3[0].ToString(); Util.ExecuteQuery("Insert into File_SectionList Values('" + FileListID + "','" + SectionListID + "')"); Util.ExecuteQuery("Insert into FileCaptionList (FileListID) Values('" + FileListID + "')"); Util.ExecuteQuery("Insert into File_SliderOrderList (FileListID) Values('" + FileListID + "')"); reader3.Close(); sqlConnection.Close(); /*---------------------------------End Store file name into database-----------------------------------*/ LabelUploadState.Visible = true; LabelUploadState.Text = "Upload status: File uploaded!"; } RefreshDropDownList(); } catch (Exception ex) { LabelUploadState.Visible = true; LabelUploadState.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message; } } else { LabelUploadState.Visible = true; LabelUploadState.Text = "Failed"; } }
protected void HomeSectionUploadBtn_Click(object sender, EventArgs e) { AutoDeleteExistImage(); if (HomeSectionImg.HasFile) { try { string filename = Path.GetFileName(HomeSectionImg.FileName); string query = "update FileList set RecordState = 0 From FileList Inner Join File_SectionList on FileList.FileListID = File_SectionList.FileListID Where File_SectionList.SectionListID = " + ddlHomeSectionNumber.SelectedValue; string query1 = "Insert Into FileList(filename) Values('" + filename + "') Select SCOPE_IDENTITY()"; string query2 = "Select count(*) From FileList Where FileName = '" + filename + "'"; string query3 = "Select count(*) From FileList Where FileName = '" + filename + "' And RecordState = 1"; SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLConnectionString"].ConnectionString); sqlConnection.Open(); SqlCommand cmdClear = new SqlCommand(query, sqlConnection); cmdClear.ExecuteNonQuery(); SqlCommand cmd = new SqlCommand(query2, sqlConnection); int count = Convert.ToInt32(cmd.ExecuteScalar()); if (count > 0) { SqlCommand cmd1 = new SqlCommand(query3, sqlConnection); int count1 = Convert.ToInt32(cmd1.ExecuteScalar()); if (count1 > 0) { LabelUploadState1.Visible = true; LabelUploadState1.Text = "This Image Name Has Been Exist..!"; } else { Util.ExecuteQuery("Update FileList Set RecordState = 1 Where FileName = '" + filename + "'"); HomeSliderImageUpload.SaveAs(Server.MapPath("~/Images/home_section/") + filename); LabelUploadState1.Visible = true; LabelUploadState1.Text = "Upload status: File uploaded!"; } } else { HomeSectionImg.SaveAs(Server.MapPath("~/Images/home_section/") + filename); /*---------------------------------Start Store file name into database-----------------------------------*/ SqlCommand cmd2 = new SqlCommand(query1, sqlConnection); SqlDataReader reader2 = cmd2.ExecuteReader(); reader2.Read(); int FileListID = Convert.ToInt32(reader2[0]); reader2.Close(); Util.ExecuteQuery("Insert into File_SectionList Values('" + FileListID + "','" + ddlHomeSectionNumber.SelectedValue + "')"); sqlConnection.Close(); /*---------------------------------End Store file name into database-----------------------------------*/ LabelUploadState1.Visible = true; LabelUploadState1.Text = "Upload status: File uploaded!"; } } catch (Exception ex) { LabelUploadState1.Visible = true; LabelUploadState1.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message; } } else { LabelUploadState1.Visible = true; LabelUploadState1.Text = "Failed"; } }