// Data Source -- update Model public bool DSupdateModel(ProductModel model) { try { // set adapter mta = new canoeDataSetTableAdapters.Canoe_ModelTableAdapter(); // update mta.UpdateModelQuery( model.Brand, model.Capacity, model.Dimension, model.Weight, model.EnergySource, model.Discription, model.RentDeposite, model.RentRatePerDay, model.CategoryID, model.ModelID ); return true; } catch (Exception ex) { throw new CanoeException("DSupdateModel", ex.Message); } }
// update Model public bool updateDSModelDB(ProductModel model) { db = new DatabaseAccess(); db.DSupdateModel(model); return true; }
// DAO -- update model public bool DAOupdateModel(ProductModel model) { try { // connect GetConnection(); // update pserson SqlCommand cmd; cmd = new SqlCommand(updateModelQuery, con); cmd.Parameters.AddWithValue("@ModelID", model.ModelID); cmd.Parameters.AddWithValue("@Brand", model.Brand); cmd.Parameters.AddWithValue("@Capacity", model.Capacity); cmd.Parameters.AddWithValue("@Dimension", model.Dimension); cmd.Parameters.AddWithValue("@Weight", model.Weight); cmd.Parameters.AddWithValue("@EnergySource", model.EnergySource); cmd.Parameters.AddWithValue("@Discription", model.Discription); cmd.Parameters.AddWithValue("@RentDeposite", model.RentDeposite); cmd.Parameters.AddWithValue("@RentRatePerDay", model.RentRatePerDay); cmd.Parameters.AddWithValue("@CategoryID", model.CategoryID); cmd.ExecuteScalar(); // close con.Close(); con.Dispose(); cmd.Dispose(); return true; } catch (Exception ex) { throw new CanoeException("DAOupdateModel", ex.Message); } }
// insert Model public bool insertDSModelDB(ProductModel model) { db = new DatabaseAccess(); db.DSinsertModel(model); return true; }
// // --- Model ----------------------- // // make Model instance public ProductModel makeModel(String modelID, String brand, String capacity, String dimension, int weight, String energySource, String discription, decimal rentDeposite, decimal rentRatePerDay, int categoryID) { ProductModel model = new ProductModel( modelID, brand, capacity, dimension, weight, energySource, discription, rentDeposite, rentRatePerDay, categoryID ); return model; }
// model make instance private ProductModel makeModelInstance() { model = manage.makeModel( modelID, brand, capacity, dimension, int.Parse(weight), energySource, discription, decimal.Parse(rentDeposite), decimal.Parse(rentRatePerDay), int.Parse(categoryID)); return model; }
// update button click private void btnDSUpdate_Click(object sender, EventArgs e) { try { // get input item getInputItem(); // input check CheckModel(); // make instance model = makeModelInstance(); // update manage.updateDSModelDB(model); MessageBox.Show("Model has been updated"); } catch (CanoeException) { } catch (Exception ex) { MessageBox.Show(ex.Message); } }
// // tab: model // // -- event Using DAO -------------------------- // create button click private void btnDAOCreate_Click(object sender, EventArgs e) { try { // get input item getInputItem(); // input check CheckModel(); // make instance model = makeModelInstance(); // insert manage.insertDAOModel(model); MessageBox.Show("New Model has been added"); } catch (CanoeException) { } catch (Exception ex) { MessageBox.Show(ex.Message); } }