using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Net; using System.Drawing; using System.Drawing.Imaging; using System.IO; public partial class CadastroInstituicao : System.Web.UI.Page { private int vID = 0; protected void Page_Load(object sender, EventArgs e) { string valor = Request.QueryString["Parametro"]; if (!Page.IsPostBack) { lblOp.Text = Geral.GetOp(Request.QueryString["Op"].ToString()); Instituicao Inst = new Instituicao(); cbbinstituicao.DataSource = Inst.GetAll(); cbbinstituicao.DataBind(); Curso Cur = new Curso(); cbbcurso.DataSource = Cur.GetAll(); cbbcurso.DataBind(); Nivel Niv = new Nivel(); cbbnivel.DataSource = Niv.GetAll(); cbbnivel.DataBind(); Estudante Cad = new Estudante(); Cad.GetId(Request.QueryString["Id"].ToString()); cbbinstituicao.SelectedItem = cbbinstituicao.Items.FindByValue(Cad.instituicao); cbbcurso.SelectedItem = cbbcurso.Items.FindByValue(Cad.curso); cbbnivel.SelectedItem = cbbnivel.Items.FindByValue(Cad.nivel); cbbsexo.Value =Cad.sexo; txtnome.Text = Cad.nome ; txtcpf.Text = Cad.cpf ; txtrg.Text = Cad.rg ; txtemail.Text = Cad.email; dtpnascimento.Date = Convert.ToDateTime(Cad.nascimento.ToString()); txtrua.Text = Cad.rua; txtnr.Text = Cad.nr; txtbairro.Text = Cad.bairro; txtcomplemento.Text = Cad.complemento; txtcep.Text = Cad.cep ; txtcidade.Text = Cad.cidade; cbbuf.Text = Cad.uf; txtfone1.Text = Cad.fone1 ; txtfone2.Text = Cad.fone2 ; txtfone2.Text = Cad.fone3 ; // Cad.emitidopor = 0; // dtpvalidade.Date = Convert.ToDateTime(Cad.validade.ToString()); //Cad.qrcode = ""; txtfone3.Text = Cad.codigo; vID = Convert.ToInt32(Request.QueryString["Id"].ToString()); imgfoto.ImageUrl = "~/Fotos/" + vID.ToString() + ".jpg"; imgqrcode.ImageUrl = "http://chart.apis.google.com/chart?cht=qr&chl=http://sis.aneestudantes.com.br/Estudante.aspx?Id=" + vID.ToString() + "&chs=150x150"; if (Request.QueryString["Op"].ToString() == "A") { uplfoto.Enabled = true; } else { uplfoto.Enabled = false; } } } protected void ASPxFormLayout1_E3_Click(object sender, EventArgs e) { if (Request.QueryString["Op"].ToString() == "N") { if (Page.IsValid) { Estudante Cad = new Estudante(); Cad.GetId(Request.QueryString["Id"].ToString()); Cad.instituicao = Convert.ToInt32(cbbinstituicao.Value.ToString()); Cad.curso = Convert.ToInt32(cbbcurso.Value.ToString()); ; Cad.nivel = Convert.ToInt32(cbbnivel.Value.ToString()); ; Cad.sexo = cbbsexo.Value.ToString(); Cad.nome = txtnome.Text; Cad.cpf = txtcpf.Text; Cad.rg = txtrg.Text; Cad.email = txtemail.Text; Cad.nascimento = dtpnascimento.Date; Cad.rua = txtrua.Text; Cad.nr = txtnr.Text; Cad.bairro = txtbairro.Text; Cad.complemento = txtcomplemento.Text; Cad.cep = txtcep.Text; Cad.cidade = txtcidade.Text; Cad.uf = cbbuf.Text; Cad.fone1 = txtfone1.Text; Cad.fone2 = txtfone2.Text; Cad.fone3 = ""; Cad.emitidopor = 0; Cad.validade = DateTime.Now; Cad.qrcode = ""; Cad.codigo = txtfone3.Text; vID = Cad.Inserir(); Response.Redirect("~/CadastroEstudante.aspx?Op=A&Id=" + vID.ToString()); imgqrcode.ImageUrl = "http://chart.apis.google.com/chart?cht=qr&chl=http://sis.aneestudantes.com.br/Estudante.aspx?Id=" + vID.ToString() + "&chs=150x150"; //int angle = 90; //string image = "~/qrcode/" + vID.ToString() + ".png"; //string imagepath = Server.MapPath(image); //Bitmap b = new Bitmap(imagepath); //Bitmap rotated = rotateImage(b, angle); //using (MemoryStream stream = new MemoryStream()) //{ // rotated.MakeTransparent(Color.White); // rotated.Save(stream, ImageFormat.Png); // Response.Clear(); // Response.ContentType = "image/png"; // stream.WriteTo(Response.OutputStream); //} //b.Dispose(); //rotated.Dispose(); } } else if (Request.QueryString["Op"].ToString() == "A") { if (Page.IsValid) { Estudante Cad = new Estudante(); Cad.GetId(Request.QueryString["Id"].ToString()); Cad.instituicao = Convert.ToInt32(cbbinstituicao.Value.ToString()); Cad.curso = Convert.ToInt32(cbbcurso.Value.ToString()); ; Cad.nivel = Convert.ToInt32(cbbnivel.Value.ToString()); ; Cad.sexo = cbbsexo.Value.ToString(); Cad.nome = txtnome.Text; Cad.cpf = txtcpf.Text; Cad.rg = txtrg.Text; Cad.email = txtemail.Text; Cad.nascimento = dtpnascimento.Date; Cad.rua = txtrua.Text; Cad.nr = txtnr.Text; Cad.bairro = txtbairro.Text; Cad.complemento = txtcomplemento.Text; Cad.cep = txtcep.Text; Cad.cidade = txtcidade.Text; Cad.uf = cbbuf.Text; Cad.fone1 = txtfone1.Text; Cad.fone2 = txtfone2.Text; Cad.fone3 = "" ; Cad.emitidopor = 0; // Cad.validade = dtpvalidade.Date; Cad.qrcode = ""; Cad.codigo = txtfone3.Text; Cad.Alterar(Request.QueryString["Id"].ToString()); vID = Convert.ToInt32(Request.QueryString["Id"].ToString()); WebClient webClient = new WebClient(); webClient.DownloadFile("http://chart.apis.google.com/chart?cht=qr&chl=http://sis.aneestudantes.com.br/Estudante.aspx?Id=" + vID.ToString() + "&chs=150x150", Server.MapPath("~/QRCode/") + vID.ToString() + ".png"); //create an object that we can use to examine an image file //int angle = 90; //string image = "~/qrcode/" + vID.ToString() + ".png"; //string imagepath = Server.MapPath(image); //Bitmap b = new Bitmap(imagepath); //Bitmap rotated = rotateImage(b, angle); //using (MemoryStream stream = new MemoryStream()) //{ // rotated.MakeTransparent(Color.White); // rotated.Save(stream, ImageFormat.Png); // Response.Clear(); // Response.ContentType = "image/png"; // stream.WriteTo(Response.OutputStream); //} //b.Dispose(); //rotated.Dispose(); } } else if (Request.QueryString["Op"].ToString() == "E") { Estudante Cad = new Estudante(); Cad.Excluir(Request.QueryString["Id"].ToString()); Response.Redirect("~/ConsultaEstudante.aspx"); } } protected void ASPxFormLayout1_E4_Click(object sender, EventArgs e) { Response.Redirect("~/ConsultaEstudante.aspx"); } protected void uplfoto_FileUploadComplete(object sender, DevExpress.Web.FileUploadCompleteEventArgs e) { vID = Convert.ToInt32(Request.QueryString["Id"].ToString()); //string Path = Page.MapPath("~/Fotos/") + e.UploadedFile.FileName; string Path; Path = Page.MapPath("~/Fotos/") + vID.ToString() + ".jpg"; // imgfoto.ImageUrl = Page.MapPath("~/Fotos/") + vID.ToString() + ".jpg"; e.UploadedFile.SaveAs(Path); } private Bitmap rotateImage(Bitmap b, float angle) { Bitmap returnBitmap = new Bitmap(b.Width, b.Height, PixelFormat.Format32bppPArgb); Graphics g = Graphics.FromImage(returnBitmap); g.TranslateTransform((float)b.Width / 2, (float)b.Height / 2); g.RotateTransform(angle); g.TranslateTransform(-(float)b.Width / 2, -(float)b.Height / 2); g.DrawImage(b, new Point(0, 0)); return returnBitmap; } protected void Button1_Click(object sender, EventArgs e) { vID = Convert.ToInt32(Request.QueryString["Id"].ToString()); string strFile = Server.MapPath("~/Fotos/") + vID.ToString() + ".jpg"; System.IO.File.WriteAllText(strFile, "Aguarde..."); System.IO.File.Delete(strFile); } }