示例#1
0
        public ActualizeazaAngajat(int id_angajat)
        {
            InitializeComponent();

            using (var context = new HramulEntities())
            {
                Angajati angajat = (from a in context.Angajatis
                                    where a.ID_ANGAJAT == id_angajat
                                    select a).First();

                tbNume.Text    = angajat.Nume;
                tbPrenume.Text = angajat.Prenume;
                tbFunctie.Text = angajat.Functie;
                tbAdresa.Text  = angajat.Adresa;
                cbRating.Text  = angajat.Rating.ToString();

                cbDepartament.Text = (from d in context.Departamentes
                                      where d.ID_DEPARTAMENT == angajat.ID_DEPARTAMENT
                                      select d.Denumire).First();

                tbSalariu.Text = (from s in context.State_de_platas
                                  where s.TIP_PLATA.Equals("SALARIU")
                                  where s.ID_ANGAJAT == 12
                                  select s.Suma).First().ToString();

                btSalveaza.Name   = "Actualizeaza";
                btSalveaza.Text   = "Actualizeaza";
                btSalveaza.Click -= btSalveaza_Click;
                btSalveaza.Click += (sender, e) => btActualizeaza_Click(id_angajat);

                FormBorderStyle = FormBorderStyle.FixedToolWindow;
            }
        }
示例#2
0
        private void menutItemPrima_Click(int id_angajat)
        {
            Form form = new PrimaInputForm(id_angajat);

            form.ShowDialog();

            MessageBox.Show("Prima a fost adaugata");

            using (var context = new HramulEntities())
            {
                var results = from s in context.State_de_platas
                              where s.ID_ANGAJAT == id_angajat
                              select new
                {
                    s.ID_PLATA,
                    s.Suma,
                    s.TIP_PLATA,
                    s.Data
                };

                dataGridViewState.DataSource = results.ToList();
            }

            InitializeMyComponenets();
        }
示例#3
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            var client_name = comboBoxClient.Text;
            int client_ID   = -1;

            foreach (var item in clientiQuery)
            {
                if (item.Nume == client_name)
                {
                    client_ID = item.ID_CLIENT;
                }
            }
            var date = dateTimePicker3.Value.Date.ToString();

            //TODO va lua ID ANGAJAT din username
            using (var context = new HramulEntities())
            {
                ObjectParameter empID   = new ObjectParameter("EmpID", typeof(int));
                ObjectParameter cliID   = new ObjectParameter("CliID", typeof(int));
                ObjectParameter ordID   = new ObjectParameter("Order_ID", typeof(int));
                ObjectParameter dateest = new ObjectParameter("DateEST", typeof(DateTime));
                context.MakeOrder(1, DateTime.Parse(date), client_ID, ordID);
                orderID = (int)ordID.Value;
                statuslabel_Comanda_ID.Text = "Comanda ID: " + orderID.ToString();
            }
            GridViewComenzi.DataSource = (from c in context.ComenziExtendeds select c).ToList();
        }
示例#4
0
        private void tbSearch_TextChanged(object sender, EventArgs e)
        {
            string name = tbSearch.Text;

            using (var context = new HramulEntities())
            {
                var results = (from a in context.Angajatis
                               join d in context.Departamentes
                               on a.ID_DEPARTAMENT equals d.ID_DEPARTAMENT
                               join s in context.State_de_platas
                               on a.ID_ANGAJAT equals s.ID_ANGAJAT
                               where s.TIP_PLATA.Equals("SALARIU")
                               where s.Data.Value.Year == DateTime.Today.Year
                               where s.Data.Value.Month == DateTime.Today.Month
                               where a.Nume.StartsWith(name)
                               orderby a.Nume
                               select new
                {
                    a.ID_ANGAJAT,
                    a.Nume,
                    a.Prenume,
                    a.Adresa,
                    a.Rating,
                    a.Functie,
                    a.Activ,
                    d.Denumire,
                    s.Suma
                }).ToList();

                dataGridView.DataSource = results;
            }
        }
