如何仅在网格视图中打印指定的行
欢迎 我有一个带有发票的销售屏幕,该屏幕在网格视图中显示了Extra Robert的报告 我只想使用选择框选择一些行时,仅在一个页面上打印了所选行,我尝试了此代码 我只想在一页上打印所选的行。谢谢
for (int i = 0; i <= DgvSale.Rows.Count - 1; i++)
{
if (Convert.ToBoolean(DgvSale.Rows[i].Cells[8].Value) == true)
{
tblRpt1 = db.readData("SELECT [Order_ID] as 'رقم الفاتورة',talb_ID as 'طلب',[Cust_Name] as 'اسم العميل',Products.Pro_Name as 'المنتج',Products.Group_ID as 'قسم',Products_Group.Group_Name as 'اسم القسم',[Sales_Detalis].[Qty] as 'الكمية',[Price] as 'السعر',[User_Name] as 'الكاشير',[Date] as 'التاريخ',[Unit] as 'الوحدة',[Sales_Detalis].Tax_Value as 'الضريبة',Price_Tax as 'السعر بعد الضريبة',[typetalab] as 'نوع الطلب',[priceservic] as 'خدمة',[shiftname] as 'شيفت',notes as 'ملاحظات',shiftnum as 'شيفت رقم',Print_Group.Print_Name,Print_Group.Name_Group FROM [dbo].[Sales_Detalis] , Products,Products_Group,Print_Group where Products.Pro_ID = Sales_Detalis.Pro_ID and Products.Pro_ID= " + row1.Cells[0].Value + " and Order_ID = " + id + " and Products.Group_ID = Products_Group.Group_ID and Print_Group.Name_Group=Products.Group_ID ORDER BY Order_ID ASC", "");
}
}
if (Properties.Settings.Default.SalePrintKind == "8CM")
{
devOrderSales2 rpt = new devOrderSales2() { DataSource = tblRpt1, DataMember = "OrderSales2" };
rpt.DataSource = tblRpt1;
rpt.Parameters["ID1"].Value = id;
rpt.PrinterName = Properties.Settings.Default.PrinterNameSteker;
rpt.xrTableCell8.Visible=true;
if (Properties.Settings.Default.saleprintauto == "0")
{
rpt.Print();
}
else if (Properties.Settings.Default.saleprintauto == "1")
{
rpt.ShowPreviewDialog();
}
}
Welcome
I have a sales screen with an invoice that is displayed in the grid view with the report of Extra Robert
I just want when I select some rows using the select box only the selected rows are printed on one page I tried this code but it prints each row in a separate report
I just want to print the selected rows on one page. Thank you
for (int i = 0; i <= DgvSale.Rows.Count - 1; i++)
{
if (Convert.ToBoolean(DgvSale.Rows[i].Cells[8].Value) == true)
{
tblRpt1 = db.readData("SELECT [Order_ID] as 'رقم الفاتورة',talb_ID as 'طلب',[Cust_Name] as 'اسم العميل',Products.Pro_Name as 'المنتج',Products.Group_ID as 'قسم',Products_Group.Group_Name as 'اسم القسم',[Sales_Detalis].[Qty] as 'الكمية',[Price] as 'السعر',[User_Name] as 'الكاشير',[Date] as 'التاريخ',[Unit] as 'الوحدة',[Sales_Detalis].Tax_Value as 'الضريبة',Price_Tax as 'السعر بعد الضريبة',[typetalab] as 'نوع الطلب',[priceservic] as 'خدمة',[shiftname] as 'شيفت',notes as 'ملاحظات',shiftnum as 'شيفت رقم',Print_Group.Print_Name,Print_Group.Name_Group FROM [dbo].[Sales_Detalis] , Products,Products_Group,Print_Group where Products.Pro_ID = Sales_Detalis.Pro_ID and Products.Pro_ID= " + row1.Cells[0].Value + " and Order_ID = " + id + " and Products.Group_ID = Products_Group.Group_ID and Print_Group.Name_Group=Products.Group_ID ORDER BY Order_ID ASC", "");
}
}
if (Properties.Settings.Default.SalePrintKind == "8CM")
{
devOrderSales2 rpt = new devOrderSales2() { DataSource = tblRpt1, DataMember = "OrderSales2" };
rpt.DataSource = tblRpt1;
rpt.Parameters["ID1"].Value = id;
rpt.PrinterName = Properties.Settings.Default.PrinterNameSteker;
rpt.xrTableCell8.Visible=true;
if (Properties.Settings.Default.saleprintauto == "0")
{
rpt.Print();
}
else if (Properties.Settings.Default.saleprintauto == "1")
{
rpt.ShowPreviewDialog();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议使用选定的记录动态创建某些条件:
另外,您应该使用现代联接语法,而不是在Where子句中使用过时的联接条件。
请注意,我已经设置了一个具有
{0}
和{1}
的SQL字符串作为占位符,后来被替换为String.format
方法。我认为产品ID为int
。条件看起来像这样的结果:用
@引入的c#verbatim字符串@
允许您在字符串中包含销钉中断,并使SQL文本更可读取。row> row1
始终指向同一行。I suggest to create the WHERE condition dynamically with the selected records:
Also, you should use the modern JOIN syntax instead of the outdated join conditions in the WHERE clause.
Note that I have set up a SQL string with
{0}
and{1}
as placeholders later being replaced with theString.Format
method. I assumed the product ids to be of typeint
. The resulting WHERE conditions looks something like this:The C# verbatim strings introduced with
@"
allow you to include line breaks within the string and to make the SQL text more readable.row1
always points to the same row. Get the row dynamically withDgvSale.Rows[i]
instead, within the loop.一种方法是首先从行中收集所有相关ID,并且仅进行1 dB查询,例如:
请注意查询中的更改:
in(“ + string.join(“,”,toprint_ids)) +“)
另外,如果您的行有非数字ID(例如GUIDS),则需要将列表更改为
list&lt; string&gt;
,并且还将查询更改为in(''''in('') + string.join(“','”,toprint_ids) +“')One way is to first collect all the relevant IDs from the rows, and only do 1 db query, eg:
Please notice the change in the query as well:
in (" + string.Join(",", toprint_ids) + ")
Also if you have non-numeric IDs for your rows (eg Guids), then you need to change the list to a
List<string>
and also change your query to likein ('" + string.Join("','", toprint_ids) + "')