public bool Delete(string empresaid, tb_cp_comercialdet BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTbCpComercialdet_DELETE", cnx))
         {
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@perianio", SqlDbType.Char, 4).Value = BE.perianio;
                 cmd.Parameters.Add("@empresa", SqlDbType.Char, 2).Value = BE.empresa;
                 cmd.Parameters.Add("@asiento", SqlDbType.Char, 10).Value = BE.asiento;
             }
             try
             {
                 cnx.Open();
                 if (cmd.ExecuteNonQuery() > 0)
                 {
                     return true;
                 }
                 else
                 {
                     return false;
                 }
             }
             catch (Exception ex)
             {
                 throw new Exception(ex.Message);
             }
         }
     }
 }
 public DataSet GetAll(string empresaid, tb_cp_comercialdet BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTbCpComercialdet_SEARCH", cnx))
         {
             DataSet ds = new DataSet();
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@perianio", SqlDbType.Char, 4).Value = BE.perianio;
                 cmd.Parameters.Add("@empresa", SqlDbType.Char, 2).Value = BE.empresa;
                 cmd.Parameters.Add("@asiento", SqlDbType.Char, 10).Value = BE.asiento;
                 cmd.Parameters.Add("@moduloid", SqlDbType.Char, 4).Value = BE.moduloid;
                 cmd.Parameters.Add("@local", SqlDbType.Char, 3).Value = BE.local;
                 cmd.Parameters.Add("@fechemision", SqlDbType.DateTime).Value = BE.fechemision;
                 cmd.Parameters.Add("@fechtermino", SqlDbType.DateTime).Value = BE.fechtermino;
                 cmd.Parameters.Add("@mnruc", SqlDbType.Char, 11).Value = BE.mnruc;
                 cmd.Parameters.Add("@ctactename", SqlDbType.VarChar, 80).Value = BE.ctactename;
                 cmd.Parameters.Add("@vendedorid", SqlDbType.Char, 4).Value = BE.vendedorid;
                 cmd.Parameters.Add("@brokerid", SqlDbType.Char, 4).Value = BE.brokerid;
                 cmd.Parameters.Add("@paisid", SqlDbType.Char, 4).Value = BE.paisid;
                 cmd.Parameters.Add("@mercadoid", SqlDbType.Char, 1).Value = BE.mercadoid;
                 cmd.Parameters.Add("@marcaid", SqlDbType.Char, 4).Value = BE.marcaid;
                 cmd.Parameters.Add("@proforma", SqlDbType.Text).Value = BE.proforma;
                 cmd.Parameters.Add("@usuar", SqlDbType.VarChar, 200).Value = BE.usuar;
             }
             try
             {
                 cnx.Open();
                 using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                 {
                     da.Fill(ds);
                 }
                 return ds;
             }
             catch (Exception ex)
             {
                 throw new Exception(ex.Message);
             }
         }
     }
 }
 public DataSet GetAll_datosdetalle(string empresaid, tb_cp_comercialdet BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTbCpComercial_SEARCH_datosdetalle", cnx))
         {
             DataSet ds = new DataSet();
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@moduloid", SqlDbType.Char, 4).Value = BE.moduloid;
                 cmd.Parameters.Add("@local", SqlDbType.Char, 3).Value = BE.local;
                 cmd.Parameters.Add("@tipodoc", SqlDbType.Char, 2).Value = BE.tipdoc;
                 cmd.Parameters.Add("@serdoc", SqlDbType.Char, 4).Value = BE.serdoc;
                 cmd.Parameters.Add("@numdoc", SqlDbType.Char, 10).Value = BE.numdoc;
             }
             try
             {
                 cnx.Open();
                 using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                 {
                     da.Fill(ds);
                 }
                 return ds;
             }
             catch (Exception ex)
             {
                 throw new Exception(ex.Message);
             }
         }
     }
 }
 public bool Update(string empresaid, tb_cp_comercialdet BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTbCpComercialdet_UPDATE", cnx))
         {
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@perianio", SqlDbType.Char, 4).Value = BE.perianio;
                 cmd.Parameters.Add("@empresa", SqlDbType.Char, 2).Value = BE.empresa;
                 cmd.Parameters.Add("@asiento", SqlDbType.Char, 10).Value = BE.asiento;
                 cmd.Parameters.Add("@moduloid", SqlDbType.Char, 4).Value = BE.moduloid;
                 cmd.Parameters.Add("@local", SqlDbType.Char, 3).Value = BE.local;
                 cmd.Parameters.Add("@fechemision", SqlDbType.DateTime).Value = BE.fechemision;
                 cmd.Parameters.Add("@fechtermino", SqlDbType.DateTime).Value = BE.fechtermino;
                 cmd.Parameters.Add("@mnruc", SqlDbType.Char, 11).Value = BE.mnruc;
                 cmd.Parameters.Add("@ctactename", SqlDbType.VarChar, 80).Value = BE.ctactename;
                 cmd.Parameters.Add("@vendedorid", SqlDbType.Char, 4).Value = BE.vendedorid;
                 cmd.Parameters.Add("@brokerid", SqlDbType.Char, 4).Value = BE.brokerid;
                 cmd.Parameters.Add("@paisid", SqlDbType.Char, 4).Value = BE.paisid;
                 cmd.Parameters.Add("@mercadoid", SqlDbType.Char, 1).Value = BE.mercadoid;
                 cmd.Parameters.Add("@marcaid", SqlDbType.Char, 4).Value = BE.marcaid;
                 cmd.Parameters.Add("@proforma", SqlDbType.Text).Value = BE.proforma;
                 cmd.Parameters.Add("@status", SqlDbType.Bit).Value = BE.status;
                 cmd.Parameters.Add("@usuar", SqlDbType.VarChar, 200).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 GetOne(string empresaid, tb_cp_comercialdet BE)
        {
            using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
            {
                using (SqlCommand cmd = new SqlCommand("gspTbCpComercialdet_SELECT", cnx))
                {
                    DataSet ds = new DataSet();

                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add("@perianio", SqlDbType.Char, 4).Value = BE.perianio;
                        cmd.Parameters.Add("@asiento", SqlDbType.Char, 10).Value = BE.asiento;
                    }

                    try
                    {
                        cnx.Open();
                        using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                        {
                            da.Fill(ds);
                        }
                        return ds;
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }
            }
        }
        private void data_TabladetallePedido2()
        {
            try
            {
                griddetallepedido2.AutoGenerateColumns = false;

                var BL = new tb_cp_comercialdetBL();
                var BE = new tb_cp_comercialdet();

                var dt = new DataTable();

                BE.moduloid = modulo;
                BE.local = local;
                BE.tipdoc = tipdoc.Text.ToString().Trim();
                BE.serdoc = serdoc.Text.Trim().PadLeft(4, '0');
                BE.numdoc = numdoc.Text.Trim().PadLeft(6, '0');

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

                if (TabladetallePedido2 != null)
                {
                    TabladetallePedido2.Clear();
                }

                if (TabladetallePedido != null)
                {
                    TabladetallePedido.Clear();
                }

                foreach (DataRow fila in dt.Rows)
                {
                    row = TabladetallePedido2.NewRow();

                    row["colorid"] = fila["colorid"].ToString();
                    row["prop01"] = fila["prop01"].ToString();
                    row["prop02"] = fila["prop02"].ToString();
                    row["prop03"] = fila["prop03"].ToString();
                    row["prop04"] = fila["prop04"].ToString();
                    row["prop05"] = fila["prop05"].ToString();
                    row["prop06"] = fila["prop06"].ToString();
                    row["prop07"] = fila["prop07"].ToString();
                    row["prop08"] = fila["prop08"].ToString();
                    row["prop09"] = fila["prop09"].ToString();
                    row["prop10"] = fila["prop10"].ToString();
                    row["prop11"] = fila["prop11"].ToString();
                    row["prop12"] = fila["prop12"].ToString();
                    row["panios"] = fila["panios"].ToString();
                    row["cantot"] = fila["cantot"].ToString();
                    row["cpromxpda"] = fila["cpromxpda"].ToString();
                    row["observacion"] = fila["observacion"].ToString();

                    row["talla01"] = fila["talla01"].ToString();
                    row["talla02"] = fila["talla02"].ToString();
                    row["talla03"] = fila["talla03"].ToString();
                    row["talla04"] = fila["talla04"].ToString();
                    row["talla05"] = fila["talla05"].ToString();
                    row["talla06"] = fila["talla06"].ToString();
                    row["talla07"] = fila["talla07"].ToString();
                    row["talla08"] = fila["talla08"].ToString();
                    row["talla09"] = fila["talla09"].ToString();
                    row["talla10"] = fila["talla10"].ToString();
                    row["talla11"] = fila["talla11"].ToString();
                    row["talla12"] = fila["talla12"].ToString();

                    TabladetallePedido2.Rows.Add(row);
                }

                griddetallepedido2.DataSource = TabladetallePedido2;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }