예제 #1
0
파일: RevitQR.cs 프로젝트: Revitspace/revit
        public void ImageTag(Document doc, SheetInfo info, ViewPortInfo vport)
        {
            // Create a new QRCoder Tag
            QRCoder.QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator();

            // Generate a new QR Tag
            QRCoder.QRCodeGenerator.QRCode qrCode = qrGenerator.CreateQrCode(data, QRCoder.QRCodeGenerator.ECCLevel.M);

            // Assemble a temp file name
            string tempfile = System.IO.Path.GetTempFileName() + ".QRTAG";

            // Get the Tags graphics element
            System.Drawing.Bitmap bmp = qrCode.GetGraphic(5);

            // Save it temporarily
            bmp.Save(tempfile);

            // Get the related view sheet
            View sheet = (View)doc.GetElement(info.sheetId);

            // Create a image element to return from import
            Element imageElement = null;

            // Get the Viewports label outline
            Outline labelOutline = vport.vport.GetLabelOutline();

            // Get the lower left corner
            XYZ labelCorner = new XYZ(info.sheet.Origin.X + (labelOutline.MinimumPoint.X), info.sheet.Origin.Y + labelOutline.MinimumPoint.Y, 0);

            // Add some distance value
            XYZ location = labelCorner.Add(new XYZ(0, -0.5 / 12.0, 0));

            // Import the image
            doc.Import(tempfile, new ImageImportOptions()
            {
                RefPoint = location, Placement = BoxPlacement.TopLeft
            }, sheet, out imageElement);

            // Delete temp file
            if (System.IO.File.Exists(tempfile))
            {
                System.IO.File.Delete(tempfile);
            }
        }
예제 #2
0
        protected void btngenerate_Click(object sender, EventArgs e)
        {
            string code = txtcode.Text;

            QRCoder.QRCodeGenerator        qrgen  = new QRCoder.QRCodeGenerator();
            QRCoder.QRCodeGenerator.QRCode qrcode = qrgen.CreateQrCode(code, QRCoder.QRCodeGenerator.ECCLevel.Q);

            System.Web.UI.WebControls.Image imgqrcode = new System.Web.UI.WebControls.Image();
            imgqrcode.Height = 150;
            imgqrcode.Width  = 150;

            using (Bitmap bitmap = qrcode.GetGraphic(20))
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    byte[] byteimage = ms.ToArray();
                    imgqrcode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteimage);
                }
                Phqrcode.Controls.Add(imgqrcode);
            }
        }
예제 #3
0
        private void excelFileGetButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter           = "Excel 2003 (*.xls)|*.xls|Excel 2007 (*.xlsx)|*.xlsx";
            dialog.InitialDirectory = @"d:\";
            dialog.Title            = "Please select an image file to encrypt.";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string    path = dialog.FileName;
                DataTable dt   = reader.ExcelFile(path, "Sheet1");
                accounts = dt.AsEnumerable().Select(dataRow => new Account()
                {
                    Bank      = dataRow[0].ToString(),
                    ReqId     = dataRow[1].ToString(),
                    AccountNo = dataRow[2].ToString(),
                    Name      = dataRow[3].ToString(),
                    Qty       = Convert.ToInt32(dataRow[4]),
                    Branch    = (dataRow[5].ToString()),
                    Currency  = dataRow[6].ToString(),

                    StartStNo = (dataRow[7].ToString()),
                    EndStNo   = (dataRow[8].ToString()),
                    Routing   = dataRow[9].ToString(),
                    MICRAc    = dataRow[10].ToString(),

                    Type = dataRow[11].ToString(),
                }).ToList();
                //accounts.Insert(0, new Account() { ReqId = dt.Columns[0].ColumnName, AccountNo = dt.Columns[1].ColumnName, Name = dt.Columns[2].ColumnName, Qty = Convert.ToInt32(dt.Columns[3].ColumnName), StartStNo = (dt.Columns[4].ColumnName), EndStNo = (dt.Columns[5].ColumnName), Routing = dt.Columns[6].ColumnName, Type = dt.Columns[7].ColumnName, Branch = dt.Columns[8].ColumnName });
                foreach (Account account in accounts)
                {
                    string s = "";
                    string a = "";

                    int serialNo = Convert.ToInt32(account.StartStNo);
                    for (int i = 0; i < account.Qty; i++)
                    {
                        if (serialNo.ToString().Count() < 7)
                        {
                            a = "0" + serialNo;
                        }
                        s  = null;
                        s += account.Name + " " + account.AccountNo + " " + account.Routing + " " + a + " " +
                             account.Branch;
                        QRCoder.QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator();
                        //QRCoder.QRCodeGenerator.QRCode qrCode = qrGenerator.CreateQrCode(s, QRCodeGenerator.ECCLevel.l);
                        QRCoder.QRCodeGenerator.QRCode qrCode = qrGenerator.CreateQrCode(s,
                                                                                         QRCoder.QRCodeGenerator.ECCLevel.H);
                        Bitmap imgOutput = qrCode.GetGraphic(1);
                        newAccounts.Add(new Account()
                        {
                            Bank = account.Bank, AccountNo = account.AccountNo, ReqId = account.ReqId, MICRAc = account.MICRAc, Currency = account.Currency, Branch = account.Branch, EndStNo = account.EndStNo, Name = account.Name, Qty = 1, Routing = account.Routing, Type = account.Type, StartStNo = a, Image = imgOutput
                        });
                        //imgOutput = ResizeImage(imgOutput, imgOutput.Width, imgOutput.Height);
                        ////Bitmap imgOutput = new Bitmap(@"D:\image.jpg");
                        //Graphics outputGraphics = Graphics.FromImage(imgOutput);

                        //EncoderParameters myEncoderParameters = new EncoderParameters(3);
                        //myEncoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L);
                        //myEncoderParameters.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.ScanMethod, (int)EncoderValue.ScanMethodInterlaced);
                        //myEncoderParameters.Param[2] = new EncoderParameter(System.Drawing.Imaging.Encoder.RenderMethod, (int)EncoderValue.RenderProgressive);

                        //ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
                        //ImageCodecInfo ici = null;
                        //foreach (ImageCodecInfo codec in codecs)
                        //{
                        //    if (codec.MimeType == "image/jpeg")
                        //        ici = codec;
                        //}

                        //imgOutput.Save(@"D:\Image\" + a +".jpg", ici, myEncoderParameters);


                        //imgOutput.Save(@"D:\Image\" + a + ".jpg", ImageFormat.Jpeg);
                        serialNo++;
                    }
                }
                CreateExcel(newAccounts);
                dataGridView1.DataSource = newAccounts;
                MessageBox.Show("Successfully Done", "Message", MessageBoxButtons.OK);
                // spreadsheet.ImportFromList(newAccounts);
            }
        }