private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (dataGridView1.Columns[e.ColumnIndex].Name == "xiangInfo") { if (PrintKind == 0) { xiangqing newXiang = new xiangqing(dataGridView1.Rows[e.RowIndex].Cells["tid"].Value.ToString()); newXiang.Show(); } if (PrintKind == 1) { xiangqing newXiang = new xiangqing(dataGridView1.Rows[e.RowIndex].Cells["TEL"].Value.ToString(), QuanJwriter); newXiang.Show(); } } }
private void printShowEXEL(int row, int count) { moban newmoban = new moban(); //收货人姓名 TextObject RecevieName = (TextObject)newmoban.ReportDefinition.ReportObjects["RecevieName"]; RecevieName.Text = dataGridView1.Rows[row].Cells["receiveName"].Value.ToString(); //收货人电话 TextObject ReceiveTel = (TextObject)newmoban.ReportDefinition.ReportObjects["ReceiveTel"]; ReceiveTel.Text = dataGridView1.Rows[row].Cells["TEL"].Value.ToString(); //提货点名称 TextObject PickPointName = (TextObject)newmoban.ReportDefinition.ReportObjects["PickPointName"]; PickPointName.Text = dataGridView1.Rows[row].Cells["Address"].Value.ToString(); ////订单号 //TextObject OrderNo = (TextObject)newmoban.ReportDefinition.ReportObjects["OrderNo"]; //OrderNo.Text = "*" + dataGridView1.Rows[row].Cells["TEL"].Value.ToString().Replace("\t","") + "*"; ////QuanJwriter xiangqing goodsinfo = new xiangqing(dataGridView1.Rows[row].Cells["TEL"].Value.ToString(), QuanJwriter); //订单详情 TextObject commidityInfo = (TextObject)newmoban.ReportDefinition.ReportObjects["commidity"]; for (; count < goodsinfo.dataGridView1.RowCount - 1; count++) { if ((count + 1) % 5 == 0) { printShowEXEL(row, count + 1); commidityInfo.Text += (count + 1).ToString() + "," + goodsinfo.dataGridView1.Rows[count].Cells["GoodsName"].Value.ToString() + "\n" + "数量:" + goodsinfo.dataGridView1.Rows[count].Cells["GoodsNum"].Value.ToString() + "份" + "\n"; break; } commidityInfo.Text += (count + 1).ToString() + "," + goodsinfo.dataGridView1.Rows[count].Cells["GoodsName"].Value.ToString() + "\n" + "数量:" + goodsinfo.dataGridView1.Rows[count].Cells["GoodsNum"].Value.ToString() + "份" + "\n"; } //小计 //database a = new database(); //TextObject subtotal = (TextObject)newmoban.ReportDefinition.ReportObjects["subtotal"]; //subtotal.Text = "订单总价¥:" + a.inputOrderInfo(dataGridView1.Rows[row].Cells["tid"].Value.ToString())["payment"] + "\n"; //下单时间 //TextObject PayTime = (TextObject)newmoban.ReportDefinition.ReportObjects["PayTime"]; //PayTime.Text = a.inputOrderInfo(dataGridView1.Rows[row].Cells["tid"].Value.ToString())["pay_time"]; //表尾 //收货人姓名2 //TextObject RecevieName2 = (TextObject)newmoban.ReportDefinition.ReportObjects["RecevieName2"]; //RecevieName2.Text = dataGridView1.Rows[row].Cells["receiveName"].Value.ToString(); ////收货人电话2 //TextObject ReceiveTel2 = (TextObject)newmoban.ReportDefinition.ReportObjects["ReceiveTel2"]; //ReceiveTel2.Text = dataGridView1.Rows[row].Cells["TEL"].Value.ToString(); ////提货点名称2 //TextObject PickPointName2 = (TextObject)newmoban.ReportDefinition.ReportObjects["PickPointName2"]; //PickPointName2.Text = dataGridView1.Rows[row].Cells["Address"].Value.ToString(); //TextObject OrderNo2 = (TextObject)newmoban.ReportDefinition.ReportObjects["OrderNo2"]; //OrderNo2.Text = dataGridView1.Rows[row].Cells["tid"].Value.ToString(); // 表尾数字订单号 //TextObject Text1 = (TextObject)newmoban.ReportDefinition.ReportObjects["Text1"]; //Text1.Text = dataGridView1.Rows[row].Cells["tid"].Value.ToString(); //crystalReportViewer1.ReportSource = newinfo; //crystalReportViewer1.Show(); //newinfo.PrintOptions.PrinterName= //newmoban.PrintOptions.PrinterName = DefaultPrinter; // 设置打印机名称 System.Drawing.Printing.PrintDocument doc = new System.Drawing.Printing.PrintDocument(); //List<string> Printer = new List<string>(); //foreach (string fPrinterName in LocalPrinter.GetLocalPrinters()) //{ // Printer.Add(fPrinterName); //} ////doc.PrinterSettings.PrinterName = DefaultPrinter; //doc.PrinterSettings.PrinterName = Printer[0].ToString(); //LocalPrinter print=new LocalPrinter(); //newmoban.PrintOptions.PrinterName=print.DefaultPrinter ; int rawKind = 1; for (int i = 0; i <= doc.PrinterSettings.PaperSizes.Count - 1; i++) { if (doc.PrinterSettings.PaperSizes[i].PaperName == "订单打印") { rawKind = doc.PrinterSettings.PaperSizes[i].RawKind; } } newmoban.PrintOptions.PrinterName = doc.PrinterSettings.PrinterName; newmoban.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)rawKind; // 设置打印纸张样式 newmoban.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.DefaultPaperOrientation; //默认纸张方向 newmoban.PrintToPrinter(1, false, 1, 1); newmoban.Dispose(); return; }