Beispiel #1
0
    protected void QRCodeOlustur()
    {
        EFDal  ed      = new EFDal();
        string BaseUrl = ConfigurationManager.AppSettings["BaseUrl"].ToString();
        //Burada daha  önce bu IstId için bir kapak oluşturulmuş mu ona bakmak gerekli..
        string DahaOnceVerilmisDosyaAdi = ed.KapakSayfasiDosyaAdiniDon(Convert.ToInt32(Request["IstId"].ToString()));
        Guid   KapakDosyaAdi            = Guid.Empty;

        if (DahaOnceVerilmisDosyaAdi != string.Empty)
        {
            KapakDosyaAdi = Guid.Parse(DahaOnceVerilmisDosyaAdi.Replace(".pdf", ""));
        }
        else
        {
            KapakDosyaAdi = Guid.NewGuid();
        }

        Session["SertifikaDosyaAdi"] = KapakDosyaAdi;


        try
        {
            string qrCodeImageFile = Guid.NewGuid().ToString();
            //string qrCodeImagePath = Server.MapPath("~/DosyaSistemi/QRCode/" + qrCodeImageFile + ".png");
            RadBarcode barcode = new RadBarcode();
            //barcode.Text = "some text";

            barcode.Text = BaseUrl + "DosyaSistemi/" + ed.kal_BolgeKoduDon(Context.User.Identity.Name).ToString() + "/" +
                           DateTime.Now.Year.ToString() + "/" + KapakDosyaAdi.ToString() + ".pdf";
            barcode.Type         = BarcodeType.QRCode;
            Session["qrCodeURL"] = barcode.Text;
            barcode.LineWidth    = 2;
            RadBinaryImage         image  = new RadBinaryImage();
            System.IO.MemoryStream stream = new System.IO.MemoryStream();
// kaldırılabilir?->
            barcode.GetImage().Save(stream, System.Drawing.Imaging.ImageFormat.Png);
            image.DataValue = stream.ToArray();
            ed.InsertqrCodeImage(Convert.ToInt32(Request["IstId"].ToString()), image.DataValue);



            //System.Drawing.Image img = barcode.GetImage();

            //img.Save(qrCodeImagePath, System.Drawing.Imaging.ImageFormat.Png);

            //return qrCodeImagePath;
        }
        catch (Exception e)
        {
            //return string.Empty;
        }
    }
Beispiel #2
0
    protected void QRCodeOlustur()
    {
        RadBarcode barcode = new RadBarcode();

        //barcode.Text = "some text";
        barcode.Text      = "";
        barcode.Type      = BarcodeType.QRCode;
        barcode.LineWidth = 2;
        RadBinaryImage image = new RadBinaryImage();

        //PlaceHolder1.Controls.Add(image);
        System.IO.MemoryStream stream = new System.IO.MemoryStream();
        barcode.GetImage().Save(stream, System.Drawing.Imaging.ImageFormat.Png);
        image.DataValue = stream.ToArray();



        System.Drawing.Image img = barcode.GetImage();
        string qrCodeImageFile   = Guid.NewGuid().ToString();

        img.Save(Server.MapPath("~/DosyaSistemi/QRCode/" + qrCodeImageFile + ".png"), System.Drawing.Imaging.ImageFormat.Png);
        //FileStream file =new FileStream(Server.MapPath("~/DosyaSistemi/Oneri.docx"))
    }
