using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using System.Collections.Generic;
public partial class _123 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void RadioButtonList1_SelectedIndexChanged1(object sender, EventArgs e)
{
if (RadioButtonList1.SelectedValue == "1")
{
lblcontact.Visible = true;
lblcontact.Text = "Seller Info";
DropDownList1.Enabled = true;
DropDownList2.Enabled = true;
txttitle.Enabled = true;
txtdesc.Enabled = true;
txtaprox.Enabled = true;
FuUpload.Enabled = true;
txtemail.Enabled = true;
txtfloor.Enabled = true;
txtno.Enabled = true;
txtdept.Enabled = true;
txtcontact.Enabled = true;
}
else
{
lblcontact.Visible = true;
lblcontact.Text = "Contact Info Of Buyer";
DropDownList1.Enabled = true;
DropDownList2.Enabled = true;
txttitle.Enabled = true;
txtdesc.Enabled = true;
txtaprox.Enabled = true;
FuUpload.Enabled = false;
txtemail.Enabled = true;
txtfloor.Enabled = true;
txtno.Enabled = true;
txtdept.Enabled = true;
txtcontact.Enabled = true;
}
}
protected void btnsave_Click1(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=D:\\site\\temporary\\App_Data\\Database.mdf;Integrated Security=True;User Instance=True");
SqlCommand cmd = new SqlCommand();
con.Open();
cmd.Connection = con;
if (RadioButtonList1.SelectedValue == "1")
{
if (FuUpload.HasFile)
{
if ((FuUpload.PostedFile.ContentType == "image/jpeg") ||
(FuUpload.PostedFile.ContentType == "image/png") ||
(FuUpload.PostedFile.ContentType == "image/gif"))
{
if (Convert.ToInt64(FuUpload.PostedFile.ContentLength) < 1500000)
{
string date = DateTime.Now.ToString();
string extension = Path.GetExtension(FuUpload.FileName);
string uniquefilename = Path.ChangeExtension(FuUpload.FileName, DateTime.Now.Ticks.ToString());
FuUpload.SaveAs(Server.MapPath("Images/" + uniquefilename + extension));
cmd.CommandText = "Insert into post_ad (Category,Sub_Category,Title,Description,Approx_Price,Contact_Name,Email,Phone_Number,Department,Floor,Photos,Buy_Sell_Id,date)values('" + DropDownList1.SelectedValue + "','" + DropDownList2.SelectedValue + "','" + txttitle.Text + "','" + txtdesc.Text + "','" + txtaprox.Text + "','" + txtcontact.Text + "', '" + txtemail.Text + "','" + txtno.Text + "','" + txtdept.Text + "','" + txtfloor.Text + "','"+ "Images/" + uniquefilename + extension + "','" + RadioButtonList1.SelectedValue + "','" + date + "')";
cmd.Parameters.AddWithValue("@ImagePath", "Images/" + uniquefilename);
int i = cmd.ExecuteNonQuery();
if (i > 0)
{
Label2.Visible = true;
Label2.Text = "Data Saved Successfully";
btnsave.Text = "Saved";
}
else
{
Label2.Visible = true;
Label2.Text = "Data not Saved";
}
}
else
{
Label2.Visible = true;
Label2.Text = "file must be less than 5 mb";
}
}
}
}
}
}
}