private void btnSub_Click(object sender, EventArgs e) { //Create an instance of a person RecipeClass temp = new RecipeClass(); //Assign the instance of a person a name //temp.Feedback = ""; //temp.Id = txtFName.Text; temp.Name = txtName.Text; // txtMName.Text; temp.Desc = txtDesc.Text; // txtLName.Text; temp.Ingr = txtIngr.Text; temp.Favorite = ckbxFav.Checked; temp.Notes = txtNotes.Text; temp.Reci = txtRecipe.Text; temp.Type = cboType.Text; if (temp.validEntry()) { label1.Text = temp.AddRecipe(); if (label1.Text == "1Record(s) Added") { this.Close(); } } else { MessageBox.Show("More data must be entered."); } }//End
private void btnDelete_Click(object sender, EventArgs e) { pictureBox1.InitialImage = null; pictureBox1.Image = null; RecipeClass temp = new RecipeClass(); Int32 intG_ID = Convert.ToInt32(lblID.Text); Int32 intRecords = temp.DeleteOneRec(intG_ID); MessageBox.Show(intRecords.ToString() + " Records Deleted."); this.Close(); }//End delete
//OVERLOADED CONSTRUCTOR - Meant to pull up existing data public NewRec(Int32 intR_ID) { InitializeComponent(); cboType.SelectedIndex = 0; btnSub.Enabled = false; btnSub.Visible = false; //Gather info about this one person and store it in a datareader RecipeClass temp = new RecipeClass(); OleDbDataReader dr = temp.FindOneRecipe(intR_ID); //Use that info to fill out the form //Loop through the records while (dr.Read()) { //Take the Name(s) from the datareader and copy them // into the appropriate text fields txtDesc.Text = dr["rDesc"].ToString(); txtIngr.Text = dr["ingr"].ToString(); txtName.Text = dr["rName"].ToString(); txtNotes.Text = dr["notes"].ToString(); txtRecipe.Text = dr["recipe"].ToString(); cboType.Text = dr["type"].ToString(); if (Boolean.Parse(dr["favorite"].ToString()) == true) { ckbxFav.Checked = true; } //added to store the ID in a label lblID.Text = dr["id"].ToString(); string curFile = @"Data\Image\" + txtName.Text + ".bmp";//@"Data\Image\" +txtName.Text+".bmp" if (File.Exists(curFile)) { //pictureBox1.Image = Image.FromFile(curFile); Image image = Image.FromFile(curFile); // Set the PictureBox image property to this image. // ... Then, adjust its height and width properties. pictureBox1.Image = image.GetThumbnailImage(257, 163, null, new IntPtr()); //pictureBox1.Height = image.Height = 163; //pictureBox1.Width = image.Width = 257; } //end if } //End wile }
}//End picbox private void btnUpdate_Click(object sender, EventArgs e) { RecipeClass temp = new RecipeClass(); temp.Name = txtName.Text; // txtMName.Text; temp.Desc = txtDesc.Text; // txtLName.Text; temp.Ingr = txtIngr.Text; temp.Favorite = ckbxFav.Checked; temp.Notes = txtNotes.Text; temp.Reci = txtRecipe.Text; temp.Type = cboType.Text; temp.Id = Int32.Parse(lblID.Text); if (temp.validEntry()) { label1.Text = temp.UpdateRec(); } else { MessageBox.Show("More data must be entered."); } }
private void btnSearch_Click(object sender, EventArgs e) { //get data RecipeClass temp = new RecipeClass(); //preform search RecipeClass temp2 = new RecipeClass(); temp2.Name = txtRname.Text; temp2.Ingr = txtIngr.Text; temp2.Favorite = chkBxFav.Checked; try { temp2.Id = Convert.ToInt32(txtID.Text); } catch { temp2.Id = -1; } temp2.Type = cboType.Text; DataSet ds = temp.SearchRec(temp2); //DataSet ds = temp.SearchRec(txtRname.Text); //display data gv_results.DataSource = ds; gv_results.DataMember = ds.Tables["RecipeTable"].ToString();//.DataSource }
}//End add Recipe //DataSet public DataSet SearchRec(RecipeClass temp)//String RecName) { //Create a dataset to return filled DataSet ds = new DataSet(); //Create a command for our SQL statement OleDbCommand comm = new OleDbCommand(); //SQL Statement String strSQL = "Select id as ID, rName as Recipe_Name, rDesc as Recipe_Description, type as Type, ingr as Ingredients, recipe as Recipe, favorite as Favorite FROM RecipeTable WHERE 0=0"; //If the First/Last Name is filled in include it as search criteria if (temp.name.Length > 0) { strSQL += " AND rName LIKE @RecName"; comm.Parameters.AddWithValue("@RecName", "%" + temp.name + "%"); } if (temp.id != null && temp.id > 0) { strSQL += " AND id LIKE @id"; comm.Parameters.AddWithValue("@id", "%" + temp.id + "%"); } if (temp.type.Length > 0) { strSQL += " AND type LIKE @ty"; comm.Parameters.AddWithValue("@ty", "%" + temp.type + "%"); } if (temp.ingr.Length > 0) { strSQL += " AND ingr LIKE @ing"; comm.Parameters.AddWithValue("@ing", "%" + temp.ingr + "%"); } if (temp.favorite == true) { strSQL += " AND favorite LIKE @fv"; comm.Parameters.AddWithValue("@fv", "%" + -1 + "%"); } //Create DB tools and Configure //************************************************ OleDbConnection conn = new OleDbConnection(); string strConn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Data\Data.accdb;Persist Security Info=False;";//@SqlDb_Game.GetConnected(); conn.ConnectionString = strConn; comm.Connection = conn; comm.CommandText = strSQL; //Create Data Adapter OleDbDataAdapter da = new OleDbDataAdapter(); da.SelectCommand = comm; //************************************************ //Get Data conn.Open(); da.Fill(ds, "RecipeTable"); conn.Close(); return(ds); }//End Search Game