Beispiel #3
0
    protected void QRCodeOlustur()
    {
        EFDal ed = new EFDal();
        string BaseUrl = ConfigurationManager.AppSettings["BaseUrl"].ToString();
        //Burada daha  önce bu IstId için bir kapak oluşturulmuş mu ona bakmak gerekli..
        string DahaOnceVerilmisDosyaAdi = ed.KapakSayfasiDosyaAdiniDon(Convert.ToInt32(Request["IstId"].ToString()));
        Guid KapakDosyaAdi = Guid.Empty;
        if (DahaOnceVerilmisDosyaAdi != string.Empty)
        {
            KapakDosyaAdi = Guid.Parse(DahaOnceVerilmisDosyaAdi.Replace(".pdf",""));
        }
        else
        {
            KapakDosyaAdi = Guid.NewGuid();
        }

        Session["SertifikaDosyaAdi"] = KapakDosyaAdi;

        try
        {
            string qrCodeImageFile = Guid.NewGuid().ToString();
            //string qrCodeImagePath = Server.MapPath("~/DosyaSistemi/QRCode/" + qrCodeImageFile + ".png");
            RadBarcode barcode = new RadBarcode();
            //barcode.Text = "some text";

            barcode.Text = BaseUrl + "DosyaSistemi/" + ed.kal_BolgeKoduDon(Context.User.Identity.Name).ToString() + "/" +
                           DateTime.Now.Year.ToString() + "/" + KapakDosyaAdi.ToString() + ".pdf";
            barcode.Type = BarcodeType.QRCode;
            Session["qrCodeURL"] = barcode.Text;
            barcode.LineWidth = 2;
            RadBinaryImage image = new RadBinaryImage();
            System.IO.MemoryStream stream = new System.IO.MemoryStream();
        // kaldırılabilir?->
            barcode.GetImage().Save(stream, System.Drawing.Imaging.ImageFormat.Png);
            image.DataValue = stream.ToArray();
            ed.InsertqrCodeImage(Convert.ToInt32(Request["IstId"].ToString()), image.DataValue);

            //System.Drawing.Image img = barcode.GetImage();

            //img.Save(qrCodeImagePath, System.Drawing.Imaging.ImageFormat.Png);

            //return qrCodeImagePath;
        }
        catch (Exception e)
        {
            //return string.Empty;
        }
    }
 private void QRS(List<DepotCode> list)
 {
     #region 图片参数
     var 图片宽度 = 600;
     var 图片高度 = 图片宽度 / 2;
     var 边框旁白 = 15;
     var 边框宽度 = 2;
     var 图标上边距 = 边框旁白 + 边框宽度 + 8;
     var 图标宽度 = 60;
     var 图标高度 = 40;
     var 图标左边距 = 边框旁白 + 边框宽度 + 33;
     var 标题字体 = "SimHei";
     var 标题字号 = 20;
     var 标题上边距 = 边框旁白 + 边框宽度 + 17;
     var 标题左边距 = 图标左边距 + 图标宽度 + 16;
     var 右侧宽度 = 200;
     var 左侧宽度 = 图片宽度 - 2 * (边框旁白 + 边框宽度) - 右侧宽度;
     var 二维码边长 = 右侧宽度;
     #if xsfx
     var 二维码上边距 = 边框旁白 + 边框宽度 + 图标高度 + 7 + 20;
     #else
     var 二维码上边距 = 边框旁白 + 边框宽度 + 图标高度 + 7;
     #endif
     var 二维码左边距 = 图片宽度 - (边框旁白 + 边框宽度) - 右侧宽度;
     var 二维码文字字体 = "Arial";
     var 二维码文字字号 = 15;
     var 二维码文字上边距 = 二维码上边距 + 二维码边长 - 15;
     var 二维码文字左边距 = 图片宽度 - (边框旁白 + 边框宽度) - 右侧宽度 + 21;
     var 左侧左边距 = 边框旁白 + 边框宽度 + 12;
     #if xsfx
     var 左侧上边距 = 边框旁白 + 边框宽度 + 图标高度 + 27-10;
     #else
     var 左侧上边距 = 边框旁白 + 边框宽度 + 图标高度 + 27;
     #endif
     var 内容字体 = "SimHei";
     var 内容字号 = 18;
     #if xsfx
     var 内容每行字数 = 17;
     #else
     var 内容每行字数 = 15;
     #endif
     var 内容空字符数 = 5;
     var W = new SolidBrush(Color.White);
     var B = new SolidBrush(Color.Black);
     var BasePath = ConfigurationManager.AppSettings["CodePath"];
     var Logo = ConfigurationManager.AppSettings["CodeLogo"];
     var Title = ConfigurationManager.AppSettings["CodeTitle"];
     #endregion
     foreach (var group in list.GroupBy(o => o.BatchId))
     {
         var fold_id = group.Key;
         var path = string.Format("{0}\\临时\\{1}", BasePath, fold_id);
         if (!Directory.Exists(path))
             Directory.CreateDirectory(path);
         var codes = group.SelectMany(o => o.CodeJson.FromJson<List<string>>()).ToList();
         foreach (var qrcode in codes)
         {
             SysImage icon = Bitmap.FromFile(Logo);
             Bitmap image = new Bitmap(图片宽度, 图片高度);
             Graphics g = Graphics.FromImage(image);
             g.FillRectangle(W, 0, 0, 图片宽度, 图片高度);
             g.DrawRectangle(new Pen(B, 边框宽度), 边框旁白, 边框旁白, 图片宽度 - 2 * 边框旁白, 图片高度 - 2 * 边框旁白);
             g.DrawImage(icon, 图标左边距, 图标上边距, 图标宽度, 图标高度);
     #if xsfx
             string title = "{0}".Formatted(Title);
             g.DrawString(title, new Font(标题字体, 标题字号), B, 标题左边距, 标题上边距);
             g.Save();
             RadBarcode code = new RadBarcode { Type = BarcodeType.QRCode, Text = qrcode, OutputType = BarcodeOutputType.EmbeddedPNG };
             code.QRCodeSettings.Mode = Telerik.Web.UI.Barcode.Modes.CodeMode.Alphanumeric;
             code.QRCodeSettings.ErrorCorrectionLevel = Telerik.Web.UI.Barcode.Modes.ErrorCorrectionLevel.M;
             code.QRCodeSettings.ECI = Telerik.Web.UI.Barcode.Modes.ECIMode.None;
             code.QRCodeSettings.AutoIncreaseVersion = true;
             code.QRCodeSettings.Version = 0;
             code.QRCodeSettings.DotSize = 5;
             SysImage qr = code.GetImage();
             g.DrawImage(qr, 二维码左边距, 二维码上边距, 二维码边长, 二维码边长);
             var content = "";
             var sb = new StringBuilder();
             var info = string.Empty;
             try
             {
                 var con = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["Entities"].ConnectionString);
                 var com = new System.Data.SqlClient.SqlCommand("EXEC [dbo].[GetQRInfo] @QR = N'{0}'".Formatted(qrcode), con);
                 con.Open();
                 var reader = com.ExecuteReader();
                 if (reader.Read())
                 {
                     info = reader.GetString(0);
                 }
                 try
                 {
                     reader.Close();
                 }
                 catch
                 {
                 }
                 try
                 {
                     con.Close();
                 }
                 catch
                 {
                 }
             }
             catch
             {
                 continue;
             }
             var infos = info.Split(new string[] { "@@@" }, StringSplitOptions.None);
             content = "       固定资产{0}".Formatted(list[0].XsfxName.Substring(list[0].XsfxName.IndexOf('(')));
             Cut(sb, content, 内容每行字数, 内容空字符数);
             content = " ";
             Cut(sb, content, 内容每行字数, 内容空字符数);
             content = "类别:{0}".Formatted(infos[5].Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0]);
             Cut(sb, content, 内容每行字数, 内容空字符数);
             content = "名称:{0}".Formatted(infos[0]);
             Cut(sb, content, 内容每行字数, 内容空字符数);
             if (infos[3] == "1")
             {
                 //content = "资产编号:{0}".Formatted(infos[4].Length > 7 ? infos[4].Substring(infos[4].Length - 7) : infos[4]);
                 //Cut(sb, content, 内容每行字数, 内容空字符数);
                 var time = infos[7].None() ? "" : DateTime.Parse(infos[7]).ToString("yyyy-MM-dd");
                 content = "购置日期:{0}".Formatted(time);
                 Cut(sb, content, 内容每行字数, 内容空字符数);
             }
             content = "条码:{0}".Formatted(qrcode);
             Cut(sb, content, 内容每行字数, 内容空字符数);
             g.DrawString(sb.ToString(), new Font(内容字体, 内容字号), B, 左侧左边距, 左侧上边距);
     #elif hb
             string title = "{0} 资产标签".Formatted(Title);
             g.DrawString(title, new Font(标题字体, 标题字号), B, 标题左边距, 标题上边距);
             g.Save();
             RadBarcode code = new RadBarcode { Type = BarcodeType.QRCode, Text = qrcode, OutputType = BarcodeOutputType.EmbeddedPNG };
             code.QRCodeSettings.Mode = Telerik.Web.UI.Barcode.Modes.CodeMode.Alphanumeric;
             code.QRCodeSettings.ErrorCorrectionLevel = Telerik.Web.UI.Barcode.Modes.ErrorCorrectionLevel.M;
             code.QRCodeSettings.ECI = Telerik.Web.UI.Barcode.Modes.ECIMode.None;
             code.QRCodeSettings.AutoIncreaseVersion = true;
             code.QRCodeSettings.Version = 0;
             code.QRCodeSettings.DotSize = 5;
             SysImage qr = code.GetImage();
             g.DrawImage(qr, 二维码左边距, 二维码上边距, 二维码边长, 二维码边长);
             g.DrawString(qrcode, new Font(二维码文字字体, 二维码文字字号), B, 二维码文字左边距, 二维码文字上边距);
             var content = "";
             var sb = new StringBuilder();
             var info = string.Empty;
             try
             {
                 var con = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["Entities"].ConnectionString);
                 var com = new System.Data.SqlClient.SqlCommand("EXEC [dbo].[GetQRInfo] @QR = N'{0}'".Formatted(qrcode), con);
                 con.Open();
                 var reader = com.ExecuteReader();
                 if (reader.Read())
                 {
                     info = reader.GetString(0);
                 }
                 try
                 {
                     reader.Close();
                 }
                 catch
                 {
                 }
                 try
                 {
                     con.Close();
                 }
                 catch
                 {
                 }
             }
             catch
             {
                 continue;
             }
             var infos = info.Split(new string[] { "@@@" }, StringSplitOptions.None);
             content = "资产名称:{0}".Formatted(infos[0]);
             Cut(sb, content, 内容每行字数, 内容空字符数);
             content = "规格型号:{0}{1}{2}".Formatted(infos[1], infos[1].None() ? "" : " ", infos[2]);
             Cut(sb, content, 内容每行字数, 内容空字符数);
             content = "资产编号:{0}".Formatted(infos[4].Length > 7 ? infos[4].Substring(infos[4].Length - 7) : infos[4]);
             Cut(sb, content, 内容每行字数, 内容空字符数);
             content = "保管部门:{0}".Formatted(infos[8].None() ? "" : infos[8]);
             Cut(sb, content, 内容每行字数, 内容空字符数);
             content = "存放地:{0}".Formatted(infos[9].None() ? "" : infos[9]);
             Cut(sb, content, 内容每行字数, 内容空字符数);
             g.DrawString(sb.ToString(), new Font(内容字体, 内容字号), B, 左侧左边距, 左侧上边距);
     #elif yz
             string title = "{0} 资产标签".Formatted(Title);
             g.DrawString(title, new Font(标题字体, 标题字号), B, 标题左边距, 标题上边距);
             g.Save();
             RadBarcode code = new RadBarcode { Type = BarcodeType.QRCode, Text = qrcode, OutputType = BarcodeOutputType.EmbeddedPNG };
             code.QRCodeSettings.Mode = Telerik.Web.UI.Barcode.Modes.CodeMode.Alphanumeric;
             code.QRCodeSettings.ErrorCorrectionLevel = Telerik.Web.UI.Barcode.Modes.ErrorCorrectionLevel.M;
             code.QRCodeSettings.ECI = Telerik.Web.UI.Barcode.Modes.ECIMode.None;
             code.QRCodeSettings.AutoIncreaseVersion = true;
             code.QRCodeSettings.Version = 0;
             code.QRCodeSettings.DotSize = 5;
             SysImage qr = code.GetImage();
             g.DrawImage(qr, 二维码左边距, 二维码上边距, 二维码边长, 二维码边长);
             g.DrawString(qrcode, new Font(二维码文字字体, 二维码文字字号), B, 二维码文字左边距, 二维码文字上边距);
             var content = "";
             var sb = new StringBuilder();
             var info = string.Empty;
             try
             {
                 var con = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["Entities"].ConnectionString);
                 var com = new System.Data.SqlClient.SqlCommand("EXEC [dbo].[GetQRInfo] @QR = N'{0}'".Formatted(qrcode), con);
                 con.Open();
                 var reader = com.ExecuteReader();
                 if (reader.Read())
                 {
                     info = reader.GetString(0);
                 }
                 try
                 {
                     reader.Close();
                 }
                 catch
                 {
                 }
                 try
                 {
                     con.Close();
                 }
                 catch
                 {
                 }
             }
             catch
             {
                 continue;
             }
             var infos = info.Split(new string[] { "@@@" }, StringSplitOptions.None);
             content = "资产名称:{0}".Formatted(infos[0]);
             Cut(sb, content, 内容每行字数, 内容空字符数);
             content = "规格型号:{0}{1}{2}".Formatted(infos[1], infos[1].None() ? "" : " ", infos[2]);
             Cut(sb, content, 内容每行字数, 内容空字符数);
             content = "资产编号:{0}".Formatted(infos[4].Length > 7 ? infos[4].Substring(infos[4].Length - 7) : infos[4]);
             Cut(sb, content, 内容每行字数, 内容空字符数);
             content = "保管部门:{0}".Formatted(infos[8].None() ? "" : infos[8]);
             Cut(sb, content, 内容每行字数, 内容空字符数);
             content = "存放地:{0}".Formatted(infos[9].None() ? "" : infos[9]);
             Cut(sb, content, 内容每行字数, 内容空字符数);
             g.DrawString(sb.ToString(), new Font(内容字体, 内容字号), B, 左侧左边距, 左侧上边距);
     #else
             string title = "{0} 资产标签".Formatted(Title);
             g.DrawString(title, new Font(标题字体, 标题字号), B, 标题左边距, 标题上边距);
             g.Save();
             RadBarcode code = new RadBarcode { Type = BarcodeType.QRCode, Text = qrcode, OutputType = BarcodeOutputType.EmbeddedPNG };
             code.QRCodeSettings.Mode = Telerik.Web.UI.Barcode.Modes.CodeMode.Alphanumeric;
             code.QRCodeSettings.ErrorCorrectionLevel = Telerik.Web.UI.Barcode.Modes.ErrorCorrectionLevel.M;
             code.QRCodeSettings.ECI = Telerik.Web.UI.Barcode.Modes.ECIMode.None;
             code.QRCodeSettings.AutoIncreaseVersion = true;
             code.QRCodeSettings.Version = 0;
             code.QRCodeSettings.DotSize = 5;
             SysImage qr = code.GetImage();
             g.DrawImage(qr, 二维码左边距, 二维码上边距, 二维码边长, 二维码边长);
             g.DrawString(qrcode, new Font(二维码文字字体, 二维码文字字号), B, 二维码文字左边距, 二维码文字上边距);
             var content = "";
             var sb = new StringBuilder();
             var info = string.Empty;
             try
             {
                 var con = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["Entities"].ConnectionString);
                 var com = new System.Data.SqlClient.SqlCommand("EXEC [dbo].[GetQRInfo] @QR = N'{0}'".Formatted(qrcode), con);
                 con.Open();
                 var reader = com.ExecuteReader();
                 if (reader.Read())
                 {
                     info = reader.GetString(0);
                 }
                 try
                 {
                     reader.Close();
                 }
                 catch
                 {
                 }
                 try
                 {
                     con.Close();
                 }
                 catch
                 {
                 }
             }
             catch
             {
                 continue;
             }
             var infos = info.Split(new string[] { "@@@" }, StringSplitOptions.None);
             content = "资产名称:{0}".Formatted(infos[0]);
             Cut(sb, content, 内容每行字数, 内容空字符数);
             content = "规格型号:{0}{1}{2}".Formatted(infos[1], infos[1].None() ? "" : " ", infos[2]);
             Cut(sb, content, 内容每行字数, 内容空字符数);
             if (infos[3] == "1")
             {
                 content = "资产编号:{0}".Formatted(infos[4].Length > 7 ? infos[4].Substring(infos[4].Length - 7) : infos[4]);
                 Cut(sb, content, 内容每行字数, 内容空字符数);
                 var time = infos[7].None() ? "" : DateTime.Parse(infos[7]).ToString("yyyy-MM-dd");
                 content = "购置日期:{0}".Formatted(time);
                 Cut(sb, content, 内容每行字数, 内容空字符数);
             }
             content = "物资分类:{0}".Formatted(infos[5]);
             Cut(sb, content, 内容每行字数, 内容空字符数);
             g.DrawString(sb.ToString(), new Font(内容字体, 内容字号), B, 左侧左边距, 左侧上边距);
     #endif
             image.Save("{0}/{1}.png".Formatted(path, qrcode), ImageFormat.Png);
             g.Dispose();
             image.Dispose();
         }
     (new FastZip()).CreateZip(string.Format("{0}\\打包\\{1}.zip".Formatted(BasePath, fold_id)), string.Format("{0}\\临时\\{1}", BasePath, fold_id), false, ".png");
     }
 }
Beispiel #5
0
    protected void QRCodeOlustur()
    {
        RadBarcode barcode = new RadBarcode();
        //barcode.Text = "some text";
        barcode.Text = "";
        barcode.Type = BarcodeType.QRCode;
        barcode.LineWidth = 2;
        RadBinaryImage image = new RadBinaryImage();
        //PlaceHolder1.Controls.Add(image);
        System.IO.MemoryStream stream = new System.IO.MemoryStream();
        barcode.GetImage().Save(stream, System.Drawing.Imaging.ImageFormat.Png);
        image.DataValue = stream.ToArray();

        System.Drawing.Image img=barcode.GetImage();
        string qrCodeImageFile = Guid.NewGuid().ToString();
        img.Save(Server.MapPath("~/DosyaSistemi/QRCode/"+qrCodeImageFile+".png"), System.Drawing.Imaging.ImageFormat.Png);
        //FileStream file =new FileStream(Server.MapPath("~/DosyaSistemi/Oneri.docx"))
    }