示例#5
0
        private void InitializeMyComponenets()
        {
            using (var context = new HramulEntities())
            {
                var results = from a in context.Angajatis
                              join d in context.Departamentes
                              on a.ID_DEPARTAMENT equals d.ID_DEPARTAMENT
                              join aa in context.SalariiCurentes
                              on a.ID_ANGAJAT equals aa.ID_ANGAJAT
                              orderby a.Nume
                              select new
                {
                    a.ID_ANGAJAT,
                    a.Nume,
                    a.Prenume,
                    a.Adresa,
                    a.Rating,
                    a.Functie,
                    a.Activ,
                    d.Denumire,
                    aa.Salariu
                };
                dataGridView.DataSource = results.ToList();

                tssNumarAngajati.Text = "Total Angajati: " +
                                        (from a in context.Salariis
                                         select a).Count();

                tssTotalSalarii.Text = "Total salarii: " +
                                       (from a in context.Salariis
                                        select a.Salariu).Sum();
            }
        }
示例#6
0
        private void menuItemActualizeaza_Click(int id_angajat)
        {
            using (var context = new HramulEntities())
            {
                Form form = new ActualizeazaAngajat(id_angajat);
                form.ShowDialog();

                InitializeMyComponenets();
            }
        }
示例#7
0
        private void InitializeMyComponents()
        {
            string[] rating = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };
            cbRating.DataSource = rating;

            using (var context = new HramulEntities())
            {
                var results = (from d in context.Departamentes
                               select d.Denumire).ToList();

                cbDepartament.DataSource = results;
            }
        }
示例#8
0
        private void btDataBase_Click(object sender, EventArgs e)
        {
            using (var context = new HramulEntities())
            {
                var angajati = (from a in context.Salariis
                                select a).ToList();

                DataGridView grid = new DataGridView();
                grid.DataSource = angajati;

                Controls.Add(grid);
                Controls.Remove(grid);

                PdfPTable pdfTable = new PdfPTable(grid.ColumnCount);
                pdfTable.DefaultCell.Padding = 3;
                pdfTable.WidthPercentage = 60;
                pdfTable.HorizontalAlignment = iTextSharp.text.Element.ALIGN_LEFT;
                pdfTable.DefaultCell.BorderWidth = 1;

                foreach (DataGridViewColumn column in grid.Columns)
                {
                    PdfPCell cell = new PdfPCell(new iTextSharp.text.Phrase(column.HeaderText));
                    cell.BackgroundColor = new iTextSharp.text.Color(240, 240, 240);
                    pdfTable.AddCell(cell);
                }

                foreach (DataGridViewRow row in grid.Rows)
                {
                    foreach (DataGridViewCell cell in row.Cells)
                    {
                        pdfTable.AddCell(cell.Value.ToString());
                    }
                }

                string file = "DataBaseExport.pdf";
                using (FileStream stream = new FileStream(file, FileMode.Create))
                {
                    iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A2, 10f, 10f, 10f, 0f);
                    PdfWriter.GetInstance(pdfDoc, stream);
                    pdfDoc.Open();
                    pdfDoc.Add(pdfTable);
                    pdfDoc.Close();
                    stream.Close();
                }
            }

            MessageBox.Show("Baza de date a fost exportata");
        }
