Example #1
0
        //Insert Menu
         public bool Insert(bayarclass c)
        {
             //Creating a default return type and setting its value to false
            bool isSuccess = false;
            //Step1 : connect DataBase
             SqlConnection conn = new SqlConnection(myconnstrng);
             try
             {
                 //Step2 : Create a SQL Query to insert Data
                 string sql = "INSERT INTO tbl_bayar (NamaPemesan, EmailPemesan, NoTelepon, TitleWisatawan, NamaWisatawan, MetodeBayar, Nominal) VALUES (@NamaPemesan, @EmailPemesan, @NoTelepon, @TitleWisatawan, @NamaWisatawan, @MetodeBayar, @Nominal)";
                 //Membuat SQL Command menggunakan sql dan conn
                 SqlCommand cmd = new SqlCommand(sql, conn);
                 //Membuat parameters untuk mengambil data
                 cmd.Parameters.AddWithValue("@NamaPemesan", c.NamaPemesan);
                 cmd.Parameters.AddWithValue("@EmailPemesan", c.EmailPemesan);
                 cmd.Parameters.AddWithValue("@NoTelepon", c.NoTelepon);
                 cmd.Parameters.AddWithValue("@TitleWisatawan", c.TitleWisatawan);
                 cmd.Parameters.AddWithValue("@NamaWisatawan", c.NamaWisatawan);
                 cmd.Parameters.AddWithValue("@MetodeBayar", c.MetodeBayar);
                 cmd.Parameters.AddWithValue("@Nominal", c.Nominal);

                 //Memanggil/membuka Connection
                 conn.Open();
                 int rows = cmd.ExecuteNonQuery();
                 //If the query runs succesfully then the value of rows will be greater then zero else it value will be 0
                 if(rows > 0)
                 {
                     isSuccess = true;
                 }
                 else
                 {
                     isSuccess = false;
                 }

             }
             catch(Exception e)
             {

             }
             finally
             {
                 conn.Close();
             }
             return isSuccess;
        }
Example #2
0
        //Membuat methode update
        public bool Update(bayarclass c)
        {
            //Create a default return type and set its default value to false
            bool isSuccess = false;
            SqlConnection conn = new SqlConnection(myconnstrng);
            try
            {
                //SQL update database
                string sql = "UPDATE tbl_bayar SET  EmailPemesan=@EmailPemesan, NoTelepon=@NoTelepon, TitleWisatawan=@TitleWisatawan, NamaWisatawan=@NamaWisatawan, MetodeBayar=@MetodeBayar, Nominal=@Nominal WHERE NamaPemesan=@NamaPemesan";
                //Membuat SQL Command menggunakan sql dan conn
                SqlCommand cmd = new SqlCommand(sql, conn);
                //Membuat parameters untuk mengambil data

                cmd.Parameters.AddWithValue("@NamaPemesan", c.NamaPemesan);
                cmd.Parameters.AddWithValue("@EmailPemesan", c.EmailPemesan);
                cmd.Parameters.AddWithValue("@NoTelepon", c.NoTelepon);
                cmd.Parameters.AddWithValue("@TitleWisatawan", c.TitleWisatawan);
                cmd.Parameters.AddWithValue("@NamaWisatawan", c.NamaWisatawan);
                cmd.Parameters.AddWithValue("@MetodeBayar", c.MetodeBayar);
                cmd.Parameters.AddWithValue("@Nominal", c.Nominal);
                
                //Memanggil/membuka Connection
                conn.Open();
                int rows = cmd.ExecuteNonQuery();
                //If the query runs succesfully then the value of rows will be greater then zero else it value will be 0
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception e)
            {
              
            }
            finally
            {
                conn.Close();
            }
            return isSuccess;
        }
Example #3
0
        //Membuat Method Delete
        public bool Delete(bayarclass c)
        {
            //Create a default return type and set its default value to false
            bool isSuccess = false;
            //membuat koneksi sql
            SqlConnection conn = new SqlConnection(myconnstrng);
            try
            {
                //SQL Delete database
                string sql = "DELETE FROM tbl_bayar WHERE NamaPemesan=@NamaPemesan";
                //Membuat SQL Command menggunakan sql dan conn
                SqlCommand cmd = new SqlCommand(sql, conn);
                //Membuat parameters untuk mengambil data
                cmd.Parameters.AddWithValue("@NamaPemesan", c.NamaPemesan);
                //Memanggil/membuka Connection
                conn.Open();
                int rows = cmd.ExecuteNonQuery();
                //If the query runs succesfully then the value of rows will be greater then zero else it value will be 0
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch(Exception e)
            {

            }
            finally
            {
                conn.Close();
            }
            return isSuccess;
        }