public void AddForm() { try { Product product = new Product(); product.Title = presenter1.addFormView.txtTitle.Text; product.Description = presenter1.addFormView.txtDescription.Text; product.Color = presenter1.addFormView.txtColor.Text; product.Size = Convert.ToDouble(presenter1.addFormView.txtSize.Text); product.Price = Convert.ToDouble(presenter1.addFormView.txtPrice.Text); product.Stock = Convert.ToInt32(presenter1.addFormView.txtSize.Text); IDBManager db = new MySQLDBManager(); db.Create(product); BindingSource bindingsource = new BindingSource(); presenter1.addFormView.dataGridView1.DataSource = null; presenter1.addFormView.dataGridView1.DataSource = bindingsource; presenter1.addFormView.dataGridView1.Refresh(); con = new MySqlConnection(); con.ConnectionString = @"datasource=127.0.0.1;port=3306;username=root;password=;database=assigment1;Convert Zero Datetime=True;"; con.Open(); adapt = new MySqlDataAdapter("select title ,description,color,size,price,stock from product", con); ds = new System.Data.DataSet(); adapt.Fill(ds, "Product_Details"); presenter1.addFormView.dataGridView1.DataSource = ds.Tables[0]; MessageBox.Show("Created!", "Add", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void TestMethod1() { Product p = new Product(); p.Title = "Test product"; p.Description = "Test description"; p.Color = "Test color"; p.Size = 24; p.Price = 24; p.Stock = 24; MySQLDBManager manager = new MySQLDBManager(); manager.Create(p); Product p1 = manager.SelectProduct(p); Assert.AreEqual(p.Title, p1.Title); Assert.AreEqual(p.Description, p1.Description); Assert.AreEqual(p.Color, p1.Color); Assert.AreEqual(p.Size, p1.Size); Assert.AreEqual(p.Price, p1.Price); Assert.AreEqual(p.Stock, p1.Stock); }