コード例 #1
0
        public void modificarColono(Calles cal)
        {
            string sentencia;

            sentencia = "update calles set nombre = '" + cal.Nombre + "' where idcalles='" + cal.Idcalles + "'";
            MySqlCommand commandDatabase = new MySqlCommand(sentencia, databaseConnection);

            try
            {
                databaseConnection.Open();
                MySqlDataReader myReader = commandDatabase.ExecuteReader();
                commandDatabase.CommandTimeout = 60;

                MessageBox.Show("Calle modificado");
                databaseConnection.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "," + ex.StackTrace);
                databaseConnection.Close();
            }
            finally
            {
                databaseConnection.Close();
            }
        }
コード例 #2
0
        public void EliminarCalle(Calles cal)
        {
            string sentencia;

            sentencia = "delete from  calles  where idcalles ='" + cal.Idcalles + "'";
            MySqlCommand commandDatabase = new MySqlCommand(sentencia, databaseConnection);

            try
            {
                databaseConnection.Open();
                MySqlDataReader myReader = commandDatabase.ExecuteReader();
                commandDatabase.CommandTimeout = 60;

                MessageBox.Show("Calle eliminada");
                databaseConnection.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "," + ex.StackTrace);
                databaseConnection.Close();
            }
            finally
            {
                databaseConnection.Close();
            }
        }
コード例 #3
0
        public void registrarColono(Calles cal)
        {
            string sentencia;

            sentencia = "Insert into calles(idcalles,nombre) values(" +
                        "'" + cal.Idcalles + "','" + cal.Nombre + "')";
            MySqlCommand commandDatabase = new MySqlCommand(sentencia, databaseConnection);


            try
            {
                databaseConnection.Open();



                MySqlDataReader myReader = commandDatabase.ExecuteReader();
                commandDatabase.CommandTimeout = 60;

                MessageBox.Show("Calle dado de alta");
                databaseConnection.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:" + ex.Message);

                MessageBox.Show("Error:" + ex.StackTrace);
            }
            finally
            {
                databaseConnection.Close();
            }
        }
