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

Form1

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

namespace Tugas5_2
{

public partial class Form1 : Form


{
public Form1()
{

InitializeComponent();
}

private void buttonLogin_Click(object sender, EventArgs e)


{
bool login = false;
foreach (NorthwindDataSet.TabelUserRow row in
northwindDataSet.TabelUser)//bandingkan satu per satu
{
if (row.UserName.Equals(textBoxUsername.Text) &&
row.Password.Equals(textBoxPassword.Text))
{
login = true;// jika kombinasi id dan password cocok
}
}
if (login)// jika login berhasil
{
MessageBox.Show("Login berhasil");
FormData newform = new FormData();
this.Hide();
newform.ShowDialog();
}
else
{
MessageBox.Show("Password atau ID tidak sesuai", "Login gagal");//jikalogin gagal
textBoxPassword.Clear();
}
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the
'loginIDDataSet.TabelUser' table. You can move, or remove it, as needed.
this.tabelUserTableAdapter.Fill(this.northwindDataSet.TabelUser);
}
}
}
FormData

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

namespace Tugas5_2
{
public partial class FormData : Form
{
public FormData()
{
InitializeComponent();
}

SqlConnection connection = new SqlConnection(@"Data Source=LENOVO\


SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True");
SqlCommand command;

private void FormData_Load(object sender, EventArgs e)


{
fungsi();
}

private void fungsi()


{
this.customersTableAdapter.Fill(this.northwindDataSet.Customers);
dataGridView1.DataSource = customersBindingSource;
}

private void buttonShowr_Click(object sender, EventArgs e)


{
bool showr = true;
if (showr)// jika login berhasil
{
FormCr newform = new FormCr();
this.Hide();
newform.ShowDialog();
}
}

public void open()


{
if (connection.State == ConnectionState.Closed)
{
connection.Open();
}
}
public void close()
{
if (connection.State == ConnectionState.Open)
{
connection.Close();
}
}

public void myQuery(string query)


{
try
{
open();
command = new SqlCommand(query, connection);

if (command.ExecuteNonQuery() == 1)
{
MessageBox.Show("query executed");
}
else
{
MessageBox.Show("query not executed");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
close();
}
}

private void buttonAdd_Click(object sender, EventArgs e)


{
string addQuery = "insert into Customers values('" + textBoxCustomer.Text +
"','" + textBoxCompany.Text + "','" + textBoxContact.Text + ")";
myQuery(addQuery);
fungsi();
}

private void buttonDelete_Click(object sender, EventArgs e)


{
string deleteQuery = "delete from Customers where CustomerID =" +
int.Parse(textBoxCustomer.Text);
myQuery(deleteQuery);
fungsi();
}

private void buttonEdit_Click(object sender, EventArgs e)


{
string editQuery = "update Customers set CustomerID='"+textBoxCustomer+"'
where CompanyName="+int.Parse(textBoxCompany.Text);
myQuery(editQuery);
fungsi();
}
private void dataGridView1_MouseClick(object sender, MouseEventArgs e)
{
textBoxCustomer.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
textBoxCompany.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
textBoxContact.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString();

}
}
FormCr

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;

namespace Tugas5_2
{
public partial class FormCr : Form
{
public FormCr()
{
InitializeComponent();
}

private void buttonShow_Click(object sender, EventArgs e)


{
ReportDocument report = new ReportDocument(); report.Load("c:\\users\\user\\
documents\visual studio 2010\\Projects\\Tugas5_2\\Tugas5_2\\CrystalReport1.rpt");//path
lengkap dari CrystalReport1.rpt
crystalReportViewer1.ReportSource = report;
crystalReportViewer1.Refresh();
}

private void buttonClose_Click(object sender, EventArgs e)


{
FormData open = new FormData();
this.Hide();
open.Show();
}
}
}

You might also like