示例#9
0
        private void btLogin_Click(object sender, EventArgs e)
        {
            string userName = tbUserName.Text;
            string parola = tbPassword.Text;

            using (var context = new HramulEntities())
            {
                try
                {
                    User user = (from u in context.Users
                                 where u.Username.Equals(userName)
                                 select u).First();

                    byte[] hash = MD5.Create().ComputeHash(ASCIIEncoding.ASCII.GetBytes(parola));
                    byte[] userHash = user.Password;

                    for(int i = 0; i < hash.Count(); i++)
                    {
                        if (hash[i] != userHash[i])
                            throw new Exception();
                    }

                    tbUserName.Hide();
                    tbPassword.Hide();
                    btLogin.Hide();

                    lbLogin.Visible = true;
                    lbLogin.Text += userName;

                    LOGGED_IN = true;

                    DEPARTAMENT = (from d in context.Departamentes
                                   join a in context.Angajatis
                                   on d.ID_DEPARTAMENT equals a.ID_DEPARTAMENT
                                   join u in context.Users
                                   on a.ID_ANGAJAT equals u.ID_ANGAJAT
                                   where u.ID_ANGAJAT == user.ID_ANGAJAT
                                   select d.Denumire
                                   ).First();

                }
                catch(Exception exception)
                {
                    MessageBox.Show("Username-ul/parolele nu se potrivesc", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
示例#10
0
        public MainForm()
        {
            InitializeComponent();

            using (var context = new HramulEntities())
            {
                ObjectParameter cheltuieli = new ObjectParameter("Cheltuieli", typeof(decimal));
                ObjectParameter castiguri = new ObjectParameter("Castiguri", typeof(decimal));

                context.CalculateProfit(cheltuieli,castiguri);

                tssCheltuieli.Text += cheltuieli.Value;
                tssCastiguri.Text += castiguri.Value;

                lbDate.Text = DateTime.Today.ToString();
                
            }
        }
示例#11
0
        private void btOK_Click(int id_angajat)
        {
            decimal suma = decimal.Parse(tbPrima.Text);

            using (var context = new HramulEntities())
            {
                State_de_plata stat = new State_de_plata
                {
                    ID_ANGAJAT = id_angajat,
                    Suma       = suma,
                    Data       = DateTime.Today,
                    TIP_PLATA  = "PRIMA"
                };

                context.State_de_platas.Add(stat);
                context.SaveChanges();
            }

            Hide();
        }
示例#12
0
        private void dataGridView_MouseDown(object sender, MouseEventArgs e)
        {
            try
            {
                int row        = dataGridView.HitTest(e.X, e.Y).RowIndex;
                var id_angajat = int.Parse(dataGridView.Rows[row].Cells[0].FormattedValue.ToString());

                if (e.Button == MouseButtons.Left)
                {
                    using (var context = new HramulEntities())
                    {
                        var results = from s in context.State_de_platas
                                      where s.ID_ANGAJAT == id_angajat
                                      select new
                        {
                            s.ID_PLATA,
                            s.Suma,
                            s.TIP_PLATA,
                            s.Data
                        };

                        dataGridViewState.DataSource = results.ToList();
                    }
                }

                if (e.Button == MouseButtons.Right)
                {
                    ContextMenu menu = new ContextMenu();
                    menu.MenuItems.Add(new MenuItem("Seteaza activ/inactiv", (s, ev) => menuItemSterge_Click(id_angajat)));
                    menu.MenuItems.Add(new MenuItem("Actualizeaza", (s, ev) => menuItemActualizeaza_Click(id_angajat)));
                    menu.MenuItems.Add(new MenuItem("Adauga prima", (s, ev) => menutItemPrima_Click(id_angajat)));
                    menu.MenuItems.Add(new MenuItem("Creaza cont", (s, ev) => menuItemCont_Click(id_angajat)));

                    menu.Show(dataGridView, new Point(e.X, e.Y));
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show("Esti in afara numarului de randuri din grid", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btInregistreaza_Click(int id_angajat)
        {
            string username = tbUtilizator.Text;
            string parola   = tbParola.Text;

            byte[] hash = MD5.Create().ComputeHash(ASCIIEncoding.ASCII.GetBytes(parola));

            User user = new User
            {
                Username   = username,
                Password   = hash,
                ID_ANGAJAT = id_angajat
            };

            using (var context = new HramulEntities())
            {
                context.Users.Add(user);

                context.SaveChanges();

                Hide();
            }
        }
示例#14
0
        private void button1_Click(object sender, EventArgs e)
        {
            string name = tbSearch.Text;

            using (var context = new HramulEntities())
            {
                var results = (from a in context.Angajatis.DefaultIfEmpty()
                               join d in context.Departamentes
                               on a.ID_DEPARTAMENT equals d.ID_DEPARTAMENT
                               join s in context.State_de_platas
                               on a.ID_ANGAJAT equals s.ID_ANGAJAT
                               where s.TIP_PLATA.Equals("SALARIU")
                               where s.Data.Value.Year == DateTime.Today.Year
                               where s.Data.Value.Month == DateTime.Today.Month
                               where a.Nume.StartsWith(name)
                               orderby a.Nume
                               select new
                {
                    a.ID_ANGAJAT,
                    a.Nume,
                    a.Prenume,
                    a.Adresa,
                    a.Rating,
                    a.Functie,
                    a.Activ,
                    d.Denumire,
                    s.Suma
                }).ToList();

                if (results.Count == 0)
                {
                    MessageBox.Show("Niciun angajat nu a fost gasit! Va rugam sa reintroduceti datele!");
                }

                dataGridView.DataSource = results;
            }
        }
示例#15
0
        private void menuItemSterge_Click(int id_angajat)
        {
            using (var context = new HramulEntities())
            {
                var angajat = (from a in context.Angajatis
                               where a.ID_ANGAJAT == id_angajat
                               select a).First();

                if (angajat.Activ == true)
                {
                    angajat.Activ = false;
                    MessageBox.Show("Angajatul a fost trecut inactiv");
                }
                else if (angajat.Activ == false)
                {
                    angajat.Activ = true;
                    MessageBox.Show("Angajatul a fost trecut activ");
                }

                context.SaveChanges();

                InitializeMyComponenets();
            }
        }
示例#16
0
        private void button2_Click(object sender, EventArgs e)
        {
            string file = "raport.xls";
            Workbook workbook = new Workbook();
            Worksheet worksheet = new Worksheet("Salarii");

            //Salarii
            worksheet.Cells[0, 0] = new Cell("Id");
            worksheet.Cells[0, 1] = new Cell("Nume");
            worksheet.Cells[0, 2] = new Cell("Preume");
            worksheet.Cells[0, 3] = new Cell("Functie");
            worksheet.Cells[0, 4] = new Cell("Rating");
            worksheet.Cells[0, 5] = new Cell("Salariu");

            using (var context = new HramulEntities())
            {
                var angajati = (from a in context.Salariis
                                select a).ToList();

                int row = 1;

                foreach(var angajat in angajati)
                {
                    worksheet.Cells[row, 0] = new Cell(angajat.ID_ANGAJAT);
                    worksheet.Cells[row, 1] = new Cell(angajat.Nume);
                    worksheet.Cells[row, 2] = new Cell(angajat.Prenume);
                    worksheet.Cells[row, 3] = new Cell(angajat.Functie);
                    worksheet.Cells[row, 4] = new Cell(angajat.Rating);
                    worksheet.Cells[row, 5] = new Cell(angajat.Salariu);

                    row++;
                }
            }

            workbook.Worksheets.Add(worksheet);

            //Facturi emise
            worksheet = new Worksheet("Facturi emise");

            worksheet.Cells[0, 0] = new Cell("Nr");
            worksheet.Cells[0, 1] = new Cell("Bani");
            worksheet.Cells[0, 2] = new Cell("Observatii");
            worksheet.Cells[0, 3] = new Cell("Data");

            using (var context = new HramulEntities())
            {
                int row = 1;

                var facturi = (from f in context.FacturiEmises
                               select f).ToList();

                foreach(var factura in facturi)
                {
                    worksheet.Cells[row, 0] = new Cell(factura.Nr);
                    worksheet.Cells[row, 1] = new Cell(factura.Bani);
                    worksheet.Cells[row, 2] = new Cell(factura.Observatii);
                    worksheet.Cells[row, 3] = new Cell(factura.Data);
                }

                row++;
            }

            workbook.Worksheets.Add(worksheet);

            worksheet = new Worksheet("Facturi primite");

            worksheet.Cells[0, 0] = new ExcelLibrary.SpreadSheet.Cell("Nr");
            worksheet.Cells[0, 1] = new Cell("Bani");
            worksheet.Cells[0, 2] = new Cell("Observatii");
            worksheet.Cells[0, 3] = new Cell("Data");

            using (var context = new HramulEntities())
            {
                int row = 1;

                var facturi = (from f in context.FacturiPrimites
                               select f).ToList();

                foreach (var factura in facturi)
                {
                    worksheet.Cells[row, 0] = new Cell(factura.Nr);
                    worksheet.Cells[row, 1] = new Cell(factura.Bani);
                    worksheet.Cells[row, 2] = new Cell(factura.Observatii);
                    worksheet.Cells[row, 3] = new Cell(factura.Data);
                }

                row++;
            }

            workbook.Worksheets.Add(worksheet);

            workbook.Save(file);

            MessageBox.Show("Raportul a fost generat!");
        }
示例#17
0
        private void btActualizeaza_Click(int id_angajat)
        {
            string  nume = null, prenume = null, adresa = null, functie = null, denumire = null;
            decimal salariu = 0;
            double  rating  = 1;

            try
            {
                if (Regex.IsMatch(tbNume.Text, "^[A-Z][a-z]*"))
                {
                    nume = tbNume.Text;
                }
                else
                {
                    throw new Exception("Numele trebuie sa contina doar litere si sa inceapa cu litera mare");
                }

                if (Regex.IsMatch(tbPrenume.Text, "[A-Z][a-z]*"))
                {
                    prenume = tbPrenume.Text;
                }
                else
                {
                    throw new Exception("Prenumele trebuie sa contina doar litere si sa inceapa cu litera mare");
                }

                if (!tbAdresa.Text.Equals(""))
                {
                    adresa = tbAdresa.Text;
                }
                else
                {
                    throw new Exception("Adresa trebuie sa nu fie nula");
                }

                rating = double.Parse(cbRating.SelectedValue.ToString());

                if (Regex.IsMatch(tbFunctie.Text, "[A-Z][a-z]*"))
                {
                    functie = tbFunctie.Text;
                }
                else
                {
                    throw new Exception("Functia trebuie sa contina doar litere si sa inceapa cu litera mare");
                }

                salariu  = decimal.Parse(tbSalariu.Text);
                denumire = cbDepartament.SelectedValue.ToString();
            }
            catch (FormatException exception)
            {
                MessageBox.Show("Salariul trebuie sa fie de tip float", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            using (var context = new HramulEntities())
            {
                Angajati angajat = (from a in context.Angajatis
                                    where a.ID_ANGAJAT == id_angajat
                                    select a).First();

                State_de_plata stat = (from s in context.State_de_platas
                                       where s.ID_ANGAJAT == id_angajat
                                       where s.Data.Value.Year == DateTime.Today.Year
                                       where s.Data.Value.Month == DateTime.Today.Month
                                       select s).First();

                int departament_id = (from d in context.Departamentes
                                      where d.Denumire.Equals(denumire)
                                      select d.ID_DEPARTAMENT).First();

                angajat.Nume           = nume;
                angajat.Prenume        = prenume;
                angajat.Functie        = functie;
                angajat.Rating         = rating;
                angajat.Adresa         = adresa;
                angajat.ID_DEPARTAMENT = departament_id;

                stat.Suma = salariu;

                context.SaveChanges();
            }

            MessageBox.Show("Angajatul a fost actualizat!");

            Hide();
        }
示例#18
0
        protected void btSalveaza_Click(object sender, EventArgs e)
        {
            string  nume = null, prenume = null, adresa = null, functie = null, denumire = null;
            decimal salariu = 0;
            double  rating  = 1;

            try
            {
                if (Regex.IsMatch(tbNume.Text, "^[A-Z][a-z]*"))
                {
                    nume = tbNume.Text;
                }
                else
                {
                    throw new Exception("Numele trebuie sa contina doar litere si sa inceapa cu litera mare");
                }

                if (Regex.IsMatch(tbPrenume.Text, "[A-Z][a-z]*"))
                {
                    prenume = tbPrenume.Text;
                }
                else
                {
                    throw new Exception("Prenumele trebuie sa contina doar litere si sa inceapa cu litera mare");
                }

                if (!tbAdresa.Text.Equals(""))
                {
                    adresa = tbAdresa.Text;
                }
                else
                {
                    throw new Exception("Adresa trebuie sa nu fie nula");
                }

                rating = double.Parse(cbRating.SelectedValue.ToString());

                if (Regex.IsMatch(tbFunctie.Text, "[A-Z][a-z]*"))
                {
                    functie = tbFunctie.Text;
                }
                else
                {
                    throw new Exception("Functia trebuie sa contina doar litere si sa inceapa cu litera mare");
                }

                salariu  = decimal.Parse(tbSalariu.Text);
                denumire = cbDepartament.SelectedValue.ToString();
            }
            catch (FormatException exception)
            {
                MessageBox.Show("Salariul trebuie sa fie de tip float", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            using (var context = new HramulEntities())
            {
                Departamente departament = (from d in context.Departamentes
                                            where d.Denumire.Equals(denumire)
                                            select d).First();

                Angajati angajat = new Angajati
                {
                    Nume         = nume,
                    Prenume      = prenume,
                    Adresa       = adresa,
                    Rating       = rating,
                    Functie      = functie,
                    Activ        = true,
                    Departamente = departament
                };

                State_de_plata stat = new State_de_plata
                {
                    Suma      = salariu,
                    TIP_PLATA = "SALARIU",
                    Data      = DateTime.Today,
                    Angajati  = angajat
                };


                context.Angajatis.Add(angajat);
                context.State_de_platas.Add(stat);

                context.SaveChanges();

                MessageBox.Show("Angajatul a fost adaugat!");

                Hide();
            }
        }