using DevExpress.Utils; using DevExpress.XtraEditors; using DevExpress.XtraGrid.Columns; using DevExpress.XtraGrid.Views.Grid; 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.ProductBarCode2 { public partial class FrmMain : BaseForm { /// /// 左侧树数据 /// public DataRow LeftRowObj; /// /// 主键名 /// private string _primaryLeftKey; /// /// 表格对象 /// /// The grid view object. public GridControlEx GridControlObj { get { return (xtc_container.SelectedTabPage.Tag as FrmMainModule).GridControlObj; } } /// /// 表格对象 /// /// The grid view object. public GridControlEx gcBottom { get { return (xtc_container.SelectedTabPage.Tag as FrmMainModule).GcBottom; } } /// /// 必须录入字段 /// private DataRow[] _nullFields = new DataRow[] { }; /// /// 基础模型 /// public ModuleModel MoudleObj { get { return (xtc_container.SelectedTabPage.Tag as FrmMainModule).MoudleObj; } } /// /// 底部基础模型 /// public ModuleModel MoudleBottomObj { get { return (xtc_container.SelectedTabPage.Tag as FrmMainModule).MoudleBottomObj; } } /// /// 表格明细集合 /// public List GridDetailModelObjs; /// /// 控件源数据 /// private DataTable _dtFields; /// /// 单据信息 /// private DataRow _drBillInfo{ get { return (xtc_container.SelectedTabPage.Tag as FrmMainModule)._drBillInfo; } } /// /// 单据模型 /// public BillModel BillModelObj; public DynamicBarCodeModel SysModel; public DynamicModuleModel dmoudelModel; /// /// 单表模型 /// public DynamicModuleModel moudelModel; /// /// 控件对象 /// public MyControl ControlObj { get { return (xtc_container.SelectedTabPage.Tag as FrmMainModule).ControlObj; } } /// /// 控件高度 /// /// The height of the control. public int ControlHeight { get; private set; } /// /// 控件数据源 /// private DataTable _controlTable; /// /// 单据明细列 /// private DataTable _detailColumns; /// /// 单据关联字段 /// public string BillRelation; /// /// 单据明细id /// public int MxId; /// /// 设置红蓝单据 /// public string BillStatus; /// /// 单据名称 /// public string typename; /// /// 左侧表格查询条件 /// private MyControl _leftGridSearchObj; /// /// 传入的参数 /// public string[] IncomingParameters; /// /// 右侧页签存的模块号和对应的顺序 /// public Dictionary TabInformation = new Dictionary(); public FrmMain() { InitializeComponent(); } protected override void OnLoad(EventArgs e) { try { SetInterfaceState();//设置界面状态 SetLeftGridView(); InitializeSetting(); SelectSettingsRows();//加载左侧数据源和设置左侧选中行 } catch (Exception ex) { LogHelper.Instance.WriteError(ex); //MessageUtil.Show(ex); string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message,ex.Message); } finally { Lskj.Control.Model.AutoSizeChange.ControllInitializeSize(this); WaitForm.HideForm(); } } /// /// 说明:判断是否终审,加载界面是否可以编辑 /// 创建人:龚宇超 /// 创建日期:2017-10-25 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// protected void SetInterfaceState() { try { this.BillModelObj = new BillAuditModel(BillImpl.GetBillInfo(this.SysModel.ModuleCode)); this.BillModelObj.MasterPreFix = BaseImpl.GetColumnPrefix(this.BillModelObj.MasterTable); this.BillModelObj.DetailPreFix = BaseImpl.GetColumnPrefix(this.BillModelObj.DetailTable); } catch (Exception) { throw; } } /// /// 说明:设置左侧表格数据 /// 创建人:龚宇超 /// 创建日期:2017-10-25 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// protected void SetLeftGridView() { this.LeftRowObj = BaseModuleImpl.GetBaseLeftTreeField(this.SysModel.MoudelId); if (this.LeftRowObj != null) { DataTable dtTable = BaseModuleImpl.GetBaseLeftGridField(this.SysModel.MoudelId); DataTable dtColorTable = BaseModuleImpl.GetBaseGridRowColors(this.LeftRowObj["fieldKey"] + ""); BillRelation = "{" + this.LeftRowObj["fieldsqlname"] + "}"; this.gcLeft.GridView.FocusedRowObjectChanged += OnGridViewRowClick; //this.gcLeft.GridView.RowClick += new DevExpress.XtraGrid.Views.Grid.RowClickEventHandler(OnGridViewRowClick); this.gcLeft.SetGridRowColors(dtColorTable); this.gcLeft.SetReadOnlyColumns(dtTable, GridCustomColumnStruct.BaseLeftGridView + this.SysModel.MoudelId); } typename = SqlHelper.ExecuteScalar(string.Format("select replace(typename,'单','') as typename from p_systembilltype where typecode='{0}'", this.SysModel.ModuleCode)) + ""; } #region 初始化属性 /// /// 说明:初始化属性设置 /// 创建人:龚宇超 /// 创建日期:2018-02-27 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void InitializeSetting() { XtraTabPage page = new XtraTabPage(); page.Text = IncomingParameters[9]; FrmMainModule frmMainModule = new FrmMainModule(); frmMainModule.BillModelObj = BillModelObj; frmMainModule.SysModel = this.SysModel; frmMainModule.gridLeft = this.gcLeft; frmMainModule.Dock = DockStyle.Fill; if (this.LeftRowObj != null) { frmMainModule.ModuleGridEx.ParentKeyField = this.LeftRowObj["fieldsqlid"] + ""; frmMainModule.ModuleGridEx.ParentUnionField = this.LeftRowObj["fieldname"] + ""; frmMainModule.GcBottom.GridView.DoubleClick += new EventHandler(OnGridViewDoubleClick); } frmMainModule.initial(); page.Tag = frmMainModule; page.Controls.Add(frmMainModule); this.xtc_container.TabPages.Add(page); this.TabInformation.Add(page.Text, this.xtc_container.TabPages.Count-1); this.xtc_container.ShowTabHeader = DefaultBoolean.False; this.xtc_container.SelectedPageChanged -= Xtc_container_SelectedPageChanged; this.xtc_container.SelectedPageChanged += Xtc_container_SelectedPageChanged; } //页签切换时刷新 private void Xtc_container_SelectedPageChanged(object sender, DevExpress.XtraTab.TabPageChangedEventArgs e) { if (xtc_container.SelectedTabPage.Tag is FrmMainModule) { FrmMainModule frmMainModule = xtc_container.SelectedTabPage.Tag as FrmMainModule; this.gcLeft.Model = frmMainModule.SysModel; this.gcLeft.ParentControl = frmMainModule.ControlObj; DataRow rowArray = this.gcLeft.GetViewFocusedDataRow(); if (!string.IsNullOrWhiteSpace(SysModel.DefaultEnabled) && rowArray.Table.Columns.Contains(SysModel.DefaultEnabled)) { string varlue = rowArray[SysModel.DefaultEnabled] + ""; if (varlue.Equals("0")) { frmMainModule.SetPermissions(true); } else if (varlue.Equals("1")) { frmMainModule.SetPermissions(false); } } } } #endregion /// /// 创建条码控件 /// private void InitControls() { } #region 修改表头 /// /// 说明:获取配置条件头属性设置 /// 创建人:王一帆 /// 创建日期:2021-09-07 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// System.String. private void SetCodeHeader(DataRow newRow) { StringBuilder updateBuilder = new StringBuilder(); foreach (ControlModel model in this.ControlObj.ControlModels) { if (!string.IsNullOrEmpty(model.DefaultValue)) { bool isStart = model.DefaultValue.StartsWith("{"); string fieldName = model.DefaultValue.Replace("{", "").Replace("}", ""); if (newRow!=null&&newRow.Table.Columns.Contains(fieldName)) { this.ControlObj.SetControlValue(model.FieldName, newRow[fieldName] + ""); } else { this.ControlObj.SetControlValue(model.FieldName, isStart ? string.Empty : model.DefaultValue); } } } } #endregion /// /// 说明:条码点击加载详细条码 /// 创建人:王一帆 /// 创建日期:2020-01-07 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void OnGridViewRowClick(object sender, EventArgs e) { try { DataRow rowArray = this.gcLeft.GetViewFocusedDataRow(); if (!string.IsNullOrWhiteSpace(SysModel.ModuleNumber) &&rowArray.Table.Columns.Contains(SysModel.ModuleNumber)) { if (!IncomingParameters[9].Equals(rowArray[SysModel.ModuleNumber] + "")) { string key=IncomingParameters[9] = rowArray[SysModel.ModuleNumber] + ""; int value = 0; if (TabInformation.TryGetValue(key, out value)) { //页签中已经存在,直接切换页签 this.xtc_container.SelectedTabPageIndex = value; } else { //添加新页签 SysModel = new DynamicBarCodeModel(IncomingParameters); InitializeSetting(); if (this.xtc_container.SelectedTabPageIndex == this.xtc_container.TabPages.Count - 1) Xtc_container_SelectedPageChanged(null,null); this.xtc_container.SelectedTabPageIndex = this.xtc_container.TabPages.Count - 1; } } } SetCodeHeader(rowArray); string detailSql = ReplaceHelper.ReplaceRowParam(rowArray, this.MoudleObj.MenuSql); string BatchBarCodeViewSql = ReplaceHelper.ReplaceRowParam(rowArray, this.MoudleBottomObj.MenuSql); BatchBarCodeViewSql = ReplaceHelper.ReplaceRowParam(_drBillInfo, BatchBarCodeViewSql); this.GridControlObj.LastSearchSql = detailSql; this.GridControlObj.SetGridViewDataSource(MainImpl.GetAdapterResult(this.GridControlObj.LastSearchSql)); this.gcBottom.LastSearchSql = BatchBarCodeViewSql; this.gcBottom.SetGridViewDataSource(MainImpl.GetAdapterResult(this.gcBottom.LastSearchSql)); } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message,ex.Message); } } /// /// 说明:删除主程序后刷新所有界面 /// 创建人:王一帆 /// 创建日期:2020-01-30 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. protected void OnDelCallBackEven(object sender, EventArgs e) { try { this.GridControlObj.SetGridViewDataSource(MainImpl.GetAdapterResult(this.GridControlObj.LastSearchSql)); this.gcBottom.SetGridViewDataSource(MainImpl.GetAdapterResult(this.gcBottom.LastSearchSql)); MessageUtil.Show("刷新成功!"); } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message,ex.Message); } } /// /// 说明:增加条码后,刷新规则按照上一次查询条件刷新 /// 创建人:王一帆 /// 创建日期:2020-01-30 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. protected void OnGridAddCallBack(object sender, EventArgs e) { //if (this.addControl.addbtnSql == null) return; //int refreshTypes = SqlHelper.ExecuteNonQuery(this.addControl.addbtnSql); //if (refreshTypes == 1) //{ // this.gcMain.SetGridViewDataSource(MainImpl.GetAdapterResult(this.gcMain.LastSearchSql)); // this.gcBottom.SetGridViewDataSource(MainImpl.GetAdapterResult(this.gcBottom.LastSearchSql)); // MessageUtil.Show("成功!"); //} } /// /// 说明:条码点击需要生产的条码 /// 创建人:王一帆 /// 创建日期:2020-01-07 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void OnGridViewDoubleClick(object sender, EventArgs e) { int successQuantity = 0;//执行成功条数 int AllQuantity = 0;//全部条数 string mag = string.Empty; try { string msgs = string.Empty; //DataRow dr = this.gcBottom.GetViewFocusedDataRow(); DataRow[] dataRows = this.gcBottom.GetViewFocusedDataRows(); AllQuantity = dataRows.Length; if (this.SysModel.Required.Equals("1") && dataRows.Length == 0) { return; } foreach (DataRow dr in dataRows) { DataRow rowArray = this.gcLeft.GetViewFocusedDataRow(); string sql = this.ControlObj.ReplaceControlValue(this.SysModel.AddbtnSql); sql = ReplaceHelper.ReplaceRowParam(rowArray, sql); sql = ReplaceHelper.ReplaceRowParam(dr, sql); string result = SqlHelper.ExecuteScalar(sql) + ""; if (result == "1") { successQuantity++; } else { mag += result + "\r\n"; } } } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } finally { if (successQuantity>0) { this.GridControlObj.SetGridViewDataSource(MainImpl.GetAdapterResult(this.GridControlObj.LastSearchSql)); this.gcBottom.SetGridViewDataSource(MainImpl.GetAdapterResult(this.gcBottom.LastSearchSql)); if(AllQuantity== successQuantity&& !this.SysModel.CancelPrompt) MessageUtil.Show("成功!"); } if (AllQuantity > successQuantity) { MessageUtil.Show(mag); } } } /// /// 界面关闭事件 /// /// /// private void FrmMain_FormClosing(object sender, FormClosingEventArgs e) { try { DataRow rowArray = this.gcLeft.GetViewFocusedDataRow(); string sql = ReplaceHelper.ReplaceRowParam(rowArray, this.SysModel.ClosebtnSql); string result = SqlHelper.ExecuteScalar(sql) + ""; if (result == "1") { e.Cancel = false;//取消关闭事件 } else { this.DialogResult = MessageUtil.Show(string.Format(result), MessageBoxButtons.YesNo); if (this.DialogResult == DialogResult.No) { e.Cancel = true;//取消关闭事件 } } } catch (Exception) { this.Dispose(); } } /// ///左侧表格选中设置行 /// /// /// private void SelectSettingsRows() { try { //设置左侧数据源 string detailSql = ReplaceHelper.ReplaceParamToValue(this.BillModelObj.DetailSql + " " + SysModel.LeftCondition, this.SysModel.BillDocumentId); //设置左侧条件和加载左侧表数据源 if (this.LeftRowObj != null) { DataTable table = BaseModuleImpl.GetCustomQueryFields(this.LeftRowObj["fieldKey"] + ""); string searchSql = detailSql + " "; if (table != null && table.Rows.Count > 0) { // 自定义查询条件 this._leftGridSearchObj = new MyControl(searchSql, this.gcLeft); this.pl_left_top.Height = this._leftGridSearchObj.InitSearchControl(table, this.pl_left_top); this._leftGridSearchObj.OnDataSourceBindCallBack += new EventHandler(OnLeftControlObjDataSourceBindCallBack); } else { this.pl_left_top.Visible = false; this.gcLeft.SetGridViewDataSource(BaseImpl.GetDataTableResult(detailSql)); } } else { this.gcLeft.SetGridViewDataSource(BaseImpl.GetDataTableResult(detailSql)); } //设置选中行 if (!string.IsNullOrWhiteSpace(this.SysModel.SelectionCriteria)) { DataTable dt = this.gcLeft.gridControl.DataSource as DataTable; DataRow[] dataRows = dt.Select(this.SysModel.SelectionCriteria); if (dt.Rows.Count > 0 && dataRows.Length > 0) { for (int i = 0; i < dt.Rows.Count; i++) { if (dt.Rows[i] == dataRows[0]) { this.gcLeft.GridView.SelectRowHandler(i); break; } } } } } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show("左侧行选择错误", ex.Message); } } /// /// 说明:数据绑定完成后加载数据 /// 创建人:龚宇超 /// 创建日期: /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. protected void OnLeftControlObjDataSourceBindCallBack(object sender, EventArgs e) { try { this._leftGridSearchObj.SearchGrid(); } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } } }