lu
6 天以前 5e376d06404a16cb3c82a93cff351c5315bbcfe3
DevApp/Gs.DevApp/UserControl/UcBtnPrint.cs
@@ -1,8 +1,12 @@
using Gs.DevApp.DevFrm.Rpt;
using Gs.DevApp.Entity;
using Gs.DevApp.ToolBox;
using Newtonsoft.Json;
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
namespace Gs.DevApp.UserControl
{
@@ -17,7 +21,6 @@
                    btnPrintClick(this, e);
                else
                    return;
                if (rptParameter == "return false")
                    return;
                if (string.IsNullOrEmpty(rptParameter))
@@ -25,24 +28,46 @@
                    MsgHelper.ShowError("没有指定报表参数,请联系技术开发人员!");
                    return;
                }
                var _bl = false;
                _bl = _ckRptService();
                if (_bl)
                #region 如果是客户的
                if (rptParameter.Contains("rpt_hgm"))
                {
                    var _obj = new
                    {
                        keyType = "客户模板"
                    };
                    var json = JsonConvert.SerializeObject(_obj);
                    try
                    {
                        using (Form frm = new RptPreview(guidKey, rptParameter))
                        var strReturn =
                            UtilityHelper.HttpPost("", "Report/GetTemplateList", json);
                        ReturnModel<DataTable> dd = UtilityHelper.ReturnToList(strReturn);
                        DataTable dt = dd.rtnData;
                        if (dd.rtnCode > 0)
                        {
                            frm.ShowDialog();
                        }
                    }
                    catch (Exception)
                            // 创建或获取一个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
                MsgHelper.ShowError("没有设计模板,请先设计模板!");
                _print();
            };
            this.btnAll.Click += (s, e) =>
            {
@@ -103,12 +128,35 @@
            return false;
        }
        public void SetPlButton( bool blPiLiang) {
        public void SetPlButton(bool blPiLiang)
        {
            if (blPiLiang == true)
                this.layoutControlItem3.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
                this.lay3.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
            else
                this.layoutControlItem3.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
                this.lay3.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("没有设计模板,请先设计模板!");
        }
    }
}