proiect sgbd

38
Universitatea din Piteşti Facultatea de Matematică-Informatică PROIECT SISTEME DE GESTIUNE AL BAZELOR DE DATE – „ CASA DE AMANET ” Profesori coordonatori: Lector univ. : PĂUN VIOREL Asistent univ. : Ţurcanu Adrian Student : Ghita Victor Specializarea : Informatica - anul II

Upload: independent

Post on 03-Mar-2023

1 views

Category:

Documents


0 download

TRANSCRIPT

Universitatea din Piteşti Facultatea de Matematică-Informatică

PROIECT SISTEME DEGESTIUNE AL BAZELOR DE

DATE – „ CASA DE AMANET ”

Profesori coordonatori:

Lector univ. : PĂUN VIORELAsistent univ. : Ţurcanu Adrian

Student :Ghita Victor

Specializarea :Informatica - anul II

Universitatea din Piteşti Facultatea de Matematică-Informatică

An universitar 2013 - 2014

1.Proiectarea bazei de date - scurta descriere program

Pentru proiectarea si realizarea bazei de date „Casa De Amanet”am folosit Microsoft SQL Server 2008 R2 .

Microsoft SQL Server este un sistem de gestionare de bazede date  relaționale (RDBMS) produs de compania americana MicrosoftCorp. Limbajele primare de interogare sunt MS-SQL și T-SQL.

Microsoft SQL Sever foloseste o varianta de SQL numita T-SQL,sau Transact-SQL, o implementare de SQL-92 (standardul ISO pentruSQL) cu unele extensii. T-SQL in principal adauga sintaxa aditionalapentru procedurile stocate si pentru tranzactii. Standardele SQLnecesita ACID; acesta este un acronim pentru cele 4 conditii pentruorice tranzactie: atomicitate, consistenta, izolare, durabilitate. MSSQL Server suporta ODBC (Open Database Connectivity).

select @@SERVERNAME = VICTOR-PC\SQLEXPRESS

select @@VERSION = Microsoft SQL Server 2008 R2 (RTM) -10.50.1617.0 (Intel X86) Apr 22 2011 11:57:00 Copyright (c)

Universitatea din Piteşti Facultatea de Matematică-Informatică

Microsoft Corporation Express Edition with Advanced Services onWindows NT 6.1 <X86> (Build 7601: Service Pack 1)

select @@CPU_BUSY = 218

2.Scenariu

Se considera baza de date a unei case de amanet . Se cere implementarea unui soft pentru gestionarea produselor (aurului) care este amanetat .

Prezentarea bazei de date :

Universitatea din Piteşti Facultatea de Matematică-Informatică

Universitatea din Piteşti Facultatea de Matematică-Informatică

Universitatea din Piteşti Facultatea de Matematică-Informatică

3. Conectarea la baza de date

Conectarea la baza de date se realizeaza folosind clasa „ConnectDB” unde sunt implentate metodele pentru select , update , insert .

Clasa ConnectDB :

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

namespace Casa_de_Amanet

