diff --git a/引用DLL/Lskj.Data.ADO.dll b/引用DLL/Lskj.Data.ADO.dll index 08f2ab0..6abd848 100644 Binary files a/引用DLL/Lskj.Data.ADO.dll and b/引用DLL/Lskj.Data.ADO.dll differ diff --git a/引用DLL/Lskj.Data.Api.dll b/引用DLL/Lskj.Data.Api.dll index e4a252a..6d3fcd7 100644 Binary files a/引用DLL/Lskj.Data.Api.dll and b/引用DLL/Lskj.Data.Api.dll differ diff --git a/引用DLL/Lskj.Web.Core.dll b/引用DLL/Lskj.Web.Core.dll index eac31d7..7248d6e 100644 Binary files a/引用DLL/Lskj.Web.Core.dll and b/引用DLL/Lskj.Web.Core.dll differ diff --git a/引用DLL/Lskj.WebErp.Core.dll b/引用DLL/Lskj.WebErp.Core.dll index e03e67a..88181c6 100644 Binary files a/引用DLL/Lskj.WebErp.Core.dll and b/引用DLL/Lskj.WebErp.Core.dll differ diff --git a/插件库/Lskj.PubAdd/FrmMain.cs b/插件库/Lskj.PubAdd/FrmMain.cs index b483729..660ffa5 100644 --- a/插件库/Lskj.PubAdd/FrmMain.cs +++ b/插件库/Lskj.PubAdd/FrmMain.cs @@ -1,194 +1,194 @@ -/****************************** -* 说明:基础档案添加界面 -* 创建人:龚宇超 -* 创建日期:2017-11-02 -* 修改人: -* 修改日期: -* 修改备注: -* 版本:1.0.0.0 -******************************/ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Windows.Forms; -using Lskj.Control; -using Lskj.Control.Model; -using Lskj.Util; -using Lskj.Business.Impl; -using Lskj.Model; -using DevExpress.XtraTab; -using DevExpress.Utils; -using Lskj.Data; -using Lskj.Business; -using System.Threading; -using DevExpress.XtraEditors; -using Lskj.Core; - -namespace Lskj.PubAdd -{ - /// - /// 基础档案添加界面 - /// - public partial class FrmMain : BaseForm - { - /// - /// 主表选中行 - /// - public DataRow MaintabFocusedRow { get; private set; } - /// - /// 系统模块实体对象 - /// - /// The system model. - public ModuleModel SysModel { get; private set; } - /// - /// 里面是否使用滚动条 - /// - public bool isAutoScroll = false; - /// - /// 调用动态链接库默认传递参数 - /// - public DynamicAddModel Model; - double H_Scaling; - double W_Scaling; - - public DataTable details = new DataTable(); - +/****************************** +* 说明:基础档案添加界面 +* 创建人:龚宇超 +* 创建日期:2017-11-02 +* 修改人: +* 修改日期: +* 修改备注: +* 版本:1.0.0.0 +******************************/ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using Lskj.Control; +using Lskj.Control.Model; +using Lskj.Util; +using Lskj.Business.Impl; +using Lskj.Model; +using DevExpress.XtraTab; +using DevExpress.Utils; +using Lskj.Data; +using Lskj.Business; +using System.Threading; +using DevExpress.XtraEditors; +using Lskj.Core; + +namespace Lskj.PubAdd +{ + /// + /// 基础档案添加界面 + /// + public partial class FrmMain : BaseForm + { + /// + /// 主表选中行 + /// + public DataRow MaintabFocusedRow { get; private set; } + /// + /// 系统模块实体对象 + /// + /// The system model. + public ModuleModel SysModel { get; private set; } + /// + /// 里面是否使用滚动条 + /// + public bool isAutoScroll = false; + /// + /// 调用动态链接库默认传递参数 + /// + public DynamicAddModel Model; + double H_Scaling; + double W_Scaling; + + public DataTable details = new DataTable(); + public FrmMain() { SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.Selectable | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor, true); InitializeComponent(); this.Activated += OnFrmMainActivated; } - /// - /// 窗体激活时 - /// - /// - /// - private void OnFrmMainActivated(object sender, EventArgs e) - { - //新增时输入焦点 - if (string.IsNullOrEmpty(this.ModuleAddControl.PrimaryValue)&& ModuleAddControl.ControlObj!=null) - { - ControlModel controlModel = ModuleAddControl.ControlObj.ControlModels.Where(n => n.Location.X != 0 || n.Location.Y != 0).OrderBy(n => n.TabOrder).FirstOrDefault(); - if (controlModel != null) - { - BaseUserControl baseControl = ModuleAddControl.ControlObj.FindControl(controlModel); - if (baseControl != null) - { - baseControl.Focus(); - } - } - } - } - /// - /// 窗体加载时 - /// - /// - protected override void OnLoad(EventArgs e) - { - WaitForm.ShowForm(); - - try - { - Console.WriteLine("初始化开始:" + DateTime.Now); - //this.SuspendLayout(); - this.SysModel = new ModuleModel(MainImpl.GetSystemdllTab(this.Model.ModuleCode)); - this.SysModel.ParmaryKey = BaseImpl.GetBasePrimaryKey(this.Model.ModuleCode); - this.SysModel.maintabFocusedRow = Model.GetMaintabFocusedRow(); - this.ModuleAddControl.OnAddRecordCallBack += OnAddRecordCallBack; - this.ModuleAddControl.OnClearCallBack += OnClearCallBack; + /// + /// 窗体激活时 + /// + /// + /// + private void OnFrmMainActivated(object sender, EventArgs e) + { + //新增时输入焦点 + if (string.IsNullOrEmpty(this.ModuleAddControl.PrimaryValue)&& ModuleAddControl.ControlObj!=null) + { + ControlModel controlModel = ModuleAddControl.ControlObj.ControlModels.Where(n => n.Location.X != 0 || n.Location.Y != 0).OrderBy(n => n.TabOrder).FirstOrDefault(); + if (controlModel != null) + { + BaseUserControl baseControl = ModuleAddControl.ControlObj.FindControl(controlModel); + if (baseControl != null) + { + baseControl.Focus(); + } + } + } + } + /// + /// 窗体加载时 + /// + /// + protected override void OnLoad(EventArgs e) + { + WaitForm.ShowForm(); + + try + { + Console.WriteLine("初始化开始:" + DateTime.Now); + //this.SuspendLayout(); + this.SysModel = new ModuleModel(MainImpl.GetSystemdllTab(this.Model.ModuleCode)); + this.SysModel.ParmaryKey = BaseImpl.GetBasePrimaryKey(this.Model.ModuleCode); + this.SysModel.maintabFocusedRow = Model.GetMaintabFocusedRow(); + this.ModuleAddControl.OnAddRecordCallBack += OnAddRecordCallBack; + this.ModuleAddControl.OnClearCallBack += OnClearCallBack; this.details = BaseModuleImpl.GetBaseAddTabDetail(Model.ModuleCode); this.CreateControlLocation(); this.SetControlPanelSize(); - - this.CreateTabDetail(); - - if (Business.Impl.LanguageTranslation.Translatable) xtcControl.TabPages[0].Text= Business.Impl.LanguageTranslation.GetTranslatedText(xtcControl.TabPages[0].Text); - - Console.WriteLine("初始化完成:" + DateTime.Now); - } - catch (Exception ex) - { - LogHelper.Instance.WriteError(ex); - string Message = ErrorMessage.PromptErrorMessage(ex); - MessageUtil.Show(Message, ex.Message); - } - finally - { - Lskj.Control.Model.AutoSizeChange.ControllInitializeSize(this); - //this.ResumeLayout(false); - } - this.Text = Model.FormText + (string.IsNullOrWhiteSpace(Model.ObjectId) ? "" : "[" + Model.ObjectId + "]"); - LogUtil.WriteDebug(Model.ModuleCode, "打开操作", ERPInfo.Instance.UserName, "打开[" + Model.FormText + "] 查看" + Model.ObjectId, Model.ModuleId + ""); - WaitForm.HideForm(); - } - /// - /// 说明:设置窗口大小 - /// 创建人:龚宇超 - /// 创建日期:2017-11-03 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The menu code. + + this.CreateTabDetail(); + + if (Business.Impl.LanguageTranslation.Translatable) xtcControl.TabPages[0].Text= Business.Impl.LanguageTranslation.GetTranslatedText(xtcControl.TabPages[0].Text); + + Console.WriteLine("初始化完成:" + DateTime.Now); + } + catch (Exception ex) + { + LogHelper.Instance.WriteError(ex); + string Message = ErrorMessage.PromptErrorMessage(ex); + MessageUtil.Show(Message, ex.Message); + } + finally + { + Lskj.Control.Model.AutoSizeChange.ControllInitializeSize(this); + //this.ResumeLayout(false); + } + this.Text = Model.FormText + (string.IsNullOrWhiteSpace(Model.ObjectId) ? "" : "[" + Model.ObjectId + "]"); + LogUtil.WriteDebug(Model.ModuleCode, "打开操作", ERPInfo.Instance.UserName, "打开[" + Model.FormText + "] 查看" + Model.ObjectId, Model.ModuleId + ""); + WaitForm.HideForm(); + } + /// + /// 说明:设置窗口大小 + /// 创建人:龚宇超 + /// 创建日期:2017-11-03 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The menu code. private void SetControlPanelSize() { DataRow item = BaseModuleImpl.GetControlParentSize(this.SysModel.FormKey); if (item != null) - { - int otherHeight = 80; - bool topVisible = false; - - if ("lskj.pubadd.dll".Equals((this.SysModel.MenuAddName).ToLower()) || - "lskj.pubadd2.dll".Equals((this.SysModel.MenuAddName).ToLower())) - { - otherHeight = 130; - topVisible = true; - } - //this.ModuleAddControl.SetTopPanelVisible(topVisible);//2023-9-1 把这个判断放入modulePanelEx初始化中 - - this.Width = Convert.ToInt32(item["width"] + ""); - - int height = this.ModuleAddControl.ControlHeight + this.ModuleAddControl.OperatePanelControlObj.Height + this.ModuleAddControl.SpeciesPanelControlObj.Height; - height = Convert.ToInt32(item["height"] + "") > height ? height : Convert.ToInt32(item["height"] + "");//如果控件高度小于设置高度,以实际高度为准 - if (ModuleAddControl.SplitContainerControl.PanelVisibility == SplitPanelVisibility.Both) - { - height += 400; - } - this.Height = height + otherHeight; - - //this.Height = Convert.ToInt32(item["height"] + "") + otherHeight; - if (this.Left < 0) this.Left = 0; - if (this.Top < 0) this.Top = 0; - this.Left = (Screen.PrimaryScreen.WorkingArea.Width - this.Width) / 2; - this.Top = (Screen.PrimaryScreen.WorkingArea.Height - this.Height) / 2; - if ((this.Width > Screen.PrimaryScreen.WorkingArea.Width || (this.Height > Screen.PrimaryScreen.WorkingArea.Height))) - { - int screenHeight = Screen.PrimaryScreen.WorkingArea.Height; - screenHeight = screenHeight - 40; - this.Height = screenHeight; - this.Top = (Screen.PrimaryScreen.WorkingArea.Height - this.Height) / 2; - isAutoScroll = true; - ModuleAddControl.plMainControlObj.AutoScroll = isAutoScroll; - if (ModuleAddControl.SplitContainerControl.PanelVisibility == SplitPanelVisibility.Both) - { - this.ModuleAddControl.SplitContainerControl.SplitterPosition = (this.Height * 2) / 3; - } - } - else - { - this.ModuleAddControl.plMainControlObj.AutoScroll = true; - this.ModuleAddControl.plMainControlObj.HorizontalScroll.Visible = false; - if (ModuleAddControl.SplitContainerControl.PanelVisibility == SplitPanelVisibility.Both) - { - this.ModuleAddControl.SplitContainerControl.SplitterPosition = this.ModuleAddControl.ControlHeight; - } - } + { + int otherHeight = 80; + bool topVisible = false; + + if ("lskj.pubadd.dll".Equals((this.SysModel.MenuAddName).ToLower()) || + "lskj.pubadd2.dll".Equals((this.SysModel.MenuAddName).ToLower())) + { + otherHeight = 130; + topVisible = true; + } + //this.ModuleAddControl.SetTopPanelVisible(topVisible);//2023-9-1 把这个判断放入modulePanelEx初始化中 + + this.Width = Convert.ToInt32(item["width"] + ""); + + int height = this.ModuleAddControl.ControlHeight + this.ModuleAddControl.OperatePanelControlObj.Height + this.ModuleAddControl.SpeciesPanelControlObj.Height; + height = Convert.ToInt32(item["height"] + "") > height ? height : Convert.ToInt32(item["height"] + "");//如果控件高度小于设置高度,以实际高度为准 + if (ModuleAddControl.SplitContainerControl.PanelVisibility == SplitPanelVisibility.Both) + { + height += 400; + } + this.Height = height + otherHeight; + + //this.Height = Convert.ToInt32(item["height"] + "") + otherHeight; + if (this.Left < 0) this.Left = 0; + if (this.Top < 0) this.Top = 0; + this.Left = (Screen.PrimaryScreen.WorkingArea.Width - this.Width) / 2; + this.Top = (Screen.PrimaryScreen.WorkingArea.Height - this.Height) / 2; + if ((this.Width > Screen.PrimaryScreen.WorkingArea.Width || (this.Height > Screen.PrimaryScreen.WorkingArea.Height))) + { + int screenHeight = Screen.PrimaryScreen.WorkingArea.Height; + screenHeight = screenHeight - 40; + this.Height = screenHeight; + this.Top = (Screen.PrimaryScreen.WorkingArea.Height - this.Height) / 2; + isAutoScroll = true; + ModuleAddControl.plMainControlObj.AutoScroll = isAutoScroll; + if (ModuleAddControl.SplitContainerControl.PanelVisibility == SplitPanelVisibility.Both) + { + this.ModuleAddControl.SplitContainerControl.SplitterPosition = (this.Height * 2) / 3; + } + } + else + { + this.ModuleAddControl.plMainControlObj.AutoScroll = true; + this.ModuleAddControl.plMainControlObj.HorizontalScroll.Visible = false; + if (ModuleAddControl.SplitContainerControl.PanelVisibility == SplitPanelVisibility.Both) + { + this.ModuleAddControl.SplitContainerControl.SplitterPosition = this.ModuleAddControl.ControlHeight; + } + } string splitWidth = IniHelper.Read(string.Format("ModulePanelExAdd_Split_{0}", this.Model.ModuleCode));//通过Key获取Value值 if (!string.IsNullOrEmpty(splitWidth)) { @@ -196,570 +196,570 @@ namespace Lskj.PubAdd } this.ModuleAddControl.SplitContainerControl.SplitterPositionChanged += OnSplitterPositionChanged; } - } - /// - /// 说明:初始化多标签 - /// 创建人:龚宇超 - /// 创建日期:2017-11-10 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - private void CreateTabDetail() - { - this.Invoke((EventHandler)delegate - { - bool isInside = false; - - foreach (DataRow item in this.details.Rows) - { - if (this.details.Columns.Contains("orderId") && !string.IsNullOrWhiteSpace(item["orderId"] + "") && int.Parse(item["orderId"] + "") < 0) - { - continue; - } - - XtraTabPage tabPage = new XtraTabPage(); - GridDetailModel detailModel = new GridDetailModel(item, null, GridCustomColumnStruct.BaseDetailGridView); - if (!string.IsNullOrEmpty(detailModel.UnionModule)) - { - ModuleModel moduleModel = new ModuleModel(MainImpl.GetSystemdllTab(detailModel.UnionModule)); - if (string.IsNullOrWhiteSpace(moduleModel.FormKey)) - { - string text = Business.Impl.LanguageTranslation.Translatable ? Business.Impl.LanguageTranslation.GetTranslatedText("模块配置错误") : "模块配置错误"; - MessageUtil.Show(detailModel.DetailName + text); - return; - } - detailModel.DetailSql = moduleModel.MenuSql; - } - detailModel.GridColumns = ReportImpl.GetReportDetailColumns(Model.ModuleCode, item["id"] + ""); - tabPage.Text = detailModel.DetailName; - tabPage.Tag = detailModel; - if (ModuleAddControl.plMainControlObj.Tag is XtraTabControl) - { - XtraTabControl xtr = ModuleAddControl.plMainControlObj.Tag as XtraTabControl; - xtr.TabPages.Add(tabPage); - isInside = true; - xtr.SelectedPageChanged += new DevExpress.XtraTab.TabPageChangedEventHandler(this.OnSelectedPageChanged); - xtr.SelectedPageChanging += new DevExpress.XtraTab.TabPageChangingEventHandler(this.OnSelectedPageChanging); - } - else - { - this.xtcControl.TabPages.Add(tabPage); - } - } - - this.xtcControl.ShowTabHeader = details.Rows.Count > 0 && !isInside ? DefaultBoolean.True : DefaultBoolean.False; - }); - } - - /// - /// 说明:创建控件 - /// 创建人:龚宇超 - /// 创建日期:2017-11-03 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - private void CreateControlLocation() - { - this.ModuleAddControl.SavaState = Model.SaveState.Equals("1"); - this.ModuleAddControl.IsView = Model.IsView; - this.ModuleAddControl.ParentKey = Model.ParentKey; - this.ModuleAddControl.ParentValue = Model.ParentValue; - this.ModuleAddControl.PrimaryKey = this.SysModel.ParmaryKey;// BaseImpl.GetBasePrimaryKey(Model.ModuleCode); 和上方获取主键执行方法相同,直接取上方的值 - this.ModuleAddControl.UnionKey = Model.UnionKey; - this.ModuleAddControl.UnionValue = Model.UnionValue; - this.ModuleAddControl.PrimaryValue = Model.ObjectId; - this.ModuleAddControl.ControlSql = Model.ControlSql; - this.ModuleAddControl.OnCloseCallback += new EventHandler(OnCloseCallback); - this.ModuleAddControl.SearchObject = Model.SearchObject; - - if (this.details.Columns.Contains("orderId")) - { - DataRow[] dataRows = details.Select("orderId<0"); - this.ModuleAddControl.DetailsData = dataRows; - } - - this.ModuleAddControl.InitializeControl(SysModel, Model, isAutoScroll); - - } - - /// - /// 说明:关闭按钮回调 - /// 创建人:龚宇超 - /// 创建日期:2017-11-08 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - protected void OnCloseCallback(object sender, EventArgs e) - { - try - { - this.DialogResult = DialogResult.OK; - this.Close(); - } - catch (Exception ex) - { - string Message = ErrorMessage.PromptErrorMessage(ex); - MessageUtil.Show(Message, ex.Message); - } - } - /// - /// 说明:查询条件执行前 - /// 创建人:龚宇超 - /// 创建日期:2017-11-10 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The sender. - /// The e. - protected void OnSearchBefore(object sender, SearchArgs e) - { - try - { - XtraTabPage tabPage = xtcControl.SelectedTabPage; - if (ModuleAddControl.plMainControlObj.Tag is XtraTabControl) - { - XtraTabControl xtr = ModuleAddControl.plMainControlObj.Tag as XtraTabControl; - tabPage = xtr.SelectedTabPage; - } - if (tabPage != null) - { - ModuleGridEx moduleGrid = tabPage.Tag as ModuleGridEx; - GridDetailModel detailModel = moduleGrid.Tag as GridDetailModel; - - moduleGrid.SearchObj.SearchGrid(detailModel.DetailSql + string.Format(" and {0}='{1}'", moduleGrid.DetailKeyField, moduleGrid.UnionValue)); - } - e.Continue = false; - } - catch (Exception ex) - { - string Message = ErrorMessage.PromptErrorMessage(ex); - MessageUtil.Show(Message, ex.Message); - } - } - /// - /// 说明:查询条件执行后 - /// 创建人:龚宇超 - /// 创建日期:2017-11-10 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - protected void OnSearchAfter(object sender, EventArgs e) - { - try - { - XtraTabPage tabPage = xtcControl.SelectedTabPage; - if (ModuleAddControl.plMainControlObj.Tag is XtraTabControl) - { - XtraTabControl xtr = ModuleAddControl.plMainControlObj.Tag as XtraTabControl; - tabPage = xtr.SelectedTabPage; - } - if (tabPage != null) - { - if (tabPage.Tag is ModuleGridEx) - { - ModuleGridEx moduleGrid = tabPage.Tag as ModuleGridEx; - GridDetailModel detailModel = moduleGrid.Tag as GridDetailModel; - tabPage.Text = detailModel.DetailName + "(" + moduleGrid.SearchObj.GridRowCount + "条)"; - } - else if (tabPage.Tag is GridControlEx) - { - - GridControlEx moduleGrid = tabPage.Tag as GridControlEx; - GridDetailModel detailModel = moduleGrid.Tag as GridDetailModel; - tabPage.Text = detailModel.DetailName + "(" + moduleGrid.DataRowCount() + "条)"; - } - - } - } - catch (Exception ex) - { - string Message = ErrorMessage.PromptErrorMessage(ex); - MessageUtil.Show(Message, ex.Message); - } - } - /// - /// 说明:切换选项卡 - /// 创建人:龚宇超 - /// 创建日期:2018-04-09 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - protected void OnSelectedPageChanging(object sender, TabPageChangingEventArgs e) - { - try - { - XtraTabPage page = e.Page; - if (page != null) - { - if (e.PrevPage == xtcControl.TabPages[0] && string.IsNullOrEmpty(this.ModuleAddControl.PrimaryValue)) - { - MessageUtil.Show(ResourceKeys.BeforeSaveData); - e.Cancel = true; - } - } - } - catch (Exception ex) - { - string Message = ErrorMessage.PromptErrorMessage(ex); - MessageUtil.Show(Message, ex.Message); - } - } - /// - /// 说明:切换标签刷新主键值 - /// 创建人:龚宇超 - /// 创建日期:2018-04-09 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - protected void OnSelectedPageChanged(object sender, TabPageChangedEventArgs e) - { - try - { - - XtraTabPage tabPage = e.Page; - ModuleAddControl.OperatePanelControlObj.Visible = true; - //XtraTabPage tabPage = this.xtcControl.SelectedTabPage; - if (tabPage.Tag is ModuleGridEx) ModuleAddControl.OperatePanelControlObj.Visible = false; - if (!(tabPage.Tag is GridDetailModel)) return; - ModuleAddControl.OperatePanelControlObj.Visible = false; - if (tabPage.Controls.Count == 0) - { - - GridDetailModel detailModel = tabPage.Tag as GridDetailModel; - ModuleModel moduleModel = null; - DynamicAddModel addModel = new DynamicAddModel(new string[] { - detailModel.DetailName, - ERPInfo.Instance.UserId, - ERPInfo.Instance.UserName, - "1",detailModel.UnionModule,"","","" - }); - addModel.Params = Model.OtherParams(); - if (detailModel.IsWebView) - { - // 加载网页 - string url = detailModel.DetailSql.StartsWith("http") ? detailModel.DetailSql : SystemInfo.Instance.OAUrl + detailModel.DetailSql; - if (!string.IsNullOrWhiteSpace(Model.ParentKey)) - { - string codeSql = "select"; - codeSql += string.Format(" '{0}' as {1}", Model.ObjectId, this.SysModel.ParmaryKey); - url = ReplaceHelper.ReplaceRowParam(BaseImpl.GetDataRowResult(codeSql), ReplaceHelper.ReplaceWhereCond(detailModel.DetailSql)); - } - if (this.ModuleAddControl.ControlObj.CurrentData != null) url = ReplaceHelper.ReplaceRowParam(this.ModuleAddControl.ControlObj.CurrentData, url); - //url= System.Web.HttpUtility.UrlEncode(url); - - if (SystemInfo.Instance.PrimitiveBrowser) - { - FrmMiniBlink webView = new FrmMiniBlink(); - webView.IsDownVerify = true; - webView.Dock = DockStyle.Fill; - webView.Tag = detailModel; - tabPage.Tag = webView; - tabPage.Controls.Add(webView); - webView.LoadUrl(ReplaceHelper.ReplaceUserInfo(url)); - } - else - { - FrmWebBrowser webView = new FrmWebBrowser(); - webView.Dock = DockStyle.Fill; - webView.Tag = detailModel; - tabPage.Tag = webView; - tabPage.Controls.Add(webView); - webView.FrmLoad(ReplaceHelper.ReplaceUserInfo(url)); - } - } - else if (detailModel.IsWebView2) - { - // 加载网页 - string url = detailModel.DetailSql.StartsWith("http") ? detailModel.DetailSql : SystemInfo.Instance.OAUrl + detailModel.DetailSql; - //url= System.Web.HttpUtility.UrlEncode(url); - if (this.ModuleAddControl.ControlObj.CurrentData != null) url = ReplaceHelper.ReplaceRowParam(this.ModuleAddControl.ControlObj.CurrentData, url); - if (SystemInfo.Instance.PrimitiveBrowser) - { - FrmMiniBlink webView = new FrmMiniBlink(); - webView.Dock = DockStyle.Fill; - webView.Tag = detailModel; - tabPage.Tag = webView; - tabPage.Controls.Add(webView); - webView.LoadUrl(ReplaceHelper.ReplaceUserInfo(url)); - } - else - { - FrmWebBrowser2 webView = new FrmWebBrowser2(); - webView.Dock = DockStyle.Fill; - webView.Tag = detailModel; - tabPage.Tag = webView; - tabPage.Controls.Add(webView); - webView.FrmLoad(ReplaceHelper.ReplaceUserInfo(url)); - } - } - else if (detailModel.IsWebView3) - { - // 加载网页 - string url = detailModel.DetailSql.StartsWith("http") ? detailModel.DetailSql : SystemInfo.Instance.OAUrl + detailModel.DetailSql; - //url= System.Web.HttpUtility.UrlEncode(url); - if (this.ModuleAddControl.ControlObj.CurrentData != null) url = ReplaceHelper.ReplaceRowParam(this.ModuleAddControl.ControlObj.CurrentData, url); - if (SystemInfo.Instance.PrimitiveBrowser) - { - FrmMiniBlink webView = new FrmMiniBlink(); - webView.AllowDownload = false; - webView.Dock = DockStyle.Fill; - webView.Tag = detailModel; - tabPage.Tag = webView; - tabPage.Controls.Add(webView); - webView.LoadUrl(ReplaceHelper.ReplaceUserInfo(url)); - } - else - { - FrmWebBrowser2 webView = new FrmWebBrowser2(); - webView.Dock = DockStyle.Fill; - webView.Tag = detailModel; - webView.AllowDownload = false; - tabPage.Tag = webView; - tabPage.Controls.Add(webView); - webView.FrmLoad(ReplaceHelper.ReplaceUserInfo(url)); - } - } - else if (string.IsNullOrEmpty(detailModel.UnionModule)) - { - PanelControl plBottom = new PanelControl(); - plBottom.Dock = DockStyle.Bottom; - plBottom.Visible = false; - PanelControl plMain = new PanelControl(); - plMain.Dock = DockStyle.Fill; - GridControlEx gridEx = detailModel.AutoMultiHeader == 1 ? new BandedGridControlEx() : new GridControlEx(); - gridEx.Dock = DockStyle.Fill; - gridEx.Tag = detailModel; - gridEx.Parent = plMain; - gridEx.Model = this.Model; - gridEx.SetReadOnlyColumns(detailModel.GridColumns, detailModel.GridCustomColumnKey); - //gridEx.SetGridRightMenus(BaseModuleImpl.GetBaseGridRightMenus(model.FormKey), this.Model, OnGridViewRightCallBack); - //gridEx.SetGridRowColors(BaseModuleImpl.GetBaseGridRowColors(model.FormKey)); - - gridEx.SetGridRightMenus(BaseModuleImpl.GetBaseGridRightMenus(detailModel.FormKey), this.Model); - gridEx.SetGridRowColors(BaseModuleImpl.GetBaseGridRowColors(detailModel.FormKey)); - if (detailModel.IsCheck == 1)//加载复选框 - { - GridDragGrid.GridAddCheckBox(gridEx.GridView); - } - // 加载配置查询条件 - if (Model != null && Model.IsDetailSearch) - { - plBottom.Visible = true; - MyControl searchObj = new MyControl(detailModel.DetailSql, gridEx); - plBottom.Height = searchObj.InitSearchControl(BaseModuleImpl.GetCustomQueryFields(detailModel.FormKey), plBottom); - } - tabPage.Tag = gridEx; - tabPage.Controls.AddRange(new PanelControl[] { plBottom, plMain }); - if (detailModel.AutoRefresh) - { - if (!string.IsNullOrWhiteSpace(this.ModuleAddControl.ParentKey)) - { - string codeSql = "select"; - codeSql += string.Format(" '{0}' as {1}", this.ModuleAddControl.PrimaryValue, this.ModuleAddControl.PrimaryKey); - gridEx.SetGridViewDataSource(SqlHelper.ExecuteDataTable(ReplaceHelper.ReplaceRowParam(BaseImpl.GetDataRowResult(codeSql), ReplaceHelper.ReplaceWhereCond(detailModel.DetailSql)))); - } - else if (this.ModuleAddControl.ControlObj.CurrentData != null) - { - gridEx.SetGridViewDataSource(SqlHelper.ExecuteDataTable(ReplaceHelper.ReplaceRowParam(this.ModuleAddControl.ControlObj.CurrentData, ReplaceHelper.ReplaceWhereCond(detailModel.DetailSql)))); - } - // 自动刷新 - } - } - else - { - - moduleModel = new ModuleModel(MainImpl.GetSystemdllTab(detailModel.UnionModule)); - moduleModel.maintabFocusedRow = SysModel.maintabFocusedRow; - ModuleGridEx moduleGrid = new ModuleGridEx(); - moduleGrid.IsDetail = true; - moduleGrid.Dock = DockStyle.Fill; - moduleGrid.Tag = detailModel; - moduleGrid.ParentKeyField = string.IsNullOrEmpty(detailModel.UnionParentField) ? SysModel.ParmaryKey : detailModel.UnionParentField; - - //直接在控件数据源中取值,控件可能是禁显状态(没用控件获取不到值) - if (!string.IsNullOrWhiteSpace(moduleGrid.ParentKeyField) && this.ModuleAddControl.ControlObj.CurrentData.Table.Columns.Contains(moduleGrid.ParentKeyField)) - { - moduleGrid.ParentKeyValue = moduleGrid.UnionValue = this.ModuleAddControl.ControlObj.CurrentData[moduleGrid.ParentKeyField] + ""; - } - - if (detailModel.AddHideBottomPanel || detailModel.HideBottomPanel || detailModel.Library.Equals("Lskj.Report.dll", StringComparison.OrdinalIgnoreCase)) - { - moduleGrid.VisibleOperPanel = false; - } - - //moduleGrid.ParentKeyValue = this.ModuleAddControl.ControlObj.GetControlValue(moduleGrid.ParentKeyField); - moduleGrid.DetailKeyField = detailModel.UnionValue; - moduleGrid.UnionKey = detailModel.UnionValue; - //moduleGrid.UnionValue = this.ModuleAddControl.ControlObj.GetControlValue(moduleGrid.ParentKeyField); //Model.ObjectId; - moduleGrid.SearchControlSql = Model.ControlSql; - moduleGrid.InitializeControl(moduleModel, addModel); - moduleGrid.SearchObj.OnSearchBeforeCallBack += new SearchEventHandler(OnSearchBefore); - moduleGrid.SearchObj.OnSearchAfterCallBack += new EventHandler(OnSearchAfter); - Lskj.Control.Model.AutoSizeChange.ControllInitializeSize(moduleGrid); - tabPage.Controls.Add(moduleGrid); - tabPage.Tag = moduleGrid; - if (detailModel.AutoRefresh) - { - moduleGrid.SearchObj.OnDataSourceBindCallBack += new EventHandler(OnMainSearchDataSourceBindCallBack); - // 自动刷新 - //moduleGrid.SearchObj.SearchGrid(ReplaceHelper.ReplaceWhereCond(moduleModel.MenuSql) + string.Format(" and {0}='{1}'", moduleGrid.DetailKeyField, moduleGrid.UnionValue)); - } - } - } - } - catch (Exception ex) - { - string Message = ErrorMessage.PromptErrorMessage(ex); - MessageUtil.Show(Message, ex.Message); - } - } - /// - /// 说明:查询条件绑定完成查询数据 - /// 创建人:龚宇超 - /// 创建日期: - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The sender. - /// The instance containing the event data. - protected void OnMainSearchDataSourceBindCallBack(object sender, EventArgs e) - { - try - { - MyControl searchobj = sender as MyControl; - //if (!string.IsNullOrEmpty(this.SysModel.CustomColumnSQL)) - //{ - // BaseImpl.ExecSqlValue(searchobj.ReplaceControlValue(this.SysModel.CustomColumnSQL)); - //} - searchobj.SearchGrid(); - OnSearchAfter(null, null); - } - catch (Exception ex) - { - string Message = ErrorMessage.PromptErrorMessage(ex); - MessageUtil.Show(Message, ex.Message); - } - - } - /// - /// 清理后回调 - /// - /// - /// - private void OnClearCallBack(object sender, EventArgs e) - { - //新增时输入焦点 - ControlModel controlModel = ModuleAddControl.ControlObj.ControlModels.Where(n => n.Location.X != 0 || n.Location.Y != 0).OrderBy(n => n.TabOrder).FirstOrDefault(); - if (controlModel != null) - { - BaseUserControl baseControl = ModuleAddControl.ControlObj.FindControl(controlModel); - if (baseControl != null) - { - baseControl.Focus(); - } - } - } - /// - /// 添加保存成功后执行 - /// - /// - /// - private void OnAddRecordCallBack(object sender, EventArgs e) - { - FormDialogModel dialogModel = new FormDialogModel() - { - DialogDllName = "Lskj.PubAdd.dll", - PubDialogType = DialogType.PubAddRecord, - ReturnTag = ModuleAddControl.ControlObj - }; - this.Tag = dialogModel; - } - /// - /// 分割条位置改变时 - /// - /// - /// + } + /// + /// 说明:初始化多标签 + /// 创建人:龚宇超 + /// 创建日期:2017-11-10 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + private void CreateTabDetail() + { + this.Invoke((EventHandler)delegate + { + bool isInside = false; + + foreach (DataRow item in this.details.Rows) + { + if (this.details.Columns.Contains("orderId") && !string.IsNullOrWhiteSpace(item["orderId"] + "") && int.Parse(item["orderId"] + "") < 0) + { + continue; + } + + XtraTabPage tabPage = new XtraTabPage(); + GridDetailModel detailModel = new GridDetailModel(item, null, GridCustomColumnStruct.BaseDetailGridView); + if (!string.IsNullOrEmpty(detailModel.UnionModule)) + { + ModuleModel moduleModel = new ModuleModel(MainImpl.GetSystemdllTab(detailModel.UnionModule)); + if (string.IsNullOrWhiteSpace(moduleModel.FormKey)) + { + string text = Business.Impl.LanguageTranslation.Translatable ? Business.Impl.LanguageTranslation.GetTranslatedText("模块配置错误") : "模块配置错误"; + MessageUtil.Show(detailModel.DetailName + text); + return; + } + detailModel.DetailSql = moduleModel.MenuSql; + } + detailModel.GridColumns = ReportImpl.GetReportDetailColumns(Model.ModuleCode, item["id"] + ""); + tabPage.Text = detailModel.DetailName; + tabPage.Tag = detailModel; + if (ModuleAddControl.plMainControlObj.Tag is XtraTabControl) + { + XtraTabControl xtr = ModuleAddControl.plMainControlObj.Tag as XtraTabControl; + xtr.TabPages.Add(tabPage); + isInside = true; + xtr.SelectedPageChanged += new DevExpress.XtraTab.TabPageChangedEventHandler(this.OnSelectedPageChanged); + xtr.SelectedPageChanging += new DevExpress.XtraTab.TabPageChangingEventHandler(this.OnSelectedPageChanging); + } + else + { + this.xtcControl.TabPages.Add(tabPage); + } + } + + this.xtcControl.ShowTabHeader = details.Rows.Count > 0 && !isInside ? DefaultBoolean.True : DefaultBoolean.False; + }); + } + + /// + /// 说明:创建控件 + /// 创建人:龚宇超 + /// 创建日期:2017-11-03 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + private void CreateControlLocation() + { + this.ModuleAddControl.SavaState = Model.SaveState.Equals("1"); + this.ModuleAddControl.IsView = Model.IsView; + this.ModuleAddControl.ParentKey = Model.ParentKey; + this.ModuleAddControl.ParentValue = Model.ParentValue; + this.ModuleAddControl.PrimaryKey = this.SysModel.ParmaryKey;// BaseImpl.GetBasePrimaryKey(Model.ModuleCode); 和上方获取主键执行方法相同,直接取上方的值 + this.ModuleAddControl.UnionKey = Model.UnionKey; + this.ModuleAddControl.UnionValue = Model.UnionValue; + this.ModuleAddControl.PrimaryValue = Model.ObjectId; + this.ModuleAddControl.ControlSql = Model.ControlSql; + this.ModuleAddControl.OnCloseCallback += new EventHandler(OnCloseCallback); + this.ModuleAddControl.SearchObject = Model.SearchObject; + + if (this.details.Columns.Contains("orderId")) + { + DataRow[] dataRows = details.Select("orderId<0"); + this.ModuleAddControl.DetailsData = dataRows; + } + + this.ModuleAddControl.InitializeControl(SysModel, Model, isAutoScroll); + + } + + /// + /// 说明:关闭按钮回调 + /// 创建人:龚宇超 + /// 创建日期:2017-11-08 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + protected void OnCloseCallback(object sender, EventArgs e) + { + try + { + this.DialogResult = DialogResult.OK; + this.Close(); + } + catch (Exception ex) + { + string Message = ErrorMessage.PromptErrorMessage(ex); + MessageUtil.Show(Message, ex.Message); + } + } + /// + /// 说明:查询条件执行前 + /// 创建人:龚宇超 + /// 创建日期:2017-11-10 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The sender. + /// The e. + protected void OnSearchBefore(object sender, SearchArgs e) + { + try + { + XtraTabPage tabPage = xtcControl.SelectedTabPage; + if (ModuleAddControl.plMainControlObj.Tag is XtraTabControl) + { + XtraTabControl xtr = ModuleAddControl.plMainControlObj.Tag as XtraTabControl; + tabPage = xtr.SelectedTabPage; + } + if (tabPage != null) + { + ModuleGridEx moduleGrid = tabPage.Tag as ModuleGridEx; + GridDetailModel detailModel = moduleGrid.Tag as GridDetailModel; + + moduleGrid.SearchObj.SearchGrid(detailModel.DetailSql + string.Format(" and {0}='{1}'", moduleGrid.DetailKeyField, moduleGrid.UnionValue)); + } + e.Continue = false; + } + catch (Exception ex) + { + string Message = ErrorMessage.PromptErrorMessage(ex); + MessageUtil.Show(Message, ex.Message); + } + } + /// + /// 说明:查询条件执行后 + /// 创建人:龚宇超 + /// 创建日期:2017-11-10 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + protected void OnSearchAfter(object sender, EventArgs e) + { + try + { + XtraTabPage tabPage = xtcControl.SelectedTabPage; + if (ModuleAddControl.plMainControlObj.Tag is XtraTabControl) + { + XtraTabControl xtr = ModuleAddControl.plMainControlObj.Tag as XtraTabControl; + tabPage = xtr.SelectedTabPage; + } + if (tabPage != null) + { + if (tabPage.Tag is ModuleGridEx) + { + ModuleGridEx moduleGrid = tabPage.Tag as ModuleGridEx; + GridDetailModel detailModel = moduleGrid.Tag as GridDetailModel; + tabPage.Text = detailModel.DetailName + "(" + moduleGrid.SearchObj.GridRowCount + "条)"; + } + else if (tabPage.Tag is GridControlEx) + { + + GridControlEx moduleGrid = tabPage.Tag as GridControlEx; + GridDetailModel detailModel = moduleGrid.Tag as GridDetailModel; + tabPage.Text = detailModel.DetailName + "(" + moduleGrid.DataRowCount() + "条)"; + } + + } + } + catch (Exception ex) + { + string Message = ErrorMessage.PromptErrorMessage(ex); + MessageUtil.Show(Message, ex.Message); + } + } + /// + /// 说明:切换选项卡 + /// 创建人:龚宇超 + /// 创建日期:2018-04-09 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + protected void OnSelectedPageChanging(object sender, TabPageChangingEventArgs e) + { + try + { + XtraTabPage page = e.Page; + if (page != null) + { + if (e.PrevPage == xtcControl.TabPages[0] && string.IsNullOrEmpty(this.ModuleAddControl.PrimaryValue)) + { + MessageUtil.Show(ResourceKeys.BeforeSaveData); + e.Cancel = true; + } + } + } + catch (Exception ex) + { + string Message = ErrorMessage.PromptErrorMessage(ex); + MessageUtil.Show(Message, ex.Message); + } + } + /// + /// 说明:切换标签刷新主键值 + /// 创建人:龚宇超 + /// 创建日期:2018-04-09 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + protected void OnSelectedPageChanged(object sender, TabPageChangedEventArgs e) + { + try + { + + XtraTabPage tabPage = e.Page; + ModuleAddControl.OperatePanelControlObj.Visible = true; + //XtraTabPage tabPage = this.xtcControl.SelectedTabPage; + if (tabPage.Tag is ModuleGridEx) ModuleAddControl.OperatePanelControlObj.Visible = false; + if (!(tabPage.Tag is GridDetailModel)) return; + ModuleAddControl.OperatePanelControlObj.Visible = false; + if (tabPage.Controls.Count == 0) + { + + GridDetailModel detailModel = tabPage.Tag as GridDetailModel; + ModuleModel moduleModel = null; + DynamicAddModel addModel = new DynamicAddModel(new string[] { + detailModel.DetailName, + ERPInfo.Instance.UserId, + ERPInfo.Instance.UserName, + "1",detailModel.UnionModule,"","","" + }); + addModel.Params = Model.OtherParams(); + if (detailModel.IsWebView) + { + // 加载网页 + string url = detailModel.DetailSql.StartsWith("http") ? detailModel.DetailSql : SystemInfo.Instance.OAUrl + detailModel.DetailSql; + if (!string.IsNullOrWhiteSpace(Model.ParentKey)) + { + string codeSql = "select"; + codeSql += string.Format(" '{0}' as {1}", Model.ObjectId, this.SysModel.ParmaryKey); + url = ReplaceHelper.ReplaceRowParam(BaseImpl.GetDataRowResult(codeSql), ReplaceHelper.ReplaceWhereCond(detailModel.DetailSql)); + } + if (this.ModuleAddControl.ControlObj.CurrentData != null) url = ReplaceHelper.ReplaceRowParam(this.ModuleAddControl.ControlObj.CurrentData, url); + //url= System.Web.HttpUtility.UrlEncode(url); + + if (SystemInfo.Instance.PrimitiveBrowser) + { + FrmMiniBlink webView = new FrmMiniBlink(); + webView.IsDownVerify = true; + webView.Dock = DockStyle.Fill; + webView.Tag = detailModel; + tabPage.Tag = webView; + tabPage.Controls.Add(webView); + webView.LoadUrl(ReplaceHelper.ReplaceUserInfo(url)); + } + else + { + FrmWebBrowser webView = new FrmWebBrowser(); + webView.Dock = DockStyle.Fill; + webView.Tag = detailModel; + tabPage.Tag = webView; + tabPage.Controls.Add(webView); + webView.FrmLoad(ReplaceHelper.ReplaceUserInfo(url)); + } + } + else if (detailModel.IsWebView2) + { + // 加载网页 + string url = detailModel.DetailSql.StartsWith("http") ? detailModel.DetailSql : SystemInfo.Instance.OAUrl + detailModel.DetailSql; + //url= System.Web.HttpUtility.UrlEncode(url); + if (this.ModuleAddControl.ControlObj.CurrentData != null) url = ReplaceHelper.ReplaceRowParam(this.ModuleAddControl.ControlObj.CurrentData, url); + if (SystemInfo.Instance.PrimitiveBrowser) + { + FrmMiniBlink webView = new FrmMiniBlink(); + webView.Dock = DockStyle.Fill; + webView.Tag = detailModel; + tabPage.Tag = webView; + tabPage.Controls.Add(webView); + webView.LoadUrl(ReplaceHelper.ReplaceUserInfo(url)); + } + else + { + FrmWebBrowser2 webView = new FrmWebBrowser2(); + webView.Dock = DockStyle.Fill; + webView.Tag = detailModel; + tabPage.Tag = webView; + tabPage.Controls.Add(webView); + webView.FrmLoad(ReplaceHelper.ReplaceUserInfo(url)); + } + } + else if (detailModel.IsWebView3) + { + // 加载网页 + string url = detailModel.DetailSql.StartsWith("http") ? detailModel.DetailSql : SystemInfo.Instance.OAUrl + detailModel.DetailSql; + //url= System.Web.HttpUtility.UrlEncode(url); + if (this.ModuleAddControl.ControlObj.CurrentData != null) url = ReplaceHelper.ReplaceRowParam(this.ModuleAddControl.ControlObj.CurrentData, url); + if (SystemInfo.Instance.PrimitiveBrowser) + { + FrmMiniBlink webView = new FrmMiniBlink(); + webView.AllowDownload = false; + webView.Dock = DockStyle.Fill; + webView.Tag = detailModel; + tabPage.Tag = webView; + tabPage.Controls.Add(webView); + webView.LoadUrl(ReplaceHelper.ReplaceUserInfo(url)); + } + else + { + FrmWebBrowser2 webView = new FrmWebBrowser2(); + webView.Dock = DockStyle.Fill; + webView.Tag = detailModel; + webView.AllowDownload = false; + tabPage.Tag = webView; + tabPage.Controls.Add(webView); + webView.FrmLoad(ReplaceHelper.ReplaceUserInfo(url)); + } + } + else if (string.IsNullOrEmpty(detailModel.UnionModule)) + { + PanelControl plBottom = new PanelControl(); + plBottom.Dock = DockStyle.Bottom; + plBottom.Visible = false; + PanelControl plMain = new PanelControl(); + plMain.Dock = DockStyle.Fill; + GridControlEx gridEx = detailModel.AutoMultiHeader == 1 ? new BandedGridControlEx() : new GridControlEx(); + gridEx.Dock = DockStyle.Fill; + gridEx.Tag = detailModel; + gridEx.Parent = plMain; + gridEx.Model = this.Model; + gridEx.SetReadOnlyColumns(detailModel.GridColumns, detailModel.GridCustomColumnKey); + //gridEx.SetGridRightMenus(BaseModuleImpl.GetBaseGridRightMenus(model.FormKey), this.Model, OnGridViewRightCallBack); + //gridEx.SetGridRowColors(BaseModuleImpl.GetBaseGridRowColors(model.FormKey)); + + gridEx.SetGridRightMenus(BaseModuleImpl.GetBaseGridRightMenus(detailModel.FormKey), this.Model); + gridEx.SetGridRowColors(BaseModuleImpl.GetBaseGridRowColors(detailModel.FormKey)); + if (detailModel.IsCheck == 1)//加载复选框 + { + GridDragGrid.GridAddCheckBox(gridEx.GridView); + } + // 加载配置查询条件 + if (Model != null && Model.IsDetailSearch) + { + plBottom.Visible = true; + MyControl searchObj = new MyControl(detailModel.DetailSql, gridEx); + plBottom.Height = searchObj.InitSearchControl(BaseModuleImpl.GetCustomQueryFields(detailModel.FormKey), plBottom); + } + tabPage.Tag = gridEx; + tabPage.Controls.AddRange(new PanelControl[] { plBottom, plMain }); + if (detailModel.AutoRefresh) + { + if (!string.IsNullOrWhiteSpace(this.ModuleAddControl.ParentKey)) + { + string codeSql = "select"; + codeSql += string.Format(" '{0}' as {1}", this.ModuleAddControl.PrimaryValue, this.ModuleAddControl.PrimaryKey); + gridEx.SetGridViewDataSource(SqlHelper.ExecuteDataTable(ReplaceHelper.ReplaceRowParam(BaseImpl.GetDataRowResult(codeSql), ReplaceHelper.ReplaceWhereCond(detailModel.DetailSql)))); + } + else if (this.ModuleAddControl.ControlObj.CurrentData != null) + { + gridEx.SetGridViewDataSource(SqlHelper.ExecuteDataTable(ReplaceHelper.ReplaceRowParam(this.ModuleAddControl.ControlObj.CurrentData, ReplaceHelper.ReplaceWhereCond(detailModel.DetailSql)))); + } + // 自动刷新 + } + } + else + { + + moduleModel = new ModuleModel(MainImpl.GetSystemdllTab(detailModel.UnionModule)); + moduleModel.maintabFocusedRow = SysModel.maintabFocusedRow; + ModuleGridEx moduleGrid = new ModuleGridEx(); + moduleGrid.IsDetail = true; + moduleGrid.Dock = DockStyle.Fill; + moduleGrid.Tag = detailModel; + moduleGrid.ParentKeyField = string.IsNullOrEmpty(detailModel.UnionParentField) ? SysModel.ParmaryKey : detailModel.UnionParentField; + + //直接在控件数据源中取值,控件可能是禁显状态(没用控件获取不到值) + if (!string.IsNullOrWhiteSpace(moduleGrid.ParentKeyField) && this.ModuleAddControl.ControlObj.CurrentData.Table.Columns.Contains(moduleGrid.ParentKeyField)) + { + moduleGrid.ParentKeyValue = moduleGrid.UnionValue = this.ModuleAddControl.ControlObj.CurrentData[moduleGrid.ParentKeyField] + ""; + } + + if (detailModel.AddHideBottomPanel || detailModel.HideBottomPanel || detailModel.Library.Equals("Lskj.Report.dll", StringComparison.OrdinalIgnoreCase)) + { + moduleGrid.VisibleOperPanel = false; + } + + //moduleGrid.ParentKeyValue = this.ModuleAddControl.ControlObj.GetControlValue(moduleGrid.ParentKeyField); + moduleGrid.DetailKeyField = detailModel.UnionValue; + moduleGrid.UnionKey = detailModel.UnionValue; + //moduleGrid.UnionValue = this.ModuleAddControl.ControlObj.GetControlValue(moduleGrid.ParentKeyField); //Model.ObjectId; + moduleGrid.SearchControlSql = Model.ControlSql; + moduleGrid.InitializeControl(moduleModel, addModel); + moduleGrid.SearchObj.OnSearchBeforeCallBack += new SearchEventHandler(OnSearchBefore); + moduleGrid.SearchObj.OnSearchAfterCallBack += new EventHandler(OnSearchAfter); + Lskj.Control.Model.AutoSizeChange.ControllInitializeSize(moduleGrid); + tabPage.Controls.Add(moduleGrid); + tabPage.Tag = moduleGrid; + if (detailModel.AutoRefresh) + { + moduleGrid.SearchObj.OnDataSourceBindCallBack += new EventHandler(OnMainSearchDataSourceBindCallBack); + // 自动刷新 + //moduleGrid.SearchObj.SearchGrid(ReplaceHelper.ReplaceWhereCond(moduleModel.MenuSql) + string.Format(" and {0}='{1}'", moduleGrid.DetailKeyField, moduleGrid.UnionValue)); + } + } + } + } + catch (Exception ex) + { + string Message = ErrorMessage.PromptErrorMessage(ex); + MessageUtil.Show(Message, ex.Message); + } + } + /// + /// 说明:查询条件绑定完成查询数据 + /// 创建人:龚宇超 + /// 创建日期: + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The sender. + /// The instance containing the event data. + protected void OnMainSearchDataSourceBindCallBack(object sender, EventArgs e) + { + try + { + MyControl searchobj = sender as MyControl; + //if (!string.IsNullOrEmpty(this.SysModel.CustomColumnSQL)) + //{ + // BaseImpl.ExecSqlValue(searchobj.ReplaceControlValue(this.SysModel.CustomColumnSQL)); + //} + searchobj.SearchGrid(); + OnSearchAfter(null, null); + } + catch (Exception ex) + { + string Message = ErrorMessage.PromptErrorMessage(ex); + MessageUtil.Show(Message, ex.Message); + } + + } + /// + /// 清理后回调 + /// + /// + /// + private void OnClearCallBack(object sender, EventArgs e) + { + //新增时输入焦点 + ControlModel controlModel = ModuleAddControl.ControlObj.ControlModels.Where(n => n.Location.X != 0 || n.Location.Y != 0).OrderBy(n => n.TabOrder).FirstOrDefault(); + if (controlModel != null) + { + BaseUserControl baseControl = ModuleAddControl.ControlObj.FindControl(controlModel); + if (baseControl != null) + { + baseControl.Focus(); + } + } + } + /// + /// 添加保存成功后执行 + /// + /// + /// + private void OnAddRecordCallBack(object sender, EventArgs e) + { + FormDialogModel dialogModel = new FormDialogModel() + { + DialogDllName = "Lskj.PubAdd.dll", + PubDialogType = DialogType.PubAddRecord, + ReturnTag = ModuleAddControl.ControlObj + }; + this.Tag = dialogModel; + } + /// + /// 分割条位置改变时 + /// + /// + /// private void OnSplitterPositionChanged(object sender, EventArgs e) { IniHelper.Write(string.Format("ModulePanelExAdd_Split_{0}", this.Model.ModuleCode), this.ModuleAddControl.SplitContainerControl.SplitterPosition + ""); } - /// - /// 说明:窗口关闭 - /// 创建人:龚宇超 - /// 创建日期:2019-07-15 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - protected void OnFormClosed(object sender, FormClosedEventArgs e) - { - if (this.ModuleAddControl.ControlObj != null) - { - this.ModuleAddControl.ControlObj.ReleaseImageResources(); - } - } - /// - /// 说明:窗口关闭之前 - /// 创建人:龚宇超 - /// 创建日期:2019-07-15 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - protected void OnFormClosing(object sender, FormClosingEventArgs e) - { - try - { - if (this.ModuleAddControl != null && this.ModuleAddControl.IsCard) - { - this.ModuleAddControl.CloseIDCardThread(); - } - this.DialogResult = DialogResult.OK; - } - catch (Exception ex) - { - string Message = ErrorMessage.PromptErrorMessage(ex); - MessageUtil.Show(Message, ex.Message); - } - } - protected override CreateParams CreateParams - { - get - { - CreateParams cp = base.CreateParams; - cp.ExStyle |= 0x02000000; - return cp; - } - } - } -} + /// + /// 说明:窗口关闭 + /// 创建人:龚宇超 + /// 创建日期:2019-07-15 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + protected void OnFormClosed(object sender, FormClosedEventArgs e) + { + if (this.ModuleAddControl.ControlObj != null) + { + this.ModuleAddControl.ControlObj.ReleaseImageResources(); + } + } + /// + /// 说明:窗口关闭之前 + /// 创建人:龚宇超 + /// 创建日期:2019-07-15 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + protected void OnFormClosing(object sender, FormClosingEventArgs e) + { + try + { + if (this.ModuleAddControl != null && this.ModuleAddControl.IsCard) + { + this.ModuleAddControl.CloseIDCardThread(); + } + this.DialogResult = DialogResult.OK; + } + catch (Exception ex) + { + string Message = ErrorMessage.PromptErrorMessage(ex); + MessageUtil.Show(Message, ex.Message); + } + } + protected override CreateParams CreateParams + { + get + { + CreateParams cp = base.CreateParams; + cp.ExStyle |= 0x02000000; + return cp; + } + } + } +} diff --git a/插件库/Lskj.PubBillManagement/BillModule.cs b/插件库/Lskj.PubBillManagement/BillModule.cs index 912ef9c..c725762 100644 --- a/插件库/Lskj.PubBillManagement/BillModule.cs +++ b/插件库/Lskj.PubBillManagement/BillModule.cs @@ -1,552 +1,552 @@ -using DevExpress.Data; -using DevExpress.Utils; -using DevExpress.XtraBars; -using DevExpress.XtraEditors; -using DevExpress.XtraGrid.Columns; -using DevExpress.XtraGrid.Views.Base; -using DevExpress.XtraGrid.Views.Grid; -using DevExpress.XtraTab; -using DevExpress.XtraTreeList.Columns; -using DevExpress.XtraTreeList.Nodes; -using Lskj.Business; -using Lskj.Business.Impl; -using Lskj.Control; -using Lskj.Control.BrowserSetting; -using Lskj.Control.Model; -using Lskj.Core; -using Lskj.Data; -using Lskj.Model; -using Lskj.PubBillManagement.Model; -using Lskj.Util; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using System; -using System.Collections; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Data.SqlClient; -using System.Drawing; -using System.IO; -using System.Linq; -using System.Net; -using System.Reflection; -using System.Text; -using System.Text.RegularExpressions; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace Lskj.PubBillManagement -{ - public partial class BillModule : UserControl - { - private static void AttachCachedTask( - Dictionary cachesDic, - object cacheOwner, - string cacheKey, - object control, - string controlKey) - { - if (cachesDic == null || cacheOwner == null || control == null || - cachesDic.GetTask(control, controlKey) != null) - { - return; - } - - Task task = cachesDic.GetTask(cacheOwner, cacheKey); - if (task != null) - cachesDic.AddTask(control, controlKey, task); - } - - /// - /// 是否为初始化创建 - /// - private bool _isInitFinish; - /// - /// 是否加载右侧控件数据 - /// - private bool _isLoadRightControlValue = true; - /// - /// 是否手动选择了模版 - /// - private bool _isSelectedTemplete; - /// - /// 是否直接打印 - /// - private bool _isExcPrint; - /// - /// 是否选择关联下发 - /// - private bool _isCheck; - /// - /// 主打印Sql - /// - private string _mainPrintSql; - private string guidField = "xxxxx_guid"; - /// - /// 主键字段 - /// - private string mRecordPrimaryField; - /// - /// 单据水印 - /// - private WaterMark _waterMark; - /// - /// 导入单据明细数据、导入单据明细并更新 - /// - private BarButtonItem _itemImport, _itemImportUpdate; - /// - /// 打印主sql中关联打印次数返回条件 - /// - private string _printModeCond; - /// - /// 打印完成后添加数据用到的参数: 表名,列前缀,主键字段,主键值,模块编号,主打印Sql - /// - private List _printSaveParams; - /// - /// 单据明细列 - /// - private DataTable _detailColumns; - private bool IsCopying = false; - - - protected DataRow BillRowItem; - /// - /// 主表控件 - /// - public MyControl ControlObj; - /// - /// 入口参数 - /// - protected DynamicBillModel SysModel; - /// - /// 是否为Brp模版 - /// - /// true if this instance is BRP templete; otherwise, false. - protected bool IsBrpTemplete { get { return SysModel is DynamicBillBrpModel; } } - /// - /// - /// - public BillModel BillModel; - /// - /// 数量名称 - /// - public string NumberMc; - /// - /// 红字单据的分配管理模块 - /// - public string rdRedUnionCode; - /// - /// 蓝字单据的分配管理模块 - /// - public string rdBlueUnionCode; - /// - /// 蓝字单据的分配管理模块 - /// - Dictionary pageNumKey = new Dictionary(); - /// - /// 是否拖拽换行展示 - /// - public bool isDragWrap = true; - /// - /// 触发主表改变刷新来源限制 - /// - private bool IsBillMaster = true; - /// - /// 是否执行了加载储存过程 - /// - //public bool ProcessExists = false; - /// - /// 保存或修改时报错信息 - /// - public string SaveErrorMessage = string.Empty; - /// - /// 单据明细删除的行 - /// - // private Dictionary ToWithdrawRows = new Dictionary(); - private List> ToWithdrawRows = new List>(); - /// - ///改变颜色行 - /// - private List ChangeColorRow = new List(); - /// - /// - /// - public string AssociatedField = string.Empty; - /// - /// 注册设置公共事件私有类 - /// - private static PubEvenImpl _eventHandler; - /// - /// 注册设置公共事件类 - /// - private static PubEvenImpl eventHandler; - /// - /// 当前人员是否有导出权限 - /// - public bool ExportPermission; - /// - /// 是否显示单据管理条数 - /// - public bool IsBillShowCount = false; - /// - /// 来源明细的页面名字后缀(设置成全局变量,更好的处理语言翻译的情况) - /// - public string DetailedSuffix = Business.Impl.LanguageTranslation.Translatable ? "-" + Business.Impl.LanguageTranslation.GetTranslatedText("明细") : "-明细"; - /// - /// 数量后缀 - /// - public string QuantitySuffix = Business.Impl.LanguageTranslation.Translatable ? Business.Impl.LanguageTranslation.GetTranslatedText("条") + ")" : "条)"; - /// - /// 新增 - /// - public string addText = Business.Impl.LanguageTranslation.Translatable ? "(" + Business.Impl.LanguageTranslation.GetTranslatedText("新增") + ")" : "(新增)"; - /// - /// 修改 - /// - public string updateText = Business.Impl.LanguageTranslation.Translatable ? "(" + Business.Impl.LanguageTranslation.GetTranslatedText("修改") + ")" : "(修改)"; - - - /// - /// 单据来源控件集合 - /// - public Dictionary BillModuleModelDic = new Dictionary(); - /// - /// 主表动态生成的日期列 - /// - public List DateColumnList = new List(); - /// - /// 主表动态生成的合计列 - /// - public GridColumn SumGridColumn = new GridColumn(); - /// - /// 附加右键菜单集合 - /// - public List itemCommonList = new List(); - /// - /// 是否已经添加了多行汇总 - /// - public bool MultiLineSummary; - /// - /// 扫码框 - /// - public TextEdit ScanCodeTextEdit = null; - /// - /// 初始化时选中的页签 - /// - public XtraTabPage InitialSelectionTab = null; - /// - /// 当前操作的ImageEdit - /// - private LabelImageEdit _imageEdit; - /// - /// 当前来源明细中变色行 - /// - private HashSet ColorHandles = new HashSet(); - /// - /// 保存验证条件表 - /// - public DataTable SaveCondTab = new DataTable(); - - - +using DevExpress.Data; +using DevExpress.Utils; +using DevExpress.XtraBars; +using DevExpress.XtraEditors; +using DevExpress.XtraGrid.Columns; +using DevExpress.XtraGrid.Views.Base; +using DevExpress.XtraGrid.Views.Grid; +using DevExpress.XtraTab; +using DevExpress.XtraTreeList.Columns; +using DevExpress.XtraTreeList.Nodes; +using Lskj.Business; +using Lskj.Business.Impl; +using Lskj.Control; +using Lskj.Control.BrowserSetting; +using Lskj.Control.Model; +using Lskj.Core; +using Lskj.Data; +using Lskj.Model; +using Lskj.PubBillManagement.Model; +using Lskj.Util; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Data.SqlClient; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Net; +using System.Reflection; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Lskj.PubBillManagement +{ + public partial class BillModule : UserControl + { + private static void AttachCachedTask( + Dictionary cachesDic, + object cacheOwner, + string cacheKey, + object control, + string controlKey) + { + if (cachesDic == null || cacheOwner == null || control == null || + cachesDic.GetTask(control, controlKey) != null) + { + return; + } + + Task task = cachesDic.GetTask(cacheOwner, cacheKey); + if (task != null) + cachesDic.AddTask(control, controlKey, task); + } + + /// + /// 是否为初始化创建 + /// + private bool _isInitFinish; + /// + /// 是否加载右侧控件数据 + /// + private bool _isLoadRightControlValue = true; + /// + /// 是否手动选择了模版 + /// + private bool _isSelectedTemplete; + /// + /// 是否直接打印 + /// + private bool _isExcPrint; + /// + /// 是否选择关联下发 + /// + private bool _isCheck; + /// + /// 主打印Sql + /// + private string _mainPrintSql; + private string guidField = "xxxxx_guid"; + /// + /// 主键字段 + /// + private string mRecordPrimaryField; + /// + /// 单据水印 + /// + private WaterMark _waterMark; + /// + /// 导入单据明细数据、导入单据明细并更新 + /// + private BarButtonItem _itemImport, _itemImportUpdate; + /// + /// 打印主sql中关联打印次数返回条件 + /// + private string _printModeCond; + /// + /// 打印完成后添加数据用到的参数: 表名,列前缀,主键字段,主键值,模块编号,主打印Sql + /// + private List _printSaveParams; + /// + /// 单据明细列 + /// + private DataTable _detailColumns; + private bool IsCopying = false; + + + protected DataRow BillRowItem; + /// + /// 主表控件 + /// + public MyControl ControlObj; + /// + /// 入口参数 + /// + protected DynamicBillModel SysModel; + /// + /// 是否为Brp模版 + /// + /// true if this instance is BRP templete; otherwise, false. + protected bool IsBrpTemplete { get { return SysModel is DynamicBillBrpModel; } } + /// + /// + /// + public BillModel BillModel; + /// + /// 数量名称 + /// + public string NumberMc; + /// + /// 红字单据的分配管理模块 + /// + public string rdRedUnionCode; + /// + /// 蓝字单据的分配管理模块 + /// + public string rdBlueUnionCode; + /// + /// 蓝字单据的分配管理模块 + /// + Dictionary pageNumKey = new Dictionary(); + /// + /// 是否拖拽换行展示 + /// + public bool isDragWrap = true; + /// + /// 触发主表改变刷新来源限制 + /// + private bool IsBillMaster = true; + /// + /// 是否执行了加载储存过程 + /// + //public bool ProcessExists = false; + /// + /// 保存或修改时报错信息 + /// + public string SaveErrorMessage = string.Empty; + /// + /// 单据明细删除的行 + /// + // private Dictionary ToWithdrawRows = new Dictionary(); + private List> ToWithdrawRows = new List>(); + /// + ///改变颜色行 + /// + private List ChangeColorRow = new List(); + /// + /// + /// + public string AssociatedField = string.Empty; + /// + /// 注册设置公共事件私有类 + /// + private static PubEvenImpl _eventHandler; + /// + /// 注册设置公共事件类 + /// + private static PubEvenImpl eventHandler; + /// + /// 当前人员是否有导出权限 + /// + public bool ExportPermission; + /// + /// 是否显示单据管理条数 + /// + public bool IsBillShowCount = false; + /// + /// 来源明细的页面名字后缀(设置成全局变量,更好的处理语言翻译的情况) + /// + public string DetailedSuffix = Business.Impl.LanguageTranslation.Translatable ? "-" + Business.Impl.LanguageTranslation.GetTranslatedText("明细") : "-明细"; + /// + /// 数量后缀 + /// + public string QuantitySuffix = Business.Impl.LanguageTranslation.Translatable ? Business.Impl.LanguageTranslation.GetTranslatedText("条") + ")" : "条)"; + /// + /// 新增 + /// + public string addText = Business.Impl.LanguageTranslation.Translatable ? "(" + Business.Impl.LanguageTranslation.GetTranslatedText("新增") + ")" : "(新增)"; + /// + /// 修改 + /// + public string updateText = Business.Impl.LanguageTranslation.Translatable ? "(" + Business.Impl.LanguageTranslation.GetTranslatedText("修改") + ")" : "(修改)"; + + + /// + /// 单据来源控件集合 + /// + public Dictionary BillModuleModelDic = new Dictionary(); + /// + /// 主表动态生成的日期列 + /// + public List DateColumnList = new List(); + /// + /// 主表动态生成的合计列 + /// + public GridColumn SumGridColumn = new GridColumn(); + /// + /// 附加右键菜单集合 + /// + public List itemCommonList = new List(); + /// + /// 是否已经添加了多行汇总 + /// + public bool MultiLineSummary; + /// + /// 扫码框 + /// + public TextEdit ScanCodeTextEdit = null; + /// + /// 初始化时选中的页签 + /// + public XtraTabPage InitialSelectionTab = null; + /// + /// 当前操作的ImageEdit + /// + private LabelImageEdit _imageEdit; + /// + /// 当前来源明细中变色行 + /// + private HashSet ColorHandles = new HashSet(); + /// + /// 保存验证条件表 + /// + public DataTable SaveCondTab = new DataTable(); + + + public BillModule() { InitializeComponent(); } - - #region 初始化操作 - /// - /// 说明:窗口加载 - /// 创建人:龚宇超 - /// 创建日期:2017-11-23 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The instance containing the event data. - public void OnLoad(DynamicBillModel Model) - { - try - { + + #region 初始化操作 + /// + /// 说明:窗口加载 + /// 创建人:龚宇超 + /// 创建日期:2017-11-23 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The instance containing the event data. + public void OnLoad(DynamicBillModel Model) + { + try + { this.SysModel = Model;// 单据动态链接库参数,入口参数 this._isInitFinish = false;// 是否为初始化创建 - this.ssc_main.Visible = false; //获取或设置一个值,该值指示是否显示该控件及其所有子控件。 - //this.ProcessExists = (Lskj.Data.Caches.CacheSYSConfig.Instance().JudgeProcessExists() && SystemInfo.Instance.isExecload); - - - - Dictionary dataCaches = Model != null ? Model.DataCaches : null; - dataCaches.GetValue(this, "DataCaches", out bool _);//等待缓存数据加载完成 + this.ssc_main.Visible = false; //获取或设置一个值,该值指示是否显示该控件及其所有子控件。 + //this.ProcessExists = (Lskj.Data.Caches.CacheSYSConfig.Instance().JudgeProcessExists() && SystemInfo.Instance.isExecload); + + + + Dictionary dataCaches = Model != null ? Model.DataCaches : null; + dataCaches.GetValue(this, "DataCaches", out bool _);//等待缓存数据加载完成 this.InitializeSetting();//初始化系统配置 this.InitializeControl();//初始化控件 this.InitlizeSpiltLocation(); - - } - catch (Exception ex) - { - LogHelper.Instance.WriteError(ex); - LogUtil.WriteError("单据初始化窗体失败!", ex); - MessageUtil.Show(ex.StackTrace); - } + + } + catch (Exception ex) + { + LogHelper.Instance.WriteError(ex); + LogUtil.WriteError("单据初始化窗体失败!", ex); + MessageUtil.Show(ex.StackTrace); + } finally { this._isInitFinish = true; this.ssc_main.Visible = true; - } - } - - - /// - /// 获取数据源缓存 - /// - /// - public void GetDataCaches(Dictionary cachesDic) - { - //获取通用数据 - Task sysModelTask = cachesDic.GetTask(this, "SysModel"); - Task systemDllRowTask = cachesDic.GetTask(this, "SystemDllRow"); - Task dynamicModelTask = cachesDic.GetTask(this, "DynamicModel"); - Task getDataCachesTask = cachesDic.AddTask(this, "DataCaches", new Task(() => - { - DynamicBillModel dynamicModel = (DynamicBillModel)dynamicModelTask.Result; - #region InitializeSetting初始化系统配置 - Task billInfoRowTask = cachesDic.AddTask(this, "BillInfo", new Task(() => - { - return BillImpl.GetBillInfo(dynamicModel.ModuleCode);//获取单个模块信息 - })); - Task billModelTask = cachesDic.AddTask(this, "BillModel", new Task(() => - { - BillModel model = null; - if (billInfoRowTask.Result != null) - { - model = new BillModel(billInfoRowTask.Result); - } - return model; - })); - BillModel billModel = billModelTask.Result; - if (billModel != null) - { - Task masterPreFixTask = cachesDic.AddTask(this, "MasterPreFix", new Task(() => - { - return BaseImpl.GetColumnPrefix(billModel.MasterTable);// 主表列前缀 - })); - Task detailPreFixTask = cachesDic.AddTask(this, "DetailPreFix", new Task(() => - { - return BaseImpl.GetColumnPrefix(billModel.DetailTable);// 明细表列前缀 - })); - } - Task menuConfigTabTask = cachesDic.AddTask(this, "MenuConfigTab", new Task(() => - { - DataRow dataRow = BaseImpl.GetMenuConfigTab(dynamicModel.ModuleId); - if (dataRow != null) - { - billModel.BillSourceIds = dataRow.Table.Columns.Contains("BillSourceIds") ? (dataRow["BillSourceIds"] + "").Trim(',') : string.Empty; - billModel.BillFlag = dataRow.Table.Columns.Contains("BillFlag") && !string.IsNullOrEmpty(dataRow["BillFlag"] + "") ? Convert.ToInt32(dataRow["BillFlag"] + "") : -1; - //billModel - } - return dataRow;//获取菜单其他配置 - })); - #region GetPrintOtherParam获取打印其他参数 - if (string.IsNullOrEmpty(billModel.PrintSql) && billModel.PrintSql.Contains("<<")) - { - string[] strs = billModel.PrintSql.Split(new[] { ">>" }, 2, StringSplitOptions.None); - _mainPrintSql = strs[1]; - _printModeCond = strs[0].Replace("<<", ""); - } - if (!string.IsNullOrEmpty(_printModeCond) && _printModeCond.IndexOf(';') > 0) - { - string[] str = _printModeCond.Split(';'); - Task printOtherSystemRowTask = cachesDic.AddTask(this, "PrintOtherSystemRow", new Task(() => - { - return AttachImpl.GetSystemModule(str[0]); - })); - Task printOtherColumnPrefixTask = cachesDic.AddTask(this, "PrintOtherColumnPrefix", new Task(() => - { - string tableName = printOtherSystemRowTask.Result["TableName"] + ""; - return BaseImpl.GetColumnPrefix(tableName); - })); - Task printOtherPrimaryKeyTask = cachesDic.AddTask(this, "PrintOtherPrimaryKey", new Task(() => - { - string modetype = printOtherSystemRowTask.Result["modType"] + ""; - return modetype == "1" ? BaseImpl.GetBasePrimaryKey(str[0]) : printOtherColumnPrefixTask.Result + "billdocument_id"; - })); - Task printOtherIsExcPrintTask = cachesDic.AddTask(this, "PrintOtherIsExcPrint", new Task(() => - { - string modetype = printOtherSystemRowTask.Result["modType"] + ""; - switch (modetype) - { - case "1": - ModuleModel mode = new ModuleModel(MainImpl.GetSystemdllTab(str[0])); - if (mode != null) - { - return mode.PrintType == 3; - } - break; - case "2": - BaseAccraditationModel model = new BaseAccraditationModel(BillAuditImpl.GetPubAuditProperty(str[0])); - if (model != null) - { - return model.BillPrintType == 3; - } - break; - } - return false; - })); - } - #endregion - Task billSettingTask = cachesDic.AddTask(this, "BillSetting", new Task(() => - { - BillImpl.InitBillSetting(billModel); - return true; - })); - #endregion - - - if (billModel.PanelWidth > 0) - { - #region InitializeBillSource初始化单据来源 - Task> detailTask = cachesDic.AddTask(this, "Details", new Task>(() => - { - List details = new List(); - DataTable table = BaseAuditImpl.GetAttachTabs(dynamicModel.ModuleCode, "100", " and orderid < 0 "); - foreach (DataRow item in table.Rows) - { - GridDetailModel gridDetailModel = new GridDetailModel(item, null, GridCustomColumnStruct.BillSourceDetailAttachGridView); - details.Add(gridDetailModel); - Task addGridColumnsTask = cachesDic.AddTask(gridDetailModel, "GridColumns", new Task(() => - { - DataTable gridColumns = BaseAuditImpl.GetBottomBasicInformation(item["formKey"] + ""); - gridDetailModel.GridColumns = gridColumns; - return gridColumns; - })); - } - return details; - })); - Task sourcesTask = cachesDic.AddTask(this, "Sources", new Task(() => - { - DataRow menuConfigRow = menuConfigTabTask.Result; - string SourceIds = (billModel.BillSourceIds + "").Trim(','); - if (!string.IsNullOrWhiteSpace(dynamicModel.SourceDetailsID)) - { - SourceIds = (SourceIds + "," + dynamicModel.SourceDetailsID).Trim(','); - } - return BillImpl.GetSources(dynamicModel.ModuleCode, SourceIds);//获取单据来源 - })); - cachesDic.AddTask(tb_buttom, "DynamicModel", dynamicModelTask); - cachesDic.AddTask(tb_buttom, "Details", detailTask); - // TabControlEx.GetDataCaches 会创建 Grid、ModuleGrid、浏览器等 - // WinForms/DevExpress 控件,延后到 InitializeBillSource - // 在 UI 线程执行。 - Task initSourcesTask = cachesDic.AddTask(this, "InitSourcesTask", new Task(() => - { - Hashtable htTable = sourcesTask.Result; - DataTable masterTable = htTable["master"] as DataTable; - for (int i = 0; i < masterTable.Rows.Count; i++) - { - DataRow sourceModelRow = masterTable.Rows[i]; - BillModuleModel billModuleModel = new BillModuleModel(); - BillSourceModel model = new BillSourceModel(sourceModelRow); - billModuleModel.SourceModel = model; - Task customQueryFieldsTask = cachesDic.AddTask(model, "CustomQueryFields", new Task(() => - { - return BaseModuleImpl.GetCustomQueryFields(model.FormKey); - })); - - // 后台阶段只加载数据,不构造任何 WinForms/DevExpress - // 对象。缓存以 BillModuleModel 为所有者,UI 创建实际 - // 控件后再绑定需要的任务。 - if (model.SourceType == 1) - { - cachesDic.AddTask(billModuleModel, "BindTreeTable", new Task(() => - { - return BaseImpl.GetDataTableResult(model.SourceSql); - })); - } - else - { - if (model.SourceType == 5) - model.ChangeSourceType(2);//单据来源显示条数 - - cachesDic.AddTask(billModuleModel, "SourceColumns", new Task(() => - { - return BillImpl.GetSourceColumns(model.Id); - })); - cachesDic.AddTask(billModuleModel, "SourceCustomColumnByDatabase", new Task(() => - { - return GridExtend.GetCustomColumnByDatabase( - GridCustomColumnStruct.BillSourceGridView + model.FormKey); - })); - cachesDic.AddTask(billModuleModel, "SourceBaseGridRowColors", new Task(() => - { - return BaseModuleImpl.GetBaseGridRowColors("BILLSOURCE_" + model.FormKey); - })); - cachesDic.AddTask(billModuleModel, "SourceBaseGridRightMenus", new Task(() => - { - return BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCE_" + model.FormKey); - })); - } - - if (string.IsNullOrWhiteSpace(model.DetailMenuCode)) - { - cachesDic.AddTask(billModuleModel, "SourceDetailCustomColumnByDatabase", new Task(() => - { - return GridExtend.GetCustomColumnByDatabase( - GridCustomColumnStruct.BillSourceDetailGridView + model.FormKey); - })); - cachesDic.AddTask(billModuleModel, "SourceDetailBaseGridRowColors", new Task(() => - { - return BaseModuleImpl.GetBaseGridRowColors("SOURCEDETAIL_" + model.FormKey); - })); - cachesDic.AddTask(billModuleModel, "SourceDetailBaseGridRightMenus", new Task(() => - { - return BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCEDT_" + model.FormKey); - })); - - if (!string.IsNullOrEmpty(model.SourceDetailsDetailsSql)) - { - cachesDic.AddTask(billModuleModel, "DetailDetails", new Task(() => - { - return BaseModuleImpl.getDetail_Details(model.FormKey); - })); - cachesDic.AddTask(billModuleModel, "SourceDetailDetailsCustomColumnByDatabase", new Task(() => - { - return GridExtend.GetCustomColumnByDatabase(string.Empty); - })); - cachesDic.AddTask(billModuleModel, "SourceDetailDetailsBaseGridRightMenus", new Task(() => - { - return BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCEDTX_" + model.FormKey); - })); - } - } - - BillModuleModelDic.Add(sourceModelRow, billModuleModel); - } - return true; - })); - #endregion - } - return true; - })); - #endregion - } - - - /// - /// 说明:初始化分割条位置 - /// 创建人:龚宇超 - /// 创建日期:2018-03-06 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// + } + } + + + /// + /// 获取数据源缓存 + /// + /// + public void GetDataCaches(Dictionary cachesDic) + { + //获取通用数据 + Task sysModelTask = cachesDic.GetTask(this, "SysModel"); + Task systemDllRowTask = cachesDic.GetTask(this, "SystemDllRow"); + Task dynamicModelTask = cachesDic.GetTask(this, "DynamicModel"); + Task getDataCachesTask = cachesDic.AddTask(this, "DataCaches", new Task(() => + { + DynamicBillModel dynamicModel = (DynamicBillModel)dynamicModelTask.Result; + #region InitializeSetting初始化系统配置 + Task billInfoRowTask = cachesDic.AddTask(this, "BillInfo", new Task(() => + { + return BillImpl.GetBillInfo(dynamicModel.ModuleCode);//获取单个模块信息 + })); + Task billModelTask = cachesDic.AddTask(this, "BillModel", new Task(() => + { + BillModel model = null; + if (billInfoRowTask.Result != null) + { + model = new BillModel(billInfoRowTask.Result); + } + return model; + })); + BillModel billModel = billModelTask.Result; + if (billModel != null) + { + Task masterPreFixTask = cachesDic.AddTask(this, "MasterPreFix", new Task(() => + { + return BaseImpl.GetColumnPrefix(billModel.MasterTable);// 主表列前缀 + })); + Task detailPreFixTask = cachesDic.AddTask(this, "DetailPreFix", new Task(() => + { + return BaseImpl.GetColumnPrefix(billModel.DetailTable);// 明细表列前缀 + })); + } + Task menuConfigTabTask = cachesDic.AddTask(this, "MenuConfigTab", new Task(() => + { + DataRow dataRow = BaseImpl.GetMenuConfigTab(dynamicModel.ModuleId); + if (dataRow != null) + { + billModel.BillSourceIds = dataRow.Table.Columns.Contains("BillSourceIds") ? (dataRow["BillSourceIds"] + "").Trim(',') : string.Empty; + billModel.BillFlag = dataRow.Table.Columns.Contains("BillFlag") && !string.IsNullOrEmpty(dataRow["BillFlag"] + "") ? Convert.ToInt32(dataRow["BillFlag"] + "") : -1; + //billModel + } + return dataRow;//获取菜单其他配置 + })); + #region GetPrintOtherParam获取打印其他参数 + if (string.IsNullOrEmpty(billModel.PrintSql) && billModel.PrintSql.Contains("<<")) + { + string[] strs = billModel.PrintSql.Split(new[] { ">>" }, 2, StringSplitOptions.None); + _mainPrintSql = strs[1]; + _printModeCond = strs[0].Replace("<<", ""); + } + if (!string.IsNullOrEmpty(_printModeCond) && _printModeCond.IndexOf(';') > 0) + { + string[] str = _printModeCond.Split(';'); + Task printOtherSystemRowTask = cachesDic.AddTask(this, "PrintOtherSystemRow", new Task(() => + { + return AttachImpl.GetSystemModule(str[0]); + })); + Task printOtherColumnPrefixTask = cachesDic.AddTask(this, "PrintOtherColumnPrefix", new Task(() => + { + string tableName = printOtherSystemRowTask.Result["TableName"] + ""; + return BaseImpl.GetColumnPrefix(tableName); + })); + Task printOtherPrimaryKeyTask = cachesDic.AddTask(this, "PrintOtherPrimaryKey", new Task(() => + { + string modetype = printOtherSystemRowTask.Result["modType"] + ""; + return modetype == "1" ? BaseImpl.GetBasePrimaryKey(str[0]) : printOtherColumnPrefixTask.Result + "billdocument_id"; + })); + Task printOtherIsExcPrintTask = cachesDic.AddTask(this, "PrintOtherIsExcPrint", new Task(() => + { + string modetype = printOtherSystemRowTask.Result["modType"] + ""; + switch (modetype) + { + case "1": + ModuleModel mode = new ModuleModel(MainImpl.GetSystemdllTab(str[0])); + if (mode != null) + { + return mode.PrintType == 3; + } + break; + case "2": + BaseAccraditationModel model = new BaseAccraditationModel(BillAuditImpl.GetPubAuditProperty(str[0])); + if (model != null) + { + return model.BillPrintType == 3; + } + break; + } + return false; + })); + } + #endregion + Task billSettingTask = cachesDic.AddTask(this, "BillSetting", new Task(() => + { + BillImpl.InitBillSetting(billModel); + return true; + })); + #endregion + + + if (billModel.PanelWidth > 0) + { + #region InitializeBillSource初始化单据来源 + Task> detailTask = cachesDic.AddTask(this, "Details", new Task>(() => + { + List details = new List(); + DataTable table = BaseAuditImpl.GetAttachTabs(dynamicModel.ModuleCode, "100", " and orderid < 0 "); + foreach (DataRow item in table.Rows) + { + GridDetailModel gridDetailModel = new GridDetailModel(item, null, GridCustomColumnStruct.BillSourceDetailAttachGridView); + details.Add(gridDetailModel); + Task addGridColumnsTask = cachesDic.AddTask(gridDetailModel, "GridColumns", new Task(() => + { + DataTable gridColumns = BaseAuditImpl.GetBottomBasicInformation(item["formKey"] + ""); + gridDetailModel.GridColumns = gridColumns; + return gridColumns; + })); + } + return details; + })); + Task sourcesTask = cachesDic.AddTask(this, "Sources", new Task(() => + { + DataRow menuConfigRow = menuConfigTabTask.Result; + string SourceIds = (billModel.BillSourceIds + "").Trim(','); + if (!string.IsNullOrWhiteSpace(dynamicModel.SourceDetailsID)) + { + SourceIds = (SourceIds + "," + dynamicModel.SourceDetailsID).Trim(','); + } + return BillImpl.GetSources(dynamicModel.ModuleCode, SourceIds);//获取单据来源 + })); + cachesDic.AddTask(tb_buttom, "DynamicModel", dynamicModelTask); + cachesDic.AddTask(tb_buttom, "Details", detailTask); + // TabControlEx.GetDataCaches 会创建 Grid、ModuleGrid、浏览器等 + // WinForms/DevExpress 控件,延后到 InitializeBillSource + // 在 UI 线程执行。 + Task initSourcesTask = cachesDic.AddTask(this, "InitSourcesTask", new Task(() => + { + Hashtable htTable = sourcesTask.Result; + DataTable masterTable = htTable["master"] as DataTable; + for (int i = 0; i < masterTable.Rows.Count; i++) + { + DataRow sourceModelRow = masterTable.Rows[i]; + BillModuleModel billModuleModel = new BillModuleModel(); + BillSourceModel model = new BillSourceModel(sourceModelRow); + billModuleModel.SourceModel = model; + Task customQueryFieldsTask = cachesDic.AddTask(model, "CustomQueryFields", new Task(() => + { + return BaseModuleImpl.GetCustomQueryFields(model.FormKey); + })); + + // 后台阶段只加载数据,不构造任何 WinForms/DevExpress + // 对象。缓存以 BillModuleModel 为所有者,UI 创建实际 + // 控件后再绑定需要的任务。 + if (model.SourceType == 1) + { + cachesDic.AddTask(billModuleModel, "BindTreeTable", new Task(() => + { + return BaseImpl.GetDataTableResult(model.SourceSql); + })); + } + else + { + if (model.SourceType == 5) + model.ChangeSourceType(2);//单据来源显示条数 + + cachesDic.AddTask(billModuleModel, "SourceColumns", new Task(() => + { + return BillImpl.GetSourceColumns(model.Id); + })); + cachesDic.AddTask(billModuleModel, "SourceCustomColumnByDatabase", new Task(() => + { + return GridExtend.GetCustomColumnByDatabase( + GridCustomColumnStruct.BillSourceGridView + model.FormKey); + })); + cachesDic.AddTask(billModuleModel, "SourceBaseGridRowColors", new Task(() => + { + return BaseModuleImpl.GetBaseGridRowColors("BILLSOURCE_" + model.FormKey); + })); + cachesDic.AddTask(billModuleModel, "SourceBaseGridRightMenus", new Task(() => + { + return BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCE_" + model.FormKey); + })); + } + + if (string.IsNullOrWhiteSpace(model.DetailMenuCode)) + { + cachesDic.AddTask(billModuleModel, "SourceDetailCustomColumnByDatabase", new Task(() => + { + return GridExtend.GetCustomColumnByDatabase( + GridCustomColumnStruct.BillSourceDetailGridView + model.FormKey); + })); + cachesDic.AddTask(billModuleModel, "SourceDetailBaseGridRowColors", new Task(() => + { + return BaseModuleImpl.GetBaseGridRowColors("SOURCEDETAIL_" + model.FormKey); + })); + cachesDic.AddTask(billModuleModel, "SourceDetailBaseGridRightMenus", new Task(() => + { + return BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCEDT_" + model.FormKey); + })); + + if (!string.IsNullOrEmpty(model.SourceDetailsDetailsSql)) + { + cachesDic.AddTask(billModuleModel, "DetailDetails", new Task(() => + { + return BaseModuleImpl.getDetail_Details(model.FormKey); + })); + cachesDic.AddTask(billModuleModel, "SourceDetailDetailsCustomColumnByDatabase", new Task(() => + { + return GridExtend.GetCustomColumnByDatabase(string.Empty); + })); + cachesDic.AddTask(billModuleModel, "SourceDetailDetailsBaseGridRightMenus", new Task(() => + { + return BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCEDTX_" + model.FormKey); + })); + } + } + + BillModuleModelDic.Add(sourceModelRow, billModuleModel); + } + return true; + })); + #endregion + } + return true; + })); + #endregion + } + + + /// + /// 说明:初始化分割条位置 + /// 创建人:龚宇超 + /// 创建日期:2018-03-06 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// private void InitlizeSpiltLocation() { try - { - // 设置单据来源底部高度 + { + // 设置单据来源底部高度 if (this.BillModel.PanelHeight == 0) { // 隐藏来源明细 @@ -558,1654 +558,1654 @@ namespace Lskj.PubBillManagement if (!string.IsNullOrEmpty(height)) this.ssc_main.SplitterPosition = Convert.ToInt32(height); } - } + } catch (Exception ex) { LogHelper.Instance.WriteError(ex); } } - /// - /// 说明:初始化系统配置 - /// 创建人:龚宇超 - /// 创建日期:2017-11-27 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - private void InitializeSetting() - { - Dictionary dataCaches = SysModel != null ? SysModel.DataCaches : null; - if (!dataCaches.GetValue(this, "BillInfo", out DataRow modelRow)) - { - modelRow = BillImpl.GetBillInfo(this.SysModel.ModuleCode);//获取单个模块信息 - } - if (modelRow == null) - { - throw new Exception("模块编号[" + this.SysModel.ModuleCode + "],配置错误!\r\n该模块信息未找到!"); - } - if (!dataCaches.GetValue(this, "BillModel", out BillModel)) - { - this.BillModel = new BillModel(modelRow);//初始化类的新实例。 - } - - if (this.BillModel != null) - { - this.BillModel.TypeName = string.IsNullOrEmpty(SysModel.BillMasterSql) ? this.SysModel.FormText : this.BillModel.TypeName;// 模块名称 - if (!string.IsNullOrWhiteSpace(this.SysModel.DocumentName)) this.BillModel.TypeName = this.SysModel.DocumentName; - - if (!dataCaches.GetValue(this, "MasterPreFix", out string masterPreFix)) - { - masterPreFix = BaseImpl.GetColumnPrefix(this.BillModel.MasterTable);// 主表列前缀 - } - this.BillModel.MasterPreFix = masterPreFix; - if (!dataCaches.GetValue(this, "DetailPreFix", out string detailPreFix)) - { - detailPreFix = BaseImpl.GetColumnPrefix(this.BillModel.DetailTable);// 明细表列前缀 - } - this.BillModel.DetailPreFix = detailPreFix; - this.BillModel.DetailOrderField = this.BillModel.DetailPreFix + "lsidx_id";// 单据来源id - if (SystemInfo.Instance.IsNotBillDetailOrder)//禁用排序 - this.BillModel.DetailOrderField = string.Empty; - } - if (!dataCaches.GetValue(this, "MenuConfigTab", out DataRow menuRow)) - { - menuRow = BaseImpl.GetMenuConfigTab(this.SysModel.ModuleId);//获取菜单其他配置 - } - if (menuRow != null) - { - this.BillModel.BillSourceIds = menuRow.Table.Columns.Contains("BillSourceIds") ? (menuRow["BillSourceIds"] + "").Trim(',') : string.Empty; - this.BillModel.BillFlag = menuRow.Table.Columns.Contains("BillFlag") && !string.IsNullOrEmpty(menuRow["BillFlag"] + "") ? Convert.ToInt32(menuRow["BillFlag"] + "") : -1; - } - if (this.SysModel.HideSource) - { - this.BillModel.PanelWidth = 0; - this.BillModel.PanelHeight = 0; - } - - if (!dataCaches.GetValue(this, "BillSetting", out bool _)) - { - BillImpl.InitBillSetting(this.BillModel); - } - } - - /// - /// 说明:初始化控件 - /// 创建人:龚宇超 - /// 创建日期:2017-11-23 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - private void InitializeControl() - { - this.InitializeBillSource();//初始化单据来源 - } - - - /// - /// 点击第一个默认新增行新增默认数据 - /// - /// - /// - private void GridView_MouseDown(object sender, MouseEventArgs e) - { - - } - - - /// - /// 说明:初始化单据来源 - /// 创建人:龚宇超 - /// 创建日期:2017-11-28 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - private void InitializeBillSource() - { - this.xtc_main_container.TabPages.Clear(); - - Dictionary dataCaches = SysModel != null ? SysModel.DataCaches : null; - if (dataCaches != null && - dataCaches.GetTask(tb_buttom, "DynamicModel") != null && - dataCaches.GetTask>(tb_buttom, "Details") != null) - { - // 该方法会预创建附加页控件,必须在 UI 线程执行。 - tb_buttom.GetDataCaches(dataCaches); - } - if (!dataCaches.GetValue(this, "Details", out List attachModels)) - { - attachModels = GetAttachTabs(); - } - if (!dataCaches.GetValue(this, "Sources", out Hashtable htTable)) - { - string SourceIds = (this.BillModel.BillSourceIds + "").Trim(','); - if (!string.IsNullOrWhiteSpace(this.SysModel.SourceDetailsID)) - { - SourceIds = (SourceIds + "," + this.SysModel.SourceDetailsID).Trim(','); - } - htTable = BillImpl.GetSources(this.SysModel.ModuleCode, SourceIds);//获取单据来源 - } - DataTable masterTable = htTable["master"] as DataTable; - DataTable detailTable = htTable["detail"] as DataTable; - - - - - /* 构造原理 - * 1. 假如存在附加信息,则底部显示来源明细(来源明细摆放在标签第一个位置)+多标签,假如标签只有一个则隐藏标签头. - * 2. 假如不存在附加信息,则底部只显示来源明细. - **/ - if (attachModels.Count > 0) - { - this.tb_buttom.Model = this.SysModel; - this.tb_buttom.ParentControlEx = this.ControlObj; - //this.tb_buttom.ParentGridEx = this.gcMain; - if (this.BillModel.RefreshSelectedDetail) - { - //配置了只刷新当前页签后,切换页签时刷新 - this.tb_buttom.TabControlObj.SelectedPageChanged += TabControlObj_SelectedPageChanged; - } - this.tb_buttom.InitTabPages(attachModels); - - } - else - { - this.tb_buttom.TabControlObj.ShowTabHeader = DevExpress.Utils.DefaultBoolean.False; - } - dataCaches.GetValue(this, "InitSourcesTask", out bool _); - - int SerialNumber = 0; - for (int i = 0; i < masterTable.Rows.Count; i++) - { - DataRow sourceModelRow = masterTable.Rows[i]; - BillModuleModel billModuleModel = BillModuleModelDic.ContainsKey(sourceModelRow) ? BillModuleModelDic[sourceModelRow] : new BillModuleModel(); - BillSourceModel model = billModuleModel.SourceModel != null ? billModuleModel.SourceModel : new BillSourceModel(sourceModelRow); - object sourceControl = billModuleModel.SourceControl != null ? billModuleModel.SourceControl : null; - object sourceDetailControl = billModuleModel.SourceDetailControl != null ? billModuleModel.SourceDetailControl : null; - object sourceDetailDetailControl = billModuleModel.SourceDetailDetailControl != null ? billModuleModel.SourceDetailDetailControl : null; - BillSourceUnionModel unionModel = new BillSourceUnionModel(); - if (!dataCaches.GetValue(model, "CustomQueryFields", out DataTable controls)) - { - controls = BaseModuleImpl.GetCustomQueryFields(model.FormKey); - } - - - XtraTabPage tabPage = new XtraTabPage(); - tabPage.Text = model.UserName; - - //只加载单据管理类型 - if (!(model.SourceType == 2 || model.SourceType == 4)) continue; - - - #region 加载来源表头 - GridControlEx gridControl = null; - TreeViewEx treeView = null; - - if (model.SourceType == 1) - { - // 来源为树类型 - treeView = sourceControl != null ? (TreeViewEx)sourceControl : new TreeViewEx(); - treeView.BorderStyle = BorderStyle.None; - treeView.Dock = DockStyle.Fill; - treeView.TreeNodeKeyField = model.SourceKeyField; - treeView.TreeNodeTextField = model.SourceResult; - if (!dataCaches.GetValue(billModuleModel, "BindTreeTable", out DataTable bindTreeTable)) - { - bindTreeTable = BaseImpl.GetDataTableResult(model.SourceSql); - } - treeView.TreeInhibitSort = model.TreeInhibitSort; - treeView.BindTreeView(bindTreeTable); - treeView.TreeNodeSelectAfter += new TreeViewEventHandler(OnTreeNodeSelectAfter); - - tabPage.Controls.Add(treeView); - } - else if (model.SourceType == 5) - { - model.ChangeSourceType(2);//单据来源显示条数 - this.IsBillShowCount = true; - } - else if (model.SourceType == 3 || model.SourceType == 4) - { - //类型为3,是树表格类型的单据管理。 - //类型为4,是树表格类型的数据来源 - gridControl = sourceControl != null ? (TreeGridControlEx)sourceControl : new TreeGridControlEx(); - gridControl.Dock = DockStyle.Fill; - gridControl.BorderStyle = System.Windows.Forms.BorderStyle.None; - gridControl.Model = this.SysModel; - - AttachCachedTask(dataCaches, billModuleModel, - "SourceCustomColumnByDatabase", gridControl, - "CustomColumnByDatabase"); - if (!dataCaches.GetValue(billModuleModel, "SourceColumns", out DataTable dtSourceColumns)) - { - dtSourceColumns = BillImpl.GetSourceColumns(model.Id); - } - if (!dataCaches.GetValue(billModuleModel, "SourceBaseGridRowColors", out DataTable dtBaseGridRowColors)) - { - dtBaseGridRowColors = BaseModuleImpl.GetBaseGridRowColors("BILLSOURCE_" + model.FormKey); - } - if (!dataCaches.GetValue(billModuleModel, "SourceBaseGridRightMenus", out DataTable dtBaseGridRightMenus)) - { - dtBaseGridRightMenus = BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCE_" + model.FormKey); - } - - //节点编号 - if (!string.IsNullOrWhiteSpace(model.SourceKeyFieldName)) (gridControl as TreeGridControlEx).TreeListObj.KeyFieldName = model.SourceKeyFieldName; - //父节点编号 - if (!string.IsNullOrWhiteSpace(model.SourceParentFieldName)) (gridControl as TreeGridControlEx).TreeListObj.ParentFieldName = model.SourceParentFieldName; - - gridControl.SetReadOnlyColumns(dtSourceColumns, GridCustomColumnStruct.BillSourceGridView + model.FormKey); - gridControl.SetGridRowColors(dtBaseGridRowColors); - //gridControl.SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridControlRightCallback); - (gridControl as TreeGridControlEx).SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridControlRightCallback); - unionModel.TreeGridControlObj = gridControl as TreeGridControlEx; - unionModel.TreeGridControlObj.TreeListObj.FocusedNodeChanged += new DevExpress.XtraTreeList.FocusedNodeChangedEventHandler(OnTreeListObjFocusedNodeChanged); - - - if (BillModel.IsBillSourceCheck == 1) - { - GridDragGrid.TreeListAddCheckBox((gridControl as TreeGridControlEx).TreeListObj); - } - tabPage.Controls.Add(gridControl); - } - else - { - // 来源为表格类型 - gridControl = sourceControl != null ? (GridControlEx)sourceControl : new GridControlEx(); - gridControl.BorderStyle = BorderStyle.None; - gridControl.Model = this.SysModel; - gridControl.Dock = DockStyle.Fill; - gridControl.ExportPermission = this.BillModel.ExportPermission; - - AttachCachedTask(dataCaches, billModuleModel, - "SourceCustomColumnByDatabase", gridControl, - "CustomColumnByDatabase"); - if (model.LoadFilter) - { - gridControl.GridView.OptionsView.ShowAutoFilterRow = true; - } - if (!dataCaches.GetValue(billModuleModel, "SourceColumns", out DataTable dtSourceColumns)) - { - dtSourceColumns = BillImpl.GetSourceColumns(model.Id); - } - if (!dataCaches.GetValue(billModuleModel, "SourceBaseGridRowColors", out DataTable dtBaseGridRowColors)) - { - dtBaseGridRowColors = BaseModuleImpl.GetBaseGridRowColors("BILLSOURCE_" + model.FormKey); - } - if (!dataCaches.GetValue(billModuleModel, "SourceBaseGridRightMenus", out DataTable dtBaseGridRightMenus)) - { - dtBaseGridRightMenus = BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCE_" + model.FormKey); - } - gridControl.SetReadOnlyColumns(dtSourceColumns, GridCustomColumnStruct.BillSourceGridView + model.FormKey); - gridControl.SetGridRowColors(dtBaseGridRowColors); - gridControl.SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridControlRightCallback); - //gridControl.GridView.SelectionChanged += new SelectionChangedEventHandler(OnGridControlSelectionChanged); - //gridControl.GridView.FocusedRowObjectChanged += OnFocusedRowObjectChanged; - //if (model.DetailsDoubleClick) - //{ - // gridControl.GridView.DoubleClick += OnSourceGridViewDoubleClick; // 2023-3-11 增加双击配置 - //} - //else - //{ - // gridControl.GridView.RowCellClick += OnGridViewRowCellClick; // 2019-11-12 cmd提出改为行点击事件,否则会出现保存提交后,单据管理无法查询出数据 - //} - - gridControl.GridView.RowCellClick += OnGridViewRowCellClick; // 2019-11-12 cmd提出改为行点击事件,否则会出现保存提交后,单据管理无法查询出数据 - - gridControl.GridView.DoubleClick += OnSourceGridViewDoubleClick;//双击事件改成打开单据主消息控件 - - - if (BillModel.IsBillSourceCheck == 1) - { - GridDragGrid.GridAddCheckBox(gridControl.GridView); - } - tabPage.Controls.Add(gridControl); - } - #endregion - - #region 加载来源明细 - XtraTabPage tabDetail = new XtraTabPage(); - - if (SystemInfo.Instance.GridRowFontSize > 0) - { - //页签大小 - FontFamily fontFamily = tabDetail.Appearance.Header.Font.FontFamily; - tabDetail.Appearance.Header.Font = new System.Drawing.Font(fontFamily, SystemInfo.Instance.GridRowFontSize); - } - - DataRow[] detailColumns = detailTable.Select("sourceId=" + model.Id); - - - //明细为表格 - GridControlEx gridDetail = new GridControlEx(); - - - - if (!string.IsNullOrWhiteSpace(model.DetailMenuCode)) - { - //来源明细配置了模块号,根据模块号创建对应的ModuleGridEx - //ModuleGridEx主要是用保存的功能,数据源sql还是根据配置的为准 - DataRow modelRow = MainImpl.GetSystemdllTab(model.DetailMenuCode);//获取模块信息 - if (modelRow == null) - { - MessageUtil.Show($"没有找到编号为 {model.DetailMenuCode} 的模块信息"); - gridDetail.Parent = gridDetail; - continue; - } - - ModuleModel sysModel = new ModuleModel(modelRow); - //设置主表sql - //model.SourceSql = sysModel.MenuSql; - - DynamicModuleModel dyncModel = new DynamicModuleModel(new[] - { sysModel.MenuName, ERPInfo.Instance.UserId, ERPInfo.Instance.UserName, - this.SysModel.Privilege, sysModel.ModeCode, "0" }); - - ModuleGridEx gridEx = new ModuleGridEx(); - gridEx.Dock = DockStyle.Fill; - if (model.SourceType == 1) - { - gridEx.LeftTreeViewEx = treeView; - } - else - { - gridEx.LeftGridEx = gridControl; - gridEx.ParentGridEx = gridControl; - } - gridEx.ParentKeyField = model.SourceKeyField; - gridEx.ParentUnionField = model.SourceKeyField; - - gridEx.VisibleSearchPanel = false;//禁止上方搜索 - gridEx.InitializeControl(sysModel, dyncModel); - - - gridDetail = gridEx.GridControlObj; - gridEx.Parent = tabDetail; - unionModel.GridDetailModuleGridEx = gridEx; - - if (sysModel.TreeAutoMultiHeader == 1) model.ChangeSourceDetailType("1"); - - - - if (SerialNumber == 0) - { - this.tb_buttom.TabControlObj.TabPages.Insert(0, tabDetail); - this.tb_buttom.TabControlObj.SelectedTabPageIndex = 0; - if (attachModels.Count > 0) - this.tb_buttom.TabControlObj.TabPages[0].Text = model.UserName + DetailedSuffix; - } - - } - else - { - if (model.sourceDetailType.Equals("1")) - { - //明细为树表格 - gridDetail = sourceDetailControl != null ? (TreeGridControlEx)sourceDetailControl : new TreeGridControlEx(); - gridDetail.Model = this.SysModel; - gridDetail.Dock = DockStyle.Fill; - AttachCachedTask(dataCaches, billModuleModel, - "SourceDetailCustomColumnByDatabase", gridDetail, - "CustomColumnByDatabase"); - gridDetail.SetReadOnlyColumns(detailColumns == null || detailColumns.Length == 0 ? new DataTable() : detailColumns.CopyToDataTable(), GridCustomColumnStruct.BillSourceDetailGridView + model.FormKey); - if (!dataCaches.GetValue(billModuleModel, "SourceDetailBaseGridRowColors", out DataTable dtBaseGridRowColors)) - { - dtBaseGridRowColors = BaseModuleImpl.GetBaseGridRowColors("SOURCEDETAIL_" + model.FormKey); - } - if (!dataCaches.GetValue(billModuleModel, "SourceDetailBaseGridRightMenus", out DataTable dtBaseGridRightMenus)) - { - dtBaseGridRightMenus = BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCEDT_" + model.FormKey); - } - gridDetail.SetGridRowColors(dtBaseGridRowColors); - gridDetail.SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridDetailRightMenuCallback); - gridDetail.Parent = tabDetail; - gridDetail.BorderStyle = System.Windows.Forms.BorderStyle.None; - - if (SerialNumber == 0) - { - this.tb_buttom.TabControlObj.TabPages.Insert(0, tabDetail); - this.tb_buttom.TabControlObj.SelectedTabPageIndex = 0; - if (attachModels.Count > 0) - this.tb_buttom.TabControlObj.TabPages[0].Text = model.UserName + DetailedSuffix; - } - - if (BillModel.IsBillDetailCheck == 1)//加载复选框 - { - GridDragGrid.TreeListAddCheckBox((gridDetail as TreeGridControlEx).TreeListObj); - } - } - else - { - - gridDetail = sourceDetailControl != null ? (GridControlEx)sourceDetailControl : new GridControlEx(); - gridDetail.Model = this.SysModel; - gridDetail.Dock = DockStyle.Fill; - AttachCachedTask(dataCaches, billModuleModel, - "SourceDetailCustomColumnByDatabase", gridDetail, - "CustomColumnByDatabase"); - gridDetail.SetReadOnlyColumns(detailColumns == null || detailColumns.Length == 0 ? new DataTable() : detailColumns.CopyToDataTable(), GridCustomColumnStruct.BillSourceDetailGridView + model.FormKey); - - if (model.DetailedLoadFilter) - { - gridDetail.GridView.OptionsView.ShowAutoFilterRow = true; - } - if (!dataCaches.GetValue(billModuleModel, "SourceDetailBaseGridRowColors", out DataTable dtBaseGridRowColors)) - { - dtBaseGridRowColors = BaseModuleImpl.GetBaseGridRowColors("SOURCEDETAIL_" + model.FormKey); - } - if (!dataCaches.GetValue(billModuleModel, "SourceDetailBaseGridRightMenus", out DataTable dtBaseGridRightMenus)) - { - dtBaseGridRightMenus = BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCEDT_" + model.FormKey); - } - gridDetail.SetGridRowColors(dtBaseGridRowColors); - gridDetail.SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridDetailRightMenuCallback); - - //明细的明细(明细分成左右2个) - if (!string.IsNullOrEmpty(model.SourceDetailsDetailsSql)) - { - GridControlEx gridDetail_Details = sourceDetailDetailControl != null ? (GridControlEx)sourceDetailDetailControl : new GridControlEx(); - gridDetail_Details.Model = this.SysModel; - gridDetail_Details.Dock = DockStyle.Fill; - //创建只读列 - if (!dataCaches.GetValue(billModuleModel, "DetailDetails", out DataTable dataTable)) - { - dataTable = BaseModuleImpl.getDetail_Details(model.FormKey); - } - AttachCachedTask(dataCaches, billModuleModel, - "SourceDetailDetailsCustomColumnByDatabase", - gridDetail_Details, "CustomColumnByDatabase"); - gridDetail_Details.SetReadOnlyColumns(dataTable); - //设置右键 - if (!dataCaches.GetValue(billModuleModel, "SourceDetailDetailsBaseGridRightMenus", out DataTable dttBaseGridRightMenus)) - { - dttBaseGridRightMenus = BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCEDTX_" + model.FormKey); - } - gridDetail_Details.SetGridRightMenus(dttBaseGridRightMenus, this.SysModel, OnGridDetailRightMenuCallback); - //明细点击 更新 明细的明细 - gridDetail.GridView.FocusedRowObjectChanged += GridView_FocusedRowObjectChanged; - gridDetail.GridView.Tag = model.SourceDetailsDetailsSql; - //创建SplitContainerControl控件,让下方可以左右拖动 - SplitContainerControl splitContainerControl = new DevExpress.XtraEditors.SplitContainerControl(); - splitContainerControl.Dock = DockStyle.Fill; - splitContainerControl.Panel1.Controls.Add(gridDetail); - gridDetail.BorderStyle = System.Windows.Forms.BorderStyle.None; - splitContainerControl.Panel2.Controls.Add(gridDetail_Details); - gridDetail_Details.BorderStyle = System.Windows.Forms.BorderStyle.None; - - splitContainerControl.SplitterMoved += new System.EventHandler(this.OnDetailsSplitterMoved); - string newwidth = IniHelper.Read(string.Format("bill_Details_Width_{0}", this.SysModel.ModuleCode));//通过Key获取Value值 - if (!string.IsNullOrEmpty(newwidth)) - { - splitContainerControl.SplitterPosition = Convert.ToInt32(newwidth); - } - else - { - int width = this.tb_buttom.Width;//获取控件宽度 - splitContainerControl.SplitterPosition = width / 2;//然后将分割位置设置在宽度一半位置 - } - - - splitContainerControl.Parent = tabDetail; - unionModel.GridDetailDetailControlObj = gridDetail_Details; - billModuleModel.SourceDetailDetailControl = gridDetail_Details; - } - else - { - gridDetail.Parent = tabDetail; - gridDetail.BorderStyle = System.Windows.Forms.BorderStyle.None; - - } - - if (SerialNumber == 0) - { - this.tb_buttom.TabControlObj.TabPages.Insert(0, tabDetail); - this.tb_buttom.TabControlObj.SelectedTabPageIndex = 0; - if (attachModels.Count > 0) - this.tb_buttom.TabControlObj.TabPages[0].Text = model.UserName + DetailedSuffix; - } - if (BillModel.IsBillDetailCheck == 1)//加载复选框 - { - GridDragGrid.GridAddCheckBox(gridDetail.GridView); - } - } - } - - - - - - - - #endregion - - billModuleModel.SourceControl = - treeView != null ? (object)treeView : gridControl; - billModuleModel.SourceDetailControl = gridDetail; - BillModuleModelDic[sourceModelRow] = billModuleModel; - - #region 加载来源条件 - if (model.SourceType == 1 && (controls == null || controls.Rows.Count == 0)) - { - //// 设置默认下拉列表框 - //DataTable columnTable = detailTable.Select("sourceId=" + model.Id + " and isnull(isVisible,0)=0").CopyToDataTable(); - //this.lceCombobox.ValueMember = this.lceCombobox.ValueField = "fieldName"; - //this.lceCombobox.TextField = "userName"; - //this.lceCombobox.SetDataSource(columnTable); - //this.lceCombobox.TextEdit.SelectedIndex = 0; - - //this.pl_treeview_detault_search.Dock = DockStyle.Bottom; - //this.pl_treeview_detault_search.Visible = true; - - //tabPage.Controls.Add(pl_treeview_detault_search); - } - else - { - // 创建自定义条件 - string searchSql = model.SourceType == 1 ? Regex.Replace(model.DetailSql, "{speciesno}", "", RegexOptions.IgnoreCase) : model.SourceSql; - PanelControl searchPanel = new PanelControl(); - MyControl searchControl = - new MyControl(searchSql, - gridControl == null ? gridDetail : gridControl, - treeView) - { - Model = this.SysModel, - OtherParams = this.SysModel.OtherParams() - }; - if (dataCaches != null) - { - dataCaches.AddTask(searchControl, "DynamicModel", - new Task(() => this.SysModel)); - dataCaches.AddTask(searchControl, "ControlsTable", - new Task(() => controls)); - searchControl.GetSearchDataCaches(dataCaches); - } - searchControl.OnSearchBeforeCallBack += new SearchEventHandler(OnSearchBefore); - searchControl.OnSearchAfterCallBack += new EventHandler(OnSearchAfterd); - if (SerialNumber == 0 && !SystemInfo.Instance.IsBillSourceRefushTag.Equals("1") && string.IsNullOrWhiteSpace(this.BillModel.InitialRefreshId)) - { - // 第一个页面要刷新数据,所以绑定事件用于初始化完成后在查询数据 - searchControl.OnDataSourceBindCallBack += new EventHandler(OnFirstPageDataSourceBindCallBack); - } - if (!string.IsNullOrWhiteSpace(this.BillModel.InitialRefreshId) && this.BillModel.InitialRefreshId.Equals(model.Id + "")) - { - searchControl.OnDataSourceBindCallBack += SearchControl_OnDataSourceBindCallBack; - InitialSelectionTab = tabPage; - } - - searchControl.ParentUnionField = model.SourceKeyField; - - searchPanel.Dock = DockStyle.Top; - searchPanel.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder; - searchPanel.BackColor = Color.Transparent; - searchPanel.Parent = tabPage; - searchControl.OtherParams = this.SysModel.OtherParams(); - searchPanel.Height = searchControl.InitSearchControl(controls, searchPanel); - unionModel.SearchObj = searchControl; - } - #endregion - - unionModel.GridControlObj = gridControl; - - if (model.sourceDetailType.Equals("1")) - { - unionModel.TreeGridDetailControlObj = (gridDetail as TreeGridControlEx); - } - else - { - unionModel.GridDetailControlObj = gridDetail; - } - - - - - unionModel.ModelObj = model; - unionModel.TreeViewObj = treeView; - if (SerialNumber == 0) - unionModel.IsChange = true; - tabPage.Tag = unionModel; - if (model.SourceType == 0 && !model.DisableShowSourceCount) - { - // 模块要查看具体条数 - unionModel.SearchObj.OnDataSourceBindCallBack += new EventHandler(OnPageDataSourceBindCallBack); - pageNumKey.Add(unionModel.SearchObj, tabPage); - } - this.xtc_main_container.TabPages.Add(tabPage); - SerialNumber++; - } - - - } - - - - - - - - - /// - /// 点击来源明细,加载明细的明细 - /// - /// - /// - private void GridView_FocusedRowObjectChanged(object sender, FocusedRowObjectChangedEventArgs e) - { - try - { - - GridView gridView = sender as GridView; - DataRow rowItem = gridView.GetFocusedDataRow(); - string sql = gridView.Tag + ""; - BillSourceUnionModel unionModel = this.xtc_main_container.SelectedTabPage.Tag as BillSourceUnionModel; - if (unionModel.GridDetailDetailControlObj != null) - { - unionModel.GridDetailDetailControlObj.gridControl.DataSource = BillImpl.GetDataTableResult(ReplaceHelper.ReplaceRowParam(rowItem, sql)); - } - } - catch (Exception ex) - { - MessageUtil.Show(ex); - } - - - } - - - - - - - - - - - - - - #region 单据来源相关 - /// - /// 说明:刷新当前选中的TabPage - /// 创建人:龚宇超 - /// 创建日期:2018-06-29 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// - private void RefreshSelectedSource() - { - if (this.xtc_main_container.SelectedTabPage == null) return;//来源选择为null(不显示左侧来源)。不执行下方刷新 - - XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; - BillSourceUnionModel model = tabPage.Tag as BillSourceUnionModel; - if (model.GridControlObj != null) this.RefreshSource(model); - if (BillModel.drgFinishHide == "1") - { - if (model.ModelObj.SourceType == 1) - { - string sqlValue = ReplaceHelper.ReplaceUserInfo(ReplaceHelper.ReplaceWhereCond(model.ModelObj.DetailSql)); - sqlValue = sqlValue.Replace("#", ""); - sqlValue = this.ControlObj.ReplaceControlValue(sqlValue); - sqlValue = ReplaceHelper.ReplaceParamToValue(sqlValue, model.TreeViewObj.GetSelectValue()); - model.GridDetailControlObj.GridControl.DataSource = BillImpl.GetDataTableResult(sqlValue); - } - else - { - this.RefreshSourceDetail(model); - } - } - if (model.ModelObj.SourceType == 0 && model.SearchObj.GridRowCount > 0) tabPage.Text = model.ModelObj.UserName + "(" + model.SearchObj.GridRowCount + QuantitySuffix; - } - /// - /// 说明:刷新单据来源主表,未传递时,默认刷新 - /// 创建人:龚宇超 - /// 创建日期:2017-12-13 - /// 修改人: - /// 修改日期: - /// 修改备注:gcMain - /// 版本:1.0 - /// - /// The union model. - /// XtraTabPage. - private void RefreshSource(BillSourceUnionModel unionModel = null) - { - if (unionModel == null || unionModel.SearchObj == null) return; - unionModel.SearchObj.SearchLastGrid(); - - - } - - - - /// - /// 说明:刷新单据来源明细 - /// 创建人:龚宇超 - /// 创建日期:2017-11-30 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The union model. - private void RefreshSourceDetail(BillSourceUnionModel unionModel) - { - if (unionModel == null) return; - XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; - - if (unionModel.ModelObj.SourceType == 1) - { - // 树加载明细 - //string fieldName = this.lceCombobox.EditValue; - //string fieldValue = this.textEdit1.Text.Trim(); - string fieldName = string.Empty; - string fieldValue = string.Empty; - string checkStrs = unionModel.TreeViewObj.GetCheckValues(); - string sqlValue = ReplaceHelper.ReplaceParamToValue(ReplaceHelper.ReplaceUserInfo(unionModel.ModelObj.DetailSql), unionModel.TreeViewObj.GetSelectNodeValue()); - - if (!string.IsNullOrEmpty(checkStrs)) - checkStrs = " and SpeciesNo in (" + checkStrs.TrimEnd(',') + ")"; - sqlValue = string.Format("select * from ({0}) temp where 1=1 ", ReplaceHelper.ReplaceWhereCond(sqlValue) + checkStrs) + string.Format(" and ({0} like '%{1}%' or dbo.P_getpy({0}) like '%{1}%')", fieldName, fieldValue); - - try - { - WaitForm.ShowForm(); - unionModel.GridDetailControlObj.GridControl.DataSource = BillImpl.GetDataTableResult(sqlValue); - } - catch (Exception ex) - { - MessageUtil.Show(ex); - LogHelper.Instance.WriteError(ex); - LogUtil.WriteError(BillModel.TypeName + "模块刷新树加载明细出错!", ex); - } - finally - { - WaitForm.HideForm(); - } - } - else - { - // 加载明细 - try - { - WaitForm.ShowForm(); - - - DataRow rowItem = unionModel.GridControlObj.GridView.GetFocusedDataRow(); - //unionModel.GridDetailControlObj.GridControl.DataSource = rowItem == null - // ? new DataTable() : BillImpl.GetDataTableResult(ReplaceHelper.ReplaceRowParam(rowItem, unionModel.ModelObj.DetailSql)); - if (unionModel.ModelObj.SourceType == 3 || unionModel.ModelObj.SourceType == 4) - { - rowItem = unionModel.TreeGridControlObj.GetViewFocusedDataRow(); - } - - - string DetailSql = unionModel.ModelObj.DetailSql; - DetailSql = ReplaceHelper.ReplaceUserInfo(DetailSql); - DetailSql = ReplaceHelper.ReplaceWhereCond(DetailSql); - DetailSql = ReplaceHelper.ReplaceRowParam(rowItem, DetailSql); - if (unionModel.SearchObj != null) - DetailSql = unionModel.SearchObj.ReplaceParentControlValue(DetailSql); - - if (unionModel.ModelObj.sourceDetailType == "1") - { - unionModel.TreeGridDetailControlObj.SetGridViewDataSource(rowItem == null - ? new DataTable() : BillImpl.GetDataTableResult(DetailSql)); - } - else - { - - - //有复选框的页签在刷新前清空选中行,否则合计在刷新数据源后不会自带改变 - if (unionModel.GridDetailControlObj.GridView.OptionsSelection.MultiSelectMode == GridMultiSelectMode.CheckBoxRowSelect && unionModel.GridDetailControlObj.GridView.OptionsSelection.MultiSelect == true) - { - //int[] selectIndexs = unionModel.GridDetailControlObj.GridView.GetSelectedRows(); - unionModel.GridDetailControlObj.GridView.ClearSelection(); - } - - unionModel.GridDetailControlObj.GridControl.DataSource = rowItem == null - ? new DataTable() : BillImpl.GetDataTableResult(DetailSql); - } - - if (unionModel.GridDetailModuleGridEx != null) - { - unionModel.GridDetailModuleGridEx.GridControlObj.LastSearchSql = DetailSql; - } - - - DataTable table = null; - if (unionModel.ModelObj.sourceDetailType == "1") - { - table = unionModel.TreeGridDetailControlObj.TreeListObj.DataSource as DataTable; - } - else - { - table = unionModel.GridDetailControlObj.GridControl.DataSource as DataTable; - } - - if (table != null && !table.Columns.Contains("_check")) - { - table.Columns.Add("_check", typeof(bool)); - foreach (DataRow row in table.Rows) - { - row["_check"] = 0; - } - } - - - - if (tb_buttom.TabControlObj.TabPages.Count > 0) - { - for (int i = 0; i < this.tb_buttom.TabControlObj.TabPages.Count; i++) - { - XtraTabPage page = this.tb_buttom.TabControlObj.TabPages[i]; - if (i == 0) continue; - if (rowItem != null && page != null) - { - this.SetTabPageDataSource(page, rowItem); - } - } - //foreach (XtraTabPage AttachPage in this.tb_buttom.TabControlObj.TabPages) - //{ - // GridDetailModel model = tb_buttom.GetGridDetailModel(AttachPage); - // if (model == null) continue; - // string sqlValue = ReplaceHelper.ReplaceRowParam(rowItem, model.DetailSql); - // this.tb_buttom.SetGridDataSource(AttachPage, sqlValue); - //} - } - } - catch (Exception ex) - { - MessageUtil.Show(ex); - LogHelper.Instance.WriteError(ex); - LogUtil.WriteError(BillModel.TypeName + "模块加载明细出错!", ex); - } - finally - { - WaitForm.HideForm(); - } - } - } - /// - /// 说明:刷新单据来源 - /// 创建人:龚宇超 - /// 创建日期:2019-12-16 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - private void SaveRefreshSource() - { - foreach (XtraTabPage tabPage in this.xtc_main_container.TabPages) - { - BillSourceUnionModel model = tabPage.Tag as BillSourceUnionModel; - if (model != null && model.GridControlObj != null && model.ModelObj.SaveRefreshFlag) - { - this.RefreshSource(model); - this.RefreshSourceDetail(model); - } - } - } - - - - - - /// - /// 说明: - /// 创建人:龚宇超 - /// 创建日期:2017-11-30 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// true if XXXX, false otherwise. - private bool ValidateDetailCond(DataRow rowItem, BillSourceUnionModel unionModel) - { - bool validate = false; - - try - { - string detailCond = ReplaceHelper.ReplaceRowParam(rowItem, unionModel.ModelObj.DetailEnableCond); - detailCond = detailCond.ToLower();//2025-09-08 赵坤表示条件全部转成小写判断。 来源明细中不能配置单元格类型(不能配置 复选框条件 {xxx}=0 ),只能写{xxx}='Ture'。这种bit类型容易忘记大小的情况 - if (detailCond.Contains("#")) - { - List condition = ReplaceHelper.GetParamFields(detailCond); - foreach (string item in condition) - { - string fieldValue = this.ControlObj.GetControlValue(item.Replace("{#", "").Replace("}", "")); - detailCond = detailCond.Replace(item, fieldValue); - } - } - if (detailCond.StartsWith("@") || detailCond.StartsWith("!")) - { - validate = "1".Equals(BaseImpl.GetDefaultValue(detailCond)); - } - else - { - - validate = ReplaceHelper.EvalCond(detailCond); - } - } - catch (Exception ex) - { - LogHelper.Instance.WriteLog(ex.StackTrace); - LogUtil.WriteError("验证多条添加条件出错!", ex); - //MessageUtil.Show(ResourceKeys.CondtionError + "\r\n" + unionModel.ModelObj.DetailEnableCond); - } - return validate; - } - /// - /// 说明:单据来源右键菜单执行完后刷新 - /// 创建人:龚宇超 - /// 创建日期:2017-12-11 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - private void OnGridControlRightCallback(object sender, EventArgs e) - { - this.RefreshSelectedSource(); - - // 执行右键菜单后刷新单据状态2020-03-23 - XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; - BillSourceUnionModel model = tabPage.Tag as BillSourceUnionModel; - } - /// - /// 说明:获取单据管理的单据来源标签 - /// 创建人:龚宇超 - /// 创建日期:2017-12-13 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - private BillSourceUnionModel GetBillSourceManager() - { - foreach (XtraTabPage item in this.xtc_main_container.TabPages) - { - BillSourceUnionModel model = item.Tag as BillSourceUnionModel; - if (model.ModelObj.SourceType == 2) - return model; - } - return null; - } - /// - /// 说明:初始化附加信息 - /// 创建人:龚宇超 - /// 创建日期:2018-04-26 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - private List GetAttachTabs() - { - List details = new List(); - - DataTable table = BaseAuditImpl.GetAttachTabs(this.SysModel.ModuleCode, "100", " and orderid < 0 "); - foreach (DataRow item in table.Rows) - { - DataTable gridColumns = BaseAuditImpl.GetBottomBasicInformation(item["formKey"] + ""); - details.Add(new GridDetailModel(item, gridColumns, GridCustomColumnStruct.BillSourceDetailAttachGridView)); - } - - return details; - } - #endregion - - - - #region 事件相关 - /// - /// 说明:打印完成后回调 - /// 创建人:龚宇超 - /// 创建日期:2018-07-05 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The sender. - /// The e. - private void OnReportPrintAfter(object sender, EventArgs e) - { - //打印完成后添加数据库 - if (_printSaveParams != null && _printSaveParams.Count > 0) - { - int result = BaseModuleImpl.SavePrintRecord(_printSaveParams[0], _printSaveParams[1], _printSaveParams[2], _printSaveParams[3], _printSaveParams[4]); - } - - } - /// - /// 说明: - /// 创建人:龚宇超 - /// 创建日期:2017-11-28 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - private void OnFrmMainKeyDown(object sender, KeyEventArgs e) - { - // 窗口获取按键则表格按键中断.有时间处理 - if (e.Modifiers.CompareTo(Keys.Control) == 0) - { - if (e.KeyCode == Keys.Down) - this.ssc_main.Collapsed = true; - if (e.KeyCode == Keys.Up) - this.ssc_main.Collapsed = false; - } - } - /// - /// 说明:树节点选中刷新明细 - /// 创建人:龚宇超 - /// 创建日期:2017-12-01 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - private void OnTreeNodeSelectAfter(object sender, TreeViewEventArgs e) - { - TreeView tree = (TreeView)sender; - XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; - BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel; - if (unionModel != null) - { - WaitForm.ShowForm(); - try - { - - - string sqlValue = ReplaceHelper.ReplaceUserInfo(ReplaceHelper.ReplaceWhereCond(unionModel.ModelObj.DetailSql)); - sqlValue = sqlValue.Replace("#", ""); - sqlValue = this.ControlObj.ReplaceControlValue(sqlValue); - if (unionModel.SearchObj != null) sqlValue = unionModel.SearchObj.ReplaceControlValue(sqlValue); - sqlValue = ReplaceHelper.ReplaceParamToValue(sqlValue, e.Node.Name); - - if (unionModel.GridDetailModuleGridEx != null) - { - unionModel.GridDetailModuleGridEx.GridControlObj.LastSearchSql = sqlValue; - } - - if (unionModel.ModelObj.sourceDetailType == "1" && unionModel.TreeGridDetailControlObj.TreeListObj != null) - { - unionModel.TreeGridDetailControlObj.TreeListObj.DataSource = BillImpl.GetDataTableResult(sqlValue); - } - else - { - unionModel.GridDetailControlObj.GridControl.DataSource = BillImpl.GetDataTableResult(sqlValue); - } - - } - catch (Exception ex) - { - LogHelper.Instance.WriteError(ex); - LogUtil.WriteError(BillModel.TypeName + "模块选中树节点" + tree.SelectedNode.Text + "刷新明细失败!", ex); - } - finally - { - WaitForm.HideForm(); - } - } - } - /// - /// 说明:单据来源切换Tab标签 - /// 创建人:龚宇超 - /// 创建日期:2017-11-28 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - private void OnTabSelectedPageChanged(object sender, TabPageChangedEventArgs e) - { - try - { - if (_isInitFinish && !SystemInfo.Instance.IsBillSourceRefushTag.Equals("1")) - { - BillSourceUnionModel unionModel = e.Page.Tag as BillSourceUnionModel; - if (unionModel != null) - { - this.RefreshSelectedSource(); - this.tb_buttom.TabControlObj.TabPages[0].Controls.Clear(); - if (unionModel.GridDetailModuleGridEx != null) - { - this.tb_buttom.TabControlObj.TabPages[0].Controls.Add(unionModel.GridDetailModuleGridEx); - } - else if (unionModel.GridDetailDetailControlObj == null) - { - this.tb_buttom.TabControlObj.TabPages[0].Controls.Add(unionModel.GridDetailControlObj != null ? unionModel.GridDetailControlObj : unionModel.TreeGridDetailControlObj); - } - else - { - //this.tb_buttom.TabControlObj.TabPages[0].Controls.Add(unionModel.GridDetailDetailControlObj); - //创建SplitContainerControl控件,让下方可以左右拖动 - SplitContainerControl splitContainerControl = new DevExpress.XtraEditors.SplitContainerControl(); - splitContainerControl.Dock = DockStyle.Fill; - splitContainerControl.Panel1.Controls.Add(unionModel.GridDetailControlObj); - splitContainerControl.Panel2.Controls.Add(unionModel.GridDetailDetailControlObj); - int width = this.tb_buttom.Width;//获取控件宽度 - splitContainerControl.SplitterPosition = width / 2;//然后将分割位置设置在宽度一半位置 - this.tb_buttom.TabControlObj.TabPages[0].Controls.Add(splitContainerControl); - } - this.tb_buttom.TabControlObj.TabPages[0].Text = unionModel.ModelObj.UserName + DetailedSuffix; - if (unionModel.IsChange == false) - { - AutoSizeChange.ControllInitializeSize(this.tb_buttom.TabControlObj.TabPages[0]); - unionModel.IsChange = true; - } - } - } - } - catch (Exception ex) - { - LogHelper.Instance.WriteError(ex); - LogUtil.WriteError("单据切换标签失败!", ex); - } - } - /// - /// 说明:单据来源树结构默认查询条件 - /// 创建人:龚宇超 - /// 创建日期:2017-11-28 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - private void OnTreeSearchClick(object sender, EventArgs e) - { - XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; - - this.RefreshSourceDetail(tabPage.Tag as BillSourceUnionModel); - } - - /// - /// 单据来源树 条件框回车查询 - /// - /// - /// - private void OnTreeConditionKeyDown(object sender, KeyEventArgs e) - { - if (e.KeyCode == Keys.Enter) - { - this.OnTreeSearchClick(null, null); - } - - } - - - /// - /// 说明:第一个页签初始化完成刷新数据 - /// 创建人:龚宇超 - /// 创建日期: - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The sender. - /// The instance containing the event data. - private void OnFirstPageDataSourceBindCallBack(object sender, EventArgs e) - { - try - { - if (IsBillMaster) - { - this.RefreshSelectedSource(); - } - } - catch (Exception ex) - { - LogHelper.Instance.WriteError(ex); - LogUtil.WriteError("单据切换标查询失败!", ex); - } - } - /// - /// 说明:第一个页签初始化完成刷新数据 - /// 创建人:龚宇超 - /// 创建日期: - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The sender. - /// The instance containing the event data. - private void OnPageDataSourceBindCallBack(object sender, EventArgs e) - { - try - { - MyControl searchControl = sender as MyControl; - XtraTabPage tabPage = pageNumKey[searchControl]; - if (tabPage.TabIndex == 0) return; - BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel; - string searchSql = unionModel.ModelObj.SourceSql; - searchSql = ReplaceHelper.ReplaceUserInfo(searchSql); - searchSql = ReplaceHelper.ReplaceWhereCond(searchSql); - searchSql = unionModel.SearchObj.SetSearchSqlValue(searchSql, true, true); - // 查找FROM子句的位置 - int fromIndex = searchSql.IndexOf("FROM", StringComparison.OrdinalIgnoreCase); - if (fromIndex != -1) - { - // 生成优化后的SQL查询 - string optimizedSql = "SELECT COUNT(*) " + searchSql.Substring(fromIndex); - searchSql = optimizedSql; - } - DataTable dt = MainImpl.GetDataTableResult(searchSql); - if (dt.Rows.Count > 0) tabPage.Text += "(" + dt.Rows[0][0] + QuantitySuffix; - } - catch (Exception ex) - { - LogHelper.Instance.WriteError(ex); - LogUtil.WriteError("单据条件绑定失败失败!", ex); - } - } - - /// - /// 跳转到指定页签,并执行配置条件的搜索 - /// - /// - /// - private void SearchControl_OnDataSourceBindCallBack(object sender, EventArgs e) - { - if (InitialSelectionTab != null) - { - this.xtc_main_container.SelectedTabPage = InitialSelectionTab; - BillSourceUnionModel model = InitialSelectionTab.Tag as BillSourceUnionModel; - if (model.SearchObj != null) model.SearchObj.SearchGrid(); - } - } - - /// - /// 说明:单据来源选中行,加载明细 - /// 创建人:龚宇超 - /// 创建日期:2017-11-30 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - private void OnGridControlSelectionChanged(object sender, SelectionChangedEventArgs e) - { - XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; - - this.RefreshSourceDetail(tabPage.Tag as BillSourceUnionModel); - } - /// - /// 说明:单据来源选中行,加载明细 - /// 创建人:龚宇超 - /// 创建日期:2017-11-30 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - private void OnGridViewRowCellClick(object sender, RowCellClickEventArgs e) - { - - XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; - BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel; - this.RefreshSourceDetail(unionModel); - } - - - - - private void OnSourceGridViewDoubleClick(object sender, EventArgs e) - { - - XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; - BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel; - //this.RefreshSourceDetail(unionModel); - DataRow rowItem = unionModel.GridControlObj.GridView.GetFocusedDataRow(); - if (rowItem == null) - return; - //单据号 - string billno = rowItem[BillModel.PrimaryKey] + ""; - - DynamicBillModel model = CloneDynamicBillModel(this.SysModel); - model.BillOrderNo = billno; - FrmBill frmBill = new FrmBill(model); - frmBill.Text = string.Format("{0}-详情[单据编号:{1}]", this.BillModel.TypeName, billno); - frmBill.ShowDialog(); - //刷新界面 - unionModel.SearchObj.SearchLastGrid(); - - } - - - // - /// 复制单据动态参数,保留原对象的运行时配置和缓存。 - /// - private static DynamicBillModel CloneDynamicBillModel(DynamicBillModel source) - { - if (source == null) - return null; - - MethodInfo method = typeof(object).GetMethod( - "MemberwiseClone", - BindingFlags.Instance | BindingFlags.NonPublic); - - return method.Invoke(source, null) as DynamicBillModel; - } - - - - /// - /// 说明:单据明细选中刷新附件明细 - /// 创建人:王一帆 - /// 创建日期:2021-06-30 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - private void OngcMainRowCellClick(object sender, RowCellClickEventArgs e) - { - if (this.tb_buttom.TabControlObj.TabPages.Count > 1) - { - SetDetailGridDataSource(); - } - } - - - - /// - /// 切换下方附加模块页签时,刷新当前页签 - /// - /// - /// - private void TabControlObj_SelectedPageChanged(object sender, TabPageChangedEventArgs e) - { - if (this.tb_buttom.TabControlObj.TabPages.Count > 1) - { - SetDetailGridDataSource(); - } - } - - /// - /// 说明:获取底部多标签数据 - /// 创建人:龚宇超 - /// 创建日期:2017-12-19 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - public void SetDetailGridDataSource() - { - DataRow rowItem = null; - //DataRow rowItem = this.gcMain.GridView.GetFocusedDataRow(); - //if (this.BillModel.DetailTreeTable) - //{ - // rowItem = (this.gcMain as TreeGridControlEx).GetViewFocusedDataRow(); - //} - int i = 0; - foreach (XtraTabPage page in this.tb_buttom.TabControlObj.TabPages) - { - if (i == 0) - { - i++; - continue; - } - if (this.BillModel.RefreshSelectedDetail && page != tb_buttom.TabControlObj.SelectedTabPage) - { - continue; - } - if (rowItem != null && page != null) - { - this.SetTabPageDataSource(page, rowItem); - } - } - } - - - - - /// - /// 说明:设置表格数据 - /// 创建人:龚宇超 - /// 创建日期:2018-01-29 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The tab page. - /// The grid control. - public void SetTabPageDataSource(XtraTabPage tabPage, DataRow rowItem) - { - - GridDetailModel model = this.tb_buttom.GetGridDetailModel(tabPage); - if (rowItem != null && model != null) - { - if (tabPage.Tag is ModuleWebView) - { - // 加载网页 - string url = ReplaceHelper.ReplaceRowParam(rowItem, ReplaceHelper.ReplaceUserInfo(model.DetailSql)); - url = url.StartsWith("http") ? url : SystemInfo.Instance.OAUrl + url; - ModuleWebView webView = tabPage.Tag as ModuleWebView; - webView.Dock = DockStyle.Fill; - webView.Tag = model; - webView.Navigate(url); - } - else if (tabPage.Tag is FrmWebBrowser) - { - // 加载网页 - string url = ReplaceHelper.ReplaceRowParam(rowItem, ReplaceHelper.ReplaceUserInfo(model.DetailSql)); - url = url.StartsWith("http") ? url : SystemInfo.Instance.OAUrl + url; - FrmWebBrowser webView = tabPage.Tag as FrmWebBrowser; - webView.Dock = DockStyle.Fill; - webView.Tag = model; - webView.LoadUrl(url); - } - else if (tabPage.Tag is FrmMiniBlink) - { - // 加载网页 - string url = ReplaceHelper.ReplaceRowParam(rowItem, ReplaceHelper.ReplaceUserInfo(model.DetailSql)); - url = url.StartsWith("http") ? url : SystemInfo.Instance.OAUrl + url; - FrmMiniBlink webView = tabPage.Tag as FrmMiniBlink; - webView.Dock = DockStyle.Fill; - webView.Tag = model; - webView.LoadUrl(url); - } - else if (tabPage.Tag is TabMultipledetails) - { - TabMultipledetails tabMultipledetails = tabPage.Tag as TabMultipledetails; - tabMultipledetails.SetConditionValues(rowItem); - - GridControlEx grdExMain = (tabMultipledetails.SplitMain.Panel1.Tag as GridControlEx); - GridDetailModel MainModel = grdExMain.Tag as GridDetailModel; - string searchMainSql = this.GetSearchSql(MainModel, rowItem); - DataTable firstTable = MainImpl.GetDataTableResult(searchMainSql); - grdExMain.LastSearchSql = searchMainSql; - grdExMain.SetGridViewDataSource(firstTable); - - if (tabMultipledetails.SplitMain.Panel2.Tag is GridControlEx) - { - GridControlEx grdExAdditional = (tabMultipledetails.SplitMain.Panel2.Tag as GridControlEx); - GridDetailModel AdditionalModel = grdExAdditional.Tag as GridDetailModel; - string searchAddSql = this.GetSearchSql(AdditionalModel, rowItem); - if (!MainModel.IsUnioDetail) - { - grdExAdditional.LastSearchSql = searchAddSql; - grdExAdditional.SetGridViewDataSource(MainImpl.GetDataTableResult(searchAddSql)); - } - //右侧是左侧的明细,左侧没有数据时。右侧赋空值(因为无法触发左侧行改变事件) - if (MainModel.IsUnioDetail && firstTable.Rows.Count == 0) - { - grdExAdditional.LastSearchSql = ""; - grdExAdditional.SetGridViewDataSource(new DataTable()); - } - } - else if (tabMultipledetails.SplitMain.Panel2.Tag is ChartControlEx) - { - ChartControlEx grdExAdditional = (tabMultipledetails.SplitMain.Panel2.Tag as ChartControlEx); - GridDetailModel AdditionalModel = grdExAdditional.Tag as GridDetailModel; - string searchAddSql = this.GetSearchSql(AdditionalModel, rowItem); - DataTable table = MainImpl.GetDataTableResult(searchAddSql); - grdExAdditional.CreateChart(table); - } - - tabPage.Text = MainModel.DetailName + "(" + firstTable.Rows.Count + QuantitySuffix; - //tabPage.Text = MainModel.DetailName + "(" + firstTable.Rows.Count + "条)"; - //tabPage.Appearance.Header.ForeColor = firstTable.Rows.Count > 0 ? Color.Red : Color.FromArgb(0, 0, 0); - } - else - { - string searchSql = this.GetSearchSql(model, rowItem); - if (tabPage.Tag is GridControlEx) - { - (tabPage.Tag as GridControlEx).LastSearchSql = searchSql; - } - this.tb_buttom.SetGridDataSource(tabPage, MainImpl.GetDataTableResult(searchSql)); - if (tabPage.Tag is GridControlEx && (tabPage.Tag as GridControlEx).ParentControl != null) - (tabPage.Tag as GridControlEx).ParentControl.SetAllControlValue(rowItem); - //配置明细直接根据条件加载 - if (model.SystemModel != null && 1 == model.SystemModel.isFirstLoad) - { - (tabPage.Tag as GridControlEx).ParentControl.SearchGrid(); - GridControlEx gridControlEx = tabPage.Tag as GridControlEx; - - if (gridControlEx.CustomGroupBandEx != null) - { - tabPage.Text = model.DetailName + "(" + gridControlEx.CustomGroupBandEx.DataRowCount() + QuantitySuffix; - } - else if (gridControlEx.CustomGroupTreeBandEx != null) - { - tabPage.Text = model.DetailName + "(" + gridControlEx.CustomGroupTreeBandEx.DataRowCount() + QuantitySuffix; - } - else - { - tabPage.Text = model.DetailName + "(" + (tabPage.Tag as GridControlEx).ParentControl.GridRowCount + QuantitySuffix; - } - //tabPage.Text = gridControlEx.CustomGroupBandEx != null ? model.DetailName + "(" + gridControlEx.CustomGroupBandEx.DataRowCount() + "条)" : model.DetailName + "(" + (tabPage.Tag as GridControlEx).ParentControl.GridRowCount + "条)"; - //tabPage.Text = model.DetailName + "(" + (tabPage.Tag as GridControlEx).ParentControl.GridRowCount + "条)"; - } - //附加信息根据主表明细选中行,判断配置的按钮条件 - Object moduleObject = tabPage.Controls.Cast().FirstOrDefault(); - ModuleGridEx moduleGridEx = null; - if (moduleObject is ModuleGridEx) - { - moduleGridEx = moduleObject as ModuleGridEx; - moduleGridEx.ParentButtonState(rowItem); - } - - } - } - - } - /// - /// 说明:获取查询条件 - /// 创建人:龚宇超 - /// 创建日期:2017-11-22 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The model. - /// The row item. - /// System.String. - protected string GetSearchSql(GridDetailModel model, DataRow rowItem) - { - string fieldName = !string.IsNullOrEmpty(model.UnionParentField) && rowItem.Table.Columns.Contains(model.UnionParentField) ? model.UnionParentField : BillModel.PrimaryKey; - string sqlValue = model.IsReadOnly || model.IsChart ? model.DetailSql : model.SystemModel.MenuSql; - string unioValue = string.Empty; - unioValue = rowItem.Table.Columns.Contains(fieldName) ? rowItem[fieldName] + "" : string.Empty; - if (this.ControlObj != null && string.IsNullOrEmpty(unioValue)) - { - unioValue = !string.IsNullOrEmpty(model.UnionParentField) && this.ControlObj.FindControl(model.UnionParentField) != null ? this.ControlObj.GetControlValue(model.UnionParentField) : unioValue; - } - sqlValue = ReplaceHelper.ReplaceRowParam(rowItem, sqlValue); - sqlValue = this.ControlObj.ReplaceControlValue(sqlValue);//后替换主表内容 - if (ReplaceHelper.IsSelect(sqlValue) && !string.IsNullOrEmpty(model.UnionValue)) - { - sqlValue = ReplaceHelper.ReplaceWhereCond(sqlValue) + string.Format(" and {0}='{1}'", model.UnionValue, unioValue); - } - if (!string.IsNullOrEmpty(model.UnionCond)) - { - string UnionCond = ReplaceHelper.ReplaceRowParam(rowItem, model.UnionCond); - sqlValue += UnionCond; - } - return sqlValue; - } - /// - /// 说明:单据来源选中行,加载明细 - /// 创建人:龚宇超 - /// 创建日期:2019-07-25 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The sender. - /// The instance containing the event data. - private void OnTreeListObjFocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e) - { - XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; - - this.RefreshSourceDetail(tabPage.Tag as BillSourceUnionModel); - } - /// - /// 说明:单据来源明细右键菜单执行后刷新数据 - /// 创建人:龚宇超 - /// 创建日期:2017-12-19 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - private void OnGridDetailRightMenuCallback(object sender, EventArgs e) - { - XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; - - this.RefreshSourceDetail(tabPage.Tag as BillSourceUnionModel); - } - - - - - - /// - /// 说明:分割条移动保存位置 - /// 创建人:龚宇超 - /// 创建日期:2018-03-06 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. + /// + /// 说明:初始化系统配置 + /// 创建人:龚宇超 + /// 创建日期:2017-11-27 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + private void InitializeSetting() + { + Dictionary dataCaches = SysModel != null ? SysModel.DataCaches : null; + if (!dataCaches.GetValue(this, "BillInfo", out DataRow modelRow)) + { + modelRow = BillImpl.GetBillInfo(this.SysModel.ModuleCode);//获取单个模块信息 + } + if (modelRow == null) + { + throw new Exception("模块编号[" + this.SysModel.ModuleCode + "],配置错误!\r\n该模块信息未找到!"); + } + if (!dataCaches.GetValue(this, "BillModel", out BillModel)) + { + this.BillModel = new BillModel(modelRow);//初始化类的新实例。 + } + + if (this.BillModel != null) + { + this.BillModel.TypeName = string.IsNullOrEmpty(SysModel.BillMasterSql) ? this.SysModel.FormText : this.BillModel.TypeName;// 模块名称 + if (!string.IsNullOrWhiteSpace(this.SysModel.DocumentName)) this.BillModel.TypeName = this.SysModel.DocumentName; + + if (!dataCaches.GetValue(this, "MasterPreFix", out string masterPreFix)) + { + masterPreFix = BaseImpl.GetColumnPrefix(this.BillModel.MasterTable);// 主表列前缀 + } + this.BillModel.MasterPreFix = masterPreFix; + if (!dataCaches.GetValue(this, "DetailPreFix", out string detailPreFix)) + { + detailPreFix = BaseImpl.GetColumnPrefix(this.BillModel.DetailTable);// 明细表列前缀 + } + this.BillModel.DetailPreFix = detailPreFix; + this.BillModel.DetailOrderField = this.BillModel.DetailPreFix + "lsidx_id";// 单据来源id + if (SystemInfo.Instance.IsNotBillDetailOrder)//禁用排序 + this.BillModel.DetailOrderField = string.Empty; + } + if (!dataCaches.GetValue(this, "MenuConfigTab", out DataRow menuRow)) + { + menuRow = BaseImpl.GetMenuConfigTab(this.SysModel.ModuleId);//获取菜单其他配置 + } + if (menuRow != null) + { + this.BillModel.BillSourceIds = menuRow.Table.Columns.Contains("BillSourceIds") ? (menuRow["BillSourceIds"] + "").Trim(',') : string.Empty; + this.BillModel.BillFlag = menuRow.Table.Columns.Contains("BillFlag") && !string.IsNullOrEmpty(menuRow["BillFlag"] + "") ? Convert.ToInt32(menuRow["BillFlag"] + "") : -1; + } + if (this.SysModel.HideSource) + { + this.BillModel.PanelWidth = 0; + this.BillModel.PanelHeight = 0; + } + + if (!dataCaches.GetValue(this, "BillSetting", out bool _)) + { + BillImpl.InitBillSetting(this.BillModel); + } + } + + /// + /// 说明:初始化控件 + /// 创建人:龚宇超 + /// 创建日期:2017-11-23 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + private void InitializeControl() + { + this.InitializeBillSource();//初始化单据来源 + } + + + /// + /// 点击第一个默认新增行新增默认数据 + /// + /// + /// + private void GridView_MouseDown(object sender, MouseEventArgs e) + { + + } + + + /// + /// 说明:初始化单据来源 + /// 创建人:龚宇超 + /// 创建日期:2017-11-28 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + private void InitializeBillSource() + { + this.xtc_main_container.TabPages.Clear(); + + Dictionary dataCaches = SysModel != null ? SysModel.DataCaches : null; + if (dataCaches != null && + dataCaches.GetTask(tb_buttom, "DynamicModel") != null && + dataCaches.GetTask>(tb_buttom, "Details") != null) + { + // 该方法会预创建附加页控件,必须在 UI 线程执行。 + tb_buttom.GetDataCaches(dataCaches); + } + if (!dataCaches.GetValue(this, "Details", out List attachModels)) + { + attachModels = GetAttachTabs(); + } + if (!dataCaches.GetValue(this, "Sources", out Hashtable htTable)) + { + string SourceIds = (this.BillModel.BillSourceIds + "").Trim(','); + if (!string.IsNullOrWhiteSpace(this.SysModel.SourceDetailsID)) + { + SourceIds = (SourceIds + "," + this.SysModel.SourceDetailsID).Trim(','); + } + htTable = BillImpl.GetSources(this.SysModel.ModuleCode, SourceIds);//获取单据来源 + } + DataTable masterTable = htTable["master"] as DataTable; + DataTable detailTable = htTable["detail"] as DataTable; + + + + + /* 构造原理 + * 1. 假如存在附加信息,则底部显示来源明细(来源明细摆放在标签第一个位置)+多标签,假如标签只有一个则隐藏标签头. + * 2. 假如不存在附加信息,则底部只显示来源明细. + **/ + if (attachModels.Count > 0) + { + this.tb_buttom.Model = this.SysModel; + this.tb_buttom.ParentControlEx = this.ControlObj; + //this.tb_buttom.ParentGridEx = this.gcMain; + if (this.BillModel.RefreshSelectedDetail) + { + //配置了只刷新当前页签后,切换页签时刷新 + this.tb_buttom.TabControlObj.SelectedPageChanged += TabControlObj_SelectedPageChanged; + } + this.tb_buttom.InitTabPages(attachModels); + + } + else + { + this.tb_buttom.TabControlObj.ShowTabHeader = DevExpress.Utils.DefaultBoolean.False; + } + dataCaches.GetValue(this, "InitSourcesTask", out bool _); + + int SerialNumber = 0; + for (int i = 0; i < masterTable.Rows.Count; i++) + { + DataRow sourceModelRow = masterTable.Rows[i]; + BillModuleModel billModuleModel = BillModuleModelDic.ContainsKey(sourceModelRow) ? BillModuleModelDic[sourceModelRow] : new BillModuleModel(); + BillSourceModel model = billModuleModel.SourceModel != null ? billModuleModel.SourceModel : new BillSourceModel(sourceModelRow); + object sourceControl = billModuleModel.SourceControl != null ? billModuleModel.SourceControl : null; + object sourceDetailControl = billModuleModel.SourceDetailControl != null ? billModuleModel.SourceDetailControl : null; + object sourceDetailDetailControl = billModuleModel.SourceDetailDetailControl != null ? billModuleModel.SourceDetailDetailControl : null; + BillSourceUnionModel unionModel = new BillSourceUnionModel(); + if (!dataCaches.GetValue(model, "CustomQueryFields", out DataTable controls)) + { + controls = BaseModuleImpl.GetCustomQueryFields(model.FormKey); + } + + + XtraTabPage tabPage = new XtraTabPage(); + tabPage.Text = model.UserName; + + //只加载单据管理类型 + if (!(model.SourceType == 2 || model.SourceType == 4)) continue; + + + #region 加载来源表头 + GridControlEx gridControl = null; + TreeViewEx treeView = null; + + if (model.SourceType == 1) + { + // 来源为树类型 + treeView = sourceControl != null ? (TreeViewEx)sourceControl : new TreeViewEx(); + treeView.BorderStyle = BorderStyle.None; + treeView.Dock = DockStyle.Fill; + treeView.TreeNodeKeyField = model.SourceKeyField; + treeView.TreeNodeTextField = model.SourceResult; + if (!dataCaches.GetValue(billModuleModel, "BindTreeTable", out DataTable bindTreeTable)) + { + bindTreeTable = BaseImpl.GetDataTableResult(model.SourceSql); + } + treeView.TreeInhibitSort = model.TreeInhibitSort; + treeView.BindTreeView(bindTreeTable); + treeView.TreeNodeSelectAfter += new TreeViewEventHandler(OnTreeNodeSelectAfter); + + tabPage.Controls.Add(treeView); + } + else if (model.SourceType == 5) + { + model.ChangeSourceType(2);//单据来源显示条数 + this.IsBillShowCount = true; + } + else if (model.SourceType == 3 || model.SourceType == 4) + { + //类型为3,是树表格类型的单据管理。 + //类型为4,是树表格类型的数据来源 + gridControl = sourceControl != null ? (TreeGridControlEx)sourceControl : new TreeGridControlEx(); + gridControl.Dock = DockStyle.Fill; + gridControl.BorderStyle = System.Windows.Forms.BorderStyle.None; + gridControl.Model = this.SysModel; + + AttachCachedTask(dataCaches, billModuleModel, + "SourceCustomColumnByDatabase", gridControl, + "CustomColumnByDatabase"); + if (!dataCaches.GetValue(billModuleModel, "SourceColumns", out DataTable dtSourceColumns)) + { + dtSourceColumns = BillImpl.GetSourceColumns(model.Id); + } + if (!dataCaches.GetValue(billModuleModel, "SourceBaseGridRowColors", out DataTable dtBaseGridRowColors)) + { + dtBaseGridRowColors = BaseModuleImpl.GetBaseGridRowColors("BILLSOURCE_" + model.FormKey); + } + if (!dataCaches.GetValue(billModuleModel, "SourceBaseGridRightMenus", out DataTable dtBaseGridRightMenus)) + { + dtBaseGridRightMenus = BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCE_" + model.FormKey); + } + + //节点编号 + if (!string.IsNullOrWhiteSpace(model.SourceKeyFieldName)) (gridControl as TreeGridControlEx).TreeListObj.KeyFieldName = model.SourceKeyFieldName; + //父节点编号 + if (!string.IsNullOrWhiteSpace(model.SourceParentFieldName)) (gridControl as TreeGridControlEx).TreeListObj.ParentFieldName = model.SourceParentFieldName; + + gridControl.SetReadOnlyColumns(dtSourceColumns, GridCustomColumnStruct.BillSourceGridView + model.FormKey); + gridControl.SetGridRowColors(dtBaseGridRowColors); + //gridControl.SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridControlRightCallback); + (gridControl as TreeGridControlEx).SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridControlRightCallback); + unionModel.TreeGridControlObj = gridControl as TreeGridControlEx; + unionModel.TreeGridControlObj.TreeListObj.FocusedNodeChanged += new DevExpress.XtraTreeList.FocusedNodeChangedEventHandler(OnTreeListObjFocusedNodeChanged); + + + if (BillModel.IsBillSourceCheck == 1) + { + GridDragGrid.TreeListAddCheckBox((gridControl as TreeGridControlEx).TreeListObj); + } + tabPage.Controls.Add(gridControl); + } + else + { + // 来源为表格类型 + gridControl = sourceControl != null ? (GridControlEx)sourceControl : new GridControlEx(); + gridControl.BorderStyle = BorderStyle.None; + gridControl.Model = this.SysModel; + gridControl.Dock = DockStyle.Fill; + gridControl.ExportPermission = this.BillModel.ExportPermission; + + AttachCachedTask(dataCaches, billModuleModel, + "SourceCustomColumnByDatabase", gridControl, + "CustomColumnByDatabase"); + if (model.LoadFilter) + { + gridControl.GridView.OptionsView.ShowAutoFilterRow = true; + } + if (!dataCaches.GetValue(billModuleModel, "SourceColumns", out DataTable dtSourceColumns)) + { + dtSourceColumns = BillImpl.GetSourceColumns(model.Id); + } + if (!dataCaches.GetValue(billModuleModel, "SourceBaseGridRowColors", out DataTable dtBaseGridRowColors)) + { + dtBaseGridRowColors = BaseModuleImpl.GetBaseGridRowColors("BILLSOURCE_" + model.FormKey); + } + if (!dataCaches.GetValue(billModuleModel, "SourceBaseGridRightMenus", out DataTable dtBaseGridRightMenus)) + { + dtBaseGridRightMenus = BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCE_" + model.FormKey); + } + gridControl.SetReadOnlyColumns(dtSourceColumns, GridCustomColumnStruct.BillSourceGridView + model.FormKey); + gridControl.SetGridRowColors(dtBaseGridRowColors); + gridControl.SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridControlRightCallback); + //gridControl.GridView.SelectionChanged += new SelectionChangedEventHandler(OnGridControlSelectionChanged); + //gridControl.GridView.FocusedRowObjectChanged += OnFocusedRowObjectChanged; + //if (model.DetailsDoubleClick) + //{ + // gridControl.GridView.DoubleClick += OnSourceGridViewDoubleClick; // 2023-3-11 增加双击配置 + //} + //else + //{ + // gridControl.GridView.RowCellClick += OnGridViewRowCellClick; // 2019-11-12 cmd提出改为行点击事件,否则会出现保存提交后,单据管理无法查询出数据 + //} + + gridControl.GridView.RowCellClick += OnGridViewRowCellClick; // 2019-11-12 cmd提出改为行点击事件,否则会出现保存提交后,单据管理无法查询出数据 + + gridControl.GridView.DoubleClick += OnSourceGridViewDoubleClick;//双击事件改成打开单据主消息控件 + + + if (BillModel.IsBillSourceCheck == 1) + { + GridDragGrid.GridAddCheckBox(gridControl.GridView); + } + tabPage.Controls.Add(gridControl); + } + #endregion + + #region 加载来源明细 + XtraTabPage tabDetail = new XtraTabPage(); + + if (SystemInfo.Instance.GridRowFontSize > 0) + { + //页签大小 + FontFamily fontFamily = tabDetail.Appearance.Header.Font.FontFamily; + tabDetail.Appearance.Header.Font = new System.Drawing.Font(fontFamily, SystemInfo.Instance.GridRowFontSize); + } + + DataRow[] detailColumns = detailTable.Select("sourceId=" + model.Id); + + + //明细为表格 + GridControlEx gridDetail = new GridControlEx(); + + + + if (!string.IsNullOrWhiteSpace(model.DetailMenuCode)) + { + //来源明细配置了模块号,根据模块号创建对应的ModuleGridEx + //ModuleGridEx主要是用保存的功能,数据源sql还是根据配置的为准 + DataRow modelRow = MainImpl.GetSystemdllTab(model.DetailMenuCode);//获取模块信息 + if (modelRow == null) + { + MessageUtil.Show($"没有找到编号为 {model.DetailMenuCode} 的模块信息"); + gridDetail.Parent = gridDetail; + continue; + } + + ModuleModel sysModel = new ModuleModel(modelRow); + //设置主表sql + //model.SourceSql = sysModel.MenuSql; + + DynamicModuleModel dyncModel = new DynamicModuleModel(new[] + { sysModel.MenuName, ERPInfo.Instance.UserId, ERPInfo.Instance.UserName, + this.SysModel.Privilege, sysModel.ModeCode, "0" }); + + ModuleGridEx gridEx = new ModuleGridEx(); + gridEx.Dock = DockStyle.Fill; + if (model.SourceType == 1) + { + gridEx.LeftTreeViewEx = treeView; + } + else + { + gridEx.LeftGridEx = gridControl; + gridEx.ParentGridEx = gridControl; + } + gridEx.ParentKeyField = model.SourceKeyField; + gridEx.ParentUnionField = model.SourceKeyField; + + gridEx.VisibleSearchPanel = false;//禁止上方搜索 + gridEx.InitializeControl(sysModel, dyncModel); + + + gridDetail = gridEx.GridControlObj; + gridEx.Parent = tabDetail; + unionModel.GridDetailModuleGridEx = gridEx; + + if (sysModel.TreeAutoMultiHeader == 1) model.ChangeSourceDetailType("1"); + + + + if (SerialNumber == 0) + { + this.tb_buttom.TabControlObj.TabPages.Insert(0, tabDetail); + this.tb_buttom.TabControlObj.SelectedTabPageIndex = 0; + if (attachModels.Count > 0) + this.tb_buttom.TabControlObj.TabPages[0].Text = model.UserName + DetailedSuffix; + } + + } + else + { + if (model.sourceDetailType.Equals("1")) + { + //明细为树表格 + gridDetail = sourceDetailControl != null ? (TreeGridControlEx)sourceDetailControl : new TreeGridControlEx(); + gridDetail.Model = this.SysModel; + gridDetail.Dock = DockStyle.Fill; + AttachCachedTask(dataCaches, billModuleModel, + "SourceDetailCustomColumnByDatabase", gridDetail, + "CustomColumnByDatabase"); + gridDetail.SetReadOnlyColumns(detailColumns == null || detailColumns.Length == 0 ? new DataTable() : detailColumns.CopyToDataTable(), GridCustomColumnStruct.BillSourceDetailGridView + model.FormKey); + if (!dataCaches.GetValue(billModuleModel, "SourceDetailBaseGridRowColors", out DataTable dtBaseGridRowColors)) + { + dtBaseGridRowColors = BaseModuleImpl.GetBaseGridRowColors("SOURCEDETAIL_" + model.FormKey); + } + if (!dataCaches.GetValue(billModuleModel, "SourceDetailBaseGridRightMenus", out DataTable dtBaseGridRightMenus)) + { + dtBaseGridRightMenus = BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCEDT_" + model.FormKey); + } + gridDetail.SetGridRowColors(dtBaseGridRowColors); + gridDetail.SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridDetailRightMenuCallback); + gridDetail.Parent = tabDetail; + gridDetail.BorderStyle = System.Windows.Forms.BorderStyle.None; + + if (SerialNumber == 0) + { + this.tb_buttom.TabControlObj.TabPages.Insert(0, tabDetail); + this.tb_buttom.TabControlObj.SelectedTabPageIndex = 0; + if (attachModels.Count > 0) + this.tb_buttom.TabControlObj.TabPages[0].Text = model.UserName + DetailedSuffix; + } + + if (BillModel.IsBillDetailCheck == 1)//加载复选框 + { + GridDragGrid.TreeListAddCheckBox((gridDetail as TreeGridControlEx).TreeListObj); + } + } + else + { + + gridDetail = sourceDetailControl != null ? (GridControlEx)sourceDetailControl : new GridControlEx(); + gridDetail.Model = this.SysModel; + gridDetail.Dock = DockStyle.Fill; + AttachCachedTask(dataCaches, billModuleModel, + "SourceDetailCustomColumnByDatabase", gridDetail, + "CustomColumnByDatabase"); + gridDetail.SetReadOnlyColumns(detailColumns == null || detailColumns.Length == 0 ? new DataTable() : detailColumns.CopyToDataTable(), GridCustomColumnStruct.BillSourceDetailGridView + model.FormKey); + + if (model.DetailedLoadFilter) + { + gridDetail.GridView.OptionsView.ShowAutoFilterRow = true; + } + if (!dataCaches.GetValue(billModuleModel, "SourceDetailBaseGridRowColors", out DataTable dtBaseGridRowColors)) + { + dtBaseGridRowColors = BaseModuleImpl.GetBaseGridRowColors("SOURCEDETAIL_" + model.FormKey); + } + if (!dataCaches.GetValue(billModuleModel, "SourceDetailBaseGridRightMenus", out DataTable dtBaseGridRightMenus)) + { + dtBaseGridRightMenus = BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCEDT_" + model.FormKey); + } + gridDetail.SetGridRowColors(dtBaseGridRowColors); + gridDetail.SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridDetailRightMenuCallback); + + //明细的明细(明细分成左右2个) + if (!string.IsNullOrEmpty(model.SourceDetailsDetailsSql)) + { + GridControlEx gridDetail_Details = sourceDetailDetailControl != null ? (GridControlEx)sourceDetailDetailControl : new GridControlEx(); + gridDetail_Details.Model = this.SysModel; + gridDetail_Details.Dock = DockStyle.Fill; + //创建只读列 + if (!dataCaches.GetValue(billModuleModel, "DetailDetails", out DataTable dataTable)) + { + dataTable = BaseModuleImpl.getDetail_Details(model.FormKey); + } + AttachCachedTask(dataCaches, billModuleModel, + "SourceDetailDetailsCustomColumnByDatabase", + gridDetail_Details, "CustomColumnByDatabase"); + gridDetail_Details.SetReadOnlyColumns(dataTable); + //设置右键 + if (!dataCaches.GetValue(billModuleModel, "SourceDetailDetailsBaseGridRightMenus", out DataTable dttBaseGridRightMenus)) + { + dttBaseGridRightMenus = BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCEDTX_" + model.FormKey); + } + gridDetail_Details.SetGridRightMenus(dttBaseGridRightMenus, this.SysModel, OnGridDetailRightMenuCallback); + //明细点击 更新 明细的明细 + gridDetail.GridView.FocusedRowObjectChanged += GridView_FocusedRowObjectChanged; + gridDetail.GridView.Tag = model.SourceDetailsDetailsSql; + //创建SplitContainerControl控件,让下方可以左右拖动 + SplitContainerControl splitContainerControl = new DevExpress.XtraEditors.SplitContainerControl(); + splitContainerControl.Dock = DockStyle.Fill; + splitContainerControl.Panel1.Controls.Add(gridDetail); + gridDetail.BorderStyle = System.Windows.Forms.BorderStyle.None; + splitContainerControl.Panel2.Controls.Add(gridDetail_Details); + gridDetail_Details.BorderStyle = System.Windows.Forms.BorderStyle.None; + + splitContainerControl.SplitterMoved += new System.EventHandler(this.OnDetailsSplitterMoved); + string newwidth = IniHelper.Read(string.Format("bill_Details_Width_{0}", this.SysModel.ModuleCode));//通过Key获取Value值 + if (!string.IsNullOrEmpty(newwidth)) + { + splitContainerControl.SplitterPosition = Convert.ToInt32(newwidth); + } + else + { + int width = this.tb_buttom.Width;//获取控件宽度 + splitContainerControl.SplitterPosition = width / 2;//然后将分割位置设置在宽度一半位置 + } + + + splitContainerControl.Parent = tabDetail; + unionModel.GridDetailDetailControlObj = gridDetail_Details; + billModuleModel.SourceDetailDetailControl = gridDetail_Details; + } + else + { + gridDetail.Parent = tabDetail; + gridDetail.BorderStyle = System.Windows.Forms.BorderStyle.None; + + } + + if (SerialNumber == 0) + { + this.tb_buttom.TabControlObj.TabPages.Insert(0, tabDetail); + this.tb_buttom.TabControlObj.SelectedTabPageIndex = 0; + if (attachModels.Count > 0) + this.tb_buttom.TabControlObj.TabPages[0].Text = model.UserName + DetailedSuffix; + } + if (BillModel.IsBillDetailCheck == 1)//加载复选框 + { + GridDragGrid.GridAddCheckBox(gridDetail.GridView); + } + } + } + + + + + + + + #endregion + + billModuleModel.SourceControl = + treeView != null ? (object)treeView : gridControl; + billModuleModel.SourceDetailControl = gridDetail; + BillModuleModelDic[sourceModelRow] = billModuleModel; + + #region 加载来源条件 + if (model.SourceType == 1 && (controls == null || controls.Rows.Count == 0)) + { + //// 设置默认下拉列表框 + //DataTable columnTable = detailTable.Select("sourceId=" + model.Id + " and isnull(isVisible,0)=0").CopyToDataTable(); + //this.lceCombobox.ValueMember = this.lceCombobox.ValueField = "fieldName"; + //this.lceCombobox.TextField = "userName"; + //this.lceCombobox.SetDataSource(columnTable); + //this.lceCombobox.TextEdit.SelectedIndex = 0; + + //this.pl_treeview_detault_search.Dock = DockStyle.Bottom; + //this.pl_treeview_detault_search.Visible = true; + + //tabPage.Controls.Add(pl_treeview_detault_search); + } + else + { + // 创建自定义条件 + string searchSql = model.SourceType == 1 ? Regex.Replace(model.DetailSql, "{speciesno}", "", RegexOptions.IgnoreCase) : model.SourceSql; + PanelControl searchPanel = new PanelControl(); + MyControl searchControl = + new MyControl(searchSql, + gridControl == null ? gridDetail : gridControl, + treeView) + { + Model = this.SysModel, + OtherParams = this.SysModel.OtherParams() + }; + if (dataCaches != null) + { + dataCaches.AddTask(searchControl, "DynamicModel", + new Task(() => this.SysModel)); + dataCaches.AddTask(searchControl, "ControlsTable", + new Task(() => controls)); + searchControl.GetSearchDataCaches(dataCaches); + } + searchControl.OnSearchBeforeCallBack += new SearchEventHandler(OnSearchBefore); + searchControl.OnSearchAfterCallBack += new EventHandler(OnSearchAfterd); + if (SerialNumber == 0 && !SystemInfo.Instance.IsBillSourceRefushTag.Equals("1") && string.IsNullOrWhiteSpace(this.BillModel.InitialRefreshId)) + { + // 第一个页面要刷新数据,所以绑定事件用于初始化完成后在查询数据 + searchControl.OnDataSourceBindCallBack += new EventHandler(OnFirstPageDataSourceBindCallBack); + } + if (!string.IsNullOrWhiteSpace(this.BillModel.InitialRefreshId) && this.BillModel.InitialRefreshId.Equals(model.Id + "")) + { + searchControl.OnDataSourceBindCallBack += SearchControl_OnDataSourceBindCallBack; + InitialSelectionTab = tabPage; + } + + searchControl.ParentUnionField = model.SourceKeyField; + + searchPanel.Dock = DockStyle.Top; + searchPanel.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder; + searchPanel.BackColor = Color.Transparent; + searchPanel.Parent = tabPage; + searchControl.OtherParams = this.SysModel.OtherParams(); + searchPanel.Height = searchControl.InitSearchControl(controls, searchPanel); + unionModel.SearchObj = searchControl; + } + #endregion + + unionModel.GridControlObj = gridControl; + + if (model.sourceDetailType.Equals("1")) + { + unionModel.TreeGridDetailControlObj = (gridDetail as TreeGridControlEx); + } + else + { + unionModel.GridDetailControlObj = gridDetail; + } + + + + + unionModel.ModelObj = model; + unionModel.TreeViewObj = treeView; + if (SerialNumber == 0) + unionModel.IsChange = true; + tabPage.Tag = unionModel; + if (model.SourceType == 0 && !model.DisableShowSourceCount) + { + // 模块要查看具体条数 + unionModel.SearchObj.OnDataSourceBindCallBack += new EventHandler(OnPageDataSourceBindCallBack); + pageNumKey.Add(unionModel.SearchObj, tabPage); + } + this.xtc_main_container.TabPages.Add(tabPage); + SerialNumber++; + } + + + } + + + + + + + + + /// + /// 点击来源明细,加载明细的明细 + /// + /// + /// + private void GridView_FocusedRowObjectChanged(object sender, FocusedRowObjectChangedEventArgs e) + { + try + { + + GridView gridView = sender as GridView; + DataRow rowItem = gridView.GetFocusedDataRow(); + string sql = gridView.Tag + ""; + BillSourceUnionModel unionModel = this.xtc_main_container.SelectedTabPage.Tag as BillSourceUnionModel; + if (unionModel.GridDetailDetailControlObj != null) + { + unionModel.GridDetailDetailControlObj.gridControl.DataSource = BillImpl.GetDataTableResult(ReplaceHelper.ReplaceRowParam(rowItem, sql)); + } + } + catch (Exception ex) + { + MessageUtil.Show(ex); + } + + + } + + + + + + + + + + + + + + #region 单据来源相关 + /// + /// 说明:刷新当前选中的TabPage + /// 创建人:龚宇超 + /// 创建日期:2018-06-29 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// + private void RefreshSelectedSource() + { + if (this.xtc_main_container.SelectedTabPage == null) return;//来源选择为null(不显示左侧来源)。不执行下方刷新 + + XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; + BillSourceUnionModel model = tabPage.Tag as BillSourceUnionModel; + if (model.GridControlObj != null) this.RefreshSource(model); + if (BillModel.drgFinishHide == "1") + { + if (model.ModelObj.SourceType == 1) + { + string sqlValue = ReplaceHelper.ReplaceUserInfo(ReplaceHelper.ReplaceWhereCond(model.ModelObj.DetailSql)); + sqlValue = sqlValue.Replace("#", ""); + sqlValue = this.ControlObj.ReplaceControlValue(sqlValue); + sqlValue = ReplaceHelper.ReplaceParamToValue(sqlValue, model.TreeViewObj.GetSelectValue()); + model.GridDetailControlObj.GridControl.DataSource = BillImpl.GetDataTableResult(sqlValue); + } + else + { + this.RefreshSourceDetail(model); + } + } + if (model.ModelObj.SourceType == 0 && model.SearchObj.GridRowCount > 0) tabPage.Text = model.ModelObj.UserName + "(" + model.SearchObj.GridRowCount + QuantitySuffix; + } + /// + /// 说明:刷新单据来源主表,未传递时,默认刷新 + /// 创建人:龚宇超 + /// 创建日期:2017-12-13 + /// 修改人: + /// 修改日期: + /// 修改备注:gcMain + /// 版本:1.0 + /// + /// The union model. + /// XtraTabPage. + private void RefreshSource(BillSourceUnionModel unionModel = null) + { + if (unionModel == null || unionModel.SearchObj == null) return; + unionModel.SearchObj.SearchLastGrid(); + + + } + + + + /// + /// 说明:刷新单据来源明细 + /// 创建人:龚宇超 + /// 创建日期:2017-11-30 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The union model. + private void RefreshSourceDetail(BillSourceUnionModel unionModel) + { + if (unionModel == null) return; + XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; + + if (unionModel.ModelObj.SourceType == 1) + { + // 树加载明细 + //string fieldName = this.lceCombobox.EditValue; + //string fieldValue = this.textEdit1.Text.Trim(); + string fieldName = string.Empty; + string fieldValue = string.Empty; + string checkStrs = unionModel.TreeViewObj.GetCheckValues(); + string sqlValue = ReplaceHelper.ReplaceParamToValue(ReplaceHelper.ReplaceUserInfo(unionModel.ModelObj.DetailSql), unionModel.TreeViewObj.GetSelectNodeValue()); + + if (!string.IsNullOrEmpty(checkStrs)) + checkStrs = " and SpeciesNo in (" + checkStrs.TrimEnd(',') + ")"; + sqlValue = string.Format("select * from ({0}) temp where 1=1 ", ReplaceHelper.ReplaceWhereCond(sqlValue) + checkStrs) + string.Format(" and ({0} like '%{1}%' or dbo.P_getpy({0}) like '%{1}%')", fieldName, fieldValue); + + try + { + WaitForm.ShowForm(); + unionModel.GridDetailControlObj.GridControl.DataSource = BillImpl.GetDataTableResult(sqlValue); + } + catch (Exception ex) + { + MessageUtil.Show(ex); + LogHelper.Instance.WriteError(ex); + LogUtil.WriteError(BillModel.TypeName + "模块刷新树加载明细出错!", ex); + } + finally + { + WaitForm.HideForm(); + } + } + else + { + // 加载明细 + try + { + WaitForm.ShowForm(); + + + DataRow rowItem = unionModel.GridControlObj.GridView.GetFocusedDataRow(); + //unionModel.GridDetailControlObj.GridControl.DataSource = rowItem == null + // ? new DataTable() : BillImpl.GetDataTableResult(ReplaceHelper.ReplaceRowParam(rowItem, unionModel.ModelObj.DetailSql)); + if (unionModel.ModelObj.SourceType == 3 || unionModel.ModelObj.SourceType == 4) + { + rowItem = unionModel.TreeGridControlObj.GetViewFocusedDataRow(); + } + + + string DetailSql = unionModel.ModelObj.DetailSql; + DetailSql = ReplaceHelper.ReplaceUserInfo(DetailSql); + DetailSql = ReplaceHelper.ReplaceWhereCond(DetailSql); + DetailSql = ReplaceHelper.ReplaceRowParam(rowItem, DetailSql); + if (unionModel.SearchObj != null) + DetailSql = unionModel.SearchObj.ReplaceParentControlValue(DetailSql); + + if (unionModel.ModelObj.sourceDetailType == "1") + { + unionModel.TreeGridDetailControlObj.SetGridViewDataSource(rowItem == null + ? new DataTable() : BillImpl.GetDataTableResult(DetailSql)); + } + else + { + + + //有复选框的页签在刷新前清空选中行,否则合计在刷新数据源后不会自带改变 + if (unionModel.GridDetailControlObj.GridView.OptionsSelection.MultiSelectMode == GridMultiSelectMode.CheckBoxRowSelect && unionModel.GridDetailControlObj.GridView.OptionsSelection.MultiSelect == true) + { + //int[] selectIndexs = unionModel.GridDetailControlObj.GridView.GetSelectedRows(); + unionModel.GridDetailControlObj.GridView.ClearSelection(); + } + + unionModel.GridDetailControlObj.GridControl.DataSource = rowItem == null + ? new DataTable() : BillImpl.GetDataTableResult(DetailSql); + } + + if (unionModel.GridDetailModuleGridEx != null) + { + unionModel.GridDetailModuleGridEx.GridControlObj.LastSearchSql = DetailSql; + } + + + DataTable table = null; + if (unionModel.ModelObj.sourceDetailType == "1") + { + table = unionModel.TreeGridDetailControlObj.TreeListObj.DataSource as DataTable; + } + else + { + table = unionModel.GridDetailControlObj.GridControl.DataSource as DataTable; + } + + if (table != null && !table.Columns.Contains("_check")) + { + table.Columns.Add("_check", typeof(bool)); + foreach (DataRow row in table.Rows) + { + row["_check"] = 0; + } + } + + + + if (tb_buttom.TabControlObj.TabPages.Count > 0) + { + for (int i = 0; i < this.tb_buttom.TabControlObj.TabPages.Count; i++) + { + XtraTabPage page = this.tb_buttom.TabControlObj.TabPages[i]; + if (i == 0) continue; + if (rowItem != null && page != null) + { + this.SetTabPageDataSource(page, rowItem); + } + } + //foreach (XtraTabPage AttachPage in this.tb_buttom.TabControlObj.TabPages) + //{ + // GridDetailModel model = tb_buttom.GetGridDetailModel(AttachPage); + // if (model == null) continue; + // string sqlValue = ReplaceHelper.ReplaceRowParam(rowItem, model.DetailSql); + // this.tb_buttom.SetGridDataSource(AttachPage, sqlValue); + //} + } + } + catch (Exception ex) + { + MessageUtil.Show(ex); + LogHelper.Instance.WriteError(ex); + LogUtil.WriteError(BillModel.TypeName + "模块加载明细出错!", ex); + } + finally + { + WaitForm.HideForm(); + } + } + } + /// + /// 说明:刷新单据来源 + /// 创建人:龚宇超 + /// 创建日期:2019-12-16 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + private void SaveRefreshSource() + { + foreach (XtraTabPage tabPage in this.xtc_main_container.TabPages) + { + BillSourceUnionModel model = tabPage.Tag as BillSourceUnionModel; + if (model != null && model.GridControlObj != null && model.ModelObj.SaveRefreshFlag) + { + this.RefreshSource(model); + this.RefreshSourceDetail(model); + } + } + } + + + + + + /// + /// 说明: + /// 创建人:龚宇超 + /// 创建日期:2017-11-30 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// true if XXXX, false otherwise. + private bool ValidateDetailCond(DataRow rowItem, BillSourceUnionModel unionModel) + { + bool validate = false; + + try + { + string detailCond = ReplaceHelper.ReplaceRowParam(rowItem, unionModel.ModelObj.DetailEnableCond); + detailCond = detailCond.ToLower();//2025-09-08 赵坤表示条件全部转成小写判断。 来源明细中不能配置单元格类型(不能配置 复选框条件 {xxx}=0 ),只能写{xxx}='Ture'。这种bit类型容易忘记大小的情况 + if (detailCond.Contains("#")) + { + List condition = ReplaceHelper.GetParamFields(detailCond); + foreach (string item in condition) + { + string fieldValue = this.ControlObj.GetControlValue(item.Replace("{#", "").Replace("}", "")); + detailCond = detailCond.Replace(item, fieldValue); + } + } + if (detailCond.StartsWith("@") || detailCond.StartsWith("!")) + { + validate = "1".Equals(BaseImpl.GetDefaultValue(detailCond)); + } + else + { + + validate = ReplaceHelper.EvalCond(detailCond); + } + } + catch (Exception ex) + { + LogHelper.Instance.WriteLog(ex.StackTrace); + LogUtil.WriteError("验证多条添加条件出错!", ex); + //MessageUtil.Show(ResourceKeys.CondtionError + "\r\n" + unionModel.ModelObj.DetailEnableCond); + } + return validate; + } + /// + /// 说明:单据来源右键菜单执行完后刷新 + /// 创建人:龚宇超 + /// 创建日期:2017-12-11 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + private void OnGridControlRightCallback(object sender, EventArgs e) + { + this.RefreshSelectedSource(); + + // 执行右键菜单后刷新单据状态2020-03-23 + XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; + BillSourceUnionModel model = tabPage.Tag as BillSourceUnionModel; + } + /// + /// 说明:获取单据管理的单据来源标签 + /// 创建人:龚宇超 + /// 创建日期:2017-12-13 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + private BillSourceUnionModel GetBillSourceManager() + { + foreach (XtraTabPage item in this.xtc_main_container.TabPages) + { + BillSourceUnionModel model = item.Tag as BillSourceUnionModel; + if (model.ModelObj.SourceType == 2) + return model; + } + return null; + } + /// + /// 说明:初始化附加信息 + /// 创建人:龚宇超 + /// 创建日期:2018-04-26 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + private List GetAttachTabs() + { + List details = new List(); + + DataTable table = BaseAuditImpl.GetAttachTabs(this.SysModel.ModuleCode, "100", " and orderid < 0 "); + foreach (DataRow item in table.Rows) + { + DataTable gridColumns = BaseAuditImpl.GetBottomBasicInformation(item["formKey"] + ""); + details.Add(new GridDetailModel(item, gridColumns, GridCustomColumnStruct.BillSourceDetailAttachGridView)); + } + + return details; + } + #endregion + + + + #region 事件相关 + /// + /// 说明:打印完成后回调 + /// 创建人:龚宇超 + /// 创建日期:2018-07-05 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The sender. + /// The e. + private void OnReportPrintAfter(object sender, EventArgs e) + { + //打印完成后添加数据库 + if (_printSaveParams != null && _printSaveParams.Count > 0) + { + int result = BaseModuleImpl.SavePrintRecord(_printSaveParams[0], _printSaveParams[1], _printSaveParams[2], _printSaveParams[3], _printSaveParams[4]); + } + + } + /// + /// 说明: + /// 创建人:龚宇超 + /// 创建日期:2017-11-28 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + private void OnFrmMainKeyDown(object sender, KeyEventArgs e) + { + // 窗口获取按键则表格按键中断.有时间处理 + if (e.Modifiers.CompareTo(Keys.Control) == 0) + { + if (e.KeyCode == Keys.Down) + this.ssc_main.Collapsed = true; + if (e.KeyCode == Keys.Up) + this.ssc_main.Collapsed = false; + } + } + /// + /// 说明:树节点选中刷新明细 + /// 创建人:龚宇超 + /// 创建日期:2017-12-01 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + private void OnTreeNodeSelectAfter(object sender, TreeViewEventArgs e) + { + TreeView tree = (TreeView)sender; + XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; + BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel; + if (unionModel != null) + { + WaitForm.ShowForm(); + try + { + + + string sqlValue = ReplaceHelper.ReplaceUserInfo(ReplaceHelper.ReplaceWhereCond(unionModel.ModelObj.DetailSql)); + sqlValue = sqlValue.Replace("#", ""); + sqlValue = this.ControlObj.ReplaceControlValue(sqlValue); + if (unionModel.SearchObj != null) sqlValue = unionModel.SearchObj.ReplaceControlValue(sqlValue); + sqlValue = ReplaceHelper.ReplaceParamToValue(sqlValue, e.Node.Name); + + if (unionModel.GridDetailModuleGridEx != null) + { + unionModel.GridDetailModuleGridEx.GridControlObj.LastSearchSql = sqlValue; + } + + if (unionModel.ModelObj.sourceDetailType == "1" && unionModel.TreeGridDetailControlObj.TreeListObj != null) + { + unionModel.TreeGridDetailControlObj.TreeListObj.DataSource = BillImpl.GetDataTableResult(sqlValue); + } + else + { + unionModel.GridDetailControlObj.GridControl.DataSource = BillImpl.GetDataTableResult(sqlValue); + } + + } + catch (Exception ex) + { + LogHelper.Instance.WriteError(ex); + LogUtil.WriteError(BillModel.TypeName + "模块选中树节点" + tree.SelectedNode.Text + "刷新明细失败!", ex); + } + finally + { + WaitForm.HideForm(); + } + } + } + /// + /// 说明:单据来源切换Tab标签 + /// 创建人:龚宇超 + /// 创建日期:2017-11-28 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + private void OnTabSelectedPageChanged(object sender, TabPageChangedEventArgs e) + { + try + { + if (_isInitFinish && !SystemInfo.Instance.IsBillSourceRefushTag.Equals("1")) + { + BillSourceUnionModel unionModel = e.Page.Tag as BillSourceUnionModel; + if (unionModel != null) + { + this.RefreshSelectedSource(); + this.tb_buttom.TabControlObj.TabPages[0].Controls.Clear(); + if (unionModel.GridDetailModuleGridEx != null) + { + this.tb_buttom.TabControlObj.TabPages[0].Controls.Add(unionModel.GridDetailModuleGridEx); + } + else if (unionModel.GridDetailDetailControlObj == null) + { + this.tb_buttom.TabControlObj.TabPages[0].Controls.Add(unionModel.GridDetailControlObj != null ? unionModel.GridDetailControlObj : unionModel.TreeGridDetailControlObj); + } + else + { + //this.tb_buttom.TabControlObj.TabPages[0].Controls.Add(unionModel.GridDetailDetailControlObj); + //创建SplitContainerControl控件,让下方可以左右拖动 + SplitContainerControl splitContainerControl = new DevExpress.XtraEditors.SplitContainerControl(); + splitContainerControl.Dock = DockStyle.Fill; + splitContainerControl.Panel1.Controls.Add(unionModel.GridDetailControlObj); + splitContainerControl.Panel2.Controls.Add(unionModel.GridDetailDetailControlObj); + int width = this.tb_buttom.Width;//获取控件宽度 + splitContainerControl.SplitterPosition = width / 2;//然后将分割位置设置在宽度一半位置 + this.tb_buttom.TabControlObj.TabPages[0].Controls.Add(splitContainerControl); + } + this.tb_buttom.TabControlObj.TabPages[0].Text = unionModel.ModelObj.UserName + DetailedSuffix; + if (unionModel.IsChange == false) + { + AutoSizeChange.ControllInitializeSize(this.tb_buttom.TabControlObj.TabPages[0]); + unionModel.IsChange = true; + } + } + } + } + catch (Exception ex) + { + LogHelper.Instance.WriteError(ex); + LogUtil.WriteError("单据切换标签失败!", ex); + } + } + /// + /// 说明:单据来源树结构默认查询条件 + /// 创建人:龚宇超 + /// 创建日期:2017-11-28 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + private void OnTreeSearchClick(object sender, EventArgs e) + { + XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; + + this.RefreshSourceDetail(tabPage.Tag as BillSourceUnionModel); + } + + /// + /// 单据来源树 条件框回车查询 + /// + /// + /// + private void OnTreeConditionKeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Enter) + { + this.OnTreeSearchClick(null, null); + } + + } + + + /// + /// 说明:第一个页签初始化完成刷新数据 + /// 创建人:龚宇超 + /// 创建日期: + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The sender. + /// The instance containing the event data. + private void OnFirstPageDataSourceBindCallBack(object sender, EventArgs e) + { + try + { + if (IsBillMaster) + { + this.RefreshSelectedSource(); + } + } + catch (Exception ex) + { + LogHelper.Instance.WriteError(ex); + LogUtil.WriteError("单据切换标查询失败!", ex); + } + } + /// + /// 说明:第一个页签初始化完成刷新数据 + /// 创建人:龚宇超 + /// 创建日期: + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The sender. + /// The instance containing the event data. + private void OnPageDataSourceBindCallBack(object sender, EventArgs e) + { + try + { + MyControl searchControl = sender as MyControl; + XtraTabPage tabPage = pageNumKey[searchControl]; + if (tabPage.TabIndex == 0) return; + BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel; + string searchSql = unionModel.ModelObj.SourceSql; + searchSql = ReplaceHelper.ReplaceUserInfo(searchSql); + searchSql = ReplaceHelper.ReplaceWhereCond(searchSql); + searchSql = unionModel.SearchObj.SetSearchSqlValue(searchSql, true, true); + // 查找FROM子句的位置 + int fromIndex = searchSql.IndexOf("FROM", StringComparison.OrdinalIgnoreCase); + if (fromIndex != -1) + { + // 生成优化后的SQL查询 + string optimizedSql = "SELECT COUNT(*) " + searchSql.Substring(fromIndex); + searchSql = optimizedSql; + } + DataTable dt = MainImpl.GetDataTableResult(searchSql); + if (dt.Rows.Count > 0) tabPage.Text += "(" + dt.Rows[0][0] + QuantitySuffix; + } + catch (Exception ex) + { + LogHelper.Instance.WriteError(ex); + LogUtil.WriteError("单据条件绑定失败失败!", ex); + } + } + + /// + /// 跳转到指定页签,并执行配置条件的搜索 + /// + /// + /// + private void SearchControl_OnDataSourceBindCallBack(object sender, EventArgs e) + { + if (InitialSelectionTab != null) + { + this.xtc_main_container.SelectedTabPage = InitialSelectionTab; + BillSourceUnionModel model = InitialSelectionTab.Tag as BillSourceUnionModel; + if (model.SearchObj != null) model.SearchObj.SearchGrid(); + } + } + + /// + /// 说明:单据来源选中行,加载明细 + /// 创建人:龚宇超 + /// 创建日期:2017-11-30 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + private void OnGridControlSelectionChanged(object sender, SelectionChangedEventArgs e) + { + XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; + + this.RefreshSourceDetail(tabPage.Tag as BillSourceUnionModel); + } + /// + /// 说明:单据来源选中行,加载明细 + /// 创建人:龚宇超 + /// 创建日期:2017-11-30 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + private void OnGridViewRowCellClick(object sender, RowCellClickEventArgs e) + { + + XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; + BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel; + this.RefreshSourceDetail(unionModel); + } + + + + + private void OnSourceGridViewDoubleClick(object sender, EventArgs e) + { + + XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; + BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel; + //this.RefreshSourceDetail(unionModel); + DataRow rowItem = unionModel.GridControlObj.GridView.GetFocusedDataRow(); + if (rowItem == null) + return; + //单据号 + string billno = rowItem[BillModel.PrimaryKey] + ""; + + DynamicBillModel model = CloneDynamicBillModel(this.SysModel); + model.BillOrderNo = billno; + FrmBill frmBill = new FrmBill(model); + frmBill.Text = string.Format("{0}-详情[单据编号:{1}]", this.BillModel.TypeName, billno); + frmBill.ShowDialog(); + //刷新界面 + unionModel.SearchObj.SearchLastGrid(); + + } + + + // + /// 复制单据动态参数,保留原对象的运行时配置和缓存。 + /// + private static DynamicBillModel CloneDynamicBillModel(DynamicBillModel source) + { + if (source == null) + return null; + + MethodInfo method = typeof(object).GetMethod( + "MemberwiseClone", + BindingFlags.Instance | BindingFlags.NonPublic); + + return method.Invoke(source, null) as DynamicBillModel; + } + + + + /// + /// 说明:单据明细选中刷新附件明细 + /// 创建人:王一帆 + /// 创建日期:2021-06-30 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + private void OngcMainRowCellClick(object sender, RowCellClickEventArgs e) + { + if (this.tb_buttom.TabControlObj.TabPages.Count > 1) + { + SetDetailGridDataSource(); + } + } + + + + /// + /// 切换下方附加模块页签时,刷新当前页签 + /// + /// + /// + private void TabControlObj_SelectedPageChanged(object sender, TabPageChangedEventArgs e) + { + if (this.tb_buttom.TabControlObj.TabPages.Count > 1) + { + SetDetailGridDataSource(); + } + } + + /// + /// 说明:获取底部多标签数据 + /// 创建人:龚宇超 + /// 创建日期:2017-12-19 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + public void SetDetailGridDataSource() + { + DataRow rowItem = null; + //DataRow rowItem = this.gcMain.GridView.GetFocusedDataRow(); + //if (this.BillModel.DetailTreeTable) + //{ + // rowItem = (this.gcMain as TreeGridControlEx).GetViewFocusedDataRow(); + //} + int i = 0; + foreach (XtraTabPage page in this.tb_buttom.TabControlObj.TabPages) + { + if (i == 0) + { + i++; + continue; + } + if (this.BillModel.RefreshSelectedDetail && page != tb_buttom.TabControlObj.SelectedTabPage) + { + continue; + } + if (rowItem != null && page != null) + { + this.SetTabPageDataSource(page, rowItem); + } + } + } + + + + + /// + /// 说明:设置表格数据 + /// 创建人:龚宇超 + /// 创建日期:2018-01-29 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The tab page. + /// The grid control. + public void SetTabPageDataSource(XtraTabPage tabPage, DataRow rowItem) + { + + GridDetailModel model = this.tb_buttom.GetGridDetailModel(tabPage); + if (rowItem != null && model != null) + { + if (tabPage.Tag is ModuleWebView) + { + // 加载网页 + string url = ReplaceHelper.ReplaceRowParam(rowItem, ReplaceHelper.ReplaceUserInfo(model.DetailSql)); + url = url.StartsWith("http") ? url : SystemInfo.Instance.OAUrl + url; + ModuleWebView webView = tabPage.Tag as ModuleWebView; + webView.Dock = DockStyle.Fill; + webView.Tag = model; + webView.Navigate(url); + } + else if (tabPage.Tag is FrmWebBrowser) + { + // 加载网页 + string url = ReplaceHelper.ReplaceRowParam(rowItem, ReplaceHelper.ReplaceUserInfo(model.DetailSql)); + url = url.StartsWith("http") ? url : SystemInfo.Instance.OAUrl + url; + FrmWebBrowser webView = tabPage.Tag as FrmWebBrowser; + webView.Dock = DockStyle.Fill; + webView.Tag = model; + webView.LoadUrl(url); + } + else if (tabPage.Tag is FrmMiniBlink) + { + // 加载网页 + string url = ReplaceHelper.ReplaceRowParam(rowItem, ReplaceHelper.ReplaceUserInfo(model.DetailSql)); + url = url.StartsWith("http") ? url : SystemInfo.Instance.OAUrl + url; + FrmMiniBlink webView = tabPage.Tag as FrmMiniBlink; + webView.Dock = DockStyle.Fill; + webView.Tag = model; + webView.LoadUrl(url); + } + else if (tabPage.Tag is TabMultipledetails) + { + TabMultipledetails tabMultipledetails = tabPage.Tag as TabMultipledetails; + tabMultipledetails.SetConditionValues(rowItem); + + GridControlEx grdExMain = (tabMultipledetails.SplitMain.Panel1.Tag as GridControlEx); + GridDetailModel MainModel = grdExMain.Tag as GridDetailModel; + string searchMainSql = this.GetSearchSql(MainModel, rowItem); + DataTable firstTable = MainImpl.GetDataTableResult(searchMainSql); + grdExMain.LastSearchSql = searchMainSql; + grdExMain.SetGridViewDataSource(firstTable); + + if (tabMultipledetails.SplitMain.Panel2.Tag is GridControlEx) + { + GridControlEx grdExAdditional = (tabMultipledetails.SplitMain.Panel2.Tag as GridControlEx); + GridDetailModel AdditionalModel = grdExAdditional.Tag as GridDetailModel; + string searchAddSql = this.GetSearchSql(AdditionalModel, rowItem); + if (!MainModel.IsUnioDetail) + { + grdExAdditional.LastSearchSql = searchAddSql; + grdExAdditional.SetGridViewDataSource(MainImpl.GetDataTableResult(searchAddSql)); + } + //右侧是左侧的明细,左侧没有数据时。右侧赋空值(因为无法触发左侧行改变事件) + if (MainModel.IsUnioDetail && firstTable.Rows.Count == 0) + { + grdExAdditional.LastSearchSql = ""; + grdExAdditional.SetGridViewDataSource(new DataTable()); + } + } + else if (tabMultipledetails.SplitMain.Panel2.Tag is ChartControlEx) + { + ChartControlEx grdExAdditional = (tabMultipledetails.SplitMain.Panel2.Tag as ChartControlEx); + GridDetailModel AdditionalModel = grdExAdditional.Tag as GridDetailModel; + string searchAddSql = this.GetSearchSql(AdditionalModel, rowItem); + DataTable table = MainImpl.GetDataTableResult(searchAddSql); + grdExAdditional.CreateChart(table); + } + + tabPage.Text = MainModel.DetailName + "(" + firstTable.Rows.Count + QuantitySuffix; + //tabPage.Text = MainModel.DetailName + "(" + firstTable.Rows.Count + "条)"; + //tabPage.Appearance.Header.ForeColor = firstTable.Rows.Count > 0 ? Color.Red : Color.FromArgb(0, 0, 0); + } + else + { + string searchSql = this.GetSearchSql(model, rowItem); + if (tabPage.Tag is GridControlEx) + { + (tabPage.Tag as GridControlEx).LastSearchSql = searchSql; + } + this.tb_buttom.SetGridDataSource(tabPage, MainImpl.GetDataTableResult(searchSql)); + if (tabPage.Tag is GridControlEx && (tabPage.Tag as GridControlEx).ParentControl != null) + (tabPage.Tag as GridControlEx).ParentControl.SetAllControlValue(rowItem); + //配置明细直接根据条件加载 + if (model.SystemModel != null && 1 == model.SystemModel.isFirstLoad) + { + (tabPage.Tag as GridControlEx).ParentControl.SearchGrid(); + GridControlEx gridControlEx = tabPage.Tag as GridControlEx; + + if (gridControlEx.CustomGroupBandEx != null) + { + tabPage.Text = model.DetailName + "(" + gridControlEx.CustomGroupBandEx.DataRowCount() + QuantitySuffix; + } + else if (gridControlEx.CustomGroupTreeBandEx != null) + { + tabPage.Text = model.DetailName + "(" + gridControlEx.CustomGroupTreeBandEx.DataRowCount() + QuantitySuffix; + } + else + { + tabPage.Text = model.DetailName + "(" + (tabPage.Tag as GridControlEx).ParentControl.GridRowCount + QuantitySuffix; + } + //tabPage.Text = gridControlEx.CustomGroupBandEx != null ? model.DetailName + "(" + gridControlEx.CustomGroupBandEx.DataRowCount() + "条)" : model.DetailName + "(" + (tabPage.Tag as GridControlEx).ParentControl.GridRowCount + "条)"; + //tabPage.Text = model.DetailName + "(" + (tabPage.Tag as GridControlEx).ParentControl.GridRowCount + "条)"; + } + //附加信息根据主表明细选中行,判断配置的按钮条件 + Object moduleObject = tabPage.Controls.Cast().FirstOrDefault(); + ModuleGridEx moduleGridEx = null; + if (moduleObject is ModuleGridEx) + { + moduleGridEx = moduleObject as ModuleGridEx; + moduleGridEx.ParentButtonState(rowItem); + } + + } + } + + } + /// + /// 说明:获取查询条件 + /// 创建人:龚宇超 + /// 创建日期:2017-11-22 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The model. + /// The row item. + /// System.String. + protected string GetSearchSql(GridDetailModel model, DataRow rowItem) + { + string fieldName = !string.IsNullOrEmpty(model.UnionParentField) && rowItem.Table.Columns.Contains(model.UnionParentField) ? model.UnionParentField : BillModel.PrimaryKey; + string sqlValue = model.IsReadOnly || model.IsChart ? model.DetailSql : model.SystemModel.MenuSql; + string unioValue = string.Empty; + unioValue = rowItem.Table.Columns.Contains(fieldName) ? rowItem[fieldName] + "" : string.Empty; + if (this.ControlObj != null && string.IsNullOrEmpty(unioValue)) + { + unioValue = !string.IsNullOrEmpty(model.UnionParentField) && this.ControlObj.FindControl(model.UnionParentField) != null ? this.ControlObj.GetControlValue(model.UnionParentField) : unioValue; + } + sqlValue = ReplaceHelper.ReplaceRowParam(rowItem, sqlValue); + sqlValue = this.ControlObj.ReplaceControlValue(sqlValue);//后替换主表内容 + if (ReplaceHelper.IsSelect(sqlValue) && !string.IsNullOrEmpty(model.UnionValue)) + { + sqlValue = ReplaceHelper.ReplaceWhereCond(sqlValue) + string.Format(" and {0}='{1}'", model.UnionValue, unioValue); + } + if (!string.IsNullOrEmpty(model.UnionCond)) + { + string UnionCond = ReplaceHelper.ReplaceRowParam(rowItem, model.UnionCond); + sqlValue += UnionCond; + } + return sqlValue; + } + /// + /// 说明:单据来源选中行,加载明细 + /// 创建人:龚宇超 + /// 创建日期:2019-07-25 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The sender. + /// The instance containing the event data. + private void OnTreeListObjFocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e) + { + XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; + + this.RefreshSourceDetail(tabPage.Tag as BillSourceUnionModel); + } + /// + /// 说明:单据来源明细右键菜单执行后刷新数据 + /// 创建人:龚宇超 + /// 创建日期:2017-12-19 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + private void OnGridDetailRightMenuCallback(object sender, EventArgs e) + { + XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; + + this.RefreshSourceDetail(tabPage.Tag as BillSourceUnionModel); + } + + + + + + /// + /// 说明:分割条移动保存位置 + /// 创建人:龚宇超 + /// 创建日期:2018-03-06 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. private void OnMainSplitterMoved(object sender, EventArgs e) { if (this._isInitFinish) @@ -2213,259 +2213,259 @@ namespace Lskj.PubBillManagement IniHelper.Write(string.Format("bill_height_{0}", this.SysModel.ModuleCode), this.ssc_main.SplitterPosition + ""); } } - /// - /// 说明:明细分割条移动保存位置 - /// 创建人:龚宇超 - /// 创建日期:2018-03-06 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - private void OnDetailsSplitterMoved(object sender, EventArgs e) - { - if (this._isInitFinish) - { - SplitContainerControl splitContainerControl = sender as SplitContainerControl; - IniHelper.Write(string.Format("bill_Details_Width_{0}", this.SysModel.ModuleCode), splitContainerControl.SplitterPosition + ""); - } - } - /// - /// 说明:单据来源查询之前处理 - /// 创建人:龚宇超 - /// 创建日期:2018-03-06 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The sender. - /// The e. - private void OnSearchBefore(object sender, SearchArgs e) - { - - // 用户搜索时不加载右侧控件值,只有点击、人为选中行在加载右侧控件值. - this._isLoadRightControlValue = false; - XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; - BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel; - if (!unionModel.SearchObj.VerifyNull()) - { - e.Continue = false; - } - } - /// - /// 说明:单据来源查询完成 - /// 创建人:龚宇超 - /// 创建日期:2018-03-06 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - /// - private void OnSearchAfterd(object sender, EventArgs e) - { - this._isLoadRightControlValue = true; - - XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; - BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel; - if (unionModel.ModelObj.SourceType == 1) - { - if (unionModel.TreeViewObj != null && unionModel.SearchObj.MainGridEx != null) - { - string sql = ReplaceHelper.ReplaceUserInfo(unionModel.SearchObj.MainGridEx.LastSearchSql); - - //和上一次查询sql相同就不再次查询了 - if (!unionModel.SearchObj.MainGridEx.LastSearchSql.Equals(sql)) - { - unionModel.SearchObj.MainGridEx.SetGridViewDataSource(BaseImpl.GetDataTableResult(sql)); - } - } - } - else - { - if (unionModel.GridControlObj != null) - { - - string sql = ReplaceHelper.ReplaceUserInfo(unionModel.GridControlObj.LastSearchSql); - - if (SubstringCount(sql, "#") > 1) - { - string fixedSql = sql.Substring(sql.IndexOf('#'), sql.LastIndexOf('#') + 1 - sql.IndexOf('#')); - string billMainCode = sql.Substring(sql.IndexOf('#'), sql.LastIndexOf('#') + 1 - sql.IndexOf('#')).Replace("#", ""); - var paramList = ReplaceHelper.GetParamFields(billMainCode); - bool isCondReplace = true; - foreach (string item in paramList) - { - string field = item.Replace("{", "").Replace("}", ""); - if (ControlObj.FindControl(field) != null) - { - string value = ControlObj.GetControlValue(field); - if (string.IsNullOrEmpty(value)) isCondReplace = false; - billMainCode = billMainCode.Replace(item, value); - } - } - if (!isCondReplace) - { - sql = sql.Replace(fixedSql, "1=1"); - } - else - { - sql = sql.Replace(fixedSql, billMainCode); - - } - } - int oldRowHandle = 0; - if (unionModel.GridControlObj.GridView != null) - { - oldRowHandle = unionModel.GridControlObj.GridView.FocusedRowHandle; - } - - //和上一次查询sql相同就不再次查询了 - if (!unionModel.GridControlObj.LastSearchSql.Equals(sql)) - { - unionModel.GridControlObj.gridControl.DataSource = BaseImpl.GetDataTableResult(sql); - unionModel.GridControlObj.GridView.SelectRowHandler(oldRowHandle); - } - - //如果没有数据,显示 (0条) - //(unionModel.ModelObj.SourceType == 0 || this.IsBillShowCount) && unionModel.SearchObj.GridRowCount > 0 - if (unionModel.ModelObj.SourceType == 0 || this.IsBillShowCount) tabPage.Text = unionModel.ModelObj.UserName + "(" + unionModel.SearchObj.GridRowCount + QuantitySuffix; - - RefreshSourceDetail(unionModel); - } - - } - - } - /// - /// 说明:判断字符串出现次数 - /// 创建人:龚宇超 - /// 创建日期: - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The string. - /// The substring. - /// System.Int32. - private static int SubstringCount(string str, string substring) - { - if (str.Contains(substring)) - { - string strReplaced = str.Replace(substring, ""); - return (str.Length - strReplaced.Length) / substring.Length; - } - - return 0; - } - - - #endregion - - - - #region - - private void tb_buttom_Load(object sender, EventArgs e) - { - - } - #endregion - - - - - - - - /// - /// 说明:检查可用条件 - /// 创建人:龚宇超 - /// 创建日期:2017-11-09 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The cond. - /// The data row. - /// true if XXXX, false otherwise. - private bool ValidateCond(string cond, DataRow dataRow) - { - bool result = false; - string condition = cond; - try - { - if (string.IsNullOrWhiteSpace(cond)) return true;//如果值是空格或者空行,默认正确 - cond = ReplaceHelper.ReplaceRowParam(dataRow, cond); - if (cond.StartsWith("@") || cond.StartsWith("!")) - { - result = "1".Equals(BaseImpl.GetDefaultValue(cond)); - } - else if (dataRow == null) - { - result = ReplaceHelper.EvalCond(cond); - } - else - { - result = ReplaceHelper.ReplaceRowParamCond(dataRow, cond); - } - return result; - } - catch (Exception ex) - { - - } - return result; - } - - - /// - /// 设置打印按钮条件 - /// - /// - public bool SetPrintButton(DataRow rowItem) - { - try - { - bool result = false; - //判断打印按钮条件 - if (!string.IsNullOrWhiteSpace(this.BillModel.PrintingConditions)) - { - if (rowItem == null) return result; - - string cond = ReplaceHelper.ReplaceRowParam(rowItem, this.BillModel.PrintingConditions); - if (cond.StartsWith("@") || cond.StartsWith("!")) - { - result = "1".Equals(BaseImpl.GetDefaultValue(cond)); - } - else - { - result = ReplaceHelper.ReplaceRowParamCond(rowItem, cond); - } - return result; - } - else - { - return true; - } - } - catch (Exception ex) - { - return false; - } - } - - - - - - - } -} + /// + /// 说明:明细分割条移动保存位置 + /// 创建人:龚宇超 + /// 创建日期:2018-03-06 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + private void OnDetailsSplitterMoved(object sender, EventArgs e) + { + if (this._isInitFinish) + { + SplitContainerControl splitContainerControl = sender as SplitContainerControl; + IniHelper.Write(string.Format("bill_Details_Width_{0}", this.SysModel.ModuleCode), splitContainerControl.SplitterPosition + ""); + } + } + /// + /// 说明:单据来源查询之前处理 + /// 创建人:龚宇超 + /// 创建日期:2018-03-06 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The sender. + /// The e. + private void OnSearchBefore(object sender, SearchArgs e) + { + + // 用户搜索时不加载右侧控件值,只有点击、人为选中行在加载右侧控件值. + this._isLoadRightControlValue = false; + XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; + BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel; + if (!unionModel.SearchObj.VerifyNull()) + { + e.Continue = false; + } + } + /// + /// 说明:单据来源查询完成 + /// 创建人:龚宇超 + /// 创建日期:2018-03-06 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + /// + private void OnSearchAfterd(object sender, EventArgs e) + { + this._isLoadRightControlValue = true; + + XtraTabPage tabPage = this.xtc_main_container.SelectedTabPage; + BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel; + if (unionModel.ModelObj.SourceType == 1) + { + if (unionModel.TreeViewObj != null && unionModel.SearchObj.MainGridEx != null) + { + string sql = ReplaceHelper.ReplaceUserInfo(unionModel.SearchObj.MainGridEx.LastSearchSql); + + //和上一次查询sql相同就不再次查询了 + if (!unionModel.SearchObj.MainGridEx.LastSearchSql.Equals(sql)) + { + unionModel.SearchObj.MainGridEx.SetGridViewDataSource(BaseImpl.GetDataTableResult(sql)); + } + } + } + else + { + if (unionModel.GridControlObj != null) + { + + string sql = ReplaceHelper.ReplaceUserInfo(unionModel.GridControlObj.LastSearchSql); + + if (SubstringCount(sql, "#") > 1) + { + string fixedSql = sql.Substring(sql.IndexOf('#'), sql.LastIndexOf('#') + 1 - sql.IndexOf('#')); + string billMainCode = sql.Substring(sql.IndexOf('#'), sql.LastIndexOf('#') + 1 - sql.IndexOf('#')).Replace("#", ""); + var paramList = ReplaceHelper.GetParamFields(billMainCode); + bool isCondReplace = true; + foreach (string item in paramList) + { + string field = item.Replace("{", "").Replace("}", ""); + if (ControlObj.FindControl(field) != null) + { + string value = ControlObj.GetControlValue(field); + if (string.IsNullOrEmpty(value)) isCondReplace = false; + billMainCode = billMainCode.Replace(item, value); + } + } + if (!isCondReplace) + { + sql = sql.Replace(fixedSql, "1=1"); + } + else + { + sql = sql.Replace(fixedSql, billMainCode); + + } + } + int oldRowHandle = 0; + if (unionModel.GridControlObj.GridView != null) + { + oldRowHandle = unionModel.GridControlObj.GridView.FocusedRowHandle; + } + + //和上一次查询sql相同就不再次查询了 + if (!unionModel.GridControlObj.LastSearchSql.Equals(sql)) + { + unionModel.GridControlObj.gridControl.DataSource = BaseImpl.GetDataTableResult(sql); + unionModel.GridControlObj.GridView.SelectRowHandler(oldRowHandle); + } + + //如果没有数据,显示 (0条) + //(unionModel.ModelObj.SourceType == 0 || this.IsBillShowCount) && unionModel.SearchObj.GridRowCount > 0 + if (unionModel.ModelObj.SourceType == 0 || this.IsBillShowCount) tabPage.Text = unionModel.ModelObj.UserName + "(" + unionModel.SearchObj.GridRowCount + QuantitySuffix; + + RefreshSourceDetail(unionModel); + } + + } + + } + /// + /// 说明:判断字符串出现次数 + /// 创建人:龚宇超 + /// 创建日期: + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The string. + /// The substring. + /// System.Int32. + private static int SubstringCount(string str, string substring) + { + if (str.Contains(substring)) + { + string strReplaced = str.Replace(substring, ""); + return (str.Length - strReplaced.Length) / substring.Length; + } + + return 0; + } + + + #endregion + + + + #region + + private void tb_buttom_Load(object sender, EventArgs e) + { + + } + #endregion + + + + + + + + /// + /// 说明:检查可用条件 + /// 创建人:龚宇超 + /// 创建日期:2017-11-09 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The cond. + /// The data row. + /// true if XXXX, false otherwise. + private bool ValidateCond(string cond, DataRow dataRow) + { + bool result = false; + string condition = cond; + try + { + if (string.IsNullOrWhiteSpace(cond)) return true;//如果值是空格或者空行,默认正确 + cond = ReplaceHelper.ReplaceRowParam(dataRow, cond); + if (cond.StartsWith("@") || cond.StartsWith("!")) + { + result = "1".Equals(BaseImpl.GetDefaultValue(cond)); + } + else if (dataRow == null) + { + result = ReplaceHelper.EvalCond(cond); + } + else + { + result = ReplaceHelper.ReplaceRowParamCond(dataRow, cond); + } + return result; + } + catch (Exception ex) + { + + } + return result; + } + + + /// + /// 设置打印按钮条件 + /// + /// + public bool SetPrintButton(DataRow rowItem) + { + try + { + bool result = false; + //判断打印按钮条件 + if (!string.IsNullOrWhiteSpace(this.BillModel.PrintingConditions)) + { + if (rowItem == null) return result; + + string cond = ReplaceHelper.ReplaceRowParam(rowItem, this.BillModel.PrintingConditions); + if (cond.StartsWith("@") || cond.StartsWith("!")) + { + result = "1".Equals(BaseImpl.GetDefaultValue(cond)); + } + else + { + result = ReplaceHelper.ReplaceRowParamCond(rowItem, cond); + } + return result; + } + else + { + return true; + } + } + catch (Exception ex) + { + return false; + } + } + + + + + + + } +} diff --git a/插件库/Lskj.PubBillSpecial/BillModule.cs b/插件库/Lskj.PubBillSpecial/BillModule.cs index 2832799..5a70e5f 100644 --- a/插件库/Lskj.PubBillSpecial/BillModule.cs +++ b/插件库/Lskj.PubBillSpecial/BillModule.cs @@ -1,492 +1,492 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Windows.Forms; -using Lskj.Control; -using Lskj.Model; -using Lskj.Control.Model; -using Lskj.Util; -using Lskj.Business.Impl; -using DevExpress.XtraGrid.Views.Grid; -using Lskj.Data; -using DevExpress.XtraBars; -using DevExpress.XtraTab; -using DevExpress.XtraEditors; -using System.Collections; -using Lskj.PubBillSpecial.Model; -using DevExpress.Data; -using DevExpress.XtraGrid.Columns; -using System.IO; -using Lskj.Business; -using System.Text.RegularExpressions; -using DevExpress.XtraTreeList.Nodes; -using DevExpress.XtraEditors.Repository; -using DevExpress.XtraGrid.Views.Base; -using System.Threading; -using DevExpress.XtraGrid.Views.Grid.ViewInfo; -using Lskj.Core; -using DevExpress.XtraTreeList.Columns; -using System.Threading.Tasks; -using DevExpress.Utils; -using System.Data.SqlClient; -using Newtonsoft.Json.Linq; -using Newtonsoft.Json; - -namespace Lskj.PubBillSpecial -{ - public partial class BillModule : UserControl - { - /// - /// 是否为初始化创建 - /// - private bool _isInitFinish; - /// - /// 是否加载右侧控件数据 - /// - private bool _isLoadRightControlValue = true; - /// - /// 是否手动选择了模版 - /// - private bool _isSelectedTemplete; - /// - /// 是否直接打印 - /// - private bool _isExcPrint; - /// - /// 是否选择关联下发 - /// - private bool _isCheck; - /// - /// 主打印Sql - /// - private string _mainPrintSql; - private string guidField = "xxxxx_guid"; - /// - /// 主键字段 - /// - private string mRecordPrimaryField; - /// - /// 单据水印 - /// - private WaterMark _waterMark; - /// - /// 导入单据明细数据、导入单据明细并更新 - /// - private BarButtonItem _itemImport, _itemImportUpdate; - /// - /// 打印主sql中关联打印次数返回条件 - /// - private string _printModeCond; - /// - /// 打印完成后添加数据用到的参数: 表名,列前缀,主键字段,主键值,模块编号,主打印Sql - /// - private List _printSaveParams; - /// - /// 单据明细列 - /// - private DataTable _detailColumns; - private bool IsCopying = false; - /// - /// 单据来源明细拖拽删除当前行数据集合 - /// - private List RemoveRowitem = new List(); - - protected DataRow BillRowItem; - /// - /// 主表控件 - /// - public MyControl ControlObj; - /// - /// 入口参数 - /// - protected DynamicBillModel SysModel; - /// - /// 是否为Brp模版 - /// - /// true if this instance is BRP templete; otherwise, false. - protected bool IsBrpTemplete { get { return SysModel is DynamicBillBrpModel; } } - /// - /// - /// - public BillModel BillModel; - /// - /// 快速扫码控件 - /// - /// The main bottom input object. - public PanelControl MainBottomInputObj { get { return this.pl_input; } } - /// - /// Brp模版控件 - /// - /// The main bottom templete object. - public PanelControl MainBottomTempleteObj { get { return this.pl_templete; } } - /// - /// 明细表格数据 - /// - /// The main bottom templete object. - public GridControlEx gcMainDetilObj { get { return this.gcMain; } } - - /// - /// Brp模版控件 - /// - /// 扫码框 - public TextEdit txtinputobj { get { return this.txt_input; } } - /// - /// 数量名称 - /// - public string NumberMc; - /// - /// 红字单据的分配管理模块 - /// - public string rdRedUnionCode; - /// - /// 蓝字单据的分配管理模块 - /// - public string rdBlueUnionCode; - /// - /// 蓝字单据的分配管理模块 - /// - Dictionary pageNumKey = new Dictionary(); - /// - /// 是否拖拽换行展示 - /// - public bool isDragWrap = true; - /// - /// 触发主表改变刷新来源限制 - /// - private bool IsBillMaster = true; - /// - /// 是否执行了加载储存过程 - /// - //public bool ProcessExists = false; - /// - /// 保存或修改时报错信息 - /// - public string SaveErrorMessage = string.Empty; - /// - /// 单据明细删除的行 - /// - // private Dictionary ToWithdrawRows = new Dictionary(); - private List> ToWithdrawRows = new List>(); - /// - ///改变颜色行 - /// - private List ChangeColorRow = new List(); - /// - /// - /// - public string AssociatedField = string.Empty; - /// - /// 注册设置公共事件私有类 - /// - private static PubEvenImpl _eventHandler; - /// - /// 注册设置公共事件类 - /// - private static PubEvenImpl eventHandler; - /// - /// 当前人员是否有导出权限 - /// - public bool ExportPermission; - /// - /// 是否显示单据管理条数 - /// - public bool IsBillShowCount = false; - /// - /// 来源明细的页面名字后缀(设置成全局变量,更好的处理语言翻译的情况) - /// - public string DetailedSuffix = Business.Impl.LanguageTranslation.Translatable ? Business.Impl.LanguageTranslation.GetTranslatedText("-明细") : "-明细"; - /// - /// 单据来源控件集合 - /// - public Dictionary BillModuleModelDic = new Dictionary(); - /// - /// 主表动态生成的日期列 - /// - public List DateColumnList = new List(); - /// - /// 主表动态生成的合计列 - /// - public GridColumn SumGridColumn = new GridColumn(); - - /// - /// 是否已经添加了多行汇总 - /// - public bool MultiLineSummary; - /// - /// 扫码框 - /// - public TextEdit ScanCodeTextEdit = null; - /// - /// 右侧表格 - /// - public ModuleGridEx gridEx = null; - /// - /// 右侧表格Model - /// - public DynamicModel gridExModel = null; - +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using Lskj.Control; +using Lskj.Model; +using Lskj.Control.Model; +using Lskj.Util; +using Lskj.Business.Impl; +using DevExpress.XtraGrid.Views.Grid; +using Lskj.Data; +using DevExpress.XtraBars; +using DevExpress.XtraTab; +using DevExpress.XtraEditors; +using System.Collections; +using Lskj.PubBillSpecial.Model; +using DevExpress.Data; +using DevExpress.XtraGrid.Columns; +using System.IO; +using Lskj.Business; +using System.Text.RegularExpressions; +using DevExpress.XtraTreeList.Nodes; +using DevExpress.XtraEditors.Repository; +using DevExpress.XtraGrid.Views.Base; +using System.Threading; +using DevExpress.XtraGrid.Views.Grid.ViewInfo; +using Lskj.Core; +using DevExpress.XtraTreeList.Columns; +using System.Threading.Tasks; +using DevExpress.Utils; +using System.Data.SqlClient; +using Newtonsoft.Json.Linq; +using Newtonsoft.Json; + +namespace Lskj.PubBillSpecial +{ + public partial class BillModule : UserControl + { + /// + /// 是否为初始化创建 + /// + private bool _isInitFinish; + /// + /// 是否加载右侧控件数据 + /// + private bool _isLoadRightControlValue = true; + /// + /// 是否手动选择了模版 + /// + private bool _isSelectedTemplete; + /// + /// 是否直接打印 + /// + private bool _isExcPrint; + /// + /// 是否选择关联下发 + /// + private bool _isCheck; + /// + /// 主打印Sql + /// + private string _mainPrintSql; + private string guidField = "xxxxx_guid"; + /// + /// 主键字段 + /// + private string mRecordPrimaryField; + /// + /// 单据水印 + /// + private WaterMark _waterMark; + /// + /// 导入单据明细数据、导入单据明细并更新 + /// + private BarButtonItem _itemImport, _itemImportUpdate; + /// + /// 打印主sql中关联打印次数返回条件 + /// + private string _printModeCond; + /// + /// 打印完成后添加数据用到的参数: 表名,列前缀,主键字段,主键值,模块编号,主打印Sql + /// + private List _printSaveParams; + /// + /// 单据明细列 + /// + private DataTable _detailColumns; + private bool IsCopying = false; + /// + /// 单据来源明细拖拽删除当前行数据集合 + /// + private List RemoveRowitem = new List(); + + protected DataRow BillRowItem; + /// + /// 主表控件 + /// + public MyControl ControlObj; + /// + /// 入口参数 + /// + protected DynamicBillModel SysModel; + /// + /// 是否为Brp模版 + /// + /// true if this instance is BRP templete; otherwise, false. + protected bool IsBrpTemplete { get { return SysModel is DynamicBillBrpModel; } } + /// + /// + /// + public BillModel BillModel; + /// + /// 快速扫码控件 + /// + /// The main bottom input object. + public PanelControl MainBottomInputObj { get { return this.pl_input; } } + /// + /// Brp模版控件 + /// + /// The main bottom templete object. + public PanelControl MainBottomTempleteObj { get { return this.pl_templete; } } + /// + /// 明细表格数据 + /// + /// The main bottom templete object. + public GridControlEx gcMainDetilObj { get { return this.gcMain; } } + + /// + /// Brp模版控件 + /// + /// 扫码框 + public TextEdit txtinputobj { get { return this.txt_input; } } + /// + /// 数量名称 + /// + public string NumberMc; + /// + /// 红字单据的分配管理模块 + /// + public string rdRedUnionCode; + /// + /// 蓝字单据的分配管理模块 + /// + public string rdBlueUnionCode; + /// + /// 蓝字单据的分配管理模块 + /// + Dictionary pageNumKey = new Dictionary(); + /// + /// 是否拖拽换行展示 + /// + public bool isDragWrap = true; + /// + /// 触发主表改变刷新来源限制 + /// + private bool IsBillMaster = true; + /// + /// 是否执行了加载储存过程 + /// + //public bool ProcessExists = false; + /// + /// 保存或修改时报错信息 + /// + public string SaveErrorMessage = string.Empty; + /// + /// 单据明细删除的行 + /// + // private Dictionary ToWithdrawRows = new Dictionary(); + private List> ToWithdrawRows = new List>(); + /// + ///改变颜色行 + /// + private List ChangeColorRow = new List(); + /// + /// + /// + public string AssociatedField = string.Empty; + /// + /// 注册设置公共事件私有类 + /// + private static PubEvenImpl _eventHandler; + /// + /// 注册设置公共事件类 + /// + private static PubEvenImpl eventHandler; + /// + /// 当前人员是否有导出权限 + /// + public bool ExportPermission; + /// + /// 是否显示单据管理条数 + /// + public bool IsBillShowCount = false; + /// + /// 来源明细的页面名字后缀(设置成全局变量,更好的处理语言翻译的情况) + /// + public string DetailedSuffix = Business.Impl.LanguageTranslation.Translatable ? Business.Impl.LanguageTranslation.GetTranslatedText("-明细") : "-明细"; + /// + /// 单据来源控件集合 + /// + public Dictionary BillModuleModelDic = new Dictionary(); + /// + /// 主表动态生成的日期列 + /// + public List DateColumnList = new List(); + /// + /// 主表动态生成的合计列 + /// + public GridColumn SumGridColumn = new GridColumn(); + + /// + /// 是否已经添加了多行汇总 + /// + public bool MultiLineSummary; + /// + /// 扫码框 + /// + public TextEdit ScanCodeTextEdit = null; + /// + /// 右侧表格 + /// + public ModuleGridEx gridEx = null; + /// + /// 右侧表格Model + /// + public DynamicModel gridExModel = null; + public BillModule() { InitializeComponent(); } - - #region 初始化操作 - /// - /// 说明:窗口加载 - /// 创建人:龚宇超 - /// 创建日期:2017-11-23 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The instance containing the event data. - public void OnLoad(DynamicBillModel Model) - { - try - { + + #region 初始化操作 + /// + /// 说明:窗口加载 + /// 创建人:龚宇超 + /// 创建日期:2017-11-23 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The instance containing the event data. + public void OnLoad(DynamicBillModel Model) + { + try + { this.SysModel = Model;// 单据动态链接库参数,入口参数 this._isInitFinish = false;// 是否为初始化创建 - this.ssc_main.Visible = false; //获取或设置一个值,该值指示是否显示该控件及其所有子控件。 - //this.ProcessExists = (Lskj.Data.Caches.CacheSYSConfig.Instance().JudgeProcessExists() && SystemInfo.Instance.isExecload); - - if (true)//5.0控件样式 - { - this.pl_main_bottom.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder; - this.pl_main_bottom.BackColor = Color.FromArgb(240, 240, 240); - this.pl_main_bottom.LookAndFeel.UseDefaultLookAndFeel = false; - this.pl_main_bottom.LookAndFeel.UseWindowsXPTheme = true; - } - - Dictionary dataCaches = Model != null ? Model.DataCaches : null; - dataCaches.GetValue(this, "DataCaches", out bool _);//等待缓存数据加载完成 + this.ssc_main.Visible = false; //获取或设置一个值,该值指示是否显示该控件及其所有子控件。 + //this.ProcessExists = (Lskj.Data.Caches.CacheSYSConfig.Instance().JudgeProcessExists() && SystemInfo.Instance.isExecload); + + if (true)//5.0控件样式 + { + this.pl_main_bottom.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder; + this.pl_main_bottom.BackColor = Color.FromArgb(240, 240, 240); + this.pl_main_bottom.LookAndFeel.UseDefaultLookAndFeel = false; + this.pl_main_bottom.LookAndFeel.UseWindowsXPTheme = true; + } + + Dictionary dataCaches = Model != null ? Model.DataCaches : null; + dataCaches.GetValue(this, "DataCaches", out bool _);//等待缓存数据加载完成 this.InitializeSetting();//初始化系统配置 this.InitializeControl();//初始化控件 this.InitlizeSpiltLocation(); - - - this.gcMain.GridView.KeyDown += new KeyEventHandler(OnToWithdraw); - this.gcMain.GridView.GridControl.ProcessGridKey += new KeyEventHandler(OnGridControlKye); - - this.gcMain.ExportPermission = this.BillModel.ExportPermission; - this.CalculateCoordinates(); - - //单据明细推拽 - if (this.BillModel.DraggingOrder && !string.IsNullOrWhiteSpace(this.BillModel.DetailOrderField)) - { - this.gcMain.InitializedragState(this.BillModel.DetailOrderField); - } - - //非中文替换(红蓝单据等固定信息) - if (Business.Impl.LanguageTranslation.Translatable) - { - this.rdBlue.Text = Business.Impl.LanguageTranslation.GetTranslatedText(this.rdBlue.Text); - this.rdRed.Text = Business.Impl.LanguageTranslation.GetTranslatedText(this.rdRed.Text); - this.labelControl1.Text = Business.Impl.LanguageTranslation.GetTranslatedText(this.labelControl1.Text); - } - } - catch (Exception ex) - { - LogHelper.Instance.WriteError(ex); - LogUtil.WriteError("单据初始化窗体失败!", ex); - MessageUtil.Show(ex.StackTrace); - } + + + this.gcMain.GridView.KeyDown += new KeyEventHandler(OnToWithdraw); + this.gcMain.GridView.GridControl.ProcessGridKey += new KeyEventHandler(OnGridControlKye); + + this.gcMain.ExportPermission = this.BillModel.ExportPermission; + this.CalculateCoordinates(); + + //单据明细推拽 + if (this.BillModel.DraggingOrder && !string.IsNullOrWhiteSpace(this.BillModel.DetailOrderField)) + { + this.gcMain.InitializedragState(this.BillModel.DetailOrderField); + } + + //非中文替换(红蓝单据等固定信息) + if (Business.Impl.LanguageTranslation.Translatable) + { + this.rdBlue.Text = Business.Impl.LanguageTranslation.GetTranslatedText(this.rdBlue.Text); + this.rdRed.Text = Business.Impl.LanguageTranslation.GetTranslatedText(this.rdRed.Text); + this.labelControl1.Text = Business.Impl.LanguageTranslation.GetTranslatedText(this.labelControl1.Text); + } + } + catch (Exception ex) + { + LogHelper.Instance.WriteError(ex); + LogUtil.WriteError("单据初始化窗体失败!", ex); + MessageUtil.Show(ex.StackTrace); + } finally { this._isInitFinish = true; this.ssc_main.Visible = true; - if (this.BillModel.MainVerticalScroll || this.BillModel.MainHorizontalScrolling) - { - this.pl_main_center_master.AutoScroll = true; - this.pl_main_center_master.VerticalScroll.Visible = this.BillModel.MainVerticalScroll;//隐藏纵向滚动条 - this.pl_main_center_master.HorizontalScroll.Visible = this.BillModel.MainHorizontalScrolling;//隐藏横向滚动条 - } - } - } - - /// - /// 获取数据源缓存 - /// - /// - public void GetDataCaches(Dictionary cachesDic) - { - //获取通用数据 - Task sysModelTask = cachesDic.GetTask(this, "SysModel"); - Task systemDllRowTask = cachesDic.GetTask(this, "SystemDllRow"); - Task dynamicModelTask = cachesDic.GetTask(this, "DynamicModel"); - Task getDataCachesTask = cachesDic.AddTask(this, "DataCaches", new Task(() => - { - DynamicBillModel dynamicModel = (DynamicBillModel)dynamicModelTask.Result; - #region InitializeSetting初始化系统配置 - Task billInfoRowTask = cachesDic.AddTask(this, "BillInfo", new Task(() => - { - return BillImpl.GetBillInfo(dynamicModel.ModuleCode);//获取单个模块信息 - })); - Task billModelTask = cachesDic.AddTask(this, "BillModel", new Task(() => - { - BillModel model = null; - if (billInfoRowTask.Result != null) - { - model = new BillModel(billInfoRowTask.Result); - } - return model; - })); - BillModel billModel = billModelTask.Result; - if (billModel != null) - { - Task masterPreFixTask = cachesDic.AddTask(this, "MasterPreFix", new Task(() => - { - return BaseImpl.GetColumnPrefix(billModel.MasterTable);// 主表列前缀 - })); - Task detailPreFixTask = cachesDic.AddTask(this, "DetailPreFix", new Task(() => - { - return BaseImpl.GetColumnPrefix(billModel.DetailTable);// 明细表列前缀 - })); - } - Task menuConfigTabTask = cachesDic.AddTask(this, "MenuConfigTab", new Task(() => - { - DataRow dataRow = BaseImpl.GetMenuConfigTab(dynamicModel.ModuleId); - if (dataRow != null) - { - billModel.BillSourceIds = dataRow.Table.Columns.Contains("BillSourceIds") ? (dataRow["BillSourceIds"] + "").Trim(',') : string.Empty; - billModel.BillFlag = dataRow.Table.Columns.Contains("BillFlag") && !string.IsNullOrEmpty(dataRow["BillFlag"] + "") ? Convert.ToInt32(dataRow["BillFlag"] + "") : -1; - //billModel - } - return dataRow;//获取菜单其他配置 - })); - #region GetPrintOtherParam获取打印其他参数 - if (string.IsNullOrEmpty(billModel.PrintSql) && billModel.PrintSql.Contains("<<")) - { - string[] strs = billModel.PrintSql.Split(new[] { ">>" }, 2, StringSplitOptions.None); - _mainPrintSql = strs[1]; - _printModeCond = strs[0].Replace("<<", ""); - } - if (!string.IsNullOrEmpty(_printModeCond) && _printModeCond.IndexOf(';') > 0) - { - string[] str = _printModeCond.Split(';'); - Task printOtherSystemRowTask = cachesDic.AddTask(this, "PrintOtherSystemRow", new Task(() => - { - return AttachImpl.GetSystemModule(str[0]); - })); - Task printOtherColumnPrefixTask = cachesDic.AddTask(this, "PrintOtherColumnPrefix", new Task(() => - { - string tableName = printOtherSystemRowTask.Result["TableName"] + ""; - return BaseImpl.GetColumnPrefix(tableName); - })); - Task printOtherPrimaryKeyTask = cachesDic.AddTask(this, "PrintOtherPrimaryKey", new Task(() => - { - string modetype = printOtherSystemRowTask.Result["modType"] + ""; - return modetype == "1" ? BaseImpl.GetBasePrimaryKey(str[0]) : printOtherColumnPrefixTask.Result + "billdocument_id"; - })); - Task printOtherIsExcPrintTask = cachesDic.AddTask(this, "PrintOtherIsExcPrint", new Task(() => - { - string modetype = printOtherSystemRowTask.Result["modType"] + ""; - switch (modetype) - { - case "1": - ModuleModel mode = new ModuleModel(MainImpl.GetSystemdllTab(str[0])); - if (mode != null) - { - return mode.PrintType == 3; - } - break; - case "2": - BaseAccraditationModel model = new BaseAccraditationModel(BillAuditImpl.GetPubAuditProperty(str[0])); - if (model != null) - { - return model.BillPrintType == 3; - } - break; - } - return false; - })); - } - #endregion - Task billSettingTask = cachesDic.AddTask(this, "BillSetting", new Task(() => - { - BillImpl.InitBillSetting(billModel); - return true; - })); - #endregion - #region InitializeControl初始化控件 - if (dynamicModel is DynamicBillBrpModel || billModel.IsBrp)// 是否为Brp模版 - { - Task getBillBrpTask = cachesDic.AddTask(this, "GetBillBrp", new Task(() => - { - return BillImpl.GetBillBrp(dynamicModel.ModuleCode); - })); - } - Task operBaseGridRightMenusTask = cachesDic.AddTask(this, "OperBaseGridRightMenus", new Task(() => - { - return BaseModuleImpl.GetBaseGridRightMenus(dynamicModel.ModuleCode, ModuleType.BillDetail);//获取右键菜单数据 - })); - #region InitializeBillInfo初始化单据控件信息 - Task controlLocationTask = cachesDic.AddTask(this, "ControlLocation", new Task(() => - { - DataTable dataTable = BaseModuleImpl.GetControlLocation(billModel.FormKey, dynamicModel.ModuleCode); - //if (billModel.CenterMain) dataTable = this.SetControlMargins(dataTable); - return dataTable; - })); - // MyControl 持有 WinForms Timer。后台阶段只加载控件配置, - // 实际 MyControl 及编辑控件由 InitializeBillInfo 在 UI 线程创建。 - Task addGroupDataTask = cachesDic.AddTask(this, "AddGroupData", new Task(() => - { - return BaseModuleImpl.GetAddGroupData(billModel.FormKey);//获取主信息分组数据 - })); - Task detailColumnsTask = cachesDic.AddTask(this, "DetailColumns", new Task(() => - { - if (dynamicModel.GridEnumObj == GridEnum.BandedGridView || billModel.AutoMultiHeader == 1) - { - return BillImpl.GetDetailColumns(dynamicModel.ModuleCode, true);//初始化单据明细列 - } - return BillImpl.GetDetailColumns(dynamicModel.ModuleCode);//初始化单据明细列 - })); - //创建表格列 - cachesDic.AddTask(gcMain, "DynamicModel", dynamicModelTask); - gcMain.GetDataCaches(cachesDic, GridCustomColumnStruct.BillDetailGridView + billModel.FormKey); - Task baseGridRowColorsTask = cachesDic.AddTask(gcMain, "BaseGridRowColors", new Task(() => - { - return BaseModuleImpl.GetBaseGridRowColors("BILLDETAIL_" + billModel.FormKey); - })); - Task baseGridRightMenusTask = cachesDic.AddTask(gcMain, "BaseGridRightMenus", new Task(() => - { - return BaseModuleImpl.GetBaseGridRightMenus("BILLDETAIL_" + dynamicModel.ModuleCode);//设置表格右键菜单 - })); - #endregion - return true; - })); - #endregion - } - - /// - /// 说明:初始化分割条位置 - /// 创建人:龚宇超 - /// 创建日期:2018-03-06 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// + if (this.BillModel.MainVerticalScroll || this.BillModel.MainHorizontalScrolling) + { + this.pl_main_center_master.AutoScroll = true; + this.pl_main_center_master.VerticalScroll.Visible = this.BillModel.MainVerticalScroll;//隐藏纵向滚动条 + this.pl_main_center_master.HorizontalScroll.Visible = this.BillModel.MainHorizontalScrolling;//隐藏横向滚动条 + } + } + } + + /// + /// 获取数据源缓存 + /// + /// + public void GetDataCaches(Dictionary cachesDic) + { + //获取通用数据 + Task sysModelTask = cachesDic.GetTask(this, "SysModel"); + Task systemDllRowTask = cachesDic.GetTask(this, "SystemDllRow"); + Task dynamicModelTask = cachesDic.GetTask(this, "DynamicModel"); + Task getDataCachesTask = cachesDic.AddTask(this, "DataCaches", new Task(() => + { + DynamicBillModel dynamicModel = (DynamicBillModel)dynamicModelTask.Result; + #region InitializeSetting初始化系统配置 + Task billInfoRowTask = cachesDic.AddTask(this, "BillInfo", new Task(() => + { + return BillImpl.GetBillInfo(dynamicModel.ModuleCode);//获取单个模块信息 + })); + Task billModelTask = cachesDic.AddTask(this, "BillModel", new Task(() => + { + BillModel model = null; + if (billInfoRowTask.Result != null) + { + model = new BillModel(billInfoRowTask.Result); + } + return model; + })); + BillModel billModel = billModelTask.Result; + if (billModel != null) + { + Task masterPreFixTask = cachesDic.AddTask(this, "MasterPreFix", new Task(() => + { + return BaseImpl.GetColumnPrefix(billModel.MasterTable);// 主表列前缀 + })); + Task detailPreFixTask = cachesDic.AddTask(this, "DetailPreFix", new Task(() => + { + return BaseImpl.GetColumnPrefix(billModel.DetailTable);// 明细表列前缀 + })); + } + Task menuConfigTabTask = cachesDic.AddTask(this, "MenuConfigTab", new Task(() => + { + DataRow dataRow = BaseImpl.GetMenuConfigTab(dynamicModel.ModuleId); + if (dataRow != null) + { + billModel.BillSourceIds = dataRow.Table.Columns.Contains("BillSourceIds") ? (dataRow["BillSourceIds"] + "").Trim(',') : string.Empty; + billModel.BillFlag = dataRow.Table.Columns.Contains("BillFlag") && !string.IsNullOrEmpty(dataRow["BillFlag"] + "") ? Convert.ToInt32(dataRow["BillFlag"] + "") : -1; + //billModel + } + return dataRow;//获取菜单其他配置 + })); + #region GetPrintOtherParam获取打印其他参数 + if (string.IsNullOrEmpty(billModel.PrintSql) && billModel.PrintSql.Contains("<<")) + { + string[] strs = billModel.PrintSql.Split(new[] { ">>" }, 2, StringSplitOptions.None); + _mainPrintSql = strs[1]; + _printModeCond = strs[0].Replace("<<", ""); + } + if (!string.IsNullOrEmpty(_printModeCond) && _printModeCond.IndexOf(';') > 0) + { + string[] str = _printModeCond.Split(';'); + Task printOtherSystemRowTask = cachesDic.AddTask(this, "PrintOtherSystemRow", new Task(() => + { + return AttachImpl.GetSystemModule(str[0]); + })); + Task printOtherColumnPrefixTask = cachesDic.AddTask(this, "PrintOtherColumnPrefix", new Task(() => + { + string tableName = printOtherSystemRowTask.Result["TableName"] + ""; + return BaseImpl.GetColumnPrefix(tableName); + })); + Task printOtherPrimaryKeyTask = cachesDic.AddTask(this, "PrintOtherPrimaryKey", new Task(() => + { + string modetype = printOtherSystemRowTask.Result["modType"] + ""; + return modetype == "1" ? BaseImpl.GetBasePrimaryKey(str[0]) : printOtherColumnPrefixTask.Result + "billdocument_id"; + })); + Task printOtherIsExcPrintTask = cachesDic.AddTask(this, "PrintOtherIsExcPrint", new Task(() => + { + string modetype = printOtherSystemRowTask.Result["modType"] + ""; + switch (modetype) + { + case "1": + ModuleModel mode = new ModuleModel(MainImpl.GetSystemdllTab(str[0])); + if (mode != null) + { + return mode.PrintType == 3; + } + break; + case "2": + BaseAccraditationModel model = new BaseAccraditationModel(BillAuditImpl.GetPubAuditProperty(str[0])); + if (model != null) + { + return model.BillPrintType == 3; + } + break; + } + return false; + })); + } + #endregion + Task billSettingTask = cachesDic.AddTask(this, "BillSetting", new Task(() => + { + BillImpl.InitBillSetting(billModel); + return true; + })); + #endregion + #region InitializeControl初始化控件 + if (dynamicModel is DynamicBillBrpModel || billModel.IsBrp)// 是否为Brp模版 + { + Task getBillBrpTask = cachesDic.AddTask(this, "GetBillBrp", new Task(() => + { + return BillImpl.GetBillBrp(dynamicModel.ModuleCode); + })); + } + Task operBaseGridRightMenusTask = cachesDic.AddTask(this, "OperBaseGridRightMenus", new Task(() => + { + return BaseModuleImpl.GetBaseGridRightMenus(dynamicModel.ModuleCode, ModuleType.BillDetail);//获取右键菜单数据 + })); + #region InitializeBillInfo初始化单据控件信息 + Task controlLocationTask = cachesDic.AddTask(this, "ControlLocation", new Task(() => + { + DataTable dataTable = BaseModuleImpl.GetControlLocation(billModel.FormKey, dynamicModel.ModuleCode); + //if (billModel.CenterMain) dataTable = this.SetControlMargins(dataTable); + return dataTable; + })); + // MyControl 持有 WinForms Timer。后台阶段只加载控件配置, + // 实际 MyControl 及编辑控件由 InitializeBillInfo 在 UI 线程创建。 + Task addGroupDataTask = cachesDic.AddTask(this, "AddGroupData", new Task(() => + { + return BaseModuleImpl.GetAddGroupData(billModel.FormKey);//获取主信息分组数据 + })); + Task detailColumnsTask = cachesDic.AddTask(this, "DetailColumns", new Task(() => + { + if (dynamicModel.GridEnumObj == GridEnum.BandedGridView || billModel.AutoMultiHeader == 1) + { + return BillImpl.GetDetailColumns(dynamicModel.ModuleCode, true);//初始化单据明细列 + } + return BillImpl.GetDetailColumns(dynamicModel.ModuleCode);//初始化单据明细列 + })); + //创建表格列 + cachesDic.AddTask(gcMain, "DynamicModel", dynamicModelTask); + gcMain.GetDataCaches(cachesDic, GridCustomColumnStruct.BillDetailGridView + billModel.FormKey); + Task baseGridRowColorsTask = cachesDic.AddTask(gcMain, "BaseGridRowColors", new Task(() => + { + return BaseModuleImpl.GetBaseGridRowColors("BILLDETAIL_" + billModel.FormKey); + })); + Task baseGridRightMenusTask = cachesDic.AddTask(gcMain, "BaseGridRightMenus", new Task(() => + { + return BaseModuleImpl.GetBaseGridRightMenus("BILLDETAIL_" + dynamicModel.ModuleCode);//设置表格右键菜单 + })); + #endregion + return true; + })); + #endregion + } + + /// + /// 说明:初始化分割条位置 + /// 创建人:龚宇超 + /// 创建日期:2018-03-06 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// private void InitlizeSpiltLocation() { try - { - // 隐藏来源 - this.ssc_main_top.PanelVisibility = SplitPanelVisibility.Panel2; - // 隐藏来源明细 - this.ssc_main.PanelVisibility = SplitPanelVisibility.Panel1; - int maxPosition = 0; - foreach (System.Windows.Forms.Control item in this.pl_main_center_master.Controls) - { - if (item is BaseUserControl baseUserControl && (baseUserControl.Location.X + baseUserControl.Width) > maxPosition) - { - maxPosition = baseUserControl.Location.X + baseUserControl.Width; - } - } + { + // 隐藏来源 + this.ssc_main_top.PanelVisibility = SplitPanelVisibility.Panel2; + // 隐藏来源明细 + this.ssc_main.PanelVisibility = SplitPanelVisibility.Panel1; + int maxPosition = 0; + foreach (System.Windows.Forms.Control item in this.pl_main_center_master.Controls) + { + if (item is BaseUserControl baseUserControl && (baseUserControl.Location.X + baseUserControl.Width) > maxPosition) + { + maxPosition = baseUserControl.Location.X + baseUserControl.Width; + } + } this.splitMainControl.SplitterPosition = maxPosition + 10; this.splitMainControl.IsSplitterFixed = true; } @@ -496,4560 +496,4560 @@ namespace Lskj.PubBillSpecial } } - /// - /// 说明:初始化系统配置 - /// 创建人:龚宇超 - /// 创建日期:2017-11-27 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - private void InitializeSetting() - { - Dictionary dataCaches = SysModel != null ? SysModel.DataCaches : null; - if (!dataCaches.GetValue(this, "BillInfo", out DataRow modelRow)) - { - modelRow = BillImpl.GetBillInfo(this.SysModel.ModuleCode);//获取单个模块信息 - } - if (modelRow == null) - { - //MessageUtil.Show("模块编号[" + this.SysModel.ModuleCode + "],配置错误!\r\n该模块信息未找到!"); - //return; - throw new Exception("模块编号[" + this.SysModel.ModuleCode + "],配置错误!\r\n该模块信息未找到!"); - } - if (!dataCaches.GetValue(this, "BillModel", out BillModel)) - { - this.BillModel = new BillModel(modelRow);//初始化类的新实例。 - } - - if (this.BillModel != null) - { - this.BillModel.TypeName = string.IsNullOrEmpty(SysModel.BillMasterSql) ? this.SysModel.FormText : this.BillModel.TypeName;// 模块名称 - if (!dataCaches.GetValue(this, "MasterPreFix", out string masterPreFix)) - { - masterPreFix = BaseImpl.GetColumnPrefix(this.BillModel.MasterTable);// 主表列前缀 - } - this.BillModel.MasterPreFix = masterPreFix; - if (!dataCaches.GetValue(this, "DetailPreFix", out string detailPreFix)) - { - detailPreFix = BaseImpl.GetColumnPrefix(this.BillModel.DetailTable);// 明细表列前缀 - } - this.BillModel.DetailPreFix = detailPreFix; - this.BillModel.DetailOrderField = this.BillModel.DetailPreFix + "lsidx_id";// 单据来源id - if (SystemInfo.Instance.IsNotBillDetailOrder)//禁用排序 - this.BillModel.DetailOrderField = string.Empty; - } - if (!dataCaches.GetValue(this, "MenuConfigTab", out DataRow menuRow)) - { - menuRow = BaseImpl.GetMenuConfigTab(this.SysModel.ModuleId);//获取菜单其他配置 - } - if (menuRow != null) - { - this.BillModel.BillSourceIds = menuRow.Table.Columns.Contains("BillSourceIds") ? (menuRow["BillSourceIds"] + "").Trim(',') : string.Empty; - this.BillModel.BillFlag = menuRow.Table.Columns.Contains("BillFlag") && !string.IsNullOrEmpty(menuRow["BillFlag"] + "") ? Convert.ToInt32(menuRow["BillFlag"] + "") : -1; - } - - //获取打印其他参数 - GetPrintOtherParam(); - if (!dataCaches.GetValue(this, "BillSetting", out bool _)) - { - BillImpl.InitBillSetting(this.BillModel); - } - - if (this.BillModel.IsBrp) - { - this.MainBottomInputObj.Visible = false; - this.MainBottomTempleteObj.Visible = true; - } - - //显示筛选行 - if (this.BillModel.LoadFilter) this.gcMain.GridView.OptionsView.ShowAutoFilterRow = true; - //树表格 - if (this.BillModel.DetailTreeTable) - { - this.pl_main_center_detail.Controls.Clear(); - this.gcMain = new TreeGridControlEx(); - this.gcMain.Dock = DockStyle.Fill; - this.pl_main_center_detail.Controls.Add(this.gcMain); - (this.gcMain as TreeGridControlEx).Expansion = this.BillModel.DetailTreeTableExpansion; - (this.gcMain as TreeGridControlEx).AddRightButton(); - //节点编号 - (this.gcMain as TreeGridControlEx).TreeListObj.KeyFieldName = "tap_id"; - //父节点编号 - (this.gcMain as TreeGridControlEx).TreeListObj.ParentFieldName = "tap_pid"; - (this.gcMain as TreeGridControlEx).SortField = this.BillModel.DetailOrderField; - - (this.gcMain as TreeGridControlEx).InitializedragState(); - } - - - } - /// - /// 说明:初始化分配关联模块 - /// 创建人:王一帆 - /// 创建日期:2020-02-18 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - private void InitializeUnionCode() - { - if (this.BillModel.PopupUnionCode.Contains(",")) - { - string[] UnionCodeSplit = this.BillModel.PopupUnionCode.Split(','); - if (UnionCodeSplit.Length >= 1) - { - this.BillModel.PopupUnionCode = this.BillModel.BillFlag == 1 ? UnionCodeSplit[1] + "" : UnionCodeSplit[0] + ""; - rdBlueUnionCode = UnionCodeSplit[0] + ""; - rdRedUnionCode = UnionCodeSplit[1] + ""; - } - } - else - { - rdBlueUnionCode = rdRedUnionCode = this.BillModel.PopupUnionCode; - } - } - /// - /// 说明:初始化控件 - /// 创建人:龚宇超 - /// 创建日期:2017-11-23 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - private void InitializeControl() - { - if (this.IsBrpTemplete || this.BillModel.IsBrp)// 是否为Brp模版 - this.InitializeTemplete(); - - this.InitializeStatus();//初始化红蓝字单 - this.InitializeOper();//初始化常用操作等功能 - this.InitializeBillInfo();//初始化单据控件信息 - this.InitializeModuleGridex(); - } - - /// - /// 初始化右侧表格 - /// - private void InitializeModuleGridex() - { - gridExModel = new DynamicModel(new string[] { "", ERPInfo.Instance.UserId, ERPInfo.Instance.UserName, this.SysModel.Privilege, this.BillModel.RightModuleCode, "0" }); - DataRow moduleInformation = MainImpl.GetSystemdllTab(this.BillModel.RightModuleCode); - if (moduleInformation == null) - { - MessageUtil.Show("没有找到编号为" + this.BillModel.RightModuleCode + "的模块信息"); - return; - } - ModuleModel model = new ModuleModel(moduleInformation); - this.gridEx = new ModuleGridEx(); - model.ParmaryKey = BaseImpl.GetBasePrimaryKey(this.BillModel.RightModuleCode); - gridEx.OnSaveGridCallBack += OnDetailSaveGridCallBack; - gridEx.DetailRightGridCallBack += OnDetailRightCallback; - gridEx.Name = "gridEx"; - gridEx.IsDetail = true; - gridEx.Dock = DockStyle.Fill; - gridEx.OperShortMode = false; // 不显示简短模式 - gridEx.VisibleSearchPanel = false; - gridEx.VisibleOperPanel = true; - gridEx.InitializeControl(model, gridExModel); - gridEx.GridControlObj.Tag = model;//都在本地图可留着备用 - //gridEx.ParentControlEx = this.gcMain; - gridEx.ParentControlObj = this.ControlObj; - gridEx.ParentGridEx = this.gcMain;//父级关联明细可扩展 - //gridEx.ParentKeyField = string.IsNullOrEmpty(model.UnionParentField) ? model.SystemModel.ParmaryKey : model.UnionParentField; - //gridEx.DetailKeyField = model.UnionValue;//新增关联可拖拽刷新数据源 - - gridEx.VisibleSearchPanel = false; - gridEx.ObjPanel.Enabled = false; - gridEx.GridControlObj.ParentControl = gridEx.SearchObj; - this.splitMainControl.Panel2.Controls.Add(gridEx); - gridEx.SearchObj.SearchGrid(); - - gridEx.ObjPanel.Height = 46; - List deleteControls = new List(); - foreach (System.Windows.Forms.Control item in gridEx.ObjPanel.Controls) - { - if (item.Name.Equals("dpbTools") || item.Name.Equals("btnUpdate") || item.Name.Equals("btnImport") || item.Name.Equals("btnExport") || item.Name.Equals("btnPrint")) - { - deleteControls.Add(item); - } - } - foreach (System.Windows.Forms.Control item in deleteControls) - { - gridEx.ObjPanel.Controls.Remove(item); - } - int j = 0, x = 72; - foreach (System.Windows.Forms.Control item in gridEx.ObjPanel.Controls) - { - item.Location = new Point(gridEx.ObjPanel.Width - x - 10, (gridEx.ObjPanel.Height - item.Height) / 2); - item.Anchor = AnchorStyles.Top | AnchorStyles.Right; - x += 79; - j++; - } - } - - #region 衍生表格数据操作 - private void OnDetailRightCallback(object sender, EventArgs e) - { - - } - private void OnDetailSaveGridCallBack(object sender, EventArgs e) - { - - } - - #endregion - - - /// - /// 说明:初始化红蓝字单 - /// 创建人:龚宇超 - /// 创建日期:2017-11-27 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - private void InitializeStatus() - { - // 初始化红、蓝单 - if (this.BillModel.BillFlag == 0) - { - this.rdBlue.Checked = true; - this.rdRed.Checked = false; - this.lbTitle.ForeColor = Color.Blue; - this.pl_red.Visible = false; - } - if (this.BillModel.BillFlag == 1) - { - this.rdRed.Checked = true; - this.rdBlue.Checked = false; - this.lbTitle.ForeColor = Color.Red; - this.pl_blue.Visible = false; - } - - - if (this.SysModel.HasReadPrivilege()) - this.pl_main_bottom.Enabled = false; - this.ssc_main_top.SplitterPosition = this.BillModel.PanelWidth; - InitializeUnionCode();//根据红蓝字段更新分配 - } - /// - /// 说明:初始化常用操作等功能 - /// 创建人:龚宇超 - /// 创建日期:2017-11-27 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - private void InitializeOper() - { - BarButtonItem itemCopyMaster = new BarButtonItem(); - itemCopyMaster.Caption = "复制表头信息"; - itemCopyMaster.ItemClick += new ItemClickEventHandler(OnCopyMasterItemClick); - BarButtonItem itemCopyAll = new BarButtonItem(); - itemCopyAll.Caption = "复制整单信息"; - itemCopyAll.ItemClick += new ItemClickEventHandler(OnCopyAllItemClick); - BarButtonItem itemExport = new BarButtonItem(); - itemExport.Caption = "导出Excel文件"; - itemExport.ItemClick += new ItemClickEventHandler(OnExportItemClick); - BarButtonItem itemFPBatch = new BarButtonItem(); - itemFPBatch.Caption = "批量分配"; - itemFPBatch.ItemClick += new ItemClickEventHandler(OnBtnFPNewClick); - this._itemImport = new BarButtonItem(); - this._itemImport.Caption = "导入Excel文件"; - this._itemImport.ItemClick += new ItemClickEventHandler(OnImportItemClick); - this._itemImportUpdate = new BarButtonItem(); - this._itemImportUpdate.Caption = "导入Excel文件(更新)"; - this._itemImportUpdate.ItemClick += new ItemClickEventHandler(OnImportUpdateItemClick); - - // 复制单据 - this.pmBill.AddItems(new BarItem[] { itemCopyMaster, itemCopyAll }); - // 导入导出 - if (this.BillModel.CanExport && this.BillModel.ExportPermission) - { - this.pmBillExp.AddItem(itemExport); - } - if (this.BillModel.CanImport) - { - this.pmBillExp.AddItems(new BarItem[] { _itemImport, _itemImportUpdate }); - } - //分配 - this.pmFP.AddItems(new BarItem[] { itemFPBatch }); - // 打印模版 - //string[] files = this.BillModel.PrintFile.Split('|'); - //for (int i = 0; i < files.Length; i++) - //{ - // string fileName = files[i]; - // if (!string.IsNullOrWhiteSpace(fileName)) - // { - // BarButtonItem itemPrint = new BarButtonItem(); - // int index = i + 1; - // itemPrint.Caption = files[i].Replace(".rmf", "").Replace(".frx", ""); - // itemPrint.Tag = files[i]; - // itemPrint.ItemClick += new ItemClickEventHandler(OnPrintItemClick); - // pMprint.AddItem(itemPrint); - // } - //} - - // 常用工具 - Dictionary dataCaches = SysModel != null ? SysModel.DataCaches : null; - if (!dataCaches.GetValue(this, "OperBaseGridRightMenus", out DataTable tableCommon)) - { - tableCommon = BaseModuleImpl.GetBaseGridRightMenus(this.SysModel.ModuleCode, ModuleType.BillDetail);//获取右键菜单数据 - } - int j = 0, x = 72; - foreach (DataRow item in tableCommon.Rows) - { - SimpleButton itemCommon = new SimpleButton(); - //itemCommon.Enabled = false; - //itemCommon.AutoSize = true; - itemCommon.Text = item["menuname"] + ""; - itemCommon.Tag = item; - itemCommon.Size = new System.Drawing.Size(72, 26); - itemCommon.Font = new Font("宋体", 9); - itemCommon.Click += new EventHandler(itemCommon_Click); - - itemCommon.Location = new Point(pl_buttom.Width - x - 10, (pl_buttom.Height - itemCommon.Height) / 2); - itemCommon.Anchor = AnchorStyles.Top | AnchorStyles.Right; - pl_buttom.Controls.Add(itemCommon); - x += 79; - if (tableCommon.Columns.Contains("menuCond")) - { - itemCommon.Enabled = ValidateCond(item["menuCond"] + "", null); - } - j++; - } - } - /// - /// 说明:常用工具点击 - /// 创建人:龚宇超 - /// 创建日期:2017-11-27 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - protected void itemCommon_Click(object sender, EventArgs e) - { - try - { - SimpleButton btn = sender as SimpleButton; - DataRow rowItem = btn.Tag as DataRow; - GridRightMenuModel model = new GridRightMenuModel(rowItem); - if (rowItem["dllname"].Equals("Lskj.PubBomImport.dll")) - { - if ((model.ParamList[7] + "").Equals("3")) - { - if (!this.BillSave(0, false)) - { - return; - } - } - } - - //获取红蓝单据 - string DocumentColor = this.rdBlue.Checked ? "0" : this.rdRed.Checked ? "1" : ""; - - - if ((rowItem["orderid"] + "").Equals("999")) - { - string ModuleCode = model.DllParam2; - FrmSource frmSource = new FrmSource(ModuleCode, SysModel, model.MaxWindow, false); - frmSource.PrimaryKey = this.BillModel.PrimaryKey; - frmSource.PrimaryValue = this.lblOrderNo.Text; - frmSource.DocumentColor = DocumentColor; - frmSource.Text = model.MenuName; - if (frmSource.ShowDialog() == DialogResult.OK) - { - this.lblOrderNo.Text = frmSource.ReturnPrimaryValue; - } - this.SetBillStatus(BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, this.lblOrderNo.Text))); - } - else if ((rowItem["orderid"] + "").Equals("888")) - { - string ModuleCode = model.DllParam2; - FrmSource frmSource = new FrmSource(ModuleCode, SysModel, model.MaxWindow, true); - frmSource.PrimaryKey = this.BillModel.PrimaryKey; - frmSource.PrimaryValue = this.lblOrderNo.Text; - frmSource.DocumentColor = DocumentColor; - frmSource.Text = model.MenuName; - if (frmSource.ShowDialog() == DialogResult.OK) - { - this.lblOrderNo.Text = frmSource.ReturnPrimaryValue; - } - this.SetBillStatus(BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, this.lblOrderNo.Text))); - } - else - { - CommonMenu menu = new CommonMenu(this.SysModel, this.ControlObj, this.gcMain); - menu.ApplyBefore += new CommonToolApplyEventHandler(OnMenuApplyBefore); - menu.DynamicLinkAfter += new CommonToolAfterDynamicLinkEventHandler(OnDynamicLinkAfter); - menu.Apply(rowItem); - if (model != null && model.Refresh) - { - string billNo = this.lblOrderNo.Text.Trim(); - this.SetBillStatus(BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, billNo))); - } - } - - - - } - catch (Exception ex) - { - string Message = ErrorMessage.PromptErrorMessage(ex); - MessageUtil.Show(Message, ex.Message); - } - - } - /// - /// 说明:初始化单据控件信息 - /// 创建人:龚宇超 - /// 创建日期:2017-11-27 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - private void InitializeBillInfo() - { - Dictionary dataCaches = SysModel != null ? SysModel.DataCaches : null; - if (!dataCaches.GetValue(this, "ControlLocation", out DataTable controls)) - { - controls = BaseModuleImpl.GetControlLocation(this.BillModel.FormKey, this.SysModel.ModuleCode); - //if (this.BillModel.CenterMain) controls = this.SetControlMargins(controls); - } - if (!dataCaches.GetValue(this, "AddGroupData", out DataTable groups)) - { - groups = BaseModuleImpl.GetAddGroupData(this.BillModel.FormKey);//获取主信息分组数据 - } - if (!dataCaches.GetValue(this, "ControlObj", out ControlObj)) - { - this.ControlObj = new MyControl() { Model = SysModel };//主表控件 - this.ControlObj.OtherParams = this.SysModel.OtherParams(); - if (dataCaches != null) - { - dataCaches.AddTask(this.ControlObj, "DynamicModel", - new Task(() => this.SysModel)); - dataCaches.AddTask(this.ControlObj, "ControlsTable", - new Task(() => controls)); - this.ControlObj.GetControlDataCaches(dataCaches); - } - } - - - - //this.ControlObj = new MyControl();//// 主表控件 - this.ControlObj.OtherParams = this.SysModel.OtherParams(); - this.ControlObj.InitControl(controls, this.pl_main_center_master, groups); - this.ControlObj.refGridLookUpData = this.BillModel.RefGridLookUpData;//2023-3-17,新增单据时刷新下拉框数据源 - this.ControlObj.OnDataFileRefrshCallBack += OnDataFileRefrshFile; - this.ControlObj.OnDataSourceBindCallBack += new EventHandler(OnInitializeHeaderCallBack); - this.pl_main_center_master.Height = (this.BillModel.ParentHeight - 36) > this.pl_main_center_master.Height ? this.pl_main_center_master.Height : this.BillModel.ParentHeight - 36; - this.splitMainControl.Height = this.pl_main_center_master.Height + pl_buttom.Height + 12; - // 初始化明细 - // 创建多表头,默认标准表格 - if (this.SysModel.GridEnumObj == GridEnum.BandedGridView || this.BillModel.AutoMultiHeader == 1) - { - this.pl_main_center_detail.Controls.Clear(); - this.gcMain = new BandedGridControlEx(); - this.gcMain.Model = this.SysModel; - this.gcMain.Dock = DockStyle.Fill; - this.pl_main_center_detail.Controls.Add(this.gcMain); - } - - if (!dataCaches.GetValue(this, "DetailColumns", out _detailColumns)) - { - _detailColumns = BillImpl.GetDetailColumns(this.SysModel.ModuleCode);//初始化单据明细列 - if (this.SysModel.GridEnumObj == GridEnum.BandedGridView || this.BillModel.AutoMultiHeader == 1) - { - //多表头sql要增加一个判断,否则多表头会出错 - _detailColumns = BillImpl.GetDetailColumns(this.SysModel.ModuleCode, true);//初始化单据明细列 - } - } - this.gcMain.DisableFieldSources = this.BillModel.DisableFieldSources; - this.gcMain.Model = this.SysModel; - this.gcMain.ParentControl = this.ControlObj;//把主表控件赋给 单据主表控件、基础档案查询条件控件等等 - this.gcMain.SetEditColumns(_detailColumns, GridCustomColumnStruct.BillDetailGridView + this.BillModel.FormKey);//设置可编辑列 - if (this.BillModel.IsBillMainDetailCheck == 1)//加载明细复选框 - { - GridDragGrid.GridAddCheckBox(this.gcMain.GridView); - } - - if (!dataCaches.GetValue(gcMain, "BaseGridRowColors", out DataTable dtBaseGridRowColors)) - { - dtBaseGridRowColors = BaseModuleImpl.GetBaseGridRowColors("BILLDETAIL_" + this.BillModel.FormKey); - } - this.gcMain.SetGridRowColors(dtBaseGridRowColors); - //触发右键回调 - this.gcMain.OnAfterLinkCilk += OnAfterLinkCilkCall; - if (!dataCaches.GetValue(gcMain, "BaseGridRightMenus", out DataTable dtBaseGridRightMenus)) - { - dtBaseGridRightMenus = BaseModuleImpl.GetBaseGridRightMenus("BILLDETAIL_" + this.SysModel.ModuleCode); - } - if (this.gcMain is BandedGridControlEx)// 判断是不是多表头表格 - { - //设置表格右键菜单 - (this.gcMain as BandedGridControlEx).SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridViewRightCallBack, this.ControlObj); - } - else if (this.BillModel.DetailTreeTable) - { - (this.gcMain as TreeGridControlEx).SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridViewRightCallBack, this.ControlObj, (this.gcMain as TreeGridControlEx).MenuStrip); - (this.gcMain as TreeGridControlEx).TreeListObj.ShowingEditor += new CancelEventHandler(OnGridViewShowingEditor); - } - else - { - this.gcMain.SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridViewRightCallBack, this.ControlObj); - this.gcMain.GridView.ShowingEditor += new CancelEventHandler(OnGridViewShowingEditor); - } - - - if (this.BillModel.DefaultAddEmptyRow) - { - this.gcMain.GridView.OptionsView.NewItemRowPosition = NewItemRowPosition.Bottom; - if (SystemInfo.Instance.IsAddEmptyRowOldTag) - { - this.gcMain.GridView.MouseDown += GridView_MouseDown; - this.gcMain.GridView.FocusedRowChanged += GridView_FocusedRowChanged; - } - else - { - this.gcMain.GridView.InitNewRow += new InitNewRowEventHandler(OnGridViewInitNewRow); - } - - } - //程序若配置扫码框则回车换行 - if (this._detailColumns.Rows.Cast().FirstOrDefault(x => x["fieldsqltag"].ToString() == ControlType.LabSacn + "") != null) - { - this.gcMain.GridView.CellValueChanged += new CellValueChangedEventHandler(OnGridViewCellValueChanged); - } - - this.gcMain.GridControl.DataSourceChanged += OnGcMainDataSourceChanged; - } - - /// - /// 表格触发右键功能 - /// - /// - /// - private void OnAfterLinkCilkCall(object sender, EventArgs e) - { - string unioright = sender + ""; - DataRow rightrowitem = this.gcMain.gridViewRightMenu.MenuTable.Rows.Cast().FirstOrDefault(x => (x["orderid"] + "").Equals(unioright)); - CommonMenu menu = new CommonMenu(this.SysModel, ControlObj, this.gcMain); - menu.Apply(rightrowitem); - } - - /// - /// 说明:数据绑定后判断是否是右键打开模块赋值 - /// 创建人:王一帆 - /// 创建日期:2020-03-27 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - protected void OnInitializeHeaderCallBack(object sender, EventArgs e) - { - // 通过右键菜单打开单据时,判断修改还是新增 - if (!string.IsNullOrEmpty(this.SysModel.BillOrderNo)) - { - // 修改 - string sqlValue = "select * from " + this.BillModel.MasterTable + " where 1=1"; - string sqlCond = string.Format(" and {0}='{1}'", this.BillModel.PrimaryKey, this.SysModel.BillOrderNo); - DataTable masterTable = BillImpl.GetDataTableResult(sqlValue + sqlCond); - - this.SetBillStatus(masterTable.Rows.Count > 0 ? masterTable.Rows[0] : null); - } - else - { - this.SetBillStatus(null); - // 新增 - if (!string.IsNullOrEmpty(this.SysModel.BillMasterSql)) - { - // 处理单据表头数据 - DataRow row = BillImpl.GetDataRowResult(this.SysModel.BillMasterSql); - if (row != null) - { - this.ControlObj.SetAllControlValue(row);//去掉第二个参数true,参数8进入的sql固定不默认赋值 - // 设置Brp模版 - if (this.IsBrpTemplete || this.BillModel.IsBrp) - { - this.SetTempleteSelectedValue(row["brpId"] + ""); - } - } - } - if (!string.IsNullOrEmpty(this.SysModel.BillMasterSql)) - { - // 处理单据明细数据 - if (!this.SysModel.BillDetailSql.StartsWith("*")) this.AddMultiRowToGridView(BillImpl.GetDataTableResult(this.SysModel.BillDetailSql)); - } - } - } - - private void AddDataColumns() - { - foreach (GridColumn gridColumn in gcMain.GridView.Columns) - { - gridColumn.Fixed = DevExpress.XtraGrid.Columns.FixedStyle.Left; - } - int dayCount = 0; - BaseUserControl baseUserControl = ControlObj.FindControl("bom_rdm_tianshu"); - if (baseUserControl != null) - { - int.TryParse(baseUserControl.EditText, out dayCount); - } - if (dayCount <= 0) - { - dayCount = 7; - } - if (DateColumnList.Count != dayCount) - { - foreach (GridColumn item in DateColumnList) - { - gcMain.GridView.Columns.Remove(item); - } - gcMain.GridView.Columns.Remove(SumGridColumn); - DateColumnList.Clear(); - for (int i = 0; i < dayCount; i++) - { - GridColumn gridColumn = new GridColumn(); - gridColumn.AppearanceCell.Options.UseTextOptions = true; - gridColumn.AppearanceCell.TextOptions.HAlignment = HorzAlignment.Center; - gridColumn.AppearanceHeader.Options.UseTextOptions = true; - gridColumn.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center; - gridColumn.OptionsColumn.AllowMove = false; - gridColumn.OptionsColumn.AllowSize = false; - gridColumn.OptionsFilter.AllowFilter = false; - gridColumn.OptionsColumn.AllowMerge = DefaultBoolean.False; - gridColumn.OptionsColumn.AllowSort = DefaultBoolean.False; - gridColumn.FieldName = $"DDay_{i}"; - gridColumn.Width = 70; - gridColumn.DisplayFormat.FormatType = FormatType.Numeric; - gridColumn.DisplayFormat.FormatString = "{0:#,##0.####}"; - gridColumn.Visible = true; - gridColumn.SummaryItem.SummaryType = SummaryItemType.Sum; - gridColumn.SummaryItem.DisplayFormat = "{0:#,##0.####}"; - gcMain.GridView.Columns.Add(gridColumn); - DateColumnList.Add(gridColumn); - } - GridColumn sumGridColumn = new GridColumn(); - sumGridColumn.AppearanceCell.Options.UseTextOptions = true; - sumGridColumn.AppearanceCell.TextOptions.HAlignment = HorzAlignment.Center; - sumGridColumn.AppearanceHeader.Options.UseTextOptions = true; - sumGridColumn.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center; - sumGridColumn.OptionsColumn.AllowEdit = false; - sumGridColumn.OptionsColumn.AllowMove = false; - sumGridColumn.OptionsColumn.AllowSize = false; - sumGridColumn.OptionsFilter.AllowFilter = false; - sumGridColumn.OptionsColumn.AllowMerge = DefaultBoolean.False; - sumGridColumn.OptionsColumn.AllowSort = DefaultBoolean.False; - sumGridColumn.FieldName = $"workingsum"; - sumGridColumn.Caption = $"工时合计"; - sumGridColumn.Width = 70; - sumGridColumn.DisplayFormat.FormatType = FormatType.Numeric; - sumGridColumn.DisplayFormat.FormatString = "{0:#,##0.####}"; - sumGridColumn.Visible = true; - sumGridColumn.SummaryItem.SummaryType = SummaryItemType.Sum; - sumGridColumn.SummaryItem.DisplayFormat = "{0:#,##0.####}"; - SumGridColumn = sumGridColumn; - gcMain.GridView.Columns.Add(sumGridColumn); - } - } - - /// - /// 根据日期修改列状态 - /// - /// - private void UpdateDynamicColumns() - { - DateTime currentDate = DateTime.Now; - BaseUserControl dateUserControl = ControlObj.FindControl("bom_rdm_ksdt"); - if (dateUserControl is LabelDateEdit labelDateEdit) - { - currentDate = labelDateEdit.TextEdit.DateTime; - } - - int dayCount = 0; - BaseUserControl baseUserControl = ControlObj.FindControl("bom_rdm_tianshu"); - if (baseUserControl != null) - { - int.TryParse(baseUserControl.EditText, out dayCount); - } - if (dayCount <= 0) - { - dayCount = 7; - } - DateTime endDate = currentDate.AddDays(dayCount); - gcMain.GridView.BeginUpdate(); - try - { - for (int i = 0; i < DateColumnList.Count; i++) - { - GridColumn gridColumn = DateColumnList[i]; - // 当前列对应的日期 = 起始日期加 i 天 - DateTime dateForColumn = currentDate.AddDays(i); - if (dateForColumn <= endDate) - { - gridColumn.FieldName = dateForColumn.ToString("yyyy-MM-dd"); - gridColumn.Caption = dateForColumn.ToString("MM-dd"); - gridColumn.Visible = true; - gridColumn.Tag = dateForColumn; - } - else - { - gridColumn.Visible = false; - } - } - - } - finally - { - gcMain.GridView.EndUpdate(); - } - } - - /// - /// 新增汇总数据(日期修改后) - /// - private void UpdateSummaryData(DataTable table = null) - { - DataTable dataTable = new DataTable(); - if (table != null) - { - dataTable = table; - } - - if (dataTable != null && dataTable.Columns.Contains("num")) - { - MultiLineSummary = true; - gcMain.GridView.OptionsView.ShowFooter = true; - DataRow[] dataRows = dataTable.Select("num='999'"); - DataRow dataRow = dataRows != null && dataRows.Length > 0 ? dataRows[0] : null; - gcMain.AddHeadquarters(dataRow); - } - else if (MultiLineSummary) - { - MultiLineSummary = false; - //清空新加的汇总列 - gcMain.AddHeadquarters(); - } - - } - - - /// - /// 说明:表格编辑时,判断是否是否编辑 - /// 创建人:王一帆 - /// 创建日期:2020-03-27 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - protected void OnGridViewShowingEditor(object sender, CancelEventArgs e) - { - try - { - GridColumnModel gridColumnModel = null; - DataRow rowItem = null; - if (this.BillModel.DetailTreeTable) - { - DevExpress.XtraTreeList.TreeList treeList = (DevExpress.XtraTreeList.TreeList)sender; - TreeListColumn treeListColumn = treeList.FocusedColumn; - if (treeListColumn.Tag != null) - { - gridColumnModel = (GridColumnModel)treeListColumn.Tag; - } - rowItem = (this.gcMain as TreeGridControlEx).GetViewFocusedDataRow(); - } - else - { - GridView gridView = (GridView)sender; - GridColumn gridColumn = gridView.FocusedColumn; - - if (gridColumn.Tag != null) - { - gridColumnModel = (GridColumnModel)gridColumn.Tag; - } - rowItem = this.gcMain.GridView.GetDataRow(this.gcMain.GridView.FocusedRowHandle); - } - - - if (gridColumnModel != null && !string.IsNullOrEmpty(gridColumnModel.DisableCond)) - { - //e.Cancel = !ReplaceHelper.EvalCond(ReplaceHelper.ReplaceRowParam(focusedRow, gridColumnModel.DisableCond)); - //e.Cancel = !ValidateCond(gridColumnModel.DisableCond, focusedRow); - string UpdateCond = this.ControlObj.ReplaceParentControlValue(gridColumnModel.DisableCond); - UpdateCond = ReplaceHelper.ReplaceRowParam(rowItem, UpdateCond); - if (!ReplaceHelper.EvalCond(UpdateCond)) - { - e.Cancel = true;//该行不可编辑 - } - } - if (!string.IsNullOrWhiteSpace(BillModel.UpdateDetailCond)) - { - string UpdateCond = this.ControlObj.ReplaceParentControlValue(BillModel.UpdateDetailCond); - UpdateCond = ReplaceHelper.ReplaceRowParam(rowItem, UpdateCond); - if (!ReplaceHelper.EvalCond(UpdateCond)) - { - e.Cancel = true;//该行不可编辑 - } - } - } - catch (Exception ex) - { - LogHelper.Instance.WriteError(ex); - - } - - - } - - /// - /// 虚拟行点击添加 - /// - /// - private void InitNewRowMethod(object sender) - { - GridView view = sender as DevExpress.XtraGrid.Views.Grid.GridView; - DataTable gridTable = (this.gcMain.GridControl.DataSource as DataTable).TrimDeleteRows(); - DataRow tmpRow = gridTable.NewRow(); - gridTable.Rows.Add(tmpRow); - int position = gridTable.Rows.Count - 1; - foreach (DataRow dr in _detailColumns.Rows) - { - GridColumnModel model = new GridColumnModel(dr); - string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue); - - - if (model.DefaultValue.Contains("{#")) - { - fieldValue = this.ControlObj.ReplaceParentControlValue(model.DefaultValue); - if (!string.IsNullOrEmpty(fieldValue)) - { - tmpRow[model.FieldName] = fieldValue; - } - } - else if (!string.IsNullOrEmpty(model.DefaultValue)) - { - if (model.DefaultValue.Contains("{ROW")) - { - if (position > 0) - { - - fieldValue = ReplaceHelper.GetParamFields(model.DefaultValue)[0]; - fieldValue = fieldValue.Replace("}", "").Replace("{", ""); - fieldValue = fieldValue.Substring(fieldValue.IndexOf('_') + 1); - string topFieldValue = gridTable.Rows[position - 1][fieldValue] + ""; - if (gridTable.Columns[model.FieldName].DataType == typeof(DateTime)) - { - if (!string.IsNullOrEmpty(topFieldValue)) tmpRow[model.FieldName] = Convert.ToDateTime(topFieldValue); - } - else - { - tmpRow[model.FieldName] = topFieldValue; - } - } - } - else - { - tmpRow[model.FieldName] = fieldValue; - } - } - } - gridTable.OrderBy(this.BillModel.DetailOrderField); - - if (tmpRow.Table.Columns.Contains(this.BillModel.DetailOrderField) && gridTable.Rows.Count == 0) - { - tmpRow[this.BillModel.DetailOrderField] = 1; - } - - this.gcMain.GridView.UpdateCurrentRow(); - this.gcMain.GridView.ShowEditor(); - } - /// - /// 切换行判断是否是虚拟行数据进行数据填充 - /// - /// - /// - private void GridView_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e) - { - DataTable gridTable = (this.gcMain.GridControl.DataSource as DataTable).TrimDeleteRows(); - int _rowNumber = this.gcMain.GridView.FocusedRowHandle; - int _prvFocused = e.PrevFocusedRowHandle; - int indexNumber = this.gcMain.GridView.RowCount; - if (_rowNumber < 0 && _prvFocused != gridTable.Rows.Count) - { - InitNewRowMethod(sender); - this.gcMain.GridView.FocusedRowHandle = indexNumber - 1; - } - } - /// - /// 说明:单据重写明细回车事件(用于扫码回车移动至下一行数据) - /// 创建人:王一帆 - /// 创建日期:2021-06-08 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The sender. - /// The instance containing the event data. - protected void OnGridViewCellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) - { - if (isDragWrap) - { - int _rowNumber = this.gcMain.GridView.FocusedRowHandle; - GridColumn focusColumn = this.gcMain.GridView.FocusedColumn; - GridColumnModel Columnmodel = focusColumn.Tag as GridColumnModel; - - if (Columnmodel.FieldType == ControlType.LabSacn) - { - this.gcMain.GridView.OptionsNavigation.EnterMoveNextColumn = false; - if (this.BillModel.DefaultAddEmptyRow && _rowNumber + 1 == this.gcMain.GridView.DataRowCount) - { - DataTable gridTable = (this.gcMain.GridView.GridControl.DataSource as DataTable).TrimDeleteRows(); - DataRow tmpRow = gridTable.NewRow(); - gridTable.Rows.Add(tmpRow); - int position = gridTable.Rows.Count - 1; - foreach (DataRow dr in _detailColumns.Rows) - { - GridColumnModel model = new GridColumnModel(dr); - string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue); - if (model.DefaultValue.Contains("{#")) - { - fieldValue = this.ControlObj.ReplaceParentControlValue(model.DefaultValue); - if (!string.IsNullOrEmpty(fieldValue)) - { - tmpRow[model.FieldName] = fieldValue; - } - } - else if (!string.IsNullOrEmpty(model.DefaultValue)) - { - if (model.DefaultValue.Contains("{ROW")) - { - if (position > 0) - { - - fieldValue = ReplaceHelper.GetParamFields(model.DefaultValue)[0]; - fieldValue = fieldValue.Replace("}", "").Replace("{", ""); - fieldValue = fieldValue.Substring(fieldValue.IndexOf('_') + 1); - string topFieldValue = gridTable.Rows[position - 1][fieldValue] + ""; - if (gridTable.Columns[model.FieldName].DataType == typeof(DateTime)) - { - if (!string.IsNullOrEmpty(topFieldValue)) tmpRow[model.FieldName] = Convert.ToDateTime(topFieldValue); - } - else - { - tmpRow[model.FieldName] = topFieldValue; - } - } - } - else - { - tmpRow[model.FieldName] = fieldValue; - } - } - } - gridTable.OrderBy(this.BillModel.DetailOrderField); - - if (tmpRow.Table.Columns.Contains(this.BillModel.DetailOrderField) && gridTable.Rows.Count == 0) - { - tmpRow[this.BillModel.DetailOrderField] = 1; - } - - this.gcMain.GridView.UpdateCurrentRow(); - this.gcMain.GridView.ShowEditor(); - } - int ColumnIndex = this.gcMain.GridView.FocusedColumn.VisibleIndex;//焦点列的坐标 - this.gcMain.GridView.FocusedRowHandle = _rowNumber + 1; - this.gcMain.GridView.FocusedColumn.VisibleIndex = ColumnIndex; - //this.gridView.OptionsNavigation.EnterMoveNextColumn = true; - } - else - { - this.gcMain.GridView.OptionsNavigation.EnterMoveNextColumn = true; - } - } - } - /// - /// 点击第一个默认新增行新增默认数据 - /// - /// - /// - private void GridView_MouseDown(object sender, MouseEventArgs e) - { - - } - - - - - /// - /// 说明:验证单据是否修改过 - /// 创建人:龚宇超 - /// 创建日期: - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - private void VerfyBillUpdated() - { - bool isUpdateDetailed = false; - DataTable table = this.gcMain.gridControl.DataSource as DataTable; - if (table != null && table.Rows.Count > 0) - { - DataRow updateRow = table.Rows.Cast().FirstOrDefault(x => x.RowState != DataRowState.Unchanged); - isUpdateDetailed = updateRow != null; - } - if (this.BillRowItem != null && (this.ControlObj.VerifyUpdated() || isUpdateDetailed)) - { - bool isReadOnly2 = !string.IsNullOrEmpty(this.BillModel.ModifyCond) && !ReplaceHelper.ReplaceRowParamCond(this.BillRowItem, this.BillModel.ModifyCond); - if (!isReadOnly2) - { - if (MessageUtil.Show(ResourceKeys.DataChanged, MessageBoxButtons.YesNo) == DialogResult.Yes) - { - this.BillSave(); - } - } - } - } - - /// - /// 说明:初始化单据按钮状态 - /// 创建人:龚宇超 - /// 创建日期:2017-12-04 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// if set to true [is edit]. - private void SetBillStatus(DataRow rowItem) - { - if (this.BillModel.unableToSave.Contains(SysModel.UserName)) - { - this.btnBillSave.Hide(); - foreach (System.Windows.Forms.Control control in pl_main_bottom.Controls) - { - - if (control.Location.X < btnBillSave.Location.X && control is DevExpress.XtraEditors.SimpleButton && control.Name != "btn_input") - { - control.Location = new Point(control.Location.X + btnBillSave.Width, control.Location.Y); - } - } - } - if (rowItem != null) - { - gridExModel.MaintabFocusedRow = rowItem; - gridEx.ObjPanel.Enabled = true; - // 单据为修改状态,无需设置赋值时不需要计算面板属性 - bool isReadOnly = !string.IsNullOrEmpty(this.BillModel.ModifyCond) && !ReplaceHelper.ReplaceRowParamCond(rowItem, this.BillModel.ModifyCond); - this.ControlObj.CanExecControl = false; // 单据为修改状态时,无需计算面板属性 - this.lbTitle.Text = this.BillModel.TypeName + "(修改)"; - this.lblOrderNo.Text = rowItem[this.BillModel.PrimaryKey] + ""; - this.rdBlue.Checked = "0".Equals(rowItem[this.BillModel.RtagidKey] + ""); - this.rdRed.Checked = "1".Equals(rowItem[this.BillModel.RtagidKey] + ""); - this.BillModel.SaveState = true; - this.rdBlue.Enabled = this.rdRed.Enabled = false; - this._itemImport.Enabled = this._itemImportUpdate.Enabled = !isReadOnly; - this.ControlObj.SetReadOnlyAllControl(isReadOnly); - this.ControlObj.SetAllControlValue(rowItem); - this.btnDelete.Enabled = this.btnBillSave.Enabled = this.btnBillApply.Enabled = !isReadOnly; - this.ControlObj.CanExecControl = true; - this.cb_input.Enabled = this.btn_input.Enabled = this.txt_input.Enabled = !isReadOnly; - this.SetButtonStatus(rowItem); - //if (this.itemCommon.Visible == true && this.itemCommon.Tag is DataRow rightRow) - //{ - // string menuCode = rightRow["menuCond"] + ""; - // if (!string.IsNullOrEmpty(menuCode)) - // { - // this.itemCommon.Enabled = ValidateCond(menuCode, rowItem); ; - // } - //} - this.BillRowItem = rowItem; - // 设置Brp模版 - if (this.IsBrpTemplete || this.BillModel.IsBrp) - { - this.SetTempleteSelectedValue(rowItem["brpId"] + ""); - this.cb_templete.Enabled = !isReadOnly; - } - this.BillModel.PopupUnionCode = rdBlue.Checked ? rdBlueUnionCode : rdRedUnionCode; - this.labelControl1.ForeColor = this.lblOrderNo.ForeColor = this.lbTitle.ForeColor = rdBlue.Checked ? Color.Blue : Color.Red; - this.gcMain.GridView.OptionsBehavior.Editable = !isReadOnly; - - // 上一次查询 - int oldRowHandle = this.gcMain.GridView.FocusedRowHandle; - //获取数据源并排序 - DataTable dt = BillImpl.GetDataTableResult(ReplaceHelper.ReplaceRowParam(rowItem, this.BillModel.DetailSql)); - if (dt.Columns.Contains(this.BillModel.DetailOrderField)) - { - DataView dataView = dt.AsDataView(); - dataView.Sort = this.BillModel.DetailOrderField; - dt = dataView.ToTable(); - dt.AcceptChanges(); - } - - if (this.BillModel.DetailTreeTable) - { - //判断是否有tap_id和tap_pid - (this.gcMain as TreeGridControlEx).SetGridViewDataSourceGenerateID(dt); - this.gcMain.GridView.SelectRowHandler(oldRowHandle); - } - else - { - this.gcMain.GridControl.DataSource = dt; - this.gcMain.GridView.SelectRowHandler(oldRowHandle); - if (this.BillModel.SelectLast && dt.Rows.Count > 0) - { - this.gcMain.GridView.SelectRowHandler(dt.Rows.Count - 1); - } - } - - - RefreshPrindMenu(); - - BaseUserControl userControl = this.ControlObj.FindControl(this.BillModel.RtagidKey); - if (userControl != null) - { - userControl.EditText = this.rdRed.Checked ? "1" : "0"; - } - string gridExSql = this.gridEx.SysModel.MenuSql; - gridExSql = ReplaceHelper.ReplaceRowParam(rowItem, gridExSql); - this.gridEx.GridControlObj.LastSearchSql = gridExSql; - this.gridEx.GridControlObj.SetGridViewDataSource(BaseImpl.GetDataTableResult(gridExSql)); - } - else - { - gridExModel.MaintabFocusedRow = null; - gridEx.ObjPanel.Enabled = false; - // 单据为新增状态 - this.btnDelete.Enabled = this.btnBillSave.Enabled = this.btnBillApply.Enabled = true; - this.lbTitle.Text = this.BillModel.TypeName + "(新增)"; - this.lblOrderNo.Text = BillImpl.GetBillNo(this.BillModel.BillSeq); - this._itemImport.Enabled = this._itemImportUpdate.Enabled = true; - this.cb_input.Enabled = this.btn_input.Enabled = this.txt_input.Enabled = true; - this.cb_templete.Enabled = true; - this.BillModel.SaveState = false; - this.ControlObj.SetReadOnlyAllControl(false); - this.rdBlue.Enabled = this.rdRed.Enabled = true; - this.SetButtonStatus(); - //if (this.itemCommon.Visible == true && this.itemCommon.Tag is DataRow rightRow) - //{ - // string menuCode = rightRow["menuCond"] + ""; - // if (!string.IsNullOrEmpty(menuCode)) - // { - // this.itemCommon.Enabled = ValidateCond(menuCode, rowItem); ; - // } - //} - // 通过右键菜单打开单据,假如明细有数据则在初始化时使用传入数据. - if (this.BillModel.DetailTreeTable) - { - (this.gcMain as TreeGridControlEx).TreeListObj.OptionsBehavior.Editable = true; - (this.gcMain as TreeGridControlEx).SetGridViewDataSourceGenerateID(BillImpl.GetDataTableResult(this.BillModel.DetailSql)); - } - else - { - this.gcMain.GridView.OptionsBehavior.Editable = true; - this.gcMain.GridControl.DataSource = BillImpl.GetDataTableResult(this.BillModel.DetailSql); - } - - BaseUserControl userControl = this.ControlObj.FindControl(this.BillModel.RtagidKey); - if (userControl != null) - { - userControl.EditText = this.rdRed.Checked ? "1" : "0"; - } - this.gridEx.GridControlObj.LastSearchSql = this.gridEx.SysModel.MenuSql; - this.gridEx.GridControlObj.SetGridViewDataSource(new DataTable()); - } - - this._waterMark = new WaterMark(this.BillModel.MasterPreFix, rowItem); - this.lbTitle.Invalidate(); - - } - #endregion - - #region 切换红、蓝字单据 - /// - /// 说明:点击蓝字单据 - /// 创建人:龚宇超 - /// 创建日期:2017-11-23 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - private void OnBlueStateClick(object sender, EventArgs e) - { - this.rdRed.Checked = false; - this.labelControl1.ForeColor = this.lblOrderNo.ForeColor = this.lbTitle.ForeColor = Color.Blue; - this.BillModel.PopupUnionCode = rdBlueUnionCode; - - BaseUserControl userControl = this.ControlObj.FindControl(this.BillModel.RtagidKey); - if (userControl != null) - { - userControl.EditText = "0"; - } - } - /// - /// 说明:点击红字单据 - /// 创建人:龚宇超 - /// 创建日期:2017-11-23 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - private void OnRedStateClick(object sender, EventArgs e) - { - this.rdBlue.Checked = false; - this.labelControl1.ForeColor = this.lblOrderNo.ForeColor = this.lbTitle.ForeColor = Color.Red; - this.BillModel.PopupUnionCode = rdRedUnionCode; - - BaseUserControl userControl = this.ControlObj.FindControl(this.BillModel.RtagidKey); - if (userControl != null) - { - userControl.EditText = "1"; - } - } - #endregion - - #region 复制单据 - /// - /// 说明:复制表头数据 - /// 创建人:龚宇超 - /// 创建日期:2017-11-27 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - protected void OnCopyMasterItemClick(object sender, ItemClickEventArgs e) - { - this.btnDelete.Enabled = this.btnBillSave.Enabled = this.btnBillApply.Enabled = true; - this.lbTitle.Text = this.BillModel.TypeName + "(新增)"; - this.lbTitle.Invalidate(); - this.lblOrderNo.Text = BillImpl.GetBillNo(this.BillModel.BillSeq); - this.BillModel.SaveState = false; - this.rdBlue.Enabled = this.rdRed.Enabled = true; - this.cb_input.Enabled = this.btn_input.Enabled = this.txt_input.Enabled = true; - this._itemImport.Enabled = this._itemImportUpdate.Enabled = true; - this.cb_templete.Enabled = true; - this.ControlObj.CopyControlValue(); - this.ControlObj.SetReadOnlyAllControl(false); - - if (this.BillModel.DetailTreeTable) - { - ((this.gcMain as TreeGridControlEx).TreeListObj.DataSource as DataTable).Clear(); - (this.gcMain as TreeGridControlEx).TreeListObj.OptionsBehavior.Editable = true; - } - else - { - this.gcMain.GridControl.DataSourceTable().Clear(); - this.gcMain.GridView.OptionsBehavior.Editable = true; - - } - - - this._waterMark = new WaterMark(this.BillModel.MasterPreFix, null); - } - /// - /// 说明:复制整单 - /// 创建人:龚宇超 - /// 创建日期:2017-11-27 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - protected void OnCopyAllItemClick(object sender, ItemClickEventArgs e) - { - try - { - WaitForm.ShowForm(ResourceKeys.Handing); - DataTable gridTable = (this.gcMain.GridControl.DataSource as DataTable).TrimDeleteRows(); - if (this.BillModel.DetailTreeTable) - { - gridTable = ((this.gcMain as TreeGridControlEx).TreeListObj.DataSource as DataTable).TrimDeleteRows(); - } - this.btnDelete.Enabled = this.btnBillSave.Enabled = this.btnBillApply.Enabled = true; - this.lbTitle.Text = this.BillModel.TypeName + "(新增)"; - this.lbTitle.Invalidate(); - this.lblOrderNo.Text = BillImpl.GetBillNo(this.BillModel.BillSeq); - this.rdBlue.Enabled = this.rdRed.Enabled = true; - this.cb_input.Enabled = this.btn_input.Enabled = this.txt_input.Enabled = true; - this._itemImport.Enabled = this._itemImportUpdate.Enabled = true; - this.cb_templete.Enabled = true; - this.ControlObj.CopyControlValue(); - this.ControlObj.SetReadOnlyAllControl(false); - this._waterMark = new WaterMark(this.BillModel.MasterPreFix, null); - if (!gridTable.Columns.Contains(ERPInfo.Instance.isAddRows)) - { - gridTable.Columns.Add(ERPInfo.Instance.isAddRows, typeof(String)); - } - // 处理单据明细 - DataTable detailTable = this.gcMain.GridControl.DataSourceTable(); - if (this.BillModel.DetailTreeTable) - { - detailTable = (this.gcMain as TreeGridControlEx).GetGridViewDataSource(); - } - bool canCopy = false; - string defaultValue = string.Empty; - - - if (this.BillModel.DetailTreeTable) - { - if (detailTable.Columns.Contains(this.BillModel.PrimaryDetailKey)) - { - (this.gcMain as TreeGridControlEx).TreeListObj.BeginUpdate(); - foreach (TreeListNode item in (this.gcMain as TreeGridControlEx).TreeListObj.Nodes) - { - //根据后台列配置可否复制 - if (_detailColumns.Columns.Contains("canCopy")) - { - //int index = detailTable.Rows.IndexOf(item); - foreach (DataRow dr in _detailColumns.Rows) - { - canCopy = !string.IsNullOrEmpty(dr["canCopy"] + "") ? "1".Equals(dr["canCopy"] + "") : false; - if (!canCopy) - { - TreeListColumn column = (this.gcMain as TreeGridControlEx).TreeListObj.Columns.ColumnByFieldName(dr["fieldName"] + ""); - //TreeListNode node = treeList.GetNode(rowIndex); - defaultValue = this.ControlObj.ReplaceParentControlValue(dr["defaultdate"] + ""); - defaultValue = BaseImpl.GetDefaultValue(defaultValue); - if (!string.IsNullOrEmpty(defaultValue)) - { - item.SetValue(column, defaultValue); - } - else - { - item.SetValue(column, DBNull.Value); - } - } - } - } - item[this.BillModel.PrimaryDetailKey] = this.lblOrderNo.Text; - } - (this.gcMain as TreeGridControlEx).TreeListObj.EndUpdate(); - } - (this.gcMain as TreeGridControlEx).TreeListObj.OptionsBehavior.Editable = true; - this.BillModel.SaveState = false; - } - else - { - if (detailTable.Columns.Contains(this.BillModel.PrimaryDetailKey)) - { - this.gcMain.GridView.BeginUpdate(); - foreach (DataRow item in detailTable.Rows) - { - //根据后台列配置可否复制 - if (_detailColumns.Columns.Contains("canCopy")) - { - int index = detailTable.Rows.IndexOf(item); - foreach (DataRow dr in _detailColumns.Rows) - { - canCopy = !string.IsNullOrEmpty(dr["canCopy"] + "") ? "1".Equals(dr["canCopy"] + "") : false; - if (!canCopy) - { - GridColumn column = this.gcMain.GridView.Columns.ColumnByFieldName(dr["fieldName"] + ""); - defaultValue = this.ControlObj.ReplaceParentControlValue(dr["defaultdate"] + ""); - defaultValue = BaseImpl.GetDefaultValue(defaultValue); - if (!string.IsNullOrEmpty(defaultValue)) - { - this.gcMain.GridView.SetRowCellValue(index, column, defaultValue); - } - else - { - this.gcMain.GridView.SetRowCellValue(index, column, DBNull.Value); - } - } - } - } - item[this.BillModel.PrimaryDetailKey] = this.lblOrderNo.Text; - } - this.gcMain.GridView.EndUpdate(); - } - this.gcMain.GridView.OptionsBehavior.Editable = true; - this.BillModel.SaveState = false; - } - - - } - catch (Exception ex) - { - - } - finally - { - WaitForm.HideForm(); - } - } - #endregion - - #region Excel操作 - /// - /// 说明:导出Excel - /// 创建人:龚宇超 - /// 创建日期:2017-11-27 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - protected void OnExportItemClick(object sender, ItemClickEventArgs e) - { - LogUtil.WriteDebug(this.SysModel.ModuleCode, "导出数据", this.SysModel.FormText, "单据明细导出", this.SysModel.ModuleId + ""); - - - if (this.BillModel.DetailTreeTable) - { - (this.gcMain as TreeGridControlEx).TreeListObj.ToTreeExcel(this.SysModel.FormText); - } - else - { - this.gcMain.GridControl.ToExcel(this.SysModel.FormText); - } - - - } - /// - /// 说明:从Excel导入 - /// 创建人:龚宇超 - /// 创建日期:2017-11-27 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - protected void OnImportItemClick(object sender, ItemClickEventArgs e) - { - OpenFileDialog dialog = new OpenFileDialog(); - dialog.Title = "选择导入文件"; - //dialog.Filter = "Excel文件(*.xls)|*.xls"; - dialog.Filter = SystemInfo.Instance.IsXlsxFirst ? "Excel文件(*.xlsx)|*.xlsx|Excel文件(*.xls)|*.xls" : - "Excel文件(*.xls)|*.xls|Excel文件(*.xlsx)|*.xlsx"; - - DialogResult result = dialog.ShowDialog(); - if (result == DialogResult.OK) - { - string fileName = dialog.FileName; - string colFields = this.gcMain.GridView.Columns.ToString(','); - - if (this.BillModel.DetailTreeTable) - { - DataTable DataImportTable = (this.gcMain as TreeGridControlEx).TreeListObj.ToExcelTreeDataTable(fileName, colFields, true, true); - DataTable NewTable = (this.gcMain as TreeGridControlEx).GetGridViewDataSource(); - TreeListColumnCollection gridColumns = (this.gcMain as TreeGridControlEx).TreeListObj.Columns; - //父节点名称 - string ParentFieldName = (this.gcMain as TreeGridControlEx).TreeListObj.ParentFieldName; - //节点名称 - string KeyFieldName = (this.gcMain as TreeGridControlEx).TreeListObj.KeyFieldName; - - if (!DataImportTable.Columns.Contains(ParentFieldName)) DataImportTable.Columns.Add(ParentFieldName); - if (!DataImportTable.Columns.Contains(KeyFieldName)) DataImportTable.Columns.Add(KeyFieldName); - - DragAddTable(DataImportTable, "0"); - } - else - { - DataTable DataImportTable = this.gcMain.GridView.ToExcelDataTable(fileName, colFields, true, true); - DataTable NewTable = this.gcMain.GridControl.DataSourceTable(); - GridColumnCollection gridColumns = this.gcMain.GridView.Columns; - foreach (DataRow rowItem in DataImportTable.Rows) - { - DataRow newRow = NewTable.NewRow(); - foreach (GridColumn col in gridColumns) - { - if ("id".Equals(col.FieldName) || col.FieldName.Equals(this.BillModel.PrimaryKey)) continue; - if (rowItem.Table.Columns.Contains(col.FieldName)) - { - // 列中是否包含对应字段,包含则使用值 - newRow[col.FieldName] = rowItem[col.FieldName]; - } - else - { - // 未包含字段,则使用控件默认值. - GridColumnModel model = col.Tag as GridColumnModel; - string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue); - if (model.DefaultValue.Contains("{#")) - { - fieldValue = this.ControlObj.ReplaceParentControlValue(model.DefaultValue); - - } - if (!string.IsNullOrEmpty(fieldValue)) - { - newRow[col.FieldName] = fieldValue; - } - } - } - NewTable.Rows.Add(newRow); - } - this.gcMain.GridControl.DataSource = NewTable; - } - - - } - } - /// - /// 说明:导入Excel文件(更新) - /// 创建人:龚宇超 - /// 创建日期:2017-11-27 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - protected void OnImportUpdateItemClick(object sender, ItemClickEventArgs e) - { - - } - #endregion - - #region 常用工具 - /// - /// 说明:验证可操作条件 - /// 创建人:龚宇超 - /// 创建日期:2018-03-07 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - protected void OnToolsClick(object sender, EventArgs e) - { - foreach (BarItemLink itemLink in pMenu.ItemLinks) - { - DataRow rowItem = itemLink.Item.Tag as DataRow; - if (rowItem != null) - { - string menuCond = rowItem["MenuCond"] + ""; - string menuCaption = itemLink.Caption; - - if (!string.IsNullOrEmpty(menuCond)) - { - try - { - bool result = true; - menuCond = ReplaceHelper.ReplaceParamToValue(menuCond, "{" + this.BillModel.PrimaryKey + "}", this.lblOrderNo.Text.Trim()); - - if (menuCond.StartsWith("@") || menuCond.StartsWith("!")) - { - result = "1".Equals(BaseImpl.GetDefaultValue(menuCond)); - } - else - { - menuCond = this.ControlObj.ReplaceControlValue(menuCond); - if (this.BillRowItem != null) - menuCond = ReplaceHelper.ReplaceRowParam(this.BillRowItem, menuCond); - menuCond = ReplaceHelper.ReplaceParamToValue(menuCond, "0"); // 未替换的参数所有替换为0 - - result = ReplaceHelper.EvalCond(menuCond); - } - itemLink.Item.Enabled = result; - } - catch (Exception ex) - { - MessageUtil.Show("[" + menuCaption + "] " + ResourceKeys.SetRightMenuCondFault); - LogHelper.Instance.WriteError(ex); - } - } - } - } - } - /// - /// 说明:常用工具点击 - /// 创建人:龚宇超 - /// 创建日期:2017-11-27 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - protected void OnCommonItemClick(object sender, ItemClickEventArgs e) - { - DataRow rowItem = e.Item.Tag as DataRow; - - CommonMenu menu = new CommonMenu(this.SysModel, this.ControlObj, null); - menu.ApplyBefore += new CommonToolApplyEventHandler(OnMenuApplyBefore); - menu.DynamicLinkAfter += new CommonToolAfterDynamicLinkEventHandler(OnDynamicLinkAfter); - menu.Apply(rowItem); - } - /// - /// 说明:执行前单独替换BilldocumentId - /// 创建人:龚宇超 - /// 创建日期:2018-03-07 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The e. - protected void OnMenuApplyBefore(ApplyArgs e) - { - string[] paramList = new string[e.MemuModel.ParamList.Count]; - - for (int i = 0; i < e.MemuModel.ParamList.Count; i++) - { - string item = e.MemuModel.ParamList[i]; - List condition = ReplaceHelper.GetParamFields(item); - foreach (string cond in condition) - { - string value = this.BillModel.PrimaryKey.Equals(cond.Replace("{", "").Replace("}", "").ToLower(), StringComparison.OrdinalIgnoreCase) ? this.lblOrderNo.Text.Trim() : cond; - item = item.Replace(cond, value); ; - } - paramList[i] = item; - } - e.MemuModel.ParamList = paramList.ToList(); - } - /// - /// 动态链接库执行完成后 - /// - /// - protected void OnDynamicLinkAfter(object sender, ApplyArgs e) - { - try - { - if (!string.IsNullOrWhiteSpace(e.MemuModel.ResultSQL)) - { - string resultSql = e.MemuModel.ResultSQL; - if (e.DialogModel != null && e.DialogModel.DialogDllName.Equals("lskj.pubadd.dll", StringComparison.OrdinalIgnoreCase) && e.DialogModel.PubDialogType == DialogType.PubAddRecord) - { - if (e.DialogModel.ReturnTag != null && e.DialogModel.ReturnTag is MyControl) - { - MyControl addControlObj = e.DialogModel.ReturnTag as MyControl; - resultSql = addControlObj.ReplaceControlValue(resultSql); - } - resultSql = this.ControlObj.ReplaceControlValue(resultSql); - DataTable dataTable = MainImpl.GetDataTableResult(resultSql); - foreach (DataRow item in dataTable.Rows) - { - this.AddRowToGridView(item); - } - } - else - { - resultSql = this.ControlObj.ReplaceControlValue(resultSql); - DataTable dataTable = MainImpl.GetDataTableResult(resultSql); - foreach (DataRow item in dataTable.Rows) - { - this.AddRowToGridView(item, false); - } - } - } - if (e.DialogModel != null && e.DialogModel.DialogDllName.Equals("Lskj.PubBomImport.dll", StringComparison.OrdinalIgnoreCase)) - { - if (e.DialogModel.ReturnTag != null && e.DialogModel.ReturnTag is BomImpRtnModel impRtnModel) - { - if (impRtnModel.ShowType.Equals("1") || impRtnModel.ShowType.Equals("2") || impRtnModel.ShowType.Equals("3") || impRtnModel.ShowType.Equals("5") || impRtnModel.ShowType.Equals("6") || impRtnModel.ShowType.Equals("7") || impRtnModel.ShowType.Equals("8") || impRtnModel.ShowType.Equals("9"))//执行保存 - { - CommonMenu menu = (CommonMenu)sender; - menu.issuccess = impRtnModel.CanSave; - } - else if (impRtnModel.ShowType.Equals("0") || impRtnModel.ShowType.Equals("00") || impRtnModel.ShowType.Equals("000"))//返回文件 - { - ControlModel controlModel = ControlObj.ControlModels.Where(n => n.LabelText.Equals("物料编码")).FirstOrDefault(); - if (controlModel == null) - { - MessageUtil.Show($"物料编码不存在"); - return; - } - string mxProductId = ControlObj.GetControlValue(controlModel); - if (string.IsNullOrEmpty(mxProductId)) - { - MessageUtil.Show($"物料编码必填"); - return; - } - ControlModel modeControlModel = ControlObj.ControlModels.Where(n => n.LabelText.Equals("上传模式")).FirstOrDefault(); - string addMode = ControlObj.GetControlValue(modeControlModel); - if (impRtnModel.ShowType.Equals("1") && string.IsNullOrEmpty(addMode)) - { - MessageUtil.Show($"上传模式必填"); - return; - } - ControlModel sepciesNoControlModel = ControlObj.ControlModels.Where(n => n.LabelText.Equals("文件分类")).FirstOrDefault(); - string sepciesNo = ControlObj.GetControlValue(sepciesNoControlModel); - if ((impRtnModel.ShowType.Equals("1") || impRtnModel.ShowType.Equals("6")) && string.IsNullOrEmpty(sepciesNo)) - { - MessageUtil.Show($"文件分类必填"); - return; - } - ControlModel fileIDControlModel = ControlObj.ControlModels.Where(n => n.LabelText.Equals("文件ID")).FirstOrDefault(); - string fileID = ControlObj.GetControlValue(fileIDControlModel); - ControlModel oldPIDControlModel = ControlObj.ControlModels.Where(n => n.LabelText.Equals("旧编码")).FirstOrDefault(); - string oldPID = ControlObj.GetControlValue(oldPIDControlModel); - DataTable sourceTable = gcMain.gridControl.DataSourceTable(); - if (impRtnModel.ShowType.Equals("000") && sourceTable.Rows.Cast().Where(n => n.RowState != DataRowState.Deleted).Count() > 0) - { - MessageUtil.Show($"只能选择单个文件,请删除后再添加"); - return; - } - if (sourceTable != null && impRtnModel.FileNames != null) - { - string afterBomFieldName = impRtnModel.AfterBomFieldName; - if (!sourceTable.Columns.Contains("BomFieldNameDir")) - { - sourceTable.Columns.Add("BomFieldNameDir"); - } - if (!sourceTable.Columns.Contains("BomFieldNamePath")) - { - sourceTable.Columns.Add("BomFieldNamePath"); - } - if (!sourceTable.Columns.Contains("BomMxMainProduct")) - { - sourceTable.Columns.Add("BomMxMainProduct"); - } - if (!sourceTable.Columns.Contains("BomMxAddState")) - { - sourceTable.Columns.Add("BomMxAddState"); - } - if (!sourceTable.Columns.Contains("qms_laddf_mode")) - { - sourceTable.Columns.Add("qms_laddf_mode"); - } - if (!sourceTable.Columns.Contains("BomAddSpeciesNo")) - { - sourceTable.Columns.Add("BomAddSpeciesNo"); - } - if (!sourceTable.Columns.Contains("BomAddChangeFileId")) - { - sourceTable.Columns.Add("BomAddChangeFileId"); - } - if (!sourceTable.Columns.Contains("BomAddOldProductId")) - { - sourceTable.Columns.Add("BomAddOldProductId"); - } - DataTable dataTable = new DataTable(); - dataTable.Columns.Add(afterBomFieldName); - dataTable.Columns.Add("BomFieldNameDir"); - dataTable.Columns.Add("BomFieldNamePath"); - dataTable.Columns.Add("BomMxMainProduct"); - dataTable.Columns.Add("BomMxAddState"); - dataTable.Columns.Add("qms_laddf_mode"); - dataTable.Columns.Add("BomAddSpeciesNo"); - dataTable.Columns.Add("BomAddChangeFileId"); - dataTable.Columns.Add("BomAddOldProductId"); - IEnumerable rowsIEnumerable = sourceTable.Rows.Cast().Where(n => n.RowState != DataRowState.Deleted); - foreach (string fileName in impRtnModel.FileNames) - { - string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName).Trim(); - //找到code相同的行 - DataRow selectRow = rowsIEnumerable.Where(n => (n[afterBomFieldName] + "").Trim().Equals(fileNameWithoutExtension, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); - if (selectRow != null) - { - //MessageUtil.Show($"{fileNameWithoutExtension}已存在,不允许重复创建"); - continue; - } - //DataRow productRow = BaseImpl.GetDataRowResult($"select top 1 billdocument_id from bom_BillTab where productid like '{code}%'"); - //if (productRow != null) - //{ - // MessageUtil.Show($"{code}已存在,不允许重复创建"); - // return; - //} - DataRow addRow = dataTable.NewRow(); - addRow[afterBomFieldName] = Path.GetFileName(fileName); - addRow["BomFieldNameDir"] = fileName; - addRow["BomFieldNamePath"] = Path.GetFileName(fileName); - addRow["BomMxMainProduct"] = mxProductId; - addRow["qms_laddf_mode"] = addMode; - addRow["BomAddSpeciesNo"] = sepciesNo; - addRow["BomAddChangeFileId"] = fileID; - addRow["BomAddOldProductId"] = oldPID; - addRow["BomMxAddState"] = this.BillModel.SaveState ? "修改" : "新增"; - dataTable.Rows.Add(addRow); - } - foreach (DataRow item in dataTable.Rows) - { - DataRow sourceRow = this.AddRowToGridView(item, true); - sourceRow["BomFieldNameDir"] = item["BomFieldNameDir"] + ""; - sourceRow["BomFieldNamePath"] = item["BomFieldNamePath"] + ""; - sourceRow["BomMxMainProduct"] = item["BomMxMainProduct"] + ""; - sourceRow["BomMxAddState"] = item["BomMxAddState"] + ""; - sourceRow["qms_laddf_mode"] = item["qms_laddf_mode"] + ""; - sourceRow["BomAddSpeciesNo"] = item["BomAddSpeciesNo"] + ""; - sourceRow["BomAddChangeFileId"] = item["BomAddChangeFileId"] + ""; - sourceRow["BomAddOldProductId"] = item["BomAddOldProductId"] + ""; - } - } - } - } - } - string movepage = (this.ControlObj.ReplaceControlValue("{qms_maddf_addMode}").Equals("6")) ? "-9998" : "-9999"; - } - catch (Exception) - { - } - } - #endregion - - #region 打印模版 - /// - /// 说明:打印完成需要参数 - /// 创建人:龚宇超 - /// 创建日期:2018-07-09 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - protected void GetPrintOtherParam() - { - Dictionary dataCaches = SysModel != null ? SysModel.DataCaches : null; - //取得打印完成后的参数 - if (!string.IsNullOrEmpty(this.BillModel.PrintSql) && this.BillModel.PrintSql.Contains("<<")) - { - string[] strs = this.BillModel.PrintSql.Split(new[] { ">>" }, 2, StringSplitOptions.None); - _mainPrintSql = strs[1]; - _printModeCond = strs[0].Replace("<<", ""); - } - if (!string.IsNullOrEmpty(_printModeCond) && _printModeCond.IndexOf(';') > 0) - { - string[] str = _printModeCond.Split(';'); - if (!dataCaches.GetValue(this, "PrintOtherSystemRow", out DataRow item)) - { - item = AttachImpl.GetSystemModule(str[0]); - } - if (item == null) return; - string tableName = item["TableName"] + ""; - string modetype = item["modType"] + ""; - if (!dataCaches.GetValue(this, "PrintOtherColumnPrefix", out string comprefix)) - { - comprefix = BaseImpl.GetColumnPrefix(tableName); - } - if (!dataCaches.GetValue(this, "PrintOtherPrimaryKey", out string primaryKey)) - { - primaryKey = modetype == "1" ? BaseImpl.GetBasePrimaryKey(str[0]) : comprefix + "billdocument_id"; - } - //表名,列前缀,主键字段,主键值,模块编号,主打印Sql - _printSaveParams = new List() { tableName, comprefix, primaryKey, str[1], str[0], _mainPrintSql }; - - //判断是否直接打印 modetype 区别单据和基础档案模块 - if (!dataCaches.GetValue(this, "PrintOtherIsExcPrint", out _isExcPrint)) - { - switch (modetype) - { - case "1": - ModuleModel mode = new ModuleModel(MainImpl.GetSystemdllTab(str[0])); - if (mode != null) _isExcPrint = mode.PrintType == 3; - break; - case "2": - BaseAccraditationModel model = new BaseAccraditationModel(BillAuditImpl.GetPubAuditProperty(str[0])); - if (model != null) _isExcPrint = model.BillPrintType == 3; - break; - } - } - } - } - /// - /// 说明:打印模版 - /// 创建人:龚宇超 - /// 创建日期:2017-11-27 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - protected void OnPrintItemClick(object sender, ItemClickEventArgs e) - { - string printFile = e.Item.Tag + ""; - string printPath = PubUtil.PrintFileAbsolutelyPath; - - if (!File.Exists(printPath)) - { - MessageUtil.Show(ResourceKeys.NotFoundPrintFile); - return; - } - - bool isPrint = this.BillModel.SaveState; - if (!isPrint) - { - if (MessageUtil.Show(ResourceKeys.BillNotSavedAndNotPrint, MessageBoxButtons.YesNo) == DialogResult.Yes) - isPrint = this.BillSave(); - } - - if (isPrint) - { - try - { - // 判断是否满足打印条件 - - //DataRow masterRow = BillImpl.GetDataRowResult(this.BillModel.MasterSql.Replace("{" + this.BillModel.PrimaryKey + "}", this.lblOrderNo.Text)); - DataRow masterRow = BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, this.lblOrderNo.Text)); - if (masterRow == null) - { - MessageUtil.Show(ResourceKeys.DataNotFount); - return; - } - - if (!ReplaceHelper.ReplaceRowParamCond(masterRow, this.BillModel.PrintCond)) - { - MessageUtil.Show(ResourceKeys.DisSatisfyPrintCond); - return; - } - - string tmpSql = ReplaceHelper.ReplaceRowParam(masterRow, this.BillModel.PrintSql); - string tmpSql1 = ReplaceHelper.ReplaceRowParam(masterRow, this.BillModel.PrintSql1); - string tmpSql2 = ReplaceHelper.ReplaceRowParam(masterRow, this.BillModel.PrintSql2); - - if (printFile.Contains(PrintUtil.TemplateFlag)) - { - //主Sql - string mainSql = string.Empty; - List tmpSqls = new List(); - if (_printSaveParams != null && _printSaveParams.Count > 0) - { - _printSaveParams[5] = mainSql = ReplaceHelper.ReplaceRowParam(masterRow, _mainPrintSql); - _printSaveParams[3] = masterRow.Table.Columns.Contains(_printSaveParams[2] + "") ? masterRow[_printSaveParams[2]] + "" : masterRow[BillModel.PrimaryKey] + ""; - tmpSqls.Add(mainSql); - tmpSqls.Add(tmpSql1); - tmpSqls.AddRange(tmpSql2.Split(';').ToList()); - } - else - { - if (!string.IsNullOrWhiteSpace(tmpSql)) tmpSqls.Add(tmpSql); - if (!string.IsNullOrWhiteSpace(tmpSql1)) tmpSqls.Add(tmpSql1); - if (!string.IsNullOrWhiteSpace(tmpSql2)) tmpSqls.AddRange(tmpSql2.Split(';').ToList()); - } - PrintUtil.OnAfterPrint -= new EventHandler(OnReportPrintAfter); - PrintUtil.OnAfterPrint += new EventHandler(OnReportPrintAfter); - PrintUtil.FastReportPrint(tmpSqls, printFile, _isExcPrint); - } - else - { - DelphiHelper.LoadDelphiDll(printPath, printPath, printFile, tmpSql, tmpSql1, this.BillModel.PrintFileType, tmpSql2); - } - //LogUtil.WriteDebug(this.SysModel.ModuleCode, "打印", "单据打印:" + printFile.Replace(".rmf", "").Replace(".frx", ""), "打印格式:" + printFile); - } - catch (Exception ex) - { - MessageUtil.Show(ex.Message + "\r\n" + ex.StackTrace); - LogUtil.WriteError(ResourceKeys.BillModule + "打印模板错误", ex); - LogHelper.Instance.WriteError(ex); - } - } - } - - /// - /// 打印 - /// - /// - /// - private void btnPrint_Click(object sender, EventArgs e) - { - string[] files = this.BillModel.PrintFile.Split('|'); - string printFile = files[0]; - string printPath = PubUtil.PrintFileAbsolutelyPath; - if (!File.Exists(printPath)) - { - MessageUtil.Show(ResourceKeys.NotFoundPrintFile); - return; - } - - bool isPrint = this.BillModel.SaveState; - if (!isPrint) - { - if (MessageUtil.Show(ResourceKeys.BillNotSavedAndNotPrint, MessageBoxButtons.YesNo) == DialogResult.Yes) - isPrint = this.BillSave(); - } - - if (isPrint) - { - try - { - // 判断是否满足打印条件 - - //DataRow masterRow = BillImpl.GetDataRowResult(this.BillModel.MasterSql.Replace("{" + this.BillModel.PrimaryKey + "}", this.lblOrderNo.Text)); - DataRow masterRow = BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, this.lblOrderNo.Text)); - if (masterRow == null) - { - MessageUtil.Show(ResourceKeys.DataNotFount); - return; - } - - if (!ReplaceHelper.ReplaceRowParamCond(masterRow, this.BillModel.PrintCond)) - { - MessageUtil.Show(ResourceKeys.DisSatisfyPrintCond); - return; - } - - string tmpSql = ReplaceHelper.ReplaceRowParam(masterRow, this.BillModel.PrintSql); - string tmpSql1 = ReplaceHelper.ReplaceRowParam(masterRow, this.BillModel.PrintSql1); - string tmpSql2 = ReplaceHelper.ReplaceRowParam(masterRow, this.BillModel.PrintSql2); - - if (printFile.Contains(PrintUtil.TemplateFlag)) - { - //主Sql - string mainSql = string.Empty; - List tmpSqls = new List(); - if (_printSaveParams != null && _printSaveParams.Count > 0) - { - _printSaveParams[5] = mainSql = ReplaceHelper.ReplaceRowParam(masterRow, _mainPrintSql); - _printSaveParams[3] = masterRow.Table.Columns.Contains(_printSaveParams[2] + "") ? masterRow[_printSaveParams[2]] + "" : masterRow[BillModel.PrimaryKey] + ""; - tmpSqls.Add(mainSql); - tmpSqls.Add(tmpSql1); - tmpSqls.AddRange(tmpSql2.Split(';').ToList()); - } - else - { - if (!string.IsNullOrWhiteSpace(tmpSql)) tmpSqls.Add(tmpSql); - if (!string.IsNullOrWhiteSpace(tmpSql1)) tmpSqls.Add(tmpSql1); - if (!string.IsNullOrWhiteSpace(tmpSql2)) tmpSqls.AddRange(tmpSql2.Split(';').ToList()); - } - PrintUtil.OnAfterPrint -= new EventHandler(OnReportPrintAfter); - PrintUtil.OnAfterPrint += new EventHandler(OnReportPrintAfter); - PrintUtil.FastReportPrint(tmpSqls, printFile, _isExcPrint); - } - else - { - DelphiHelper.LoadDelphiDll(printPath, printPath, printFile, tmpSql, tmpSql1, this.BillModel.PrintFileType, tmpSql2); - } - //LogUtil.WriteDebug(this.SysModel.ModuleCode, "打印", "单据打印:" + printFile.Replace(".rmf", "").Replace(".frx", ""), "打印格式:" + printFile); - if (ScanCodeTextEdit != null) ScanCodeTextEdit.Focus(); - } - catch (Exception ex) - { - MessageUtil.Show(ex.Message + "\r\n" + ex.StackTrace); - LogUtil.WriteError(ResourceKeys.BillModule + "打印模板错误", ex); - LogHelper.Instance.WriteError(ex); - } - } - } - #endregion - - #region 单据来源相关 - - /// - /// 说明:刷新单据来源主表,未传递时,默认刷新 - /// 创建人:龚宇超 - /// 创建日期:2017-12-13 - /// 修改人: - /// 修改日期: - /// 修改备注:gcMain - /// 版本:1.0 - /// - /// The union model. - /// XtraTabPage. - private void RefreshSource(BillSourceUnionModel unionModel = null) - { - if (unionModel == null || unionModel.SearchObj == null) return; - unionModel.SearchObj.SearchLastGrid(); - } - - /// - /// 说明:刷新表格列(时间) - /// 创建人:王一帆 - /// 创建日期:2018-08-16 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// - /// - private void OnDataFileRefrshFile(object sender, EventArgs e) - { - AddDataColumns(); - UpdateDynamicColumns(); - UpdateSummaryData(); - OnGcMainDataSourceChanged(gcMain.GridView, null);//手动刷新日期合计数据源 - } - - - /// - /// 说明:计算列关联字段 - /// 创建人:龚宇超 - /// 创建日期:2017-12-18 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The model. - /// The field value. - protected virtual void SetUnionValue(GridColumnModel model, string fieldValue, DataRow rowItem) - { - DataTable table = this.gcMain.gridControl.DataSourceTable(); - //DataRow rowItem = this.gridView.GetFocusedDataRow(); - string unionValues = model.UnionValues; - if (rowItem != null && model != null) - { - unionValues = ReplaceHelper.ReplaceRowParam(rowItem, unionValues.Replace("{" + model.FieldName + "}", fieldValue)); - if (this.ControlObj != null) - { - unionValues = ControlObj.ReplaceParentControlValue(unionValues); - } - try - { - string[] fields = model.UnionFields.Trim(',').Split(','); - DataRow rowResult = BaseImpl.GetDataRowResult(unionValues); - if (rowResult != null) - { - for (int i = 0; i < fields.Length; i++) - { - string field = fields[i]; - string value = rowResult.Table.Columns.Contains(field) ? rowResult[field] + "" : null; - rowItem[field] = value; - } - } - else - { - // 设置为空 - for (int i = 0; i < fields.Length; i++) - { - string field = fields[i]; - rowItem[field] = DBNull.Value; - } - } - } - catch (Exception ex) - { - LogHelper.Instance.WriteError(ex); - LogUtil.WriteError("计算列关联字段--错误-->" + unionValues, ex); - } - } - } - /// - /// 说明:禁用控件条件 - /// 创建人:龚宇超 - /// 创建日期:2019-01-22 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The model. - /// The field value. - protected virtual void SetDisableColumn(GridColumnModel model, string fieldValue, DataRow rowItem) - { - if (model.EnableCond != string.Empty) - { - List columns = this.gcMain.ObjmControlList.FindAll(x => x.EnableCond.Contains("{" + model.FieldName + "}")).ToList(); - foreach (GridColumnModel item in columns) - { - try - { - string disableCond = ReplaceHelper.ReplaceRowParam(rowItem, item.EnableCond.Replace("{" + model.FieldName + "}", fieldValue)); - string diaableType = item.DisableType; - if (this.BillModel.DetailTreeTable) - { - (this.gcMain as TreeGridControlEx).TreeListObj.Columns.ColumnByFieldName(model.FieldName).Visible = ("true".Equals(EvalHelper.Eval(ReplaceHelper.ReplaceEvalCond(disableCond)) + "", StringComparison.OrdinalIgnoreCase)); - } - else - { - this.gcMain.GridView.Columns.ColumnByFieldName(model.FieldName).Visible = ("true".Equals(EvalHelper.Eval(ReplaceHelper.ReplaceEvalCond(disableCond)) + "", StringComparison.OrdinalIgnoreCase)); - } - } - catch (Exception) - { - } - } - } - } - /// - /// 说明:计算列计算公式 - /// 创建人:龚宇超 - /// 创建日期:2017-12-18 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The model. - /// The field value. - protected virtual void SetCalcValue(GridColumnModel model, string fieldValue, DataRow rowItem) - { - try - { - DataTable table = this.gcMain.gridControl.DataSourceTable(); - if (rowItem != null && model != null) - { - List calcModels = this.gcMain.ObjmControlList.FindAll(x => !string.IsNullOrEmpty(x.CalcExpr)).OrderBy(y => y.CalcOrder).ToList(); - - foreach (GridColumnModel gridModel in calcModels) - { - // 计算顺序小于当前控件则不计算 - if (gridModel.CalcOrder < model.CalcOrder) continue; - - if (!gridModel.FieldName.Equals(model.FieldName, StringComparison.OrdinalIgnoreCase)) - { - bool isTruncate = false; - string calcExpr = gridModel.CalcExpr; - if (calcExpr.StartsWith("@truncate:")) - { - calcExpr = calcExpr.Substring(10); - isTruncate = true; - } - - try - { - if (this.ControlObj != null) - calcExpr = ControlObj.ReplaceParentControlValue(calcExpr); - - calcExpr = ReplaceHelper.ReplaceRowParam(rowItem, calcExpr); - //EvalHelper.Eval2(ReplaceHelper.ReplaceEvalCond(calcExpr)) + "" - string result = EvalHelper.Eval2(ReplaceHelper.ReplaceEvalCond(calcExpr)) + ""; - if (isTruncate) - { - result += result.Contains(".") ? "0000000000" : ".0000000000"; - rowItem[gridModel.FieldName] = result.Substring(0, result.IndexOf(".")) + result.Substring(result.IndexOf("."), model.Decimals + 1); - //this.gridView.SetRowCellValue(this.gridView.FocusedRowHandle, this.gridView.Columns[gridModel.FieldName], result.Substring(0, result.IndexOf(".")) + result.Substring(result.IndexOf("."), model.Decimals + 1)); - } - else - { - try - { - double d = 0; - if (!string.IsNullOrEmpty(result) && - !"NaN".Equals(result, StringComparison.OrdinalIgnoreCase) && - !"非数字".Equals(result, StringComparison.OrdinalIgnoreCase) && - !"undefined".Equals(result, StringComparison.OrdinalIgnoreCase) && - result != "∞" && result != "-∞" && - !"正无穷大".Equals(result, StringComparison.OrdinalIgnoreCase) && - !"负无穷大".Equals(result, StringComparison.OrdinalIgnoreCase) && - double.TryParse(result, out d)) - { - if (string.IsNullOrEmpty(gridModel.DataFormat)) - { - result = Math.Round(Convert.ToDouble(d), model.Decimals, MidpointRounding.AwayFromZero) + ""; - } - else - { - //计算后先执行保存小数位数 - result = string.Format("{0:" + gridModel.DataFormat + "}", Convert.ToDecimal(result)); - } - if (model.FieldType == 7 && result.Contains('%')) - { - result = (double.Parse(result.Replace("%", "")) * 0.01).ToString(); - } - rowItem[gridModel.FieldName] = result; - // 判断计算列有无关联值 - GridColumnModel UnionModel = calcModels.FirstOrDefault(x => x.FieldName == gridModel.FieldName); - if (!string.IsNullOrEmpty(UnionModel.UnionFields)) - { - this.SetUnionValue(UnionModel, rowItem[gridModel.FieldName] + "", rowItem); - } - //this.gridView.SetRowCellValue(this.gridView.FocusedRowHandle, this.gridView.Columns[gridModel.FieldName], result); - } - } - catch (Exception) - { - - } - } - } - catch (Exception ex) - { - LogHelper.Instance.WriteError(ex); - LogUtil.WriteError("计算列计算公式--错误-->" + rowItem[gridModel.FieldName], ex); - } - } - } - } - } - catch (Exception ex) - { - LogHelper.Instance.WriteError(ex); - string Message = ErrorMessage.PromptErrorMessage(ex); - // MessageUtil.Show(Message,ex.Message); - } - } - /// - /// 说明:添加行到单据明细中 - /// 创建人:龚宇超 - /// 创建日期:2017-11-30 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The row item. - /// The union model. - private DataRow AddRowToGridView(DataRow rowItem, bool dataProcessing = true) - { - GridColumnCollection gridColumns = this.gcMain.GridView.Columns; - DataTable gridTable = (this.gcMain.GridControl.DataSource as DataTable).TrimDeleteRows(); - if (!gridTable.Columns.Contains(ERPInfo.Instance.isAddRows)) - { - gridTable.Columns.Add(ERPInfo.Instance.isAddRows, typeof(String)); - } - string repeatProduct = this.gcMain.GridView.Columns["ProductId"] != null && rowItem.Table.Columns.Contains("ProductId") ? "ProductId" : this.BillModel.DetailPreFix + "ProductId"; - AssociatedField = repeatProduct; - if ("1".Equals(this.BillModel.DetailDoubleClickTip) && rowItem.Table.Columns.Contains(repeatProduct)) - { - - //上面方法无法处理大小写,改成搜索的形式 - DataTable dt = this.gcMain.gridControl.DataSourceTable(); - if (dt != null && dt.Rows.Count > 0 && dt.Columns.Contains(repeatProduct)) - { - DataRow[] drs = dt.Select(repeatProduct + "='" + rowItem[repeatProduct] + "'"); - if (drs.Length >= 1) - { - DialogResult dialog = MessageUtil.Show(ResourceKeys.ProductIsRepet, MessageBoxButtons.YesNo); - if (dialog != DialogResult.Yes) - { - return null; - } - } - } - } - DataRow newRow = gridTable.NewRow(); - //if (gridTable.Columns.Contains(guidField)) - //{ - // newRow[guidField] = Guid.NewGuid().ToString(); - //} - //2024-1-29改成>=,之前为>导致选中第一行只会添加到最后一行(测试空白行没有影响) - int position = this.gcMain.GridView.FocusedRowHandle >= 0 ? gridTable.Rows.Count > 0 ? this.gcMain.GridView.FocusedRowHandle : 0 : gridTable.Rows.Count - 1; - bool isLastRow = this.gcMain.GridView.IsLastVisibleRow; - this.gcMain.GridView.BeginDataUpdate(); - GridView gridView = this.gcMain.GridView; - // 赋值明细字段 - foreach (GridColumn col in gridColumns) - { - try - { - // 未包含字段,则使用控件默认值. - GridColumnModel model = col.Tag as GridColumnModel; - if (model == null) - { - if (rowItem.Table.Columns.Contains(col.FieldName)) - { - // 来源列中是否包含对应字段,包含则使用值 - newRow[col.FieldName] = rowItem[col.FieldName]; - } - continue; - } - if (rowItem.Table.Columns.Contains(col.FieldName)) - { - // 来源列中是否包含对应字段,包含则使用值 - newRow[col.FieldName] = rowItem[col.FieldName]; - if (dataProcessing) - { - if (!string.IsNullOrEmpty(model.UnionFields)) - { - this.SetUnionValue(model, rowItem[col.FieldName] + "", newRow); - } - SetCalcValue(model, rowItem[col.FieldName] + "", newRow); - } - - } - else - { - - if (col.FieldName.Contains("_Ls")) - { - string[] unioFielName = col.FieldName.Split('_'); - string UnioValue = unioFielName[unioFielName.Length - 1]; - DataColumn grid = rowItem.Table.Columns.Cast().FirstOrDefault(x => x.ColumnName.Split('_')[x.ColumnName.Split('_').Length - 1].Equals(UnioValue)); - if (dataProcessing) - { - if (grid != null && !string.IsNullOrEmpty(model.UnionFields)) - { - this.SetUnionValue(model, rowItem[col.FieldName] + "", newRow); - } - SetCalcValue(model, rowItem[col.FieldName] + "", newRow); - } - - } - else - { - string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue); - //int nowPositon = !isLastRow ? position : gridTable.Rows.Count - 1; - - if (model.DefaultValue.Contains("{#")) - { - fieldValue = this.ControlObj.ReplaceParentControlValue(model.DefaultValue); - if (fieldValue.StartsWith("@")) - { - fieldValue = BaseImpl.GetDefaultValue(fieldValue); - } - if (!string.IsNullOrEmpty(fieldValue)) - { - newRow[col.FieldName] = fieldValue; - if (dataProcessing) - { - if (!string.IsNullOrEmpty(model.UnionFields)) - { - this.SetUnionValue(model, newRow[col.FieldName] + "", newRow); - } - SetCalcValue(model, newRow[col.FieldName] + "", newRow); - } - //计算规则配置在结果字段上,所以无需验证当前操作控件 - //this.gcMain.GridView.SetFocusedRowCellValue(col, fieldValue); - } - } - else if (!string.IsNullOrEmpty(model.DefaultValue)) - { - if (string.IsNullOrEmpty(newRow[col.FieldName] + "")) - { - newRow[col.FieldName] = fieldValue; - } - if (dataProcessing) - { - if (!string.IsNullOrEmpty(model.UnionFields)) - { - this.SetUnionValue(model, newRow[col.FieldName] + "", newRow); - } - SetCalcValue(model, newRow[col.FieldName] + "", newRow); - //this.gcMain.GridView.SetFocusedRowCellValue(col, fieldValue); - } - } - } - } - SetDisableColumn(model, newRow[col.FieldName] + "", newRow); - //GridColumnModel model = col.Tag as GridColumnModel; - if (model.LimitLength > 0) - { - DataRow HandleRow = newRow; - int MaxInputLength = System.Text.Encoding.Default.GetBytes(newRow[col.FieldName] + "").Length; - if (model.LimitLength < MaxInputLength) - HandleRow.SetColumnError(HandleRow.Table.Columns[col.ColumnHandle], "当前输入文本超过设定长度!");//满足条件设置错误信息 - } - } - catch (Exception ex) - { - LogHelper.Instance.WriteError(ex); - //LogUtil.WriteError(col.FieldName + "添加出错!", ex); - } - } - this.gcMain.GridView.EndDataUpdate(); - if (!isLastRow) - { - // 插入数据行 - gridTable.Rows.InsertAt(newRow, position + 1); - this.gcMain.GridView.ClearSelection(); - this.gcMain.GridView.SelectRowHandler(position + 1); - } - else - { - // 添加数据行 - gridTable.Rows.Add(newRow); - this.gcMain.GridView.ClearSelection(); - this.gcMain.GridView.SelectRowHandler(gridTable.Rows.Count - 1); - } - - - // 插入数据后 - if (isLastRow) - { - this.gcMain.GridView.ClearSelection(); - this.gcMain.GridView.SelectRowHandler(position + 1); - } - if (!string.IsNullOrEmpty(NumberMc) && gridTable.Columns.Contains(mRecordPrimaryField)) - { - DataRow[] rt = gridTable.Rows.Cast().Where(x => (newRow[BillModel.DetailPreFix + "ProductId"] + "").Equals(x[BillModel.DetailPreFix + "ProductId"] + "") && !string.IsNullOrEmpty(x[mRecordPrimaryField] + "")).ToArray(); - foreach (DataRow item in rt) - { - if (newRow != null) - { - newRow[NumberMc] = Convert.ToDouble(newRow[NumberMc]) - Convert.ToDouble(item[NumberMc]); - } - this.gcMain.OnGridViewCellValueChanged(this.gcMain, new CellValueChangedEventArgs(position + 1, this.gcMain.GridView.Columns[NumberMc], newRow[NumberMc] + "")); - this.gcMain.GridView.UpdateCurrentRow(); - this.gcMain.GridView.ShowEditor(); - if (Convert.ToDouble(newRow[NumberMc] + "") == 0.0) - { - gridTable.Rows.Remove(newRow); - MessageUtil.Show("数量已分配完毕!无需再进行拖拽!"); - } - } - } - gridTable.OrderBy(this.BillModel.DetailOrderField); - this.gcMain.GridView.UpdateCurrentRow(); - this.gcMain.GridView.ShowEditor(); - return newRow; - } - /// - /// 说明:添加多行到单据明细中 - /// 创建人:龚宇超 - /// 创建日期:2017-11-30 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The row item. - /// The union model. - private void AddRowsToGridView(DataTable dataTable, BillSourceUnionModel unionModel) - { - WaitForm.ShowForm(); - GridColumnCollection gridColumns = this.gcMain.GridView.Columns; - DataTable gridTable = (this.gcMain.GridControl.DataSource as DataTable).TrimDeleteRows().Copy(); - if (!gridTable.Columns.Contains(ERPInfo.Instance.isAddRows)) - { - gridTable.Columns.Add(ERPInfo.Instance.isAddRows, typeof(String)); - } - int position = this.gcMain.GridView.FocusedRowHandle; - bool isLastRow = this.gcMain.GridView.IsLastVisibleRow; - bool onlyOne = true; - foreach (DataRow rowItem in dataTable.Rows) - { - if (unionModel == null || ValidateDetailCond(rowItem, unionModel)) - { - string repeatProduct = this.gcMain.GridView.Columns["ProductId"] != null && dataTable.Columns.Contains("ProductId") ? "ProductId" : this.BillModel.DetailPreFix + "ProductId"; - AssociatedField = repeatProduct; - if ("1".Equals(this.BillModel.DetailDoubleClickTip) && this.gcMain.GridView.Columns[repeatProduct] != null && dataTable.Columns.Contains(repeatProduct)) - { - // 需要提示编码重复 - //GridView view = this.gcMain.GridView; - //bool result = (view.LocateByValue(repeatProduct, rowItem[repeatProduct], null) >= 0) | - // (view.LocateByValue(repeatProduct, rowItem[repeatProduct], null) >= 0) | - // (view.LocateByValue(repeatProduct, rowItem[repeatProduct], null) >= 0) | - // (view.LocateByValue(repeatProduct, rowItem[repeatProduct], null) >= 0); - //if (result) - //{ - // DialogResult dialog = MessageUtil.Show(ResourceKeys.ProductIsRepet, MessageBoxButtons.YesNo); - // if (dialog != DialogResult.Yes) - // return; - //} - - //上面方法无法处理大小写,改成搜索的形式 - DataTable dt = this.gcMain.gridControl.DataSourceTable(); - if (dt != null && dt.Rows.Count > 0 && dt.Columns.Contains(repeatProduct)) - { - DataRow[] drs = dt.Select(repeatProduct + "='" + rowItem[repeatProduct] + "'"); - if (drs.Length >= 1) - { - DialogResult dialog = MessageUtil.Show(ResourceKeys.ProductIsRepet, MessageBoxButtons.YesNo); - if (dialog != DialogResult.Yes) - return; - } - } - - } - - DataRow newRow = gridTable.NewRow(); - newRow.BeginEdit(); - // 赋值明细字段 - foreach (GridColumn col in gridColumns) - { - try - { - GridColumnModel model = col.Tag as GridColumnModel; - if (model == null) continue; - if (dataTable.Columns.Contains(col.FieldName)) - { - // 来源列中是否包含对应字段,包含则使用值 - newRow[col.FieldName] = rowItem[col.FieldName]; - if (!string.IsNullOrEmpty(model.UnionFields)) - { - this.SetUnionValue(model, rowItem[col.FieldName] + "", newRow); - } - SetCalcValue(model, rowItem[col.FieldName] + "", newRow); - - } - else - { - // 未包含字段,则使用控件默认值. - if (col.FieldName.Contains("_Ls")) - { - string[] unioFielName = col.FieldName.Split('_'); - string UnioValue = unioFielName[unioFielName.Length - 1]; - DataColumn grid = dataTable.Columns.Cast().FirstOrDefault(x => x.ColumnName.Split('_')[x.ColumnName.Split('_').Length - 1].Equals(UnioValue)); - if (grid != null && !string.IsNullOrEmpty(model.UnionFields)) - { - this.SetUnionValue(model, rowItem[col.FieldName] + "", newRow); - } - SetCalcValue(model, rowItem[col.FieldName] + "", newRow); - - } - else - { - string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue); - //int nowPositon = !isLastRow ? position : gridTable.Rows.Count - 1; - if (model.DefaultValue.Contains("{#")) - { - fieldValue = this.ControlObj.ReplaceParentControlValue(model.DefaultValue); - if (!string.IsNullOrEmpty(fieldValue)) - { - newRow[col.FieldName] = fieldValue; - if (!string.IsNullOrEmpty(model.UnionFields)) - { - this.SetUnionValue(model, fieldValue + "", newRow); - } - SetCalcValue(model, fieldValue + "", newRow); - - //计算规则配置在结果字段上,所以无需验证当前操作控件 - //this.gcMain.GridView.SetFocusedRowCellValue(col, fieldValue); - } - } - else if (!string.IsNullOrEmpty(model.DefaultValue)) - { - if (string.IsNullOrEmpty(newRow[col.FieldName] + "")) - { - newRow[col.FieldName] = fieldValue; - } - - if (!string.IsNullOrEmpty(model.UnionFields)) - { - this.SetUnionValue(model, newRow[col.FieldName] + "", newRow); - } - SetCalcValue(model, newRow[col.FieldName] + "", newRow); - - //this.gcMain.GridView.SetFocusedRowCellValue(col, fieldValue); - } - } - } - SetDisableColumn(model, newRow[col.FieldName] + "", newRow); - } - catch (Exception ex) - { - LogHelper.Instance.WriteError(ex); - //LogUtil.WriteError(col.FieldName + "添加出错!", ex); - } - } - newRow.EndEdit(); - if (!isLastRow) - { - // 插入数据行 - gridTable.Rows.InsertAt(newRow, position); - //this.gcMain.GridView.ClearSelection(); - //this.gcMain.GridView.SelectRowHandler(position); - } - else - { - // 添加数据行 - gridTable.Rows.Add(newRow); - // this.gcMain.GridView.ClearSelection(); - // this.gcMain.GridView.SelectRowHandler(gridTable.Rows.Count - 1); - } - position++; - //if (isLastRow) - //{ - // this.gcMain.GridView.ClearSelection(); - // this.gcMain.GridView.SelectRowHandler(position + 1); - //} - if (!string.IsNullOrEmpty(NumberMc) && gridTable.Columns.Contains(mRecordPrimaryField)) - { - DataRow[] rt = gridTable.Rows.Cast().Where(x => (newRow[BillModel.DetailPreFix + "ProductId"] + "").Equals(x[BillModel.DetailPreFix + "ProductId"] + "") && !string.IsNullOrEmpty(x[mRecordPrimaryField] + "")).ToArray(); - foreach (DataRow item in rt) - { - if (newRow != null) - { - newRow[NumberMc] = Convert.ToDouble(newRow[NumberMc]) - Convert.ToDouble(item[NumberMc]); - } - this.gcMain.OnGridViewCellValueChanged(this.gcMain, new CellValueChangedEventArgs(position + 1, this.gcMain.GridView.Columns[NumberMc], newRow[NumberMc] + "")); - this.gcMain.GridView.UpdateCurrentRow(); - this.gcMain.GridView.ShowEditor(); - if (Convert.ToDouble(newRow[NumberMc] + "") == 0.0) - { - gridTable.Rows.Remove(newRow); - MessageUtil.Show("数量已分配完毕!无需再进行拖拽!"); - } - } - } - } - else - { - if (onlyOne) - { - onlyOne = false; - if (!string.IsNullOrEmpty(unionModel.ModelObj.DetailEnableMsg)) - { - if (unionModel.ModelObj.DetailEnableMsg.StartsWith("select", StringComparison.OrdinalIgnoreCase) || - unionModel.ModelObj.DetailEnableMsg.StartsWith("exec", StringComparison.OrdinalIgnoreCase)) - { - MessageUtil.Show(BaseImpl.GetResult(unionModel.ModelObj.DetailEnableMsg) + ""); - } - else - { - MessageUtil.Show(unionModel.ModelObj.DetailEnableMsg); - } - } - } - } - } - this.gcMain.GridControl.DataSource = gridTable; - if (position >= 0) - this.gcMain.GridView.SelectRowHandler(position); - else - this.gcMain.GridView.SelectRowHandler(gridTable.Rows.Count - 1); - //this.gcMain.GridView.SelectRowHandler(position); - gridTable.OrderBy(this.BillModel.DetailOrderField); - this.gcMain.GridView.UpdateCurrentRow(); - this.gcMain.GridView.ShowEditor(); - WaitForm.HideForm(); - } - /// - /// 添加多行数据到单据明细中,禁用所有关联和默认值的获取 - /// - /// - /// - private void AddRowsToGridViewFast(DataRow[] rowItems) - { - try - { - DataTable gridTable = (this.gcMain.GridControl.DataSource as DataTable).TrimDeleteRows(); - foreach (DataRow rowItem in rowItems) - { - DataRow dataRow = gridTable.NewRow(); - foreach (DataColumn column in gridTable.Columns) - { - if (rowItem.Table.Columns.Contains(column.ColumnName)) - { - dataRow[column] = rowItem[column.ColumnName]; - } - } - gridTable.Rows.Add(dataRow); - } - } - catch (Exception ex) - { - MessageUtil.Show(ex.Message); - } - } - /// - /// 说明:检查添加数据到表格中是否包含 - /// - /// 创建人:龚宇超 - /// 创建日期:2018-04-20 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The row item. - /// The union model. - /// if set to true [only popup]. - private void AddRowToGridViewByBom(DataRow rowItem, BillSourceUnionModel unionModel, ref bool onlyPopup) - { - if (!string.IsNullOrEmpty(unionModel.ModelObj.BomSql)) - { - string bomSql = unionModel.ModelObj.BomSql; - // 检查是否有bom配置 - if (unionModel.ModelObj.LoadBom == 1) - { - // 自动带出bom数据,不弹出选择 - DataTable table = BaseImpl.GetDataTableResult(ReplaceHelper.ReplaceRowParam(rowItem, bomSql)); - foreach (DataRow item in table.Rows) - { - this.AddRowToGridView(item); - } - } - else if (unionModel.ModelObj.LoadBom == 2) - { - DataTable table = BaseImpl.GetDataTableResult(ReplaceHelper.ReplaceRowParam(rowItem, bomSql)); - - if (!onlyPopup && table.Rows.Count > 0) - { - // 自动带出bom数据,弹出选择 - FrmBomSelect frmSelect = new FrmBomSelect(); - frmSelect.Caption = unionModel.ModelObj.BomCaption; - frmSelect.GridColumns = unionModel.GridDetailControlObj.GridView.Columns; - frmSelect.BomDataTable = table; - - DialogResult result = frmSelect.ShowDialog(); - onlyPopup = frmSelect.OnlyPopup; - - if (result == DialogResult.OK && frmSelect.SelectBomRows != null && frmSelect.SelectBomRows.Length > 0) - { - foreach (DataRow item in frmSelect.SelectBomRows) - { - this.AddRowToGridView(item); - } - } - } - else - { - foreach (DataRow item in table.Rows) - { - this.AddRowToGridView(item); - } - } - } - } - } - - /// - /// 说明:添加多条数据到单据明细 - /// 创建人:龚宇超 - /// 创建日期:2018-05-30 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The table. - private void AddMultiRowToGridView(DataTable table, BillSourceUnionModel unionModel = null) - { - if (table == null) return; - if (this.BillModel.DetailTreeTable) - { - this.AddRowsToTreeGridControl(table, unionModel); - } - else - { - this.AddRowsToGridView(table, unionModel); - } - - - Application.DoEvents(); - } - /// - /// 说明:是否允许添加明细 - /// 创建人:龚宇超 - /// 创建日期:2018-06-06 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// true if this instance [can add detail row]; otherwise, false. - private bool CanAddDetailRow() - { - // 检测是否正在筛选数据 - if (!string.IsNullOrEmpty(gcMain.GridView.FindFilterText.Trim()) || - !string.IsNullOrEmpty(gcMain.GridView.FilterPanelText.Trim())) - { - if (MessageUtil.Show(ResourceKeys.GridViewSearching, MessageBoxButtons.YesNo) == DialogResult.Yes) - { - this.gcMain.GridView.FindFilterText = ""; - return true; - } - return false; - } - // 检测是否点击了排序表格 - if (this.gcMain.GridView.HasSortColumn()) - { - //if (MessageUtil.Show(ResourceKeys.GridViewColumnSorting, MessageBoxButtons.YesNo) == DialogResult.Yes) - //{ - this.gcMain.GridView.Columns.ClearAllSort(); - // return true; - //} - //return false; - } - // 检测是否为提交或者终审模块 - if (_waterMark.Text.Contains("已终审")) - { - MessageUtil.Show(ResourceKeys.AddBillDetailed); - return false; - } - return true; - } - - /// - /// 说明:单据明细撤回操作 - /// 创建人:曹屹峰 - /// 创建日期:2021-11-09 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - private void OnToWithdraw(object sender, KeyEventArgs e) - { - if (e.Control && e.KeyCode == Keys.Z) - { - if (ToWithdrawRows.Count < 1) return; - DataTable gridTable = (this.gcMain.GridControl.DataSource as DataTable).TrimDeleteRows(); - Dictionary undo = ToWithdrawRows[ToWithdrawRows.Count - 1]; - foreach (int key in undo.Keys) - { - DataRow dr = gridTable.NewRow(); - dr.ItemArray = undo[key].ItemArray; - gridTable.Rows.InsertAt(dr, key); - this.gcMain.GridView.ClearSelection(); - this.gcMain.GridView.SelectRowHandler(key); - } - gridTable.OrderBy(this.BillModel.DetailOrderField); - ToWithdrawRows.RemoveAt(ToWithdrawRows.Count - 1); - } - if (e.Alt) - { - GridView gridView = sender as GridView; - if (gridView == null) return; - if (e.KeyCode == Keys.Up) - { - DataTable dtTable = gcMain.gridControl.DataSource as DataTable; - if (gridView.FocusedRowHandle > 0 && dtTable.Columns.Contains(this.BillModel.DetailOrderField)) - { - dtTable = SwapRow(gridView.FocusedRowHandle, gridView.FocusedRowHandle - 1, dtTable); - dtTable.OrderBy(this.BillModel.DetailOrderField); - //DataTableOrderBy(dtTable); - } - } - else if (e.KeyCode == Keys.Down) - { - DataTable dtTable = gcMain.gridControl.DataSource as DataTable; - if (gridView.FocusedRowHandle < dtTable.Rows.Count - 1 && dtTable.Columns.Contains(this.BillModel.DetailOrderField)) - { - dtTable = SwapRow(gridView.FocusedRowHandle, gridView.FocusedRowHandle + 1, dtTable); - dtTable.OrderBy(this.BillModel.DetailOrderField); - //DataTableOrderBy(dtTable); - } - } - } - } - private DataTable SwapRow(int index1, int index2, DataTable dt) - { - DataRow dr = dt.NewRow(); - dr.ItemArray = dt.Rows[index1].ItemArray; - dt.Rows[index1].ItemArray = dt.Rows[index2].ItemArray; - dt.Rows[index2].ItemArray = dr.ItemArray; - return dt; - } - private void DataTableOrderBy(DataTable dtTable) - { - try - { - if (dtTable.Columns.Contains(this.BillModel.DetailOrderField)) - { - for (int i = 0; i < dtTable.Rows.Count; i++) - { - DataRow row = dtTable.Rows[i]; - if (row.RowState != DataRowState.Deleted) - { - row[this.BillModel.DetailOrderField] = (i + 1); - } - } - } - } - catch (Exception) - { - } - } - - /// - /// 说明: - /// 创建人:龚宇超 - /// 创建日期:2017-11-30 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// true if XXXX, false otherwise. - private bool ValidateDetailCond(DataRow rowItem, BillSourceUnionModel unionModel) - { - bool validate = false; - - try - { - string detailCond = ReplaceHelper.ReplaceRowParam(rowItem, unionModel.ModelObj.DetailEnableCond); - if (detailCond.Contains("#")) - { - List condition = ReplaceHelper.GetParamFields(detailCond); - foreach (string item in condition) - { - string fieldValue = this.ControlObj.GetControlValue(item.Replace("{#", "").Replace("}", "")); - detailCond = detailCond.Replace(item, fieldValue); - } - } - if (detailCond.StartsWith("@") || detailCond.StartsWith("!")) - { - validate = "1".Equals(BaseImpl.GetDefaultValue(detailCond)); - } - else - { - - validate = ReplaceHelper.EvalCond(detailCond); - } - } - catch (Exception ex) - { - LogHelper.Instance.WriteLog(ex.StackTrace); - LogUtil.WriteError("验证多条添加条件出错!", ex); - //MessageUtil.Show(ResourceKeys.CondtionError + "\r\n" + unionModel.ModelObj.DetailEnableCond); - } - return validate; - } - - - /// - /// 说明:初始化附加信息 - /// 创建人:龚宇超 - /// 创建日期:2018-04-26 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - private List GetAttachTabs() - { - List details = new List(); - - DataTable table = BaseAuditImpl.GetAttachTabs(this.SysModel.ModuleCode, "100", " and orderid < 0 "); - foreach (DataRow item in table.Rows) - { - DataTable gridColumns = BaseAuditImpl.GetBottomBasicInformation(item["formKey"] + ""); - details.Add(new GridDetailModel(item, gridColumns, GridCustomColumnStruct.BillSourceDetailAttachGridView)); - } - - return details; - } - #endregion - - #region 单据保存、提交 - /// - /// 说明:获取添加表头数据 - /// 创建人:龚宇超 - /// 创建日期:2017-12-07 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The parmary value. - /// System.String. - private string GetAddRecord(ref string parmaryValue) - { - if (BillModel.NewVer == 0) - { - // 检查当前的单据号是否已被占用. - string newBillNo = BillImpl.GetBillNo(this.BillModel.BillSeq); - - if (!parmaryValue.Equals(newBillNo)) - { - if (MessageUtil.Show(ResourceKeys.BillRecordRepeat, MessageBoxButtons.YesNo) == DialogResult.No) - { - return string.Empty; - } - else - { - this.lblOrderNo.Text = newBillNo; - parmaryValue = newBillNo; - } - } - } - - StringBuilder fieldBuilder = new StringBuilder(); - StringBuilder valueBuilder = new StringBuilder(); - - DataTable DetailedProperties = BaseImpl.GetDataTableResult(string.Format("select COLUMN_NAME,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH from information_schema.columns where table_name = '{0}'", BillModel.MasterTable)); - - string errorMessage = string.Empty;//数据不符合数据库规范的信息 - foreach (ControlModel model in this.ControlObj.ControlModels) - { - if (!model.IsSave || - model.FieldName.Equals(BillModel.PrimaryKey, StringComparison.OrdinalIgnoreCase) || - model.FieldName.Equals(BillModel.RtagidKey, StringComparison.OrdinalIgnoreCase) || - model.FieldType == ControlType.LabPic || - model.FieldType == ControlType.LabPicEx) - continue; - - if (string.IsNullOrWhiteSpace(model.FieldName)) continue; - - string fieldValue = this.ControlObj.GetControlValue(model); - if (SystemInfo.Instance.TrimWhiteSpace) - fieldValue = fieldValue.Trim(); - if (fieldValue == "****") continue; - - errorMessage = errorMessage + DatabaseFormatJudgment.SaveOrModifyBalidation(DetailedProperties, model, fieldValue); - if (string.IsNullOrEmpty(fieldValue) && model.Isintordecimal) fieldValue = "0";//数值保存时为空的话默认保存为0; - - fieldBuilder.Append(model.FieldName + ","); - valueBuilder.Append(string.IsNullOrEmpty(fieldValue) ? this.ControlObj.GetNullValue(model) : string.Format("N'{0}',", fieldValue)); - - - - } - if (!string.IsNullOrWhiteSpace(errorMessage)) SaveErrorMessage = "表头错误:" + errorMessage; - // 增加主键 - fieldBuilder.Append(BillModel.PrimaryKey); - valueBuilder.Append("N'" + parmaryValue + "'"); - // 增加红蓝字单标记 - fieldBuilder.Append("," + BillModel.RtagidKey); - valueBuilder.Append(",N'" + (rdRed.Checked ? 1 : 0) + "'"); - - return string.Format("insert into {0}({1}) values ({2})", BillModel.MasterTable, fieldBuilder.ToString().TrimEnd(','), valueBuilder.ToString().TrimEnd(',')); - } - /// - /// 说明:获取修改表头数据 - /// 创建人:龚宇超 - /// 创建日期:2017-12-07 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// 单据值. - /// System.String. - private string GetUpdateRecord(string parmaryValue) - { - StringBuilder updateBuilder = new StringBuilder(); - - - DataTable DetailedProperties = BaseImpl.GetDataTableResult(string.Format("select COLUMN_NAME,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH from information_schema.columns where table_name = '{0}'", BillModel.MasterTable)); - - - string errorMessage = string.Empty;//数据不符合数据库规范的信息 - // 修改单据 - foreach (ControlModel model in this.ControlObj.ControlModels) - { - if (!model.IsSave || - model.FieldName.Equals(BillModel.RtagidKey, StringComparison.OrdinalIgnoreCase) || - model.FieldType == ControlType.LabPic || - model.FieldType == ControlType.LabPicEx) - continue; - - if (string.IsNullOrWhiteSpace(model.FieldName)) continue; - - BaseUserControl userControl = this.ControlObj.FindControl(model); - if (userControl != null) - { - string fieldValue = this.ControlObj.GetControlValue(model); - if (SystemInfo.Instance.TrimWhiteSpace) - fieldValue = fieldValue.Trim(); - if (fieldValue == "****") continue; - - errorMessage = errorMessage + DatabaseFormatJudgment.SaveOrModifyBalidation(DetailedProperties, model, fieldValue); - if (string.IsNullOrEmpty(fieldValue) && model.Isintordecimal) fieldValue = "0";//数值保存时为空的话默认保存为0; - - updateBuilder.Append(string.IsNullOrEmpty(fieldValue) ? string.Format("{0}={1}", model.FieldName, this.ControlObj.GetNullValue(model)) : string.Format("{0}=N'{1}',", model.FieldName, fieldValue.Contains("'") ? fieldValue.Replace("'", "''") : fieldValue)); - - } - - } - if (!string.IsNullOrWhiteSpace(errorMessage)) SaveErrorMessage = "表头错误:" + errorMessage; - return string.Format("update {0} set {1} where {2}='{3}'", BillModel.MasterTable, updateBuilder.ToString().TrimEnd(','), BillModel.PrimaryKey, parmaryValue); - } - /// - /// 说明:获取保存明细数据 - /// 创建人:龚宇超 - /// 创建日期:2017-12-07 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// System.String. - private StringBuilder GetDetailRecord(string guid, string billNo, List addRowList) - { - // 构造明细 - StringBuilder detailBuilder = new StringBuilder(); - DataTable detailTable = this.gcMain.GridControl.DataSourceTable().TrimDeleteRows(); - if (this.BillModel.DetailTreeTable) - { - detailTable = ((this.gcMain as TreeGridControlEx).TreeListObj.DataSource as DataTable).TrimDeleteRows(); - } - - string Autogrowcolumn = SqlHelper.ExecuteScalar(string.Format("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.columns WHERE TABLE_NAME='{0}' AND COLUMNPROPERTY(OBJECT_ID('{0}'),COLUMN_NAME,'IsIdentity')=1", BillModel.DetailTable)) + ""; ;//自增长列 - DataTable DetailedProperties = BaseImpl.GetDataTableResult(string.Format("select COLUMN_NAME,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH from information_schema.columns where table_name = '{0}'", BillModel.DetailTable + "_temp"));//单据明细性表 - - //主键 - //DataTable primaryKeydt = BaseImpl.GetDataTableResult(string.Format("SELECT TABLE_NAME,COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME='{0}'", BillModel.DetailTable)); - //string primaryKey = string.Empty; - //bool AddPrimaryKey = false; - //if (primaryKeydt.Rows.Count > 0) - //{ - // primaryKey = primaryKeydt.Rows[0]["COLUMN_NAME"] + ""; - //} - //if (!string.IsNullOrWhiteSpace(primaryKey)) - //{ - // DataTable dt = this.gcMain.gridControl.DataSource as DataTable; - // if (dt.Columns.Contains(primaryKey)) - // { - // AddPrimaryKey = true; - // } - //} - - if (detailTable.Rows.Count > 0) - { - int lineNumber = 1; - DataTable BillColumns = BaseImpl.GetDataTableResult(string.Format("select * from {0} where 1<>1", BillModel.DetailTable)); - DataTable BillTempColumns = BaseImpl.GetDataTableResult(string.Format("select * from {0} where 1<>1", BillModel.DetailTable + "_temp")); - foreach (DataRow dataRow in detailTable.Rows) - { - string errorMessage = string.Empty;//数据不符合数据库规范的信息 - StringBuilder fields = new StringBuilder(); - StringBuilder values = new StringBuilder(); - string detailSql = @"insert into " + BillModel.DetailTable + "_temp" + "({0}) values({1})"; - fields.Append("sysstr,"); - values.Append("'" + guid + "',"); - - foreach (DataColumn item in BillColumns.Columns) - { - //GridColumn col = this.gcMain.GridView.VisibleColumns.OfType().FirstOrDefault(x => x.FieldName == item.ColumnName); - //if (col == null) - //{ - // continue; - //} - if (item.ColumnName.Equals(guidField) || item.ColumnName.Equals(mRecordPrimaryField) || item.ColumnName.Equals(ERPInfo.Instance.isAddRows)) continue; - if (!BillTempColumns.Columns.Contains(item.ColumnName)) - { - string type = "varchar(100)"; - if (item.DataType == typeof(DateTime)) - { - type = "datetime"; - } - BaseImpl.ExecSqlValue(string.Format("alter table {0} add {1} {2}", BillModel.DetailTable + "_temp", item.ColumnName, type)); - } - - if (this.BillModel.DetailTreeTable) - { - TreeListColumn[] TreeListColumns = (this.gcMain as TreeGridControlEx).TreeListObj.Columns.Cast().Where(x => x.FieldName.Equals(item.Caption, StringComparison.OrdinalIgnoreCase)).ToArray(); - if (TreeListColumns.Count() == 0 && item.Caption.Equals(BillModel.PrimaryDetailKey)) - { - string primaryValues = dataRow[BillModel.PrimaryDetailKey] + ""; - if (!string.IsNullOrWhiteSpace(primaryValues)) - { - fields.Append(item.ColumnName + ","); - values.Append("N'" + primaryValues.Replace("'", "''") + "',"); - } - } - if (TreeListColumns.Count() == 0) continue; - } - else - { - GridColumn[] gridColumns = gcMain.GridView.Columns.Cast().Where(x => x.FieldName.Equals(item.Caption, StringComparison.OrdinalIgnoreCase)).ToArray(); - - if (gridColumns.Count() == 0 && item.Caption.Equals(BillModel.PrimaryDetailKey)) - { - string primaryValues = dataRow[BillModel.PrimaryDetailKey] + ""; - if (!string.IsNullOrWhiteSpace(primaryValues)) - { - fields.Append(item.ColumnName + ","); - values.Append("N'" + primaryValues.Replace("'", "''") + "',"); - } - } - if (gridColumns.Count() == 0) continue; - } - - - fields.Append(item.ColumnName + ","); - string fieldValue = dataRow.Table.Columns.Contains(item.ColumnName) ? dataRow[item.ColumnName] + "" : string.Empty; - if (addRowList != null && addRowList.Contains(dataRow) && Autogrowcolumn.Equals(item.ColumnName)) - { - fieldValue = ""; - }; - //if (SystemInfo.Instance.TrimWhiteSpace) - // fieldValue = fieldValue.Trim(); - if (item.ColumnName.Equals(BillModel.PrimaryDetailKey, StringComparison.OrdinalIgnoreCase)) - fieldValue = billNo; - if (!string.IsNullOrWhiteSpace(fieldValue)) - { - values.Append(item.DataType == typeof(DateTime) ? "'" + Convert.ToDateTime(fieldValue).ToString("yyyy-MM-dd HH:mm:ss") + "'," : fieldValue.Contains("'") ? "N'" + fieldValue.Replace("'", "''") + "'," : "N'" + fieldValue + "',"); - } - else - { - if (item.DataType == typeof(Decimal) || - item.DataType == typeof(Double) || - item.DataType == typeof(Int16) || - item.DataType == typeof(Int32) || - item.DataType == typeof(Int64)) - values.Append("0,"); - else if (item.DataType == typeof(DateTime)) - { - values.Append("NULL,"); - } - else - { - values.Append("'',"); - - } - - } - errorMessage = errorMessage + DatabaseFormatJudgment.SaveOrModifyBalidation(_detailColumns, DetailedProperties, dataRow, item, fieldValue); - - //SaveErrorMessage = SaveErrorMessage +(string.IsNullOrWhiteSpace(DatabaseFormatJudgment.SaveOrModifyBalidation(_detailColumns, DetailedProperties, dataRow, item, fieldValue))?"":); - } - - - - detailBuilder.AppendFormat(detailSql, fields.ToString().Trim(','), values.ToString().Trim(',')); - if (!string.IsNullOrWhiteSpace(errorMessage)) errorMessage = "第" + lineNumber + "行:" + errorMessage; - SaveErrorMessage = SaveErrorMessage + errorMessage; - lineNumber++; - } - } - return detailBuilder; - } - /// - /// 说明:保存单据 - /// 创建人:龚宇超 - /// 创建日期:2018-04-20 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// 是否继续执行(0.1). - /// 是否显示成功提示信息 - /// true if XXXX, false otherwise. - private bool BillSave(int comfirm = 0, bool canTipMsg = true) - { - bool saveResult = false; - - if (this.gridEx != null) - { - DataRow[] modifiedRows = (this.gridEx.GridControlObj.GridControl.DataSource as DataTable) - .Rows - .Cast() - .Where(x => x.RowState == DataRowState.Modified || x.RowState == DataRowState.Added) - .ToArray(); - if (modifiedRows != null && modifiedRows.Length >0) - { - this.gridEx.isSuccessfullySaved = false; - this.gridEx.BtnSave.PerformClick(); - if (!this.gridEx.isSuccessfullySaved) return false; - } - - } - - if (this.ControlObj.VerifyNull()) - { - //保存前执行某个右键 - if (!string.IsNullOrEmpty(BillModel.BeforeBillSaveExec)) - { - DataRow menuRow = BaseModuleImpl.GetBaseGridRightMenuById(BillModel.BeforeBillSaveExec); - if (menuRow != null) - { - #region 特殊处理 - string movepage = (this.ControlObj.ReplaceControlValue("{qms_maddf_addMode}").Equals("6")) ? "-9998" : "-9999"; - DataTable table = gcMain.gridControl.DataSourceTable(); - ControlModel modeControlModel = ControlObj.ControlModels.Where(n => n.LabelText.Equals("上传模式")).FirstOrDefault(); - string addMode = ControlObj.GetControlValue(modeControlModel); - if (modeControlModel != null && table.Columns.Contains("qms_laddf_mode")) - { - foreach (DataRow item in table.Rows) - { - item["qms_laddf_mode"] = addMode; - } - } - ControlModel speciesNoControlModel = ControlObj.ControlModels.Where(n => n.LabelText.Equals("文件分类")).FirstOrDefault(); - string speciesNo = ControlObj.GetControlValue(speciesNoControlModel); - if (speciesNoControlModel != null && table.Columns.Contains("BomAddSpeciesNo")) - { - foreach (DataRow item in table.Rows) - { - item["BomAddSpeciesNo"] = speciesNo; - } - } - #endregion - CommonMenu menu = new CommonMenu(this.SysModel, this.ControlObj, this.gcMain); - menu.ApplyBefore += new CommonToolApplyEventHandler(OnMenuApplyBefore); - menu.DynamicLinkAfter += new CommonToolAfterDynamicLinkEventHandler(OnDynamicLinkAfter); - StaticControl.RightMenuGridView = gcMain.GridView; - StaticControl.RightMenuMyControl = ControlObj; - menu.Apply(menuRow); - if (!menu.issuccess) - { - return false; - } - } - } - //虚构一个保存存储过程 - DataTable tvp = new DataTable(); - //更新前进行数据源筛选 - if (DateColumnList.Count > 0) - { - // 创建临时表 - tvp.Columns.Add("lblOrderNo", typeof(string)); // 固定主键 - tvp.Columns.Add("billdocument_id", typeof(string)); // 固定主键 - tvp.Columns.Add("showday", typeof(string)); - tvp.Columns.Add("amount", typeof(decimal)); - - // 获取主数据源 - DataTable mainDataSource = gcMain.GridControl.DataSourceTable(); - if (mainDataSource.Columns.Contains(BillModel.DetailUUIDKey)) - { - // 遍历主数据源 - foreach (DataRow row in mainDataSource.Rows) - { - if (row.RowState == DataRowState.Modified || row.RowState == DataRowState.Added) - { - // 提取 billdocument_id - string key = row[BillModel.DetailUUIDKey].ToString(); - if (!string.IsNullOrEmpty(key)) - { - // 遍历列并处理虚拟列 - foreach (GridColumn col in DateColumnList) - { - // 检查值是否发生变化 - bool isVerifyupd = true; - if (row.RowState == DataRowState.Modified) - { - object originalValue = row[col.FieldName, DataRowVersion.Original]; - object currentValue = row[col.FieldName, DataRowVersion.Current]; - isVerifyupd = !object.Equals(originalValue, currentValue); - } - - if (isVerifyupd) - { - // 解析金额 - decimal newAmount = 0m; - if (row[col.FieldName] != DBNull.Value && !string.IsNullOrWhiteSpace(row[col.FieldName].ToString())) - { - decimal.TryParse(row[col.FieldName].ToString(), out newAmount); - } - // 插入数据到临时表 - DataRow dr = tvp.NewRow(); - dr["billdocument_id"] = key; - dr["showday"] = col.FieldName; //列名如 "2025-03-06" - dr["amount"] = newAmount; - tvp.Rows.Add(dr); - } - } - } - } - } - } - } - //记录表格状态 - List addRowList = new List(); - DataTable sourceTable = gcMain.GridControl.DataSourceTable(); - foreach (DataRow dataRow in sourceTable.Rows) - { - if (dataRow.RowState == DataRowState.Added) - { - addRowList.Add(dataRow); - } - } - // 保存之前先进行表格更新 - if (this.BillModel.DetailTreeTable) - { - (this.gcMain as TreeGridControlEx).TreeListObj.PostEditor(); - //(this.gcMain as TreeGridControlEx).TreeListObj.UpdateCurrentRow(); - } - else - { - this.gcMain.GridView.PostEditor(); - this.gcMain.GridView.UpdateCurrentRow(); - } - - - try - { - if (this.gcMain.VerifyNull()) - { - if (this.gcMain.RepeatedVerificationNames.Count > 0 && this.gcMain.VerifyDuplicateColumns()) - { - MessageUtil.Show("表格中数据内容重复,保存失败!"); - return saveResult; - } - - - WaitForm.ShowForm(ResourceKeys.DataSaving); - string billNo = this.lblOrderNo.Text.Trim(); - string detailGuid = Guid.NewGuid().ToString(); - - string masterSql = BillModel.SaveState ? GetUpdateRecord(billNo) : GetAddRecord(ref billNo); - string detailSql = GetDetailRecord(detailGuid, billNo, addRowList).ToString(); - - // 检查单据头数据合法性 - if (string.IsNullOrEmpty(masterSql)) return false; - - // 验证明细合法性 - if (string.IsNullOrEmpty(detailSql) && !this.BillModel.SaveNullDetail) - { - MessageUtil.Show(ResourceKeys.BillDetailIsNotNull); - return false; - } - - - string tipMsg = string.Empty; - int result = BillImpl.BillSave(masterSql, detailSql, BillModel.DetailTable, ref billNo, detailGuid, BillModel.BillSeq, BillModel.SaveState ? 2 : 1, comfirm, out tipMsg, 0, this.BillModel.NewVer); - WaitForm.HideForm(); - switch (result) - { - case 1: - // 保存成功 - if (canTipMsg) MessageUtil.Show(BillModel.TypeName + ResourceKeys.SaveSuccess); - #region 单据保存成功调用Api接口 - if (ApiHelper.IsExecEventApi(Interface.Api.OperateEvent.AfterModuleDataChange, this.SysModel.ModuleCode, 0)) - { - ApiHelper apiHelper = new ApiHelper(this.SysModel.ModuleCode, billNo, BillModel.PrimaryKey, BillModel.MasterTable, 0); - switch (BillModel.SaveState) - { - case false: - apiHelper.OnEvent(Interface.Api.OperateEvent.AfterModuleDataChange, Interface.Api.ActionType.Add);//添加 - break; - case true: - apiHelper.OnEvent(Interface.Api.OperateEvent.AfterModuleDataChange, Interface.Api.ActionType.Update);//更新 - break; - } - if (!string.IsNullOrEmpty(apiHelper.apiResutMsg) && canTipMsg) - MessageUtil.Show(apiHelper.apiResutMsg); - } - #endregion - this.lblOrderNo.Text = billNo; - this.SetBillStatus(BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, billNo))); - saveResult = true; - RefreshPrindMenu(); - //保存完成后所有数据源进行拼接执行保存 - if (tvp != null && tvp.Rows.Count > 0) - { - if (gcMain.jhrowitem != null) - { - // 插入数据到临时表 - DataRow dr = tvp.NewRow(); - dr["lblOrderNo"] = billNo; - dr["billdocument_id"] = "计划文件" + gcMain.jhrowitem.ToJsonObject(); - if (DateColumnList.Count > 0 && DateColumnList[0].Tag is DateTime dateTime) - { - dr["showday"] = dateTime.ToString("yyyy-MM-dd"); //日期 - } - tvp.Rows.Add(dr); - - } - foreach (DataRow item in tvp.Rows) - { - item["lblOrderNo"] = billNo; - } - - // 调用存储过程保存变更数据 - string msg; - int ret = SaveDayPlanChanges(tvp, out msg); - OnGcMainDataSourceChanged(gcMain.GridView, null);//手动刷新日期合计数据源 - } - break; - case 9: - // 继续执行保存 - if (string.IsNullOrWhiteSpace(tipMsg)) tipMsg = "保存单据临时表失败"; - if (MessageUtil.Show(tipMsg, MessageBoxButtons.YesNo) == DialogResult.Yes) - this.BillSave(1, canTipMsg); - saveResult = true; - break; - default: - // 保存失败 - SaveErrorMessage = SaveErrorMessage + "\r\n" + "出错原因:\r\n" + tipMsg; - MessageUtil.Show(BillModel.TypeName + ResourceKeys.SaveFault + "\r\n" + SaveErrorMessage); - SaveErrorMessage = string.Empty; - - if (tipMsg.Contains("ruleid") && false) - { - string ruleid = tipMsg.Split(',')[0].Replace("ruleid", "").Replace("=", "").Trim(); - string sql = string.Format("select * from p_systembusinesslogictab where id = '{0}'", ruleid); - string rulesModid = string.Empty; - string rulesParam = this.ControlObj.ReplaceParentControlValue(ReplaceHelper.ReplaceUserInfo("")); - - } - - if (tipMsg.StartsWith("@") && false) - { - //根据tipMsg中数据找到pMenu中对应的右键 - foreach (BarItemLink itemLink in pMenu.ItemLinks) - { - if (false) - { - ErrorRestriction errorRestriction = new ErrorRestriction(tipMsg, this.SysModel, this.ControlObj, itemLink, this.BillModel, this.lblOrderNo.Text.Trim()); - DialogResult drr = errorRestriction.ShowDialog(); - errorRestriction.Dispose(); - } - } - } - break; - } - } - } - catch (Exception ex) - { - - if (string.IsNullOrWhiteSpace(SaveErrorMessage)) - { - MessageUtil.Show(ex.Message); - } - else - { - MessageUtil.Show("保存单据失败!\r\n" + SaveErrorMessage); - } - SaveErrorMessage = string.Empty; - LogHelper.Instance.WriteError(ex); - LogUtil.WriteError("保存单据失败!", ex); - } - finally - { - WaitForm.HideForm(); - } - } - return saveResult; - } - /// - /// 说明:通过配置条件刷新打印菜单 - /// 创建人:王一帆 - /// 创建日期:2020-04-10 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The hint MSG. - /// true if XXXX, false otherwise. - public void RefreshPrindMenu() - { - if (!string.IsNullOrWhiteSpace(BillModel.BillPrintTag)) - { - pMprint.ClearLinks(); - // 打印模版 - DataRow rowItem = this.gcMain.GridView.GetDataRow(this.gcMain.GridView.FocusedRowHandle); - string BillPrintTag = this.ControlObj.ReplaceParentControlValue(BillModel.BillPrintTag); - BillPrintTag = ReplaceHelper.ReplaceRowParam(rowItem, BillPrintTag); - // BillPrintTag = ReplaceHelper.ReplaceParamToValue(BillPrintTag,this.lblOrderNo.Text.Trim()); - string value = MainImpl.GetResult(ReplaceHelper.ReplaceRowParam(rowItem, BillPrintTag)) + ""; - string[] files = value.Split('|'); - for (int i = 0; i < files.Length; i++) - { - string fileName = files[i]; - if (!string.IsNullOrWhiteSpace(fileName)) - { - BarButtonItem itemPrint = new BarButtonItem(); - int index = i + 1; - itemPrint.Caption = files[i].Replace(".rmf", "").Replace(".frx", ""); - itemPrint.Tag = files[i]; - itemPrint.ItemClick += new ItemClickEventHandler(OnPrintItemClick); - pMprint.AddItem(itemPrint); - } - } - } - } - /// - /// 说明:单据提交 - /// 创建人:龚宇超 - /// 创建日期:2017-12-13 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The hint MSG. - /// true if XXXX, false otherwise. - private void BillApply(string hintMsg, int comfirm = 0) - { - try - { - WaitForm.ShowForm(ResourceKeys.Handing); - string tipMsg = string.Empty; - string billNo = this.lblOrderNo.Text.Trim(); - - - int result = BillImpl.BillApply(this.SysModel.ModuleCode, billNo, "", 1, out tipMsg, comfirm); - WaitForm.HideForm(); - switch (result) - { - case 1: - // 提交成功 - if (!this.BillModel.DisableSubmitPrompt) MessageUtil.Show(BillModel.TypeName + ResourceKeys.ApplySuccess); - //this.SetBillStatus(BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, billNo))); - - //提交成功后固定清空 - //this.BillModel.ApplyRefresh - if (true) - { - this.SetBillStatus(null); - this.ControlObj.ResetControlValue(); - } - - #region 提交审核成功后调用API - if (ApiHelper.IsExecEventApi(Interface.Api.OperateEvent.AfterModuleAuditStateChange, this.SysModel.ModuleCode, 0)) - { - ApiHelper apiHelper = new ApiHelper(this.SysModel.ModuleCode, billNo, this.BillModel.PrimaryKey, this.BillModel.MasterTable, 0); - apiHelper.OnEvent(Interface.Api.OperateEvent.AfterModuleAuditStateChange, Interface.Api.ActionType.Submit);//提交 - if (!string.IsNullOrEmpty(apiHelper.apiResutMsg)) - MessageUtil.Show(apiHelper.apiResutMsg); - } - #endregion - #region 提交审核成功后是否直接调用新增 - if (BillModel.IsApplyAferAdd || SystemInfo.Instance.BillNewAfterCommit) - { - this.OnBillAddClick(this.btnBillAdd, null); - //this.btnBillAdd.PerformClick(); - } - #endregion - // 推送消息 - PushHelper push = new PushHelper(billNo, "0", this.SysModel.ModuleCode, "", "", 0); - push.Push_Bill_Oper_Message(); - - break; - case 9: - // 继续执行保存 - if (string.IsNullOrWhiteSpace(tipMsg)) tipMsg = "提交单据失败"; - if (MessageUtil.Show(tipMsg, MessageBoxButtons.YesNo) == DialogResult.Yes) - this.BillApply("", 1); - break; - case 99: - // 继续执行提交 - if (MessageUtil.Show(tipMsg, MessageBoxButtons.YesNo) == DialogResult.Yes) - { - FrmPrompt prompt = new FrmPrompt(tipMsg); - prompt.Size = new Size(300, 200); - - DialogResult dialog = prompt.ShowDialog(); - if (dialog == DialogResult.OK) - { - this.BillApply(prompt.PromptMsg); - } - } - break; - default: - // 提交失败 - MessageUtil.Show(BillModel.TypeName + ResourceKeys.ApplyFault + "\r\n" + tipMsg); - break; - } - } - catch - { - throw; - } - finally - { - WaitForm.HideForm(); - } - } - #endregion - - #region 事件相关 - /// - /// 说明:点击空白界面后需要获取焦点 - /// 创建人:王一帆 - /// 创建日期:2020-09-04 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - private void OnMainFocusAfter(object sender, EventArgs e) - { - this.pl_main_center_master.Focus(); - } - /// - /// 说明:打印完成后回调 - /// 创建人:龚宇超 - /// 创建日期:2018-07-05 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The sender. - /// The e. - private void OnReportPrintAfter(object sender, EventArgs e) - { - //打印完成后添加数据库 - if (_printSaveParams != null && _printSaveParams.Count > 0) - { - int result = BaseModuleImpl.SavePrintRecord(_printSaveParams[0], _printSaveParams[1], _printSaveParams[2], _printSaveParams[3], _printSaveParams[4]); - } - - } - /// - /// 说明: - /// 创建人:龚宇超 - /// 创建日期:2017-11-28 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - private void OnFrmMainKeyDown(object sender, KeyEventArgs e) - { - // 窗口获取按键则表格按键中断.有时间处理 - if (e.Modifiers.CompareTo(Keys.Control) == 0) - { - if (e.KeyCode == Keys.Left) - this.ssc_main_top.Collapsed = true; - if (e.KeyCode == Keys.Right) - this.ssc_main_top.Collapsed = false; - if (e.KeyCode == Keys.Down) - this.ssc_main.Collapsed = true; - if (e.KeyCode == Keys.Up) - this.ssc_main.Collapsed = false; - } - } - - - /// - /// 说明:第一个页签初始化完成刷新数据 - /// 创建人:龚宇超 - /// 创建日期: - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The sender. - /// The instance containing the event data. - private void OnPageDataSourceBindCallBack(object sender, EventArgs e) - { - try - { - MyControl searchControl = sender as MyControl; - XtraTabPage tabPage = pageNumKey[searchControl]; - if (tabPage.TabIndex == 0) return; - BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel; - string searchSql = unionModel.ModelObj.SourceSql; - searchSql = ReplaceHelper.ReplaceUserInfo(searchSql); - searchSql = ReplaceHelper.ReplaceWhereCond(searchSql); - searchSql = unionModel.SearchObj.SetSearchSqlValue(searchSql, true, true); - // 查找FROM子句的位置 - int fromIndex = searchSql.IndexOf("FROM", StringComparison.OrdinalIgnoreCase); - if (fromIndex != -1) - { - // 生成优化后的SQL查询 - string optimizedSql = "SELECT COUNT(*) " + searchSql.Substring(fromIndex); - searchSql = optimizedSql; - } - DataTable dt = MainImpl.GetDataTableResult(searchSql); - if (dt.Rows.Count > 0) tabPage.Text += "(" + dt.Rows[0][0] + "条)"; - } - catch (Exception ex) - { - LogHelper.Instance.WriteError(ex); - LogUtil.WriteError("单据条件绑定失败失败!", ex); - } - } - - - - /// - /// 主表数据源改变时 - /// - /// - /// - private void OnGcMainDataSourceChanged(object sender, EventArgs e) - { - if (DateColumnList.Count > 0 && DateColumnList[0].Tag is DateTime dateTime) - { - string billNo = this.lblOrderNo.Text; - this.gcMain.GridControl.DataSourceChanged -= OnGcMainDataSourceChanged; - DataTable dataTable = gcMain.GridControl.DataSource as DataTable; - if (dataTable != null) - { - //DataTable dataMain = dataTable.Copy(); - //string sqlValue = "select * from RD_worktimetab where 1 = 1"; - //sqlValue = $"{sqlValue} and lblOrderNo = '{billNo}' and showday >= '{dateTime.ToString("yyyy-MM-dd")}'"; - //DataTable dataDayPlan = BaseImpl.GetDataTableResult(sqlValue); - //---------- 查询①:渲染表格排程” ---------- - string sqlExcludePlan = "SELECT * FROM RD_worktimetab WHERE 1 = 1"; - sqlExcludePlan += $" AND lblOrderNo = '{billNo}'"; - sqlExcludePlan += $" AND showday >= '{dateTime:yyyy-MM-dd}'"; - sqlExcludePlan += " AND billdocument_id NOT LIKE N'计划文件%'"; - // 获取结果 - DataTable dataNoPlanFile = BaseImpl.GetDataTableResult(sqlExcludePlan); - // ---------- 查询②:只包含“计划文件” ---------- - string sqlIncludePlan = "SELECT billdocument_id FROM RD_worktimetab WHERE 1 = 1"; - sqlIncludePlan += $" AND lblOrderNo = '{billNo}'"; - sqlIncludePlan += $" AND showday >= '{dateTime:yyyy-MM-dd}'"; - sqlIncludePlan += " AND billdocument_id LIKE N'计划文件%'"; - // 获取结果 - DataTable dataOnlyPlanFile = BaseImpl.GetDataTableResult(sqlIncludePlan); - MergeMainDataWithDayPlan(dataTable, dataNoPlanFile, dateTime); - //若存在缓存计划数据则渲染合计 - if (dataOnlyPlanFile.Rows.Count > 0) - { - string jhrowtiemjson = (dataOnlyPlanFile.Rows[0]["billdocument_id"] + "").Replace("计划文件", ""); - try - { - JObject rowObject = JsonConvert.DeserializeObject(jhrowtiemjson); - JArray jArray = new JArray(); - jArray.Add(rowObject); - DataRow jhrowitem = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(jArray)).Rows[0]; - //渲染计划合计 - gcMain.AddHeadquarters(jhrowitem); - } - catch (Exception) - { - } - } - gcMain.RefreshHeaderColor(); - this.gcMain.GridControl.DataSource = null; - this.gcMain.GridControl.DataSource = dataTable; - } - this.gcMain.GridControl.DataSourceChanged += OnGcMainDataSourceChanged; - } - } - - /// - /// 保存日计划变更数据(批量保存)。 - /// 调用存储过程 usp_MergeDayPlanChanges,将所有变更记录一次性提交到数据库。 - /// 通过 TVP 参数传递数据,同时捕获输出参数 @msg 和返回值。 - /// - /// 包含所有变更记录的 DataTable,必须与 dbo.DayPlanChangeType 定义一致 - /// 输出提示信息,存储过程执行后的返回消息 - /// 存储过程返回值,成功返回 1,失败返回 0 - public int SaveDayPlanChanges(DataTable tvp, out string message) - { - // 创建输出参数 @msg - SqlParameter pMsg = new SqlParameter("@msg", SqlDbType.VarChar, 2000) - { - Direction = ParameterDirection.Output - }; - // 创建返回值参数 @return - SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int) - { - Direction = ParameterDirection.ReturnValue - }; - // 创建 TVP 参数,名称必须与存储过程参数一致 - SqlParameter tvpParam = new SqlParameter("@DayPlanChanges", SqlDbType.Structured) - { - TypeName = "dbo.DayPlanChangeTVP", - Value = tvp - }; - // 构造参数数组 - SqlParameter[] parameters = new SqlParameter[] { tvpParam, pMsg, returnValue }; - // 执行存储过程,此处调用 ExecuteNonQuery 即可,不需要返回数据集 - // 请确保 DBUtil.ExecuteNonQuery 方法能够传递参数并执行存储过程 - BaseImpl.ExecProcedure("usp_MergeDayPlanChanges2025", parameters); - // 获取输出参数 @msg 中的提示信息 - message = pMsg.Value.ToString(); - // 获取存储过程的返回值 - int result = Convert.ToInt32(returnValue.Value); - return result; - } - - /// - /// 计划明细与主数据合并: - /// 1) 按 起算 7 天动态生成列; - /// 2) 把 dataDayPlan 中对应日期的 amount 值填入主表; - /// 3) 计算行级合计写入 “heji” 列。 - /// - private DataTable MergeMainDataWithDayPlan(DataTable dataMain, DataTable dataDayPlan, DateTime startDate) - { - const string rightPrimaryKey = "billdocument_id"; // dataDayPlan 主键 - const string dateField = "showday"; - const string amountField = "amount"; - string topPrimaryKey = BillModel.DetailUUIDKey; // dataMain 主键 - - int dayCount = 0; - BaseUserControl baseUserControl = ControlObj.FindControl("bom_rdm_tianshu"); - if (baseUserControl != null) - { - int.TryParse(baseUserControl.EditText, out dayCount); - } - if (dayCount <= 0) - { - dayCount = 7; - } - DateTime endDate = startDate.AddDays(dayCount); - - // ---------- 1. 预索引 dataDayPlan:billdocument_id -> List ---------- - var dayPlanMap = new Dictionary>(); - foreach (DataRow row in dataDayPlan.Rows) - { - string billId = row[rightPrimaryKey].ToString(); - if (!dayPlanMap.TryGetValue(billId, out var list)) - { - list = new List(); - dayPlanMap[billId] = list; - } - list.Add(row); - } - - // ---------- 2. 为主表添加日期列和合计列 ---------- - for (DateTime d = startDate; d <= endDate; d = d.AddDays(1)) - { - string colName = d.ToString("yyyy-MM-dd"); - if (!dataMain.Columns.Contains(colName)) - dataMain.Columns.Add(colName, typeof(decimal)); - } - if (!dataMain.Columns.Contains("workingsum")) - dataMain.Columns.Add("workingsum", typeof(decimal)); - - // ---------- 3. 预构建填充映射:主键 -> (日期列名, 金额) ---------- - var dataMap = new Dictionary>(); - foreach (DataRow mainRow in dataMain.Rows) - { - string key = mainRow[topPrimaryKey].ToString(); - var inner = new Dictionary(); - dataMap[key] = inner; - - if (dayPlanMap.TryGetValue(key, out var rows)) - { - foreach (DataRow dayRow in rows) - { - if (dayRow[dateField] == DBNull.Value) continue; - - DateTime d = Convert.ToDateTime(dayRow[dateField]); - if (d < startDate || d > endDate) continue; - - string col = d.ToString("yyyy-MM-dd"); - if (!dataMain.Columns.Contains(col)) continue; - - if (decimal.TryParse(dayRow[amountField]?.ToString(), out decimal amt)) - inner[col] = amt; - } - } - } - - // ---------- 4. 一次性填充并计算行合计 ---------- - foreach (DataRow mainRow in dataMain.Rows) - { - string key = mainRow[topPrimaryKey].ToString(); - decimal rowSum = 0m; - - if (dataMap.TryGetValue(key, out var inner)) - { - foreach (var kv in inner) - { - mainRow[kv.Key] = kv.Value; - rowSum += kv.Value; - } - } - - mainRow["workingsum"] = rowSum; // 行汇总 - } - - return dataMain; - } - - /// - /// 构建带日期的数据源 - /// - /// - /// - /// - /// - private void UpdateRowWithDayPlan(DataRow focusedRow, DataTable dataDayPlan, DateTime startDate) - { - string rightPrimaryKey = "billdocument_id"; - string dateField = "showday"; - string amountField = "amount"; - string topPrimaryKey = BillModel.DetailUUIDKey; - - int dayCount = 0; - BaseUserControl baseUserControl = ControlObj.FindControl("bom_rdm_tianshu"); - if (baseUserControl != null) - { - int.TryParse(baseUserControl.EditText, out dayCount); - } - if (dayCount <= 0) - { - dayCount = 7; - } - - DateTime endDate = startDate.AddDays(dayCount); // 计算结束日期 - // **1. 预索引 dataDayPlan 数据(billdocument_id -> 该 key 相关的所有行)** - Dictionary> dayPlanMap = new Dictionary>(); - foreach (DataRow row in dataDayPlan.Rows) - { - string billId = row[rightPrimaryKey].ToString(); - if (!dayPlanMap.ContainsKey(billId)) - { - dayPlanMap[billId] = new List(); - } - dayPlanMap[billId].Add(row); - } - // **2. 预构建主数据的列** - for (DateTime dt = startDate; dt <= endDate; dt = dt.AddDays(1)) - { - string colName = dt.ToString("yyyy-MM-dd"); - if (!focusedRow.Table.Columns.Contains(colName)) - { - focusedRow.Table.Columns.Add(colName, typeof(decimal)); // 确保列存在 - } - } - // **3. 预构建数据填充映射表** - Dictionary> dataMap = new Dictionary>(); - string key = focusedRow[topPrimaryKey].ToString(); - if (!dataMap.ContainsKey(key)) - { - dataMap[key] = new Dictionary(); - } - // **查找 key 关联的时间数据** - if (dayPlanMap.ContainsKey(key)) - { - foreach (DataRow dayRow in dayPlanMap[key]) - { - if (dayRow[dateField] != DBNull.Value) - { - DateTime dayValue = Convert.ToDateTime(dayRow[dateField]); - string colName = dayValue.ToString("yyyy-MM-dd"); - if (dayValue >= startDate && dayValue <= endDate && focusedRow.Table.Columns.Contains(colName)) - { - decimal.TryParse(dayRow[amountField] + "", out decimal amountValue); - dataMap[key][colName] = amountValue; - } - } - } - } - // **4. 一次性填充 DataTable(避免逐行赋值带来的性能问题)** - if (dataMap.ContainsKey(key)) - { - foreach (var col in dataMap[key]) - { - focusedRow[col.Key] = col.Value; - } - } - } - - - - - - - /// - /// 说明:获取查询条件 - /// 创建人:龚宇超 - /// 创建日期:2017-11-22 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The model. - /// The row item. - /// System.String. - protected string GetSearchSql(GridDetailModel model, DataRow rowItem) - { - string fieldName = !string.IsNullOrEmpty(model.UnionParentField) && rowItem.Table.Columns.Contains(model.UnionParentField) ? model.UnionParentField : BillModel.PrimaryKey; - string sqlValue = model.IsReadOnly || model.IsChart ? model.DetailSql : model.SystemModel.MenuSql; - string unioValue = string.Empty; - unioValue = rowItem.Table.Columns.Contains(fieldName) ? rowItem[fieldName] + "" : string.Empty; - if (this.ControlObj != null && string.IsNullOrEmpty(unioValue)) - { - unioValue = !string.IsNullOrEmpty(model.UnionParentField) && this.ControlObj.FindControl(model.UnionParentField) != null ? this.ControlObj.GetControlValue(model.UnionParentField) : unioValue; - } - sqlValue = ReplaceHelper.ReplaceRowParam(rowItem, sqlValue); - sqlValue = this.ControlObj.ReplaceControlValue(sqlValue);//后替换主表内容 - if (ReplaceHelper.IsSelect(sqlValue) && !string.IsNullOrEmpty(model.UnionValue)) - { - sqlValue = ReplaceHelper.ReplaceWhereCond(sqlValue) + string.Format(" and {0}='{1}'", model.UnionValue, unioValue); - } - if (!string.IsNullOrEmpty(model.UnionCond)) - { - string UnionCond = ReplaceHelper.ReplaceRowParam(rowItem, model.UnionCond); - sqlValue += UnionCond; - } - return sqlValue; - } - - - - /// - /// 说明:单据空行新增时初始化默认值 - /// 创建人:dl - /// 创建日期:2019-01-29 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - private void OnGridViewInitNewRow(object sender, InitNewRowEventArgs e) - { - GridView view = sender as DevExpress.XtraGrid.Views.Grid.GridView; - DataTable gridTable = (this.gcMain.GridControl.DataSource as DataTable).TrimDeleteRows(); - DataRow tmpRow = view.GetDataRow(e.RowHandle); - GridColumnCollection gridColumns = view.Columns; - //gridTable.Rows.Add(tmpRow); - int position = gridTable.Rows.Count; - foreach (GridColumn col in gridColumns) - { - GridColumnModel model = col.Tag as GridColumnModel; - if (model == null) - { - continue; - } - string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue); - - if (model.DefaultValue.Contains("{#")) - { - fieldValue = this.ControlObj.ReplaceParentControlValue(model.DefaultValue); - if (!string.IsNullOrEmpty(fieldValue)) - { - tmpRow[col.FieldName] = fieldValue; - view.SetFocusedRowCellValue(col, fieldValue); - } - } - else if (!string.IsNullOrEmpty(model.DefaultValue)) - { - - tmpRow[col.FieldName] = fieldValue; - view.SetFocusedRowCellValue(col, fieldValue); - - if (model.DefaultValue.Contains("{ROW")) - { - if (position > 0) - { - - fieldValue = ReplaceHelper.GetParamFields(model.DefaultValue)[0]; - fieldValue = fieldValue.Replace("}", "").Replace("{", ""); - fieldValue = fieldValue.Substring(fieldValue.IndexOf('_') + 1); - string topFieldValue = gridTable.Rows[position - 1][fieldValue] + ""; - if (gridTable.Columns[model.FieldName].DataType == typeof(DateTime)) - { - if (!string.IsNullOrEmpty(topFieldValue)) - { - tmpRow[model.FieldName] = Convert.ToDateTime(topFieldValue); - view.SetFocusedRowCellValue(col, topFieldValue); - } - } - else - { - tmpRow[model.FieldName] = topFieldValue; - view.SetFocusedRowCellValue(col, topFieldValue); - } - } - } - else - { - tmpRow[model.FieldName] = fieldValue; - view.SetFocusedRowCellValue(col, fieldValue); - } - - } - } - //设置序号 - gridTable.OrderBy(this.BillModel.DetailOrderField, false); - //设置当前行序号 - if (gridTable != null && gridTable.Rows.Count > 0 && !string.IsNullOrEmpty(this.BillModel.DetailOrderField) && gridTable.Columns.Contains(this.BillModel.DetailOrderField)) - { - bool getMaxIndex = int.TryParse(gridTable.Rows.Cast().Max(n => n[this.BillModel.DetailOrderField]) + "", out int maxIndex); - if (getMaxIndex) - { - tmpRow[this.BillModel.DetailOrderField] = maxIndex + 1; - } - } - if (gridTable.Columns.Contains(this.BillModel.DetailOrderField) && gridTable.Rows.Count == 0) - { - tmpRow[this.BillModel.DetailOrderField] = 1; - } - //this.gcMain.GridView.UpdateCurrentRow(); - //this.gcMain.GridView.ShowEditor(); - } - /// - /// 说明:右键菜单执行后刷新数据,刷新规则按照上一次查询条件刷新 - /// 创建人:龚宇超 - /// 创建日期:2017-11-02 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The sender. - /// The instance containing the event data. - private void OnGridViewRightCallBack(object sender, EventArgs e) - { - string billNo = this.lblOrderNo.Text.Trim(); - this.SetBillStatus(BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, billNo))); - } - /// - /// 说明:重绘单据水印 - /// 创建人:龚宇超 - /// 创建日期:2017-12-04 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - private void OnLabelTitlePaint(object sender, PaintEventArgs e) - { - if (this._waterMark != null) - { - GraphicsText graphicsText = new GraphicsText(); - graphicsText.Graphics = e.Graphics; - - // 绘制围绕点旋转的文本 - StringFormat format = new StringFormat(); - format.Alignment = StringAlignment.Center; - format.LineAlignment = StringAlignment.Center; - - // 绘制单据状态文本 - if (!string.IsNullOrEmpty(this._waterMark.Text)) - { - graphicsText.DrawString(this._waterMark.Text, new Font("宋体", 12, FontStyle.Bold), new SolidBrush(Color.Red), new PointF(50, 21), format, -15f); - - e.Graphics.TranslateTransform(0, 0); - e.Graphics.RotateTransform(-15f); - e.Graphics.DrawRectangle(new Pen(Color.Red, 2f), new Rectangle(14, 20, 55, 21)); - } - - // 绘制打印次数文本 - e.Graphics.ResetTransform(); - if (!string.IsNullOrEmpty(this._waterMark.Print)) - { - graphicsText.DrawString(this._waterMark.Print, new Font("宋体", 11, FontStyle.Bold), new SolidBrush(Color.Red), new PointF((this.lbTitle.Width - 70), 21), format, -15f); - - e.Graphics.TranslateTransform(this.lbTitle.Width - 70, 21); - e.Graphics.RotateTransform(-15f); - e.Graphics.DrawRectangle(new Pen(Color.Red, 2f), new Rectangle(-35, -14, 70, 21)); - } - - // 绘制收款文本 - e.Graphics.ResetTransform(); - if (!string.IsNullOrEmpty(this._waterMark.Collect)) - { - graphicsText.DrawString(this._waterMark.Collect, new Font("宋体", 12, FontStyle.Bold), new SolidBrush(Color.Red), new PointF((this.lbTitle.Width - 170), 21), format, -15f); - - e.Graphics.TranslateTransform(this.lbTitle.Width - 100, 21); - e.Graphics.RotateTransform(-15f); - e.Graphics.DrawRectangle(new Pen(Color.Red, 2f), new Rectangle(-100, -32, 55, 21)); - } - } - } - - - - - /// - /// 说明:新增单据 - /// 创建人:龚宇超 - /// 创建日期:2017-12-14 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - private void OnBillAddClick(object sender, EventArgs e) - { - if (!this.BillModel.SaveState && this.gcMain.DataRowCount() > 0) - { - DialogResult result = MessageUtil.Show(("数据未保存,是否确定新建单据?"), MessageBoxButtons.YesNo); - if (result == DialogResult.Yes) - { - this.SetBillStatus(null); - this.ControlObj.ResetControlValue(this.BillModel.ManuallyTriggerCorrelation, true); - } - } - else - { - this.SetBillStatus(null); - this.ControlObj.ResetControlValue(this.BillModel.ManuallyTriggerCorrelation, true); - } - if (ScanCodeTextEdit != null) ScanCodeTextEdit.Focus(); - } - - /// - /// 关闭时判断是否存在为保存新增单据 - /// - /// - public bool closeTheJudgment() - { - //if(this.ControlObj.VerifyUpdated()) - if (!this.BillModel.SaveState && this.gcMain.DataRowCount() > 0) - { - return true; - } - return false; - - } - - - /// - /// 说明:删除明细记录 - /// 创建人:龚宇超 - /// 创建日期:2017-12-05 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - private void OnDeleteClick(object sender, EventArgs e) - { - try - { - //树表格删除 - if (this.BillModel.DetailTreeTable) - { - string deleteCond = this.ControlObj.ReplaceParentControlValue(BillModel.DeleteDetailCond); - (this.gcMain as TreeGridControlEx).DeleteSelectedRows(deleteCond); - return; - } - - - - int[] rows = this.gcMain.GridView.GetSelectedRows(); - if (rows.Length < 1) - return; - - DataTable dt = this.gcMain.GridView.GetGridViewFilteredAndSortedDataToDataTable(); - - - if (string.IsNullOrEmpty(BillModel.DeleteDetailCond)) - { - DialogResult result = MessageUtil.Show(string.Format(ResourceKeys.DeleteRows, rows.Length), MessageBoxButtons.YesNo); - if (result == DialogResult.Yes) - { - //保存删除的行和对应的行号 - //撤销多次 - Dictionary undo = new Dictionary(); - for (int i = 0; i < rows.Length; i++) - { - DataRow rowItem = this.gcMain.GridView.GetDataRow(rows[i]); - DataRow dr = dt.NewRow(); - dr.ItemArray = rowItem.ItemArray; - undo.Add(rows[i], dr); - } - ToWithdrawRows.Add(undo); - this.gcMain.GridView.Columns.ClearAllSort(); - this.gcMain.GridView.DeleteSelectedRows(); - this.gcMain.GridView.ClearSelection(); - this.gcMain.GridView.SelectRow(this.gcMain.GridView.FocusedRowHandle); - this.gcMain.GridControl.DataSourceTable().OrderBy(this.BillModel.DetailOrderField); - } - } - else - { - string successMsg = string.Empty, faultMsg = string.Empty; - string deleteCond = this.ControlObj.ReplaceParentControlValue(BillModel.DeleteDetailCond); - List deleteRows = new List(); - List faultInts = new List(); - //ToWithdrawRows.Clear();//清空上一次记录的删除行 - Dictionary undo = new Dictionary(); - - foreach (int rowIndex in rows) - { - DataRow rowItem = this.gcMain.GridView.GetDataRow(rowIndex); - - string deleteCond2 = ReplaceHelper.ReplaceRowParam(rowItem, deleteCond); - - if (ReplaceHelper.EvalCond(deleteCond2)) - { - deleteRows.Add(rowItem); - DataRow dr = dt.NewRow(); - dr.ItemArray = rowItem.ItemArray; - undo.Add(rowIndex, dr); - - } - else - { - faultInts.Add(rowIndex); - } - } - ToWithdrawRows.Add(undo); - DataTable table = this.gcMain.GridControl.DataSourceTable(); - foreach (DataRow item in deleteRows) - { - table.Rows.Remove(item); - } - - if (faultInts != null && faultInts.Count > 0) - { - MessageUtil.Show("发现如下:" + string.Join(",", faultInts.ToArray()) + "行不满足条件无法删除!"); - } - else - { - MessageUtil.Show("删除成功!"); - } - } - if (ScanCodeTextEdit != null) ScanCodeTextEdit.Focus(); - return; - } - catch (Exception ex) - { - LogHelper.Instance.WriteError(ex); - } - - } - - - - /// - /// 说明:单据保存 - /// 创建人:龚宇超 - /// 创建日期:2017-12-07 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - private void OnBillSaveClick(object sender, EventArgs e) - { - try - { - if (this.BillSave()) - { - ToWithdrawRows.Clear(); - } - if (ScanCodeTextEdit != null) ScanCodeTextEdit.Focus(); - } - catch (Exception ex) - { - MessageUtil.Show(ex); - } - } - /// - /// 说明:单据保存提交 - /// 创建人:龚宇超 - /// 创建日期:2017-12-07 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - private void OnBillApplyClick(object sender, EventArgs e) - { - try - { - DialogResult result = MessageUtil.Show(ResourceKeys.BillApply, MessageBoxButtons.YesNo); - if (result == DialogResult.Yes) - { - if (this.BillSave(0, false)) - { - ToWithdrawRows.Clear(); - this.BillApply(""); - } - } - if (ScanCodeTextEdit != null) ScanCodeTextEdit.Focus(); - return; - } - catch (Exception ex) - { - MessageUtil.Show(ex); - } - - } - /// - /// 说明:分割条移动保存位置 - /// 创建人:龚宇超 - /// 创建日期:2018-03-06 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - private void OnTopSplitterMoved(object sender, EventArgs e) - { - if (this._isInitFinish)// 是否为初始化创建 - { - IniHelper.Write(string.Format("bill_width_{0}", this.SysModel.ModuleCode), this.ssc_main_top.SplitterPosition + ""); - } - } - /// - /// 说明:分割条移动保存位置 - /// 创建人:龚宇超 - /// 创建日期:2018-03-06 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. + /// + /// 说明:初始化系统配置 + /// 创建人:龚宇超 + /// 创建日期:2017-11-27 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + private void InitializeSetting() + { + Dictionary dataCaches = SysModel != null ? SysModel.DataCaches : null; + if (!dataCaches.GetValue(this, "BillInfo", out DataRow modelRow)) + { + modelRow = BillImpl.GetBillInfo(this.SysModel.ModuleCode);//获取单个模块信息 + } + if (modelRow == null) + { + //MessageUtil.Show("模块编号[" + this.SysModel.ModuleCode + "],配置错误!\r\n该模块信息未找到!"); + //return; + throw new Exception("模块编号[" + this.SysModel.ModuleCode + "],配置错误!\r\n该模块信息未找到!"); + } + if (!dataCaches.GetValue(this, "BillModel", out BillModel)) + { + this.BillModel = new BillModel(modelRow);//初始化类的新实例。 + } + + if (this.BillModel != null) + { + this.BillModel.TypeName = string.IsNullOrEmpty(SysModel.BillMasterSql) ? this.SysModel.FormText : this.BillModel.TypeName;// 模块名称 + if (!dataCaches.GetValue(this, "MasterPreFix", out string masterPreFix)) + { + masterPreFix = BaseImpl.GetColumnPrefix(this.BillModel.MasterTable);// 主表列前缀 + } + this.BillModel.MasterPreFix = masterPreFix; + if (!dataCaches.GetValue(this, "DetailPreFix", out string detailPreFix)) + { + detailPreFix = BaseImpl.GetColumnPrefix(this.BillModel.DetailTable);// 明细表列前缀 + } + this.BillModel.DetailPreFix = detailPreFix; + this.BillModel.DetailOrderField = this.BillModel.DetailPreFix + "lsidx_id";// 单据来源id + if (SystemInfo.Instance.IsNotBillDetailOrder)//禁用排序 + this.BillModel.DetailOrderField = string.Empty; + } + if (!dataCaches.GetValue(this, "MenuConfigTab", out DataRow menuRow)) + { + menuRow = BaseImpl.GetMenuConfigTab(this.SysModel.ModuleId);//获取菜单其他配置 + } + if (menuRow != null) + { + this.BillModel.BillSourceIds = menuRow.Table.Columns.Contains("BillSourceIds") ? (menuRow["BillSourceIds"] + "").Trim(',') : string.Empty; + this.BillModel.BillFlag = menuRow.Table.Columns.Contains("BillFlag") && !string.IsNullOrEmpty(menuRow["BillFlag"] + "") ? Convert.ToInt32(menuRow["BillFlag"] + "") : -1; + } + + //获取打印其他参数 + GetPrintOtherParam(); + if (!dataCaches.GetValue(this, "BillSetting", out bool _)) + { + BillImpl.InitBillSetting(this.BillModel); + } + + if (this.BillModel.IsBrp) + { + this.MainBottomInputObj.Visible = false; + this.MainBottomTempleteObj.Visible = true; + } + + //显示筛选行 + if (this.BillModel.LoadFilter) this.gcMain.GridView.OptionsView.ShowAutoFilterRow = true; + //树表格 + if (this.BillModel.DetailTreeTable) + { + this.pl_main_center_detail.Controls.Clear(); + this.gcMain = new TreeGridControlEx(); + this.gcMain.Dock = DockStyle.Fill; + this.pl_main_center_detail.Controls.Add(this.gcMain); + (this.gcMain as TreeGridControlEx).Expansion = this.BillModel.DetailTreeTableExpansion; + (this.gcMain as TreeGridControlEx).AddRightButton(); + //节点编号 + (this.gcMain as TreeGridControlEx).TreeListObj.KeyFieldName = "tap_id"; + //父节点编号 + (this.gcMain as TreeGridControlEx).TreeListObj.ParentFieldName = "tap_pid"; + (this.gcMain as TreeGridControlEx).SortField = this.BillModel.DetailOrderField; + + (this.gcMain as TreeGridControlEx).InitializedragState(); + } + + + } + /// + /// 说明:初始化分配关联模块 + /// 创建人:王一帆 + /// 创建日期:2020-02-18 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + private void InitializeUnionCode() + { + if (this.BillModel.PopupUnionCode.Contains(",")) + { + string[] UnionCodeSplit = this.BillModel.PopupUnionCode.Split(','); + if (UnionCodeSplit.Length >= 1) + { + this.BillModel.PopupUnionCode = this.BillModel.BillFlag == 1 ? UnionCodeSplit[1] + "" : UnionCodeSplit[0] + ""; + rdBlueUnionCode = UnionCodeSplit[0] + ""; + rdRedUnionCode = UnionCodeSplit[1] + ""; + } + } + else + { + rdBlueUnionCode = rdRedUnionCode = this.BillModel.PopupUnionCode; + } + } + /// + /// 说明:初始化控件 + /// 创建人:龚宇超 + /// 创建日期:2017-11-23 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + private void InitializeControl() + { + if (this.IsBrpTemplete || this.BillModel.IsBrp)// 是否为Brp模版 + this.InitializeTemplete(); + + this.InitializeStatus();//初始化红蓝字单 + this.InitializeOper();//初始化常用操作等功能 + this.InitializeBillInfo();//初始化单据控件信息 + this.InitializeModuleGridex(); + } + + /// + /// 初始化右侧表格 + /// + private void InitializeModuleGridex() + { + gridExModel = new DynamicModel(new string[] { "", ERPInfo.Instance.UserId, ERPInfo.Instance.UserName, this.SysModel.Privilege, this.BillModel.RightModuleCode, "0" }); + DataRow moduleInformation = MainImpl.GetSystemdllTab(this.BillModel.RightModuleCode); + if (moduleInformation == null) + { + MessageUtil.Show("没有找到编号为" + this.BillModel.RightModuleCode + "的模块信息"); + return; + } + ModuleModel model = new ModuleModel(moduleInformation); + this.gridEx = new ModuleGridEx(); + model.ParmaryKey = BaseImpl.GetBasePrimaryKey(this.BillModel.RightModuleCode); + gridEx.OnSaveGridCallBack += OnDetailSaveGridCallBack; + gridEx.DetailRightGridCallBack += OnDetailRightCallback; + gridEx.Name = "gridEx"; + gridEx.IsDetail = true; + gridEx.Dock = DockStyle.Fill; + gridEx.OperShortMode = false; // 不显示简短模式 + gridEx.VisibleSearchPanel = false; + gridEx.VisibleOperPanel = true; + gridEx.InitializeControl(model, gridExModel); + gridEx.GridControlObj.Tag = model;//都在本地图可留着备用 + //gridEx.ParentControlEx = this.gcMain; + gridEx.ParentControlObj = this.ControlObj; + gridEx.ParentGridEx = this.gcMain;//父级关联明细可扩展 + //gridEx.ParentKeyField = string.IsNullOrEmpty(model.UnionParentField) ? model.SystemModel.ParmaryKey : model.UnionParentField; + //gridEx.DetailKeyField = model.UnionValue;//新增关联可拖拽刷新数据源 + + gridEx.VisibleSearchPanel = false; + gridEx.ObjPanel.Enabled = false; + gridEx.GridControlObj.ParentControl = gridEx.SearchObj; + this.splitMainControl.Panel2.Controls.Add(gridEx); + gridEx.SearchObj.SearchGrid(); + + gridEx.ObjPanel.Height = 46; + List deleteControls = new List(); + foreach (System.Windows.Forms.Control item in gridEx.ObjPanel.Controls) + { + if (item.Name.Equals("dpbTools") || item.Name.Equals("btnUpdate") || item.Name.Equals("btnImport") || item.Name.Equals("btnExport") || item.Name.Equals("btnPrint")) + { + deleteControls.Add(item); + } + } + foreach (System.Windows.Forms.Control item in deleteControls) + { + gridEx.ObjPanel.Controls.Remove(item); + } + int j = 0, x = 72; + foreach (System.Windows.Forms.Control item in gridEx.ObjPanel.Controls) + { + item.Location = new Point(gridEx.ObjPanel.Width - x - 10, (gridEx.ObjPanel.Height - item.Height) / 2); + item.Anchor = AnchorStyles.Top | AnchorStyles.Right; + x += 79; + j++; + } + } + + #region 衍生表格数据操作 + private void OnDetailRightCallback(object sender, EventArgs e) + { + + } + private void OnDetailSaveGridCallBack(object sender, EventArgs e) + { + + } + + #endregion + + + /// + /// 说明:初始化红蓝字单 + /// 创建人:龚宇超 + /// 创建日期:2017-11-27 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + private void InitializeStatus() + { + // 初始化红、蓝单 + if (this.BillModel.BillFlag == 0) + { + this.rdBlue.Checked = true; + this.rdRed.Checked = false; + this.lbTitle.ForeColor = Color.Blue; + this.pl_red.Visible = false; + } + if (this.BillModel.BillFlag == 1) + { + this.rdRed.Checked = true; + this.rdBlue.Checked = false; + this.lbTitle.ForeColor = Color.Red; + this.pl_blue.Visible = false; + } + + + if (this.SysModel.HasReadPrivilege()) + this.pl_main_bottom.Enabled = false; + this.ssc_main_top.SplitterPosition = this.BillModel.PanelWidth; + InitializeUnionCode();//根据红蓝字段更新分配 + } + /// + /// 说明:初始化常用操作等功能 + /// 创建人:龚宇超 + /// 创建日期:2017-11-27 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + private void InitializeOper() + { + BarButtonItem itemCopyMaster = new BarButtonItem(); + itemCopyMaster.Caption = "复制表头信息"; + itemCopyMaster.ItemClick += new ItemClickEventHandler(OnCopyMasterItemClick); + BarButtonItem itemCopyAll = new BarButtonItem(); + itemCopyAll.Caption = "复制整单信息"; + itemCopyAll.ItemClick += new ItemClickEventHandler(OnCopyAllItemClick); + BarButtonItem itemExport = new BarButtonItem(); + itemExport.Caption = "导出Excel文件"; + itemExport.ItemClick += new ItemClickEventHandler(OnExportItemClick); + BarButtonItem itemFPBatch = new BarButtonItem(); + itemFPBatch.Caption = "批量分配"; + itemFPBatch.ItemClick += new ItemClickEventHandler(OnBtnFPNewClick); + this._itemImport = new BarButtonItem(); + this._itemImport.Caption = "导入Excel文件"; + this._itemImport.ItemClick += new ItemClickEventHandler(OnImportItemClick); + this._itemImportUpdate = new BarButtonItem(); + this._itemImportUpdate.Caption = "导入Excel文件(更新)"; + this._itemImportUpdate.ItemClick += new ItemClickEventHandler(OnImportUpdateItemClick); + + // 复制单据 + this.pmBill.AddItems(new BarItem[] { itemCopyMaster, itemCopyAll }); + // 导入导出 + if (this.BillModel.CanExport && this.BillModel.ExportPermission) + { + this.pmBillExp.AddItem(itemExport); + } + if (this.BillModel.CanImport) + { + this.pmBillExp.AddItems(new BarItem[] { _itemImport, _itemImportUpdate }); + } + //分配 + this.pmFP.AddItems(new BarItem[] { itemFPBatch }); + // 打印模版 + //string[] files = this.BillModel.PrintFile.Split('|'); + //for (int i = 0; i < files.Length; i++) + //{ + // string fileName = files[i]; + // if (!string.IsNullOrWhiteSpace(fileName)) + // { + // BarButtonItem itemPrint = new BarButtonItem(); + // int index = i + 1; + // itemPrint.Caption = files[i].Replace(".rmf", "").Replace(".frx", ""); + // itemPrint.Tag = files[i]; + // itemPrint.ItemClick += new ItemClickEventHandler(OnPrintItemClick); + // pMprint.AddItem(itemPrint); + // } + //} + + // 常用工具 + Dictionary dataCaches = SysModel != null ? SysModel.DataCaches : null; + if (!dataCaches.GetValue(this, "OperBaseGridRightMenus", out DataTable tableCommon)) + { + tableCommon = BaseModuleImpl.GetBaseGridRightMenus(this.SysModel.ModuleCode, ModuleType.BillDetail);//获取右键菜单数据 + } + int j = 0, x = 72; + foreach (DataRow item in tableCommon.Rows) + { + SimpleButton itemCommon = new SimpleButton(); + //itemCommon.Enabled = false; + //itemCommon.AutoSize = true; + itemCommon.Text = item["menuname"] + ""; + itemCommon.Tag = item; + itemCommon.Size = new System.Drawing.Size(72, 26); + itemCommon.Font = new Font("宋体", 9); + itemCommon.Click += new EventHandler(itemCommon_Click); + + itemCommon.Location = new Point(pl_buttom.Width - x - 10, (pl_buttom.Height - itemCommon.Height) / 2); + itemCommon.Anchor = AnchorStyles.Top | AnchorStyles.Right; + pl_buttom.Controls.Add(itemCommon); + x += 79; + if (tableCommon.Columns.Contains("menuCond")) + { + itemCommon.Enabled = ValidateCond(item["menuCond"] + "", null); + } + j++; + } + } + /// + /// 说明:常用工具点击 + /// 创建人:龚宇超 + /// 创建日期:2017-11-27 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + protected void itemCommon_Click(object sender, EventArgs e) + { + try + { + SimpleButton btn = sender as SimpleButton; + DataRow rowItem = btn.Tag as DataRow; + GridRightMenuModel model = new GridRightMenuModel(rowItem); + if (rowItem["dllname"].Equals("Lskj.PubBomImport.dll")) + { + if ((model.ParamList[7] + "").Equals("3")) + { + if (!this.BillSave(0, false)) + { + return; + } + } + } + + //获取红蓝单据 + string DocumentColor = this.rdBlue.Checked ? "0" : this.rdRed.Checked ? "1" : ""; + + + if ((rowItem["orderid"] + "").Equals("999")) + { + string ModuleCode = model.DllParam2; + FrmSource frmSource = new FrmSource(ModuleCode, SysModel, model.MaxWindow, false); + frmSource.PrimaryKey = this.BillModel.PrimaryKey; + frmSource.PrimaryValue = this.lblOrderNo.Text; + frmSource.DocumentColor = DocumentColor; + frmSource.Text = model.MenuName; + if (frmSource.ShowDialog() == DialogResult.OK) + { + this.lblOrderNo.Text = frmSource.ReturnPrimaryValue; + } + this.SetBillStatus(BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, this.lblOrderNo.Text))); + } + else if ((rowItem["orderid"] + "").Equals("888")) + { + string ModuleCode = model.DllParam2; + FrmSource frmSource = new FrmSource(ModuleCode, SysModel, model.MaxWindow, true); + frmSource.PrimaryKey = this.BillModel.PrimaryKey; + frmSource.PrimaryValue = this.lblOrderNo.Text; + frmSource.DocumentColor = DocumentColor; + frmSource.Text = model.MenuName; + if (frmSource.ShowDialog() == DialogResult.OK) + { + this.lblOrderNo.Text = frmSource.ReturnPrimaryValue; + } + this.SetBillStatus(BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, this.lblOrderNo.Text))); + } + else + { + CommonMenu menu = new CommonMenu(this.SysModel, this.ControlObj, this.gcMain); + menu.ApplyBefore += new CommonToolApplyEventHandler(OnMenuApplyBefore); + menu.DynamicLinkAfter += new CommonToolAfterDynamicLinkEventHandler(OnDynamicLinkAfter); + menu.Apply(rowItem); + if (model != null && model.Refresh) + { + string billNo = this.lblOrderNo.Text.Trim(); + this.SetBillStatus(BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, billNo))); + } + } + + + + } + catch (Exception ex) + { + string Message = ErrorMessage.PromptErrorMessage(ex); + MessageUtil.Show(Message, ex.Message); + } + + } + /// + /// 说明:初始化单据控件信息 + /// 创建人:龚宇超 + /// 创建日期:2017-11-27 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + private void InitializeBillInfo() + { + Dictionary dataCaches = SysModel != null ? SysModel.DataCaches : null; + if (!dataCaches.GetValue(this, "ControlLocation", out DataTable controls)) + { + controls = BaseModuleImpl.GetControlLocation(this.BillModel.FormKey, this.SysModel.ModuleCode); + //if (this.BillModel.CenterMain) controls = this.SetControlMargins(controls); + } + if (!dataCaches.GetValue(this, "AddGroupData", out DataTable groups)) + { + groups = BaseModuleImpl.GetAddGroupData(this.BillModel.FormKey);//获取主信息分组数据 + } + if (!dataCaches.GetValue(this, "ControlObj", out ControlObj)) + { + this.ControlObj = new MyControl() { Model = SysModel };//主表控件 + this.ControlObj.OtherParams = this.SysModel.OtherParams(); + if (dataCaches != null) + { + dataCaches.AddTask(this.ControlObj, "DynamicModel", + new Task(() => this.SysModel)); + dataCaches.AddTask(this.ControlObj, "ControlsTable", + new Task(() => controls)); + this.ControlObj.GetControlDataCaches(dataCaches); + } + } + + + + //this.ControlObj = new MyControl();//// 主表控件 + this.ControlObj.OtherParams = this.SysModel.OtherParams(); + this.ControlObj.InitControl(controls, this.pl_main_center_master, groups); + this.ControlObj.refGridLookUpData = this.BillModel.RefGridLookUpData;//2023-3-17,新增单据时刷新下拉框数据源 + this.ControlObj.OnDataFileRefrshCallBack += OnDataFileRefrshFile; + this.ControlObj.OnDataSourceBindCallBack += new EventHandler(OnInitializeHeaderCallBack); + this.pl_main_center_master.Height = (this.BillModel.ParentHeight - 36) > this.pl_main_center_master.Height ? this.pl_main_center_master.Height : this.BillModel.ParentHeight - 36; + this.splitMainControl.Height = this.pl_main_center_master.Height + pl_buttom.Height + 12; + // 初始化明细 + // 创建多表头,默认标准表格 + if (this.SysModel.GridEnumObj == GridEnum.BandedGridView || this.BillModel.AutoMultiHeader == 1) + { + this.pl_main_center_detail.Controls.Clear(); + this.gcMain = new BandedGridControlEx(); + this.gcMain.Model = this.SysModel; + this.gcMain.Dock = DockStyle.Fill; + this.pl_main_center_detail.Controls.Add(this.gcMain); + } + + if (!dataCaches.GetValue(this, "DetailColumns", out _detailColumns)) + { + _detailColumns = BillImpl.GetDetailColumns(this.SysModel.ModuleCode);//初始化单据明细列 + if (this.SysModel.GridEnumObj == GridEnum.BandedGridView || this.BillModel.AutoMultiHeader == 1) + { + //多表头sql要增加一个判断,否则多表头会出错 + _detailColumns = BillImpl.GetDetailColumns(this.SysModel.ModuleCode, true);//初始化单据明细列 + } + } + this.gcMain.DisableFieldSources = this.BillModel.DisableFieldSources; + this.gcMain.Model = this.SysModel; + this.gcMain.ParentControl = this.ControlObj;//把主表控件赋给 单据主表控件、基础档案查询条件控件等等 + this.gcMain.SetEditColumns(_detailColumns, GridCustomColumnStruct.BillDetailGridView + this.BillModel.FormKey);//设置可编辑列 + if (this.BillModel.IsBillMainDetailCheck == 1)//加载明细复选框 + { + GridDragGrid.GridAddCheckBox(this.gcMain.GridView); + } + + if (!dataCaches.GetValue(gcMain, "BaseGridRowColors", out DataTable dtBaseGridRowColors)) + { + dtBaseGridRowColors = BaseModuleImpl.GetBaseGridRowColors("BILLDETAIL_" + this.BillModel.FormKey); + } + this.gcMain.SetGridRowColors(dtBaseGridRowColors); + //触发右键回调 + this.gcMain.OnAfterLinkCilk += OnAfterLinkCilkCall; + if (!dataCaches.GetValue(gcMain, "BaseGridRightMenus", out DataTable dtBaseGridRightMenus)) + { + dtBaseGridRightMenus = BaseModuleImpl.GetBaseGridRightMenus("BILLDETAIL_" + this.SysModel.ModuleCode); + } + if (this.gcMain is BandedGridControlEx)// 判断是不是多表头表格 + { + //设置表格右键菜单 + (this.gcMain as BandedGridControlEx).SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridViewRightCallBack, this.ControlObj); + } + else if (this.BillModel.DetailTreeTable) + { + (this.gcMain as TreeGridControlEx).SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridViewRightCallBack, this.ControlObj, (this.gcMain as TreeGridControlEx).MenuStrip); + (this.gcMain as TreeGridControlEx).TreeListObj.ShowingEditor += new CancelEventHandler(OnGridViewShowingEditor); + } + else + { + this.gcMain.SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridViewRightCallBack, this.ControlObj); + this.gcMain.GridView.ShowingEditor += new CancelEventHandler(OnGridViewShowingEditor); + } + + + if (this.BillModel.DefaultAddEmptyRow) + { + this.gcMain.GridView.OptionsView.NewItemRowPosition = NewItemRowPosition.Bottom; + if (SystemInfo.Instance.IsAddEmptyRowOldTag) + { + this.gcMain.GridView.MouseDown += GridView_MouseDown; + this.gcMain.GridView.FocusedRowChanged += GridView_FocusedRowChanged; + } + else + { + this.gcMain.GridView.InitNewRow += new InitNewRowEventHandler(OnGridViewInitNewRow); + } + + } + //程序若配置扫码框则回车换行 + if (this._detailColumns.Rows.Cast().FirstOrDefault(x => x["fieldsqltag"].ToString() == ControlType.LabSacn + "") != null) + { + this.gcMain.GridView.CellValueChanged += new CellValueChangedEventHandler(OnGridViewCellValueChanged); + } + + this.gcMain.GridControl.DataSourceChanged += OnGcMainDataSourceChanged; + } + + /// + /// 表格触发右键功能 + /// + /// + /// + private void OnAfterLinkCilkCall(object sender, EventArgs e) + { + string unioright = sender + ""; + DataRow rightrowitem = this.gcMain.gridViewRightMenu.MenuTable.Rows.Cast().FirstOrDefault(x => (x["orderid"] + "").Equals(unioright)); + CommonMenu menu = new CommonMenu(this.SysModel, ControlObj, this.gcMain); + menu.Apply(rightrowitem); + } + + /// + /// 说明:数据绑定后判断是否是右键打开模块赋值 + /// 创建人:王一帆 + /// 创建日期:2020-03-27 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + protected void OnInitializeHeaderCallBack(object sender, EventArgs e) + { + // 通过右键菜单打开单据时,判断修改还是新增 + if (!string.IsNullOrEmpty(this.SysModel.BillOrderNo)) + { + // 修改 + string sqlValue = "select * from " + this.BillModel.MasterTable + " where 1=1"; + string sqlCond = string.Format(" and {0}='{1}'", this.BillModel.PrimaryKey, this.SysModel.BillOrderNo); + DataTable masterTable = BillImpl.GetDataTableResult(sqlValue + sqlCond); + + this.SetBillStatus(masterTable.Rows.Count > 0 ? masterTable.Rows[0] : null); + } + else + { + this.SetBillStatus(null); + // 新增 + if (!string.IsNullOrEmpty(this.SysModel.BillMasterSql)) + { + // 处理单据表头数据 + DataRow row = BillImpl.GetDataRowResult(this.SysModel.BillMasterSql); + if (row != null) + { + this.ControlObj.SetAllControlValue(row);//去掉第二个参数true,参数8进入的sql固定不默认赋值 + // 设置Brp模版 + if (this.IsBrpTemplete || this.BillModel.IsBrp) + { + this.SetTempleteSelectedValue(row["brpId"] + ""); + } + } + } + if (!string.IsNullOrEmpty(this.SysModel.BillMasterSql)) + { + // 处理单据明细数据 + if (!this.SysModel.BillDetailSql.StartsWith("*")) this.AddMultiRowToGridView(BillImpl.GetDataTableResult(this.SysModel.BillDetailSql)); + } + } + } + + private void AddDataColumns() + { + foreach (GridColumn gridColumn in gcMain.GridView.Columns) + { + gridColumn.Fixed = DevExpress.XtraGrid.Columns.FixedStyle.Left; + } + int dayCount = 0; + BaseUserControl baseUserControl = ControlObj.FindControl("bom_rdm_tianshu"); + if (baseUserControl != null) + { + int.TryParse(baseUserControl.EditText, out dayCount); + } + if (dayCount <= 0) + { + dayCount = 7; + } + if (DateColumnList.Count != dayCount) + { + foreach (GridColumn item in DateColumnList) + { + gcMain.GridView.Columns.Remove(item); + } + gcMain.GridView.Columns.Remove(SumGridColumn); + DateColumnList.Clear(); + for (int i = 0; i < dayCount; i++) + { + GridColumn gridColumn = new GridColumn(); + gridColumn.AppearanceCell.Options.UseTextOptions = true; + gridColumn.AppearanceCell.TextOptions.HAlignment = HorzAlignment.Center; + gridColumn.AppearanceHeader.Options.UseTextOptions = true; + gridColumn.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center; + gridColumn.OptionsColumn.AllowMove = false; + gridColumn.OptionsColumn.AllowSize = false; + gridColumn.OptionsFilter.AllowFilter = false; + gridColumn.OptionsColumn.AllowMerge = DefaultBoolean.False; + gridColumn.OptionsColumn.AllowSort = DefaultBoolean.False; + gridColumn.FieldName = $"DDay_{i}"; + gridColumn.Width = 70; + gridColumn.DisplayFormat.FormatType = FormatType.Numeric; + gridColumn.DisplayFormat.FormatString = "{0:#,##0.####}"; + gridColumn.Visible = true; + gridColumn.SummaryItem.SummaryType = SummaryItemType.Sum; + gridColumn.SummaryItem.DisplayFormat = "{0:#,##0.####}"; + gcMain.GridView.Columns.Add(gridColumn); + DateColumnList.Add(gridColumn); + } + GridColumn sumGridColumn = new GridColumn(); + sumGridColumn.AppearanceCell.Options.UseTextOptions = true; + sumGridColumn.AppearanceCell.TextOptions.HAlignment = HorzAlignment.Center; + sumGridColumn.AppearanceHeader.Options.UseTextOptions = true; + sumGridColumn.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center; + sumGridColumn.OptionsColumn.AllowEdit = false; + sumGridColumn.OptionsColumn.AllowMove = false; + sumGridColumn.OptionsColumn.AllowSize = false; + sumGridColumn.OptionsFilter.AllowFilter = false; + sumGridColumn.OptionsColumn.AllowMerge = DefaultBoolean.False; + sumGridColumn.OptionsColumn.AllowSort = DefaultBoolean.False; + sumGridColumn.FieldName = $"workingsum"; + sumGridColumn.Caption = $"工时合计"; + sumGridColumn.Width = 70; + sumGridColumn.DisplayFormat.FormatType = FormatType.Numeric; + sumGridColumn.DisplayFormat.FormatString = "{0:#,##0.####}"; + sumGridColumn.Visible = true; + sumGridColumn.SummaryItem.SummaryType = SummaryItemType.Sum; + sumGridColumn.SummaryItem.DisplayFormat = "{0:#,##0.####}"; + SumGridColumn = sumGridColumn; + gcMain.GridView.Columns.Add(sumGridColumn); + } + } + + /// + /// 根据日期修改列状态 + /// + /// + private void UpdateDynamicColumns() + { + DateTime currentDate = DateTime.Now; + BaseUserControl dateUserControl = ControlObj.FindControl("bom_rdm_ksdt"); + if (dateUserControl is LabelDateEdit labelDateEdit) + { + currentDate = labelDateEdit.TextEdit.DateTime; + } + + int dayCount = 0; + BaseUserControl baseUserControl = ControlObj.FindControl("bom_rdm_tianshu"); + if (baseUserControl != null) + { + int.TryParse(baseUserControl.EditText, out dayCount); + } + if (dayCount <= 0) + { + dayCount = 7; + } + DateTime endDate = currentDate.AddDays(dayCount); + gcMain.GridView.BeginUpdate(); + try + { + for (int i = 0; i < DateColumnList.Count; i++) + { + GridColumn gridColumn = DateColumnList[i]; + // 当前列对应的日期 = 起始日期加 i 天 + DateTime dateForColumn = currentDate.AddDays(i); + if (dateForColumn <= endDate) + { + gridColumn.FieldName = dateForColumn.ToString("yyyy-MM-dd"); + gridColumn.Caption = dateForColumn.ToString("MM-dd"); + gridColumn.Visible = true; + gridColumn.Tag = dateForColumn; + } + else + { + gridColumn.Visible = false; + } + } + + } + finally + { + gcMain.GridView.EndUpdate(); + } + } + + /// + /// 新增汇总数据(日期修改后) + /// + private void UpdateSummaryData(DataTable table = null) + { + DataTable dataTable = new DataTable(); + if (table != null) + { + dataTable = table; + } + + if (dataTable != null && dataTable.Columns.Contains("num")) + { + MultiLineSummary = true; + gcMain.GridView.OptionsView.ShowFooter = true; + DataRow[] dataRows = dataTable.Select("num='999'"); + DataRow dataRow = dataRows != null && dataRows.Length > 0 ? dataRows[0] : null; + gcMain.AddHeadquarters(dataRow); + } + else if (MultiLineSummary) + { + MultiLineSummary = false; + //清空新加的汇总列 + gcMain.AddHeadquarters(); + } + + } + + + /// + /// 说明:表格编辑时,判断是否是否编辑 + /// 创建人:王一帆 + /// 创建日期:2020-03-27 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + protected void OnGridViewShowingEditor(object sender, CancelEventArgs e) + { + try + { + GridColumnModel gridColumnModel = null; + DataRow rowItem = null; + if (this.BillModel.DetailTreeTable) + { + DevExpress.XtraTreeList.TreeList treeList = (DevExpress.XtraTreeList.TreeList)sender; + TreeListColumn treeListColumn = treeList.FocusedColumn; + if (treeListColumn.Tag != null) + { + gridColumnModel = (GridColumnModel)treeListColumn.Tag; + } + rowItem = (this.gcMain as TreeGridControlEx).GetViewFocusedDataRow(); + } + else + { + GridView gridView = (GridView)sender; + GridColumn gridColumn = gridView.FocusedColumn; + + if (gridColumn.Tag != null) + { + gridColumnModel = (GridColumnModel)gridColumn.Tag; + } + rowItem = this.gcMain.GridView.GetDataRow(this.gcMain.GridView.FocusedRowHandle); + } + + + if (gridColumnModel != null && !string.IsNullOrEmpty(gridColumnModel.DisableCond)) + { + //e.Cancel = !ReplaceHelper.EvalCond(ReplaceHelper.ReplaceRowParam(focusedRow, gridColumnModel.DisableCond)); + //e.Cancel = !ValidateCond(gridColumnModel.DisableCond, focusedRow); + string UpdateCond = this.ControlObj.ReplaceParentControlValue(gridColumnModel.DisableCond); + UpdateCond = ReplaceHelper.ReplaceRowParam(rowItem, UpdateCond); + if (!ReplaceHelper.EvalCond(UpdateCond)) + { + e.Cancel = true;//该行不可编辑 + } + } + if (!string.IsNullOrWhiteSpace(BillModel.UpdateDetailCond)) + { + string UpdateCond = this.ControlObj.ReplaceParentControlValue(BillModel.UpdateDetailCond); + UpdateCond = ReplaceHelper.ReplaceRowParam(rowItem, UpdateCond); + if (!ReplaceHelper.EvalCond(UpdateCond)) + { + e.Cancel = true;//该行不可编辑 + } + } + } + catch (Exception ex) + { + LogHelper.Instance.WriteError(ex); + + } + + + } + + /// + /// 虚拟行点击添加 + /// + /// + private void InitNewRowMethod(object sender) + { + GridView view = sender as DevExpress.XtraGrid.Views.Grid.GridView; + DataTable gridTable = (this.gcMain.GridControl.DataSource as DataTable).TrimDeleteRows(); + DataRow tmpRow = gridTable.NewRow(); + gridTable.Rows.Add(tmpRow); + int position = gridTable.Rows.Count - 1; + foreach (DataRow dr in _detailColumns.Rows) + { + GridColumnModel model = new GridColumnModel(dr); + string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue); + + + if (model.DefaultValue.Contains("{#")) + { + fieldValue = this.ControlObj.ReplaceParentControlValue(model.DefaultValue); + if (!string.IsNullOrEmpty(fieldValue)) + { + tmpRow[model.FieldName] = fieldValue; + } + } + else if (!string.IsNullOrEmpty(model.DefaultValue)) + { + if (model.DefaultValue.Contains("{ROW")) + { + if (position > 0) + { + + fieldValue = ReplaceHelper.GetParamFields(model.DefaultValue)[0]; + fieldValue = fieldValue.Replace("}", "").Replace("{", ""); + fieldValue = fieldValue.Substring(fieldValue.IndexOf('_') + 1); + string topFieldValue = gridTable.Rows[position - 1][fieldValue] + ""; + if (gridTable.Columns[model.FieldName].DataType == typeof(DateTime)) + { + if (!string.IsNullOrEmpty(topFieldValue)) tmpRow[model.FieldName] = Convert.ToDateTime(topFieldValue); + } + else + { + tmpRow[model.FieldName] = topFieldValue; + } + } + } + else + { + tmpRow[model.FieldName] = fieldValue; + } + } + } + gridTable.OrderBy(this.BillModel.DetailOrderField); + + if (tmpRow.Table.Columns.Contains(this.BillModel.DetailOrderField) && gridTable.Rows.Count == 0) + { + tmpRow[this.BillModel.DetailOrderField] = 1; + } + + this.gcMain.GridView.UpdateCurrentRow(); + this.gcMain.GridView.ShowEditor(); + } + /// + /// 切换行判断是否是虚拟行数据进行数据填充 + /// + /// + /// + private void GridView_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e) + { + DataTable gridTable = (this.gcMain.GridControl.DataSource as DataTable).TrimDeleteRows(); + int _rowNumber = this.gcMain.GridView.FocusedRowHandle; + int _prvFocused = e.PrevFocusedRowHandle; + int indexNumber = this.gcMain.GridView.RowCount; + if (_rowNumber < 0 && _prvFocused != gridTable.Rows.Count) + { + InitNewRowMethod(sender); + this.gcMain.GridView.FocusedRowHandle = indexNumber - 1; + } + } + /// + /// 说明:单据重写明细回车事件(用于扫码回车移动至下一行数据) + /// 创建人:王一帆 + /// 创建日期:2021-06-08 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The sender. + /// The instance containing the event data. + protected void OnGridViewCellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) + { + if (isDragWrap) + { + int _rowNumber = this.gcMain.GridView.FocusedRowHandle; + GridColumn focusColumn = this.gcMain.GridView.FocusedColumn; + GridColumnModel Columnmodel = focusColumn.Tag as GridColumnModel; + + if (Columnmodel.FieldType == ControlType.LabSacn) + { + this.gcMain.GridView.OptionsNavigation.EnterMoveNextColumn = false; + if (this.BillModel.DefaultAddEmptyRow && _rowNumber + 1 == this.gcMain.GridView.DataRowCount) + { + DataTable gridTable = (this.gcMain.GridView.GridControl.DataSource as DataTable).TrimDeleteRows(); + DataRow tmpRow = gridTable.NewRow(); + gridTable.Rows.Add(tmpRow); + int position = gridTable.Rows.Count - 1; + foreach (DataRow dr in _detailColumns.Rows) + { + GridColumnModel model = new GridColumnModel(dr); + string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue); + if (model.DefaultValue.Contains("{#")) + { + fieldValue = this.ControlObj.ReplaceParentControlValue(model.DefaultValue); + if (!string.IsNullOrEmpty(fieldValue)) + { + tmpRow[model.FieldName] = fieldValue; + } + } + else if (!string.IsNullOrEmpty(model.DefaultValue)) + { + if (model.DefaultValue.Contains("{ROW")) + { + if (position > 0) + { + + fieldValue = ReplaceHelper.GetParamFields(model.DefaultValue)[0]; + fieldValue = fieldValue.Replace("}", "").Replace("{", ""); + fieldValue = fieldValue.Substring(fieldValue.IndexOf('_') + 1); + string topFieldValue = gridTable.Rows[position - 1][fieldValue] + ""; + if (gridTable.Columns[model.FieldName].DataType == typeof(DateTime)) + { + if (!string.IsNullOrEmpty(topFieldValue)) tmpRow[model.FieldName] = Convert.ToDateTime(topFieldValue); + } + else + { + tmpRow[model.FieldName] = topFieldValue; + } + } + } + else + { + tmpRow[model.FieldName] = fieldValue; + } + } + } + gridTable.OrderBy(this.BillModel.DetailOrderField); + + if (tmpRow.Table.Columns.Contains(this.BillModel.DetailOrderField) && gridTable.Rows.Count == 0) + { + tmpRow[this.BillModel.DetailOrderField] = 1; + } + + this.gcMain.GridView.UpdateCurrentRow(); + this.gcMain.GridView.ShowEditor(); + } + int ColumnIndex = this.gcMain.GridView.FocusedColumn.VisibleIndex;//焦点列的坐标 + this.gcMain.GridView.FocusedRowHandle = _rowNumber + 1; + this.gcMain.GridView.FocusedColumn.VisibleIndex = ColumnIndex; + //this.gridView.OptionsNavigation.EnterMoveNextColumn = true; + } + else + { + this.gcMain.GridView.OptionsNavigation.EnterMoveNextColumn = true; + } + } + } + /// + /// 点击第一个默认新增行新增默认数据 + /// + /// + /// + private void GridView_MouseDown(object sender, MouseEventArgs e) + { + + } + + + + + /// + /// 说明:验证单据是否修改过 + /// 创建人:龚宇超 + /// 创建日期: + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + private void VerfyBillUpdated() + { + bool isUpdateDetailed = false; + DataTable table = this.gcMain.gridControl.DataSource as DataTable; + if (table != null && table.Rows.Count > 0) + { + DataRow updateRow = table.Rows.Cast().FirstOrDefault(x => x.RowState != DataRowState.Unchanged); + isUpdateDetailed = updateRow != null; + } + if (this.BillRowItem != null && (this.ControlObj.VerifyUpdated() || isUpdateDetailed)) + { + bool isReadOnly2 = !string.IsNullOrEmpty(this.BillModel.ModifyCond) && !ReplaceHelper.ReplaceRowParamCond(this.BillRowItem, this.BillModel.ModifyCond); + if (!isReadOnly2) + { + if (MessageUtil.Show(ResourceKeys.DataChanged, MessageBoxButtons.YesNo) == DialogResult.Yes) + { + this.BillSave(); + } + } + } + } + + /// + /// 说明:初始化单据按钮状态 + /// 创建人:龚宇超 + /// 创建日期:2017-12-04 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// if set to true [is edit]. + private void SetBillStatus(DataRow rowItem) + { + if (this.BillModel.unableToSave.Contains(SysModel.UserName)) + { + this.btnBillSave.Hide(); + foreach (System.Windows.Forms.Control control in pl_main_bottom.Controls) + { + + if (control.Location.X < btnBillSave.Location.X && control is DevExpress.XtraEditors.SimpleButton && control.Name != "btn_input") + { + control.Location = new Point(control.Location.X + btnBillSave.Width, control.Location.Y); + } + } + } + if (rowItem != null) + { + gridExModel.MaintabFocusedRow = rowItem; + gridEx.ObjPanel.Enabled = true; + // 单据为修改状态,无需设置赋值时不需要计算面板属性 + bool isReadOnly = !string.IsNullOrEmpty(this.BillModel.ModifyCond) && !ReplaceHelper.ReplaceRowParamCond(rowItem, this.BillModel.ModifyCond); + this.ControlObj.CanExecControl = false; // 单据为修改状态时,无需计算面板属性 + this.lbTitle.Text = this.BillModel.TypeName + "(修改)"; + this.lblOrderNo.Text = rowItem[this.BillModel.PrimaryKey] + ""; + this.rdBlue.Checked = "0".Equals(rowItem[this.BillModel.RtagidKey] + ""); + this.rdRed.Checked = "1".Equals(rowItem[this.BillModel.RtagidKey] + ""); + this.BillModel.SaveState = true; + this.rdBlue.Enabled = this.rdRed.Enabled = false; + this._itemImport.Enabled = this._itemImportUpdate.Enabled = !isReadOnly; + this.ControlObj.SetReadOnlyAllControl(isReadOnly); + this.ControlObj.SetAllControlValue(rowItem); + this.btnDelete.Enabled = this.btnBillSave.Enabled = this.btnBillApply.Enabled = !isReadOnly; + this.ControlObj.CanExecControl = true; + this.cb_input.Enabled = this.btn_input.Enabled = this.txt_input.Enabled = !isReadOnly; + this.SetButtonStatus(rowItem); + //if (this.itemCommon.Visible == true && this.itemCommon.Tag is DataRow rightRow) + //{ + // string menuCode = rightRow["menuCond"] + ""; + // if (!string.IsNullOrEmpty(menuCode)) + // { + // this.itemCommon.Enabled = ValidateCond(menuCode, rowItem); ; + // } + //} + this.BillRowItem = rowItem; + // 设置Brp模版 + if (this.IsBrpTemplete || this.BillModel.IsBrp) + { + this.SetTempleteSelectedValue(rowItem["brpId"] + ""); + this.cb_templete.Enabled = !isReadOnly; + } + this.BillModel.PopupUnionCode = rdBlue.Checked ? rdBlueUnionCode : rdRedUnionCode; + this.labelControl1.ForeColor = this.lblOrderNo.ForeColor = this.lbTitle.ForeColor = rdBlue.Checked ? Color.Blue : Color.Red; + this.gcMain.GridView.OptionsBehavior.Editable = !isReadOnly; + + // 上一次查询 + int oldRowHandle = this.gcMain.GridView.FocusedRowHandle; + //获取数据源并排序 + DataTable dt = BillImpl.GetDataTableResult(ReplaceHelper.ReplaceRowParam(rowItem, this.BillModel.DetailSql)); + if (dt.Columns.Contains(this.BillModel.DetailOrderField)) + { + DataView dataView = dt.AsDataView(); + dataView.Sort = this.BillModel.DetailOrderField; + dt = dataView.ToTable(); + dt.AcceptChanges(); + } + + if (this.BillModel.DetailTreeTable) + { + //判断是否有tap_id和tap_pid + (this.gcMain as TreeGridControlEx).SetGridViewDataSourceGenerateID(dt); + this.gcMain.GridView.SelectRowHandler(oldRowHandle); + } + else + { + this.gcMain.GridControl.DataSource = dt; + this.gcMain.GridView.SelectRowHandler(oldRowHandle); + if (this.BillModel.SelectLast && dt.Rows.Count > 0) + { + this.gcMain.GridView.SelectRowHandler(dt.Rows.Count - 1); + } + } + + + RefreshPrindMenu(); + + BaseUserControl userControl = this.ControlObj.FindControl(this.BillModel.RtagidKey); + if (userControl != null) + { + userControl.EditText = this.rdRed.Checked ? "1" : "0"; + } + string gridExSql = this.gridEx.SysModel.MenuSql; + gridExSql = ReplaceHelper.ReplaceRowParam(rowItem, gridExSql); + this.gridEx.GridControlObj.LastSearchSql = gridExSql; + this.gridEx.GridControlObj.SetGridViewDataSource(BaseImpl.GetDataTableResult(gridExSql)); + } + else + { + gridExModel.MaintabFocusedRow = null; + gridEx.ObjPanel.Enabled = false; + // 单据为新增状态 + this.btnDelete.Enabled = this.btnBillSave.Enabled = this.btnBillApply.Enabled = true; + this.lbTitle.Text = this.BillModel.TypeName + "(新增)"; + this.lblOrderNo.Text = BillImpl.GetBillNo(this.BillModel.BillSeq); + this._itemImport.Enabled = this._itemImportUpdate.Enabled = true; + this.cb_input.Enabled = this.btn_input.Enabled = this.txt_input.Enabled = true; + this.cb_templete.Enabled = true; + this.BillModel.SaveState = false; + this.ControlObj.SetReadOnlyAllControl(false); + this.rdBlue.Enabled = this.rdRed.Enabled = true; + this.SetButtonStatus(); + //if (this.itemCommon.Visible == true && this.itemCommon.Tag is DataRow rightRow) + //{ + // string menuCode = rightRow["menuCond"] + ""; + // if (!string.IsNullOrEmpty(menuCode)) + // { + // this.itemCommon.Enabled = ValidateCond(menuCode, rowItem); ; + // } + //} + // 通过右键菜单打开单据,假如明细有数据则在初始化时使用传入数据. + if (this.BillModel.DetailTreeTable) + { + (this.gcMain as TreeGridControlEx).TreeListObj.OptionsBehavior.Editable = true; + (this.gcMain as TreeGridControlEx).SetGridViewDataSourceGenerateID(BillImpl.GetDataTableResult(this.BillModel.DetailSql)); + } + else + { + this.gcMain.GridView.OptionsBehavior.Editable = true; + this.gcMain.GridControl.DataSource = BillImpl.GetDataTableResult(this.BillModel.DetailSql); + } + + BaseUserControl userControl = this.ControlObj.FindControl(this.BillModel.RtagidKey); + if (userControl != null) + { + userControl.EditText = this.rdRed.Checked ? "1" : "0"; + } + this.gridEx.GridControlObj.LastSearchSql = this.gridEx.SysModel.MenuSql; + this.gridEx.GridControlObj.SetGridViewDataSource(new DataTable()); + } + + this._waterMark = new WaterMark(this.BillModel.MasterPreFix, rowItem); + this.lbTitle.Invalidate(); + + } + #endregion + + #region 切换红、蓝字单据 + /// + /// 说明:点击蓝字单据 + /// 创建人:龚宇超 + /// 创建日期:2017-11-23 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + private void OnBlueStateClick(object sender, EventArgs e) + { + this.rdRed.Checked = false; + this.labelControl1.ForeColor = this.lblOrderNo.ForeColor = this.lbTitle.ForeColor = Color.Blue; + this.BillModel.PopupUnionCode = rdBlueUnionCode; + + BaseUserControl userControl = this.ControlObj.FindControl(this.BillModel.RtagidKey); + if (userControl != null) + { + userControl.EditText = "0"; + } + } + /// + /// 说明:点击红字单据 + /// 创建人:龚宇超 + /// 创建日期:2017-11-23 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + private void OnRedStateClick(object sender, EventArgs e) + { + this.rdBlue.Checked = false; + this.labelControl1.ForeColor = this.lblOrderNo.ForeColor = this.lbTitle.ForeColor = Color.Red; + this.BillModel.PopupUnionCode = rdRedUnionCode; + + BaseUserControl userControl = this.ControlObj.FindControl(this.BillModel.RtagidKey); + if (userControl != null) + { + userControl.EditText = "1"; + } + } + #endregion + + #region 复制单据 + /// + /// 说明:复制表头数据 + /// 创建人:龚宇超 + /// 创建日期:2017-11-27 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + protected void OnCopyMasterItemClick(object sender, ItemClickEventArgs e) + { + this.btnDelete.Enabled = this.btnBillSave.Enabled = this.btnBillApply.Enabled = true; + this.lbTitle.Text = this.BillModel.TypeName + "(新增)"; + this.lbTitle.Invalidate(); + this.lblOrderNo.Text = BillImpl.GetBillNo(this.BillModel.BillSeq); + this.BillModel.SaveState = false; + this.rdBlue.Enabled = this.rdRed.Enabled = true; + this.cb_input.Enabled = this.btn_input.Enabled = this.txt_input.Enabled = true; + this._itemImport.Enabled = this._itemImportUpdate.Enabled = true; + this.cb_templete.Enabled = true; + this.ControlObj.CopyControlValue(); + this.ControlObj.SetReadOnlyAllControl(false); + + if (this.BillModel.DetailTreeTable) + { + ((this.gcMain as TreeGridControlEx).TreeListObj.DataSource as DataTable).Clear(); + (this.gcMain as TreeGridControlEx).TreeListObj.OptionsBehavior.Editable = true; + } + else + { + this.gcMain.GridControl.DataSourceTable().Clear(); + this.gcMain.GridView.OptionsBehavior.Editable = true; + + } + + + this._waterMark = new WaterMark(this.BillModel.MasterPreFix, null); + } + /// + /// 说明:复制整单 + /// 创建人:龚宇超 + /// 创建日期:2017-11-27 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + protected void OnCopyAllItemClick(object sender, ItemClickEventArgs e) + { + try + { + WaitForm.ShowForm(ResourceKeys.Handing); + DataTable gridTable = (this.gcMain.GridControl.DataSource as DataTable).TrimDeleteRows(); + if (this.BillModel.DetailTreeTable) + { + gridTable = ((this.gcMain as TreeGridControlEx).TreeListObj.DataSource as DataTable).TrimDeleteRows(); + } + this.btnDelete.Enabled = this.btnBillSave.Enabled = this.btnBillApply.Enabled = true; + this.lbTitle.Text = this.BillModel.TypeName + "(新增)"; + this.lbTitle.Invalidate(); + this.lblOrderNo.Text = BillImpl.GetBillNo(this.BillModel.BillSeq); + this.rdBlue.Enabled = this.rdRed.Enabled = true; + this.cb_input.Enabled = this.btn_input.Enabled = this.txt_input.Enabled = true; + this._itemImport.Enabled = this._itemImportUpdate.Enabled = true; + this.cb_templete.Enabled = true; + this.ControlObj.CopyControlValue(); + this.ControlObj.SetReadOnlyAllControl(false); + this._waterMark = new WaterMark(this.BillModel.MasterPreFix, null); + if (!gridTable.Columns.Contains(ERPInfo.Instance.isAddRows)) + { + gridTable.Columns.Add(ERPInfo.Instance.isAddRows, typeof(String)); + } + // 处理单据明细 + DataTable detailTable = this.gcMain.GridControl.DataSourceTable(); + if (this.BillModel.DetailTreeTable) + { + detailTable = (this.gcMain as TreeGridControlEx).GetGridViewDataSource(); + } + bool canCopy = false; + string defaultValue = string.Empty; + + + if (this.BillModel.DetailTreeTable) + { + if (detailTable.Columns.Contains(this.BillModel.PrimaryDetailKey)) + { + (this.gcMain as TreeGridControlEx).TreeListObj.BeginUpdate(); + foreach (TreeListNode item in (this.gcMain as TreeGridControlEx).TreeListObj.Nodes) + { + //根据后台列配置可否复制 + if (_detailColumns.Columns.Contains("canCopy")) + { + //int index = detailTable.Rows.IndexOf(item); + foreach (DataRow dr in _detailColumns.Rows) + { + canCopy = !string.IsNullOrEmpty(dr["canCopy"] + "") ? "1".Equals(dr["canCopy"] + "") : false; + if (!canCopy) + { + TreeListColumn column = (this.gcMain as TreeGridControlEx).TreeListObj.Columns.ColumnByFieldName(dr["fieldName"] + ""); + //TreeListNode node = treeList.GetNode(rowIndex); + defaultValue = this.ControlObj.ReplaceParentControlValue(dr["defaultdate"] + ""); + defaultValue = BaseImpl.GetDefaultValue(defaultValue); + if (!string.IsNullOrEmpty(defaultValue)) + { + item.SetValue(column, defaultValue); + } + else + { + item.SetValue(column, DBNull.Value); + } + } + } + } + item[this.BillModel.PrimaryDetailKey] = this.lblOrderNo.Text; + } + (this.gcMain as TreeGridControlEx).TreeListObj.EndUpdate(); + } + (this.gcMain as TreeGridControlEx).TreeListObj.OptionsBehavior.Editable = true; + this.BillModel.SaveState = false; + } + else + { + if (detailTable.Columns.Contains(this.BillModel.PrimaryDetailKey)) + { + this.gcMain.GridView.BeginUpdate(); + foreach (DataRow item in detailTable.Rows) + { + //根据后台列配置可否复制 + if (_detailColumns.Columns.Contains("canCopy")) + { + int index = detailTable.Rows.IndexOf(item); + foreach (DataRow dr in _detailColumns.Rows) + { + canCopy = !string.IsNullOrEmpty(dr["canCopy"] + "") ? "1".Equals(dr["canCopy"] + "") : false; + if (!canCopy) + { + GridColumn column = this.gcMain.GridView.Columns.ColumnByFieldName(dr["fieldName"] + ""); + defaultValue = this.ControlObj.ReplaceParentControlValue(dr["defaultdate"] + ""); + defaultValue = BaseImpl.GetDefaultValue(defaultValue); + if (!string.IsNullOrEmpty(defaultValue)) + { + this.gcMain.GridView.SetRowCellValue(index, column, defaultValue); + } + else + { + this.gcMain.GridView.SetRowCellValue(index, column, DBNull.Value); + } + } + } + } + item[this.BillModel.PrimaryDetailKey] = this.lblOrderNo.Text; + } + this.gcMain.GridView.EndUpdate(); + } + this.gcMain.GridView.OptionsBehavior.Editable = true; + this.BillModel.SaveState = false; + } + + + } + catch (Exception ex) + { + + } + finally + { + WaitForm.HideForm(); + } + } + #endregion + + #region Excel操作 + /// + /// 说明:导出Excel + /// 创建人:龚宇超 + /// 创建日期:2017-11-27 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + protected void OnExportItemClick(object sender, ItemClickEventArgs e) + { + LogUtil.WriteDebug(this.SysModel.ModuleCode, "导出数据", this.SysModel.FormText, "单据明细导出", this.SysModel.ModuleId + ""); + + + if (this.BillModel.DetailTreeTable) + { + (this.gcMain as TreeGridControlEx).TreeListObj.ToTreeExcel(this.SysModel.FormText); + } + else + { + this.gcMain.GridControl.ToExcel(this.SysModel.FormText); + } + + + } + /// + /// 说明:从Excel导入 + /// 创建人:龚宇超 + /// 创建日期:2017-11-27 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + protected void OnImportItemClick(object sender, ItemClickEventArgs e) + { + OpenFileDialog dialog = new OpenFileDialog(); + dialog.Title = "选择导入文件"; + //dialog.Filter = "Excel文件(*.xls)|*.xls"; + dialog.Filter = SystemInfo.Instance.IsXlsxFirst ? "Excel文件(*.xlsx)|*.xlsx|Excel文件(*.xls)|*.xls" : + "Excel文件(*.xls)|*.xls|Excel文件(*.xlsx)|*.xlsx"; + + DialogResult result = dialog.ShowDialog(); + if (result == DialogResult.OK) + { + string fileName = dialog.FileName; + string colFields = this.gcMain.GridView.Columns.ToString(','); + + if (this.BillModel.DetailTreeTable) + { + DataTable DataImportTable = (this.gcMain as TreeGridControlEx).TreeListObj.ToExcelTreeDataTable(fileName, colFields, true, true); + DataTable NewTable = (this.gcMain as TreeGridControlEx).GetGridViewDataSource(); + TreeListColumnCollection gridColumns = (this.gcMain as TreeGridControlEx).TreeListObj.Columns; + //父节点名称 + string ParentFieldName = (this.gcMain as TreeGridControlEx).TreeListObj.ParentFieldName; + //节点名称 + string KeyFieldName = (this.gcMain as TreeGridControlEx).TreeListObj.KeyFieldName; + + if (!DataImportTable.Columns.Contains(ParentFieldName)) DataImportTable.Columns.Add(ParentFieldName); + if (!DataImportTable.Columns.Contains(KeyFieldName)) DataImportTable.Columns.Add(KeyFieldName); + + DragAddTable(DataImportTable, "0"); + } + else + { + DataTable DataImportTable = this.gcMain.GridView.ToExcelDataTable(fileName, colFields, true, true); + DataTable NewTable = this.gcMain.GridControl.DataSourceTable(); + GridColumnCollection gridColumns = this.gcMain.GridView.Columns; + foreach (DataRow rowItem in DataImportTable.Rows) + { + DataRow newRow = NewTable.NewRow(); + foreach (GridColumn col in gridColumns) + { + if ("id".Equals(col.FieldName) || col.FieldName.Equals(this.BillModel.PrimaryKey)) continue; + if (rowItem.Table.Columns.Contains(col.FieldName)) + { + // 列中是否包含对应字段,包含则使用值 + newRow[col.FieldName] = rowItem[col.FieldName]; + } + else + { + // 未包含字段,则使用控件默认值. + GridColumnModel model = col.Tag as GridColumnModel; + string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue); + if (model.DefaultValue.Contains("{#")) + { + fieldValue = this.ControlObj.ReplaceParentControlValue(model.DefaultValue); + + } + if (!string.IsNullOrEmpty(fieldValue)) + { + newRow[col.FieldName] = fieldValue; + } + } + } + NewTable.Rows.Add(newRow); + } + this.gcMain.GridControl.DataSource = NewTable; + } + + + } + } + /// + /// 说明:导入Excel文件(更新) + /// 创建人:龚宇超 + /// 创建日期:2017-11-27 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + protected void OnImportUpdateItemClick(object sender, ItemClickEventArgs e) + { + + } + #endregion + + #region 常用工具 + /// + /// 说明:验证可操作条件 + /// 创建人:龚宇超 + /// 创建日期:2018-03-07 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + protected void OnToolsClick(object sender, EventArgs e) + { + foreach (BarItemLink itemLink in pMenu.ItemLinks) + { + DataRow rowItem = itemLink.Item.Tag as DataRow; + if (rowItem != null) + { + string menuCond = rowItem["MenuCond"] + ""; + string menuCaption = itemLink.Caption; + + if (!string.IsNullOrEmpty(menuCond)) + { + try + { + bool result = true; + menuCond = ReplaceHelper.ReplaceParamToValue(menuCond, "{" + this.BillModel.PrimaryKey + "}", this.lblOrderNo.Text.Trim()); + + if (menuCond.StartsWith("@") || menuCond.StartsWith("!")) + { + result = "1".Equals(BaseImpl.GetDefaultValue(menuCond)); + } + else + { + menuCond = this.ControlObj.ReplaceControlValue(menuCond); + if (this.BillRowItem != null) + menuCond = ReplaceHelper.ReplaceRowParam(this.BillRowItem, menuCond); + menuCond = ReplaceHelper.ReplaceParamToValue(menuCond, "0"); // 未替换的参数所有替换为0 + + result = ReplaceHelper.EvalCond(menuCond); + } + itemLink.Item.Enabled = result; + } + catch (Exception ex) + { + MessageUtil.Show("[" + menuCaption + "] " + ResourceKeys.SetRightMenuCondFault); + LogHelper.Instance.WriteError(ex); + } + } + } + } + } + /// + /// 说明:常用工具点击 + /// 创建人:龚宇超 + /// 创建日期:2017-11-27 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + protected void OnCommonItemClick(object sender, ItemClickEventArgs e) + { + DataRow rowItem = e.Item.Tag as DataRow; + + CommonMenu menu = new CommonMenu(this.SysModel, this.ControlObj, null); + menu.ApplyBefore += new CommonToolApplyEventHandler(OnMenuApplyBefore); + menu.DynamicLinkAfter += new CommonToolAfterDynamicLinkEventHandler(OnDynamicLinkAfter); + menu.Apply(rowItem); + } + /// + /// 说明:执行前单独替换BilldocumentId + /// 创建人:龚宇超 + /// 创建日期:2018-03-07 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The e. + protected void OnMenuApplyBefore(ApplyArgs e) + { + string[] paramList = new string[e.MemuModel.ParamList.Count]; + + for (int i = 0; i < e.MemuModel.ParamList.Count; i++) + { + string item = e.MemuModel.ParamList[i]; + List condition = ReplaceHelper.GetParamFields(item); + foreach (string cond in condition) + { + string value = this.BillModel.PrimaryKey.Equals(cond.Replace("{", "").Replace("}", "").ToLower(), StringComparison.OrdinalIgnoreCase) ? this.lblOrderNo.Text.Trim() : cond; + item = item.Replace(cond, value); ; + } + paramList[i] = item; + } + e.MemuModel.ParamList = paramList.ToList(); + } + /// + /// 动态链接库执行完成后 + /// + /// + protected void OnDynamicLinkAfter(object sender, ApplyArgs e) + { + try + { + if (!string.IsNullOrWhiteSpace(e.MemuModel.ResultSQL)) + { + string resultSql = e.MemuModel.ResultSQL; + if (e.DialogModel != null && e.DialogModel.DialogDllName.Equals("lskj.pubadd.dll", StringComparison.OrdinalIgnoreCase) && e.DialogModel.PubDialogType == DialogType.PubAddRecord) + { + if (e.DialogModel.ReturnTag != null && e.DialogModel.ReturnTag is MyControl) + { + MyControl addControlObj = e.DialogModel.ReturnTag as MyControl; + resultSql = addControlObj.ReplaceControlValue(resultSql); + } + resultSql = this.ControlObj.ReplaceControlValue(resultSql); + DataTable dataTable = MainImpl.GetDataTableResult(resultSql); + foreach (DataRow item in dataTable.Rows) + { + this.AddRowToGridView(item); + } + } + else + { + resultSql = this.ControlObj.ReplaceControlValue(resultSql); + DataTable dataTable = MainImpl.GetDataTableResult(resultSql); + foreach (DataRow item in dataTable.Rows) + { + this.AddRowToGridView(item, false); + } + } + } + if (e.DialogModel != null && e.DialogModel.DialogDllName.Equals("Lskj.PubBomImport.dll", StringComparison.OrdinalIgnoreCase)) + { + if (e.DialogModel.ReturnTag != null && e.DialogModel.ReturnTag is BomImpRtnModel impRtnModel) + { + if (impRtnModel.ShowType.Equals("1") || impRtnModel.ShowType.Equals("2") || impRtnModel.ShowType.Equals("3") || impRtnModel.ShowType.Equals("5") || impRtnModel.ShowType.Equals("6") || impRtnModel.ShowType.Equals("7") || impRtnModel.ShowType.Equals("8") || impRtnModel.ShowType.Equals("9"))//执行保存 + { + CommonMenu menu = (CommonMenu)sender; + menu.issuccess = impRtnModel.CanSave; + } + else if (impRtnModel.ShowType.Equals("0") || impRtnModel.ShowType.Equals("00") || impRtnModel.ShowType.Equals("000"))//返回文件 + { + ControlModel controlModel = ControlObj.ControlModels.Where(n => n.LabelText.Equals("物料编码")).FirstOrDefault(); + if (controlModel == null) + { + MessageUtil.Show($"物料编码不存在"); + return; + } + string mxProductId = ControlObj.GetControlValue(controlModel); + if (string.IsNullOrEmpty(mxProductId)) + { + MessageUtil.Show($"物料编码必填"); + return; + } + ControlModel modeControlModel = ControlObj.ControlModels.Where(n => n.LabelText.Equals("上传模式")).FirstOrDefault(); + string addMode = ControlObj.GetControlValue(modeControlModel); + if (impRtnModel.ShowType.Equals("1") && string.IsNullOrEmpty(addMode)) + { + MessageUtil.Show($"上传模式必填"); + return; + } + ControlModel sepciesNoControlModel = ControlObj.ControlModels.Where(n => n.LabelText.Equals("文件分类")).FirstOrDefault(); + string sepciesNo = ControlObj.GetControlValue(sepciesNoControlModel); + if ((impRtnModel.ShowType.Equals("1") || impRtnModel.ShowType.Equals("6")) && string.IsNullOrEmpty(sepciesNo)) + { + MessageUtil.Show($"文件分类必填"); + return; + } + ControlModel fileIDControlModel = ControlObj.ControlModels.Where(n => n.LabelText.Equals("文件ID")).FirstOrDefault(); + string fileID = ControlObj.GetControlValue(fileIDControlModel); + ControlModel oldPIDControlModel = ControlObj.ControlModels.Where(n => n.LabelText.Equals("旧编码")).FirstOrDefault(); + string oldPID = ControlObj.GetControlValue(oldPIDControlModel); + DataTable sourceTable = gcMain.gridControl.DataSourceTable(); + if (impRtnModel.ShowType.Equals("000") && sourceTable.Rows.Cast().Where(n => n.RowState != DataRowState.Deleted).Count() > 0) + { + MessageUtil.Show($"只能选择单个文件,请删除后再添加"); + return; + } + if (sourceTable != null && impRtnModel.FileNames != null) + { + string afterBomFieldName = impRtnModel.AfterBomFieldName; + if (!sourceTable.Columns.Contains("BomFieldNameDir")) + { + sourceTable.Columns.Add("BomFieldNameDir"); + } + if (!sourceTable.Columns.Contains("BomFieldNamePath")) + { + sourceTable.Columns.Add("BomFieldNamePath"); + } + if (!sourceTable.Columns.Contains("BomMxMainProduct")) + { + sourceTable.Columns.Add("BomMxMainProduct"); + } + if (!sourceTable.Columns.Contains("BomMxAddState")) + { + sourceTable.Columns.Add("BomMxAddState"); + } + if (!sourceTable.Columns.Contains("qms_laddf_mode")) + { + sourceTable.Columns.Add("qms_laddf_mode"); + } + if (!sourceTable.Columns.Contains("BomAddSpeciesNo")) + { + sourceTable.Columns.Add("BomAddSpeciesNo"); + } + if (!sourceTable.Columns.Contains("BomAddChangeFileId")) + { + sourceTable.Columns.Add("BomAddChangeFileId"); + } + if (!sourceTable.Columns.Contains("BomAddOldProductId")) + { + sourceTable.Columns.Add("BomAddOldProductId"); + } + DataTable dataTable = new DataTable(); + dataTable.Columns.Add(afterBomFieldName); + dataTable.Columns.Add("BomFieldNameDir"); + dataTable.Columns.Add("BomFieldNamePath"); + dataTable.Columns.Add("BomMxMainProduct"); + dataTable.Columns.Add("BomMxAddState"); + dataTable.Columns.Add("qms_laddf_mode"); + dataTable.Columns.Add("BomAddSpeciesNo"); + dataTable.Columns.Add("BomAddChangeFileId"); + dataTable.Columns.Add("BomAddOldProductId"); + IEnumerable rowsIEnumerable = sourceTable.Rows.Cast().Where(n => n.RowState != DataRowState.Deleted); + foreach (string fileName in impRtnModel.FileNames) + { + string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName).Trim(); + //找到code相同的行 + DataRow selectRow = rowsIEnumerable.Where(n => (n[afterBomFieldName] + "").Trim().Equals(fileNameWithoutExtension, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); + if (selectRow != null) + { + //MessageUtil.Show($"{fileNameWithoutExtension}已存在,不允许重复创建"); + continue; + } + //DataRow productRow = BaseImpl.GetDataRowResult($"select top 1 billdocument_id from bom_BillTab where productid like '{code}%'"); + //if (productRow != null) + //{ + // MessageUtil.Show($"{code}已存在,不允许重复创建"); + // return; + //} + DataRow addRow = dataTable.NewRow(); + addRow[afterBomFieldName] = Path.GetFileName(fileName); + addRow["BomFieldNameDir"] = fileName; + addRow["BomFieldNamePath"] = Path.GetFileName(fileName); + addRow["BomMxMainProduct"] = mxProductId; + addRow["qms_laddf_mode"] = addMode; + addRow["BomAddSpeciesNo"] = sepciesNo; + addRow["BomAddChangeFileId"] = fileID; + addRow["BomAddOldProductId"] = oldPID; + addRow["BomMxAddState"] = this.BillModel.SaveState ? "修改" : "新增"; + dataTable.Rows.Add(addRow); + } + foreach (DataRow item in dataTable.Rows) + { + DataRow sourceRow = this.AddRowToGridView(item, true); + sourceRow["BomFieldNameDir"] = item["BomFieldNameDir"] + ""; + sourceRow["BomFieldNamePath"] = item["BomFieldNamePath"] + ""; + sourceRow["BomMxMainProduct"] = item["BomMxMainProduct"] + ""; + sourceRow["BomMxAddState"] = item["BomMxAddState"] + ""; + sourceRow["qms_laddf_mode"] = item["qms_laddf_mode"] + ""; + sourceRow["BomAddSpeciesNo"] = item["BomAddSpeciesNo"] + ""; + sourceRow["BomAddChangeFileId"] = item["BomAddChangeFileId"] + ""; + sourceRow["BomAddOldProductId"] = item["BomAddOldProductId"] + ""; + } + } + } + } + } + string movepage = (this.ControlObj.ReplaceControlValue("{qms_maddf_addMode}").Equals("6")) ? "-9998" : "-9999"; + } + catch (Exception) + { + } + } + #endregion + + #region 打印模版 + /// + /// 说明:打印完成需要参数 + /// 创建人:龚宇超 + /// 创建日期:2018-07-09 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + protected void GetPrintOtherParam() + { + Dictionary dataCaches = SysModel != null ? SysModel.DataCaches : null; + //取得打印完成后的参数 + if (!string.IsNullOrEmpty(this.BillModel.PrintSql) && this.BillModel.PrintSql.Contains("<<")) + { + string[] strs = this.BillModel.PrintSql.Split(new[] { ">>" }, 2, StringSplitOptions.None); + _mainPrintSql = strs[1]; + _printModeCond = strs[0].Replace("<<", ""); + } + if (!string.IsNullOrEmpty(_printModeCond) && _printModeCond.IndexOf(';') > 0) + { + string[] str = _printModeCond.Split(';'); + if (!dataCaches.GetValue(this, "PrintOtherSystemRow", out DataRow item)) + { + item = AttachImpl.GetSystemModule(str[0]); + } + if (item == null) return; + string tableName = item["TableName"] + ""; + string modetype = item["modType"] + ""; + if (!dataCaches.GetValue(this, "PrintOtherColumnPrefix", out string comprefix)) + { + comprefix = BaseImpl.GetColumnPrefix(tableName); + } + if (!dataCaches.GetValue(this, "PrintOtherPrimaryKey", out string primaryKey)) + { + primaryKey = modetype == "1" ? BaseImpl.GetBasePrimaryKey(str[0]) : comprefix + "billdocument_id"; + } + //表名,列前缀,主键字段,主键值,模块编号,主打印Sql + _printSaveParams = new List() { tableName, comprefix, primaryKey, str[1], str[0], _mainPrintSql }; + + //判断是否直接打印 modetype 区别单据和基础档案模块 + if (!dataCaches.GetValue(this, "PrintOtherIsExcPrint", out _isExcPrint)) + { + switch (modetype) + { + case "1": + ModuleModel mode = new ModuleModel(MainImpl.GetSystemdllTab(str[0])); + if (mode != null) _isExcPrint = mode.PrintType == 3; + break; + case "2": + BaseAccraditationModel model = new BaseAccraditationModel(BillAuditImpl.GetPubAuditProperty(str[0])); + if (model != null) _isExcPrint = model.BillPrintType == 3; + break; + } + } + } + } + /// + /// 说明:打印模版 + /// 创建人:龚宇超 + /// 创建日期:2017-11-27 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + protected void OnPrintItemClick(object sender, ItemClickEventArgs e) + { + string printFile = e.Item.Tag + ""; + string printPath = PubUtil.PrintFileAbsolutelyPath; + + if (!File.Exists(printPath)) + { + MessageUtil.Show(ResourceKeys.NotFoundPrintFile); + return; + } + + bool isPrint = this.BillModel.SaveState; + if (!isPrint) + { + if (MessageUtil.Show(ResourceKeys.BillNotSavedAndNotPrint, MessageBoxButtons.YesNo) == DialogResult.Yes) + isPrint = this.BillSave(); + } + + if (isPrint) + { + try + { + // 判断是否满足打印条件 + + //DataRow masterRow = BillImpl.GetDataRowResult(this.BillModel.MasterSql.Replace("{" + this.BillModel.PrimaryKey + "}", this.lblOrderNo.Text)); + DataRow masterRow = BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, this.lblOrderNo.Text)); + if (masterRow == null) + { + MessageUtil.Show(ResourceKeys.DataNotFount); + return; + } + + if (!ReplaceHelper.ReplaceRowParamCond(masterRow, this.BillModel.PrintCond)) + { + MessageUtil.Show(ResourceKeys.DisSatisfyPrintCond); + return; + } + + string tmpSql = ReplaceHelper.ReplaceRowParam(masterRow, this.BillModel.PrintSql); + string tmpSql1 = ReplaceHelper.ReplaceRowParam(masterRow, this.BillModel.PrintSql1); + string tmpSql2 = ReplaceHelper.ReplaceRowParam(masterRow, this.BillModel.PrintSql2); + + if (printFile.Contains(PrintUtil.TemplateFlag)) + { + //主Sql + string mainSql = string.Empty; + List tmpSqls = new List(); + if (_printSaveParams != null && _printSaveParams.Count > 0) + { + _printSaveParams[5] = mainSql = ReplaceHelper.ReplaceRowParam(masterRow, _mainPrintSql); + _printSaveParams[3] = masterRow.Table.Columns.Contains(_printSaveParams[2] + "") ? masterRow[_printSaveParams[2]] + "" : masterRow[BillModel.PrimaryKey] + ""; + tmpSqls.Add(mainSql); + tmpSqls.Add(tmpSql1); + tmpSqls.AddRange(tmpSql2.Split(';').ToList()); + } + else + { + if (!string.IsNullOrWhiteSpace(tmpSql)) tmpSqls.Add(tmpSql); + if (!string.IsNullOrWhiteSpace(tmpSql1)) tmpSqls.Add(tmpSql1); + if (!string.IsNullOrWhiteSpace(tmpSql2)) tmpSqls.AddRange(tmpSql2.Split(';').ToList()); + } + PrintUtil.OnAfterPrint -= new EventHandler(OnReportPrintAfter); + PrintUtil.OnAfterPrint += new EventHandler(OnReportPrintAfter); + PrintUtil.FastReportPrint(tmpSqls, printFile, _isExcPrint); + } + else + { + DelphiHelper.LoadDelphiDll(printPath, printPath, printFile, tmpSql, tmpSql1, this.BillModel.PrintFileType, tmpSql2); + } + //LogUtil.WriteDebug(this.SysModel.ModuleCode, "打印", "单据打印:" + printFile.Replace(".rmf", "").Replace(".frx", ""), "打印格式:" + printFile); + } + catch (Exception ex) + { + MessageUtil.Show(ex.Message + "\r\n" + ex.StackTrace); + LogUtil.WriteError(ResourceKeys.BillModule + "打印模板错误", ex); + LogHelper.Instance.WriteError(ex); + } + } + } + + /// + /// 打印 + /// + /// + /// + private void btnPrint_Click(object sender, EventArgs e) + { + string[] files = this.BillModel.PrintFile.Split('|'); + string printFile = files[0]; + string printPath = PubUtil.PrintFileAbsolutelyPath; + if (!File.Exists(printPath)) + { + MessageUtil.Show(ResourceKeys.NotFoundPrintFile); + return; + } + + bool isPrint = this.BillModel.SaveState; + if (!isPrint) + { + if (MessageUtil.Show(ResourceKeys.BillNotSavedAndNotPrint, MessageBoxButtons.YesNo) == DialogResult.Yes) + isPrint = this.BillSave(); + } + + if (isPrint) + { + try + { + // 判断是否满足打印条件 + + //DataRow masterRow = BillImpl.GetDataRowResult(this.BillModel.MasterSql.Replace("{" + this.BillModel.PrimaryKey + "}", this.lblOrderNo.Text)); + DataRow masterRow = BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, this.lblOrderNo.Text)); + if (masterRow == null) + { + MessageUtil.Show(ResourceKeys.DataNotFount); + return; + } + + if (!ReplaceHelper.ReplaceRowParamCond(masterRow, this.BillModel.PrintCond)) + { + MessageUtil.Show(ResourceKeys.DisSatisfyPrintCond); + return; + } + + string tmpSql = ReplaceHelper.ReplaceRowParam(masterRow, this.BillModel.PrintSql); + string tmpSql1 = ReplaceHelper.ReplaceRowParam(masterRow, this.BillModel.PrintSql1); + string tmpSql2 = ReplaceHelper.ReplaceRowParam(masterRow, this.BillModel.PrintSql2); + + if (printFile.Contains(PrintUtil.TemplateFlag)) + { + //主Sql + string mainSql = string.Empty; + List tmpSqls = new List(); + if (_printSaveParams != null && _printSaveParams.Count > 0) + { + _printSaveParams[5] = mainSql = ReplaceHelper.ReplaceRowParam(masterRow, _mainPrintSql); + _printSaveParams[3] = masterRow.Table.Columns.Contains(_printSaveParams[2] + "") ? masterRow[_printSaveParams[2]] + "" : masterRow[BillModel.PrimaryKey] + ""; + tmpSqls.Add(mainSql); + tmpSqls.Add(tmpSql1); + tmpSqls.AddRange(tmpSql2.Split(';').ToList()); + } + else + { + if (!string.IsNullOrWhiteSpace(tmpSql)) tmpSqls.Add(tmpSql); + if (!string.IsNullOrWhiteSpace(tmpSql1)) tmpSqls.Add(tmpSql1); + if (!string.IsNullOrWhiteSpace(tmpSql2)) tmpSqls.AddRange(tmpSql2.Split(';').ToList()); + } + PrintUtil.OnAfterPrint -= new EventHandler(OnReportPrintAfter); + PrintUtil.OnAfterPrint += new EventHandler(OnReportPrintAfter); + PrintUtil.FastReportPrint(tmpSqls, printFile, _isExcPrint); + } + else + { + DelphiHelper.LoadDelphiDll(printPath, printPath, printFile, tmpSql, tmpSql1, this.BillModel.PrintFileType, tmpSql2); + } + //LogUtil.WriteDebug(this.SysModel.ModuleCode, "打印", "单据打印:" + printFile.Replace(".rmf", "").Replace(".frx", ""), "打印格式:" + printFile); + if (ScanCodeTextEdit != null) ScanCodeTextEdit.Focus(); + } + catch (Exception ex) + { + MessageUtil.Show(ex.Message + "\r\n" + ex.StackTrace); + LogUtil.WriteError(ResourceKeys.BillModule + "打印模板错误", ex); + LogHelper.Instance.WriteError(ex); + } + } + } + #endregion + + #region 单据来源相关 + + /// + /// 说明:刷新单据来源主表,未传递时,默认刷新 + /// 创建人:龚宇超 + /// 创建日期:2017-12-13 + /// 修改人: + /// 修改日期: + /// 修改备注:gcMain + /// 版本:1.0 + /// + /// The union model. + /// XtraTabPage. + private void RefreshSource(BillSourceUnionModel unionModel = null) + { + if (unionModel == null || unionModel.SearchObj == null) return; + unionModel.SearchObj.SearchLastGrid(); + } + + /// + /// 说明:刷新表格列(时间) + /// 创建人:王一帆 + /// 创建日期:2018-08-16 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// + /// + private void OnDataFileRefrshFile(object sender, EventArgs e) + { + AddDataColumns(); + UpdateDynamicColumns(); + UpdateSummaryData(); + OnGcMainDataSourceChanged(gcMain.GridView, null);//手动刷新日期合计数据源 + } + + + /// + /// 说明:计算列关联字段 + /// 创建人:龚宇超 + /// 创建日期:2017-12-18 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The model. + /// The field value. + protected virtual void SetUnionValue(GridColumnModel model, string fieldValue, DataRow rowItem) + { + DataTable table = this.gcMain.gridControl.DataSourceTable(); + //DataRow rowItem = this.gridView.GetFocusedDataRow(); + string unionValues = model.UnionValues; + if (rowItem != null && model != null) + { + unionValues = ReplaceHelper.ReplaceRowParam(rowItem, unionValues.Replace("{" + model.FieldName + "}", fieldValue)); + if (this.ControlObj != null) + { + unionValues = ControlObj.ReplaceParentControlValue(unionValues); + } + try + { + string[] fields = model.UnionFields.Trim(',').Split(','); + DataRow rowResult = BaseImpl.GetDataRowResult(unionValues); + if (rowResult != null) + { + for (int i = 0; i < fields.Length; i++) + { + string field = fields[i]; + string value = rowResult.Table.Columns.Contains(field) ? rowResult[field] + "" : null; + rowItem[field] = value; + } + } + else + { + // 设置为空 + for (int i = 0; i < fields.Length; i++) + { + string field = fields[i]; + rowItem[field] = DBNull.Value; + } + } + } + catch (Exception ex) + { + LogHelper.Instance.WriteError(ex); + LogUtil.WriteError("计算列关联字段--错误-->" + unionValues, ex); + } + } + } + /// + /// 说明:禁用控件条件 + /// 创建人:龚宇超 + /// 创建日期:2019-01-22 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The model. + /// The field value. + protected virtual void SetDisableColumn(GridColumnModel model, string fieldValue, DataRow rowItem) + { + if (model.EnableCond != string.Empty) + { + List columns = this.gcMain.ObjmControlList.FindAll(x => x.EnableCond.Contains("{" + model.FieldName + "}")).ToList(); + foreach (GridColumnModel item in columns) + { + try + { + string disableCond = ReplaceHelper.ReplaceRowParam(rowItem, item.EnableCond.Replace("{" + model.FieldName + "}", fieldValue)); + string diaableType = item.DisableType; + if (this.BillModel.DetailTreeTable) + { + (this.gcMain as TreeGridControlEx).TreeListObj.Columns.ColumnByFieldName(model.FieldName).Visible = ("true".Equals(EvalHelper.Eval(ReplaceHelper.ReplaceEvalCond(disableCond)) + "", StringComparison.OrdinalIgnoreCase)); + } + else + { + this.gcMain.GridView.Columns.ColumnByFieldName(model.FieldName).Visible = ("true".Equals(EvalHelper.Eval(ReplaceHelper.ReplaceEvalCond(disableCond)) + "", StringComparison.OrdinalIgnoreCase)); + } + } + catch (Exception) + { + } + } + } + } + /// + /// 说明:计算列计算公式 + /// 创建人:龚宇超 + /// 创建日期:2017-12-18 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The model. + /// The field value. + protected virtual void SetCalcValue(GridColumnModel model, string fieldValue, DataRow rowItem) + { + try + { + DataTable table = this.gcMain.gridControl.DataSourceTable(); + if (rowItem != null && model != null) + { + List calcModels = this.gcMain.ObjmControlList.FindAll(x => !string.IsNullOrEmpty(x.CalcExpr)).OrderBy(y => y.CalcOrder).ToList(); + + foreach (GridColumnModel gridModel in calcModels) + { + // 计算顺序小于当前控件则不计算 + if (gridModel.CalcOrder < model.CalcOrder) continue; + + if (!gridModel.FieldName.Equals(model.FieldName, StringComparison.OrdinalIgnoreCase)) + { + bool isTruncate = false; + string calcExpr = gridModel.CalcExpr; + if (calcExpr.StartsWith("@truncate:")) + { + calcExpr = calcExpr.Substring(10); + isTruncate = true; + } + + try + { + if (this.ControlObj != null) + calcExpr = ControlObj.ReplaceParentControlValue(calcExpr); + + calcExpr = ReplaceHelper.ReplaceRowParam(rowItem, calcExpr); + //EvalHelper.Eval2(ReplaceHelper.ReplaceEvalCond(calcExpr)) + "" + string result = EvalHelper.Eval2(ReplaceHelper.ReplaceEvalCond(calcExpr)) + ""; + if (isTruncate) + { + result += result.Contains(".") ? "0000000000" : ".0000000000"; + rowItem[gridModel.FieldName] = result.Substring(0, result.IndexOf(".")) + result.Substring(result.IndexOf("."), model.Decimals + 1); + //this.gridView.SetRowCellValue(this.gridView.FocusedRowHandle, this.gridView.Columns[gridModel.FieldName], result.Substring(0, result.IndexOf(".")) + result.Substring(result.IndexOf("."), model.Decimals + 1)); + } + else + { + try + { + double d = 0; + if (!string.IsNullOrEmpty(result) && + !"NaN".Equals(result, StringComparison.OrdinalIgnoreCase) && + !"非数字".Equals(result, StringComparison.OrdinalIgnoreCase) && + !"undefined".Equals(result, StringComparison.OrdinalIgnoreCase) && + result != "∞" && result != "-∞" && + !"正无穷大".Equals(result, StringComparison.OrdinalIgnoreCase) && + !"负无穷大".Equals(result, StringComparison.OrdinalIgnoreCase) && + double.TryParse(result, out d)) + { + if (string.IsNullOrEmpty(gridModel.DataFormat)) + { + result = Math.Round(Convert.ToDouble(d), model.Decimals, MidpointRounding.AwayFromZero) + ""; + } + else + { + //计算后先执行保存小数位数 + result = string.Format("{0:" + gridModel.DataFormat + "}", Convert.ToDecimal(result)); + } + if (model.FieldType == 7 && result.Contains('%')) + { + result = (double.Parse(result.Replace("%", "")) * 0.01).ToString(); + } + rowItem[gridModel.FieldName] = result; + // 判断计算列有无关联值 + GridColumnModel UnionModel = calcModels.FirstOrDefault(x => x.FieldName == gridModel.FieldName); + if (!string.IsNullOrEmpty(UnionModel.UnionFields)) + { + this.SetUnionValue(UnionModel, rowItem[gridModel.FieldName] + "", rowItem); + } + //this.gridView.SetRowCellValue(this.gridView.FocusedRowHandle, this.gridView.Columns[gridModel.FieldName], result); + } + } + catch (Exception) + { + + } + } + } + catch (Exception ex) + { + LogHelper.Instance.WriteError(ex); + LogUtil.WriteError("计算列计算公式--错误-->" + rowItem[gridModel.FieldName], ex); + } + } + } + } + } + catch (Exception ex) + { + LogHelper.Instance.WriteError(ex); + string Message = ErrorMessage.PromptErrorMessage(ex); + // MessageUtil.Show(Message,ex.Message); + } + } + /// + /// 说明:添加行到单据明细中 + /// 创建人:龚宇超 + /// 创建日期:2017-11-30 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The row item. + /// The union model. + private DataRow AddRowToGridView(DataRow rowItem, bool dataProcessing = true) + { + GridColumnCollection gridColumns = this.gcMain.GridView.Columns; + DataTable gridTable = (this.gcMain.GridControl.DataSource as DataTable).TrimDeleteRows(); + if (!gridTable.Columns.Contains(ERPInfo.Instance.isAddRows)) + { + gridTable.Columns.Add(ERPInfo.Instance.isAddRows, typeof(String)); + } + string repeatProduct = this.gcMain.GridView.Columns["ProductId"] != null && rowItem.Table.Columns.Contains("ProductId") ? "ProductId" : this.BillModel.DetailPreFix + "ProductId"; + AssociatedField = repeatProduct; + if ("1".Equals(this.BillModel.DetailDoubleClickTip) && rowItem.Table.Columns.Contains(repeatProduct)) + { + + //上面方法无法处理大小写,改成搜索的形式 + DataTable dt = this.gcMain.gridControl.DataSourceTable(); + if (dt != null && dt.Rows.Count > 0 && dt.Columns.Contains(repeatProduct)) + { + DataRow[] drs = dt.Select(repeatProduct + "='" + rowItem[repeatProduct] + "'"); + if (drs.Length >= 1) + { + DialogResult dialog = MessageUtil.Show(ResourceKeys.ProductIsRepet, MessageBoxButtons.YesNo); + if (dialog != DialogResult.Yes) + { + return null; + } + } + } + } + DataRow newRow = gridTable.NewRow(); + //if (gridTable.Columns.Contains(guidField)) + //{ + // newRow[guidField] = Guid.NewGuid().ToString(); + //} + //2024-1-29改成>=,之前为>导致选中第一行只会添加到最后一行(测试空白行没有影响) + int position = this.gcMain.GridView.FocusedRowHandle >= 0 ? gridTable.Rows.Count > 0 ? this.gcMain.GridView.FocusedRowHandle : 0 : gridTable.Rows.Count - 1; + bool isLastRow = this.gcMain.GridView.IsLastVisibleRow; + this.gcMain.GridView.BeginDataUpdate(); + GridView gridView = this.gcMain.GridView; + // 赋值明细字段 + foreach (GridColumn col in gridColumns) + { + try + { + // 未包含字段,则使用控件默认值. + GridColumnModel model = col.Tag as GridColumnModel; + if (model == null) + { + if (rowItem.Table.Columns.Contains(col.FieldName)) + { + // 来源列中是否包含对应字段,包含则使用值 + newRow[col.FieldName] = rowItem[col.FieldName]; + } + continue; + } + if (rowItem.Table.Columns.Contains(col.FieldName)) + { + // 来源列中是否包含对应字段,包含则使用值 + newRow[col.FieldName] = rowItem[col.FieldName]; + if (dataProcessing) + { + if (!string.IsNullOrEmpty(model.UnionFields)) + { + this.SetUnionValue(model, rowItem[col.FieldName] + "", newRow); + } + SetCalcValue(model, rowItem[col.FieldName] + "", newRow); + } + + } + else + { + + if (col.FieldName.Contains("_Ls")) + { + string[] unioFielName = col.FieldName.Split('_'); + string UnioValue = unioFielName[unioFielName.Length - 1]; + DataColumn grid = rowItem.Table.Columns.Cast().FirstOrDefault(x => x.ColumnName.Split('_')[x.ColumnName.Split('_').Length - 1].Equals(UnioValue)); + if (dataProcessing) + { + if (grid != null && !string.IsNullOrEmpty(model.UnionFields)) + { + this.SetUnionValue(model, rowItem[col.FieldName] + "", newRow); + } + SetCalcValue(model, rowItem[col.FieldName] + "", newRow); + } + + } + else + { + string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue); + //int nowPositon = !isLastRow ? position : gridTable.Rows.Count - 1; + + if (model.DefaultValue.Contains("{#")) + { + fieldValue = this.ControlObj.ReplaceParentControlValue(model.DefaultValue); + if (fieldValue.StartsWith("@")) + { + fieldValue = BaseImpl.GetDefaultValue(fieldValue); + } + if (!string.IsNullOrEmpty(fieldValue)) + { + newRow[col.FieldName] = fieldValue; + if (dataProcessing) + { + if (!string.IsNullOrEmpty(model.UnionFields)) + { + this.SetUnionValue(model, newRow[col.FieldName] + "", newRow); + } + SetCalcValue(model, newRow[col.FieldName] + "", newRow); + } + //计算规则配置在结果字段上,所以无需验证当前操作控件 + //this.gcMain.GridView.SetFocusedRowCellValue(col, fieldValue); + } + } + else if (!string.IsNullOrEmpty(model.DefaultValue)) + { + if (string.IsNullOrEmpty(newRow[col.FieldName] + "")) + { + newRow[col.FieldName] = fieldValue; + } + if (dataProcessing) + { + if (!string.IsNullOrEmpty(model.UnionFields)) + { + this.SetUnionValue(model, newRow[col.FieldName] + "", newRow); + } + SetCalcValue(model, newRow[col.FieldName] + "", newRow); + //this.gcMain.GridView.SetFocusedRowCellValue(col, fieldValue); + } + } + } + } + SetDisableColumn(model, newRow[col.FieldName] + "", newRow); + //GridColumnModel model = col.Tag as GridColumnModel; + if (model.LimitLength > 0) + { + DataRow HandleRow = newRow; + int MaxInputLength = System.Text.Encoding.Default.GetBytes(newRow[col.FieldName] + "").Length; + if (model.LimitLength < MaxInputLength) + HandleRow.SetColumnError(HandleRow.Table.Columns[col.ColumnHandle], "当前输入文本超过设定长度!");//满足条件设置错误信息 + } + } + catch (Exception ex) + { + LogHelper.Instance.WriteError(ex); + //LogUtil.WriteError(col.FieldName + "添加出错!", ex); + } + } + this.gcMain.GridView.EndDataUpdate(); + if (!isLastRow) + { + // 插入数据行 + gridTable.Rows.InsertAt(newRow, position + 1); + this.gcMain.GridView.ClearSelection(); + this.gcMain.GridView.SelectRowHandler(position + 1); + } + else + { + // 添加数据行 + gridTable.Rows.Add(newRow); + this.gcMain.GridView.ClearSelection(); + this.gcMain.GridView.SelectRowHandler(gridTable.Rows.Count - 1); + } + + + // 插入数据后 + if (isLastRow) + { + this.gcMain.GridView.ClearSelection(); + this.gcMain.GridView.SelectRowHandler(position + 1); + } + if (!string.IsNullOrEmpty(NumberMc) && gridTable.Columns.Contains(mRecordPrimaryField)) + { + DataRow[] rt = gridTable.Rows.Cast().Where(x => (newRow[BillModel.DetailPreFix + "ProductId"] + "").Equals(x[BillModel.DetailPreFix + "ProductId"] + "") && !string.IsNullOrEmpty(x[mRecordPrimaryField] + "")).ToArray(); + foreach (DataRow item in rt) + { + if (newRow != null) + { + newRow[NumberMc] = Convert.ToDouble(newRow[NumberMc]) - Convert.ToDouble(item[NumberMc]); + } + this.gcMain.OnGridViewCellValueChanged(this.gcMain, new CellValueChangedEventArgs(position + 1, this.gcMain.GridView.Columns[NumberMc], newRow[NumberMc] + "")); + this.gcMain.GridView.UpdateCurrentRow(); + this.gcMain.GridView.ShowEditor(); + if (Convert.ToDouble(newRow[NumberMc] + "") == 0.0) + { + gridTable.Rows.Remove(newRow); + MessageUtil.Show("数量已分配完毕!无需再进行拖拽!"); + } + } + } + gridTable.OrderBy(this.BillModel.DetailOrderField); + this.gcMain.GridView.UpdateCurrentRow(); + this.gcMain.GridView.ShowEditor(); + return newRow; + } + /// + /// 说明:添加多行到单据明细中 + /// 创建人:龚宇超 + /// 创建日期:2017-11-30 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The row item. + /// The union model. + private void AddRowsToGridView(DataTable dataTable, BillSourceUnionModel unionModel) + { + WaitForm.ShowForm(); + GridColumnCollection gridColumns = this.gcMain.GridView.Columns; + DataTable gridTable = (this.gcMain.GridControl.DataSource as DataTable).TrimDeleteRows().Copy(); + if (!gridTable.Columns.Contains(ERPInfo.Instance.isAddRows)) + { + gridTable.Columns.Add(ERPInfo.Instance.isAddRows, typeof(String)); + } + int position = this.gcMain.GridView.FocusedRowHandle; + bool isLastRow = this.gcMain.GridView.IsLastVisibleRow; + bool onlyOne = true; + foreach (DataRow rowItem in dataTable.Rows) + { + if (unionModel == null || ValidateDetailCond(rowItem, unionModel)) + { + string repeatProduct = this.gcMain.GridView.Columns["ProductId"] != null && dataTable.Columns.Contains("ProductId") ? "ProductId" : this.BillModel.DetailPreFix + "ProductId"; + AssociatedField = repeatProduct; + if ("1".Equals(this.BillModel.DetailDoubleClickTip) && this.gcMain.GridView.Columns[repeatProduct] != null && dataTable.Columns.Contains(repeatProduct)) + { + // 需要提示编码重复 + //GridView view = this.gcMain.GridView; + //bool result = (view.LocateByValue(repeatProduct, rowItem[repeatProduct], null) >= 0) | + // (view.LocateByValue(repeatProduct, rowItem[repeatProduct], null) >= 0) | + // (view.LocateByValue(repeatProduct, rowItem[repeatProduct], null) >= 0) | + // (view.LocateByValue(repeatProduct, rowItem[repeatProduct], null) >= 0); + //if (result) + //{ + // DialogResult dialog = MessageUtil.Show(ResourceKeys.ProductIsRepet, MessageBoxButtons.YesNo); + // if (dialog != DialogResult.Yes) + // return; + //} + + //上面方法无法处理大小写,改成搜索的形式 + DataTable dt = this.gcMain.gridControl.DataSourceTable(); + if (dt != null && dt.Rows.Count > 0 && dt.Columns.Contains(repeatProduct)) + { + DataRow[] drs = dt.Select(repeatProduct + "='" + rowItem[repeatProduct] + "'"); + if (drs.Length >= 1) + { + DialogResult dialog = MessageUtil.Show(ResourceKeys.ProductIsRepet, MessageBoxButtons.YesNo); + if (dialog != DialogResult.Yes) + return; + } + } + + } + + DataRow newRow = gridTable.NewRow(); + newRow.BeginEdit(); + // 赋值明细字段 + foreach (GridColumn col in gridColumns) + { + try + { + GridColumnModel model = col.Tag as GridColumnModel; + if (model == null) continue; + if (dataTable.Columns.Contains(col.FieldName)) + { + // 来源列中是否包含对应字段,包含则使用值 + newRow[col.FieldName] = rowItem[col.FieldName]; + if (!string.IsNullOrEmpty(model.UnionFields)) + { + this.SetUnionValue(model, rowItem[col.FieldName] + "", newRow); + } + SetCalcValue(model, rowItem[col.FieldName] + "", newRow); + + } + else + { + // 未包含字段,则使用控件默认值. + if (col.FieldName.Contains("_Ls")) + { + string[] unioFielName = col.FieldName.Split('_'); + string UnioValue = unioFielName[unioFielName.Length - 1]; + DataColumn grid = dataTable.Columns.Cast().FirstOrDefault(x => x.ColumnName.Split('_')[x.ColumnName.Split('_').Length - 1].Equals(UnioValue)); + if (grid != null && !string.IsNullOrEmpty(model.UnionFields)) + { + this.SetUnionValue(model, rowItem[col.FieldName] + "", newRow); + } + SetCalcValue(model, rowItem[col.FieldName] + "", newRow); + + } + else + { + string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue); + //int nowPositon = !isLastRow ? position : gridTable.Rows.Count - 1; + if (model.DefaultValue.Contains("{#")) + { + fieldValue = this.ControlObj.ReplaceParentControlValue(model.DefaultValue); + if (!string.IsNullOrEmpty(fieldValue)) + { + newRow[col.FieldName] = fieldValue; + if (!string.IsNullOrEmpty(model.UnionFields)) + { + this.SetUnionValue(model, fieldValue + "", newRow); + } + SetCalcValue(model, fieldValue + "", newRow); + + //计算规则配置在结果字段上,所以无需验证当前操作控件 + //this.gcMain.GridView.SetFocusedRowCellValue(col, fieldValue); + } + } + else if (!string.IsNullOrEmpty(model.DefaultValue)) + { + if (string.IsNullOrEmpty(newRow[col.FieldName] + "")) + { + newRow[col.FieldName] = fieldValue; + } + + if (!string.IsNullOrEmpty(model.UnionFields)) + { + this.SetUnionValue(model, newRow[col.FieldName] + "", newRow); + } + SetCalcValue(model, newRow[col.FieldName] + "", newRow); + + //this.gcMain.GridView.SetFocusedRowCellValue(col, fieldValue); + } + } + } + SetDisableColumn(model, newRow[col.FieldName] + "", newRow); + } + catch (Exception ex) + { + LogHelper.Instance.WriteError(ex); + //LogUtil.WriteError(col.FieldName + "添加出错!", ex); + } + } + newRow.EndEdit(); + if (!isLastRow) + { + // 插入数据行 + gridTable.Rows.InsertAt(newRow, position); + //this.gcMain.GridView.ClearSelection(); + //this.gcMain.GridView.SelectRowHandler(position); + } + else + { + // 添加数据行 + gridTable.Rows.Add(newRow); + // this.gcMain.GridView.ClearSelection(); + // this.gcMain.GridView.SelectRowHandler(gridTable.Rows.Count - 1); + } + position++; + //if (isLastRow) + //{ + // this.gcMain.GridView.ClearSelection(); + // this.gcMain.GridView.SelectRowHandler(position + 1); + //} + if (!string.IsNullOrEmpty(NumberMc) && gridTable.Columns.Contains(mRecordPrimaryField)) + { + DataRow[] rt = gridTable.Rows.Cast().Where(x => (newRow[BillModel.DetailPreFix + "ProductId"] + "").Equals(x[BillModel.DetailPreFix + "ProductId"] + "") && !string.IsNullOrEmpty(x[mRecordPrimaryField] + "")).ToArray(); + foreach (DataRow item in rt) + { + if (newRow != null) + { + newRow[NumberMc] = Convert.ToDouble(newRow[NumberMc]) - Convert.ToDouble(item[NumberMc]); + } + this.gcMain.OnGridViewCellValueChanged(this.gcMain, new CellValueChangedEventArgs(position + 1, this.gcMain.GridView.Columns[NumberMc], newRow[NumberMc] + "")); + this.gcMain.GridView.UpdateCurrentRow(); + this.gcMain.GridView.ShowEditor(); + if (Convert.ToDouble(newRow[NumberMc] + "") == 0.0) + { + gridTable.Rows.Remove(newRow); + MessageUtil.Show("数量已分配完毕!无需再进行拖拽!"); + } + } + } + } + else + { + if (onlyOne) + { + onlyOne = false; + if (!string.IsNullOrEmpty(unionModel.ModelObj.DetailEnableMsg)) + { + if (unionModel.ModelObj.DetailEnableMsg.StartsWith("select", StringComparison.OrdinalIgnoreCase) || + unionModel.ModelObj.DetailEnableMsg.StartsWith("exec", StringComparison.OrdinalIgnoreCase)) + { + MessageUtil.Show(BaseImpl.GetResult(unionModel.ModelObj.DetailEnableMsg) + ""); + } + else + { + MessageUtil.Show(unionModel.ModelObj.DetailEnableMsg); + } + } + } + } + } + this.gcMain.GridControl.DataSource = gridTable; + if (position >= 0) + this.gcMain.GridView.SelectRowHandler(position); + else + this.gcMain.GridView.SelectRowHandler(gridTable.Rows.Count - 1); + //this.gcMain.GridView.SelectRowHandler(position); + gridTable.OrderBy(this.BillModel.DetailOrderField); + this.gcMain.GridView.UpdateCurrentRow(); + this.gcMain.GridView.ShowEditor(); + WaitForm.HideForm(); + } + /// + /// 添加多行数据到单据明细中,禁用所有关联和默认值的获取 + /// + /// + /// + private void AddRowsToGridViewFast(DataRow[] rowItems) + { + try + { + DataTable gridTable = (this.gcMain.GridControl.DataSource as DataTable).TrimDeleteRows(); + foreach (DataRow rowItem in rowItems) + { + DataRow dataRow = gridTable.NewRow(); + foreach (DataColumn column in gridTable.Columns) + { + if (rowItem.Table.Columns.Contains(column.ColumnName)) + { + dataRow[column] = rowItem[column.ColumnName]; + } + } + gridTable.Rows.Add(dataRow); + } + } + catch (Exception ex) + { + MessageUtil.Show(ex.Message); + } + } + /// + /// 说明:检查添加数据到表格中是否包含 + /// + /// 创建人:龚宇超 + /// 创建日期:2018-04-20 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The row item. + /// The union model. + /// if set to true [only popup]. + private void AddRowToGridViewByBom(DataRow rowItem, BillSourceUnionModel unionModel, ref bool onlyPopup) + { + if (!string.IsNullOrEmpty(unionModel.ModelObj.BomSql)) + { + string bomSql = unionModel.ModelObj.BomSql; + // 检查是否有bom配置 + if (unionModel.ModelObj.LoadBom == 1) + { + // 自动带出bom数据,不弹出选择 + DataTable table = BaseImpl.GetDataTableResult(ReplaceHelper.ReplaceRowParam(rowItem, bomSql)); + foreach (DataRow item in table.Rows) + { + this.AddRowToGridView(item); + } + } + else if (unionModel.ModelObj.LoadBom == 2) + { + DataTable table = BaseImpl.GetDataTableResult(ReplaceHelper.ReplaceRowParam(rowItem, bomSql)); + + if (!onlyPopup && table.Rows.Count > 0) + { + // 自动带出bom数据,弹出选择 + FrmBomSelect frmSelect = new FrmBomSelect(); + frmSelect.Caption = unionModel.ModelObj.BomCaption; + frmSelect.GridColumns = unionModel.GridDetailControlObj.GridView.Columns; + frmSelect.BomDataTable = table; + + DialogResult result = frmSelect.ShowDialog(); + onlyPopup = frmSelect.OnlyPopup; + + if (result == DialogResult.OK && frmSelect.SelectBomRows != null && frmSelect.SelectBomRows.Length > 0) + { + foreach (DataRow item in frmSelect.SelectBomRows) + { + this.AddRowToGridView(item); + } + } + } + else + { + foreach (DataRow item in table.Rows) + { + this.AddRowToGridView(item); + } + } + } + } + } + + /// + /// 说明:添加多条数据到单据明细 + /// 创建人:龚宇超 + /// 创建日期:2018-05-30 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The table. + private void AddMultiRowToGridView(DataTable table, BillSourceUnionModel unionModel = null) + { + if (table == null) return; + if (this.BillModel.DetailTreeTable) + { + this.AddRowsToTreeGridControl(table, unionModel); + } + else + { + this.AddRowsToGridView(table, unionModel); + } + + + Application.DoEvents(); + } + /// + /// 说明:是否允许添加明细 + /// 创建人:龚宇超 + /// 创建日期:2018-06-06 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// true if this instance [can add detail row]; otherwise, false. + private bool CanAddDetailRow() + { + // 检测是否正在筛选数据 + if (!string.IsNullOrEmpty(gcMain.GridView.FindFilterText.Trim()) || + !string.IsNullOrEmpty(gcMain.GridView.FilterPanelText.Trim())) + { + if (MessageUtil.Show(ResourceKeys.GridViewSearching, MessageBoxButtons.YesNo) == DialogResult.Yes) + { + this.gcMain.GridView.FindFilterText = ""; + return true; + } + return false; + } + // 检测是否点击了排序表格 + if (this.gcMain.GridView.HasSortColumn()) + { + //if (MessageUtil.Show(ResourceKeys.GridViewColumnSorting, MessageBoxButtons.YesNo) == DialogResult.Yes) + //{ + this.gcMain.GridView.Columns.ClearAllSort(); + // return true; + //} + //return false; + } + // 检测是否为提交或者终审模块 + if (_waterMark.Text.Contains("已终审")) + { + MessageUtil.Show(ResourceKeys.AddBillDetailed); + return false; + } + return true; + } + + /// + /// 说明:单据明细撤回操作 + /// 创建人:曹屹峰 + /// 创建日期:2021-11-09 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + private void OnToWithdraw(object sender, KeyEventArgs e) + { + if (e.Control && e.KeyCode == Keys.Z) + { + if (ToWithdrawRows.Count < 1) return; + DataTable gridTable = (this.gcMain.GridControl.DataSource as DataTable).TrimDeleteRows(); + Dictionary undo = ToWithdrawRows[ToWithdrawRows.Count - 1]; + foreach (int key in undo.Keys) + { + DataRow dr = gridTable.NewRow(); + dr.ItemArray = undo[key].ItemArray; + gridTable.Rows.InsertAt(dr, key); + this.gcMain.GridView.ClearSelection(); + this.gcMain.GridView.SelectRowHandler(key); + } + gridTable.OrderBy(this.BillModel.DetailOrderField); + ToWithdrawRows.RemoveAt(ToWithdrawRows.Count - 1); + } + if (e.Alt) + { + GridView gridView = sender as GridView; + if (gridView == null) return; + if (e.KeyCode == Keys.Up) + { + DataTable dtTable = gcMain.gridControl.DataSource as DataTable; + if (gridView.FocusedRowHandle > 0 && dtTable.Columns.Contains(this.BillModel.DetailOrderField)) + { + dtTable = SwapRow(gridView.FocusedRowHandle, gridView.FocusedRowHandle - 1, dtTable); + dtTable.OrderBy(this.BillModel.DetailOrderField); + //DataTableOrderBy(dtTable); + } + } + else if (e.KeyCode == Keys.Down) + { + DataTable dtTable = gcMain.gridControl.DataSource as DataTable; + if (gridView.FocusedRowHandle < dtTable.Rows.Count - 1 && dtTable.Columns.Contains(this.BillModel.DetailOrderField)) + { + dtTable = SwapRow(gridView.FocusedRowHandle, gridView.FocusedRowHandle + 1, dtTable); + dtTable.OrderBy(this.BillModel.DetailOrderField); + //DataTableOrderBy(dtTable); + } + } + } + } + private DataTable SwapRow(int index1, int index2, DataTable dt) + { + DataRow dr = dt.NewRow(); + dr.ItemArray = dt.Rows[index1].ItemArray; + dt.Rows[index1].ItemArray = dt.Rows[index2].ItemArray; + dt.Rows[index2].ItemArray = dr.ItemArray; + return dt; + } + private void DataTableOrderBy(DataTable dtTable) + { + try + { + if (dtTable.Columns.Contains(this.BillModel.DetailOrderField)) + { + for (int i = 0; i < dtTable.Rows.Count; i++) + { + DataRow row = dtTable.Rows[i]; + if (row.RowState != DataRowState.Deleted) + { + row[this.BillModel.DetailOrderField] = (i + 1); + } + } + } + } + catch (Exception) + { + } + } + + /// + /// 说明: + /// 创建人:龚宇超 + /// 创建日期:2017-11-30 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// true if XXXX, false otherwise. + private bool ValidateDetailCond(DataRow rowItem, BillSourceUnionModel unionModel) + { + bool validate = false; + + try + { + string detailCond = ReplaceHelper.ReplaceRowParam(rowItem, unionModel.ModelObj.DetailEnableCond); + if (detailCond.Contains("#")) + { + List condition = ReplaceHelper.GetParamFields(detailCond); + foreach (string item in condition) + { + string fieldValue = this.ControlObj.GetControlValue(item.Replace("{#", "").Replace("}", "")); + detailCond = detailCond.Replace(item, fieldValue); + } + } + if (detailCond.StartsWith("@") || detailCond.StartsWith("!")) + { + validate = "1".Equals(BaseImpl.GetDefaultValue(detailCond)); + } + else + { + + validate = ReplaceHelper.EvalCond(detailCond); + } + } + catch (Exception ex) + { + LogHelper.Instance.WriteLog(ex.StackTrace); + LogUtil.WriteError("验证多条添加条件出错!", ex); + //MessageUtil.Show(ResourceKeys.CondtionError + "\r\n" + unionModel.ModelObj.DetailEnableCond); + } + return validate; + } + + + /// + /// 说明:初始化附加信息 + /// 创建人:龚宇超 + /// 创建日期:2018-04-26 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + private List GetAttachTabs() + { + List details = new List(); + + DataTable table = BaseAuditImpl.GetAttachTabs(this.SysModel.ModuleCode, "100", " and orderid < 0 "); + foreach (DataRow item in table.Rows) + { + DataTable gridColumns = BaseAuditImpl.GetBottomBasicInformation(item["formKey"] + ""); + details.Add(new GridDetailModel(item, gridColumns, GridCustomColumnStruct.BillSourceDetailAttachGridView)); + } + + return details; + } + #endregion + + #region 单据保存、提交 + /// + /// 说明:获取添加表头数据 + /// 创建人:龚宇超 + /// 创建日期:2017-12-07 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The parmary value. + /// System.String. + private string GetAddRecord(ref string parmaryValue) + { + if (BillModel.NewVer == 0) + { + // 检查当前的单据号是否已被占用. + string newBillNo = BillImpl.GetBillNo(this.BillModel.BillSeq); + + if (!parmaryValue.Equals(newBillNo)) + { + if (MessageUtil.Show(ResourceKeys.BillRecordRepeat, MessageBoxButtons.YesNo) == DialogResult.No) + { + return string.Empty; + } + else + { + this.lblOrderNo.Text = newBillNo; + parmaryValue = newBillNo; + } + } + } + + StringBuilder fieldBuilder = new StringBuilder(); + StringBuilder valueBuilder = new StringBuilder(); + + DataTable DetailedProperties = BaseImpl.GetDataTableResult(string.Format("select COLUMN_NAME,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH from information_schema.columns where table_name = '{0}'", BillModel.MasterTable)); + + string errorMessage = string.Empty;//数据不符合数据库规范的信息 + foreach (ControlModel model in this.ControlObj.ControlModels) + { + if (!model.IsSave || + model.FieldName.Equals(BillModel.PrimaryKey, StringComparison.OrdinalIgnoreCase) || + model.FieldName.Equals(BillModel.RtagidKey, StringComparison.OrdinalIgnoreCase) || + model.FieldType == ControlType.LabPic || + model.FieldType == ControlType.LabPicEx) + continue; + + if (string.IsNullOrWhiteSpace(model.FieldName)) continue; + + string fieldValue = this.ControlObj.GetControlValue(model); + if (SystemInfo.Instance.TrimWhiteSpace) + fieldValue = fieldValue.Trim(); + if (fieldValue == "****") continue; + + errorMessage = errorMessage + DatabaseFormatJudgment.SaveOrModifyBalidation(DetailedProperties, model, fieldValue); + if (string.IsNullOrEmpty(fieldValue) && model.Isintordecimal) fieldValue = "0";//数值保存时为空的话默认保存为0; + + fieldBuilder.Append(model.FieldName + ","); + valueBuilder.Append(string.IsNullOrEmpty(fieldValue) ? this.ControlObj.GetNullValue(model) : string.Format("N'{0}',", fieldValue)); + + + + } + if (!string.IsNullOrWhiteSpace(errorMessage)) SaveErrorMessage = "表头错误:" + errorMessage; + // 增加主键 + fieldBuilder.Append(BillModel.PrimaryKey); + valueBuilder.Append("N'" + parmaryValue + "'"); + // 增加红蓝字单标记 + fieldBuilder.Append("," + BillModel.RtagidKey); + valueBuilder.Append(",N'" + (rdRed.Checked ? 1 : 0) + "'"); + + return string.Format("insert into {0}({1}) values ({2})", BillModel.MasterTable, fieldBuilder.ToString().TrimEnd(','), valueBuilder.ToString().TrimEnd(',')); + } + /// + /// 说明:获取修改表头数据 + /// 创建人:龚宇超 + /// 创建日期:2017-12-07 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// 单据值. + /// System.String. + private string GetUpdateRecord(string parmaryValue) + { + StringBuilder updateBuilder = new StringBuilder(); + + + DataTable DetailedProperties = BaseImpl.GetDataTableResult(string.Format("select COLUMN_NAME,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH from information_schema.columns where table_name = '{0}'", BillModel.MasterTable)); + + + string errorMessage = string.Empty;//数据不符合数据库规范的信息 + // 修改单据 + foreach (ControlModel model in this.ControlObj.ControlModels) + { + if (!model.IsSave || + model.FieldName.Equals(BillModel.RtagidKey, StringComparison.OrdinalIgnoreCase) || + model.FieldType == ControlType.LabPic || + model.FieldType == ControlType.LabPicEx) + continue; + + if (string.IsNullOrWhiteSpace(model.FieldName)) continue; + + BaseUserControl userControl = this.ControlObj.FindControl(model); + if (userControl != null) + { + string fieldValue = this.ControlObj.GetControlValue(model); + if (SystemInfo.Instance.TrimWhiteSpace) + fieldValue = fieldValue.Trim(); + if (fieldValue == "****") continue; + + errorMessage = errorMessage + DatabaseFormatJudgment.SaveOrModifyBalidation(DetailedProperties, model, fieldValue); + if (string.IsNullOrEmpty(fieldValue) && model.Isintordecimal) fieldValue = "0";//数值保存时为空的话默认保存为0; + + updateBuilder.Append(string.IsNullOrEmpty(fieldValue) ? string.Format("{0}={1}", model.FieldName, this.ControlObj.GetNullValue(model)) : string.Format("{0}=N'{1}',", model.FieldName, fieldValue.Contains("'") ? fieldValue.Replace("'", "''") : fieldValue)); + + } + + } + if (!string.IsNullOrWhiteSpace(errorMessage)) SaveErrorMessage = "表头错误:" + errorMessage; + return string.Format("update {0} set {1} where {2}='{3}'", BillModel.MasterTable, updateBuilder.ToString().TrimEnd(','), BillModel.PrimaryKey, parmaryValue); + } + /// + /// 说明:获取保存明细数据 + /// 创建人:龚宇超 + /// 创建日期:2017-12-07 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// System.String. + private StringBuilder GetDetailRecord(string guid, string billNo, List addRowList) + { + // 构造明细 + StringBuilder detailBuilder = new StringBuilder(); + DataTable detailTable = this.gcMain.GridControl.DataSourceTable().TrimDeleteRows(); + if (this.BillModel.DetailTreeTable) + { + detailTable = ((this.gcMain as TreeGridControlEx).TreeListObj.DataSource as DataTable).TrimDeleteRows(); + } + + string Autogrowcolumn = SqlHelper.ExecuteScalar(string.Format("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.columns WHERE TABLE_NAME='{0}' AND COLUMNPROPERTY(OBJECT_ID('{0}'),COLUMN_NAME,'IsIdentity')=1", BillModel.DetailTable)) + ""; ;//自增长列 + DataTable DetailedProperties = BaseImpl.GetDataTableResult(string.Format("select COLUMN_NAME,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH from information_schema.columns where table_name = '{0}'", BillModel.DetailTable + "_temp"));//单据明细性表 + + //主键 + //DataTable primaryKeydt = BaseImpl.GetDataTableResult(string.Format("SELECT TABLE_NAME,COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME='{0}'", BillModel.DetailTable)); + //string primaryKey = string.Empty; + //bool AddPrimaryKey = false; + //if (primaryKeydt.Rows.Count > 0) + //{ + // primaryKey = primaryKeydt.Rows[0]["COLUMN_NAME"] + ""; + //} + //if (!string.IsNullOrWhiteSpace(primaryKey)) + //{ + // DataTable dt = this.gcMain.gridControl.DataSource as DataTable; + // if (dt.Columns.Contains(primaryKey)) + // { + // AddPrimaryKey = true; + // } + //} + + if (detailTable.Rows.Count > 0) + { + int lineNumber = 1; + DataTable BillColumns = BaseImpl.GetDataTableResult(string.Format("select * from {0} where 1<>1", BillModel.DetailTable)); + DataTable BillTempColumns = BaseImpl.GetDataTableResult(string.Format("select * from {0} where 1<>1", BillModel.DetailTable + "_temp")); + foreach (DataRow dataRow in detailTable.Rows) + { + string errorMessage = string.Empty;//数据不符合数据库规范的信息 + StringBuilder fields = new StringBuilder(); + StringBuilder values = new StringBuilder(); + string detailSql = @"insert into " + BillModel.DetailTable + "_temp" + "({0}) values({1})"; + fields.Append("sysstr,"); + values.Append("'" + guid + "',"); + + foreach (DataColumn item in BillColumns.Columns) + { + //GridColumn col = this.gcMain.GridView.VisibleColumns.OfType().FirstOrDefault(x => x.FieldName == item.ColumnName); + //if (col == null) + //{ + // continue; + //} + if (item.ColumnName.Equals(guidField) || item.ColumnName.Equals(mRecordPrimaryField) || item.ColumnName.Equals(ERPInfo.Instance.isAddRows)) continue; + if (!BillTempColumns.Columns.Contains(item.ColumnName)) + { + string type = "varchar(100)"; + if (item.DataType == typeof(DateTime)) + { + type = "datetime"; + } + BaseImpl.ExecSqlValue(string.Format("alter table {0} add {1} {2}", BillModel.DetailTable + "_temp", item.ColumnName, type)); + } + + if (this.BillModel.DetailTreeTable) + { + TreeListColumn[] TreeListColumns = (this.gcMain as TreeGridControlEx).TreeListObj.Columns.Cast().Where(x => x.FieldName.Equals(item.Caption, StringComparison.OrdinalIgnoreCase)).ToArray(); + if (TreeListColumns.Count() == 0 && item.Caption.Equals(BillModel.PrimaryDetailKey)) + { + string primaryValues = dataRow[BillModel.PrimaryDetailKey] + ""; + if (!string.IsNullOrWhiteSpace(primaryValues)) + { + fields.Append(item.ColumnName + ","); + values.Append("N'" + primaryValues.Replace("'", "''") + "',"); + } + } + if (TreeListColumns.Count() == 0) continue; + } + else + { + GridColumn[] gridColumns = gcMain.GridView.Columns.Cast().Where(x => x.FieldName.Equals(item.Caption, StringComparison.OrdinalIgnoreCase)).ToArray(); + + if (gridColumns.Count() == 0 && item.Caption.Equals(BillModel.PrimaryDetailKey)) + { + string primaryValues = dataRow[BillModel.PrimaryDetailKey] + ""; + if (!string.IsNullOrWhiteSpace(primaryValues)) + { + fields.Append(item.ColumnName + ","); + values.Append("N'" + primaryValues.Replace("'", "''") + "',"); + } + } + if (gridColumns.Count() == 0) continue; + } + + + fields.Append(item.ColumnName + ","); + string fieldValue = dataRow.Table.Columns.Contains(item.ColumnName) ? dataRow[item.ColumnName] + "" : string.Empty; + if (addRowList != null && addRowList.Contains(dataRow) && Autogrowcolumn.Equals(item.ColumnName)) + { + fieldValue = ""; + }; + //if (SystemInfo.Instance.TrimWhiteSpace) + // fieldValue = fieldValue.Trim(); + if (item.ColumnName.Equals(BillModel.PrimaryDetailKey, StringComparison.OrdinalIgnoreCase)) + fieldValue = billNo; + if (!string.IsNullOrWhiteSpace(fieldValue)) + { + values.Append(item.DataType == typeof(DateTime) ? "'" + Convert.ToDateTime(fieldValue).ToString("yyyy-MM-dd HH:mm:ss") + "'," : fieldValue.Contains("'") ? "N'" + fieldValue.Replace("'", "''") + "'," : "N'" + fieldValue + "',"); + } + else + { + if (item.DataType == typeof(Decimal) || + item.DataType == typeof(Double) || + item.DataType == typeof(Int16) || + item.DataType == typeof(Int32) || + item.DataType == typeof(Int64)) + values.Append("0,"); + else if (item.DataType == typeof(DateTime)) + { + values.Append("NULL,"); + } + else + { + values.Append("'',"); + + } + + } + errorMessage = errorMessage + DatabaseFormatJudgment.SaveOrModifyBalidation(_detailColumns, DetailedProperties, dataRow, item, fieldValue); + + //SaveErrorMessage = SaveErrorMessage +(string.IsNullOrWhiteSpace(DatabaseFormatJudgment.SaveOrModifyBalidation(_detailColumns, DetailedProperties, dataRow, item, fieldValue))?"":); + } + + + + detailBuilder.AppendFormat(detailSql, fields.ToString().Trim(','), values.ToString().Trim(',')); + if (!string.IsNullOrWhiteSpace(errorMessage)) errorMessage = "第" + lineNumber + "行:" + errorMessage; + SaveErrorMessage = SaveErrorMessage + errorMessage; + lineNumber++; + } + } + return detailBuilder; + } + /// + /// 说明:保存单据 + /// 创建人:龚宇超 + /// 创建日期:2018-04-20 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// 是否继续执行(0.1). + /// 是否显示成功提示信息 + /// true if XXXX, false otherwise. + private bool BillSave(int comfirm = 0, bool canTipMsg = true) + { + bool saveResult = false; + + if (this.gridEx != null) + { + DataRow[] modifiedRows = (this.gridEx.GridControlObj.GridControl.DataSource as DataTable) + .Rows + .Cast() + .Where(x => x.RowState == DataRowState.Modified || x.RowState == DataRowState.Added) + .ToArray(); + if (modifiedRows != null && modifiedRows.Length >0) + { + this.gridEx.isSuccessfullySaved = false; + this.gridEx.BtnSave.PerformClick(); + if (!this.gridEx.isSuccessfullySaved) return false; + } + + } + + if (this.ControlObj.VerifyNull()) + { + //保存前执行某个右键 + if (!string.IsNullOrEmpty(BillModel.BeforeBillSaveExec)) + { + DataRow menuRow = BaseModuleImpl.GetBaseGridRightMenuById(BillModel.BeforeBillSaveExec); + if (menuRow != null) + { + #region 特殊处理 + string movepage = (this.ControlObj.ReplaceControlValue("{qms_maddf_addMode}").Equals("6")) ? "-9998" : "-9999"; + DataTable table = gcMain.gridControl.DataSourceTable(); + ControlModel modeControlModel = ControlObj.ControlModels.Where(n => n.LabelText.Equals("上传模式")).FirstOrDefault(); + string addMode = ControlObj.GetControlValue(modeControlModel); + if (modeControlModel != null && table.Columns.Contains("qms_laddf_mode")) + { + foreach (DataRow item in table.Rows) + { + item["qms_laddf_mode"] = addMode; + } + } + ControlModel speciesNoControlModel = ControlObj.ControlModels.Where(n => n.LabelText.Equals("文件分类")).FirstOrDefault(); + string speciesNo = ControlObj.GetControlValue(speciesNoControlModel); + if (speciesNoControlModel != null && table.Columns.Contains("BomAddSpeciesNo")) + { + foreach (DataRow item in table.Rows) + { + item["BomAddSpeciesNo"] = speciesNo; + } + } + #endregion + CommonMenu menu = new CommonMenu(this.SysModel, this.ControlObj, this.gcMain); + menu.ApplyBefore += new CommonToolApplyEventHandler(OnMenuApplyBefore); + menu.DynamicLinkAfter += new CommonToolAfterDynamicLinkEventHandler(OnDynamicLinkAfter); + StaticControl.RightMenuGridView = gcMain.GridView; + StaticControl.RightMenuMyControl = ControlObj; + menu.Apply(menuRow); + if (!menu.issuccess) + { + return false; + } + } + } + //虚构一个保存存储过程 + DataTable tvp = new DataTable(); + //更新前进行数据源筛选 + if (DateColumnList.Count > 0) + { + // 创建临时表 + tvp.Columns.Add("lblOrderNo", typeof(string)); // 固定主键 + tvp.Columns.Add("billdocument_id", typeof(string)); // 固定主键 + tvp.Columns.Add("showday", typeof(string)); + tvp.Columns.Add("amount", typeof(decimal)); + + // 获取主数据源 + DataTable mainDataSource = gcMain.GridControl.DataSourceTable(); + if (mainDataSource.Columns.Contains(BillModel.DetailUUIDKey)) + { + // 遍历主数据源 + foreach (DataRow row in mainDataSource.Rows) + { + if (row.RowState == DataRowState.Modified || row.RowState == DataRowState.Added) + { + // 提取 billdocument_id + string key = row[BillModel.DetailUUIDKey].ToString(); + if (!string.IsNullOrEmpty(key)) + { + // 遍历列并处理虚拟列 + foreach (GridColumn col in DateColumnList) + { + // 检查值是否发生变化 + bool isVerifyupd = true; + if (row.RowState == DataRowState.Modified) + { + object originalValue = row[col.FieldName, DataRowVersion.Original]; + object currentValue = row[col.FieldName, DataRowVersion.Current]; + isVerifyupd = !object.Equals(originalValue, currentValue); + } + + if (isVerifyupd) + { + // 解析金额 + decimal newAmount = 0m; + if (row[col.FieldName] != DBNull.Value && !string.IsNullOrWhiteSpace(row[col.FieldName].ToString())) + { + decimal.TryParse(row[col.FieldName].ToString(), out newAmount); + } + // 插入数据到临时表 + DataRow dr = tvp.NewRow(); + dr["billdocument_id"] = key; + dr["showday"] = col.FieldName; //列名如 "2025-03-06" + dr["amount"] = newAmount; + tvp.Rows.Add(dr); + } + } + } + } + } + } + } + //记录表格状态 + List addRowList = new List(); + DataTable sourceTable = gcMain.GridControl.DataSourceTable(); + foreach (DataRow dataRow in sourceTable.Rows) + { + if (dataRow.RowState == DataRowState.Added) + { + addRowList.Add(dataRow); + } + } + // 保存之前先进行表格更新 + if (this.BillModel.DetailTreeTable) + { + (this.gcMain as TreeGridControlEx).TreeListObj.PostEditor(); + //(this.gcMain as TreeGridControlEx).TreeListObj.UpdateCurrentRow(); + } + else + { + this.gcMain.GridView.PostEditor(); + this.gcMain.GridView.UpdateCurrentRow(); + } + + + try + { + if (this.gcMain.VerifyNull()) + { + if (this.gcMain.RepeatedVerificationNames.Count > 0 && this.gcMain.VerifyDuplicateColumns()) + { + MessageUtil.Show("表格中数据内容重复,保存失败!"); + return saveResult; + } + + + WaitForm.ShowForm(ResourceKeys.DataSaving); + string billNo = this.lblOrderNo.Text.Trim(); + string detailGuid = Guid.NewGuid().ToString(); + + string masterSql = BillModel.SaveState ? GetUpdateRecord(billNo) : GetAddRecord(ref billNo); + string detailSql = GetDetailRecord(detailGuid, billNo, addRowList).ToString(); + + // 检查单据头数据合法性 + if (string.IsNullOrEmpty(masterSql)) return false; + + // 验证明细合法性 + if (string.IsNullOrEmpty(detailSql) && !this.BillModel.SaveNullDetail) + { + MessageUtil.Show(ResourceKeys.BillDetailIsNotNull); + return false; + } + + + string tipMsg = string.Empty; + int result = BillImpl.BillSave(masterSql, detailSql, BillModel.DetailTable, ref billNo, detailGuid, BillModel.BillSeq, BillModel.SaveState ? 2 : 1, comfirm, out tipMsg, 0, this.BillModel.NewVer); + WaitForm.HideForm(); + switch (result) + { + case 1: + // 保存成功 + if (canTipMsg) MessageUtil.Show(BillModel.TypeName + ResourceKeys.SaveSuccess); + #region 单据保存成功调用Api接口 + if (ApiHelper.IsExecEventApi(Interface.Api.OperateEvent.AfterModuleDataChange, this.SysModel.ModuleCode, 0)) + { + ApiHelper apiHelper = new ApiHelper(this.SysModel.ModuleCode, billNo, BillModel.PrimaryKey, BillModel.MasterTable, 0); + switch (BillModel.SaveState) + { + case false: + apiHelper.OnEvent(Interface.Api.OperateEvent.AfterModuleDataChange, Interface.Api.ActionType.Add);//添加 + break; + case true: + apiHelper.OnEvent(Interface.Api.OperateEvent.AfterModuleDataChange, Interface.Api.ActionType.Update);//更新 + break; + } + if (!string.IsNullOrEmpty(apiHelper.apiResutMsg) && canTipMsg) + MessageUtil.Show(apiHelper.apiResutMsg); + } + #endregion + this.lblOrderNo.Text = billNo; + this.SetBillStatus(BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, billNo))); + saveResult = true; + RefreshPrindMenu(); + //保存完成后所有数据源进行拼接执行保存 + if (tvp != null && tvp.Rows.Count > 0) + { + if (gcMain.jhrowitem != null) + { + // 插入数据到临时表 + DataRow dr = tvp.NewRow(); + dr["lblOrderNo"] = billNo; + dr["billdocument_id"] = "计划文件" + gcMain.jhrowitem.ToJsonObject(); + if (DateColumnList.Count > 0 && DateColumnList[0].Tag is DateTime dateTime) + { + dr["showday"] = dateTime.ToString("yyyy-MM-dd"); //日期 + } + tvp.Rows.Add(dr); + + } + foreach (DataRow item in tvp.Rows) + { + item["lblOrderNo"] = billNo; + } + + // 调用存储过程保存变更数据 + string msg; + int ret = SaveDayPlanChanges(tvp, out msg); + OnGcMainDataSourceChanged(gcMain.GridView, null);//手动刷新日期合计数据源 + } + break; + case 9: + // 继续执行保存 + if (string.IsNullOrWhiteSpace(tipMsg)) tipMsg = "保存单据临时表失败"; + if (MessageUtil.Show(tipMsg, MessageBoxButtons.YesNo) == DialogResult.Yes) + this.BillSave(1, canTipMsg); + saveResult = true; + break; + default: + // 保存失败 + SaveErrorMessage = SaveErrorMessage + "\r\n" + "出错原因:\r\n" + tipMsg; + MessageUtil.Show(BillModel.TypeName + ResourceKeys.SaveFault + "\r\n" + SaveErrorMessage); + SaveErrorMessage = string.Empty; + + if (tipMsg.Contains("ruleid") && false) + { + string ruleid = tipMsg.Split(',')[0].Replace("ruleid", "").Replace("=", "").Trim(); + string sql = string.Format("select * from p_systembusinesslogictab where id = '{0}'", ruleid); + string rulesModid = string.Empty; + string rulesParam = this.ControlObj.ReplaceParentControlValue(ReplaceHelper.ReplaceUserInfo("")); + + } + + if (tipMsg.StartsWith("@") && false) + { + //根据tipMsg中数据找到pMenu中对应的右键 + foreach (BarItemLink itemLink in pMenu.ItemLinks) + { + if (false) + { + ErrorRestriction errorRestriction = new ErrorRestriction(tipMsg, this.SysModel, this.ControlObj, itemLink, this.BillModel, this.lblOrderNo.Text.Trim()); + DialogResult drr = errorRestriction.ShowDialog(); + errorRestriction.Dispose(); + } + } + } + break; + } + } + } + catch (Exception ex) + { + + if (string.IsNullOrWhiteSpace(SaveErrorMessage)) + { + MessageUtil.Show(ex.Message); + } + else + { + MessageUtil.Show("保存单据失败!\r\n" + SaveErrorMessage); + } + SaveErrorMessage = string.Empty; + LogHelper.Instance.WriteError(ex); + LogUtil.WriteError("保存单据失败!", ex); + } + finally + { + WaitForm.HideForm(); + } + } + return saveResult; + } + /// + /// 说明:通过配置条件刷新打印菜单 + /// 创建人:王一帆 + /// 创建日期:2020-04-10 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The hint MSG. + /// true if XXXX, false otherwise. + public void RefreshPrindMenu() + { + if (!string.IsNullOrWhiteSpace(BillModel.BillPrintTag)) + { + pMprint.ClearLinks(); + // 打印模版 + DataRow rowItem = this.gcMain.GridView.GetDataRow(this.gcMain.GridView.FocusedRowHandle); + string BillPrintTag = this.ControlObj.ReplaceParentControlValue(BillModel.BillPrintTag); + BillPrintTag = ReplaceHelper.ReplaceRowParam(rowItem, BillPrintTag); + // BillPrintTag = ReplaceHelper.ReplaceParamToValue(BillPrintTag,this.lblOrderNo.Text.Trim()); + string value = MainImpl.GetResult(ReplaceHelper.ReplaceRowParam(rowItem, BillPrintTag)) + ""; + string[] files = value.Split('|'); + for (int i = 0; i < files.Length; i++) + { + string fileName = files[i]; + if (!string.IsNullOrWhiteSpace(fileName)) + { + BarButtonItem itemPrint = new BarButtonItem(); + int index = i + 1; + itemPrint.Caption = files[i].Replace(".rmf", "").Replace(".frx", ""); + itemPrint.Tag = files[i]; + itemPrint.ItemClick += new ItemClickEventHandler(OnPrintItemClick); + pMprint.AddItem(itemPrint); + } + } + } + } + /// + /// 说明:单据提交 + /// 创建人:龚宇超 + /// 创建日期:2017-12-13 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The hint MSG. + /// true if XXXX, false otherwise. + private void BillApply(string hintMsg, int comfirm = 0) + { + try + { + WaitForm.ShowForm(ResourceKeys.Handing); + string tipMsg = string.Empty; + string billNo = this.lblOrderNo.Text.Trim(); + + + int result = BillImpl.BillApply(this.SysModel.ModuleCode, billNo, "", 1, out tipMsg, comfirm); + WaitForm.HideForm(); + switch (result) + { + case 1: + // 提交成功 + if (!this.BillModel.DisableSubmitPrompt) MessageUtil.Show(BillModel.TypeName + ResourceKeys.ApplySuccess); + //this.SetBillStatus(BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, billNo))); + + //提交成功后固定清空 + //this.BillModel.ApplyRefresh + if (true) + { + this.SetBillStatus(null); + this.ControlObj.ResetControlValue(); + } + + #region 提交审核成功后调用API + if (ApiHelper.IsExecEventApi(Interface.Api.OperateEvent.AfterModuleAuditStateChange, this.SysModel.ModuleCode, 0)) + { + ApiHelper apiHelper = new ApiHelper(this.SysModel.ModuleCode, billNo, this.BillModel.PrimaryKey, this.BillModel.MasterTable, 0); + apiHelper.OnEvent(Interface.Api.OperateEvent.AfterModuleAuditStateChange, Interface.Api.ActionType.Submit);//提交 + if (!string.IsNullOrEmpty(apiHelper.apiResutMsg)) + MessageUtil.Show(apiHelper.apiResutMsg); + } + #endregion + #region 提交审核成功后是否直接调用新增 + if (BillModel.IsApplyAferAdd || SystemInfo.Instance.BillNewAfterCommit) + { + this.OnBillAddClick(this.btnBillAdd, null); + //this.btnBillAdd.PerformClick(); + } + #endregion + // 推送消息 + PushHelper push = new PushHelper(billNo, "0", this.SysModel.ModuleCode, "", "", 0); + push.Push_Bill_Oper_Message(); + + break; + case 9: + // 继续执行保存 + if (string.IsNullOrWhiteSpace(tipMsg)) tipMsg = "提交单据失败"; + if (MessageUtil.Show(tipMsg, MessageBoxButtons.YesNo) == DialogResult.Yes) + this.BillApply("", 1); + break; + case 99: + // 继续执行提交 + if (MessageUtil.Show(tipMsg, MessageBoxButtons.YesNo) == DialogResult.Yes) + { + FrmPrompt prompt = new FrmPrompt(tipMsg); + prompt.Size = new Size(300, 200); + + DialogResult dialog = prompt.ShowDialog(); + if (dialog == DialogResult.OK) + { + this.BillApply(prompt.PromptMsg); + } + } + break; + default: + // 提交失败 + MessageUtil.Show(BillModel.TypeName + ResourceKeys.ApplyFault + "\r\n" + tipMsg); + break; + } + } + catch + { + throw; + } + finally + { + WaitForm.HideForm(); + } + } + #endregion + + #region 事件相关 + /// + /// 说明:点击空白界面后需要获取焦点 + /// 创建人:王一帆 + /// 创建日期:2020-09-04 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + private void OnMainFocusAfter(object sender, EventArgs e) + { + this.pl_main_center_master.Focus(); + } + /// + /// 说明:打印完成后回调 + /// 创建人:龚宇超 + /// 创建日期:2018-07-05 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The sender. + /// The e. + private void OnReportPrintAfter(object sender, EventArgs e) + { + //打印完成后添加数据库 + if (_printSaveParams != null && _printSaveParams.Count > 0) + { + int result = BaseModuleImpl.SavePrintRecord(_printSaveParams[0], _printSaveParams[1], _printSaveParams[2], _printSaveParams[3], _printSaveParams[4]); + } + + } + /// + /// 说明: + /// 创建人:龚宇超 + /// 创建日期:2017-11-28 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + private void OnFrmMainKeyDown(object sender, KeyEventArgs e) + { + // 窗口获取按键则表格按键中断.有时间处理 + if (e.Modifiers.CompareTo(Keys.Control) == 0) + { + if (e.KeyCode == Keys.Left) + this.ssc_main_top.Collapsed = true; + if (e.KeyCode == Keys.Right) + this.ssc_main_top.Collapsed = false; + if (e.KeyCode == Keys.Down) + this.ssc_main.Collapsed = true; + if (e.KeyCode == Keys.Up) + this.ssc_main.Collapsed = false; + } + } + + + /// + /// 说明:第一个页签初始化完成刷新数据 + /// 创建人:龚宇超 + /// 创建日期: + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The sender. + /// The instance containing the event data. + private void OnPageDataSourceBindCallBack(object sender, EventArgs e) + { + try + { + MyControl searchControl = sender as MyControl; + XtraTabPage tabPage = pageNumKey[searchControl]; + if (tabPage.TabIndex == 0) return; + BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel; + string searchSql = unionModel.ModelObj.SourceSql; + searchSql = ReplaceHelper.ReplaceUserInfo(searchSql); + searchSql = ReplaceHelper.ReplaceWhereCond(searchSql); + searchSql = unionModel.SearchObj.SetSearchSqlValue(searchSql, true, true); + // 查找FROM子句的位置 + int fromIndex = searchSql.IndexOf("FROM", StringComparison.OrdinalIgnoreCase); + if (fromIndex != -1) + { + // 生成优化后的SQL查询 + string optimizedSql = "SELECT COUNT(*) " + searchSql.Substring(fromIndex); + searchSql = optimizedSql; + } + DataTable dt = MainImpl.GetDataTableResult(searchSql); + if (dt.Rows.Count > 0) tabPage.Text += "(" + dt.Rows[0][0] + "条)"; + } + catch (Exception ex) + { + LogHelper.Instance.WriteError(ex); + LogUtil.WriteError("单据条件绑定失败失败!", ex); + } + } + + + + /// + /// 主表数据源改变时 + /// + /// + /// + private void OnGcMainDataSourceChanged(object sender, EventArgs e) + { + if (DateColumnList.Count > 0 && DateColumnList[0].Tag is DateTime dateTime) + { + string billNo = this.lblOrderNo.Text; + this.gcMain.GridControl.DataSourceChanged -= OnGcMainDataSourceChanged; + DataTable dataTable = gcMain.GridControl.DataSource as DataTable; + if (dataTable != null) + { + //DataTable dataMain = dataTable.Copy(); + //string sqlValue = "select * from RD_worktimetab where 1 = 1"; + //sqlValue = $"{sqlValue} and lblOrderNo = '{billNo}' and showday >= '{dateTime.ToString("yyyy-MM-dd")}'"; + //DataTable dataDayPlan = BaseImpl.GetDataTableResult(sqlValue); + //---------- 查询①:渲染表格排程” ---------- + string sqlExcludePlan = "SELECT * FROM RD_worktimetab WHERE 1 = 1"; + sqlExcludePlan += $" AND lblOrderNo = '{billNo}'"; + sqlExcludePlan += $" AND showday >= '{dateTime:yyyy-MM-dd}'"; + sqlExcludePlan += " AND billdocument_id NOT LIKE N'计划文件%'"; + // 获取结果 + DataTable dataNoPlanFile = BaseImpl.GetDataTableResult(sqlExcludePlan); + // ---------- 查询②:只包含“计划文件” ---------- + string sqlIncludePlan = "SELECT billdocument_id FROM RD_worktimetab WHERE 1 = 1"; + sqlIncludePlan += $" AND lblOrderNo = '{billNo}'"; + sqlIncludePlan += $" AND showday >= '{dateTime:yyyy-MM-dd}'"; + sqlIncludePlan += " AND billdocument_id LIKE N'计划文件%'"; + // 获取结果 + DataTable dataOnlyPlanFile = BaseImpl.GetDataTableResult(sqlIncludePlan); + MergeMainDataWithDayPlan(dataTable, dataNoPlanFile, dateTime); + //若存在缓存计划数据则渲染合计 + if (dataOnlyPlanFile.Rows.Count > 0) + { + string jhrowtiemjson = (dataOnlyPlanFile.Rows[0]["billdocument_id"] + "").Replace("计划文件", ""); + try + { + JObject rowObject = JsonConvert.DeserializeObject(jhrowtiemjson); + JArray jArray = new JArray(); + jArray.Add(rowObject); + DataRow jhrowitem = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(jArray)).Rows[0]; + //渲染计划合计 + gcMain.AddHeadquarters(jhrowitem); + } + catch (Exception) + { + } + } + gcMain.RefreshHeaderColor(); + this.gcMain.GridControl.DataSource = null; + this.gcMain.GridControl.DataSource = dataTable; + } + this.gcMain.GridControl.DataSourceChanged += OnGcMainDataSourceChanged; + } + } + + /// + /// 保存日计划变更数据(批量保存)。 + /// 调用存储过程 usp_MergeDayPlanChanges,将所有变更记录一次性提交到数据库。 + /// 通过 TVP 参数传递数据,同时捕获输出参数 @msg 和返回值。 + /// + /// 包含所有变更记录的 DataTable,必须与 dbo.DayPlanChangeType 定义一致 + /// 输出提示信息,存储过程执行后的返回消息 + /// 存储过程返回值,成功返回 1,失败返回 0 + public int SaveDayPlanChanges(DataTable tvp, out string message) + { + // 创建输出参数 @msg + SqlParameter pMsg = new SqlParameter("@msg", SqlDbType.VarChar, 2000) + { + Direction = ParameterDirection.Output + }; + // 创建返回值参数 @return + SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int) + { + Direction = ParameterDirection.ReturnValue + }; + // 创建 TVP 参数,名称必须与存储过程参数一致 + SqlParameter tvpParam = new SqlParameter("@DayPlanChanges", SqlDbType.Structured) + { + TypeName = "dbo.DayPlanChangeTVP", + Value = tvp + }; + // 构造参数数组 + SqlParameter[] parameters = new SqlParameter[] { tvpParam, pMsg, returnValue }; + // 执行存储过程,此处调用 ExecuteNonQuery 即可,不需要返回数据集 + // 请确保 DBUtil.ExecuteNonQuery 方法能够传递参数并执行存储过程 + BaseImpl.ExecProcedure("usp_MergeDayPlanChanges2025", parameters); + // 获取输出参数 @msg 中的提示信息 + message = pMsg.Value.ToString(); + // 获取存储过程的返回值 + int result = Convert.ToInt32(returnValue.Value); + return result; + } + + /// + /// 计划明细与主数据合并: + /// 1) 按 起算 7 天动态生成列; + /// 2) 把 dataDayPlan 中对应日期的 amount 值填入主表; + /// 3) 计算行级合计写入 “heji” 列。 + /// + private DataTable MergeMainDataWithDayPlan(DataTable dataMain, DataTable dataDayPlan, DateTime startDate) + { + const string rightPrimaryKey = "billdocument_id"; // dataDayPlan 主键 + const string dateField = "showday"; + const string amountField = "amount"; + string topPrimaryKey = BillModel.DetailUUIDKey; // dataMain 主键 + + int dayCount = 0; + BaseUserControl baseUserControl = ControlObj.FindControl("bom_rdm_tianshu"); + if (baseUserControl != null) + { + int.TryParse(baseUserControl.EditText, out dayCount); + } + if (dayCount <= 0) + { + dayCount = 7; + } + DateTime endDate = startDate.AddDays(dayCount); + + // ---------- 1. 预索引 dataDayPlan:billdocument_id -> List ---------- + var dayPlanMap = new Dictionary>(); + foreach (DataRow row in dataDayPlan.Rows) + { + string billId = row[rightPrimaryKey].ToString(); + if (!dayPlanMap.TryGetValue(billId, out var list)) + { + list = new List(); + dayPlanMap[billId] = list; + } + list.Add(row); + } + + // ---------- 2. 为主表添加日期列和合计列 ---------- + for (DateTime d = startDate; d <= endDate; d = d.AddDays(1)) + { + string colName = d.ToString("yyyy-MM-dd"); + if (!dataMain.Columns.Contains(colName)) + dataMain.Columns.Add(colName, typeof(decimal)); + } + if (!dataMain.Columns.Contains("workingsum")) + dataMain.Columns.Add("workingsum", typeof(decimal)); + + // ---------- 3. 预构建填充映射:主键 -> (日期列名, 金额) ---------- + var dataMap = new Dictionary>(); + foreach (DataRow mainRow in dataMain.Rows) + { + string key = mainRow[topPrimaryKey].ToString(); + var inner = new Dictionary(); + dataMap[key] = inner; + + if (dayPlanMap.TryGetValue(key, out var rows)) + { + foreach (DataRow dayRow in rows) + { + if (dayRow[dateField] == DBNull.Value) continue; + + DateTime d = Convert.ToDateTime(dayRow[dateField]); + if (d < startDate || d > endDate) continue; + + string col = d.ToString("yyyy-MM-dd"); + if (!dataMain.Columns.Contains(col)) continue; + + if (decimal.TryParse(dayRow[amountField]?.ToString(), out decimal amt)) + inner[col] = amt; + } + } + } + + // ---------- 4. 一次性填充并计算行合计 ---------- + foreach (DataRow mainRow in dataMain.Rows) + { + string key = mainRow[topPrimaryKey].ToString(); + decimal rowSum = 0m; + + if (dataMap.TryGetValue(key, out var inner)) + { + foreach (var kv in inner) + { + mainRow[kv.Key] = kv.Value; + rowSum += kv.Value; + } + } + + mainRow["workingsum"] = rowSum; // 行汇总 + } + + return dataMain; + } + + /// + /// 构建带日期的数据源 + /// + /// + /// + /// + /// + private void UpdateRowWithDayPlan(DataRow focusedRow, DataTable dataDayPlan, DateTime startDate) + { + string rightPrimaryKey = "billdocument_id"; + string dateField = "showday"; + string amountField = "amount"; + string topPrimaryKey = BillModel.DetailUUIDKey; + + int dayCount = 0; + BaseUserControl baseUserControl = ControlObj.FindControl("bom_rdm_tianshu"); + if (baseUserControl != null) + { + int.TryParse(baseUserControl.EditText, out dayCount); + } + if (dayCount <= 0) + { + dayCount = 7; + } + + DateTime endDate = startDate.AddDays(dayCount); // 计算结束日期 + // **1. 预索引 dataDayPlan 数据(billdocument_id -> 该 key 相关的所有行)** + Dictionary> dayPlanMap = new Dictionary>(); + foreach (DataRow row in dataDayPlan.Rows) + { + string billId = row[rightPrimaryKey].ToString(); + if (!dayPlanMap.ContainsKey(billId)) + { + dayPlanMap[billId] = new List(); + } + dayPlanMap[billId].Add(row); + } + // **2. 预构建主数据的列** + for (DateTime dt = startDate; dt <= endDate; dt = dt.AddDays(1)) + { + string colName = dt.ToString("yyyy-MM-dd"); + if (!focusedRow.Table.Columns.Contains(colName)) + { + focusedRow.Table.Columns.Add(colName, typeof(decimal)); // 确保列存在 + } + } + // **3. 预构建数据填充映射表** + Dictionary> dataMap = new Dictionary>(); + string key = focusedRow[topPrimaryKey].ToString(); + if (!dataMap.ContainsKey(key)) + { + dataMap[key] = new Dictionary(); + } + // **查找 key 关联的时间数据** + if (dayPlanMap.ContainsKey(key)) + { + foreach (DataRow dayRow in dayPlanMap[key]) + { + if (dayRow[dateField] != DBNull.Value) + { + DateTime dayValue = Convert.ToDateTime(dayRow[dateField]); + string colName = dayValue.ToString("yyyy-MM-dd"); + if (dayValue >= startDate && dayValue <= endDate && focusedRow.Table.Columns.Contains(colName)) + { + decimal.TryParse(dayRow[amountField] + "", out decimal amountValue); + dataMap[key][colName] = amountValue; + } + } + } + } + // **4. 一次性填充 DataTable(避免逐行赋值带来的性能问题)** + if (dataMap.ContainsKey(key)) + { + foreach (var col in dataMap[key]) + { + focusedRow[col.Key] = col.Value; + } + } + } + + + + + + + /// + /// 说明:获取查询条件 + /// 创建人:龚宇超 + /// 创建日期:2017-11-22 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The model. + /// The row item. + /// System.String. + protected string GetSearchSql(GridDetailModel model, DataRow rowItem) + { + string fieldName = !string.IsNullOrEmpty(model.UnionParentField) && rowItem.Table.Columns.Contains(model.UnionParentField) ? model.UnionParentField : BillModel.PrimaryKey; + string sqlValue = model.IsReadOnly || model.IsChart ? model.DetailSql : model.SystemModel.MenuSql; + string unioValue = string.Empty; + unioValue = rowItem.Table.Columns.Contains(fieldName) ? rowItem[fieldName] + "" : string.Empty; + if (this.ControlObj != null && string.IsNullOrEmpty(unioValue)) + { + unioValue = !string.IsNullOrEmpty(model.UnionParentField) && this.ControlObj.FindControl(model.UnionParentField) != null ? this.ControlObj.GetControlValue(model.UnionParentField) : unioValue; + } + sqlValue = ReplaceHelper.ReplaceRowParam(rowItem, sqlValue); + sqlValue = this.ControlObj.ReplaceControlValue(sqlValue);//后替换主表内容 + if (ReplaceHelper.IsSelect(sqlValue) && !string.IsNullOrEmpty(model.UnionValue)) + { + sqlValue = ReplaceHelper.ReplaceWhereCond(sqlValue) + string.Format(" and {0}='{1}'", model.UnionValue, unioValue); + } + if (!string.IsNullOrEmpty(model.UnionCond)) + { + string UnionCond = ReplaceHelper.ReplaceRowParam(rowItem, model.UnionCond); + sqlValue += UnionCond; + } + return sqlValue; + } + + + + /// + /// 说明:单据空行新增时初始化默认值 + /// 创建人:dl + /// 创建日期:2019-01-29 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + private void OnGridViewInitNewRow(object sender, InitNewRowEventArgs e) + { + GridView view = sender as DevExpress.XtraGrid.Views.Grid.GridView; + DataTable gridTable = (this.gcMain.GridControl.DataSource as DataTable).TrimDeleteRows(); + DataRow tmpRow = view.GetDataRow(e.RowHandle); + GridColumnCollection gridColumns = view.Columns; + //gridTable.Rows.Add(tmpRow); + int position = gridTable.Rows.Count; + foreach (GridColumn col in gridColumns) + { + GridColumnModel model = col.Tag as GridColumnModel; + if (model == null) + { + continue; + } + string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue); + + if (model.DefaultValue.Contains("{#")) + { + fieldValue = this.ControlObj.ReplaceParentControlValue(model.DefaultValue); + if (!string.IsNullOrEmpty(fieldValue)) + { + tmpRow[col.FieldName] = fieldValue; + view.SetFocusedRowCellValue(col, fieldValue); + } + } + else if (!string.IsNullOrEmpty(model.DefaultValue)) + { + + tmpRow[col.FieldName] = fieldValue; + view.SetFocusedRowCellValue(col, fieldValue); + + if (model.DefaultValue.Contains("{ROW")) + { + if (position > 0) + { + + fieldValue = ReplaceHelper.GetParamFields(model.DefaultValue)[0]; + fieldValue = fieldValue.Replace("}", "").Replace("{", ""); + fieldValue = fieldValue.Substring(fieldValue.IndexOf('_') + 1); + string topFieldValue = gridTable.Rows[position - 1][fieldValue] + ""; + if (gridTable.Columns[model.FieldName].DataType == typeof(DateTime)) + { + if (!string.IsNullOrEmpty(topFieldValue)) + { + tmpRow[model.FieldName] = Convert.ToDateTime(topFieldValue); + view.SetFocusedRowCellValue(col, topFieldValue); + } + } + else + { + tmpRow[model.FieldName] = topFieldValue; + view.SetFocusedRowCellValue(col, topFieldValue); + } + } + } + else + { + tmpRow[model.FieldName] = fieldValue; + view.SetFocusedRowCellValue(col, fieldValue); + } + + } + } + //设置序号 + gridTable.OrderBy(this.BillModel.DetailOrderField, false); + //设置当前行序号 + if (gridTable != null && gridTable.Rows.Count > 0 && !string.IsNullOrEmpty(this.BillModel.DetailOrderField) && gridTable.Columns.Contains(this.BillModel.DetailOrderField)) + { + bool getMaxIndex = int.TryParse(gridTable.Rows.Cast().Max(n => n[this.BillModel.DetailOrderField]) + "", out int maxIndex); + if (getMaxIndex) + { + tmpRow[this.BillModel.DetailOrderField] = maxIndex + 1; + } + } + if (gridTable.Columns.Contains(this.BillModel.DetailOrderField) && gridTable.Rows.Count == 0) + { + tmpRow[this.BillModel.DetailOrderField] = 1; + } + //this.gcMain.GridView.UpdateCurrentRow(); + //this.gcMain.GridView.ShowEditor(); + } + /// + /// 说明:右键菜单执行后刷新数据,刷新规则按照上一次查询条件刷新 + /// 创建人:龚宇超 + /// 创建日期:2017-11-02 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The sender. + /// The instance containing the event data. + private void OnGridViewRightCallBack(object sender, EventArgs e) + { + string billNo = this.lblOrderNo.Text.Trim(); + this.SetBillStatus(BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, billNo))); + } + /// + /// 说明:重绘单据水印 + /// 创建人:龚宇超 + /// 创建日期:2017-12-04 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + private void OnLabelTitlePaint(object sender, PaintEventArgs e) + { + if (this._waterMark != null) + { + GraphicsText graphicsText = new GraphicsText(); + graphicsText.Graphics = e.Graphics; + + // 绘制围绕点旋转的文本 + StringFormat format = new StringFormat(); + format.Alignment = StringAlignment.Center; + format.LineAlignment = StringAlignment.Center; + + // 绘制单据状态文本 + if (!string.IsNullOrEmpty(this._waterMark.Text)) + { + graphicsText.DrawString(this._waterMark.Text, new Font("宋体", 12, FontStyle.Bold), new SolidBrush(Color.Red), new PointF(50, 21), format, -15f); + + e.Graphics.TranslateTransform(0, 0); + e.Graphics.RotateTransform(-15f); + e.Graphics.DrawRectangle(new Pen(Color.Red, 2f), new Rectangle(14, 20, 55, 21)); + } + + // 绘制打印次数文本 + e.Graphics.ResetTransform(); + if (!string.IsNullOrEmpty(this._waterMark.Print)) + { + graphicsText.DrawString(this._waterMark.Print, new Font("宋体", 11, FontStyle.Bold), new SolidBrush(Color.Red), new PointF((this.lbTitle.Width - 70), 21), format, -15f); + + e.Graphics.TranslateTransform(this.lbTitle.Width - 70, 21); + e.Graphics.RotateTransform(-15f); + e.Graphics.DrawRectangle(new Pen(Color.Red, 2f), new Rectangle(-35, -14, 70, 21)); + } + + // 绘制收款文本 + e.Graphics.ResetTransform(); + if (!string.IsNullOrEmpty(this._waterMark.Collect)) + { + graphicsText.DrawString(this._waterMark.Collect, new Font("宋体", 12, FontStyle.Bold), new SolidBrush(Color.Red), new PointF((this.lbTitle.Width - 170), 21), format, -15f); + + e.Graphics.TranslateTransform(this.lbTitle.Width - 100, 21); + e.Graphics.RotateTransform(-15f); + e.Graphics.DrawRectangle(new Pen(Color.Red, 2f), new Rectangle(-100, -32, 55, 21)); + } + } + } + + + + + /// + /// 说明:新增单据 + /// 创建人:龚宇超 + /// 创建日期:2017-12-14 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + private void OnBillAddClick(object sender, EventArgs e) + { + if (!this.BillModel.SaveState && this.gcMain.DataRowCount() > 0) + { + DialogResult result = MessageUtil.Show(("数据未保存,是否确定新建单据?"), MessageBoxButtons.YesNo); + if (result == DialogResult.Yes) + { + this.SetBillStatus(null); + this.ControlObj.ResetControlValue(this.BillModel.ManuallyTriggerCorrelation, true); + } + } + else + { + this.SetBillStatus(null); + this.ControlObj.ResetControlValue(this.BillModel.ManuallyTriggerCorrelation, true); + } + if (ScanCodeTextEdit != null) ScanCodeTextEdit.Focus(); + } + + /// + /// 关闭时判断是否存在为保存新增单据 + /// + /// + public bool closeTheJudgment() + { + //if(this.ControlObj.VerifyUpdated()) + if (!this.BillModel.SaveState && this.gcMain.DataRowCount() > 0) + { + return true; + } + return false; + + } + + + /// + /// 说明:删除明细记录 + /// 创建人:龚宇超 + /// 创建日期:2017-12-05 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + private void OnDeleteClick(object sender, EventArgs e) + { + try + { + //树表格删除 + if (this.BillModel.DetailTreeTable) + { + string deleteCond = this.ControlObj.ReplaceParentControlValue(BillModel.DeleteDetailCond); + (this.gcMain as TreeGridControlEx).DeleteSelectedRows(deleteCond); + return; + } + + + + int[] rows = this.gcMain.GridView.GetSelectedRows(); + if (rows.Length < 1) + return; + + DataTable dt = this.gcMain.GridView.GetGridViewFilteredAndSortedDataToDataTable(); + + + if (string.IsNullOrEmpty(BillModel.DeleteDetailCond)) + { + DialogResult result = MessageUtil.Show(string.Format(ResourceKeys.DeleteRows, rows.Length), MessageBoxButtons.YesNo); + if (result == DialogResult.Yes) + { + //保存删除的行和对应的行号 + //撤销多次 + Dictionary undo = new Dictionary(); + for (int i = 0; i < rows.Length; i++) + { + DataRow rowItem = this.gcMain.GridView.GetDataRow(rows[i]); + DataRow dr = dt.NewRow(); + dr.ItemArray = rowItem.ItemArray; + undo.Add(rows[i], dr); + } + ToWithdrawRows.Add(undo); + this.gcMain.GridView.Columns.ClearAllSort(); + this.gcMain.GridView.DeleteSelectedRows(); + this.gcMain.GridView.ClearSelection(); + this.gcMain.GridView.SelectRow(this.gcMain.GridView.FocusedRowHandle); + this.gcMain.GridControl.DataSourceTable().OrderBy(this.BillModel.DetailOrderField); + } + } + else + { + string successMsg = string.Empty, faultMsg = string.Empty; + string deleteCond = this.ControlObj.ReplaceParentControlValue(BillModel.DeleteDetailCond); + List deleteRows = new List(); + List faultInts = new List(); + //ToWithdrawRows.Clear();//清空上一次记录的删除行 + Dictionary undo = new Dictionary(); + + foreach (int rowIndex in rows) + { + DataRow rowItem = this.gcMain.GridView.GetDataRow(rowIndex); + + string deleteCond2 = ReplaceHelper.ReplaceRowParam(rowItem, deleteCond); + + if (ReplaceHelper.EvalCond(deleteCond2)) + { + deleteRows.Add(rowItem); + DataRow dr = dt.NewRow(); + dr.ItemArray = rowItem.ItemArray; + undo.Add(rowIndex, dr); + + } + else + { + faultInts.Add(rowIndex); + } + } + ToWithdrawRows.Add(undo); + DataTable table = this.gcMain.GridControl.DataSourceTable(); + foreach (DataRow item in deleteRows) + { + table.Rows.Remove(item); + } + + if (faultInts != null && faultInts.Count > 0) + { + MessageUtil.Show("发现如下:" + string.Join(",", faultInts.ToArray()) + "行不满足条件无法删除!"); + } + else + { + MessageUtil.Show("删除成功!"); + } + } + if (ScanCodeTextEdit != null) ScanCodeTextEdit.Focus(); + return; + } + catch (Exception ex) + { + LogHelper.Instance.WriteError(ex); + } + + } + + + + /// + /// 说明:单据保存 + /// 创建人:龚宇超 + /// 创建日期:2017-12-07 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + private void OnBillSaveClick(object sender, EventArgs e) + { + try + { + if (this.BillSave()) + { + ToWithdrawRows.Clear(); + } + if (ScanCodeTextEdit != null) ScanCodeTextEdit.Focus(); + } + catch (Exception ex) + { + MessageUtil.Show(ex); + } + } + /// + /// 说明:单据保存提交 + /// 创建人:龚宇超 + /// 创建日期:2017-12-07 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + private void OnBillApplyClick(object sender, EventArgs e) + { + try + { + DialogResult result = MessageUtil.Show(ResourceKeys.BillApply, MessageBoxButtons.YesNo); + if (result == DialogResult.Yes) + { + if (this.BillSave(0, false)) + { + ToWithdrawRows.Clear(); + this.BillApply(""); + } + } + if (ScanCodeTextEdit != null) ScanCodeTextEdit.Focus(); + return; + } + catch (Exception ex) + { + MessageUtil.Show(ex); + } + + } + /// + /// 说明:分割条移动保存位置 + /// 创建人:龚宇超 + /// 创建日期:2018-03-06 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + private void OnTopSplitterMoved(object sender, EventArgs e) + { + if (this._isInitFinish)// 是否为初始化创建 + { + IniHelper.Write(string.Format("bill_width_{0}", this.SysModel.ModuleCode), this.ssc_main_top.SplitterPosition + ""); + } + } + /// + /// 说明:分割条移动保存位置 + /// 创建人:龚宇超 + /// 创建日期:2018-03-06 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. private void OnMainSplitterMoved(object sender, EventArgs e) { if (this._isInitFinish) @@ -5057,1806 +5057,1806 @@ namespace Lskj.PubBillSpecial IniHelper.Write(string.Format("bill_height_{0}", this.SysModel.ModuleCode), this.ssc_main.SplitterPosition + ""); } } - /// - /// 说明:明细分割条移动保存位置 - /// 创建人:龚宇超 - /// 创建日期:2018-03-06 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - private void OnDetailsSplitterMoved(object sender, EventArgs e) - { - if (this._isInitFinish) - { - SplitContainerControl splitContainerControl = sender as SplitContainerControl; - IniHelper.Write(string.Format("bill_Details_Width_{0}", this.SysModel.ModuleCode), splitContainerControl.SplitterPosition + ""); - } - } - - - /// - /// 说明:判断字符串出现次数 - /// 创建人:龚宇超 - /// 创建日期: - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The string. - /// The substring. - /// System.Int32. - private static int SubstringCount(string str, string substring) - { - if (str.Contains(substring)) - { - string strReplaced = str.Replace(substring, ""); - return (str.Length - strReplaced.Length) / substring.Length; - } - - return 0; - } - /// - /// 说明:帮助文档 - /// 创建人:龚宇超 - /// 创建日期:2020-01-15 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The sender. - /// The instance containing the event data. - private void OnHelpClick(object sender, EventArgs e) - { - WebBrowserUtil.StartWebBrowser(this.SysModel.ModuleCode, this.BillModel.TypeName); - } - - /// - /// 说明:分配明细 - /// 创建人:龚宇超 - /// 创建日期:2020-01-15 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - private void OnBtnFPOldClick(object sender, EventArgs e) - { - this.gcMain.GridView.PostEditor(); - FPOld(); - } - private void OnBtnFPNewClick(object sender, EventArgs e) - { - this.gcMain.GridView.PostEditor(); - FPNew(); - } - /// - /// 新版分配 - /// - private void FPNew() - { - try - { - this.gcMain.GridView.FocusedRowHandle = 0; - DataTable table = this.gcMain.GridControl.DataSource as DataTable; - if (!table.Columns.Contains(guidField)) - { - table.Columns.Add(guidField, typeof(string)); - } - #region 创建分配界面 - string[] args = { this.SysModel.FormText, this.SysModel.UserId, this.SysModel.UserName, this.SysModel.Privilege, this.SysModel.ModuleCode, this.SysModel.ModuleId + "", this.BillModel.PopupUnionCode, "1000" }; - DynamicBaseSelectModel baseModel = new DynamicBaseSelectModel(args); - using (FrmBaseSelectBatch frmSelect = new FrmBaseSelectBatch(baseModel, this.ControlObj, this.gcMain)) - { - frmSelect.Text = this.BillModel.TypeName; - frmSelect.InitControl(); - frmSelect.OnAfterFPCallback += OnAfterFPCallback; - #region 初始化第一条数据 - DataRow rowItem = this.gcMain.GridView.GetFocusedDataRow(); - if (rowItem == null) - { - return; - } - rowItem[guidField] = Guid.NewGuid().ToString(); - if (!string.IsNullOrEmpty(mRecordPrimaryField) && table.Columns.Contains(this.mRecordPrimaryField)) - { - // 检查数据是否为分配后的行 - if (!string.IsNullOrEmpty(rowItem[this.mRecordPrimaryField] + "")) - { - if (this.gcMain.GridView.FocusedRowHandle + 1 <= this.gcMain.GridView.RowCount - 1) - { - this.gcMain.GridView.FocusedRowHandle += 1; - FPNew(); - } - return; - } - } - if (!string.IsNullOrEmpty(mRecordPrimaryField)) - { - frmSelect.FpRows = table.Rows.Cast().Where(x => (rowItem[guidField] + "").Equals(x[guidField] + "")).ToArray(); - if (frmSelect.FpRows != null && frmSelect.FpRows.Length > 0) - { - List rows = frmSelect.FpRows.ToList(); - rows.Remove(rowItem); - frmSelect.FpRows = rows.ToArray(); - } - if (table.Columns.Contains(mRecordPrimaryField)) - { - frmSelect.FpOtherRows = table.Rows.Cast().Where(x => !(rowItem[guidField] + "").Equals(x[guidField] + "") && !string.IsNullOrEmpty(x[mRecordPrimaryField] + "")).ToArray(); - } - } - frmSelect.InitData(rowItem); - frmSelect.OnBtnFPClick(null, null); - #endregion - //frmSelect.ShowDialog(); - #endregion - } - } - catch (Exception ex) - { - MessageUtil.Show(ex.Message); - } - } - /// - /// 分配完成后回调 - /// - /// - /// - private void OnAfterFPCallback(object sender, EventArgs e) - { - WaitForm.ShowForm(); - try - { - // 临时禁用新增行(空白行) - if (this.BillModel.DefaultAddEmptyRow) this.gcMain.GridView.OptionsView.NewItemRowPosition = NewItemRowPosition.None; - DataRow rowItem = this.gcMain.GridView.GetFocusedDataRow(); - if (rowItem == null) - { - return; - } - DataTable table = this.gcMain.GridControl.DataSource as DataTable; - FrmBaseSelectBatch frmSelect = (FrmBaseSelectBatch)sender; - rowItem[guidField] = Guid.NewGuid().ToString(); - if (!string.IsNullOrEmpty(mRecordPrimaryField) && table.Columns.Contains(this.mRecordPrimaryField)) - { - // 检查数据是否为分配后的行 - if (!string.IsNullOrEmpty(rowItem[this.mRecordPrimaryField] + "")) - { - if (this.gcMain.GridView.FocusedRowHandle + 1 <= this.gcMain.GridView.RowCount - 1) - { - this.gcMain.GridView.FocusedRowHandle += 1; - OnAfterFPCallback(sender, e); - } - return; - } - } - if (!string.IsNullOrEmpty(mRecordPrimaryField)) - { - frmSelect.FpRows = table.Rows.Cast().Where(x => (rowItem[guidField] + "").Equals(x[guidField] + "")).ToArray(); - if (frmSelect.FpRows != null && frmSelect.FpRows.Length > 0) - { - List rows = frmSelect.FpRows.ToList(); - rows.Remove(rowItem); - frmSelect.FpRows = rows.ToArray(); - } - if (table.Columns.Contains(mRecordPrimaryField)) - { - frmSelect.FpOtherRows = table.Rows.Cast().Where(x => !(rowItem[guidField] + "").Equals(x[guidField] + "") && !string.IsNullOrEmpty(x[mRecordPrimaryField] + "")).ToArray(); - } - } - frmSelect.InitData(rowItem); - bool success = frmSelect.FP(); - if (success) - { - if (frmSelect.SelectedRows != null && frmSelect.SelectedRows.Length > 0) - { - // 增加标识列 - if (!table.Columns.Contains(frmSelect.RecordPrimaryField)) - { - this.mRecordPrimaryField = frmSelect.RecordPrimaryField; - table.Columns.Add(this.mRecordPrimaryField, typeof(String)); - } - foreach (DataRow item in frmSelect.SelectedRows) - { - DataRow newRow = table.NewRow(); - newRow.ItemArray = rowItem.ItemArray; - newRow[guidField] = rowItem[guidField]; - DataColumn IsIdentCol = newRow.Table.Columns.Cast().FirstOrDefault(x => x.ColumnName == BaseImpl.GetResult(string.Format("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.columns WHERE TABLE_NAME='{0}' AND COLUMNPROPERTY(OBJECT_ID('{0}'),COLUMN_NAME,'IsIdentity')=1", BillModel.DetailTable)) + ""); - //自增长列分配按空值取 - if (IsIdentCol != null) - { - if (IsIdentCol.DataType == typeof(Decimal) || - IsIdentCol.DataType == typeof(Double) || - IsIdentCol.DataType == typeof(Int16) || - IsIdentCol.DataType == typeof(Int32) || - IsIdentCol.DataType == typeof(Int64)) - { - newRow[IsIdentCol.ColumnName] = 0; - } - } - foreach (DataColumn col in item.Table.Columns) - { - if (table.Columns.Contains(col.ColumnName)) - { - //newRow[col.ColumnName] = item[col.ColumnName]; - newRow[col.ColumnName] = item[col.ColumnName]; - GridColumn column = this.gcMain.GridView.Columns[col.ColumnName]; - if (column != null) - { - GridColumnModel model = column.Tag as GridColumnModel; - if (!string.IsNullOrEmpty(model.UnionFields)) - { - this.SetUnionValue(model, rowItem[column.FieldName] + "", newRow); - } - SetCalcValue(model, rowItem[column.FieldName] + "", newRow); - } - } - } - newRow[frmSelect.AmountField] = item[frmSelect.AmountField]; - newRow[frmSelect.RecordPrimaryField] = item[frmSelect.RecordPrimaryField]; - table.Rows.Add(newRow); - } - NumberMc = frmSelect.AmountField; - table.Rows.Remove(rowItem); - // 重排顺序 - table.OrderBy(this.BillModel.DetailOrderField); - this.gcMain.GridView.UpdateCurrentRow(); - this.gcMain.GridView.ShowEditor(); - if (frmSelect.isNextOne) - { - int SourceRowIndex = this.gcMain.GridView.GetFocusedDataSourceRowIndex(); - DataRow[] a = table.Rows.Cast().Where(x => string.IsNullOrEmpty(x[guidField].ToString())).ToArray(); - if (a.Length != 0) - { - this.gcMain.GridView.FocusedRowHandle = SourceRowIndex; - OnAfterFPCallback(sender, e); - } - else - { - MessageUtil.Show("全部分配完毕"); - // frmSelect.SelectRowItem = null; - } - } - } - } - else - { - if (this.gcMain.GridView.FocusedRowHandle + 1 <= this.gcMain.GridView.RowCount - 1) - { - this.gcMain.GridView.FocusedRowHandle += 1; - OnAfterFPCallback(sender, e); - } - else - { - MessageUtil.Show("全部分配完毕"); - } - } - } - catch (Exception) - { - throw; - } - finally - { - // 重新开启新增行(空白行) - if (this.BillModel.DefaultAddEmptyRow) this.gcMain.GridView.OptionsView.NewItemRowPosition = NewItemRowPosition.Bottom; - WaitForm.HideForm(); - } - } - - /// - /// 老版分配 - /// - private void FPOld() - { - try - { - DataRow rowItem = this.gcMain.GridView.GetFocusedDataRow(); - if (rowItem == null) - { - MessageUtil.Show("请先选择一条明细在进行分配!"); - return; - } - DataTable table = this.gcMain.GridControl.DataSource as DataTable; - if (!table.Columns.Contains(guidField)) - { - table.Columns.Add(guidField, typeof(string)); - } - rowItem[guidField] = Guid.NewGuid().ToString(); ; - if (!string.IsNullOrEmpty(mRecordPrimaryField) && table.Columns.Contains(this.mRecordPrimaryField)) - { - // 检查数据是否为分配后的行 - if (!string.IsNullOrEmpty(rowItem[this.mRecordPrimaryField] + "")) - { - MessageUtil.Show("该行数据为已分配后的数据,无需分配!"); - return; - } - } - string[] args = { this.SysModel.FormText, this.SysModel.UserId, this.SysModel.UserName, this.SysModel.Privilege, this.SysModel.ModuleCode, this.SysModel.ModuleId + "", this.BillModel.PopupUnionCode, "1000" }; - DynamicBaseSelectModel baseModel = new DynamicBaseSelectModel(args); - using (FrmBaseSelect frmSelect = new FrmBaseSelect(baseModel, this.ControlObj, this.gcMain)) - { - //if (frmSelect.SelectRowItem == null) - //{ - // frmSelect = new FrmBaseSelect(baseModel, this.ControlObj, this.gcMain); - //} - frmSelect.Text = this.BillModel.TypeName; - frmSelect.SelectRowItem = rowItem; - bool isNextOne = false; - if (!string.IsNullOrEmpty(mRecordPrimaryField)) - { - frmSelect.FpRows = table.Rows.Cast().Where(x => (rowItem[guidField] + "").Equals(x[guidField] + "")).ToArray(); - if (frmSelect.FpRows != null && frmSelect.FpRows.Length > 0) - { - List rows = frmSelect.FpRows.ToList(); - rows.Remove(rowItem); - frmSelect.FpRows = rows.ToArray(); - } - if (table.Columns.Contains(mRecordPrimaryField)) - { - frmSelect.FpOtherRows = table.Rows.Cast().Where(x => !(rowItem[guidField] + "").Equals(x[guidField] + "") && !string.IsNullOrEmpty(x[mRecordPrimaryField] + "")).ToArray(); - } - } - if (frmSelect.ShowDialog() == DialogResult.OK && frmSelect.SelectedRows != null && frmSelect.SelectedRows.Length > 0) - { - //if (frmSelect.isNextOne) - //{ - // isNextOne = true; - //} - //else - //{ - // isNextOne = false; - //} - // 增加标识列 - if (!table.Columns.Contains(frmSelect.RecordPrimaryField)) - { - this.mRecordPrimaryField = frmSelect.RecordPrimaryField; - table.Columns.Add(this.mRecordPrimaryField, typeof(String)); - } - - foreach (DataRow item in frmSelect.SelectedRows) - { - DataRow newRow = table.NewRow(); - newRow.ItemArray = rowItem.ItemArray; - newRow[guidField] = rowItem[guidField]; - DataColumn IsIdentCol = newRow.Table.Columns.Cast().FirstOrDefault(x => x.ColumnName == BaseImpl.GetResult(string.Format("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.columns WHERE TABLE_NAME='{0}' AND COLUMNPROPERTY(OBJECT_ID('{0}'),COLUMN_NAME,'IsIdentity')=1", BillModel.DetailTable)) + ""); - //自增长列分配按空值取 - if (IsIdentCol != null) - { - if (IsIdentCol.DataType == typeof(Decimal) || - IsIdentCol.DataType == typeof(Double) || - IsIdentCol.DataType == typeof(Int16) || - IsIdentCol.DataType == typeof(Int32) || - IsIdentCol.DataType == typeof(Int64)) - { - newRow[IsIdentCol.ColumnName] = 0; - } - } - foreach (DataColumn col in item.Table.Columns) - { - if (table.Columns.Contains(col.ColumnName)) - { - //newRow[col.ColumnName] = item[col.ColumnName]; - newRow[col.ColumnName] = item[col.ColumnName]; - GridColumn column = this.gcMain.GridView.Columns[col.ColumnName]; - if (column != null) - { - GridColumnModel model = column.Tag as GridColumnModel; - if (!string.IsNullOrEmpty(model.UnionFields)) - { - this.SetUnionValue(model, rowItem[column.FieldName] + "", newRow); - } - SetCalcValue(model, rowItem[column.FieldName] + "", newRow); - } - } - } - newRow[frmSelect.AmountField] = item[frmSelect.AmountField]; - newRow[frmSelect.RecordPrimaryField] = item[frmSelect.RecordPrimaryField]; - table.Rows.Add(newRow); - } - NumberMc = frmSelect.AmountField; - //double syAmount = frmSelect.GetSyAmount(); - //if (syAmount > 0) - //{ - // rowItem[frmSelect.AmountField] = frmSelect.GetSyAmount(); - //} - //else - //{ - // table.Rows.Remove(rowItem); - //} - table.Rows.Remove(rowItem); - // 重排顺序 - table.OrderBy(this.BillModel.DetailOrderField); - this.gcMain.GridView.UpdateCurrentRow(); - this.gcMain.GridView.ShowEditor(); - } - if (frmSelect.isNextOne) - { - int SourceRowIndex = this.gcMain.GridView.GetFocusedDataSourceRowIndex(); - DataRow[] a = table.Rows.Cast().Where(x => string.IsNullOrEmpty(x[guidField].ToString())).ToArray(); - if (a.Length != 0) - { - this.gcMain.GridView.FocusedRowHandle = SourceRowIndex; - OnBtnFPOldClick(null, null); - } - else - { - MessageUtil.Show("全部分配完毕"); - // frmSelect.SelectRowItem = null; - } - } - } - } - catch (Exception ex) - { - MessageUtil.Show(ex); - } - } - private void cb_templete_QueryCloseUp(object sender, CancelEventArgs e) - { - this.SetTempSelect(true); - } - #endregion - - #region 单据快速录入相关 - /// - /// 说明:快速录入明细 - /// 创建人:龚宇超 - /// 创建日期:2019-08-05 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - private void InputGridView() - { - try - { - WaitForm.ShowForm(); - - string inputText = txt_input.Text.Trim(); - ComboBoxEditModel editObj = cb_input.SelectedItem as ComboBoxEditModel; - - if (string.IsNullOrWhiteSpace(inputText)) - { - MessageUtil.Show(ResourceKeys.KeyWordNotNull); - return; - } - if (editObj != null) - { - - DataTable table = BaseImpl.GetDataTableResult(this.ControlObj.ReplaceControlValue(ReplaceHelper.ReplaceSearchControlCond(editObj.SourceModel.CodeInputSql, inputText))); - if (table.Rows.Count == 0) - { - MessageUtil.Show(ResourceKeys.NotFoundKeyWord); - return; - } - else - { - bool onlyPopup = false; - foreach (DataRow rowItem in table.Rows) - { - this.AddRowToGridView(rowItem); - this.AddRowToGridViewByBom(rowItem, editObj.UnionModel, ref onlyPopup); - - } - } - - } - } - catch (Exception ex) - { - MessageUtil.Show(ex); - LogUtil.WriteError("单据快速录入明细出错!", ex); - } - finally - { - WaitForm.HideForm(); - } - } - /// - /// 说明:单据快速录入 - /// 创建人:龚宇超 - /// 创建日期:2018-04-19 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - private void OnInputClick(object sender, EventArgs e) - { - this.InputGridView(); - } - /// - /// 说明: - /// 创建人:龚宇超 - /// 创建日期:2019-08-05 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The sender. - /// The instance containing the event data. - private void OnInputKeyDown(object sender, KeyEventArgs e) - { - if (e.KeyCode == Keys.Enter) - { - this.InputGridView(); - this.txt_input.EditValue = ""; - this.txt_input.Focus(); - } - } - #endregion - - #region 单据模版录入相关 - private void SetTempSelect(bool isTip) - { - ComboBoxEditModel model = this.cb_templete.SelectedItem as ComboBoxEditModel; - - if (model != null) - { - bool isExec = true; - DataTable detailTable = gcMain.GridControl.DataSourceTable(); - if (detailTable != null && detailTable.Rows.Count > 0 && isTip) - { - DialogResult result = XtraMessageBox.Show("确定要切换模版?\r\n注:切换模版会清空明细数据.", "系统提示", MessageBoxButtons.YesNo); - isExec = result == DialogResult.Yes; - } - if (isExec) - { - if (isExec) - { - string title = model.RowItem["rpname"] + ""; - string brpId = model.RowItem["id"] + ""; - - // 设置标题 - this.Parent.Text = title; - // 清空明细 - detailTable.Clear(); - - // 设置主表固定字段 - LabelTextEdit textEdit = this.ControlObj.FindControl("brpid") as LabelTextEdit; - if (textEdit == null) - { - MessageUtil.Show(ResourceKeys.NotFountBrpID); - return; - } - textEdit.EditText = brpId; - - // 重新设置明细列 - DataTable columns = BillImpl.GetBillDetailBrpColumns(brpId); - if (columns != null && columns.Rows.Count > 0) - gcMain.SetEditColumns(columns); - else - gcMain.GridView.Columns.Clear(); - } - } - } - } - /// - /// 说明:初始化Brp模版 - /// 创建人:龚宇超 - /// 创建日期:2018-04-20 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - private void InitializeTemplete() - { - Dictionary dataCaches = SysModel != null ? SysModel.DataCaches : null; - if (!dataCaches.GetValue(this, "BillBrp", out DataTable table)) - { - table = BillImpl.GetBillBrp(this.SysModel.ModuleCode); - } - List tempModels = new List(); - - foreach (DataRow item in table.Rows) - { - ComboBoxEditModel editModel = new ComboBoxEditModel() - { - ValuemMeber = "id", - TextMember = "RpName", - RowItem = item - }; - this.cb_templete.Properties.Items.Add(editModel); - tempModels.Add(editModel); - } - this.cb_templete.Tag = tempModels; - } - /// - /// 说明:设置Brp模版 - /// 创建人:龚宇超 - /// 创建日期:2018-04-23 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - private void SetTempleteSelectedValue(string id) - { - List tempModels = this.cb_templete.Tag as List; - if (tempModels != null) - { - ComboBoxEditModel model = tempModels.Find(x => id.Equals(x.RowItem[x.ValuemMeber] + "")); - if (model == null) - gcMain.GridView.Columns.Clear(); - else - { - this.cb_templete.SelectedItem = model; - this.SetTempSelect(false); - } - } - } - /// - /// 说明:手动选择模版 - /// 创建人:龚宇超 - /// 创建日期:2018-04-23 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The source of the event. - /// The instance containing the event data. - private void OnTempleteClick(object sender, EventArgs e) - { - this._isSelectedTemplete = true; - } - /// - /// 说明:单据选中/取消选中数据 - /// 创建人:龚宇超 - /// 创建日期:2020-05-12 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The sender. - /// The instance containing the event data. - private void OnGridViewIsCheckClick(object sender, RowCellClickEventArgs e) - { - try - { - DataRow rowItem = (sender as GridView).GetFocusedDataRow(); - if (rowItem != null && e.Column.FieldName == "_check") - { - rowItem["_check"] = "True".Equals(rowItem["_check"] + "") ? 0 : 1; - rowItem.AcceptChanges(); - } - } - catch (Exception) - { - } - } - - private void tb_buttom_Load(object sender, EventArgs e) - { - - } - - - - /// - /// 刷新明细表 - /// - /// - /// - private void btnRefresh_Click(object sender, EventArgs e) - { - try - { - WaitForm.ShowForm(); - //主表明细 - this.gcMain.RefreshDataSource(); - } - catch (Exception ex) - { - string Message = ErrorMessage.PromptErrorMessage(ex); - MessageUtil.Show(Message, ex.Message); - } - finally - { - WaitForm.HideForm(); - } - - } - - - - - - #endregion - - #region 计算贷方的值 - /// - /// 说明:计算贷方的值 - /// 创建人:曹屹峰 - /// 创建日期:2022-01-19 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - private void OnGridControlKye(object sender, KeyEventArgs e) - { - try - { - if (!e.KeyData.Equals(Keys.F1)) return; - GridColumn column = this.gcMain.GridView.FocusedColumn; - //if (!string.IsNullOrWhiteSpace(column.View.EditingValue + "")) return; - GridColumnModel model = column.Tag as GridColumnModel; - int[] rows = this.gcMain.GridView.GetSelectedRows(); - if (model.FieldType == 115) - { - if (rows.Length != 1) return; - DataTable dataSource = this.gcMain.gridControl.DataSource as DataTable;//gridView.GetGridViewFilteredAndSortedDataToDataTable(); - GridColumn debit = this.gcMain.GridView.Columns.FirstOrDefault(x => x.Caption.Equals("借方金额")); - GridColumn credit = this.gcMain.GridView.Columns.FirstOrDefault(x => x.Caption.Equals("贷方金额")); - double debitAmount = 0;//借方金额 - double creditAmount = 0;//贷方金额 - foreach (DataRow item in dataSource.Rows) - { - if (!string.IsNullOrWhiteSpace(item[debit.FieldName].ToString())) debitAmount += double.Parse(item[debit.FieldName].ToString()); - if (!string.IsNullOrWhiteSpace(item[credit.FieldName].ToString())) creditAmount += double.Parse(item[credit.FieldName].ToString()); - } - //借方和贷方是否相等 - double differenceAmount = debitAmount - creditAmount; - if (differenceAmount > 0 && column.FieldName.Equals(credit.FieldName)) - { - dataSource.Rows[rows[0]][column.FieldName] = differenceAmount + double.Parse(dataSource.Rows[rows[0]][column.FieldName] + ""); - this.gcMain.GridView.UpdateCurrentRow(); - this.gcMain.GridView.ShowEditor(); - } - if (differenceAmount < 0 && column.FieldName.Equals(debit.FieldName)) - { - dataSource.Rows[rows[0]][column.FieldName] = differenceAmount * -1 + double.Parse(dataSource.Rows[rows[0]][column.FieldName] + ""); - this.gcMain.GridView.UpdateCurrentRow(); - this.gcMain.GridView.ShowEditor(); - } - - SendKeys.Send("{Esc}"); - //e.Handled = true; - - } - } - catch (Exception ex) - { - MessageUtil.Show(ex.Message); - } - } - #endregion - - - - /// - /// 重新计算右上角按钮坐标 - /// - private void CalculateCoordinates() - { - List buttons = new List();//没有隐藏的按钮集合 - - - - - //设置扫码控件 - if (!string.IsNullOrWhiteSpace(this.BillModel.CodeExecuteSql) && !string.IsNullOrWhiteSpace(this.BillModel.CodeExecuteParameter)) - { - this.pl_input.Controls.Clear(); - this.pl_input.Visible = false; - - LabelControl label = new LabelControl(); - label.Font = new Font("宋体", 12F); - label.Text = "串号扫描"; - label.Top = (pl_main_bottom.Height - label.Height) / 2; - label.Left = 15; - label.Parent = pl_main_bottom; - - this.ScanCodeTextEdit = new TextEdit(); - this.ScanCodeTextEdit.Properties.AutoHeight = false; - ScanCodeTextEdit.Height = this.pl_main_bottom.Height / 2; - ScanCodeTextEdit.Width = 300; - ScanCodeTextEdit.Properties.Appearance.Font = new Font("宋体", 12F); - ScanCodeTextEdit.Left = label.Width + 18; - ScanCodeTextEdit.Top = (pl_main_bottom.Height - ScanCodeTextEdit.Height) / 2; - ScanCodeTextEdit.BackColor = ColorTranslator.FromHtml("#FFC0CB"); - ScanCodeTextEdit.KeyDown += Text_KeyDown; - ScanCodeTextEdit.Parent = pl_main_bottom; - - } - - - } - - /// - /// 拖拽后添加表格数据源 - /// - /// 新增数据源 - /// 父节点号 - public void DragAddTable(DataTable dataTable, string Pid) - { - try - { - if (dataTable == null || dataTable.Rows.Count < 1) return; - - WaitForm.ShowForm(ResourceKeys.Handing); - //父节点名称 - string ParentFieldName = (this.gcMain as TreeGridControlEx).TreeListObj.ParentFieldName; - //节点名称 - string KeyFieldName = (this.gcMain as TreeGridControlEx).TreeListObj.KeyFieldName; - //主表明细结构 - DataTable TreeTable = ((this.gcMain as TreeGridControlEx).TreeListObj.DataSource as DataTable).Clone(); - //明细表数据 - TreeListColumnCollection gridColumns = (this.gcMain as TreeGridControlEx).TreeListObj.Columns; - //可以添加的行节点id - List nodeId = new List(); - - //数据源的id和pid全部加上目标节点(加上后当前数据源就是目标节点的子节点数据源) - if (dataTable.Columns.Contains(ParentFieldName) && dataTable.Columns.Contains(KeyFieldName)) - { - //当前树表格中最大的id号 - int NodeId = int.Parse((this.gcMain as TreeGridControlEx).GetNewNodesId()) - 1; - //当前树表格中如果id为bull,要赋值的id值(节点id不能为null) - int NewNodeId = int.Parse((this.gcMain as TreeGridControlEx).GetNewNodesId()); - - //根据当前的节点号,改变新增数据源中的节点号 - foreach (DataRow rowItem in dataTable.Rows) - { - // 新增表格中的数据id全部加上最大id号,如果是空就默认去赋最大id+1的值 - if (!string.IsNullOrWhiteSpace(rowItem[KeyFieldName] + "")) - { - rowItem[KeyFieldName] = int.Parse(rowItem[KeyFieldName] + "") + NodeId; - } - else - { - rowItem[KeyFieldName] = NewNodeId; - NewNodeId++; - } - - //pid为0或者null的改成目标节点的节点号,有值的默认加上最大id值 - if (string.IsNullOrWhiteSpace(rowItem[ParentFieldName] + "") || int.Parse(rowItem[ParentFieldName] + "") == 0) - { - rowItem[ParentFieldName] = Pid; - - } - else if (int.Parse(rowItem[ParentFieldName] + "") > 0) - { - rowItem[ParentFieldName] = int.Parse(rowItem[ParentFieldName] + "") + NodeId; - } - - DataRow newRow = TreeTable.NewRow(); - newRow.BeginEdit(); - // 赋值明细字段 - foreach (TreeListColumn col in gridColumns) - { - try - { - GridColumnModel model = col.Tag as GridColumnModel; - if (dataTable.Columns.Contains(col.FieldName)) - { - // 来源列中是否包含对应字段,包含则使用值 - newRow[col.FieldName] = rowItem[col.FieldName]; - if (!string.IsNullOrEmpty(model.UnionFields)) - { - this.SetUnionValue(model, rowItem[col.FieldName] + "", newRow); - } - SetCalcValue(model, rowItem[col.FieldName] + "", newRow); - } - else - { - // 未包含字段,则使用控件默认值. - if (col.FieldName.Contains("_Ls")) - { - string[] unioFielName = col.FieldName.Split('_'); - string UnioValue = unioFielName[unioFielName.Length - 1]; - DataColumn grid = dataTable.Columns.Cast().FirstOrDefault(x => x.ColumnName.Split('_')[x.ColumnName.Split('_').Length - 1].Equals(UnioValue)); - if (grid != null && !string.IsNullOrEmpty(model.UnionFields)) - { - this.SetUnionValue(model, rowItem[col.FieldName] + "", newRow); - } - SetCalcValue(model, rowItem[col.FieldName] + "", newRow); - - } - else - { - string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue); - - if (model.DefaultValue.Contains("{#")) - { - fieldValue = this.ControlObj.ReplaceParentControlValue(model.DefaultValue); - if (!string.IsNullOrEmpty(fieldValue)) - { - newRow[col.FieldName] = fieldValue; - if (!string.IsNullOrEmpty(model.UnionFields)) - { - this.SetUnionValue(model, fieldValue + "", newRow); - } - SetCalcValue(model, fieldValue + "", newRow); - - //计算规则配置在结果字段上,所以无需验证当前操作控件 - //this.gcMain.GridView.SetFocusedRowCellValue(col, fieldValue); - } - } - else if (!string.IsNullOrEmpty(model.DefaultValue)) - { - newRow[col.FieldName] = fieldValue; - if (!string.IsNullOrEmpty(model.UnionFields)) - { - this.SetUnionValue(model, fieldValue + "", newRow); - } - SetCalcValue(model, fieldValue + "", newRow); - - } - } - } - SetDisableColumn(model, newRow[col.FieldName] + "", newRow); - } - catch (Exception ex) - { - LogHelper.Instance.WriteError(ex); - } - } - - newRow.EndEdit(); - TreeTable.Rows.Add(newRow); - } - //(this.gcMain as TreeGridControlEx).SetGridViewDataSourceGenerateID(TreeTable); - //添加到主表明细中 - while (TreeTable.Rows.Count != nodeId.Count) - { - foreach (DataRow item in TreeTable.Rows) - { - //是一级节点或者父节点已经添加了的数据,会添加到明细表中 - if ((Pid.Equals(item[ParentFieldName] + "") || nodeId.Contains(item[ParentFieldName] + "")) && !nodeId.Contains(item[KeyFieldName] + "")) - { - nodeId.Add(item[KeyFieldName] + ""); - //添加到主表明细中 - this.AddMultiRowTreeGridControl(new DataRow[] { item }, item[ParentFieldName] + ""); - } - } - } - //排序 - (this.gcMain as TreeGridControlEx).DataSourceSorting(); - - } - } - catch (Exception ex) - { - string Message = ErrorMessage.PromptErrorMessage(ex); - MessageUtil.Show(Message, ex.Message); - } - finally - { - WaitForm.HideForm(); - } - - } - - /// - /// 说明:添加多条数据到单据明细 - /// 创建人:龚宇超 - /// 创建日期:2017-11-30 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - private void AddMultiRowTreeGridControl(DataRow[] rowItems, string Pid) - { - this.isDragWrap = false;//用于设置拖拽时不允许扫码控件换行 - bool onlyOne = true; - - foreach (DataRow rowItem in rowItems) - { - // 检查当前记录是否满足条件 - - this.AddRowToTreeGridControl(rowItem, Pid); - if (!string.IsNullOrWhiteSpace(this.BillModel.ChangeColColor)) - { - if (rowItem.Table.Columns.Contains(this.BillModel.ChangeColColor)) - { - rowItem[this.BillModel.ChangeColColor] = "1"; - } - } - } - this.isDragWrap = true;//用于设置拖拽时不允许扫码控件换行 - - } - - /// - /// 说明:添加行到单据明细中 - /// 创建人:龚宇超 - /// 创建日期:2017-11-30 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The row item. - /// The union model. - private void AddRowToTreeGridControl(DataRow rowItem, string Pid) - { - TreeListColumnCollection gridColumns = (this.gcMain as TreeGridControlEx).TreeListObj.Columns; - DataTable gridTable = ((this.gcMain as TreeGridControlEx).TreeListObj.DataSource as DataTable).TrimDeleteRows(); - if (!gridTable.Columns.Contains(ERPInfo.Instance.isAddRows)) - { - gridTable.Columns.Add(ERPInfo.Instance.isAddRows, typeof(String)); - } - string repeatProduct = (this.gcMain as TreeGridControlEx).TreeListObj.Columns["ProductId"] != null && rowItem.Table.Columns.Contains("ProductId") ? "ProductId" : this.BillModel.DetailPreFix + "ProductId"; - AssociatedField = repeatProduct; - if ("1".Equals(this.BillModel.DetailDoubleClickTip) && rowItem.Table.Columns.Contains(repeatProduct)) - { - // 需要提示编码重复 - DataTable dt = (this.gcMain as TreeGridControlEx).TreeListObj.DataSource as DataTable; - if (dt != null && dt.Rows.Count > 0 && dt.Columns.Contains(repeatProduct)) - { - DataRow[] drs = dt.Select(repeatProduct + "='" + rowItem[repeatProduct] + "'"); - if (drs.Length >= 1) - { - DialogResult dialog = MessageUtil.Show(ResourceKeys.ProductIsRepet, MessageBoxButtons.YesNo); - if (dialog != DialogResult.Yes) - return; - } - } - } - DataRow newRow = gridTable.NewRow(); - //2024-1-29改成>=,之前为>导致选中第一行只会添加到最后一行(测试空白行没有影响) - int position = this.gcMain.GridView.FocusedRowHandle >= 0 ? gridTable.Rows.Count > 0 ? this.gcMain.GridView.FocusedRowHandle : 0 : gridTable.Rows.Count - 1; - - - - (this.gcMain as TreeGridControlEx).TreeListObj.BeginUpdate(); - GridView gridView = this.gcMain.GridView; - // 赋值明细字段 - foreach (TreeListColumn col in gridColumns) - { - try - { - // 未包含字段,则使用控件默认值. - GridColumnModel model = col.Tag as GridColumnModel; - - if (rowItem.Table.Columns.Contains(col.FieldName)) - { - // 来源列中是否包含对应字段,包含则使用值 - newRow[col.FieldName] = rowItem[col.FieldName]; - if (!string.IsNullOrEmpty(model.UnionFields)) - { - this.SetUnionValue(model, rowItem[col.FieldName] + "", newRow); - } - SetCalcValue(model, rowItem[col.FieldName] + "", newRow); - } - else - { - - if (col.FieldName.Contains("_Ls")) - { - string[] unioFielName = col.FieldName.Split('_'); - string UnioValue = unioFielName[unioFielName.Length - 1]; - DataColumn grid = rowItem.Table.Columns.Cast().FirstOrDefault(x => x.ColumnName.Split('_')[x.ColumnName.Split('_').Length - 1].Equals(UnioValue)); - if (grid != null && !string.IsNullOrEmpty(model.UnionFields)) - { - this.SetUnionValue(model, rowItem[col.FieldName] + "", newRow); - } - SetCalcValue(model, rowItem[col.FieldName] + "", newRow); - } - else - { - string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue); - - if (model.DefaultValue.Contains("{#")) - { - fieldValue = this.ControlObj.ReplaceParentControlValue(model.DefaultValue); - if (!string.IsNullOrEmpty(fieldValue)) - { - newRow[col.FieldName] = fieldValue; - if (!string.IsNullOrEmpty(model.UnionFields)) - { - this.SetUnionValue(model, fieldValue + "", newRow); - } - SetCalcValue(model, fieldValue + "", newRow); - } - } - else if (!string.IsNullOrEmpty(model.DefaultValue)) - { - newRow[col.FieldName] = fieldValue; - if (!string.IsNullOrEmpty(model.UnionFields)) - { - this.SetUnionValue(model, fieldValue + "", newRow); - } - SetCalcValue(model, fieldValue + "", newRow); - } - } - } - SetDisableColumn(model, newRow[col.FieldName] + "", newRow); - if (model.LimitLength > 0) - { - DataRow HandleRow = newRow; - int MaxInputLength = System.Text.Encoding.Default.GetBytes(newRow[col.FieldName] + "").Length; - if (model.LimitLength < MaxInputLength) - HandleRow.SetColumnError(HandleRow.Table.Columns[col.ColumnHandle], "当前输入文本超过设定长度!");//满足条件设置错误信息 - } - } - catch (Exception ex) - { - LogHelper.Instance.WriteError(ex); - } - } - (this.gcMain as TreeGridControlEx).TreeListObj.EndUpdate(); - if (string.IsNullOrWhiteSpace(newRow[(this.gcMain as TreeGridControlEx).TreeListObj.KeyFieldName] + "")) - { - newRow[(this.gcMain as TreeGridControlEx).TreeListObj.KeyFieldName] = (this.gcMain as TreeGridControlEx).GetNewNodesId();//节点id为空,就默认给当前数据源最大id+1 - } - - if (!string.IsNullOrWhiteSpace(Pid)) - { - newRow[(this.gcMain as TreeGridControlEx).TreeListObj.ParentFieldName] = Pid;//拖拽到目标节点的id - } - // 添加数据行 - gridTable.Rows.Add(newRow); - - - if (!string.IsNullOrEmpty(NumberMc) && gridTable.Columns.Contains(mRecordPrimaryField)) - { - DataRow[] rt = gridTable.Rows.Cast().Where(x => (newRow[BillModel.DetailPreFix + "ProductId"] + "").Equals(x[BillModel.DetailPreFix + "ProductId"] + "") && !string.IsNullOrEmpty(x[mRecordPrimaryField] + "")).ToArray(); - foreach (DataRow item in rt) - { - if (newRow != null) - { - newRow[NumberMc] = Convert.ToDouble(newRow[NumberMc]) - Convert.ToDouble(item[NumberMc]); - } - //this.gcMain.OnGridViewCellValueChanged(this.gcMain, new CellValueChangedEventArgs(position + 1, this.gcMain.GridView.Columns[NumberMc], newRow[NumberMc] + "")); - //this.gcMain.GridView.UpdateCurrentRow(); - //this.gcMain.GridView.ShowEditor(); - if (Convert.ToDouble(newRow[NumberMc] + "") == 0.0) - { - gridTable.Rows.Remove(newRow); - MessageUtil.Show("数量已分配完毕!无需再进行拖拽!"); - } - } - } - //gridTable.OrderBy(this.BillModel.DetailOrderField); - //设置排序列的值 - (this.gcMain as TreeGridControlEx).DataSourceSorting(); - } - - - /// - /// 说明:添加多行到单据明细中 - /// 创建人:龚宇超 - /// 创建日期:2017-11-30 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The row item. - /// The union model. - private void AddRowsToTreeGridControl(DataTable dataTable, BillSourceUnionModel unionModel) - { - WaitForm.ShowForm(); - TreeListColumnCollection gridColumns = (this.gcMain as TreeGridControlEx).TreeListObj.Columns; - DataTable gridTable = ((this.gcMain as TreeGridControlEx).TreeListObj.DataSource as DataTable).TrimDeleteRows().Copy(); - - if (!gridTable.Columns.Contains(ERPInfo.Instance.isAddRows)) - { - gridTable.Columns.Add(ERPInfo.Instance.isAddRows, typeof(String)); - } - - TreeListNode treeNode = (this.gcMain as TreeGridControlEx).TreeListObj.FocusedNode as TreeListNode; - int position = 0; - if (treeNode != null) position = treeNode.Id; - - - //bool isLastRow = this.gcMain.GridView.IsLastVisibleRow; - - - - bool onlyOne = true; - foreach (DataRow rowItem in dataTable.Rows) - { - if (unionModel == null || ValidateDetailCond(rowItem, unionModel)) - { - - string repeatProduct = (this.gcMain as TreeGridControlEx).TreeListObj.Columns["ProductId"] != null && rowItem.Table.Columns.Contains("ProductId") ? "ProductId" : this.BillModel.DetailPreFix + "ProductId"; - AssociatedField = repeatProduct; - - if ("1".Equals(this.BillModel.DetailDoubleClickTip) && gridColumns[repeatProduct] != null && dataTable.Columns.Contains(repeatProduct)) - { - //上面方法无法处理大小写,改成搜索的形式 - DataTable dt = (this.gcMain as TreeGridControlEx).TreeListObj.DataSource as DataTable; - if (dt != null && dt.Rows.Count > 0 && dt.Columns.Contains(repeatProduct)) - { - DataRow[] drs = dt.Select(repeatProduct + "='" + rowItem[repeatProduct] + "'"); - if (drs.Length >= 1) - { - DialogResult dialog = MessageUtil.Show(ResourceKeys.ProductIsRepet, MessageBoxButtons.YesNo); - if (dialog != DialogResult.Yes) - return; - } - } - - } - - DataRow newRow = gridTable.NewRow(); - newRow.BeginEdit(); - // 赋值明细字段 - foreach (TreeListColumn col in gridColumns) - { - try - { - GridColumnModel model = col.Tag as GridColumnModel; - if (dataTable.Columns.Contains(col.FieldName)) - { - // 来源列中是否包含对应字段,包含则使用值 - newRow[col.FieldName] = rowItem[col.FieldName]; - if (!string.IsNullOrEmpty(model.UnionFields)) - { - this.SetUnionValue(model, rowItem[col.FieldName] + "", newRow); - } - SetCalcValue(model, rowItem[col.FieldName] + "", newRow); - } - else - { - // 未包含字段,则使用控件默认值. - if (col.FieldName.Contains("_Ls")) - { - string[] unioFielName = col.FieldName.Split('_'); - string UnioValue = unioFielName[unioFielName.Length - 1]; - DataColumn grid = dataTable.Columns.Cast().FirstOrDefault(x => x.ColumnName.Split('_')[x.ColumnName.Split('_').Length - 1].Equals(UnioValue)); - if (grid != null && !string.IsNullOrEmpty(model.UnionFields)) - { - this.SetUnionValue(model, rowItem[col.FieldName] + "", newRow); - } - SetCalcValue(model, rowItem[col.FieldName] + "", newRow); - - } - else - { - string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue); - - if (model.DefaultValue.Contains("{#")) - { - fieldValue = this.ControlObj.ReplaceParentControlValue(model.DefaultValue); - if (!string.IsNullOrEmpty(fieldValue)) - { - newRow[col.FieldName] = fieldValue; - if (!string.IsNullOrEmpty(model.UnionFields)) - { - this.SetUnionValue(model, fieldValue + "", newRow); - } - SetCalcValue(model, fieldValue + "", newRow); - - //计算规则配置在结果字段上,所以无需验证当前操作控件 - //this.gcMain.GridView.SetFocusedRowCellValue(col, fieldValue); - } - } - else if (!string.IsNullOrEmpty(model.DefaultValue)) - { - newRow[col.FieldName] = fieldValue; - if (!string.IsNullOrEmpty(model.UnionFields)) - { - this.SetUnionValue(model, fieldValue + "", newRow); - } - SetCalcValue(model, fieldValue + "", newRow); - - } - } - } - SetDisableColumn(model, newRow[col.FieldName] + "", newRow); - } - catch (Exception ex) - { - LogHelper.Instance.WriteError(ex); - } - } - // newRow[(this.gcMain as TreeGridControlEx).TreeListObj.KeyFieldName] = (this.gcMain as TreeGridControlEx).GetNewNodesId();//节点id - newRow.EndEdit(); - gridTable.Rows.Add(newRow); - - position++; - - if (!string.IsNullOrEmpty(NumberMc) && gridTable.Columns.Contains(mRecordPrimaryField)) - { - DataRow[] rt = gridTable.Rows.Cast().Where(x => (newRow[BillModel.DetailPreFix + "ProductId"] + "").Equals(x[BillModel.DetailPreFix + "ProductId"] + "") && !string.IsNullOrEmpty(x[mRecordPrimaryField] + "")).ToArray(); - foreach (DataRow item in rt) - { - if (newRow != null) - { - newRow[NumberMc] = Convert.ToDouble(newRow[NumberMc]) - Convert.ToDouble(item[NumberMc]); - } - //(this.gcMain as TreeGridControlEx).GcMain_CellValueChanged(this.gcMain as TreeGridControlEx, new CellValueChangedEventArgs(position, this.gcMain.GridView.Columns[NumberMc], newRow[NumberMc] + "")); - //this.gcMain.GridView.UpdateCurrentRow(); - //this.gcMain.GridView.ShowEditor(); - if (Convert.ToDouble(newRow[NumberMc] + "") == 0.0) - { - gridTable.Rows.Remove(newRow); - MessageUtil.Show("数量已分配完毕!无需再进行拖拽!"); - } - } - } - } - else - { - if (onlyOne) - { - onlyOne = false; - if (!string.IsNullOrEmpty(unionModel.ModelObj.DetailEnableMsg)) - { - if (unionModel.ModelObj.DetailEnableMsg.StartsWith("select", StringComparison.OrdinalIgnoreCase) || - unionModel.ModelObj.DetailEnableMsg.StartsWith("exec", StringComparison.OrdinalIgnoreCase)) - { - MessageUtil.Show(BaseImpl.GetResult(unionModel.ModelObj.DetailEnableMsg) + ""); - } - else - { - MessageUtil.Show(unionModel.ModelObj.DetailEnableMsg); - } - } - } - } - } - (this.gcMain as TreeGridControlEx).SetGridViewDataSourceGenerateID(gridTable); - //this.gcMain.GridControl.DataSource = gridTable; - //if (position >= 0) - // this.gcMain.GridView.SelectRowHandler(position); - //else - // this.gcMain.GridView.SelectRowHandler(gridTable.Rows.Count - 1); - - //gridTable.OrderBy(this.BillModel.DetailOrderField); - //this.gcMain.GridView.UpdateCurrentRow(); - //this.gcMain.GridView.ShowEditor(); - gridTable.OrderBy(this.BillModel.DetailOrderField); - (this.gcMain as TreeGridControlEx).DataSourceSorting(); - WaitForm.HideForm(); - } - - - - - - /// - /// 说明:是否允许添加明细 - /// 创建人:龚宇超 - /// 创建日期:2018-06-06 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// true if this instance [can add detail row]; otherwise, false. - private bool CanAddTreeDetailRow() - { - // 检测是否正在筛选数据 - if (!string.IsNullOrEmpty((this.gcMain as TreeGridControlEx).TreeListObj.FindFilterText.Trim()) || - !string.IsNullOrEmpty((this.gcMain as TreeGridControlEx).TreeListObj.FilterPanelText.Trim())) - { - if (MessageUtil.Show(ResourceKeys.GridViewSearching, MessageBoxButtons.YesNo) == DialogResult.Yes) - { - (this.gcMain as TreeGridControlEx).TreeListObj.FindFilterText = ""; - return true; - } - return false; - } - // 检测是否点击了排序表格 - if ((this.gcMain as TreeGridControlEx).IsColumnSorted()) - { - (this.gcMain as TreeGridControlEx).ClearAllSort(); - } - // 检测是否为提交或者终审模块 - if (_waterMark.Text.Contains("已终审")) - { - MessageUtil.Show(ResourceKeys.AddBillDetailed); - return false; - } - return true; - } - - - /// - /// 说明:检查可用条件 - /// 创建人:龚宇超 - /// 创建日期:2017-11-09 - /// 修改人: - /// 修改日期: - /// 修改备注: - /// 版本:1.0 - /// - /// The cond. - /// The data row. - /// true if XXXX, false otherwise. - private bool ValidateCond(string cond, DataRow dataRow) - { - bool result = false; - string condition = cond; - try - { - if (string.IsNullOrWhiteSpace(cond)) return true;//如果值是空格或者空行,默认正确 - cond = ReplaceHelper.ReplaceRowParam(dataRow, cond); - if (cond.StartsWith("@") || cond.StartsWith("!")) - { - result = "1".Equals(BaseImpl.GetDefaultValue(cond)); - } - else if (dataRow == null) - { - result = ReplaceHelper.EvalCond(cond); - } - else - { - result = ReplaceHelper.ReplaceRowParamCond(dataRow, cond); - } - return result; - } - catch (Exception ex) - { - - } - return result; - } - - - /// - /// 页签里数据修改后刷新主表和主表明细 - /// - /// - /// - private void Tab_OnDetailSaveGridCallBack(object sender, EventArgs e) - { - try - { - this.SetBillStatus(BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, this.lblOrderNo.Text))); - } - catch (Exception ex) - { - string Message = ErrorMessage.PromptErrorMessage(ex); - MessageUtil.Show(Message, ex.Message); - } - } - - - - /// - /// 扫码回车事件 - /// - /// - /// - private void Text_KeyDown(object sender, KeyEventArgs e) - { - if (e.KeyCode == Keys.Enter) - { - TextEdit textEdit = sender as TextEdit; - string inputText = textEdit.Text; - if (!string.IsNullOrWhiteSpace(this.BillModel.CodeExecuteSql) && !string.IsNullOrWhiteSpace(this.BillModel.CodeExecuteParameter)) - { - if (inputText.Length > 50) - { - MessageUtil.Show("扫码长度过长,请重新扫码"); - return; - } - - //获取选中行 - DataRow MainRowItem = gcMain.GridView.GetFocusedDataRow(); - if (MainRowItem == null) - { - MainRowItem = gcMain.GridControl.DataSourceTable().NewRow(); - } - //获取红蓝单据 - string DocumentColor = this.rdBlue.Checked ? "0" : this.rdRed.Checked ? "1" : ""; - //数量,默认为1 - int Quantity = 1; - /* - A:弹框输入数量 - B;不弹框,默认数量为1 - C:配置了扫码关联模块,根据数量sql结果。判断是否弹窗。数量默认为1 - - this.BillModel.ScanCodeFixedPrefix为条码前缀,扫码内容前缀和配置相同,默认为B - */ - string Type = string.Empty; - if (!string.IsNullOrWhiteSpace(this.BillModel.ScanCodeFixedPrefix) && inputText.StartsWith(this.BillModel.ScanCodeFixedPrefix)) - { - Type = "B"; - } - else - { - string Sql = string.Format("select line_str from wms_ScanCodeLinetab a where modid='{0}' and hl_tig='{1}'", this.SysModel.ModuleCode, DocumentColor); - Type = SqlHelper.ExecuteScalar(Sql) + ""; - if (string.IsNullOrWhiteSpace(Type)) - { - MessageUtil.Show("扫码配置错误,请联系朗速服务人员"); - return; - } - } - switch (Type.ToUpper()) - { - case "A": - - FrmAdd frmAdd = new FrmAdd(); - if (frmAdd.ShowDialog() == DialogResult.OK) - { - Quantity = frmAdd.Quantity; - } - else - { - textEdit.EditValue = ""; - textEdit.Focus(); - return; - } - this.ExecuteWcanningSQL(MainRowItem, Quantity + "", DocumentColor, inputText); - break; - case "B": - this.ExecuteWcanningSQL(MainRowItem, Quantity + "", DocumentColor, inputText); - break; - case "C": - if (!string.IsNullOrWhiteSpace(this.BillModel.ScanCodeModuleCode)) - { - //根据传入的模块号获取模块信息 - DataRow modelRow = MainImpl.GetSystemdllTab(this.BillModel.ScanCodeModuleCode);//获取模块信息 - if (modelRow == null) - { - MessageUtil.Show("模块编号[" + this.BillModel.ScanCodeModuleCode + "],配置错误!\r\n该模块信息未找到!"); - return; - } - if (modelRow.Table.Columns.Contains("countSql") && !string.IsNullOrWhiteSpace(modelRow["countSql"] + "")) - { - string sql = modelRow["countSql"] + ""; - sql = ReplaceHelper.ReplaceUserInfo(sql); - sql = ReplaceHelper.ReplaceParamToValue(sql, "{value}", inputText); - string num = SqlHelper.ExecuteScalar(sql) + ""; - num = this.IsNumberic(num) ? num : "0"; - if (int.Parse(num) == 0) - { - MessageUtil.Show("未检测到扫码信息存在,请检查相应前序业务!"); - } - else if (int.Parse(num) == 1) - { - this.ExecuteWcanningSQL(MainRowItem, Quantity + "", DocumentColor, inputText); - } - else if (int.Parse(num) > 1) - { - FrmScanCodeAssociation frmScanCodeAssociation = new FrmScanCodeAssociation(modelRow, inputText); - if (frmScanCodeAssociation.ShowDialog() == DialogResult.OK) - { - string Codes = frmScanCodeAssociation.StringCodes; - this.ExecuteWcanningSQL(MainRowItem, Quantity + "", DocumentColor, Codes); - } - else - { - textEdit.EditValue = ""; - textEdit.Focus(); - return; - } - } - } - } - else - { - MessageUtil.Show("扫码配置错误"); - return; - } - break; - - } - } - - textEdit.EditValue = ""; - textEdit.Focus(); - } - } - - - /// - /// 执行扫码的存储过程 - /// - /// 明细选中行 - ///数量 - ///红蓝单据字段 - ///串码,多个用;隔开 - public void ExecuteWcanningSQL(DataRow MainRowItem, string Quantity, string DocumentColor, string Codes) - { - int j = 0; - foreach (string code in Codes.TrimEnd(';').Split(';')) - { - if (string.IsNullOrWhiteSpace(code)) continue; - List Parameter = this.BillModel.CodeExecuteParameter.Split(',').ToList(); - for (int i = 0; i < Parameter.Count; i++) - { - string item = Parameter[i]; - if (item.Contains("{DocumentColor}")) - { - item = ReplaceHelper.ReplaceParamToValue(item, "{DocumentColor}", DocumentColor); - } - if (item.Contains("{amount}")) - { - item = Quantity + ""; - } - //替换单据号 - item = ReplaceHelper.ReplaceParamToValue(item, "{" + this.BillModel.PrimaryKey + "}", this.lblOrderNo.Text); - //替换选中行(没有就传空) - item = ReplaceHelper.ReplaceRowParam(MainRowItem, item); - //替换扫码内容 - item = ReplaceHelper.ReplaceParamToValue(item, "{value}", code); - Parameter[i] = item; - } - - - List procParams = ReplaceHelper.GetParamFields(this.BillModel.CodeExecuteSql); - List sqlParamList = new List(); - string[] paramStr = procParams[0].Replace("{", "").Replace("}", "").Split(','); - SqlParameter pMsg = new SqlParameter("@msg", SqlDbType.VarChar, 2000); - - for (int i = 0; i < paramStr.Length; i++) - { - string item = paramStr[i]; - if (paramStr[i].Equals("@msg", StringComparison.OrdinalIgnoreCase)) - { - pMsg.Direction = ParameterDirection.InputOutput; - pMsg.Value = Parameter.Count > i ? string.IsNullOrEmpty(Parameter[i]) ? "" : Parameter[i] : ""; - sqlParamList.Add(pMsg); - } - else - { - string paramStr1 = paramStr[i]; - SqlParameter param = new SqlParameter(string.Format("{0}", paramStr1), SqlDbType.VarChar); - param.Value = Parameter[i]; - sqlParamList.Add(param); - } - } - SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int, 4); - returnValue.Direction = ParameterDirection.ReturnValue; - int result; - sqlParamList.Add(returnValue); - - try - { - result = MainImpl.ExecProcedure(this.BillModel.CodeExecuteSql.Replace(procParams[0], "").Trim(), sqlParamList.ToArray()); - } - catch (SqlException sex) - { - string Message = ErrorMessage.PromptErrorMessage(sex); - MessageUtil.Show(Message, sex.Message); - return; - } - catch (Exception ex) - { - string Message = ErrorMessage.PromptErrorMessage(ex); - MessageUtil.Show(Message, ex.Message); - return; - } - int rValue = Convert.ToInt32(returnValue.Value); - string varchar = pMsg.Value + ""; - switch (rValue) - { - case 1: - if (string.IsNullOrWhiteSpace(varchar)) - { - //刷新当前单据 - if (j == Codes.TrimEnd(';').Split(';').Length - 1) - { - this.SetBillStatus(BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, this.lblOrderNo.Text))); - } - - } - else - { - //刷新返回的单据号 - this.lblOrderNo.Text = varchar; - this.SetBillStatus(BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, varchar))); - } - break; - case -1: - MessageUtil.Show(ResourceKeys.OperFault + "\n" + pMsg.Value); - break; - } - j++; - } - } - - - - - /// - /// 设置辅助功能按钮状态 - /// - /// - public void SetButtonStatus(DataRow rowItem = null) - { - foreach (System.Windows.Forms.Control control in pl_buttom.Controls) - { - if (control is SimpleButton) - { - SimpleButton button = control as SimpleButton; - DataRow dr = button.Tag as DataRow; - if (dr != null && dr.Table.Columns.Contains("menuCond")) - { - string menuCond = dr["menuCond"] + ""; - if (!string.IsNullOrWhiteSpace(menuCond) && rowItem == null) - { - //menuCond = "'{wms_louts_Billdocument_Id}'<>''"; - menuCond = ReplaceHelper.ReplaceParamToValue(menuCond, "{" + this.BillModel.PrimaryKey + "}", this.lblOrderNo.Text); - } - button.Enabled = ValidateCond(menuCond, rowItem); - //button.Enabled = true; - } - } - - } - } - - /// - /// 设置控件边距 - /// - /// - /// - public DataTable SetControlMargins(DataTable dataTable) - { - int minLeft = int.MaxValue; - int maxRightEdge = 0; - - // 检查 DataTable 是否为空且包含所需列 - if (dataTable != null && dataTable.Rows.Count > 0 && - dataTable.Columns.Contains("controlLeft") && - dataTable.Columns.Contains("controlWidth")) - { - foreach (DataRow row in dataTable.Rows) - { - // 尝试解析 controlLeft 和 controlWidth - if (int.TryParse(row["controlLeft"].ToString(), out int left) && - int.TryParse(row["controlWidth"].ToString(), out int width)) - { - if (left < minLeft) - { - minLeft = left; - } - int rightEdge = left + width; - if (rightEdge > maxRightEdge) - { - maxRightEdge = rightEdge; - } - } - } - } - if (minLeft == int.MaxValue) minLeft = 0; - - - int MovingDistance = (Screen.PrimaryScreen.WorkingArea.Width - maxRightEdge) / 2; - - if (dataTable.Columns.Contains("controlLeft") && MovingDistance > 0) - { - foreach (DataRow item in dataTable.Rows) - { - item["controlLeft"] = int.Parse(item["controlLeft"] + "") + MovingDistance - minLeft; - - } - } - return dataTable; - } - - - /// - /// 判断是不是数值 - /// - /// - /// - private bool IsNumberic(string oText) - { - try - { - int var1 = Convert.ToInt32(oText); - return true; - } - catch - { - return false; - } - } - } -} + /// + /// 说明:明细分割条移动保存位置 + /// 创建人:龚宇超 + /// 创建日期:2018-03-06 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + private void OnDetailsSplitterMoved(object sender, EventArgs e) + { + if (this._isInitFinish) + { + SplitContainerControl splitContainerControl = sender as SplitContainerControl; + IniHelper.Write(string.Format("bill_Details_Width_{0}", this.SysModel.ModuleCode), splitContainerControl.SplitterPosition + ""); + } + } + + + /// + /// 说明:判断字符串出现次数 + /// 创建人:龚宇超 + /// 创建日期: + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The string. + /// The substring. + /// System.Int32. + private static int SubstringCount(string str, string substring) + { + if (str.Contains(substring)) + { + string strReplaced = str.Replace(substring, ""); + return (str.Length - strReplaced.Length) / substring.Length; + } + + return 0; + } + /// + /// 说明:帮助文档 + /// 创建人:龚宇超 + /// 创建日期:2020-01-15 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The sender. + /// The instance containing the event data. + private void OnHelpClick(object sender, EventArgs e) + { + WebBrowserUtil.StartWebBrowser(this.SysModel.ModuleCode, this.BillModel.TypeName); + } + + /// + /// 说明:分配明细 + /// 创建人:龚宇超 + /// 创建日期:2020-01-15 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + private void OnBtnFPOldClick(object sender, EventArgs e) + { + this.gcMain.GridView.PostEditor(); + FPOld(); + } + private void OnBtnFPNewClick(object sender, EventArgs e) + { + this.gcMain.GridView.PostEditor(); + FPNew(); + } + /// + /// 新版分配 + /// + private void FPNew() + { + try + { + this.gcMain.GridView.FocusedRowHandle = 0; + DataTable table = this.gcMain.GridControl.DataSource as DataTable; + if (!table.Columns.Contains(guidField)) + { + table.Columns.Add(guidField, typeof(string)); + } + #region 创建分配界面 + string[] args = { this.SysModel.FormText, this.SysModel.UserId, this.SysModel.UserName, this.SysModel.Privilege, this.SysModel.ModuleCode, this.SysModel.ModuleId + "", this.BillModel.PopupUnionCode, "1000" }; + DynamicBaseSelectModel baseModel = new DynamicBaseSelectModel(args); + using (FrmBaseSelectBatch frmSelect = new FrmBaseSelectBatch(baseModel, this.ControlObj, this.gcMain)) + { + frmSelect.Text = this.BillModel.TypeName; + frmSelect.InitControl(); + frmSelect.OnAfterFPCallback += OnAfterFPCallback; + #region 初始化第一条数据 + DataRow rowItem = this.gcMain.GridView.GetFocusedDataRow(); + if (rowItem == null) + { + return; + } + rowItem[guidField] = Guid.NewGuid().ToString(); + if (!string.IsNullOrEmpty(mRecordPrimaryField) && table.Columns.Contains(this.mRecordPrimaryField)) + { + // 检查数据是否为分配后的行 + if (!string.IsNullOrEmpty(rowItem[this.mRecordPrimaryField] + "")) + { + if (this.gcMain.GridView.FocusedRowHandle + 1 <= this.gcMain.GridView.RowCount - 1) + { + this.gcMain.GridView.FocusedRowHandle += 1; + FPNew(); + } + return; + } + } + if (!string.IsNullOrEmpty(mRecordPrimaryField)) + { + frmSelect.FpRows = table.Rows.Cast().Where(x => (rowItem[guidField] + "").Equals(x[guidField] + "")).ToArray(); + if (frmSelect.FpRows != null && frmSelect.FpRows.Length > 0) + { + List rows = frmSelect.FpRows.ToList(); + rows.Remove(rowItem); + frmSelect.FpRows = rows.ToArray(); + } + if (table.Columns.Contains(mRecordPrimaryField)) + { + frmSelect.FpOtherRows = table.Rows.Cast().Where(x => !(rowItem[guidField] + "").Equals(x[guidField] + "") && !string.IsNullOrEmpty(x[mRecordPrimaryField] + "")).ToArray(); + } + } + frmSelect.InitData(rowItem); + frmSelect.OnBtnFPClick(null, null); + #endregion + //frmSelect.ShowDialog(); + #endregion + } + } + catch (Exception ex) + { + MessageUtil.Show(ex.Message); + } + } + /// + /// 分配完成后回调 + /// + /// + /// + private void OnAfterFPCallback(object sender, EventArgs e) + { + WaitForm.ShowForm(); + try + { + // 临时禁用新增行(空白行) + if (this.BillModel.DefaultAddEmptyRow) this.gcMain.GridView.OptionsView.NewItemRowPosition = NewItemRowPosition.None; + DataRow rowItem = this.gcMain.GridView.GetFocusedDataRow(); + if (rowItem == null) + { + return; + } + DataTable table = this.gcMain.GridControl.DataSource as DataTable; + FrmBaseSelectBatch frmSelect = (FrmBaseSelectBatch)sender; + rowItem[guidField] = Guid.NewGuid().ToString(); + if (!string.IsNullOrEmpty(mRecordPrimaryField) && table.Columns.Contains(this.mRecordPrimaryField)) + { + // 检查数据是否为分配后的行 + if (!string.IsNullOrEmpty(rowItem[this.mRecordPrimaryField] + "")) + { + if (this.gcMain.GridView.FocusedRowHandle + 1 <= this.gcMain.GridView.RowCount - 1) + { + this.gcMain.GridView.FocusedRowHandle += 1; + OnAfterFPCallback(sender, e); + } + return; + } + } + if (!string.IsNullOrEmpty(mRecordPrimaryField)) + { + frmSelect.FpRows = table.Rows.Cast().Where(x => (rowItem[guidField] + "").Equals(x[guidField] + "")).ToArray(); + if (frmSelect.FpRows != null && frmSelect.FpRows.Length > 0) + { + List rows = frmSelect.FpRows.ToList(); + rows.Remove(rowItem); + frmSelect.FpRows = rows.ToArray(); + } + if (table.Columns.Contains(mRecordPrimaryField)) + { + frmSelect.FpOtherRows = table.Rows.Cast().Where(x => !(rowItem[guidField] + "").Equals(x[guidField] + "") && !string.IsNullOrEmpty(x[mRecordPrimaryField] + "")).ToArray(); + } + } + frmSelect.InitData(rowItem); + bool success = frmSelect.FP(); + if (success) + { + if (frmSelect.SelectedRows != null && frmSelect.SelectedRows.Length > 0) + { + // 增加标识列 + if (!table.Columns.Contains(frmSelect.RecordPrimaryField)) + { + this.mRecordPrimaryField = frmSelect.RecordPrimaryField; + table.Columns.Add(this.mRecordPrimaryField, typeof(String)); + } + foreach (DataRow item in frmSelect.SelectedRows) + { + DataRow newRow = table.NewRow(); + newRow.ItemArray = rowItem.ItemArray; + newRow[guidField] = rowItem[guidField]; + DataColumn IsIdentCol = newRow.Table.Columns.Cast().FirstOrDefault(x => x.ColumnName == BaseImpl.GetResult(string.Format("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.columns WHERE TABLE_NAME='{0}' AND COLUMNPROPERTY(OBJECT_ID('{0}'),COLUMN_NAME,'IsIdentity')=1", BillModel.DetailTable)) + ""); + //自增长列分配按空值取 + if (IsIdentCol != null) + { + if (IsIdentCol.DataType == typeof(Decimal) || + IsIdentCol.DataType == typeof(Double) || + IsIdentCol.DataType == typeof(Int16) || + IsIdentCol.DataType == typeof(Int32) || + IsIdentCol.DataType == typeof(Int64)) + { + newRow[IsIdentCol.ColumnName] = 0; + } + } + foreach (DataColumn col in item.Table.Columns) + { + if (table.Columns.Contains(col.ColumnName)) + { + //newRow[col.ColumnName] = item[col.ColumnName]; + newRow[col.ColumnName] = item[col.ColumnName]; + GridColumn column = this.gcMain.GridView.Columns[col.ColumnName]; + if (column != null) + { + GridColumnModel model = column.Tag as GridColumnModel; + if (!string.IsNullOrEmpty(model.UnionFields)) + { + this.SetUnionValue(model, rowItem[column.FieldName] + "", newRow); + } + SetCalcValue(model, rowItem[column.FieldName] + "", newRow); + } + } + } + newRow[frmSelect.AmountField] = item[frmSelect.AmountField]; + newRow[frmSelect.RecordPrimaryField] = item[frmSelect.RecordPrimaryField]; + table.Rows.Add(newRow); + } + NumberMc = frmSelect.AmountField; + table.Rows.Remove(rowItem); + // 重排顺序 + table.OrderBy(this.BillModel.DetailOrderField); + this.gcMain.GridView.UpdateCurrentRow(); + this.gcMain.GridView.ShowEditor(); + if (frmSelect.isNextOne) + { + int SourceRowIndex = this.gcMain.GridView.GetFocusedDataSourceRowIndex(); + DataRow[] a = table.Rows.Cast().Where(x => string.IsNullOrEmpty(x[guidField].ToString())).ToArray(); + if (a.Length != 0) + { + this.gcMain.GridView.FocusedRowHandle = SourceRowIndex; + OnAfterFPCallback(sender, e); + } + else + { + MessageUtil.Show("全部分配完毕"); + // frmSelect.SelectRowItem = null; + } + } + } + } + else + { + if (this.gcMain.GridView.FocusedRowHandle + 1 <= this.gcMain.GridView.RowCount - 1) + { + this.gcMain.GridView.FocusedRowHandle += 1; + OnAfterFPCallback(sender, e); + } + else + { + MessageUtil.Show("全部分配完毕"); + } + } + } + catch (Exception) + { + throw; + } + finally + { + // 重新开启新增行(空白行) + if (this.BillModel.DefaultAddEmptyRow) this.gcMain.GridView.OptionsView.NewItemRowPosition = NewItemRowPosition.Bottom; + WaitForm.HideForm(); + } + } + + /// + /// 老版分配 + /// + private void FPOld() + { + try + { + DataRow rowItem = this.gcMain.GridView.GetFocusedDataRow(); + if (rowItem == null) + { + MessageUtil.Show("请先选择一条明细在进行分配!"); + return; + } + DataTable table = this.gcMain.GridControl.DataSource as DataTable; + if (!table.Columns.Contains(guidField)) + { + table.Columns.Add(guidField, typeof(string)); + } + rowItem[guidField] = Guid.NewGuid().ToString(); ; + if (!string.IsNullOrEmpty(mRecordPrimaryField) && table.Columns.Contains(this.mRecordPrimaryField)) + { + // 检查数据是否为分配后的行 + if (!string.IsNullOrEmpty(rowItem[this.mRecordPrimaryField] + "")) + { + MessageUtil.Show("该行数据为已分配后的数据,无需分配!"); + return; + } + } + string[] args = { this.SysModel.FormText, this.SysModel.UserId, this.SysModel.UserName, this.SysModel.Privilege, this.SysModel.ModuleCode, this.SysModel.ModuleId + "", this.BillModel.PopupUnionCode, "1000" }; + DynamicBaseSelectModel baseModel = new DynamicBaseSelectModel(args); + using (FrmBaseSelect frmSelect = new FrmBaseSelect(baseModel, this.ControlObj, this.gcMain)) + { + //if (frmSelect.SelectRowItem == null) + //{ + // frmSelect = new FrmBaseSelect(baseModel, this.ControlObj, this.gcMain); + //} + frmSelect.Text = this.BillModel.TypeName; + frmSelect.SelectRowItem = rowItem; + bool isNextOne = false; + if (!string.IsNullOrEmpty(mRecordPrimaryField)) + { + frmSelect.FpRows = table.Rows.Cast().Where(x => (rowItem[guidField] + "").Equals(x[guidField] + "")).ToArray(); + if (frmSelect.FpRows != null && frmSelect.FpRows.Length > 0) + { + List rows = frmSelect.FpRows.ToList(); + rows.Remove(rowItem); + frmSelect.FpRows = rows.ToArray(); + } + if (table.Columns.Contains(mRecordPrimaryField)) + { + frmSelect.FpOtherRows = table.Rows.Cast().Where(x => !(rowItem[guidField] + "").Equals(x[guidField] + "") && !string.IsNullOrEmpty(x[mRecordPrimaryField] + "")).ToArray(); + } + } + if (frmSelect.ShowDialog() == DialogResult.OK && frmSelect.SelectedRows != null && frmSelect.SelectedRows.Length > 0) + { + //if (frmSelect.isNextOne) + //{ + // isNextOne = true; + //} + //else + //{ + // isNextOne = false; + //} + // 增加标识列 + if (!table.Columns.Contains(frmSelect.RecordPrimaryField)) + { + this.mRecordPrimaryField = frmSelect.RecordPrimaryField; + table.Columns.Add(this.mRecordPrimaryField, typeof(String)); + } + + foreach (DataRow item in frmSelect.SelectedRows) + { + DataRow newRow = table.NewRow(); + newRow.ItemArray = rowItem.ItemArray; + newRow[guidField] = rowItem[guidField]; + DataColumn IsIdentCol = newRow.Table.Columns.Cast().FirstOrDefault(x => x.ColumnName == BaseImpl.GetResult(string.Format("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.columns WHERE TABLE_NAME='{0}' AND COLUMNPROPERTY(OBJECT_ID('{0}'),COLUMN_NAME,'IsIdentity')=1", BillModel.DetailTable)) + ""); + //自增长列分配按空值取 + if (IsIdentCol != null) + { + if (IsIdentCol.DataType == typeof(Decimal) || + IsIdentCol.DataType == typeof(Double) || + IsIdentCol.DataType == typeof(Int16) || + IsIdentCol.DataType == typeof(Int32) || + IsIdentCol.DataType == typeof(Int64)) + { + newRow[IsIdentCol.ColumnName] = 0; + } + } + foreach (DataColumn col in item.Table.Columns) + { + if (table.Columns.Contains(col.ColumnName)) + { + //newRow[col.ColumnName] = item[col.ColumnName]; + newRow[col.ColumnName] = item[col.ColumnName]; + GridColumn column = this.gcMain.GridView.Columns[col.ColumnName]; + if (column != null) + { + GridColumnModel model = column.Tag as GridColumnModel; + if (!string.IsNullOrEmpty(model.UnionFields)) + { + this.SetUnionValue(model, rowItem[column.FieldName] + "", newRow); + } + SetCalcValue(model, rowItem[column.FieldName] + "", newRow); + } + } + } + newRow[frmSelect.AmountField] = item[frmSelect.AmountField]; + newRow[frmSelect.RecordPrimaryField] = item[frmSelect.RecordPrimaryField]; + table.Rows.Add(newRow); + } + NumberMc = frmSelect.AmountField; + //double syAmount = frmSelect.GetSyAmount(); + //if (syAmount > 0) + //{ + // rowItem[frmSelect.AmountField] = frmSelect.GetSyAmount(); + //} + //else + //{ + // table.Rows.Remove(rowItem); + //} + table.Rows.Remove(rowItem); + // 重排顺序 + table.OrderBy(this.BillModel.DetailOrderField); + this.gcMain.GridView.UpdateCurrentRow(); + this.gcMain.GridView.ShowEditor(); + } + if (frmSelect.isNextOne) + { + int SourceRowIndex = this.gcMain.GridView.GetFocusedDataSourceRowIndex(); + DataRow[] a = table.Rows.Cast().Where(x => string.IsNullOrEmpty(x[guidField].ToString())).ToArray(); + if (a.Length != 0) + { + this.gcMain.GridView.FocusedRowHandle = SourceRowIndex; + OnBtnFPOldClick(null, null); + } + else + { + MessageUtil.Show("全部分配完毕"); + // frmSelect.SelectRowItem = null; + } + } + } + } + catch (Exception ex) + { + MessageUtil.Show(ex); + } + } + private void cb_templete_QueryCloseUp(object sender, CancelEventArgs e) + { + this.SetTempSelect(true); + } + #endregion + + #region 单据快速录入相关 + /// + /// 说明:快速录入明细 + /// 创建人:龚宇超 + /// 创建日期:2019-08-05 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + private void InputGridView() + { + try + { + WaitForm.ShowForm(); + + string inputText = txt_input.Text.Trim(); + ComboBoxEditModel editObj = cb_input.SelectedItem as ComboBoxEditModel; + + if (string.IsNullOrWhiteSpace(inputText)) + { + MessageUtil.Show(ResourceKeys.KeyWordNotNull); + return; + } + if (editObj != null) + { + + DataTable table = BaseImpl.GetDataTableResult(this.ControlObj.ReplaceControlValue(ReplaceHelper.ReplaceSearchControlCond(editObj.SourceModel.CodeInputSql, inputText))); + if (table.Rows.Count == 0) + { + MessageUtil.Show(ResourceKeys.NotFoundKeyWord); + return; + } + else + { + bool onlyPopup = false; + foreach (DataRow rowItem in table.Rows) + { + this.AddRowToGridView(rowItem); + this.AddRowToGridViewByBom(rowItem, editObj.UnionModel, ref onlyPopup); + + } + } + + } + } + catch (Exception ex) + { + MessageUtil.Show(ex); + LogUtil.WriteError("单据快速录入明细出错!", ex); + } + finally + { + WaitForm.HideForm(); + } + } + /// + /// 说明:单据快速录入 + /// 创建人:龚宇超 + /// 创建日期:2018-04-19 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + private void OnInputClick(object sender, EventArgs e) + { + this.InputGridView(); + } + /// + /// 说明: + /// 创建人:龚宇超 + /// 创建日期:2019-08-05 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The sender. + /// The instance containing the event data. + private void OnInputKeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Enter) + { + this.InputGridView(); + this.txt_input.EditValue = ""; + this.txt_input.Focus(); + } + } + #endregion + + #region 单据模版录入相关 + private void SetTempSelect(bool isTip) + { + ComboBoxEditModel model = this.cb_templete.SelectedItem as ComboBoxEditModel; + + if (model != null) + { + bool isExec = true; + DataTable detailTable = gcMain.GridControl.DataSourceTable(); + if (detailTable != null && detailTable.Rows.Count > 0 && isTip) + { + DialogResult result = XtraMessageBox.Show("确定要切换模版?\r\n注:切换模版会清空明细数据.", "系统提示", MessageBoxButtons.YesNo); + isExec = result == DialogResult.Yes; + } + if (isExec) + { + if (isExec) + { + string title = model.RowItem["rpname"] + ""; + string brpId = model.RowItem["id"] + ""; + + // 设置标题 + this.Parent.Text = title; + // 清空明细 + detailTable.Clear(); + + // 设置主表固定字段 + LabelTextEdit textEdit = this.ControlObj.FindControl("brpid") as LabelTextEdit; + if (textEdit == null) + { + MessageUtil.Show(ResourceKeys.NotFountBrpID); + return; + } + textEdit.EditText = brpId; + + // 重新设置明细列 + DataTable columns = BillImpl.GetBillDetailBrpColumns(brpId); + if (columns != null && columns.Rows.Count > 0) + gcMain.SetEditColumns(columns); + else + gcMain.GridView.Columns.Clear(); + } + } + } + } + /// + /// 说明:初始化Brp模版 + /// 创建人:龚宇超 + /// 创建日期:2018-04-20 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + private void InitializeTemplete() + { + Dictionary dataCaches = SysModel != null ? SysModel.DataCaches : null; + if (!dataCaches.GetValue(this, "BillBrp", out DataTable table)) + { + table = BillImpl.GetBillBrp(this.SysModel.ModuleCode); + } + List tempModels = new List(); + + foreach (DataRow item in table.Rows) + { + ComboBoxEditModel editModel = new ComboBoxEditModel() + { + ValuemMeber = "id", + TextMember = "RpName", + RowItem = item + }; + this.cb_templete.Properties.Items.Add(editModel); + tempModels.Add(editModel); + } + this.cb_templete.Tag = tempModels; + } + /// + /// 说明:设置Brp模版 + /// 创建人:龚宇超 + /// 创建日期:2018-04-23 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + private void SetTempleteSelectedValue(string id) + { + List tempModels = this.cb_templete.Tag as List; + if (tempModels != null) + { + ComboBoxEditModel model = tempModels.Find(x => id.Equals(x.RowItem[x.ValuemMeber] + "")); + if (model == null) + gcMain.GridView.Columns.Clear(); + else + { + this.cb_templete.SelectedItem = model; + this.SetTempSelect(false); + } + } + } + /// + /// 说明:手动选择模版 + /// 创建人:龚宇超 + /// 创建日期:2018-04-23 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The source of the event. + /// The instance containing the event data. + private void OnTempleteClick(object sender, EventArgs e) + { + this._isSelectedTemplete = true; + } + /// + /// 说明:单据选中/取消选中数据 + /// 创建人:龚宇超 + /// 创建日期:2020-05-12 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The sender. + /// The instance containing the event data. + private void OnGridViewIsCheckClick(object sender, RowCellClickEventArgs e) + { + try + { + DataRow rowItem = (sender as GridView).GetFocusedDataRow(); + if (rowItem != null && e.Column.FieldName == "_check") + { + rowItem["_check"] = "True".Equals(rowItem["_check"] + "") ? 0 : 1; + rowItem.AcceptChanges(); + } + } + catch (Exception) + { + } + } + + private void tb_buttom_Load(object sender, EventArgs e) + { + + } + + + + /// + /// 刷新明细表 + /// + /// + /// + private void btnRefresh_Click(object sender, EventArgs e) + { + try + { + WaitForm.ShowForm(); + //主表明细 + this.gcMain.RefreshDataSource(); + } + catch (Exception ex) + { + string Message = ErrorMessage.PromptErrorMessage(ex); + MessageUtil.Show(Message, ex.Message); + } + finally + { + WaitForm.HideForm(); + } + + } + + + + + + #endregion + + #region 计算贷方的值 + /// + /// 说明:计算贷方的值 + /// 创建人:曹屹峰 + /// 创建日期:2022-01-19 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + private void OnGridControlKye(object sender, KeyEventArgs e) + { + try + { + if (!e.KeyData.Equals(Keys.F1)) return; + GridColumn column = this.gcMain.GridView.FocusedColumn; + //if (!string.IsNullOrWhiteSpace(column.View.EditingValue + "")) return; + GridColumnModel model = column.Tag as GridColumnModel; + int[] rows = this.gcMain.GridView.GetSelectedRows(); + if (model.FieldType == 115) + { + if (rows.Length != 1) return; + DataTable dataSource = this.gcMain.gridControl.DataSource as DataTable;//gridView.GetGridViewFilteredAndSortedDataToDataTable(); + GridColumn debit = this.gcMain.GridView.Columns.FirstOrDefault(x => x.Caption.Equals("借方金额")); + GridColumn credit = this.gcMain.GridView.Columns.FirstOrDefault(x => x.Caption.Equals("贷方金额")); + double debitAmount = 0;//借方金额 + double creditAmount = 0;//贷方金额 + foreach (DataRow item in dataSource.Rows) + { + if (!string.IsNullOrWhiteSpace(item[debit.FieldName].ToString())) debitAmount += double.Parse(item[debit.FieldName].ToString()); + if (!string.IsNullOrWhiteSpace(item[credit.FieldName].ToString())) creditAmount += double.Parse(item[credit.FieldName].ToString()); + } + //借方和贷方是否相等 + double differenceAmount = debitAmount - creditAmount; + if (differenceAmount > 0 && column.FieldName.Equals(credit.FieldName)) + { + dataSource.Rows[rows[0]][column.FieldName] = differenceAmount + double.Parse(dataSource.Rows[rows[0]][column.FieldName] + ""); + this.gcMain.GridView.UpdateCurrentRow(); + this.gcMain.GridView.ShowEditor(); + } + if (differenceAmount < 0 && column.FieldName.Equals(debit.FieldName)) + { + dataSource.Rows[rows[0]][column.FieldName] = differenceAmount * -1 + double.Parse(dataSource.Rows[rows[0]][column.FieldName] + ""); + this.gcMain.GridView.UpdateCurrentRow(); + this.gcMain.GridView.ShowEditor(); + } + + SendKeys.Send("{Esc}"); + //e.Handled = true; + + } + } + catch (Exception ex) + { + MessageUtil.Show(ex.Message); + } + } + #endregion + + + + /// + /// 重新计算右上角按钮坐标 + /// + private void CalculateCoordinates() + { + List buttons = new List();//没有隐藏的按钮集合 + + + + + //设置扫码控件 + if (!string.IsNullOrWhiteSpace(this.BillModel.CodeExecuteSql) && !string.IsNullOrWhiteSpace(this.BillModel.CodeExecuteParameter)) + { + this.pl_input.Controls.Clear(); + this.pl_input.Visible = false; + + LabelControl label = new LabelControl(); + label.Font = new Font("宋体", 12F); + label.Text = "串号扫描"; + label.Top = (pl_main_bottom.Height - label.Height) / 2; + label.Left = 15; + label.Parent = pl_main_bottom; + + this.ScanCodeTextEdit = new TextEdit(); + this.ScanCodeTextEdit.Properties.AutoHeight = false; + ScanCodeTextEdit.Height = this.pl_main_bottom.Height / 2; + ScanCodeTextEdit.Width = 300; + ScanCodeTextEdit.Properties.Appearance.Font = new Font("宋体", 12F); + ScanCodeTextEdit.Left = label.Width + 18; + ScanCodeTextEdit.Top = (pl_main_bottom.Height - ScanCodeTextEdit.Height) / 2; + ScanCodeTextEdit.BackColor = ColorTranslator.FromHtml("#FFC0CB"); + ScanCodeTextEdit.KeyDown += Text_KeyDown; + ScanCodeTextEdit.Parent = pl_main_bottom; + + } + + + } + + /// + /// 拖拽后添加表格数据源 + /// + /// 新增数据源 + /// 父节点号 + public void DragAddTable(DataTable dataTable, string Pid) + { + try + { + if (dataTable == null || dataTable.Rows.Count < 1) return; + + WaitForm.ShowForm(ResourceKeys.Handing); + //父节点名称 + string ParentFieldName = (this.gcMain as TreeGridControlEx).TreeListObj.ParentFieldName; + //节点名称 + string KeyFieldName = (this.gcMain as TreeGridControlEx).TreeListObj.KeyFieldName; + //主表明细结构 + DataTable TreeTable = ((this.gcMain as TreeGridControlEx).TreeListObj.DataSource as DataTable).Clone(); + //明细表数据 + TreeListColumnCollection gridColumns = (this.gcMain as TreeGridControlEx).TreeListObj.Columns; + //可以添加的行节点id + List nodeId = new List(); + + //数据源的id和pid全部加上目标节点(加上后当前数据源就是目标节点的子节点数据源) + if (dataTable.Columns.Contains(ParentFieldName) && dataTable.Columns.Contains(KeyFieldName)) + { + //当前树表格中最大的id号 + int NodeId = int.Parse((this.gcMain as TreeGridControlEx).GetNewNodesId()) - 1; + //当前树表格中如果id为bull,要赋值的id值(节点id不能为null) + int NewNodeId = int.Parse((this.gcMain as TreeGridControlEx).GetNewNodesId()); + + //根据当前的节点号,改变新增数据源中的节点号 + foreach (DataRow rowItem in dataTable.Rows) + { + // 新增表格中的数据id全部加上最大id号,如果是空就默认去赋最大id+1的值 + if (!string.IsNullOrWhiteSpace(rowItem[KeyFieldName] + "")) + { + rowItem[KeyFieldName] = int.Parse(rowItem[KeyFieldName] + "") + NodeId; + } + else + { + rowItem[KeyFieldName] = NewNodeId; + NewNodeId++; + } + + //pid为0或者null的改成目标节点的节点号,有值的默认加上最大id值 + if (string.IsNullOrWhiteSpace(rowItem[ParentFieldName] + "") || int.Parse(rowItem[ParentFieldName] + "") == 0) + { + rowItem[ParentFieldName] = Pid; + + } + else if (int.Parse(rowItem[ParentFieldName] + "") > 0) + { + rowItem[ParentFieldName] = int.Parse(rowItem[ParentFieldName] + "") + NodeId; + } + + DataRow newRow = TreeTable.NewRow(); + newRow.BeginEdit(); + // 赋值明细字段 + foreach (TreeListColumn col in gridColumns) + { + try + { + GridColumnModel model = col.Tag as GridColumnModel; + if (dataTable.Columns.Contains(col.FieldName)) + { + // 来源列中是否包含对应字段,包含则使用值 + newRow[col.FieldName] = rowItem[col.FieldName]; + if (!string.IsNullOrEmpty(model.UnionFields)) + { + this.SetUnionValue(model, rowItem[col.FieldName] + "", newRow); + } + SetCalcValue(model, rowItem[col.FieldName] + "", newRow); + } + else + { + // 未包含字段,则使用控件默认值. + if (col.FieldName.Contains("_Ls")) + { + string[] unioFielName = col.FieldName.Split('_'); + string UnioValue = unioFielName[unioFielName.Length - 1]; + DataColumn grid = dataTable.Columns.Cast().FirstOrDefault(x => x.ColumnName.Split('_')[x.ColumnName.Split('_').Length - 1].Equals(UnioValue)); + if (grid != null && !string.IsNullOrEmpty(model.UnionFields)) + { + this.SetUnionValue(model, rowItem[col.FieldName] + "", newRow); + } + SetCalcValue(model, rowItem[col.FieldName] + "", newRow); + + } + else + { + string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue); + + if (model.DefaultValue.Contains("{#")) + { + fieldValue = this.ControlObj.ReplaceParentControlValue(model.DefaultValue); + if (!string.IsNullOrEmpty(fieldValue)) + { + newRow[col.FieldName] = fieldValue; + if (!string.IsNullOrEmpty(model.UnionFields)) + { + this.SetUnionValue(model, fieldValue + "", newRow); + } + SetCalcValue(model, fieldValue + "", newRow); + + //计算规则配置在结果字段上,所以无需验证当前操作控件 + //this.gcMain.GridView.SetFocusedRowCellValue(col, fieldValue); + } + } + else if (!string.IsNullOrEmpty(model.DefaultValue)) + { + newRow[col.FieldName] = fieldValue; + if (!string.IsNullOrEmpty(model.UnionFields)) + { + this.SetUnionValue(model, fieldValue + "", newRow); + } + SetCalcValue(model, fieldValue + "", newRow); + + } + } + } + SetDisableColumn(model, newRow[col.FieldName] + "", newRow); + } + catch (Exception ex) + { + LogHelper.Instance.WriteError(ex); + } + } + + newRow.EndEdit(); + TreeTable.Rows.Add(newRow); + } + //(this.gcMain as TreeGridControlEx).SetGridViewDataSourceGenerateID(TreeTable); + //添加到主表明细中 + while (TreeTable.Rows.Count != nodeId.Count) + { + foreach (DataRow item in TreeTable.Rows) + { + //是一级节点或者父节点已经添加了的数据,会添加到明细表中 + if ((Pid.Equals(item[ParentFieldName] + "") || nodeId.Contains(item[ParentFieldName] + "")) && !nodeId.Contains(item[KeyFieldName] + "")) + { + nodeId.Add(item[KeyFieldName] + ""); + //添加到主表明细中 + this.AddMultiRowTreeGridControl(new DataRow[] { item }, item[ParentFieldName] + ""); + } + } + } + //排序 + (this.gcMain as TreeGridControlEx).DataSourceSorting(); + + } + } + catch (Exception ex) + { + string Message = ErrorMessage.PromptErrorMessage(ex); + MessageUtil.Show(Message, ex.Message); + } + finally + { + WaitForm.HideForm(); + } + + } + + /// + /// 说明:添加多条数据到单据明细 + /// 创建人:龚宇超 + /// 创建日期:2017-11-30 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + private void AddMultiRowTreeGridControl(DataRow[] rowItems, string Pid) + { + this.isDragWrap = false;//用于设置拖拽时不允许扫码控件换行 + bool onlyOne = true; + + foreach (DataRow rowItem in rowItems) + { + // 检查当前记录是否满足条件 + + this.AddRowToTreeGridControl(rowItem, Pid); + if (!string.IsNullOrWhiteSpace(this.BillModel.ChangeColColor)) + { + if (rowItem.Table.Columns.Contains(this.BillModel.ChangeColColor)) + { + rowItem[this.BillModel.ChangeColColor] = "1"; + } + } + } + this.isDragWrap = true;//用于设置拖拽时不允许扫码控件换行 + + } + + /// + /// 说明:添加行到单据明细中 + /// 创建人:龚宇超 + /// 创建日期:2017-11-30 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The row item. + /// The union model. + private void AddRowToTreeGridControl(DataRow rowItem, string Pid) + { + TreeListColumnCollection gridColumns = (this.gcMain as TreeGridControlEx).TreeListObj.Columns; + DataTable gridTable = ((this.gcMain as TreeGridControlEx).TreeListObj.DataSource as DataTable).TrimDeleteRows(); + if (!gridTable.Columns.Contains(ERPInfo.Instance.isAddRows)) + { + gridTable.Columns.Add(ERPInfo.Instance.isAddRows, typeof(String)); + } + string repeatProduct = (this.gcMain as TreeGridControlEx).TreeListObj.Columns["ProductId"] != null && rowItem.Table.Columns.Contains("ProductId") ? "ProductId" : this.BillModel.DetailPreFix + "ProductId"; + AssociatedField = repeatProduct; + if ("1".Equals(this.BillModel.DetailDoubleClickTip) && rowItem.Table.Columns.Contains(repeatProduct)) + { + // 需要提示编码重复 + DataTable dt = (this.gcMain as TreeGridControlEx).TreeListObj.DataSource as DataTable; + if (dt != null && dt.Rows.Count > 0 && dt.Columns.Contains(repeatProduct)) + { + DataRow[] drs = dt.Select(repeatProduct + "='" + rowItem[repeatProduct] + "'"); + if (drs.Length >= 1) + { + DialogResult dialog = MessageUtil.Show(ResourceKeys.ProductIsRepet, MessageBoxButtons.YesNo); + if (dialog != DialogResult.Yes) + return; + } + } + } + DataRow newRow = gridTable.NewRow(); + //2024-1-29改成>=,之前为>导致选中第一行只会添加到最后一行(测试空白行没有影响) + int position = this.gcMain.GridView.FocusedRowHandle >= 0 ? gridTable.Rows.Count > 0 ? this.gcMain.GridView.FocusedRowHandle : 0 : gridTable.Rows.Count - 1; + + + + (this.gcMain as TreeGridControlEx).TreeListObj.BeginUpdate(); + GridView gridView = this.gcMain.GridView; + // 赋值明细字段 + foreach (TreeListColumn col in gridColumns) + { + try + { + // 未包含字段,则使用控件默认值. + GridColumnModel model = col.Tag as GridColumnModel; + + if (rowItem.Table.Columns.Contains(col.FieldName)) + { + // 来源列中是否包含对应字段,包含则使用值 + newRow[col.FieldName] = rowItem[col.FieldName]; + if (!string.IsNullOrEmpty(model.UnionFields)) + { + this.SetUnionValue(model, rowItem[col.FieldName] + "", newRow); + } + SetCalcValue(model, rowItem[col.FieldName] + "", newRow); + } + else + { + + if (col.FieldName.Contains("_Ls")) + { + string[] unioFielName = col.FieldName.Split('_'); + string UnioValue = unioFielName[unioFielName.Length - 1]; + DataColumn grid = rowItem.Table.Columns.Cast().FirstOrDefault(x => x.ColumnName.Split('_')[x.ColumnName.Split('_').Length - 1].Equals(UnioValue)); + if (grid != null && !string.IsNullOrEmpty(model.UnionFields)) + { + this.SetUnionValue(model, rowItem[col.FieldName] + "", newRow); + } + SetCalcValue(model, rowItem[col.FieldName] + "", newRow); + } + else + { + string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue); + + if (model.DefaultValue.Contains("{#")) + { + fieldValue = this.ControlObj.ReplaceParentControlValue(model.DefaultValue); + if (!string.IsNullOrEmpty(fieldValue)) + { + newRow[col.FieldName] = fieldValue; + if (!string.IsNullOrEmpty(model.UnionFields)) + { + this.SetUnionValue(model, fieldValue + "", newRow); + } + SetCalcValue(model, fieldValue + "", newRow); + } + } + else if (!string.IsNullOrEmpty(model.DefaultValue)) + { + newRow[col.FieldName] = fieldValue; + if (!string.IsNullOrEmpty(model.UnionFields)) + { + this.SetUnionValue(model, fieldValue + "", newRow); + } + SetCalcValue(model, fieldValue + "", newRow); + } + } + } + SetDisableColumn(model, newRow[col.FieldName] + "", newRow); + if (model.LimitLength > 0) + { + DataRow HandleRow = newRow; + int MaxInputLength = System.Text.Encoding.Default.GetBytes(newRow[col.FieldName] + "").Length; + if (model.LimitLength < MaxInputLength) + HandleRow.SetColumnError(HandleRow.Table.Columns[col.ColumnHandle], "当前输入文本超过设定长度!");//满足条件设置错误信息 + } + } + catch (Exception ex) + { + LogHelper.Instance.WriteError(ex); + } + } + (this.gcMain as TreeGridControlEx).TreeListObj.EndUpdate(); + if (string.IsNullOrWhiteSpace(newRow[(this.gcMain as TreeGridControlEx).TreeListObj.KeyFieldName] + "")) + { + newRow[(this.gcMain as TreeGridControlEx).TreeListObj.KeyFieldName] = (this.gcMain as TreeGridControlEx).GetNewNodesId();//节点id为空,就默认给当前数据源最大id+1 + } + + if (!string.IsNullOrWhiteSpace(Pid)) + { + newRow[(this.gcMain as TreeGridControlEx).TreeListObj.ParentFieldName] = Pid;//拖拽到目标节点的id + } + // 添加数据行 + gridTable.Rows.Add(newRow); + + + if (!string.IsNullOrEmpty(NumberMc) && gridTable.Columns.Contains(mRecordPrimaryField)) + { + DataRow[] rt = gridTable.Rows.Cast().Where(x => (newRow[BillModel.DetailPreFix + "ProductId"] + "").Equals(x[BillModel.DetailPreFix + "ProductId"] + "") && !string.IsNullOrEmpty(x[mRecordPrimaryField] + "")).ToArray(); + foreach (DataRow item in rt) + { + if (newRow != null) + { + newRow[NumberMc] = Convert.ToDouble(newRow[NumberMc]) - Convert.ToDouble(item[NumberMc]); + } + //this.gcMain.OnGridViewCellValueChanged(this.gcMain, new CellValueChangedEventArgs(position + 1, this.gcMain.GridView.Columns[NumberMc], newRow[NumberMc] + "")); + //this.gcMain.GridView.UpdateCurrentRow(); + //this.gcMain.GridView.ShowEditor(); + if (Convert.ToDouble(newRow[NumberMc] + "") == 0.0) + { + gridTable.Rows.Remove(newRow); + MessageUtil.Show("数量已分配完毕!无需再进行拖拽!"); + } + } + } + //gridTable.OrderBy(this.BillModel.DetailOrderField); + //设置排序列的值 + (this.gcMain as TreeGridControlEx).DataSourceSorting(); + } + + + /// + /// 说明:添加多行到单据明细中 + /// 创建人:龚宇超 + /// 创建日期:2017-11-30 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The row item. + /// The union model. + private void AddRowsToTreeGridControl(DataTable dataTable, BillSourceUnionModel unionModel) + { + WaitForm.ShowForm(); + TreeListColumnCollection gridColumns = (this.gcMain as TreeGridControlEx).TreeListObj.Columns; + DataTable gridTable = ((this.gcMain as TreeGridControlEx).TreeListObj.DataSource as DataTable).TrimDeleteRows().Copy(); + + if (!gridTable.Columns.Contains(ERPInfo.Instance.isAddRows)) + { + gridTable.Columns.Add(ERPInfo.Instance.isAddRows, typeof(String)); + } + + TreeListNode treeNode = (this.gcMain as TreeGridControlEx).TreeListObj.FocusedNode as TreeListNode; + int position = 0; + if (treeNode != null) position = treeNode.Id; + + + //bool isLastRow = this.gcMain.GridView.IsLastVisibleRow; + + + + bool onlyOne = true; + foreach (DataRow rowItem in dataTable.Rows) + { + if (unionModel == null || ValidateDetailCond(rowItem, unionModel)) + { + + string repeatProduct = (this.gcMain as TreeGridControlEx).TreeListObj.Columns["ProductId"] != null && rowItem.Table.Columns.Contains("ProductId") ? "ProductId" : this.BillModel.DetailPreFix + "ProductId"; + AssociatedField = repeatProduct; + + if ("1".Equals(this.BillModel.DetailDoubleClickTip) && gridColumns[repeatProduct] != null && dataTable.Columns.Contains(repeatProduct)) + { + //上面方法无法处理大小写,改成搜索的形式 + DataTable dt = (this.gcMain as TreeGridControlEx).TreeListObj.DataSource as DataTable; + if (dt != null && dt.Rows.Count > 0 && dt.Columns.Contains(repeatProduct)) + { + DataRow[] drs = dt.Select(repeatProduct + "='" + rowItem[repeatProduct] + "'"); + if (drs.Length >= 1) + { + DialogResult dialog = MessageUtil.Show(ResourceKeys.ProductIsRepet, MessageBoxButtons.YesNo); + if (dialog != DialogResult.Yes) + return; + } + } + + } + + DataRow newRow = gridTable.NewRow(); + newRow.BeginEdit(); + // 赋值明细字段 + foreach (TreeListColumn col in gridColumns) + { + try + { + GridColumnModel model = col.Tag as GridColumnModel; + if (dataTable.Columns.Contains(col.FieldName)) + { + // 来源列中是否包含对应字段,包含则使用值 + newRow[col.FieldName] = rowItem[col.FieldName]; + if (!string.IsNullOrEmpty(model.UnionFields)) + { + this.SetUnionValue(model, rowItem[col.FieldName] + "", newRow); + } + SetCalcValue(model, rowItem[col.FieldName] + "", newRow); + } + else + { + // 未包含字段,则使用控件默认值. + if (col.FieldName.Contains("_Ls")) + { + string[] unioFielName = col.FieldName.Split('_'); + string UnioValue = unioFielName[unioFielName.Length - 1]; + DataColumn grid = dataTable.Columns.Cast().FirstOrDefault(x => x.ColumnName.Split('_')[x.ColumnName.Split('_').Length - 1].Equals(UnioValue)); + if (grid != null && !string.IsNullOrEmpty(model.UnionFields)) + { + this.SetUnionValue(model, rowItem[col.FieldName] + "", newRow); + } + SetCalcValue(model, rowItem[col.FieldName] + "", newRow); + + } + else + { + string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue); + + if (model.DefaultValue.Contains("{#")) + { + fieldValue = this.ControlObj.ReplaceParentControlValue(model.DefaultValue); + if (!string.IsNullOrEmpty(fieldValue)) + { + newRow[col.FieldName] = fieldValue; + if (!string.IsNullOrEmpty(model.UnionFields)) + { + this.SetUnionValue(model, fieldValue + "", newRow); + } + SetCalcValue(model, fieldValue + "", newRow); + + //计算规则配置在结果字段上,所以无需验证当前操作控件 + //this.gcMain.GridView.SetFocusedRowCellValue(col, fieldValue); + } + } + else if (!string.IsNullOrEmpty(model.DefaultValue)) + { + newRow[col.FieldName] = fieldValue; + if (!string.IsNullOrEmpty(model.UnionFields)) + { + this.SetUnionValue(model, fieldValue + "", newRow); + } + SetCalcValue(model, fieldValue + "", newRow); + + } + } + } + SetDisableColumn(model, newRow[col.FieldName] + "", newRow); + } + catch (Exception ex) + { + LogHelper.Instance.WriteError(ex); + } + } + // newRow[(this.gcMain as TreeGridControlEx).TreeListObj.KeyFieldName] = (this.gcMain as TreeGridControlEx).GetNewNodesId();//节点id + newRow.EndEdit(); + gridTable.Rows.Add(newRow); + + position++; + + if (!string.IsNullOrEmpty(NumberMc) && gridTable.Columns.Contains(mRecordPrimaryField)) + { + DataRow[] rt = gridTable.Rows.Cast().Where(x => (newRow[BillModel.DetailPreFix + "ProductId"] + "").Equals(x[BillModel.DetailPreFix + "ProductId"] + "") && !string.IsNullOrEmpty(x[mRecordPrimaryField] + "")).ToArray(); + foreach (DataRow item in rt) + { + if (newRow != null) + { + newRow[NumberMc] = Convert.ToDouble(newRow[NumberMc]) - Convert.ToDouble(item[NumberMc]); + } + //(this.gcMain as TreeGridControlEx).GcMain_CellValueChanged(this.gcMain as TreeGridControlEx, new CellValueChangedEventArgs(position, this.gcMain.GridView.Columns[NumberMc], newRow[NumberMc] + "")); + //this.gcMain.GridView.UpdateCurrentRow(); + //this.gcMain.GridView.ShowEditor(); + if (Convert.ToDouble(newRow[NumberMc] + "") == 0.0) + { + gridTable.Rows.Remove(newRow); + MessageUtil.Show("数量已分配完毕!无需再进行拖拽!"); + } + } + } + } + else + { + if (onlyOne) + { + onlyOne = false; + if (!string.IsNullOrEmpty(unionModel.ModelObj.DetailEnableMsg)) + { + if (unionModel.ModelObj.DetailEnableMsg.StartsWith("select", StringComparison.OrdinalIgnoreCase) || + unionModel.ModelObj.DetailEnableMsg.StartsWith("exec", StringComparison.OrdinalIgnoreCase)) + { + MessageUtil.Show(BaseImpl.GetResult(unionModel.ModelObj.DetailEnableMsg) + ""); + } + else + { + MessageUtil.Show(unionModel.ModelObj.DetailEnableMsg); + } + } + } + } + } + (this.gcMain as TreeGridControlEx).SetGridViewDataSourceGenerateID(gridTable); + //this.gcMain.GridControl.DataSource = gridTable; + //if (position >= 0) + // this.gcMain.GridView.SelectRowHandler(position); + //else + // this.gcMain.GridView.SelectRowHandler(gridTable.Rows.Count - 1); + + //gridTable.OrderBy(this.BillModel.DetailOrderField); + //this.gcMain.GridView.UpdateCurrentRow(); + //this.gcMain.GridView.ShowEditor(); + gridTable.OrderBy(this.BillModel.DetailOrderField); + (this.gcMain as TreeGridControlEx).DataSourceSorting(); + WaitForm.HideForm(); + } + + + + + + /// + /// 说明:是否允许添加明细 + /// 创建人:龚宇超 + /// 创建日期:2018-06-06 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// true if this instance [can add detail row]; otherwise, false. + private bool CanAddTreeDetailRow() + { + // 检测是否正在筛选数据 + if (!string.IsNullOrEmpty((this.gcMain as TreeGridControlEx).TreeListObj.FindFilterText.Trim()) || + !string.IsNullOrEmpty((this.gcMain as TreeGridControlEx).TreeListObj.FilterPanelText.Trim())) + { + if (MessageUtil.Show(ResourceKeys.GridViewSearching, MessageBoxButtons.YesNo) == DialogResult.Yes) + { + (this.gcMain as TreeGridControlEx).TreeListObj.FindFilterText = ""; + return true; + } + return false; + } + // 检测是否点击了排序表格 + if ((this.gcMain as TreeGridControlEx).IsColumnSorted()) + { + (this.gcMain as TreeGridControlEx).ClearAllSort(); + } + // 检测是否为提交或者终审模块 + if (_waterMark.Text.Contains("已终审")) + { + MessageUtil.Show(ResourceKeys.AddBillDetailed); + return false; + } + return true; + } + + + /// + /// 说明:检查可用条件 + /// 创建人:龚宇超 + /// 创建日期:2017-11-09 + /// 修改人: + /// 修改日期: + /// 修改备注: + /// 版本:1.0 + /// + /// The cond. + /// The data row. + /// true if XXXX, false otherwise. + private bool ValidateCond(string cond, DataRow dataRow) + { + bool result = false; + string condition = cond; + try + { + if (string.IsNullOrWhiteSpace(cond)) return true;//如果值是空格或者空行,默认正确 + cond = ReplaceHelper.ReplaceRowParam(dataRow, cond); + if (cond.StartsWith("@") || cond.StartsWith("!")) + { + result = "1".Equals(BaseImpl.GetDefaultValue(cond)); + } + else if (dataRow == null) + { + result = ReplaceHelper.EvalCond(cond); + } + else + { + result = ReplaceHelper.ReplaceRowParamCond(dataRow, cond); + } + return result; + } + catch (Exception ex) + { + + } + return result; + } + + + /// + /// 页签里数据修改后刷新主表和主表明细 + /// + /// + /// + private void Tab_OnDetailSaveGridCallBack(object sender, EventArgs e) + { + try + { + this.SetBillStatus(BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, this.lblOrderNo.Text))); + } + catch (Exception ex) + { + string Message = ErrorMessage.PromptErrorMessage(ex); + MessageUtil.Show(Message, ex.Message); + } + } + + + + /// + /// 扫码回车事件 + /// + /// + /// + private void Text_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Enter) + { + TextEdit textEdit = sender as TextEdit; + string inputText = textEdit.Text; + if (!string.IsNullOrWhiteSpace(this.BillModel.CodeExecuteSql) && !string.IsNullOrWhiteSpace(this.BillModel.CodeExecuteParameter)) + { + if (inputText.Length > 50) + { + MessageUtil.Show("扫码长度过长,请重新扫码"); + return; + } + + //获取选中行 + DataRow MainRowItem = gcMain.GridView.GetFocusedDataRow(); + if (MainRowItem == null) + { + MainRowItem = gcMain.GridControl.DataSourceTable().NewRow(); + } + //获取红蓝单据 + string DocumentColor = this.rdBlue.Checked ? "0" : this.rdRed.Checked ? "1" : ""; + //数量,默认为1 + int Quantity = 1; + /* + A:弹框输入数量 + B;不弹框,默认数量为1 + C:配置了扫码关联模块,根据数量sql结果。判断是否弹窗。数量默认为1 + + this.BillModel.ScanCodeFixedPrefix为条码前缀,扫码内容前缀和配置相同,默认为B + */ + string Type = string.Empty; + if (!string.IsNullOrWhiteSpace(this.BillModel.ScanCodeFixedPrefix) && inputText.StartsWith(this.BillModel.ScanCodeFixedPrefix)) + { + Type = "B"; + } + else + { + string Sql = string.Format("select line_str from wms_ScanCodeLinetab a where modid='{0}' and hl_tig='{1}'", this.SysModel.ModuleCode, DocumentColor); + Type = SqlHelper.ExecuteScalar(Sql) + ""; + if (string.IsNullOrWhiteSpace(Type)) + { + MessageUtil.Show("扫码配置错误,请联系朗速服务人员"); + return; + } + } + switch (Type.ToUpper()) + { + case "A": + + FrmAdd frmAdd = new FrmAdd(); + if (frmAdd.ShowDialog() == DialogResult.OK) + { + Quantity = frmAdd.Quantity; + } + else + { + textEdit.EditValue = ""; + textEdit.Focus(); + return; + } + this.ExecuteWcanningSQL(MainRowItem, Quantity + "", DocumentColor, inputText); + break; + case "B": + this.ExecuteWcanningSQL(MainRowItem, Quantity + "", DocumentColor, inputText); + break; + case "C": + if (!string.IsNullOrWhiteSpace(this.BillModel.ScanCodeModuleCode)) + { + //根据传入的模块号获取模块信息 + DataRow modelRow = MainImpl.GetSystemdllTab(this.BillModel.ScanCodeModuleCode);//获取模块信息 + if (modelRow == null) + { + MessageUtil.Show("模块编号[" + this.BillModel.ScanCodeModuleCode + "],配置错误!\r\n该模块信息未找到!"); + return; + } + if (modelRow.Table.Columns.Contains("countSql") && !string.IsNullOrWhiteSpace(modelRow["countSql"] + "")) + { + string sql = modelRow["countSql"] + ""; + sql = ReplaceHelper.ReplaceUserInfo(sql); + sql = ReplaceHelper.ReplaceParamToValue(sql, "{value}", inputText); + string num = SqlHelper.ExecuteScalar(sql) + ""; + num = this.IsNumberic(num) ? num : "0"; + if (int.Parse(num) == 0) + { + MessageUtil.Show("未检测到扫码信息存在,请检查相应前序业务!"); + } + else if (int.Parse(num) == 1) + { + this.ExecuteWcanningSQL(MainRowItem, Quantity + "", DocumentColor, inputText); + } + else if (int.Parse(num) > 1) + { + FrmScanCodeAssociation frmScanCodeAssociation = new FrmScanCodeAssociation(modelRow, inputText); + if (frmScanCodeAssociation.ShowDialog() == DialogResult.OK) + { + string Codes = frmScanCodeAssociation.StringCodes; + this.ExecuteWcanningSQL(MainRowItem, Quantity + "", DocumentColor, Codes); + } + else + { + textEdit.EditValue = ""; + textEdit.Focus(); + return; + } + } + } + } + else + { + MessageUtil.Show("扫码配置错误"); + return; + } + break; + + } + } + + textEdit.EditValue = ""; + textEdit.Focus(); + } + } + + + /// + /// 执行扫码的存储过程 + /// + /// 明细选中行 + ///数量 + ///红蓝单据字段 + ///串码,多个用;隔开 + public void ExecuteWcanningSQL(DataRow MainRowItem, string Quantity, string DocumentColor, string Codes) + { + int j = 0; + foreach (string code in Codes.TrimEnd(';').Split(';')) + { + if (string.IsNullOrWhiteSpace(code)) continue; + List Parameter = this.BillModel.CodeExecuteParameter.Split(',').ToList(); + for (int i = 0; i < Parameter.Count; i++) + { + string item = Parameter[i]; + if (item.Contains("{DocumentColor}")) + { + item = ReplaceHelper.ReplaceParamToValue(item, "{DocumentColor}", DocumentColor); + } + if (item.Contains("{amount}")) + { + item = Quantity + ""; + } + //替换单据号 + item = ReplaceHelper.ReplaceParamToValue(item, "{" + this.BillModel.PrimaryKey + "}", this.lblOrderNo.Text); + //替换选中行(没有就传空) + item = ReplaceHelper.ReplaceRowParam(MainRowItem, item); + //替换扫码内容 + item = ReplaceHelper.ReplaceParamToValue(item, "{value}", code); + Parameter[i] = item; + } + + + List procParams = ReplaceHelper.GetParamFields(this.BillModel.CodeExecuteSql); + List sqlParamList = new List(); + string[] paramStr = procParams[0].Replace("{", "").Replace("}", "").Split(','); + SqlParameter pMsg = new SqlParameter("@msg", SqlDbType.VarChar, 2000); + + for (int i = 0; i < paramStr.Length; i++) + { + string item = paramStr[i]; + if (paramStr[i].Equals("@msg", StringComparison.OrdinalIgnoreCase)) + { + pMsg.Direction = ParameterDirection.InputOutput; + pMsg.Value = Parameter.Count > i ? string.IsNullOrEmpty(Parameter[i]) ? "" : Parameter[i] : ""; + sqlParamList.Add(pMsg); + } + else + { + string paramStr1 = paramStr[i]; + SqlParameter param = new SqlParameter(string.Format("{0}", paramStr1), SqlDbType.VarChar); + param.Value = Parameter[i]; + sqlParamList.Add(param); + } + } + SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int, 4); + returnValue.Direction = ParameterDirection.ReturnValue; + int result; + sqlParamList.Add(returnValue); + + try + { + result = MainImpl.ExecProcedure(this.BillModel.CodeExecuteSql.Replace(procParams[0], "").Trim(), sqlParamList.ToArray()); + } + catch (SqlException sex) + { + string Message = ErrorMessage.PromptErrorMessage(sex); + MessageUtil.Show(Message, sex.Message); + return; + } + catch (Exception ex) + { + string Message = ErrorMessage.PromptErrorMessage(ex); + MessageUtil.Show(Message, ex.Message); + return; + } + int rValue = Convert.ToInt32(returnValue.Value); + string varchar = pMsg.Value + ""; + switch (rValue) + { + case 1: + if (string.IsNullOrWhiteSpace(varchar)) + { + //刷新当前单据 + if (j == Codes.TrimEnd(';').Split(';').Length - 1) + { + this.SetBillStatus(BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, this.lblOrderNo.Text))); + } + + } + else + { + //刷新返回的单据号 + this.lblOrderNo.Text = varchar; + this.SetBillStatus(BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, varchar))); + } + break; + case -1: + MessageUtil.Show(ResourceKeys.OperFault + "\n" + pMsg.Value); + break; + } + j++; + } + } + + + + + /// + /// 设置辅助功能按钮状态 + /// + /// + public void SetButtonStatus(DataRow rowItem = null) + { + foreach (System.Windows.Forms.Control control in pl_buttom.Controls) + { + if (control is SimpleButton) + { + SimpleButton button = control as SimpleButton; + DataRow dr = button.Tag as DataRow; + if (dr != null && dr.Table.Columns.Contains("menuCond")) + { + string menuCond = dr["menuCond"] + ""; + if (!string.IsNullOrWhiteSpace(menuCond) && rowItem == null) + { + //menuCond = "'{wms_louts_Billdocument_Id}'<>''"; + menuCond = ReplaceHelper.ReplaceParamToValue(menuCond, "{" + this.BillModel.PrimaryKey + "}", this.lblOrderNo.Text); + } + button.Enabled = ValidateCond(menuCond, rowItem); + //button.Enabled = true; + } + } + + } + } + + /// + /// 设置控件边距 + /// + /// + /// + public DataTable SetControlMargins(DataTable dataTable) + { + int minLeft = int.MaxValue; + int maxRightEdge = 0; + + // 检查 DataTable 是否为空且包含所需列 + if (dataTable != null && dataTable.Rows.Count > 0 && + dataTable.Columns.Contains("controlLeft") && + dataTable.Columns.Contains("controlWidth")) + { + foreach (DataRow row in dataTable.Rows) + { + // 尝试解析 controlLeft 和 controlWidth + if (int.TryParse(row["controlLeft"].ToString(), out int left) && + int.TryParse(row["controlWidth"].ToString(), out int width)) + { + if (left < minLeft) + { + minLeft = left; + } + int rightEdge = left + width; + if (rightEdge > maxRightEdge) + { + maxRightEdge = rightEdge; + } + } + } + } + if (minLeft == int.MaxValue) minLeft = 0; + + + int MovingDistance = (Screen.PrimaryScreen.WorkingArea.Width - maxRightEdge) / 2; + + if (dataTable.Columns.Contains("controlLeft") && MovingDistance > 0) + { + foreach (DataRow item in dataTable.Rows) + { + item["controlLeft"] = int.Parse(item["controlLeft"] + "") + MovingDistance - minLeft; + + } + } + return dataTable; + } + + + /// + /// 判断是不是数值 + /// + /// + /// + private bool IsNumberic(string oText) + { + try + { + int var1 = Convert.ToInt32(oText); + return true; + } + catch + { + return false; + } + } + } +} diff --git a/插件库/Lskj.QueryEssentialInfo/QueryApiUtil.cs b/插件库/Lskj.QueryEssentialInfo/QueryApiUtil.cs index 6f01704..572044c 100644 --- a/插件库/Lskj.QueryEssentialInfo/QueryApiUtil.cs +++ b/插件库/Lskj.QueryEssentialInfo/QueryApiUtil.cs @@ -438,6 +438,11 @@ namespace Lskj.QueryEssentialInfo { bizDataJObject.Add("taxRelatedMatters", detailRow.Table.Columns.Contains("taxRelatedMatters") ? detailRow["taxRelatedMatters"] + "" : ""); } + string dimissionDate = detailRow.Table.Columns.Contains("employedDate") ? detailRow["employedDate"] + "" : ""; + if (!string.IsNullOrEmpty(dimissionDate)) + { + bizDataJObject.Add("dimissionDate", dimissionDate); + } bizDataJObject.Add("phoneNumber", detailRow.Table.Columns.Contains("phoneNumber") ? detailRow["phoneNumber"] + "" : ""); bizDataJObject.Add("isDeductExpense", detailRow.Table.Columns.Contains("isDeductExpense") ? detailRow["isDeductExpense"] + "" : ""); bizlistJArray.Add(bizDataJObject);