public ActionResult FormAttestation(string Mode, int Code)
        {
            ATTESTATIONS Element = new ATTESTATIONS();

            if (Mode == "Create")
            {
                ViewBag.TITRE_PAGE = "AJOUTER UNE NOUVELLE ATTESTATION";
                ViewBag.DATE       = DateTime.Today.ToShortDateString();
                int Max = 1;
                List <ATTESTATIONS> liste = BD.ATTESTATIONS.Where(Elt => Elt.DATE.Year == DateTime.Today.Year).ToList();
                if (liste.Count > 0)
                {
                    Max = liste.Select(Elt => Elt.NUMERO).Max();
                    Max++;
                }
                ViewBag.REFERENCE = "ATT" + Max.ToString("000") + "/" + DateTime.Today.Year;
            }
            if (Mode == "Edit")
            {
                Element            = BD.ATTESTATIONS.Find(Code);
                ViewBag.TITRE_PAGE = "MODIFIER UNE ATTESTATION";
                ViewBag.DATE       = Element.DATE.ToShortDateString();
                ViewBag.REFERENCE  = Element.REFERENCE;
            }
            ViewBag.Mode = Mode;
            ViewBag.Code = Code;
            return(View(Element));
        }
        public ActionResult Delete(int Code)
        {
            ATTESTATIONS Selected = BD.ATTESTATIONS.Find(Code);

            BD.ATTESTATIONS.Remove(Selected);
            BD.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult GetFileByID(string id)
        {
            int          ID          = int.Parse(id);
            ATTESTATIONS attestation = BD.ATTESTATIONS.Find(ID);
            dynamic      dt          = new
            {
                LOCALITE    = attestation.LOCALITE,
                DATE        = attestation.DATE.ToShortDateString(),
                REFERENCE   = attestation.REFERENCE,
                TITRE       = attestation.MODELES_ATTESTATIONS.TITRE,
                DESCRIPTION = GetDescriptionByEmployee(ID),
                SIGNE_PAR   = attestation.SIGNE_PAR,
            };

            ReportDocument rptH     = new ReportDocument();
            string         FileName = Server.MapPath("/Reports/ATTESTATION.rpt");

            rptH.Load(FileName);
            rptH.SetDataSource(new[] { dt });
            Stream stream = rptH.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);

            return(File(stream, "application/pdf"));
        }
        public string GetDescriptionByEmployee(int id)
        {
            string                Result      = string.Empty;
            ATTESTATIONS          attestation = BD.ATTESTATIONS.Find(id);
            EMPLOYEES             employee    = attestation.EMPLOYEES;
            MODELES_ATTESTATIONS  model       = attestation.MODELES_ATTESTATIONS;
            List <CHAMPS_MODELES> liste       = BD.CHAMPS_MODELES.Where(Element => Element.MODELES_ATTESTATIONS.ID == model.ID).OrderBy(Element => Element.ORDRE).ToList();

            foreach (CHAMPS_MODELES Element in liste)
            {
                if (Element.TYPE == "TEXT")
                {
                    if (Element.VALEUR.Trim() == string.Empty)
                    {
                        Result += Environment.NewLine;
                        Result += Environment.NewLine;
                    }

                    Result += Element.VALEUR + " ";
                }
                if (Element.TYPE == "TABLE")
                {
                    if (Element.VALEUR == "CIN")
                    {
                        Result += employee.CIN + " ";
                    }
                    if (Element.VALEUR == "FULLNAME")
                    {
                        Result += employee.FULLNAME + " ";
                    }
                    if (Element.VALEUR == "NUM_ASS_SOC")
                    {
                        Result += employee.NUM_ASS_SOC + " ";
                    }
                    if (Element.VALEUR == "QUALIFICATION")
                    {
                        Result += employee.QUALIFICATION + " ";
                    }
                    if (Element.VALEUR == "NUMERO")
                    {
                        Result += employee.NUMERO + " ";
                    }
                    if (Element.VALEUR == "ADRESSE")
                    {
                        Result += employee.ADRESSE + " ";
                    }
                    if (Element.VALEUR == "CIVILITE")
                    {
                        Result += employee.CIVILITE + " ";
                    }
                    if (Element.VALEUR == "SALAIRE")
                    {
                        Result += ((decimal)employee.SALAIRE) * 13 + " ";
                    }
                    if (Element.VALEUR == "DEMARRAGE")
                    {
                        Result += employee.DEMARRAGE.Value.ToShortDateString() + " ";
                    }
                }
            }
            return(Result);
        }
        public ActionResult SendFormAttestation(string Mode, string Code)
        {
            string REFERENCE   = Request.Params["REFERENCE"] != null ? Request.Params["REFERENCE"].ToString() : string.Empty;
            string MODELE      = Request.Params["MODELE"] != null ? Request.Params["MODELE"].ToString() : string.Empty;
            string employee    = Request.Params["employee"] != null ? Request.Params["employee"].ToString() : string.Empty;
            string LOCALITE    = Request.Params["LOCALITE"] != null ? Request.Params["LOCALITE"].ToString() : string.Empty;
            string DATE        = Request.Params["DATE"] != null ? Request.Params["DATE"].ToString() : string.Empty;
            string SIGNE_PAR   = Request.Params["SIGNE_PAR"] != null ? Request.Params["SIGNE_PAR"].ToString() : string.Empty;
            string DECHARGE    = Request.Params["DECHARGE"] != null ? "true" : "false";
            string COMMENTAIRE = Request.Params["COMMENTAIRE"] != null ? Request.Params["COMMENTAIRE"].ToString() : "";


            DateTime  SelectedDate     = DateTime.Parse(DATE);
            int       ID               = int.Parse(employee);
            EMPLOYEES SelectedEmployee = BD.EMPLOYEES.Find(ID);

            int SelectedModel          = int.Parse(MODELE);
            MODELES_ATTESTATIONS Model = BD.MODELES_ATTESTATIONS.Find(SelectedModel);

            if (Mode == "Create")
            {
                int Max = 1;
                List <ATTESTATIONS> liste = BD.ATTESTATIONS.Where(Elt => Elt.DATE.Year == DateTime.Today.Year).ToList();
                if (liste.Count > 0)
                {
                    Max = liste.Select(Elt => Elt.NUMERO).Max();
                    Max++;
                }

                ATTESTATIONS NewElement = new ATTESTATIONS();
                NewElement.EMPLOYE              = ID;
                NewElement.EMPLOYEES            = SelectedEmployee;
                NewElement.DATE                 = SelectedDate;
                NewElement.REFERENCE            = REFERENCE;
                NewElement.NUMERO               = Max;
                NewElement.MODELE               = SelectedModel;
                NewElement.MODELES_ATTESTATIONS = Model;
                NewElement.LOCALITE             = LOCALITE;
                NewElement.COMMENTAIRE          = COMMENTAIRE != "undefined" ? COMMENTAIRE : string.Empty;
                NewElement.SIGNE_PAR            = SIGNE_PAR;
                NewElement.DECHARGE             = Boolean.Parse(DECHARGE);
                BD.ATTESTATIONS.Add(NewElement);
                BD.SaveChanges();
            }
            if (Mode == "Edit")
            {
                int          SeletedPretID = int.Parse(Code);
                ATTESTATIONS NewElement    = BD.ATTESTATIONS.Find(SeletedPretID);
                NewElement.EMPLOYE   = ID;
                NewElement.EMPLOYEES = SelectedEmployee;
                NewElement.DATE      = SelectedDate;
                //NewElement.REFERENCE = REFERENCE;
                //NewElement.NUMERO = Max;
                NewElement.MODELE = SelectedModel;
                NewElement.MODELES_ATTESTATIONS = Model;
                NewElement.LOCALITE             = LOCALITE;
                NewElement.COMMENTAIRE          = COMMENTAIRE != "undefined" ? COMMENTAIRE : string.Empty;
                NewElement.SIGNE_PAR            = SIGNE_PAR;
                NewElement.DECHARGE             = Boolean.Parse(DECHARGE);
                BD.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }