程序第一次打印时工作正常。但是当我要打印时,会发生第二次收货错误。
第一个错误1
的屏幕截图我试过(正如我在互联网上找到的那样) - 取消选中启用Visual Studio托管进程并检查启用非托管代码再次出现之后现在它给出了这样的错误..
第二个错误2
的屏幕截图代码:
private void btnprint_Click(object sender, EventArgs e)
{
try
{
if (txtcash.Text == "" || txttpri.Text == "" || txtftot.Text == "")
{
MessageBox.Show("Please Input Cash Price ! ", "Sales", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
txtbal.Text = (Convert.ToInt32(txtcash.Text) - Convert.ToInt32(txtftot.Text)).ToString();
printDialog1.ShowDialog();
printDocument1.Print();
radreta.Enabled = true;
radwhol.Enabled = true;
radreta.Checked = false;
radwhol.Checked = false;
}
}
catch (Exception)
{
MessageBox.Show("Printing Issue !", "Message");
}
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
try
{
salesconnection.Open();
OleDbCommand cmdprint = new OleDbCommand();
cmdprint.Connection = salesconnection;
cmdprint.CommandText = "Select * from saletrans";
OleDbDataReader printreder = cmdprint.ExecuteReader();
int x = 50;
int y = 65;
int width = 800;
int height = 0;
StringFormat left = new StringFormat();
left.Alignment = StringAlignment.Near;
StringFormat center = new StringFormat();
center.Alignment = StringAlignment.Near;
e.Graphics.DrawString(" Toyota Motor Corporation Area Store Branch ", new Font("Georgia", 15, FontStyle.Bold), Brushes.DarkRed, new Rectangle(x, y, width, height), left);
y = 85;
e.Graphics.DrawString(" No:56,Kurunegala Road,Katugasthota", new Font("Georgia", 12, FontStyle.Bold), Brushes.DarkRed, new Rectangle(x, y, width, height), left);
y = 100;
e.Graphics.DrawString(" toyotamotorcorporation@gmail.com / TpNo: 081-2225468/081-2224445", new Font("Georgia", 11, FontStyle.Bold), Brushes.DarkRed, new Rectangle(x, y, width, height), left);
y = 138;
e.Graphics.DrawString(" " + "Product ID" + " " + "Product Name" + " " + "Unit/P" + " " + "Quantity" + " " + "Sub Total(Rs:)", new Font("Georgia", 13, FontStyle.Bold), Brushes.CadetBlue, new Rectangle(x, y, width, height), left);
y = 146;
e.Graphics.DrawString("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", new Font("Georgia", 12, FontStyle.Bold), Brushes.CadetBlue, new Rectangle(x, y, width, height), left);
x = 110;
y = 155;
while (printreder.Read())
{
y = y + 20;
e.Graphics.DrawString("" + printreder["ProductID"] + " " + printreder["ProductName"].ToString(), new Font("Georgia", 13, FontStyle.Bold), Brushes.Black, new Rectangle(x, y, width, height), left);
y = y + 20;
e.Graphics.DrawString(" " + printreder["Unitprice"] + " x " + printreder["Quantity"].ToString() + " = " + printreder["Total"].ToString(), new Font("Georgia", 13, FontStyle.Bold), Brushes.Black, new Rectangle(x, y, width, height), left);
}
y = y + 25;
x = 60;
e.Graphics.DrawString("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", new Font("Georgia", 12, FontStyle.Bold), Brushes.CadetBlue, new Rectangle(x, y, width, height), left);
y = y + 15;
x = 490;
e.Graphics.DrawString("Grand Total " + txtftot.Text, new Font("Georgia", 14, FontStyle.Bold), Brushes.DarkRed, new Rectangle(x, y, width, height), left);
y = y + 20;
e.Graphics.DrawString("Cash " + txtcash.Text, new Font("Georgia", 14, FontStyle.Bold), Brushes.DarkRed, new Rectangle(x, y, width, height), left);
y = y + 20;
e.Graphics.DrawString("-------------------------------------", new Font("Georgia", 14, FontStyle.Bold), Brushes.DarkRed, new Rectangle(x, y, width, height), left);
y = y + 20;
e.Graphics.DrawString("Balance " + txtbal.Text, new Font("Georgia", 14, FontStyle.Bold), Brushes.DarkRed, new Rectangle(x, y, width, height), left);
x = 60;
y = y + 30;
e.Graphics.DrawString("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", new Font("Georgia", 12, FontStyle.Bold), Brushes.CadetBlue, new Rectangle(x, y, width, height), left);
y = y + 20;
e.Graphics.DrawString("Customer Name & ID : " + txtcname.Text +" / "+ cmbcid.Text, new Font("Georgia", 12, FontStyle.Bold), Brushes.DarkBlue, new Rectangle(x, y, width, height), center);
y = y + 30;
e.Graphics.DrawString(frmlog.user.ToString() + " " + DateTime.Now, new Font("Georgia", 12, FontStyle.Bold), Brushes.DarkBlue, new Rectangle(x, y, width, height), center);
y = y + 20;
e.Graphics.DrawString("** Exchange Possible Within 7 Days **", new Font("Georgia", 12, FontStyle.Bold), Brushes.DarkBlue, new Rectangle(x, y, width, height), center);
y = y + 20;
e.Graphics.DrawString("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", new Font("Georgia", 12, FontStyle.Bold), Brushes.CadetBlue, new Rectangle(x, y, width, height), left);
y = y + 20;
e.Graphics.DrawString("Software by NKP Developer", new Font("Georgia", 12, FontStyle.Bold), Brushes.DarkBlue, new Rectangle(x, y, width, height), center);
pictureBox1.Image = Image.FromFile("E:\\NIBM\\C#\\GROUP PROJECT\\graphics\\Billlogo.png");
Point loc = new Point(300, 15);
e.Graphics.DrawImage(pictureBox1.Image, loc);
printreder.Close();
salesconnection.Close();
salesconnection.Open();
OleDbCommand deleteall = new OleDbCommand();
deleteall.Connection = salesconnection;
string del = "delete from saletrans";
deleteall.CommandText = del;
deleteall.ExecuteNonQuery();
salesconnection.Close();
dataGridView2.DataSource = null;
dataGridView2.Refresh();
cmbcid.Enabled = true;
cmbcid.Text = "";
txtcname.Text = "";
txtbal.Text = "";
txtcash.Text = "";
txttpri.Text = "0";
txtftot.Text = "0";
btnnewbill.Enabled = false;
btnpurdelete.Enabled = false;
btncalculate.Enabled = false;
btnprint.Enabled = false;
sum = 0;
}
catch (Exception)
{
MessageBox.Show("Printing Issue !", "Message");
}
}