private void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            CrystalPrintConfigModel validConfig = GetValidationModel();

            if (validConfig != null)
            {
                var model = this.gpConfig.DataContext as CrystalPrintConfigModel;
                if (model.Id == 0) // 插入打印配置
                {
                    string result = new CrystalPrintConfigService().AddConfig(validConfig);
                    MessageBox.Show(result);
                }
                else // 更新打印配置
                {
                    validConfig.Id = model.Id;
                    string result = new CrystalPrintConfigService().ModifyConfig(validConfig);
                    MessageBox.Show(result);
                }
                this.gpConfig.DataContext = new CrystalPrintConfigService().GetCrystalPrintConfig(1, Dns.GetHostName());
            }
            else
            {
                MessageBox.Show(" 参数录入不合法 ");
            }
        }
Ejemplo n.º 2
0
        public bool UpdateCrystalPrintConfig(CrystalPrintConfigModel model)
        {
            string sql = @" update SJCrystalPrintConfig set Orientation=@Orientation,PrinterName=@PrinterName,MarginLeft=@MarginLeft,MarginTop=@MarginTop,MarginRight=@MarginRight,MarginBottom=@MarginBottom,PaperName=@PaperName where Id=@Id;";

            using (var connection = SqlDb.UpdateConnection)
            {
                return(connection.Execute(sql, model) > 0);
            }
        }
Ejemplo n.º 3
0
        public string ModifyConfig(CrystalPrintConfigModel model)
        {
            int count = dal.ModifyCrystalPrintConfig(model);

            if (count != 1)
            {
                return(" 更改参数配置失败");
            }
            return(" 保存成功 ");
        }
Ejemplo n.º 4
0
        public string AddConfig(CrystalPrintConfigModel model)
        {
            int count = dal.AddCrystalPrintConfig(model);

            if (count != 1)
            {
                return(" 新增参数配置失败");
            }
            return(" 保存成功 ");
        }
Ejemplo n.º 5
0
        public bool InsertCrystalPrintConfig(CrystalPrintConfigModel model)
        {
            string sql = @" insert into SJCrystalPrintConfig(TypeId,TypeDesciption,HostName,PrinterName,MarginLeft,MarginTop,MarginRight,MarginBottom,PaperName,UserId)
                            values(@TypeId,@TypeDesciption,@HostName,@PrinterName,@MarginLeft,@MarginTop,@MarginRight,@MarginBottom,@PaperName,@UserId);";

            using (var connection = SqlDb.UpdateConnection)
            {
                return(connection.Execute(sql, model) > 0);
            }
        }
Ejemplo n.º 6
0
 public int ModifyCrystalPrintConfig(CrystalPrintConfigModel model)
 {
     return(SqlHelper.ExecuteNonQuery(" update SJCrystalPrintConfig set Orientation=@Orientation,PrinterName=@PrinterName,MarginLeft=@MarginLeft,MarginTop=@MarginTop,MarginRight=@MarginRight,MarginBottom=@MarginBottom ,PaperName=@PaperName where Id=@Id",
                                      new SqlParameter[] { new SqlParameter("@Id", model.Id),
                                                           new SqlParameter("@Orientation", model.Orientation ?? ""),
                                                           new SqlParameter("@PrinterName", model.PrinterName ?? ""),
                                                           new SqlParameter("@MarginLeft", model.MarginLeft),
                                                           new SqlParameter("@MarginTop", model.MarginTop),
                                                           new SqlParameter("@MarginRight", model.MarginRight),
                                                           new SqlParameter("@MarginBottom", model.MarginBottom),
                                                           new SqlParameter("@PaperName", model.PaperName) }
                                      ));
 }
