示例#1
0
        private void button_pontaj_Click(object sender, EventArgs e)
        {
            try
            {
                using (HREntities hr = new HREntities())
                {
                    pontaje p = hr.pontajes.FirstOrDefault(r => r.id_personal == (int)comboBox_nume.SelectedValue &&
                                                           r.date_out == null);

                    //if (hr.pontajes.Any(r => r.Transaction == (int)comboBox_nume.SelectedValue))) return;//verificare daca exita randuri in BD
                    //pontaje interogare=from pontaje in hr.pontajes
                    //               where pontaje.id_personal==pontaje.id_personal
                    //               select pontaje;
                    if ((p == null) || (p.date_out != null))//adauga intrare noua
                    {
                        pontaje pont = new pontaje();
                        pont.id_personal = (int)comboBox_nume.SelectedValue;
                        pont.date_in     = DateTime.Now; //dateTime_dateInPontaj.Value;
                        hr.pontajes.Add(pont);
                    }
                    else  //salveaza dataout
                    {
                        p.date_out = DateTime.Now;
                    }
                    hr.SaveChanges();
                    MessageBox.Show("Pontaj salvat!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n" + ex.StackTrace + "\n" + ex.InnerException);
            }
        }
示例#2
0
 private void button_delete_Click(object sender, EventArgs e)
 {
     try
     {
         if (MessageBox.Show("Sigur stergeti?", "Stergere") == DialogResult.OK)
         {
             /* functioneaza la fel
              * MessageBox.Show(dataGridView.Rows.Count.ToString());
              * MessageBox.Show(dataGridView.Columns.Count.ToString());
              * MessageBox.Show(dataGridView.RowCount.ToString());
              * MessageBox.Show(dataGridView.ColumnCount.ToString());
              * */
             //MessageBox.Show(dataGridView.SelectedCells[0].RowIndex.ToString());//return nr rand , incepe cu 0
             int rowindex = dataGridView.CurrentCell.RowIndex;//return nr rand , incepe cu 0
             //int columnindex= dataGridView.CurrentCell.ColumnIndex;
             //MessageBox.Show(dataGridView.Rows[rowindex].Cells[columnindex].Value.ToString());//return continutul celulei curente
             int id_act = (int)dataGridView.Rows[rowindex].Cells[0].Value;//returneaza id-ul randului selectat
             using (HREntities hr = new HREntities())
             {
                 acte act = hr.actes.FirstOrDefault(r => r.id == id_act);
                 if (act != null)
                 {
                     hr.actes.Remove(act);
                     hr.SaveChanges();
                     grid_list();
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message + "\n" + ex.StackTrace + "\n" + ex.InnerException);
     }
 }
示例#3
0
        private void grid_list()
        {
            try
            {
                using (HREntities hr = new HREntities())
                {
                    //pt editarea in Grid
                    //BindingSource bs = new BindingSource();

                    /*
                     * var interogare = from act in hr.actes //interogarre de tip Linq
                     *                  orderby act.id
                     *                  select act;
                     * * varianta asta da eroare pentru ca incearca sa extraga si istoric cereri
                     */
                    var interogare = from act in hr.actes //interogarre de tip Linq
                                     orderby act.id
                                     select new { act.id, act.denumire, act.continut };

                    var lista_acte = interogare.ToList();
                    //bs.DataSource = interogare.ToList();
                    //dataGridView.DataSource = bs;
                    dataGridView.DataSource = lista_acte;
                    //doar aici exista deja coloanele
                    dataGridView.Columns[0].Visible = false;
                    dataGridView.Columns[1].Width   = 300;
                    dataGridView.Columns[2].Width   = 700;

                    /*
                     * foreach (var item in interogare)
                     * {
                     *  MessageBox.Show(item.denumire + item.continut);
                     * }*/
                    //sau - asta permite editarea dar nu se salveaza
                    //dataGridView.DataSource = hr.actes.ToList();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace + "\n\n" + ex.InnerException);
            }
        }
示例#4
0
        private void populate_combo()
        {
            try
            {
                using (HREntities hr = new HREntities())
                {
                    //var interogare = from personal in hr.personals
                    //                 orderby personal.name
                    //                 select new { personal.id, personal.name };

                    //var lista_nume = interogare.tolist();
                    //comboBox_nume.DataSource = interogare;
                    comboBox_nume.DataSource    = hr.personals.ToList();
                    comboBox_nume.ValueMember   = "id";
                    comboBox_nume.DisplayMember = "name";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace + "\n\n" + ex.InnerException);
            }
        }
示例#5
0
 private void frm_Add_acte_Load(object sender, EventArgs e)
 {
     if (editare)
     {//pentru editare
         try{
             this.Text = "Modificare act";
             using (HREntities hr = new HREntities()){
                 acte act = hr.actes.FirstOrDefault(r => r.id == id_edit);
                 if (act != null)
                 {
                     textBox_denumire.Text = act.denumire.ToString();
                     textBox_link.Text     = act.continut.ToString();
                 }
             }
         }catch (Exception ex) {
             MessageBox.Show(ex.Message + "\n" + ex.StackTrace + "\n" + ex.InnerException);
         }
     }
     else
     {
         //pt adaugare
     }
 }
示例#6
0
 private void button_Ok_Click(object sender, EventArgs e)
 {
     if (editare)
     {
         /*
          * ent.actes.FirstOrDefault(r => r.id == 1);
          * acte a = new acte();
          * a.denumire = textBox_denumire.Text;
          * a.continut = textBox_link.Text;
          * ent.SaveChanges();
          */
         try
         {
             using (HREntities ent = new HREntities())
             {
                 acte act = ent.actes.FirstOrDefault(r => r.id == id_edit);
                 if (act != null)
                 {
                     act.denumire = textBox_denumire.Text;
                     act.continut = textBox_link.Text;
                     ent.SaveChanges();
                 }
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message + "\n" + ex.StackTrace + "\n" + ex.InnerException);
         }
     }
     else
     {
         /*HREntities ent= new HREntities();
          * acte a = new acte();
          * a.denumire = textBox_denumire.Text;
          * a.continut = textBox_link.Text;
          *
          * ent.actes.Add(a);
          * ent.SaveChanges();*/
         try
         {
             using (HREntities ent = new HREntities())
             {
                 acte act = new acte
                 {
                     denumire = textBox_denumire.Text,
                     continut = textBox_link.Text,
                 };
                 ent.actes.Add(act);
                 ent.SaveChanges();
             }
         }
         catch (Exception ex)
         {
             // throw;
             MessageBox.Show(ex.Message + "\n" + ex.StackTrace + "\n" + ex.InnerException);
         } finally {
             //release daca e cazul
         }
     }
     this.Close();
 }
示例#7
0
        private void button_ok_Click(object sender, EventArgs e)
        {
            if (emplo)
            {
                //////////////////// Utilizare tranzactii

                /*
                 * using (HREntities hr = new HREntities())
                 * {
                 *  using (var dbContextTransaction = hr.Database.BeginTransaction())
                 *  {
                 *      try
                 *      {
                 *          hr.Database.ExecuteSqlCommand(
                 *              @"UPDATE Blogs SET Rating = 5" +
                 *                  " WHERE Name LIKE '%Entity Framework%'"
                 *              );
                 *
                 *          var query = hr.actes.Where(p => p.Blog.Rating >= 5);
                 *          foreach (var post in query)
                 *          {
                 *              post.Title += "[Cool Blog]";
                 *          }
                 *
                 *          hr.SaveChanges();
                 *
                 *          dbContextTransaction.Commit();
                 *      }
                 *      catch (Exception)
                 *      {
                 *          dbContextTransaction.Rollback();
                 *      }
                 *  }
                 * }
                 */
                //////////////////
                HREntities ent = new HREntities();
                ent.actes.FirstOrDefault(r => r.id == 1);
                personal  b = new personal();
                employee  a = new employee();
                trainer   c = new trainer();
                candidate d = new candidate();
                b.name = textBox_nume.Text;
                int x = 0;
                Int32.TryParse(textBox_telefon.Text, out x);
                b.phone   = x;
                b.address = textBox_adresa.Text;
                int y = 0;
                Int32.TryParse(textBox_cnp.Text, out y);
                b.CNP      = y;
                b.email    = textBox_email.Text;
                b.civilst  = textBox_starecivila.Text;
                b.depart   = textBox_departament.Text;
                b.sex      = checkBox_sexM.Text;
                b.sex      = checkBox_sexF.Text;
                b.username = textBox_numeutilizator.Text;
                b.pass     = textBox_parola.Text;
                //nu am stiut sa convertim datetime in string :(!!

                //a.data_in = dateTime_dataangajarii.Text;
                //a.data_in = dateTime_dataplecarii.Text;
                // c.schedule = textBox_orarTraining;
                // c.beginning = dateTime_inceputTraining.Text;
                // c.finish = dateTime_sfarsitTraining.Text;
                d.CV = textBox_cv.Text;//aici ar trebui un buton de upload, dar nu am reusit sa-l facem...


                ent.SaveChanges();
            }

            else

            {
                HREntities ent = new HREntities();
                personal   b   = new personal();
                employee   a   = new employee();
                trainer    c   = new trainer();
                candidate  d   = new candidate();
                b.name = textBox_nume.Text;
                int x = 0;
                Int32.TryParse(textBox_telefon.Text, out x);
                b.phone   = x;
                b.address = textBox_adresa.Text;
                int y = 0;
                Int32.TryParse(textBox_cnp.Text, out y);
                b.CNP      = y;
                b.email    = textBox_email.Text;
                b.civilst  = textBox_starecivila.Text;
                b.depart   = textBox_departament.Text;
                b.sex      = checkBox_sexM.Text;
                b.sex      = checkBox_sexF.Text;
                b.username = textBox_numeutilizator.Text;
                b.pass     = textBox_parola.Text;
                //nu am stiut sa convertim datetime in string :(!!

                //a.data_in = dateTime_dataangajarii.Text;
                //a.data_in = dateTime_dataplecarii.Text;
                // c.schedule = textBox_orarTraining;
                // c.beginning = dateTime_inceputTraining.Text;
                // c.finish = dateTime_sfarsitTraining.Text;
                d.CV = textBox_cv.Text;

                ent.employees.Add(a);
                ent.personals.Add(b);
                ent.trainers.Add(c);
                ent.candidates.Add(d);
                ent.SaveChanges();
            }
            this.Close();
        }