private void btnCreateMaterial_Click(object sender, EventArgs e) { AssemMaterial mat = new AssemMaterial(); double cost = -1; double co2 = -1; double rval = -1; double laborCost = -1; double laborHours = -1; double dailyOutput = -1; if(!FoundNulls()) { if(!Double.TryParse(txtCost.Text, out cost)) MessageBox.Show("Cost value must be numeric."); else if (!Double.TryParse(txtCO2.Text, out co2)) MessageBox.Show("CO2 emission value must be numeric."); else if (!Double.TryParse(txtRValue.Text, out rval)) MessageBox.Show("R-Value value must be numeric."); else if (!Double.TryParse(txtLaborCost.Text, out laborCost)) MessageBox.Show("Labor cost value must be numeric."); else if (!Double.TryParse(txtlaborHours.Text, out laborHours)) MessageBox.Show("Labor hours value must be numeric."); else if (!Double.TryParse(txtDailyOutput.Text, out dailyOutput)) MessageBox.Show("Daily Output value must be numeric."); else { mat.Name = txtName.Text; mat.Description = txtDesc.Text; mat.CostPerUnit = cost; mat.CO2PerUnit = co2; mat.Unit = cboUnit.Text; mat.RValue = rval; this.createdMaterial = mat; MaterialLabor labor = new MaterialLabor(); labor.Cost = laborCost; labor.Hours = laborHours; labor.DailyOutPut = dailyOutput; this.createdMaterial.Labor = labor; this.createdMaterial.Summary = summ; this.DialogResult = DialogResult.OK; this.Close(); } } }
public List<AssemMaterial> getMaterialsByAssemblyName(String assemName) { List<AssemMaterial> materials = new List<AssemMaterial>(); using (OleDbConnection conn = this.getConnection()) { conn.Open(); using (OleDbCommand comm = conn.CreateCommand()) { comm.CommandType = CommandType.Text; comm.CommandText = "SELECT MatName, Description, CostPerUnit, CO2PerUnit, Unit, LaborCost, LaborHours, DailyOutput " + "FROM Material INNER JOIN Labor ON (Material.ID = Labor.MaterialID)" + "WHERE Material.ID IN " + "(SELECT MaterialID FROM Assem_Mat WHERE AssemblyID = " + "(SELECT ID FROM Assembly WHERE AssemName =?)) ORDER BY MatName;"; comm.Parameters.AddWithValue("@name", assemName); using (OleDbDataReader reader = comm.ExecuteReader()) { if (reader.HasRows) { materials = new List<AssemMaterial>(); while (reader.Read()) { AssemMaterial m = new AssemMaterial(); MaterialLabor labor = new MaterialLabor(); m.Name = reader["MatName"].ToString(); m.Description = reader["Description"].ToString(); m.CostPerUnit = (double)reader["CostPerUnit"]; m.CO2PerUnit = (double)reader["CO2PerUnit"]; m.Unit = reader["Unit"].ToString(); labor.Cost = (double)reader["LaborCost"]; labor.DailyOutPut = (double)reader["DailyOutput"]; labor.Hours = (double)reader["LaborHours"]; m.Labor = labor; materials.Add(m); } } } } conn.Close(); } return materials; }