public DataSet GetAll_U_P(string empresaid, tb_usuariosxproceso BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTbUsuariosProceso_GETALL", cnx))
         {
             DataSet ds = new DataSet();
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@procesoid", SqlDbType.Char, 4).Value = BE.procesoid;
                 cmd.Parameters.Add("@usuar", SqlDbType.Char, 15).Value = BE.usuar;
                 cmd.Parameters.Add("@password", SqlDbType.Char, 20).Value = BE.password;
                 cmd.Parameters.Add("@orden", SqlDbType.Int).Value = BE.norden;
                 cmd.Parameters.Add("@login", SqlDbType.Char, 15).Value = BE.login;
             }
             try
             {
                 cnx.Open();
                 using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                 {
                     da.Fill(ds);
                 }
                 return ds;
             }
             catch (Exception ex)
             {
                 Sql_Error = ex.Message;
                 throw new Exception(ex.Message);
             }
         }
     }
 }
        private void btnAceptar_Click(object sender, EventArgs e)
        {
            txtClaveNew.Text = txtClaveNew.Text.Trim();
            txtClaveConfNew.Text = txtClaveConfNew.Text.Trim();

            //string LcClaveAntigua = fungen.EncryptStr(txtClave.Text.Trim().ToLower(), "key");
            //string LcClaveAntigua = VariablesPublicas.Encriptar(txtClave.Text.Trim(), "SI");
            string LcClaveAntigua = VariablesPublicas.Encripta(txtClave.Text.Trim());

            //string NewClave = fungen.EncryptStr(txtClaveNew.Text.Trim().ToLower(), "key");
            //string NewClave = VariablesPublicas.Encriptar(txtClaveNew.Text.Trim(), "SI");
            string NewClave = VariablesPublicas.Encripta(txtClaveNew.Text.Trim());

            //string NewClaveConfirma = fungen.EncryptStr(txtClaveConfNew.Text.Trim().ToLower(), "key");
            //string NewClaveConfirma = VariablesPublicas.Encriptar(txtClaveConfNew.Text.Trim(), "SI");
            string NewClaveConfirma = VariablesPublicas.Encripta(txtClaveConfNew.Text.Trim());

            if (!(Equivalencias.Left(LcClaveAntigua,20) == Cursor01.Rows[0]["password"].ToString().Trim()))
            //if (!(LcClaveAntigua == Cursor01.Rows[0]["password"].ToString().Trim()))
            {
                MessageBox.Show("Confirme Clave Antigua...", "Mensaje del Sistema");
                txtClave.Focus();
                return;
            }
            if (!(NewClave == NewClaveConfirma))
            {
                MessageBox.Show("Confirme Nueva Clave...", "Mensaje del Sistema");
                txtClaveConfNew.Focus();
                return;
            }
            Cursor01.Rows[0]["password"] = NewClaveConfirma;
            usuariosxprocesoBL BL = new usuariosxprocesoBL();
            tb_usuariosxproceso BE = new tb_usuariosxproceso();

            BE.procesoid = _TipoProceso;
            BE.ntipo = 1;
            //if (UsuariosProcesosInsertUpdated(_TipoProceso, Cursor01, 1))
            if (BL.UsuariosProcesosInsertUpdated(VariablesPublicas.EmpresaID.ToString(), BE, Cursor01))
            {
                MessageBox.Show("Clave ha sido modificada satisfactoriamente...?", "Mensaje del Sistema");
                Close();
            }
        }
        public void CargaData()
        {
            string CodProceso = "..";
            if (cboProceso.SelectedValue != null)
            {
                CodProceso = cboProceso.SelectedValue.ToString();
            }

            dgOrdenes.DataSource = null;

            usuariosxprocesoBL BL = new usuariosxprocesoBL();
            tb_usuariosxproceso BE = new tb_usuariosxproceso();

            BE.procesoid = CodProceso;
            BE.norden = 1;
            oDetalle = BL.GetAll_U_P(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];
            //oDetalle = ocapa.UsuariosProcesoGetAll(CodProceso, "", "", 1, "");

            dgOrdenes.AutoGenerateColumns = false;
            dgOrdenes.Columns["Column5"].DataPropertyName = "uprocesoid";
            dgOrdenes.Columns["Column1"].DataPropertyName = "usuar";
            dgOrdenes.Columns["Column2"].DataPropertyName = "nomusuario";
            dgOrdenes.Columns["Column3"].DataPropertyName = "password";
            dgOrdenes.Columns["Column6"].DataPropertyName = "firma";

            //Column6
            oDetalle.Columns["uprocesoid"].AllowDBNull = true;
            oDetalle.Columns["usuar"].AllowDBNull = true;
            oDetalle.Columns["nomusuario"].AllowDBNull = true;
            oDetalle.Columns["password"].AllowDBNull = true;
            oDetalle.Columns["FIRMA"].AllowDBNull = true;

            oDetalle.Columns["uprocesoid"].ReadOnly = false;
            oDetalle.Columns["usuar"].ReadOnly = false;
            oDetalle.Columns["nomusuario"].ReadOnly = false;
            oDetalle.Columns["password"].ReadOnly = false;
            oDetalle.Columns["firma"].ReadOnly = false;

            dgOrdenes.DataSource = oDetalle;
        }
        private void btnAceptar_Click(object sender, EventArgs e)
        {
            if (txtUsuario.Text.Trim().Length == 0)
            {
                MessageBox.Show("Ingrese Usuario...", "Mensaje del Sistema");
                return;
            }
            DataTable OData = new DataTable();
            DataTable DataPassword = new DataTable();
            int Recno = 0;

            usuariosBL BL = new usuariosBL();
            tb_usuarios BE = new tb_usuarios();

            BE.usuar = txtUsuario.Text.Trim().ToLower();
            OData = BL.GetAll(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];
            //OData = GetAll("", txtUsuario.Text, 0);
            string LcClave = "";
            //LcClave = fungen.EncryptStr(txtClave.Text.Trim(), "key");
            //LcClave = VariablesPublicas.Encriptar(txtClave.Text.Trim(), "SI");
            LcClave = VariablesPublicas.Encripta(txtClave.Text.Trim());
            DataPassword = null;
            if (OData.Rows.Count > 0)
            {
                usuariosxprocesoBL BL1 = new usuariosxprocesoBL();
                tb_usuariosxproceso BE1 = new tb_usuariosxproceso();

                BE1.procesoid = TipoProceso;
                BE1.usuar = OData.Rows[0]["usuar"].ToString().Trim();
                BE1.password = LcClave;
                BE1.norden = 0;
                DataPassword = BL1.GetAll_U_P(VariablesPublicas.EmpresaID.ToString(), BE1).Tables[0];
                //DataPassword = BL1.GetAll_U_P(TipoProceso, OData.Rows[0]["codigo"], LcClave, 0, "");
                if (DataPassword.Rows.Count > 0)
                {
                    if (!(DataPassword.Rows[0]["password"].ToString().Trim() == Equivalencias.Left(LcClave.Trim(),20)))
                    //if (!(DataPassword.Rows[0]["password"].ToString().Trim() == LcClave.Trim()))
                    {
                        for (Recno = 0; Recno <= DataPassword.Rows.Count - 1; Recno++)
                        {
                            DataPassword.Rows[Recno].Delete();
                        }
                        DataPassword.AcceptChanges();
                    }
                }
                if (DataPassword.Rows.Count > 0)
                {
                    if (DataPassword.Rows[0]["destadousuario"].ToString() == "ACTIVO")
                    {
                        PasaIdentificacionDelegado(OData.Rows[0]["usuar"].ToString());
                        Close();
                    }
                    else
                    {
                        MessageBox.Show("El Usuario No esta Activo..." + "\r" + "Verifique con Administrador del Sistema...?", "Mensaje del Sistema");
                        txtClave.Focus();
                    }
                }
                else
                {
                    MessageBox.Show("Password Errado... Verifique?", "Mensaje del Sistema");
                    txtClave.Focus();
                    Intentos = Intentos + 1;
                }
            }
            else
            {
                MessageBox.Show("Usuario No Existe... Verifique?", "Mensaje del Sistema");
                Intentos = Intentos + 1;
            }

            if (Intentos == 3)
            {
                MessageBox.Show("Excedió el máximo de intentos permitidos...?", "Mensaje del Sistema");
                Close();
            }
        }
        private void Frm_Identificacion_Load(object sender, EventArgs e)
        {
            Label3.Text = "";
            btnCambiaClave.Enabled = false;
            DataTable Cursor01 = new DataTable();

            usuariosxprocesoBL BL = new usuariosxprocesoBL();
            tb_usuariosxproceso BE = new tb_usuariosxproceso();

            BE.procesoid = TipoProceso;
            BE.norden = 1;
            Cursor01 = BL.GetAll(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];
            if (Cursor01.Rows.Count > 0)
            {
                Label3.Text = Cursor01.Rows[0]["descripcion"].ToString().Trim();
                Label3.Visible = Label3.Text.Trim().Length > 0;
            }
            txtUsuario.Focus();
        }
        private void btnCambiaClave_Click(object sender, EventArgs e)
        {
            DataTable cursor01 = new DataTable();
            usuariosxprocesoBL BL = new usuariosxprocesoBL();
            tb_usuariosxproceso BE = new tb_usuariosxproceso();

            BE.procesoid = TipoProceso;
            BE.usuar = txtUsuario.Text.Trim().ToLower();
            //BE.password = fungen.EncryptStr(txtClave.Text.ToLower().Trim(),"key");
            //BE.password =  VariablesPublicas.Encriptar(txtClave.Text.Trim(), "SI");
            BE.password = VariablesPublicas.Encripta(txtClave.Text.Trim());
            BE.norden = 1;
            BE.login = txtUsuario.Text.Trim().ToLower();
            cursor01 = BL.GetAll_U_P(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];
            //cursor01 = IBL.GetAll_U_P(TipoProceso, "", txtClave.Text.Trim(), 1, txtUsuario.Text.Trim());
            if (cursor01.Rows.Count > 0)
            {
                Frm_CambiaClaveAccesoProceso tmpform = new Frm_CambiaClaveAccesoProceso();
                tmpform._LoginUsuario = txtUsuario.Text;
                tmpform._TipoProceso = TipoProceso;
                tmpform.Owner = this;
                tmpform.ShowDialog();
            }
            else
            {
                MessageBox.Show("Verifique usuario o Clave.. Datos Erróneos", "Mensaje del Sistema");
            }
        }
 public bool UsuariosProcesosInsertUpdated(string empresaid, tb_usuariosxproceso BE, DataTable TablaDatos)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         bool xreturn = true;
         int lcont = 0;
         //BE.ntipo = 0 Borra y Graba 1 Sólo Graba el Registro Actual
         if (BE.ntipo == 0)
         {
             using (SqlCommand cmd = new SqlCommand("gspTbUsuariosProceso_DELETED", cnx))
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@uprocesoid", SqlDbType.Char,4).Value =  BE.procesoid;
                 try
                 {
                     cnx.Open();
                     if (cmd.ExecuteNonQuery() > 0)
                     {
                         xreturn = true;
                     }
                     else
                     {
                         xreturn = false;
                     }
                     cnx.Close();
                 }
                 catch (Exception ex)
                 {
                     Sql_Error = ex.Message;
                     //throw new Exception(ex.Message);
                     xreturn = false;
                     cnx.Close();
                 }
             }
         }
         for (lcont = 0; lcont <= TablaDatos.Rows.Count - 1; lcont++)
         {
             using (SqlCommand cmd = new SqlCommand("gspTbUsuariosProceso_InsertUpdated", cnx))
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@uprocesoid", SqlDbType.Char, 4).Value = TablaDatos.Rows[lcont]["uprocesoid"];
                 cmd.Parameters.Add("@usuar", SqlDbType.Char, 15).Value = TablaDatos.Rows[lcont]["usuar"];
                 cmd.Parameters.Add("@password", SqlDbType.Char, 20).Value = Convert.ToString(TablaDatos.Rows[lcont]["password"]);
                 cmd.Parameters.Add("@firma", SqlDbType.VarChar, 200).Value = TablaDatos.Rows[lcont]["firma"];
                 try
                 {
                     cnx.Open();
                     if (cmd.ExecuteNonQuery() > 0)
                     {
                         xreturn = true;
                     }
                     else
                     {
                         xreturn = false;
                     }
                     cnx.Close();
                 }
                 catch (Exception ex)
                 {
                     Sql_Error = ex.Message;
                     //throw new Exception(ex.Message);
                     xreturn = false;
                     cnx.Close();
                 }
             }
         }
         return xreturn;
     }
 }
        public bool UsuariosProcesos_Replicar(string empresaid, tb_usuariosxproceso BE)
        {
            using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
            {
                try
                {
                    using (SqlCommand cmd = new SqlCommand("gspTbUsuariosProceso_REPLICAR", cnx))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add("@usuar", SqlDbType.Char, 15).Value = BE.usuar;
                        cmd.Parameters.Add("@procesoidorigen", SqlDbType.Char, 4).Value = BE.procesoid;

                        cnx.Open();
                        if (cmd.ExecuteNonQuery() > 0)
                        {
                            return true;
                        }
                        else
                        {
                            return false;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Sql_Error = ex.Message;
                    throw new Exception(ex.Message);
                }
            }
        }
        private void Frm_CambiaClaveAccesoProceso_Load(object sender, EventArgs e)
        {
            Label5.Visible = false;
            Label5.Text = "";
            FormBorderStyle = FormBorderStyle.Fixed3D;
            DataTable cursor02 = new DataTable();
            usuariosxprocesoBL BL = new usuariosxprocesoBL();
            tb_usuariosxproceso BE = new tb_usuariosxproceso();

            BE.procesoid = _TipoProceso;
            BE.norden = 1;
            cursor02 = BL.GetAll(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];
            //cursor02 = BL.GetAll(_TipoProceso, 1);
            if (cursor02.Rows.Count > 0)
            {
                Label5.Text = cursor02.Rows[0]["descripcion"].ToString();
                Label5.Visible = true;
            }
            MaximizeBox = false;
            MinimizeBox = false;

            usuariosxprocesoBL BL1 = new usuariosxprocesoBL();
            tb_usuariosxproceso BE1 = new tb_usuariosxproceso();

            BE1.procesoid = _TipoProceso;
            BE1.usuar = _LoginUsuario.ToLower();
            BE1.norden = 1;
            BE1.login = _LoginUsuario;
            Cursor01 = BL1.GetAll_U_P(VariablesPublicas.EmpresaID.ToString(), BE1).Tables[0];
            //Cursor01 = BL1.GetAll_U_P(_TipoProceso, "", "", 1, _LoginUsuario);
            if (Cursor01.Rows.Count > 0)
            {
                txtUsuario.Text = Cursor01.Rows[0]["usuar"].ToString().Trim() + "-" + Cursor01.Rows[0]["nomusuario"];
            }
            txtUsuario.Enabled = Cursor01.Rows.Count == 0;
        }
        private BindingSource NewMethodPr()
        {
            usuariosxprocesoBL BL = new usuariosxprocesoBL();
            tb_usuariosxproceso BE = new tb_usuariosxproceso();

            BE.norden = 1;
            DataTable table = BL.GetAll(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];
            DataRowCollection rows = table.Rows;

            object[] cell;
            Dictionary<string, string> dic = new Dictionary<string, string>();
            BindingSource binding = new BindingSource();

            foreach (DataRow item in rows)
            {
                cell = item.ItemArray;
                dic.Add(cell[0].ToString(), cell[0].ToString() + " - " + cell[1].ToString());
                cell = null;
            }
            binding.DataSource = dic;
            return binding;
        }
        private void btnReplicar_Click(object sender, EventArgs e)
        {
            if (dgOrdenes.CurrentRow != null)
            {
                string xmensaje = "Usuario :" + dgOrdenes.Rows[dgOrdenes.CurrentRow.Index].Cells["COLUMN2"].Value;

                string message = "Desea replicar datos de " + xmensaje + " En Todos los procesos del sistema...?" + '\r' + "La información de accesos del usuario será reemplazada";
                string caption = "Mensaje del Sistema";
                MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                DialogResult result;

                // Muestra el cuadro de mensaje.
                result = MessageBox.Show(this, message, caption, buttons, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                if (result == DialogResult.Yes)
                {
                    usuariosxprocesoBL BL = new usuariosxprocesoBL();
                    tb_usuariosxproceso BE = new tb_usuariosxproceso();

                    BE.usuar = dgOrdenes.Rows[dgOrdenes.CurrentRow.Index].Cells["COLUMN1"].Value.ToString().Trim();
                    BE.procesoid = dgOrdenes.Rows[dgOrdenes.CurrentRow.Index].Cells["COLUMN5"].Value.ToString().Trim();
                    if (!BL.UsuariosProcesos_Replicar(VariablesPublicas.EmpresaID.ToString(), BE))
                    //if (!BL.UsuariosProcesos_Replicar(dgOrdenes.Rows[dgOrdenes.CurrentRow.Index].Cells["COLUMN1"].Value, dgOrdenes.Rows[dgOrdenes.CurrentRow.Index].Cells["COLUMN5"].Value))
                    {
                        Frm_Class.ShowError(BL.Sql_Error, this);
                    }
                    else
                    {
                        MessageBox.Show("Proceso culminado satisfactoriamente", "Mensaje del Sistema");
                    }
                }
            }
        }
        public void Guardar()
        {
            int ncont = 0;
            dgOrdenes.EndEdit();
            oDetalle.AcceptChanges();
            for (ncont = 0; ncont <= oDetalle.Rows.Count - 1; ncont++)
            {
                oDetalle.Rows[ncont]["uprocesoid"] = cboProceso.SelectedValue;
            }
            usuariosxprocesoBL BL = new usuariosxprocesoBL();
            tb_usuariosxproceso BE = new tb_usuariosxproceso();

            BE.procesoid = cboProceso.SelectedValue.ToString().Trim();
            BE.ntipo = 0;
            if (BL.UsuariosProcesosInsertUpdated(VariablesPublicas.EmpresaID.ToString(), BE, oDetalle) == true)
            {
                HabilitarBotones(true);
                HabilitarControles(true);
                CargaData();
            }
            else
            {
                Frm_Class.ShowError(BL.Sql_Error, this);
            }
        }