Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. OleDbConnection con;
  2.  
  3. private void dataGridView1_RowPostPaint_1(object sender, DataGridViewRowPostPaintEventArgs e)
  4. {
  5. this.dataGridView1.Rows[e.RowIndex].Cells["column1"].Value = (e.RowIndex + 1).ToString();
  6. }
  7.  
  8. private void btn_Browse_Click(object sender, EventArgs e)
  9. {
  10. //load file
  11. try
  12. {
  13. OpenFileDialog openfile1 = new OpenFileDialog();
  14. openfile1.Filter = "Excel Files|*.xls;*.xlsx";
  15. if (openfile1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  16. {
  17. this.txt_File.Text = openfile1.FileName;
  18. if (!string.IsNullOrEmpty(openfile1.FileName))
  19. {
  20. con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + openfile1.FileName + ";Extended Properties=Excel 12.0;");
  21. con.Open();
  22. DataTable dt = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
  23. con.Close();
  24.  
  25. Combo_Sheet.Items.Clear();
  26.  
  27. for (int i = 0; i < dt.Rows.Count; i++)
  28. {
  29. String sheetName = dt.Rows[i]["TABLE_NAME"].ToString();
  30. Combo_Sheet.Items.Add(sheetName);
  31. }
  32. }
  33. }
  34. }
  35. catch
  36. {
  37. }
  38. }
  39.  
  40. try
  41. {
  42. OleDbDataAdapter oda = new OleDbDataAdapter("Select * from [" + Combo_Sheet.Text + "]", con);
  43. DataTable dt = new DataTable();
  44. oda.Fill(dt);
  45. dataGridView1.DataSource = null;
  46. dataGridView1.DataSource = dt;
  47.  
  48. }
  49. catch
  50. {
  51. }
  52.  
  53. private void txt_Name_TextChanged(object sender, EventArgs e)
  54. {
  55. lb_Name.Text = txt_Name.Text.ToUpper();
  56. }
  57.  
  58. private void txt_Part_TextChanged(object sender, EventArgs e)
  59. {
  60. lb_Part.Text = txt_Part.Text.ToUpper();
  61. }
  62.  
  63. private void txt_Code_TextChanged(object sender, EventArgs e)
  64. {
  65. lb_Code.Text = txt_Code.Text.ToUpper();
  66. //generate barcode from textbox3
  67. //overwrite label 3 with code name
  68. lb_Code.Text = txt_Code.Text.ToUpper();
  69. string barCode = txt_Code.Text;
  70. try
  71. {
  72. Zen.Barcode.Code128BarcodeDraw brCode = Zen.Barcode.BarcodeDrawFactory.Code128WithChecksum;
  73. pictureBox1.Image = brCode.Draw(barCode, 40);
  74. }
  75. catch (Exception ex)
  76. {
  77. MessageBox.Show(ex.Message);
  78. }
  79. }
  80.  
  81. private void btn_Print_Click(object sender, EventArgs e)
  82. {
  83. //show print dialog and print
  84. PrintDialog printDlg = new PrintDialog();
  85. if (printDlg.ShowDialog() == DialogResult.OK) printDocument1.Print();
  86. //printDocument1.Print();
  87. }
  88.  
  89.  
  90. private void printDocument1_PrintPage_1(object sender, System.Drawing.Printing.PrintPageEventArgs e)
  91. {
  92. //setup printing area
  93. Bitmap bm = new Bitmap(3000, 3000);
  94. Graphics gm = Graphics.FromImage(bm);
  95. bm.SetResolution(300, 300);
  96. gm.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
  97. gm.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
  98.  
  99. panel1.DrawToBitmap(bm, new Rectangle(0, 0, 3000, 3000));
  100. e.Graphics.DrawImage(bm, new Rectangle(0, 10, 900, 700));
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement