public DataSet GetAll(string empresaid, tb_pp_variante BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTbPpVariante_SEARCH", cnx))
         {
             DataSet ds = new DataSet();
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@variante", SqlDbType.Char, 6).Value = BE.variante;
                 cmd.Parameters.Add("@codtizado", SqlDbType.Char, 8).Value = BE.codtizado;
                 cmd.Parameters.Add("@variantename", SqlDbType.VarChar, 50).Value = BE.variantename;
             }
             try
             {
                 cnx.Open();
                 using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                 {
                     da.Fill(ds);
                 }
                 return ds;
             }
             catch (Exception ex)
             {
                 throw new Exception(ex.Message);
             }
         }
     }
 }
        public DataSet GeneraCod(string empresaid, tb_pp_variante BE)
        {
            using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
            {
                using (SqlCommand cmd = new SqlCommand("gspTbPpVariante_GEN_Codigo", cnx))
                {
                    DataSet ds = new DataSet();

                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add("@marcaid", SqlDbType.Char, 2).Value = BE.marcaid;
                    }

                    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_pp_variante BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTbPpVariante_DELETE", cnx))
         {
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@variante", SqlDbType.Char, 6).Value = BE.variante;
             }
             try
             {
                 cnx.Open();
                 if (cmd.ExecuteNonQuery() > 0)
                 {
                     return true;
                 }
                 else
                 {
                     return false;
                 }
             }
             catch (Exception ex)
             {
                 throw new Exception(ex.Message);
             }
         }
     }
 }
        private void CargarDatosVariantes(String _xcodvar)
        {
            var BL = new tb_pp_varianteBL();
            var BE = new tb_pp_variante();
            var dt = new DataTable();
            BE.variante = _xcodvar.ToString();

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

            if (dt.Rows.Count > 0)
            {
                articname.Text = dt.Rows[0]["variantename"].ToString();
                cmb_categoriaid.SelectedValue = dt.Rows[0]["categoriaid"].ToString();
                marcaid.Text = dt.Rows[0]["marcaid"].ToString();
                marcaname.Text = dt.Rows[0]["marcaname"].ToString();
                _xmarcadescort = dt.Rows[0]["marcadescort"].ToString();

                lineaid.Text = dt.Rows[0]["lineaid"].ToString();
                lineaname.Text = dt.Rows[0]["lineaname"].ToString();
                if (dt.Rows[0]["lineadescort"].ToString() == string.Empty)
                {
                    _xlineadescort = dt.Rows[0]["lineaname"].ToString();
                }
                else
                {
                    _xlineadescort = dt.Rows[0]["lineadescort"].ToString();
                }

                modeloid.Text = dt.Rows[0]["modeloid"].ToString();
                modeloname.Text = dt.Rows[0]["modeloname"].ToString();
                _xmodelodescort = dt.Rows[0]["modelodescort"].ToString();

                familiatelaid.Text = dt.Rows[0]["familiatelaid"].ToString();
                familiatelaname.Text = dt.Rows[0]["familianame"].ToString();
                cmb_generoid.SelectedValue = dt.Rows[0]["generoid"].ToString();
                cmb_categoriaid.SelectedValue = dt.Rows[0]["categoriaid"].ToString();
                cmb_botapieid.SelectedValue = dt.Rows[0]["botapieid"].ToString();
                cmb_entalleid.SelectedValue = dt.Rows[0]["entalleid"].ToString();
                cmb_parteid.SelectedValue = dt.Rows[0]["parteid"].ToString();
            }
        }
        private void Insert()
        {
            try
            {
                if (variante.Text.Trim().Length == 0)
                {
                    MessageBox.Show("Falta Codigo Variante !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    if (marcaid.Text.Trim().Length == 0)
                    {
                        MessageBox.Show("Falta Codigo de Marca", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        if (lineaid.Text.Trim().Length == 0)
                        {
                            MessageBox.Show("Falta Codigo de Linea", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        else
                        {
                            if (modeloid.Text.Trim().Length == 0)
                            {
                                MessageBox.Show("Falta Codigo de Modelo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                            else
                            {
                                if (familiatelaid.Text.Trim().Length == 0)
                                {
                                    MessageBox.Show("Falta Codigo de FamiliaTelas", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    return;
                                }
                                else
                                {
                                    if (codtizado.Text.Trim().Length == 0)
                                    {
                                        MessageBox.Show("Falta Codigo de Articulo-Generado", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                        return;
                                    }
                                    else
                                    {
                                        if (cmb_categoriaid.SelectedIndex == -1)
                                        {
                                            MessageBox.Show("Falta Seleccionar La Categoria", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                            return;
                                        }
                                        else
                                        {
                                            if (cmb_generoid.SelectedIndex == -1)
                                            {
                                                MessageBox.Show("Falta Seleccionar el Genero", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                                return;
                                            }
                                            else
                                            {
                                                if (cmb_parteid.SelectedIndex == -1)
                                                {
                                                    MessageBox.Show("Falta Seleccionar Parte ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                                    return;
                                                }
                                                else
                                                {
                                                    if (cmb_entalleid.SelectedIndex == -1)
                                                    {
                                                        MessageBox.Show("Falta Seleccionar Entalle", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                                        return;
                                                    }
                                                    else
                                                    {
                                                        var BL = new tb_pp_varianteBL();
                                                        var BE = new tb_pp_variante();

                                                        BE.variante = variante.Text.ToString();
                                                        BE.codtizado = codtizado.Text.ToString();
                                                        BE.variantename = variantename.Text.ToString();
                                                        BE.categoriaid = cmb_categoriaid.SelectedValue.ToString();
                                                        BE.marcaid = marcaid.Text.Trim();
                                                        BE.lineaid = lineaid.Text.Trim();
                                                        BE.generoid = cmb_generoid.SelectedValue.ToString();
                                                        BE.tejidoid = _tejidoid.ToString();
                                                        BE.familiatelaid = familiatelaid.Text.Trim();
                                                        BE.botapieid = cmb_botapieid.SelectedValue.ToString();
                                                        BE.entalleid = cmb_entalleid.SelectedValue.ToString();
                                                        BE.modeloid = modeloid.Text.Trim();
                                                        BE.parteid = cmb_parteid.SelectedValue.ToString();
                                                        BE.aprobado = chk_aprobado.Checked;
                                                        BE.perianio = cboanio.SelectedValue.ToString();
                                                        BE.perimes = cboMesini.SelectedValue.ToString();
                                                        BE.diseñadorid = cmb_disenadorid.SelectedValue.ToString();
                                                        if (fech_prese.Checked)
                                                        {
                                                            BE.fechprese = Convert.ToDateTime(fech_prese.Text);
                                                        }
                                                        if (fech_aprob.Checked)
                                                        {
                                                            BE.fechaprob = Convert.ToDateTime(fech_aprob.Text);
                                                        }
                                                        BE.tippy = tip_py.Text.ToString();
                                                        BE.serppy = ser_py.Text.ToString();
                                                        BE.numppy = num_py.Text.ToString();
                                                        BE.status = "0";
                                                        BE.usuar = VariablesPublicas.Usuar.Trim();

                                                        if (BL.Insert(EmpresaID, BE))
                                                        {
                                                            MessageBox.Show("Datos Grabados Correctamente !!!", "Confirmación", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                                            procesado = true;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void Delete()
        {
            try
            {
                if (variante.Text.Trim().Length != 6)
                {
                    MessageBox.Show("Falta Codigo Variante !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    var BL = new tb_pp_varianteBL();
                    var BE = new tb_pp_variante();

                    BE.variante = variante.Text.ToString();
                    BE.codtizado = codtizado.Text.ToString();

                    if (BL.Delete(EmpresaID, BE))
                    {
                        SEGURIDAD_LOG("E");
                        MessageBox.Show("Datos Eliminados Correctamente !!!", "Confirmación", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        NIVEL_FORMS();
                        form_bloqueado(false);
                        data_TablaVariante();
                        btn_nuevo.Enabled = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void data_TablaVariante()
        {
            try
            {
                if (TablaVariante.Rows.Count > 0)
                {
                    TablaVariante.Rows.Clear();
                }
                var BL = new tb_pp_varianteBL();
                var BE = new tb_pp_variante();

                BE.variantename = txt_criterio.Text.ToString();

                TablaVariante = BL.GetAll(EmpresaID, BE).Tables[0];
                if (TablaVariante.Rows.Count > 0)
                {
                    btn_imprimir.Enabled = true;
                    MDI_gridvariante.DataSource = TablaVariante;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 private void _GenerarCodigo()
 {
     var BE = new tb_pp_variante();
     var BL = new tb_pp_varianteBL();
     var dt = new DataTable();
     BE.marcaid = marcaid.Text.Trim().ToString();
     dt = BL.GeneraCod(EmpresaID, BE).Tables[0];
     if (dt.Rows.Count > 0)
     {
         variante.Text = dt.Rows[0]["Codigo"].ToString();
     }
     else
     {
         variante.Text = "ERROR";
     }
 }
        public bool Update_foto(string empresaid, tb_pp_variante BE)
        {
            using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
            {
                using (SqlCommand cmd = new SqlCommand("gspTbPtArticulo_UPDATE_foto", cnx))
                {

                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        //cmd.Parameters.Add("@articidold", SqlDbType.Char, 8).Value = BE.articidold;
                        //cmd.Parameters.Add("@docname", SqlDbType.VarChar, 100).Value = BE.docname;
                        //cmd.Parameters.Add("@foto", SqlDbType.Image).Value = BE.Foto;
                    }
                    try
                    {
                        cnx.Open();
                        if (cmd.ExecuteNonQuery() > 0)
                        {
                            return true;
                        }
                        else
                        {
                            return false;
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }
            }
        }
 public bool Update(string empresaid, tb_pp_variante BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTbPpVariante_UPDATE", cnx))
         {
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@variante", SqlDbType.Char, 6).Value = BE.variante;
                 cmd.Parameters.Add("@codtizado", SqlDbType.Char, 8).Value = BE.codtizado;
                 cmd.Parameters.Add("@variantename", SqlDbType.VarChar, 50).Value = BE.variantename;
                 cmd.Parameters.Add("@categoriaid", SqlDbType.Char, 2).Value = BE.categoriaid;
                 cmd.Parameters.Add("@marcaid", SqlDbType.Char, 2).Value = BE.marcaid;
                 cmd.Parameters.Add("@lineaid", SqlDbType.Char, 2).Value = BE.lineaid;
                 cmd.Parameters.Add("@generoid", SqlDbType.Char, 1).Value = BE.generoid;
                 cmd.Parameters.Add("@tejidoid", SqlDbType.Char, 2).Value = BE.tejidoid;
                 cmd.Parameters.Add("@familiatelaid", SqlDbType.Char, 3).Value = BE.familiatelaid;
                 cmd.Parameters.Add("@botapieid", SqlDbType.Char, 2).Value = BE.botapieid;
                 cmd.Parameters.Add("@entalleid", SqlDbType.Char, 2).Value = BE.entalleid;
                 cmd.Parameters.Add("@modeloid", SqlDbType.Char, 4).Value = BE.modeloid;
                 cmd.Parameters.Add("@parteid", SqlDbType.Char, 1).Value = BE.parteid;
                 cmd.Parameters.Add("@aprobado", SqlDbType.Bit).Value = BE.aprobado;
                 cmd.Parameters.Add("@perianio", SqlDbType.Char, 4).Value = BE.perianio;
                 cmd.Parameters.Add("@perimes", SqlDbType.Char, 2).Value = BE.perimes;
                 cmd.Parameters.Add("@disenadorid", SqlDbType.Char, 4).Value = BE.diseñadorid;
                 cmd.Parameters.Add("@fechprese", SqlDbType.DateTime).Value = BE.fechprese;
                 cmd.Parameters.Add("@fechaprob", SqlDbType.DateTime).Value = BE.fechaprob;
                 cmd.Parameters.Add("@tippy", SqlDbType.Char, 2).Value = BE.tippy;
                 cmd.Parameters.Add("@serpy", SqlDbType.Char, 4).Value = BE.serppy;
                 cmd.Parameters.Add("@numpy", SqlDbType.Char, 10).Value = BE.numppy;
                 cmd.Parameters.Add("@status", SqlDbType.Char, 1).Value = BE.status;
                 cmd.Parameters.Add("@usuar", SqlDbType.Char, 15).Value = BE.usuar;
             }
             try
             {
                 cnx.Open();
                 if (cmd.ExecuteNonQuery() > 0)
                 {
                     return true;
                 }
                 else
                 {
                     return false;
                 }
             }
             catch (Exception ex)
             {
                 throw new Exception(ex.Message);
             }
         }
     }
 }
 public DataSet GetAll_foto(string empresaid, tb_pp_variante BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTbPtArticulo_SEARCH_foto", cnx))
         {
             DataSet ds = new DataSet();
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 //cmd.Parameters.Add("@articidold", SqlDbType.Char, 8).Value = BE.articidold;
             }
             try
             {
                 cnx.Open();
                 using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                 {
                     da.Fill(ds);
                 }
                 return ds;
             }
             catch (Exception ex)
             {
                 throw new Exception(ex.Message);
             }
         }
     }
 }