0% found this document useful (0 votes)
13 views3 pages

code2pdf_67294b4b2b839

Uploaded by

linnmongt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

code2pdf_67294b4b2b839

Uploaded by

linnmongt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Tugas2_FahmirizalBudiRamadhan
{
public partial class FAnggota : Form
{
public FAnggota()
{
InitializeComponent();
}

public void bersih(Control ctrlapa)


{
foreach (Control kontrol in ctrlapa.Controls)
{
{
if (kontrol is TextBox)
{
((TextBox)kontrol).Text = "";
}
else if (kontrol.Controls.Count > 0)
{
bersih(kontrol);
}
}
}
}

private void panel5_Paint(object sender, PaintEventArgs e)


{

private void FAnggota_Paint(object sender, PaintEventArgs e)


{
KF.untukRounded(panel2, 1, 1, 30, 30);
KF.untukRounded(panel3, 20, 20, 1, 1);
KF.untukRounded(panel12, 20, 20, 1, 1);
KF.untukRounded(dataGridView1, 20, 20, 1, 1);
KF.untukRounded(panel18, 30, 30, 30, 30);
KF.untukRounded(panel19, 30, 1, 1, 30);
KF.untukRounded(button1, 1, 30, 30, 1);
}

private void panel4_Paint(object sender, PaintEventArgs e)


{

private void label6_Click(object sender, EventArgs e)


{

private void FAnggota_Load(object sender, EventArgs e)


{
dataGridView1.MultiSelect = false;
dataGridView1.CellPainting += dataGridView1_CellPainting;
}

private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)


{
// Periksa apakah sel saat ini adalah header kolom
if (e.RowIndex == -1 && e.ColumnIndex >= 0)
{
// Mengatur background dan garis batas header
e.PaintBackground(e.ClipBounds, true);

// Buat StringFormat untuk mengatur teks di tengah


StringFormat sf = new StringFormat
{
Alignment = StringAlignment.Center, // Horizontal Center
LineAlignment = StringAlignment.Center // Vertical Center
};

// Menggambar teks header secara manual


e.Graphics.DrawString(
e.Value?.ToString(), // Nilai teks dari header
e.CellStyle.Font, // Font yang digunakan
Brushes.Black, // Warna teks
e.CellBounds, // Area cell
sf // Pengaturan alignment
);

// Mencegah rendering default


e.Handled = true;
}
}

int norut = 0;
string kondisi = "simpan";
int lokasi_ubah;

private void pictureBox1_Click(object sender, EventArgs e)


{
if (kondisi == "simpan")
{
norut++;

dataGridView1.Rows.Add("" + norut, "" + txt_nama.Text, "" + txt_email.Text, "" + txt_alamat.Text, "" + txt_user.Text, "" + txt_pass.Text, "Anggota"

}
else if (kondisi == "ubah")
{
dataGridView1.Rows[lokasi_ubah].Cells[1].Value = txt_nama.Text;
dataGridView1.Rows[lokasi_ubah].Cells[2].Value = txt_email.Text;
dataGridView1.Rows[lokasi_ubah].Cells[3].Value = txt_alamat.Text;
dataGridView1.Rows[lokasi_ubah].Cells[4].Value = txt_user.Text;
dataGridView1.Rows[lokasi_ubah].Cells[5].Value = txt_pass.Text;
DialogInfo DI = new DialogInfo("Success", "Data Berhasil Diedit !", Properties.Resources.Ok_32px, Color.FromArgb(57, 155, 53));
DI.ShowDialog();
kondisi = "simpan";
}

bersih(this);
dataGridView1.ClearSelection();
}

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)


{
int idx_baris = dataGridView1.CurrentCell.RowIndex;
int idx_kolom = dataGridView1.CurrentCell.ColumnIndex;

if (idx_kolom == 7)
{
dialogtanya DT = new dialogtanya("Are You Sure ?", "Do you really want edit this data? You will be able to undo this action.");
DialogResult setuju = DT.ShowDialog();
if (setuju == DialogResult.Yes)
{
lokasi_ubah = idx_baris;
kondisi = "ubah";
string nama = dataGridView1.Rows[idx_baris].Cells[1].Value.ToString();
string email = dataGridView1.Rows[idx_baris].Cells[2].Value.ToString();
string alamat = dataGridView1.Rows[idx_baris].Cells[3].Value.ToString();
string user = dataGridView1.Rows[idx_baris].Cells[4].Value.ToString();
string pass = dataGridView1.Rows[idx_baris].Cells[5].Value.ToString();

txt_nama.Text = nama;
txt_email.Text = email;
txt_alamat.Text = alamat;
txt_user.Text = user;
txt_pass.Text = pass;

}
else if (idx_kolom == 8)
{
dialogtanya DT = new dialogtanya("Are You Sure ?", "Do you really want delete this data? You will not be able to undo this action.");
DialogResult setuju = DT.ShowDialog();
if (setuju == DialogResult.Yes)
{
dataGridView1.Rows.RemoveAt(idx_baris);
DialogInfo DI = new DialogInfo("Success", "Data Berhasil Dihapus !", Properties.Resources.Ok_32px, Color.FromArgb(57, 155, 53));
DI.ShowDialog();
}
}
}

private void button1_Click(object sender, EventArgs e)


{
string cari = txtcari.Text;
string adagak = "ga";
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
string namaagt = dataGridView1.Rows[i].Cells[1].Value.ToString();

if (namaagt == cari)
{
adagak = "ada";
lokasi_ubah = i;
kondisi = "ubah";
string nama = dataGridView1.Rows[i].Cells[1].Value.ToString();
string email = dataGridView1.Rows[i].Cells[2].Value.ToString();
string alamat = dataGridView1.Rows[i].Cells[3].Value.ToString();
string user = dataGridView1.Rows[i].Cells[4].Value.ToString();
string pass = dataGridView1.Rows[i].Cells[5].Value.ToString();

txt_nama.Text = nama;
txt_email.Text = email;
txt_alamat.Text = alamat;
txt_user.Text = user;
txt_pass.Text = pass;
}
}
if (adagak == "ga")
{
System.Media.SoundPlayer player = new System.Media.SoundPlayer(Properties.Resources.awas);
player.Play();
DialogInfo DI = new DialogInfo("Peringatan", "Data Tidak Ditemukan !", Properties.Resources.Attention_32px, Color.FromArgb(255, 202, 40));
DI.ShowDialog();
}
}

private void dataGridView1_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e)


{

private void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e)


{
if (e.ColumnIndex == 8 && e.RowIndex > -1)
{
dataGridView1.Cursor = Cursors.Hand; // Set cursor to Hand for column index 8
} else if (e.ColumnIndex == 7 && e.RowIndex > -1)
{
dataGridView1.Cursor = Cursors.Hand; // Set cursor to Hand for column index 8
}
else
{
dataGridView1.Cursor = Cursors.Default; // Set cursor to Hand for column index 8
}
}

private void dataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e)


{
}
}
}

You might also like