Advertisement
ioana_martin98

Untitled

Jun 12th, 2019
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.42 KB | None | 0 0
  1. namespace ShoppingSmeureanu
  2. {
  3.     public partial class Form1 : Form
  4.     {
  5.  
  6.         ItemCumparaturi[] vectCumparaturi;
  7.         public Form1()
  8.         {
  9.             vectCumparaturi = new ItemCumparaturi[]
  10.             {
  11.                 new ItemCumparaturi(1,1,2),
  12.                 new ItemCumparaturi(3,4,3),
  13.                 new ItemCumparaturi(4,3,100),
  14.                 new ItemCumparaturi(2,2,2)
  15.             };
  16.             InitializeComponent();
  17.         }
  18.  
  19.         public float CalculValoare(int codp)
  20.         {
  21.             float result = 0;
  22.             foreach(ItemCumparaturi i in vectCumparaturi)
  23.             {
  24.                 if(i.CodP == codp)
  25.                 {
  26.                     Marfa m = new Marfa(i.CodM);
  27.                     result += m.PretM * i.Cantitate;
  28.                 }
  29.             }
  30.             return result;
  31.         }
  32.  
  33.         public string getNumePersoana(int codp)
  34.         {
  35.             Persoana p = new Persoana(codp);
  36.             return p.NumeP;
  37.         }
  38.  
  39.         private void Form1_Load(object sender, EventArgs e)
  40.         {
  41.             // TODO: This line of code loads data into the 'dbDataSet.Persoana' table. You can move, or remove it, as needed.
  42.             this.persoanaTableAdapter.Fill(this.dbDataSet.Persoana);
  43.             // TODO: This line of code loads data into the 'dbDataSet.Marfa' table. You can move, or remove it, as needed.
  44.             this.marfaTableAdapter.Fill(this.dbDataSet.Marfa);
  45.         }
  46.  
  47.         private void button1_Click(object sender, EventArgs e)
  48.         {
  49.             PrintPreviewDialog dlg = new PrintPreviewDialog();
  50.             dlg.Document = printDocument1;
  51.             dlg.ShowDialog();
  52.         }
  53.  
  54.         private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
  55.         {
  56.             e.Graphics.DrawString("Raport:", new Font("Arial",30,FontStyle.Regular), Brushes.Black, new Point(10, 10));
  57.             int y = 25;
  58.             foreach(ItemCumparaturi i in vectCumparaturi)
  59.             {
  60.                 y = y + 20;
  61.                 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));
  62.             }
  63.         }
  64.  
  65.         private void button2_Click(object sender, EventArgs e)
  66.         {
  67.             DataSet s = dbDataSet.GetChanges();
  68.             if(s != null)
  69.             {
  70.                 marfaTableAdapter.Update((dbDataSet)s);
  71.                 persoanaTableAdapter.Update((dbDataSet)s);
  72.             }
  73.         }
  74.  
  75.         private void button3_Click(object sender, EventArgs e)
  76.         {
  77.             if (tbLitera.Text.Length != 0 && tbPrag.Text.Length != 0)
  78.             {
  79.                 textBox1.Clear();
  80.                 DataTable tP = dbDataSet.Tables["Persoana"];
  81.                 DataTable tM = dbDataSet.Tables["Marfa"];
  82.                 for (int i = 0; i < tP.Rows.Count; i++)
  83.                 {
  84.                     if (tP.Rows[i]["NumeP"].ToString().StartsWith(tbLitera.Text))
  85.                     {
  86.                         string nume = tP.Rows[i]["NumeP"] + Environment.NewLine;
  87.                         foreach (ItemCumparaturi ic in vectCumparaturi)
  88.                         {
  89.                             if (ic.CodP == Convert.ToInt32(tP.Rows[i]["id"]) && (float)Convert.ToDouble(tM.Rows[ic.CodM - 1]["PretM"]) > Convert.ToInt32(tbPrag.Text))
  90.                             {
  91.                                 textBox1.Text += nume + "\t" + tM.Rows[ic.CodM - 1]["DenumireM"] + " " + tM.Rows[ic.CodM - 1]["PretM"] + Environment.NewLine;
  92.                             }
  93.                         }
  94.                     }
  95.                 }
  96.             }
  97.             else
  98.             {
  99.                 MessageBox.Show("N-ai completat");
  100.                 tbPrag.Clear();
  101.                 tbLitera.Clear();
  102.             }
  103.         }
  104.  
  105.         private void copyToolStripMenuItem_Click(object sender, EventArgs e)
  106.         {
  107.             string clipText = "";
  108.             for(int i = 0; i < dataGridView1.SelectedRows.Count; i++)
  109.             {
  110.                 clipText += "Marfa " + dataGridView1.SelectedRows[i].Cells[0].Value + " are pretul " + dataGridView1.SelectedRows[i].Cells[1].Value + Environment.NewLine;
  111.             }
  112.             Clipboard.SetText(clipText);
  113.         }
  114.     }
  115. }
  116.  
  117. namespace ShoppingSmeureanu
  118. {
  119.     class ItemCumparaturi
  120.     {
  121.         public int CodP, CodM, Cantitate;
  122.  
  123.         public ItemCumparaturi(int codP, int codM, int cantitate)
  124.         {
  125.             CodP = codP;
  126.             CodM = codM;
  127.             Cantitate = cantitate;
  128.         }
  129.     }
  130. }
  131.  
  132. namespace ShoppingSmeureanu
  133. {
  134.     class Persoana
  135.     {
  136.         public int CodP;
  137.         public string NumeP;
  138.  
  139.         public Persoana(int codP)
  140.         {
  141.             try
  142.             {
  143.                 CodP = codP;
  144.                 string query = "select * from persoana where id = " + codP;
  145.                 OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=db.accdb");
  146.                 conn.Open();
  147.                 OleDbCommand com = new OleDbCommand(query,conn);
  148.                 OleDbDataReader r = com.ExecuteReader();
  149.                 r.Read();
  150.                 NumeP = r["NumeP"].ToString();
  151.                 conn.Close();
  152.             }
  153.             catch (Exception ex)
  154.             {
  155.                 Console.WriteLine(ex.Message);
  156.                 CodP = 0;
  157.                 NumeP = "necunoscut";
  158.             }
  159.         }
  160.     }
  161. }
  162.  
  163. namespace ShoppingSmeureanu
  164. {
  165.     class Marfa
  166.     {
  167.         public int CodM;
  168.         public string DenumireM;
  169.         public float PretM;
  170.  
  171.         public Marfa(int codM)
  172.         {
  173.             try
  174.             {
  175.                 CodM = codM;
  176.                 string query = "select * from marfa where id = " + codM;
  177.                 OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=db.accdb");
  178.                 conn.Open();
  179.                 OleDbCommand com = new OleDbCommand(query,conn);
  180.                 OleDbDataReader r = com.ExecuteReader();
  181.                 r.Read();
  182.                 DenumireM = r["DenumireM"].ToString();
  183.                 PretM = (float)Convert.ToDouble(r["PretM"]);
  184.                 conn.Close();
  185.             }
  186.             catch
  187.             {
  188.                 CodM = 0;
  189.                 DenumireM = "necunoscut";
  190.                 PretM = 0;
  191.             }
  192.         }
  193.     }
  194. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement