コード例 #1
0
ファイル: dataManager.cs プロジェクト: javierfil/SocketServer
        internal Employee buscarEmpleadoxPersonIDenBD(string p)
        {
            Employee res = null;

            SqlConnection cnn = new SqlConnection(conexion);
            cnn.Open();
            SqlCommand cmd = cnn.CreateCommand();

            cmd.CommandText = "select * from Empleados where PersonID = '" + p + "'";
            cmd.CommandType = CommandType.Text;
            try
            {
                SqlDataReader rdr = cmd.ExecuteReader();

                if (rdr.Read())
                {
                    res = new Employee();

                    res.Id = Convert.ToInt32(rdr["idEmpleado"].ToString());
                    res.Nombre = rdr["Nombre"].ToString();
                    res.Apellido = rdr["Apellido"].ToString();

                    res.NumeroDocumento = rdr["NumeroDocumento"].ToString();

                    res.Empresa = rdr["Empresa"].ToString();

                    res.Imagen = rdr["Imagen"].ToString();
                    res.imageVersion = Convert.ToInt32(rdr["IdImagen"].ToString());

                    res.VersionEmpleado = Convert.ToInt32(rdr["Version"].ToString());
                    res.PersonID = Convert.ToInt32(rdr["PersonID"].ToString());

                }
                else loguearString("Error cargando empleado x PersonID: No existe empleado con el PersonID = " + p, TiposLOG.HH);
            }
            catch (Exception e)
            {
                loguearString("Error cargando empleado x PersonID(" + p + "): " + e.Message, TiposLOG.HH);
                res = null;
            }
            finally
            {
                    cnn.Close();
            }

            return res;
        }
