Ejemplo n.º 1
0
        private void submitAddressBtn_Click(object sender, RoutedEventArgs e)
        {
            ExpenseManagerData.AddressInfo newAddress = new ExpenseManagerData.AddressInfo();

            newAddress.id = GenerateId();

            newAddress.name = nameBtn.Text;
            newAddress.mobile = mobBtn.Text;
            newAddress.home = homeBtn.Text;
            newAddress.office = ofcBtn.Text;
            newAddress.address = addressBtn.Text;
            newAddress.email = emailBtn.Text;
            newAddress.note = noteBtn.Text;

            ExpenseManagerDb.DbInteraction.DoEnterAddress(newAddress);

            addressTC.SelectedIndex = 0;
        }
Ejemplo n.º 2
0
        private static List<AddressInfo> QueryAllAddressList()
        {
            List<AddressInfo> AllAddressList = new List<AddressInfo>();
            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 address;";
                MySql.Data.MySqlClient.MySqlDataReader msqlReader = msqlCommand.ExecuteReader();

                while (msqlReader.Read())
                {
                    AddressInfo Address = new AddressInfo();

                    Address.id = msqlReader.GetString("id");
                    Address.name = msqlReader.GetString("name");
                    Address.mobile = msqlReader.GetString("mobile");
                    Address.home = msqlReader.GetString("home");
                    Address.office = msqlReader.GetString("office");
                    Address.address = msqlReader.GetString("address");
                    Address.email = msqlReader.GetString("email");
                    Address.note = msqlReader.GetString("note");

                    AllAddressList.Add(Address);
                }
            }

            catch (Exception er)
            {
            }
            finally
            {
                //always close the connection
                msqlConnection.Close();
            }

            return AllAddressList;
        }
Ejemplo n.º 3
0
 public static int DoEnterAddress(AddressInfo NewAddress)
 {
     return DoRegisterNewAddressindb(NewAddress);
 }
Ejemplo n.º 4
0
        private static int DoRegisterNewAddressindb(AddressInfo NewAddress)
        {
            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 address(id,name,mobile,home,office,address,email,note) "
                                    + "VALUES(@id,@name,@mobile,@home,@office,@address,@email,@note)";

                msqlCommand.Parameters.AddWithValue("@id", NewAddress.id);
                msqlCommand.Parameters.AddWithValue("@name", NewAddress.name);
                msqlCommand.Parameters.AddWithValue("@mobile", NewAddress.mobile);
                msqlCommand.Parameters.AddWithValue("@home", NewAddress.home);
                msqlCommand.Parameters.AddWithValue("@office", NewAddress.office);
                msqlCommand.Parameters.AddWithValue("@address", NewAddress.address);
                msqlCommand.Parameters.AddWithValue("@email", NewAddress.email);
                msqlCommand.Parameters.AddWithValue("@note", NewAddress.note);

                msqlCommand.ExecuteNonQuery();

                returnVal = 1;
            }
            catch (Exception er)
            {
                returnVal = 0;
            }
            finally
            {
                //always close the connection
                msqlConnection.Close();
            }
            return returnVal;
        }