{

class ConnectDB {

public static string stringConectare ="Data Source=Victor-PC\\SQLEXPRESS; Initial Catalog=Casa Amanet;Integrated Security=SSPI"; public static SqlConnection con = new SqlConnection(ConnectDB.stringConectare); public static SqlConnection con2 = new SqlConnection(ConnectDB.stringConectare); public static DataSet ds = null; public static SqlDataAdapter daUs = null; public static SqlDataAdapter daAng = null;

public static List<Dictionary<String, Object>> select(String sql) { List<Dictionary<String, Object>> rez = null; try

Universitatea din Piteşti Facultatea de Matematică-Informatică

{ con.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandText = sql; try { SqlDataReader rdr = cmd.ExecuteReader(); if (rdr.HasRows) { rez = new List<Dictionary<String, Object>>(); while (rdr.Read()) { Dictionary<String, Object> rand = new Dictionary<String, Object>(); for (int i = 0; i < rdr.FieldCount; i++) rand.Add(rdr.GetName(i), rdr.GetValue(i)); rez.Add(rand); } } rdr.Close(); } catch { MessageBox.Show("Eroare la executarea query-ului."); } con.Close(); } catch { MessageBox.Show("A aparut o eroare la conectarea la baza de date!"); }

return rez; }

public static void update(String sql) { try { con.Open(); string query = sql; SqlCommand cmd = new SqlCommand(query, con); cmd.ExecuteNonQuery(); con.Close(); // MessageBox.Show("Update efectuat cu succes"); } catch (Exception) { con.Close(); MessageBox.Show("Update Erorr"); }

Universitatea din Piteşti Facultatea de Matematică-Informatică

}

public static void insert(String sql) { try { con.Open(); string query = sql; SqlCommand cmd = new SqlCommand(query, con); cmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("Inserarea in baza de date efectuata cu succes"); } catch (Exception) { con.Close(); // MessageBox.Show("eroare la insert"); } }

public static bool inBase(String sql) { int nr = 0; try { if (ConnectDB.con2.State.ToString() != "Open") ConnectDB.con2.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = ConnectDB.con2; cmd.CommandText = sql; cmd.ExecuteNonQuery(); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { nr++; } ConnectDB.con2.Close(); } catch (Exception e) { ConnectDB.con2.Close(); MessageBox.Show(e.ToString()); }

if (nr > 0) return true; else return false;

Universitatea din Piteşti Facultatea de Matematică-Informatică

} }}

Aplicatia se deschide cu o forma de login . Pentru a avea acces la datele din baza , trebuie sa introducem corect utilizatorul si parola aflate in baza .

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 Casa_de_Amanet{ public partial class Login : Form

Universitatea din Piteşti Facultatea de Matematică-Informatică

{ public Login() { InitializeComponent(); }

public static string str;

private void lblTitlu_Click(object sender, EventArgs e) {

}

private void Login_Load(object sender, EventArgs e) {

}

private void btnLogin_Click(object sender, EventArgs e) {

if (ConnectDB.inBase("select * from tUtilizatori WHERE nume='" + txtNume.Text + "'AND parola='" + txtParola.Text + "'")) { str = (string)txtNume.Text; Amanet gold = new Amanet(); gold.Show(); this.Hide();

} else {

MessageBox.Show("Utilizator sau Parola gresite ! "); return; } }

private void txtNume_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)13) { if (ConnectDB.inBase("select * from tUtilizatori WHERE nume='" + txtNume.Text + "' AND parola='" + txtParola.Text + "'")) { str = (string)txtNume.Text; Amanet gold = new Amanet(); gold.Show(); this.Hide();

}

Universitatea din Piteşti Facultatea de Matematică-Informatică

else {

MessageBox.Show("Utilizator sau Parola gresite ! "); return; }

} else if (e.KeyChar == (char)27) this.Hide();

}

private void txtParola_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)13) { if (ConnectDB.inBase("select * from tUtilizatori WHERE nume='" + txtNume.Text + "' AND parola='" + txtParola.Text + "'")) { str = (string)txtNume.Text; Amanet gold = new Amanet(); gold.Show(); this.Hide();

} else {

MessageBox.Show("Utilizator sau Parola gresite ! "); return; } } else if (e.KeyChar == (char)27) this.Hide();

} }}

Universitatea din Piteşti Facultatea de Matematică-Informatică

Dupa autentificarea utilizatorului avem acces la interfata . Aceasta un menu strip, date despre casier, ziua curenta, datele firmei, contine 5 butoane „Adauga Client”,”Adauga Contract”,”Vezi Contract”,”Stoc Amanet” si „Stoc Vanzare” si logo-ul firmei.

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

Universitatea din Piteşti Facultatea de Matematică-Informatică

