刷卡后 combobox中有了卡号 焦点就到了textbox上面
那这个要写在什么事件里呢还有呀 谁有那个打印超市那种小票的代码
要打印的东西是写在一个tabcontrol里面的
网上好多代码。。看不懂 汗
谁有谁有 帮帮我吧 无限感激
那这个要写在什么事件里呢还有呀 谁有那个打印超市那种小票的代码
要打印的东西是写在一个tabcontrol里面的
网上好多代码。。看不懂 汗
谁有谁有 帮帮我吧 无限感激
调试欢乐多
我试过了,你选择好小票打印机为默认打印机,打出来的效果还可以,不过你要把代码写得好看点
private void print(PrintPageEventArgs e)
{
float x = 0f;
float y = 0f;
Graphics g = e.Graphics;
Font TitleFont = new Font("宋体", 9, FontStyle.Bold);
string TitleText = "某某超市(某某店)";
SizeF TitleSize = g.MeasureString(TitleText, TitleFont);
float TitleX = (e.PageBounds.Width - TitleSize.Width) / 2;
g.DrawString(TitleText, TitleFont, Brushes.Black, TitleX, y);
y += TitleFont.Height + 2f;
g.DrawString("单据号" + Job.DanJuHao, TitleFont, Brushes.Black, x, y);
g.DrawString("时间" + DateTime.Now.ToShortTimeString(), TitleFont, Brushes.Black, x + 121f, y);
y += TitleSize.Height + 1f;
g.DrawString("商品名称", TitleFont, Brushes.Black, x, y);
g.DrawString("售价", TitleFont, Brushes.Black, x + 70f, y);
g.DrawString("数量", TitleFont, Brushes.Black, x + 111f, y);
g.DrawString("金额", TitleFont, Brushes.Black, x + 144f, y);
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
y += TitleSize.Height;
g.DrawString(dataGridView1[1, i].Value.ToString(), TitleFont, Brushes.Black, x, y);
g.DrawString(dataGridView1[5, i].Value.ToString(), TitleFont, Brushes.Black, x + 70f, y);
g.DrawString(dataGridView1[4, i].Value.ToString(), TitleFont, Brushes.Black, x + 118f, y);
g.DrawString(dataGridView1[7, i].Value.ToString(), TitleFont, Brushes.Black, x + 144f, y);
}
y = y + TitleSize.Height;
g.DrawString("合计:", TitleFont, Brushes.Black, x, y);
g.DrawString(textBox数量.Text, TitleFont, Brushes.Black, x + 118f, y);
g.DrawString(textBox应收.Text, TitleFont, Brushes.Black, x + 144f, y);
y = y + TitleSize.Height;
float YS = float.Parse(textBox实收.Text.Trim());
string TempText = "应收:" + textBox应收.Text;
g.DrawString(TempText, TitleFont, Brushes.Black, x, y);
y += TitleSize.Height;
TempText = "实收:" + YS.ToString("f2");
g.DrawString(TempText, TitleFont, Brushes.Black, x, y);
y += TitleSize.Height;
TempText = "找零:" + textBox找零.Text;
g.DrawString(TempText, TitleFont, Brushes.Black, x, y);
//y = y + TitleSize.Height;
//g.DrawString("三天内可凭此电脑小票退换货", TitleFont, Brushes.Black, x, y);
string End = "——谢谢惠顾——";
TitleSize = g.MeasureString(End, TitleFont);
x = (e.PageBounds.Width - TitleSize.Width) / 2;
g.DrawString(End, TitleFont, Brushes.Black, x, y + TitleSize.Height );
}
写在TextChanged事件里:private void comboBox1_TextChanged(object sender, EventArgs e)
{
if (comboBox1.Text == "条件")
textBox1.Select();//获取焦点(激活)
}
private void comboBox1_TextChanged(object sender, EventArgs e)
{if (comboBox1.Text !=" ")
textBox1.Focus();
}
卡号后会自动加个回车
{
/* if (comboBox2.Text == "2009577813270007")
{
textBox1.Select();//获取焦点(激活)
}*/
string sql = "select * from ConsumptionCardInfor where 顾客编号='" +memberid + "'";
mycon.Open();
SqlCommand cmd = new SqlCommand(sql, mycon);
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())
{ if (comboBox2.Text == sdr["卡号"].ToString())
{ textBox1.Select();//获取焦点(激活)
}
else
{
MessageBox.Show("异常卡!");
comboBox2.Text = "";
comboBox2.Select();
}
}
sdr.Close();
mycon.Close();
}
为什么老是说连接未关闭 ?
sqldataReader是不能关连接的
本来好好的 改点别的代码 前面就出现这个错误了 而且是反复在不同的地方出现
谁能教教我 怎么写才能不出这个错