Beispiel #1
0
        public ActionResult ExportCal(int id)
        {
            try
            {
                TblCalLoad ob = db.TblCalLoad.Find(id);
                if (ob == null)
                {
                    throw new Exception("Data not found.");
                }

                SoilCalculatedModel md = new SoilCalculatedModel(uow)
                {
                    inputC        = ob.InputC,
                    inputDegree   = ob.InputDegree,
                    ModelId       = ob.ModelId,
                    inputSafeload = ob.InputSafeLoad
                };

                string sourceFile = Server.MapPath("~/files/KEMREXCalculated.xlsx");
                byte[] byteArray  = IOFile.ReadAllBytes(sourceFile);
                using (MemoryStream stream = new MemoryStream())
                {
                    stream.Write(byteArray, 0, (int)byteArray.Length);
                    using (SpreadsheetDocument spreadsheetDoc = SpreadsheetDocument.Open(stream, true))
                    {
                        IEnumerable <Sheet> sheets = spreadsheetDoc.WorkbookPart.Workbook.GetFirstChild <Sheets>().Elements <Sheet>().Where(s => s.Name == "Calculated");
                        if (sheets.Count() <= 0)
                        {
                            throw new Exception("Cannot find 'Calculated' sheet in source file.");
                        }

                        string        relationshipId = sheets.First().Id.Value;
                        WorksheetPart worksheetPart  = (WorksheetPart)spreadsheetDoc.WorkbookPart.GetPartById(relationshipId);
                        if (worksheetPart == null)
                        {
                            throw new Exception("Cannot load 'Calculated' sheet.");
                        }

                        Worksheet sheet = worksheetPart.Worksheet;
                        UpdateCell(ref sheet, "E", 5, md.inputC.ToString());
                        UpdateCell(ref sheet, "E", 6, md.inputDegree.ToString());
                        UpdateCell(ref sheet, "E", 7, md.ModelInfo.PileName);
                        UpdateCell(ref sheet, "E", 11, md.inputC.ToString());
                        UpdateCell(ref sheet, "E", 12, md.ModelInfo.PileDia.ToString("#,##0.000"));
                        UpdateCell(ref sheet, "E", 13, md.ClayAb.ToString("#,##0.00000"));
                        UpdateCell(ref sheet, "E", 15, md.Qu.ToString("#,##0.00"));
                        UpdateCell(ref sheet, "E", 18, md.ShearH.ToString("#,##0"));
                        UpdateCell(ref sheet, "E", 19, md.ShearArea.ToString("#,##0.000"));
                        UpdateCell(ref sheet, "E", 21, md.ShearResist.ToString("#,##0.00"));
                        UpdateCell(ref sheet, "E", 24, md.UltCompressForce.ToString("#,##0"));
                        UpdateCell(ref sheet, "E", 26, md.ShearResist.ToString("#,##0.00"));
                        UpdateCell(ref sheet, "E", 31, md.UpliftH.ToString("#,##0.000"));
                        UpdateCell(ref sheet, "E", 32, md.UpliftHcone.ToString("#,##0.000"));
                        UpdateCell(ref sheet, "E", 33, md.WeightOfSoil.ToString("#,##0"));
                        UpdateCell(ref sheet, "E", 34, md.ShearResist.ToString("#,##0.00"));
                        UpdateCell(ref sheet, "E", 36, md.UltUpliftForce.ToString("#,##0"));
                        UpdateCell(ref sheet, "E", 37, md.Quplift.ToString("#,##0.00"));
                    }
                    //IOFile.WriteAllBytes("C:\\temp\\newName.xlsx", stream.ToArray());
                    string mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                    Response.Buffer = true;
                    Response.Clear();
                    Response.ContentType = mimeType;
                    Response.AddHeader("content-disposition", "attachment; filename= KEMREXCalculated-" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xlsx");
                    Response.BinaryWrite(stream.ToArray());
                    Response.Flush(); // send it to the client to download
                    Response.End();
                }
                return(View());
            }
            catch (Exception ex)
            { return(RedirectToAction("Index", "Soil", new { msg = "Something wrong. [" + ex.GetMessage() + "]", msgType = AlertMsgType.Danger })); }
        }
Beispiel #2
0
        public ActionResult Calculated()
        {
            SysRole role = CurrentUser.Role(3).Role();

            ViewBag.canWrite = role.SysRolePermission.Where(x => x.MenuId == 3210 && x.PermissionId == 2 && x.PermissionFlag).Count() > 0;
            int                 CalId       = Request.Form["CalId"].ParseInt();
            decimal             cValue      = Request.Form["inputC"].ParseDecimal();
            int                 degreeValue = Request.Form["inputDegree"].ParseInt();
            int                 modelId     = Request.Form["inputModel"].ParseInt();
            decimal             safeLoad    = Request.Form["inputSafeLoad"].ParseDecimal();
            string              name        = Request.Form["inputProject"];
            string              remark      = Request.Form["inputRemark"];
            SoilCalculatedModel md          = new SoilCalculatedModel(uow)
            {
                calId         = CalId,
                inputC        = cValue,
                inputDegree   = degreeValue,
                ModelId       = modelId,
                inputSafeload = safeLoad,
                ProjectName   = name,
                CalRemark     = remark
            };

            if (Request.Form["isExported"].ParseBoolean())
            {
                string sourceFile = Server.MapPath("~/files/KEMREXCalculated.xlsx");
                byte[] byteArray  = IOFile.ReadAllBytes(sourceFile);
                using (MemoryStream stream = new MemoryStream())
                {
                    stream.Write(byteArray, 0, (int)byteArray.Length);
                    using (SpreadsheetDocument spreadsheetDoc = SpreadsheetDocument.Open(stream, true))
                    {
                        IEnumerable <Sheet> sheets = spreadsheetDoc.WorkbookPart.Workbook.GetFirstChild <Sheets>().Elements <Sheet>().Where(s => s.Name == "Calculated");
                        if (sheets.Count() <= 0)
                        {
                            throw new Exception("Cannot find 'Calculated' sheet in source file.");
                        }

                        string        relationshipId = sheets.First().Id.Value;
                        WorksheetPart worksheetPart  = (WorksheetPart)spreadsheetDoc.WorkbookPart.GetPartById(relationshipId);
                        if (worksheetPart == null)
                        {
                            throw new Exception("Cannot load 'Calculated' sheet.");
                        }

                        Worksheet sheet = worksheetPart.Worksheet;
                        UpdateCell(ref sheet, "E", 5, md.inputC.ToString());
                        UpdateCell(ref sheet, "E", 6, md.inputDegree.ToString());
                        UpdateCell(ref sheet, "E", 7, md.ModelInfo.PileName);
                        UpdateCell(ref sheet, "E", 11, md.inputC.ToString());
                        UpdateCell(ref sheet, "E", 12, md.ModelInfo.PileDia.ToString("#,##0.000"));
                        UpdateCell(ref sheet, "E", 13, md.ClayAb.ToString("#,##0.00000"));
                        UpdateCell(ref sheet, "E", 15, md.Qu.ToString("#,##0.00"));
                        UpdateCell(ref sheet, "E", 18, md.ShearH.ToString("#,##0"));
                        UpdateCell(ref sheet, "E", 19, md.ShearArea.ToString("#,##0.000"));
                        UpdateCell(ref sheet, "E", 21, md.ShearResist.ToString("#,##0.00"));
                        UpdateCell(ref sheet, "E", 24, md.UltCompressForce.ToString("#,##0"));
                        UpdateCell(ref sheet, "E", 26, md.ShearResist.ToString("#,##0.00"));
                        UpdateCell(ref sheet, "E", 31, md.UpliftH.ToString("#,##0.000"));
                        UpdateCell(ref sheet, "E", 32, md.UpliftHcone.ToString("#,##0.000"));
                        UpdateCell(ref sheet, "E", 33, md.WeightOfSoil.ToString("#,##0"));
                        UpdateCell(ref sheet, "E", 34, md.ShearResist.ToString("#,##0.00"));
                        UpdateCell(ref sheet, "E", 36, md.UltUpliftForce.ToString("#,##0"));
                        UpdateCell(ref sheet, "E", 37, md.Quplift.ToString("#,##0.00"));
                    }
                    //IOFile.WriteAllBytes("C:\\temp\\newName.xlsx", stream.ToArray());
                    string mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                    Response.Buffer = true;
                    Response.Clear();
                    Response.ContentType = mimeType;
                    Response.AddHeader("content-disposition", "attachment; filename= KEMREXCalculated-" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xlsx");
                    Response.BinaryWrite(stream.ToArray());
                    Response.Flush(); // send it to the client to download
                    Response.End();
                }
            }
            return(View(md));
        }
Beispiel #3
0
        public ActionResult Export(int id)
        {
            try
            {
                TblCalLoad ob = db.TblCalLoad
                                .Where(x => x.CalId == id)
                                .FirstOrDefault();
                if (ob == null)
                {
                    throw new Exception("Data not found.");
                }
                SoilCalculatedModel md = new SoilCalculatedModel(uow)
                {
                    inputC        = ob.InputC,
                    inputDegree   = ob.InputDegree,
                    ModelId       = ob.ModelId,
                    inputSafeload = ob.InputSafeLoad
                };
                ReportDataSource rptData   = new ReportDataSource("db", new List <SysParameter>());
                ReportViewer     rptViewer = new ReportViewer();
                rptViewer.ProcessingMode                   = ProcessingMode.Local;
                rptViewer.LocalReport.ReportPath           = Server.MapPath("~/reports/rptLoadCalculator.rdlc");
                rptViewer.LocalReport.EnableExternalImages = true;
                string imagePath = new Uri(Server.MapPath("~/" + ob.PileModel().TblPileSeries.SeriesImage)).AbsoluteUri;
                rptViewer.LocalReport.SetParameters(new ReportParameter("imagePile", imagePath));
                rptViewer.LocalReport.SetParameters(new ReportParameter("pileWidth", (md.ModelInfo.PileDia * 1000).ToString("#,##0")));
                rptViewer.LocalReport.SetParameters(new ReportParameter("pileLength", md.ModelInfo.PileLength.ToString("#,##0")));
                rptViewer.LocalReport.SetParameters(new ReportParameter("inputC", md.inputC.ToString()));
                rptViewer.LocalReport.SetParameters(new ReportParameter("inputDegree", md.inputDegree.ToString()));
                rptViewer.LocalReport.SetParameters(new ReportParameter("inputModel", md.ModelInfo.PileName));
                rptViewer.LocalReport.SetParameters(new ReportParameter("dataSu", md.inputC.ToString()));
                rptViewer.LocalReport.SetParameters(new ReportParameter("dataDia", md.ClayDia.ToString("#,##0.000")));
                rptViewer.LocalReport.SetParameters(new ReportParameter("dataAb", md.ClayAb.ToString("#,##0.00000")));
                rptViewer.LocalReport.SetParameters(new ReportParameter("dataQb", md.Qu.ToString("#,##0.00")));
                rptViewer.LocalReport.SetParameters(new ReportParameter("dataShearH", md.ShearH.ToString()));
                rptViewer.LocalReport.SetParameters(new ReportParameter("dataShearArea", md.ShearArea.ToString("#,##0.000")));
                rptViewer.LocalReport.SetParameters(new ReportParameter("dataShearResist", md.ShearResist.ToString("#,##0.00")));
                rptViewer.LocalReport.SetParameters(new ReportParameter("dataQComp", md.UltCompressForce.ToString("#,##0")));
                rptViewer.LocalReport.SetParameters(new ReportParameter("dataSafeLoadComp", md.Qcomp.ToString("#,##0.00")));
                rptViewer.LocalReport.SetParameters(new ReportParameter("dataHCone", md.UpliftH.ToString("#,##0.000")));
                rptViewer.LocalReport.SetParameters(new ReportParameter("dataWeightOfSoil", md.WeightOfSoil.ToString("#,##0")));
                rptViewer.LocalReport.SetParameters(new ReportParameter("dataQUplift", md.UltUpliftForce.ToString("#,##0")));
                rptViewer.LocalReport.SetParameters(new ReportParameter("dataSafeLoadUplift", md.Quplift.ToString("#,##0.00")));
                rptViewer.LocalReport.DataSources.Clear();
                rptViewer.LocalReport.DataSources.Add(rptData);


                Warning[] warnings;
                string[]  streamids;
                string    mimeType;
                string    encoding;
                string    filenameExtension;
                byte[]    bytes = rptViewer.LocalReport.Render(
                    "PDF", null, out mimeType, out encoding, out filenameExtension,
                    out streamids, out warnings);

                Response.Buffer = true;
                Response.Clear();
                Response.ContentType = mimeType;
                Response.AddHeader("content-disposition", "attachment; filename= LoadCalc-" + CurrentDate.ToString("yyyy-MM-dd_HHmmss") + "." + filenameExtension);
                Response.OutputStream.Write(bytes, 0, bytes.Length); // create the file
                Response.Flush();                                    // send it to the client to download
                Response.End();
                return(View());
            }
            catch (Exception ex)
            { return(RedirectToAction("Index", "KPT", new { msg = ex.GetMessage(), msgType = AlertMsgType.Danger })); }
        }