Exemplo n.º 1
0
 private void LoadTable()
 {
     try
     {
         Koneksi        kon    = new Koneksi();
         SqlConnection  sqlcon = kon.getConnection();
         string         sql    = "select id_room, id_room_type,name,status from tb_room;";
         SqlCommand     sqlcom = new SqlCommand(sql, sqlcon);
         SqlDataAdapter sqlda  = new SqlDataAdapter();
         sqlda.SelectCommand = sqlcom;
         DataTable dTable = new DataTable();
         sqlda.Fill(dTable);
         dg_room.DataSource = dTable;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 2
0
 private void LoadTable()
 {
     try
     {
         Koneksi        kon    = new Koneksi();
         SqlConnection  sqlcon = kon.getConnection();
         string         sql    = "select id_customer,name, birthdate,address,phonenumber,card_type,card_number from tb_customer;";
         SqlCommand     sqlcom = new SqlCommand(sql, sqlcon);
         SqlDataAdapter sqlda  = new SqlDataAdapter();
         sqlda.SelectCommand = sqlcom;
         DataTable dTable = new DataTable();
         sqlda.Fill(dTable);
         dg_customer.DataSource = dTable; // here i have assign dTable object to the dataGridView1 object to display data.
         sqlcon.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 3
0
 private void LoadTable()
 {
     try
     {
         Koneksi        kon    = new Koneksi();
         SqlConnection  sqlcon = kon.getConnection();
         string         sql    = "select id_transaction, id_room, id_customer,datein, dateout,status from tb_transaction;";
         SqlCommand     sqlcom = new SqlCommand(sql, sqlcon);
         SqlDataAdapter sqlda  = new SqlDataAdapter();
         sqlda.SelectCommand = sqlcom;
         DataTable dTable = new DataTable();
         sqlda.Fill(dTable);
         dg_transaction.DataSource = dTable; // here i have assign dTable object to the dataGridView1 object to display data.
         sqlcon.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 4
0
 private void cb_roomtype()
 {
     try
     {
         Koneksi        kon       = new Koneksi();
         string         sql       = "select * from tb_room_type;";
         SqlConnection  sqlcon    = kon.getConnection();
         SqlCommand     sqlcom    = new SqlCommand(sql, sqlcon);
         SqlDataAdapter MyAdapter = new SqlDataAdapter();
         MyAdapter.SelectCommand = sqlcom;
         DataTable dTable = new DataTable();
         MyAdapter.Fill(dTable);
         cb_idroomtype.DataSource    = dTable;
         cb_idroomtype.ValueMember   = "id_room_type";
         cb_idroomtype.DisplayMember = "id_room_type";
         // MyConn2.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 5
0
 private void LoadTable()
 {
     try
     {
         Koneksi       kon    = new Koneksi();
         SqlConnection sqlcon = kon.getConnection();
         string        sql    = "select id_room_type,name,price,information from tb_room_type;";
         SqlCommand    sqlcom = new SqlCommand(sql, sqlcon);
         //  MyConn2.Open();
         //For offline connection we weill use  MySqlDataAdapter class.
         SqlDataAdapter sqlda = new SqlDataAdapter();
         sqlda.SelectCommand = sqlcom;
         DataTable dTable = new DataTable();
         sqlda.Fill(dTable);
         dg_roomtype.DataSource = dTable; // here i have assign dTable object to the dataGridView1 object to display data.
         sqlcon.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 6
0
 private void btn_update_Click(object sender, EventArgs e)
 {
     if (ValidateData() == 0)
     {
         Koneksi       kon      = new Koneksi();
         SqlConnection sqlcon   = kon.getConnection();
         string        msg      = string.Empty;
         string        birthday = dt_birthdate.Value.ToString("yyyy-MM-dd");
         using (sqlcon)
         {
             sqlcon.Open();
             string     sql    = "update tb_customer set name = @name, birthdate = @birth, address = @address, phonenumber=@phone, card_type=@ctype,card_number=@cnum where id_customer = @id";
             SqlCommand sqlcom = new SqlCommand(sql, sqlcon);
             using (sqlcom)
             {
                 sqlcom.Parameters.AddWithValue("@id", tb_idcust.Text);
                 sqlcom.Parameters.AddWithValue("@name", tb_name.Text);
                 sqlcom.Parameters.AddWithValue("@birth", birthday);
                 sqlcom.Parameters.AddWithValue("@address", tb_address.Text);
                 sqlcom.Parameters.AddWithValue("@phone", tb_phone.Text);
                 sqlcom.Parameters.AddWithValue("@ctype", cb_cardtype.Text);
                 sqlcom.Parameters.AddWithValue("@cnum", tb_cardnumber.Text);
                 int res = sqlcom.ExecuteNonQuery();
                 msg = (res != 0 ? "Data has been updated." : "Oops, something went wrong.");
             }
             sqlcon.Close();
         }
         MessageBox.Show(msg);
         Reset();
         AutoGenerate();
         LoadTable();
     }
     else
     {
         MessageBox.Show("Please Fix The Error");
     }
 }
Exemplo n.º 7
0
        private void btn_delete_Click(object sender, EventArgs e)
        {
            Koneksi       kon    = new Koneksi();
            SqlConnection sqlcon = kon.getConnection();
            string        msg    = string.Empty;

            using (sqlcon)
            {
                sqlcon.Open();
                string     sql    = "delete from tb_customer where id_customer = @id";
                SqlCommand sqlcom = new SqlCommand(sql, sqlcon);
                using (sqlcon)
                {
                    sqlcom.Parameters.AddWithValue("@id", tb_idcust.Text);
                    int res = sqlcom.ExecuteNonQuery();
                    msg = (res != 0 ? "Data has been deleted " : "Oops, something went wrong");
                }
                sqlcon.Close();
            }
            MessageBox.Show(msg);
            Reset();
            AutoGenerate();
            LoadTable();
        }
Exemplo n.º 8
0
 private void btn_update_Click(object sender, EventArgs e)
 {
     if (ValidateData() == 0)
     {
         Koneksi       kon    = new Koneksi();
         SqlConnection sqlcon = kon.getConnection();
         string        msg    = string.Empty;
         using (sqlcon)
         {
             sqlcon.Open();
             string     sql    = "update tb_admin set name = @name, username = @username,password=@password, address = @address, phonenumber=@phone, admin_type=@admintype where id_admin = @id";
             SqlCommand sqlcom = new SqlCommand(sql, sqlcon);
             using (sqlcom)
             {
                 sqlcom.Parameters.AddWithValue("@id", tb_idadmin.Text);
                 sqlcom.Parameters.AddWithValue("@name", tb_name.Text);
                 sqlcom.Parameters.AddWithValue("@username", tb_username.Text);
                 sqlcom.Parameters.AddWithValue("@password", tb_password.Text);
                 sqlcom.Parameters.AddWithValue("@address", tb_address.Text);
                 sqlcom.Parameters.AddWithValue("@phone", tb_phone.Text);
                 sqlcom.Parameters.AddWithValue("@admintype", cb_admintype.Text);
                 int res = sqlcom.ExecuteNonQuery();
                 msg = (res != 0 ? "Data has been updated." : "Oops, something went wrong.");
             }
             sqlcon.Close();
         }
         MessageBox.Show(msg);
         Reset();
         AutoGenerate();
         LoadTable();
     }
     else
     {
         MessageBox.Show("Please Fix The Error");
     }
 }
Exemplo n.º 9
0
        private void AutoGenerate()
        {
            Koneksi       konn    = new Koneksi();
            SqlConnection sqlconn = konn.getConnection();

            using (sqlconn)
            {
                string kode      = "1";
                string no        = "1";
                string kodeten   = "1";
                string noten     = "1";
                int    numtenint = 1;
                sqlconn.Open();
                string     sqlcode       = "select  top 1   SUBSTRING(id_customer,1,3)  from tb_customer order by id_customer desc";
                string     sqlnum        = " select  top 1   SUBSTRING(id_customer,4,1)  from tb_customer order by id_customer desc";
                string     sqlcodeten    = "select  top 1   SUBSTRING(id_customer,1,2)  from tb_customer order by id_customer desc";
                string     sqlnumten     = " select  top 1   SUBSTRING(id_customer,3,2)  from tb_customer order by id_customer desc";
                SqlCommand sqlcomcode    = new SqlCommand(sqlcode, sqlconn);
                SqlCommand sqlcomnum     = new SqlCommand(sqlnum, sqlconn);
                SqlCommand sqlcomcodeten = new SqlCommand(sqlcodeten, sqlconn);
                SqlCommand sqlcomnumten  = new SqlCommand(sqlnumten, sqlconn);

                using (sqlcomcode)
                {
                    SqlDataReader drcode = sqlcomcode.ExecuteReader();
                    if (drcode.Read())
                    {
                        kode = drcode.GetString(0);
                    }
                }
                sqlconn.Close();
                sqlconn.Open();
                using (sqlcomcodeten)
                {
                    SqlDataReader drcodeten = sqlcomcodeten.ExecuteReader();
                    if (drcodeten.Read())
                    {
                        kodeten = drcodeten.GetString(0);
                    }
                }
                sqlconn.Close();

                sqlconn.Open();
                using (sqlcomnumten)
                {
                    SqlDataReader drnumten = sqlcomnumten.ExecuteReader();
                    if (drnumten.Read())
                    {
                        noten     = drnumten.GetString(0);
                        numtenint = Convert.ToInt16(noten);
                    }
                }
                sqlconn.Close();

                sqlconn.Open();
                using (sqlcomnum)
                {
                    SqlDataReader drnum = sqlcomnum.ExecuteReader();
                    if (drnum.Read())
                    {
                        string num    = drnum.GetString(0);
                        int    numint = Convert.ToInt16(num);
                        if (numint == 9)
                        {
                            numint = numtenint;
                            kode   = kodeten;
                        }
                        int nomor = numint + 1;
                        no = Convert.ToString(nomor);
                    }
                }
                tb_idcust.Text = kode + no;

                sqlconn.Close();


                tb_idcust.Text = kode + no;
            }
        }