Code: Select all
vsTwain1.StartDevice();
vsTwain1.ShowUI = false;
if (vsTwain1.SelectSource())
{
vsTwain1.DisableAfterAcquire = true;
vsTwain1.MaxImages = 1;
vsTwain1.AutoCleanBuffer = true;
vsTwain1.OpenDataSource();
vsTwain1.PixelType = PixelType.BW;
if (vsTwain1.FeederPresent)
{
string dirPath = "q:\\EmployerDocuments\\" + myController.CurrentEmployer.Office + "\\";
string dateString = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString("00") + DateTime.Now.Day.ToString("00");
RelatedDocumentType rdType = (RelatedDocumentType)ScanItemTypeComboBox.SelectedItem;
string docDesc = rdType.DocumentTypeDesc;
string filePath = dirPath+myController.CurrentEmployer.EmployerId.ToString() + docDesc + dateString + ".pdf";
Int32 numOfPages = Int32.Parse(NumberOfPagesTextBox.Value.ToString());
vsTwain1.FeederEnabled = true;
vsTwain1.AutoFeed = true;
vsTwain1.XferCount = 1;
vsTwain1.PdfMultiPage = true;
if (vsTwain1.FeederLoaded)
{
vsTwain1.ShowIndicators = true;
while (vsTwain1.AcquireModal())
{
try
{
if (pictureBox1.Image != null)
{
pictureBox1.Dispose();
pictureBox1.Image = null;
}
pictureBox1.Image = vsTwain1.GetCurrentImage();
vsTwain1.SaveImage(0, filePath);
}
catch (TwainException ex)
{
if (vsTwain1.ErrorCode != Vintasoft.Twain.ErrorCode.None)
MessageBox.Show(vsTwain1.ErrorString);
else
MessageBox.Show(ex.Message);
}
}
Int32 docTypeId = Int32.Parse(rdType.DocumentTypeId.ToString());
myController.SaveScannedRecord(docTypeId, filePath, DescriptionTextBox.Text.ToString(), numOfPages);
vsTwain1.StopDevice();
MessageBox.Show("Scan completed.");
}
}
}
DescriptionTextBox.Text = string.Empty;
NumberOfPagesTextBox.Value = 1;
PopulateDocumentsGrid();
this.Cursor = Cursors.Arrow;
}
catch (Exception ex)
{
if (vsTwain1.ErrorCode != Vintasoft.Twain.ErrorCode.None)
MessageBox.Show(vsTwain1.ErrorString);
else
MessageBox.Show(ex.Message);
}
}