namespace Casa_de_Amanet{ public partial class Amanet : Form { public Amanet() { InitializeComponent(); }

private void lblDate_Click(object sender, EventArgs e)

// Functie care se verifica daca produsele au trecut de perioada de gratie si se afla la vanzare

public void verifica() { ConnectDB.update("UPDATE tContracte SET la_vanzare=1 WHERE achitat=0 AND DATEDIFF(DAY, data_expirare,GETDATE())>=10;");

}

private void Amanet_Load(object sender, EventArgs e) { lblData.Text = DateTime.Now.ToString("D"); label3.Text = Login.str; this.verifica();

}

private void btnAddClient_Click(object sender, EventArgs e) { AddClient frmaddcl = new AddClient(); frmaddcl.Show(); this.Hide(); }

private void btnAddContract_Click(object sender, EventArgs e) { AddContract frmaddco = new AddContract(); frmaddco.Show(); this.Hide(); }

private void vtn_Click(object sender, EventArgs e) { VCT frmavct = new VCT(); frmavct.Show(); this.Hide();

Universitatea din Piteşti Facultatea de Matematică-Informatică

}

private void btnStocAm_Click(object sender, EventArgs e) { Stoc frmstoc = new Stoc(); frmstoc.Show(); this.Hide(); }

private void btnStocV_Click(object sender, EventArgs e) { StocV frmstocv = new StocV(); frmstocv.Show(); this.Hide(); }

private void btnVanzare_Click(object sender, EventArgs e) { Vanzare frmvan = new Vanzare(); frmvan.Show(); this.Hide(); }

private void aur14KToolStripMenuItem_Click(object sender, EventArgs e) { V14 frmv14 = new V14(); frmv14.Show(); this.Hide(); }

private void aur18KToolStripMenuItem_Click(object sender, EventArgs e) { V18 frmv18 = new V18(); frmv18.Show(); this.Hide(); }

private void aur24KToolStripMenuItem_Click(object sender, EventArgs e) { V24 frmv24 = new V24(); frmv24.Show(); this.Hide(); }

private void iesireToolStripMenuItem_Click(object sender, EventArgs e) { Login log = new Login(); log.Show(); this.Hide(); }

Universitatea din Piteşti Facultatea de Matematică-Informatică

private void detaliiAplicatieToolStripMenuItem_Click(object sender, EventArgs e) { Detalii frmdet = new Detalii(); frmdet.Show(); this.Hide(); }

private void clientiToolStripMenuItem_Click(object sender, EventArgs e) { Clienti frmcl = new Clienti(); frmcl.Show(); this.Hide(); }

private void exportaToolStripMenuItem_Click(object sender, EventArgs e) { Exporta frmex = new Exporta(); frmex.Show(); this.Hide(); }

private void modificareContractToolStripMenuItem_Click(object sender, EventArgs e) { Modificare frmmod = new Modificare(); frmmod.Show(); this.Hide(); }

}}

Adaugare Client

Universitatea din Piteşti Facultatea de Matematică-Informatică

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

namespace Casa_de_Amanet{ public partial class AddClient : Form { public AddClient() { InitializeComponent(); } private void btnBack_Click(object sender, EventArgs e) { Amanet frmam = new Amanet();

Universitatea din Piteşti Facultatea de Matematică-Informatică

frmam.Show(); this.Hide(); }

private void btnClear_Click(object sender, EventArgs e) { txtadresa.Text = string.Empty; txtci.Text = string.Empty; txtcnp.Text = string.Empty; txtnume.Text = string.Empty; txtprenume.Text = string.Empty; txttelefon.Text = string.Empty; }

private void btnAdd_Click(object sender, EventArgs e) { try { ConnectDB.insert("insert into tClienti values ((select isnull(max(id_client),0)+1 from tClienti),'" + txtcnp.Text + "','" + txtnume.Text + "','" + txtprenume.Text + "','" + txtci.Text + "','" + txtadresa.Text + "','" + txttelefon.Text + "');"); MessageBox.Show("Client Adaugat"); txtadresa.Text = string.Empty; txtci.Text = string.Empty; txtcnp.Text = string.Empty; txtnume.Text = string.Empty; txtprenume.Text = string.Empty; txttelefon.Text = string.Empty; } catch(Exception) { MessageBox.Show("Eroare !! Nici un client nu a fost adaugat ! ") ; }

} }}

Avem apoi butonul Adaugare contract :

Universitatea din Piteşti Facultatea de Matematică-Informatică

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

