void Llena_Datos() { aa_EGrupo_art = funciones.Lee_Grupo_art(tid.Text.ToString().Trim()); if (aa_EGrupo_art != null) { aa_modo = "m"; tdescr.Text = aa_EGrupo_art.descripcion; if (aa_EGrupo_art.estado.ToUpper() == "A") { cb_estado.SelectedIndex = 0; } else { cb_estado.SelectedIndex = 1; } PB_Foto.SizeMode = PictureBoxSizeMode.Zoom; if (aa_EGrupo_art.foto != "") { PB_Foto.Image = funciones.Base64ToImage(aa_EGrupo_art.foto); } ii_foto = aa_EGrupo_art.foto; } else { Valida_codigo(); } }
private void button3_Click(object sender, EventArgs e) { string sql = ""; string Error = ""; errorProvider1.Clear(); string mensaje = "ESTE CAMPO NO PUEDE ESTAR EN BLANCO"; if (string.IsNullOrWhiteSpace(tid.Text.ToString().Trim())) { MessageBox.Show(mensaje); errorProvider1.SetError(tid, mensaje); tid.Focus(); return; } if (string.IsNullOrWhiteSpace(tdescr.Text.ToString().Trim())) { MessageBox.Show(mensaje); errorProvider1.SetError(tdescr, mensaje); tdescr.Focus(); } if (aa_modo.ToUpper().Trim() == "A") { if (cb_estado.SelectedIndex != 0) { MessageBox.Show("NO PUEDE REGISTRAR CON ESTADO DIFERENTE DE ACTIVO"); return; } } aa_EGrupo_art = new Clases.EGrupo_art(); aa_EGrupo_art.id = tid.Text; aa_EGrupo_art.descripcion = tdescr.Text; aa_EGrupo_art.estado = cb_estado.SelectedItem.ToString().Trim().ToUpper().Substring(0, 1); if (aa_modo.ToString().Trim().ToUpper() != "A") { aa_EGrupo_art.foto = ii_foto; } if (!funciones.Inserta_Grupo_art(aa_modo, aa_EGrupo_art, FileName, ref Error)) { MessageBox.Show(Error); return; } if (aa_modo.Trim().ToLower() == "a") { Limpia(); } else { this.DialogResult = DialogResult.OK; } }
public static Clases.EGrupo_art Lee_Grupo_art(string id) { Clases.EGrupo_art ii_Grupo_art = new Clases.EGrupo_art(); DataSet DS = new DataSet(); string Error = ""; string sql = " SELECT * from GRUPO_ARTICULO WHERE id_g_articulo = '" + id + "'"; DS = funciones.EjecutaSQL(sql, ref Error); if (DS.Tables[0].Rows.Count > 0) { ii_Grupo_art.id = id; ii_Grupo_art.descripcion = DS.Tables[0].Rows[0][1].ToString(); ii_Grupo_art.estado = DS.Tables[0].Rows[0][2].ToString(); ii_Grupo_art.foto = DS.Tables[0].Rows[0][3].ToString(); return(ii_Grupo_art); } return(null); }
public static bool Inserta_Grupo_art(string ii_Modo, Clases.EGrupo_art ii_EGrupo_art, string ii_FileName, ref string Error) { Error = ""; SqlConnection con = OpenC(ref Error); SqlCommand cmd; FileStream fs; BinaryReader br; byte[] ImageData = null; string base64data = ""; try { if (ii_FileName.Length > 0) { base64data = ImageToBase64(ii_FileName); ii_EGrupo_art.foto = base64data; } string sql = ""; if (ii_Modo.Trim().ToUpper() == "A") { sql = "INSERT INTO GRUPO_ARTICULO VALUES(@id," + "@descripcion," + "@estado," + "@foto)"; } else { sql = "UPDATE GRUPO_ARTICULO SET " + "descr_g_articulo =@descripcion," + "estado_Grupo_art=@estado," + "estado_g_articulo =@tipo," + "foto_g_articulo =@foto" + " WHERE id_g_articulo=@id"; } cmd = new SqlCommand(sql, con); cmd.Parameters.Add("@id", SqlDbType.Int, 8); cmd.Parameters.Add("@descripcion", SqlDbType.VarChar, 500); cmd.Parameters.Add("@estado", SqlDbType.Char, 1); cmd.Parameters.Add("@foto", SqlDbType.VarChar); cmd.Parameters["@id"].Value = ii_EGrupo_art.id; cmd.Parameters["@descripcion"].Value = ii_EGrupo_art.descripcion; cmd.Parameters["@estado"].Value = ii_EGrupo_art.estado; cmd.Parameters["@foto"].Value = ii_EGrupo_art.foto; con.Open(); int RowsAffected = cmd.ExecuteNonQuery(); con.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } finally { if (con.State == ConnectionState.Open) { con.Close(); } } return(true); }