private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                System.Data.DataRow foundRow = SiaWin.Empresas.Rows.Find(SiaWin._BusinessId);
                int idLogo = Convert.ToInt32(foundRow["BusinessLogo"].ToString().Trim());
                cnEmp = foundRow[SiaWin.CmpBusinessCn].ToString().Trim();
                string aliasemp   = foundRow["BusinessAlias"].ToString().Trim();
                string nomempresa = foundRow["BusinessName"].ToString().Trim();

                if (string.IsNullOrEmpty(codemp))
                {
                    codemp = foundRow["BusinessCode"].ToString().Trim();
                }
                else
                {
                    DataTable dt        = SiaWin.Func.SqlDT("select * from Business where BusinessCode='" + codemp + "' ", "Empresas", 0);
                    int       idEmpresa = 0;
                    if (dt.Rows.Count > 0)
                    {
                        idEmpresa = Convert.ToInt32(dt.Rows[0]["BusinessId"]);
                    }
                    System.Data.DataRow foundRowEmpresa = SiaWin.Empresas.Rows.Find(idEmpresa);
                    nomempresa = foundRowEmpresa["BusinessName"].ToString().Trim();
                }

                this.Title  = "Kardex - Empresa:" + codemp + "-" + nomempresa;
                FecIni.Text = DateTime.Now.ToShortDateString();

                // idmodulo

                DataRow[] drmodulo = SiaWin.Modulos.Select("ModulesCode='IN'");
                if (drmodulo == null)
                {
                    this.IsEnabled = false;
                }
                moduloid = Convert.ToInt32(drmodulo[0]["ModulesId"].ToString());
                //MessageBox.Show("Modulo id:"+moduloid.ToString());
                if (!string.IsNullOrEmpty(codref))
                {
                    TextBoxbod.Text = codbod;
                    BuscarBod(codbod);
                    TextBoxRef.Text = codref;
                    BuscarCod(codref);
                    BtnConsultar.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
                }
            }
            catch (Exception w)
            {
                MessageBox.Show("error al cargar el Load:" + w);
            }
        }
        private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                string tag = ((TextBox)sender).Tag.ToString();

                if (tag == "inmae_ref")
                {
                    if (e.Key == System.Windows.Input.Key.Enter & string.IsNullOrEmpty(TextBoxRef.Text.Trim()))
                    {
                        dynamic ww = SiaWin.WindowExt(9326, "InBuscarReferencia");
                        ww.Height                = 400;
                        ww.Conexion              = SiaWin.Func.DatosEmp(idemp);
                        ww.idEmp                 = idemp;
                        ww.idBod                 = idBod;
                        ww.ShowInTaskbar         = false;
                        ww.Owner                 = Application.Current.MainWindow;
                        ww.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                        ww.ShowDialog();

                        if (!string.IsNullOrEmpty(ww.Codigo))
                        {
                            TextBoxRef.Text = ww.Codigo;
                            TXNomRef.Text   = ww.Nombre;
                            TextBoxbod.Focus();
                        }
                        ww        = null;
                        e.Handled = true;
                    }
                }
                if (tag == "inmae_bod")
                {
                    if (e.Key == System.Windows.Input.Key.Enter & string.IsNullOrEmpty(TextBoxbod.Text.Trim()))
                    {
                        string cmptabla = tag; string cmpcodigo = "cod_bod"; string cmpnombre = "nom_bod"; string cmporden = "cod_bod"; string cmpidrow = "idrow"; string cmptitulo = "Maestra de bodegas"; string cmpconexion = cnEmp; Boolean mostrartodo = true; string cmpwhere = "";
                        int    idr = 0; string code = ""; string nom = "";

                        dynamic winb = SiaWin.WindowBuscar(cmptabla, cmpcodigo, cmpnombre, cmporden, cmpidrow, cmptitulo, SiaWin.Func.DatosEmp(idemp), mostrartodo, cmpwhere, idEmp: idemp);
                        winb.ShowInTaskbar = false;
                        winb.Owner         = Application.Current.MainWindow;
                        winb.ShowDialog();
                        idr  = winb.IdRowReturn;
                        code = winb.Codigo;
                        nom  = winb.Nombre;
                        winb = null;

                        if (idr > 0)
                        {
                            TextBoxbod.Text = code;
                            TxNomBod.Text   = nom;

                            //var uiElement = e.OriginalSource as UIElement;
                            //uiElement.MoveFocus(new TraversalRequest(FocusNavigationDirection.Down));
                            BtnConsultar.Focus();
                        }
                        e.Handled = true;
                    }
                }
                if (e.Key == Key.Enter & !string.IsNullOrEmpty(((TextBox)sender).Text.Trim()))
                {
                    var uiElement = e.OriginalSource as UIElement;
                    uiElement.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }