Question: Answer this once and youll answer 5 post! Need help with this assignment in C# The primary (main) form of the application will contain a
Answer this once and youll answer 5 post!
Need help with this assignment in C#
The primary (main) form of the application will contain a list box, a picture box, a multi-lined textbox, and three buttons, as follows:
Given a list of words, the user may click on any of these words, and upon selection, the application will automatically:
Display an image related to the word
Display the definition of the word in the multi-line text box
Additionally, there are three buttons:
Add Word -Delete Word -Edit Word
Add Word:
When the user clicks on Add Word, the application will display a separate modal form that will allow the user to enter the information related to the new word he/she wishes to add.
The user will enter the word, an image name, and a definition. If they are satisfied with what theyve entered and want to commit the information to the database, they hit the Add Word button near the bottom of this form.
The images can be copied into an Images directory (folder) under the bin/Debug/ directory (the directory the executable lives in if youre compiling/building in Debug mode.) The images are copied into this directory manually (the program isnt responsible for putting the images into this directory.
However, the name you put under Image Name must match exactly the name of the image in the Images directory. For example, if the word the user is entering is sausage, then the image may be sausage.png. Therefore, you must ensure there is an image loaded into the Images directory named sausage.png.
The application should prevent the user from adding the word if they leave any of the three textboxes empty. In other words, communication with the database will only occur if all three of the textboxes have non-empty content in them.
If the user decides they dont want to add the word, they can just hit the X in the corner and close this form, without adding the item to the database.
Delete Word:
The Delete Word option simply pops up a Message Box asking if the user is sure they want to delete the selected word. If the user clicks OK or Yes, then the word will be deleted from the database (and the dataset and list box.) If he/she clicks Cancel or No, the word will remain in the database (and the dataset, and the list box.)
Edit Word :
When the user presses the Edit Word button (with a particular selection of word made), the Edit Word form will be displayed and look almost identical to the Add Word option shown above. The difference will be that the word will not be editable (the textboxs Enabled property will be set to false) and the image location and definition will load with whatever the database contains as their current data.
Upon changing the data, the user may press Edit Word to commit the changes to the database.
I have some of the coding done i just need to know if im on the right path?
THIS IS THE CODE I HAVE COMPLETED:
namespace Capstone { public partial class dictionary : Form { public dictionary() { InitializeComponent(); }
private void Form1_Load(object sender, EventArgs e) { InitializeComponent(); listBox1.SelectedIndex = 0; //Dog.SelectedIndex; // pictureBox1.Image = Properties.Resources.white;
}
private void addButton_Click(object sender, EventArgs e) { AddForm addForm = new AddForm(); addForm.Show();
this.Validate(); //this.myDBDataSet1.EndEdit(); //this.UpdateAll(this.studentDBDataSet);
}
private void deleteButton_Click(object sender, EventArgs e) { DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete the selected word", "Warning", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { SqlCommand sqlcom = new SqlCommand(st, connection); try { sqlcom.ExecuteNonQuery(); MessageBox.Show("delete successful"); } catch (SqlException ex) { MessageBox.Show(ex.Message); } } else if (dialogResult == DialogResult.No) { //do something else } }
private void editButton_Click(object sender, EventArgs e) { EditForm editForm = new EditForm(); editForm.Show(); }
private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { int index = listBox1.SelectedIndex;
int count = listBox1.SelectedItems.Count;
if (index == 0) { pictureBox1.Image = Properties.Resources.white;
displayBox.Text = ("mans best friend"); }
else if (index == 1) { pictureBox1.Image = Properties.Resources.atom; displayBox.Text = ("very small");
}
else if (index == 2) { pictureBox1.Image = Properties.Resources.fire; displayBox.Text = ("hot you probably shoudnt touch it or play with it..... unless your chuck noress"); }
else if (index == 3) { pictureBox1.Image = Properties.Resources.sandal; displayBox.Text = ("dont wear with socks"); } } } }//end dictionary
namespace Capstone { public partial class AddForm : Form { public AddForm() { InitializeComponent(); }
private void Add_Load(object sender, EventArgs e) { }
private void button1_Click(object sender, EventArgs e) { //String selectdBtB = cs; //foreach(String cs in new string[] {cs, cs2 }) // { // using (OdbcDataAdapter adp = new OdbcDataAdapter(selectdBtB, cs)) // { // adp.Fill(); NOT SURE THIS IS CORRECT OR I NEED? using (var connection = new SqlConnection("connectionString")) { connection.Open(); var sql = "INSERT INTO Main(LIST, IMAGE, DISPLAY) VALUES(@LIST, @IMAGE, @DISPLAY)"; using (var cmd = new SqlCommand(sql, connection)) { cmd.Parameters.AddWithValue("@LIST", /*NEEDTOCHANGE*/.Text); cmd.Parameters.AddWithValue("@IMAGE", /*NEEDTOCHANGE*/.Img); cmd.Parameters.AddWithValue("@DISPLAY", /*NEEDTOCHANGE*/.Text);
cmd.ExecuteNonQuery(); } } } } }//end Addform
namespace Capstone { public partial class EditForm : Form { public EditForm() { InitializeComponent(); }
private void Edit_Load(object sender, EventArgs e) {
}
private void editButton_Click(object sender, EventArgs e) { DataTable dt = new DataTable(); SqlDataAdapter slctRow = new SqlDataAdapter("SELECT * FROM myEmployees WHERE EmpID=" + Convert.ToInt16(/*NEEDTOCHANGE*/.SelectedRows[0].Cells[0].Value.ToString()) + " ", sc); slctRow.Fill(dt);
//display records into textboxes /*NEEDTOCHANGE*/.Text = dt.Rows[0][0].ToString(); /*NEEDTOCHANGE*/.Text = dt.Rows[0][1].ToString();//SINCE AN IMAGE TOSTRING CORRECT? /*NEEDTOCHANGE*/.Text = dt.Rows[0][2].ToString();
} } }//end EditForm
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