namespace Casa_de_Amanet{ public partial class Modificare : Form { public Modificare() { InitializeComponent(); }

private void Modificare_Load(object sender, EventArgs e) {

}

private void btnAdd_Click(object sender, EventArgs e)

Universitatea din Piteşti Facultatea de Matematică-Informatică

{ if (txtcomision.Text != "") ConnectDB.update("update tContracte set comision=" + txtcomision.Text + " where id_contract=" + txtidcontract.Text);

ConnectDB.update("update tContracte set val_finala =" + txtvf.Text + " where id_contract=" + txtidcontract.Text);

ConnectDB.update("update tContracte set data_contract='"+ data_c.Text+"' where id_contract="+ txtidcontract.Text ); ConnectDB.update("update tContracte set data_expirare='" + data_e.Text + "' where id_contract=" + txtidcontract.Text);

ConnectDB.update("update tContracte set achitat=" + txtAchitat.Text + " where id_contract=" + txtidcontract.Text);

clear(); }

public static double val_initiala;

private void btnCalc_Click(object sender, EventArgs e) { if (txtidcontract.Text == String.Empty && txtidcontract.Text == "") MessageBox.Show("Introduceti Id Contract");

else { ConnectDB.con.Open(); SqlCommand comanda = new SqlCommand(); comanda.Connection = ConnectDB.con; comanda.CommandText = "select val_initiala from tContracte where id_contract="+ txtidcontract.Text; SqlDataReader reader; reader = comanda.ExecuteReader();

while (reader.Read()) { val_initiala = Convert.ToDouble(reader[0]); } ConnectDB.con.Close();

var timp = Convert.ToString((data_e.Value - data_c.Value).TotalDays);

if (txtcomision.Text != "" && val_initiala != 0) {

MessageBox.Show(timp.ToString() + " zile");

Universitatea din Piteşti Facultatea de Matematică-Informatică

txtvf.Text = (Convert.ToDouble(timp) * Convert.ToDouble(txtcomision.Text) * 1 / 10 + val_initiala + 25).ToString();

}

else { MessageBox.Show("Completati campurile");

}

}

}

public void clear() { txtAchitat.Text = ""; txtcomision.Text = ""; txtidcontract.Text = ""; txtvf.Text = ""; }

private void txtvf_TextChanged(object sender, EventArgs e) {

}

private void data_c_ValueChanged(object sender, EventArgs e) { data_c.Value.ToString("yyyy-mm-dd"); }

private void data_e_ValueChanged(object sender, EventArgs e) { data_c.Value.ToString("yyyy-mm-dd"); }

private void iesireToolStripMenuItem_Click(object sender, EventArgs e) { Login log = new Login(); log.Show(); this.Hide(); }

private void detaliiAplicatieToolStripMenuItem_Click(object sender, EventArgs e) { Detalii frmdet = new Detalii(); frmdet.Show();

Universitatea din Piteşti Facultatea de Matematică-Informatică

this.Hide(); }

private void clientiToolStripMenuItem_Click(object sender, EventArgs e) { Clienti frmcl = new Clienti(); frmcl.ShowDialog(); }

private void exportaToolStripMenuItem_Click(object sender, EventArgs e) { Exporta frmex = new Exporta(); frmex.Show(); this.Hide(); }

private void aur14KToolStripMenuItem_Click(object sender, EventArgs e) { V14 frmv14 = new V14(); frmv14.Show(); this.Hide(); }

private void aur18KToolStripMenuItem_Click(object sender, EventArgs e) { V18 frmv18 = new V18(); frmv18.Show(); this.Hide(); }

private void aur24KToolStripMenuItem_Click(object sender, EventArgs e) { V24 frmv24 = new V24(); frmv24.Show(); this.Hide(); }

private void btnBack_Click(object sender, EventArgs e) { Amanet frmam = new Amanet(); frmam.Show(); this.Hide(); } }}

Urmatorul buton este VeziContract unde se poate accesa oricecontract bazat pe id-ul sau.

Universitatea din Piteşti Facultatea de Matematică-Informatică

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