Ejemplo n.º 7
0
 public int AddCrystalPrintConfig(CrystalPrintConfigModel model)
 {
     return(SqlHelper.ExecuteNonQuery(" insert into SJCrystalPrintConfig(TypeId,TypeDesciption,HostName,Orientation,PrinterName,MarginLeft,MarginTop,MarginRight,MarginBottom,PaperName) values   (@TypeId,@TypeDesciption,@HostName,@Orientation,@PrinterName,@MarginLeft,@MarginTop,@MarginRight,@MarginBottom,@PaperName)",
                                      new SqlParameter[] {
         new SqlParameter("@TypeId", model.TypeId),
         new SqlParameter("@TypeDesciption", model.TypeDesciption),
         new SqlParameter("@HostName", model.HostName),
         new SqlParameter("@Orientation", model.Orientation ?? ""),
         new SqlParameter("@PrinterName", model.PrinterName ?? ""),
         new SqlParameter("@MarginLeft", model.MarginLeft),
         new SqlParameter("@MarginTop", model.MarginTop),
         new SqlParameter("@MarginRight", model.MarginRight),
         new SqlParameter("@MarginBottom", model.MarginBottom),
         new SqlParameter("@PaperName", model.PaperName)
     }
                                      ));
 }
        private void BtnPrint_Click(object sender, RoutedEventArgs e)
        {
            if (this.MainDataGrid.SelectedItems.Count == 1)
            {
                CustomerModel           customer    = this.MainDataGrid.SelectedItem as CustomerModel;
                CrystalPrintConfigModel validConfig = GetValidationModel();
                if (validConfig != null)
                {
                    DataTable dataTable = UniversalFunction.ModelToTable <CustomerModel>(new List <CustomerModel> {
                        this.MainDataGrid.SelectedItems[0] as CustomerModel
                    });
                    ReportDocument reportDoc = new ReportDocument();

                    string reportDataSource = System.IO.Path.Combine(Directory.GetCurrentDirectory(), "Report/Customer.rpt");
                    reportDoc.Load(reportDataSource);
                    reportDoc.SetDataSource(dataTable);



                    ////打印机名称设置
                    //reportDoc.PrintOptions.PrinterName = validConfig.PrinterName;

                    //// 打印方向设置(此处和对应的模板方向一致即可)
                    //if (validConfig.Orientation == "横向")
                    //    reportDoc.PrintOptions.PaperOrientation = PaperOrientation.Landscape;
                    //else if (validConfig.Orientation == "竖向")
                    //    reportDoc.PrintOptions.PaperOrientation = PaperOrientation.Portrait;
                    //else
                    //    reportDoc.PrintOptions.PaperOrientation = PaperOrientation.DefaultPaperOrientation;

                    ////打印机页面大小设置
                    //PageSettings settings = new PageSettings(new PrinterSettings { PrinterName = validConfig.PrinterName });
                    //var pageSizes = PrintHelper.GetPrinterPageSizes(validConfig.PrinterName);
                    //int rawKind = Convert.ToInt32(this.CbPaperSize.SelectedValue);
                    //reportDoc.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)rawKind;


                    // 打印机页边距设置
                    //PageMargins margins = reportDoc.PrintOptions.PageMargins;

                    // margins.bottomMargin = validConfig.MarginBottom * 100;
                    // margins.leftMargin = validConfig.MarginLeft * 100;
                    // margins.rightMargin = validConfig.MarginRight * 100;
                    // margins.topMargin = validConfig.MarginTop * 100;
                    // reportDoc.PrintOptions.ApplyPageMargins(margins);     //应用页边距。



                    PrinterSettings printerSettings = new PrinterSettings();
                    printerSettings.PrinterName = validConfig.PrinterName;
                    PageSettings pageSettings = new PageSettings(printerSettings);
                    pageSettings.Margins = new Margins {
                        Left = validConfig.MarginLeft * 1000 / 254, Top = validConfig.MarginTop * 1000 / 254, Right = validConfig.MarginRight * 1000 / 254, Bottom = validConfig.MarginBottom * 1000 / 254
                    };
                    pageSettings.Landscape = validConfig.Orientation == "竖向"?true:false;


                    // 打印
                    //reportDoc.PrintToPrinter(1, true, 0, 0); 完全按照模板【页面设置】配置参数,自定义需要用重载方法,载入打印机配置。
                    reportDoc.PrintToPrinter(printerSettings, pageSettings, true);
                    reportDoc.Close();
                    reportDoc.Dispose();
                    MessageBox.Show(" 打印成功 ");
                }
                else
                {
                    MessageBox.Show(" 打印参数错误 ");
                }
            }
            else
            {
                MessageBox.Show("先选择一条需要打印的记录");
            }
        }