private void Importar_Excel()
        {
            var CuadroDialogo = new OpenFileDialog();
            CuadroDialogo.DefaultExt = "xls";
            CuadroDialogo.Filter = "xls file(*.xls)|*.xlsx";
            CuadroDialogo.AddExtension = true;
            CuadroDialogo.RestoreDirectory = true;
            CuadroDialogo.Title = "Seleccionar Archivo";

            if (CuadroDialogo.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    var excelApp = new Excel.Application();
                    var excelBook = excelApp.Workbooks.Open(CuadroDialogo.FileName, Type.Missing, false, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
                    var excelWorksheet = (Excel._Worksheet)excelBook.Worksheets.get_Item(1);
                    excelApp.Visible = false;

                    var x = 2;
                    if (TablapromoDet.Rows.Count > 0)
                    {
                        TablapromoDet.Rows.Clear();
                    }
                    while (excelWorksheet.get_Range("A" + x).Value2 != null)
                    {
                        TablapromoDet.Rows.Add(promoid.Text.Trim(),
                                            string.Empty,
                                            excelWorksheet.get_Range("A" + x).Value2.ToString(),
                                            excelWorksheet.get_Range("B" + x).Value2.ToString(),
                                            excelWorksheet.get_Range("C" + x).Value2.ToString(),
                                            1,
                                            excelWorksheet.get_Range("D" + x).Value2.ToString(),
                                            excelWorksheet.get_Range("E" + x).Value2.ToString(),
                                            "0",
                                            VariablesPublicas.Usuar.ToString(),
                                            DateTime.Today.ToShortDateString());
                        x++;
                    }

                    var BL = new tb_px_promocionesdetBL();
                    var BE = new tb_px_promocionesdet();

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

                    var item = 0;
                    foreach (DataRow fila in TablapromoDet.Rows)
                    {
                        Detalle = new tb_px_promocionesdet.Item();
                        item++;

                        Detalle.promoid = Convert.ToInt32(promoid.Text.ToString());
                        Detalle.articid = string.Empty;
                        Detalle.articidold = fila["articidold"].ToString().Trim();
                        Detalle.articname = fila["articname"].ToString().Trim();
                        Detalle.es_dscto = Convert.ToBoolean(fila["es_dscto"].ToString().Trim());
                        Detalle.cantidad = 1;
                        Detalle.percdscto = Convert.ToDecimal(fila["percdscto"].ToString());
                        Detalle.precunit = Convert.ToDecimal(fila["precunit"].ToString());
                        Detalle.status = "0";
                        Detalle.UsuarIP = VariablesPublicas.Usuar;
                        Detalle.feact = Convert.ToDateTime(fila["feact"].ToString().Trim());

                        ListaItems.Add(Detalle);
                    }
                    if (ListaItems.Count == 0)
                    {
                        MessageBox.Show("Documento SIN DETALLE Y/O DETALLE INCORRECTO !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    BE.promoid = Convert.ToInt32(promoid.Text.ToString());
                    BE.ListaItems = ListaItems;

                    EliminarDet(Convert.ToInt32(promoid.Text.ToString()));

                    if (BL.InsertDet(EmpresaID, BE))
                    {
                        MessageBox.Show("Datos Grabados Correctamente !!!", "Confirmación", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        CargarDetalle();
                        Nuevo2(false);
                        btn_add.Enabled = true;
                    }

                    excelApp.Quit();
                }
                catch (Exception sms)
                {
                    MessageBox.Show(sms.Message);
                }
            }
        }
        private bool EliminarDet(Int32 xpromoid)
        {
            var result = false;
            try
            {
                var BL = new tb_px_promocionesdetBL();
                var BE = new tb_px_promocionesdet();
                BE.promoid = xpromoid;

                if (BL.Delete2(EmpresaID, BE))
                {
                    result = true;
                }
                else
                {
                    result = false;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }
        private void btn_update_Click(object sender, EventArgs e)
        {
            if (articid.Text.Length == 0)
            {
                MessageBox.Show("Ingrese Articulo ...!!!", "Información");
                return;
            }

            var BL = new tb_px_promocionesdetBL();
            var BE = new tb_px_promocionesdet();

            BE.promoid = Convert.ToInt32(promoid.Text.Trim());
            BE.articid = xx_articid.Trim();
            BE.articidold = articid.Text.Trim();
            BE.articname = articname.Text.Trim();
            BE.es_dscto = chk_aldoc2.Checked;
            BE.percdscto = Convert.ToDecimal(percdscto.Text.Trim());
            BE.cantidad = 1;
            BE.precunit = Convert.ToDecimal(precunit.Text.Trim());
            BE.status = "0";
            BE.UsuarIP = VariablesPublicas.Usuar.ToString().Trim();
            BE.feact = Convert.ToDateTime(DateTime.Today.ToShortDateString());

            if (BL.Update(EmpresaID, BE))
            {
                MessageBox.Show("Datos Modificados Correctamente !!!", "Confirmación", MessageBoxButtons.OK, MessageBoxIcon.Information);
                CargarDetalle();
                Nuevo2(false);
                btn_add.Enabled = true;
                btn_update.Enabled = false;
                btn_cancelar.PerformClick();
            }
        }
        private void CargarDetalle()
        {
            var BL = new tb_px_promocionesdetBL();
            var BE = new tb_px_promocionesdet();
            TablapromoDet = new DataTable();
            if (promoid.Text.Trim().Length > 0)
            {
                BE.promoid = Convert.ToInt32(promoid.Text.Trim());
            }

            TablapromoDet = BL.GetAll(EmpresaID, BE).Tables[0];
            if (TablapromoDet.Rows.Count > 0)
            {
                dgb_promodet.DataSource = TablapromoDet;
            }
            else
            {
                dgb_promodet.DataSource = TablapromoDet;
            }
        }
        private void btn_del_Click(object sender, EventArgs e)
        {
            if ((dgb_promodet.RowCount != null))
            {
                if (promoid.Text.Trim().Length == 0)
                {
                    MessageBox.Show("Falta Codigo de Lista de Precios", "Informacion", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                else
                {
                    if (articid.Text.Trim().Length == 0)
                    {
                        MessageBox.Show("Falta Codigo de Artículo", "Informacion", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }
                var BL = new tb_px_promocionesdetBL();
                var BE = new tb_px_promocionesdet();
                BE.promoid = Convert.ToInt32(promoid.Text.Trim());
                BE.articid = xx_articid.Trim();
                BE.articidold = articid.Text.Trim();

                if (BL.Delete(EmpresaID, BE))
                {
                    CargarDetalle();
                    articid.Text = string.Empty;
                    chk_aldoc2.Checked = false;
                    articname.Text = string.Empty;
                    percdscto.Text = string.Empty;
                    precunit.Text = string.Empty;
                    btn_del.Enabled = false;
                }
            }
        }