Esempio n. 1
0
        protected void btnadd_Click(object sender, EventArgs e)
        {
            List <int> noofrows = new List <int>();
            int        rows     = 10;

            int.TryParse(txtnofrows.Text.Trim(), out rows);

            for (int i = 0; i < rows; i++)
            {
                noofrows.Add(i);
            }
            GridViewlisting.DataSource = noofrows;
            GridViewlisting.DataBind();
        }
Esempio n. 2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                ////////Load Data Into Master Table Store
                string storename   = txtstorename.Text;
                string yourname    = txtname.Text;
                string contactno   = txtcontact.Text;
                string email       = txtemail.Text;
                string sociallink1 = txtsociallink1.Text;
                string sociallink2 = txtsociallink2.Text;
                string address     = txtaddress.Text;
                string state       = ddlstate.SelectedItem.ToString();
                string city        = ddlcity.SelectedItem.ToString();
                string area        = txtarea.Text;
                string town        = txttown.Text;
                string country     = txtcountry.Text;
                long   zipcode     = long.Parse(txtzipcode.Text);
                string description = txtstoredescription.Text;

                con.Open();
                SqlCommand cmd0 = new SqlCommand(@"INSERT INTO Storemaster(Storename,Yourname,Contactno,Email,Sociallink1,Sociallink2,Address,State,City,Area,Town,Country,Zipcode,Description,ListingPriority,Package) values('" + storename + "','" + yourname + "','" + contactno + "','" + email + "','" + sociallink1 + "','" + sociallink2 + "','" + address + "','" + state + "','" + city + "','" + area + "','" + town + "','" + country + "','" + zipcode + "','" + description + "','low','Free');", con);
                cmd0.ExecuteNonQuery();

                SqlCommand cmd1 = new SqlCommand("Select MAX(StoreId) from Storemaster;", con);
                cmd1.ExecuteNonQuery();


                SqlDataReader dr0 = cmd1.ExecuteReader();
                while (dr0.Read())   // This is how record is read. Loop through the each record
                {
                    var storeid = long.Parse(dr0[0].ToString());
                    lblstoreid.Text = storeid.ToString();
                }
                dr0.Close();

                int Store_id = int.Parse(lblstoreid.Text.ToString());

                foreach (GridViewRow g1 in GridViewlisting.Rows)
                {
                    int        StoreId         = Store_id;
                    string     productname     = (g1.FindControl("txtprodname") as TextBox).Text;
                    string     productcategory = (g1.FindControl("txtprodcategory") as TextBox).Text;
                    decimal    productprice    = decimal.Parse((g1.FindControl("txtprodprice") as TextBox).Text);
                    FileUpload fuploadFile     = (FileUpload)g1.FindControl("FUproductimage");


                    //string Description = (g1.FindControl("lblDescription") as TextBox).Text;
                    if (fuploadFile.HasFile)
                    {
                        FileInfo fi              = new FileInfo(fuploadFile.FileName);
                        string   name            = fi.Name;
                        byte[]   documentcontent = fuploadFile.FileBytes;

                        SqlCommand com = new SqlCommand("Insert into Storeproducts (StoreId,Productname,Productcategory,Productprice,Productimage) values (@StoreId,@Productname,@Productcategory,@Productprice,@Productimage)", con);
                        com.Parameters.AddWithValue("@StoreId", SqlDbType.Int).Value             = StoreId;
                        com.Parameters.AddWithValue("@Productname", SqlDbType.VarChar).Value     = productname;
                        com.Parameters.AddWithValue("@Productcategory", SqlDbType.VarChar).Value = productcategory;
                        com.Parameters.AddWithValue("@Productprice", SqlDbType.Decimal).Value    = productprice;
                        com.Parameters.AddWithValue("@Productimage", SqlDbType.VarBinary).Value  = documentcontent;
                        com.ExecuteNonQuery();
                    }
                }

                if (imageupload1.HasFile && imageupload2.HasFile && imageupload3.HasFile)
                {
                    FileInfo fi1    = new FileInfo(imageupload1.FileName);
                    string   name1  = fi1.Name;
                    byte[]   image1 = imageupload1.FileBytes;

                    FileInfo fi2    = new FileInfo(imageupload2.FileName);
                    string   name2  = fi2.Name;
                    byte[]   image2 = imageupload2.FileBytes;

                    FileInfo fi3    = new FileInfo(imageupload3.FileName);
                    string   name3  = fi3.Name;
                    byte[]   image3 = imageupload3.FileBytes;

                    SqlCommand com = new SqlCommand("Insert into StoreImages (StoreId,Image1,Image2,Image3) values (@StoreId,@Image1,@Image2,@Image3)", con);
                    com.Parameters.AddWithValue("@StoreId", SqlDbType.VarChar).Value  = Store_id;
                    com.Parameters.AddWithValue("@Image1", SqlDbType.VarBinary).Value = image1;
                    com.Parameters.AddWithValue("@Image2", SqlDbType.VarBinary).Value = image2;
                    com.Parameters.AddWithValue("@Image3", SqlDbType.VarBinary).Value = image3;
                    com.ExecuteNonQuery();
                }

                else if (imageupload1.HasFile && !imageupload2.HasFile && !imageupload3.HasFile)
                {
                    FileInfo fi1    = new FileInfo(imageupload1.FileName);
                    string   name1  = fi1.Name;
                    byte[]   image1 = imageupload1.FileBytes;


                    SqlCommand com = new SqlCommand("Insert into StoreImages (StoreId,Image1 ) values (@StoreId,@Image1)", con);
                    com.Parameters.AddWithValue("@StoreId", SqlDbType.VarChar).Value  = Store_id;
                    com.Parameters.AddWithValue("@Image1", SqlDbType.VarBinary).Value = image1;
                    com.ExecuteNonQuery();
                }
                else if (!imageupload1.HasFile && imageupload2.HasFile && !imageupload3.HasFile)
                {
                    FileInfo fi2    = new FileInfo(imageupload2.FileName);
                    string   name2  = fi2.Name;
                    byte[]   image2 = imageupload2.FileBytes;



                    SqlCommand com = new SqlCommand("Insert into StoreImages (StoreId, Image2) values (@StoreId, @Image2)", con);
                    com.Parameters.AddWithValue("@StoreId", SqlDbType.VarChar).Value  = Store_id;
                    com.Parameters.AddWithValue("@Image2", SqlDbType.VarBinary).Value = image2;

                    com.ExecuteNonQuery();
                }
                else if (!imageupload1.HasFile && !imageupload2.HasFile && imageupload3.HasFile)
                {
                    FileInfo fi3    = new FileInfo(imageupload3.FileName);
                    string   name3  = fi3.Name;
                    byte[]   image3 = imageupload3.FileBytes;

                    SqlCommand com = new SqlCommand("Insert into StoreImages (StoreId,Image3) values (@StoreId,@Image3)", con);
                    com.Parameters.AddWithValue("@StoreId", SqlDbType.VarChar).Value  = Store_id;
                    com.Parameters.AddWithValue("@Image3", SqlDbType.VarBinary).Value = image3;
                    com.ExecuteNonQuery();
                }
                else if (imageupload1.HasFile && !imageupload2.HasFile && !imageupload3.HasFile)
                {
                    FileInfo fi1    = new FileInfo(imageupload1.FileName);
                    string   name1  = fi1.Name;
                    byte[]   image1 = imageupload1.FileBytes;


                    SqlCommand com = new SqlCommand("Insert into StoreImages (StoreId,Image1) values (@StoreId,@Image1)", con);
                    com.Parameters.AddWithValue("@StoreId", SqlDbType.VarChar).Value  = Store_id;
                    com.Parameters.AddWithValue("@Image1", SqlDbType.VarBinary).Value = image1;

                    com.ExecuteNonQuery();
                }

                else if (imageupload1.HasFile && imageupload2.HasFile && !imageupload3.HasFile)
                {
                    FileInfo fi1    = new FileInfo(imageupload1.FileName);
                    string   name1  = fi1.Name;
                    byte[]   image1 = imageupload1.FileBytes;

                    FileInfo fi2    = new FileInfo(imageupload2.FileName);
                    string   name2  = fi2.Name;
                    byte[]   image2 = imageupload2.FileBytes;



                    SqlCommand com = new SqlCommand("Insert into StoreImages (StoreId,Image1,Image2) values (@StoreId,@Image1,@Image2)", con);
                    com.Parameters.AddWithValue("@StoreId", SqlDbType.VarChar).Value  = Store_id;
                    com.Parameters.AddWithValue("@Image1", SqlDbType.VarBinary).Value = image1;
                    com.Parameters.AddWithValue("@Image2", SqlDbType.VarBinary).Value = image2;
                    com.ExecuteNonQuery();
                }
                con.Close();
                string display = "Store Added Successfully!";
                ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + display + "');", true);

                txtstorename.Text   = "";
                txtname.Text        = "";
                txtcontact.Text     = "";
                txtemail.Text       = "";
                txtsociallink1.Text = "";
                txtsociallink2.Text = "";
                txtaddress.Text     = "";
                ddlstate.ClearSelection();
                ddlcity.ClearSelection();
                txtarea.Text             = "";
                txttown.Text             = "";
                txtzipcode.Text          = "";
                txtstoredescription.Text = "";
                txtnofrows.Text          = "";

                DataTable ds = new DataTable();
                ds = null;
                GridViewlisting.DataSource = ds;
                GridViewlisting.DataBind();
            }
            catch (Exception ex)
            {
                string display1 = ex.Message;
                ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + display1 + "');", true);
            }



            //string display = "Coaching Class Added Successfully!";
            //ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + display + "');", true);


            //txtinstitutename.Text = "";
            //txtname.Text = "";
            //txtcontact.Text = "";
            //txtemail.Text = "";
            //txtsociallink1.Text = "";
            //txtsociallink2.Text = "";
            //txtaddress.Text = "";
            //ddlstate.ClearSelection();
            //ddlcity.ClearSelection();
            //txtarea.Text = "";
            //txttown.Text = "";
            //txtzipcode.Text = "";
            //txtClassdescription.Text = "";
            //cblfacilities.ClearSelection();
            //cbl8board.ClearSelection();
            //cbl9board.ClearSelection();
            //cbl10board.ClearSelection();



            //logoupload.Dispose();
            //image2.Dispose();
            //image3.Dispose();
        }