public DataSet GetAll_paginacion(string empresaid, tb_mottrasladoint BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTbMottrasladoint_SEARCH_paginacion", cnx))
         {
             DataSet ds = new DataSet();
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@moduloid", SqlDbType.Char, 4).Value = BE.moduloid;
                 cmd.Parameters.Add("@mottrasladointid", SqlDbType.Char, 2).Value = BE.mottrasladointid;
                 cmd.Parameters.Add("@posicion", SqlDbType.VarChar, 10).Value = BE.posicion;
             }
             try
             {
                 cnx.Open();
                 using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                 {
                     da.Fill(ds);
                 }
                 return ds;
             }
             catch (Exception ex)
             {
                 throw new Exception(ex.Message);
             }
         }
     }
 }
 public bool Delete(string empresaid, tb_mottrasladoint BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTbMottrasladoint_DELETE", cnx))
         {
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@moduloid", SqlDbType.Char, 4).Value = BE.moduloid;
                 cmd.Parameters.Add("@mottrasladointid", SqlDbType.Char, 2).Value = BE.mottrasladointid;
             }
             try
             {
                 cnx.Open();
                 if (cmd.ExecuteNonQuery() > 0)
                 {
                     return true;
                 }
                 else
                 {
                     return false;
                 }
             }
             catch (Exception ex)
             {
                 throw new Exception(ex.Message);
             }
         }
     }
 }
 private void data_cbo_mottrasladointid()
 {
     try
     {
         var BL = new tb_mottrasladointBL();
         var BE = new tb_mottrasladoint();
         BE.moduloid = modulo;
         BE.tipmov = almacaccionid.Trim().PadLeft(1, '0').Substring(0, 1);
         mottrasladointid.DataSource = BL.GetAll(EmpresaID, BE).Tables[0];
         mottrasladointid.ValueMember = "mottrasladointid";
         mottrasladointid.DisplayMember = "mottrasladointname";
         mottrasladointid.SelectedIndex = -1;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        private void ValidaMotivoint()
        {
            if (mottrasladointid.Text.Trim().Length > 0)
            {
                var BL = new tb_mottrasladointBL();
                var BE = new tb_mottrasladoint();
                var dt = new DataTable();

                BE.moduloid = modulo;
                BE.mottrasladointid = mottrasladointid.Text.Trim().PadLeft(2, '0');

                dt = BL.GetOne(EmpresaID, BE).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    mottrasladointid.Text = dt.Rows[0]["mottrasladointid"].ToString().Trim();
                    mottrasladointname.Text = dt.Rows[0]["mottrasladointname"].ToString().Trim();
                }
                else
                {
                    mottrasladointid.Text = string.Empty;
                    mottrasladointname.Text = string.Empty;
                }
            }
            else
            {
                mottrasladointid.Text = string.Empty;
                mottrasladointname.Text = string.Empty;
            }
        }
        void CargarMotivos()
        {
            try
            {
                var BL = new tb_mottrasladointBL();
                var BE = new tb_mottrasladoint();
                DataTable dt = new DataTable();
                BE.moduloid = modulo;
                BE.tipmov = Equivalencias.Left(cmb_tipdoc.SelectedValue.ToString(),1).ToString();
                dt = BL.GetAll(EmpresaID, BE).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    cmb_motivo.DataSource = dt;
                    cmb_motivo.ValueMember = "mottrasladointid";
                    cmb_motivo.DisplayMember = "mottrasladointname";
                    cmb_motivo.SelectedIndex = -1;

                    cmb_motivo.Enabled = true;
                    txt_serop.Enabled = true;

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void Update()
        {
            try
            {
                if (moduloid.Text.Trim().Length != 4)
                {
                    MessageBox.Show("Falta Codigo Modulo !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else if (mottrasladointid.Text.Trim().Length != 2)
                {
                    MessageBox.Show("Ingrese codigo motivo de traslado interno !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else if (mottrasladointname.Text.Trim().Length == 0)
                {
                    MessageBox.Show("Ingrese nombre de motivo !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    tb_mottrasladointBL BL = new tb_mottrasladointBL();
                    tb_mottrasladoint BE = new tb_mottrasladoint();

                    BE.moduloid = moduloid.Text.Trim();
                    BE.mottrasladointid = mottrasladointid.Text.Trim().PadLeft(2, '0');
                    BE.mottrasladointname = mottrasladointname.Text.ToUpper();
                    BE.codigosunat = codigosunat.Text.Trim().ToUpper();
                    BE.escompra = escompra.Checked;
                    BE.esventa = esventa.Checked;
                    if (tipmov1.Checked)
                        BE.tipmov = "1";
                    if (tipmov2.Checked)
                        BE.tipmov = "2";

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

                BE.moduloid = moduloid.Text.Trim();
                BE.mottrasladointid = mottrasladointid.Text.Trim().PadLeft(2, '0');
                BE.posicion = posicion.Trim();

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

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

                    moduloid.Text = dt.Rows[0]["moduloid"].ToString().Trim();
                    moduloname.Text = dt.Rows[0]["moduloname"].ToString().Trim();
                    mottrasladointid.Text = dt.Rows[0]["mottrasladointid"].ToString().Trim();
                    mottrasladointname.Text = dt.Rows[0]["mottrasladointname"].ToString().Trim();
                    codigosunat.Text = dt.Rows[0]["codigosunat"].ToString().Trim();
                    if (dt.Rows[0]["escompra"].ToString().Trim().Length > 0)
                        escompra.Checked = Convert.ToBoolean(dt.Rows[0]["escompra"]);
                    if (dt.Rows[0]["esventa"].ToString().Trim().Length > 0)
                        esventa.Checked = Convert.ToBoolean(dt.Rows[0]["esventa"]);
                    if (dt.Rows[0]["tipmov"].ToString().Trim().Length > 0)
                    {
                        if (dt.Rows[0]["tipmov"].ToString().Trim() == "1")
                            tipmov1.Checked = true;
                        else if (dt.Rows[0]["tipmov"].ToString().Trim() == "2")
                            tipmov2.Checked = true;
                    }
                    else
                    {
                        tipmov1.Checked = false;
                        tipmov2.Checked = false;
                    }

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

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

                    btn_buscar.Enabled = true;
                    btn_log.Enabled = true;
                    btn_salir.Enabled = true;

                    data_Tablamottrasladoint();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void Delete()
        {
            try
            {
                if (moduloid.Text.Trim().Length != 4)
                {
                    MessageBox.Show("Falta Codigo Modulo !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else if (mottrasladointid.Text.Trim().Length != 2)
                {
                    MessageBox.Show("Ingrese nuevo motivo de traslado interno !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    tb_mottrasladointBL BL = new tb_mottrasladointBL();
                    tb_mottrasladoint BE = new tb_mottrasladoint();

                    BE.moduloid = moduloid.Text.Trim();
                    BE.mottrasladointid = mottrasladointid.Text.Trim().PadLeft(2, '0');

                    if (BL.Delete(EmpresaID, BE))
                    {
                        SEGURIDAD_LOG("E");
                        MessageBox.Show("Datos Eliminado correctamente !!!", "ConfirmaciĆ³n", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        NIVEL_FORMS();
                        limpiar_documento();
                        form_bloqueado(false);
                        data_Tablamottrasladoint();
                        btn_nuevo.Enabled = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void data_Tablamottrasladoint()
        {
            try
            {
                if (Tablamottrasladoint.Rows.Count > 0)
                    Tablamottrasladoint.Rows.Clear();
                tb_mottrasladointBL BL = new tb_mottrasladointBL();
                tb_mottrasladoint BE = new tb_mottrasladoint();
                BE.moduloid = moduloid.Text.Trim();
                switch (cbo_buscar.SelectedIndex)
                {
                    case 0:
                        BE.mottrasladointname = txt_criterio.Text.Trim();
                        break;
                    case 1:
                        if (txt_criterio.Text.Trim().Length > 0)
                        {
                            BE.mottrasladointid = txt_criterio.Text.Trim().ToUpper().PadLeft(3, '0');
                        }
                        break;
                    case 2:
                        if (txt_criterio.Text.Trim().Length > 0)
                        {
                            BE.tipmov = txt_criterio.Text.Trim();
                        }
                        break;
                    default:
                        //**
                        break;
                }

                Tablamottrasladoint = BL.GetAll(EmpresaID, BE).Tables[0];
                if (Tablamottrasladoint.Rows.Count > 0)
                {
                    btn_imprimir.Enabled = true;
                    gridmottrasladoint.DataSource = Tablamottrasladoint;
                    gridmottrasladoint.Rows[0].Selected = false;
                    gridmottrasladoint.Focus();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void ValidaMottrasladoint()
        {
            if (mottrasladointid.Text.Trim().Length > 0 && ssModo == "NEW")
            {
                tb_mottrasladointBL BL = new tb_mottrasladointBL();
                tb_mottrasladoint BE = new tb_mottrasladoint();
                DataTable dt = new DataTable();

                BE.moduloid = modulo;
                BE.mottrasladointid = mottrasladointid.Text.Trim().PadLeft(4, '0');

                dt = BL.GetAll(EmpresaID, BE).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    mottrasladointid.Text = dt.Rows[0]["mottrasladointid"].ToString().Trim();
                    mottrasladointname.Text = dt.Rows[0]["mottrasladointname"].ToString().Trim();
                    mottrasladointname.Text = moduloname.Text.Trim() + " " + dt.Rows[0]["mottrasladointname"].ToString().Trim();
                }
                else
                {
                    mottrasladointid.Text = "";
                    mottrasladointname.Text = "";
                    mottrasladointname.Text = moduloname.Text.Trim();
                }
            }
            if (mottrasladointid.Text.Trim().Length == 0 && ssModo == "NEW")
            {
                mottrasladointid.Text = "";
                mottrasladointname.Text = "";
                mottrasladointname.Text = moduloname.Text.Trim();
            }
        }
 public bool Update(string empresaid, tb_mottrasladoint BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTbMottrasladoint_UPDATE", cnx))
         {
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@moduloid", SqlDbType.Char, 4).Value = BE.moduloid;
                 cmd.Parameters.Add("@mottrasladointid", SqlDbType.Char, 2).Value = BE.mottrasladointid;
                 cmd.Parameters.Add("@mottrasladointname", SqlDbType.VarChar, 50).Value = BE.mottrasladointname;
                 cmd.Parameters.Add("@tipmov", SqlDbType.Char, 1).Value = BE.tipmov;
                 cmd.Parameters.Add("@esventa", SqlDbType.Bit).Value = BE.esventa;
                 cmd.Parameters.Add("@escompra", SqlDbType.Bit).Value = BE.escompra;
                 cmd.Parameters.Add("@codigosunat", SqlDbType.Char, 2).Value = BE.codigosunat;
             }
             try
             {
                 cnx.Open();
                 if (cmd.ExecuteNonQuery() > 0)
                 {
                     return true;
                 }
                 else
                 {
                     return false;
                 }
             }
             catch (Exception ex)
             {
                 throw new Exception(ex.Message);
             }
         }
     }
 }