コード例 #1
0
        public ActionResult Create(BarcodeGenerateModel model)
        {
            var Data = obj.SaveBarcodeGen(model);

            TempData["Error"] = Data;
            GenerateReport(model);
            return(RedirectToAction("Index"));
        }
コード例 #2
0
        public List <BarcodeGenerateModel> ShowAllBarcodeGenList()
        {
            List <BarcodeGenerateModel> List = new List <BarcodeGenerateModel>();
            var data = _entities.tblGenBarcodes.ToList();

            foreach (var item in data)
            {
                BarcodeGenerateModel model = new BarcodeGenerateModel();
                model.RawMaterialsId  = item.RawMaterialId;
                model.Name            = item.tbl_RawMaterials.Name;
                model.RawCategoryId   = item.tbl_RawMaterials.rawcategoryId;
                model.RawCategoryName = item.tbl_RawMaterials.RawCategory.Name;
                model.NoOfBarcode     = item.NoOfBarcode;
                model.Id = item.Id;
                List.Add(model);
            }
            return(List);
        }
コード例 #3
0
        public string SaveBarcodeGen(BarcodeGenerateModel model)
        {
            tblGenBarcode tb = new tblGenBarcode();

            try
            {
                tb.CreateDateTime = DateTime.Now;
                tb.UserId         = WebSecurity.CurrentUserId;
                tb.RawMaterialId  = model.RawMaterialsId;
                tb.NoOfBarcode    = model.NoOfBarcode;
                _entities.tblGenBarcodes.Add(tb);
                _entities.SaveChanges();
                return("Record Saved Successfully...");
            }
            catch
            {
                return("something Wrong try Agian !");
            }
        }
コード例 #4
0
        protected void GenerateReport(BarcodeGenerateModel model)
        {
            var img = (from p in db.tbl_RawMaterials  where p.RawMaterialId == model.RawMaterialsId select p).SingleOrDefault();

            string imgPath = Server.MapPath("~/barcodes/" + img.barcode + ".png");

            Font   Font15          = FontFactory.GetFont("Verdana", 12, Font.BOLDITALIC);
            string str_pdffilename = "barcode.pdf";
            string str_pdfpath     = Server.MapPath("~/barcodes/") + str_pdffilename;

            Document  doc    = new Document(PageSize.A4, 50, 50, 55, 25);
            PdfWriter writer = PdfWriter.GetInstance(doc, Response.OutputStream);

            doc.Open();

            PdfPTable table = new iTextSharp.text.pdf.PdfPTable(4);

            table.WidthPercentage = 100;
            float[] intwidth = new float[4] {
                1, 1, 1, 1
            };
            table.SetWidths(intwidth);
            table.DefaultCell.BorderColor = new BaseColor(0, 0, 0, 0);
            table.DefaultCell.BorderWidth = 1;
            table.SpacingAfter            = 1;
            table.HorizontalAlignment     = Element.ALIGN_CENTER;

            PdfPCell cellPdf1 = new PdfPCell();

            cellPdf1                   = new PdfPCell(new Phrase(img.Name, Font15));
            cellPdf1.Border            = 0;
            cellPdf1.Colspan           = 4;
            cellPdf1.BorderWidthBottom = 1F;
            cellPdf1.BorderWidthLeft   = 0;
            cellPdf1.BorderWidthRight  = 0;
            cellPdf1.BorderWidthTop    = 0;
            cellPdf1.SetLeading(.5F, .5F);
            cellPdf1.BorderWidthBottom   = 0;
            cellPdf1.HorizontalAlignment = Element.ALIGN_MIDDLE;
            cellPdf1.VerticalAlignment   = Element.ALIGN_MIDDLE;
            table.AddCell(cellPdf1);

            for (int i = 0; i < model.NoOfBarcode; i++)
            {
                Image    png     = Image.GetInstance(imgPath);
                PdfPCell cellPdf = new PdfPCell((Image.GetInstance(png)));
                png.ScaleToFit(1F, 2F);
                png.SpacingBefore      = 0F;
                png.Alignment          = Element.ALIGN_MIDDLE;
                cellPdf.Border         = 0;
                cellPdf.Colspan        = 0;
                cellPdf.Rowspan        = 1;
                cellPdf.BorderWidthTop = 0;
                cellPdf.SetLeading(0F, 0F);
                cellPdf.BorderWidthBottom   = 0;
                cellPdf.HorizontalAlignment = Element.ALIGN_MIDDLE;
                cellPdf.VerticalAlignment   = Element.ALIGN_MIDDLE;
                table.AddCell(cellPdf);
            }



            doc.Add(table);

            writer.CloseStream = false;
            doc.Close();
            Response.Buffer      = true;
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=" + img.Name + " - Barcode.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Write(doc);
            Response.End();
            string script = string.Format(@"showDialogfile('{0}')", str_pdffilename);
            //ScriptManager.RegisterClientScriptBlock(this, typeof(Page), UniqueID, script, true);
        }