Exemplo n.º 1
0
        public static Pointage getOneById(int id, bool full)
        {
            Pointage         bean    = new Pointage();
            NpgsqlConnection connect = new Connexion().Connection();

            try
            {
                string           query = "select * from yvs_grh_pointage where id =" + id + ";";
                NpgsqlCommand    Lcmd  = new NpgsqlCommand(query, connect);
                NpgsqlDataReader lect  = Lcmd.ExecuteReader();
                if (lect.HasRows)
                {
                    while (lect.Read())
                    {
                        bean = Return(lect, full);
                    }
                }
                return(bean);
            }
            catch (Exception ex)
            {
                Messages.Exception("PointageDao (getOneById)", ex);
                return(bean);
            }
            finally
            {
                Connexion.Close(connect);
            }
        }
Exemplo n.º 2
0
        public bool getInsert_N(Pointage bean)
        {
            NpgsqlConnection connect = new Connexion().Connection();

            try
            {
                if (bean.Presence != null ? bean.Presence.Id > 0 : false)
                {
                    string        query = "insert into yvs_grh_pointage(heure_entree, heure_sortie, valider, presence, date_save_entree, date_save_sortie, author) values (null, null, false," + bean.Presence.Id + ",null,null," + (Constantes.USERS.Author > 0 ? Constantes.USERS.Author.ToString() : "null") + ")";
                    NpgsqlCommand cmd   = new NpgsqlCommand(query, connect);
                    cmd.ExecuteNonQuery();
                    return(true);
                }
                return(false);
            }
            catch (Exception ex)
            {
                Messages.Exception("PointageDao (getInsert)", ex);
                return(false);
            }
            finally
            {
                Connexion.Close(connect);
            }
        }
