using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;
public partial class school1_comm : System.Web.UI.Page
{
int idddd;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbcon"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
scl(); getnews(); session();// getcat(); STATE();
}
}
protected void rpnews_ItemCommand(object source, RepeaterCommandEventArgs e)
{
int indexno = e.Item.ItemIndex;
Label lid = (Label)rpnews.Items[indexno].FindControl("lblid");
Session["commandid"] = lid.Text;
Session["iid"] = lid.Text;
if (e.CommandName == "delete")
{
SqlCommand cmd = new SqlCommand("delete from tes where id='" + lid.Text + "'", con);
// cmd.Parameters.AddWithValue("@id", lid.Text);
// cmd.CommandType = CommandType.StoredProcedure;
con.Open();
int j = cmd.ExecuteNonQuery();
con.Close();
if (j > 0)
{
Response.Write("");
}
}
if (e.CommandName == "Edit")
{
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter();
DataRow dr;
SqlCommand cmd = new SqlCommand("SELECT * from dbo.tes where id='" + lid.Text + "'", con);
da.SelectCommand = cmd;
dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
dr = dt.Rows[0];
string mm = Convert.ToString(dr["id"]);
Image1.ImageUrl = Convert.ToString(dr["p1"]);
TextBox1.Text = Convert.ToString(dr["name"]);
DropDownList1.Text = Convert.ToString(dr["REM"]);
Button1.Visible = false;
Button2.Visible = true;
//ins.Text = Convert.ToString(db.dr[5]);
// DropDownList1.Text = X;
}
}
getnews();
}
private void getid()
{
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter();
DataRow dr;
SqlCommand cmd = new SqlCommand("SELECT count(id) from facc where ID='" + Session["cid"] + "'", con);
da.SelectCommand = cmd;
dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
dr = dt.Rows[0];
string a = Convert.ToString(dr[0]);
// TextBox1.Text = Convert.ToString(dr["name"]);
// Image1.ImageUrl = Convert.ToString(dr["p1"]);
idddd = Convert.ToInt32(dr[0]);
// idddd = idddd + 1;
//int aa = Convert.ToInt32(Label3.Text);
//int bb = aa / sc;
//Label2.Text = bb.ToString();
}
}
private void iddsd()
{
SqlCommand cmd = new SqlCommand("select id from dbo.facc order by id desc", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
int ib = Convert.ToInt32(dt.Rows[0][0]);
Session["iidd"] = ib;
}
else
{
Session["iidd"] = "1";
}
}
private void getnews()
{
SqlCommand cmd = new SqlCommand("select * from dbo.facc order by id desc", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
rpnews.DataSource = dt;
rpnews.DataBind();
}
}
protected void rpnews_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
iddsd();
// Check file exist or not
if (FileUpload1.PostedFile != null)
{
// Check the extension of image
string extension = Path.GetExtension(FileUpload1.FileName);
if (extension.ToLower() == ".png" || extension.ToLower() == ".jpg" || extension.ToLower() == ".jpeg" || extension.ToLower() == ".mp4")
{
Stream strm = FileUpload1.PostedFile.InputStream;
string targetPath = Server.MapPath(@"~/uploads/") + FileUpload1.FileName;
string s = Session["iidd"].ToString() + extension;
string filePath = "~//uploads//" + s;
FileUpload1.SaveAs(Server.MapPath(filePath));
// Print new Size of file (height or Width)
// Label2.Text = thumbImg.Size.ToString();
//Show Image
Image1.ImageUrl = filePath;
string dd = "uploads/" + s;
if (con.State == 0)
con.Open();
getid();
iddsd();
SqlCommand cmd = new SqlCommand("insert into facc (session,sid,REM,name,web,p1,p2) VALUES ('" + DropDownList3.SelectedItem.Text + "','" + DropDownList2.SelectedItem.Value + "','" + DropDownList1.Text + "','" + TextBox1.Text + "','PPS','" + Image1.ImageUrl + "','" + dd + "')", con);
cmd.ExecuteNonQuery();
Response.Write("");
getnews();
Image1.ImageUrl = "";
}
}
}
private void scl()
{
SqlCommand cmd = new SqlCommand("SELECT * FROM SchoolInfo where web='PPS'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.SelectCommand = cmd;
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
DropDownList2.DataSource = dt;
DropDownList2.DataValueField = "id";
DropDownList2.DataTextField = "SchoolName";
DropDownList2.DataBind();
DropDownList2.Items.Insert(0, "......Select School .......");
}
}
private void session()
{
SqlCommand cmd = new SqlCommand("SELECT * FROM session where wuser='PPS'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.SelectCommand = cmd;
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
DropDownList3.DataSource = dt;
DropDownList3.DataValueField = "id";
DropDownList3.DataTextField = "session";
DropDownList3.DataBind();
DropDownList3.Items.Insert(0, "...Select session ...");
}
}
protected void Button2_Click1(object sender, EventArgs e)
{
// Check file exist or not
if (FileUpload1.PostedFile != null)
{
// Check the extension of image
string extension = Path.GetExtension(FileUpload1.FileName);
//if (extension.ToLower() == ".png" || extension.ToLower() == ".jpg")
//{
// Stream strm = FileUpload1.PostedFile.InputStream;
// using (var image = System.Drawing.Image.FromStream(strm))
// {
// // Print Original Size of file (Height or Width)
// Label1.Text = image.Size.ToString();
// int newWidth = 1640; // New Width of Image in Pixel
// int newHeight = 700; // New Height of Image in Pixel
// var thumbImg = new Bitmap(newWidth, newHeight);
// var thumbGraph = Graphics.FromImage(thumbImg);
// thumbGraph.CompositingQuality = CompositingQuality.HighQuality;
// thumbGraph.SmoothingMode = SmoothingMode.HighQuality;
// thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
// var imgRectangle = new Rectangle(0, 0, newWidth, newHeight);
// thumbGraph.DrawImage(image, imgRectangle);
// Save the file
string targetPath = Server.MapPath(@"~/uploads/") + FileUpload1.FileName;
FileUpload1.SaveAs(targetPath);
// Print new Size of file (height or Width)
//Label2.Text = thumbImg.Size.ToString();
//Show Image
Image1.ImageUrl = "~\\GRA\\" + FileUpload1.FileName;
string dd = "GRA\\" + FileUpload1.FileName;
if (con.State == 0)
con.Open();
try
{
SqlCommand cmd = new SqlCommand("update FACC set ins='" + Session["cid"] + "',session='" + DropDownList3.SelectedItem.Text + "', sid='" + DropDownList2.SelectedItem.Value + "', REM='" + DropDownList1.Text + "', name='" + TextBox1.Text + "', P1='" + Image1.ImageUrl + "',P2='" + dd + "'where id='" + Session["iid"] + "'", con);
cmd.ExecuteNonQuery();
Response.Write("");
getnews();
Image1.ImageUrl = "";
}
catch (Exception ex)
{
Response.Write("");
}
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("select * from dbo.facc WHERE REM='" + DropDownList1.Text + "' order by id desc", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
rpnews.DataSource = dt;
rpnews.DataBind();
}
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("select * from dbo.facc WHERE SID='" + DropDownList1.SelectedItem.Value + "' order by id desc", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
rpnews.DataSource = dt;
rpnews.DataBind();
}
}
protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("select * from dbo.facc WHERE REM='" + DropDownList2.Text + "' AND SID='" + DropDownList1.SelectedItem.Value + "' AND Session='" + DropDownList3.Text + "' order by id desc", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
rpnews.DataSource = dt;
rpnews.DataBind();
}
}
}