private void get_tipocambio(string fecha)
        {
            try
            {
                var BL = new tipocambioBL();
                var dt = new DataTable();

                dt = BL.GetOne(EmpresaID, Convert.ToDateTime(fecha)).Tables[0];

                if (dt.Rows.Count > 0)
                {
                    tcamb.Text = Convert.ToDecimal(dt.Rows[0]["venta"]).ToString("###,##0.0000");
                }
                else
                {
                    tcamb.Text = "1";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void actualizatipocambio()
        {
            if (u_n_opsel == 0)
            {
                return;
            }
            string xfecha = null;
            if (fechaRefer.ShowCheckBox & !(fechaRefer.Text.ToString() == "01/01/1900"))
            {
                xfecha = Convert.ToDateTime(fechaRefer.Text).ToString();
            }
            else
            {
                xfecha = Convert.ToDateTime(fRegistro.Text).ToString();
            }
            tipocambioBL BL = new tipocambioBL();
            tb_tipocambio BE = new tb_tipocambio();

            BE.fecha = Convert.ToDateTime(xfecha);
            DataTable tcambio = BL.GetAll(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];

            if (tcambio.Rows.Count > 0)
            {
                txtTipocambio.Text = tcambio.Rows[0]["venta"].ToString();
            }
            else
            {
                txtTipocambio.Text = "0.00";
                //DevExpress.XtraEditors.XtraMessageBox.Show("Actualice el Tipo de Cambio?", "Mensaje del Sistema", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private void actualizatipocambio()
        {
            //string fecha = null;
            //fecha = Strings.Mid(femision.Text, 7, 4) + Strings.Mid(femision.Text, 4, 2) + Strings.Mid(femision.Text, 1, 2);
            //DataTable tcambio = new DataTable();
            //tcambio = ocapa.fa23i00_consulta(fecha, "", "", GlobalVars.GetInstance.Company);
            //if (tcambio.Rows.Count > 0)
            //{
            //    if (tcambio.Rows[0]["tcam_23i"] > tcambio.Rows[0]["tcamv_23i"])
            //    {
            //        txtcambio.Text = tcambio.Rows[0]["tcam_23i"];
            //    }
            //    else
            //    {
            //        txtcambio.Text = tcambio.Rows[0]["tcamv_23i"];
            //    }
            //}
            //else
            //{
            //    txtcambio.Text = "";
            //}
            tipocambioBL BL = new tipocambioBL();
            tb_tipocambio BE = new tb_tipocambio();

            BE.anio = Convert.ToInt16(VariablesPublicas.perianio.ToString());
            BE.fecha = Convert.ToDateTime(fEmision.Text);

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

            if (tcambio.Rows.Count > 0)
            {
                if (Convert.ToDecimal(tcambio.Rows[0]["compra"]) > Convert.ToDecimal(tcambio.Rows[0]["venta"]))
                {
                    txtCambio.Text = tcambio.Rows[0]["compra"].ToString();
                }
                else
                {
                    txtCambio.Text = tcambio.Rows[0]["venta"].ToString();
                }
            }
            else
            {
                txtCambio.Text = "0.0000";
                //XtraMessageBox.Show("Actualice el Tipo de Cambio?", "Mensaje del Sistema", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private void get_tipocambio(String fecha)
        {
            try
            {
                var BL = new tipocambioBL();
                var dt = new DataTable();

                dt = BL.GetOne(EmpresaID, Convert.ToDateTime(fecha)).Tables[0];
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void get_tipocambio(string fecha)
        {
            try
            {
                // Genera Tipo de cambio dependiendo la fech del documento
                tipocambioBL BL = new tipocambioBL();
                tb_tipocambio BE = new tb_tipocambio();
                DataTable dt = new DataTable();

                dt = BL.GetOne(EmpresaID, Convert.ToDateTime(fecha)).Tables[0];

                if (dt.Rows.Count > 0)
                {
                    xtipocambio = Convert.ToDecimal(dt.Rows[0]["venta"]);
                }
                else
                {
                    xtipocambio = 1;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void get_tipocambio(String fecha)
        {
            try
            {
                //genera tipo de cambio dependiendo la fech del documento
                tipocambioBL BL = new tipocambioBL();
                tb_tipocambio BE = new tb_tipocambio();
                DataTable dt = new DataTable();

                dt = BL.GetOne(EmpresaID, Convert.ToDateTime(fecha)).Tables[0];

                //if (dt.Rows.Count > 0)
                //{
                //    tcamb.Text = Convert.ToDecimal(dt.Rows[0]["venta"]).ToString("###,##0.0000");
                //}
                //else
                //{
                //    tcamb.Text = "1";
                //}

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void actualizatipocambio()
        {
            tipocambioBL BL = new tipocambioBL();
            tb_tipocambio BE = new tb_tipocambio();

            BE.fecha = Convert.ToDateTime(fRegistro.Text);
            DataTable tcambio = BL.GetAll(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];

            if (tcambio.Rows.Count > 0)
            {
                txtTipocambio.Text = tcambio.Rows[0]["venta"].ToString();
            }
            else
            {
                txtTipocambio.Text = "";
            }

            //tipocambioBL BL = new tipocambioBL();
            //tb_tipocambio BE = new tb_tipocambio();

            //if (cboTcamuso.Text.Substring(0, 1) != "E")
            //{
            //    txtTipocambio.Enabled = false;

            //    BE.fecha = Convert.ToDateTime(fRegistro.Text);
            //    DataTable tcambio = BL.GetAll(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];

            //    if (tcambio.Rows.Count > 0)
            //    {
            //        if (cboTcamuso.Text.Substring(0, 1) == "V")
            //        { txtTipocambio.Text = tcambio.Rows[0]["venta"].ToString(); }
            //        if (cboTcamuso.Text.Substring(0, 1) == "C")
            //        { txtTipocambio.Text = tcambio.Rows[0]["compra"].ToString(); }
            //        if (cboTcamuso.Text.Substring(0, 1) == "P")
            //        { txtTipocambio.Text = tcambio.Rows[0]["promedio"].ToString(); }
            //    }
            //    else
            //    {
            //        txtTipocambio.Text = "0";
            //        decimal TipoCambio = VariablesPublicas.StringtoDecimal(txtTipocambio.Text);
            //        txtTipocambio.Text = TipoCambio.ToString("##.0000");
            //        //XtraMessageBox.Show("Actualice el Tipo de Cambio?", "Mensaje del Sistema", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //    }
            //}
            //else
            //{
            //    txtTipocambio.Enabled = true;
            //    decimal TipoCambio = VariablesPublicas.StringtoDecimal(txtTipocambio.Text);
            //    txtTipocambio.Text = TipoCambio.ToString("##.00000");
            //}
        }
        private Decimal TipoCambio(DateTime fechdoc)
        {
            tipocambioBL BL = new tipocambioBL();
            tb_tipocambio BE = new tb_tipocambio();

            DataTable tabletipocamb = new DataTable();
            //decimal tipocambio =0;

            try
            {
                tabletipocamb = BL.GetOne(VariablesPublicas.EmpresaID.ToString(), fechdoc).Tables[0];
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            if (tabletipocamb.Rows.Count > 0)
            {
                return Convert.ToDecimal(tabletipocamb.Rows[0]["venta"]);
            }
            else
            {
                //XtraMessageBox.Show("Resgistre el Tipo de Cambio para la fecha " + fechdoc, "Mensaje delSistema", MessageBoxButtons.OK, MessageBoxIcon.Question);
                return 0;
            }
            //tipocambio = Convert.ToDecimal(table.Rows[0]["venta"]);
        }
        private void actualizatipocambio()
        {
            tipocambioBL BL = new tipocambioBL();
            tb_tipocambio BE = new tb_tipocambio();

            //BE.anio = Convert.ToInt16(VariablesPublicas.perianio.ToString());
            BE.fecha = Convert.ToDateTime(fEmision.Text);

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

            if (tcambio.Rows.Count > 0)
            {
                if (Convert.ToDecimal(tcambio.Rows[0]["compra"]) > Convert.ToDecimal(tcambio.Rows[0]["venta"]))
                {
                    txtTipCamb.Text = tcambio.Rows[0]["compra"].ToString();
                }
                else
                {
                    txtTipCamb.Text = tcambio.Rows[0]["venta"].ToString();
                }

                //if (cboTcamuso.Text.Substring(0, 1) == "V")
                //{ txtCambio.Text = tcambio.Rows[0]["venta"].ToString(); }
                //if (cboTcamuso.Text.Substring(0, 1) == "C")
                //{ txtCambio.Text = tcambio.Rows[0]["compra"].ToString(); }
                //if (cboTcamuso.Text.Substring(0, 1) == "P")
                //{ txtCambio.Text = tcambio.Rows[0]["promedio"].ToString(); }
                //if (cboTcamuso.Text.Substring(0, 1) == "E")
                //{ txtCambio.Enabled = true; }
                //else
                //{ txtCambio.Enabled = false; }
            }
            else
            {
                txtTipCamb.Text = "0.00";
                //XtraMessageBox.Show("Actualice el Tipo de Cambio?", "Mensaje del Sistema", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private void save_internet()
        {
            bool zprocesaok = false;
            if ((GridTipocambio.DataSource != null))
            {
                if (GridTipocambio.RowCount > 0)
                {
                    zprocesaok = true;

                    if (XtraMessageBox.Show("Desea grabar información extraida de la Sunat...?", "Mensaje del Sistema", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                    {
                        tipocambioBL BL = new tipocambioBL();
                        tb_tipocambio BE = new tb_tipocambio();

                        if (BL.Insert_Update(VariablesPublicas.EmpresaID, tmptabla))
                        {
                            U_CancelarEdicion(0);
                        }
                        else
                        {
                            Frm_Class.ShowError(BL.Sql_Error, this);
                        }
                    }
                    TabControl1.SelectedIndex = 0;
                }
            }
            if (!zprocesaok)
            {
                XtraMessageBox.Show("Extraiga información", "Mensaje del Sistema", MessageBoxButtons.OK, MessageBoxIcon.Error);
                btnextraertcambio.Focus();
            }
        }
        private void save()
        {
            if (u_Validate())
            {
                try
                {
                    tipocambioBL BL = new tipocambioBL();
                    tb_tipocambio BE = new tb_tipocambio();

                    DateTime zfecha=Convert.ToDateTime(txtfecha.Text);

                    BE.fecha = zfecha;
                    BE.perianio = VariablesPublicas.PADL(zfecha.Date.Year.ToString(), 4, "0");
                    BE.perimes = VariablesPublicas.PADL(zfecha.Date.Month.ToString(), 2, "0");

                    BE.compra = Convert.ToDecimal(txtcompra.Text);
                    BE.venta = Convert.ToDecimal(txtventa.Text);
                    BE.promedio = (BE.compra + BE.venta) / 2;
                    BE.usuar = VariablesPublicas.Usuar.Trim();

                    if (u_n_opsel == 1)
                    {
                        if (BL.Insert(VariablesPublicas.EmpresaID.ToString(), BE))
                        {
                            U_CancelarEdicion(0);
                            //MessageBox.Show("Se grabó con éxito", "Mensaje del Sistema", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            XtraMessageBox.Show("Contacte con sistemas", "Mensaje del Sistema", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    else
                    {
                        if (BL.Update(VariablesPublicas.EmpresaID.ToString(), BE))
                        {
                            U_CancelarEdicion(0);
                            //MessageBox.Show("Se grabó con éxito", "Mensaje del Sistema", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            XtraMessageBox.Show("Contacte con sistemas", "Mensaje del Sistema", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                }
                catch (Exception ex)
                {
                    XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        private void llenar_gridtipocambio()
        {
            try
            {
                tipocambioBL BL = new tipocambioBL();
                tb_tipocambio BE = new tb_tipocambio();

                BE.perianio = VariablesPublicas.perianio.ToString();

                Tabla = BL.GetAll(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void Accion(int naccion)
        {
            switch (naccion)
            {
                case 1:
                    u_n_opsel = 1;
                    U_RefrescaControles();
                    Blanquear();
                    txtfecha.Text = Equivalencias.Mid(DateTime.Now.ToString(), 1, 10);
                    if ((GridExaminar.CurrentRow != null))
                    {
                        GridExaminar.CurrentRow.Selected = false;
                    }
                    txtcompra.Focus();
                    break;
                case 2:
                    j_Fecha = txtfecha.Text;
                    POnedatos();
                    u_n_opsel = 2;
                    U_RefrescaControles();
                    GridExaminar.CurrentRow.Selected = true;
                    j_Sigla = txtcompra.Text;
                    txtcompra.Focus();
                    break;
                case 3:
                    xnomcampo = "";
                    if ((GridExaminar.CurrentRow != null))
                    {
                        if (xnomcampo.Length == 0)
                        {
                            if (XtraMessageBox.Show("Desea Eliminar Registro ...?", "Mensaje del Sistema", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                            {
                                for (lc_cont = 0; lc_cont <= Tabla.Rows.Count - 1; lc_cont++)
                                {
                                    if (Tabla.Rows[lc_cont]["fecha"] == GridExaminar.Rows[GridExaminar.CurrentRow.Index].Cells["fecha"].Value)
                                    {
                                        Tabla.Rows[lc_cont].Delete();
                                        Tabla.AcceptChanges();
                                        break;
                                    }
                                }

                                if ((GridExaminar.CurrentRow != null))
                                {
                                    try
                                    {
                                        tipocambioBL BL = new tipocambioBL();
                                        tb_tipocambio BE = new tb_tipocambio();

                                        BE.anio = Convert.ToInt16(VariablesPublicas.perianio.ToString());
                                        BE.fecha = Convert.ToDateTime(GridExaminar.Rows[GridExaminar.CurrentRow.Index].Cells["fecha"].Value.ToString());

                                        if (!BL.Delete(VariablesPublicas.EmpresaID.ToString(), BE))
                                        {
                                            XtraMessageBox.Show("Contacte con sistemas", "Mensaje del Sistema", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    }
                                }

                                //GridExaminar.Rows.Remove(GridExaminar.Rows[GridExaminar.CurrentRow.Index]);
                                GridExaminar.Refresh();
                                Tabla.AcceptChanges();
                                U_CancelarEdicion(0);
                            }
                        }
                        else
                        {
                            XtraMessageBox.Show(xnomcampo, "Imposible eliminar documento", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    break;
            }
        }
        private bool u_Validate()
        {
            string xmsg = "";
            object xobjeto = new object();
            if (txtfecha.Text.Trim().Length == 0)
            {
                xmsg = xmsg + "Ingrese fecha" + Equivalencias.Chr(13);
                xobjeto = txtfecha;
            }
            if (txtfecha.Text.Trim().Length > 0)
            {
                if (!Equivalencias.IsDate(txtfecha.Text))
                {
                    xmsg = xmsg + "Fecha inválida" + Equivalencias.Chr(13);
                    xobjeto = txtfecha;
                }
                xobjeto = txtfecha;
            }
            if (!Equivalencias.IsNumeric(txtcompra.Text.Trim()))
            {
                xmsg = xmsg + "Falta tipo de cambio compra" + Equivalencias.Chr(13);
                xobjeto = txtcompra;
            }

            if (!Equivalencias.IsNumeric(txtventa.Text.Trim()))
            {
                xmsg = xmsg + "Falta tipo de cambio venta" + Equivalencias.Chr(13);
                xobjeto = txtventa;
            }
            if (u_n_opsel == 1 | !(txtfecha.Text == j_Fecha))
            {
                try
                {
                    tipocambioBL BL = new tipocambioBL();
                    tb_tipocambio BE = new tb_tipocambio();

                    BE.anio = Convert.ToInt16(VariablesPublicas.perianio.ToString());
                    BE.fecha = Convert.ToDateTime(txtfecha.Text);

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

                    if (tmpcursor.Rows.Count > 0)
                    {
                        xmsg = "Fecha ya registrada";
                        xobjeto = txtfecha;
                    }
                }
                catch (Exception ex)
                {
                    XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            if (!(xmsg.Trim().Length == 0))
            {
                XtraMessageBox.Show(xmsg, "Validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                if ((xobjeto != null))
                {
                    xobjeto = Focus();
                }
                if (Controls.ContainsKey("txtfecha"))
                {
                    Controls["txtfecha"].Focus();
                }
            }
            return xmsg.Trim().Length == 0;
        }