コード例 #4
0
        public async Task <HttpResponseMessage> Add()
        {
            var    folderName  = "Content/Photos";
            var    CurrentTime = Helper.Now();
            string json        = "";
            var    fromAndroid = false;

            var PATH           = HttpContext.Current.Server.MapPath("~/" + folderName);
            var rootUrl        = Request.RequestUri.AbsoluteUri.Replace(Request.RequestUri.AbsolutePath, String.Empty);
            var streamProvider = new MultipartFormDataStreamProvider(PATH);


            if (Request.Content.IsMimeMultipartContent())
            {
                await Request.Content.ReadAsMultipartAsync(streamProvider);

                var PIN         = streamProvider.FormData["Pin"];
                var Plate       = streamProvider.FormData["Plate"];
                var Cone        = streamProvider.FormData["Cone"];
                var IdStreet    = Guid.Parse(streamProvider.FormData["IdStreet"]);
                var NumberHouse = streamProvider.FormData["NumberHouse"];
                var IdSubject   = Guid.Parse(streamProvider.FormData["IdSubject"]);
                var Photo       = "";

                Visitantes newVisitor = (from us in db.Visitantes where us.pin == PIN select us).FirstOrDefault();
                Calles     street     = (from ca in db.Calles where ca.id_calle == IdStreet select ca).FirstOrDefault();
                Asuntos    subject    = (from sub in db.Asuntos where sub.id_asunto == IdSubject select sub).FirstOrDefault();

                Domicilios address = (from dom in db.Domicilios where dom.id_calle == IdStreet && dom.no_casa == NumberHouse select dom).FirstOrDefault();

                if (newVisitor == null)
                {
                    json = Helper.toJson(false, "No existe el visitante");

                    return(new HttpResponseMessage()
                    {
                        Content = new StringContent(json.ToString(), Encoding.UTF8, "application/json")
                    });
                }

                if (address == null)
                {
                    json = Helper.toJson(false, "No existe el domicilio");

                    return(new HttpResponseMessage()
                    {
                        Content = new StringContent(json.ToString(), Encoding.UTF8, "application/json")
                    });
                }

                foreach (MultipartFileData fileData in streamProvider.FileData)
                {
                    if (string.IsNullOrEmpty(fileData.Headers.ContentDisposition.FileName))
                    {
                        return(Request.CreateResponse(HttpStatusCode.NotAcceptable, "This request is not properly formatted"));
                    }
                    string fileName = fileData.Headers.ContentDisposition.FileName;
                    if (fileName.StartsWith("\"") && fileName.EndsWith("\""))
                    {
                        fileName = fileName.Trim('"');
                    }
                    if (fileName.Contains(@"/") || fileName.Contains(@"\"))
                    {
                        fileName = Path.GetFileName(fileName);
                    }

                    string ext = Path.GetExtension(fileName);

                    var phototemp = Guid.NewGuid().ToString().ToUpper() + ext;
                    var photo     = Guid.NewGuid().ToString().ToUpper() + ext;
                    var lastphoto = Guid.NewGuid().ToString().ToUpper() + ext;

                    File.Move(fileData.LocalFileName, Path.Combine(PATH, phototemp));

                    string text = System.IO.File.ReadAllText(Path.Combine(PATH, phototemp));

                    string base64 = text.Split(',')[1];
                    if (Helper.IsBase64(base64))
                    {
                        fromAndroid = true;
                        byte[] bytes = Convert.FromBase64String(base64);
                        using (Image image = Image.FromStream(new MemoryStream(bytes)))
                        {
                            image.Save(Path.Combine(PATH, photo), ImageFormat.Jpeg);  // Or Png
                        }
                    }
                    else
                    {
                        File.Move(fileData.LocalFileName, Path.Combine(PATH, photo));
                    }
                    // First load the image somehow
                    Image myImage = Image.FromFile(Path.Combine(PATH, photo), true);

                    if (myImage.Width < myImage.Height)
                    {
                        Helper.RotateAndSaveImage(Path.Combine(PATH, photo), Path.Combine(PATH, lastphoto));
                    }
                    else
                    {
                        myImage.Save(Path.Combine(PATH, lastphoto), System.Drawing.Imaging.ImageFormat.Jpeg);
                    }
                    // Save the image with a quality of 50%
                    myImage.Dispose();

                    Image LastImage = Image.FromFile(Path.Combine(PATH, lastphoto), true);
                    Helper.SaveJpeg(Path.Combine(PATH, "min" + lastphoto), LastImage, 40);
                    LastImage.Dispose();

                    if (File.Exists(Path.Combine(PATH, phototemp)))
                    {
                        File.Delete(Path.Combine(PATH, phototemp));
                    }
                    if (File.Exists(Path.Combine(PATH, photo)))
                    {
                        File.Delete(Path.Combine(PATH, photo));
                    }
                    Photo = lastphoto;
                }

                try
                {
                    Accesos acceso = new Accesos();
                    acceso.id_acceso      = Guid.NewGuid();
                    acceso.id_visitante   = newVisitor.id_visitante;
                    acceso.id_asunto      = IdSubject;
                    acceso.id_domicilio   = address.id_domicilio;
                    acceso.fecha          = Helper.Now();
                    acceso.placa          = Plate == "undefined" ? "" : Plate;
                    acceso.cono           = Cone == "undefined" ? "" : Cone;
                    acceso.identificacion = Photo;

                    db.Accesos.Add(acceso);

                    db.SaveChanges();

                    if (fromAndroid)
                    {
                        json = Helper.toJson(true, "Acceso Grabado");
                    }
                    else
                    {
                        json = Helper.toJson(true, "Acceso Grabado");
                    }


                    return(new HttpResponseMessage()
                    {
                        Content = new StringContent(json.ToString(), Encoding.UTF8, "application/json")
                    });
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                          eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            //Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",ve.PropertyName, ve.ErrorMessage);

                            EventLog eventLog = new EventLog("Application");

                            eventLog.Source = "BonaterraSite";
                            eventLog.WriteEntry("- Property: " + ve.PropertyName + ", Error: " + ve.ErrorMessage, EventLogEntryType.Information, 101, 1);
                        }

                        json = Helper.toJson(false, "No se pudo guardar el acceso");

                        return(new HttpResponseMessage()
                        {
                            Content = new StringContent(json.ToString(), Encoding.UTF8, "application/json")
                        });
                    }
                    throw;
                }
            }
            json = Helper.toJson(false, "Error");

            return(new HttpResponseMessage()
            {
                Content = new StringContent(json.ToString(), Encoding.UTF8, "application/json")
            });
        }