private void ConstructQuantityGrid() { DataTable table = new DataTable(); table.Columns.Add(new DataColumn("ColorCode", typeof(string))); CertificationBO certification = panelPrint.DataContext as CertificationBO; var style = certification.Style; var sizes = style.Sizes.OrderBy(o => o.Code).ToList(); foreach (var sn in sizes) { table.Columns.Add(new DataColumn(sn.Name, typeof(int))); gvDatas.Columns.Add(new telerik::GridViewDataColumn() { Header = sn.Name, UniqueName = sn.Name, DataMemberBinding = new Binding(sn.Name) }); } var colors = style.Colors.OrderBy(o => o.Code).ToList(); foreach (var cc in colors) { //gvDatas.Items.Add(new QuantitySetForProStyle { ColorCode = cc.Code }); DataRow row = table.NewRow(); table.Rows.Add(row); row["ColorCode"] = cc.Code; } gvDatas.ItemsSource = table.DefaultView;//一定要用DataView,否则不能编辑,shit //gvDatas.BeginEdit();//默认为第一个能编辑的cell }
private void PrintWithGridViewQuantity(object sender, RoutedEventArgs e) { RadButton btn = (RadButton)sender; PrintQueue defaultPrintQueue = LocalPrintServer.GetDefaultPrintQueue(); var printDialog = new PrintDialog(); printDialog.PrintQueue = defaultPrintQueue; //var copies = ((CertificationPrintTicket)btn.DataContext).Copies; //var barCodes = _productUniqueCodeMappingVM.GenerateBarCodes(copies); CertificationBO certification = panelPrint.DataContext as CertificationBO; var dv = gvDatas.ItemsSource as DataView; int quaSuccessful = 0; foreach (DataRowView row in dv) { for (int i = 1; i < dv.Table.Columns.Count; i++) { int qua = 0; int.TryParse(row[i].ToString(), out qua); if (qua > 0) { string ccode = row[0].ToString(); string sname = dv.Table.Columns[i].ColumnName; certification.Color = string.Format("[{0}]{1}", ccode, VMGlobal.Colors.Find(o => o.Code == ccode).Name); certification.Size = string.Format("[{0}]{1}", VMGlobal.Sizes.Find(o => o.Name == sname).Code, sname); certification.Quantity = qua; var product = _certificationPrintVM.GetProduct(certification.StyleID, ccode, sname); if (product != null) { var barCodes = #if UniqueCode _certificationPrintVM.GenerateBarCodes(qua); #else Enumerable.Range(1, qua).Select(o => product.Code).ToList(); #endif try { this.Print(product.ID, printDialog, barCodes, ref quaSuccessful); } catch (Exception ex) { MessageBox.Show("打印出现异常,错误信息:" + ex.Message); goto Finally; } } } } } Finally: MessageBox.Show("合格证打印并保存成功" + quaSuccessful + "份"); //var paginator = new CertificationPaginator(panelPrint, gvDatas.ItemsSource as DataView, _productUniqueCodeMappingVM) //{ // PageSize = new Size(printDialog.PrintableAreaWidth, printDialog.PrintableAreaHeight)//此处可能需要进行缩放处理 //}; //if (paginator.PageCount == 0) //{ // MessageBox.Show("请输入打印份数."); // return; //} //try //{ // printDialog.PrintDocument(paginator, "合格证"); //} //catch (Exception ex) //{ // MessageBox.Show("打印出现异常,错误信息:" + ex.Message); //} //finally //{ // if (paginator.PageNumber > 1) // { // CertificationBO certification = panelPrint.DataContext as CertificationBO; // var mappings = paginator.BarCodes.Take(paginator.PageNumber).Select(o => new ProductUniqueCodeMapping { ProductID = certification.StyleID, UniqueCode = o }); // var result = _productUniqueCodeMappingVM.AddMappings(mappings); // if (result.IsSucceed) // { // MessageBox.Show("合格证成功打印" + paginator.PageNumber + "份"); // if (paginator.PageNumber == paginator.PageCount) // this.Close(); // } // else // MessageBox.Show(result.Message); // } //} //printDialog.PrintVisual(panelPrint, "测试"); }