namespace Casa_de_Amanet{ public partial class VCT : Form { public VCT() { InitializeComponent(); }

private void VCT_Load(object sender, EventArgs e) {

List<Dictionary<String, Object>> rez = ConnectDB.select("select * from tContracte"); if (rez != null) { rez.ForEach(delegate(Dictionary<String, Object> rand)

Universitatea din Piteşti Facultatea de Matematică-Informatică

{

ListViewItem it = new ListViewItem();

it.SubItems.Add(rand["id_contract"].ToString()); it.SubItems.Add(rand["id_client"].ToString()); it.SubItems.Add(rand["tip_obiect"].ToString()); it.SubItems.Add(rand["cantitate"].ToString()); it.SubItems.Add(rand["um"].ToString()); it.SubItems.Add(rand["data_contract"].ToString()); it.SubItems.Add(rand["data_expirare"].ToString()); it.SubItems.Add(rand["comision"].ToString()); it.SubItems.Add(rand["val_initiala"].ToString()); it.SubItems.Add(rand["val_finala"].ToString()); it.SubItems.Add(rand["achitat"].ToString());

lContracte.Items.Add(it); });

}

}

private void txtcauta_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)13) { int cifra = 0; try { cifra = Int32.Parse(txtcauta.Text); } catch { cifra = 0; }

lContracte.Items.Clear();

List<Dictionary<String, Object>> rez = ConnectDB.select("select * from tContracte WHERE id_contract=" + cifra); if (rez != null) {

rez.ForEach(delegate(Dictionary<String, Object> rand) {

ListViewItem it = new ListViewItem();

Universitatea din Piteşti Facultatea de Matematică-Informatică

it.SubItems.Add(rand["id_contract"].ToString()); it.SubItems.Add(rand["id_client"].ToString()); it.SubItems.Add(rand["tip_obiect"].ToString()); it.SubItems.Add(rand["cantitate"].ToString()); it.SubItems.Add(rand["um"].ToString()); it.SubItems.Add(rand["data_contract"].ToString()); it.SubItems.Add(rand["data_expirare"].ToString()); it.SubItems.Add(rand["comision"].ToString()); it.SubItems.Add(rand["val_initiala"].ToString()); it.SubItems.Add(rand["val_finala"].ToString()); it.SubItems.Add(rand["achitat"].ToString());

lContracte.Items.Add(it); });

} }

}

private void lContracte_SelectedIndexChanged(object sender, EventArgs e) {

}

private void txtcauta_TextChanged(object sender, EventArgs e) {

}

private void lblCauta_Click(object sender, EventArgs e) {

}

private void btnBack_Click(object sender, EventArgs e) { Amanet frmam = new Amanet(); frmam.Show(); this.Hide(); } }}

Universitatea din Piteşti Facultatea de Matematică-Informatică

Stoc Amanet , ne arata Data Grid View-ul datelor stocate:

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

namespace Casa_de_Amanet{ public partial class Stoc : Form { public Stoc() { InitializeComponent(); }

private void Stoc_Load(object sender, EventArgs e) { ConnectDB.ds = new DataSet();

string strSql = "select * from tContracte where achitat=0 ";

Universitatea din Piteşti Facultatea de Matematică-Informatică

ConnectDB.daUs = new SqlDataAdapter(strSql, ConnectDB.con); ConnectDB.daUs.Fill(ConnectDB.ds, "tContracte");

dgvs.DataSource = ConnectDB.ds; dgvs.DataMember = "tContracte"; }

private void btnBack_Click(object sender, EventArgs e) { Amanet frmam = new Amanet(); frmam.Show(); this.Hide(); } }}

Stoc Vanzare e ultimul buton al interfetei , prezentand un Data Grid View a produselor iesite din perioada de gratie si puse la vanzare.

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

namespace Casa_de_Amanet

Universitatea din Piteşti Facultatea de Matematică-Informatică

{ public partial class StocV : Form { public StocV() { InitializeComponent(); }

private void StocV_Load(object sender, EventArgs e) { ConnectDB.ds = new DataSet();

string strSql = "select * from vContracte "; ConnectDB.daUs = new SqlDataAdapter(strSql, ConnectDB.con); ConnectDB.daUs.Fill(ConnectDB.ds, "vContracte");

dgvV.DataSource = ConnectDB.ds; dgvV.DataMember = "vContracte"; }

private void btnAct_Click(object sender, EventArgs e) { SqlCommandBuilder cb = new SqlCommandBuilder(ConnectDB.daUs); DataSet dsChange = ConnectDB.ds.GetChanges(); if (dsChange != null) {

ConnectDB.daUs.Update(dsChange, "tContracte");

ConnectDB.ds.AcceptChanges(); } }

private void button2_Click(object sender, EventArgs e) { Amanet frmam = new Amanet(); frmam.Show(); this.Hide(); } }}

MenuStip contine un tab pentru Vizualizarea diferitelor produse de aursi al clientilor , un tab pentru modificarea datelor din contrat , un tab pentru a exporta contractul in format .txt pentru printarea acestuia catre client , un tab pentru afisarea detaliilor aplicatiei si ultimul tab face log out-ul userului curent.

Universitatea din Piteşti Facultatea de Matematică-Informatică

using System;using System.Collections.Generic;using System.ComponentModel;

