Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- OleDbConnection con;
- private void dataGridView1_RowPostPaint_1(object sender, DataGridViewRowPostPaintEventArgs e)
- {
- this.dataGridView1.Rows[e.RowIndex].Cells["column1"].Value = (e.RowIndex + 1).ToString();
- }
- private void btn_Browse_Click(object sender, EventArgs e)
- {
- //load file
- try
- {
- OpenFileDialog openfile1 = new OpenFileDialog();
- openfile1.Filter = "Excel Files|*.xls;*.xlsx";
- if (openfile1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- this.txt_File.Text = openfile1.FileName;
- if (!string.IsNullOrEmpty(openfile1.FileName))
- {
- con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + openfile1.FileName + ";Extended Properties=Excel 12.0;");
- con.Open();
- DataTable dt = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
- con.Close();
- Combo_Sheet.Items.Clear();
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- String sheetName = dt.Rows[i]["TABLE_NAME"].ToString();
- Combo_Sheet.Items.Add(sheetName);
- }
- }
- }
- }
- catch
- {
- }
- }
- try
- {
- OleDbDataAdapter oda = new OleDbDataAdapter("Select * from [" + Combo_Sheet.Text + "]", con);
- DataTable dt = new DataTable();
- oda.Fill(dt);
- dataGridView1.DataSource = null;
- dataGridView1.DataSource = dt;
- }
- catch
- {
- }
- private void txt_Name_TextChanged(object sender, EventArgs e)
- {
- lb_Name.Text = txt_Name.Text.ToUpper();
- }
- private void txt_Part_TextChanged(object sender, EventArgs e)
- {
- lb_Part.Text = txt_Part.Text.ToUpper();
- }
- private void txt_Code_TextChanged(object sender, EventArgs e)
- {
- lb_Code.Text = txt_Code.Text.ToUpper();
- //generate barcode from textbox3
- //overwrite label 3 with code name
- lb_Code.Text = txt_Code.Text.ToUpper();
- string barCode = txt_Code.Text;
- try
- {
- Zen.Barcode.Code128BarcodeDraw brCode = Zen.Barcode.BarcodeDrawFactory.Code128WithChecksum;
- pictureBox1.Image = brCode.Draw(barCode, 40);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- private void btn_Print_Click(object sender, EventArgs e)
- {
- //show print dialog and print
- PrintDialog printDlg = new PrintDialog();
- if (printDlg.ShowDialog() == DialogResult.OK) printDocument1.Print();
- //printDocument1.Print();
- }
- private void printDocument1_PrintPage_1(object sender, System.Drawing.Printing.PrintPageEventArgs e)
- {
- //setup printing area
- Bitmap bm = new Bitmap(3000, 3000);
- Graphics gm = Graphics.FromImage(bm);
- bm.SetResolution(300, 300);
- gm.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
- gm.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
- panel1.DrawToBitmap(bm, new Rectangle(0, 0, 3000, 3000));
- e.Graphics.DrawImage(bm, new Rectangle(0, 10, 900, 700));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement