private void button1_Click(object sender, EventArgs e) { button1.Enabled = false; try { if (textBox1.Text.Length == 0) { //get images from scanner List <System.Drawing.Image> images = WIAScanner.Scan((string)comboBox1.SelectedItem, resolution, type); foreach (System.Drawing.Image image in images) { pictureBox1.Image = image; //save scanned image into specific folder saveImage(image, textBox3.Text + "\\" + DateTime.Now.ToString("yyyy-MM-dd HHmmss")); textBox1.Text = DateTime.Now.ToString("yyyy-MM-dd HHmmss"); } } else { //If Document Name not Empty if (radioButton1.Checked) { //For Unlimited Option //For MultiScan int temp = 0; int count = 0; String overHead = ""; if (Directory.Exists(textBox3.Text + "\\" + textBox1.Text)) { while (Directory.Exists(textBox3.Text + "\\" + textBox1.Text + " (" + count + ")")) { count++; } Directory.CreateDirectory(textBox3.Text + "\\" + textBox1.Text + " (" + count + ")"); overHead = " (" + count + ")"; } else { Directory.CreateDirectory(textBox3.Text + "\\" + textBox1.Text); } String directorySavePath = textBox3.Text + "\\" + textBox1.Text + overHead + "\\"; while (true) { ConfirmingDialogBox cdb = new ConfirmingDialogBox(); cdb.currentpage = temp + 1; cdb.maxpage = 0; cdb.ShowDialog(); if (cdb.status == 1) { try { List <System.Drawing.Image> images = WIAScanner.Scan((string)comboBox1.SelectedItem, resolution, type); foreach (System.Drawing.Image image in images) { rotate(image); pictureBox1.Image = image; //save scanned image into specific folder saveImage(image, directorySavePath + temp); temp++; } } catch (Exception e1) { DialogResult dr = MessageBox.Show("Unfortunately, the software has encountered the following Error : " + e1.Message, "SCANNING ERROR", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error); if (dr == DialogResult.Ignore) { temp++; } else if (dr == DialogResult.Abort) { break; } } } else { break; } } } else if (int.Parse(textBox2.Text) > 0) { int n = int.Parse(textBox2.Text); if (n == 1) { List <System.Drawing.Image> images = WIAScanner.Scan((string)comboBox1.SelectedItem, resolution, type); foreach (System.Drawing.Image image in images) { pictureBox1.Image = image; //save scanned image into specific folder if (File.Exists(textBox3.Text + "\\" + textBox1.Text + ".jpeg")) { int temp = 0; while (File.Exists(textBox3.Text + "\\" + textBox1.Text + " (" + temp + ").jpeg")) { temp++; } saveImage(image, textBox3.Text + "\\" + textBox1.Text + "(" + temp + ")"); } else { saveImage(image, textBox3.Text + "\\" + textBox1.Text + DateTime.Now.ToString("yyyy-MM-dd HHmmss")); } } } else { //For MultiScan int temp = 0; int count = 0; String overHead = ""; if (Directory.Exists(textBox3.Text + "\\" + textBox1.Text)) { while (Directory.Exists(textBox3.Text + "\\" + textBox1.Text + " (" + count + ")")) { count++; } Directory.CreateDirectory(textBox3.Text + "\\" + textBox1.Text + " (" + count + ")"); overHead = " (" + count + ")"; } else { Directory.CreateDirectory(textBox3.Text + "\\" + textBox1.Text); } String directorySavePath = textBox3.Text + "\\" + textBox1.Text + overHead + "\\"; for (int i = 0; i < int.Parse(textBox2.Text); i++) { ConfirmingDialogBox cdb = new ConfirmingDialogBox(); cdb.maxpage = int.Parse(textBox2.Text); cdb.currentpage = i + 1; cdb.ShowDialog(); if (cdb.status == 1) { List <System.Drawing.Image> images = WIAScanner.Scan((string)comboBox1.SelectedItem, resolution, type); foreach (System.Drawing.Image image in images) { rotate(image); pictureBox1.Image = image; //save scanned image into specific folder saveImage(image, directorySavePath + temp); temp++; } } else { break; } } } } else { MessageBox.Show("Please enter the number of pages you wish to scan in the dedicated Textbox.", "PARAMETER MISSING", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception exc) { MessageBox.Show(exc.Message); } pdfIfRequired(); button1.Enabled = true; }
private void button1_Click(object sender, EventArgs e) { button1.Enabled = false; try { if (textBox1.Text.Length == 0) { //get images from scanner List <Image> images = WIAScanner.Scan((string)comboBox1.SelectedItem); foreach (Image image in images) { pictureBox1.Image = image; //save scanned image into specific folder image.Save(textBox3.Text + "\\" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".jpeg", ImageFormat.Jpeg); } } else { //If Document Name not Empty if (radioButton1.Checked) { //For Unlimited Option //For MultiScan int temp = 0; if (Directory.Exists(textBox3.Text + "\\" + textBox1.Text)) { int count = 0; while (Directory.Exists(textBox3.Text + "\\" + textBox1.Text + " (" + count + ")")) { count++; } Directory.CreateDirectory(textBox3.Text + "\\" + textBox1.Text + " (" + count + ")"); } else { Directory.CreateDirectory(textBox3.Text + "\\" + textBox1.Text); } while (true) { ConfirmingDialogBox cdb = new ConfirmingDialogBox(); cdb.currentpage = temp + 1; cdb.maxpage = 0; cdb.ShowDialog(); if (cdb.status == 1) { List <Image> images = WIAScanner.Scan((string)comboBox1.SelectedItem); foreach (Image image in images) { rotate(image); pictureBox1.Image = image; //save scanned image into specific folder image.Save(textBox3.Text + "\\" + textBox1.Text + "\\" + temp + ".jpeg", ImageFormat.Jpeg); temp++; } } else { break; } } } else if (int.Parse(textBox2.Text) > 0) { int n = int.Parse(textBox2.Text); if (n == 1) { List <Image> images = WIAScanner.Scan((string)comboBox1.SelectedItem); foreach (Image image in images) { pictureBox1.Image = image; //save scanned image into specific folder if (File.Exists(textBox3.Text + "\\" + textBox1.Text + ".jpeg")) { int temp = 0; while (File.Exists(textBox3.Text + "\\" + textBox1.Text + " (" + temp + ").jpeg")) { temp++; } image.Save(textBox3.Text + "\\" + textBox1.Text + "(" + temp + ").jpeg", ImageFormat.Jpeg); } else { image.Save(textBox3.Text + "\\" + textBox1.Text + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".jpeg", ImageFormat.Jpeg); } } } else { //For MultiScan int temp = 0; if (Directory.Exists(textBox3.Text + "\\" + textBox1.Text)) { int count = 0; while (Directory.Exists(textBox3.Text + "\\" + textBox1.Text + " (" + count + ")")) { count++; } Directory.CreateDirectory(textBox3.Text + "\\" + textBox1.Text + " (" + count + ")"); } else { Directory.CreateDirectory(textBox3.Text + "\\" + textBox1.Text); } for (int i = 0; i < int.Parse(textBox2.Text); i++) { ConfirmingDialogBox cdb = new ConfirmingDialogBox(); cdb.maxpage = int.Parse(textBox2.Text); cdb.currentpage = i + 1; cdb.ShowDialog(); if (cdb.status == 1) { List <Image> images = WIAScanner.Scan((string)comboBox1.SelectedItem); foreach (Image image in images) { rotate(image); pictureBox1.Image = image; //save scanned image into specific folder image.Save(textBox3.Text + "\\" + textBox1.Text + "\\" + temp + ".jpeg", ImageFormat.Jpeg); temp++; } } else { break; } } } } else { MessageBox.Show("Please enter the number of pages you wish to scan in the dedicated Textbox.", "PARAMETER MISSING", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception exc) { MessageBox.Show(exc.Message); } button1.Enabled = true; }