Exemplo n.º 3
0
        private void dgv_pointage_MouseDown(object sender, MouseEventArgs e)
        {
            DataGridView.HitTestInfo info = dgv_pointage.HitTest(e.X, e.Y); //get info
            int pos = dgv_pointage.HitTest(e.X, e.Y).RowIndex;

            if (pos > -1)
            {
                if (dgv_pointage.Rows[pos].Cells[0].Value != null)
                {
                    Int64 id = (Int64)dgv_pointage.Rows[pos].Cells[0].Value;
                    if (id > 0)
                    {
                        Pointage f = pointages.Find(x => x.Id == id);
                        switch (e.Button)
                        {
                        case MouseButtons.Right:
                        {
                            ResetPointage();
                            dgv_pointage.Rows[pos].Selected = true;         //Select the row
                        }
                        break;

                        default:
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
 public static bool Update(Pointage bean, long id, string adresse)
 {
     try
     {
         return(PointageDAO.getUpdate(bean, id, adresse));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Exemplo n.º 5
0
 public static bool InsertU(Pointage bean, string adresse)
 {
     try
     {
         return(PointageDAO.getInsert_U(bean, adresse));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Exemplo n.º 6
0
        public static bool getInsert(Pointage bean, string adresse)
        {
            NpgsqlConnection connect = new Connexion().Connection(adresse);

            try
            {
                if (bean.Presence != null ? bean.Presence.Id > 0 : false)
                {
                    string query = "insert into yvs_grh_pointage(heure_entree, valider, presence, date_save_entree, pointeuse_in, date_save_sortie, system_in, heure_supplementaire, author) values ";
                    if (bean.PointeuseIn != null ? bean.PointeuseIn.Id > 0 : false)
                    {
                        if (bean._HeureEntree() != null)
                        {
                            query += "('" + bean.HeureEntree + "',false ," + bean.Presence.Id + ",'" + bean.HeureEntree + "'," + bean.PointeuseIn.Id + ", null, '" + bean.SystemIn + "', '" + bean.Supplementaire + "'," + (Constantes.USERS.Author > 0 ? Constantes.USERS.Author.ToString() : "null") + ")";
                        }
                        else
                        {
                            query += "(null, false ," + bean.Presence.Id + ", null," + bean.PointeuseIn.Id + ", null, '" + bean.SystemIn + "', '" + bean.Supplementaire + "'," + (Constantes.USERS.Author > 0 ? Constantes.USERS.Author.ToString() : "null") + ")";
                        }
                    }
                    else
                    {
                        if (bean._HeureEntree() != null)
                        {
                            query += "('" + bean.HeureEntree + "', false," + bean.Presence.Id + ",'" + bean.HeureEntree + "', null, null, '" + bean.SystemIn + "', '" + bean.Supplementaire + "'," + (Constantes.USERS.Author > 0 ? Constantes.USERS.Author.ToString() : "null") + ")";
                        }
                        else
                        {
                            query += "(null, false ," + bean.Presence.Id + ", null, null, null, '" + bean.SystemIn + "', '" + bean.Supplementaire + "'," + (Constantes.USERS.Author > 0 ? Constantes.USERS.Author.ToString() : "null") + ")";
                        }
                    }
                    NpgsqlCommand cmd = new NpgsqlCommand(query, connect);
                    cmd.ExecuteNonQuery();
                    return(true);
                }
                return(false);
            }
            catch (Exception ex)
            {
                Messages.Exception("PointageDao (getInsert)", ex);
                return(false);
            }
            finally
            {
                Connexion.Close(connect);
            }
        }
Exemplo n.º 7
0
        public static bool getUpdate(Pointage bean, long id, string adresse)
        {
            NpgsqlConnection connect = new Connexion().Connection(adresse);

            try
            {
                string query = "update yvs_grh_pointage set ";
                if (bean.PointeuseOut != null ? bean.PointeuseOut.Id > 0 : false)
                {
                    if (bean._HeureSortie() != null)
                    {
                        query += "valider = " + bean.Valider + " , horaire_normale = " + bean.Valider + " , heure_sortie ='" + bean.HeureSortie + "', date_save_sortie ='" + bean.HeureSortie + "', pointeuse_out =" + bean.PointeuseOut.Id + ", system_out = '" + bean.SystemOut + "'";
                    }
                    else
                    {
                        query += "valider = " + bean.Valider + " , horaire_normale = " + bean.Valider + " , pointeuse_out =" + bean.PointeuseOut.Id + ", system_out = '" + bean.SystemOut + "'";
                    }
                }
                else
                {
                    if (bean._HeureSortie() != null)
                    {
                        query += "valider = " + bean.Valider + " , horaire_normale = " + bean.Valider + " , heure_sortie ='" + bean.HeureSortie + "', date_save_sortie ='" + bean.HeureSortie + "', system_out = '" + bean.SystemOut + "'";
                    }
                    else
                    {
                        query += "valider = " + bean.Valider + " , horaire_normale = " + bean.Valider + " , system_out = '" + bean.SystemOut + "'";
                    }
                }
                query += " where id = " + id;
                NpgsqlCommand cmd = new NpgsqlCommand(query, connect);
                cmd.ExecuteNonQuery();
                return(true);
            }
            catch (Exception ex)
            {
                Messages.Exception("PointageDao (getUpdate)", ex);
                return(false);
            }
            finally
            {
                Connexion.Close(connect);
            }
        }
Exemplo n.º 8
0
        private static Pointage Return(NpgsqlDataReader lect, bool full)
        {
            Pointage bean = new Pointage();

            bean.Id = Convert.ToInt32(lect["id"].ToString());
            if ((lect["heure_entree"] != null) ? lect["heure_entree"].ToString() != "" : false)
            {
                bean.HeureEntree = Convert.ToDateTime(lect["heure_entree"].ToString());
            }
            if ((lect["heure_sortie"] != null) ? lect["heure_sortie"].ToString() != "" : false)
            {
                bean.HeureSortie = Convert.ToDateTime(lect["heure_sortie"].ToString());
            }
            bean.Valider        = Convert.ToBoolean((lect["valider"].ToString() != "") ? lect["valider"].ToString() : "false");
            bean.Supplementaire = Convert.ToBoolean((lect["heure_supplementaire"].ToString() != "") ? lect["heure_supplementaire"].ToString() : "false");
            bean.Presence       = new Presence(Convert.ToInt32(lect["presence"].ToString()));
            bean.SystemIn       = (Boolean)((lect["system_in"] != null) ? (!lect["system_in"].ToString().Trim().Equals("") ? lect["system_in"] : false) : false);
            bean.SystemOut      = (Boolean)((lect["system_out"] != null) ? (!lect["system_out"].ToString().Trim().Equals("") ? lect["system_out"] : false) : false);
            if (full)
            {
                bean.Presence = PresenceDAO.getOneById(Convert.ToInt32(lect["presence"].ToString()), false);
            }
            if ((lect["pointeuse_in"] != null) ? lect["pointeuse_in"].ToString() != "" : false)
            {
                bean.PointeuseIn = new Pointeuse(Convert.ToInt32(lect["pointeuse_in"].ToString()));
                if (full)
                {
                    bean.PointeuseIn = PointeuseDAO.getOneById(Convert.ToInt32(lect["pointeuse_in"].ToString()));
                }
            }
            if ((lect["pointeuse_out"] != null) ? lect["pointeuse_out"].ToString() != "" : false)
            {
                bean.PointeuseOut = new Pointeuse(Convert.ToInt32(lect["pointeuse_out"].ToString()));
                if (full)
                {
                    bean.PointeuseOut = PointeuseDAO.getOneById(Convert.ToInt32(lect["pointeuse_out"].ToString()));
                }
            }
            return(bean);
        }
Exemplo n.º 9
0
        private void dgv_pointage_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            DataGridViewCell cell = this.dgv_pointage.Rows[e.RowIndex].Cells[0];
            Pointage         po   = PointageBLL.OneById(Convert.ToInt32(cell.Value));

            if ((e.ColumnIndex == this.dgv_pointage.Columns["heure_sortie"].Index) && e.Value != null)
            {
                cell = this.dgv_pointage.Rows[e.RowIndex].Cells[e.ColumnIndex];
                if ((po.HeureSortie != null) ? po.HeureSortie.ToString() != "01/01/0001 00:00:00" : false)
                {
                    cell.ToolTipText = po.HeureSortie.ToString();
                }
            }
            else if ((e.ColumnIndex == this.dgv_pointage.Columns["heure_entree"].Index) && e.Value != null)
            {
                cell = this.dgv_pointage.Rows[e.RowIndex].Cells[e.ColumnIndex];
                if ((po.HeureEntree != null) ? po.HeureEntree.ToString() != "01/01/0001 00:00:00" : false)
                {
                    cell.ToolTipText = po.HeureEntree.ToString();
                }
            }
        }
Exemplo n.º 10
0
        public async Task <IActionResult> BenevoleEditOrCreate(int id, [FromBody][Bind("BenevoleID,Date,NbDemiJournees")] Pointage pointage)
        {
            if (id != pointage.BenevoleID)
            {
                return(BadRequest("id does not match BenevoleId"));
            }

            var existing = _context.Pointages
                           .Where(p => p.BenevoleID == pointage.BenevoleID && p.Date == pointage.Date.Date)
                           .SingleOrDefault();

            if (existing != null)
            {
                pointage.ID = existing.ID;
            }

            var benevole = _context.Benevoles.Include(b => b.Adresses).SingleOrDefault(b => b.ID == pointage.BenevoleID);
            var adresse  = benevole.GetAdresseFromDate(pointage.Date);
            var centreId = adresse.CentreID;

            pointage.AdresseID = adresse.ID;

            if (existing != null && existing.AdresseID != pointage.AdresseID)
            {
                return(BadRequest("AdresseID does not match with existing pointage"));
            }

            var userCentreId = GetCurrentUser().CentreID;

            if (userCentreId != null && centreId != userCentreId)
            {
                return(Forbid());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    bool created = false;

                    if (existing != null)
                    {
                        existing.NbDemiJournees = pointage.NbDemiJournees;
                        _context.Update(existing);
                    }
                    else
                    {
                        created = true;
                        _context.Pointages.Add(pointage);
                    }

                    await _context.SaveChangesAsync();

                    if (created)
                    {
                        LogInfo("Pointage créé au {DatePointage:dd/MM/yyyy} pour le benevole #{BenevoleID} sur l'adresse {AdresseID}", pointage.Date, pointage.BenevoleID, pointage.AdresseID);
                    }
                    else
                    {
                        LogInfo("Pointage modifié au {DatePointage:dd/MM/yyyy} pour le benevole #{BenevoleID} sur l'adresse {AdresseID}", pointage.Date, pointage.BenevoleID, pointage.AdresseID);
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PointageExists(pointage.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(Json(new { id = pointage.ID }));
            }

            return(View(pointage));
        }