public void ValidaDetalle()
        {
            if (txtRuc.Text.Trim().Length > 0)
            {
                clienteBL BL = new clienteBL();
                tb_cliente BE = new tb_cliente();

                BE.nmruc = txtRuc.Text;
                DataTable tmptabla = BL.GetAll(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];

                if (tmptabla.Rows.Count == 0)
                {
                    txtRuc.Text = j_String;
                }
                else
                {
                    //txtRuc.Text = tmptabla.Rows[0]["nmruc"].ToString();
                    txtCtactename.Text = tmptabla.Rows[0]["ctactename"].ToString();
                    U_CargaDatos();
                }
            }
            else
            {
                txtRuc.Text = j_String;
            }
        }
 private void ValidaInsert_Update()
 {
     var BL = new clienteBL();
     var BE = new tb_cliente();
     var dt = new DataTable();
     BE.ctacte = Equivalencias.Right(txtcodigo.Text.Trim(),4);
     dt = BL.GetAll_CODdbf(VariablesPublicas.EmpresaID, BE).Tables[0];
     if (dt.Rows.Count > 0)
     {
         var n = Convert.ToInt32(dt.Rows[0]["cant"].ToString());
         if (n > 0)
         {
             Update_DBF();
         }
         else
         {
             Insert_DBF();
         }
     }
 }
        private void ValidaCliente()
        {
            if (nmruc.Text.Trim().Length > 0 || ctacte.Text.Trim().Length > 0)
            {
                var BL = new clienteBL();
                var BE = new tb_cliente();
                var dt = new DataTable();

                BE.ctacte = ctacte.Text.Trim().PadLeft(7, '0');
                if (nmruc.Text.Trim().Length > 0)
                {
                    BE.nmruc = nmruc.Text.Trim();
                }
                dt = BL.GetAll(EmpresaID, BE).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    ctacte.Text = dt.Rows[0]["ctacte"].ToString().Trim();
                    nmruc.Text = dt.Rows[0]["nmruc"].ToString().Trim();
                    ctactename.Text = dt.Rows[0]["ctactename"].ToString().Trim();
                    direc.Text = dt.Rows[0]["direc"].ToString().Trim();
                }
                else
                {
                    ctacte.Text = string.Empty;
                    nmruc.Text = string.Empty;
                    ctactename.Text = string.Empty;
                    direc.Text = string.Empty;

                    direcnume = string.Empty;
                    direcname.Text = string.Empty;
                    direcdeta.Text = string.Empty;
                    nmruc.Focus();
                }
            }
        }
        private void ValidaCliente()
        {
            if (dominioid.Text.Trim().Length > 0)
            {
                clienteBL BL = new clienteBL();
                tb_cliente BE = new tb_cliente();

                DataTable dt = new DataTable();

                String cta = ctacte.Text.Trim().PadLeft(7, '0');
                BE.ctacte = cta.ToString();
                ctacte.Text = cta.ToString();

                dt = BL.GetAll(EmpresaID, BE).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    ctacte.Text = dt.Rows[0]["ctacte"].ToString().Trim();
                    xNmruc = dt.Rows[0]["nmruc"].ToString().Trim();
                    xLocalDirec = dt.Rows[0]["localdirec"].ToString().Trim();
                    ctactename.Text = dt.Rows[0]["ctactename"].ToString().Trim();
                    direcnume.Text = dt.Rows[0]["direcnume"].ToString().Trim();
                }
                else
                {
                    ctacte.Text = "";
                    xNmruc = "";
                    xLocalDirec = "";
                    ctactename.Text = "";
                    direcnume.Text = "";
                }
            }
            else
            {
                ctacte.Text = "";
                xNmruc = "";
                xLocalDirec = "";
                ctactename.Text = "";
                direcnume.Text = "";
            }
        }
        private void ValidamosProcedencia()
        {
            clienteBL BL = new clienteBL();
            tb_cliente BE = new tb_cliente();

            DataTable dt = new DataTable();
            BE.ctacte = _ctacte.ToString();
            BE.filtro = "2";
            dt = BL.GetAll(EmpresaID, BE).Tables[0];

            if (dt.Rows.Count > 0)
            {
                if (modulo.ToString() != "0500") // Diferente Porque No Diferenciamos su Proveedor
                {
                    String set_ctacte = dt.Rows[0]["ctacte"].ToString().Trim();
                    String set_ctactename = dt.Rows[0]["ctactename"].ToString().Trim();
                    String set_paisname = dt.Rows[0]["paisname"].ToString().Trim();
                    String set_paisid = dt.Rows[0]["paisid"].ToString().Trim();

                    if (set_paisid == "9589") // Codigo de Peru
                    {
                        this.procedenciaid.SelectedIndex = 0;
                        txt_paisname.Text = set_paisname.ToString();
                    }
                    else
                    {
                        this.procedenciaid.SelectedIndex = 1;
                        txt_paisname.Text = set_paisname.ToString();
                    }
                }
                else
                {
                    this.procedenciaid.SelectedIndex = 0;
                    txt_paisname.Text = "PERÚ";
                }
            }
            else
            {

            }
        }
        private bool Validacion()
        {
            object xobjeto = null;
            int lc_cont = 0;
            string xmsgstring = "";
            DataTable tmptabla = new DataTable();
            dynamic xfill = "...";
            if (txtNumero.Text.Trim().Length == 0)
            {
                xmsgstring = xmsgstring + "\r\n" + "Ingrese Número de Comprobante...?";
                xobjeto = txtNumero;
            }
            //if (txtNumFin.Text.Trim().Length == 0)
            //{
            //    xmsgstring = xmsgstring + "\r\n" + "Ingrese Número de Comprobante Final...?";
            //    xobjeto = txtNumFin;
            //}
            if (txtRuc.Text.Trim().Length == 0)
            {
                xmsgstring = xmsgstring + "\r\n" + "Ingrese Cliente...?";
                xobjeto = txtRuc;
            }
            else
            {
                try
                {
                    clienteBL BL = new clienteBL();
                    tb_cliente BE = new tb_cliente();

                    BE.nmruc = txtRuc.Text;
                    if ((BL.GetAll(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0]).Rows.Count == 0)
                    {
                        xmsgstring = (xmsgstring + ("\r\n" + "Cliente no existe...?"));
                        xobjeto = txtRuc;
                    }
                }
                catch (Exception ex)
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            if (txtTipoventa.Text.Trim().Length == 0)
            {
                xmsgstring = xmsgstring + "\r\n" + "Ingrese Tipo Venta...?";
                xobjeto = txtTipoventa;
            }
            else
            {
            }
            Decimal vmntipocambio = VariablesPublicas.StringtoDecimal(txtTipocambio.Text);
            if (vmntipocambio == 0)
            {
                xmsgstring = xmsgstring + "\r\n" + "Ingrese Tipo de Cambio...?";
                xobjeto = fRegistro;
            }
            if (validaduplicidad())
            {
                xmsgstring = xmsgstring + xfill;
            }
            if ((txtGlosa.Text.Trim()).Trim().Length == 0)
            {
                xmsgstring = xmsgstring + "\r\n" + "Ingrese glosa...?";
                xobjeto = txtGlosa;
            }
            string xcodtmp = "";
            string xcodtmpr = "";
            double canttmp = 0;
            DataTable otabla = new DataTable();
            if (DetFacturacion.Rows.Count == 0)
            {
                xmsgstring = xmsgstring + "\r\n" + "Ingrese detalles al movimiento...?";
                xobjeto = GridExaminar;
            }
            if (xmsgstring.Trim().Length == 0)
            {
                for (lc_cont = 0; lc_cont <= DetFacturacion.Rows.Count - 1; lc_cont++)
                {
                    // Validando Rubro
                    xcodtmp = "";
                    if (!object.ReferenceEquals(DetFacturacion.Rows[lc_cont]["rubroid"], DBNull.Value))
                    {
                        xcodtmpr = DetFacturacion.Rows[lc_cont]["rubroid"].ToString();
                    }
                    if (xcodtmpr.Trim().Length == 0)
                    {
                        xcodtmpr = "...";
                    }
                    if (xcodtmpr.Trim().Length > 0)
                    {
                        try
                        {
                            tb_co_rubroventasBL BL = new tb_co_rubroventasBL();
                            tb_co_rubroventas BE = new tb_co_rubroventas();

                            BE.rubroid = xcodtmpr;
                            tmptabla = BL.GetAll(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];

                            if (tmptabla.Rows.Count == 0)
                            {
                                xmsgstring = (xmsgstring + ("\r\n" + "Rubro de Ventas no Existe...?"));
                                xobjeto = GridExaminar;
                            }
                            if (tmptabla.Rows.Count > 0)
                            {
                                if (tmptabla.Rows[0]["cuentaid"].ToString().Trim().Length != 7)
                                {
                                    xmsgstring = (xmsgstring + ("\r\n" + "Rubro no Asociado a una Cuenta Contable Válida...?"));
                                    xobjeto = GridExaminar;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            DevExpress.XtraEditors.XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    // Validando Item
                    if (!object.ReferenceEquals(DetFacturacion.Rows[lc_cont]["productid"], DBNull.Value))
                    {
                        xcodtmp = DetFacturacion.Rows[lc_cont]["productid"].ToString();
                    }
                    else
                    {
                        xcodtmp = "";
                    }
                    if (xcodtmp.Trim().Length > 0)
                    {
                        try
                        {
                            tb_pt_productoBL BL = new tb_pt_productoBL();
                            tb_pt_producto BE = new tb_pt_producto();
                            BE.productid = xcodtmp;
                            otabla = BL.GetAll(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];
                            if (otabla.Rows.Count == 0)
                            {
                                xmsgstring = "Código de Artículo no existe...?";
                                xobjeto = GridExaminar;
                            }
                        }
                        catch (Exception ex)
                        {
                            DevExpress.XtraEditors.XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    // Validando Precios
                    if (!object.ReferenceEquals(DetFacturacion.Rows[lc_cont]["precunit"], DBNull.Value))
                    {
                        canttmp = Convert.ToDouble(DetFacturacion.Rows[lc_cont]["precunit"]);
                    }
                    else
                    {
                        canttmp = 0;
                    }
                    if (canttmp <= 0)
                    {
                        xmsgstring = xmsgstring + "\r\n" + "Ingrese precio...?";
                        xobjeto = GridExaminar;
                    }
                    if (!object.ReferenceEquals(DetFacturacion.Rows[lc_cont]["cantidad"], DBNull.Value))
                    {
                        canttmp = Convert.ToDouble(DetFacturacion.Rows[lc_cont]["cantidad"]);
                    }
                    else
                    {
                        canttmp = 0;
                    }
                    if (canttmp <= 0)
                    {
                        xmsgstring = xmsgstring + "\r\n" + "Ingrese Cantidades...?";
                        xobjeto = GridExaminar;
                    }
                    // Validando Centro de Costo
                    DataTable tmptablarelacionccosto = new DataTable();
                    string vmccosto;
                    vmccosto = "...";
                    if (!(DetFacturacion.Rows[lc_cont]["cencosid"] == DBNull.Value))
                    {
                        if (DetFacturacion.Rows[lc_cont]["cencosid"].ToString().Trim().Length > 0)
                        {
                            vmccosto = DetFacturacion.Rows[lc_cont]["cencosid"].ToString();
                        }
                    }
                    try
                    {
                        centrocostoBL BL = new centrocostoBL();
                        tb_centrocosto BE = new tb_centrocosto();

                        if (xcodtmpr != "...")
                        {
                            BE.cencosdivi = Equivalencias.Mid(tmptabla.Rows[0]["cuentaid"].ToString(), 1, 1);
                            tmptablarelacionccosto = BL.GetAll(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];
                        }
                        if (tmptablarelacionccosto.Rows.Count > 0)
                        {
                            int qqqcont;
                            bool zhalladoccosto = false;
                            for (qqqcont = 0; (qqqcont <= (tmptablarelacionccosto.Rows.Count - 1)); qqqcont++)
                            {
                                if (tmptablarelacionccosto.Rows[qqqcont]["cencosid"].ToString() == vmccosto)
                                {
                                    zhalladoccosto = true;
                                    break;
                                }
                            }
                            if (!zhalladoccosto)
                            {
                                xmsgstring = (xmsgstring + ("\r\n" + "Centro de Costo no asociado al Rubro...?"));
                            }
                            else
                            {
                                for (qqqcont = 0; (qqqcont <= (GridExaminar.Rows.Count - 1)); qqqcont++)
                                {
                                    if (GridExaminar.Rows[qqqcont].Cells["asientoitems"].Value == DetFacturacion.Rows[lc_cont]["asientoitems"])
                                    {
                                        if (GridExaminar.CurrentCell == null)
                                        {
                                            GridExaminar.CurrentCell = GridExaminar.Rows[qqqcont].Cells["rubroid"];
                                        }
                                        GridExaminar.CurrentCell.ReadOnly = true;
                                        GridExaminar.CurrentCell = GridExaminar.Rows[qqqcont].Cells["cencosid"];
                                        GridExaminar.BeginEdit(true);
                                        GridExaminar.CurrentCell.ReadOnly = false;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    if ((xmsgstring.Trim().Length > 0))
                    {
                        break;
                    }
                }
            }
            if (xmsgstring.Trim().Length == 0)
            {
                if (u_n_opsel == 1 | (W_KEY0001 != txtRuc.Text + cboTipdoc.SelectedValue + txtSerie.Text + txtNumero.Text))
                {
                    tmptabla = null;
                    try
                    {
                        tb_co_VentascabBL BL = new tb_co_VentascabBL();
                        tb_co_Ventascab BE = new tb_co_Ventascab();

                        BE.nmruc = txtRuc.Text;
                        BE.tipdoc = cboTipdoc.SelectedValue.ToString();
                        BE.serdoc = txtSerie.Text;
                        BE.numdoc = txtNumero.Text;

                        tmptabla = BL.GetAll(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];

                        if (!(tmptabla == null))
                        {
                            if (tmptabla.Rows.Count > 0)
                            {
                                xmsgstring = ("Documento Ya registrado en Periodo : " + tmptabla.Rows[0]["perianio"] + " Registro Nº " +
                                             tmptabla.Rows[0]["diarioid"] + "/" +
                                             tmptabla.Rows[0]["perimes"] + "-" + tmptabla.Rows[0]["asiento"]);
                                xobjeto = txtNumero;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            if (xobjeto != null)
            {
                try
                {
                    xobjeto = Focus();
                }
                catch (Exception ex)
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            if (xmsgstring.Trim().Length > 0 & xmsgstring.Trim() != xfill)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(xmsgstring, "Validación de Datos", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            if (xmsgstring.Trim().Length == 0)
            {
                if (!PuedeEditarEliminar("Grabar Nuevo Registro", VariablesPublicas.PADL(fRegistro.Value.Month.ToString(), 2, "0")))
                {
                    xmsgstring = "...";
                }
            }
            if (xmsgstring.Trim().Length == 0)
            {
                return VariablesPublicas.U_ValidaFechaRegistroProvision(VariablesPublicas.perianio, txtMes.Text, fRegistro.Value);
            }
            else
            {
                return xmsgstring.Trim().Length == 0;
            }
        }
        public void ValidaDetalle()
        {
            if (txtdetalle.Text.Trim().Length > 0)
            {
                var BL = new clienteBL();
                var BE = new tb_cliente();

                BE.nmruc = txtdetalle.Text.Trim();
                tmptabla = BL.GetAll(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];

                if (BL.Sql_Error.Length == 0)
                {
                    if (tmptabla.Rows.Count > 0)
                    {
                        txtdcuentamayor.Text = tmptabla.Rows[0]["ctactename"].ToString();
                        U_CargaDatos();
                    }
                }
            }
        }
 protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         switch (filtro)
         {
             case "PS":
                 tb_cxc_vendorBL PSBL = new tb_cxc_vendorBL();
                 tb_cxc_vendor PSBE = new tb_cxc_vendor();
                 DataTable PSDT = new DataTable();
                 PSBE.ddnni = GridView1.SelectedRow.Cells[2].Text;
                 PSDT = PSBL.GetAll(Session["ssEmpresaID"].ToString(), PSBE).Tables[0];
                 txt_vendorid.Text = PSDT.Rows[0]["vendorid"].ToString();
                 txt_vendorname.Text = PSDT.Rows[0]["vendorname"].ToString();
                 break;
             case "PR":
                  clienteBL BL = new clienteBL();
                  tb_cliente BE = new tb_cliente();
                  DataTable dt = new DataTable();
                  BE.ctacte = GridView1.SelectedRow.Cells[1].Text;
                  dt = BL.GetAll(Session["ssEmpresaID"].ToString(), BE).Tables[0];
                  txt_ctacte.Text = dt.Rows[0]["ctacte"].ToString();
                  txt_ctactename.Text = dt.Rows[0]["ctactename"].ToString();
                  txt_ruc.Text = dt.Rows[0]["nmruc"].ToString();
                  direc_entrega.Text = dt.Rows[0]["direc"].ToString();
                  break;
             case "PA":
                  txt_articidold.Text = GridView1.SelectedRow.Cells[1].Text;
                  MetodoCargarLineal();
                  break;
         }
         UpdatePanel2.Update();
         ModalPopupExtender2.Hide();
     }
     catch (Exception ex)
     {
         ClientMessage(ex.Message);
     }
 }
        private void ObtenemosCab()
        {
            if (tipguia.Text.Trim().Length > 0)
            {
                var BL = new tb_ad_movimientosBL();
                var BE = new tb_ad_movimientos();

                var dt = new DataTable();
                BE.moduloid = modulo;
                BE.local = local;
                BE.tipodoc = tipguia.Text.ToString();
                BE.serdoc = serguia.Text.Trim();
                BE.numdoc = numguia.Text;

                dt = BL.GetOne(EmpresaID, BE).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    dt.Rows[0]["numdoc"].ToString().Trim();
                    fechguia.Value = Convert.ToDateTime(dt.Rows[0]["fechdoc"]);
                    ctacte.Text = dt.Rows[0]["ctacte"].ToString().Trim();
                    nmruc.Text = dt.Rows[0]["nmruc"].ToString().Trim();
                    ctactename.Text = dt.Rows[0]["ctactename"].ToString().Trim();
                    var BL2 = new clienteBL();
                    var BE2 = new tb_cliente();
                    var dt2 = new DataTable();
                    BE2.ctacte = ctacte.Text;
                    dt2 = BL2.GetAll(EmpresaID, BE2).Tables[0];
                    direc.Text = dt2.Rows[0]["direc"].ToString().Trim();

                    moneda.SelectedValue = dt.Rows[0]["moneda"].ToString().Trim();
                }
            }
        }
        private void CargaDatos()
        {
            var lc_cont = 0;
            var nposcolumnasortear = string.Empty;
            var PrvSotOrder = default(SortOrder);
            var zordenado = false;
            var xcodcliente = string.Empty;
            var xBuscar = string.Empty;
            if (GridExaminar.CurrentRow != null)
            {
                xcodcliente = GridExaminar.Rows[GridExaminar.CurrentRow.Index].Cells["ctacte"].Value.ToString();
            }
            if ( GridExaminar.SortedColumn != null )
            {
                nposcolumnasortear = GridExaminar.Columns[GridExaminar.SortedColumn.Index].Name;
                PrvSotOrder = GridExaminar.SortOrder;
                zordenado = true;
            }
            if (txtCadenaBuscar.Text.Trim().Length > 0)
            {
                xBuscar = txtCadenaBuscar.Text.Trim().ToUpper();
            }
            else
            {
                xBuscar = string.Empty;
            }
            try
            {
                var BL = new clienteBL();
                var BE = new tb_cliente();

                switch (cboCriterioBusqueda.SelectedItem.ToString())
                {
                    case "Razón Social":
                        BE.ctactename = xBuscar;
                        break;
                    case "Ruc":
                        BE.nmruc = xBuscar;
                        break;
                    case "Código":
                        BE.ctacte = xBuscar;
                        break;
                    default:
                        BE.ctactename = xBuscar;
                        break;
                }
                tablaclientes = BL.GetAll(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            GridExaminar.AutoGenerateColumns = false;
            GridExaminar.DataSource = tablaclientes;

            VariablesPublicas.PintaEncabezados(GridExaminar);
            if (zordenado)
            {
                if ( PrvSotOrder == SortOrder.Ascending )
                {
                    GridExaminar.Sort(GridExaminar.Columns[nposcolumnasortear], System.ComponentModel.ListSortDirection.Ascending);
                }
                else
                {
                    GridExaminar.Sort(GridExaminar.Columns[nposcolumnasortear], System.ComponentModel.ListSortDirection.Descending);
                }
            }
            else
            {
                GridExaminar.Sort(GridExaminar.Columns["ctacte"], System.ComponentModel.ListSortDirection.Ascending);
            }
            if ( GridExaminar.CurrentRow == null )
            {
                if ( GridExaminar.RowCount > 0 )
                {
                    GridExaminar.CurrentCell = GridExaminar.Rows[0].Cells["ctacte"];
                }
            }
            for (lc_cont = 0; lc_cont < GridExaminar.Rows.Count; lc_cont++)
            {
                if (GridExaminar.Rows[lc_cont].Cells["ctacte"].ToString() == xcodcliente)
                {
                    GridExaminar.CurrentCell = GridExaminar.Rows[lc_cont].Cells["ctacte"];
                    break;
                }
            }
        }
        private void ValidaCliente()
        {
            if (ctacte.Text.Trim().Length > 0)
            {
                clienteBL BL = new clienteBL();
                tb_cliente BE = new tb_cliente();
                DataTable dt = new DataTable();

                BE.ctacte = ctacte.Text.Trim().PadLeft(7, '0');

                dt = BL.GetAll(EmpresaID, BE).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    ctacte.Text = dt.Rows[0]["ctacte"].ToString().Trim();
                    ctactename.Text = dt.Rows[0]["ctactename"].ToString().Trim();
                }
                else
                {
                    ctacte.Text = "";
                    ctactename.Text = "";
                }
            }
        }
        private void btnsave_Click(object sender, EventArgs e)
        {
            if (U_Validacion())
            {
                try
                {
                    if (txtcanalvtaid.Text.Length == 0)
                    {
                        MessageBox.Show("Ingrese el Canal de Venta !!!");
                        return;
                    }

                    var BL = new clienteBL();
                    var BE = new tb_cliente();

                    BE.ctacte = txtcodigo.Text.Trim().ToUpper();
                    BE.ctactename = txtrazonsocial.Text.Trim().ToUpper();
                    BE.docuidentid = cboTipdoc.SelectedValue.ToString();
                    BE.nmruc = txtmnruc.Text.Trim().ToUpper();
                    if (rbnatural.Checked == true)
                    {
                        BE.tpperson = "01";
                    }
                    if (rbjuridica.Checked == true)
                    {
                        BE.tpperson = "02";
                    }
                    if (rbnodom.Checked == true)
                    {
                        BE.tpperson = "03";
                    }
                    BE.agerent = chkretencion.Checked;
                    BE.appat = txtapepat.Text.Trim().ToUpper();
                    BE.apmat = txtapemat.Text.Trim().ToUpper();
                    BE.nombr = txtnombres.Text.Trim().ToUpper();
                    BE.direc = txtdireccion.Text.Trim().ToUpper();
                    BE.paisid = txtpaisid.Text.Trim().ToUpper();
                    if (txtpaisid.Text.Trim() != "9589")
                    {
                        BE.ubige = "000000";
                    }
                    else
                    {
                        BE.ubige = cboDistr.SelectedValue.ToString();
                    }

                    BE.telef1 = txttelefono1.Text.Trim().ToUpper();
                    BE.email = txtemail.Text.Trim().ToUpper();
                    BE.urweb = txtweb.Text.Trim().ToUpper();
                    BE.telef2 = txttelefono2.Text.Trim().ToUpper();
                    BE.telef3 = txttelefono3.Text.Trim().ToUpper();
                    BE.contacto = txtContacto.Text.Trim().ToUpper();
                    BE.nctactedetraccion = txtctadetrac.Text.Trim().ToUpper();
                    BE.canalventaid = txtcanalvtaid.Text;
                    BE.replegaldni = txtreplegaldni.Text;
                    BE.replegalname = txtreplegalname.Text;

                    if (rbactivo.Checked == true)
                    {
                        BE.status = "0";
                    }
                    if (rbbaja.Checked == true)
                    {
                        BE.status = "1";
                    }
                    if (rbanulado.Checked == true)
                    {
                        BE.status = "9";
                    }
                    BE.usuar = VariablesPublicas.Usuar.Trim();

                    if (u_n_opsel == 1)
                    {
                        if (BL.Insert(VariablesPublicas.EmpresaID.ToString(), BE))
                        {
                        }
                        else
                        {
                            MessageBox.Show("Contacte con sistemas", "Mensaje del Sistema", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }

                        ValidaInsert_Update();
                    }
                    else
                    {
                        if (BL.Update(VariablesPublicas.EmpresaID.ToString(), BE))
                        {
                        }
                        else
                        {
                            MessageBox.Show("Contacte con sistemas", "Mensaje del Sistema", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }

                        ValidaInsert_Update();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                #region Direcciones
                //if (gridAnexos.RowCount > 0)
                //{
                //    try
                //    {
                //        var BL = new cliente_direcBL();
                //        var BE = new tb_cliente_direc();

                //        var Detalle = new tb_cliente_direc.Item();
                //        var ListaItems = new List<tb_cliente_direc.Item>();

                //        BE.ctacte = txtcodigo.Text.Trim().ToUpper();
                //        var item = 0;
                //        foreach (DataRow fila in TablaAnexos.Rows)
                //        {
                //            Detalle = new tb_cliente_direc.Item();
                //            item++;
                //            Detalle.direcnume = fila["direcnume"].ToString();
                //            Detalle.direcname = fila["direcname"].ToString();
                //            Detalle.direcdeta = fila["direcdeta"].ToString();
                //            Detalle.telef = fila["telef"].ToString();
                //            Detalle.ubige = fila["ubige"].ToString();
                //            Detalle.usuar = VariablesPublicas.Usuar.ToString();
                //            Detalle.status = "0";

                //            ListaItems.Add(Detalle);
                //        }
                //        BE.ListaItems = ListaItems;

                //        if (BL.Insert_XML(VariablesPublicas.EmpresaID.ToString(), BE))
                //        {
                //        }
                //        else
                //        {
                //            MessageBox.Show("Contacte con sistemas", "Mensaje del Sistema", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                //        }

                //        InsertDirecc_DBF();

                //    }
                //    catch (Exception ex)
                //    {
                //        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //    }
                //}
                #endregion

                #region Cuentas Bancarias
                if (gridBancos.RowCount > 0)
                {
                    try
                    {
                        var BL = new cliente_bancoBL();
                        var BE = new tb_cliente_banco();

                        var Detalle = new tb_cliente_banco.Item();
                        var ListaItems = new List<tb_cliente_banco.Item>();

                        BE.ctacte = txtcodigo.Text.Trim().ToUpper();
                        var item = 0;
                        foreach (DataRow fila in TablaBancos.Rows)
                        {
                            Detalle = new tb_cliente_banco.Item();

                            item++;

                            Detalle.bancoid = fila["bancoid"].ToString();
                            Detalle.ctactemn = fila["ctactemn"].ToString();
                            Detalle.ctacteme = fila["ctacteme"].ToString();
                            Detalle.usuar = VariablesPublicas.Usuar.ToString();

                            ListaItems.Add(Detalle);
                        }
                        BE.ListaItems = ListaItems;

                        if (BL.Insert_XML(VariablesPublicas.EmpresaID.ToString(), BE))
                        {
                            MessageBox.Show("Se grabó con éxito", "Mensaje del Sistema", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("Contacte con sistemas", "Mensaje del Sistema", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                #endregion

                U_CancelarEdicion(0);
            }
        }
        private void btndelete_Click(object sender, EventArgs e)
        {
            if (!(GridExaminar.CurrentRow == null))
            {
                if (MessageBox.Show("Desea eliminar datos de cliente ...?"
                                    + txtmnruc.Text.Trim() + "-" + txtnomdetalle.Text.Trim(), "Mensaje del Sistema", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                {
                    try
                    {
                        var BL = new clienteBL();
                        var BE = new tb_cliente();

                        BE.ctacte = GridExaminar.Rows[GridExaminar.CurrentRow.Index].Cells["ctacte"].Value.ToString();

                        if (BL.Delete(VariablesPublicas.EmpresaID.ToString(), BE))
                        {
                            GridExaminar.Rows.Remove(GridExaminar.CurrentRow);
                            GridExaminar.Refresh();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            U_RefrescaControles();
        }
        private void blanquear()
        {
            var BL = new clienteBL();
            var BE = new tb_cliente();

            try
            {
                txtcodigo.Text = BL.GetNextCod(VariablesPublicas.EmpresaID.ToString(), BE);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            txtmnruc.Text = string.Empty;
            rbjuridica.Checked = true;
            chkretencion.Checked = false;
            txtrazonsocial.Text = string.Empty;
            txtapepat.Text = string.Empty;
            txtapemat.Text = string.Empty;
            txtnombres.Text = string.Empty;
            txtdireccion.Text = string.Empty;
            txtContacto.Text = string.Empty;
            txtemail.Text = string.Empty;
            txtweb.Text = string.Empty;
            txttelefono1.Text = string.Empty;
            txttelefono2.Text = string.Empty;
            txttelefono3.Text = string.Empty;
            txtctadetrac.Text = string.Empty;
            txtpaisid.Text = string.Empty;
            txtpaisname.Text = string.Empty;
            lblDireccion.Text = string.Empty;
            rbactivo.Checked = false;
            rbbaja.Checked = false;
            rbanulado.Checked = false;
            txtCondicion.Text = string.Empty;
            txtcoddetalle.Text = string.Empty;
            txtRucAnexo.Text = string.Empty;
            txtnomdetalle.Text = string.Empty;
            txtcanalvtaid.Text = string.Empty;
            txtcanalvtaname.Text = string.Empty;
            txtreplegaldni.Text = string.Empty;
            txtreplegalname.Text = string.Empty;

            if (TablaAnexos != null)
            {
                TablaAnexos.AcceptChanges();
                if (TablaAnexos.Rows.Count > 0)
                {
                    for (vmncont = 0; vmncont < TablaAnexos.Rows.Count; vmncont++)
                    {
                        TablaAnexos.Rows[vmncont].Delete();
                    }
                    TablaAnexos.AcceptChanges();
                }
            }
            txtCodigob.Text = string.Empty;
            txtRucb.Text = string.Empty;
            txtCtactenameb.Text = string.Empty;
            if (TablaBancos != null)
            {
                TablaBancos.AcceptChanges();
                if (TablaBancos.Rows.Count > 0)
                {
                    for (vmncont = 0; vmncont < TablaBancos.Rows.Count; vmncont++)
                    {
                        TablaBancos.Rows[vmncont].Delete();
                    }
                    TablaBancos.AcceptChanges();
                }
            }
        }
        private void ValidaProveedor()
        {
            if (txtRuc.Text.Trim().Length > 0)
            {
                clienteBL BL = new clienteBL();
                tb_cliente BE = new tb_cliente();

                BE.nmruc = txtRuc.Text;
                DataTable tmptabla = BL.GetAll(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];

                if (tmptabla.Rows.Count == 0)
                {
                    xctacte = j_Ctacte;
                    txtRuc.Text = j_String;
                }
                else
                {
                    xtipopersona = tmptabla.Rows[0]["tpperson"].ToString();
                    xtipodocidentidad = tmptabla.Rows[0]["docuidentid"].ToString();
                    xctacte = tmptabla.Rows[0]["ctacte"].ToString();
                    txtRuc.Text = tmptabla.Rows[0]["nmruc"].ToString();
                    txtCtactename.Text = tmptabla.Rows[0]["ctactename"].ToString().Trim();
                    //txtDireccion.Text = tmptabla.Rows[0]["direc"].ToString().Trim();
                    xdirec = tmptabla.Rows[0]["direc"].ToString().Trim();
                    xubige = tmptabla.Rows[0]["ubige"].ToString().Trim();
                    //cboDpto.SelectedValue = Equivalencias.Left(xubige, 2);
                    //LlenarProvi(cboProv, cboDistr, cboDpto.SelectedValue.ToString());
                    //LlenarDistr(cboDistr, cboProv.SelectedValue.ToString());

                    //cboProv.SelectedValue = Equivalencias.Left(xubige, 4);
                    //cboDistr.SelectedValue = xubige;

                    if (object.ReferenceEquals(tmptabla.Rows[0]["agerent"], DBNull.Value))
                    {
                        rbagenteretencionsi.Checked = false;
                        rbagenteretencionno.Checked = true;
                    }
                    else
                    {
                        rbagenteretencionsi.Checked = Convert.ToBoolean(tmptabla.Rows[0]["agerent"]) == true;
                        rbagenteretencionno.Checked = Convert.ToBoolean(tmptabla.Rows[0]["agerent"]) == false;
                    }

                    if (object.ReferenceEquals(tmptabla.Rows[0]["buencontr"], DBNull.Value))
                    {
                        rbbuencontribuyentesi.Checked = false;
                        rbbuencontribuyenteno.Checked = true;
                    }
                    else
                    {
                        rbbuencontribuyentesi.Checked = Convert.ToBoolean(tmptabla.Rows[0]["buencontr"]) == true;
                        rbbuencontribuyenteno.Checked = Convert.ToBoolean(tmptabla.Rows[0]["buencontr"]) == false;
                    }

                    if (object.ReferenceEquals(tmptabla.Rows[0]["buencontr"], DBNull.Value))
                    {
                        rbpercepcionsi.Checked = false;
                        rbpercepcionno.Checked = true;
                    }
                    else
                    {
                        rbpercepcionsi.Checked = Convert.ToBoolean(tmptabla.Rows[0]["agenperc"]) == true;
                        rbpercepcionno.Checked = Convert.ToBoolean(tmptabla.Rows[0]["agenperc"]) == false;
                    }
                }
            }
            else
            {
                xctacte = j_Ctacte;
                txtRuc.Text = j_String;
            }
        }
        private void ValControls()
        {
            var BL = new clienteBL();
            var BE = new tb_cliente();
            var dt = new DataTable();

            BE.defacliepub = true;
            dt = BL.GetAll(EmpresaID, BE).Tables[0];
            if (tipodoc.SelectedValue.ToString() == "FA" ||
                tipodoc.SelectedValue.ToString() == "TK")
            {
                btnextraersunat.Image = global::BapFormulariosNet.Properties.Resources.go_sunat1;
                lblruc.Text = "RUC:";
                lbltitulo.Text = "FACTURA";
                nmruc.MaxLength = 11;
                lbltitulo.Location = new Point(422, 9);
                tip_operacion = "01";

                if (dt.Rows.Count > 0)
                {
                    ctacte.Text = dt.Rows[0]["ctacte"].ToString();
                    ctactename.Text = dt.Rows[0]["ctactename"].ToString();
                }
                else
                {
                    ctacte.Text = string.Empty;
                    ctactename.Text = string.Empty;
                }

                if (tipodoc.SelectedValue.ToString() == "TK")
                {
                    lblruc.Text = "DNI/RUC:";
                    lbltitulo.Text = "TICKET";
                    lbltitulo.Location = new Point(422, 9);
                }
            }
            else
            {
                if (tipodoc.SelectedValue.ToString() == "BV")
                {
                    btnextraersunat.Image = global::BapFormulariosNet.Properties.Resources.go_reniec;
                    lblruc.Text = "DNI:";
                    lbltitulo.Text = "BOLETA";
                    nmruc.MaxLength = 8;
                    lbltitulo.Location = new Point(422, 9);
                    tip_operacion = "01";

                    if (dt.Rows.Count > 0)
                    {
                        ctacte.Text = dt.Rows[0]["ctacte"].ToString();
                        ctactename.Text = dt.Rows[0]["ctactename"].ToString();
                    }
                    else
                    {
                        ctacte.Text = string.Empty;
                        ctactename.Text = string.Empty;
                    }
                }
                else
                {
                    if (tipodoc.SelectedValue.ToString() == "NC")
                    {
                        lblruc.Text = "DNI/RUC:";
                        lbltitulo.Text = "NOTA DE CREDITO";
                        lbltitulo.Location = new Point(350, 9);
                        tip_operacion = "05";
                    }
                }
            }
        }
        private void ValidaProveedorAval()
        {
            if (txtRucAval.Text.Trim().Length > 0)
            {
                clienteBL BL = new clienteBL();
                tb_cliente BE = new tb_cliente();

                BE.nmruc = txtRucAval.Text;
                DataTable tmptabla = BL.GetAll(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];

                if (tmptabla.Rows.Count == 0)
                {
                    txtRucAval.Text = j_String;
                }
                else
                {
                    xctacteaval = tmptabla.Rows[0]["ctacte"].ToString();
                    txtRucAval.Text = tmptabla.Rows[0]["nmruc"].ToString().Trim();
                    txtCtactenameAval.Text = tmptabla.Rows[0]["ctactename"].ToString().Trim();
                    txtDireccionAval.Text = tmptabla.Rows[0]["direc"].ToString().Trim();
                    txtTelefAval.Text = tmptabla.Rows[0]["telef1"].ToString().Trim();
                }
            }
            else
            {
                txtRuc.Text = j_String;
            }
        }
        private void Update()
        {
            var BL = new clienteBL();
            var BE = new tb_cliente();

            if (BL.Update2(EmpresaID, BE))
            {
                MessageBox.Show("Datos Modificados Correctamente !!!", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information);

                form_bloqueado(false);
                btn_nuevo.Enabled = true;
                btn_imprimir.Enabled = true;
                btn_salir.Enabled = true;
                btn_grabar.Enabled = false;
            }
        }
    private void data_gridRazonSocial()
    {
        clienteBL BL = new clienteBL();
        tb_cliente BE = new tb_cliente();

        switch (cbo_filtro.SelectedValue)
        {
            case "01":
                BE.ctacte = txt_filter.Text.Trim().ToUpper();
                break;
            case "02":
                BE.ctactename = txt_filter.Text.Trim().ToUpper();
                break;
            default:
                //**
                break;
        }
        try
        {
            //Eliminar Columnas Actuales(Opcional):
            GridView1.Columns.Clear();
            GridView1.Width = 550;
            //Objeto Columna:
            CommandField image;
            //Crear Columna:
            image = new CommandField();
            image.ButtonType = ButtonType.Image;
            image.SelectImageUrl = "~/Images/go-search.png";
            image.ShowSelectButton = true;
            image.ItemStyle.Width = 10;
            image.ItemStyle.Wrap = true;
            GridView1.Columns.Add(image);

            BoundField DDNNI;
            DDNNI = new BoundField();
            DDNNI.DataField = "ctacte";
            DDNNI.HeaderText = "CODIGO";
            DDNNI.ItemStyle.Width = 80;
            GridView1.Columns.Add(DDNNI);

            BoundField NOMBR;
            NOMBR = new BoundField();
            NOMBR.DataField = "ctactename";
            NOMBR.HeaderText = "NOMBRES";
            NOMBR.ItemStyle.Width = 250;
            GridView1.Columns.Add(NOMBR);

            GridView1.DataSource = BL.GetAll(Session["ssEmpresaID"].ToString(), BE);
            GridView1.DataBind();
            GridView1.Visible = true;
        }
        catch (Exception ex)
        {
            ClientMessage(ex.Message);
        }
    }
        private void ValidaProveedor()
        {
            sw_novaluechange = true;
            Int16 lc_cont = default(Int16);
            bool zhallado = false;
            string VMNROITEM = Examinar.Rows[Examinar.CurrentRow.Index].Cells["asientoitems"].Value.ToString();
            string xcodartic = "..";
            if ((!object.ReferenceEquals(Examinar.Rows[Examinar.CurrentRow.Index].Cells["nmruc"].Value, DBNull.Value)))
            {
                xcodartic = Examinar.Rows[Examinar.CurrentRow.Index].Cells["nmruc"].Value.ToString();
            }
            if (xcodartic.Trim().Length == 0)
            {
                tmpTablaContable.Rows[lc_cont]["nmruc"] = "";
                tmpTablaContable.Rows[lc_cont]["ctactename"] = "";
                zhallado = true;
            }
            else
            {
                clienteBL BL = new clienteBL();
                tb_cliente BE = new tb_cliente();

                BE.nmruc = xcodartic;
                tmptabla = BL.GetAll(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];
                for (lc_cont = 0; lc_cont <= tmpTablaContable.Rows.Count - 1; lc_cont++)
                {
                    if (tmpTablaContable.Rows[lc_cont]["asientoitems"].ToString() == VMNROITEM)
                    {
                        if (tmptabla.Rows.Count > 0)
                        {
                            tmpTablaContable.Rows[lc_cont]["nmruc"] = tmptabla.Rows[0]["nmruc"];
                            tmpTablaContable.Rows[lc_cont]["ctactename"] = tmptabla.Rows[0]["ctactename"];
                            zhallado = true;
                            break;
                        }
                    }
                }
            }
            if (!zhallado)
            {
                Examinar.Rows[Examinar.CurrentRow.Index].Cells["nmruc"].Value = j_detalle;
            }
            Examinar.Refresh();
            sw_novaluechange = false;
        }
        private void ValidaProveedor()
        {
            DataTable tmtabla = null;
            string xcodmotivo = "..";
            if (txtRuc.Text.Trim().Length > 0)
            {
                xcodmotivo = txtRuc.Text.Trim();
            }
            clienteBL BL = new clienteBL();
            tb_cliente BE = new tb_cliente();

            BE.nmruc = xcodmotivo;
            tmtabla = BL.GetAll(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];
            if (tmtabla.Rows.Count == 0)
            {
                txtRuc.Text = j_String;
            }
            else
            {
                txtCtacte.Text = tmtabla.Rows[0]["ctacte"].ToString().Trim();
                txtRuc.Text = tmtabla.Rows[0]["nmruc"].ToString();
                lblnomprov.Text = tmtabla.Rows[0]["ctactename"].ToString();
            }
        }
        public void ValidaDetalle()
        {
            if (txtDetalle.Text.Trim().Length > 0)
            {
                clienteBL BL = new clienteBL();
                tb_cliente BE = new tb_cliente();

                BE.nmruc = txtDetalle.Text.Trim();
                tmptabla = BL.GetAll(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];
                //tmptabla = ocapa.cag1000_CONSULTA(GlobalVars.GetInstance.CompanyGeneral, txtdetalle.Text, "", "", "", "", "", "", 1, "", 0, "", "");
                if (BL.Sql_Error.Length == 0)
                {
                    if (tmptabla.Rows.Count > 0)
                    {
                        txtNomdetalle.Text = tmptabla.Rows[0]["ctactename"].ToString().Trim();
                        U_CargaDatos();
                    }
                }
            }
        }
        private void ValidaProveedor()
        {
            if (txtRuc.Text.Trim().Length > 0)
            {
                clienteBL BL = new clienteBL();
                tb_cliente BE = new tb_cliente();

                BE.nmruc = txtRuc.Text;
                DataTable tmptabla = BL.GetAll(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];

                if (tmptabla.Rows.Count == 0)
                {
                    txtRuc.Text = j_String;
                }
                else
                {
                    xtipopersona = tmptabla.Rows[0]["tpperson"].ToString();
                    xtipodocidentidad = tmptabla.Rows[0]["docuidentid"].ToString();
                    xctacte = tmptabla.Rows[0]["ctacte"].ToString();
                    txtRuc.Text = tmptabla.Rows[0]["nmruc"].ToString();
                    txtCtactename.Text = tmptabla.Rows[0]["ctactename"].ToString();
                    xdirec = tmptabla.Rows[0]["direc"].ToString();
                    xubige = tmptabla.Rows[0]["ubige"].ToString();
                }
            }
            else
            {
                txtRuc.Text = j_String;
            }
        }
        void llenar_GridExaminar()
        {
            try
            {
                clienteBL BL = new clienteBL();
                tb_cliente BE = new tb_cliente();

                switch (cboCriterioBusqueda.SelectedItem.ToString())
                {
                    case "Razón Social":
                        BE.ctactename = txtCadenaBuscar.Text.Trim().ToUpper();
                        break;
                    case "Ruc":
                        BE.nmruc = txtCadenaBuscar.Text.Trim().ToUpper();
                        break;
                    case "Código":
                        BE.ctacte = txtCadenaBuscar.Text.Trim().ToUpper();
                        break;
                    default:
                        BE.ctactename = txtCadenaBuscar.Text.Trim().ToUpper();
                        break;
                }

                //Sw_LOad = false;
                if (GridExaminar.RowCount > 0)
                {
                    GridExaminar.Focus();
                    GridExaminar.BeginEdit(true);
                }
                GridExaminar.AutoGenerateColumns = false;
                GridExaminar.DataSource = BL.GetAll(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];
                U_pINTAR();
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public void ValidaDetalle()
        {
            sw_novaluechange = true;
            Int16 lc_cont = default(Int16);
            bool zhallado = false;
            string xcodartic = "..";
            if (txtRuc.Text.Trim().Length > 0)
            {
                xcodartic = txtRuc.Text;
            }
            if (xcodartic.Trim().Length == 0)
            {
            }
            else
            {
                clienteBL BL = new clienteBL();
                tb_cliente BE = new tb_cliente();

                BE.nmruc = xcodartic;
                tmptabla = BL.GetAll(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];
                //tmptabla = ocapa.cag1000_CONSULTA(GlobalVars.GetInstance.Company, xcodartic, "", "", "", "", "", "", 1, "", 0, "", "");
                if (BL.Sql_Error.Length == 0)
                {
                    if (tmptabla.Rows.Count > 0)
                    {
                        txtRuc.Text = tmptabla.Rows[lc_cont]["nmruc"].ToString();
                        txtCtactename.Text = tmptabla.Rows[lc_cont]["ctactename"].ToString();
                        zhallado = true;
                    }
                }
            }
            if (!zhallado)
            {
                txtRuc.Text = j_ruc;
            }
            else
            {
                AnexaDetalle();
            }
            sw_novaluechange = false;
            txtRuc.Focus();
        }
        private void ValidamosProcedencia()
        {
            var BL = new clienteBL();
            var BE = new tb_cliente();

            var dt = new DataTable();
            BE.ctacte = _ctacte.ToString();
            BE.filtro = "2";
            dt = BL.GetAll(EmpresaID, BE).Tables[0];

            if (dt.Rows.Count > 0)
            {
                if (moduloiddes.SelectedValue.ToString() != "0500")
                {
                    dt.Rows[0]["ctacte"].ToString().Trim();
                    dt.Rows[0]["ctactename"].ToString().Trim();
                    var set_paisname = dt.Rows[0]["paisname"].ToString().Trim();
                    var set_paisid = dt.Rows[0]["paisid"].ToString().Trim();

                    if (set_paisid == "9589")
                    {
                        procedenciaid.SelectedIndex = 0;
                        txt_paisname.Text = set_paisname.ToString();
                    }
                    else
                    {
                        procedenciaid.SelectedIndex = 1;
                        txt_paisname.Text = set_paisname.ToString();
                    }
                }
                else
                {
                    procedenciaid.SelectedIndex = 0;
                    txt_paisname.Text = "PERÚ";
                }
            }
        }
        public void ValidaDetalle()
        {
            sw_novaluechange = true;
            Int16 lc_cont = default(Int16);
            bool zhallado = false;
            string xcodartic = "..";
            if (txtRuc.Text.Trim().Length > 0)
            {
                xcodartic = txtRuc.Text;
            }
            if (xcodartic.Trim().Length == 0)
            {
                txtCtactename.Text = "";
                zhallado = true;
            }
            else
            {
                clienteBL BL = new clienteBL();
                tb_cliente BE = new tb_cliente();

                BE.nmruc = xcodartic;
                tmptabla = BL.GetAll(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];
                if (tmptabla.Rows.Count > 0)
                {
                    xctacte = tmptabla.Rows[lc_cont]["ctacte"].ToString();
                    txtRuc.Text = tmptabla.Rows[lc_cont]["nmruc"].ToString();
                    txtCtactename.Text = tmptabla.Rows[lc_cont]["ctactename"].ToString().Trim();
                    zhallado = true;
                }
            }
            if (!zhallado)
            {
                txtRuc.Text = j_ruc;
            }
            sw_novaluechange = false;
        }
        private bool Validacion_Grabar()
        {
            object xobjeto = null;
            int lc_cont = 0;
            string xmsgstring = "";
            DataTable tmptabla = new DataTable();
            dynamic xfill = "###...";
            if (txtCuentaid.Text.Trim().Length == 0)
            {
                xmsgstring = (xmsgstring + ("\r\n" + "Configure Cuenta para retención del IGV !!!"));
                xobjeto = txtCuentaid;
            }
            //if (txtCuentaidP.Text.Trim().Length == 0)
            //{
            //    if (rbnPagos.Checked == true | rbnLetras.Checked == true)
            //    {
            //        xmsgstring = (xmsgstring + ("\r\n" + "Configure Cuenta para el pago o canje en letras !!!"));
            //        xobjeto = txtCuentaidP;
            //    }
            //}
            if (txtRuc.Text.Trim().Length == 0)
            {
                xmsgstring = (xmsgstring + ("\r\n" + "Ingrese Proveedor !!!"));
                xobjeto = txtRuc;
            }
            else
            {
                try
                {
                    clienteBL BL = new clienteBL();
                    tb_cliente BE = new tb_cliente();

                    BE.nmruc = txtRuc.Text.Trim();
                    tmptabla = BL.GetAll(VariablesPublicas.EmpresaID, BE).Tables[0];
                    if ((BL.Sql_Error.Length > 0))
                    {
                        Frm_Class.ShowError(("Error al validar datos de proveedor" + ("\r\n" + BL.Sql_Error)), this);
                        return false;
                    }
                    if ((tmptabla.Rows.Count == 0))
                    {
                        xmsgstring = (xmsgstring + ("\r\n" + "Proveedor no existe"));
                        xobjeto = txtRuc;
                    }
                    //if ((BL.GetAll(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0]).Rows.Count == 0)
                    //{
                    //    xmsgstring = (xmsgstring + ('\r' + "Proveedor no existe !!!"));
                    //    xobjeto = txtRuc;
                    //}
                    else
                    {
                        if ((!object.ReferenceEquals(tmptabla.Rows[0]["agerent"], DBNull.Value)))
                        {
                            if (Convert.ToBoolean(tmptabla.Rows[0]["agerent"]))
                            {
                                xmsgstring = (xmsgstring + ("\r\n" + "No se puede aplicar retención sobre un Agente de Retención"));
                                xobjeto = txtRuc;
                            }
                        }
                        if ((!object.ReferenceEquals(tmptabla.Rows[0]["buencontr"], DBNull.Value)))
                        {
                            if (Convert.ToBoolean(tmptabla.Rows[0]["buencontr"]))
                            {
                                xmsgstring = (xmsgstring + ("\r\n" + "No se puede aplicar retención sobre un buen contribuyente"));
                                xobjeto = txtRuc;
                            }
                        }
                        if ((!object.ReferenceEquals(tmptabla.Rows[0]["agenperc"], DBNull.Value)))
                        {
                            if (Convert.ToBoolean(tmptabla.Rows[0]["agenperc"]))
                            {
                                xmsgstring = (xmsgstring + ("\r\n" + "No se puede aplicar retención sobre un Agente de Percepción"));
                                xobjeto = txtRuc;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            decimal vmncambio = VariablesPublicas.StringtoDecimal(txtTipocambio.Text);
            if (vmncambio == 0)
            {
                xmsgstring = (xmsgstring + ("\r\n" + "Ingrese Tipo de Cambio !!!"));
                xobjeto = fRegistro;
            }

            if ((txtGlosa.Text.Trim()).Trim().Length == 0)
            {
                xmsgstring = (xmsgstring + ("\r\n" + "Ingrese glosa !!!"));
                xobjeto = txtGlosa;
            }
            //if ((txtNumOpe.Text.Trim()).Trim().Length == 0)
            //{
            //    xmsgstring = (xmsgstring + ("\r\n" + "Ingrese Número Cheque u Operación !!!"));
            //    xobjeto = txtNumOpe;
            //}
            decimal montoretencion = VariablesPublicas.StringtoDecimal(txtImpRetencion.Text);
            if (montoretencion == 0)
            {
                xmsgstring = (xmsgstring + ("\r\n" + "Click en Botón Cálcular Retención !!!"));
                xobjeto = btnCalcular;
            }
            if ((xmsgstring.Trim().Length == 0))
            {
                for (lc_cont = 0; (lc_cont <= (DetFacturacion.Rows.Count - 1)); lc_cont++)
                {
                    if (((Convert.ToDecimal(DetFacturacion.Rows[lc_cont]["importeretencionsoles"]) == 0))) //&& (Convert.ToDecimal(DetFacturacion.Rows[lc_cont]["impretencion1"]) == 0)))
                    {
                        xmsgstring = (xmsgstring + ("\r\n" + "Ingrese Retención del documento"));
                    }
                    if (((DetFacturacion.Rows[lc_cont]["tipdoc"].ToString().Trim().Length > 0) && (DetFacturacion.Rows[lc_cont]["numdoc"].ToString().Trim().Length > 0)))
                    {
                        tb_co_ComprascabBL BLCO = new tb_co_ComprascabBL();
                        tb_co_Comprascab BECO = new tb_co_Comprascab();

                        BECO.nmruc = txtRuc.Text.Trim();
                        BECO.tipodoc = DetFacturacion.Rows[lc_cont]["tipdoc"].ToString();
                        BECO.serdoc = DetFacturacion.Rows[lc_cont]["serdoc"].ToString();
                        BECO.numdoc = DetFacturacion.Rows[lc_cont]["numdoc"].ToString();
                        tmptabla = BLCO.GetAll(VariablesPublicas.EmpresaID.ToString(), BECO).Tables[0];
                        //tmptabla = ocapa.KAG0300_consulta(GlobalVars.GetInstance.Company, "", "", "", "", "", TXTCODCLIENTE.Text, DetFacturacion.Rows[lc_cont]["tipdoc_3a"], DetFacturacion.Rows[lc_cont]["numdoc"].Substring(0, 4), DetFacturacion.Rows[lc_cont]["numdoc"].Substring(5, 8));
                        if ((BLCO.Sql_Error.Length > 0))
                        {
                            Frm_Class.ShowError(("Error al validar documento de Compra " + ("\r\n" + BLCO.Sql_Error)), this);
                            return false;
                        }
                        if ((tmptabla.Rows.Count > 0))
                        {
                            if ((Convert.ToBoolean(tmptabla.Rows[0]["afecdetraccion"]) == true))
                            {
                                xmsgstring = (xmsgstring + "\r\n"
                                            + "Asiento R/C N°: " + tmptabla.Rows[0]["diarioid"].ToString() + "/" + tmptabla.Rows[0]["perimes"].ToString() + "-" + tmptabla.Rows[0]["asiento"].ToString() + "\r\n"

                                            + "Comprobante N°: "
                                            + DetFacturacion.Rows[lc_cont]["tipdoc"].ToString() + "/" + DetFacturacion.Rows[lc_cont]["serdoc"].ToString() + "-" + DetFacturacion.Rows[lc_cont]["numdoc"].ToString() + "\r\n"
                                            + "Tiene Detracción ... Imposible Aplicar Retención");
                            }
                        }
                    }
                }
            }

            if (xmsgstring.Trim().Length == 0)
            {
                //if (u_n_opsel == 1 | (W_KEY0001 != cboTipdoc.SelectedValue.ToString().Trim() + txtSerie.Text.Trim() + txtNumero.Text.Trim()))
                //{
                //    tmptabla = null;
                //    try
                //    {
                //        tb_co_retencionescabBL BL = new tb_co_retencionescabBL();
                //        tb_co_retencionescab BE = new tb_co_retencionescab();

                //        //BE.nmruc = txtRuc.Text;
                //        BE.tipdoc = cboTipdoc.SelectedValue.ToString().Trim();
                //        BE.serdoc = txtSerie.Text.Trim();
                //        BE.numdoc = txtNumero.Text.Trim();

                //        tmptabla = BL.GetAll(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];

                //        if (!(tmptabla == null))
                //        {
                //            if (tmptabla.Rows.Count > 0)
                //            {
                //                xmsgstring = ("Documento Ya registrado en Periodo : " + tmptabla.Rows[0]["perianio"] + " Registro Nº "
                //                            + tmptabla.Rows[0]["perimes"] + "-" + tmptabla.Rows[0]["asiento"]);
                //                xobjeto = txtNumero;
                //            }
                //        }
                //    }
                //    catch (Exception ex)
                //    {
                //        DevExpress.XtraEditors.XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //    }
                //}
            }
            if (!(xobjeto == null))
            {
                try
                {
                    xobjeto = Focus();
                }
                catch (Exception ex)
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            if (xmsgstring.Trim().Length > 0 & xmsgstring.Trim() != xfill)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(xmsgstring, "Validación de Datos", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            if (xmsgstring.Trim().Length == 0)
            {
                if (!PuedeEditarEliminar("Grabar Nuevo Registro", VariablesPublicas.PADL(fRegistro.Value.Month.ToString(), 2, "0")))
                {
                    xmsgstring = "...";
                }
            }
            if (xmsgstring.Trim().Length == 0)
            {
                return VariablesPublicas.U_ValidaFechaRegistroProvision(VariablesPublicas.perianio, txtMes.Text, fRegistro.Value);
            }
            else
            {
                return xmsgstring.Trim().Length == 0;
            }
        }
        private void ValidaCliente()
        {
            if (txt_ctacte.Text.Trim().Length > 0)
            {
                var BL = new clienteBL();
                var BE = new tb_cliente();
                var dt = new DataTable();

                BE.ctacte = txt_ctacte.Text.Trim().PadLeft(7, '0');
                dt = BL.GetAll(EmpresaID, BE).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    txt_ctacte.Text = dt.Rows[0]["ctacte"].ToString().Trim();
                    txt_ctactename.Text = dt.Rows[0]["ctactename"].ToString().Trim();
                }
                else
                {
                    txt_ctacte.Text = string.Empty;
                    txt_ctactename.Text = string.Empty;
                }
            }
        }
        private bool U_Validacion()
        {
            var xmsg = string.Empty;
            var objeto = new object();
            var tmptabla = new DataTable();
            if ((txtrazonsocial.Text.Trim().Length == 0))
            {
                xmsg = "Ingrese Razón Social / Nombres  de cliente";
                objeto = txtrazonsocial;
            }
            else
            {
                if ((txtmnruc.Text.Length > 0))
                {
                    if (((u_n_opsel == 1) || !(j_Ruc == txtmnruc.Text)))
                    {
                        var BL = new clienteBL();
                        var BE = new tb_cliente();

                        BE.nmruc = txtmnruc.Text;
                        tmptabla = BL.GetAll(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];
                        if ((tmptabla.Rows.Count > 0))
                        {
                            xmsg = "RUC ya registrado";
                            objeto = txtmnruc;
                        }
                    }
                }
                if ((u_n_opsel == 1))
                {
                    if ((txtcodigo.Text.Trim().Length == 0))
                    {
                        xmsg = "Ingrese Código";
                        objeto = txtcodigo;
                    }
                    else
                    {
                        var BL = new clienteBL();
                        var BE = new tb_cliente();

                        BE.ctacte = txtcodigo.Text;
                        tmptabla = BL.GetAll(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];
                        if ((tmptabla.Rows.Count > 0))
                        {
                            xmsg = "Código ya registrado";
                            objeto = txtcodigo;
                        }
                    }
                }
            }
            if ((xmsg.Trim().Length > 0))
            {
                MessageBox.Show(xmsg, "Error en Ingreso de Datos", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                if (!(objeto == null))
                {
                    objeto = Focus();
                }
            }
            return xmsg.Trim().Length == 0;
        }