Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ShoppingSmeureanu
- {
- public partial class Form1 : Form
- {
- ItemCumparaturi[] vectCumparaturi;
- public Form1()
- {
- vectCumparaturi = new ItemCumparaturi[]
- {
- new ItemCumparaturi(1,1,2),
- new ItemCumparaturi(3,4,3),
- new ItemCumparaturi(4,3,100),
- new ItemCumparaturi(2,2,2)
- };
- InitializeComponent();
- }
- public float CalculValoare(int codp)
- {
- float result = 0;
- foreach(ItemCumparaturi i in vectCumparaturi)
- {
- if(i.CodP == codp)
- {
- Marfa m = new Marfa(i.CodM);
- result += m.PretM * i.Cantitate;
- }
- }
- return result;
- }
- public string getNumePersoana(int codp)
- {
- Persoana p = new Persoana(codp);
- return p.NumeP;
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- // TODO: This line of code loads data into the 'dbDataSet.Persoana' table. You can move, or remove it, as needed.
- this.persoanaTableAdapter.Fill(this.dbDataSet.Persoana);
- // TODO: This line of code loads data into the 'dbDataSet.Marfa' table. You can move, or remove it, as needed.
- this.marfaTableAdapter.Fill(this.dbDataSet.Marfa);
- }
- private void button1_Click(object sender, EventArgs e)
- {
- PrintPreviewDialog dlg = new PrintPreviewDialog();
- dlg.Document = printDocument1;
- dlg.ShowDialog();
- }
- private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
- {
- e.Graphics.DrawString("Raport:", new Font("Arial",30,FontStyle.Regular), Brushes.Black, new Point(10, 10));
- int y = 25;
- foreach(ItemCumparaturi i in vectCumparaturi)
- {
- y = y + 20;
- e.Graphics.DrawString(DateTime.Now.ToString() + " " + getNumePersoana(i.CodP) + " " + CalculValoare(i.CodP), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(10, y+10));
- }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- DataSet s = dbDataSet.GetChanges();
- if(s != null)
- {
- marfaTableAdapter.Update((dbDataSet)s);
- persoanaTableAdapter.Update((dbDataSet)s);
- }
- }
- private void button3_Click(object sender, EventArgs e)
- {
- if (tbLitera.Text.Length != 0 && tbPrag.Text.Length != 0)
- {
- textBox1.Clear();
- DataTable tP = dbDataSet.Tables["Persoana"];
- DataTable tM = dbDataSet.Tables["Marfa"];
- for (int i = 0; i < tP.Rows.Count; i++)
- {
- if (tP.Rows[i]["NumeP"].ToString().StartsWith(tbLitera.Text))
- {
- string nume = tP.Rows[i]["NumeP"] + Environment.NewLine;
- foreach (ItemCumparaturi ic in vectCumparaturi)
- {
- if (ic.CodP == Convert.ToInt32(tP.Rows[i]["id"]) && (float)Convert.ToDouble(tM.Rows[ic.CodM - 1]["PretM"]) > Convert.ToInt32(tbPrag.Text))
- {
- textBox1.Text += nume + "\t" + tM.Rows[ic.CodM - 1]["DenumireM"] + " " + tM.Rows[ic.CodM - 1]["PretM"] + Environment.NewLine;
- }
- }
- }
- }
- }
- else
- {
- MessageBox.Show("N-ai completat");
- tbPrag.Clear();
- tbLitera.Clear();
- }
- }
- private void copyToolStripMenuItem_Click(object sender, EventArgs e)
- {
- string clipText = "";
- for(int i = 0; i < dataGridView1.SelectedRows.Count; i++)
- {
- clipText += "Marfa " + dataGridView1.SelectedRows[i].Cells[0].Value + " are pretul " + dataGridView1.SelectedRows[i].Cells[1].Value + Environment.NewLine;
- }
- Clipboard.SetText(clipText);
- }
- }
- }
- namespace ShoppingSmeureanu
- {
- class ItemCumparaturi
- {
- public int CodP, CodM, Cantitate;
- public ItemCumparaturi(int codP, int codM, int cantitate)
- {
- CodP = codP;
- CodM = codM;
- Cantitate = cantitate;
- }
- }
- }
- namespace ShoppingSmeureanu
- {
- class Persoana
- {
- public int CodP;
- public string NumeP;
- public Persoana(int codP)
- {
- try
- {
- CodP = codP;
- string query = "select * from persoana where id = " + codP;
- OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=db.accdb");
- conn.Open();
- OleDbCommand com = new OleDbCommand(query,conn);
- OleDbDataReader r = com.ExecuteReader();
- r.Read();
- NumeP = r["NumeP"].ToString();
- conn.Close();
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- CodP = 0;
- NumeP = "necunoscut";
- }
- }
- }
- }
- namespace ShoppingSmeureanu
- {
- class Marfa
- {
- public int CodM;
- public string DenumireM;
- public float PretM;
- public Marfa(int codM)
- {
- try
- {
- CodM = codM;
- string query = "select * from marfa where id = " + codM;
- OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=db.accdb");
- conn.Open();
- OleDbCommand com = new OleDbCommand(query,conn);
- OleDbDataReader r = com.ExecuteReader();
- r.Read();
- DenumireM = r["DenumireM"].ToString();
- PretM = (float)Convert.ToDouble(r["PretM"]);
- conn.Close();
- }
- catch
- {
- CodM = 0;
- DenumireM = "necunoscut";
- PretM = 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement