public static int DoEnterContactus(ContactusInfo NewContactus) { return DoRegisterNewContactusindb(NewContactus); }
private static int DoRegisterNewContactusindb(ContactusInfo NewContactus) { int returnVal = 0; MySql.Data.MySqlClient.MySqlConnection msqlConnection = OpenDbConnection(); try { //define the command reference MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand(); //define the connection used by the command object msqlCommand.Connection = msqlConnection; msqlCommand.CommandText = "INSERT INTO contactus(id,feedDate,name,address,mobileno,email,type,feedback) " + "VALUES(@id,@feedDate,@name,@address,@mobileno,@email,@type,@feedback)"; msqlCommand.Parameters.AddWithValue("@id", NewContactus.id); msqlCommand.Parameters.AddWithValue("@feedDate", NewContactus.feedDate); msqlCommand.Parameters.AddWithValue("@name", NewContactus.name); msqlCommand.Parameters.AddWithValue("@address", NewContactus.address); msqlCommand.Parameters.AddWithValue("@mobileno", NewContactus.mobileno); msqlCommand.Parameters.AddWithValue("@email", NewContactus.email); msqlCommand.Parameters.AddWithValue("@type", NewContactus.type); msqlCommand.Parameters.AddWithValue("@feedback", NewContactus.feedback); msqlCommand.ExecuteNonQuery(); returnVal = 1; } catch (Exception er) { returnVal = 0; } finally { //always close the connection msqlConnection.Close(); } return returnVal; }
private static List<ContactusInfo> QueryAllContactusList() { List<ContactusInfo> ContactusList = new List<ContactusInfo>(); MySql.Data.MySqlClient.MySqlConnection msqlConnection = OpenDbConnection(); try { //define the command reference MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand(); msqlCommand.Connection = msqlConnection; msqlCommand.CommandText = "Select * From contactus;"; MySql.Data.MySqlClient.MySqlDataReader msqlReader = msqlCommand.ExecuteReader(); while (msqlReader.Read()) { ContactusInfo Contactus = new ContactusInfo(); Contactus.id = msqlReader.GetString("id"); Contactus.feedDate = msqlReader.GetDateTime("feedDate"); Contactus.name = msqlReader.GetString("name"); Contactus.address = msqlReader.GetString("address"); Contactus.mobileno = msqlReader.GetString("mobileno"); Contactus.email = msqlReader.GetString("email"); Contactus.type = msqlReader.GetString("type"); Contactus.feedback = msqlReader.GetString("feedback"); ContactusList.Add(Contactus); } } catch (Exception er) { } finally { //always close the connection msqlConnection.Close(); } return ContactusList; }
private void submitFdBckBtn_Click(object sender, RoutedEventArgs e) { if (!nameTB.Text.Equals("") && !addressTB.Text.Equals("") && !mobilenoTB.Text.Equals("") && !emailTB.Text.Equals("") && !typeCB.Text.Equals("") && !contactusTB.Text.Equals("")) { ShoppingMallData.ContactusInfo newContactus = new ShoppingMallData.ContactusInfo(); newContactus.id = GenerateId(); newContactus.feedDate = feedDateDp.SelectedDate.Value; newContactus.name = nameTB.Text; newContactus.address = addressTB.Text; newContactus.mobileno = mobilenoTB.Text; newContactus.email = emailTB.Text; newContactus.type = typeCB.Text; newContactus.feedback = contactusTB.Text; ShoppingMallDb.DbInteraction.DoEnterContactus(newContactus); clearFeedBackFields(); fetchFeedBackData(); } else { MessageBox.Show("Please Insert Info Properly"); } }