コード例 #2
0
ファイル: dataManager.cs プロジェクト: javierfil/SocketServer
        private Dictionary<int, Employee> LoadEmpleados()
        {
            if (listaEmpleados != null)
            {
                return listaEmpleados;
            }
            else
            {
                listaEmpleados = new Dictionary<int, Employee>();

                int idEmpleado;
                string Nombre;
                string Apellido;
                bool Sexo = true;
                string eMail;
                string Direccion = "";
                //string Nacionalidad;
                //string Ciudad;
                DateTime FechaNacimiento;
                string Telefono;
                string Celular;
                string TipoDocumento;
                string NumeroDocumento;
                DateTime FechaExpedicionDocumento;
                DateTime FechaVencimientoDocumento;
                string Empresa;
                string Imagen;          // El path + nombre del archivo
                int IdImagen;
                byte[] imageBytes = null;
                string ultimaActualizacion;

                SqlConnection cnn = new SqlConnection(conexion);
                try
                {
                    //SqlCommand cmd = new SqlCommand("ListarEmpleados", cnn);
                    //cmd.CommandType = CommandType.StoredProcedure;

                    //cnn.Open();

                    //SqlDataReader lector = cmd.ExecuteReader();
                    cnn.Open();
                    SqlCommand cmd = cnn.CreateCommand();
                    cmd.CommandText = "select * from Empleados";
                    cmd.CommandType = CommandType.Text;

                    SqlDataReader lector = cmd.ExecuteReader();

                    int cant = 0;
                    Regex rHora = new Regex(@"(.*)-(.*)-(.*) (.*):(.*):(.*)");
                    while (lector.Read())
                    {
                        idEmpleado = Convert.ToInt32(lector["idEmpleado"]);
                        Nombre = lector["Nombre"].ToString();
                        Apellido = lector["Apellido"].ToString();

                        if (lector["Sexo"] != DBNull.Value)
                        {
                            Sexo = Convert.ToBoolean(lector["Sexo"]);
                        }
                        eMail = lector["eMail"].ToString();

                        if (lector["Direccion"] != DBNull.Value)
                        {
                            Direccion = lector["Direccion"].ToString();
                        }
                        FechaNacimiento = new DateTime(2013, 01, 01);

                        if (lector["FechaNacimiento"] != null)
                        {
                            if (lector["FechaNacimiento"].ToString().Length > 6)
                            {
                                FechaNacimiento = Convert.ToDateTime(lector["FechaNacimiento"].ToString());
                            }
                        }

                        Telefono = lector["Telefono"].ToString();
                        Celular = lector["Celular"].ToString();
                        TipoDocumento = lector["TipoDocumento"].ToString();

                        NumeroDocumento = lector["NumeroDocumento"].ToString();

                        FechaExpedicionDocumento = new DateTime(2013, 1, 1);
                        if (lector["FechaExpedicionDocumento"] != null)
                        {
                            if (lector["FechaExpedicionDocumento"].ToString().Length > 6)
                            {
                                FechaExpedicionDocumento = Convert.ToDateTime(lector["FechaExpedicionDocumento"]);
                            }

                        }
                        FechaVencimientoDocumento = new DateTime(2013, 12, 12);
                        if (lector["FechaVencimientoDocumento"] != null)
                        {
                            if (lector["FechaVencimientoDocumento"].ToString().Length > 6)
                            {
                                FechaVencimientoDocumento = Convert.ToDateTime(lector["FechaVencimientoDocumento"]);
                            }
                        }

                        Empresa = lector["Empresa"].ToString();

                        Imagen = lector["Imagen"].ToString();
                        IdImagen = Convert.ToInt32(lector["IdImagen"]);

                        ultimaActualizacion = lector["ultimaActualizacion"].ToString();

                        Employee emp = new Employee();

                        Match mHora = rHora.Match(ultimaActualizacion);

                        if (mHora.Success)
                        {
                            DateTime d = new DateTime(Convert.ToInt32(mHora.Groups[1].Value), Convert.ToInt32(mHora.Groups[2].Value), Convert.ToInt32(mHora.Groups[3].Value), Convert.ToInt32(mHora.Groups[4].Value), Convert.ToInt32(mHora.Groups[5].Value), Convert.ToInt32(mHora.Groups[6].Value));
                            emp.ultimaActualizacion = d;
                        }
                        else { loguearString("No paso la expresion regular de la hora. LoadEmpleados", TiposLOG.HH); }

                        bool valido = true;
                        int version = -1;
                        try { version = Convert.ToInt32(lector["Version"].ToString()); }
                        catch { valido = false; }

                        int personID = -1;
                        try { personID = Convert.ToInt32(lector["PersonID"].ToString()); }
                        catch { valido = false; }

                        emp.VersionEmpleado = version;
                        emp.PersonID = personID;

                        emp.Id = idEmpleado;
                        emp.Nombre = Nombre;
                        emp.Apellido = Apellido;
                        emp.Sexo = Sexo;
                        emp.EMail = eMail;
                        emp.Direccion = Direccion;
                        // emp.Nacionalidad = Nacionalidad;
                        // emp.Ciudad = Ciudad;
                        emp.FechaNacimiento = FechaNacimiento;
                        emp.Telefono = Telefono;
                        emp.Celular = Celular;
                        emp.TipoDocumento = TipoDocumento;
                        emp.NumeroDocumento = NumeroDocumento;
                        emp.FechaExpedicionDocumento = FechaExpedicionDocumento;
                        emp.FechaVencimientoDocumento = FechaVencimientoDocumento;

                        //DEBUG - ACA POR AHORA ES ""
                        emp.Empresa = Empresa;
                        emp.Empresa = "";

                        emp.Imagen = Imagen;
                        emp.imageVersion = IdImagen;

                        if (Imagen != "")
                        {
                            try
                            {
                                string fileName = Path.GetFileName(Imagen);
                                if (fileName != "")
                                {
                                    string imagePath = SystemConfiguration.ImagesPath;
                                    imageBytes = File.ReadAllBytes(imagePath + @"/" + fileName);
                                    cant++;
                                }
                                else
                                {
                                    imageBytes = null;
                                    emp.Imagen = "";
                                }

                            }
                            catch (Exception)
                            {
                                imageBytes = null;
                                emp.Imagen = "";
                            }
                        }
                        else
                        {
                            imageBytes = null;
                            emp.Imagen = "";
                        }

                        emp.attachImage(imageBytes);

                        if (valido) listaEmpleados.Add(idEmpleado, emp);

                    }

                }
                catch (Exception ex)
                {
                    loguearString("Excepcion en LoadEmpleados: " + ex.Message, TiposLOG.HH);

                }
                finally
                {
                    cnn.Close();
                }
            }

            return listaEmpleados;
        }
