protected void btnIzbrisi_Click(object sender, EventArgs e) { if (tbSelected_Id.Text != "") { SlikaMeni.ImageUrl = ""; SqlConnection connection = new SqlConnection(); connection.ConnectionString = ConfigurationManager.ConnectionStrings["Konekcija"].ConnectionString; SqlCommand komanda = new SqlCommand(); komanda.Connection = connection; komanda.CommandText = "DELETE FROM Meni WHERE Meni_Id = " + tbSelected_Id.Text; try { connection.Open(); komanda.ExecuteNonQuery(); } finally { connection.Close(); tbSelected_Id.Text = ""; tbPromeniTekst.Text = ""; tbPromeniOpis.Text = ""; ddlPromeniPodmeni.SelectedIndex = -1; DSCeloMeni.ConnectionString = ConfigurationManager.ConnectionStrings["Konekcija"].ConnectionString; DSGlavnoMeni.ConnectionString = ConfigurationManager.ConnectionStrings["Konekcija"].ConnectionString; DSPodmeni.ConnectionString = ConfigurationManager.ConnectionStrings["Konekcija"].ConnectionString; DSSitePodmenija.ConnectionString = ConfigurationManager.ConnectionStrings["Konekcija"].ConnectionString; DSCeloMeni.SelectCommand = "SELECT Meni_Id, Tekst FROM Meni UNION SELECT '',''"; DSGlavnoMeni.SelectCommand = "SELECT * FROM Meni Where ParentMeni_Id IS NULL ORDER BY f_Sort"; DSPodmeni.SelectCommand = "SELECT * FROM Meni WHERE 1=2"; DSSitePodmenija.SelectCommand = "SELECT * FROM Meni WHERE 1=2"; DSCeloMeni.DataBind(); DSGlavnoMeni.DataBind(); DSPodmeni.DataBind(); DSSitePodmenija.DataBind(); if (Session["VtoroMeni"] != "") { lbGlavnoMeni.SelectedIndex = Convert.ToInt32(Session["GlavnoMeni"]); DSPodmeni.SelectCommand = "SELECT * FROM Meni Where NOT ParentMeni_Id IS NULL AND ParentMeni_Id = " + lbGlavnoMeni.SelectedValue + " ORDER BY f_Sort"; DSPodmeni.ConnectionString = ConfigurationManager.ConnectionStrings["Konekcija"].ConnectionString; DSPodmeni.DataBind(); } if (Session["TretoMeni"] != "") { lbPodmeni.SelectedIndex = Convert.ToInt32(Session["VtoroMeni"]); DSSitePodmenija.SelectCommand = @"select Meni_Id, Tekst, f_Sort from Meni where ParentMeni_Id=" + lbPodmeni.SelectedValue + @" union select Meni_Id, Tekst, f_Sort from Meni where ParentMeni_Id IN (select Meni_Id from Meni where ParentMeni_Id=" + lbPodmeni.SelectedValue + ") ORDER BY f_Sort"; DSSitePodmenija.ConnectionString = ConfigurationManager.ConnectionStrings["Konekcija"].ConnectionString; DSSitePodmenija.DataBind(); } ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "AlertPopup", "alert('Ставката е избришана!');", true); } } }
protected void btnDodadi_Click(object sender, EventArgs e) { if (tbPromeniTekst.Text != "") { String f_Stranica = "0"; if (cbStranica.Checked) { f_Stranica = "1"; } SqlConnection connection = new SqlConnection(); connection.ConnectionString = ConfigurationManager.ConnectionStrings["Konekcija"].ConnectionString; SqlCommand komanda = new SqlCommand(); komanda.Connection = connection; String Podmeni = ddlPromeniPodmeni.SelectedValue; if (Convert.ToInt32(Podmeni) < 1) { Podmeni = "NULL"; } if (fuPromeniSlika.PostedFile.ContentLength != 0) { Bitmap originalBMP = new Bitmap(fuPromeniSlika.FileContent); // Calculate the new image dimensions int origWidth = originalBMP.Width; int origHeight = originalBMP.Height; int sngRatio = origWidth / origHeight; int newWidth = 20; if (sngRatio < 1) { sngRatio = 1; } int newHeight = newWidth / sngRatio; int newWidth2 = 70; if (sngRatio < 1) { sngRatio = 1; } int newHeight2 = newWidth2 / sngRatio; // Create a new bitmap which will hold the previous resized bitmap Bitmap newBMP = new Bitmap(originalBMP, newWidth, newHeight); Graphics oGraphics = Graphics.FromImage(newBMP); oGraphics.SmoothingMode = SmoothingMode.AntiAlias; oGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic; oGraphics.DrawImage(originalBMP, 0, 0, newWidth, newHeight); byte[] data; Bitmap newBMP2 = new Bitmap(originalBMP, newWidth2, newHeight2); Graphics oGraphics2 = Graphics.FromImage(newBMP2); oGraphics2.SmoothingMode = SmoothingMode.AntiAlias; oGraphics2.InterpolationMode = InterpolationMode.HighQualityBicubic; oGraphics2.DrawImage(originalBMP, 0, 0, newWidth2, newHeight2); byte[] data2; using (System.IO.MemoryStream stream = new System.IO.MemoryStream()) { newBMP.Save(stream, System.Drawing.Imaging.ImageFormat.Png); stream.Position = 0; data = new byte[stream.Length]; data = stream.ToArray(); newBMP2.Save(stream, System.Drawing.Imaging.ImageFormat.Png); stream.Position = 0; data2 = new byte[stream.Length]; data2 = stream.ToArray(); } komanda.CommandText = @"INSERT INTO Meni (Tekst, Opis, ParentMeni_Id, Slika, SlikaGolema, f_Stranica, f_Sort) VALUES ( ' " + tbPromeniTekst.Text + "', '" + tbPromeniOpis.Text + @"', " + Podmeni + ", @Slika, @SlikaGolema , " + f_Stranica + @", (SELECT isnull(MAX(f_Sort),0)+1 FROM Meni WHERE ParentMeni_Id = " + Podmeni + ") )"; komanda.Parameters.Add("@Slika", data); komanda.Parameters.Add("@SlikaGolema", data2); } else { komanda.CommandText = @"INSERT INTO Meni (Tekst, Opis, ParentMeni_Id, f_Stranica, f_Sort) VALUES ( ' " + tbPromeniTekst.Text + "', '" + tbPromeniOpis.Text + @"', " + Podmeni + ", " + f_Stranica + @", (SELECT isnull(MAX(f_Sort),0)+1 FROM Meni WHERE ParentMeni_Id = " + Podmeni + ") )"; } try { connection.Open(); komanda.ExecuteNonQuery(); } finally { connection.Close(); DSCeloMeni.ConnectionString = ConfigurationManager.ConnectionStrings["Konekcija"].ConnectionString; DSGlavnoMeni.ConnectionString = ConfigurationManager.ConnectionStrings["Konekcija"].ConnectionString; DSPodmeni.ConnectionString = ConfigurationManager.ConnectionStrings["Konekcija"].ConnectionString; DSSitePodmenija.ConnectionString = ConfigurationManager.ConnectionStrings["Konekcija"].ConnectionString; DSCeloMeni.SelectCommand = "SELECT Meni_Id, Tekst FROM Meni UNION SELECT '',''"; DSGlavnoMeni.SelectCommand = "SELECT * FROM Meni Where ParentMeni_Id IS NULL ORDER BY f_Sort"; DSPodmeni.SelectCommand = "SELECT * FROM Meni WHERE 1=2"; DSSitePodmenija.SelectCommand = "SELECT * FROM Meni WHERE 1=2"; DSCeloMeni.DataBind(); DSGlavnoMeni.DataBind(); //DSPodmeni.DataBind(); //DSSitePodmenija.DataBind(); if (Session["GlavnoMeni"] != "") { lbGlavnoMeni.SelectedIndex = Convert.ToInt32(Session["GlavnoMeni"]); } if (Session["VtoroMeni"] != "") { DSPodmeni.SelectCommand = "SELECT * FROM Meni Where NOT ParentMeni_Id IS NULL AND ParentMeni_Id = " + lbGlavnoMeni.SelectedValue + " ORDER BY f_Sort"; DSPodmeni.ConnectionString = ConfigurationManager.ConnectionStrings["Konekcija"].ConnectionString; DSPodmeni.DataBind(); lbPodmeni.SelectedIndex = Convert.ToInt32(Session["VtoroMeni"]); } if (Session["TretoMeni"] != "") { DSSitePodmenija.SelectCommand = @"select Meni_Id, Tekst, f_Sort from Meni where ParentMeni_Id=" + lbPodmeni.SelectedValue + @" union select Meni_Id, Tekst, f_Sort from Meni where ParentMeni_Id IN (select Meni_Id from Meni where ParentMeni_Id=" + lbPodmeni.SelectedValue + ") ORDER BY f_Sort"; DSSitePodmenija.ConnectionString = ConfigurationManager.ConnectionStrings["Konekcija"].ConnectionString; DSSitePodmenija.DataBind(); lbSitePodmenija.SelectedIndex = Convert.ToInt32(Session["TretoMeni"]); } ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "AlertPopup", "alert('Ставката е додадена!');", true); } } }