private void update_btn_Click(object sender, EventArgs e) { string errorMsg = ""; bool tempHold; decimal customVal; tempHold = decimal.TryParse(unBox.Text, out customVal); if (tempHold == false) { customVal = -1; } if (obCo.Text == "Student") { student stuOb = new student(obCo.Text, idBox.Text, firstBox.Text, lastBox.Text, unCo.Text, customVal); errorMsg = stuOb.ErrorMsg(); if (errorMsg == "")// had to make these gross looking nested if statements to generate the errorMsg value twice to output SQL exceptions to the user (breaking the unique value restriction on BuddyId) { stuOb.updateSQL(oldBox.Text); errorMsg = stuOb.ErrorMsg(); if (errorMsg == "") { outLb.Text = stuOb.displayMe() + "\n\nStudent object updated successfully!"; } else { outLb.Text = errorMsg; } } else { outLb.Text = errorMsg; } } if (obCo.Text == "Teacher") { teacher teaOb = new teacher(obCo.Text, idBox.Text, firstBox.Text, lastBox.Text, unCo.Text, customVal); errorMsg = teaOb.ErrorMsg(); if (errorMsg == "") { teaOb.updateSQL(oldBox.Text); errorMsg = teaOb.ErrorMsg(); if (errorMsg == "") { outLb.Text = teaOb.displayMe() + "\n\nTeacher object updated successfully!"; } else { outLb.Text = errorMsg; } } else { outLb.Text = errorMsg; } } if (obCo.Text == "Administrator") { administrator admOb = new administrator(obCo.Text, idBox.Text, firstBox.Text, lastBox.Text, unCo.Text, customVal); errorMsg = admOb.ErrorMsg(); if (errorMsg == "") { admOb.updateSQL(oldBox.Text); errorMsg = admOb.ErrorMsg(); if (errorMsg == "") { outLb.Text = admOb.displayMe() + "\n\nAdministrator object updated successfully!"; } else { outLb.Text = errorMsg; } } else { outLb.Text = errorMsg; } } if (errorMsg == "") { cancel_btn.Text = "Finish"; update_btn.Visible = false; } }
private void button1_Click(object sender, EventArgs e) { //new sql stuffffff /* * string connString = "Data Source = sql.neit.edu,4500; Initial Catalog =SE245_CBrown; User ID=se245_Cbrown; Password=Hsilop401;"; * SqlConnection connection = new SqlConnection(connString); * string selectStatement = "SELECT ProductCode, Description, UnitPrice, OnHandQuantity FROM Products WHERE ProductCode= @ProductCode"; * SqlCommand selectCommand = new SqlCommand(selectStatement, connection); * selectCommand.Parameters.AddWithValue("@ProductCode", productID); * connection.Open(); * SqlDataReader customerReader = selectCommand.ExecuteReader(); * customerReader.Read(); * connection.Close(); * */ //end of new sql stufffffffffff bool fff; string errorMsg = ""; decimal customVal; fff = decimal.TryParse(unBox.Text, out customVal); if (fff == false) { customVal = -1; } if (obCo.Text == "Student") { student stuOb = new student(obCo.Text, idBox.Text, firstBox.Text, lastBox.Text, unCo.Text, customVal); if (errorMsg == "") // had to make these gross looking nested if statements to generate the errorMsg value twice to output SQL exceptions to the user (breaking the unique value restriction on BuddyId) { //no i didn't that was dumbbbb stuOb.sendSQL(); errorMsg = stuOb.ErrorMsg(); if (errorMsg == "") { outLb.Text = stuOb.displayMe() + "\n\nStudent object created successfully!"; } else { outLb.Text = errorMsg; } } else { outLb.Text = errorMsg; } } if (obCo.Text == "Teacher") { teacher teaOb = new teacher(obCo.Text, idBox.Text, firstBox.Text, lastBox.Text, unCo.Text, customVal); if (errorMsg == "") { teaOb.sendSQL(); errorMsg = teaOb.ErrorMsg(); if (errorMsg == "") { outLb.Text = teaOb.displayMe() + "\n\nTeacher object created successfully!"; } else { outLb.Text = errorMsg; } } else { outLb.Text = errorMsg; } } if (obCo.Text == "Administrator") { administrator admOb = new administrator(obCo.Text, idBox.Text, firstBox.Text, lastBox.Text, unCo.Text, customVal); if (errorMsg == "") { admOb.sendSQL(); errorMsg = admOb.ErrorMsg(); if (errorMsg == "") { outLb.Text = admOb.displayMe() + "\n\nAdministrator object created successfully!"; } else { outLb.Text = errorMsg; } } else { outLb.Text = errorMsg; } } }