public void CreateMaintenanceRequestReport(MaintRequestInitiation maintReqSingle)
        {
            using (WordprocessingDocument doc = WordprocessingDocument.Open(@"C:\Users\cabuk\Desktop\maintreqdetails.docx", true))
            {
                var document = doc.MainDocumentPart.Document;

                //loop through the preoprties of the maintenance request initation object
                foreach (PropertyInfo prop in maintReqSingle.GetType().GetProperties())
                {
                    //loop through the text in the word document
                    foreach (var text in document.Descendants <Text>())
                    {
                        //if the text found is equal to the proeprtyname then put text there
                        //the placeholder in the word document is {propertyname}
                        if (text.Text == "{" + prop.Name + "}")
                        {
                            var type = prop.Name;

                            if (prop.Name == "Factory")
                            {
                                text.Text = text.Text.Replace("{Factory}", maintReqSingle.Factory.FactoryName);
                            }
                            else
                            {
                                text.Text = text.Text.Replace(prop.Name, prop.GetValue(maintReqSingle, null).ToString());
                            }
                        }
                    }
                }

                doc.Save();
            }
        }
Exemplo n.º 2
0
        public void ExportSingalReqest(MaintRequestInitiation maintReqSingle, ObservableCollection <MaintRequestInitiationRisk> maintReqRiskList)
        {
            var template = new XLTemplate(@"C:\Excel Export Test\TestRequest.xlsx");

            template.AddVariable(maintReqSingle);
            template.Generate();
            template.SaveAs(@"C:\Excel Export Test\New Report " + maintReqSingle.Id + ".xlsx");

            //open the excel file and loop through and set the risks
            using (var workbook = XLWorkbook.OpenFromTemplate(@"C:\Excel Export Test\New Report " + maintReqSingle.Id + ".xlsx"))
            {
                var worksheet = workbook.Worksheet(1);

                //loop through the risks and put into the correct position
                foreach (var item in maintReqSingle.Risks)
                {
                    var riskId = item.Id;

                    //loop through the risk link table to get the set level of risk
                    foreach (var itemRisk in maintReqRiskList)
                    {
                        if (itemRisk.RiskId == item.Id)
                        {
                            //switch(item.RiskName)
                            //{
                            //    case "Slips, trips and falls":
                            //        if (itemRisk.RiskLevel == "H") { worksheet.Cell("C18").Value = "X";  }
                            //        if (itemRisk.RiskLevel == "M") { worksheet.Cell("D18").Value = "X"; }
                            //        if (itemRisk.RiskLevel == "L") { worksheet.Cell("E18").Value = "X"; }
                            //        break;
                            //    case "Falls from height":
                            //        if (itemRisk.RiskLevel == "H") { worksheet.Cell("C19").Value = "X"; }
                            //        if (itemRisk.RiskLevel == "M") { worksheet.Cell("D19").Value = "X"; }
                            //        if (itemRisk.RiskLevel == "L") { worksheet.Cell("E19").Value = "X"; }
                            //        break;
                            //    case "Contact with moving machinery":
                            //        if (itemRisk.RiskLevel == "H") { worksheet.Cell("C20").Value = "X"; }
                            //        if (itemRisk.RiskLevel == "M") { worksheet.Cell("D20").Value = "X"; }
                            //        if (itemRisk.RiskLevel == "L") { worksheet.Cell("E20").Value = "X"; }
                            //        break;
                            //    case "Electrical":
                            //        if (itemRisk.RiskLevel == "H") { worksheet.Cell("C21").Value = "X"; }
                            //        if (itemRisk.RiskLevel == "M") { worksheet.Cell("D21").Value = "X"; }
                            //        if (itemRisk.RiskLevel == "L") { worksheet.Cell("E21").Value = "X"; }
                            //        break;
                            //}
                        }
                    }
                }

                workbook.SaveAs(@"C:\Excel Export Test\New Report " + maintReqSingle.Id + "trtrtr.xlsx");
            }
        }
Exemplo n.º 3
0
        public void EnterManyToManyTableMaintReqInitation2()
        {
            //using (var context = new SACOMaintenanceContext())
            //{
            //context.Database.EnsureDeleted();
            //context.Database.EnsureCreated();
            //}

            //Get PPE Items
            var        PpeDataProvider = new PPEDataProvider();
            List <PPE> ppeItem         = new List <PPE>();

            ppeItem = (List <PPE>)PpeDataProvider.LoadAllPPE();

            //Get Risk Items
            var         riskDataProvider = new RiskDataProvider();
            List <Risk> maintRisks       = new List <Risk>();

            maintRisks = (List <Risk>)riskDataProvider.LoadallRisks();

            //Add new maintenance request and add PPE item to List
            var maintInition = new MaintRequestInitiation();

            maintInition.RequestedById  = 1;
            maintInition.AreaId         = 1;
            maintInition.FactoryId      = 1;
            maintInition.CompanyId      = 1;
            maintInition.RequestDetails = "This is request one detail and it needs fixing";
            maintInition.DateRaised     = DateTime.Now;
            maintInition.EquipmentId    = 1;
            maintInition.RequestTypeId  = 1;

            var maintInitiation = new MaintRequestInitiationDataProvider();

            maintInitiation.AddEditRequestInitiation(maintInition);
            var getMaint = maintInitiation.GetSingleRequestInitiation(2);

            getMaint.Risks.AddRange(maintRisks);
            getMaint.PPEEquipment.AddRange(ppeItem);

            maintInitiation.AddEditRequestInitiation(getMaint);
        }