Aland Sabr Maruf

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

create database Retail;

use Retail;
create table Login(
id int identity primary key,
username varchar(50),
passwordd varchar(50),
adminrole varchar(50)

);
select * from Login;

create table Products(


id int identity primary key,
Barcode varchar(50),
ProductName varchar(50),
purchaseprice varchar(50),
sellprice varchar(50),
qty int,
ExpDate date

);
create table SoldProducts(
productid int identity primary key,
Barcode varchar(50),
sellprice varchar(50),
qty int,
ExpDate date

);

//Form Froshtn Code


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;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{

public Form1()// form 1 Formy Froshtn form 2 formy login


{
InitializeComponent();
}
public string ShowNameUser { get; set; }

// henany nawi user


private void Form1_Load(object sender, EventArgs e)
{
lbluser.Text = ShowNameUser;
}

private void ShowData(){


try{
SqlConnection con = new SqlConnection("Data Source=DESKTOP-
H4DN4EG\SQLEXPRESS;Initial Catalog=Retail;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("select * from Products ",con);
SqlDataAdapter adr= new SqlDataAdapter(cmd);
DataSet ds=new DataSet();
adr.Fill(ds,"Products");
dataGridView1.DataSource=ds.Tables["Products"];
con.Close();

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

}
}

private void btnsearch_Click(object sender, EventArgs e)


{
try{
SqlConnection con = new SqlConnection("Data Source=DESKTOP-
H4DN4EG\SQLEXPRESS;Initial Catalog=Retail;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("select * from Products where Barcode
LIKE '%' + @Barcode + '%' ",con);
cmd.Parameters.AddWithValue("@Barcode",txtsearch.Text);
SqlDataAdapter adr= new SqlDataAdapter(cmd);
DataSet ds=new DataSet();
adr.Fill(ds,"Products");
dataGridView1.DataSource=ds.Tables["Products"];
con.Close();

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

}
}

private void btninsertitem_Click(object sender, EventArgs e)


{
try{
SqlConnection con = new SqlConnection("Data Source=DESKTOP-
H4DN4EG\SQLEXPRESS;Initial Catalog=Retail;Integrated Security=True");
con.Open();
SqlCommand cmd= new SqlCommand("insert into
Products(Barcode,ProductName,purchaseprice,sellprice,qty,ExpDate)values(@Barcode,@Product
Name,@purchaseprice,@sellprice,@qty,@ExpDate)",con);
cmd.Parameters.AddWithValue("@Barcode",txtbarcode.Text);
cmd.Parameters.AddWithValue("@ProductName",txtproname.Text);
cmd.Parameters.AddWithValue("@purchaseprice",txtpurchaseprise.Text);
cmd.Parameters.AddWithValue("@sellprice",txtsell.Text);
cmd.Parameters.AddWithValue("@qty",txtqty.Text);

cmd.Parameters.AddWithValue("@ExpDate",datetimeexp.value.ToString("yyyy/MM/dd");
cmd.ExecuteNonQuery();
con.Close();
ShowData();
}
catch(Exception ex){
MessageBox.Show(ex.Message);

// koy Gshtyaka
private void dataGridView1_RowsAdded(object sender,
DataGridViewRowsAddedEventArgs e)
{
int Summ=0;
for(int i=0; i<dataGridView1.Rows.Count; i++){

Summ=Summ+Convert.ToInt16(dataGridView1.Rows[i].Cells[1].Value);

}
txtsumall.Text=Summ.ToString();

}
}
//Form Login Code
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;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
//form 2 login
public Form2()
{
InitializeComponent();
}

private void btninsert_Click(object sender, EventArgs e)


{
string name;
string pass;
string adtype;
try
{
SqlConnection con = new SqlConnection("Data Source=DESKTOP-
H4DN4EG\SQLEXPRESS;Initial Catalog=Retail;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("select * from Login where username=@User
and passwordd=@Pass",con);
cmd.Parameters.AddWithValue("@User",txtuser);
cmd.Parameters.AddWithValue("@Pass",txtpass);
SqlDataReader rdr=cmd.ExecuteReader();
if(rdr.HasRows){

rdr.Read();
name=rdr.["username"].ToString();
pass=rdr.["passwordd"].ToString();
if(adtype=="Admin"){
Form1 froshtn = new Form1();
froshtn.Show();

}
else{
MessageBox.Show("error login please Only Users register Admin
Role");

}
con.Close();

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

}
}
}
}

You might also like