Ejemplo n.º 1
0
        public int doInsertDaftarUKM(StudentUKM acc)
        {
            con.Open();
            SqlCommand cmd = new SqlCommand("insert into StudentUKM(id_account, id_ukm, Status) values(@account, @ukm, @status)", con);

            cmd.Parameters.AddWithValue("@account", acc.IdAccount);
            cmd.Parameters.AddWithValue("@ukm", acc.Ukmid);
            cmd.Parameters.AddWithValue("@status", "Pending");

            int result = cmd.ExecuteNonQuery();

            if (result == 1)
            {
                con.Close();
                return(1);
            }
            else
            {
                con.Close();
                return(0);
            }
        }
Ejemplo n.º 2
0
        public int doInsertCaptainAdmin(Account acc, StudentUKM ukm)
        {
            con.Open();
            int        hasil = 0;
            SqlCommand cmd   = new SqlCommand("insert into Account(Nim, Name, Gender, Address, Phonenumber, Faculty, Major, Batch, Username, Password, Status) values(@nim, @name, @gender, @address, @phonenumber, @faculty, @major, @batch, @username, @password, @status)", con);

            cmd.Parameters.AddWithValue("@nim", acc.Nim);
            cmd.Parameters.AddWithValue("@name", acc.Name);
            cmd.Parameters.AddWithValue("@gender", acc.Gender);
            cmd.Parameters.AddWithValue("@address", acc.Address);
            cmd.Parameters.AddWithValue("@phonenumber", acc.PhoneNumber);
            cmd.Parameters.AddWithValue("@faculty", acc.Faculty);
            cmd.Parameters.AddWithValue("@major", acc.Major);
            cmd.Parameters.AddWithValue("@batch", acc.Batch);
            cmd.Parameters.AddWithValue("@username", acc.Username);
            cmd.Parameters.AddWithValue("@password", acc.Password);
            cmd.Parameters.AddWithValue("@status", "Captain");

            int result = cmd.ExecuteNonQuery();

            if (result == 1)
            {
                SqlCommand cmd2 = new SqlCommand("insert into StudentUKM(id_ukm, Status) values(@idukm, @status)", con);
                cmd2.Parameters.AddWithValue("@idukm", ukm.Ukmid);
                cmd2.Parameters.AddWithValue("@status", "Active");

                int result2 = cmd2.ExecuteNonQuery();
                if (result2 == 1)
                {
                    SqlCommand cmd3 = new SqlCommand("select top 1 * from Account order by id desc", con);

                    SqlDataAdapter da3 = new SqlDataAdapter(cmd3);
                    DataTable      dt3 = new DataTable();
                    da3.Fill(dt3);

                    if (dt3.Rows.Count > 0)
                    {
                        for (int i = 0; i < dt3.Rows.Count; i++)
                        {
                            id = dt3.Rows[i]["id"].ToString();
                        }

                        SqlCommand     cmd4 = new SqlCommand("select top 1 * from StudentUKM order by id desc", con);
                        SqlDataAdapter da4  = new SqlDataAdapter(cmd4);
                        DataTable      dt4  = new DataTable();
                        da4.Fill(dt4);

                        if (dt4.Rows.Count > 0)
                        {
                            for (int i = 0; i < dt4.Rows.Count; i++)
                            {
                                idstudenukm = dt4.Rows[i]["id"].ToString();
                            }

                            SqlCommand cmd5 = new SqlCommand("update StudentUKM set id_account = @id where id = @idd", con);
                            cmd5.Parameters.AddWithValue("@id", id);
                            cmd5.Parameters.AddWithValue("@idd", idstudenukm);
                            int result5 = cmd5.ExecuteNonQuery();
                            if (result5 > 0)
                            {
                                con.Close();
                                hasil = 1;
                            }
                            else
                            {
                                con.Close();
                                hasil = 0;
                            }
                        }
                        else
                        {
                            hasil = 0;
                        }
                    }
                }
                else
                {
                    hasil = 0;
                }
            }
            else
            {
                hasil = 0;
            }

            return(hasil);
        }