Пример #1
0
        void Llena_Datos()
        {
            aa_EReceta = funciones.Lee_Receta(tid.Text.ToString().Trim());

            if (aa_EReceta != null)
            {
                aa_modo     = "m";
                tdescr.Text = aa_EReceta.descripcion;
                TTipo.Text  = aa_EReceta.tipo;
                if (aa_EReceta.estado.ToUpper() == "A")
                {
                    cb_estado.SelectedIndex = 0;
                }
                else
                {
                    cb_estado.SelectedIndex = 1;
                }
                PB_Foto.SizeMode = PictureBoxSizeMode.Zoom;
                if (aa_EReceta.foto != "")
                {
                    //byte[] image = aa_EReceta.foto;
                    //MemoryStream ms = new MemoryStream(image);
                    //Image img = Image.FromStream(ms);
                    PB_Foto.Image = funciones.Base64ToImage(aa_EReceta.foto);
                }
                ii_foto        = aa_EReceta.foto;
                TPorcion.Text  = aa_EReceta.porcion.ToString().Trim();
                TDuracion.Text = aa_EReceta.duracion.ToString().Trim();
            }
            else
            {
                Valida_codigo();
            }
        }
Пример #2
0
 private void Formula_Load(object sender, EventArgs e)
 {
     if (aa_modo.ToUpper() == "A")
     {
         tid.Enabled = true;
     }
     else
     {
         aa_Receta = funciones.Lee_Receta(aa_id.ToString());
         Pasa_Datos();
     }
 }
Пример #3
0
        void Limpia_Datos()
        {
            aa_Receta = new Clases.EReceta();
            aa_id     = "";
            aa_modo   = "a";
            foreach (Control item in this.Controls)
            {
                try
                {
                    if (item is TextBox)
                    {
                        item.Text = "";
                    }
                }
                catch { }
            }

            dataGridView1.Rows.Clear();
            tid.Enabled = true;
        }
Пример #4
0
        public static Clases.EReceta Lee_Receta(string id)
        {
            Clases.EReceta ii_Receta = new Clases.EReceta();
            DataSet        DS        = new DataSet();
            string         Error     = "";
            string         sql       = "  SELECT * from RECETA WHERE  id_receta = '" + id + "'";

            DS = funciones.EjecutaSQL(sql, ref Error);
            if (DS.Tables[0].Rows.Count > 0)
            {
                ii_Receta.id          = id;
                ii_Receta.descripcion = DS.Tables[0].Rows[0][1].ToString();
                ii_Receta.estado      = DS.Tables[0].Rows[0][2].ToString();
                ii_Receta.tipo        = DS.Tables[0].Rows[0][3].ToString();
                if (DS.Tables[0].Rows[0][4].ToString() != "")
                {
                    ii_Receta.foto = DS.Tables[0].Rows[0][4].ToString();
                }
                ii_Receta.porcion  = int.Parse(DS.Tables[0].Rows[0][5].ToString());
                ii_Receta.duracion = decimal.Parse(DS.Tables[0].Rows[0][6].ToString());
                return(ii_Receta);
            }
            return(null);
        }
Пример #5
0
        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 (string.IsNullOrWhiteSpace(TTipo.Text.ToString().Trim()))
            {
                MessageBox.Show(mensaje);
                errorProvider1.SetError(TTipo, mensaje);
                TTipo.Focus();
            }
            if (string.IsNullOrWhiteSpace(TDuracion.Text.ToString().Trim()))
            {
                MessageBox.Show(mensaje);
                errorProvider1.SetError(TDuracion, mensaje);
                TDuracion.Focus();
            }

            if (aa_modo.ToUpper().Trim() == "A")
            {
                if (cb_estado.SelectedIndex != 0)
                {
                    MessageBox.Show("NO PUEDE REGISTRAR CON ESTADO DIFERENTE DE ACTIVO");
                    return;
                }
            }
            aa_EReceta             = new Clases.EReceta();
            aa_EReceta.id          = tid.Text;
            aa_EReceta.descripcion = tdescr.Text;
            aa_EReceta.estado      = cb_estado.SelectedItem.ToString().Trim().ToUpper().Substring(0, 1);
            aa_EReceta.tipo        = TTipo.Text;
            aa_EReceta.duracion    = Convert.ToDecimal(TDuracion.Text.ToString());
            aa_EReceta.porcion     = int.Parse(TPorcion.Text.ToString());
            if (aa_modo.ToString().Trim().ToUpper() != "A")
            {
                aa_EReceta.foto = ii_foto;
            }
            if (!funciones.Inserta_Receta(aa_modo, aa_EReceta, FileName, ref Error))
            {
                MessageBox.Show(Error);
                return;
            }
            if (aa_modo.Trim().ToLower() == "a")
            {
                Limpia();
            }
            else
            {
                this.DialogResult = DialogResult.OK;
            }
        }
Пример #6
0
        public static bool Inserta_Receta(string ii_Modo, Clases.EReceta ii_EReceta, 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_EReceta.foto = base64data;
                }


                string sql = "";
                if (ii_Modo.Trim().ToUpper() == "A")
                {
                    sql = "INSERT INTO RECETA VALUES(@id," +
                          "@descripcion," +
                          "@estado," +
                          "@tipo," +
                          "@foto," +
                          "@porcion," +
                          "@duracion)";
                }
                else
                {
                    sql = "UPDATE RECETA SET " +
                          "descr_receta =@descripcion," +
                          "estado_receta=@estado," +
                          "id_tipo_receta =@tipo," +
                          "foto_receta =@foto," +
                          "porcion_receta =@porcion," +
                          "tiempo_receta =@duracion" +
                          " WHERE id_receta=@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("@tipo", SqlDbType.Int, 8);
                cmd.Parameters.Add("@foto", SqlDbType.VarChar);
                cmd.Parameters.Add("@porcion", SqlDbType.Int, 8);
                cmd.Parameters.Add("@duracion", SqlDbType.Decimal, 5);

                cmd.Parameters["@id"].Value          = ii_EReceta.id;
                cmd.Parameters["@descripcion"].Value = ii_EReceta.descripcion;
                cmd.Parameters["@estado"].Value      = ii_EReceta.estado;
                cmd.Parameters["@tipo"].Value        = ii_EReceta.tipo;
                cmd.Parameters["@foto"].Value        = ii_EReceta.foto;

                cmd.Parameters["@porcion"].Value  = ii_EReceta.porcion;
                cmd.Parameters["@duracion"].Value = ii_EReceta.duracion;

                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);
        }