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.SweepCodeExe.Control; using Lskj.SweepCodeExe.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; namespace Lskj.SweepCodeExe { public partial class FrmMain : BaseForm { /// /// 说明:初始化后构造方法 /// 创建人:王一帆 /// 创建日期:2021-06-15 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// public FrmMain() { InitializeComponent(); } #region 公共变量 /// /// 入口模型 /// public DynamicProductionModel SysModel; /// /// 扫码提示表 /// public DataTable tips; /// ///查询条件控件 /// public MyControl SearchObj; /// /// 主控件集 /// public MyControl ControlObj; /// /// 基础模型 /// public ModuleModel MoudleObj; /// /// 明细初始集合 /// public List GridInitDetailModel; /// /// 表格明细集合 /// public List GridDetailModelObjs; /// /// 明细衍生到下侧数据 /// public List GridDetailAddObj; /// /// 明细衍生到右侧数据 /// public List GridDetailRightObj; /// /// 右侧按钮数据字典 /// public Dictionary sweepDic = new Dictionary(); /// /// 中间输入控件数据字典 /// public Dictionary sweepMidControl = new Dictionary(); /// /// Occurs when [on top mouse down callback]. /// public event MouseEventHandler OnTopMouseDownCallback; /// /// Occurs when [on top mouse up call back]. /// public event MouseEventHandler OnTopMouseUpCallBack; /// /// Occurs when [on top mouse move call back]. /// public event MouseEventHandler OnTopMouseMoveCallBack; #endregion #region 私有变量 /// /// 子系统默认背景色 /// 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 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; /// /// 是否鼠标按下 /// private bool _isMouseDown; /// /// 记录窗口位置 /// private Point _mousePostion; #endregion #region 事件 #region 窗体加载时 /// /// 说明:窗体加载时 /// 创建人:王一帆 /// 创建日期:2021-06-15 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The instance containing the event data. protected override void OnLoad(EventArgs e) { WaitForm.ShowForm(); try { splitMain.SetPanelCollapsed(true);//初始折叠 _splitLocation = this.splitMain.SplitterPosition; this.splitMain.SplitGroupPanelCollapsed += new SplitGroupPanelCollapsedEventHandler(OnClickSplitBar); 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(); this.InitializeDetailGrid(); } } catch (Exception ex) { throw; } finally { } WaitForm.HideForm(); this.Location = new Point((Screen.PrimaryScreen.Bounds.Width - this.Width) / 2, (Screen.PrimaryScreen.Bounds.Height - this.Height) / 2); } #endregion #region 点击分割条展开右边明细 /// /// 说明:点击分割条展开右边明细 /// 创建人:王一帆 /// 创建日期:2021-06-16 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void OnClickSplitBar(object sender, SplitGroupPanelCollapsedEventArgs e) { if (this.Size.Width < _windowWidth) { this.Size = new Size(_windowWidth, this.Size.Height); } else { this.Size = new Size(_windowWidth - 200, 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 (!string.IsNullOrEmpty(_searchCode)) //{ // string SearchCode = ReplaceHelper.ReplaceParamToValue(_searchCode, txtFixKey.Text); // 未替换的参数所有替换搜索值 // _rowItem = BaseImpl.GetDataTableResult(ReplaceHelper.ReplaceWhereCond(this.MoudleObj.MenuSql + " " + SearchCode)).Rows[0]; //} //else //{ // _rowItem = BaseImpl.GetDataTableResult(ReplaceHelper.ReplaceWhereCond(this.MoudleObj.MenuSql + "and" + _primaryKey + "=" + txtFixKey.Text)).Rows[0]; //} if (_rowItem == null) { MessageUtil.Show("请查询工单号!"); return; } SweepIsUsable(); try { WaitForm.ShowForm(); SweepButton button = sender as SweepButton; if (button != null) { if (button.Tag is GridRightMenuModel) { GridRightMenuModel model = button.Tag as GridRightMenuModel; BaseRightMenu menu = new BaseRightMenu(); menu.Model = this.SysModel; if (model.DllName == "Lskj.FrmCompletion.dll") { // 保存流转步骤 FrmCompletion frmCompletion = new FrmCompletion(); List paramList = new List(); paramList = this.HandleRightMenuParams(model.ParamList, _rowItem); frmCompletion.finishWork(this.SysModel.ModuleCode, _rowItem, SysModel, paramList, LastRefreshSql); if (frmCompletion.ShowDialog() == DialogResult.OK) { if (!string.IsNullOrWhiteSpace(LastRefreshSql)) { _rowItem = BaseImpl.GetDataRowResult(LastRefreshSql); IniAllControl(_rowItem, false); } else { Refresh(null, true); } } } else { if (menu.ExecRightMenu(model, new DataRow[] { _rowItem }) && model.Refresh) { if (!string.IsNullOrWhiteSpace(LastRefreshSql)) { _rowItem = BaseImpl.GetDataRowResult(LastRefreshSql); IniAllControl(_rowItem, false); } else { Refresh(null, true); } } } } } } catch (Exception ex) { MessageUtil.Show(ex); } 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) { 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('&'); 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; int key = 0; for (int i = 0; i < sweepMidControl.Count; i++) { if (sweepMidControl[i] == FocusControl) key = i; break; } if (key == 0) { sweepMidControl[1].Focus(); } else if (key == 1) { sweepMidControl[2].Focus(); } } else { SearchMainGrid(true); } } catch (Exception ex) { MessageUtil.Show(ex); } } } #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(); } sweepMidControl[2].Focus(); } } } catch (Exception ex) { MessageUtil.Show(ex); } } #endregion #region 窗体关闭事件 /// /// 说明:窗体关闭事件 /// 创建人:王一帆 /// 创建日期:2021-06-25 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void OnbtnCloseClick(object sender, EventArgs e) { this.Dispose(); } #endregion #region 窗体最小化事件 /// /// 说明:窗体最小化事件 /// 创建人:王一帆 /// 创建日期:2021-06-25 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void OnBtnFormMix(object sender, EventArgs e) { this.WindowState = FormWindowState.Minimized; } #endregion #region 窗口移动事件 private void OnTopMouseDown(object sender, MouseEventArgs e) { base.OnMouseDown(e); _mousePostion = Cursor.Position; _isMouseDown = true; } private void OnTopMouseMove(object sender, MouseEventArgs e) { base.OnMouseMove(e); if (_isMouseDown) { Point tempPos = Cursor.Position; this.Location = new Point(Location.X + (tempPos.X - _mousePostion.X), Location.Y + (tempPos.Y - _mousePostion.Y)); _mousePostion = Cursor.Position; } } private void OnTopMouseUp(object sender, MouseEventArgs e) { base.OnMouseUp(e); _isMouseDown = false; this.Focus(); } #endregion #endregion #region 方法 #region 刷新 /// /// 说明:刷新 /// 创建人:龚宇超 /// 创建日期:2018-02-28 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void Refresh(string[] pageIndexs, bool isRefresh = false) { int selectdetailTabIndex = 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 GridDetailAddObj) { string sqlValue = this.GetSearchSql(gridmodel, _rowItem); if (isRefresh || pageIndexs.Contains(gridmodel.Orderid + "")) { this.TabBottom.TabControlObj.SelectedTabPage = this.TabBottom.TabControlObj.TabPages.Where(o => o.Text == gridmodel.DetailName).FirstOrDefault(); if (this.TabBottom.TabControlObj.SelectedTabPage == null) this.TabBottom.TabControlObj.SelectedTabPage = this.TabBottom.TabControlObj.TabPages[0]; this.TabBottom.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 扫码调用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() { this._primaryKey = BaseImpl.GetBasePrimaryKey(this.SysModel.ModuleCode); this.MoudleObj = new ModuleModel(MainImpl.GetSystemdllTab(this.SysModel.ModuleCode)); //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); this.MoudleObj.ParmaryKey = BaseImpl.GetBasePrimaryKey(this.SysModel.ModuleCode); DataTable queryTable = BaseModuleImpl.GetCustomQueryFields(this.MoudleObj.CondKey); if (queryTable != null && queryTable.Rows.Count > 0) { _searchFile = queryTable.Rows[0]["fieldName"] + ""; _searchCode = queryTable.Rows[0]["checkCond"] + ""; this.lab_searchName.Text = queryTable.Rows[0]["userName"] + ""; } this.GridInitDetailModel = GetDetailGrids(); this.GridDetailModelObjs = GridInitDetailModel.Where(o => o.displayMode != 1 && o.rightVisible != 1 && o.Orderid != 100).ToList(); this.GridDetailAddObj = GridInitDetailModel.Where(o => o.displayMode == 1).ToList(); this.GridDetailRightObj = GridInitDetailModel.Where(o => o.rightVisible == 1).ToList(); 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 = BaseModuleImpl.GetBaseGridRightMenus(this.SysModel.ModuleCode); this.TabRight.Model = this.TabBottom.Model = this.detailTab.Model = this.SysModel; if (!string.IsNullOrEmpty(this.SysModel.ParmaryValue)) { this.txtFixKey.Text = this._keyValue = this.SysModel.ParmaryValue; } } #endregion #region 获取明细 /// /// 说明:获取报表明细 /// 创建人:王一帆 /// 创建日期:2021-06-16 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private List GetDetailGrids() { List details = new List(); DataTable moduleDetailBottomTable = BaseModuleImpl.GetBaseDetailPages(this.SysModel.ModuleCode); if (moduleDetailBottomTable.Rows.Count == 0) { moduleDetailBottomTable = BaseModuleImpl.GetBaseAddTabDetail(this.SysModel.ModuleCode); } foreach (DataRow item in moduleDetailBottomTable.Rows) { DataTable dtGridColumns = ReportImpl.GetReportDetailColumns(this.SysModel.ModuleCode, item["id"] + ""); details.Add(new GridDetailModel(item, dtGridColumns, GridCustomColumnStruct.BaseDetailGridView)); } return details; } #endregion #region 初始化控件 /// /// 说明:初始化控件 /// 创建人:王一帆 /// 创建日期:2021-06-16 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void InitializeControl() { this.ControlObj = new MyControl(); this.ControlObj.InitControl(_dtFields, this.pl_Main_Center, false); int top = 0; int left = 0; this.pl_Main.Height = Convert.ToInt32(pl_Main.Height * _FormHeight); double result = (Screen.PrimaryScreen.Bounds.Height * Screen.PrimaryScreen.Bounds.Width) / (double)(1080 * 1920); result = result == 1 ? result : result * 1.5; if (_codeFields.Rows.Count > 0) { for (int i = 0; i < _codeFields.Rows.Count; i++) { top += Convert.ToInt32((17 * _FormHeight)); DataRow item = _codeFields.Rows[i]; if (!string.IsNullOrEmpty(item["fieldsql"] + "")) { SweepAutoEdit sweepControl = new SweepAutoEdit(); sweepControl.orderId = i + ""; sweepControl.Parent = detailplControl; sweepControl.TitleLabelObj.Text = item["username1"] + ""; sweepControl.ValueMember = sweepControl.ValueField = item["fieldsqlid"] + ""; ; sweepControl.TextMember = item["fieldsqlname"] + ""; ; sweepControl.SourceSQL = item["fieldsql"] + ""; sweepControl.DataSource = MainImpl.GetDataTableResult(item["fieldsql"] + ""); sweepControl.Top = top; //sweepControl.Left = Convert.ToInt32(32 * _FormWidth); sweepControl.Tag = item; sweepControl.Width = Convert.ToInt32(this.detailpl_Left.Width * 0.7 * _FormWidth); sweepControl.OnEnterAfterback += OnEnterAfterCell; sweepControl.Name = item["fieldname"] + ""; sweepControl.ControlObj = this.ControlObj; sweepControl.Height = Convert.ToInt32(sweepControl.Height * _FormHeight) + 5; sweepControl.FontSize = Convert.ToInt32((double)10.5 * result); Image image = sweepControl.TextEdit.Properties.Buttons[0].Image; Size size = new Size(Convert.ToInt32(sweepControl.TextEdit.Properties.Buttons[0].Image.Width * _FormWidth), Convert.ToInt32(sweepControl.TextEdit.Properties.Buttons[0].Image.Height * _FormHeight)); sweepControl.TextEdit.Properties.Buttons[0].Image = resizeImage(image, size); sweepControl.Popup.Width = Convert.ToInt32(sweepControl.Popup.Width * _FormWidth); sweepControl.Popup.Height = Convert.ToInt32(sweepControl.Popup.Height * _FormHeight); sweepControl.Popup.GridViewObj.Appearance.Row.Font = new System.Drawing.Font("Microsoft YaHei UI", (float)(10.5 * result)); //sweepControl.Popup.GridViewObj.Appearance.Row.Font = new System.Drawing.Font("Microsoft YaHei UI", (float)(sweepControl.Popup.GridViewObj.Appearance.Row.Font.Size * result)); top += sweepControl.Height; sweepMidControl.Add(i, sweepControl); } else { SweepControl sweepControl = new SweepControl(); sweepControl.orderId = i + ""; sweepControl.Parent = detailplControl; sweepControl.TitleLabelObj.Text = item["username1"] + ""; sweepControl.Top = top; //sweepControl.Left = Convert.ToInt32(32 * _FormWidth); sweepControl.Width = Convert.ToInt32(this.detailpl_Left.Width * 0.7 * _FormWidth); sweepControl.Tag = item; sweepControl.KeyDown += OnKeyDown; sweepControl.Name = item["fieldname"] + ""; sweepControl.Height = Convert.ToInt32(sweepControl.Height * _FormHeight) + 5; sweepControl.FontSize = Convert.ToInt32((double)10.5 * result); Image image = sweepControl.ObjButtonEdit.Properties.Buttons[0].Image; Size size = new Size(Convert.ToInt32(sweepControl.ObjButtonEdit.Properties.Buttons[0].Image.Width * _FormWidth), Convert.ToInt32(sweepControl.ObjButtonEdit.Properties.Buttons[0].Image.Height * _FormHeight)); sweepControl.ObjButtonEdit.Properties.Buttons[0].Image = resizeImage(image, size); top += sweepControl.Height; sweepMidControl.Add(i, sweepControl); } } } this.detailContorl.Height = top + Convert.ToInt32(15 * _FormHeight); ; if (_RightFields.Rows.Count > 0) { top = 22; left = 34; for (int i = 0; i < _RightFields.Rows.Count; i++) { SweepButton sweepButton = new SweepButton(); DataRow item = _RightFields.Rows[i]; GridRightMenuModel menuModel = new GridRightMenuModel(item); sweepButton.Parent = detailControl_Right; sweepButton.TitleLabelObj.Text = menuModel.MenuName; sweepButton.Tag = menuModel; sweepButton.OnClick += new EventHandler(OnModuleClick); sweepButton.BackColor = ColorTranslator.FromHtml(_defaultColors[i % 4]);//背景颜色 sweepButton.Width = Convert.ToInt32(sweepButton.Width * _FormWidth); sweepButton.Height = Convert.ToInt32(sweepButton.Height * _FormHeight); sweepButton.FontSize = Convert.ToInt32((double)10.5 * result); if (i % 2 == 0) { if (i != 0) { left += Convert.ToInt32(34 * _FormWidth) + sweepButton.Width; top -= (sweepButton.Height + Convert.ToInt32(22 * _FormHeight)); } } else { top += sweepButton.Height + Convert.ToInt32(22 * _FormHeight); } sweepButton.Top = top; sweepButton.Left = left; sweepDic.Add(menuModel.OrderId, sweepButton); } } } #endregion #region 初始化扫码功能模块的明细数据 /// /// 说明:初始化扫码功能模块的明细数据 /// 创建人:王一帆 /// 创建日期:2021-06-16 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void InitializeDetailGrid() { //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.pl_Bottom.Height = Convert.ToInt32(this.pl_Bottom.Height * _FormHeight); //this.Height = Convert.ToInt32(this.Height * result); // this.TabBottom.Height = Convert.ToInt32(this.TabBottom.Height * result); this.detailTab.InitTabPages(GridDetailModelObjs); this.TabBottom.InitTabPages(GridDetailAddObj); this.TabRight.InitTabPages(GridDetailRightObj);//InitTabPages(GridDetailRightObj) 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; TabBottom.TabControlObj.ShowTabHeader = TabBottom.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) { //三部分明细数据源更新 setTabPageGridData(detailTab, dataRowItem); setTabPageGridData(TabBottom, dataRowItem); setTabPageGridData(TabRight, dataRowItem); this.ControlObj.SetAllControlValue(dataRowItem); 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] + ""); } else { 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 { lab_Tips.Text = ""; if (!string.IsNullOrEmpty(_searchCode)) { string SearchCode = ReplaceHelper.ReplaceParamToValue(_searchCode, txtFixKey.Text); // 未替换的参数所有替换搜索值 LastRefreshSql = ReplaceHelper.ReplaceParamToValue(this.MoudleObj.RefreshSql, txtFixKey.Text); _rowItem = BaseImpl.GetDataRowResult(ReplaceHelper.ReplaceWhereCond(this.MoudleObj.MenuSql) + " " + SearchCode); } else { _rowItem = BaseImpl.GetDataTableResult(ReplaceHelper.ReplaceWhereCond(this.MoudleObj.MenuSql + "and" + _primaryKey + "=" + txtFixKey.Text)).Rows[0]; } 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) lab_Tips.Text = rowItem[tips.Rows[0]["fieldname"] + ""] + ""; 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 (isFocus) { SweepControl sweepControl = this.detailplControl.Controls.Cast().FirstOrDefault(x => x.orderId == "0"); sweepControl.ObjButtonEdit.Focus(); } sweepMidControl[0].Focus(); } else { _rowItem = null; this.ControlObj.ResetControlValue(); LoadNewForm(_rowItem); SweepIsUsable(); this.txtFixKey.Text =string.Empty; this.lab_Tips.Text = "该工单不存在!"; } 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);//缩放比 double result = (Screen.PrimaryScreen.Bounds.Height * Screen.PrimaryScreen.Bounds.Width) / (double)(1080 * 1920); result = result == 1 ? result : result * 1.5; this.Size = new Size(Convert.ToInt32(1310 * _FormWidth), Convert.ToInt32(900 * _FormHeight)); this.splitMain.SplitterPosition = this.Size.Width;//设置分割条位置 _windowWidth = this.Size.Width + 200; this.detailpl_Left.Width = Convert.ToInt32(this.Width * 0.7); this.pl_Main.Width = Convert.ToInt32(this.pl_Main.Width * _FormWidth); this.pl_Main.Height = Convert.ToInt32(this.pl_Main.Height * _FormHeight); this.pl_topTilte.Height = Convert.ToInt32(this.pl_topTilte.Height * _FormHeight); btnClose.Width = Convert.ToInt32(btnClose.Width * _FormWidth); btnClose.Height = Convert.ToInt32(btnClose.Height * _FormHeight); btnClose.Font = new Font("微软雅黑", (float)(this.btnClose.Font.Size * result)); btnFormMix.Width = Convert.ToInt32(btnFormMix.Width * _FormWidth); btnFormMix.Height = Convert.ToInt32(btnFormMix.Height * _FormHeight); btnFormMix.Font = new Font("微软雅黑", (float)(this.btnFormMix.Font.Size * result)); labelControl1.Font = new Font("微软雅黑", (float)(this.labelControl1.Font.Size * result)); this.lab_searchName.Font = new Font("微软雅黑", (float)(this.lab_searchName.Font.Size * result), FontStyle.Bold);//_fontSize; workOrderNoPanel.Width = Convert.ToInt32(Math.Round((double)workOrderNoPanel.Width * _FormWidth)); workOrderNoPanel.Height = Convert.ToInt32((double)workOrderNoPanel.Height * _FormHeight); workOrderNoPanel.Top = Convert.ToInt32((double)workOrderNoPanel.Top * _FormHeight); txtFixKey.Font = new Font("微软雅黑", (float)(txtFixKey.Font.Size * result)); 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); labelControl5.Font = new Font("微软雅黑", (float)(labelControl5.Font.Size * result), FontStyle.Bold); labelControl5.Top = Convert.ToInt32((double)labelControl5.Top * _FormHeight); labelControl3.Font = new Font("微软雅黑", (float)(labelControl3.Font.Size * result), FontStyle.Bold); labelControl3.Top = Convert.ToInt32((double)labelControl3.Top * _FormHeight); detailTab_Title.Height = Convert.ToInt32((double)detailTab_Title.Height * _FormHeight); lbTitle.Font = new Font("微软雅黑", (float)(lbTitle.Font.Size * result), FontStyle.Bold); pl_Bottom_Title.Height = Convert.ToInt32((double)pl_Bottom_Title.Height * _FormHeight); label1.Font = new Font("微软雅黑", (float)(label1.Font.Size * result), 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); } #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 detailControl_Right.Controls) { GridRightMenuModel model = sweepButton.Tag as GridRightMenuModel; if (_rowItem == null) { sweepButton.Enabled = false; sweepButton.BackColor = ColorTranslator.FromHtml("#D1D1D1");//背景颜色 } else { if (!string.IsNullOrWhiteSpace(model.MenuCond)) { try { string cond = ReplaceHelper.ReplaceRowParam(_rowItem, model.MenuCond); sweepButton.Enabled = ReplaceHelper.EvalCond(cond); sweepButton.BackColor = sweepButton.Enabled ? ColorTranslator.FromHtml(_defaultColors[i % 4]) : ColorTranslator.FromHtml("#D1D1D1"); } catch (Exception) { } } } i++; } } #endregion #endregion } }