gciraman2024
Member
- Joined
- May 19, 2024
- Messages
- 12
- Programming Experience
- 3-5
Hi Team
We experience an issue with our barcode printing application, the problem is when we reprint it gives an error message below on this screen shot. When we debug it and notice on try statement is looking for a path and give this error, all the environments we set including the paths. Printing is also a problem and we struggling to fix this need help.
We experience an issue with our barcode printing application, the problem is when we reprint it gives an error message below on this screen shot. When we debug it and notice on try statement is looking for a path and give this error, all the environments we set including the paths. Printing is also a problem and we struggling to fix this need help.
printing method:
private void btnReprint_Click(object sender, EventArgs e)
{
string paths = "", appPath = "";
try
{
string reportName = "";
string optionSelected = "";
if (cboReprintPrintOption.SelectedValue.ToString() == "1") //Thermal Printer Small
{
optionSelected = "ThermalSmall";
reportName = Properties.Settings.Default.ReportNameSmallThermal;
}
else if (cboReprintPrintOption.SelectedValue.ToString() == "2") //Thermal Printer Large
{
optionSelected = "ThermalLarge";
reportName = Properties.Settings.Default.ReportNameLargeThermal;
}
else if (cboReprintPrintOption.SelectedValue.ToString() == "3") //A4
{
optionSelected = "A4";
reportName = Properties.Settings.Default.ReportNameA4;
}
CreateBarcodeDataTable();
dtReprintBarcode.Clear();
if (optionSelected == "A4")
{
if (cboReprintPrinter.Text.Contains("ZDesigner"))
{
MessageBox.Show("A4 cannot be printed to selected Printer. Please choose a different printer", "Invalid Printer");
return;
}
for (int i = 0; i < dgvReprintBarcode.Rows.Count - 1; i++)
{
string LabelID = dgvReprintBarcode.Rows[I].Cells["LabelID"].Value.ToString();
string ProdCode = dgvReprintBarcode.Rows[I].Cells["ProdCode"].Value.ToString();
string BatchNumber = dgvReprintBarcode.Rows[I].Cells["BatchNum"].Value.ToString();
string Weight = dgvReprintBarcode.Rows[I].Cells["Weight"].Value.ToString();
string FGprodcode = dgvReprintBarcode.Rows[I].Cells["FGprodcode"].Value.ToString();
string DatePrinted = dgvReprintBarcode.Rows[I].Cells["PrintDateTime"].Value.ToString();
dtReprintBarcode.Rows.Add("*" + LabelID.ToString().PadLeft(8, '0') + "*", ProdCode, BatchNumber, Weight, FGprodcode, DatePrinted);
}
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
String Root = Directory.GetCurrentDirectory();
paths = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Report\" + reportName);
if (DevEnvironment == '1')
{
appPath = Path.Combine(path, @"Report\" + reportName);
}
else
{
appPath = Path.Combine(Application.StartupPath, @"Report\" + reportName);
}
try
{
cry.Load(appPath);
}
catch
{
if (DevEnvironment == '1')
{
appPath = Path.Combine(path, @"Report\" + reportName);
}
else
{
appPath = Path.Combine(Application.StartupPath, @"Report\" + reportName);
}
}
cry.SetDataSource(dtReprintBarcode);
crystalReportViewer1.ReportSource = cry;
string PrinterName = this.printDocument1.PrinterSettings.PrinterName;
cry.PrintOptions.PrinterName = PrinterName;
printDocument1.PrinterSettings.PrinterName = cboReprintPrinter.Text.ToString();
cry.Refresh();
cry.PrintOptions.PrinterName = cboReprintPrinter.Text.ToString();
int numberOfPages = 0;
numberOfPages = Convert.ToInt32(Math.Ceiling((Convert.ToDouble(txtLabelID.Text) - Convert.ToDouble(txtLabelIdEnd.Text)) / 6));
cry.PrintToPrinter(1, false, 1, numberOfPages);
}
else if (optionSelected == "ThermalSmall" || optionSelected == "ThermalLarge")
{
ReprintToThermal(reportName);
}
txtLabelID.Text = "";
txtLabelIdEnd.Text = "";
dgvReprintBarcode.DataSource = null;
crystalReportViewer1.ReportSource = null;
crystalReportViewer1.Refresh();
}
catch (Exception ex)
{
MessageBox.Show(ex.InnerException.ToString() + " Path: " + Environment.CurrentDirectory + @"\");
if (ex.InnerException.ToString().Contains("cannot find the file"))
{
MessageBox.Show("Path: " + appPath + " " + paths);
}
}
}
Attachments
Last edited by a moderator: