public DataSet GetAll_paginacion(string empresaid, tb_60color BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTb60Color_SEARCH_paginacion", cnx))
         {
             DataSet ds = new DataSet();
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@moduloid", SqlDbType.Char, 4).Value = BE.moduloid;
                 cmd.Parameters.Add("@colorid", SqlDbType.Char, 3).Value = BE.colorid;
                 cmd.Parameters.Add("@posicion", SqlDbType.VarChar, 10).Value = BE.posicion;
             }
             try
             {
                 cnx.Open();
                 using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                 {
                     da.Fill(ds);
                 }
                 return ds;
             }
             catch (Exception ex)
             {
                 throw new Exception(ex.Message);
             }
         }
     }
 }
 public bool Delete(string empresaid, tb_60color BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTb60Color_DELETE", cnx))
         {
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@moduloid", SqlDbType.Char, 4).Value = BE.moduloid;
                 cmd.Parameters.Add("@colorid", SqlDbType.Char, 3).Value = BE.colorid;
             }
             try
             {
                 cnx.Open();
                 if (cmd.ExecuteNonQuery() > 0)
                 {
                     return true;
                 }
                 else
                 {
                     return false;
                 }
             }
             catch (Exception ex)
             {
                 throw new Exception(ex.Message);
             }
         }
     }
 }
 public bool Insert(string empresaid, tb_60color BE)
 {
     return tablaDA.Insert(empresaid, BE);
 }
 public DataSet GetReport(string empresaid, tb_60color BE)
 {
     return tablaDA.GetReport(empresaid, BE);
 }
 public DataSet GetAll_paginacion(string empresaid, tb_60color BE)
 {
     return tablaDA.GetAll_paginacion(empresaid, BE);
 }
 public bool Delete(string empresaid, tb_60color BE)
 {
     return tablaDA.Delete(empresaid, BE);
 }
        private void ValidaColor()
        {
            if (colorid.Text.Trim().Length > 0)
            {
                var BL = new tb_60colorBL();
                var BE = new tb_60color();
                var dt = new DataTable();

                BE.moduloid = moduloiddes.SelectedValue.ToString();
                if (moduloiddes.SelectedValue.ToString() == "0000")
                {
                    MessageBox.Show("Seleccione Almacen", "Information");
                    return;
                }
                BE.colorid = colorid.Text.Trim().PadLeft(3, '0');

                dt = BL.GetAll(EmpresaID, BE).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    colorid.Text = dt.Rows[0]["colorid"].ToString().Trim();
                    colorname.Text = dt.Rows[0]["colorname"].ToString().Trim();
                    generar_denominacion();
                }
                else
                {
                    colorid.Text = string.Empty;
                    colorname.Text = string.Empty;
                    generar_denominacion();
                }
            }
            else
            {
                colorid.Text = string.Empty;
                colorname.Text = string.Empty;
                generar_denominacion();
            }
        }
        private void ValidaColor()
        {
            if (colorid.Text.Trim().Length > 0)
            {
                tb_60colorBL BL = new tb_60colorBL();
                tb_60color BE = new tb_60color();
                DataTable dt = new DataTable();

                BE.moduloid = modulo;
                BE.colorid = colorid.Text.Trim().PadLeft(3, '0');

                dt = BL.GetAll(EmpresaID, BE).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    colorid.Text = dt.Rows[0]["colorid"].ToString().Trim();
                    colorname.Text = dt.Rows[0]["colorname"].ToString().Trim();
                    generar_denominacion();
                }
                else
                {
                    colorid.Text = "";
                    colorname.Text = "";
                    generar_denominacion();
                }
            }
            else
            {
                colorid.Text = "";
                colorname.Text = "";
                generar_denominacion();
            }
        }
        private void Insert()
        {
            try
            {
                if (colorname.Text.Trim().Length == 0)
                {
                    MessageBox.Show("Ingrese nombre de color", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    var BL = new tb_60colorBL();
                    var BE = new tb_60color();

                    BE.moduloid = modulo;
                    BE.colorname = colorname.Text.ToUpper();
                    BE.usuar = VariablesPublicas.Usuar.Trim();

                    if (BL.Insert(EmpresaID, BE))
                    {
                        MessageBox.Show("Datos grabados correctamente !!!", "Confirmación", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        procesado = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void Delete()
        {
            try
            {
                if (colorid.Text.Trim().Length != 3)
                {
                    MessageBox.Show("Falta Codigo color !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    var BL = new tb_60colorBL();
                    var BE = new tb_60color();
                    BE.moduloid = modulo;
                    BE.colorid = colorid.Text.Trim().PadLeft(3, '0');
                    BE.colorname = colorname.Text.ToUpper();
                    BE.usuar = VariablesPublicas.Usuar.Trim();

                    if (BL.Delete(EmpresaID, BE))
                    {
                        SEGURIDAD_LOG("E");
                        MessageBox.Show("Datos eliminado correctamente !!!", "Confirmación", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        NIVEL_FORMS();
                        limpiar_documento();
                        form_bloqueado(false);
                        data_Tablacolor();
                        btn_nuevo.Enabled = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void data_Tablacolor()
        {
            try
            {
                if (Tablacolor.Rows.Count > 0)
                {
                    Tablacolor.Rows.Clear();
                }
                var BL = new tb_60colorBL();
                var BE = new tb_60color();

                BE.moduloid = modulo;
                BE.colorname = txt_criterio.Text.Trim().ToUpper();

                Tablacolor = BL.GetAll(EmpresaID, BE).Tables[0];
                if (Tablacolor.Rows.Count > 0)
                {
                    btn_imprimir.Enabled = true;
                    gridcolor.DataSource = Tablacolor;
                    gridcolor.Rows[0].Selected = false;
                    gridcolor.Focus();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void ValidaColor_nuevo()
        {
            if (colorid.Text.Trim().Length != 3)
            {
                return;
            }
            var BL = new tb_60colorBL();
            var BE = new tb_60color();
            var dt = new DataTable();
            BE.moduloid = moduloiddes.SelectedValue.ToString();
            if (moduloiddes.SelectedValue.ToString() == "0000")
            {
                MessageBox.Show("Seleccione Almacen", "Information");
                return;
            }

            BE.colorid = colorid.Text.Trim();

            dt = BL.GetOne(EmpresaID, BE).Tables[0];
            if (dt.Rows.Count > 0)
            {
                mensaje.Text = "YA EXISTE";
                mensaje.ForeColor = Color.Red;
                colorname.Text = string.Empty;
            }
            else
            {
                mensaje.Text = "VALIDO";
                mensaje.ForeColor = Color.Green;
                colorid.Text = colorid.Text.Trim().ToUpper();
                form_bloqueado(true);
                btn_cancelar.Enabled = true;
                btn_grabar.Enabled = true;
            }
        }
        private void active_color()
        {
            try
            {
                var path = string.Empty;
                var directorios = Application.StartupPath.Split('\\');
                if (directorios.Length > 0)
                {
                    path = directorios[0] + "\\" + directorios[1];
                }
                var reportecolor = new CR_color();

                var BL = new tb_60colorBL();
                var BE = new tb_60color();
                var dt = new DataTable();
                BE.moduloid = moduloid.ToString();
                dt = BL.GetAll(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    reportecolor.DataDefinition.FormulaFields["empresaname"].Text = "'EMPRESA: " + VariablesPublicas.EmpresaName.Trim() + "'";
                    reportecolor.DataDefinition.FormulaFields["empresaruc"].Text = "'RUC: " + VariablesPublicas.EmpresaRuc.Trim() + "'";
                    reportecolor.SetDataSource(Movimiento_color());
                    crystalReportViewer1.ReportSource = reportecolor;
                    crystalReportViewer1.Show();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private DataTable Movimiento_color()
        {
            try
            {
                DtReporte = new DataTable("color");

                var BL = new tb_60colorBL();
                var BE = new tb_60color();

                BE.moduloid = moduloid.Trim();

                DtReporte = BL.GetReport(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];
                if (DtReporte != null)
                {
                    return DtReporte;
                }
                else
                {
                    return DtReporte;
                }
            }
            catch (Exception ex)
            {
                return null;
            }
        }
 public bool Update(string empresaid, tb_60color BE)
 {
     return tablaDA.Update(empresaid, BE);
 }
        private void ValidaColor()
        {
            if (colorid.Text.Trim().Length > 0)
            {
                var BL = new tb_60colorBL();
                var BE = new tb_60color();
                var dt = new DataTable();

                BE.moduloid = modulo;
                BE.colorid = colorid.Text.Trim().PadLeft(3, '0');

                dt = BL.GetAll(EmpresaID, BE).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    colorid.Text = dt.Rows[0]["colorid"].ToString().Trim();
                    colorname.Text = dt.Rows[0]["colorname"].ToString().Trim();
                }
                else
                {
                    colorid.Text = string.Empty;
                    colorname.Text = string.Empty;
                }
            }
            else
            {
                colorid.Text = string.Empty;
                colorname.Text = string.Empty;
            }
        }
        private void Update()
        {
            try
            {
                if (colorid.Text.Trim().Length != 3)
                {
                    MessageBox.Show("Falta Codigo color !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    if (colorname.Text.Trim().Length == 0)
                    {
                        MessageBox.Show("Ingrese nombre de color", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        var BL = new tb_60colorBL();
                        var BE = new tb_60color();
                        BE.moduloid = modulo;
                        BE.colorid = colorid.Text.Trim().PadLeft(3, '0');
                        BE.colorname = colorname.Text.ToUpper();
                        BE.usuar = VariablesPublicas.Usuar.Trim();

                        if (BL.Update(EmpresaID, BE))
                        {
                            SEGURIDAD_LOG("M");
                            MessageBox.Show("Datos modificado correctamente !!!", "Confirmación", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            procesado = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void form_cargar_datos(String posicion)
        {
            try
            {
                var BL = new tb_60colorBL();
                var BE = new tb_60color();
                var dt = new DataTable();

                BE.moduloid = modulo;
                if (undcodigoid.Text.Trim().Length > 0)
                {
                    BE.colorid = undcodigoid.Text.Trim().PadLeft(4, '0');
                }
                BE.posicion = posicion.Trim();

                dt = BL.GetAll_paginacion(EmpresaID, BE).Tables[0];

                if (dt.Rows.Count > 0)
                {
                    limpiar_documento();
                    ssModo = "EDIT";

                    undcodigoid.Text = dt.Rows[0]["colorid"].ToString().Trim();
                    unidmname.Text = dt.Rows[0]["colorname"].ToString().Trim();

                    btn_editar.Enabled = true;
                    btn_eliminar.Enabled = true;
                    btn_imprimir.Enabled = true;

                    btn_primero.Enabled = true;
                    btn_anterior.Enabled = true;
                    btn_siguiente.Enabled = true;
                    btn_ultimo.Enabled = true;

                    btn_buscar.Enabled = true;
                    btn_log.Enabled = true;
                    btn_salir.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void ValidaColor_nuevo()
        {
            if (colorid.Text.Trim().Length != 3)
            {
                return;
            }
            var BL = new tb_60colorBL();
            var BE = new tb_60color();
            var dt = new DataTable();
            BE.moduloid = modulo;
            BE.colorid = colorid.Text.Trim();

            dt = BL.GetOne(EmpresaID, BE).Tables[0];
            if (dt.Rows.Count > 0)
            {
                mensaje.Text = "YA EXISTE";
                mensaje.ForeColor = Color.Red;
                colorname.Text = string.Empty;
            }
            else
            {
                mensaje.Text = "VALIDO";
                mensaje.ForeColor = Color.Green;
                colorid.Text = colorid.Text.Trim().ToUpper();
                form_bloqueado(true);
                btn_cancelar.Enabled = true;
                btn_grabar.Enabled = true;
            }
        }