简体   繁体   English

当我尝试打印销售发票时出现问题

[英]problem when i try printing sales invoice

private void button1_Click(object sender, EventArgs e)
{
    hesham2020Entities2 db = new hesham2020Entities2();
    string u;
    u = textBox1.Text.Trim();
    var y = from v in db.inv_detail
            from s in db.invoice_head 
            where s.invno==u
            select new
                {v.unit,v.qty,v.p_no,v.description,v.price,v.tot_price,s.invno,s.customer_id,s.inv_dat,s.po_no,s.total,s.currency};
    CrystalReport6 crt = new CrystalReport6();
    crt.SetDataSource(y);
    crv9.Refresh();
    crt.SetParameterValue(0, comboBox2.SelectedItem);
    crt.SetParameterValue(1, comboBox3.SelectedItem);
    //crt.SetParameterValue(2, textBox1.Text);
    crv9.ReportSource = crt;
    crv9.Refresh();
}

when i try to print this invoice if the invoice details contain 3 rows it printed 9 rows, that mean every row printed 3 times, but when the invoice details contain 1 row it printed 1 row.当我尝试打印此发票时,如果发票详细信息包含 3 行,它会打印 9 行,这意味着每行打印 3 次,但是当发票详细信息包含 1 行时,它会打印 1 行。 i can not know the reason of the error我不知道错误的原因

You are missing the join between inv_detail and invoice_head.您缺少 inv_detail 和 invoice_head 之间的连接。 Basically you are doing a cartesian product, you should try something like:基本上你正在做一个笛卡尔积,你应该尝试这样的事情:

from db.invoice_head 
join db.inv_detail
on [...]

I think the following code can help you, maybe you forgot to use join correctly.我认为以下代码可以帮助您,也许您忘记正确使用 join 。

I used Id property for Join我使用 Id 属性加入

var y = (from v in db.inv_detail
                 join  s in db.invoice_head on v.HeaderId equals s.Id
            where s.Id == u
                 select new
            {
                v.Id
            }).ToList();

or或者

var query = db.inv_detail
            .Join(db.invoice_head, 
                post => post.HeaderId,       
                meta => meta.Id,  
                (post, meta) => new { Post = post, Meta = meta }) 
            .Where(postAndMeta => postAndMeta.Post.Id == u);  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM