User

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

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;
using System.Data.SqlClient;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace supermarket
{
public partial class FormSeller : Form
{
//koneksi database
SqlConnection conn = new SqlConnection("Data Source=DESKTOP-V6TQFSL\\SQLEXPRESS;Initial
Catalog=DBSUPERMARKETMB;Integrated Security=True");
public FormSeller()
{
InitializeComponent();
KondisiAwal();
}
void KondisiAwal()
{
conn.Open();
string query = "select * from tb_Seller";
SqlDataAdapter da = new SqlDataAdapter(query, conn);
SqlCommandBuilder scbul = new SqlCommandBuilder(da);
var ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
conn.Close();
bersih();
}
void bersih()
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";

private void button4_Click(object sender, EventArgs e)


{
try
{
if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "")
{
MessageBox.Show("Pilih Dulu Category");
}
else
{
conn.Open();
string query = "insert into tb_Seller values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text +
"','" + textBox4.Text + "','" + textBox5.Text + "')";
SqlCommand cmd = new SqlCommand(query, conn);
cmd.ExecuteNonQuery();
MessageBox.Show("Data Sukser di Tambah");
conn.Close();
KondisiAwal();

}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

private void button5_Click(object sender, EventArgs e)


{
Application.Exit();
}

private void button6_Click(object sender, EventArgs e)


{
try
{
if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "")
{
MessageBox.Show("Pilih Dulu Category");
}
else
{
conn.Open();
string query = "update tb_Seller set SellerName='" + textBox2.Text + "',SellerAge='" + textBox3.Text +
"',SellerPhone='" + textBox4.Text + "',SellerPass='" + textBox5.Text+ "' where SellerId='" + textBox1.Text + "'";
SqlCommand cmd = new SqlCommand(query, conn);
cmd.ExecuteNonQuery();
MessageBox.Show("Data Berhasil Di Edit");
conn.Close();
KondisiAwal();
}
}
catch (Exception x)
{
MessageBox.Show(x.Message);
}
}

private void button7_Click(object sender, EventArgs e)


{
try
{
if (textBox1.Text == "")
{
MessageBox.Show("Pilih Dulu Category");
}
else
{
conn.Open();
string query = "delete from tb_Seller where SellerId='" + textBox1.Text + "'";
SqlCommand cmd = new SqlCommand(query, conn);
cmd.ExecuteNonQuery();
MessageBox.Show("Category Deleted sukcses");
conn.Close();
KondisiAwal();
}

}
catch (Exception x)
{
MessageBox.Show(x.ToString());
}
}

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)


{
//koding cari di datagridview
try
{
DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
textBox1.Text = row.Cells["SellerId"].Value.ToString();
textBox2.Text = row.Cells["SellerName"].Value.ToString();
textBox3.Text = row.Cells["SellerAge"].Value.ToString();
textBox4.Text = row.Cells["SellerPhone"].Value.ToString();
textBox5.Text = row.Cells["SellerPass"].Value.ToString();

}
catch (Exception x)
{
MessageBox.Show(x.ToString());

}
}

private void label8_Click(object sender, EventArgs e)


{
this.Hide();
FormLogin login = new FormLogin();
login.Show();
}
}
}

You might also like