Universitatea din Piteşti Facultatea de Matematică-Informatică

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

namespace Casa_de_Amanet{ public partial class V14 : Form { public V14() { InitializeComponent(); }

private void button2_Click(object sender, EventArgs e) { Amanet frmam = new Amanet(); frmam.Show(); this.Hide(); }

private void V14_Load(object sender, EventArgs e) { ConnectDB.ds = new DataSet();

string strSql = "select * from tContracte where tip_obiect like '%14k%' "; ConnectDB.daUs = new SqlDataAdapter(strSql, ConnectDB.con); ConnectDB.daUs.Fill(ConnectDB.ds, "tContracte");

dgv14.DataSource = ConnectDB.ds; dgv14.DataMember = "tContracte"; }

private void btnAct_Click(object sender, EventArgs e) { SqlCommandBuilder cb = new SqlCommandBuilder(ConnectDB.daUs); DataSet dsChange = ConnectDB.ds.GetChanges(); if (dsChange != null) {

ConnectDB.daUs.Update(dsChange, "tContracte");

ConnectDB.ds.AcceptChanges(); } } }}

Universitatea din Piteşti Facultatea de Matematică-Informatică

Toate celalte vizualizari din tabul „Vizualizare sunt” pe acelasi principiu .

Optiunea „Modificare” ne ofera posibilatea de a modifica detaliile unui contrat existent sau achitarea acestuia .

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