コード例 #3
0
        private void btnImportar_click(object sender, EventArgs e)
        {
            ListView.SelectedListViewItemCollection  listaElegidos= listViewUsuarios.SelectedItems;

            foreach (ListViewItem item in listaElegidos)
            {
                string tarjeta = item.SubItems[0].Text;
                string Nombre = item.SubItems[1].Text;
                string Apellido = item.SubItems[2].Text;
                string Acceso = item.SubItems[3].Text;

                Employee nuevoEmpleado = new Employee();
                //nuevoEmpleado.Tarjeta = tarjeta;
                nuevoEmpleado.Nombre = Nombre;
                nuevoEmpleado.Apellido = Apellido;
                //bool realAccess = true ;
                //if (Acceso == "Permitido")
                //{
                //    realAccess = true;
                //}
                //else
                //{
                //    realAccess = false;
                //}

                //nuevoEmpleado.Acceso = realAccess;

            }
            MessageBox.Show("Agregados " + listaElegidos.Count + " empleados al sistema");
        }
        private void button3_Click_1(object sender, EventArgs e)
        {
            Employee emp = new Employee();

            //emp.Tarjeta = "1234";
            emp.Nombre = "Javier";
            emp.Apellido = "Filippini";
            //emp.Acceso = true;
            mainApp.DataManager.addUser("1234", emp);
        }
        private void LoadEmpleados()
        {
            if (File.Exists(dataSource + @"\\personal.xml"))
            {

                XmlDocument xDoc = new XmlDocument();
                xDoc.Load(dataSource + @"\\personal.xml");

                listaUsuarios.Clear();

                foreach (XmlElement elem in xDoc.SelectNodes("/Empleados/Empleado"))
                {
                    string tarjeta = elem.Attributes["tarjeta"].Value;
                    string nombre = elem.Attributes["nombre"].Value;
                    string apellido = elem.Attributes["apellido"].Value;
                    string empresa = elem.Attributes["empresa"].Value;
                    bool acceso = bool.Parse(elem.Attributes["acceso"].Value);
                    bool sexo = bool.Parse(elem.Attributes["sexo"].Value);
                    DateTime FechaNacimiento = DateTime.Parse(elem.Attributes["fechaNacimiento"].Value);
                    string Funcion = elem.Attributes["funcion"].Value;
                    string Direccion = elem.Attributes["direccion"].Value;
                    string Departamento = elem.Attributes["departamento"].Value;
                    string Nacionalidad = elem.Attributes["nacionalidad"].Value;
                    string Telefono = elem.Attributes["telefono"].Value;
                    EstadosCiviles EstadoCivil = (EstadosCiviles)Enum.Parse(typeof(EstadosCiviles), elem.Attributes["estadoCivil"].Value);
                    string NombreConyugue = elem.Attributes["nombreConyugue"].Value;
                    string NombrePadre = elem.Attributes["nombrePadre"].Value;
                    string NombreMadre = elem.Attributes["nombreMadre"].Value;
                    string NivelEscolaridad = elem.Attributes["nivelEscolaridad"].Value;
                    DateTime ValidezCarnetSalud = DateTime.Parse(elem.Attributes["validezCarnetSalud"].Value);
                    string SSNO = elem.Attributes["SSNO"].Value;
                    DateTime FechaExpedicionSSNO = DateTime.Parse(elem.Attributes["fechaExpedicionSSNO"].Value);
                    DateTime FechaVencimientoSSNO = DateTime.Parse(elem.Attributes["fechaVencimientoSSNO"].Value);
                    CategoríasLibretasConducir CategoriaLibretaConducir = (CategoríasLibretasConducir)Enum.Parse(typeof(CategoríasLibretasConducir), elem.Attributes["categoriaLibretaConducir"].Value);
                    DateTime VencimientoLibretaConducir = DateTime.Parse(elem.Attributes["vencimientoLibretaConducir"].Value);
                    DateTime IngresoBPS = DateTime.Parse(elem.Attributes["ingresoBPS"].Value);
                    string TipoAportacion = elem.Attributes["tipoAportacion"].Value;
                    DateTime VigenciaBSE = DateTime.Parse(elem.Attributes["vigenciaBSE"].Value);
                    string imageName = elem.Attributes["imagen"].Value;

                    Employee emp = new Employee();

                    emp.Tarjeta = tarjeta;
                    emp.Nombre = nombre;
                    emp.Apellido = apellido;
                    emp.Empresa = empresa;
                    emp.Acceso = acceso;
                    emp.Sexo = sexo;
                    emp.FechaNacimiento = FechaNacimiento;
                    emp.Funcion = Funcion;
                    emp.Direccion = Direccion;
                    emp.Departamento = Departamento;
                    emp.Nacionalidad = Nacionalidad;
                    emp.Telefono = Telefono;
                    emp.EstadoCivil = EstadoCivil;
                    emp.NombreConyugue = NombreConyugue;
                    emp.NombrePadre = NombrePadre;
                    emp.NombreMadre = NombreMadre;
                    emp.NivelEscolaridad = NivelEscolaridad;
                    emp.ValidezCarnetSalud = ValidezCarnetSalud;
                    emp.SSNO = SSNO;
                    emp.FechaExpedicionSSNO = FechaExpedicionSSNO;
                    emp.FechaVencimientoSSNO = FechaVencimientoSSNO;
                    emp.CategoriaLibretaConducir = CategoriaLibretaConducir;
                    emp.VencimientoLibretaConducir = VencimientoLibretaConducir;
                    emp.IngresoBPS = IngresoBPS;
                    emp.TipoAportación = TipoAportacion;
                    emp.VigenciaBSE = VigenciaBSE;
                    emp.imageFileName = imageName;
                    if (imageName!="")
                        attachImageByteArray(emp, imageName);

                    if (!listaUsuarios.ContainsKey(tarjeta))
                    {
                        listaUsuarios.Add(tarjeta, emp);
                    }
                }
            }
        }
 private void attachImageByteArray(Employee v_emp, string imagename)
 {
     byte[] bytes = File.ReadAllBytes(imagename);
     v_emp.attachImage(bytes);
 }
        public void addUser(string idUser, Employee v_usuario)
        {
            if (listaUsuarios.ContainsKey(idUser))
            {
                listaUsuarios.Remove(idUser);
                listaUsuarios.Add(idUser, v_usuario);
            }
            else
            {
                listaUsuarios.Add(idUser, v_usuario);
            }

            SaveEmpleados();            // Guarda los datos en el disco
        }