Click here to Skip to main content
15,922,533 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
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)
    {

        //if (Session["XyzUserAuthentication"] == null)
        //{
        //    Response.Redirect("login.aspx");
        //}

    }


C#
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;
    }
}


C#
        protected void btnsave_Click1(object sender, EventArgs e)
        {


            //SqlConnection con = new SqlConnection("Server=traning-pc9;Database=samsung;Integrated Security=True;");
            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 photofolder = Path.Combine(@"D:\site\temporary\Images", User.Identity.Name);
                            string extension = Path.GetExtension(FuUpload.FileName);
                            string uniquefilename = Path.ChangeExtension(FuUpload.FileName, DateTime.Now.Ticks.ToString());
                            //string filename = Path.GetFileName(FuUpload.PostedFile.FileName);
                            FuUpload.SaveAs(Server.MapPath("Images/" + uniquefilename + extension));
                            //FuUpload.SaveAs(Path.Combine(uniquefilename + extension));
                            //FuUpload.SaveAs(Server.MapPath("Images/" + UniqueID +filename));
                            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";


                         }


                        }

                    }
                }
}
}
}
Posted
Updated 4-Aug-13 18:34pm
v2
Comments
[no name] 5-Aug-13 0:34am    
What is the problem you are facing....??
Harshit Wadhera 5-Aug-13 1:16am    
i just want to save the date which should expire after 1 month or 2 month according to the user which post the data. And data should not display after expire.
[no name] 5-Aug-13 1:19am    
expire data means what..??do you want to delete it permanently from database..??
Harshit Wadhera 5-Aug-13 1:21am    
not delete but it should not display after 1 or 2 month

1 solution

Hi,

Below is my suggestion to achieve your functionality :

When you insert data into database, provide date and time of the inserted data and using service or specific action (like page load) you can check is there any data inserted 1 or 2 month ago ?

If you found any data than set the flag of that data ("IsExpired") to true.

And when you retrieve data from the database to display it to the user, retrieve only those data which are having "Isexpired" flag to false.

Below is the database design look like :

Table : MyData

Id | Name | Email | CreatedDate | IsExpired
1 | aaa | a@a.com | 2013-05-05 11:16:26.240 | 0
2 | bbb | b@b.com | 2013-05-10 15:16:26.240 | 1
3 | ccc | c@c.com | 2013-05-07 11:16:26.240 | 1
3 | ddd | d@d.com | 2013-05-08 11:16:26.240 | 0
 
Share this answer
 
v2
Comments
ArunRajendra 5-Aug-13 2:28am    
I guess this solution may not work as expiry is not fixed it can 1 month or 2 month. And there is a performance issue as each time all the records has to be checked.
CodeBlack 5-Aug-13 2:49am    
thats true. it will cause performance issue. So instead of that we can run background thread as well :) . And If expiry is not fixed than you will have to update sql or linq query based on the expiry conditions.

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