namespace Casa_de_Amanet{ public partial class Modificare : Form

Universitatea din Piteşti Facultatea de Matematică-Informatică

{ public Modificare() { InitializeComponent(); }

private void Modificare_Load(object sender, EventArgs e) {

}

private void btnAdd_Click(object sender, EventArgs e) { if (txtcomision.Text != "") ConnectDB.update("update tContracte set comision=" + txtcomision.Text + " where id_contract=" + txtidcontract.Text);

ConnectDB.update("update tContracte set val_finala =" + txtvf.Text + " where id_contract=" + txtidcontract.Text);

ConnectDB.update("update tContracte set data_contract='"+ data_c.Text+"' where id_contract="+ txtidcontract.Text ); ConnectDB.update("update tContracte set data_expirare='" + data_e.Text + "' where id_contract=" + txtidcontract.Text);

ConnectDB.update("update tContracte set achitat=" + txtAchitat.Text + " where id_contract=" + txtidcontract.Text);

clear(); }

public static double val_initiala;

private void btnCalc_Click(object sender, EventArgs e) { if (txtidcontract.Text == String.Empty && txtidcontract.Text == "") MessageBox.Show("Introduceti Id Contract");

else { ConnectDB.con.Open(); SqlCommand comanda = new SqlCommand(); comanda.Connection = ConnectDB.con; comanda.CommandText = "select val_initiala from tContracte where id_contract="+ txtidcontract.Text; SqlDataReader reader; reader = comanda.ExecuteReader();

while (reader.Read())

Universitatea din Piteşti Facultatea de Matematică-Informatică

{ val_initiala = Convert.ToDouble(reader[0]); } ConnectDB.con.Close();

var timp = Convert.ToString((data_e.Value - data_c.Value).TotalDays);

if (txtcomision.Text != "" && val_initiala != 0) {

MessageBox.Show(timp.ToString() + " zile"); txtvf.Text = (Convert.ToDouble(timp) * Convert.ToDouble(txtcomision.Text) * 1 / 10 + val_initiala + 25).ToString();

// ConnectDB.con.Open(); }

else { MessageBox.Show("Completati campurile");

}

}

}

public void clear() { txtAchitat.Text = ""; txtcomision.Text = ""; txtidcontract.Text = ""; txtvf.Text = ""; }

private void txtvf_TextChanged(object sender, EventArgs e) {

}

private void data_c_ValueChanged(object sender, EventArgs e) { data_c.Value.ToString("yyyy-mm-dd"); }

private void data_e_ValueChanged(object sender, EventArgs e)

Universitatea din Piteşti Facultatea de Matematică-Informatică

{ data_c.Value.ToString("yyyy-mm-dd"); }

private void iesireToolStripMenuItem_Click(object sender, EventArgs e) { Login log = new Login(); log.Show(); this.Hide(); }

private void detaliiAplicatieToolStripMenuItem_Click(object sender, EventArgs e) { Detalii frmdet = new Detalii(); frmdet.Show(); this.Hide(); }

private void clientiToolStripMenuItem_Click(object sender, EventArgs e) { Clienti frmcl = new Clienti(); frmcl.ShowDialog(); }

private void exportaToolStripMenuItem_Click(object sender, EventArgs e) { Exporta frmex = new Exporta(); frmex.Show(); this.Hide(); }

private void aur14KToolStripMenuItem_Click(object sender, EventArgs e) { V14 frmv14 = new V14(); frmv14.Show(); this.Hide(); }

private void aur18KToolStripMenuItem_Click(object sender, EventArgs e) { V18 frmv18 = new V18(); frmv18.Show(); this.Hide(); }

private void aur24KToolStripMenuItem_Click(object sender, EventArgs e) { V24 frmv24 = new V24(); frmv24.Show(); this.Hide();

Universitatea din Piteşti Facultatea de Matematică-Informatică

}

private void btnBack_Click(object sender, EventArgs e) { Amanet frmam = new Amanet(); frmam.Show(); this.Hide(); } }}

In functie de id-ul contracului putem sa salvam contractual in format .txt pentru printarea acestuia si inmanarea catre client. Putem selecta unde dorim sa salvam fisierul .

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

namespace Casa_de_Amanet{ public partial class Exporta : Form { public Exporta()

Universitatea din Piteşti Facultatea de Matematică-Informatică

{ InitializeComponent(); }

private void btnexporta_Click(object sender, EventArgs e) { FolderBrowserDialog fb = new FolderBrowserDialog(); fb.ShowDialog();

List<Dictionary<String, Object>> rez = ConnectDB.select("select * from tContracte where id_contract =" + txtId.Text); if (rez != null) { Dictionary<String, Object> produs = rez.ElementAt(0);

String nume_client = ConnectDB.select("SELECT nume+' '+prenume as nume_full FROM tClienti WHERE id_client=" + produs["id_client"].ToString()).ElementAt(0)["nume_full"].ToString();

String text = " Subsemnatul/Subsemnata " + nume_client + " am amanetat un/o " + produs["tip_obiect"].ToString() + " in data de " + produs["data_contract"] + " pana la data de " +produs["data_expirare"]+ " cu un comision in valoare de 0." +produs["comision"] +". \r\n Suma predata clientului este in valoare de "+ produs["val_initiala"]+" lei . Suma rambursata Casei de Amanet urmand sa fie "+produs["val_finala"]+ " lei , pana la data de mai sus . "+ " ";

using (StreamWriter sw = new StreamWriter(fb.SelectedPath + "\\" + nume_client + ".txt")) {

sw.Write(text); } MessageBox.Show(text);

}

}

private void button2_Click(object sender, EventArgs e) { Amanet frmam = new Amanet(); frmam.Show(); this.Hide(); }

private void aur18KToolStripMenuItem_Click(object sender, EventArgs e)

Universitatea din Piteşti Facultatea de Matematică-Informatică

{ V18 frmv18 = new V18(); frmv18.Show(); this.Hide(); }

private void aur24KToolStripMenuItem_Click(object sender, EventArgs e) { V24 frmv24 = new V24(); frmv24.Show(); this.Hide(); }

private void clientiToolStripMenuItem_Click(object sender, EventArgs e) { Clienti frmcl = new Clienti(); frmcl.ShowDialog(); }

private void contracteToolStripMenuItem_Click(object sender, EventArgs e) { VCT frmvct = new VCT(); frmvct.ShowDialog(); }

private void detaliiAplicatieToolStripMenuItem_Click(object sender, EventArgs e) { Detalii frmdet = new Detalii(); frmdet.Show(); this.Hide(); } }}

„Detalii Aplicatie ”

Universitatea din Piteşti Facultatea de Matematică-Informatică

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 Casa_de_Amanet{ public partial class Detalii : Form { public Detalii() { InitializeComponent(); }

private void rb1_MouseClick(object sender, MouseEventArgs e) { Amanet am = new Amanet(); am.Show(); this.Hide(); }

private void Detalii_Load(object sender, EventArgs e) {

}

}

Universitatea din Piteşti Facultatea de Matematică-Informatică

}

„Log Out” – deconcteaza userul curent pentru posibilitatea autentificarii unui alt utilizator .