Code Project2 1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

C:\Users\shiva\OneDrive\Documents\Visual ... Generator\WindowsFormsApplication1\Form2.

cs 1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Net;
using System.IO;

namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
BarcodeLib.Barcode b = new BarcodeLib.Barcode();
string barcodeImage;
string dt = "";
string imageSavePath = Application.StartupPath + "/bar/";

SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-SHIVA\SQLEXPRESS;Initial


Catalog=shivam1;Integrated Security=True");
SqlCommand cmd = new SqlCommand();
string str;

public Form2()
{
InitializeComponent();
}

private void Form2_Load(object sender, EventArgs e)


{

void clear()
{
textBoxDesc.Text = textBox1.Text = textBox2.Text = textBoxPname.Text = "";

private void buttonSave_Click(object sender, EventArgs e)


{
dt = textBoxPname.Text.ToUpper();
barcodeImage = dt + ".png";

createBarCode();

byte[] mydata;
FileInfo finfo = new FileInfo(imageSavePath+barcodeImage);
long numbyte = finfo.Length;
FileStream fstream = new FileStream(imageSavePath+barcodeImage, FileMode.Open,
FileAccess.Read);
BinaryReader breader = new BinaryReader(fstream);
mydata = breader.ReadBytes(Convert.ToInt32(numbyte));
str="insert into product(name,price,manufacturer,description,img) values ('"+
textBoxPname.Text+"','"+textBox1.Text+"','"+textBox2.Text+"','"+textBoxDesc.Text+"',@img)
";

con.Open();
cmd.Connection = con;
cmd.CommandText = str;
cmd.Parameters.Add(new SqlParameter("@img", (object)mydata));
cmd.ExecuteNonQuery();
con.Close();
C:\Users\shiva\OneDrive\Documents\Visual ... Generator\WindowsFormsApplication1\Form2.cs 2
clear();
label2.Visible = true;

public void createBarCode()


{
Bitmap temp = new Bitmap(1, 1);
temp.SetPixel(0, 0, this.BackColor);
pictureBox1.Image = (Image)temp;

int w = Convert.ToInt32(300);
int h = Convert.ToInt32(50);

BarcodeLib.TYPE type = BarcodeLib.TYPE.UNSPECIFIED;


type = BarcodeLib.TYPE.CODE39;

if (type != BarcodeLib.TYPE.UNSPECIFIED)
{
b.IncludeLabel = true;
pictureBox1.Image = b.Encode(type, dt.Trim(), this.b.ForeColor, this.b.
BackColor, w, h);

pictureBox1.Width = pictureBox1.Image.Width;
pictureBox1.Height = pictureBox1.Image.Height;

pictureBox1.Image.Save(imageSavePath + barcodeImage);

}
}

You might also like