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.SweepCode.Control; using Lskj.Util; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; using System.Text; using System.Windows.Forms; using System.Threading; using DevExpress.XtraGrid.Views.Grid; namespace Lskj.MesPrintCode { public partial class FrmMain : BaseForm { /// /// 说明:初始化后构造方法 /// 创建人:王一帆 /// 创建日期:2021-06-15 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// public FrmMain() { this.DoubleBuffered = true; //SetStyle(ControlStyles.UserPaint, true); //SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景. //SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲 InitializeComponent(); } #region 公共变量 /// /// 下拉框的数据源的实际值 /// public string ComValueMember; /// /// 下拉框的数据源的显示值 /// public string ComDisplayMember; /// /// 下拉框的数据源 /// public DataTable ComBoxSource = new DataTable(); /// /// 搜索之前执行的存储过程 /// public string BeforeStored = ""; /// /// 搜索之后执行的存储过程 /// public string AfterStored = ""; /// /// 下拉框筛选后触发存储过程 /// public string ScreenStored = ""; /// /// 界面关闭触发存储过程 /// public string FrmCloseStored = ""; /// /// 主搜索框回车不跳转扫码区域 /// public string IsGotoFirstCtr = "isAtuoGotoFirstSweepControl"; /// /// 主搜索框搜索后改变开工状态 /// public string IsSweepTipStata = "SweepTipStata"; /// /// 入口模型 /// public DynamicMesProduct SysModel; /// /// 扫码提示表 /// public DataTable tips; /// ///查询条件控件 /// public MyControl SearchObj; /// /// 主控件集 /// public MyControl ControlObj; /// /// 基础模型 /// public ModuleModel MoudleObj; /// /// 明细基础模型 /// public ModuleModel DetalModel; /// /// 明细初始集合 /// public List GridInitDetailModel; /// /// 表格明细集合 /// public List GridDetailModelObjs; /// /// 内部表格集合 /// public List GridOtherModelObj; /// /// 主表格模块 /// public List GridMainModelObj; /// /// 明细衍生到下侧数据 /// public List GridDetailAddObj; /// /// 明细衍生到右侧数据 /// public List GridDetailRightObj; /// /// 扫码衍生类 /// public GridRightMenuModel GridSweepRight; /// /// 右侧按钮数据字典 /// public Dictionary sweepDic = new Dictionary(); /// /// 中间输入控件数据字典 /// public Dictionary sweepMidControl = new Dictionary(); /// /// 提示消息框 /// public LevitationPanel levitationPanel; /// /// 上一次工单拼接键 /// public string afterRshKey = ""; /// /// 上一次工单值 /// public string aftertxtFixKey = ""; /// /// 查询是否刷新 /// public bool isSearchRefresh = true; /// /// 是否是加载第一次弹出框 /// public bool isFristSearch = false; #endregion #region 私有变量 List colorlist = new List() { ColorTranslator.FromHtml("#CBEAEC"), ColorTranslator.FromHtml("#D0E3F3"), ColorTranslator.FromHtml("#FDE7CC"), ColorTranslator.FromHtml("#FCD5CF") }; /// /// 子系统默认背景色 /// private string[] _defaultColors = { "#0198A3", "#1C76C8", "#F88906", "#EA5C46" }; /// /// 数据索引 /// private int _dataIndex; /// /// 初始化完成标记 /// private bool _isInitFinish; /// /// 附件部分显隐 /// private bool _isFilePanelVisble; /// /// 附件源sql /// private string _fileSql; /// /// 主键值 /// private string _keyValue; /// /// 主键名 /// private string _primaryKey; /// /// 附件地址 /// private string _filePath; /// /// 选项卡刷新页签 /// private string[] _pageIndex; /// /// 当前数据内容 /// private DataRow _rowItem; /// /// 界面上一次刷新sql /// private string LastRefreshSql; /// /// 控件源数据 /// private DataTable _dtFields; /// /// 扫码控件源数据 /// private DataTable _codeFields; /// /// 动态加载右侧按钮 /// private DataTable _RightFields; /// /// 主表数据 /// private DataTable _dtMainTable; /// /// pdf附件资源 /// private DataTable _dtFiles; /// /// 搜索字段 /// private string _searchFile; /// /// 搜索字段条件 /// private string _searchCode; /// /// 搜索第二个字段 /// private string _searchSecondFile; /// /// 搜索第二个字段条件 /// private string _searchSecondCode; /// /// 附件下拉菜单 /// private LabelComboxEdit _fileComboBox; /// /// 查看附件 /// private ModuleWebView _moduleWebView; /// /// 选项卡排序Sql /// private Dictionary _dicOrder = new Dictionary(); /// ///默认窗口长度 /// private int _windowWidth; /// /// 分割条横坐标 /// private int _splitLocation; /// /// 设置的字体大小 /// private int _fontSize; /// /// 分辨率改变时界面的比例大小(高) /// private double _FormHeight; /// /// 分辨率改变时界面的比例大小(宽) /// private double _FormWidth; #endregion #region 事件 #region 窗体加载时 /// /// 说明:窗体加载时 /// 创建人:王一帆 /// 创建日期:2021-06-15 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The instance containing the event data. protected override void OnLoad(EventArgs e) { WaitForm.ShowForm(); try { //SweepTipStata.Hide(); this.labelTips.MouseMove += OnTips_MouseMove; this.labelTips.MouseLeave += OnTips_MouseLeave; //splitMain.SetPanelCollapsed(true);//初始折叠 this.Width = 1150; //_splitLocation = this.splitMain.SplitterPosition; _windowWidth = this.Width; //this.splitMain.SplitGroupPanelCollapsed += new SplitGroupPanelCollapsedEventHandler(OnClickSplitBar); if (this.SysModel.Privilege.Equals("3")) this.panelMain.Height = 800; SysModel.Privilege = this.SysModel.Privilege.Equals("3") ? "1" : SysModel.ModuleId > 0 ? BaseImpl.GetUserPurviewsByMenuId(SysModel.ModuleId + "") + "" : BaseImpl.GetUserPurviewsByMenuCode(SysModel.ModuleCode) + ""; this._isInitFinish = false; if (!this.SysModel.HasPrivilege()) { MessageUtil.Show(ResourceKeys.UnPurview); this.Close(); } else { this.InitializeSetting();//初始化属性设置 this.ResizeControl();//根据分辨率重绘界面大小 this.InitializeControl();//设置control初始化 this.InitializeDetailGrid();//初始化扫码功能模块的明细数据 this.InitSpliterPosition();//初始化分割条位置 //this.SweepIsUsable();//扫码完成后判断右键是否可点击 this.txtEditClass.SelectedIndexChanged += new EventHandler(chooseToChange); } } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } finally { Lskj.Control.Model.AutoSizeChange.ControllInitializeSize(this); } WaitForm.HideForm(); } #endregion #region 工单选中索引改变事件 /// /// 说明:工单选中改变 /// 创建人:曹屹峰 /// 创建日期:2021-10-8 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void chooseToChange(object sender, EventArgs e) { DataRow rowItem = ComBoxSource != null && ComBoxSource.Rows.Count > 0 ? ComBoxSource.Select("1=1").FirstOrDefault(x => txtEditClass.Text == x[ComDisplayMember] + "") : null; if (rowItem != null) { this.txtFixKey.Focus(); } } #endregion #region 点击分割条展开右边明细 /// /// 说明:点击分割条展开右边明细 /// 创建人:王一帆 /// 创建日期:2021-06-16 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void OnClickSplitBar(object sender, SplitGroupPanelCollapsedEventArgs e) { if (this.Size.Width <= _windowWidth) { this.Size = new Size(_windowWidth + 200, this.Size.Height); } else { this.Size = new Size(_windowWidth, this.Size.Height); } Rectangle r = new Rectangle(_splitLocation, 0, 200, this.Size.Height); splitMain.Panel2.RectangleToClient(r); } #endregion #region 点击加载的右键事件 /// /// 说明:点击加载的右键事件 /// 创建人:王一帆 /// 创建日期:2021-06-16 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void OnModuleClick(object sender, EventArgs e) { if (_rowItem == null) { MessageUtil.Show("请查询工单号!"); return; } try { WaitForm.ShowForm(); if (sender is SweepButton) { SweepButton button = sender as SweepButton; if (button != null) { if (button.Tag is GridRightMenuModel) { GridRightMenuModel model = button.Tag as GridRightMenuModel; DataRow gcMainSecRows = this.gcOutput.GetViewFocusedDataRow(); if (button.Parent == plExpectBtn) { gcMainSecRows = this.gcExpected.GetViewFocusedDataRow(); } BaseRightMenu menu = new BaseRightMenu(); menu.Model = this.SysModel; if (menu.ExecRightMenu(model, new DataRow[] { gcMainSecRows }) && model.Refresh) { if (!string.IsNullOrWhiteSpace(LastRefreshSql)) { _rowItem = BaseImpl.GetDataRowResult(LastRefreshSql); IniAllControl(_rowItem, false); } else { Refresh(null, true); } } } } } } catch (Exception ex) { //MessageUtil.Show(ex); string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } finally { WaitForm.HideForm(); } } #endregion #region 处理右键菜单10个扩展参数 /// /// 说明:处理右键菜单10个扩展参数 /// 创建人:王一帆 /// 创建日期:2017-10-30 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The parameter list. protected virtual List HandleRightMenuParams(List paramList, DataRow rowData, DataRow[] rowDatas = null) { List handleParamList = new List(); foreach (string item in paramList) { if (!string.IsNullOrWhiteSpace(item)) { string fieldValue = ReplaceHelper.ReplaceUserInfo(item); string firstChar = fieldValue.Length > 0 ? fieldValue.Substring(0, 1) : ""; switch (firstChar) { case "@": // sql处理 { string value = MainImpl.GetResult(ReplaceHelper.ReplaceRowParam(rowData, fieldValue.Replace("@", ""))) + ""; handleParamList.Add(value); } break; case "#": // 需要传入的sql语句 handleParamList.Add(ReplaceHelper.ReplaceRowParam(rowData, fieldValue.Replace("#", "")) + ""); break; case "[": //[FormTitle_格式数据 if (fieldValue.StartsWith("[FormTitle_")) { handleParamList.Add(ReplaceHelper.ReplaceRowParam(rowData, fieldValue.Replace("[FormTitle_", "")) + ""); } else { if (rowDatas != null) { handleParamList.Add(ReplaceHelper.ReplaceRowParam(rowDatas, fieldValue, "'", "'") + ""); } else { handleParamList.Add(ReplaceHelper.ReplaceRowParam(rowData, fieldValue) + ""); } } break; case "$": //传入参数不需要任何处理 handleParamList.Add(fieldValue.Replace("$", "") + ""); break; default: handleParamList.Add(ReplaceHelper.ReplaceRowParam(rowData, fieldValue) + ""); break; } } else { handleParamList.Add(item); } } return handleParamList; } #endregion #region 主搜索控件回车事件 /// /// 说明:主搜索控件回车事件 /// 创建人:王一帆 /// 创建日期:2021-06-16 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void OnKeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (!string.IsNullOrEmpty(MoudleObj.BeforeStored)) { try { string sql = ReplaceHelper.ReplaceUserInfo(MoudleObj.BeforeStored); string result = SqlHelper.ExecuteScalar(sql) + ""; if (!string.IsNullOrEmpty(result)) MessageUtil.Show(result); } finally { } } try { //if (sender is SweepControl && !string.IsNullOrEmpty(this._keyValue)) //{ // SweepControl sweepControl = sender as SweepControl; // DataRow item = sweepControl.Tag as DataRow; // string SweepControlText = sweepControl.ObjSweepControlText; // string msgs = string.Empty, refreshPages = string.Empty, reRightButton = string.Empty; // int returnValue = ScanningCheckCard(this.SysModel.ModuleCode, SweepControlText, this._keyValue, this.SysModel.UserId, this.SysModel.UserName, 0, item["fieldname"] + "", out msgs, out refreshPages, out reRightButton); // string[] resultMsgs = msgs.ToLower().Split('&'); // string[] _positionIndex = refreshPages.Split(';'); // if (returnValue != 1) // { // MessageUtil.Show(resultMsgs[0]); // } // else // { // string positionIndex = string.Empty; // _pageIndex = _positionIndex[0].Split(','); // if (_positionIndex.Count() > 1) positionIndex = _positionIndex[1]; // if (resultMsgs.Length >= 2) // { // GetMsgParamters(resultMsgs); // } // else // { // if (_pageIndex != null) Refresh(_pageIndex, false, positionIndex); // } // if (!string.IsNullOrEmpty(reRightButton)) // { // (sweepDic[double.Parse(reRightButton)] as SweepButton).OnClickCallBack(); // } // System.Windows.Forms.Control FocusControl = this.ActiveControl; // for (int i = 0; i < sweepMidControl.Count - 1; i++) // { // if (sweepMidControl[i] == FocusControl) // { // sweepMidControl[i + 1].Focus(); // } // break; // } // } // if (!SystemInfo.Instance.isRemberText) // { // sweepControl.ObjButtonEdit.Text = ""; // } //} //else //{ SearchMainGrid(true); if (!string.IsNullOrEmpty(MoudleObj.AfterStored) && _rowItem != null) { try { string sql = this.ControlObj.ReplaceControlValue(MoudleObj.AfterStored); sql = ReplaceHelper.ReplaceRowParam(_rowItem, sql); string result = SqlHelper.ExecuteScalar(sql) + ""; if (!string.IsNullOrEmpty(result) && isFristSearch) MessageUtil.Show(result); _rowItem = BaseImpl.GetDataRowResult(LastRefreshSql); IniAllControl(_rowItem, false); isFristSearch = true; } catch { } } } catch (Exception ex) { //MessageUtil.Show(ex); string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } } #endregion #region 下拉框控件获取数据后自动执行回车事件 /// /// 说明:下拉框控件获取数据后自动执行回车事件 /// 创建人:王一帆 /// 创建日期:2021-07-04 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void OnEnterAfterCell(object sender, EventArgs e) { try { if (!string.IsNullOrEmpty(this._keyValue)) { SweepAutoEdit sweepAutoEdit = sender as SweepAutoEdit; DataRow item = sweepAutoEdit.Tag as DataRow; string SweepControlText = sweepAutoEdit.EditValue; string msgs = string.Empty, refreshPages = string.Empty, reRightButton = string.Empty; int returnValue = ScanningCheckCard(this.SysModel.ModuleCode, SweepControlText, this._keyValue, this.SysModel.UserId, this.SysModel.UserName, 0, item["fieldname"] + "", out msgs, out refreshPages, out reRightButton); string[] resultMsgs = msgs.ToLower().Split('&'); if (returnValue != 1) { MessageUtil.Show(resultMsgs[0]); } else { _pageIndex = refreshPages.Split(','); if (resultMsgs.Length >= 2) { GetMsgParamters(resultMsgs); } else { if (_pageIndex != null) Refresh(_pageIndex); } if (!string.IsNullOrEmpty(reRightButton)) { (sweepDic[double.Parse(reRightButton)] as SweepButton).OnClickCallBack(); } System.Windows.Forms.Control FocusControl = this.ActiveControl; for (int i = 0; i < sweepMidControl.Count - 1; i++) { if (sweepMidControl[i] == FocusControl) { sweepMidControl[i + 1].Focus(); break; } } } } } catch (Exception ex) { //MessageUtil.Show(ex); string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } #endregion #region 鼠标划过事件 private void OnMouseMove(object sender, EventArgs e) { SweepButton sweepButton = (SweepButton)sender; if (sweepButton.isEnable) { sweepButton.BackColor = ColorTranslator.FromHtml("#eac205"); } } #endregion #region 鼠标滑过提示信息事件 private void OnTips_MouseMove(object sender, MouseEventArgs e) { try { if (labelTips.Text != "") { levitationPanel.Location = new Point(this.panelMain.PointToClient(MousePosition).X + 15, this.panelMain.PointToClient(MousePosition).Y + 15); levitationPanel.labelLev.Text = labelTips.Text; levitationPanel.Show(); } } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } #endregion #region 鼠标提示信息事件 private void OnTips_MouseLeave(object sender, EventArgs e) { try { levitationPanel.Hide(); } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } #endregion #region 鼠标离开事件 private void OnMouseLeave(object sender, EventArgs e) { try { SweepButton sweepButton = (SweepButton)sender; if (sweepButton.isEnable) { sweepButton.BackColor = sweepButton.emptyColor; } } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } #endregion #region 优化加载速度 /// /// 优化加载速度 /// //protected override CreateParams CreateParams //{ // get // { // CreateParams cp = base.CreateParams; // cp.ExStyle |= 0x02000000; // return cp; // } //} #endregion #region 下拉框选择刷新触发的存储过程 /// /// 下拉框选择刷新触发的存储过程 /// private void OnSelectedValueChanged(object sender, EventArgs e) { OnPubComChange(); } #endregion #region 下拉扫码框回车触发绑定功能 /// /// 说明:下拉扫码框回车触发绑定功能 /// 创建人:王一帆 /// 创建日期:2021-09-23 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void OnSelectedKeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (ComBoxSource != null && ComBoxSource.Rows.Count > 0) { DataRow rowItem = ComBoxSource.Select("1=1").FirstOrDefault(x => txtEditClass.Text == x[ComDisplayMember] + ""); DataRow ValuerowItem = ComBoxSource.Select("1=1").FirstOrDefault(x => txtEditClass.Text == x[ComValueMember] + ""); if (rowItem != null) { this.txtEditClass.Text = rowItem[ComDisplayMember] + ""; } if (ValuerowItem != null) { this.txtEditClass.Text = ValuerowItem[ComDisplayMember] + ""; } } OnPubComChange(); this.txtFixKey.Focus(); } } #endregion #region 下拉扫码框回车触发绑定功能 /// /// 说明:下拉框改变公共功能 /// 创建人:王一帆 /// 创建日期:2021-09-23 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void OnPubComChange() { if (!string.IsNullOrEmpty(MoudleObj.ScreenStored) && _rowItem != null) { if (MoudleObj.isRihgtRefresh == 1) { isSearchRefresh = false; string[] txtArgs = aftertxtFixKey.Split('-'); if (!string.IsNullOrEmpty(txtArgs[0])) { //ComboBoxModel model = this.txtEditClass.SelectedItem as ComboBoxModel; DataRow rowItem = ComBoxSource != null && ComBoxSource.Rows.Count > 0 ? ComBoxSource.Select("1=1").FirstOrDefault(x => txtEditClass.Text == x[ComDisplayMember] + "") : null; if (rowItem != null && !(rowItem[ComValueMember] + txtArgs[0]).Equals(afterRshKey)) { afterRshKey = rowItem[ComValueMember] + txtArgs[0]; isSearchRefresh = true; } } } string sql = this.ControlObj.ReplaceControlValue(MoudleObj.ScreenStored); sql = ReplaceHelper.ReplaceRowParam(_rowItem, sql); string result = SqlHelper.ExecuteScalar(sql) + ""; _rowItem = BaseImpl.GetDataRowResult(LastRefreshSql); this.ControlObj.ResetControlValue(); string codeSql = "Select"; bool isDoubleCode = false;//是否有多个条件 if (!string.IsNullOrEmpty(_searchCode)) { string SearchCode = ReplaceHelper.ReplaceParamToValue(_searchCode, aftertxtFixKey); // 未替换的参数所有替换搜索值 codeSql += string.Format(" '{0}' as {1}", aftertxtFixKey, _searchFile); DataRow rowItem = ComBoxSource != null && ComBoxSource.Rows.Count > 0 ? ComBoxSource.Select("1=1").FirstOrDefault(x => txtEditClass.Text == x[ComDisplayMember] + "") : null; if (rowItem != null) { isDoubleCode = true; SearchCode += " " + ReplaceHelper.ReplaceParamToValue(_searchSecondCode, rowItem[ComValueMember] + ""); // 未替换的参数所有替换搜索值 codeSql += string.Format(",'{0}' as {1}", rowItem[ComValueMember] + "", _searchSecondFile); } LastRefreshSql = isDoubleCode ? ReplaceHelper.ReplaceRowParam(BaseImpl.GetDataRowResult(codeSql), this.MoudleObj.RefreshSql) : ReplaceHelper.ReplaceParamToValue(this.MoudleObj.RefreshSql, aftertxtFixKey); _rowItem = BaseImpl.GetDataRowResult(ReplaceHelper.ReplaceWhereCond(this.MoudleObj.MenuSql) + " " + SearchCode); } else { _rowItem = BaseImpl.GetDataTableResult(ReplaceHelper.ReplaceWhereCond(this.MoudleObj.MenuSql + "and" + _primaryKey + "=" + aftertxtFixKey)).Rows[0]; } IniAllControl(_rowItem, false); if (!string.IsNullOrEmpty(result)) MessageUtil.Show(result); } // this.txtFixKey.Focus(); } #endregion #region 扫码模块关闭时触发 /// /// 扫码模块关闭时触发 /// private void OnFormClosed(object sender, FormClosedEventArgs e) { if (!string.IsNullOrEmpty(MoudleObj.FrmCloseStored)) { string sql = this.ControlObj.ReplaceControlValue(MoudleObj.FrmCloseStored); sql = ReplaceHelper.ReplaceRowParam(_rowItem, sql); string result = SqlHelper.ExecuteScalar(sql) + ""; if (!string.IsNullOrEmpty(result)) MessageUtil.Show(result); } } #endregion #endregion #region 方法 #region 初始化分割条位置 /// /// 说明:初始化分割条位置 /// 创建人:龚宇超 /// 创建日期:2017-12-15 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void InitSpliterPosition() { string spliterPosition = IniHelper.Read(string.Format("Step_spliterPositionMain_{0}", this.SysModel.ModuleCode)); if (!string.IsNullOrEmpty(spliterPosition)) this.splitMain.SplitterPosition = Convert.ToInt32(spliterPosition); string split_Details = IniHelper.Read(string.Format("split_DetailsMain_{0}", this.SysModel.ModuleCode)); if (!string.IsNullOrEmpty(split_Details)) this.split_Details.SplitterPosition = Convert.ToInt32(split_Details); string splitDetail = IniHelper.Read(string.Format("Step_splitDetailPositionMain_{0}", this.SysModel.ModuleCode)); if (!string.IsNullOrEmpty(splitDetail)) this.splitDetail.SplitterPosition = Convert.ToInt32(splitDetail); string split_Main_Top = IniHelper.Read(string.Format("split_Main_Top_{0}", this.SysModel.ModuleCode)); if (!string.IsNullOrEmpty(split_Main_Top)) this.split_Main_Top.SplitterPosition = Convert.ToInt32(split_Main_Top); } #endregion #region 刷新 /// /// 说明:刷新 /// 创建人:龚宇超 /// 创建日期:2018-02-28 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void Refresh(string[] pageIndexs, bool isRefresh = false, string positionIndex = "") { int selectdetailTabIndex = !string.IsNullOrEmpty(positionIndex) ? int.Parse(positionIndex) : this.detailTab.TabControlObj.SelectedTabPageIndex; foreach (GridDetailModel gridmodel in GridDetailModelObjs) { string sqlValue = this.GetSearchSql(gridmodel, _rowItem); if (isRefresh || pageIndexs.Contains(gridmodel.Orderid + "")) { this.detailTab.TabControlObj.SelectedTabPage = this.detailTab.TabControlObj.TabPages.Where(o => o.Text.Contains(gridmodel.DetailName)).FirstOrDefault(); if (this.detailTab.TabControlObj.SelectedTabPage == null) this.detailTab.TabControlObj.SelectedTabPage = this.detailTab.TabControlObj.TabPages[0]; this.detailTab.SetGridDataSource(MainImpl.GetDataTableResult(sqlValue)); } } foreach (GridDetailModel gridmodel in GridDetailRightObj) { string sqlValue = this.GetSearchSql(gridmodel, _rowItem); if (isRefresh || pageIndexs.Contains(gridmodel.Orderid + "")) { this.TabRight.TabControlObj.SelectedTabPage = this.TabRight.TabControlObj.TabPages.Where(o => o.Text == gridmodel.DetailName).FirstOrDefault(); if (this.TabRight.TabControlObj.SelectedTabPage == null) this.TabRight.TabControlObj.SelectedTabPage = this.detailTab.TabControlObj.TabPages[0]; this.TabRight.SetGridDataSource(MainImpl.GetDataTableResult(sqlValue)); } } this.detailTab.TabControlObj.SelectedTabPageIndex = selectdetailTabIndex; } #endregion #region 获取验证返回操作参数 /// /// 说明:获取验证返回操作参数 /// 创建人:龚宇超 /// 创建日期:2018-03-01 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void OnSplitterPositionChanged(object sender, EventArgs e) { IniHelper.Write(string.Format("Step_spliterPositionMain_{0}", this.SysModel.ModuleCode), this.splitMain.SplitterPosition + ""); } /// /// 说明:获取验证返回操作参数 /// 创建人:王一帆 /// 创建日期:2018-03-01 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void OnDetailsMainPositionChanged(object sender, EventArgs e) { IniHelper.Write(string.Format("split_DetailsMain_{0}", this.SysModel.ModuleCode), this.split_Details.SplitterPosition + ""); } /// /// 说明:获取验证返回操作参数 /// 创建人:龚宇超 /// 创建日期:2018-03-01 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void OnSplitDetailPositionChanged(object sender, EventArgs e) { IniHelper.Write(string.Format("Step_splitDetailPositionMain_{0}", this.SysModel.ModuleCode), this.splitDetail.SplitterPosition + ""); } /// /// 说明:获取验证返回操作参数 /// 创建人:龚宇超 /// 创建日期:2018-03-01 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void OnsplitMainTopPositionChanged(object sender, EventArgs e) { IniHelper.Write(string.Format("split_Main_Top_{0}", this.SysModel.ModuleCode), this.split_Main_Top.SplitterPosition + ""); } #endregion #region 扫码调用dll /// /// 说明:获取验证返回操作参数 /// 创建人:龚宇超 /// 创建日期:2018-03-01 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void GetMsgParamters(string[] msgs) { if (msgs[1].Contains("module=")) { string[] paramters = msgs[1].Split('='); if (paramters.Length != 2) { MessageUtil.Show(ResourceKeys.ProcNameSettingFault); return; } string[] defaultParams = paramters[1].Split('^'); if (defaultParams.Length < 4) { MessageUtil.Show(ResourceKeys.ExcuteMoudleFail); return; } string dllName = defaultParams[1]; string moduleTitle = defaultParams[2]; string saveState = defaultParams[3]; if ("lskj.pubadd3.dll".Equals(dllName) || "lskj.pubadd2.dll".Equals(dllName)) dllName = "Lskj.PubAdd.dll"; List paramList = new List(); for (int i = 4; i < 14; i++) { paramList.Add(defaultParams.Length > i ? defaultParams[i] : ""); } //执行dll string[] str = { this.SysModel.FormText, ERPInfo.Instance.UserId, ERPInfo.Instance.UserName, this.SysModel.Privilege, this.SysModel.ModuleCode, paramList[0], paramList[1], paramList[2], paramList[3], paramList[4], paramList[5], paramList[6], paramList[7], paramList[8], paramList[9], "", "", saveState }; IForm form = FormHelper.LoadDllForm(dllName, str); if (form == null) { MessageUtil.Show(ResourceKeys.DyncmicDllNotFount); return; } if (form.SubForm == null) { MessageUtil.Show(ResourceKeys.DyncmicDllInitFault); return; } form.SubForm.WindowState = FormWindowState.Normal; form.SubForm.StartPosition = FormStartPosition.CenterScreen; form.SubForm.Text = moduleTitle; DialogResult dr = form.SubForm.ShowDialog(); if (_pageIndex != null) Refresh(_pageIndex); } } #endregion #region 初始化属性 /// /// 说明:初始化属性设置 /// 创建人:王一帆 /// 创建日期:2021-06-16 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void InitializeSetting() { //string key=BaseImpl.GetBasePrimaryKey(this.SysModel.ModuleCode); this._primaryKey = BaseImpl.GetBasePrimaryKey(this.SysModel.ModuleCode); DataTable dataRows = BaseModuleImpl.GetBaseGridColumns(SysModel.ModuleCode); //DataRow dgxx = MainImpl.GetSystemdllTab(this.SysModel.ModuleCode); DataRow dgxx2 = MainImpl.GetSystemdllTab(this.SysModel.ModuleCode); this.MoudleObj = new ModuleModel(dgxx2); this._fontSize = 14;//获取扫码控件字体大小 int H = Screen.PrimaryScreen.Bounds.Height; int W = Screen.PrimaryScreen.Bounds.Width; this._fontSize = H * W >= 1920 * 1080 ? _fontSize : Convert.ToInt32(_fontSize * H * W / 1920 / 1080 * 1.3); //string key2 = BaseImpl.GetBasePrimaryKey(this.SysModel.ModuleCode); this.MoudleObj.ParmaryKey = BaseImpl.GetBasePrimaryKey(this.SysModel.ModuleCode); DataTable queryTable = BaseModuleImpl.GetCustomQueryFields(this.MoudleObj.CondKey); //DataTable queryTable2 = BaseModuleImpl.GetCustomQueryFields(this.MoudleObj.CondKey); if (queryTable != null && queryTable.Rows.Count > 0) { if (queryTable.Rows.Count == 1) { this.searchClass.Visible = false; } int searchNamewidth = 0; int searchClassWidth = 0; foreach (DataRow queryItem in queryTable.Rows) { int FieldType = int.Parse(queryItem["fieldTypeId"] + ""); if (FieldType == ControlType.LabSacn) { _searchFile = queryItem["fieldName"] + ""; _searchCode = queryItem["checkCond"] + ""; this.lab_searchName.Text = queryItem["userName"] + ""; searchNamewidth = int.Parse(queryItem["controlWidth"] + ""); } else { _searchSecondFile = queryItem["fieldName"] + ""; _searchSecondCode = queryItem["checkCond"] + ""; this.lab_searchClass.Text = queryItem["userName"] + ""; string ValueMember = ControlType.LabComboxValue == FieldType || ControlType.LabAutoCompleteValueParam == FieldType ? queryItem["lookupKeyField"] + "" : queryItem["lookupResult"] + ""; //string ValueMember = ControlType.LabComboxValue == FieldType || ControlType.LabAutoCompleteValueParam == FieldType ? model.ValueMember : model.TextMember; //comboxEdit.ValueField = model.ValueMember; //comboxEdit.TextField = model.TextMember; ComBoxSource = MainImpl.GetDataTableResult(queryItem["lookupSql"] + ""); this.SetDataSource(ComBoxSource, ValueMember, queryItem["lookupResult"] + ""); //this.lab_searchClass.Width = searchClassWidth = int.Parse(queryItem["controlWidth"] + ""); this.searchClass.Width = searchClassWidth = int.Parse(queryItem["controlWidth"] + ""); } } this.pl_search.Width = searchNamewidth + searchClassWidth; } this.GridInitDetailModel = GetDetailGrids(this.SysModel.ModuleCode); this.GridMainModelObj = GridInitDetailModel.Where(o => o.displayMode != 1 && o.rightVisible != 1 && o.Orderid == 1).ToList(); this.GridDetailRightObj = GridInitDetailModel.Where(o => o.rightVisible == 1).ToList(); DataTable sweepRight = BaseModuleImpl.GetBaseGridRightMenus(this.SysModel.ModuleCode); this.GridSweepRight = sweepRight != null ? new GridRightMenuModel(sweepRight.Rows[0]) : null; if (GridMainModelObj.Count > 0) { this.GridDetailModelObjs = GetDetailGrids(this.GridMainModelObj[0].UnionModule); this.GridOtherModelObj = GridDetailModelObjs.Where(o => o.displayMode != 1 && o.rightVisible != 1 && o.Orderid > 0 && o.Orderid < 4).ToList(); this.GridDetailModelObjs = GridDetailModelObjs.Where(o => o.displayMode != 1 && o.rightVisible != 1 && o.Orderid > 3).ToList(); } else { MessageUtil.Show("未找到主表配置数据源!请查验"); return; } this._dtFields = BaseModuleImpl.GetControlLocation(this.MoudleObj.FormKey, this.SysModel.ModuleCode); this._codeFields = BaseImpl.GetSweepCode(this.SysModel.ModuleCode); tips = BaseImpl.GetSweepCodeTips(this.SysModel.ModuleCode);//获取提示信息 this._RightFields = sweepRight; this.TabRight.Model = this.detailTab.Model = this.SysModel; this.gcMain.GridView.FocusedRowObjectChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventHandler(OnGridViewFocusedRowObjectChanged); this.gcMain.GridView.RowCellClick += new RowCellClickEventHandler(GridView_RowCellClick); this.gcLeftDetail.GridView.FocusedRowObjectChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventHandler(OnLeftViewFocusedRowObjectChanged); this.gcLeftDetail.GridView.RowCellClick += new RowCellClickEventHandler(LeftView_RowCellClick); if (!string.IsNullOrEmpty(this.SysModel.ParmaryValue)) { this.txtFixKey.Text = this._keyValue = this.SysModel.ParmaryValue; } } /// /// 说明:加载明细数据 /// 创建人:龚宇超 /// 创建日期:2018-09-28 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void GridView_RowCellClick(object sender, RowCellClickEventArgs e) { try { WaitForm.ShowForm(); DataRow gcMainSecRows = this.gcMain.GetViewFocusedDataRow(); foreach (GridDetailModel detailModel in GridOtherModelObj) { string searchSql = this.GetSearchSql(detailModel, gcMainSecRows); switch (detailModel.Orderid)//通过明细数据源加载表格 { case 1://左侧表 this.gcLeftDetail.SetGridViewDataSource(MainImpl.GetDataTableResult(searchSql)); break; case 2://产出表 this.gcOutput.SetGridViewDataSource(MainImpl.GetDataTableResult(searchSql)); break; case 3://余料表 this.gcExpected.SetGridViewDataSource(MainImpl.GetDataTableResult(searchSql)); break; default: //三部分明细数据源更新 setTabPageGridData(detailTab, gcMainSecRows); break; } } } catch (Exception ex) { LogHelper.Instance.WriteError(ex); string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show("加载明细数据失败!" + Message); } finally { WaitForm.HideForm(); } } /// /// 说明:加载明细数据 /// 创建人:龚宇超 /// 创建日期:2018-09-28 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void LeftView_RowCellClick(object sender, RowCellClickEventArgs e) { try { WaitForm.ShowForm(); DataRow gcMainSecRows = this.gcLeftDetail.GetViewFocusedDataRow(); foreach (GridDetailModel detailModel in GridOtherModelObj) { string searchSql = this.GetSearchSql(detailModel, gcMainSecRows); switch (detailModel.Orderid)//通过明细数据源加载表格 { case 2://产出表 this.gcOutput.SetGridViewDataSource(MainImpl.GetDataTableResult(searchSql)); break; } } } catch (Exception ex) { LogHelper.Instance.WriteError(ex); string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show("加载明细数据失败!" + Message); } finally { WaitForm.HideForm(); } } /// /// 说明:数据行发生改变加载明细 /// 创建人:龚宇超 /// 创建日期: /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. protected void OnLeftViewFocusedRowObjectChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventArgs e) { try { WaitForm.ShowForm(); DataRow gcMainSecRows = this.gcLeftDetail.GetViewFocusedDataRow(); foreach (GridDetailModel detailModel in GridOtherModelObj) { string searchSql = this.GetSearchSql(detailModel, gcMainSecRows); switch (detailModel.Orderid)//通过明细数据源加载表格 { case 2://产出表 this.gcOutput.SetGridViewDataSource(MainImpl.GetDataTableResult(searchSql)); break; } } } catch (Exception ex) { LogHelper.Instance.WriteError(ex); string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show("加载明细数据失败!" + Message); } finally { WaitForm.HideForm(); } } /// /// 说明:数据行发生改变加载明细 /// 创建人:龚宇超 /// 创建日期: /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. protected void OnGridViewFocusedRowObjectChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventArgs e) { try { WaitForm.ShowForm(); DataRow gcMainSecRows = this.gcMain.GetViewFocusedDataRow(); foreach (GridDetailModel detailModel in GridOtherModelObj) { string searchSql = this.GetSearchSql(detailModel, gcMainSecRows); switch (detailModel.Orderid)//通过明细数据源加载表格 { case 1://左侧表 this.gcLeftDetail.SetGridViewDataSource(MainImpl.GetDataTableResult(searchSql)); break; case 2://产出表 this.gcOutput.SetGridViewDataSource(MainImpl.GetDataTableResult(searchSql)); break; case 3://余料表 this.gcExpected.SetGridViewDataSource(MainImpl.GetDataTableResult(searchSql)); break; default: //三部分明细数据源更新 setTabPageGridData(detailTab, gcMainSecRows); break; } } } catch (Exception ex) { LogHelper.Instance.WriteError(ex); string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show("加载明细数据失败!" + Message); } finally { WaitForm.HideForm(); } } #region 初始化第二条件下拉框的值 #region 下拉框通用类 /// /// 说明:下拉框通用类 /// 创建人:王一帆 /// 创建日期:2021-06-16 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// class ComboBoxModel { public string ValueMember; public string DisplayMember; public DataRow RowItem; public override string ToString() { return this.RowItem[DisplayMember] + ""; } } #endregion /// /// 说明:设置数据源 /// 创建人:王一帆 /// 创建日期:2017-08-08 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// 数据源 public void SetDataSource(DataTable dataSource, string ValueField, string TextField) { try { ComValueMember = ValueField; ComDisplayMember = TextField; foreach (DataRow item in dataSource.Rows) { ComboBoxModel model = new ComboBoxModel { ValueMember = ValueField, DisplayMember = TextField, RowItem = item }; this.txtEditClass.Properties.Items.Add(model); } } catch (Exception) { } } #endregion /// /// 通过字体内容提升长度 /// /// protected int GetCharWidth() { int CharWidth = 22; float DefaultFontSize = 12; return Convert.ToInt32(CharWidth + (lab_searchName.Font.Size > DefaultFontSize ? lab_searchName.Font.Size - DefaultFontSize : 0)); } #endregion #region 获取明细 /// /// 说明:获取报表明细 /// 创建人:王一帆 /// 创建日期:2021-06-16 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private List GetDetailGrids(string moduleCode = "") { List details = new List(); //DataTable moduleDetailBottomTable = BaseModuleImpl.GetBaseDetailPages(this.SysModel.ModuleCode); DataTable moduleDetailBottomTable = BaseModuleImpl.GetBaseDetailPages(moduleCode); if (moduleDetailBottomTable.Rows.Count == 0) { moduleDetailBottomTable = BaseModuleImpl.GetBaseAddTabDetail(moduleCode); } foreach (DataRow item in moduleDetailBottomTable.Rows) { // DataTable dtGridColumns2 = ReportImpl.GetReportDetailColumns(this.SysModel.ModuleCode, item["id"] + ""); DataTable dtGridColumns = ReportImpl.GetReportDetailColumns(moduleCode, item["id"] + ""); details.Add(new GridDetailModel(item, dtGridColumns, GridCustomColumnStruct.BaseDetailGridView)); } return details; } #endregion #region 初始化控件 /// /// 说明:初始化控件 /// 创建人:王一帆 /// 创建日期:2021-06-16 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void InitializeControl() { levitationPanel = new LevitationPanel(); this.Controls.Add(levitationPanel); levitationPanel.BringToFront(); levitationPanel.Hide(); this.panel1.Left = this.pl_search.Location.X + this.pl_search.Width + 10; this.labelTips.Location = new Point(this.panel1.Location.X + this.panel1.Width + 10, (this.pl_search.Height - this.labelTips.Height) / 2); this.ControlObj = new MyControl(); //this.ControlObj.InitControl(_dtFields, this.pl_Main_Center, false); DataRow ModelObj = MainImpl.GetSystemdllTab(this.GridMainModelObj[0].UnionModule); this.DetalModel = new ModuleModel(ModelObj); if (this.GridMainModelObj[0].IsReadOnly) { gcMain.SetReadOnlyColumns(this.GridMainModelObj[0].GridColumns, this.GridMainModelObj[0].GridCustomColumnKey); gcMain.SetGridRowColors(BaseModuleImpl.GetBaseGridRowColors(this.GridMainModelObj[0].FormKey)); } else { DataTable _gridColumns = BaseModuleImpl.GetBaseGridColumns(this.GridMainModelObj[0].UnionModule); DataTable _gridAllColumns = BaseModuleImpl.GetBaseGridAllColumns(this.GridMainModelObj[0].UnionModule); if (DetalModel.CanEdit) { this.gcMain.SetEditColumns(_gridColumns, GridCustomColumnStruct.BaseMainGridView + DetalModel.FormKey); } else { this.gcMain.SetReadOnlyColumns(_gridColumns, GridCustomColumnStruct.BaseMainGridView + DetalModel.FormKey); } } this.GridMainModelObj[0].SystemModel = DetalModel; gcMain.Tag = this.GridMainModelObj[0]; foreach (GridDetailModel detailModel in GridOtherModelObj) { DataTable rightTab = BaseModuleImpl.GetBaseGridRightMenus(detailModel.UnionModule); int right = plExpectBtn.Width - 10; int left = 10; switch (detailModel.Orderid)//通过明细数据源加载表格 { case 1://左侧表 if (detailModel.IsReadOnly) { gcLeftDetail.SetReadOnlyColumns(detailModel.GridColumns, detailModel.GridCustomColumnKey); gcLeftDetail.SetGridRowColors(BaseModuleImpl.GetBaseGridRowColors(detailModel.FormKey)); } else { ModuleModel newModuleModel = new ModuleModel(MainImpl.GetSystemdllTab(detailModel.UnionModule)); DataTable _gridColumns = BaseModuleImpl.GetBaseGridColumns(detailModel.UnionModule); DataTable _gridAllColumns = BaseModuleImpl.GetBaseGridAllColumns(detailModel.UnionModule); if (newModuleModel.CanEdit) { this.gcLeftDetail.SetEditColumns(_gridColumns, GridCustomColumnStruct.BaseMainGridView + newModuleModel.FormKey); } else { this.gcLeftDetail.SetReadOnlyColumns(_gridColumns, GridCustomColumnStruct.BaseMainGridView + newModuleModel.FormKey); } } break; case 2://产出表 if (detailModel.IsReadOnly) { gcOutput.SetReadOnlyColumns(detailModel.GridColumns, detailModel.GridCustomColumnKey); gcOutput.SetGridRowColors(BaseModuleImpl.GetBaseGridRowColors(detailModel.FormKey)); } else { ModuleModel newModuleModel = new ModuleModel(MainImpl.GetSystemdllTab(detailModel.UnionModule)); DataTable _gridColumns = BaseModuleImpl.GetBaseGridColumns(detailModel.UnionModule); DataTable _gridAllColumns = BaseModuleImpl.GetBaseGridAllColumns(detailModel.UnionModule); if (newModuleModel.CanEdit) { this.gcOutput.SetEditColumns(_gridColumns, GridCustomColumnStruct.BaseMainGridView + newModuleModel.FormKey); } else { this.gcOutput.SetReadOnlyColumns(_gridColumns, GridCustomColumnStruct.BaseMainGridView + newModuleModel.FormKey); } } gcOutput.Tag = detailModel; if (rightTab.Rows.Count > 0) { for (int i = 0; i < rightTab.Rows.Count; i++) { SweepButton sweepButton = new SweepButton(); DataRow item = rightTab.Rows[i]; GridRightMenuModel menuModel = new GridRightMenuModel(item); sweepButton.Parent = plOutRightBtn; sweepButton.TitleLabelObj.Text = menuModel.MenuName; sweepButton.Tag = menuModel; sweepButton.OnClick += new EventHandler(OnModuleClick); sweepButton.OnHover += new EventHandler(OnMouseMove); sweepButton.OnLeave += new EventHandler(OnMouseLeave); sweepButton.BackColor = ColorTranslator.FromHtml(_defaultColors[i % 4]);//背景颜色 sweepButton.emptyColor = ColorTranslator.FromHtml(_defaultColors[i % 4]); int top = Convert.ToInt32((plOutRightBtn.Height - sweepButton.Height) / 2); sweepButton.Top = top; sweepButton.Left = left; left += sweepButton.Width+ 10; } } break; case 3://余料表 if (detailModel.IsReadOnly) { gcExpected.SetReadOnlyColumns(detailModel.GridColumns, detailModel.GridCustomColumnKey); gcExpected.SetGridRowColors(BaseModuleImpl.GetBaseGridRowColors(detailModel.FormKey)); } else { ModuleModel newModuleModel = new ModuleModel(MainImpl.GetSystemdllTab(detailModel.UnionModule)); DataTable _gridColumns = BaseModuleImpl.GetBaseGridColumns(detailModel.UnionModule); DataTable _gridAllColumns = BaseModuleImpl.GetBaseGridAllColumns(detailModel.UnionModule); if (newModuleModel.CanEdit) { this.gcExpected.SetEditColumns(_gridColumns, GridCustomColumnStruct.BaseMainGridView + newModuleModel.FormKey); } else { this.gcExpected.SetReadOnlyColumns(_gridColumns, GridCustomColumnStruct.BaseMainGridView + newModuleModel.FormKey); } } gcExpected.Tag = detailModel; if (rightTab.Rows.Count > 0) { for (int i = rightTab.Rows.Count-1; i >= 0; i--) { SweepButton sweepButton = new SweepButton(); DataRow item = rightTab.Rows[i]; GridRightMenuModel menuModel = new GridRightMenuModel(item); sweepButton.Parent = plExpectBtn; sweepButton.TitleLabelObj.Text = menuModel.MenuName; sweepButton.Tag = menuModel; sweepButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); sweepButton.OnClick += new EventHandler(OnModuleClick); sweepButton.OnHover += new EventHandler(OnMouseMove); sweepButton.OnLeave += new EventHandler(OnMouseLeave); sweepButton.BackColor = ColorTranslator.FromHtml(_defaultColors[i % 4]);//背景颜色 sweepButton.emptyColor = ColorTranslator.FromHtml(_defaultColors[i % 4]); int top = Convert.ToInt32((plExpectBtn.Height - sweepButton.Height) / 2); sweepButton.Top = top; sweepButton.Left = right - sweepButton.Width; right = sweepButton.Left - 10; } } break; } } } #endregion #region 初始化扫码功能模块的明细数据 /// /// 说明:初始化扫码功能模块的明细数据 /// 创建人:王一帆 /// 创建日期:2021-06-16 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void InitializeDetailGrid() { if (_fontSize != 0) { decimal result = Math.Round((decimal)_fontSize / (decimal)12, 2);//缩放比 //this.plDetail.Width = Convert.ToInt32(this.plDetail.Width * result); //this.plDetail.Height = Convert.ToInt32(this.plDetail.Height * result); //this.panelDetail.Height = Convert.ToInt32(this.panelDetail.Height * result); //this.pl_Bottom.Width = Convert.ToInt32(this.pl_Bottom.Width * result); //this.Height = Convert.ToInt32(this.Height * result); // this.TabBottom.Height = Convert.ToInt32(this.TabBottom.Height * result); } if (GridDetailModelObjs.Count > 0) { this.detailTab.InitTabPages(GridDetailModelObjs, _fontSize); } else { this.splitDetail.PanelVisibility = SplitPanelVisibility.Panel1; } if (GridDetailRightObj.Count > 0) { this.TabRight.InitTabPages(GridDetailRightObj);//InitTabPages(GridDetailRightObj) } else { this.splitMain.PanelVisibility = SplitPanelVisibility.Panel1; } if (!string.IsNullOrEmpty(this._keyValue)) { SearchMainGrid(); } SetTabPageStyle(); //SweepIsUsable(); } #endregion #region 设置动态TabPage的样式 /// /// 说明:设置动态的TabPage的样式隐藏页签标题 /// 创建人:龚宇超 /// 创建日期:2018-02-27 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void SetTabPageStyle() { detailTab.TabControlObj.ShowTabHeader = detailTab.TabControlObj.TabPages.Count == 1 ? DefaultBoolean.False : DefaultBoolean.Default; TabRight.TabControlObj.ShowTabHeader = TabRight.TabControlObj.TabPages.Count == 1 ? DefaultBoolean.False : DefaultBoolean.Default; } #endregion #region 加载新数据源 /// /// 说明:加载新的数据 /// 创建人:王一帆 /// 创建日期:2021-06-21 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// 数据索引 private void LoadNewForm(DataRow dataRowItem) { if (isSearchRefresh || !SystemInfo.Instance.isRemberText) setTabPageGridData(TabRight, dataRowItem); //主明细数据源刷新 GridDetailModel detailModel = gcMain.Tag as GridDetailModel; gcMain.LastSearchSql = this.GetSearchSql(detailModel, dataRowItem); gcMain.SetGridViewDataSource(SqlHelper.ExecuteDataTable(gcMain.LastSearchSql)); this._keyValue = dataRowItem == null ? string.Empty : dataRowItem[this._primaryKey] + ""; } #endregion #region 设置选项卡数据源 /// /// 说明:设置选项卡数据源 /// 创建人:王一帆 /// 创建日期:2021-06-21 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void setTabPageGridData(TabControlEx tabDetail, DataRow rowItem) { foreach (XtraTabPage tabPage in tabDetail.TabControlObj.TabPages) { GridDetailModel model = tabDetail.GetGridDetailModel(tabPage); if (tabPage.Tag is ModuleWebView) { // 加载网页 string url = model.DetailSql.StartsWith("http") ? model.DetailSql : SystemInfo.Instance.OAUrl + model.DetailSql; ModuleWebView webView = tabPage.Tag as ModuleWebView; webView.Dock = DockStyle.Fill; webView.Tag = model; webView.Navigate(ReplaceHelper.ReplaceRowParam(rowItem, ReplaceHelper.ReplaceUserInfo(url))); } else { GridControlEx gridControl = tabPage.Tag as GridControlEx; gridControl.LastSearchSql = this.GetSearchSql(model, rowItem); tabDetail.SetGridDataSource(tabPage, MainImpl.GetDataTableResult(gridControl.LastSearchSql)); } } } #endregion #region 获取查询条件 /// /// 说明:获取查询条件 /// 创建人:龚宇超 /// 创建日期:2021-06-21 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The model. /// The row item. /// System.String. protected string GetSearchSql(GridDetailModel model, DataRow rowItem) { string fieldName = !string.IsNullOrEmpty(model.UnionParentField) ? model.UnionParentField : this.MoudleObj.ParmaryKey; string sqlValue = model.IsReadOnly ? model.DetailSql : model.SystemModel.MenuSql; string orderCond = _dicOrder.FirstOrDefault(o => o.Key == model.UnionModule).Value; if (rowItem == null) return ReplaceHelper.ReplaceWhereCond(sqlValue) + " and 1<>1"; if (ReplaceHelper.IsSelect(sqlValue) && !string.IsNullOrEmpty(model.UnionValue)) { sqlValue = ReplaceHelper.ReplaceWhereCond(sqlValue) + string.Format(" and {0}='{1}'", model.UnionValue, rowItem[fieldName] + ""); } sqlValue = ReplaceHelper.ReplaceRowParam(rowItem, sqlValue); return sqlValue + orderCond; } #endregion #region 公用刷新主表程序 /// /// 说明:主程序刷新方法 /// 创建人:王一帆 /// 创建日期:2021-06-21 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The model. /// The row item. /// System.String. public void SearchMainGrid(bool isFocus = false) { try { labelTips.Text = ""; //lab_TipsText = ""; string codeSql = "select"; bool isDoubleCode = false;//是否有多个条件 this.panel1.BackgroundImage = global::Lskj.MesPrintCode.Properties.Resources.message; panel1.BackColor = Color.FromArgb(65, 115, 188); string SearchCode = string.Empty; if (!string.IsNullOrEmpty(_searchCode)) { SearchCode = ReplaceHelper.ReplaceParamToValue(_searchCode, txtFixKey.Text); // 未替换的参数所有替换搜索值 codeSql += string.Format(" '{0}' as {1}", txtFixKey.Text, _searchFile); DataRow rowItem = ComBoxSource != null && ComBoxSource.Rows.Count > 0 ? ComBoxSource.Select("1=1").FirstOrDefault(x => txtEditClass.Text == x[ComDisplayMember] + "") : null; if (rowItem != null) { isDoubleCode = true; SearchCode += " " + ReplaceHelper.ReplaceParamToValue(_searchSecondCode, rowItem[ComValueMember] + ""); // 未替换的参数所有替换搜索值 codeSql += string.Format(",'{0}' as {1}", rowItem[ComValueMember] + "", _searchSecondFile); } LastRefreshSql = isDoubleCode ? ReplaceHelper.ReplaceRowParam(BaseImpl.GetDataRowResult(codeSql), this.MoudleObj.RefreshSql) : ReplaceHelper.ReplaceParamToValue(this.MoudleObj.RefreshSql, txtFixKey.Text); if (!string.IsNullOrEmpty(SysModel.unioParentKey) && !string.IsNullOrEmpty(SysModel.unioParentValue)) { SearchCode += string.Format(" and {0} = '{1}'", SysModel.unioParentKey, SysModel.unioParentValue); } _rowItem = BaseImpl.GetDataRowResult(ReplaceHelper.ReplaceWhereCond(this.MoudleObj.MenuSql) + " " + SearchCode); } else { string newSql = ReplaceHelper.ReplaceParamToValue(ReplaceHelper.ReplaceWhereCond(this.MoudleObj.MenuSql), txtFixKey.Text); if (!string.IsNullOrEmpty(SysModel.unioParentKey) && !string.IsNullOrEmpty(SysModel.unioParentValue)) { SearchCode += string.Format(" and {0} = '{1}'", SysModel.unioParentKey, SysModel.unioParentValue); } _rowItem = BaseImpl.GetDataRowResult(newSql+ SearchCode); } if (GridSweepRight != null && isFocus) { BaseRightMenu menu = new BaseRightMenu(); menu.Model = this.SysModel; if (!menu.ExecRightMenu(GridSweepRight, new DataRow[] { _rowItem }) && !GridSweepRight.Refresh) { MessageUtil.Show("执行扫码配置右键失败!"); return; } } IniAllControl(_rowItem, isFocus); } catch (Exception ex) { MessageUtil.Show(ex); } } #region 刷新所有界面数据 /// /// 说明:刷新所有界面数据 /// 创建人:王一帆 /// 创建日期:2021-07-04 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// public void IniAllControl(DataRow rowItem, bool isFocus) { if (rowItem != null) { if (tips != null && tips.Rows.Count > 0) { labelTips.Text = rowItem[tips.Rows[0]["fieldname"] + ""] + ""; //lab_TipsText = rowItem[tips.Rows[0]["fieldname"] + ""] + ""; } //for (int i = 0; i < sweepMidControl.Count; i++) //{ // if (sweepMidControl[i] is SweepControl) // { // SweepControl sweepControl = (sweepMidControl[i] as SweepControl); // DataRow item = sweepControl.Tag as DataRow; // string cond = ReplaceHelper.ReplaceRowParam(_rowItem, item["disableCond"] + ""); // bool isEnabled = string.IsNullOrEmpty(item["disableCond"] + "") ? true : ReplaceHelper.EvalCond(cond); // sweepControl.Enabled = isEnabled; // } // if (sweepMidControl[i] is SweepAutoEdit) // { // SweepAutoEdit sweepAutoEdit = (sweepMidControl[i] as SweepAutoEdit); // DataRow item = sweepAutoEdit.Tag as DataRow; // string cond = ReplaceHelper.ReplaceRowParam(_rowItem, item["disableCond"] + ""); // bool isEnabled = string.IsNullOrEmpty(item["disableCond"] + "") ? true : ReplaceHelper.EvalCond(cond); // sweepAutoEdit.Enabled = isEnabled; // } //} //foreach (System.Windows.Forms.Control control in detailplControl.Controls) //{ // if (control is SweepControl) // { // SweepControl sweepControl = (control as SweepControl); // sweepControl.ObjButtonEdit.Text = rowItem[sweepControl.Name] + ""; // } // if (control is SweepAutoEdit) // { // SweepAutoEdit sweepAutoEdit = (control as SweepAutoEdit); // sweepAutoEdit.EditValue = rowItem[sweepAutoEdit.Name] + ""; // } //} LoadNewForm(rowItem); //this.ControlObj.SetAllControlValue(rowItem); if (!SystemInfo.Instance.isRemberText) { this.txtFixKey.Text = string.Empty; } } else { _rowItem = null; this.ControlObj.ResetControlValue(); LoadNewForm(_rowItem); this.txtFixKey.Text = string.Empty; aftertxtFixKey = string.Empty; labelTips.Text = "该工单不存在!"; //lab_TipsText = "该工单不存在!"; this.panel1.BackgroundImage = global::Lskj.MesPrintCode.Properties.Resources.红喇叭; } SweepIsUsable(); } #endregion #endregion #region 扫码框执行的存储过程 /// /// 说明:生产过程随工单扫码验证 /// 创建人:龚宇超 /// 创建日期:2017-08-12 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// 模块编号. /// 扫码信息. /// 主键值. /// 用户Id. /// 用户名 /// 确认标记. /// 返回消息 /// 刷新页签 /// System.Int32. public static int ScanningCheckCard(string menuCode, string scanCode, string parmaryValue, string operatorId, string operatorName, int flag, string scanField, out string msgs, out string refreshPages, out string reRightButton) { SqlParameter msg = new SqlParameter("@msg", SqlDbType.VarChar, 2000); msg.Direction = ParameterDirection.Output; SqlParameter pageindex = new SqlParameter("@pageindex", SqlDbType.VarChar, 50); pageindex.Direction = ParameterDirection.Output; SqlParameter rightIndex = new SqlParameter("@actionIndex", SqlDbType.VarChar, 50); rightIndex.Direction = ParameterDirection.Output; SqlParameter returnValue = new SqlParameter("@return_value", SqlDbType.Int, 4); returnValue.Direction = ParameterDirection.ReturnValue; SqlParameter[] param = { new SqlParameter("@modid",SqlDbType.VarChar,10), new SqlParameter("@scanCode",SqlDbType.VarChar,50), new SqlParameter("@keyvalue",SqlDbType.VarChar,40), new SqlParameter("@operatorId",SqlDbType.Int,4), new SqlParameter("@operatorName",SqlDbType.VarChar,20), new SqlParameter("@comfirmFlag",SqlDbType.VarChar,500), new SqlParameter("@scanField",SqlDbType.VarChar,40), pageindex, rightIndex, msg, returnValue }; param[0].Value = menuCode; param[1].Value = scanCode; param[2].Value = parmaryValue; param[3].Value = operatorId; param[4].Value = operatorName; param[5].Value = flag; param[6].Value = scanField; SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, "p_mrp_ProcessScanning", "temp", param); msgs = msg.Value + ""; refreshPages = pageindex.Value + ""; reRightButton = rightIndex.Value + ""; return Convert.ToInt32(returnValue.Value); } #endregion #region 根据字体缩放大小 /// /// 说明:根据字体缩放大小 /// 创建人:曹屹峰 /// 创建日期:2021-07-04 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void ResizeControl() { _FormHeight = (double)(Screen.PrimaryScreen.Bounds.Height) / (double)1080; _FormWidth = (double)(Screen.PrimaryScreen.Bounds.Width) / (double)1920; if (_fontSize == 0) return; double result = Math.Round((double)_fontSize / (double)txtFixKey.Font.Size, 2);//缩放比 Font originalAttributes = this.lab_searchName.Font; this.lab_searchName.Font = new Font(originalAttributes.Name, _fontSize, FontStyle.Bold);//_fontSize; pl_search.Width = Convert.ToInt32(Math.Round((double)pl_search.Width * _FormWidth)); pl_search.Height = Convert.ToInt32((double)pl_search.Height * _FormHeight); pl_search.Top = Convert.ToInt32((double)pl_search.Top * _FormHeight); originalAttributes = this.txtFixKey.Font; txtFixKey.Font = new Font(originalAttributes.Name, _fontSize); //detailpl_Left.Width = Convert.ToInt32((double)detailpl_Left.Width * _FormWidth); //pl_TopSearch.Width = Convert.ToInt32(pl_TopSearch.Width * result); pl_TopSearch.Height = Convert.ToInt32((double)pl_TopSearch.Height * _FormHeight); panel1.Width = Convert.ToInt32((double)panel1.Width * _FormWidth); panel1.Height = Convert.ToInt32((double)panel1.Height * _FormHeight); panel1.Top = Convert.ToInt32((double)panel1.Top * _FormHeight); //lab_searchName.Top = Convert.ToInt32(lab_searchName.Top * result); //pl_MainState.Height = Convert.ToInt32((double)pl_MainState.Height * _FormHeight); //originalAttributes = this.labelControl5.Font; //labelControl5.Font = new Font(originalAttributes.Name, _fontSize, FontStyle.Bold); //labelControl5.Top = Convert.ToInt32((double)labelControl5.Top * _FormHeight); //originalAttributes = this.SweepTipStata.Font; //SweepTipStata.Font = new Font(originalAttributes.Name, _fontSize, FontStyle.Bold); //SweepTipStata.Top = Convert.ToInt32((double)SweepTipStata.Top * _FormHeight); detailTab_Title.Height = Convert.ToInt32((double)detailTab_Title.Height * _FormHeight); originalAttributes = this.lbTitle.Font; lbTitle.Font = new Font(originalAttributes.Name, _fontSize, FontStyle.Bold); Image image = txtFixKey.Properties.Buttons[0].Image; Size size = new Size(Convert.ToInt32((double)txtFixKey.Properties.Buttons[0].Image.Width * _FormWidth), Convert.ToInt32((double)txtFixKey.Properties.Buttons[0].Image.Height * _FormHeight)); txtFixKey.Properties.Buttons[0].Image = resizeImage(image, size); this.lab_searchName.Width = this.lab_searchName.Text.Length * GetCharWidth(); this.lab_searchClass.Width = this.lab_searchClass.Text.Length * GetCharWidth(); this.lab_searchName.Location = new Point(0, this.txtFixKey.Location.Y); //this.detailpl_Left.Width = Convert.ToInt32(this.Size.Width / 3.5); this.lab_searchClass.Font = new Font(originalAttributes.Name, _fontSize, FontStyle.Bold);//_fontSize; this.txtEditClass.Font = new Font(originalAttributes.Name, _fontSize); } #endregion #region 改变图片大小 /// /// 说明:改变图片大小 /// 创建人:曹屹峰 /// 创建日期:2021-07-04 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private static System.Drawing.Image resizeImage(System.Drawing.Image imgToResize, Size size) { //获取图片宽度 int sourceWidth = imgToResize.Width; //获取图片高度 int sourceHeight = imgToResize.Height; float nPercent = 0; float nPercentW = 0; float nPercentH = 0; //计算宽度的缩放比例 nPercentW = ((float)size.Width / (float)sourceWidth); //计算高度的缩放比例 nPercentH = ((float)size.Height / (float)sourceHeight); if (nPercentH < nPercentW) nPercent = nPercentH; else nPercent = nPercentW; //期望的宽度 int destWidth = (int)(sourceWidth * nPercent); //期望的高度 int destHeight = (int)(sourceHeight * nPercent); Bitmap b = new Bitmap(destWidth, destHeight); Graphics g = Graphics.FromImage((System.Drawing.Image)b); g.InterpolationMode = InterpolationMode.HighQualityBicubic; //绘制图像 g.DrawImage(imgToResize, 0, 0, destWidth, destHeight); g.Dispose(); return (System.Drawing.Image)b; } #endregion #region 扫码完成后判断右键是否可点击 /// /// 说明:扫码完成后判断右键是否可点击 /// 创建人:王一帆 /// 创建日期:2021-06-25 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// public void SweepIsUsable() { int i = 0; // 判断右键菜单是否可用 foreach (SweepButton sweepButton in detailControlBtn.Controls) { GridRightMenuModel model = sweepButton.Tag as GridRightMenuModel; if (_rowItem == null) { //sweepButton.Enabled = false; sweepButton.isEnable = false; sweepButton.BackColor = colorlist[i % 4];//背景颜色 } else { if (!string.IsNullOrWhiteSpace(model.MenuCond)) { try { string cond = ReplaceHelper.ReplaceRowParam(_rowItem, model.MenuCond); //sweepButton.Enabled = ReplaceHelper.EvalCond(cond); sweepButton.isEnable = ReplaceHelper.EvalCond(cond); sweepButton.BackColor = sweepButton.isEnable ? ColorTranslator.FromHtml(_defaultColors[i % 4]) : colorlist[i % 4]; } catch (Exception) { } } else { sweepButton.isEnable = false; sweepButton.BackColor = colorlist[i % 4]; } } i++; } } #endregion #endregion } }