using DevExpress.Utils; using DevExpress.XtraEditors; using DevExpress.XtraTab; using Lskj.Business; using Lskj.Business.Impl; using Lskj.Control; using Lskj.Control.Model; using Lskj.Core; using Lskj.Data; using Lskj.Model; using Lskj.Util; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Lskj.PubVoucherPush { public partial class FrmMain : BaseForm { /// /// 模块类 /// public DynamicVoucher SysModel; /// /// 主程序的基础模型 /// public ModuleModel MoudleMainObj; /// /// 右键参数 /// public MyControl rightControl; /// /// 右侧表格行中的模块号,和对应的左侧页签号 /// public Dictionary TabInformation = new Dictionary(); /// /// 主键 /// public string ParmaryKey; /// /// 开始日期 /// public DateTime StartDate { get { return new DateTime(zdrq.TextEdit.DateTime.Year, zdrq.TextEdit.DateTime.Month, 1); } } /// /// 结束日期 /// public DateTime EndDate { get { return new DateTime(zdrq.TextEdit.DateTime.Year, zdrq.TextEdit.DateTime.Month, 1).AddMonths(1).AddDays(-1); } } public FrmMain() { InitializeComponent(); } /// /// 说明:窗口初始化 /// 创建人:龚宇超 /// 创建日期:2017-11-21 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The instance containing the event data. protected override void OnLoad(EventArgs e) { WaitForm.ShowForm(); try { if (SysModel != null) { //隐藏标签 this.xtc_container.ShowTabHeader = DefaultBoolean.False; this.InitializationConditions(); this.InitializeLeftTable(); this.InitSpliterPosition(); this.splitMain.SplitterPositionChanged += SplitMain_SplitterPositionChanged; this.btnCondSearch.Click += BtnCondSearch_Click; this.OnGridLeftRowClick(null, null); } } catch (Exception ex) { //MessageUtil.Show(ex.Message + "\r\n" + ex.StackTrace); string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } finally { Lskj.Control.Model.AutoSizeChange.ControllInitializeSize(this); } WaitForm.HideForm(); } /// /// 初始化上方条件 /// private void InitializationConditions() { DateTime now = DateTime.Now; zdrq.EditText = new DateTime(now.Year, now.Month, 1) + ""; zdrq.TextEdit.Properties.DisplayFormat.FormatString = "yyyy年MM月"; zdrq.TextEdit.Properties.DisplayFormat.FormatType = FormatType.Custom; zdrq.TextEdit.Properties.EditFormat.FormatString = "yyyy年MM月"; zdrq.TextEdit.Properties.EditFormat.FormatType = FormatType.Custom; zdrq.TextEdit.Properties.Mask.EditMask = "yyyy年MM月"; zdrq.TextEdit.Properties.Mask.UseMaskAsDisplayFormat = true; zdrq.TextEdit.Properties.VistaCalendarViewStyle = DevExpress.XtraEditors.VistaCalendarViewStyle.YearView; //右键条件参数 pzz.TextField = "ctext"; pzz.ValueField = "csign"; pzz.ValueMember = "csign"; try { pzz.SetDataSource(SqlHelper.ExecuteDataTable("select * from UFDATA_001_2024.dbo.dsign")); pzz.TextEdit.SelectedIndex = 0; } catch (Exception ex) { } fjs.EditText = "0"; jfkmhb.EditText = "1"; dfkmhb.EditText = "1"; jffmhb.EditText = "1"; dffmhb.EditText = "1"; tbhxls.EditText = "1"; sfxjhd.EditText = "1"; this.rightControl = new MyControl(); rightControl.ParentPanel = pl_top; } /// /// 初始化左侧表 /// private void InitializeLeftTable() { //获得模块属性 this.MoudleMainObj = new ModuleModel(MainImpl.GetSystemdllTab(this.SysModel.ModuleCode));//获取主模块构建类 //获取主键 this.ParmaryKey = BaseImpl.GetBasePrimaryKey(this.SysModel.ModuleCode); //获取设置左侧表列数据 DataTable LeftGridColumns = BaseModuleImpl.GetBaseGridColumns(this.SysModel.ModuleCode); this.gridLeft.SetReadOnlyColumns(LeftGridColumns); DataTable rightMenus = BaseModuleImpl.GetBaseGridRightMenus(this.SysModel.ModuleCode); this.gridLeft.SetGridRightMenus(rightMenus, this.SysModel, OnGridViewRightCallBack, rightControl); this.gridLeft.gridViewRightMenu.AllowRightCallback = true; this.gridLeft.gridViewRightMenu.OnBeforeHandleParamsCallback += OnBeforeHandleParamsCallback; //设置左侧数据源 string menuSql = this.MoudleMainObj.MenuSql.Replace("{year}", StartDate.Year.ToString()).Replace("{month}", StartDate.Month.ToString()); this.gridLeft.gridControl.DataSource = BaseImpl.GetDataTableResult(menuSql); //左侧表格行改变,刷新右侧表格列 this.gridLeft.GridView.RowClick += OnGridLeftRowClick; } /// /// 说明:初始化分割条位置 /// 创建人:龚宇超 /// 创建日期:2017-12-15 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void InitSpliterPosition() { string spliterPosition = IniHelper.Read(string.Format("PubVoucherPush__splitMain{0}", this.SysModel.ModuleCode)); if (!string.IsNullOrEmpty(spliterPosition)) this.splitMain.SplitterPosition = Convert.ToInt32(spliterPosition); } /// /// 说明:拿到底部表格数据 /// 创建人:龚宇超 /// 创建日期:2017-11-21 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// List<GridDetailModel>. private List GetDetails(string mainModuleCode) { List details = new List();//表格明细对象的集合 DataTable table = BaseModuleImpl.GetBaseDetailPages(mainModuleCode);// 根据传入的模块编号获得基础档案底部标签的数据 foreach (DataRow item in table.Rows) { DataTable gridColumns = ReportImpl.GetReportDetailColumns(mainModuleCode, item["id"] + "");//获取报表明细列 details.Add(new GridDetailModel(item, gridColumns, GridCustomColumnStruct.BaseDetailGridView)); } return details; } /// /// 左侧表点击事件 /// /// /// private void OnGridLeftRowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e) { try { DataRow rowItem = this.gridLeft.GetViewFocusedDataRow(); //刷新右侧上方表格列 if (rowItem != null && !string.IsNullOrEmpty(MoudleMainObj.MainModuleCodeField) && this.gridLeft.GridView.Columns.ColumnByFieldName(MoudleMainObj.MainModuleCodeField) != null) { string mainModuleCode = rowItem[MoudleMainObj.MainModuleCodeField] + ""; int value = 0; if (TabInformation.TryGetValue(mainModuleCode, out value)) { //页签中已经存在,直接切换页签 this.xtc_container.SelectedTabPageIndex = value; } else { //添加新页签 GridControlEx sendGridEx = new GridControlEx(); sendGridEx.Dock = DockStyle.Fill; //创建新的XtraTabControl XtraTabControl innerTabControl = new XtraTabControl(); innerTabControl.Dock = DockStyle.Fill; //创建"待推送"页签 XtraTabPage tabPageFailed = new XtraTabPage(); tabPageFailed.Text = "待推送"; ModuleGridDetailEx failedGridControlEx = new ModuleGridDetailEx(); // 创建新的GridControlEx实例 failedGridControlEx.Dock = DockStyle.Fill; ModuleModel SysModel = new ModuleModel(MainImpl.GetSystemdllTab(mainModuleCode)); DynamicModel dyncModel = new DynamicModuleModel(new string[] { "待推送", ERPInfo.Instance.UserId, ERPInfo.Instance.UserName, "2", mainModuleCode, "0" }); failedGridControlEx.GridDetailList = GetDetails(mainModuleCode);// 底部多标签表格数据 SysModel.CsHasDefultSearch = false; //failedGridControlEx.ModuleGridObj.SearchObj = rightControl; failedGridControlEx.InitializeControl(SysModel, dyncModel); failedGridControlEx.ModuleGridObj.GridControlObj.gridViewRightMenu.OnBeforeHandleParamsCallback += OnBeforeHandleParamsCallback; failedGridControlEx.ModuleGridObj.VisibleSearchPanel = false; failedGridControlEx.ModuleGridObj.GridControlObj.ParentControl = rightControl; failedGridControlEx.ModuleGridObj.GridControlObj.gridViewRightMenu.SetRightCallback(OnGridViewRightCallBack); failedGridControlEx.ModuleGridObj.GridControlObj.gridViewRightMenu.AllowRightCallback = true; tabPageFailed.Controls.Add(failedGridControlEx); innerTabControl.TabPages.Add(tabPageFailed); tabPageFailed.Tag = failedGridControlEx; //创建"推送成功"页签 XtraTabPage tabPageSuccess = new XtraTabPage(); tabPageSuccess.Text = "推送成功"; DynamicModel dyncModelnew = new DynamicModuleModel(new string[] { "推送成功", ERPInfo.Instance.UserId, ERPInfo.Instance.UserName, "2", mainModuleCode, "0" }); sendGridEx.Model = dyncModelnew; sendGridEx.SetReadOnlyColumns(BaseModuleImpl.GetBaseGridColumns(mainModuleCode)); ModuleModel sendModel = new ModuleModel(MainImpl.GetSystemdllTab(mainModuleCode)); sendGridEx.Tag = sendModel; tabPageSuccess.Controls.Add(sendGridEx); innerTabControl.TabPages.Add(tabPageSuccess); tabPageSuccess.Tag = sendGridEx; //设置上方右键菜单 sendGridEx.ParentControl = rightControl; DataTable rightMenus = BaseModuleImpl.GetBaseGridRightMenus(mainModuleCode); sendGridEx.SetGridRightMenus(rightMenus, this.SysModel, OnGridViewRightCallBack, rightControl); sendGridEx.gridViewRightMenu.AllowRightCallback = true; sendGridEx.gridViewRightMenu.OnBeforeHandleParamsCallback += OnBeforeHandleParamsCallback; //将innerTabControl添加到新的页签中 XtraTabPage page = new XtraTabPage(); page.Tag = innerTabControl; // 将innerTabControl作为Tag page.Dock = DockStyle.Fill; page.Controls.Add(innerTabControl); this.xtc_container.TabPages.Add(page); this.TabInformation.Add(mainModuleCode, this.xtc_container.TabPages.Count - 1); this.xtc_container.SelectedTabPageIndex = this.xtc_container.TabPages.Count - 1; } //刷新右侧 BtnCondSearch(); //this.BtnCondSearch_Click(null, null); } } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } /// /// 右键执行后刷新数据 /// /// /// private void OnGridViewRightCallBack(object sender, EventArgs e) { //BtnCondSearch(); this.BtnCondSearch_Click(null, null); } /// /// 分割条改变时 /// /// /// private void SplitMain_SplitterPositionChanged(object sender, EventArgs e) { IniHelper.Write(string.Format("PubVoucherPush__splitMain{0}", this.SysModel.ModuleCode), this.splitMain.SplitterPosition + ""); } /// /// 搜索按钮点击后刷新当前选中页签的数据源 /// /// /// private void BtnCondSearch_Click(object sender, EventArgs e) { int selectIndex = this.gridLeft.GridView.FocusedRowHandle; string menuSql = this.MoudleMainObj.MenuSql.Replace("{year}", StartDate.Year.ToString()).Replace("{month}", StartDate.Month.ToString()); this.gridLeft.gridControl.DataSource = BaseImpl.GetDataTableResult(menuSql); this.gridLeft.GridView.FocusedRowHandle = selectIndex; BtnCondSearch(); } /// /// 右键参数替换前执行 /// /// /// private void OnBeforeHandleParamsCallback(object sender, HandleParamsArgs e) { string fieldValue = e.FieldValue; string item = e.ParamItem; DataRow detailRow = null; DataRow focusedRow = e.FocusedRow; DataRow leftFocusedRow = this.gridLeft.GridView.GetFocusedDataRow(); DataTable sourceTable = this.gridLeft.GridControl.DataSourceTable(); DataRow[] rowDatas = null; string mainModuleCode = ""; string insertType = ""; string billdocumentField = ""; string operateDateField = ""; if (sourceTable.Rows.IndexOf(e.FocusedRow) >= 0) { leftFocusedRow = e.FocusedRow; mainModuleCode = leftFocusedRow.Table.Columns.Contains("DllCoid") ? leftFocusedRow["DllCoid"] + "" : ""; insertType = leftFocusedRow.Table.Columns.Contains("insertType") ? leftFocusedRow["insertType"] + "" : ""; billdocumentField = leftFocusedRow.Table.Columns.Contains("billdocument_id") ? leftFocusedRow["billdocument_id"] + "" : ""; operateDateField = leftFocusedRow.Table.Columns.Contains("operateDate") ? leftFocusedRow["operateDate"] + "" : ""; if (!string.IsNullOrEmpty(mainModuleCode)) { ModuleModel moduleModel = new ModuleModel(MainImpl.GetSystemdllTab(mainModuleCode)); string TopSql = moduleModel.MenuSql; if (e.paramList[5].Equals("{Operateway}", StringComparison.OrdinalIgnoreCase)) { TopSql = TopSql.Replace("{sdate}", StartDate.ToString("yyyy-MM-dd")).Replace("{edate}", EndDate.ToString("yyyy-MM-dd")); TopSql = ReplaceHelper.ReplaceWhereCond(TopSql) + string.Format(" and (convert(date,convert(varchar(10),pzdate,120))>=convert(date,'{0}')) and (convert(date,convert(varchar(10),pzdate,120))<=convert(date,'{1}') and(ISNULL(issendvoucher,0) = '0' OR (ISNULL(issendvoucher,0) = '1' AND ISNULL(issendsuccess,0) = '0'))) ", StartDate.ToString("yyyy-MM-dd"), EndDate.ToString("yyyy-MM-dd")); DataTable detailTable = BaseImpl.GetDataTableResult(TopSql); rowDatas = detailTable.Select(); } else if (e.paramList[5].Equals("{Operateways}", StringComparison.OrdinalIgnoreCase)) { TopSql = TopSql.Replace("{sdate}", StartDate.ToString("yyyy-MM-dd")).Replace("{edate}", EndDate.ToString("yyyy-MM-dd")); TopSql = ReplaceHelper.ReplaceWhereCond(TopSql) + string.Format(" and (convert(date,convert(varchar(10),pzdate,120))>=convert(date,'{0}')) and (convert(date,convert(varchar(10),pzdate,120))<=convert(date,'{1}') and ISNULL(issendvoucher,0) = '1' and ISNULL(issendsuccess,0) = '1') ", StartDate.ToString("yyyy-MM-dd"), EndDate.ToString("yyyy-MM-dd")); DataTable detailTable = BaseImpl.GetDataTableResult(TopSql); rowDatas = detailTable.Select(); } } } if (rowDatas == null) { rowDatas = e.Rows; } if (rowDatas != null && rowDatas.Length > 0) { detailRow = rowDatas[0]; } if (!string.IsNullOrWhiteSpace(item) && item.Equals("MergeExec_{billdocument_Id}", StringComparison.OrdinalIgnoreCase)) { if (string.IsNullOrEmpty(insertType) || !insertType.Equals("0") || rowDatas == null || rowDatas.Length == 0 || string.IsNullOrEmpty(billdocumentField)) { if (!string.IsNullOrEmpty(insertType) && !insertType.Equals("0")) { fieldValue = ""; } else { fieldValue = item; } } else { fieldValue = ReplaceHelper.ReplaceRowParam(rowDatas, "{" + billdocumentField + "}"); } } else if (!string.IsNullOrWhiteSpace(item) && item.Equals("MergeExec_{operateDate}", StringComparison.OrdinalIgnoreCase)) { if (string.IsNullOrEmpty(insertType) || !insertType.Equals("0") || rowDatas == null || rowDatas.Length == 0 || string.IsNullOrEmpty(operateDateField)) { if (!string.IsNullOrEmpty(insertType) && !insertType.Equals("0")) { fieldValue = ""; } else { fieldValue = item; } } else { fieldValue = ReplaceHelper.ReplaceRowParam(rowDatas, "{" + operateDateField + "}"); } } if (!string.IsNullOrWhiteSpace(item) && item.TrimStart().StartsWith("MergeExec_", StringComparison.OrdinalIgnoreCase)) { fieldValue = ReplaceHelper.ReplaceRowParam(rowDatas, fieldValue.Replace("MergeExec_", "", true)); } else if (item.TrimStart().StartsWith("{vouvher_submitCond}", StringComparison.OrdinalIgnoreCase) && rightControl != null) { string text = ""; if (item.TrimStart().StartsWith("{vouvher_submitCond}_", StringComparison.OrdinalIgnoreCase)) { text = "{StartDate};{EndDate};{pzz};{fjs};{jfkmhb};{jffmhb};{tbhxls};{dfkmhb};{dffmhb};{sfxjhd};{zdrq};{billdocument_id};{issendsuccess};{tabName};1"; } else if (item.TrimStart().StartsWith("{vouvher_submitCond}", StringComparison.OrdinalIgnoreCase)) { if (string.IsNullOrEmpty(insertType) || insertType.Equals("0")) { text = "{StartDate};{EndDate};{pzz};{fjs};{jfkmhb};{jffmhb};{tbhxls};{dfkmhb};{dffmhb};{sfxjhd};{zdrq};{billdocument_id};{issendsuccess};{tabName};0"; } else { text = "{StartDate};{EndDate};{pzz};{fjs};{jfkmhb};{jffmhb};{tbhxls};{dfkmhb};{dffmhb};{sfxjhd};{zdrq};{billdocument_id};{issendsuccess};{tabName};1"; } } System.Windows.Forms.Control controlObj = null; System.Windows.Forms.Control controlGroupBox = rightControl.ParentPanel.Controls.Cast().FirstOrDefault(x => x.Name.Equals("GroupRightData", StringComparison.OrdinalIgnoreCase)); if (controlGroupBox != null) { if (controlGroupBox is GroupBox && controlObj == null) { controlObj = controlGroupBox.Controls.Cast().FirstOrDefault(x => x.Name.Equals("zdrq", StringComparison.OrdinalIgnoreCase)); } } if (controlObj != null && controlObj is LabelDateEdit) { LabelDateEdit zdrqControl = controlObj as LabelDateEdit; DateTime startDateTime = new DateTime(zdrqControl.TextEdit.DateTime.Year, zdrqControl.TextEdit.DateTime.Month, 1); DateTime endDateTime = new DateTime(zdrqControl.TextEdit.DateTime.Year, zdrqControl.TextEdit.DateTime.Month, 1).AddMonths(1).AddDays(-1); fieldValue = text.Replace("{StartDate}", startDateTime.ToString("yyyy-MM-dd")).Replace("{EndDate}", endDateTime.ToString("yyyy-MM-dd")); } fieldValue = rightControl.ReplaceFixedControlValue(fieldValue); } if (leftFocusedRow != null) { fieldValue = ReplaceHelper.ReplaceRowParam(leftFocusedRow, fieldValue); } if (focusedRow != null) { fieldValue = ReplaceHelper.ReplaceRowParam(focusedRow, fieldValue); } if (detailRow != null) { fieldValue = ReplaceHelper.ReplaceRowParam(detailRow, fieldValue); } e.FieldValue = fieldValue; } /// /// 搜索方法 /// /// private void BtnCondSearch() { try { WaitForm.ShowForm(ResourceKeys.Handing); DataRow rowItem = this.gridLeft.GetViewFocusedDataRow(); if (rowItem != null) { //上方 XtraTabPage tabPage = this.xtc_container.SelectedTabPage; if (tabPage.Tag is XtraTabControl) { XtraTabControl innerTabControl = tabPage.Tag as XtraTabControl; foreach (XtraTabPage SelectPage in innerTabControl.TabPages) { if (SelectPage.Tag is GridControlEx) { GridControlEx frmMainModule = SelectPage.Tag as GridControlEx; string TopSql = (frmMainModule.Tag as ModuleModel).MenuSql; TopSql = TopSql.Replace("{sdate}", StartDate.ToString("yyyy-MM-dd")).Replace("{edate}", StartDate.ToString("yyyy-MM-dd")); TopSql = ReplaceHelper.ReplaceWhereCond(TopSql) + string.Format(" and (convert(date,convert(varchar(10),pzdate,120))>=convert(date,'{0}')) and (convert(date,convert(varchar(10),pzdate,120))<=convert(date,'{1}') and ISNULL(issendvoucher,0) = '1' and ISNULL(issendsuccess,0) = '1') ", StartDate.ToString("yyyy-MM-dd"), EndDate.ToString("yyyy-MM-dd")); //TopSql = ReplaceHelper.ReplaceWhereCond(TopSql) + string.Format(" and (convert(date,convert(varchar(10),pzdate,120))>=convert(date,'{0}')) and (convert(date,convert(varchar(10),pzdate,120))<=convert(date,'{1}')) ", StartDate.EditText, EndDate.EditText); frmMainModule.SetGridViewDataSource(SqlHelper.ExecuteDataTable(TopSql)); string CountText = "(" + frmMainModule.DataRowCount() + "条)"; SelectPage.Text = "推送成功" + CountText; } else if (SelectPage.Tag is ModuleGridDetailEx) { ModuleGridDetailEx moduleGridDetailEx = SelectPage.Tag as ModuleGridDetailEx; string TopSql = moduleGridDetailEx.SysModel.MenuSql; TopSql = TopSql.Replace("{sdate}", StartDate.ToString("yyyy-MM-dd")).Replace("{edate}", EndDate.ToString("yyyy-MM-dd")); TopSql = ReplaceHelper.ReplaceWhereCond(TopSql) + string.Format(" and (convert(date,convert(varchar(10),pzdate,120))>=convert(date,'{0}')) and (convert(date,convert(varchar(10),pzdate,120))<=convert(date,'{1}') and(ISNULL(issendvoucher,0) = '0' OR (ISNULL(issendvoucher,0) = '1' AND ISNULL(issendsuccess,0) = '0'))) ", StartDate.ToString("yyyy-MM-dd"), EndDate.ToString("yyyy-MM-dd")); //TopSql = ReplaceHelper.ReplaceWhereCond(TopSql) + string.Format(" and (convert(date,convert(varchar(10),pzdate,120))>=convert(date,'{0}')) and (convert(date,convert(varchar(10),pzdate,120))<=convert(date,'{1}')) ", StartDate.EditText, EndDate.EditText); moduleGridDetailEx.ModuleGridObj.GridControlObj.SetGridViewDataSource(SqlHelper.ExecuteDataTable(TopSql)); string CountText = "(" + moduleGridDetailEx.ModuleGridObj.GridControlObj.DataRowCount() + "条)"; SelectPage.Text = "待推送" + CountText; } } //下方 //frmMainModule.BottomGridControlEx.SetGridViewDataSource(SqlHelper.ExecuteDataTable(BottomSql)); } } } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } finally { WaitForm.HideForm(); } } /// /// 说明:获取查询条件 /// 创建人:龚宇超 /// 创建日期:2017-11-22 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The model. /// The row item. /// System.String. protected string GetSearchSql(GridDetailModel model, DataRow rowItem, bool isLeft = false) { string fieldName = !string.IsNullOrEmpty(model.UnionParentField) && rowItem.Table.Columns.Contains(model.UnionParentField) ? model.UnionParentField : this.ParmaryKey; string sqlValue = model.IsReadOnly || model.IsChart ? model.DetailSql : model.SystemModel.MenuSql; sqlValue = ReplaceHelper.ReplaceRowParam(rowItem, sqlValue); if (ReplaceHelper.IsSelect(sqlValue) && !string.IsNullOrEmpty(model.UnionValue)) { string Conditions = string.Empty; //是左侧选中行,并且没有替换字段,则使用主表选中行 Conditions = rowItem[fieldName] + ""; sqlValue = ReplaceHelper.ReplaceWhereCond(sqlValue) + string.Format(" and {0}='{1}'", model.UnionValue, Conditions); sqlValue += string.Format(" and dDate >= '{0}' and dDate <= '{1}' ", StartDate.ToString("yyyy-MM-dd"), EndDate.ToString("yyyy-MM-dd")); } if (!string.IsNullOrEmpty(model.UnionCond)) { string UnionCond = ReplaceHelper.ReplaceRowParam(rowItem, model.UnionCond); sqlValue += UnionCond; } return sqlValue; } /// /// 一键推送 /// /// /// private void btn_AllStep_Click(object sender, EventArgs e) { try { if (this.xtc_container.SelectedTabPage != null && this.xtc_container.SelectedTabPage.Controls.Count > 0 && this.xtc_container.SelectedTabPage.Controls[0] is GridControlEx) { GridControlEx frmMainModule = this.xtc_container.SelectedTabPage.Controls[0] as GridControlEx; if (frmMainModule != null && frmMainModule.GridControl.ContextMenuStrip != null) { ToolStripMenuItem toolStripMenu = frmMainModule.GridControl.ContextMenuStrip.Items.Cast().Where(n => n.Text.Equals("推送凭证")).FirstOrDefault(); if (toolStripMenu != null && toolStripMenu.Tag != null && toolStripMenu.Tag is GridRightMenuModel) { GridRightMenuModel gridRightMenu = toolStripMenu.Tag as GridRightMenuModel; if ((gridRightMenu.ActionType + "").Equals("1") && !string.IsNullOrEmpty(gridRightMenu.Action) && gridRightMenu.Action.Equals("Data_InsertU8WithBillNoAPI{@OperatorId,@Operateway,@operatedate,@billNo,@msg}")) { string operatorId = ERPInfo.Instance.UserId; string operateWay = gridRightMenu.DllParam2; string operateDateField = gridRightMenu.DllParam3.Replace("{", "").Replace("}", ""); string billNoField = gridRightMenu.DllParam4.Replace("{", "").Replace("}", ""); string operateDate = ""; string billNo = ""; DataTable sourceTab = frmMainModule.GridControl.DataSourceTable(); int[] selectIndexs = frmMainModule.GridView.GetSelectedRows(); foreach (int selectIndex in selectIndexs) { DataRow item = frmMainModule.GridView.GetDataRow(selectIndex); if (item.Table.Columns.Contains(operateDateField) && item.Table.Columns.Contains(billNoField)) { operateDate += string.Format("{0},", item[operateDateField] + ""); billNo += string.Format("{0},", item[billNoField] + ""); } else { MessageUtil.Show("数据异常,单据号或操作日期不存在"); return; } } if (!string.IsNullOrEmpty(billNo) && !string.IsNullOrEmpty(operateDate)) { int insertValue = ExecuteInsertU8(operatorId, operateWay, operateDate.TrimEnd(','), billNo.TrimEnd(','), out string insertMsg); if (insertValue != 1) { MessageUtil.Show("凭证推送失败" + "\r\n" + insertMsg); } else { DataRow dataRow = this.gridLeft.GridView.GetFocusedDataRow(); if (dataRow != null) { string userName = ERPInfo.Instance.UserName; string startDate = StartDate.ToString("yyyyMMdd"); string endDate = EndDate.ToString("yyyyMMdd"); string pzz = this.pzz.EditValue; int fjs = int.TryParse(this.fjs.TextEdit.EditValue + "", out int fjsNum) ? fjsNum : 0; string jfkmhb = this.jfkmhb.TextEdit.Checked ? "1" : "0"; string jffmhb = this.jffmhb.TextEdit.Checked ? "1" : "0"; string tbhxls = this.tbhxls.TextEdit.Checked ? "1" : "0"; string dfkmhb = this.dfkmhb.TextEdit.Checked ? "1" : "0"; string dffmhb = this.dffmhb.TextEdit.Checked ? "1" : "0"; string sfxjhd = this.sfxjhd.TextEdit.Checked ? "1" : "0"; string zdrq = this.zdrq.TextEdit.DateTime.ToString("yyyyMMdd"); string strCollected = "'" + dataRow["cVouchType"] + "'"; string globalBatch = DateTime.Now.ToString("yyyyMMddHHmmss"); string submitCond = $"{startDate};{endDate};{pzz};{fjs};{jfkmhb};{jffmhb};{tbhxls};{dfkmhb};{dffmhb};{sfxjhd};{zdrq}"; int returnValue = ExecuteVoucherAllStep(userName, globalBatch, strCollected, submitCond, out string msg); if (returnValue == -1) { MessageUtil.Show("凭证推送失败" + "\r\n" + msg); } else { MessageUtil.Show("凭证推送成功"); } } } } else { MessageUtil.Show("未找到符合推送要求的数据"); } } } } } } catch (Exception ex) { MessageUtil.Show(ex.Message); } finally { BtnCondSearch(); //this.BtnCondSearch_Click(null, null); } } /// /// 凭证新增 /// /// /// /// /// /// /// public static int ExecuteVoucherAllStep(string operatorName, string globalBatch, string strCollected, string submitCond, out string tipMsg) { SqlParameter pMsg = new SqlParameter("@msg", SqlDbType.VarChar, -1); pMsg.Direction = ParameterDirection.Output; SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int, 4); returnValue.Direction = ParameterDirection.ReturnValue; SqlParameter[] param = { new SqlParameter("@operator", SqlDbType.NVarChar, 50), new SqlParameter("@globalBatch", SqlDbType.NVarChar, 50), new SqlParameter("@strCollected", SqlDbType.NVarChar, 200), new SqlParameter("@submitCond", SqlDbType.NVarChar, -1), pMsg, returnValue }; param[0].Value = operatorName; param[1].Value = globalBatch; param[2].Value = strCollected; param[3].Value = submitCond; SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, "DataU8_VoucherAllStep", "result", param); tipMsg = pMsg.Value.ToString(); return Convert.ToInt32(returnValue.Value); } /// /// 凭证推送 /// /// /// /// /// /// /// public static int ExecuteInsertU8(string operatorId, string operateWay, string operateDate, string billNo, out string tipMsg) { SqlParameter pMsg = new SqlParameter("@msg", SqlDbType.VarChar, -1); pMsg.Direction = ParameterDirection.Output; SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int, 4); returnValue.Direction = ParameterDirection.ReturnValue; SqlParameter[] param = { new SqlParameter("@OperatorId", SqlDbType.Int,4), new SqlParameter("@Operateway", SqlDbType.Int, 4), new SqlParameter("@operatedate", SqlDbType.VarChar, -1), new SqlParameter("@billNo", SqlDbType.VarChar, -1), pMsg, returnValue }; param[0].Value = operatorId; param[1].Value = operateWay; param[2].Value = operateDate; param[3].Value = billNo; SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, "Data_InsertU8WithBillNoAPI", "result", param); tipMsg = pMsg.Value.ToString(); return Convert.ToInt32(returnValue.Value); } } }