| | |
| | | using Gs.DevApp.DevFrm.Rpt; |
| | | using Gs.DevApp.DevFrm.Sys; |
| | | using Gs.DevApp.Entity; |
| | | using Gs.DevApp.ToolBox; |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Linq; |
| | | using System; |
| | | using System.Data; |
| | | using System.Drawing; |
| | | using System.IO; |
| | | using System.Windows.Forms; |
| | | |
| | | |
| | | namespace Gs.DevApp.UserControl |
| | | { |
| | |
| | | public UcBtnPrint() |
| | | { |
| | | InitializeComponent(); |
| | | btnReport.Click += BtnReport_ItemClick; |
| | | btnDesign.Click += BtnDesign_ItemClick; |
| | | |
| | | |
| | | //预览打印 |
| | | this.btnPrint.Click += (s, e) => |
| | | { |
| | | if (btnPrintClick != null) |
| | | btnPrintClick(this, e); |
| | | else |
| | | return; |
| | | if (rptParameter == "return false") |
| | | return; |
| | | if (string.IsNullOrEmpty(rptParameter)) |
| | | { |
| | | MsgHelper.ShowError("没有指定报表参数,请联系技术开发人员!"); |
| | | return; |
| | | } |
| | | #region 如果是客户的后盖码 |
| | | if (rptParameter.Contains("rpt_hgm")) |
| | | { |
| | | var _obj = new |
| | | { |
| | | keyType = "客户模板" |
| | | }; |
| | | var json = JsonConvert.SerializeObject(_obj); |
| | | try |
| | | { |
| | | var strReturn = |
| | | UtilityHelper.HttpPost("", "Report/GetTemplateList", json); |
| | | ReturnModel<DataTable> dd = UtilityHelper.ReturnToList(strReturn); |
| | | DataTable dt = dd.rtnData; |
| | | if (dd.rtnCode > 0) |
| | | { |
| | | // 创建或获取一个ContextMenu对象(例如使用ContextMenuStrip) |
| | | ContextMenu contextMenu = new ContextMenu(); |
| | | foreach (DataRow dr in dt.Rows) |
| | | { |
| | | MenuItem menuItem1 = new MenuItem(dr["reportType"].ToString() + "【" + dr["reportName"].ToString() + "】"); |
| | | menuItem1.Click += (ss, ee) => |
| | | { |
| | | rptParameter = rptParameter.Replace("rpt_hgm", dr["reportType"].ToString()); |
| | | _print(); |
| | | }; |
| | | contextMenu.MenuItems.Add(menuItem1); |
| | | } |
| | | // 显示菜单在按钮的位置 |
| | | contextMenu.Show(btnPrint, new Point(0, btnPrint.Height)); // 调整第二个参数以调整菜单的显示位置 |
| | | return; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { } |
| | | } |
| | | #endregion |
| | | _print(); |
| | | }; |
| | | //批量操作 |
| | | this.btnAll.Click += (s, e) => |
| | | { |
| | | if (btnAllClick != null) |
| | | btnAllClick(this, e); |
| | | else |
| | | return; |
| | | }; |
| | | //直接打印 |
| | | this.btnZhiJie.Click += (s, e) => |
| | | { |
| | | if (btnZhiJieClick != null) |
| | | btnZhiJieClick(this, e); |
| | | else |
| | | return; |
| | | if (rptParameter == "return false") |
| | | return; |
| | | if (string.IsNullOrEmpty(rptParameter)) |
| | | { |
| | | MsgHelper.ShowError("没有指定报表参数,请联系技术开发人员!"); |
| | | return; |
| | | } |
| | | var _obj = new |
| | | { |
| | | rptParameter = rptParameter, |
| | | guid = guidKey, |
| | | isDesign = 0 |
| | | }; |
| | | try |
| | | { |
| | | var strJson = UtilityHelper.HttpPost("", "Report/GetRptData", |
| | | JsonConvert.SerializeObject(_obj)); |
| | | var _job = JObject.Parse(strJson); |
| | | var rtnCode = _job["rtnCode"].ToString(); |
| | | if (int.Parse(rtnCode) > 0) |
| | | { |
| | | //模板 |
| | | var report = new FastReport.Report(); |
| | | var buffer = (byte[])_job["rtnData"]["reportTemplateData"]; |
| | | using (var Stream = new MemoryStream(buffer)) |
| | | { |
| | | report.Load(Stream); |
| | | } |
| | | //主表 |
| | | var array = new JArray(); |
| | | foreach (var a in _job["rtnData"]["zb"]) array.Add(a); |
| | | var _zb = JsonConvert.DeserializeObject<DataTable>(array.ToString()); |
| | | _zb.TableName = "zb"; |
| | | //明细表1 |
| | | var array1 = new JArray(); |
| | | foreach (var a in _job["rtnData"]["mx1"]) array1.Add(a); |
| | | var _mx1 = JsonConvert.DeserializeObject<DataTable>(array1.ToString()); |
| | | _mx1.TableName = "mx1"; |
| | | //明细表2 |
| | | var array2 = new JArray(); |
| | | foreach (var a in _job["rtnData"]["mx2"]) array2.Add(a); |
| | | var _mx2 = JsonConvert.DeserializeObject<DataTable>(array2.ToString()); |
| | | _mx2.TableName = "mx2"; |
| | | //加到数据集中 |
| | | var ds = new DataSet(); |
| | | ds.Tables.Add(_zb); |
| | | ds.Tables.Add(_mx1); |
| | | ds.Tables.Add(_mx2); |
| | | report.RegisterData(ds); |
| | | report.Print(); |
| | | // report.ShowPrepared(); |
| | | } |
| | | else |
| | | { |
| | | MsgHelper.ShowError("提示:" + _job["rtnMsg"]); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MsgHelper.ShowError("提示:" + ex.Message); |
| | | } |
| | | }; |
| | | } |
| | | /// <summary> |
| | | /// 关键字,一般是主键 |
| | | /// </summary> |
| | | public string guidKey { get; set; } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 批量操作时的关键字:托板码 |
| | | /// </summary> |
| | | public string allClickKey { get; set; } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 报表,在数据库中要唯一,如:存储过程名{入参1名|入参值,入参2名|入参值} |
| | | /// </summary> |
| | | public string rptParameter { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 打印 |
| | | /// </summary> |
| | | public event EventHandler btnPrintClick; |
| | | |
| | | /// <summary> |
| | | /// 设置报表 |
| | | /// 批量操作 |
| | | /// </summary> |
| | | public event EventHandler btnDesignClick; |
| | | public event EventHandler btnAllClick; |
| | | |
| | | /// <summary> |
| | | /// 报表 |
| | | /// 直接打印 |
| | | /// </summary> |
| | | public event EventHandler btnReportClick; |
| | | public event EventHandler btnZhiJieClick; |
| | | |
| | | private void BtnReport_ItemClick(object sender, EventArgs e) |
| | | { |
| | | if (btnReportClick != null) |
| | | btnReportClick(this, e); |
| | | else |
| | | return; |
| | | |
| | | if (rptParameter == "return false") |
| | | return; |
| | | if (string.IsNullOrEmpty(rptParameter)) |
| | | { |
| | | MsgHelper.ShowError("没有指定报表参数,请联系技术开发人员!"); |
| | | return; |
| | | } |
| | | var _bl = false; |
| | | _bl = _ckRptService(); |
| | | if (_bl) |
| | | { |
| | | try |
| | | { |
| | | using (Form frm = new RptPreview(guidKey, rptParameter)) |
| | | { |
| | | frm.ShowDialog(); |
| | | } |
| | | } |
| | | catch (Exception) |
| | | { |
| | | } |
| | | return; |
| | | } |
| | | |
| | | MsgHelper.ShowError("没有设计模板,请先设计模板!"); |
| | | } |
| | | |
| | | private void BtnDesign_ItemClick(object sender, EventArgs e) |
| | | { |
| | | if (btnDesignClick != null) |
| | | btnDesignClick(this, e); |
| | | else |
| | | return; |
| | | |
| | | if (string.IsNullOrEmpty(rptParameter)) |
| | | { |
| | | MsgHelper.ShowError("没有指定报表参数,请联系技术开发人员!"); |
| | | return; |
| | | } |
| | | var _bl = false; |
| | | _bl = _ckRptService(); |
| | | //如果已经有模板了,直接打开设置模板 |
| | | if (_bl) |
| | | { |
| | | var frm = new EasyRptDesign(guidKey, rptParameter); |
| | | frm.ShowDialog(); |
| | | return; |
| | | } |
| | | //否则向导设计模板 |
| | | var rptWizard = new ShowRptWizard(guidKey, rptParameter); |
| | | rptWizard.ShowDialog(); |
| | | } |
| | | private bool _ckRptService() |
| | | { |
| | | try |
| | |
| | | return false; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 设置批量按钮可见性 |
| | | /// </summary> |
| | | /// <param name="blPiLiang"></param> |
| | | public void SetPlButton(bool blPiLiang) |
| | | { |
| | | if (blPiLiang == true) |
| | | this.lay3.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; |
| | | else |
| | | this.lay3.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置确定按钮可见性 |
| | | /// </summary> |
| | | /// <param name="blPiLiang"></param> |
| | | public void SetPrintButton(bool blPiLiang) |
| | | { |
| | | if (blPiLiang == true) |
| | | this.lay1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; |
| | | else |
| | | this.lay1.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 预览打印 |
| | | /// </summary> |
| | | private void _print() |
| | | { |
| | | var _bl = false; |
| | | _bl = _ckRptService(); |
| | | if (_bl) |
| | | { |
| | | try |
| | | { |
| | | using (Form frm = new RptPreview(guidKey, rptParameter)) |
| | | { |
| | | frm.ShowDialog(); |
| | | } |
| | | } |
| | | catch (Exception) |
| | | { |
| | | } |
| | | return; |
| | | } |
| | | MsgHelper.ShowError("没有设计模板,请先设计模板!"); |
| | | } |
| | | } |
| | | } |