10081 lines
492 KiB
C#
10081 lines
492 KiB
C#
using DevExpress.Data;
|
||
using DevExpress.Utils;
|
||
using DevExpress.XtraBars;
|
||
using DevExpress.XtraEditors;
|
||
using DevExpress.XtraGrid.Columns;
|
||
using DevExpress.XtraGrid.Views.Base;
|
||
using DevExpress.XtraGrid.Views.Grid;
|
||
using DevExpress.XtraTab;
|
||
using DevExpress.XtraTreeList.Columns;
|
||
using DevExpress.XtraTreeList.Nodes;
|
||
using Lskj.Business;
|
||
using Lskj.Business.Impl;
|
||
using Lskj.Control;
|
||
using Lskj.Control.BrowserSetting;
|
||
using Lskj.Control.Model;
|
||
using Lskj.Core;
|
||
using Lskj.Data;
|
||
using Lskj.Model;
|
||
using Lskj.PubBill.Model;
|
||
using Lskj.Util;
|
||
using Newtonsoft.Json;
|
||
using Newtonsoft.Json.Linq;
|
||
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Data.SqlClient;
|
||
using System.Drawing;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Net;
|
||
using System.Text;
|
||
using System.Text.RegularExpressions;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
|
||
namespace Lskj.PubBill
|
||
{
|
||
public partial class BillModule : UserControl
|
||
{
|
||
/// <summary>
|
||
/// 是否为初始化创建
|
||
/// </summary>
|
||
private bool _isInitFinish;
|
||
/// <summary>
|
||
/// 是否加载右侧控件数据
|
||
/// </summary>
|
||
private bool _isLoadRightControlValue = true;
|
||
/// <summary>
|
||
/// 是否手动选择了模版
|
||
/// </summary>
|
||
private bool _isSelectedTemplete;
|
||
/// <summary>
|
||
/// 是否直接打印
|
||
/// </summary>
|
||
private bool _isExcPrint;
|
||
/// <summary>
|
||
/// 是否选择关联下发
|
||
/// </summary>
|
||
private bool _isCheck;
|
||
/// <summary>
|
||
/// 主打印Sql
|
||
/// </summary>
|
||
private string _mainPrintSql;
|
||
private string guidField = "xxxxx_guid";
|
||
/// <summary>
|
||
/// 主键字段
|
||
/// </summary>
|
||
private string mRecordPrimaryField;
|
||
/// <summary>
|
||
/// 单据水印
|
||
/// </summary>
|
||
private WaterMark _waterMark;
|
||
/// <summary>
|
||
/// 导入单据明细数据、导入单据明细并更新
|
||
/// </summary>
|
||
private BarButtonItem _itemImport, _itemImportUpdate;
|
||
/// <summary>
|
||
/// 打印主sql中关联打印次数返回条件
|
||
/// </summary>
|
||
private string _printModeCond;
|
||
/// <summary>
|
||
/// 打印完成后添加数据用到的参数: 表名,列前缀,主键字段,主键值,模块编号,主打印Sql
|
||
/// </summary>
|
||
private List<string> _printSaveParams;
|
||
/// <summary>
|
||
/// 单据明细列
|
||
/// </summary>
|
||
private DataTable _detailColumns;
|
||
private bool IsCopying = false;
|
||
|
||
|
||
protected DataRow BillRowItem;
|
||
/// <summary>
|
||
/// 主表控件
|
||
/// </summary>
|
||
public MyControl ControlObj;
|
||
/// <summary>
|
||
/// 入口参数
|
||
/// </summary>
|
||
protected DynamicBillModel SysModel;
|
||
/// <summary>
|
||
/// 是否为Brp模版
|
||
/// </summary>
|
||
/// <value><c>true</c> if this instance is BRP templete; otherwise, <c>false</c>.</value>
|
||
protected bool IsBrpTemplete { get { return SysModel is DynamicBillBrpModel; } }
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public BillModel BillModel;
|
||
/// <summary>
|
||
/// 快速扫码控件
|
||
/// </summary>
|
||
/// <value>The main bottom input object.</value>
|
||
public PanelControl MainBottomInputObj { get { return this.pl_input; } }
|
||
/// <summary>
|
||
/// Brp模版控件
|
||
/// </summary>
|
||
/// <value>The main bottom templete object.</value>
|
||
public PanelControl MainBottomTempleteObj { get { return this.pl_templete; } }
|
||
/// <summary>
|
||
/// 明细表格数据
|
||
/// </summary>
|
||
/// <value>The main bottom templete object.</value>
|
||
public GridControlEx gcMainDetilObj { get { return this.gcMain; } }
|
||
|
||
/// <summary>
|
||
/// Brp模版控件
|
||
/// </summary>
|
||
/// <value>扫码框</value>
|
||
public TextEdit txtinputobj { get { return this.txt_input; } }
|
||
/// <summary>
|
||
/// 数量名称
|
||
/// </summary>
|
||
public string NumberMc;
|
||
/// <summary>
|
||
/// 红字单据的分配管理模块
|
||
/// </summary>
|
||
public string rdRedUnionCode;
|
||
/// <summary>
|
||
/// 蓝字单据的分配管理模块
|
||
/// </summary>
|
||
public string rdBlueUnionCode;
|
||
/// <summary>
|
||
/// 蓝字单据的分配管理模块
|
||
/// </summary>
|
||
Dictionary<MyControl, XtraTabPage> pageNumKey = new Dictionary<MyControl, XtraTabPage>();
|
||
/// <summary>
|
||
/// 是否拖拽换行展示
|
||
/// </summary>
|
||
public bool isDragWrap = true;
|
||
/// <summary>
|
||
/// 触发主表改变刷新来源限制
|
||
/// </summary>
|
||
private bool IsBillMaster = true;
|
||
/// <summary>
|
||
/// 是否执行了加载储存过程
|
||
/// </summary>
|
||
//public bool ProcessExists = false;
|
||
/// <summary>
|
||
/// 保存或修改时报错信息
|
||
/// </summary>
|
||
public string SaveErrorMessage = string.Empty;
|
||
/// <summary>
|
||
/// 单据明细删除的行
|
||
/// </summary>
|
||
// private Dictionary<int,DataRow> ToWithdrawRows = new Dictionary<int,DataRow>();
|
||
private List<Dictionary<int, DataRow>> ToWithdrawRows = new List<Dictionary<int, DataRow>>();
|
||
/// <summary>
|
||
///改变颜色行
|
||
/// </summary>
|
||
private List<DataRow> ChangeColorRow = new List<DataRow>();
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public string AssociatedField = string.Empty;
|
||
/// <summary>
|
||
/// 注册设置公共事件私有类
|
||
/// </summary>
|
||
private static PubEvenImpl _eventHandler;
|
||
/// <summary>
|
||
/// 注册设置公共事件类
|
||
/// </summary>
|
||
private static PubEvenImpl eventHandler;
|
||
/// <summary>
|
||
/// 当前人员是否有导出权限
|
||
/// </summary>
|
||
public bool ExportPermission;
|
||
/// <summary>
|
||
/// 是否显示单据管理条数
|
||
/// </summary>
|
||
public bool IsBillShowCount = false;
|
||
/// <summary>
|
||
/// 来源明细的页面名字后缀(设置成全局变量,更好的处理语言翻译的情况)
|
||
/// </summary>
|
||
public string DetailedSuffix = Business.Impl.LanguageTranslation.Translatable ? "-" + Business.Impl.LanguageTranslation.GetTranslatedText("明细") : "-明细";
|
||
/// <summary>
|
||
/// 数量后缀
|
||
/// </summary>
|
||
public string QuantitySuffix = Business.Impl.LanguageTranslation.Translatable ? Business.Impl.LanguageTranslation.GetTranslatedText("条") + ")" : "条)";
|
||
/// <summary>
|
||
/// 新增
|
||
/// </summary>
|
||
public string addText = Business.Impl.LanguageTranslation.Translatable ? "(" + Business.Impl.LanguageTranslation.GetTranslatedText("新增") + ")" : "(新增)";
|
||
/// <summary>
|
||
/// 修改
|
||
/// </summary>
|
||
public string updateText = Business.Impl.LanguageTranslation.Translatable ? "(" + Business.Impl.LanguageTranslation.GetTranslatedText("修改") + ")" : "(修改)";
|
||
|
||
|
||
/// <summary>
|
||
/// 单据来源控件集合
|
||
/// </summary>
|
||
public Dictionary<DataRow, BillModuleModel> BillModuleModelDic = new Dictionary<DataRow, BillModuleModel>();
|
||
/// <summary>
|
||
/// 主表动态生成的日期列
|
||
/// </summary>
|
||
public List<GridColumn> DateColumnList = new List<GridColumn>();
|
||
/// <summary>
|
||
/// 主表动态生成的合计列
|
||
/// </summary>
|
||
public GridColumn SumGridColumn = new GridColumn();
|
||
/// <summary>
|
||
/// 附加右键菜单集合
|
||
/// </summary>
|
||
public List<SimpleButton> itemCommonList = new List<SimpleButton>();
|
||
/// <summary>
|
||
/// 是否已经添加了多行汇总
|
||
/// </summary>
|
||
public bool MultiLineSummary;
|
||
/// <summary>
|
||
/// 扫码框
|
||
/// </summary>
|
||
public TextEdit ScanCodeTextEdit = null;
|
||
/// <summary>
|
||
/// 初始化时选中的页签
|
||
/// </summary>
|
||
public XtraTabPage InitialSelectionTab = null;
|
||
/// <summary>
|
||
/// 当前操作的ImageEdit
|
||
/// </summary>
|
||
private LabelImageEdit _imageEdit;
|
||
/// <summary>
|
||
/// 当前来源明细中变色行
|
||
/// </summary>
|
||
private HashSet<int> ColorHandles = new HashSet<int>();
|
||
/// <summary>
|
||
/// 保存验证条件表
|
||
/// </summary>
|
||
public DataTable SaveCondTab = new DataTable();
|
||
|
||
|
||
|
||
public BillModule()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
|
||
#region 初始化操作
|
||
/// <summary>
|
||
/// <para>说明:窗口加载</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-23 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
public void OnLoad(DynamicBillModel Model)
|
||
{
|
||
try
|
||
{
|
||
this.SysModel = Model;// 单据动态链接库参数,入口参数
|
||
this._isInitFinish = false;// 是否为初始化创建
|
||
this.ssc_main.Visible = false; //获取或设置一个值,该值指示是否显示该控件及其所有子控件。
|
||
//this.ProcessExists = (Lskj.Data.Caches.CacheSYSConfig.Instance().JudgeProcessExists() && SystemInfo.Instance.isExecload);
|
||
|
||
if (true)//5.0控件样式
|
||
{
|
||
this.pl_main_bottom.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
|
||
this.pl_main_bottom.BackColor = Color.FromArgb(240, 240, 240);
|
||
this.pl_main_bottom.LookAndFeel.UseDefaultLookAndFeel = false;
|
||
this.pl_main_bottom.LookAndFeel.UseWindowsXPTheme = true;
|
||
}
|
||
|
||
Dictionary<object, Hashtable> dataCaches = Model != null ? Model.DataCaches : null;
|
||
dataCaches.GetValue(this, "DataCaches", out bool _);//等待缓存数据加载完成
|
||
this.InitializeSetting();//初始化系统配置
|
||
this.InitializeControl();//初始化控件
|
||
this.InitlizeSpiltLocation();
|
||
|
||
this.gcMain.GridView.KeyDown += new KeyEventHandler(OnToWithdraw);
|
||
this.gcMain.GridView.GridControl.ProcessGridKey += new KeyEventHandler(OnGridControlKye);
|
||
|
||
this.gcMain.ExportPermission = this.BillModel.ExportPermission;
|
||
|
||
this.CalculateCoordinates();
|
||
|
||
//单据明细推拽
|
||
if (this.BillModel.DraggingOrder && !string.IsNullOrWhiteSpace(this.BillModel.DetailOrderField))
|
||
{
|
||
this.gcMain.InitializedragState(this.BillModel.DetailOrderField);
|
||
}
|
||
|
||
//非中文替换(红蓝单据等固定信息)
|
||
if (Business.Impl.LanguageTranslation.Translatable)
|
||
{
|
||
this.rdBlue.Text = Business.Impl.LanguageTranslation.GetTranslatedText(this.rdBlue.Text);
|
||
this.rdRed.Text = Business.Impl.LanguageTranslation.GetTranslatedText(this.rdRed.Text);
|
||
this.labelControl1.Text = Business.Impl.LanguageTranslation.GetTranslatedText(this.labelControl1.Text);
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Instance.WriteError(ex);
|
||
LogUtil.WriteError("单据初始化窗体失败!", ex);
|
||
MessageUtil.Show(ex.StackTrace);
|
||
}
|
||
finally
|
||
{
|
||
this._isInitFinish = true;
|
||
this.ssc_main.Visible = true;
|
||
if (this.BillModel.MainVerticalScroll || this.BillModel.MainHorizontalScrolling)
|
||
{
|
||
this.pl_main_center_master.AutoScroll = true;
|
||
this.pl_main_center_master.VerticalScroll.Visible = this.BillModel.MainVerticalScroll;//隐藏纵向滚动条
|
||
this.pl_main_center_master.HorizontalScroll.Visible = this.BillModel.MainHorizontalScrolling;//隐藏横向滚动条
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 获取数据源缓存
|
||
/// </summary>
|
||
/// <param name="cachesDic"></param>
|
||
public void GetDataCaches(Dictionary<object, Hashtable> cachesDic)
|
||
{
|
||
//获取通用数据
|
||
Task<ModuleModel> sysModelTask = cachesDic.GetTask<ModuleModel>(this, "SysModel");
|
||
Task<DataRow> systemDllRowTask = cachesDic.GetTask<DataRow>(this, "SystemDllRow");
|
||
Task<DynamicModel> dynamicModelTask = cachesDic.GetTask<DynamicModel>(this, "DynamicModel");
|
||
Task<bool> getDataCachesTask = cachesDic.AddTask(this, "DataCaches", new Task<bool>(() =>
|
||
{
|
||
DynamicBillModel dynamicModel = (DynamicBillModel)dynamicModelTask.Result;
|
||
#region InitializeSetting初始化系统配置
|
||
Task<DataRow> billInfoRowTask = cachesDic.AddTask(this, "BillInfo", new Task<DataRow>(() =>
|
||
{
|
||
return BillImpl.GetBillInfo(dynamicModel.ModuleCode);//获取单个模块信息
|
||
}));
|
||
Task<BillModel> billModelTask = cachesDic.AddTask(this, "BillModel", new Task<BillModel>(() =>
|
||
{
|
||
BillModel model = null;
|
||
if (billInfoRowTask.Result != null)
|
||
{
|
||
model = new BillModel(billInfoRowTask.Result);
|
||
}
|
||
return model;
|
||
}));
|
||
BillModel billModel = billModelTask.Result;
|
||
if (billModel != null)
|
||
{
|
||
Task<string> masterPreFixTask = cachesDic.AddTask(this, "MasterPreFix", new Task<string>(() =>
|
||
{
|
||
return BaseImpl.GetColumnPrefix(billModel.MasterTable);// 主表列前缀
|
||
}));
|
||
Task<string> detailPreFixTask = cachesDic.AddTask(this, "DetailPreFix", new Task<string>(() =>
|
||
{
|
||
return BaseImpl.GetColumnPrefix(billModel.DetailTable);// 明细表列前缀
|
||
}));
|
||
}
|
||
Task<DataRow> menuConfigTabTask = cachesDic.AddTask(this, "MenuConfigTab", new Task<DataRow>(() =>
|
||
{
|
||
DataRow dataRow = BaseImpl.GetMenuConfigTab(dynamicModel.ModuleId);
|
||
if (dataRow != null)
|
||
{
|
||
billModel.BillSourceIds = dataRow.Table.Columns.Contains("BillSourceIds") ? (dataRow["BillSourceIds"] + "").Trim(',') : string.Empty;
|
||
billModel.BillFlag = dataRow.Table.Columns.Contains("BillFlag") && !string.IsNullOrEmpty(dataRow["BillFlag"] + "") ? Convert.ToInt32(dataRow["BillFlag"] + "") : -1;
|
||
//billModel
|
||
}
|
||
return dataRow;//获取菜单其他配置
|
||
}));
|
||
#region GetPrintOtherParam获取打印其他参数
|
||
if (string.IsNullOrEmpty(billModel.PrintSql) && billModel.PrintSql.Contains("<<"))
|
||
{
|
||
string[] strs = billModel.PrintSql.Split(new[] { ">>" }, 2, StringSplitOptions.None);
|
||
_mainPrintSql = strs[1];
|
||
_printModeCond = strs[0].Replace("<<", "");
|
||
}
|
||
if (!string.IsNullOrEmpty(_printModeCond) && _printModeCond.IndexOf(';') > 0)
|
||
{
|
||
string[] str = _printModeCond.Split(';');
|
||
Task<DataRow> printOtherSystemRowTask = cachesDic.AddTask(this, "PrintOtherSystemRow", new Task<DataRow>(() =>
|
||
{
|
||
return AttachImpl.GetSystemModule(str[0]);
|
||
}));
|
||
Task<string> printOtherColumnPrefixTask = cachesDic.AddTask(this, "PrintOtherColumnPrefix", new Task<string>(() =>
|
||
{
|
||
string tableName = printOtherSystemRowTask.Result["TableName"] + "";
|
||
return BaseImpl.GetColumnPrefix(tableName);
|
||
}));
|
||
Task<string> printOtherPrimaryKeyTask = cachesDic.AddTask(this, "PrintOtherPrimaryKey", new Task<string>(() =>
|
||
{
|
||
string modetype = printOtherSystemRowTask.Result["modType"] + "";
|
||
return modetype == "1" ? BaseImpl.GetBasePrimaryKey(str[0]) : printOtherColumnPrefixTask.Result + "billdocument_id";
|
||
}));
|
||
Task<bool> printOtherIsExcPrintTask = cachesDic.AddTask(this, "PrintOtherIsExcPrint", new Task<bool>(() =>
|
||
{
|
||
string modetype = printOtherSystemRowTask.Result["modType"] + "";
|
||
switch (modetype)
|
||
{
|
||
case "1":
|
||
ModuleModel mode = new ModuleModel(MainImpl.GetSystemdllTab(str[0]));
|
||
if (mode != null)
|
||
{
|
||
return mode.PrintType == 3;
|
||
}
|
||
break;
|
||
case "2":
|
||
BaseAccraditationModel model = new BaseAccraditationModel(BillAuditImpl.GetPubAuditProperty(str[0]));
|
||
if (model != null)
|
||
{
|
||
return model.BillPrintType == 3;
|
||
}
|
||
break;
|
||
}
|
||
return false;
|
||
}));
|
||
}
|
||
#endregion
|
||
Task<bool> billSettingTask = cachesDic.AddTask(this, "BillSetting", new Task<bool>(() =>
|
||
{
|
||
BillImpl.InitBillSetting(billModel);
|
||
return true;
|
||
}));
|
||
#endregion
|
||
#region InitializeControl初始化控件
|
||
if (dynamicModel is DynamicBillBrpModel || billModel.IsBrp)// 是否为Brp模版
|
||
{
|
||
Task<DataTable> getBillBrpTask = cachesDic.AddTask(this, "GetBillBrp", new Task<DataTable>(() =>
|
||
{
|
||
return BillImpl.GetBillBrp(dynamicModel.ModuleCode);
|
||
}));
|
||
}
|
||
Task<DataTable> operBaseGridRightMenusTask = cachesDic.AddTask(this, "OperBaseGridRightMenus", new Task<DataTable>(() =>
|
||
{
|
||
return BaseModuleImpl.GetBaseGridRightMenus(dynamicModel.ModuleCode, ModuleType.BillDetail);//获取右键菜单数据
|
||
}));
|
||
#region InitializeBillInfo初始化单据控件信息
|
||
Task<DataTable> controlLocationTask = cachesDic.AddTask(this, "ControlLocation", new Task<DataTable>(() =>
|
||
{
|
||
DataTable controls = BaseModuleImpl.GetControlLocation(billModel.FormKey, dynamicModel.ModuleCode);
|
||
if (!string.IsNullOrWhiteSpace(billModel.BillSourceControlName))
|
||
{
|
||
var targetRow = controls.AsEnumerable()
|
||
.FirstOrDefault(row => row.Field<string>("fieldName").Equals(this.BillModel.BillSourceControlName, StringComparison.OrdinalIgnoreCase));
|
||
if (targetRow != null)
|
||
{
|
||
targetRow["fieldTypeId"] = "-11";
|
||
}
|
||
}
|
||
return controls;
|
||
}));
|
||
Task<MyControl> controlObjTask = cachesDic.AddTask(this, "ControlObj", new Task<MyControl>(() =>
|
||
{
|
||
MyControl myControl = new MyControl() { Model = dynamicModel };
|
||
myControl.OtherParams = dynamicModel.OtherParams();
|
||
cachesDic.AddTask(myControl, "DynamicModel", dynamicModelTask);
|
||
cachesDic.AddTask(myControl, "ControlsTable", controlLocationTask);
|
||
myControl.GetControlDataCaches(cachesDic);
|
||
return myControl;//主表控件
|
||
}));
|
||
Task<DataTable> addGroupDataTask = cachesDic.AddTask(this, "AddGroupData", new Task<DataTable>(() =>
|
||
{
|
||
return BaseModuleImpl.GetAddGroupData(billModel.FormKey);//获取主信息分组数据
|
||
}));
|
||
Task<DataTable> detailColumnsTask = cachesDic.AddTask(this, "DetailColumns", new Task<DataTable>(() =>
|
||
{
|
||
if (dynamicModel.GridEnumObj == GridEnum.BandedGridView || billModel.AutoMultiHeader == 1)
|
||
{
|
||
return BillImpl.GetDetailColumns(dynamicModel.ModuleCode, true);//初始化单据明细列
|
||
}
|
||
return BillImpl.GetDetailColumns(dynamicModel.ModuleCode);//初始化单据明细列
|
||
}));
|
||
//创建表格列
|
||
cachesDic.AddTask(gcMain, "DynamicModel", dynamicModelTask);
|
||
gcMain.GetDataCaches(cachesDic, GridCustomColumnStruct.BillDetailGridView + billModel.FormKey);
|
||
Task<DataTable> baseGridRowColorsTask = cachesDic.AddTask(gcMain, "BaseGridRowColors", new Task<DataTable>(() =>
|
||
{
|
||
return BaseModuleImpl.GetBaseGridRowColors("BILLDETAIL_" + billModel.FormKey);
|
||
}));
|
||
Task<DataTable> baseGridRightMenusTask = cachesDic.AddTask(gcMain, "BaseGridRightMenus", new Task<DataTable>(() =>
|
||
{
|
||
return BaseModuleImpl.GetBaseGridRightMenus("BILLDETAIL_" + dynamicModel.ModuleCode);//设置表格右键菜单
|
||
}));
|
||
Task<DataTable> saveCondTabTask = cachesDic.AddTask(this, "SaveCondTab", new Task<DataTable>(() =>
|
||
{
|
||
return BaseModuleImpl.GetClientCond(dynamicModel.ModuleCode);
|
||
}));
|
||
|
||
#endregion
|
||
if (billModel.PanelWidth > 0)
|
||
{
|
||
#region InitializeBillSource初始化单据来源
|
||
Task<List<GridDetailModel>> detailTask = cachesDic.AddTask(this, "Details", new Task<List<GridDetailModel>>(() =>
|
||
{
|
||
List<GridDetailModel> details = new List<GridDetailModel>();
|
||
DataTable table = BaseAuditImpl.GetAttachTabs(dynamicModel.ModuleCode, "100", " and orderid < 0 ");
|
||
foreach (DataRow item in table.Rows)
|
||
{
|
||
GridDetailModel gridDetailModel = new GridDetailModel(item, null, GridCustomColumnStruct.BillSourceDetailAttachGridView);
|
||
details.Add(gridDetailModel);
|
||
Task<DataTable> addGridColumnsTask = cachesDic.AddTask(gridDetailModel, "GridColumns", new Task<DataTable>(() =>
|
||
{
|
||
DataTable gridColumns = BaseAuditImpl.GetBottomBasicInformation(item["formKey"] + "");
|
||
gridDetailModel.GridColumns = gridColumns;
|
||
return gridColumns;
|
||
}));
|
||
}
|
||
return details;
|
||
}));
|
||
Task<Hashtable> sourcesTask = cachesDic.AddTask(this, "Sources", new Task<Hashtable>(() =>
|
||
{
|
||
DataRow menuConfigRow = menuConfigTabTask.Result;
|
||
string SourceIds = (billModel.BillSourceIds + "").Trim(',');
|
||
if (!string.IsNullOrWhiteSpace(dynamicModel.SourceDetailsID))
|
||
{
|
||
SourceIds = (SourceIds + "," + dynamicModel.SourceDetailsID).Trim(',');
|
||
}
|
||
return BillImpl.GetSources(dynamicModel.ModuleCode, SourceIds);//获取单据来源
|
||
}));
|
||
cachesDic.AddTask(tb_buttom, "DynamicModel", dynamicModelTask);
|
||
cachesDic.AddTask(tb_buttom, "Details", detailTask);
|
||
tb_buttom.GetDataCaches(cachesDic);
|
||
Task<bool> initSourcesTask = cachesDic.AddTask(this, "InitSourcesTask", new Task<bool>(() =>
|
||
{
|
||
Hashtable htTable = sourcesTask.Result;
|
||
DataTable masterTable = htTable["master"] as DataTable;
|
||
DataTable detailTable = htTable["detail"] as DataTable;
|
||
for (int i = 0; i < masterTable.Rows.Count; i++)
|
||
{
|
||
DataRow sourceModelRow = masterTable.Rows[i];
|
||
BillModuleModel billModuleModel = new BillModuleModel();
|
||
BillSourceModel model = new BillSourceModel(sourceModelRow);
|
||
billModuleModel.SourceModel = model;
|
||
Task<DataTable> customQueryFieldsTask = cachesDic.AddTask(model, "CustomQueryFields", new Task<DataTable>(() =>
|
||
{
|
||
return BaseModuleImpl.GetCustomQueryFields(model.FormKey);
|
||
}));
|
||
#region 加载来源表头
|
||
GridControlEx gridControl = null;
|
||
TreeViewEx treeView = null;
|
||
if (model.SourceType == 1)
|
||
{
|
||
// 来源为树类型
|
||
treeView = new TreeViewEx();
|
||
billModuleModel.SourceControl = treeView;
|
||
Task<DataTable> bindTreeTableTask = cachesDic.AddTask(treeView, "BindTreeTable", new Task<DataTable>(() =>
|
||
{
|
||
return BaseImpl.GetDataTableResult(model.SourceSql);
|
||
}));
|
||
}
|
||
else if (model.SourceType == 5)
|
||
{
|
||
model.ChangeSourceType(2);//单据来源显示条数
|
||
}
|
||
else if (model.SourceType == 3 || model.SourceType == 4)
|
||
{
|
||
gridControl = new TreeGridControlEx();
|
||
billModuleModel.SourceControl = gridControl;
|
||
Task<DataTable> sourceColumnsTask = cachesDic.AddTask(gridControl, "SourceColumns", new Task<DataTable>(() =>
|
||
{
|
||
return BillImpl.GetSourceColumns(model.Id);
|
||
}));
|
||
Task<DataTable> sourceGridRowColorsTask = cachesDic.AddTask(gridControl, "BaseGridRowColors", new Task<DataTable>(() =>
|
||
{
|
||
return BaseModuleImpl.GetBaseGridRowColors("BILLSOURCE_" + model.FormKey);
|
||
}));
|
||
Task<DataTable> sourceGridRightMenusTask = cachesDic.AddTask(gridControl, "BaseGridRightMenus", new Task<DataTable>(() =>
|
||
{
|
||
return BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCE_" + model.FormKey);
|
||
}));
|
||
}
|
||
else
|
||
{
|
||
// 来源为表格类型
|
||
gridControl = new GridControlEx();
|
||
billModuleModel.SourceControl = gridControl;
|
||
Task<DataTable> sourceColumnsTask = cachesDic.AddTask(gridControl, "SourceColumns", new Task<DataTable>(() =>
|
||
{
|
||
return BillImpl.GetSourceColumns(model.Id);
|
||
}));
|
||
//创建表格列
|
||
cachesDic.AddTask(gridControl, "DynamicModel", dynamicModelTask);
|
||
gridControl.GetDataCaches(cachesDic, GridCustomColumnStruct.BillSourceGridView + model.FormKey);
|
||
Task<DataTable> sourceGridRowColorsTask = cachesDic.AddTask(gridControl, "BaseGridRowColors", new Task<DataTable>(() =>
|
||
{
|
||
return BaseModuleImpl.GetBaseGridRowColors("BILLSOURCE_" + model.FormKey);
|
||
}));
|
||
Task<DataTable> sourceGridRightMenusTask = cachesDic.AddTask(gridControl, "BaseGridRightMenus", new Task<DataTable>(() =>
|
||
{
|
||
return BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCE_" + model.FormKey);
|
||
}));
|
||
}
|
||
#endregion
|
||
#region 加载来源明细
|
||
GridControlEx gridDetail = new GridControlEx();
|
||
if (model.sourceDetailType.Equals("1"))
|
||
{
|
||
//明细为树表格
|
||
gridDetail = new TreeGridControlEx();
|
||
billModuleModel.SourceDetailControl = gridDetail;
|
||
//创建表格列
|
||
cachesDic.AddTask(gridDetail, "DynamicModel", dynamicModelTask);
|
||
gridDetail.GetDataCaches(cachesDic, GridCustomColumnStruct.BillSourceDetailGridView + model.FormKey);
|
||
Task<DataTable> detailGridRowColorsTask = cachesDic.AddTask(gridDetail, "BaseGridRowColors", new Task<DataTable>(() =>
|
||
{
|
||
return BaseModuleImpl.GetBaseGridRowColors("SOURCEDETAIL_" + model.FormKey);
|
||
}));
|
||
Task<DataTable> detailGridRightMenusTask = cachesDic.AddTask(gridDetail, "BaseGridRightMenus", new Task<DataTable>(() =>
|
||
{
|
||
return BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCEDT_" + model.FormKey);
|
||
}));
|
||
|
||
}
|
||
else
|
||
{
|
||
gridDetail = new GridControlEx();
|
||
billModuleModel.SourceDetailControl = gridDetail;
|
||
//创建表格列
|
||
cachesDic.AddTask(gridDetail, "DynamicModel", dynamicModelTask);
|
||
gridDetail.GetDataCaches(cachesDic, GridCustomColumnStruct.BillSourceDetailGridView + model.FormKey);
|
||
Task<DataTable> detailGridRowColorsTask = cachesDic.AddTask(gridDetail, "BaseGridRowColors", new Task<DataTable>(() =>
|
||
{
|
||
return BaseModuleImpl.GetBaseGridRowColors("SOURCEDETAIL_" + model.FormKey);
|
||
}));
|
||
Task<DataTable> detailGridRightMenusTask = cachesDic.AddTask(gridDetail, "BaseGridRightMenus", new Task<DataTable>(() =>
|
||
{
|
||
return BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCEDT_" + model.FormKey);
|
||
}));
|
||
//明细的明细(明细分成左右2个)
|
||
if (!string.IsNullOrEmpty(model.SourceDetailsDetailsSql))
|
||
{
|
||
GridControlEx gridDetail_Details = new GridControlEx();
|
||
billModuleModel.SourceDetailDetailControl = gridDetail_Details;
|
||
//创建只读列
|
||
Task<DataTable> detailDetailsTask = cachesDic.AddTask(gridDetail_Details, "DetailDetails", new Task<DataTable>(() =>
|
||
{
|
||
return BaseModuleImpl.getDetail_Details(model.FormKey);
|
||
}));
|
||
//创建表格列
|
||
cachesDic.AddTask(gridDetail_Details, "DynamicModel", dynamicModelTask);
|
||
gridDetail_Details.GetDataCaches(cachesDic);
|
||
Task<DataTable> detailDetailsGridRightMenusTask = cachesDic.AddTask(gridDetail_Details, "BaseGridRightMenus", new Task<DataTable>(() =>
|
||
{
|
||
return BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCEDTX_" + model.FormKey);
|
||
}));
|
||
}
|
||
}
|
||
#endregion
|
||
BillModuleModelDic.Add(sourceModelRow, billModuleModel);
|
||
#region 加载来源条件
|
||
Task<MyControl> searchControlTask = cachesDic.AddTask(sourceModelRow, "SearchControl", new Task<MyControl>(() =>
|
||
{
|
||
DataTable controls = customQueryFieldsTask.Result;
|
||
MyControl searchControl = null;
|
||
if (model.SourceType != 1 || (controls != null && controls.Rows.Count > 0))
|
||
{
|
||
// 创建自定义条件
|
||
string searchSql = model.SourceType == 1 ? Regex.Replace(model.DetailSql, "{speciesno}", "", RegexOptions.IgnoreCase) : model.SourceSql;
|
||
searchControl = new MyControl(searchSql, gridControl == null ? gridDetail : gridControl, treeView);
|
||
searchControl.Model = dynamicModel;
|
||
searchControl.OtherParams = dynamicModel.OtherParams();
|
||
cachesDic.AddTask(searchControl, "DynamicModel", dynamicModelTask);
|
||
cachesDic.AddTask(searchControl, "ControlsTable", customQueryFieldsTask);
|
||
searchControl.GetSearchDataCaches(cachesDic);
|
||
}
|
||
return searchControl;
|
||
}));
|
||
#endregion
|
||
}
|
||
return true;
|
||
}));
|
||
#endregion
|
||
}
|
||
return true;
|
||
}));
|
||
#endregion
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:初始化分割条位置</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-03-06 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void InitlizeSpiltLocation()
|
||
{
|
||
try
|
||
{
|
||
// 设置单据来源左侧宽度
|
||
if (this.BillModel.PanelWidth == 0)
|
||
{
|
||
// 隐藏来源
|
||
this.ssc_main_top.PanelVisibility = SplitPanelVisibility.Panel2;
|
||
}
|
||
else
|
||
{
|
||
string width = IniHelper.Read(string.Format("bill_width_{0}", this.SysModel.ModuleCode));
|
||
if (!string.IsNullOrEmpty(width))
|
||
this.ssc_main_top.SplitterPosition = Convert.ToInt32(width);
|
||
}
|
||
|
||
// 设置单据来源底部高度
|
||
if (this.BillModel.PanelHeight == 0)
|
||
{
|
||
// 隐藏来源明细
|
||
this.ssc_main.PanelVisibility = SplitPanelVisibility.Panel1;
|
||
}
|
||
else
|
||
{
|
||
string height = IniHelper.Read(string.Format("bill_height_{0}", this.SysModel.ModuleCode));
|
||
if (!string.IsNullOrEmpty(height))
|
||
this.ssc_main.SplitterPosition = Convert.ToInt32(height);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Instance.WriteError(ex);
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:初始化系统配置</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-27 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void InitializeSetting()
|
||
{
|
||
Dictionary<object, Hashtable> dataCaches = SysModel != null ? SysModel.DataCaches : null;
|
||
if (!dataCaches.GetValue(this, "BillInfo", out DataRow modelRow))
|
||
{
|
||
modelRow = BillImpl.GetBillInfo(this.SysModel.ModuleCode);//获取单个模块信息
|
||
}
|
||
if (modelRow == null)
|
||
{
|
||
//MessageUtil.Show("模块编号[" + this.SysModel.ModuleCode + "],配置错误!\r\n该模块信息未找到!");
|
||
//return;
|
||
throw new Exception("模块编号[" + this.SysModel.ModuleCode + "],配置错误!\r\n该模块信息未找到!");
|
||
}
|
||
if (!dataCaches.GetValue(this, "BillModel", out BillModel))
|
||
{
|
||
this.BillModel = new BillModel(modelRow);//初始化类的新实例。
|
||
}
|
||
|
||
if (this.BillModel != null)
|
||
{
|
||
this.BillModel.TypeName = string.IsNullOrEmpty(SysModel.BillMasterSql) ? this.SysModel.FormText : this.BillModel.TypeName;// 模块名称
|
||
if (!string.IsNullOrWhiteSpace(this.SysModel.DocumentName)) this.BillModel.TypeName = this.SysModel.DocumentName;
|
||
|
||
if (!dataCaches.GetValue(this, "MasterPreFix", out string masterPreFix))
|
||
{
|
||
masterPreFix = BaseImpl.GetColumnPrefix(this.BillModel.MasterTable);// 主表列前缀
|
||
}
|
||
this.BillModel.MasterPreFix = masterPreFix;
|
||
if (!dataCaches.GetValue(this, "DetailPreFix", out string detailPreFix))
|
||
{
|
||
detailPreFix = BaseImpl.GetColumnPrefix(this.BillModel.DetailTable);// 明细表列前缀
|
||
}
|
||
this.BillModel.DetailPreFix = detailPreFix;
|
||
this.BillModel.DetailOrderField = this.BillModel.DetailPreFix + "lsidx_id";// 单据来源id
|
||
if (SystemInfo.Instance.IsNotBillDetailOrder)//禁用排序
|
||
this.BillModel.DetailOrderField = string.Empty;
|
||
}
|
||
if (!dataCaches.GetValue(this, "MenuConfigTab", out DataRow menuRow))
|
||
{
|
||
menuRow = BaseImpl.GetMenuConfigTab(this.SysModel.ModuleId);//获取菜单其他配置
|
||
}
|
||
if (menuRow != null)
|
||
{
|
||
this.BillModel.BillSourceIds = menuRow.Table.Columns.Contains("BillSourceIds") ? (menuRow["BillSourceIds"] + "").Trim(',') : string.Empty;
|
||
this.BillModel.BillFlag = menuRow.Table.Columns.Contains("BillFlag") && !string.IsNullOrEmpty(menuRow["BillFlag"] + "") ? Convert.ToInt32(menuRow["BillFlag"] + "") : -1;
|
||
}
|
||
if (this.SysModel.HideSource)
|
||
{
|
||
this.BillModel.PanelWidth = 0;
|
||
this.BillModel.PanelHeight = 0;
|
||
}
|
||
|
||
|
||
//获取打印其他参数
|
||
GetPrintOtherParam();
|
||
if (!dataCaches.GetValue(this, "BillSetting", out bool _))
|
||
{
|
||
BillImpl.InitBillSetting(this.BillModel);
|
||
}
|
||
|
||
if (this.BillModel.IsBrp)
|
||
{
|
||
this.MainBottomInputObj.Visible = false;
|
||
this.MainBottomTempleteObj.Visible = true;
|
||
}
|
||
|
||
//显示筛选行
|
||
if (this.BillModel.LoadFilter) this.gcMain.GridView.OptionsView.ShowAutoFilterRow = true;
|
||
//树表格
|
||
if (this.BillModel.DetailTreeTable)
|
||
{
|
||
this.pl_main_center_detail.Controls.Clear();
|
||
this.gcMain = new TreeGridControlEx();
|
||
this.gcMain.Dock = DockStyle.Fill;
|
||
this.pl_main_center_detail.Controls.Add(this.gcMain);
|
||
(this.gcMain as TreeGridControlEx).Expansion = this.BillModel.DetailTreeTableExpansion;
|
||
(this.gcMain as TreeGridControlEx).AddRightButton();
|
||
//节点编号
|
||
(this.gcMain as TreeGridControlEx).TreeListObj.KeyFieldName = "tap_id";
|
||
//父节点编号
|
||
(this.gcMain as TreeGridControlEx).TreeListObj.ParentFieldName = "tap_pid";
|
||
(this.gcMain as TreeGridControlEx).SortField = this.BillModel.DetailOrderField;
|
||
//(this.gcMain as TreeGridControlEx).TreeTableDragCondition = this.BillModel.TreeTableDragCondition;
|
||
|
||
(this.gcMain as TreeGridControlEx).InitializedragState();
|
||
}
|
||
|
||
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:初始化分配关联模块</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2020-02-18 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void InitializeUnionCode()
|
||
{
|
||
if (this.BillModel.PopupUnionCode.Contains(","))
|
||
{
|
||
string[] UnionCodeSplit = this.BillModel.PopupUnionCode.Split(',');
|
||
if (UnionCodeSplit.Length >= 1)
|
||
{
|
||
this.BillModel.PopupUnionCode = this.BillModel.BillFlag == 1 ? UnionCodeSplit[1] + "" : UnionCodeSplit[0] + "";
|
||
rdBlueUnionCode = UnionCodeSplit[0] + "";
|
||
rdRedUnionCode = UnionCodeSplit[1] + "";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
rdBlueUnionCode = rdRedUnionCode = this.BillModel.PopupUnionCode;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:初始化控件</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-23 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void InitializeControl()
|
||
{
|
||
if (this.IsBrpTemplete || this.BillModel.IsBrp)// 是否为Brp模版
|
||
this.InitializeTemplete();
|
||
|
||
this.InitializeStatus();//初始化红蓝字单
|
||
this.InitializeOper();//初始化常用操作等功能
|
||
this.InitializeBillInfo();//初始化单据控件信息
|
||
|
||
if (this.BillModel.PanelWidth > 0)
|
||
this.InitializeBillSource();//初始化单据来源
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:初始化红蓝字单</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-27 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void InitializeStatus()
|
||
{
|
||
// 初始化红、蓝单
|
||
if (this.BillModel.BillFlag == 0)
|
||
{
|
||
this.rdBlue.Checked = true;
|
||
this.rdRed.Checked = false;
|
||
this.lbTitle.ForeColor = Color.Blue;
|
||
this.pl_red.Visible = false;
|
||
}
|
||
if (this.BillModel.BillFlag == 1)
|
||
{
|
||
this.rdRed.Checked = true;
|
||
this.rdBlue.Checked = false;
|
||
this.lbTitle.ForeColor = Color.Red;
|
||
this.pl_blue.Visible = false;
|
||
}
|
||
this.dpCopyBill.Enabled = this.BillModel.CanCopy;
|
||
this.dpbImport.Enabled = this.BillModel.CanImport || this.BillModel.CanExport;
|
||
|
||
if (this.SysModel.HasReadPrivilege())
|
||
this.pl_main_bottom.Enabled = false;
|
||
this.ssc_main_top.SplitterPosition = this.BillModel.PanelWidth;
|
||
InitializeUnionCode();//根据红蓝字段更新分配
|
||
this.dbpFP.Visible = !string.IsNullOrWhiteSpace(this.BillModel.PopupUnionCode);
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:初始化常用操作等功能</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-27 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void InitializeOper()
|
||
{
|
||
BarButtonItem itemCopyMaster = new BarButtonItem();
|
||
itemCopyMaster.Caption = "复制表头信息";
|
||
itemCopyMaster.ItemClick += new ItemClickEventHandler(OnCopyMasterItemClick);
|
||
BarButtonItem itemCopyAll = new BarButtonItem();
|
||
itemCopyAll.Caption = "复制整单信息";
|
||
itemCopyAll.ItemClick += new ItemClickEventHandler(OnCopyAllItemClick);
|
||
BarButtonItem itemExport = new BarButtonItem();
|
||
itemExport.Caption = "导出Excel文件";
|
||
itemExport.ItemClick += new ItemClickEventHandler(OnExportItemClick);
|
||
BarButtonItem itemFPBatch = new BarButtonItem();
|
||
itemFPBatch.Caption = "批量分配";
|
||
itemFPBatch.ItemClick += new ItemClickEventHandler(OnBtnFPNewClick);
|
||
this._itemImport = new BarButtonItem();
|
||
this._itemImport.Caption = "导入Excel文件";
|
||
this._itemImport.ItemClick += new ItemClickEventHandler(OnImportItemClick);
|
||
this._itemImportUpdate = new BarButtonItem();
|
||
this._itemImportUpdate.Caption = "导入Excel文件(更新)";
|
||
this._itemImportUpdate.ItemClick += new ItemClickEventHandler(OnImportUpdateItemClick);
|
||
|
||
// 复制单据
|
||
this.pmBill.AddItems(new BarItem[] { itemCopyMaster, itemCopyAll });
|
||
// 导入导出
|
||
if (this.BillModel.CanExport && this.BillModel.ExportPermission)
|
||
{
|
||
this.pmBillExp.AddItem(itemExport);
|
||
}
|
||
if (this.BillModel.CanImport)
|
||
{
|
||
this.pmBillExp.AddItems(new BarItem[] { _itemImport, _itemImportUpdate });
|
||
}
|
||
//分配
|
||
this.pmFP.AddItems(new BarItem[] { itemFPBatch });
|
||
// 打印模版
|
||
string[] files = this.BillModel.PrintFile.Split('|');
|
||
for (int i = 0; i < files.Length; i++)
|
||
{
|
||
string fileName = files[i];
|
||
if (!string.IsNullOrWhiteSpace(fileName))
|
||
{
|
||
BarButtonItem itemPrint = new BarButtonItem();
|
||
int index = i + 1;
|
||
itemPrint.Caption = files[i].Replace(".rmf", "").Replace(".frx", "");
|
||
itemPrint.Tag = files[i];
|
||
itemPrint.ItemClick += new ItemClickEventHandler(OnPrintItemClick);
|
||
pMprint.AddItem(itemPrint);
|
||
}
|
||
}
|
||
|
||
// 常用工具
|
||
Dictionary<object, Hashtable> dataCaches = SysModel != null ? SysModel.DataCaches : null;
|
||
if (!dataCaches.GetValue(this, "OperBaseGridRightMenus", out DataTable tableCommon))
|
||
{
|
||
tableCommon = BaseModuleImpl.GetBaseGridRightMenus(this.SysModel.ModuleCode, ModuleType.BillDetail);//获取右键菜单数据
|
||
}
|
||
int j = 0, x = 0;
|
||
foreach (DataRow item in tableCommon.Rows)
|
||
{
|
||
if (j > 1)
|
||
{
|
||
BarButtonItem itemCommon = new BarButtonItem();
|
||
itemCommon.Caption = item["menuname"] + "";
|
||
itemCommon.Tag = item;
|
||
itemCommon.ItemClick += new ItemClickEventHandler(OnCommonItemClick);
|
||
if (tableCommon.Columns.Contains("menuCond"))
|
||
{
|
||
itemCommon.Enabled = ValidateCond(item["menuCond"] + "", null);
|
||
}
|
||
pMenu.AddItem(itemCommon);
|
||
}
|
||
else
|
||
{
|
||
SimpleButton itemCommon = new SimpleButton();
|
||
//itemCommon.AutoSize = true;
|
||
itemCommon.Text = item["menuname"] + "";
|
||
itemCommon.Tag = item;
|
||
itemCommon.Size = new System.Drawing.Size(67, 26);
|
||
itemCommon.Font = new Font("宋体", 9);
|
||
itemCommon.Click += new EventHandler(itemCommon_Click);
|
||
int inputWidth = pl_input.Visible ? pl_input.Width : 0;
|
||
itemCommon.Location = new Point(x + 6 + inputWidth, 6);
|
||
pl_main_bottom.Controls.Add(itemCommon);
|
||
x += itemCommon.Width + 6;
|
||
|
||
if (tableCommon.Columns.Contains("menuCond"))
|
||
{
|
||
itemCommon.Enabled = ValidateCond(item["menuCond"] + "", null);
|
||
}
|
||
itemCommonList.Add(itemCommon);
|
||
j++;
|
||
}
|
||
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:常用工具点击</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-27 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="ItemClickEventArgs"/> instance containing the event data.</param>
|
||
protected void itemCommon_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
SimpleButton btn = sender as SimpleButton;
|
||
DataRow rowItem = btn.Tag as DataRow;
|
||
GridRightMenuModel model = new GridRightMenuModel(rowItem);
|
||
|
||
if (!string.IsNullOrWhiteSpace(model.ClickCond))
|
||
{
|
||
string clickCond = this.ControlObj.ReplaceControlValue(model.ClickCond) + "";
|
||
bool condResult = ValidateCond(clickCond, null);
|
||
if (!condResult) return;
|
||
}
|
||
|
||
if (rowItem["dllname"].Equals("Lskj.PubBomImport.dll"))
|
||
{
|
||
if ((model.ParamList[7] + "").Equals("3"))
|
||
{
|
||
if (!this.BillSave(0, false))
|
||
{
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
StaticControl.RightMenuGridView = gcMain.GridView;
|
||
StaticControl.Comprefix = this.BillModel.DetailPreFix;
|
||
CommonMenu menu = new CommonMenu(this.SysModel, this.ControlObj, this.gcMain);
|
||
menu.ApplyBefore += new CommonToolApplyEventHandler(OnMenuApplyBefore);
|
||
menu.DynamicLinkAfter += new CommonToolAfterDynamicLinkEventHandler(OnDynamicLinkAfter);
|
||
menu.Apply(rowItem);
|
||
|
||
if (StaticControl.ReturnRowLisy.Count > 0)
|
||
{
|
||
DataRow[] dataRows = StaticControl.ReturnRowLisy.ToArray();
|
||
foreach (DataRow item in dataRows)
|
||
{
|
||
if (this.BillModel.DetailTreeTable)
|
||
{
|
||
this.AddRowToTreeGridControl(item, "0");
|
||
}
|
||
else
|
||
{
|
||
this.AddRowToGridView(item);
|
||
}
|
||
}
|
||
}
|
||
|
||
if (model != null && model.Refresh)
|
||
{
|
||
string billNo = this.lblOrderNo.Text.Trim();
|
||
this.SetBillStatus(BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, billNo)));
|
||
if (ControlObj != null && ControlObj.ParentPanel != null)
|
||
{
|
||
ControlObj.ParentPanel.Invalidate();
|
||
ControlObj.ParentPanel.Update();
|
||
}
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:初始化单据控件信息</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-27 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void InitializeBillInfo()
|
||
{
|
||
Dictionary<object, Hashtable> dataCaches = SysModel != null ? SysModel.DataCaches : null;
|
||
if (!dataCaches.GetValue(this, "ControlLocation", out DataTable controls))
|
||
{
|
||
controls = BaseModuleImpl.GetControlLocation(this.BillModel.FormKey, this.SysModel.ModuleCode);
|
||
if (!string.IsNullOrWhiteSpace(this.BillModel.BillSourceControlName))
|
||
{
|
||
var targetRow = controls.AsEnumerable()
|
||
.FirstOrDefault(row => row.Field<string>("fieldName").Equals(this.BillModel.BillSourceControlName, StringComparison.OrdinalIgnoreCase));
|
||
if (targetRow != null)
|
||
{
|
||
targetRow["fieldTypeId"] = "-11";
|
||
}
|
||
}
|
||
}
|
||
if (!dataCaches.GetValue(this, "AddGroupData", out DataTable groups))
|
||
{
|
||
groups = BaseModuleImpl.GetAddGroupData(this.BillModel.FormKey);//获取主信息分组数据
|
||
}
|
||
if (!dataCaches.GetValue(this, "ControlObj", out ControlObj))
|
||
{
|
||
this.ControlObj = new MyControl() { Model = SysModel };//主表控件
|
||
}
|
||
|
||
//this.ControlObj = new MyControl();//// 主表控件
|
||
this.ControlObj.OpenDocumentSource += OpenTheSourcePopup;
|
||
this.ControlObj.OtherParams = this.SysModel.OtherParams();
|
||
this.ControlObj.InitControl(controls, this.pl_main_center_master, groups);
|
||
this.ControlObj.refGridLookUpData = this.BillModel.RefGridLookUpData;//2023-3-17,新增单据时刷新下拉框数据源
|
||
this.ControlObj.OnSourceRefrshCallBack += OnRefreshBillSource;
|
||
this.ControlObj.OnDataFileRefrshCallBack += OnDataFileRefrshFile;
|
||
this.ControlObj.OnDataSourceBindCallBack += new EventHandler(OnInitializeHeaderCallBack);
|
||
|
||
this.pl_main_center_master.Height = (this.BillModel.ParentHeight - 36) > this.pl_main_center_master.Height ? this.pl_main_center_master.Height : this.BillModel.ParentHeight - 36;
|
||
|
||
//设置图片框的上传和删除事件
|
||
this.SetImageEvent(controls);
|
||
|
||
// 初始化明细
|
||
// 创建多表头,默认标准表格
|
||
if (this.SysModel.GridEnumObj == GridEnum.BandedGridView || this.BillModel.AutoMultiHeader == 1)
|
||
{
|
||
this.pl_main_center_detail.Controls.Clear();
|
||
this.gcMain = new BandedGridControlEx();
|
||
this.gcMain.Model = this.SysModel;
|
||
this.gcMain.Dock = DockStyle.Fill;
|
||
this.pl_main_center_detail.Controls.Add(this.gcMain);
|
||
}
|
||
|
||
if (!dataCaches.GetValue(this, "DetailColumns", out _detailColumns))
|
||
{
|
||
_detailColumns = BillImpl.GetDetailColumns(this.SysModel.ModuleCode);//初始化单据明细列
|
||
if (this.SysModel.GridEnumObj == GridEnum.BandedGridView || this.BillModel.AutoMultiHeader == 1)
|
||
{
|
||
//多表头sql要增加一个判断,否则多表头会出错
|
||
_detailColumns = BillImpl.GetDetailColumns(this.SysModel.ModuleCode, true);//初始化单据明细列
|
||
}
|
||
}
|
||
this.gcMain.DisableFieldSources = this.BillModel.DisableFieldSources;
|
||
this.gcMain.Model = this.SysModel;
|
||
this.gcMain.ParentControl = this.ControlObj;//把主表控件赋给 单据主表控件、基础档案查询条件控件等等
|
||
this.gcMain.SetEditColumns(_detailColumns, GridCustomColumnStruct.BillDetailGridView + this.BillModel.FormKey);//设置可编辑列
|
||
if (this.BillModel.IsBillMainDetailCheck == 1)//加载明细复选框
|
||
{
|
||
if (this.BillModel.DetailTreeTable)
|
||
{
|
||
GridDragGrid.TreeListAddCheckBox((this.gcMain as TreeGridControlEx).TreeListObj);
|
||
}
|
||
else
|
||
{
|
||
GridDragGrid.GridAddCheckBox(this.gcMain.GridView);
|
||
}
|
||
}
|
||
|
||
if (!dataCaches.GetValue(gcMain, "BaseGridRowColors", out DataTable dtBaseGridRowColors))
|
||
{
|
||
dtBaseGridRowColors = BaseModuleImpl.GetBaseGridRowColors("BILLDETAIL_" + this.BillModel.FormKey);
|
||
}
|
||
this.gcMain.SetGridRowColors(dtBaseGridRowColors);
|
||
//触发右键回调
|
||
this.gcMain.OnAfterLinkCilk += OnAfterLinkCilkCall;
|
||
if (!dataCaches.GetValue(gcMain, "BaseGridRightMenus", out DataTable dtBaseGridRightMenus))
|
||
{
|
||
dtBaseGridRightMenus = BaseModuleImpl.GetBaseGridRightMenus("BILLDETAIL_" + this.SysModel.ModuleCode);
|
||
}
|
||
if (this.gcMain is BandedGridControlEx)// 判断是不是多表头表格
|
||
{
|
||
//设置表格右键菜单
|
||
(this.gcMain as BandedGridControlEx).SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridViewRightCallBack, this.ControlObj);
|
||
(this.gcMain as BandedGridControlEx).GridView.ShowingEditor += new CancelEventHandler(OnGridViewShowingEditor);
|
||
}
|
||
else if (this.BillModel.DetailTreeTable)
|
||
{
|
||
(this.gcMain as TreeGridControlEx).SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridViewRightCallBack, this.ControlObj, (this.gcMain as TreeGridControlEx).MenuStrip);
|
||
//(this.gcMain as TreeGridControlEx).TreeListObj.DoubleClick += new EventHandler(OnGridViewDoubleClick);//和下方行单击事件功能一致(TreeListObj_MouseClick),同样的sql会重复执行。先注释 2025-06-30
|
||
(this.gcMain as TreeGridControlEx).TreeListObj.ShowingEditor += new CancelEventHandler(OnGridViewShowingEditor);
|
||
}
|
||
else
|
||
{
|
||
this.gcMain.SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridViewRightCallBack, this.ControlObj);
|
||
//this.gcMain.GridView.DoubleClick += new EventHandler(OnGridViewDoubleClick);//和下方行单击事件功能一致(OngcMainRowCellClick),同样的sql会重复执行。先注释 2025-06-30
|
||
this.gcMain.GridView.ShowingEditor += new CancelEventHandler(OnGridViewShowingEditor);
|
||
}
|
||
|
||
if (!dataCaches.GetValue(this, "SaveCondTab", out this.SaveCondTab))
|
||
{
|
||
this.SaveCondTab = BaseModuleImpl.GetClientCond(this.SysModel.ModuleCode);
|
||
}
|
||
|
||
|
||
if (this.BillModel.DefaultAddEmptyRow)
|
||
{
|
||
this.gcMain.GridView.OptionsView.NewItemRowPosition = NewItemRowPosition.Bottom;
|
||
if (SystemInfo.Instance.IsAddEmptyRowOldTag)
|
||
{
|
||
this.gcMain.GridView.MouseDown += GridView_MouseDown;
|
||
this.gcMain.GridView.FocusedRowChanged += GridView_FocusedRowChanged;
|
||
}
|
||
else
|
||
{
|
||
this.gcMain.GridView.InitNewRow += new InitNewRowEventHandler(OnGridViewInitNewRow);
|
||
}
|
||
//this.gcMain.GridView.InitNewRow += new InitNewRowEventHandler(OnGridViewInitNewRow);
|
||
//this.gcMain.GridView.OptionsView.NewItemRowPosition = NewItemRowPosition.Bottom;
|
||
//this.gcMain.GridView.MouseDown += GridView_MouseDown;
|
||
//this.gcMain.GridView.FocusedRowChanged += GridView_FocusedRowChanged;
|
||
}
|
||
//程序若配置扫码框则回车换行
|
||
if (this._detailColumns.Rows.Cast<DataRow>().FirstOrDefault(x => x["fieldsqltag"].ToString() == ControlType.LabSacn + "") != null)
|
||
{
|
||
this.gcMain.GridView.CellValueChanged += new CellValueChangedEventHandler(OnGridViewCellValueChanged);
|
||
}
|
||
|
||
if (this.BillModel.DetailTreeTable)
|
||
{
|
||
(this.gcMain as TreeGridControlEx).TreeListObj.MouseClick += TreeListObj_MouseClick;
|
||
}
|
||
else
|
||
{
|
||
this.gcMain.GridView.RowCellClick += OngcMainRowCellClick;
|
||
}
|
||
this.gcMain.GridControl.DataSourceChanged += OnGcMainDataSourceChanged;
|
||
this.gcMain.OnAllAfterParseCallBack += OnAllAfterParseCallBack;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 表格触发右键功能
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void OnAfterLinkCilkCall(object sender, EventArgs e)
|
||
{
|
||
string unioright = sender + "";
|
||
DataRow rightrowitem = this.gcMain.gridViewRightMenu.MenuTable.Rows.Cast<DataRow>().FirstOrDefault(x => (x["orderid"] + "").Equals(unioright));
|
||
|
||
GridRightMenuModel model = new GridRightMenuModel(rightrowitem);
|
||
DataRow rowItem = this.gcMain.GetViewFocusedDataRow();
|
||
if (!string.IsNullOrWhiteSpace(model.MenuCond))
|
||
{
|
||
//判断条件
|
||
DataRow row = this.gcMain.GridView.GetFocusedDataRow();
|
||
string cond = ReplaceHelper.ReplaceRowParam(row, model.MenuCond);
|
||
bool condResult = ValidateCond(cond, null);
|
||
if (!condResult) return;
|
||
}
|
||
|
||
CommonMenu menu = new CommonMenu(this.SysModel, ControlObj, this.gcMain);
|
||
menu.Apply(rightrowitem);
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:数据绑定后判断是否是右键打开模块赋值</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2020-03-27 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="CancelEventArgs"/> instance containing the event data.</param>
|
||
protected void OnInitializeHeaderCallBack(object sender, EventArgs e)
|
||
{
|
||
// 通过右键菜单打开单据时,判断修改还是新增
|
||
if (!string.IsNullOrEmpty(this.SysModel.BillOrderNo))
|
||
{
|
||
// 修改
|
||
string sqlValue = "select * from " + this.BillModel.MasterTable + " where 1=1";
|
||
string sqlCond = string.Format(" and {0}='{1}'", this.BillModel.PrimaryKey, this.SysModel.BillOrderNo);
|
||
DataTable masterTable = BillImpl.GetDataTableResult(sqlValue + sqlCond);
|
||
|
||
this.SetBillStatus(masterTable.Rows.Count > 0 ? masterTable.Rows[0] : null);
|
||
}
|
||
else
|
||
{
|
||
this.SetBillStatus(null);
|
||
// 新增
|
||
if (!string.IsNullOrEmpty(this.SysModel.BillMasterSql))
|
||
{
|
||
// 处理单据表头数据
|
||
DataRow row = BillImpl.GetDataRowResult(this.SysModel.BillMasterSql);
|
||
if (row != null)
|
||
{
|
||
if (row.Table.Columns.Contains(this.BillModel.RtagidKey))
|
||
{
|
||
string Rtagid = row[this.BillModel.RtagidKey] + "";
|
||
// 初始化红、蓝单
|
||
if (Rtagid.Equals("0"))
|
||
{
|
||
this.rdBlue.Checked = true;
|
||
this.rdRed.Checked = false;
|
||
this.lbTitle.ForeColor = Color.Blue;
|
||
this.pl_red.Visible = false;
|
||
this.pl_blue.Visible = true;
|
||
}
|
||
else if (Rtagid.Equals("1"))
|
||
{
|
||
this.rdRed.Checked = true;
|
||
this.rdBlue.Checked = false;
|
||
this.lbTitle.ForeColor = Color.Red;
|
||
this.pl_blue.Visible = false;
|
||
this.pl_red.Visible = true;
|
||
}
|
||
|
||
}
|
||
|
||
|
||
this.ControlObj.SetAllControlValue(row);//去掉第二个参数true,参数8进入的sql固定不默认赋值
|
||
// 设置Brp模版
|
||
if (this.IsBrpTemplete || this.BillModel.IsBrp)
|
||
{
|
||
this.SetTempleteSelectedValue(row["brpId"] + "");
|
||
}
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(this.SysModel.BillMasterSql))
|
||
{
|
||
// 处理单据明细数据
|
||
if (!this.SysModel.BillDetailSql.StartsWith("*")) this.AddMultiRowToGridView(BillImpl.GetDataTableResult(this.SysModel.BillDetailSql));
|
||
}
|
||
}
|
||
}
|
||
|
||
private void AddDataColumns()
|
||
{
|
||
foreach (GridColumn gridColumn in gcMain.GridView.Columns)
|
||
{
|
||
gridColumn.Fixed = DevExpress.XtraGrid.Columns.FixedStyle.Left;
|
||
}
|
||
int dayCount = 0;
|
||
BaseUserControl baseUserControl = ControlObj.FindControl("bom_rdm_tianshu");
|
||
if (baseUserControl != null)
|
||
{
|
||
int.TryParse(baseUserControl.EditText, out dayCount);
|
||
}
|
||
if (dayCount <= 0)
|
||
{
|
||
dayCount = 7;
|
||
}
|
||
if (DateColumnList.Count != dayCount)
|
||
{
|
||
foreach (GridColumn item in DateColumnList)
|
||
{
|
||
gcMain.GridView.Columns.Remove(item);
|
||
}
|
||
gcMain.GridView.Columns.Remove(SumGridColumn);
|
||
DateColumnList.Clear();
|
||
for (int i = 0; i < dayCount; i++)
|
||
{
|
||
GridColumn gridColumn = new GridColumn();
|
||
gridColumn.AppearanceCell.Options.UseTextOptions = true;
|
||
gridColumn.AppearanceCell.TextOptions.HAlignment = HorzAlignment.Center;
|
||
gridColumn.AppearanceHeader.Options.UseTextOptions = true;
|
||
gridColumn.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
|
||
gridColumn.OptionsColumn.AllowMove = false;
|
||
gridColumn.OptionsColumn.AllowSize = false;
|
||
gridColumn.OptionsFilter.AllowFilter = false;
|
||
gridColumn.OptionsColumn.AllowMerge = DefaultBoolean.False;
|
||
gridColumn.OptionsColumn.AllowSort = DefaultBoolean.False;
|
||
gridColumn.FieldName = $"DDay_{i}";
|
||
gridColumn.Width = 70;
|
||
gridColumn.DisplayFormat.FormatType = FormatType.Numeric;
|
||
gridColumn.DisplayFormat.FormatString = "{0:#,##0.####}";
|
||
gridColumn.Visible = true;
|
||
gridColumn.SummaryItem.SummaryType = SummaryItemType.Sum;
|
||
gridColumn.SummaryItem.DisplayFormat = "{0:#,##0.####}";
|
||
gcMain.GridView.Columns.Add(gridColumn);
|
||
DateColumnList.Add(gridColumn);
|
||
}
|
||
GridColumn sumGridColumn = new GridColumn();
|
||
sumGridColumn.AppearanceCell.Options.UseTextOptions = true;
|
||
sumGridColumn.AppearanceCell.TextOptions.HAlignment = HorzAlignment.Center;
|
||
sumGridColumn.AppearanceHeader.Options.UseTextOptions = true;
|
||
sumGridColumn.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
|
||
sumGridColumn.OptionsColumn.AllowEdit = false;
|
||
sumGridColumn.OptionsColumn.AllowMove = false;
|
||
sumGridColumn.OptionsColumn.AllowSize = false;
|
||
sumGridColumn.OptionsFilter.AllowFilter = false;
|
||
sumGridColumn.OptionsColumn.AllowMerge = DefaultBoolean.False;
|
||
sumGridColumn.OptionsColumn.AllowSort = DefaultBoolean.False;
|
||
sumGridColumn.FieldName = $"workingsum";
|
||
sumGridColumn.Caption = $"工时合计";
|
||
sumGridColumn.Width = 70;
|
||
sumGridColumn.DisplayFormat.FormatType = FormatType.Numeric;
|
||
sumGridColumn.DisplayFormat.FormatString = "{0:#,##0.####}";
|
||
sumGridColumn.Visible = true;
|
||
sumGridColumn.SummaryItem.SummaryType = SummaryItemType.Sum;
|
||
sumGridColumn.SummaryItem.DisplayFormat = "{0:#,##0.####}";
|
||
SumGridColumn = sumGridColumn;
|
||
gcMain.GridView.Columns.Add(sumGridColumn);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据日期修改列状态
|
||
/// </summary>
|
||
/// <param name="currentDate"></param>
|
||
private void UpdateDynamicColumns()
|
||
{
|
||
DateTime currentDate = DateTime.Now;
|
||
BaseUserControl dateUserControl = ControlObj.FindControl("bom_rdm_ksdt");
|
||
if (dateUserControl is LabelDateEdit labelDateEdit)
|
||
{
|
||
currentDate = labelDateEdit.TextEdit.DateTime;
|
||
}
|
||
|
||
int dayCount = 0;
|
||
BaseUserControl baseUserControl = ControlObj.FindControl("bom_rdm_tianshu");
|
||
if (baseUserControl != null)
|
||
{
|
||
int.TryParse(baseUserControl.EditText, out dayCount);
|
||
}
|
||
if (dayCount <= 0)
|
||
{
|
||
dayCount = 7;
|
||
}
|
||
|
||
DateTime endDate = currentDate.AddDays(dayCount); // 保持你的原逻辑
|
||
|
||
var view = gcMain.GridView;
|
||
view.BeginUpdate();
|
||
try
|
||
{
|
||
// 1) 更新每个日期列的显示属性,并确保“动态列不固定”
|
||
for (int i = 0; i < DateColumnList.Count; i++)
|
||
{
|
||
GridColumn gridColumn = DateColumnList[i];
|
||
DateTime dateForColumn = currentDate.AddDays(i);
|
||
|
||
if (dateForColumn <= endDate)
|
||
{
|
||
gridColumn.FieldName = dateForColumn.ToString("yyyy-MM-dd");
|
||
gridColumn.Caption = dateForColumn.ToString("MM-dd");
|
||
gridColumn.Visible = true;
|
||
gridColumn.Tag = dateForColumn;
|
||
|
||
// 关键:动态日期列不要固定,让它参与水平滚动
|
||
gridColumn.Fixed = DevExpress.XtraGrid.Columns.FixedStyle.None;
|
||
}
|
||
else
|
||
{
|
||
gridColumn.Visible = false;
|
||
}
|
||
}
|
||
|
||
// 合计列也不要固定(保持可水平滚动)
|
||
if (SumGridColumn != null)
|
||
SumGridColumn.Fixed = DevExpress.XtraGrid.Columns.FixedStyle.None;
|
||
|
||
// 2) 明确“从左到右”的可见顺序
|
||
// 先找到左侧固定列的最大 VisibleIndex,动态列排在它们之后
|
||
int baseIndex = 0;
|
||
foreach (GridColumn c in view.Columns)
|
||
{
|
||
if (c.Visible && c.Fixed == DevExpress.XtraGrid.Columns.FixedStyle.Left)
|
||
baseIndex = Math.Max(baseIndex, c.VisibleIndex + 1);
|
||
}
|
||
|
||
// 起始日期在左,依次向右:start, start+1, ...
|
||
int run = 0;
|
||
for (int i = 0; i < DateColumnList.Count; i++)
|
||
{
|
||
var col = DateColumnList[i];
|
||
if (!col.Visible) continue;
|
||
col.VisibleIndex = baseIndex + run;
|
||
run++;
|
||
}
|
||
|
||
// 合计列放在日期列最后
|
||
if (SumGridColumn != null && SumGridColumn.Visible)
|
||
SumGridColumn.VisibleIndex = baseIndex + run;
|
||
}
|
||
finally
|
||
{
|
||
view.EndUpdate();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 新增汇总数据(日期修改后)
|
||
/// </summary>
|
||
private void UpdateSummaryData(DataTable table = null)
|
||
{
|
||
DataTable dataTable = new DataTable();
|
||
if (table != null)
|
||
{
|
||
dataTable = table;
|
||
}
|
||
else
|
||
{
|
||
XtraTabPage tabPage = this.xtc_left_container.SelectedTabPage;
|
||
BillSourceUnionModel model = tabPage.Tag as BillSourceUnionModel;
|
||
if (model.GridControlObj != null)
|
||
{
|
||
|
||
if (model.ModelObj.sourceDetailType.Equals("1"))
|
||
{
|
||
dataTable = model.TreeGridDetailControlObj.TreeListObj.DataSource as DataTable;
|
||
}
|
||
else
|
||
{
|
||
dataTable = model.GridDetailControlObj.GridControl.DataSource as DataTable;
|
||
}
|
||
}
|
||
}
|
||
if (dataTable != null && dataTable.Columns.Contains("num"))
|
||
{
|
||
MultiLineSummary = true;
|
||
gcMain.GridView.OptionsView.ShowFooter = true;
|
||
DataRow[] dataRows = dataTable.Select("num='999'");
|
||
DataRow dataRow = dataRows != null && dataRows.Length > 0 ? dataRows[0] : null;
|
||
gcMain.AddHeadquarters(dataRow);
|
||
}
|
||
else if (MultiLineSummary)
|
||
{
|
||
MultiLineSummary = false;
|
||
//清空新加的汇总列
|
||
gcMain.AddHeadquarters();
|
||
}
|
||
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:表格编辑时,判断是否是否编辑</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2020-03-27 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="CancelEventArgs"/> instance containing the event data.</param>
|
||
protected void OnGridViewShowingEditor(object sender, CancelEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
GridColumnModel gridColumnModel = null;
|
||
DataRow rowItem = null;
|
||
if (this.BillModel.DetailTreeTable)
|
||
{
|
||
DevExpress.XtraTreeList.TreeList treeList = (DevExpress.XtraTreeList.TreeList)sender;
|
||
TreeListColumn treeListColumn = treeList.FocusedColumn;
|
||
if (treeListColumn.Tag != null)
|
||
{
|
||
gridColumnModel = (GridColumnModel)treeListColumn.Tag;
|
||
}
|
||
rowItem = (this.gcMain as TreeGridControlEx).GetViewFocusedDataRow();
|
||
}
|
||
else
|
||
{
|
||
GridView gridView = (GridView)sender;
|
||
GridColumn gridColumn = gridView.FocusedColumn;
|
||
|
||
if (gridColumn.Tag != null)
|
||
{
|
||
gridColumnModel = (GridColumnModel)gridColumn.Tag;
|
||
|
||
}
|
||
rowItem = this.gcMain.GridView.GetDataRow(this.gcMain.GridView.FocusedRowHandle);
|
||
}
|
||
|
||
|
||
if (gridColumnModel != null && !string.IsNullOrEmpty(gridColumnModel.DisableCond))
|
||
{
|
||
//e.Cancel = !ReplaceHelper.EvalCond(ReplaceHelper.ReplaceRowParam(focusedRow, gridColumnModel.DisableCond));
|
||
//e.Cancel = !ValidateCond(gridColumnModel.DisableCond, focusedRow);
|
||
string UpdateCond = this.ControlObj.ReplaceParentControlValue(gridColumnModel.DisableCond);
|
||
UpdateCond = ReplaceHelper.ReplaceRowParam(rowItem, UpdateCond);
|
||
if (!ReplaceHelper.EvalCond(UpdateCond))
|
||
{
|
||
e.Cancel = true;//该行不可编辑
|
||
}
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(BillModel.UpdateDetailCond))
|
||
{
|
||
string UpdateCond = this.ControlObj.ReplaceParentControlValue(BillModel.UpdateDetailCond);
|
||
UpdateCond = ReplaceHelper.ReplaceRowParam(rowItem, UpdateCond);
|
||
if (!ReplaceHelper.EvalCond(UpdateCond))
|
||
{
|
||
e.Cancel = true;//该行不可编辑
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Instance.WriteError(ex);
|
||
|
||
}
|
||
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 虚拟行点击添加
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
private void InitNewRowMethod(object sender)
|
||
{
|
||
GridView view = sender as DevExpress.XtraGrid.Views.Grid.GridView;
|
||
DataTable gridTable = (this.gcMain.GridControl.DataSource as DataTable).TrimDeleteRows();
|
||
DataRow tmpRow = gridTable.NewRow();
|
||
gridTable.Rows.Add(tmpRow);
|
||
int position = gridTable.Rows.Count - 1;
|
||
foreach (DataRow dr in _detailColumns.Rows)
|
||
{
|
||
GridColumnModel model = new GridColumnModel(dr);
|
||
string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue);
|
||
|
||
|
||
if (model.DefaultValue.Contains("{#"))
|
||
{
|
||
fieldValue = this.ControlObj.ReplaceParentControlValue(model.DefaultValue);
|
||
if (!string.IsNullOrEmpty(fieldValue))
|
||
{
|
||
tmpRow[model.FieldName] = fieldValue;
|
||
}
|
||
}
|
||
else if (!string.IsNullOrEmpty(model.DefaultValue))
|
||
{
|
||
if (model.DefaultValue.Contains("{ROW"))
|
||
{
|
||
if (position > 0)
|
||
{
|
||
|
||
fieldValue = ReplaceHelper.GetParamFields(model.DefaultValue)[0];
|
||
fieldValue = fieldValue.Replace("}", "").Replace("{", "");
|
||
fieldValue = fieldValue.Substring(fieldValue.IndexOf('_') + 1);
|
||
string topFieldValue = gridTable.Rows[position - 1][fieldValue] + "";
|
||
if (gridTable.Columns[model.FieldName].DataType == typeof(DateTime))
|
||
{
|
||
if (!string.IsNullOrEmpty(topFieldValue)) tmpRow[model.FieldName] = Convert.ToDateTime(topFieldValue);
|
||
}
|
||
else
|
||
{
|
||
tmpRow[model.FieldName] = topFieldValue;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
tmpRow[model.FieldName] = fieldValue;
|
||
}
|
||
}
|
||
}
|
||
gridTable.OrderBy(this.BillModel.DetailOrderField);
|
||
|
||
if (tmpRow.Table.Columns.Contains(this.BillModel.DetailOrderField) && gridTable.Rows.Count == 0)
|
||
{
|
||
tmpRow[this.BillModel.DetailOrderField] = 1;
|
||
}
|
||
|
||
this.gcMain.GridView.UpdateCurrentRow();
|
||
this.gcMain.GridView.ShowEditor();
|
||
}
|
||
/// <summary>
|
||
/// 切换行判断是否是虚拟行数据进行数据填充
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void GridView_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
|
||
{
|
||
DataTable gridTable = (this.gcMain.GridControl.DataSource as DataTable).TrimDeleteRows();
|
||
int _rowNumber = this.gcMain.GridView.FocusedRowHandle;
|
||
int _prvFocused = e.PrevFocusedRowHandle;
|
||
int indexNumber = this.gcMain.GridView.RowCount;
|
||
if (_rowNumber < 0 && _prvFocused != gridTable.Rows.Count)
|
||
{
|
||
InitNewRowMethod(sender);
|
||
this.gcMain.GridView.FocusedRowHandle = indexNumber - 1;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:单据重写明细回车事件(用于扫码回车移动至下一行数据)</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2021-06-08 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="KeyEventArgs"/> instance containing the event data.</param>
|
||
protected void OnGridViewCellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
|
||
{
|
||
if (isDragWrap)
|
||
{
|
||
int _rowNumber = this.gcMain.GridView.FocusedRowHandle;
|
||
GridColumn focusColumn = this.gcMain.GridView.FocusedColumn;
|
||
GridColumnModel Columnmodel = focusColumn.Tag as GridColumnModel;
|
||
|
||
if (Columnmodel.FieldType == ControlType.LabSacn)
|
||
{
|
||
this.gcMain.GridView.OptionsNavigation.EnterMoveNextColumn = false;
|
||
if (this.BillModel.DefaultAddEmptyRow && _rowNumber + 1 == this.gcMain.GridView.DataRowCount)
|
||
{
|
||
DataTable gridTable = (this.gcMain.GridView.GridControl.DataSource as DataTable).TrimDeleteRows();
|
||
DataRow tmpRow = gridTable.NewRow();
|
||
gridTable.Rows.Add(tmpRow);
|
||
int position = gridTable.Rows.Count - 1;
|
||
foreach (DataRow dr in _detailColumns.Rows)
|
||
{
|
||
GridColumnModel model = new GridColumnModel(dr);
|
||
string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue);
|
||
if (model.DefaultValue.Contains("{#"))
|
||
{
|
||
fieldValue = this.ControlObj.ReplaceParentControlValue(model.DefaultValue);
|
||
if (!string.IsNullOrEmpty(fieldValue))
|
||
{
|
||
tmpRow[model.FieldName] = fieldValue;
|
||
}
|
||
}
|
||
else if (!string.IsNullOrEmpty(model.DefaultValue))
|
||
{
|
||
if (model.DefaultValue.Contains("{ROW"))
|
||
{
|
||
if (position > 0)
|
||
{
|
||
|
||
fieldValue = ReplaceHelper.GetParamFields(model.DefaultValue)[0];
|
||
fieldValue = fieldValue.Replace("}", "").Replace("{", "");
|
||
fieldValue = fieldValue.Substring(fieldValue.IndexOf('_') + 1);
|
||
string topFieldValue = gridTable.Rows[position - 1][fieldValue] + "";
|
||
if (gridTable.Columns[model.FieldName].DataType == typeof(DateTime))
|
||
{
|
||
if (!string.IsNullOrEmpty(topFieldValue)) tmpRow[model.FieldName] = Convert.ToDateTime(topFieldValue);
|
||
}
|
||
else
|
||
{
|
||
tmpRow[model.FieldName] = topFieldValue;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
tmpRow[model.FieldName] = fieldValue;
|
||
}
|
||
}
|
||
}
|
||
gridTable.OrderBy(this.BillModel.DetailOrderField);
|
||
|
||
if (tmpRow.Table.Columns.Contains(this.BillModel.DetailOrderField) && gridTable.Rows.Count == 0)
|
||
{
|
||
tmpRow[this.BillModel.DetailOrderField] = 1;
|
||
}
|
||
|
||
this.gcMain.GridView.UpdateCurrentRow();
|
||
this.gcMain.GridView.ShowEditor();
|
||
}
|
||
int ColumnIndex = this.gcMain.GridView.FocusedColumn.VisibleIndex;//焦点列的坐标
|
||
this.gcMain.GridView.FocusedRowHandle = _rowNumber + 1;
|
||
this.gcMain.GridView.FocusedColumn.VisibleIndex = ColumnIndex;
|
||
//this.gridView.OptionsNavigation.EnterMoveNextColumn = true;
|
||
}
|
||
else
|
||
{
|
||
this.gcMain.GridView.OptionsNavigation.EnterMoveNextColumn = true;
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 点击第一个默认新增行新增默认数据
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void GridView_MouseDown(object sender, MouseEventArgs e)
|
||
{
|
||
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:初始化单据来源</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-28 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void InitializeBillSource()
|
||
{
|
||
this.xtc_left_container.TabPages.Clear();
|
||
|
||
Dictionary<object, Hashtable> dataCaches = SysModel != null ? SysModel.DataCaches : null;
|
||
if (!dataCaches.GetValue(this, "Details", out List<GridDetailModel> attachModels))
|
||
{
|
||
attachModels = GetAttachTabs();
|
||
}
|
||
if (!dataCaches.GetValue(this, "Sources", out Hashtable htTable))
|
||
{
|
||
string SourceIds = (this.BillModel.BillSourceIds + "").Trim(',');
|
||
if (!string.IsNullOrWhiteSpace(this.SysModel.SourceDetailsID))
|
||
{
|
||
SourceIds = (SourceIds + "," + this.SysModel.SourceDetailsID).Trim(',');
|
||
}
|
||
htTable = BillImpl.GetSources(this.SysModel.ModuleCode, SourceIds);//获取单据来源
|
||
}
|
||
DataTable masterTable = htTable["master"] as DataTable;
|
||
DataTable detailTable = htTable["detail"] as DataTable;
|
||
|
||
|
||
|
||
|
||
/* 构造原理
|
||
* 1. 假如存在附加信息,则底部显示来源明细(来源明细摆放在标签第一个位置)+多标签,假如标签只有一个则隐藏标签头.
|
||
* 2. 假如不存在附加信息,则底部只显示来源明细.
|
||
**/
|
||
if (attachModels.Count > 0)
|
||
{
|
||
this.tb_buttom.Model = this.SysModel;
|
||
this.tb_buttom.ParentControlEx = this.ControlObj;
|
||
this.tb_buttom.ParentGridEx = this.gcMain;
|
||
if (this.BillModel.AttachmentRefreshMain)
|
||
{
|
||
this.tb_buttom.OnDetailSaveGridCallBack += Tab_OnDetailSaveGridCallBack;
|
||
}
|
||
this.tb_buttom.BillDetailRightGridCallBack += Tab_OnDetailSaveGridCallBack;//OnMrpBtnClickCallback
|
||
if (this.BillModel.RefreshSelectedDetail)
|
||
{
|
||
//配置了只刷新当前页签后,切换页签时刷新
|
||
this.tb_buttom.TabControlObj.SelectedPageChanged += TabControlObj_SelectedPageChanged;
|
||
}
|
||
this.tb_buttom.InitTabPages(attachModels);
|
||
this.tb_buttom.OnRightCallback += new EventHandler(OnButtomRightCallBack);
|
||
}
|
||
else
|
||
{
|
||
this.tb_buttom.TabControlObj.ShowTabHeader = DevExpress.Utils.DefaultBoolean.False;
|
||
}
|
||
dataCaches.GetValue(this, "InitSourcesTask", out bool _);
|
||
//dataCaches.GetValue(gcMain, "InitSourcesTask", out bool _);
|
||
|
||
for (int i = 0; i < masterTable.Rows.Count; i++)
|
||
{
|
||
DataRow sourceModelRow = masterTable.Rows[i];
|
||
BillModuleModel billModuleModel = BillModuleModelDic.ContainsKey(sourceModelRow) ? BillModuleModelDic[sourceModelRow] : new BillModuleModel();
|
||
BillSourceModel model = billModuleModel.SourceModel != null ? billModuleModel.SourceModel : new BillSourceModel(sourceModelRow);
|
||
object sourceControl = billModuleModel.SourceControl != null ? billModuleModel.SourceControl : null;
|
||
object sourceDetailControl = billModuleModel.SourceDetailControl != null ? billModuleModel.SourceDetailControl : null;
|
||
object sourceDetailDetailControl = billModuleModel.SourceDetailDetailControl != null ? billModuleModel.SourceDetailDetailControl : null;
|
||
BillSourceUnionModel unionModel = new BillSourceUnionModel();
|
||
if (!dataCaches.GetValue(model, "CustomQueryFields", out DataTable controls))
|
||
{
|
||
controls = BaseModuleImpl.GetCustomQueryFields(model.FormKey);
|
||
}
|
||
|
||
if (false)
|
||
{
|
||
string menuCode = string.Empty;
|
||
DataRow modelRow = MainImpl.GetSystemdllTab(menuCode);//获取模块信息
|
||
ModuleModel sysModel = new ModuleModel(modelRow);
|
||
//设置主表sql
|
||
//model.SourceSql = sysModel.MenuSql;
|
||
//获取主表列
|
||
DataTable dtSourceColumns = BaseModuleImpl.GetBaseGridColumns(sysModel.ModeCode);
|
||
//获取明细消息
|
||
|
||
//明细sql
|
||
//model.DetailSql
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
XtraTabPage tabPage = new XtraTabPage();
|
||
tabPage.Text = model.UserName;
|
||
|
||
|
||
|
||
#region 加载快速添加
|
||
if (!string.IsNullOrWhiteSpace(model.CodeInputSql) && !string.IsNullOrWhiteSpace(model.CodeInputCaption))
|
||
{
|
||
ComboBoxEditModel editModel = new ComboBoxEditModel()
|
||
{
|
||
ValuemMeber = "id",
|
||
TextMember = "CodeInputCaption",
|
||
RowItem = masterTable.Rows[i],
|
||
SourceModel = model,
|
||
UnionModel = unionModel
|
||
};
|
||
this.cb_input.Properties.Items.Add(editModel);
|
||
}
|
||
#endregion
|
||
|
||
#region 加载来源表头
|
||
GridControlEx gridControl = null;
|
||
TreeViewEx treeView = null;
|
||
|
||
if (model.SourceType == 1)
|
||
{
|
||
// 来源为树类型
|
||
treeView = sourceControl != null ? (TreeViewEx)sourceControl : new TreeViewEx();
|
||
treeView.BorderStyle = BorderStyle.None;
|
||
treeView.Dock = DockStyle.Fill;
|
||
treeView.TreeNodeKeyField = model.SourceKeyField;
|
||
treeView.TreeNodeTextField = model.SourceResult;
|
||
if (!dataCaches.GetValue(treeView, "BindTreeTable", out DataTable bindTreeTable))
|
||
{
|
||
bindTreeTable = BaseImpl.GetDataTableResult(model.SourceSql);
|
||
}
|
||
treeView.TreeInhibitSort = model.TreeInhibitSort;
|
||
treeView.BindTreeView(bindTreeTable);
|
||
treeView.TreeNodeSelectAfter += new TreeViewEventHandler(OnTreeNodeSelectAfter);
|
||
|
||
tabPage.Controls.Add(treeView);
|
||
}
|
||
else if (model.SourceType == 5)
|
||
{
|
||
model.ChangeSourceType(2);//单据来源显示条数
|
||
this.IsBillShowCount = true;
|
||
}
|
||
else if (model.SourceType == 3 || model.SourceType == 4)
|
||
{
|
||
//类型为3,是树表格类型的单据管理。
|
||
//类型为4,是树表格类型的数据来源
|
||
gridControl = sourceControl != null ? (TreeGridControlEx)sourceControl : new TreeGridControlEx();
|
||
gridControl.Dock = DockStyle.Fill;
|
||
gridControl.BorderStyle = System.Windows.Forms.BorderStyle.None;
|
||
gridControl.Model = this.SysModel;
|
||
|
||
if (!dataCaches.GetValue(gridControl, "SourceColumns", out DataTable dtSourceColumns))
|
||
{
|
||
dtSourceColumns = BillImpl.GetSourceColumns(model.Id);
|
||
}
|
||
if (!dataCaches.GetValue(gridControl, "BaseGridRowColors", out DataTable dtBaseGridRowColors))
|
||
{
|
||
dtBaseGridRowColors = BaseModuleImpl.GetBaseGridRowColors("BILLSOURCE_" + model.FormKey);
|
||
}
|
||
if (!dataCaches.GetValue(gridControl, "BaseGridRightMenus", out DataTable dtBaseGridRightMenus))
|
||
{
|
||
dtBaseGridRightMenus = BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCE_" + model.FormKey);
|
||
}
|
||
|
||
//节点编号
|
||
if (!string.IsNullOrWhiteSpace(model.SourceKeyFieldName)) (gridControl as TreeGridControlEx).TreeListObj.KeyFieldName = model.SourceKeyFieldName;
|
||
//父节点编号
|
||
if (!string.IsNullOrWhiteSpace(model.SourceParentFieldName)) (gridControl as TreeGridControlEx).TreeListObj.ParentFieldName = model.SourceParentFieldName;
|
||
|
||
gridControl.SetReadOnlyColumns(dtSourceColumns, GridCustomColumnStruct.BillSourceGridView + model.FormKey);
|
||
gridControl.SetGridRowColors(dtBaseGridRowColors);
|
||
//gridControl.SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridControlRightCallback);
|
||
(gridControl as TreeGridControlEx).SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridControlRightCallback);
|
||
unionModel.TreeGridControlObj = gridControl as TreeGridControlEx;
|
||
unionModel.TreeGridControlObj.TreeListObj.FocusedNodeChanged += new DevExpress.XtraTreeList.FocusedNodeChangedEventHandler(OnTreeListObjFocusedNodeChanged);
|
||
|
||
|
||
if (BillModel.IsBillSourceCheck == 1)
|
||
{
|
||
GridDragGrid.TreeListAddCheckBox((gridControl as TreeGridControlEx).TreeListObj);
|
||
}
|
||
|
||
if (model.SourceType == 4)
|
||
{
|
||
//来源拖拽到主表
|
||
if (this.BillModel.DetailTreeTable)
|
||
{
|
||
TreeGridDragTree treeGridDragTree = new TreeGridDragTree((gridControl as TreeGridControlEx).TreeListObj, (this.gcMain as TreeGridControlEx).TreeListObj);
|
||
treeGridDragTree.CanDragParentNode = true;
|
||
treeGridDragTree.NeglectingNodes = true;
|
||
treeGridDragTree.OnDragComplete += TreeGridDragTree_OnDragComplete;
|
||
}
|
||
else
|
||
{
|
||
TreeGridDragGrid treeGridDragGrid = new TreeGridDragGrid((gridControl as TreeGridControlEx).TreeListObj, this.gcMain.GridView);
|
||
treeGridDragGrid.OnDragComplete += TreeGridDragGrid_OnDragComplete;
|
||
}
|
||
}
|
||
|
||
|
||
tabPage.Controls.Add(gridControl);
|
||
}
|
||
else
|
||
{
|
||
// 来源为表格类型
|
||
gridControl = sourceControl != null ? (GridControlEx)sourceControl : new GridControlEx();
|
||
gridControl.BorderStyle = BorderStyle.None;
|
||
gridControl.Model = this.SysModel;
|
||
gridControl.Dock = DockStyle.Fill;
|
||
gridControl.ExportPermission = this.BillModel.ExportPermission;
|
||
|
||
if (model.LoadFilter)
|
||
{
|
||
gridControl.GridView.OptionsView.ShowAutoFilterRow = true;
|
||
}
|
||
if (!dataCaches.GetValue(gridControl, "SourceColumns", out DataTable dtSourceColumns))
|
||
{
|
||
dtSourceColumns = BillImpl.GetSourceColumns(model.Id);
|
||
}
|
||
if (!dataCaches.GetValue(gridControl, "BaseGridRowColors", out DataTable dtBaseGridRowColors))
|
||
{
|
||
dtBaseGridRowColors = BaseModuleImpl.GetBaseGridRowColors("BILLSOURCE_" + model.FormKey);
|
||
}
|
||
if (!dataCaches.GetValue(gridControl, "BaseGridRightMenus", out DataTable dtBaseGridRightMenus))
|
||
{
|
||
dtBaseGridRightMenus = BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCE_" + model.FormKey);
|
||
}
|
||
gridControl.SetReadOnlyColumns(dtSourceColumns, GridCustomColumnStruct.BillSourceGridView + model.FormKey);
|
||
gridControl.SetGridRowColors(dtBaseGridRowColors);
|
||
gridControl.SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridControlRightCallback);
|
||
//gridControl.GridView.SelectionChanged += new SelectionChangedEventHandler(OnGridControlSelectionChanged);
|
||
//gridControl.GridView.FocusedRowObjectChanged += OnFocusedRowObjectChanged;
|
||
if (model.DetailsDoubleClick)
|
||
{
|
||
gridControl.GridView.DoubleClick += OnSourceGridViewDoubleClick; // 2023-3-11 增加双击配置
|
||
}
|
||
else
|
||
{
|
||
gridControl.GridView.RowCellClick += OnGridViewRowCellClick; // 2019-11-12 cmd提出改为行点击事件,否则会出现保存提交后,单据管理无法查询出数据
|
||
}
|
||
|
||
if (BillModel.IsBillSourceCheck == 1)
|
||
{
|
||
GridDragGrid.GridAddCheckBox(gridControl.GridView);
|
||
}
|
||
if (model.SourceType == 0)
|
||
{
|
||
//来源拖拽到主表
|
||
if (this.BillModel.DetailTreeTable)
|
||
{
|
||
GridDragTreeGrid dragDetailGrid = new GridDragTreeGrid(gridControl.GridView, (this.gcMain as TreeGridControlEx).TreeListObj);
|
||
dragDetailGrid.CanDragParentNode = true;
|
||
dragDetailGrid.NeglectingNodes = true;
|
||
dragDetailGrid.OnDragComplete += DragDetailGrid_OnDragMainGridCompleted;
|
||
}
|
||
else
|
||
{
|
||
GridDragGrid dragMainGrid = new GridDragGrid(gridControl.GridView, this.gcMain.GridView);
|
||
dragMainGrid.OnDragComplete += new GridFragGridCompleteEventHandler(OnDragMainGridCompleted);
|
||
}
|
||
}
|
||
|
||
tabPage.Controls.Add(gridControl);
|
||
}
|
||
#endregion
|
||
|
||
#region 加载来源明细
|
||
XtraTabPage tabDetail = new XtraTabPage();
|
||
|
||
if (SystemInfo.Instance.GridRowFontSize > 0)
|
||
{
|
||
//页签大小
|
||
FontFamily fontFamily = tabDetail.Appearance.Header.Font.FontFamily;
|
||
tabDetail.Appearance.Header.Font = new System.Drawing.Font(fontFamily, SystemInfo.Instance.GridRowFontSize);
|
||
}
|
||
|
||
DataRow[] detailColumns = detailTable.Select("sourceId=" + model.Id);
|
||
|
||
|
||
//明细为表格
|
||
GridControlEx gridDetail = new GridControlEx();
|
||
|
||
|
||
if (model.sourceDetailType.Equals("1"))
|
||
{
|
||
//明细为树表格
|
||
gridDetail = sourceDetailControl != null ? (TreeGridControlEx)sourceDetailControl : new TreeGridControlEx();
|
||
gridDetail.Model = this.SysModel;
|
||
gridDetail.Dock = DockStyle.Fill;
|
||
gridDetail.SetReadOnlyColumns(detailColumns == null || detailColumns.Length == 0 ? new DataTable() : detailColumns.CopyToDataTable(), GridCustomColumnStruct.BillSourceDetailGridView + model.FormKey);
|
||
if (!dataCaches.GetValue(gridDetail, "BaseGridRowColors", out DataTable dtBaseGridRowColors))
|
||
{
|
||
dtBaseGridRowColors = BaseModuleImpl.GetBaseGridRowColors("SOURCEDETAIL_" + model.FormKey);
|
||
}
|
||
if (!dataCaches.GetValue(gridDetail, "BaseGridRightMenus", out DataTable dtBaseGridRightMenus))
|
||
{
|
||
dtBaseGridRightMenus = BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCEDT_" + model.FormKey);
|
||
}
|
||
gridDetail.SetGridRowColors(dtBaseGridRowColors);
|
||
gridDetail.SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridDetailRightMenuCallback);
|
||
gridDetail.Parent = tabDetail;
|
||
gridDetail.BorderStyle = System.Windows.Forms.BorderStyle.None;
|
||
|
||
if (i == 0)
|
||
{
|
||
this.tb_buttom.TabControlObj.TabPages.Insert(0, tabDetail);
|
||
this.tb_buttom.TabControlObj.SelectedTabPageIndex = 0;
|
||
if (attachModels.Count > 0)
|
||
this.tb_buttom.TabControlObj.TabPages[0].Text = model.UserName + DetailedSuffix;
|
||
}
|
||
if (model.MainDetailsAddType != "2")
|
||
{
|
||
TreeGridDragGrid treeGridDragGrid = new TreeGridDragGrid((gridDetail as TreeGridControlEx).TreeListObj, this.gcMain.GridView);
|
||
treeGridDragGrid.OnDragComplete += new TreeGridDragGridCompleteEventHandler(OnTreeGridDetailGridCompleted);
|
||
}
|
||
if (BillModel.IsBillDetailCheck == 1)//加载复选框
|
||
{
|
||
GridDragGrid.TreeListAddCheckBox((gridDetail as TreeGridControlEx).TreeListObj);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
|
||
gridDetail = sourceDetailControl != null ? (GridControlEx)sourceDetailControl : new GridControlEx();
|
||
gridDetail.Model = this.SysModel;
|
||
gridDetail.Dock = DockStyle.Fill;
|
||
gridDetail.SetReadOnlyColumns(detailColumns == null || detailColumns.Length == 0 ? new DataTable() : detailColumns.CopyToDataTable(), GridCustomColumnStruct.BillSourceDetailGridView + model.FormKey);
|
||
|
||
if (model.DetailedLoadFilter)
|
||
{
|
||
gridDetail.GridView.OptionsView.ShowAutoFilterRow = true;
|
||
}
|
||
if (!dataCaches.GetValue(gridDetail, "BaseGridRowColors", out DataTable dtBaseGridRowColors))
|
||
{
|
||
dtBaseGridRowColors = BaseModuleImpl.GetBaseGridRowColors("SOURCEDETAIL_" + model.FormKey);
|
||
}
|
||
if (!dataCaches.GetValue(gridDetail, "BaseGridRightMenus", out DataTable dtBaseGridRightMenus))
|
||
{
|
||
dtBaseGridRightMenus = BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCEDT_" + model.FormKey);
|
||
}
|
||
gridDetail.SetGridRowColors(dtBaseGridRowColors);
|
||
gridDetail.SetGridRightMenus(dtBaseGridRightMenus, this.SysModel, OnGridDetailRightMenuCallback);
|
||
if (BillModel.IsBillDetailCheck == 0)
|
||
{
|
||
if (model.MainDetailsAddType != "2") gridDetail.GridView.DoubleClick += new EventHandler(OnGridDetailDoubleClick);
|
||
}
|
||
//明细的明细(明细分成左右2个)
|
||
if (!string.IsNullOrEmpty(model.SourceDetailsDetailsSql))
|
||
{
|
||
GridControlEx gridDetail_Details = sourceDetailDetailControl != null ? (GridControlEx)sourceDetailDetailControl : new GridControlEx();
|
||
gridDetail_Details.Model = this.SysModel;
|
||
gridDetail_Details.Dock = DockStyle.Fill;
|
||
//创建只读列
|
||
if (!dataCaches.GetValue(gridDetail_Details, "Detail_Details", out DataTable dataTable))
|
||
{
|
||
dataTable = BaseModuleImpl.getDetail_Details(model.FormKey);
|
||
}
|
||
gridDetail_Details.SetReadOnlyColumns(dataTable);
|
||
//设置右键
|
||
if (!dataCaches.GetValue(gridDetail_Details, "BaseGridRightMenus", out DataTable dttBaseGridRightMenus))
|
||
{
|
||
dttBaseGridRightMenus = BaseModuleImpl.GetBaseGridRightMenus("BILLSOURCEDTX_" + model.FormKey);
|
||
}
|
||
gridDetail_Details.SetGridRightMenus(dttBaseGridRightMenus, this.SysModel, OnGridDetailRightMenuCallback);
|
||
//明细点击 更新 明细的明细
|
||
gridDetail.GridView.FocusedRowObjectChanged += GridView_FocusedRowObjectChanged;
|
||
gridDetail.GridView.Tag = model.SourceDetailsDetailsSql;
|
||
//创建SplitContainerControl控件,让下方可以左右拖动
|
||
SplitContainerControl splitContainerControl = new DevExpress.XtraEditors.SplitContainerControl();
|
||
splitContainerControl.Dock = DockStyle.Fill;
|
||
splitContainerControl.Panel1.Controls.Add(gridDetail);
|
||
gridDetail.BorderStyle = System.Windows.Forms.BorderStyle.None;
|
||
splitContainerControl.Panel2.Controls.Add(gridDetail_Details);
|
||
gridDetail_Details.BorderStyle = System.Windows.Forms.BorderStyle.None;
|
||
|
||
splitContainerControl.SplitterMoved += new System.EventHandler(this.OnDetailsSplitterMoved);
|
||
string newwidth = IniHelper.Read(string.Format("bill_Details_Width_{0}", this.SysModel.ModuleCode));//通过Key获取Value值
|
||
if (!string.IsNullOrEmpty(newwidth))
|
||
{
|
||
splitContainerControl.SplitterPosition = Convert.ToInt32(newwidth);
|
||
}
|
||
else
|
||
{
|
||
int width = this.tb_buttom.Width;//获取控件宽度
|
||
splitContainerControl.SplitterPosition = width / 2;//然后将分割位置设置在宽度一半位置
|
||
}
|
||
if (model.MainDetailsAddType != "1")
|
||
{
|
||
//明细的明细拖拽到上方
|
||
if (this.BillModel.DetailTreeTable)
|
||
{
|
||
GridDragTreeGrid dragDetaigDetailGrid = new GridDragTreeGrid(gridDetail_Details.GridView, (this.gcMain as TreeGridControlEx).TreeListObj);
|
||
dragDetaigDetailGrid.CanDragParentNode = true;
|
||
dragDetaigDetailGrid.NeglectingNodes = true;
|
||
dragDetaigDetailGrid.OnDragComplete += DragDetailGrid_OnDragComplete;
|
||
}
|
||
else
|
||
{
|
||
GridDragGrid dragDetaigDetailGrid = new GridDragGrid(gridDetail_Details.GridView, this.gcMain.GridView);
|
||
dragDetaigDetailGrid.OnDragComplete += new GridFragGridCompleteEventHandler(OnDragDetailGridCompleted);
|
||
}
|
||
|
||
if (BillModel.IsBillDetailCheck == 0)
|
||
{
|
||
//明细的明细双击加载到上方
|
||
gridDetail_Details.GridView.DoubleClick += new EventHandler(OnGridDetailDetailDoubleClick);
|
||
}
|
||
}
|
||
|
||
splitContainerControl.Parent = tabDetail;
|
||
unionModel.GridDetailDetailControlObj = gridDetail_Details;
|
||
}
|
||
else
|
||
{
|
||
gridDetail.Parent = tabDetail;
|
||
gridDetail.BorderStyle = System.Windows.Forms.BorderStyle.None;
|
||
|
||
}
|
||
|
||
if (i == 0)
|
||
{
|
||
this.tb_buttom.TabControlObj.TabPages.Insert(0, tabDetail);
|
||
this.tb_buttom.TabControlObj.SelectedTabPageIndex = 0;
|
||
if (attachModels.Count > 0)
|
||
this.tb_buttom.TabControlObj.TabPages[0].Text = model.UserName + DetailedSuffix;
|
||
}
|
||
|
||
if (model.MainDetailsAddType != "2")
|
||
{
|
||
if (this.BillModel.DetailTreeTable)
|
||
{
|
||
GridDragTreeGrid dragDetailGrid = new GridDragTreeGrid(gridDetail.GridView, (this.gcMain as TreeGridControlEx).TreeListObj);
|
||
dragDetailGrid.CanDragParentNode = true;
|
||
dragDetailGrid.NeglectingNodes = true;
|
||
dragDetailGrid.OnDragComplete += DragDetailGrid_OnDragComplete;
|
||
|
||
unionModel.AddDataSql = model.AddDataSql;
|
||
unionModel.AddDataCondition = model.AddDataCondition;
|
||
}
|
||
else
|
||
{
|
||
GridDragGrid dragDetailGrid = new GridDragGrid(gridDetail.GridView, this.gcMain.GridView);
|
||
dragDetailGrid.OnDragComplete += new GridFragGridCompleteEventHandler(OnDragDetailGridCompleted);
|
||
if (this.BillModel.IsSelectSourceColor) gridDetail.GridView.CustomDrawCell += GridView_CustomDrawCell;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
if (BillModel.IsBillDetailCheck == 1)//加载复选框
|
||
{
|
||
GridDragGrid.GridAddCheckBox(gridDetail.GridView);
|
||
}
|
||
}
|
||
|
||
|
||
#endregion
|
||
|
||
#region 加载来源条件
|
||
if (model.SourceType == 1 && (controls == null || controls.Rows.Count == 0))
|
||
{
|
||
// 设置默认下拉列表框
|
||
DataTable columnTable = detailTable.Select("sourceId=" + model.Id + " and isnull(isVisible,0)=0").CopyToDataTable();
|
||
this.lceCombobox.ValueMember = this.lceCombobox.ValueField = "fieldName";
|
||
this.lceCombobox.TextField = "userName";
|
||
this.lceCombobox.SetDataSource(columnTable);
|
||
this.lceCombobox.TextEdit.SelectedIndex = 0;
|
||
|
||
this.pl_treeview_detault_search.Dock = DockStyle.Bottom;
|
||
this.pl_treeview_detault_search.Visible = true;
|
||
|
||
tabPage.Controls.Add(pl_treeview_detault_search);
|
||
}
|
||
else
|
||
{
|
||
// 创建自定义条件
|
||
string searchSql = model.SourceType == 1 ? Regex.Replace(model.DetailSql, "{speciesno}", "", RegexOptions.IgnoreCase) : model.SourceSql;
|
||
//searchSql = ReplaceHelper.ReplaceParam(searchSql);
|
||
PanelControl searchPanel = new PanelControl();
|
||
if (!dataCaches.GetValue(sourceModelRow, "SearchControl", out MyControl searchControl))
|
||
{
|
||
searchControl = new MyControl(searchSql, gridControl == null ? gridDetail : gridControl, treeView);
|
||
}
|
||
searchControl.OnSearchBeforeCallBack += new SearchEventHandler(OnSearchBefore);
|
||
searchControl.OnSearchAfterCallBack += new EventHandler(OnSearchAfterd);
|
||
if (i == 0 && !SystemInfo.Instance.IsBillSourceRefushTag.Equals("1") && string.IsNullOrWhiteSpace(this.BillModel.InitialRefreshId))
|
||
{
|
||
// 第一个页面要刷新数据,所以绑定事件用于初始化完成后在查询数据
|
||
searchControl.OnDataSourceBindCallBack += new EventHandler(OnFirstPageDataSourceBindCallBack);
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(this.BillModel.InitialRefreshId) && this.BillModel.InitialRefreshId.Equals(model.Id + ""))
|
||
{
|
||
searchControl.OnDataSourceBindCallBack += SearchControl_OnDataSourceBindCallBack;
|
||
InitialSelectionTab = tabPage;
|
||
}
|
||
|
||
searchControl.ParentUnionField = model.SourceKeyField;
|
||
|
||
searchPanel.Dock = DockStyle.Bottom;
|
||
searchPanel.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
|
||
searchPanel.BackColor = Color.Transparent;
|
||
searchPanel.Parent = tabPage;
|
||
searchControl.OtherParams = this.SysModel.OtherParams();
|
||
searchPanel.Height = searchControl.InitSearchControl(controls, searchPanel);
|
||
unionModel.SearchObj = searchControl;
|
||
}
|
||
#endregion
|
||
|
||
unionModel.GridControlObj = gridControl;
|
||
if (model.sourceDetailType.Equals("1"))
|
||
{
|
||
unionModel.TreeGridDetailControlObj = (gridDetail as TreeGridControlEx);
|
||
}
|
||
else
|
||
{
|
||
unionModel.GridDetailControlObj = gridDetail;
|
||
}
|
||
|
||
|
||
|
||
|
||
unionModel.ModelObj = model;
|
||
unionModel.TreeViewObj = treeView;
|
||
if (i == 0)
|
||
unionModel.IsChange = true;
|
||
tabPage.Tag = unionModel;
|
||
if (model.SourceType == 0 && !model.DisableShowSourceCount)
|
||
{
|
||
// 模块要查看具体条数
|
||
unionModel.SearchObj.OnDataSourceBindCallBack += new EventHandler(OnPageDataSourceBindCallBack);
|
||
pageNumKey.Add(unionModel.SearchObj, tabPage);
|
||
}
|
||
this.xtc_left_container.TabPages.Add(tabPage);
|
||
}
|
||
if (this.cb_input.Properties.Items.Count > 0)
|
||
{
|
||
this.pl_input.Visible = true;
|
||
this.cb_input.SelectedIndex = 0;
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 单据来源拖拽到主表明细中(树表格拖拽到树表格)
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void TreeGridDragTree_OnDragComplete(object sender, TreeGridDragTreeGridArgs e)
|
||
{
|
||
if (e.GridViewSelectRows == null || e.GridViewSelectRows.Length == 0) return;
|
||
|
||
try
|
||
{
|
||
if (this.CanAddDetailRow())
|
||
{
|
||
if (this.BillModel.DisableDragPrompt || MessageUtil.Show(ResourceKeys.DragSelectRow, MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||
{
|
||
XtraTabPage tabPage = this.xtc_left_container.SelectedTabPage;
|
||
BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel;
|
||
TreeListNode focusedNode = e.SourceTreeList.FocusedNode;
|
||
var selectedNodes = e.SourceTreeList.Selection;
|
||
int i = 0;
|
||
foreach (TreeListNode treeNode in e.SourceTreeList.Selection)
|
||
{
|
||
// 拖动多行,所以明细数据改为动态查询
|
||
DataRowView dataRowView = e.SourceTreeList.GetDataRecordByNode(treeNode) as DataRowView;
|
||
DataRow rowItem = dataRowView != null ? dataRowView.Row : null;
|
||
this.RefreshSourceDetail(tabPage.Tag as BillSourceUnionModel);
|
||
DataTable details = BillImpl.GetDataTableResult(ReplaceHelper.ReplaceRowParam(rowItem, unionModel.ModelObj.DetailSql));
|
||
if (unionModel.ModelObj.sourceDetailType != "1" && unionModel.GridDetailControlObj.GridView != null && focusedNode == treeNode)
|
||
{
|
||
//details = unionModel.GridDetailControlObj.GridView.GetGridViewFilteredAndSortedDataToDataTable();
|
||
details = unionModel.GridDetailControlObj.GridControl.DataSource as DataTable;
|
||
}
|
||
else if (unionModel.ModelObj.sourceDetailType == "1" && unionModel.TreeGridDetailControlObj.TreeListObj != null && focusedNode == treeNode)
|
||
{
|
||
details = unionModel.TreeGridDetailControlObj.TreeListObj.DataSource as DataTable;
|
||
}
|
||
//details = GetGridViewFilteredAndSortedDataToDataTable(unionModel.GridDetailControlObj.GridView);
|
||
//DataTable details = unionModel.GridDetailControlObj.GridView.DataController.GetAllFilteredAndSortedRows().OfType<DataRow>().CopyToDataTable();
|
||
this.ControlObj.SetAllControlValue(rowItem, this.BillModel.isReplaceFixed);
|
||
|
||
if (unionModel.ModelObj.CadDragDetail)
|
||
{
|
||
this.AddMultiRowToGridView(details, unionModel);
|
||
|
||
if (BillModel.drgFinishHide == "1" && unionModel.GridDetailControlObj != null)
|
||
{
|
||
var detailRows = details.AsEnumerable().ToList();
|
||
foreach (var detailRow in detailRows)
|
||
{
|
||
if (unionModel.GridDetailControlObj.GridControl.DataSourceTable().Rows.IndexOf(detailRow) >= 0)
|
||
{
|
||
unionModel.GridDetailControlObj.GridControl.DataSourceTable().Rows.Remove(detailRow);
|
||
}
|
||
if (unionModel.GridDetailDetailControlObj != null && unionModel.GridDetailDetailControlObj.GridControl.DataSourceTable().Rows.IndexOf(detailRow) >= 0)
|
||
{
|
||
unionModel.GridDetailDetailControlObj.GridControl.DataSourceTable().Rows.Remove(detailRow);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
//单据为新增状态,根据最后一行的内容设置红蓝单据
|
||
if (!this.BillModel.SaveState && e.SourceTreeList.Selection.Count - 1 == i && rowItem.Table.Columns.Contains(this.BillModel.RtagidKey) && this.BillModel.BillFlag != 0 && this.BillModel.BillFlag != 1)
|
||
{
|
||
if ("0".Equals(rowItem[this.BillModel.RtagidKey] + ""))
|
||
{
|
||
this.rdBlue.Checked = true;
|
||
this.OnBlueStateClick(null, null);
|
||
}
|
||
if ("1".Equals(rowItem[this.BillModel.RtagidKey] + ""))
|
||
{
|
||
this.rdRed.Checked = true;
|
||
this.OnRedStateClick(null, null);
|
||
}
|
||
}
|
||
i++;
|
||
}
|
||
if (unionModel.ModelObj.DragAndSave && e.SourceTreeList.Selection.Count == i && i != 0)
|
||
{
|
||
this.OnBillSaveClick(null, null);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Instance.WriteError(ex);
|
||
LogUtil.WriteError("单据来源表格拖拽完出错!", ex);
|
||
MessageUtil.Show(ResourceKeys.OperFault);
|
||
}
|
||
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 单据来源拖拽到主表明细中(树表格拖拽到表格)
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void TreeGridDragGrid_OnDragComplete(object sender, TreeGridDragGridArgs e)
|
||
{
|
||
if (e.GridViewSelectRows == null || e.GridViewSelectRows.Length == 0) return;
|
||
|
||
try
|
||
{
|
||
if (this.CanAddDetailRow())
|
||
{
|
||
if (this.BillModel.DisableDragPrompt || MessageUtil.Show(ResourceKeys.DragSelectRow, MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||
{
|
||
XtraTabPage tabPage = this.xtc_left_container.SelectedTabPage;
|
||
BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel;
|
||
int i = 0;
|
||
TreeListNode focusedNode = e.TreeListObj.FocusedNode;
|
||
var selectedNodes = e.TreeListObj.Selection;
|
||
foreach (TreeListNode treeNode in e.TreeListObj.Selection)
|
||
{
|
||
// 拖动多行,所以明细数据改为动态查询
|
||
DataRowView dataRowView = e.TreeListObj.GetDataRecordByNode(treeNode) as DataRowView;
|
||
DataRow rowItem = dataRowView != null ? dataRowView.Row : null;
|
||
this.RefreshSourceDetail(tabPage.Tag as BillSourceUnionModel);
|
||
DataTable details = BillImpl.GetDataTableResult(ReplaceHelper.ReplaceRowParam(rowItem, unionModel.ModelObj.DetailSql));
|
||
if (unionModel.ModelObj.sourceDetailType != "1" && unionModel.GridDetailControlObj.GridView != null && focusedNode == treeNode)
|
||
{
|
||
details = unionModel.GridDetailControlObj.GridControl.DataSource as DataTable;
|
||
}
|
||
else if (unionModel.ModelObj.sourceDetailType == "1" && unionModel.TreeGridDetailControlObj.TreeListObj != null && focusedNode == treeNode)
|
||
{
|
||
details = unionModel.TreeGridDetailControlObj.TreeListObj.DataSource as DataTable;
|
||
}
|
||
this.ControlObj.SetAllControlValue(rowItem, this.BillModel.isReplaceFixed);
|
||
|
||
if (unionModel.ModelObj.CadDragDetail)
|
||
{
|
||
this.AddMultiRowToGridView(details, unionModel);
|
||
|
||
if (BillModel.drgFinishHide == "1" && unionModel.GridDetailControlObj != null)
|
||
{
|
||
var detailRows = details.AsEnumerable().ToList();
|
||
foreach (var detailRow in detailRows)
|
||
{
|
||
if (unionModel.GridDetailControlObj.GridControl.DataSourceTable().Rows.IndexOf(detailRow) >= 0)
|
||
{
|
||
unionModel.GridDetailControlObj.GridControl.DataSourceTable().Rows.Remove(detailRow);
|
||
}
|
||
if (unionModel.GridDetailDetailControlObj != null && unionModel.GridDetailDetailControlObj.GridControl.DataSourceTable().Rows.IndexOf(detailRow) >= 0)
|
||
{
|
||
unionModel.GridDetailDetailControlObj.GridControl.DataSourceTable().Rows.Remove(detailRow);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
//单据为新增状态,根据最后一行的内容设置红蓝单据
|
||
if (!this.BillModel.SaveState && e.TreeListObj.Selection.Count - 1 == i && rowItem.Table.Columns.Contains(this.BillModel.RtagidKey) && this.BillModel.BillFlag != 0 && this.BillModel.BillFlag != 1)
|
||
{
|
||
if ("0".Equals(rowItem[this.BillModel.RtagidKey] + ""))
|
||
{
|
||
this.rdBlue.Checked = true;
|
||
this.OnBlueStateClick(null, null);
|
||
}
|
||
if ("1".Equals(rowItem[this.BillModel.RtagidKey] + ""))
|
||
{
|
||
this.rdRed.Checked = true;
|
||
this.OnRedStateClick(null, null);
|
||
}
|
||
}
|
||
i++;
|
||
}
|
||
if (unionModel.ModelObj.DragAndSave && e.TreeListObj.Selection.Count == i && i != 0)
|
||
{
|
||
this.OnBillSaveClick(null, null);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Instance.WriteError(ex);
|
||
LogUtil.WriteError("单据来源表格拖拽完出错!", ex);
|
||
MessageUtil.Show(ResourceKeys.OperFault);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 点击来源明细,加载明细的明细
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void GridView_FocusedRowObjectChanged(object sender, FocusedRowObjectChangedEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
|
||
GridView gridView = sender as GridView;
|
||
DataRow rowItem = gridView.GetFocusedDataRow();
|
||
string sql = gridView.Tag + "";
|
||
BillSourceUnionModel unionModel = this.xtc_left_container.SelectedTabPage.Tag as BillSourceUnionModel;
|
||
if (unionModel.GridDetailDetailControlObj != null)
|
||
{
|
||
unionModel.GridDetailDetailControlObj.gridControl.DataSource = BillImpl.GetDataTableResult(ReplaceHelper.ReplaceRowParam(rowItem, sql));
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageUtil.Show(ex);
|
||
}
|
||
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:验证单据是否修改过</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期: </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void VerfyBillUpdated()
|
||
{
|
||
bool isUpdateDetailed = false;
|
||
DataTable table = this.gcMain.gridControl.DataSource as DataTable;
|
||
if (table != null && table.Rows.Count > 0)
|
||
{
|
||
DataRow updateRow = table.Rows.Cast<DataRow>().FirstOrDefault(x => x.RowState != DataRowState.Unchanged);
|
||
isUpdateDetailed = updateRow != null;
|
||
}
|
||
if (this.BillRowItem != null && (this.ControlObj.VerifyUpdated() || isUpdateDetailed))
|
||
{
|
||
bool isReadOnly2 = !string.IsNullOrEmpty(this.BillModel.ModifyCond) && !ReplaceHelper.ReplaceRowParamCond(this.BillRowItem, this.BillModel.ModifyCond);
|
||
if (!isReadOnly2)
|
||
{
|
||
if (MessageUtil.Show(ResourceKeys.DataChanged, MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||
{
|
||
this.BillSave();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:初始化单据按钮状态</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-12-04 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="isEdit">if set to <c>true</c> [is edit].</param>
|
||
private void SetBillStatus(DataRow rowItem)
|
||
{
|
||
if (this.BillModel.unableToSave.Contains(SysModel.UserName))
|
||
{
|
||
this.btnBillSave.Hide();
|
||
foreach (System.Windows.Forms.Control control in pl_main_bottom.Controls)
|
||
{
|
||
|
||
if (control.Location.X < btnBillSave.Location.X && control is DevExpress.XtraEditors.SimpleButton && control.Name != "btn_input")
|
||
{
|
||
control.Location = new Point(control.Location.X + btnBillSave.Width, control.Location.Y);
|
||
}
|
||
}
|
||
}
|
||
if (rowItem != null)
|
||
{
|
||
// 单据为修改状态,无需设置赋值时不需要计算面板属性
|
||
bool isReadOnly = !string.IsNullOrEmpty(this.BillModel.ModifyCond) && !ReplaceHelper.ReplaceRowParamCond(rowItem, this.BillModel.ModifyCond);
|
||
this.ControlObj.CanExecControl = false; // 单据为修改状态时,无需计算面板属性
|
||
this.lbTitle.Text = this.BillModel.TypeName + updateText;
|
||
this.lblOrderNo.Text = rowItem[this.BillModel.PrimaryKey] + "";
|
||
this.rdBlue.Checked = "0".Equals(rowItem[this.BillModel.RtagidKey] + "");
|
||
this.rdRed.Checked = "1".Equals(rowItem[this.BillModel.RtagidKey] + "");
|
||
this.BillModel.SaveState = true;
|
||
this.rdBlue.Enabled = this.rdRed.Enabled = false;
|
||
this._itemImport.Enabled = this._itemImportUpdate.Enabled = !isReadOnly;
|
||
this.ControlObj.SetReadOnlyAllControl(isReadOnly);
|
||
this.ControlObj.SetAllControlValue(rowItem);
|
||
this.dbpFP.Enabled = this.btnDelete.Enabled = this.btnBillSave.Enabled = this.btnBillApply.Enabled = !isReadOnly;
|
||
this.ControlObj.CanExecControl = true;
|
||
this.cb_input.Enabled = this.btn_input.Enabled = this.txt_input.Enabled = !isReadOnly;
|
||
foreach (SimpleButton item in itemCommonList)
|
||
{
|
||
if (item.Visible == true && item.Tag is DataRow rightRow)
|
||
{
|
||
string menuCode = rightRow["menuCond"] + "";
|
||
if (!string.IsNullOrEmpty(menuCode))
|
||
{
|
||
item.Enabled = ValidateCond(menuCode, rowItem); ;
|
||
}
|
||
}
|
||
}
|
||
this.BillRowItem = rowItem;
|
||
// 设置Brp模版
|
||
if (this.IsBrpTemplete || this.BillModel.IsBrp)
|
||
{
|
||
this.SetTempleteSelectedValue(rowItem["brpId"] + "");
|
||
this.cb_templete.Enabled = !isReadOnly;
|
||
}
|
||
this.BillModel.PopupUnionCode = rdBlue.Checked ? rdBlueUnionCode : rdRedUnionCode;
|
||
this.dbpFP.Visible = !string.IsNullOrWhiteSpace(this.BillModel.PopupUnionCode);
|
||
this.labelControl1.ForeColor = this.lblOrderNo.ForeColor = this.lbTitle.ForeColor = rdBlue.Checked ? Color.Blue : Color.Red;
|
||
this.gcMain.GridView.OptionsBehavior.Editable = !isReadOnly;
|
||
if (tb_buttom.TabControlObj.TabPages.Count > 0)
|
||
{
|
||
for (int i = 0; i < this.tb_buttom.TabControlObj.TabPages.Count; i++)
|
||
{
|
||
XtraTabPage page = this.tb_buttom.TabControlObj.TabPages[i];
|
||
if (page != null && page.Controls[0] is ModuleGridEx moduleGridEx)
|
||
{
|
||
bool result = !isReadOnly;
|
||
if (!string.IsNullOrWhiteSpace(this.BillModel.AdditionalCond)) result = ReplaceHelper.ReplaceRowParamCond(rowItem, this.BillModel.AdditionalCond);
|
||
moduleGridEx.GridControlObj.GridView.OptionsBehavior.Editable = result;
|
||
if (moduleGridEx.SysModel != null && moduleGridEx.SysModel.IsCustomGroup == 1 && (moduleGridEx.GridControlObj.CustomGroupBandEx != null || moduleGridEx.GridControlObj.CustomGroupTreeBandEx != null))
|
||
{
|
||
if (moduleGridEx.GridControlObj.CustomGroupBandEx != null) moduleGridEx.GridControlObj.CustomGroupBandEx.GridView.OptionsBehavior.Editable = result;
|
||
if (moduleGridEx.GridControlObj.CustomGroupTreeBandEx != null) moduleGridEx.GridControlObj.CustomGroupTreeBandEx.TreeListObj.OptionsBehavior.Editable = result;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
// 上一次查询
|
||
int oldRowHandle = this.gcMain.GridView.FocusedRowHandle;
|
||
//获取数据源并排序
|
||
DataTable dt = BillImpl.GetDataTableResult(ReplaceHelper.ReplaceRowParam(rowItem, this.BillModel.DetailSql));
|
||
if (dt.Columns.Contains(this.BillModel.DetailOrderField))
|
||
{
|
||
DataView dataView = dt.AsDataView();
|
||
dataView.Sort = this.BillModel.DetailOrderField;
|
||
dt = dataView.ToTable();
|
||
dt.AcceptChanges();
|
||
}
|
||
|
||
if (this.BillModel.DetailTreeTable)
|
||
{
|
||
//判断是否有tap_id和tap_pid
|
||
(this.gcMain as TreeGridControlEx).SetGridViewDataSourceGenerateID(dt);
|
||
this.gcMain.GridView.SelectRowHandler(oldRowHandle);
|
||
}
|
||
else
|
||
{
|
||
this.gcMain.GridControl.DataSource = dt;
|
||
this.gcMain.GridView.SelectRowHandler(oldRowHandle);
|
||
if (this.BillModel.SelectLast && dt.Rows.Count > 0)
|
||
{
|
||
this.gcMain.GridView.SelectRowHandler(dt.Rows.Count - 1);
|
||
}
|
||
}
|
||
|
||
|
||
RefreshPrindMenu();
|
||
|
||
BaseUserControl userControl = this.ControlObj.FindControl(this.BillModel.RtagidKey);
|
||
if (userControl != null)
|
||
{
|
||
userControl.EditText = this.rdRed.Checked ? "1" : "0";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// 单据为新增状态
|
||
this.dbpFP.Enabled = this.btnDelete.Enabled = this.btnBillSave.Enabled = this.btnBillApply.Enabled = true;
|
||
this.lbTitle.Text = this.BillModel.TypeName + addText;
|
||
this.lblOrderNo.Text = BillImpl.GetBillNo(this.BillModel.BillSeq);
|
||
this._itemImport.Enabled = this._itemImportUpdate.Enabled = true;
|
||
this.cb_input.Enabled = this.btn_input.Enabled = this.txt_input.Enabled = true;
|
||
this.cb_templete.Enabled = true;
|
||
this.BillModel.SaveState = false;
|
||
this.ControlObj.SetReadOnlyAllControl(false);
|
||
this.rdBlue.Enabled = this.rdRed.Enabled = true;
|
||
foreach (SimpleButton item in itemCommonList)
|
||
{
|
||
if (item.Visible == true && item.Tag is DataRow rightRow)
|
||
{
|
||
string menuCode = rightRow["menuCond"] + "";
|
||
if (!string.IsNullOrEmpty(menuCode))
|
||
{
|
||
item.Enabled = ValidateCond(menuCode, rowItem); ;
|
||
}
|
||
}
|
||
}
|
||
|
||
// 通过右键菜单打开单据,假如明细有数据则在初始化时使用传入数据.
|
||
if (this.BillModel.DetailTreeTable)
|
||
{
|
||
(this.gcMain as TreeGridControlEx).TreeListObj.OptionsBehavior.Editable = true;
|
||
(this.gcMain as TreeGridControlEx).SetGridViewDataSourceGenerateID(BillImpl.GetDataTableResult(this.BillModel.DetailSql));
|
||
}
|
||
else
|
||
{
|
||
this.gcMain.GridView.OptionsBehavior.Editable = true;
|
||
this.gcMain.GridControl.DataSource = BillImpl.GetDataTableResult(this.BillModel.DetailSql);
|
||
}
|
||
|
||
if (tb_buttom.TabControlObj.TabPages.Count > 0)
|
||
{
|
||
for (int i = 0; i < this.tb_buttom.TabControlObj.TabPages.Count; i++)
|
||
{
|
||
XtraTabPage page = this.tb_buttom.TabControlObj.TabPages[i];
|
||
if (page != null && page.Controls[0] is ModuleGridEx moduleGridEx)
|
||
{
|
||
moduleGridEx.GridControlObj.GridView.OptionsBehavior.Editable = true;
|
||
if (moduleGridEx.SysModel != null && moduleGridEx.SysModel.IsCustomGroup == 1 && (moduleGridEx.GridControlObj.CustomGroupBandEx != null || moduleGridEx.GridControlObj.CustomGroupTreeBandEx != null))
|
||
{
|
||
if (moduleGridEx.GridControlObj.CustomGroupBandEx != null) moduleGridEx.GridControlObj.CustomGroupBandEx.GridView.OptionsBehavior.Editable = true;
|
||
if (moduleGridEx.GridControlObj.CustomGroupTreeBandEx != null) moduleGridEx.GridControlObj.CustomGroupTreeBandEx.TreeListObj.OptionsBehavior.Editable = true;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
BaseUserControl userControl = this.ControlObj.FindControl(this.BillModel.RtagidKey);
|
||
if (userControl != null)
|
||
{
|
||
userControl.EditText = this.rdRed.Checked ? "1" : "0";
|
||
}
|
||
}
|
||
|
||
//设置打印按钮状态
|
||
this.btnPrint.Enabled = this.SetPrintButton(rowItem);
|
||
|
||
this._waterMark = new WaterMark(this.BillModel.MasterPreFix, rowItem);
|
||
this.lbTitle.Invalidate();
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 切换红、蓝字单据
|
||
/// <summary>
|
||
/// <para>说明:点击蓝字单据</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-23 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
private void OnBlueStateClick(object sender, EventArgs e)
|
||
{
|
||
this.rdRed.Checked = false;
|
||
this.labelControl1.ForeColor = this.lblOrderNo.ForeColor = this.lbTitle.ForeColor = Color.Blue;
|
||
this.dbpFP.Visible = !string.IsNullOrWhiteSpace(rdBlueUnionCode);
|
||
this.BillModel.PopupUnionCode = rdBlueUnionCode;
|
||
|
||
BaseUserControl userControl = this.ControlObj.FindControl(this.BillModel.RtagidKey);
|
||
if (userControl != null)
|
||
{
|
||
userControl.EditText = "0";
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:点击红字单据</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-23 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
private void OnRedStateClick(object sender, EventArgs e)
|
||
{
|
||
this.rdBlue.Checked = false;
|
||
this.labelControl1.ForeColor = this.lblOrderNo.ForeColor = this.lbTitle.ForeColor = Color.Red;
|
||
this.dbpFP.Visible = !string.IsNullOrWhiteSpace(rdRedUnionCode);
|
||
this.BillModel.PopupUnionCode = rdRedUnionCode;
|
||
|
||
BaseUserControl userControl = this.ControlObj.FindControl(this.BillModel.RtagidKey);
|
||
if (userControl != null)
|
||
{
|
||
userControl.EditText = "1";
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 复制单据
|
||
/// <summary>
|
||
/// <para>说明:复制表头数据</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-27 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="ItemClickEventArgs"/> instance containing the event data.</param>
|
||
protected void OnCopyMasterItemClick(object sender, ItemClickEventArgs e)
|
||
{
|
||
this.dbpFP.Enabled = this.btnDelete.Enabled = this.btnBillSave.Enabled = this.btnBillApply.Enabled = true;
|
||
this.lbTitle.Text = this.BillModel.TypeName + addText;
|
||
this.lbTitle.Invalidate();
|
||
this.lblOrderNo.Text = BillImpl.GetBillNo(this.BillModel.BillSeq);
|
||
this.BillModel.SaveState = false;
|
||
this.rdBlue.Enabled = this.rdRed.Enabled = true;
|
||
this.cb_input.Enabled = this.btn_input.Enabled = this.txt_input.Enabled = true;
|
||
this._itemImport.Enabled = this._itemImportUpdate.Enabled = true;
|
||
this.cb_templete.Enabled = true;
|
||
this.ControlObj.CopyControlValue(this.BillModel.CancelCopyAssociation);
|
||
this.ControlObj.SetReadOnlyAllControl(false);
|
||
|
||
if (this.BillModel.DetailTreeTable)
|
||
{
|
||
((this.gcMain as TreeGridControlEx).TreeListObj.DataSource as DataTable).Clear();
|
||
(this.gcMain as TreeGridControlEx).TreeListObj.OptionsBehavior.Editable = true;
|
||
}
|
||
else
|
||
{
|
||
this.gcMain.GridControl.DataSourceTable().Clear();
|
||
this.gcMain.GridView.OptionsBehavior.Editable = true;
|
||
|
||
}
|
||
|
||
if (ScanCodeTextEdit != null) ScanCodeTextEdit.Focus();
|
||
this._waterMark = new WaterMark(this.BillModel.MasterPreFix, null);
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:复制整单</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-27 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="ItemClickEventArgs"/> instance containing the event data.</param>
|
||
protected void OnCopyAllItemClick(object sender, ItemClickEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
WaitForm.ShowForm(ResourceKeys.Handing);
|
||
DataTable gridTable = (this.gcMain.GridControl.DataSource as DataTable).TrimDeleteRows();
|
||
if (this.BillModel.DetailTreeTable)
|
||
{
|
||
gridTable = ((this.gcMain as TreeGridControlEx).TreeListObj.DataSource as DataTable).TrimDeleteRows();
|
||
}
|
||
this.dbpFP.Enabled = this.btnDelete.Enabled = this.btnBillSave.Enabled = this.btnBillApply.Enabled = true;
|
||
this.lbTitle.Text = this.BillModel.TypeName + addText;
|
||
this.lbTitle.Invalidate();
|
||
this.lblOrderNo.Text = BillImpl.GetBillNo(this.BillModel.BillSeq);
|
||
this.rdBlue.Enabled = this.rdRed.Enabled = true;
|
||
this.cb_input.Enabled = this.btn_input.Enabled = this.txt_input.Enabled = true;
|
||
this._itemImport.Enabled = this._itemImportUpdate.Enabled = true;
|
||
this.cb_templete.Enabled = true;
|
||
this.ControlObj.CopyControlValue(this.BillModel.CancelCopyAssociation);
|
||
this.ControlObj.SetReadOnlyAllControl(false);
|
||
this._waterMark = new WaterMark(this.BillModel.MasterPreFix, null);
|
||
if (!gridTable.Columns.Contains(ERPInfo.Instance.isAddRows))
|
||
{
|
||
gridTable.Columns.Add(ERPInfo.Instance.isAddRows, typeof(String));
|
||
}
|
||
// 处理单据明细
|
||
DataTable detailTable = this.gcMain.GridControl.DataSourceTable();
|
||
if (this.BillModel.DetailTreeTable)
|
||
{
|
||
detailTable = (this.gcMain as TreeGridControlEx).GetGridViewDataSource();
|
||
}
|
||
bool canCopy = false;
|
||
string defaultValue = string.Empty;
|
||
|
||
|
||
if (this.BillModel.DetailTreeTable)
|
||
{
|
||
if (detailTable.Columns.Contains(this.BillModel.PrimaryDetailKey))
|
||
{
|
||
(this.gcMain as TreeGridControlEx).TreeListObj.BeginUpdate();
|
||
foreach (TreeListNode item in (this.gcMain as TreeGridControlEx).TreeListObj.Nodes)
|
||
{
|
||
//根据后台列配置可否复制
|
||
if (_detailColumns.Columns.Contains("canCopy"))
|
||
{
|
||
//int index = detailTable.Rows.IndexOf(item);
|
||
foreach (DataRow dr in _detailColumns.Rows)
|
||
{
|
||
canCopy = !string.IsNullOrEmpty(dr["canCopy"] + "") ? "1".Equals(dr["canCopy"] + "") : false;
|
||
if (!canCopy)
|
||
{
|
||
TreeListColumn column = (this.gcMain as TreeGridControlEx).TreeListObj.Columns.ColumnByFieldName(dr["fieldName"] + "");
|
||
//TreeListNode node = treeList.GetNode(rowIndex);
|
||
defaultValue = this.ControlObj.ReplaceParentControlValue(dr["defaultdate"] + "");
|
||
defaultValue = BaseImpl.GetDefaultValue(defaultValue);
|
||
if (!string.IsNullOrEmpty(defaultValue))
|
||
{
|
||
item.SetValue(column, defaultValue);
|
||
}
|
||
else
|
||
{
|
||
item.SetValue(column, DBNull.Value);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
item[this.BillModel.PrimaryDetailKey] = this.lblOrderNo.Text;
|
||
}
|
||
(this.gcMain as TreeGridControlEx).TreeListObj.EndUpdate();
|
||
}
|
||
(this.gcMain as TreeGridControlEx).TreeListObj.OptionsBehavior.Editable = true;
|
||
this.BillModel.SaveState = false;
|
||
}
|
||
else
|
||
{
|
||
if (detailTable.Columns.Contains(this.BillModel.PrimaryDetailKey))
|
||
{
|
||
this.gcMain.GridView.BeginUpdate();
|
||
foreach (DataRow item in detailTable.Rows)
|
||
{
|
||
//根据后台列配置可否复制
|
||
if (_detailColumns.Columns.Contains("canCopy"))
|
||
{
|
||
int index = detailTable.Rows.IndexOf(item);
|
||
foreach (DataRow dr in _detailColumns.Rows)
|
||
{
|
||
canCopy = !string.IsNullOrEmpty(dr["canCopy"] + "") ? "1".Equals(dr["canCopy"] + "") : false;
|
||
if (!canCopy)
|
||
{
|
||
GridColumn column = this.gcMain.GridView.Columns.ColumnByFieldName(dr["fieldName"] + "");
|
||
defaultValue = this.ControlObj.ReplaceParentControlValue(dr["defaultdate"] + "");
|
||
defaultValue = BaseImpl.GetDefaultValue(defaultValue);
|
||
if (!string.IsNullOrEmpty(defaultValue))
|
||
{
|
||
this.gcMain.GridView.SetRowCellValue(index, column, defaultValue);
|
||
}
|
||
else
|
||
{
|
||
this.gcMain.GridView.SetRowCellValue(index, column, DBNull.Value);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
item[this.BillModel.PrimaryDetailKey] = this.lblOrderNo.Text;
|
||
}
|
||
this.gcMain.GridView.EndUpdate();
|
||
}
|
||
this.gcMain.GridView.OptionsBehavior.Editable = true;
|
||
this.BillModel.SaveState = false;
|
||
}
|
||
if (ScanCodeTextEdit != null) ScanCodeTextEdit.Focus();
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
}
|
||
finally
|
||
{
|
||
WaitForm.HideForm();
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region Excel操作
|
||
/// <summary>
|
||
/// <para>说明:导出Excel</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-27 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="ItemClickEventArgs"/> instance containing the event data.</param>
|
||
protected void OnExportItemClick(object sender, ItemClickEventArgs e)
|
||
{
|
||
LogUtil.WriteDebug(this.SysModel.ModuleCode, "导出数据", this.SysModel.FormText, "单据明细导出", this.SysModel.ModuleId + "");
|
||
|
||
|
||
if (this.BillModel.DetailTreeTable)
|
||
{
|
||
(this.gcMain as TreeGridControlEx).TreeListObj.ToTreeExcel(this.SysModel.FormText);
|
||
}
|
||
else
|
||
{
|
||
this.gcMain.GridControl.ToExcel(this.SysModel.FormText);
|
||
}
|
||
|
||
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:从Excel导入</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-27 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="ItemClickEventArgs"/> instance containing the event data.</param>
|
||
protected void OnImportItemClick(object sender, ItemClickEventArgs e)
|
||
{
|
||
OpenFileDialog dialog = new OpenFileDialog();
|
||
dialog.Title = "选择导入文件";
|
||
//dialog.Filter = "Excel文件(*.xls)|*.xls";
|
||
dialog.Filter = SystemInfo.Instance.IsXlsxFirst ? "Excel文件(*.xlsx)|*.xlsx|Excel文件(*.xls)|*.xls" :
|
||
"Excel文件(*.xls)|*.xls|Excel文件(*.xlsx)|*.xlsx";
|
||
|
||
DialogResult result = dialog.ShowDialog();
|
||
if (result == DialogResult.OK)
|
||
{
|
||
string fileName = dialog.FileName;
|
||
string colFields = this.gcMain.GridView.Columns.ToString(',');
|
||
|
||
if (this.BillModel.DetailTreeTable)
|
||
{
|
||
DataTable DataImportTable = (this.gcMain as TreeGridControlEx).TreeListObj.ToExcelTreeDataTable(fileName, colFields, true, true);
|
||
DataTable NewTable = (this.gcMain as TreeGridControlEx).GetGridViewDataSource();
|
||
TreeListColumnCollection gridColumns = (this.gcMain as TreeGridControlEx).TreeListObj.Columns;
|
||
//父节点名称
|
||
string ParentFieldName = (this.gcMain as TreeGridControlEx).TreeListObj.ParentFieldName;
|
||
//节点名称
|
||
string KeyFieldName = (this.gcMain as TreeGridControlEx).TreeListObj.KeyFieldName;
|
||
|
||
if (!DataImportTable.Columns.Contains(ParentFieldName)) DataImportTable.Columns.Add(ParentFieldName);
|
||
if (!DataImportTable.Columns.Contains(KeyFieldName)) DataImportTable.Columns.Add(KeyFieldName);
|
||
|
||
DragAddTable(DataImportTable, "0");
|
||
}
|
||
else
|
||
{
|
||
DataTable DataImportTable = this.gcMain.GridView.ToExcelDataTable(fileName, colFields, true, true);
|
||
DataTable NewTable = this.gcMain.GridControl.DataSourceTable();
|
||
GridColumnCollection gridColumns = this.gcMain.GridView.Columns;
|
||
foreach (DataRow rowItem in DataImportTable.Rows)
|
||
{
|
||
DataRow newRow = NewTable.NewRow();
|
||
foreach (GridColumn col in gridColumns)
|
||
{
|
||
if ("id".Equals(col.FieldName) || col.FieldName.Equals(this.BillModel.PrimaryKey)) continue;
|
||
if (rowItem.Table.Columns.Contains(col.FieldName))
|
||
{
|
||
// 列中是否包含对应字段,包含则使用值
|
||
newRow[col.FieldName] = rowItem[col.FieldName];
|
||
}
|
||
else
|
||
{
|
||
// 未包含字段,则使用控件默认值.
|
||
GridColumnModel model = col.Tag as GridColumnModel;
|
||
string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue);
|
||
if (model.DefaultValue.Contains("{#"))
|
||
{
|
||
fieldValue = this.ControlObj.ReplaceParentControlValue(model.DefaultValue);
|
||
|
||
}
|
||
if (!string.IsNullOrEmpty(fieldValue))
|
||
{
|
||
newRow[col.FieldName] = fieldValue;
|
||
}
|
||
}
|
||
}
|
||
NewTable.Rows.Add(newRow);
|
||
}
|
||
this.gcMain.GridControl.DataSource = NewTable;
|
||
}
|
||
|
||
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:导入Excel文件(更新)</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-27 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="ItemClickEventArgs"/> instance containing the event data.</param>
|
||
protected void OnImportUpdateItemClick(object sender, ItemClickEventArgs e)
|
||
{
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 常用工具
|
||
/// <summary>
|
||
/// <para>说明:验证可操作条件</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-03-07 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
protected void OnToolsClick(object sender, EventArgs e)
|
||
{
|
||
foreach (BarItemLink itemLink in pMenu.ItemLinks)
|
||
{
|
||
DataRow rowItem = itemLink.Item.Tag as DataRow;
|
||
if (rowItem != null)
|
||
{
|
||
string menuCond = rowItem["MenuCond"] + "";
|
||
string menuCaption = itemLink.Caption;
|
||
|
||
if (!string.IsNullOrEmpty(menuCond))
|
||
{
|
||
try
|
||
{
|
||
bool result = true;
|
||
menuCond = ReplaceHelper.ReplaceParamToValue(menuCond, "{" + this.BillModel.PrimaryKey + "}", this.lblOrderNo.Text.Trim());
|
||
|
||
if (menuCond.StartsWith("@") || menuCond.StartsWith("!"))
|
||
{
|
||
result = "1".Equals(BaseImpl.GetDefaultValue(menuCond));
|
||
}
|
||
else
|
||
{
|
||
menuCond = this.ControlObj.ReplaceControlValue(menuCond);
|
||
if (this.BillRowItem != null)
|
||
menuCond = ReplaceHelper.ReplaceRowParam(this.BillRowItem, menuCond);
|
||
menuCond = ReplaceHelper.ReplaceParamToValue(menuCond, "0"); // 未替换的参数所有替换为0
|
||
|
||
result = ReplaceHelper.EvalCond(menuCond);
|
||
}
|
||
itemLink.Item.Enabled = result;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageUtil.Show("[" + menuCaption + "] " + ResourceKeys.SetRightMenuCondFault);
|
||
LogHelper.Instance.WriteError(ex);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:常用工具点击</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-27 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="ItemClickEventArgs"/> instance containing the event data.</param>
|
||
protected void OnCommonItemClick(object sender, ItemClickEventArgs e)
|
||
{
|
||
DataRow rowItem = e.Item.Tag as DataRow;
|
||
|
||
CommonMenu menu = new CommonMenu(this.SysModel, this.ControlObj, null);
|
||
menu.ApplyBefore += new CommonToolApplyEventHandler(OnMenuApplyBefore);
|
||
menu.DynamicLinkAfter += new CommonToolAfterDynamicLinkEventHandler(OnDynamicLinkAfter);
|
||
menu.Apply(rowItem);
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:执行前单独替换BilldocumentId</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-03-07 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="e">The e.</param>
|
||
protected void OnMenuApplyBefore(ApplyArgs e)
|
||
{
|
||
string[] paramList = new string[e.MemuModel.ParamList.Count];
|
||
|
||
for (int i = 0; i < e.MemuModel.ParamList.Count; i++)
|
||
{
|
||
string item = e.MemuModel.ParamList[i];
|
||
List<string> condition = ReplaceHelper.GetParamFields(item);
|
||
foreach (string cond in condition)
|
||
{
|
||
string value = this.BillModel.PrimaryKey.Equals(cond.Replace("{", "").Replace("}", "").ToLower(), StringComparison.OrdinalIgnoreCase) ? this.lblOrderNo.Text.Trim() : cond;
|
||
item = item.Replace(cond, value); ;
|
||
}
|
||
paramList[i] = item;
|
||
}
|
||
e.MemuModel.ParamList = paramList.ToList();
|
||
}
|
||
/// <summary>
|
||
/// 动态链接库执行完成后
|
||
/// </summary>
|
||
/// <param name="e"></param>
|
||
protected void OnDynamicLinkAfter(object sender, ApplyArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(e.MemuModel.ResultSQL))
|
||
{
|
||
string resultSql = e.MemuModel.ResultSQL;
|
||
if (e.DialogModel != null && e.DialogModel.DialogDllName.Equals("lskj.pubadd.dll", StringComparison.OrdinalIgnoreCase) && e.DialogModel.PubDialogType == DialogType.PubAddRecord)
|
||
{
|
||
if (e.DialogModel.ReturnTag != null && e.DialogModel.ReturnTag is MyControl)
|
||
{
|
||
MyControl addControlObj = e.DialogModel.ReturnTag as MyControl;
|
||
resultSql = addControlObj.ReplaceControlValue(resultSql);
|
||
}
|
||
resultSql = this.ControlObj.ReplaceControlValue(resultSql);
|
||
DataTable dataTable = MainImpl.GetDataTableResult(resultSql);
|
||
foreach (DataRow item in dataTable.Rows)
|
||
{
|
||
this.AddRowToGridView(item);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
resultSql = this.ControlObj.ReplaceControlValue(resultSql);
|
||
DataTable dataTable = MainImpl.GetDataTableResult(resultSql);
|
||
foreach (DataRow item in dataTable.Rows)
|
||
{
|
||
this.AddRowToGridView(item, false);
|
||
}
|
||
}
|
||
}
|
||
if (e.DialogModel != null && e.DialogModel.DialogDllName.Equals("Lskj.PubBomImport.dll", StringComparison.OrdinalIgnoreCase))
|
||
{
|
||
if (e.DialogModel.ReturnTag != null && e.DialogModel.ReturnTag is BomImpRtnModel impRtnModel)
|
||
{
|
||
if (impRtnModel.ShowType.Equals("1") || impRtnModel.ShowType.Equals("2") || impRtnModel.ShowType.Equals("3") || impRtnModel.ShowType.Equals("5") || impRtnModel.ShowType.Equals("6") || impRtnModel.ShowType.Equals("7") || impRtnModel.ShowType.Equals("8") || impRtnModel.ShowType.Equals("9"))//执行保存
|
||
{
|
||
CommonMenu menu = (CommonMenu)sender;
|
||
menu.issuccess = impRtnModel.CanSave;
|
||
}
|
||
else if (impRtnModel.ShowType.Equals("0") || impRtnModel.ShowType.Equals("00") || impRtnModel.ShowType.Equals("000"))//返回文件
|
||
{
|
||
ControlModel controlModel = ControlObj.ControlModels.Where(n => n.LabelText.Equals("物料编码")).FirstOrDefault();
|
||
if (controlModel == null)
|
||
{
|
||
MessageUtil.Show($"物料编码不存在");
|
||
return;
|
||
}
|
||
string mxProductId = ControlObj.GetControlValue(controlModel);
|
||
if (string.IsNullOrEmpty(mxProductId))
|
||
{
|
||
MessageUtil.Show($"物料编码必填");
|
||
return;
|
||
}
|
||
ControlModel modeControlModel = ControlObj.ControlModels.Where(n => n.LabelText.Equals("上传模式")).FirstOrDefault();
|
||
string addMode = ControlObj.GetControlValue(modeControlModel);
|
||
if (impRtnModel.ShowType.Equals("1") && string.IsNullOrEmpty(addMode))
|
||
{
|
||
MessageUtil.Show($"上传模式必填");
|
||
return;
|
||
}
|
||
ControlModel sepciesNoControlModel = ControlObj.ControlModels.Where(n => n.LabelText.Equals("文件分类")).FirstOrDefault();
|
||
string sepciesNo = ControlObj.GetControlValue(sepciesNoControlModel);
|
||
if ((impRtnModel.ShowType.Equals("1") || impRtnModel.ShowType.Equals("6")) && string.IsNullOrEmpty(sepciesNo))
|
||
{
|
||
MessageUtil.Show($"文件分类必填");
|
||
return;
|
||
}
|
||
ControlModel fileIDControlModel = ControlObj.ControlModels.Where(n => n.LabelText.Equals("文件ID")).FirstOrDefault();
|
||
string fileID = ControlObj.GetControlValue(fileIDControlModel);
|
||
ControlModel oldPIDControlModel = ControlObj.ControlModels.Where(n => n.LabelText.Equals("旧编码")).FirstOrDefault();
|
||
string oldPID = ControlObj.GetControlValue(oldPIDControlModel);
|
||
DataTable sourceTable = gcMain.gridControl.DataSourceTable();
|
||
if (impRtnModel.ShowType.Equals("000") && sourceTable.Rows.Cast<DataRow>().Where(n => n.RowState != DataRowState.Deleted).Count() > 0)
|
||
{
|
||
MessageUtil.Show($"只能选择单个文件,请删除后再添加");
|
||
return;
|
||
}
|
||
if (sourceTable != null && impRtnModel.FileNames != null)
|
||
{
|
||
string afterBomFieldName = impRtnModel.AfterBomFieldName;
|
||
if (!sourceTable.Columns.Contains("BomFieldNameDir"))
|
||
{
|
||
sourceTable.Columns.Add("BomFieldNameDir");
|
||
}
|
||
if (!sourceTable.Columns.Contains("BomFieldNamePath"))
|
||
{
|
||
sourceTable.Columns.Add("BomFieldNamePath");
|
||
}
|
||
if (!sourceTable.Columns.Contains("BomMxMainProduct"))
|
||
{
|
||
sourceTable.Columns.Add("BomMxMainProduct");
|
||
}
|
||
if (!sourceTable.Columns.Contains("BomMxAddState"))
|
||
{
|
||
sourceTable.Columns.Add("BomMxAddState");
|
||
}
|
||
if (!sourceTable.Columns.Contains("qms_laddf_mode"))
|
||
{
|
||
sourceTable.Columns.Add("qms_laddf_mode");
|
||
}
|
||
if (!sourceTable.Columns.Contains("BomAddSpeciesNo"))
|
||
{
|
||
sourceTable.Columns.Add("BomAddSpeciesNo");
|
||
}
|
||
if (!sourceTable.Columns.Contains("BomAddChangeFileId"))
|
||
{
|
||
sourceTable.Columns.Add("BomAddChangeFileId");
|
||
}
|
||
if (!sourceTable.Columns.Contains("BomAddOldProductId"))
|
||
{
|
||
sourceTable.Columns.Add("BomAddOldProductId");
|
||
}
|
||
DataTable dataTable = new DataTable();
|
||
dataTable.Columns.Add(afterBomFieldName);
|
||
dataTable.Columns.Add("BomFieldNameDir");
|
||
dataTable.Columns.Add("BomFieldNamePath");
|
||
dataTable.Columns.Add("BomMxMainProduct");
|
||
dataTable.Columns.Add("BomMxAddState");
|
||
dataTable.Columns.Add("qms_laddf_mode");
|
||
dataTable.Columns.Add("BomAddSpeciesNo");
|
||
dataTable.Columns.Add("BomAddChangeFileId");
|
||
dataTable.Columns.Add("BomAddOldProductId");
|
||
IEnumerable<DataRow> rowsIEnumerable = sourceTable.Rows.Cast<DataRow>().Where(n => n.RowState != DataRowState.Deleted);
|
||
foreach (string fileName in impRtnModel.FileNames)
|
||
{
|
||
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName).Trim();
|
||
//找到code相同的行
|
||
DataRow selectRow = rowsIEnumerable.Where(n => (n[afterBomFieldName] + "").Trim().Equals(fileNameWithoutExtension, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
||
if (selectRow != null)
|
||
{
|
||
//MessageUtil.Show($"{fileNameWithoutExtension}已存在,不允许重复创建");
|
||
continue;
|
||
}
|
||
//DataRow productRow = BaseImpl.GetDataRowResult($"select top 1 billdocument_id from bom_BillTab where productid like '{code}%'");
|
||
//if (productRow != null)
|
||
//{
|
||
// MessageUtil.Show($"{code}已存在,不允许重复创建");
|
||
// return;
|
||
//}
|
||
DataRow addRow = dataTable.NewRow();
|
||
addRow[afterBomFieldName] = Path.GetFileName(fileName);
|
||
addRow["BomFieldNameDir"] = fileName;
|
||
addRow["BomFieldNamePath"] = Path.GetFileName(fileName);
|
||
addRow["BomMxMainProduct"] = mxProductId;
|
||
addRow["qms_laddf_mode"] = addMode;
|
||
addRow["BomAddSpeciesNo"] = sepciesNo;
|
||
addRow["BomAddChangeFileId"] = fileID;
|
||
addRow["BomAddOldProductId"] = oldPID;
|
||
addRow["BomMxAddState"] = this.BillModel.SaveState ? "修改" : "新增";
|
||
dataTable.Rows.Add(addRow);
|
||
}
|
||
foreach (DataRow item in dataTable.Rows)
|
||
{
|
||
DataRow sourceRow = this.AddRowToGridView(item, true);
|
||
sourceRow["BomFieldNameDir"] = item["BomFieldNameDir"] + "";
|
||
sourceRow["BomFieldNamePath"] = item["BomFieldNamePath"] + "";
|
||
sourceRow["BomMxMainProduct"] = item["BomMxMainProduct"] + "";
|
||
sourceRow["BomMxAddState"] = item["BomMxAddState"] + "";
|
||
sourceRow["qms_laddf_mode"] = item["qms_laddf_mode"] + "";
|
||
sourceRow["BomAddSpeciesNo"] = item["BomAddSpeciesNo"] + "";
|
||
sourceRow["BomAddChangeFileId"] = item["BomAddChangeFileId"] + "";
|
||
sourceRow["BomAddOldProductId"] = item["BomAddOldProductId"] + "";
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
string movepage = (this.ControlObj.ReplaceControlValue("{qms_maddf_addMode}").Equals("6")) ? "-9998" : "-9999";
|
||
foreach (XtraTabPage xtraTabPage in this.tb_buttom.TabControlObj.TabPages)
|
||
{
|
||
if (xtraTabPage.Tag != null && (xtraTabPage.Tag != null && xtraTabPage.Tag is System.Windows.Forms.Control pageControl) && pageControl.Tag != null)
|
||
{
|
||
|
||
if (pageControl.Tag is GridDetailModel detailModel && (detailModel.Orderid + "").Equals(movepage))
|
||
{
|
||
this.tb_buttom.TabControlObj.SelectedTabPage = xtraTabPage;
|
||
StaticControl.BomUnionPage = xtraTabPage;
|
||
if (xtraTabPage.Tag is GridControlEx)
|
||
{
|
||
DataRow dataRow = this.gcMain.GetViewFocusedDataRow();
|
||
GridControlEx gridControl = xtraTabPage.Tag as GridControlEx;
|
||
GridDetailModel Detailmodel = gridControl.Tag as GridDetailModel;
|
||
string DetailSql = this.ControlObj.ReplaceControlValue(Detailmodel.DetailSql);
|
||
DetailSql = ReplaceHelper.ReplaceRowParam(dataRow, DetailSql);
|
||
gridControl.SetGridViewDataSource(MainImpl.GetDataTableResult(DetailSql));
|
||
}
|
||
|
||
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 打印模版
|
||
/// <summary>
|
||
/// <para>说明:打印完成需要参数</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-07-09 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
protected void GetPrintOtherParam()
|
||
{
|
||
Dictionary<object, Hashtable> dataCaches = SysModel != null ? SysModel.DataCaches : null;
|
||
//取得打印完成后的参数
|
||
if (!string.IsNullOrEmpty(this.BillModel.PrintSql) && this.BillModel.PrintSql.Contains("<<"))
|
||
{
|
||
string[] strs = this.BillModel.PrintSql.Split(new[] { ">>" }, 2, StringSplitOptions.None);
|
||
_mainPrintSql = strs[1];
|
||
_printModeCond = strs[0].Replace("<<", "");
|
||
}
|
||
if (!string.IsNullOrEmpty(_printModeCond) && _printModeCond.IndexOf(';') > 0)
|
||
{
|
||
string[] str = _printModeCond.Split(';');
|
||
if (!dataCaches.GetValue(this, "PrintOtherSystemRow", out DataRow item))
|
||
{
|
||
item = AttachImpl.GetSystemModule(str[0]);
|
||
}
|
||
if (item == null) return;
|
||
string tableName = item["TableName"] + "";
|
||
string modetype = item["modType"] + "";
|
||
if (!dataCaches.GetValue(this, "PrintOtherColumnPrefix", out string comprefix))
|
||
{
|
||
comprefix = BaseImpl.GetColumnPrefix(tableName);
|
||
}
|
||
if (!dataCaches.GetValue(this, "PrintOtherPrimaryKey", out string primaryKey))
|
||
{
|
||
primaryKey = modetype == "1" ? BaseImpl.GetBasePrimaryKey(str[0]) : comprefix + "billdocument_id";
|
||
}
|
||
//表名,列前缀,主键字段,主键值,模块编号,主打印Sql
|
||
_printSaveParams = new List<string>() { tableName, comprefix, primaryKey, str[1], str[0], _mainPrintSql };
|
||
|
||
//判断是否直接打印 modetype 区别单据和基础档案模块
|
||
if (!dataCaches.GetValue(this, "PrintOtherIsExcPrint", out _isExcPrint))
|
||
{
|
||
switch (modetype)
|
||
{
|
||
case "1":
|
||
ModuleModel mode = new ModuleModel(MainImpl.GetSystemdllTab(str[0]));
|
||
if (mode != null) _isExcPrint = mode.PrintType == 3;
|
||
break;
|
||
case "2":
|
||
BaseAccraditationModel model = new BaseAccraditationModel(BillAuditImpl.GetPubAuditProperty(str[0]));
|
||
if (model != null) _isExcPrint = model.BillPrintType == 3;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:打印模版</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-27 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="ItemClickEventArgs"/> instance containing the event data.</param>
|
||
protected void OnPrintItemClick(object sender, ItemClickEventArgs e)
|
||
{
|
||
string printFile = e.Item.Tag + "";
|
||
string printPath = PubUtil.PrintFileAbsolutelyPath;
|
||
|
||
if (!File.Exists(printPath))
|
||
{
|
||
MessageUtil.Show(ResourceKeys.NotFoundPrintFile);
|
||
return;
|
||
}
|
||
|
||
bool isPrint = this.BillModel.SaveState;
|
||
if (!isPrint)
|
||
{
|
||
if (MessageUtil.Show(ResourceKeys.BillNotSavedAndNotPrint, MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||
isPrint = this.BillSave();
|
||
}
|
||
|
||
if (isPrint)
|
||
{
|
||
try
|
||
{
|
||
// 判断是否满足打印条件
|
||
|
||
//DataRow masterRow = BillImpl.GetDataRowResult(this.BillModel.MasterSql.Replace("{" + this.BillModel.PrimaryKey + "}", this.lblOrderNo.Text));
|
||
DataRow masterRow = BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, this.lblOrderNo.Text));
|
||
if (masterRow == null)
|
||
{
|
||
MessageUtil.Show(ResourceKeys.DataNotFount);
|
||
return;
|
||
}
|
||
|
||
if (!ReplaceHelper.ReplaceRowParamCond(masterRow, this.BillModel.PrintCond))
|
||
{
|
||
MessageUtil.Show(ResourceKeys.DisSatisfyPrintCond);
|
||
return;
|
||
}
|
||
|
||
string tmpSql = ReplaceHelper.ReplaceRowParam(masterRow, this.BillModel.PrintSql);
|
||
string tmpSql1 = ReplaceHelper.ReplaceRowParam(masterRow, this.BillModel.PrintSql1);
|
||
string tmpSql2 = ReplaceHelper.ReplaceRowParam(masterRow, this.BillModel.PrintSql2);
|
||
|
||
if (printFile.Contains(PrintUtil.TemplateFlag))
|
||
{
|
||
//主Sql
|
||
string mainSql = string.Empty;
|
||
List<string> tmpSqls = new List<string>();
|
||
if (_printSaveParams != null && _printSaveParams.Count > 0)
|
||
{
|
||
_printSaveParams[5] = mainSql = ReplaceHelper.ReplaceRowParam(masterRow, _mainPrintSql);
|
||
_printSaveParams[3] = masterRow.Table.Columns.Contains(_printSaveParams[2] + "") ? masterRow[_printSaveParams[2]] + "" : masterRow[BillModel.PrimaryKey] + "";
|
||
tmpSqls.Add(mainSql);
|
||
tmpSqls.Add(tmpSql1);
|
||
tmpSqls.AddRange(tmpSql2.Split(';').ToList());
|
||
}
|
||
else
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(tmpSql)) tmpSqls.Add(tmpSql);
|
||
if (!string.IsNullOrWhiteSpace(tmpSql1)) tmpSqls.Add(tmpSql1);
|
||
if (!string.IsNullOrWhiteSpace(tmpSql2)) tmpSqls.AddRange(tmpSql2.Split(';').ToList());
|
||
}
|
||
PrintUtil.OnAfterPrint -= new EventHandler(OnReportPrintAfter);
|
||
PrintUtil.OnAfterPrint += new EventHandler(OnReportPrintAfter);
|
||
PrintUtil.FastReportPrint(tmpSqls, printFile, _isExcPrint);
|
||
}
|
||
else
|
||
{
|
||
DelphiHelper.LoadDelphiDll(printPath, printPath, printFile, tmpSql, tmpSql1, this.BillModel.PrintFileType, tmpSql2);
|
||
}
|
||
//LogUtil.WriteDebug(this.SysModel.ModuleCode, "打印", "单据打印:" + printFile.Replace(".rmf", "").Replace(".frx", ""), "打印格式:" + printFile);
|
||
if (ScanCodeTextEdit != null) ScanCodeTextEdit.Focus();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageUtil.Show(ex.Message + "\r\n" + ex.StackTrace);
|
||
LogUtil.WriteError(ResourceKeys.BillModule + "打印模板错误", ex);
|
||
LogHelper.Instance.WriteError(ex);
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 单据来源相关
|
||
/// <summary>
|
||
/// <para>说明:刷新当前选中的TabPage</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-06-29 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// </summary>
|
||
private void RefreshSelectedSource()
|
||
{
|
||
if (this.xtc_left_container.SelectedTabPage == null) return;//来源选择为null(不显示左侧来源)。不执行下方刷新
|
||
|
||
XtraTabPage tabPage = this.xtc_left_container.SelectedTabPage;
|
||
BillSourceUnionModel model = tabPage.Tag as BillSourceUnionModel;
|
||
if (model.GridControlObj != null) this.RefreshSource(model);
|
||
if (BillModel.drgFinishHide == "1")
|
||
{
|
||
if (model.ModelObj.SourceType == 1)
|
||
{
|
||
string sqlValue = ReplaceHelper.ReplaceUserInfo(ReplaceHelper.ReplaceWhereCond(model.ModelObj.DetailSql));
|
||
sqlValue = sqlValue.Replace("#", "");
|
||
sqlValue = this.ControlObj.ReplaceControlValue(sqlValue);
|
||
sqlValue = ReplaceHelper.ReplaceParamToValue(sqlValue, model.TreeViewObj.GetSelectValue());
|
||
model.GridDetailControlObj.GridControl.DataSource = BillImpl.GetDataTableResult(sqlValue);
|
||
}
|
||
else
|
||
{
|
||
this.RefreshSourceDetail(model);
|
||
}
|
||
}
|
||
if (model.ModelObj.SourceType == 0 && model.SearchObj.GridRowCount > 0) tabPage.Text = model.ModelObj.UserName + "(" + model.SearchObj.GridRowCount + QuantitySuffix;
|
||
// 假如只有单据来源主表没有记录,则手动调用刷新明细.否则会通过选中行自动刷新明细
|
||
//if (model.GridControlObj != null && model.GridControlObj.DataRowCount() == 0)
|
||
//{
|
||
// this.RefreshSourceDetail(model);
|
||
//}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:刷新单据来源主表,未传递时,默认刷新</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-12-13 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>gcMain
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="unionModel">The union model.</param>
|
||
/// <returns>XtraTabPage.</returns>
|
||
private void RefreshSource(BillSourceUnionModel unionModel = null)
|
||
{
|
||
if (unionModel == null || unionModel.SearchObj == null) return;
|
||
unionModel.SearchObj.SearchLastGrid();
|
||
|
||
//string sql = ReplaceHelper.ReplaceUserInfo(unionModel.ModelObj.SourceSql);
|
||
//int Handle = 0;
|
||
//if (unionModel.GridControlObj != null) Handle = unionModel.GridControlObj.GridView.FocusedRowHandle;
|
||
//sql = sql.Replace("#", "");
|
||
//List<string> paramList = ReplaceHelper.GetParamFields(sql);
|
||
//if (unionModel.SearchObj != null)
|
||
//{
|
||
// //sql拼接来源条件和替换主表控件值
|
||
// sql = this.ControlObj.ReplaceControlValue(unionModel.SearchObj.SetSearchSqlValue(sql, true));
|
||
//}
|
||
//if (unionModel.GridControlObj != null)
|
||
//{
|
||
// unionModel.GridControlObj.gridControl.DataSource = BaseImpl.GetDataTableResult(sql);
|
||
|
||
// if (unionModel.GridControlObj != null)
|
||
// {
|
||
// unionModel.GridControlObj.GridView.SelectRowHandler(Handle);
|
||
// //this.RefreshSourceDetail(tabPage.Tag as BillSourceUnionModel);
|
||
// }
|
||
// RefreshSourceDetail(unionModel);
|
||
//}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:右边选择下拉框刷新左边来源</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-08-16 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
///
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
private void OnRefreshBillSource(object sender, EventArgs e)
|
||
{
|
||
XtraTabPage tabPage = this.xtc_left_container.SelectedTabPage;
|
||
BaseUserControl baseControl = (sender as System.Windows.Forms.Control).ToBaseUserControl();
|
||
string RefreshName = baseControl.Name.Substring(4);
|
||
BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel;
|
||
if (unionModel.ModelObj.SourceType != 2)
|
||
{
|
||
|
||
int Handle = 0;
|
||
string sql = ReplaceHelper.ReplaceUserInfo(unionModel.ModelObj.SourceSql);
|
||
if (unionModel.GridControlObj != null) Handle = unionModel.GridControlObj.GridView.FocusedRowHandle;
|
||
sql = sql.Replace("#", "");
|
||
List<string> paramList = ReplaceHelper.GetParamFields(sql);
|
||
if (unionModel.SearchObj != null)
|
||
{
|
||
//来源条件和主表改变控件名字相同,就把主表控件值赋个来源条件
|
||
foreach (ControlModel item in unionModel.SearchObj.ControlModels)
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(item.DefaultValue) && RefreshName.Equals(item.DefaultValue.Replace("{", "").Replace("}", "")))
|
||
{
|
||
unionModel.SearchObj.SetControlValue(item, baseControl.EditText);
|
||
}
|
||
else if (RefreshName.Equals(item.FieldName))
|
||
{
|
||
unionModel.SearchObj.SetControlValue(item, baseControl.EditText);
|
||
}
|
||
}
|
||
|
||
//sql拼接来源条件和替换主表控件值
|
||
sql = this.ControlObj.ReplaceControlValue(unionModel.SearchObj.SetSearchSqlValue(sql, true));
|
||
}
|
||
if (unionModel.GridControlObj != null)
|
||
{
|
||
unionModel.GridControlObj.gridControl.DataSource = BaseImpl.GetDataTableResult(sql);
|
||
|
||
if (unionModel.GridControlObj != null)
|
||
{
|
||
unionModel.GridControlObj.GridView.SelectRowHandler(Handle);
|
||
//this.RefreshSourceDetail(tabPage.Tag as BillSourceUnionModel);
|
||
}
|
||
RefreshSourceDetail(unionModel);
|
||
}
|
||
if (unionModel.TreeViewObj != null && unionModel.ModelObj.DetailSql.IndexOf(RefreshName, StringComparison.OrdinalIgnoreCase) >= 0)
|
||
{
|
||
IsBillMaster = false;
|
||
if (unionModel.TreeViewObj.TreeView.SelectedNode == null) unionModel.TreeViewObj.TreeView.SelectedNode = unionModel.TreeViewObj.TreeView.Nodes[0];//选中
|
||
sql = ReplaceHelper.ReplaceUserInfo(ReplaceHelper.ReplaceWhereCond(unionModel.ModelObj.DetailSql));
|
||
sql = sql.Replace("#", "");
|
||
sql = this.ControlObj.ReplaceControlValue(sql);
|
||
sql = ReplaceHelper.ReplaceParamToValue(sql, unionModel.TreeViewObj.TreeView.SelectedNode.Name);
|
||
unionModel.GridDetailControlObj.GridControl.DataSource = BillImpl.GetDataTableResult(sql);
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:刷新表格列(时间)</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2018-08-16 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void OnDataFileRefrshFile(object sender, EventArgs e)
|
||
{
|
||
AddDataColumns();
|
||
UpdateDynamicColumns();
|
||
UpdateSummaryData();
|
||
|
||
// ✅ 新增:开启横向滚动(避免列宽自适应吃掉滚动条)
|
||
var gv = gcMain.GridView as DevExpress.XtraGrid.Views.Grid.GridView;
|
||
if (gv != null)
|
||
{
|
||
gv.OptionsView.ColumnAutoWidth = false;
|
||
gv.HorzScrollVisibility = DevExpress.XtraGrid.Views.Base.ScrollVisibility.Always;
|
||
}
|
||
|
||
// 你原来的手动刷新——保持
|
||
OnGcMainDataSourceChanged(gcMain.GridView, null);
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:刷新单据来源明细</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-30 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="unionModel">The union model.</param>
|
||
private void RefreshSourceDetail(BillSourceUnionModel unionModel)
|
||
{
|
||
if (unionModel == null) return;
|
||
XtraTabPage tabPage = this.xtc_left_container.SelectedTabPage;
|
||
|
||
if (unionModel.ModelObj.SourceType == 1)
|
||
{
|
||
// 树加载明细
|
||
string fieldName = this.lceCombobox.EditValue;
|
||
string fieldValue = this.textEdit1.Text.Trim();
|
||
string checkStrs = unionModel.TreeViewObj.GetCheckValues();
|
||
string sqlValue = ReplaceHelper.ReplaceParamToValue(ReplaceHelper.ReplaceUserInfo(unionModel.ModelObj.DetailSql), unionModel.TreeViewObj.GetSelectNodeValue());
|
||
|
||
if (!string.IsNullOrEmpty(checkStrs))
|
||
checkStrs = " and SpeciesNo in (" + checkStrs.TrimEnd(',') + ")";
|
||
sqlValue = string.Format("select * from ({0}) temp where 1=1 ", ReplaceHelper.ReplaceWhereCond(sqlValue) + checkStrs) + string.Format(" and ({0} like '%{1}%' or dbo.P_getpy({0}) like '%{1}%')", fieldName, fieldValue);
|
||
|
||
try
|
||
{
|
||
WaitForm.ShowForm();
|
||
unionModel.GridDetailControlObj.GridControl.DataSource = BillImpl.GetDataTableResult(sqlValue);
|
||
this.ClearHighlightRows(unionModel.GridDetailControlObj.GridView);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageUtil.Show(ex);
|
||
LogHelper.Instance.WriteError(ex);
|
||
LogUtil.WriteError(BillModel.TypeName + "模块刷新树加载明细出错!", ex);
|
||
}
|
||
finally
|
||
{
|
||
WaitForm.HideForm();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// 加载明细
|
||
try
|
||
{
|
||
WaitForm.ShowForm();
|
||
|
||
|
||
DataRow rowItem = unionModel.GridControlObj.GridView.GetFocusedDataRow();
|
||
//unionModel.GridDetailControlObj.GridControl.DataSource = rowItem == null
|
||
// ? new DataTable() : BillImpl.GetDataTableResult(ReplaceHelper.ReplaceRowParam(rowItem, unionModel.ModelObj.DetailSql));
|
||
if (unionModel.ModelObj.SourceType == 3 || unionModel.ModelObj.SourceType == 4)
|
||
{
|
||
rowItem = unionModel.TreeGridControlObj.GetViewFocusedDataRow();
|
||
}
|
||
|
||
|
||
string DetailSql = unionModel.ModelObj.DetailSql;
|
||
DetailSql = ReplaceHelper.ReplaceUserInfo(DetailSql);
|
||
DetailSql = ReplaceHelper.ReplaceWhereCond(DetailSql);
|
||
DetailSql = ReplaceHelper.ReplaceRowParam(rowItem, DetailSql);
|
||
if (unionModel.SearchObj != null)
|
||
DetailSql = unionModel.SearchObj.ReplaceParentControlValue(DetailSql);
|
||
|
||
if (unionModel.ModelObj.sourceDetailType == "1")
|
||
{
|
||
unionModel.TreeGridDetailControlObj.SetGridViewDataSource(rowItem == null
|
||
? new DataTable() : BillImpl.GetDataTableResult(DetailSql));
|
||
}
|
||
else
|
||
{
|
||
|
||
|
||
//有复选框的页签在刷新前清空选中行,否则合计在刷新数据源后不会自带改变
|
||
if (unionModel.GridDetailControlObj.GridView.OptionsSelection.MultiSelectMode == GridMultiSelectMode.CheckBoxRowSelect && unionModel.GridDetailControlObj.GridView.OptionsSelection.MultiSelect == true)
|
||
{
|
||
//int[] selectIndexs = unionModel.GridDetailControlObj.GridView.GetSelectedRows();
|
||
unionModel.GridDetailControlObj.GridView.ClearSelection();
|
||
}
|
||
|
||
unionModel.GridDetailControlObj.GridControl.DataSource = rowItem == null
|
||
? new DataTable() : BillImpl.GetDataTableResult(DetailSql);
|
||
this.ClearHighlightRows(unionModel.GridDetailControlObj.GridView);
|
||
}
|
||
|
||
|
||
DataTable table = null;
|
||
if (unionModel.ModelObj.sourceDetailType == "1")
|
||
{
|
||
table = unionModel.TreeGridDetailControlObj.TreeListObj.DataSource as DataTable;
|
||
}
|
||
else
|
||
{
|
||
table = unionModel.GridDetailControlObj.GridControl.DataSource as DataTable;
|
||
}
|
||
|
||
if (table != null && !table.Columns.Contains("_check"))
|
||
{
|
||
table.Columns.Add("_check", typeof(bool));
|
||
foreach (DataRow row in table.Rows)
|
||
{
|
||
row["_check"] = 0;
|
||
}
|
||
}
|
||
|
||
if (table != null)
|
||
{
|
||
UpdateSummaryData(table);
|
||
}
|
||
|
||
if (unionModel.ModelObj.SourceType == 2 && this._isLoadRightControlValue)
|
||
{
|
||
string masterSql = rowItem == null ? BillModel.MasterSql.Replace("{" + BillModel.PrimaryKey + "}", this.lblOrderNo.Text) : ReplaceHelper.ReplaceRowParam(rowItem, BillModel.MasterSql);
|
||
// 加载单据信息
|
||
this.SetBillStatus(BillImpl.GetDataRowResult(masterSql));
|
||
}
|
||
else if (unionModel.ModelObj.SourceType == 3 && this._isLoadRightControlValue)
|
||
{
|
||
//string masterSql = focusedNode == null ? BillModel.MasterSql.Replace("{" + BillModel.PrimaryKey + "}", this.lblOrderNo.Text) : ReplaceHelper.ReplaceNodeParam(focusedNode, BillModel.MasterSql);
|
||
string masterSql = rowItem == null ? BillModel.MasterSql.Replace("{" + BillModel.PrimaryKey + "}", this.lblOrderNo.Text) : ReplaceHelper.ReplaceRowParam(rowItem, BillModel.MasterSql);
|
||
// 加载单据信息
|
||
this.SetBillStatus(BillImpl.GetDataRowResult(masterSql));
|
||
}
|
||
|
||
if (tb_buttom.TabControlObj.TabPages.Count > 0)
|
||
{
|
||
for (int i = 0; i < this.tb_buttom.TabControlObj.TabPages.Count; i++)
|
||
{
|
||
XtraTabPage page = this.tb_buttom.TabControlObj.TabPages[i];
|
||
if (i == 0) continue;
|
||
if (rowItem != null && page != null)
|
||
{
|
||
this.SetTabPageDataSource(page, rowItem);
|
||
}
|
||
}
|
||
//foreach (XtraTabPage AttachPage in this.tb_buttom.TabControlObj.TabPages)
|
||
//{
|
||
// GridDetailModel model = tb_buttom.GetGridDetailModel(AttachPage);
|
||
// if (model == null) continue;
|
||
// string sqlValue = ReplaceHelper.ReplaceRowParam(rowItem, model.DetailSql);
|
||
// this.tb_buttom.SetGridDataSource(AttachPage, sqlValue);
|
||
//}
|
||
}
|
||
DataTable gridTable = (this.gcMain.GridControl.DataSource as DataTable).TrimDeleteRows();
|
||
gridTable.OrderBy(this.BillModel.DetailOrderField);
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageUtil.Show(ex);
|
||
LogHelper.Instance.WriteError(ex);
|
||
LogUtil.WriteError(BillModel.TypeName + "模块加载明细出错!", ex);
|
||
}
|
||
finally
|
||
{
|
||
WaitForm.HideForm();
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:刷新单据来源</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2019-12-16 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void SaveRefreshSource()
|
||
{
|
||
foreach (XtraTabPage tabPage in this.xtc_left_container.TabPages)
|
||
{
|
||
BillSourceUnionModel model = tabPage.Tag as BillSourceUnionModel;
|
||
if (model != null && model.GridControlObj != null && model.ModelObj.SaveRefreshFlag)
|
||
{
|
||
this.RefreshSource(model);
|
||
this.RefreshSourceDetail(model);
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:计算列关联字段</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-12-18 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="model">The model.</param>
|
||
/// <param name="fieldValue">The field value.</param>
|
||
protected virtual void SetUnionValue(GridColumnModel model, string fieldValue, DataRow rowItem)
|
||
{
|
||
DataTable table = this.gcMain.gridControl.DataSourceTable();
|
||
//DataRow rowItem = this.gridView.GetFocusedDataRow();
|
||
string unionValues = model.UnionValues;
|
||
if (rowItem != null && model != null)
|
||
{
|
||
unionValues = ReplaceHelper.ReplaceRowParam(rowItem, unionValues.Replace("{" + model.FieldName + "}", fieldValue));
|
||
if (this.ControlObj != null)
|
||
{
|
||
unionValues = ControlObj.ReplaceParentControlValue(unionValues);
|
||
}
|
||
try
|
||
{
|
||
string[] fields = model.UnionFields.Trim(',').Split(',');
|
||
DataRow rowResult = BaseImpl.GetDataRowResult(unionValues);
|
||
if (rowResult != null)
|
||
{
|
||
for (int i = 0; i < fields.Length; i++)
|
||
{
|
||
string field = fields[i];
|
||
string value = rowResult.Table.Columns.Contains(field) ? rowResult[field] + "" : null;
|
||
rowItem[field] = value;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// 设置为空
|
||
for (int i = 0; i < fields.Length; i++)
|
||
{
|
||
string field = fields[i];
|
||
rowItem[field] = DBNull.Value;
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Instance.WriteError(ex);
|
||
LogUtil.WriteError("计算列关联字段--错误-->" + unionValues, ex);
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:禁用控件条件</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2019-01-22 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="model">The model.</param>
|
||
/// <param name="fieldValue">The field value.</param>
|
||
protected virtual void SetDisableColumn(GridColumnModel model, string fieldValue, DataRow rowItem)
|
||
{
|
||
if (model.EnableCond != string.Empty)
|
||
{
|
||
List<GridColumnModel> columns = this.gcMain.ObjmControlList.FindAll(x => x.EnableCond.Contains("{" + model.FieldName + "}")).ToList();
|
||
foreach (GridColumnModel item in columns)
|
||
{
|
||
try
|
||
{
|
||
string disableCond = ReplaceHelper.ReplaceRowParam(rowItem, item.EnableCond.Replace("{" + model.FieldName + "}", fieldValue));
|
||
string diaableType = item.DisableType;
|
||
if (this.BillModel.DetailTreeTable)
|
||
{
|
||
(this.gcMain as TreeGridControlEx).TreeListObj.Columns.ColumnByFieldName(model.FieldName).Visible = ("true".Equals(EvalHelper.Eval(ReplaceHelper.ReplaceEvalCond(disableCond)) + "", StringComparison.OrdinalIgnoreCase));
|
||
}
|
||
else
|
||
{
|
||
this.gcMain.GridView.Columns.ColumnByFieldName(model.FieldName).Visible = ("true".Equals(EvalHelper.Eval(ReplaceHelper.ReplaceEvalCond(disableCond)) + "", StringComparison.OrdinalIgnoreCase));
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:计算列计算公式</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-12-18 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="model">The model.</param>
|
||
/// <param name="fieldValue">The field value.</param>
|
||
protected virtual void SetCalcValue(GridColumnModel model, string fieldValue, DataRow rowItem)
|
||
{
|
||
try
|
||
{
|
||
DataTable table = this.gcMain.gridControl.DataSourceTable();
|
||
if (rowItem != null && model != null)
|
||
{
|
||
List<GridColumnModel> calcModels = this.gcMain.ObjmControlList.FindAll(x => !string.IsNullOrEmpty(x.CalcExpr)).OrderBy(y => y.CalcOrder).ToList();
|
||
|
||
foreach (GridColumnModel gridModel in calcModels)
|
||
{
|
||
// 计算顺序小于当前控件则不计算
|
||
if (gridModel.CalcOrder < model.CalcOrder) continue;
|
||
|
||
if (!gridModel.FieldName.Equals(model.FieldName, StringComparison.OrdinalIgnoreCase))
|
||
{
|
||
bool isTruncate = false;
|
||
string calcExpr = gridModel.CalcExpr;
|
||
if (calcExpr.StartsWith("@truncate:"))
|
||
{
|
||
calcExpr = calcExpr.Substring(10);
|
||
isTruncate = true;
|
||
}
|
||
|
||
try
|
||
{
|
||
if (this.ControlObj != null)
|
||
calcExpr = ControlObj.ReplaceParentControlValue(calcExpr);
|
||
|
||
calcExpr = ReplaceHelper.ReplaceRowParam(rowItem, calcExpr);
|
||
//EvalHelper.Eval2(ReplaceHelper.ReplaceEvalCond(calcExpr)) + ""
|
||
string result = EvalHelper.Eval2(ReplaceHelper.ReplaceEvalCond(calcExpr)) + "";
|
||
if (isTruncate)
|
||
{
|
||
result += result.Contains(".") ? "0000000000" : ".0000000000";
|
||
rowItem[gridModel.FieldName] = result.Substring(0, result.IndexOf(".")) + result.Substring(result.IndexOf("."), model.Decimals + 1);
|
||
//this.gridView.SetRowCellValue(this.gridView.FocusedRowHandle, this.gridView.Columns[gridModel.FieldName], result.Substring(0, result.IndexOf(".")) + result.Substring(result.IndexOf("."), model.Decimals + 1));
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
double d = 0;
|
||
if (!string.IsNullOrEmpty(result) &&
|
||
!"NaN".Equals(result, StringComparison.OrdinalIgnoreCase) &&
|
||
!"非数字".Equals(result, StringComparison.OrdinalIgnoreCase) &&
|
||
!"undefined".Equals(result, StringComparison.OrdinalIgnoreCase) &&
|
||
result != "∞" && result != "-∞" &&
|
||
!"正无穷大".Equals(result, StringComparison.OrdinalIgnoreCase) &&
|
||
!"负无穷大".Equals(result, StringComparison.OrdinalIgnoreCase) &&
|
||
double.TryParse(result, out d))
|
||
{
|
||
if (string.IsNullOrEmpty(gridModel.DataFormat))
|
||
{
|
||
result = Math.Round(Convert.ToDouble(d), model.Decimals, MidpointRounding.AwayFromZero) + "";
|
||
}
|
||
else
|
||
{
|
||
//计算后先执行保存小数位数
|
||
result = string.Format("{0:" + gridModel.DataFormat + "}", Convert.ToDecimal(result));
|
||
}
|
||
if (model.FieldType == 7 && result.Contains('%'))
|
||
{
|
||
result = (double.Parse(result.Replace("%", "")) * 0.01).ToString();
|
||
}
|
||
rowItem[gridModel.FieldName] = result;
|
||
// 判断计算列有无关联值
|
||
GridColumnModel UnionModel = calcModels.FirstOrDefault(x => x.FieldName == gridModel.FieldName);
|
||
if (!string.IsNullOrEmpty(UnionModel.UnionFields))
|
||
{
|
||
this.SetUnionValue(UnionModel, rowItem[gridModel.FieldName] + "", rowItem);
|
||
}
|
||
//this.gridView.SetRowCellValue(this.gridView.FocusedRowHandle, this.gridView.Columns[gridModel.FieldName], result);
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Instance.WriteError(ex);
|
||
LogUtil.WriteError("计算列计算公式--错误-->" + rowItem[gridModel.FieldName], ex);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Instance.WriteError(ex);
|
||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||
// MessageUtil.Show(Message,ex.Message);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:添加行到单据明细中</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-30 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="rowItem">The row item.</param>
|
||
/// <param name="unionModel">The union model.</param>
|
||
private DataRow AddRowToGridView(DataRow rowItem, bool dataProcessing = true)
|
||
{
|
||
GridColumnCollection gridColumns = this.gcMain.GridView.Columns;
|
||
DataTable gridTable = (this.gcMain.GridControl.DataSource as DataTable).TrimDeleteRows();
|
||
if (!gridTable.Columns.Contains(ERPInfo.Instance.isAddRows))
|
||
{
|
||
gridTable.Columns.Add(ERPInfo.Instance.isAddRows, typeof(String));
|
||
}
|
||
string repeatProduct = this.gcMain.GridView.Columns["ProductId"] != null && rowItem.Table.Columns.Contains("ProductId") ? "ProductId" : this.BillModel.DetailPreFix + "ProductId";
|
||
AssociatedField = repeatProduct;
|
||
if ("1".Equals(this.BillModel.DetailDoubleClickTip) && rowItem.Table.Columns.Contains(repeatProduct))
|
||
{
|
||
|
||
//上面方法无法处理大小写,改成搜索的形式
|
||
DataTable dt = this.gcMain.gridControl.DataSourceTable();
|
||
if (dt != null && dt.Rows.Count > 0 && dt.Columns.Contains(repeatProduct))
|
||
{
|
||
DataRow[] drs = dt.Select(repeatProduct + "='" + rowItem[repeatProduct] + "'");
|
||
if (drs.Length >= 1)
|
||
{
|
||
DialogResult dialog = MessageUtil.Show(ResourceKeys.ProductIsRepet, MessageBoxButtons.YesNo);
|
||
if (dialog != DialogResult.Yes)
|
||
{
|
||
return null;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
DataRow newRow = gridTable.NewRow();
|
||
//if (gridTable.Columns.Contains(guidField))
|
||
//{
|
||
// newRow[guidField] = Guid.NewGuid().ToString();
|
||
//}
|
||
//2024-1-29改成>=,之前为>导致选中第一行只会添加到最后一行(测试空白行没有影响)
|
||
int position = this.gcMain.GridView.FocusedRowHandle >= 0 ? gridTable.Rows.Count > 0 ? this.gcMain.GridView.FocusedRowHandle : 0 : gridTable.Rows.Count - 1;
|
||
bool isLastRow = this.gcMain.GridView.IsLastVisibleRow;
|
||
this.gcMain.GridView.BeginDataUpdate();
|
||
GridView gridView = this.gcMain.GridView;
|
||
// 赋值明细字段
|
||
foreach (GridColumn col in gridColumns)
|
||
{
|
||
try
|
||
{
|
||
// 未包含字段,则使用控件默认值.
|
||
GridColumnModel model = col.Tag as GridColumnModel;
|
||
if (model == null)
|
||
{
|
||
if (rowItem.Table.Columns.Contains(col.FieldName))
|
||
{
|
||
// 来源列中是否包含对应字段,包含则使用值
|
||
newRow[col.FieldName] = rowItem[col.FieldName];
|
||
}
|
||
continue;
|
||
}
|
||
if (rowItem.Table.Columns.Contains(col.FieldName))
|
||
{
|
||
// 来源列中是否包含对应字段,包含则使用值
|
||
newRow[col.FieldName] = rowItem[col.FieldName];
|
||
if (dataProcessing)
|
||
{
|
||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||
{
|
||
this.SetUnionValue(model, rowItem[col.FieldName] + "", newRow);
|
||
}
|
||
SetCalcValue(model, rowItem[col.FieldName] + "", newRow);
|
||
}
|
||
|
||
}
|
||
else
|
||
{
|
||
|
||
if (col.FieldName.Contains("_Ls"))
|
||
{
|
||
string[] unioFielName = col.FieldName.Split('_');
|
||
string UnioValue = unioFielName[unioFielName.Length - 1];
|
||
DataColumn grid = rowItem.Table.Columns.Cast<DataColumn>().FirstOrDefault(x => x.ColumnName.Split('_')[x.ColumnName.Split('_').Length - 1].Equals(UnioValue));
|
||
if (dataProcessing)
|
||
{
|
||
if (grid != null && !string.IsNullOrEmpty(model.UnionFields))
|
||
{
|
||
this.SetUnionValue(model, rowItem[col.FieldName] + "", newRow);
|
||
}
|
||
SetCalcValue(model, rowItem[col.FieldName] + "", newRow);
|
||
}
|
||
|
||
}
|
||
else
|
||
{
|
||
string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue);
|
||
//int nowPositon = !isLastRow ? position : gridTable.Rows.Count - 1;
|
||
|
||
if (model.DefaultValue.Contains("{#"))
|
||
{
|
||
fieldValue = this.ControlObj.ReplaceParentControlValue(model.DefaultValue);
|
||
if (fieldValue.StartsWith("@"))
|
||
{
|
||
fieldValue = BaseImpl.GetDefaultValue(fieldValue);
|
||
}
|
||
if (!string.IsNullOrEmpty(fieldValue))
|
||
{
|
||
newRow[col.FieldName] = fieldValue;
|
||
if (dataProcessing)
|
||
{
|
||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||
{
|
||
this.SetUnionValue(model, newRow[col.FieldName] + "", newRow);
|
||
}
|
||
SetCalcValue(model, newRow[col.FieldName] + "", newRow);
|
||
}
|
||
//计算规则配置在结果字段上,所以无需验证当前操作控件
|
||
//this.gcMain.GridView.SetFocusedRowCellValue(col, fieldValue);
|
||
}
|
||
}
|
||
else if (!string.IsNullOrEmpty(model.DefaultValue))
|
||
{
|
||
if (string.IsNullOrEmpty(newRow[col.FieldName] + "") || this.BillModel.DragFixedDefault)
|
||
{
|
||
newRow[col.FieldName] = fieldValue;
|
||
}
|
||
if (dataProcessing)
|
||
{
|
||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||
{
|
||
this.SetUnionValue(model, newRow[col.FieldName] + "", newRow);
|
||
}
|
||
SetCalcValue(model, newRow[col.FieldName] + "", newRow);
|
||
//this.gcMain.GridView.SetFocusedRowCellValue(col, fieldValue);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
SetDisableColumn(model, newRow[col.FieldName] + "", newRow);
|
||
//GridColumnModel model = col.Tag as GridColumnModel;
|
||
if (model.LimitLength > 0)
|
||
{
|
||
DataRow HandleRow = newRow;
|
||
int MaxInputLength = System.Text.Encoding.Default.GetBytes(newRow[col.FieldName] + "").Length;
|
||
if (model.LimitLength < MaxInputLength)
|
||
HandleRow.SetColumnError(HandleRow.Table.Columns[col.ColumnHandle], "当前输入文本超过设定长度!");//满足条件设置错误信息
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Instance.WriteError(ex);
|
||
//LogUtil.WriteError(col.FieldName + "添加出错!", ex);
|
||
}
|
||
}
|
||
this.gcMain.GridView.EndDataUpdate();
|
||
|
||
if (SystemInfo.Instance.BillAddAtTheEnd) isLastRow = true;
|
||
|
||
if (!isLastRow)
|
||
{
|
||
// 插入数据行
|
||
gridTable.Rows.InsertAt(newRow, position + 1);
|
||
this.gcMain.GridView.ClearSelection();
|
||
this.gcMain.GridView.SelectRowHandler(position + 1);
|
||
}
|
||
else
|
||
{
|
||
// 添加数据行
|
||
gridTable.Rows.Add(newRow);
|
||
this.gcMain.GridView.ClearSelection();
|
||
this.gcMain.GridView.SelectRowHandler(gridTable.Rows.Count - 1);
|
||
}
|
||
|
||
|
||
// 插入数据后
|
||
//if (isLastRow)
|
||
//{
|
||
// this.gcMain.GridView.ClearSelection();
|
||
// this.gcMain.GridView.SelectRowHandler(position + 1);
|
||
//}
|
||
if (!string.IsNullOrEmpty(NumberMc) && gridTable.Columns.Contains(mRecordPrimaryField))
|
||
{
|
||
DataRow[] rt = gridTable.Rows.Cast<DataRow>().Where(x => (newRow[BillModel.DetailPreFix + "ProductId"] + "").Equals(x[BillModel.DetailPreFix + "ProductId"] + "") && !string.IsNullOrEmpty(x[mRecordPrimaryField] + "")).ToArray();
|
||
foreach (DataRow item in rt)
|
||
{
|
||
if (newRow != null)
|
||
{
|
||
newRow[NumberMc] = Convert.ToDouble(newRow[NumberMc]) - Convert.ToDouble(item[NumberMc]);
|
||
}
|
||
this.gcMain.OnGridViewCellValueChanged(this.gcMain, new CellValueChangedEventArgs(position + 1, this.gcMain.GridView.Columns[NumberMc], newRow[NumberMc] + ""));
|
||
this.gcMain.GridView.UpdateCurrentRow();
|
||
this.gcMain.GridView.ShowEditor();
|
||
if (Convert.ToDouble(newRow[NumberMc] + "") == 0.0)
|
||
{
|
||
gridTable.Rows.Remove(newRow);
|
||
MessageUtil.Show("数量已分配完毕!无需再进行拖拽!");
|
||
}
|
||
}
|
||
}
|
||
gridTable.OrderBy(this.BillModel.DetailOrderField);
|
||
this.gcMain.GridView.UpdateCurrentRow();
|
||
this.gcMain.GridView.ShowEditor();
|
||
return newRow;
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:添加多行到单据明细中</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-30 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="rowItem">The row item.</param>
|
||
/// <param name="unionModel">The union model.</param>
|
||
private void AddRowsToGridView(DataTable dataTable, BillSourceUnionModel unionModel)
|
||
{
|
||
WaitForm.ShowForm();
|
||
GridColumnCollection gridColumns = this.gcMain.GridView.Columns;
|
||
DataTable gridTable = (this.gcMain.GridControl.DataSource as DataTable).TrimDeleteRows().Copy();
|
||
if (!gridTable.Columns.Contains(ERPInfo.Instance.isAddRows))
|
||
{
|
||
gridTable.Columns.Add(ERPInfo.Instance.isAddRows, typeof(String));
|
||
}
|
||
int position = this.gcMain.GridView.FocusedRowHandle;
|
||
bool isLastRow = this.gcMain.GridView.IsLastVisibleRow;
|
||
bool onlyOne = true;
|
||
foreach (DataRow rowItem in dataTable.Rows)
|
||
{
|
||
if (unionModel == null || ValidateDetailCond(rowItem, unionModel))
|
||
{
|
||
string repeatProduct = this.gcMain.GridView.Columns["ProductId"] != null && dataTable.Columns.Contains("ProductId") ? "ProductId" : this.BillModel.DetailPreFix + "ProductId";
|
||
AssociatedField = repeatProduct;
|
||
if ("1".Equals(this.BillModel.DetailDoubleClickTip) && this.gcMain.GridView.Columns[repeatProduct] != null && dataTable.Columns.Contains(repeatProduct))
|
||
{
|
||
// 需要提示编码重复
|
||
//GridView view = this.gcMain.GridView;
|
||
//bool result = (view.LocateByValue(repeatProduct, rowItem[repeatProduct], null) >= 0) |
|
||
// (view.LocateByValue(repeatProduct, rowItem[repeatProduct], null) >= 0) |
|
||
// (view.LocateByValue(repeatProduct, rowItem[repeatProduct], null) >= 0) |
|
||
// (view.LocateByValue(repeatProduct, rowItem[repeatProduct], null) >= 0);
|
||
//if (result)
|
||
//{
|
||
// DialogResult dialog = MessageUtil.Show(ResourceKeys.ProductIsRepet, MessageBoxButtons.YesNo);
|
||
// if (dialog != DialogResult.Yes)
|
||
// return;
|
||
//}
|
||
|
||
//上面方法无法处理大小写,改成搜索的形式
|
||
DataTable dt = this.gcMain.gridControl.DataSourceTable();
|
||
if (dt != null && dt.Rows.Count > 0 && dt.Columns.Contains(repeatProduct))
|
||
{
|
||
DataRow[] drs = dt.Select(repeatProduct + "='" + rowItem[repeatProduct] + "'");
|
||
if (drs.Length >= 1)
|
||
{
|
||
DialogResult dialog = MessageUtil.Show(ResourceKeys.ProductIsRepet, MessageBoxButtons.YesNo);
|
||
if (dialog != DialogResult.Yes)
|
||
return;
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
DataRow newRow = gridTable.NewRow();
|
||
newRow.BeginEdit();
|
||
// 赋值明细字段
|
||
foreach (GridColumn col in gridColumns)
|
||
{
|
||
try
|
||
{
|
||
GridColumnModel model = col.Tag as GridColumnModel;
|
||
if (model == null) continue;
|
||
if (dataTable.Columns.Contains(col.FieldName))
|
||
{
|
||
// 来源列中是否包含对应字段,包含则使用值
|
||
newRow[col.FieldName] = rowItem[col.FieldName];
|
||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||
{
|
||
this.SetUnionValue(model, rowItem[col.FieldName] + "", newRow);
|
||
}
|
||
SetCalcValue(model, rowItem[col.FieldName] + "", newRow);
|
||
|
||
}
|
||
else
|
||
{
|
||
// 未包含字段,则使用控件默认值.
|
||
if (col.FieldName.Contains("_Ls"))
|
||
{
|
||
string[] unioFielName = col.FieldName.Split('_');
|
||
string UnioValue = unioFielName[unioFielName.Length - 1];
|
||
DataColumn grid = dataTable.Columns.Cast<DataColumn>().FirstOrDefault(x => x.ColumnName.Split('_')[x.ColumnName.Split('_').Length - 1].Equals(UnioValue));
|
||
if (grid != null && !string.IsNullOrEmpty(model.UnionFields))
|
||
{
|
||
this.SetUnionValue(model, rowItem[col.FieldName] + "", newRow);
|
||
}
|
||
SetCalcValue(model, rowItem[col.FieldName] + "", newRow);
|
||
|
||
}
|
||
else
|
||
{
|
||
string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue);
|
||
//int nowPositon = !isLastRow ? position : gridTable.Rows.Count - 1;
|
||
if (model.DefaultValue.Contains("{#"))
|
||
{
|
||
fieldValue = this.ControlObj.ReplaceParentControlValue(model.DefaultValue);
|
||
if (!string.IsNullOrEmpty(fieldValue))
|
||
{
|
||
newRow[col.FieldName] = fieldValue;
|
||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||
{
|
||
this.SetUnionValue(model, fieldValue + "", newRow);
|
||
}
|
||
SetCalcValue(model, fieldValue + "", newRow);
|
||
|
||
//计算规则配置在结果字段上,所以无需验证当前操作控件
|
||
//this.gcMain.GridView.SetFocusedRowCellValue(col, fieldValue);
|
||
}
|
||
}
|
||
else if (!string.IsNullOrEmpty(model.DefaultValue))
|
||
{
|
||
|
||
if (string.IsNullOrEmpty(newRow[col.FieldName] + "") || this.BillModel.DragFixedDefault)
|
||
{
|
||
newRow[col.FieldName] = fieldValue;
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||
{
|
||
this.SetUnionValue(model, newRow[col.FieldName] + "", newRow);
|
||
}
|
||
SetCalcValue(model, newRow[col.FieldName] + "", newRow);
|
||
|
||
//this.gcMain.GridView.SetFocusedRowCellValue(col, fieldValue);
|
||
}
|
||
}
|
||
}
|
||
SetDisableColumn(model, newRow[col.FieldName] + "", newRow);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Instance.WriteError(ex);
|
||
//LogUtil.WriteError(col.FieldName + "添加出错!", ex);
|
||
}
|
||
}
|
||
newRow.EndEdit();
|
||
|
||
if (SystemInfo.Instance.BillAddAtTheEnd) isLastRow = true;
|
||
|
||
if (!isLastRow)
|
||
{
|
||
// 插入数据行
|
||
gridTable.Rows.InsertAt(newRow, position);
|
||
//this.gcMain.GridView.ClearSelection();
|
||
//this.gcMain.GridView.SelectRowHandler(position);
|
||
}
|
||
else
|
||
{
|
||
// 添加数据行
|
||
gridTable.Rows.Add(newRow);
|
||
// this.gcMain.GridView.ClearSelection();
|
||
// this.gcMain.GridView.SelectRowHandler(gridTable.Rows.Count - 1);
|
||
}
|
||
position++;
|
||
//if (isLastRow)
|
||
//{
|
||
// this.gcMain.GridView.ClearSelection();
|
||
// this.gcMain.GridView.SelectRowHandler(position + 1);
|
||
//}
|
||
if (!string.IsNullOrEmpty(NumberMc) && gridTable.Columns.Contains(mRecordPrimaryField))
|
||
{
|
||
DataRow[] rt = gridTable.Rows.Cast<DataRow>().Where(x => (newRow[BillModel.DetailPreFix + "ProductId"] + "").Equals(x[BillModel.DetailPreFix + "ProductId"] + "") && !string.IsNullOrEmpty(x[mRecordPrimaryField] + "")).ToArray();
|
||
foreach (DataRow item in rt)
|
||
{
|
||
if (newRow != null)
|
||
{
|
||
newRow[NumberMc] = Convert.ToDouble(newRow[NumberMc]) - Convert.ToDouble(item[NumberMc]);
|
||
}
|
||
this.gcMain.OnGridViewCellValueChanged(this.gcMain, new CellValueChangedEventArgs(position + 1, this.gcMain.GridView.Columns[NumberMc], newRow[NumberMc] + ""));
|
||
this.gcMain.GridView.UpdateCurrentRow();
|
||
this.gcMain.GridView.ShowEditor();
|
||
if (Convert.ToDouble(newRow[NumberMc] + "") == 0.0)
|
||
{
|
||
gridTable.Rows.Remove(newRow);
|
||
MessageUtil.Show("数量已分配完毕!无需再进行拖拽!");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (onlyOne)
|
||
{
|
||
onlyOne = false;
|
||
if (!string.IsNullOrEmpty(unionModel.ModelObj.DetailEnableMsg))
|
||
{
|
||
if (unionModel.ModelObj.DetailEnableMsg.StartsWith("select", StringComparison.OrdinalIgnoreCase) ||
|
||
unionModel.ModelObj.DetailEnableMsg.StartsWith("exec", StringComparison.OrdinalIgnoreCase))
|
||
{
|
||
MessageUtil.Show(BaseImpl.GetResult(unionModel.ModelObj.DetailEnableMsg) + "");
|
||
}
|
||
else
|
||
{
|
||
MessageUtil.Show(unionModel.ModelObj.DetailEnableMsg);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
this.gcMain.GridControl.DataSource = gridTable;
|
||
if (position >= 0)
|
||
this.gcMain.GridView.SelectRowHandler(position);
|
||
else
|
||
this.gcMain.GridView.SelectRowHandler(gridTable.Rows.Count - 1);
|
||
//this.gcMain.GridView.SelectRowHandler(position);
|
||
gridTable.OrderBy(this.BillModel.DetailOrderField);
|
||
this.gcMain.GridView.UpdateCurrentRow();
|
||
this.gcMain.GridView.ShowEditor();
|
||
WaitForm.HideForm();
|
||
}
|
||
/// <summary>
|
||
/// 添加多行数据到单据明细中,禁用所有关联和默认值的获取
|
||
/// </summary>
|
||
/// <param name="dataTable"></param>
|
||
/// <param name="unionModel"></param>
|
||
private void AddRowsToGridViewFast(DataRow[] rowItems)
|
||
{
|
||
try
|
||
{
|
||
DataTable gridTable = (this.gcMain.GridControl.DataSource as DataTable).TrimDeleteRows();
|
||
foreach (DataRow rowItem in rowItems)
|
||
{
|
||
DataRow dataRow = gridTable.NewRow();
|
||
foreach (DataColumn column in gridTable.Columns)
|
||
{
|
||
if (rowItem.Table.Columns.Contains(column.ColumnName))
|
||
{
|
||
dataRow[column] = rowItem[column.ColumnName];
|
||
}
|
||
}
|
||
gridTable.Rows.Add(dataRow);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageUtil.Show(ex.Message);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:检查添加数据到表格中是否包含
|
||
/// </para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-04-20 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="rowItem">The row item.</param>
|
||
/// <param name="unionModel">The union model.</param>
|
||
/// <param name="onlyPopup">if set to <c>true</c> [only popup].</param>
|
||
private void AddRowToGridViewByBom(DataRow rowItem, BillSourceUnionModel unionModel, ref bool onlyPopup)
|
||
{
|
||
if (!string.IsNullOrEmpty(unionModel.ModelObj.BomSql))
|
||
{
|
||
string bomSql = unionModel.ModelObj.BomSql;
|
||
// 检查是否有bom配置
|
||
if (unionModel.ModelObj.LoadBom == 1)
|
||
{
|
||
// 自动带出bom数据,不弹出选择
|
||
DataTable table = BaseImpl.GetDataTableResult(ReplaceHelper.ReplaceRowParam(rowItem, bomSql));
|
||
foreach (DataRow item in table.Rows)
|
||
{
|
||
this.AddRowToGridView(item);
|
||
}
|
||
}
|
||
else if (unionModel.ModelObj.LoadBom == 2)
|
||
{
|
||
DataTable table = BaseImpl.GetDataTableResult(ReplaceHelper.ReplaceRowParam(rowItem, bomSql));
|
||
|
||
if (!onlyPopup && table.Rows.Count > 0)
|
||
{
|
||
// 自动带出bom数据,弹出选择
|
||
FrmBomSelect frmSelect = new FrmBomSelect();
|
||
frmSelect.Caption = unionModel.ModelObj.BomCaption;
|
||
frmSelect.GridColumns = unionModel.GridDetailControlObj.GridView.Columns;
|
||
frmSelect.BomDataTable = table;
|
||
|
||
DialogResult result = frmSelect.ShowDialog();
|
||
onlyPopup = frmSelect.OnlyPopup;
|
||
|
||
if (result == DialogResult.OK && frmSelect.SelectBomRows != null && frmSelect.SelectBomRows.Length > 0)
|
||
{
|
||
foreach (DataRow item in frmSelect.SelectBomRows)
|
||
{
|
||
this.AddRowToGridView(item);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
foreach (DataRow item in table.Rows)
|
||
{
|
||
this.AddRowToGridView(item);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:添加多条数据到单据明细</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-30 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void AddMultiRowToGridView(DataRow[] rowItems)
|
||
{
|
||
bool onlyPopup = false;
|
||
this.isDragWrap = false;//用于设置拖拽时不允许扫码控件换行
|
||
XtraTabPage tabPage = this.xtc_left_container.SelectedTabPage;
|
||
BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel;
|
||
if (unionModel != null)
|
||
{
|
||
bool onlyOne = true;
|
||
for (int i = 0; i < rowItems.Length; i++)
|
||
{
|
||
DataRow rowItem = rowItems[i]; //unionModel.GridDetailControlObj.GridView.GetDataRow(selectedRows[i]);
|
||
// 检查当前记录是否满足条件
|
||
if (ValidateDetailCond(rowItem, unionModel))
|
||
{
|
||
this.AddRowToGridView(rowItem);
|
||
if (!string.IsNullOrWhiteSpace(this.BillModel.ChangeColColor))
|
||
{
|
||
if (rowItem.Table.Columns.Contains(this.BillModel.ChangeColColor))
|
||
{
|
||
rowItem[this.BillModel.ChangeColColor] = "1";
|
||
//ChangeColorRow.Add(rowItem);
|
||
}
|
||
}
|
||
this.AddRowToGridViewByBom(rowItem, unionModel, ref onlyPopup);
|
||
if (BillModel.drgFinishHide == "1" && unionModel.GridDetailControlObj != null)
|
||
{
|
||
if (unionModel.GridDetailControlObj.GridControl.DataSourceTable().Rows.IndexOf(rowItem) >= 0)
|
||
{
|
||
unionModel.GridDetailControlObj.GridControl.DataSourceTable().Rows.Remove(rowItem);
|
||
}
|
||
if (unionModel.GridDetailDetailControlObj != null && unionModel.GridDetailDetailControlObj.GridControl.DataSourceTable().Rows.IndexOf(rowItem) >= 0)
|
||
{
|
||
unionModel.GridDetailDetailControlObj.GridControl.DataSourceTable().Rows.Remove(rowItem);
|
||
}
|
||
}
|
||
if (BillModel.DrgDetailAndSource && unionModel.GridControlObj != null)//移动明细主表数据到主表
|
||
{
|
||
try
|
||
{
|
||
int[] rows = unionModel.GridControlObj.GridView.GetSelectedRows();
|
||
foreach (int index in rows)
|
||
{
|
||
DataRow dataRow = unionModel.GridControlObj.GridView.GetDataRow(index);
|
||
this.ControlObj.SetAllControlValue(dataRow, true);
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (onlyOne)
|
||
{
|
||
onlyOne = false;
|
||
if (!string.IsNullOrEmpty(unionModel.ModelObj.DetailEnableMsg))
|
||
{
|
||
if (unionModel.ModelObj.DetailEnableMsg.StartsWith("select", StringComparison.OrdinalIgnoreCase) ||
|
||
unionModel.ModelObj.DetailEnableMsg.StartsWith("exec", StringComparison.OrdinalIgnoreCase))
|
||
{
|
||
MessageUtil.Show(BaseImpl.GetResult(unionModel.ModelObj.DetailEnableMsg) + "");
|
||
}
|
||
else
|
||
{
|
||
MessageUtil.Show(unionModel.ModelObj.DetailEnableMsg);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
this.isDragWrap = true;//用于设置拖拽时不允许扫码控件换行
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:添加多条数据到单据明细</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-05-30 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="table">The table.</param>
|
||
private void AddMultiRowToGridView(DataTable table, BillSourceUnionModel unionModel = null)
|
||
{
|
||
if (table == null) return;
|
||
if (this.BillModel.DetailTreeTable)
|
||
{
|
||
this.AddRowsToTreeGridControl(table, unionModel);
|
||
}
|
||
else
|
||
{
|
||
|
||
if (!this.BillModel.IsFastDragAddDetail)
|
||
{
|
||
this.AddRowsToGridView(table, unionModel);
|
||
}
|
||
else
|
||
{
|
||
// 全部行转数组
|
||
DataRow[] dragRows = table.Select();
|
||
this.AddRowsToGridViewFast(dragRows);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
Application.DoEvents();
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:是否允许添加明细</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-06-06 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <returns><c>true</c> if this instance [can add detail row]; otherwise, <c>false</c>.</returns>
|
||
private bool CanAddDetailRow()
|
||
{
|
||
// 检测是否正在筛选数据
|
||
if (!string.IsNullOrEmpty(gcMain.GridView.FindFilterText.Trim()) ||
|
||
!string.IsNullOrEmpty(gcMain.GridView.FilterPanelText.Trim()))
|
||
{
|
||
if (MessageUtil.Show(ResourceKeys.GridViewSearching, MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||
{
|
||
this.gcMain.GridView.FindFilterText = "";
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
// 检测是否点击了排序表格
|
||
if (this.gcMain.GridView.HasSortColumn())
|
||
{
|
||
//if (MessageUtil.Show(ResourceKeys.GridViewColumnSorting, MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||
//{
|
||
this.gcMain.GridView.Columns.ClearAllSort();
|
||
// return true;
|
||
//}
|
||
//return false;
|
||
}
|
||
// 检测是否为提交或者终审模块
|
||
string text = Business.Impl.LanguageTranslation.Translatable ? Business.Impl.LanguageTranslation.GetTranslatedText("已终审") : "已终审";
|
||
if (_waterMark.Text.Contains(text) && !this.BillModel.BillFinalReviewAdd)
|
||
{
|
||
MessageUtil.Show(ResourceKeys.AddBillDetailed);
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:单据明细撤回操作</para>
|
||
/// <para>创建人:曹屹峰</para>
|
||
/// <para>创建日期:2021-11-09 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void OnToWithdraw(object sender, KeyEventArgs e)
|
||
{
|
||
if (e.Control && e.KeyCode == Keys.Z)
|
||
{
|
||
if (ToWithdrawRows.Count < 1) return;
|
||
DataTable gridTable = (this.gcMain.GridControl.DataSource as DataTable).TrimDeleteRows();
|
||
Dictionary<int, DataRow> undo = ToWithdrawRows[ToWithdrawRows.Count - 1];
|
||
foreach (int key in undo.Keys)
|
||
{
|
||
DataRow dr = gridTable.NewRow();
|
||
dr.ItemArray = undo[key].ItemArray;
|
||
gridTable.Rows.InsertAt(dr, key);
|
||
this.gcMain.GridView.ClearSelection();
|
||
this.gcMain.GridView.SelectRowHandler(key);
|
||
}
|
||
gridTable.OrderBy(this.BillModel.DetailOrderField);
|
||
ToWithdrawRows.RemoveAt(ToWithdrawRows.Count - 1);
|
||
}
|
||
if (e.Alt)
|
||
{
|
||
GridView gridView = sender as GridView;
|
||
if (gridView == null) return;
|
||
if (e.KeyCode == Keys.Up)
|
||
{
|
||
DataTable dtTable = gcMain.gridControl.DataSource as DataTable;
|
||
if (gridView.FocusedRowHandle > 0 && dtTable.Columns.Contains(this.BillModel.DetailOrderField))
|
||
{
|
||
dtTable = SwapRow(gridView.FocusedRowHandle, gridView.FocusedRowHandle - 1, dtTable);
|
||
dtTable.OrderBy(this.BillModel.DetailOrderField);
|
||
//DataTableOrderBy(dtTable);
|
||
}
|
||
}
|
||
else if (e.KeyCode == Keys.Down)
|
||
{
|
||
DataTable dtTable = gcMain.gridControl.DataSource as DataTable;
|
||
if (gridView.FocusedRowHandle < dtTable.Rows.Count - 1 && dtTable.Columns.Contains(this.BillModel.DetailOrderField))
|
||
{
|
||
dtTable = SwapRow(gridView.FocusedRowHandle, gridView.FocusedRowHandle + 1, dtTable);
|
||
dtTable.OrderBy(this.BillModel.DetailOrderField);
|
||
//DataTableOrderBy(dtTable);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
private DataTable SwapRow(int index1, int index2, DataTable dt)
|
||
{
|
||
DataRow dr = dt.NewRow();
|
||
dr.ItemArray = dt.Rows[index1].ItemArray;
|
||
dt.Rows[index1].ItemArray = dt.Rows[index2].ItemArray;
|
||
dt.Rows[index2].ItemArray = dr.ItemArray;
|
||
return dt;
|
||
}
|
||
private void DataTableOrderBy(DataTable dtTable)
|
||
{
|
||
try
|
||
{
|
||
if (dtTable.Columns.Contains(this.BillModel.DetailOrderField))
|
||
{
|
||
for (int i = 0; i < dtTable.Rows.Count; i++)
|
||
{
|
||
DataRow row = dtTable.Rows[i];
|
||
if (row.RowState != DataRowState.Deleted)
|
||
{
|
||
row[this.BillModel.DetailOrderField] = (i + 1);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-30 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
|
||
private bool ValidateDetailCond(DataRow rowItem, BillSourceUnionModel unionModel)
|
||
{
|
||
bool validate = false;
|
||
|
||
try
|
||
{
|
||
string detailCond = ReplaceHelper.ReplaceRowParam(rowItem, unionModel.ModelObj.DetailEnableCond);
|
||
detailCond = detailCond.ToLower();//2025-09-08 赵坤表示条件全部转成小写判断。 来源明细中不能配置单元格类型(不能配置 复选框条件 {xxx}=0 ),只能写{xxx}='Ture'。这种bit类型容易忘记大小的情况
|
||
if (detailCond.Contains("#"))
|
||
{
|
||
List<string> condition = ReplaceHelper.GetParamFields(detailCond);
|
||
foreach (string item in condition)
|
||
{
|
||
string fieldValue = this.ControlObj.GetControlValue(item.Replace("{#", "").Replace("}", ""));
|
||
detailCond = detailCond.Replace(item, fieldValue);
|
||
}
|
||
}
|
||
if (detailCond.StartsWith("@") || detailCond.StartsWith("!"))
|
||
{
|
||
validate = "1".Equals(BaseImpl.GetDefaultValue(detailCond));
|
||
}
|
||
else
|
||
{
|
||
|
||
validate = ReplaceHelper.EvalCond(detailCond);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Instance.WriteLog(ex.StackTrace);
|
||
LogUtil.WriteError("验证多条添加条件出错!", ex);
|
||
//MessageUtil.Show(ResourceKeys.CondtionError + "\r\n" + unionModel.ModelObj.DetailEnableCond);
|
||
}
|
||
return validate;
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:单据来源右键菜单执行完后刷新</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-12-11 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
private void OnGridControlRightCallback(object sender, EventArgs e)
|
||
{
|
||
this.RefreshSelectedSource();
|
||
|
||
// 执行右键菜单后刷新单据状态2020-03-23
|
||
XtraTabPage tabPage = this.xtc_left_container.SelectedTabPage;
|
||
BillSourceUnionModel model = tabPage.Tag as BillSourceUnionModel;
|
||
if (model.ModelObj.SourceType == 2 && this._isLoadRightControlValue)
|
||
{
|
||
DataRow rowItem = null;
|
||
if (model.GridControlObj.DataRowCount() > 0)
|
||
{
|
||
DataRow selectRow = model.GridControlObj.GridView.GetFocusedDataRow();
|
||
rowItem = BillImpl.GetDataRowResult(ReplaceHelper.ReplaceRowParam(selectRow, BillModel.MasterSql));
|
||
}
|
||
// 加载单据信息
|
||
this.SetBillStatus(rowItem);
|
||
if (rowItem == null)
|
||
{
|
||
this.ControlObj.ResetControlValue();
|
||
}
|
||
}
|
||
if (model.ModelObj.SourceType == 3 && this._isLoadRightControlValue)
|
||
{
|
||
DataRow rowItem = null;
|
||
if (model.GridControlObj.DataRowCount() > 0)
|
||
{
|
||
DataRow selectRow = model.TreeGridControlObj.GetViewFocusedDataRow(); ;
|
||
rowItem = BillImpl.GetDataRowResult(ReplaceHelper.ReplaceRowParam(selectRow, BillModel.MasterSql));
|
||
}
|
||
// 加载单据信息
|
||
this.SetBillStatus(rowItem);
|
||
if (rowItem == null)
|
||
{
|
||
this.ControlObj.ResetControlValue();
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:获取单据管理的单据来源标签</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-12-13 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private BillSourceUnionModel GetBillSourceManager()
|
||
{
|
||
foreach (XtraTabPage item in this.xtc_left_container.TabPages)
|
||
{
|
||
BillSourceUnionModel model = item.Tag as BillSourceUnionModel;
|
||
if (model.ModelObj.SourceType == 2)
|
||
return model;
|
||
}
|
||
return null;
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:初始化附加信息</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-04-26 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private List<GridDetailModel> GetAttachTabs()
|
||
{
|
||
List<GridDetailModel> details = new List<GridDetailModel>();
|
||
|
||
DataTable table = BaseAuditImpl.GetAttachTabs(this.SysModel.ModuleCode, "100", " and orderid < 0 ");
|
||
foreach (DataRow item in table.Rows)
|
||
{
|
||
DataTable gridColumns = BaseAuditImpl.GetBottomBasicInformation(item["formKey"] + "");
|
||
details.Add(new GridDetailModel(item, gridColumns, GridCustomColumnStruct.BillSourceDetailAttachGridView));
|
||
}
|
||
|
||
return details;
|
||
}
|
||
#endregion
|
||
|
||
#region 单据保存、提交
|
||
/// <summary>
|
||
/// <para>说明:获取添加表头数据</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-12-07 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="parmaryValue">The parmary value.</param>
|
||
/// <returns>System.String.</returns>
|
||
private string GetAddRecord(ref string parmaryValue)
|
||
{
|
||
if (BillModel.NewVer == 0 || BillModel.SaveVerifyBillNo)
|
||
{
|
||
// 检查当前的单据号是否已被占用.
|
||
string newBillNo = BillImpl.GetBillNo(this.BillModel.BillSeq);
|
||
|
||
if (!parmaryValue.Equals(newBillNo))
|
||
{
|
||
if (MessageUtil.Show(ResourceKeys.BillRecordRepeat, MessageBoxButtons.YesNo) == DialogResult.No)
|
||
{
|
||
return string.Empty;
|
||
}
|
||
else
|
||
{
|
||
this.lblOrderNo.Text = newBillNo;
|
||
parmaryValue = newBillNo;
|
||
}
|
||
}
|
||
}
|
||
|
||
StringBuilder fieldBuilder = new StringBuilder();
|
||
StringBuilder valueBuilder = new StringBuilder();
|
||
|
||
//DataTable DetailedProperties = BaseImpl.GetDataTableResult(string.Format("select COLUMN_NAME,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH from information_schema.columns where table_name = '{0}'", BillModel.MasterTable));
|
||
DataTable DetailedProperties = MainImpl.GetDatabaseProperty(BillModel.MasterTable);
|
||
|
||
string errorMessage = string.Empty;//数据不符合数据库规范的信息
|
||
foreach (ControlModel model in this.ControlObj.ControlModels)
|
||
{
|
||
if (!model.IsSave ||
|
||
model.FieldName.Equals(BillModel.PrimaryKey, StringComparison.OrdinalIgnoreCase) ||
|
||
model.FieldName.Equals(BillModel.RtagidKey, StringComparison.OrdinalIgnoreCase) ||
|
||
model.FieldType == ControlType.LabPic ||
|
||
model.FieldType == ControlType.LabPicEx ||
|
||
model.FieldType == ControlType.LabPrompt)
|
||
continue;
|
||
|
||
if (string.IsNullOrWhiteSpace(model.FieldName)) continue;
|
||
|
||
string fieldValue = this.ControlObj.GetControlValue(model);
|
||
if (SystemInfo.Instance.TrimWhiteSpace)
|
||
fieldValue = fieldValue.Trim();
|
||
if (fieldValue == "****") continue;
|
||
|
||
errorMessage = errorMessage + DatabaseFormatJudgment.SaveOrModifyBalidation(DetailedProperties, model, fieldValue);
|
||
if (string.IsNullOrEmpty(fieldValue) && model.Isintordecimal) fieldValue = "0";//数值保存时为空的话默认保存为0;
|
||
|
||
fieldBuilder.Append(model.FieldName + ",");
|
||
valueBuilder.Append(string.IsNullOrEmpty(fieldValue) ? this.ControlObj.GetNullValue(model) : string.Format("N'{0}',", fieldValue));
|
||
|
||
|
||
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(errorMessage)) SaveErrorMessage = "表头错误:" + errorMessage;
|
||
// 增加主键
|
||
fieldBuilder.Append(BillModel.PrimaryKey);
|
||
valueBuilder.Append("N'" + parmaryValue + "'");
|
||
// 增加红蓝字单标记
|
||
fieldBuilder.Append("," + BillModel.RtagidKey);
|
||
valueBuilder.Append(",N'" + (rdRed.Checked ? 1 : 0) + "'");
|
||
|
||
return string.Format("insert into {0}({1}) values ({2})", BillModel.MasterTable, fieldBuilder.ToString().TrimEnd(','), valueBuilder.ToString().TrimEnd(','));
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:获取修改表头数据</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-12-07 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="parmaryValue">单据值.</param>
|
||
/// <returns>System.String.</returns>
|
||
private string GetUpdateRecord(string parmaryValue)
|
||
{
|
||
StringBuilder updateBuilder = new StringBuilder();
|
||
|
||
|
||
//DataTable DetailedProperties = BaseImpl.GetDataTableResult(string.Format("select COLUMN_NAME,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH from information_schema.columns where table_name = '{0}'", BillModel.MasterTable));
|
||
DataTable DetailedProperties = MainImpl.GetDatabaseProperty(BillModel.MasterTable);
|
||
|
||
string errorMessage = string.Empty;//数据不符合数据库规范的信息
|
||
// 修改单据
|
||
foreach (ControlModel model in this.ControlObj.ControlModels)
|
||
{
|
||
if (!model.IsSave ||
|
||
model.FieldName.Equals(BillModel.RtagidKey, StringComparison.OrdinalIgnoreCase) ||
|
||
model.FieldType == ControlType.LabPic ||
|
||
model.FieldType == ControlType.LabPicEx ||
|
||
model.FieldType == ControlType.LabPrompt)
|
||
continue;
|
||
|
||
if (string.IsNullOrWhiteSpace(model.FieldName)) continue;
|
||
|
||
BaseUserControl userControl = this.ControlObj.FindControl(model);
|
||
if (userControl != null)
|
||
{
|
||
string fieldValue = this.ControlObj.GetControlValue(model);
|
||
if (SystemInfo.Instance.TrimWhiteSpace)
|
||
fieldValue = fieldValue.Trim();
|
||
if (fieldValue == "****") continue;
|
||
|
||
errorMessage = errorMessage + DatabaseFormatJudgment.SaveOrModifyBalidation(DetailedProperties, model, fieldValue);
|
||
if (string.IsNullOrEmpty(fieldValue) && model.Isintordecimal) fieldValue = "0";//数值保存时为空的话默认保存为0;
|
||
|
||
updateBuilder.Append(string.IsNullOrEmpty(fieldValue) ? string.Format("{0}={1}", model.FieldName, this.ControlObj.GetNullValue(model)) : string.Format("{0}=N'{1}',", model.FieldName, fieldValue.Contains("'") ? fieldValue.Replace("'", "''") : fieldValue));
|
||
|
||
}
|
||
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(errorMessage)) SaveErrorMessage = "表头错误:" + errorMessage;
|
||
return string.Format("update {0} set {1} where {2}='{3}'", BillModel.MasterTable, updateBuilder.ToString().TrimEnd(','), BillModel.PrimaryKey, parmaryValue);
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:获取保存明细数据</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-12-07 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <returns>System.String.</returns>
|
||
private StringBuilder GetDetailRecord(string guid, string billNo, List<DataRow> addRowList)
|
||
{
|
||
// 构造明细
|
||
StringBuilder detailBuilder = new StringBuilder();
|
||
DataTable detailTable = this.gcMain.GridControl.DataSourceTable().TrimDeleteRows();
|
||
if (this.BillModel.DetailTreeTable)
|
||
{
|
||
detailTable = ((this.gcMain as TreeGridControlEx).TreeListObj.DataSource as DataTable).TrimDeleteRows();
|
||
}
|
||
|
||
//string Autogrowcolumn = SqlHelper.ExecuteScalar(string.Format("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.columns WHERE TABLE_NAME='{0}' AND COLUMNPROPERTY(OBJECT_ID('{0}'),COLUMN_NAME,'IsIdentity')=1", BillModel.DetailTable)) + ""; ;//自增长列
|
||
//DataTable DetailedProperties = BaseImpl.GetDataTableResult(string.Format("select COLUMN_NAME,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH from information_schema.columns where table_name = '{0}'", BillModel.DetailTable + "_temp"));//单据明细性表
|
||
|
||
string Autogrowcolumn = MainImpl.GetAutogrowcolumn(BillModel.DetailTable);
|
||
DataTable DetailedProperties = MainImpl.GetDatabaseProperty(BillModel.DetailTable + "_temp");//单据明细性表
|
||
|
||
//主键
|
||
//DataTable primaryKeydt = BaseImpl.GetDataTableResult(string.Format("SELECT TABLE_NAME,COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME='{0}'", BillModel.DetailTable));
|
||
//string primaryKey = string.Empty;
|
||
//bool AddPrimaryKey = false;
|
||
//if (primaryKeydt.Rows.Count > 0)
|
||
//{
|
||
// primaryKey = primaryKeydt.Rows[0]["COLUMN_NAME"] + "";
|
||
//}
|
||
//if (!string.IsNullOrWhiteSpace(primaryKey))
|
||
//{
|
||
// DataTable dt = this.gcMain.gridControl.DataSource as DataTable;
|
||
// if (dt.Columns.Contains(primaryKey))
|
||
// {
|
||
// AddPrimaryKey = true;
|
||
// }
|
||
//}
|
||
|
||
if (detailTable.Rows.Count > 0)
|
||
{
|
||
int lineNumber = 1;
|
||
DataTable BillColumns = BaseImpl.GetDataTableResult(string.Format("select * from {0} where 1<>1", BillModel.DetailTable));
|
||
DataTable BillTempColumns = BaseImpl.GetDataTableResult(string.Format("select * from {0} where 1<>1", BillModel.DetailTable + "_temp"));
|
||
foreach (DataRow dataRow in detailTable.Rows)
|
||
{
|
||
string errorMessage = string.Empty;//数据不符合数据库规范的信息
|
||
StringBuilder fields = new StringBuilder();
|
||
StringBuilder values = new StringBuilder();
|
||
string detailSql = @"insert into " + BillModel.DetailTable + "_temp" + "({0}) values({1});";
|
||
fields.Append("sysstr,");
|
||
values.Append("'" + guid + "',");
|
||
|
||
foreach (DataColumn item in BillColumns.Columns)
|
||
{
|
||
//GridColumn col = this.gcMain.GridView.VisibleColumns.OfType<GridColumn>().FirstOrDefault(x => x.FieldName == item.ColumnName);
|
||
//if (col == null)
|
||
//{
|
||
// continue;
|
||
//}
|
||
if (item.ColumnName.Equals(guidField) || item.ColumnName.Equals(mRecordPrimaryField) || item.ColumnName.Equals(ERPInfo.Instance.isAddRows)) continue;
|
||
if (!BillTempColumns.Columns.Contains(item.ColumnName))
|
||
{
|
||
string type = "varchar(100)";
|
||
if (item.DataType == typeof(DateTime))
|
||
{
|
||
type = "datetime";
|
||
}
|
||
BaseImpl.ExecSqlValue(string.Format("alter table {0} add {1} {2}", BillModel.DetailTable + "_temp", item.ColumnName, type));
|
||
}
|
||
|
||
if (this.BillModel.DetailTreeTable)
|
||
{
|
||
TreeListColumn[] TreeListColumns = (this.gcMain as TreeGridControlEx).TreeListObj.Columns.Cast<TreeListColumn>().Where(x => x.FieldName.Equals(item.Caption, StringComparison.OrdinalIgnoreCase)).ToArray();
|
||
if (TreeListColumns.Count() == 0 && item.Caption.Equals(BillModel.PrimaryDetailKey))
|
||
{
|
||
string primaryValues = dataRow[BillModel.PrimaryDetailKey] + "";
|
||
if (!string.IsNullOrWhiteSpace(primaryValues))
|
||
{
|
||
fields.Append(item.ColumnName + ",");
|
||
values.Append("N'" + primaryValues.Replace("'", "''") + "',");
|
||
}
|
||
}
|
||
if (TreeListColumns.Count() == 0) continue;
|
||
}
|
||
else
|
||
{
|
||
GridColumn[] gridColumns = gcMain.GridView.Columns.Cast<GridColumn>().Where(x => x.FieldName.Equals(item.Caption, StringComparison.OrdinalIgnoreCase)).ToArray();
|
||
|
||
if (gridColumns.Count() == 0 && item.Caption.Equals(BillModel.PrimaryDetailKey))
|
||
{
|
||
string primaryValues = dataRow[BillModel.PrimaryDetailKey] + "";
|
||
if (!string.IsNullOrWhiteSpace(primaryValues))
|
||
{
|
||
fields.Append(item.ColumnName + ",");
|
||
values.Append("N'" + primaryValues.Replace("'", "''") + "',");
|
||
}
|
||
}
|
||
if (gridColumns.Count() == 0) continue;
|
||
}
|
||
|
||
|
||
fields.Append(item.ColumnName + ",");
|
||
string fieldValue = dataRow.Table.Columns.Contains(item.ColumnName) ? dataRow[item.ColumnName] + "" : string.Empty;
|
||
if (addRowList != null && addRowList.Contains(dataRow) && Autogrowcolumn.Equals(item.ColumnName))
|
||
{
|
||
fieldValue = "";
|
||
};
|
||
//if (SystemInfo.Instance.TrimWhiteSpace)
|
||
// fieldValue = fieldValue.Trim();
|
||
if (item.ColumnName.Equals(BillModel.PrimaryDetailKey, StringComparison.OrdinalIgnoreCase))
|
||
fieldValue = billNo;
|
||
if (!string.IsNullOrWhiteSpace(fieldValue))
|
||
{
|
||
values.Append(item.DataType == typeof(DateTime) ? "'" + Convert.ToDateTime(fieldValue).ToString("yyyy-MM-dd HH:mm:ss") + "'," : fieldValue.Contains("'") ? "N'" + fieldValue.Replace("'", "''") + "'," : "N'" + fieldValue + "',");
|
||
}
|
||
else
|
||
{
|
||
if (item.DataType == typeof(Decimal) ||
|
||
item.DataType == typeof(Double) ||
|
||
item.DataType == typeof(Int16) ||
|
||
item.DataType == typeof(Int32) ||
|
||
item.DataType == typeof(Int64))
|
||
values.Append("0,");
|
||
else if (item.DataType == typeof(DateTime))
|
||
{
|
||
values.Append("NULL,");
|
||
}
|
||
else
|
||
{
|
||
values.Append("'',");
|
||
|
||
}
|
||
|
||
}
|
||
errorMessage = errorMessage + DatabaseFormatJudgment.SaveOrModifyBalidation(_detailColumns, DetailedProperties, dataRow, item, fieldValue);
|
||
|
||
//SaveErrorMessage = SaveErrorMessage +(string.IsNullOrWhiteSpace(DatabaseFormatJudgment.SaveOrModifyBalidation(_detailColumns, DetailedProperties, dataRow, item, fieldValue))?"":);
|
||
}
|
||
|
||
|
||
|
||
detailBuilder.AppendFormat(detailSql, fields.ToString().Trim(','), values.ToString().Trim(','));
|
||
if (!string.IsNullOrWhiteSpace(errorMessage)) errorMessage = "第" + lineNumber + "行:" + errorMessage;
|
||
SaveErrorMessage = SaveErrorMessage + errorMessage;
|
||
lineNumber++;
|
||
}
|
||
}
|
||
return detailBuilder;
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:保存单据</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-04-20 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="comfirm">是否继续执行(0.1).</param>
|
||
/// <param name="canTipMsg">是否显示成功提示信息</param>
|
||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
|
||
private bool BillSave(int comfirm = 0, bool canTipMsg = true)
|
||
{
|
||
bool saveResult = false;
|
||
if (this.ControlObj.VerifyNull())
|
||
{
|
||
//保存前执行某个右键
|
||
if (!string.IsNullOrEmpty(BillModel.BeforeBillSaveExec))
|
||
{
|
||
DataRow menuRow = BaseModuleImpl.GetBaseGridRightMenuById(BillModel.BeforeBillSaveExec);
|
||
if (menuRow != null)
|
||
{
|
||
#region 特殊处理
|
||
string movepage = (this.ControlObj.ReplaceControlValue("{qms_maddf_addMode}").Equals("6")) ? "-9998" : "-9999";
|
||
foreach (XtraTabPage xtraTabPage in this.tb_buttom.TabControlObj.TabPages)
|
||
{
|
||
if (xtraTabPage.Tag != null && (xtraTabPage.Tag != null && xtraTabPage.Tag is System.Windows.Forms.Control pageControl) && pageControl.Tag != null)
|
||
{
|
||
if (pageControl.Tag is GridDetailModel detailModel && (detailModel.Orderid + "").Equals(movepage))
|
||
{
|
||
if (xtraTabPage.Tag is GridControlEx uniongGcEx)
|
||
{
|
||
DataTable unionTable = uniongGcEx.GridControl.DataSourceTable();
|
||
if (unionTable != null && unionTable.Rows.Count > 0 && uniongGcEx.GridView.GetSelectedRows().Length == 0)
|
||
{
|
||
DialogResult dialogResult = MessageUtil.Show("未选择关联引用修改\r\n是否不需要进行选择?", MessageBoxButtons.OKCancel);
|
||
if (dialogResult == DialogResult.Cancel)
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
DataTable table = gcMain.gridControl.DataSourceTable();
|
||
ControlModel modeControlModel = ControlObj.ControlModels.Where(n => n.LabelText.Equals("上传模式")).FirstOrDefault();
|
||
string addMode = ControlObj.GetControlValue(modeControlModel);
|
||
if (modeControlModel != null && table.Columns.Contains("qms_laddf_mode"))
|
||
{
|
||
foreach (DataRow item in table.Rows)
|
||
{
|
||
item["qms_laddf_mode"] = addMode;
|
||
}
|
||
}
|
||
ControlModel speciesNoControlModel = ControlObj.ControlModels.Where(n => n.LabelText.Equals("文件分类")).FirstOrDefault();
|
||
string speciesNo = ControlObj.GetControlValue(speciesNoControlModel);
|
||
if (speciesNoControlModel != null && table.Columns.Contains("BomAddSpeciesNo"))
|
||
{
|
||
foreach (DataRow item in table.Rows)
|
||
{
|
||
item["BomAddSpeciesNo"] = speciesNo;
|
||
}
|
||
}
|
||
#endregion
|
||
CommonMenu menu = new CommonMenu(this.SysModel, this.ControlObj, this.gcMain);
|
||
menu.ApplyBefore += new CommonToolApplyEventHandler(OnMenuApplyBefore);
|
||
menu.DynamicLinkAfter += new CommonToolAfterDynamicLinkEventHandler(OnDynamicLinkAfter);
|
||
StaticControl.RightMenuGridView = gcMain.GridView;
|
||
StaticControl.Comprefix = this.BillModel.DetailPreFix;
|
||
StaticControl.RightMenuMyControl = ControlObj;
|
||
menu.Apply(menuRow);
|
||
if (!menu.issuccess)
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
//记录表格状态
|
||
List<DataRow> addRowList = new List<DataRow>();
|
||
DataTable sourceTable = gcMain.GridControl.DataSourceTable();
|
||
foreach (DataRow dataRow in sourceTable.Rows)
|
||
{
|
||
if (dataRow.RowState == DataRowState.Added)
|
||
{
|
||
addRowList.Add(dataRow);
|
||
}
|
||
}
|
||
// 保存之前先进行表格更新
|
||
if (this.BillModel.DetailTreeTable)
|
||
{
|
||
(this.gcMain as TreeGridControlEx).TreeListObj.PostEditor();
|
||
//(this.gcMain as TreeGridControlEx).TreeListObj.UpdateCurrentRow();
|
||
}
|
||
else
|
||
{
|
||
this.gcMain.GridView.PostEditor();
|
||
this.gcMain.GridView.UpdateCurrentRow();
|
||
}
|
||
//虚构一个保存存储过程
|
||
DataTable tvp = new DataTable();
|
||
//更新前进行数据源筛选
|
||
if (DateColumnList.Count > 0)
|
||
{
|
||
// 创建临时表
|
||
tvp.Columns.Add("lblOrderNo", typeof(string)); // 固定主键
|
||
tvp.Columns.Add("billdocument_id", typeof(string)); // 固定主键
|
||
tvp.Columns.Add("showday", typeof(string));
|
||
tvp.Columns.Add("amount", typeof(decimal));
|
||
|
||
// 获取主数据源
|
||
DataTable mainDataSource = gcMain.GridControl.DataSourceTable();
|
||
if (mainDataSource.Columns.Contains(BillModel.DetailUUIDKey))
|
||
{
|
||
// 遍历主数据源
|
||
foreach (DataRow row in mainDataSource.Rows)
|
||
{
|
||
if (row.RowState == DataRowState.Modified || row.RowState == DataRowState.Added)
|
||
{
|
||
// 提取 billdocument_id
|
||
string key = row[BillModel.DetailUUIDKey].ToString();
|
||
if (!string.IsNullOrEmpty(key))
|
||
{
|
||
// 遍历列并处理虚拟列
|
||
foreach (GridColumn col in DateColumnList)
|
||
{
|
||
// 检查值是否发生变化
|
||
bool isVerifyupd = true;
|
||
if (row.RowState == DataRowState.Modified)
|
||
{
|
||
object originalValue = row[col.FieldName, DataRowVersion.Original];
|
||
object currentValue = row[col.FieldName, DataRowVersion.Current];
|
||
isVerifyupd = !object.Equals(originalValue, currentValue);
|
||
}
|
||
|
||
if (isVerifyupd)
|
||
{
|
||
// 解析金额
|
||
decimal newAmount = 0m;
|
||
if (row[col.FieldName] != DBNull.Value && !string.IsNullOrWhiteSpace(row[col.FieldName].ToString()))
|
||
{
|
||
decimal.TryParse(row[col.FieldName].ToString(), out newAmount);
|
||
}
|
||
// 插入数据到临时表
|
||
DataRow dr = tvp.NewRow();
|
||
dr["billdocument_id"] = key;
|
||
dr["showday"] = col.FieldName; //列名如 "2025-03-06"
|
||
dr["amount"] = newAmount;
|
||
tvp.Rows.Add(dr);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
try
|
||
{
|
||
if (this.gcMain.VerifyNull())
|
||
{
|
||
if (this.gcMain.RepeatedVerificationNames.Count > 0 && this.gcMain.VerifyDuplicateColumns())
|
||
{
|
||
MessageUtil.Show("表格中数据内容重复,保存失败!");
|
||
return saveResult;
|
||
}
|
||
//if(!VerificationCond()) return saveResult;
|
||
|
||
WaitForm.ShowForm(ResourceKeys.DataSaving);
|
||
string billNo = this.lblOrderNo.Text.Trim();
|
||
string detailGuid = Guid.NewGuid().ToString();
|
||
|
||
string masterSql = BillModel.SaveState ? GetUpdateRecord(billNo) : GetAddRecord(ref billNo);
|
||
string detailSql = GetDetailRecord(detailGuid, billNo, addRowList).ToString();
|
||
// 检查单据头数据合法性
|
||
if (string.IsNullOrEmpty(masterSql)) return false;
|
||
|
||
// 验证明细合法性
|
||
if (string.IsNullOrEmpty(detailSql) && !this.BillModel.SaveNullDetail)
|
||
{
|
||
MessageUtil.Show(ResourceKeys.BillDetailIsNotNull);
|
||
return false;
|
||
}
|
||
|
||
|
||
string tipMsg = string.Empty;
|
||
int result = BillImpl.BillSave(masterSql, detailSql, BillModel.DetailTable, ref billNo, detailGuid, BillModel.BillSeq, BillModel.SaveState ? 2 : 1, comfirm, out tipMsg, 0, this.BillModel.NewVer);
|
||
WaitForm.HideForm();
|
||
switch (result)
|
||
{
|
||
case 1:
|
||
// 保存成功
|
||
if (canTipMsg) MessageUtil.Show(BillModel.TypeName + ResourceKeys.SaveSuccess);
|
||
#region 单据保存成功调用Api接口
|
||
if (ApiHelper.IsExecEventApi(Interface.Api.OperateEvent.AfterModuleDataChange, this.SysModel.ModuleCode, 0))
|
||
{
|
||
ApiHelper apiHelper = new ApiHelper(this.SysModel.ModuleCode, billNo, BillModel.PrimaryKey, BillModel.MasterTable, 0);
|
||
switch (BillModel.SaveState)
|
||
{
|
||
case false:
|
||
apiHelper.OnEvent(Interface.Api.OperateEvent.AfterModuleDataChange, Interface.Api.ActionType.Add);//添加
|
||
break;
|
||
case true:
|
||
apiHelper.OnEvent(Interface.Api.OperateEvent.AfterModuleDataChange, Interface.Api.ActionType.Update);//更新
|
||
break;
|
||
}
|
||
if (!apiHelper.apiHandler.GetApiSuccess(apiHelper.apiHandlerModels) && canTipMsg)
|
||
{
|
||
MessageUtil.Show(apiHelper.apiResutMsg);
|
||
}
|
||
}
|
||
#endregion
|
||
this.lblOrderNo.Text = billNo;
|
||
this.SetBillStatus(BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, billNo)));
|
||
saveResult = true;
|
||
SaveRefreshSource();
|
||
RefreshPrindMenu();
|
||
//刷新下方配置的附件模块
|
||
if (this.BillModel.SaveRefreshAdditional) this.OngcMainRowCellClick(null, null);
|
||
|
||
//保存完成后所有数据源进行拼接执行保存
|
||
if (tvp != null && tvp.Rows.Count > 0)
|
||
{
|
||
if (gcMain.jhrowitem != null)
|
||
{
|
||
// 插入数据到临时表
|
||
DataRow dr = tvp.NewRow();
|
||
dr["lblOrderNo"] = billNo;
|
||
dr["billdocument_id"] = "计划文件" + gcMain.jhrowitem.ToJsonObject();
|
||
if (DateColumnList.Count > 0 && DateColumnList[0].Tag is DateTime dateTime)
|
||
{
|
||
dr["showday"] = dateTime.ToString("yyyy-MM-dd"); //日期
|
||
}
|
||
tvp.Rows.Add(dr);
|
||
|
||
}
|
||
foreach (DataRow item in tvp.Rows)
|
||
{
|
||
item["lblOrderNo"] = billNo;
|
||
}
|
||
|
||
// 调用存储过程保存变更数据
|
||
string msg;
|
||
int ret = SaveDayPlanChanges(tvp, out msg);
|
||
if (ret != 1)
|
||
{
|
||
MessageUtil.Show("保存失败:" + msg);
|
||
}
|
||
OnGcMainDataSourceChanged(gcMain.GridView, null);//手动刷新日期合计数据源
|
||
}
|
||
break;
|
||
case 9:
|
||
// 继续执行保存
|
||
if (string.IsNullOrWhiteSpace(tipMsg)) tipMsg = "保存单据临时表失败";
|
||
if (MessageUtil.Show(tipMsg, MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||
saveResult = this.BillSave(1, canTipMsg);
|
||
break;
|
||
default:
|
||
// 保存失败
|
||
SaveErrorMessage = SaveErrorMessage + "\r\n" + "出错原因:\r\n" + tipMsg;
|
||
MessageUtil.Show(BillModel.TypeName + ResourceKeys.SaveFault + "\r\n" + SaveErrorMessage);
|
||
SaveErrorMessage = string.Empty;
|
||
|
||
if (tipMsg.Contains("ruleid") && false)
|
||
{
|
||
string ruleid = tipMsg.Split(',')[0].Replace("ruleid", "").Replace("=", "").Trim();
|
||
string sql = string.Format("select * from p_systembusinesslogictab where id = '{0}'", ruleid);
|
||
string rulesModid = string.Empty;
|
||
string rulesParam = this.ControlObj.ReplaceParentControlValue(ReplaceHelper.ReplaceUserInfo(""));
|
||
|
||
}
|
||
|
||
if (tipMsg.StartsWith("@") && false)
|
||
{
|
||
//根据tipMsg中数据找到pMenu中对应的右键
|
||
foreach (BarItemLink itemLink in pMenu.ItemLinks)
|
||
{
|
||
if (false)
|
||
{
|
||
ErrorRestriction errorRestriction = new ErrorRestriction(tipMsg, this.SysModel, this.ControlObj, itemLink, this.BillModel, this.lblOrderNo.Text.Trim());
|
||
DialogResult drr = errorRestriction.ShowDialog();
|
||
errorRestriction.Dispose();
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
if (string.IsNullOrWhiteSpace(SaveErrorMessage))
|
||
{
|
||
MessageUtil.Show(ex.Message);
|
||
}
|
||
else
|
||
{
|
||
MessageUtil.Show("保存单据失败!\r\n" + SaveErrorMessage);
|
||
}
|
||
SaveErrorMessage = string.Empty;
|
||
LogHelper.Instance.WriteError(ex);
|
||
LogUtil.WriteError("保存单据失败!", ex);
|
||
}
|
||
finally
|
||
{
|
||
WaitForm.HideForm();
|
||
}
|
||
}
|
||
return saveResult;
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:通过配置条件刷新打印菜单</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2020-04-10 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="hintMsg">The hint MSG.</param>
|
||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
|
||
public void RefreshPrindMenu()
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(BillModel.BillPrintTag))
|
||
{
|
||
pMprint.ClearLinks();
|
||
// 打印模版
|
||
DataRow rowItem = this.gcMain.GridView.GetDataRow(this.gcMain.GridView.FocusedRowHandle);
|
||
string BillPrintTag = this.ControlObj.ReplaceParentControlValue(BillModel.BillPrintTag);
|
||
BillPrintTag = ReplaceHelper.ReplaceRowParam(rowItem, BillPrintTag);
|
||
// BillPrintTag = ReplaceHelper.ReplaceParamToValue(BillPrintTag,this.lblOrderNo.Text.Trim());
|
||
string value = MainImpl.GetResult(ReplaceHelper.ReplaceRowParam(rowItem, BillPrintTag)) + "";
|
||
string[] files = value.Split('|');
|
||
for (int i = 0; i < files.Length; i++)
|
||
{
|
||
string fileName = files[i];
|
||
if (!string.IsNullOrWhiteSpace(fileName))
|
||
{
|
||
BarButtonItem itemPrint = new BarButtonItem();
|
||
int index = i + 1;
|
||
itemPrint.Caption = files[i].Replace(".rmf", "").Replace(".frx", "");
|
||
itemPrint.Tag = files[i];
|
||
itemPrint.ItemClick += new ItemClickEventHandler(OnPrintItemClick);
|
||
pMprint.AddItem(itemPrint);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:单据提交</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-12-13 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="hintMsg">The hint MSG.</param>
|
||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
|
||
private void BillApply(string hintMsg, int comfirm = 0)
|
||
{
|
||
try
|
||
{
|
||
WaitForm.ShowForm(ResourceKeys.Handing);
|
||
string tipMsg = string.Empty;
|
||
string billNo = this.lblOrderNo.Text.Trim();
|
||
|
||
#region 提交审核前调用API
|
||
if (ApiHelper.IsExecEventApi(Interface.Api.OperateEvent.BeforeModuleAuditStateChange, this.SysModel.ModuleCode, 0))
|
||
{
|
||
ApiHelper apiHelper = new ApiHelper(this.SysModel.ModuleCode, billNo, this.BillModel.PrimaryKey, this.BillModel.MasterTable, 0);
|
||
apiHelper.OnEvent(Interface.Api.OperateEvent.BeforeModuleAuditStateChange, Interface.Api.ActionType.Submit);//提交
|
||
if (!apiHelper.apiHandler.GetApiSuccess(apiHelper.apiHandlerModels))
|
||
{
|
||
MessageUtil.Show(ResourceKeys.ApplyFault + "\r\n" + apiHelper.apiResutMsg);
|
||
return;
|
||
}
|
||
}
|
||
#endregion
|
||
int result = BillImpl.BillApply(this.SysModel.ModuleCode, billNo, "", 1, out tipMsg, comfirm);
|
||
WaitForm.HideForm();
|
||
switch (result)
|
||
{
|
||
case 1:
|
||
// 提交成功
|
||
if (!this.BillModel.DisableSubmitPrompt) MessageUtil.Show(BillModel.TypeName + ResourceKeys.ApplySuccess);
|
||
this.SetBillStatus(BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, billNo)));
|
||
this.RefreshSource(GetBillSourceManager());
|
||
this.RefreshSelectedSource();
|
||
|
||
if (this.BillModel.ApplyRefresh)
|
||
{
|
||
this.SetBillStatus(null);
|
||
this.ControlObj.ResetControlValue();
|
||
}
|
||
|
||
#region 提交审核成功后调用API
|
||
if (ApiHelper.IsExecEventApi(Interface.Api.OperateEvent.AfterModuleAuditStateChange, this.SysModel.ModuleCode, 0))
|
||
{
|
||
ApiHelper apiHelper = new ApiHelper(this.SysModel.ModuleCode, billNo, this.BillModel.PrimaryKey, this.BillModel.MasterTable, 0);
|
||
apiHelper.OnEvent(Interface.Api.OperateEvent.AfterModuleAuditStateChange, Interface.Api.ActionType.Submit);//提交
|
||
if (!apiHelper.apiHandler.GetApiSuccess(apiHelper.apiHandlerModels))
|
||
{
|
||
MessageUtil.Show(apiHelper.apiResutMsg);
|
||
}
|
||
}
|
||
#endregion
|
||
#region 提交审核成功后是否直接调用新增
|
||
if (BillModel.IsApplyAferAdd || SystemInfo.Instance.BillNewAfterCommit)
|
||
{
|
||
this.OnBillAddClick(this.btnBillAdd, null);
|
||
//this.btnBillAdd.PerformClick();
|
||
}
|
||
#endregion
|
||
// 推送消息
|
||
PushHelper push = new PushHelper(billNo, "0", this.SysModel.ModuleCode, "", "", 0);
|
||
push.Push_Bill_Oper_Message();
|
||
|
||
break;
|
||
case 9:
|
||
// 继续执行保存
|
||
if (string.IsNullOrWhiteSpace(tipMsg)) tipMsg = "提交单据失败";
|
||
if (MessageUtil.Show(tipMsg, MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||
this.BillApply("", 1);
|
||
break;
|
||
case 99:
|
||
// 继续执行提交
|
||
if (MessageUtil.Show(tipMsg, MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||
{
|
||
FrmPrompt prompt = new FrmPrompt(tipMsg);
|
||
prompt.Size = new Size(300, 200);
|
||
|
||
DialogResult dialog = prompt.ShowDialog();
|
||
if (dialog == DialogResult.OK)
|
||
{
|
||
this.BillApply(prompt.PromptMsg);
|
||
}
|
||
}
|
||
break;
|
||
default:
|
||
// 提交失败
|
||
MessageUtil.Show(BillModel.TypeName + ResourceKeys.ApplyFault + "\r\n" + tipMsg);
|
||
break;
|
||
}
|
||
}
|
||
catch
|
||
{
|
||
throw;
|
||
}
|
||
finally
|
||
{
|
||
WaitForm.HideForm();
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 事件相关
|
||
/// <summary>
|
||
/// <para>说明:点击空白界面后需要获取焦点</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2020-09-04 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void OnMainFocusAfter(object sender, EventArgs e)
|
||
{
|
||
this.pl_main_center_master.Focus();
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:打印完成后回调</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-07-05 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The e.</param>
|
||
private void OnReportPrintAfter(object sender, EventArgs e)
|
||
{
|
||
//打印完成后添加数据库
|
||
if (_printSaveParams != null && _printSaveParams.Count > 0)
|
||
{
|
||
int result = BaseModuleImpl.SavePrintRecord(_printSaveParams[0], _printSaveParams[1], _printSaveParams[2], _printSaveParams[3], _printSaveParams[4]);
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-28 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="KeyEventArgs"/> instance containing the event data.</param>
|
||
private void OnFrmMainKeyDown(object sender, KeyEventArgs e)
|
||
{
|
||
// 窗口获取按键则表格按键中断.有时间处理
|
||
if (e.Modifiers.CompareTo(Keys.Control) == 0)
|
||
{
|
||
if (e.KeyCode == Keys.Left)
|
||
this.ssc_main_top.Collapsed = true;
|
||
if (e.KeyCode == Keys.Right)
|
||
this.ssc_main_top.Collapsed = false;
|
||
if (e.KeyCode == Keys.Down)
|
||
this.ssc_main.Collapsed = true;
|
||
if (e.KeyCode == Keys.Up)
|
||
this.ssc_main.Collapsed = false;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:树节点选中刷新明细</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-12-01 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="TreeViewEventArgs"/> instance containing the event data.</param>
|
||
private void OnTreeNodeSelectAfter(object sender, TreeViewEventArgs e)
|
||
{
|
||
TreeView tree = (TreeView)sender;
|
||
XtraTabPage tabPage = this.xtc_left_container.SelectedTabPage;
|
||
BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel;
|
||
if (unionModel != null)
|
||
{
|
||
WaitForm.ShowForm();
|
||
try
|
||
{
|
||
|
||
|
||
string sqlValue = ReplaceHelper.ReplaceUserInfo(ReplaceHelper.ReplaceWhereCond(unionModel.ModelObj.DetailSql));
|
||
sqlValue = sqlValue.Replace("#", "");
|
||
sqlValue = this.ControlObj.ReplaceControlValue(sqlValue);
|
||
if (unionModel.SearchObj != null) sqlValue = unionModel.SearchObj.ReplaceControlValue(sqlValue);
|
||
sqlValue = ReplaceHelper.ReplaceParamToValue(sqlValue, e.Node.Name);
|
||
|
||
if (unionModel.ModelObj.sourceDetailType == "1" && unionModel.TreeGridDetailControlObj.TreeListObj != null)
|
||
{
|
||
unionModel.TreeGridDetailControlObj.TreeListObj.DataSource = BillImpl.GetDataTableResult(sqlValue);
|
||
}
|
||
else
|
||
{
|
||
unionModel.GridDetailControlObj.GridControl.DataSource = BillImpl.GetDataTableResult(sqlValue);
|
||
this.ClearHighlightRows(unionModel.GridDetailControlObj.GridView);
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Instance.WriteError(ex);
|
||
LogUtil.WriteError(BillModel.TypeName + "模块选中树节点" + tree.SelectedNode.Text + "刷新明细失败!", ex);
|
||
}
|
||
finally
|
||
{
|
||
WaitForm.HideForm();
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:单据来源切换Tab标签</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-28 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="TabPageChangedEventArgs"/> instance containing the event data.</param>
|
||
private void OnTabSelectedPageChanged(object sender, TabPageChangedEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (_isInitFinish && !SystemInfo.Instance.IsBillSourceRefushTag.Equals("1"))
|
||
{
|
||
BillSourceUnionModel unionModel = e.Page.Tag as BillSourceUnionModel;
|
||
if (unionModel != null)
|
||
{
|
||
this.RefreshSelectedSource();
|
||
this.tb_buttom.TabControlObj.TabPages[0].Controls.Clear();
|
||
if (unionModel.GridDetailDetailControlObj == null)
|
||
{
|
||
this.tb_buttom.TabControlObj.TabPages[0].Controls.Add(unionModel.GridDetailControlObj != null ? unionModel.GridDetailControlObj : unionModel.TreeGridDetailControlObj);
|
||
}
|
||
else
|
||
{
|
||
//this.tb_buttom.TabControlObj.TabPages[0].Controls.Add(unionModel.GridDetailDetailControlObj);
|
||
//创建SplitContainerControl控件,让下方可以左右拖动
|
||
SplitContainerControl splitContainerControl = new DevExpress.XtraEditors.SplitContainerControl();
|
||
splitContainerControl.Dock = DockStyle.Fill;
|
||
splitContainerControl.Panel1.Controls.Add(unionModel.GridDetailControlObj);
|
||
splitContainerControl.Panel2.Controls.Add(unionModel.GridDetailDetailControlObj);
|
||
int width = this.tb_buttom.Width;//获取控件宽度
|
||
splitContainerControl.SplitterPosition = width / 2;//然后将分割位置设置在宽度一半位置
|
||
this.tb_buttom.TabControlObj.TabPages[0].Controls.Add(splitContainerControl);
|
||
}
|
||
this.tb_buttom.TabControlObj.TabPages[0].Text = unionModel.ModelObj.UserName + DetailedSuffix;
|
||
if (unionModel.IsChange == false)
|
||
{
|
||
AutoSizeChange.ControllInitializeSize(this.tb_buttom.TabControlObj.TabPages[0]);
|
||
unionModel.IsChange = true;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Instance.WriteError(ex);
|
||
LogUtil.WriteError("单据切换标签失败!", ex);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:单据来源树结构默认查询条件</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-28 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
private void OnTreeSearchClick(object sender, EventArgs e)
|
||
{
|
||
XtraTabPage tabPage = this.xtc_left_container.SelectedTabPage;
|
||
|
||
this.RefreshSourceDetail(tabPage.Tag as BillSourceUnionModel);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 单据来源树 条件框回车查询
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void OnTreeConditionKeyDown(object sender, KeyEventArgs e)
|
||
{
|
||
if (e.KeyCode == Keys.Enter)
|
||
{
|
||
this.OnTreeSearchClick(null, null);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:第一个页签初始化完成刷新数据</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期: </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
private void OnFirstPageDataSourceBindCallBack(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (IsBillMaster)
|
||
{
|
||
this.RefreshSelectedSource();
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Instance.WriteError(ex);
|
||
LogUtil.WriteError("单据切换标查询失败!", ex);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:第一个页签初始化完成刷新数据</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期: </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
private void OnPageDataSourceBindCallBack(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
MyControl searchControl = sender as MyControl;
|
||
XtraTabPage tabPage = pageNumKey[searchControl];
|
||
if (tabPage.TabIndex == 0) return;
|
||
BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel;
|
||
string searchSql = unionModel.ModelObj.SourceSql;
|
||
searchSql = ReplaceHelper.ReplaceUserInfo(searchSql);
|
||
searchSql = ReplaceHelper.ReplaceWhereCond(searchSql);
|
||
searchSql = unionModel.SearchObj.SetSearchSqlValue(searchSql, true, true);
|
||
// 查找FROM子句的位置
|
||
int fromIndex = searchSql.IndexOf("FROM", StringComparison.OrdinalIgnoreCase);
|
||
if (fromIndex != -1)
|
||
{
|
||
// 生成优化后的SQL查询
|
||
string optimizedSql = "SELECT COUNT(*) " + searchSql.Substring(fromIndex);
|
||
searchSql = optimizedSql;
|
||
}
|
||
DataTable dt = MainImpl.GetDataTableResult(searchSql);
|
||
if (dt.Rows.Count > 0) tabPage.Text += "(" + dt.Rows[0][0] + QuantitySuffix;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Instance.WriteError(ex);
|
||
LogUtil.WriteError("单据条件绑定失败失败!", ex);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 跳转到指定页签,并执行配置条件的搜索
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void SearchControl_OnDataSourceBindCallBack(object sender, EventArgs e)
|
||
{
|
||
if (InitialSelectionTab != null)
|
||
{
|
||
this.xtc_left_container.SelectedTabPage = InitialSelectionTab;
|
||
BillSourceUnionModel model = InitialSelectionTab.Tag as BillSourceUnionModel;
|
||
if (model.SearchObj != null) model.SearchObj.SearchGrid();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:单据来源选中行,加载明细</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-30 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="SelectionChangedEventArgs"/> instance containing the event data.</param>
|
||
private void OnGridControlSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||
{
|
||
XtraTabPage tabPage = this.xtc_left_container.SelectedTabPage;
|
||
|
||
this.RefreshSourceDetail(tabPage.Tag as BillSourceUnionModel);
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:单据来源选中行,加载明细</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-30 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="SelectionChangedEventArgs"/> instance containing the event data.</param>
|
||
private void OnGridViewRowCellClick(object sender, RowCellClickEventArgs e)
|
||
{
|
||
|
||
XtraTabPage tabPage = this.xtc_left_container.SelectedTabPage;
|
||
BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel;
|
||
this.RefreshSourceDetail(unionModel);
|
||
}
|
||
/// <summary>
|
||
/// 单据来源双击行,加载明细
|
||
/// </summary>
|
||
/// <para>创建人:唐德馨</para>
|
||
/// <para>创建日期:2023-03-11 </para>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void OnSourceGridViewDoubleClick(object sender, EventArgs e)
|
||
{
|
||
|
||
XtraTabPage tabPage = this.xtc_left_container.SelectedTabPage;
|
||
BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel;
|
||
this.RefreshSourceDetail(unionModel);
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:单据明细选中刷新附件明细</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2021-06-30 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="SelectionChangedEventArgs"/> instance containing the event data.</param>
|
||
private void OngcMainRowCellClick(object sender, RowCellClickEventArgs e)
|
||
{
|
||
if (this.tb_buttom.TabControlObj.TabPages.Count > 1)
|
||
{
|
||
|
||
SetDetailGridDataSource();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 主表数据源改变时
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void OnGcMainDataSourceChanged(object sender, EventArgs e)
|
||
{
|
||
if (DateColumnList.Count > 0 && DateColumnList[0].Tag is DateTime dateTime)
|
||
{
|
||
string billNo = this.lblOrderNo.Text;
|
||
this.gcMain.GridControl.DataSourceChanged -= OnGcMainDataSourceChanged;
|
||
DataTable dataTable = gcMain.GridControl.DataSource as DataTable;
|
||
if (dataTable != null)
|
||
{
|
||
//DataTable dataMain = dataTable.Copy();
|
||
//string sqlValue = "select * from RD_worktimetab where 1 = 1";
|
||
//sqlValue = $"{sqlValue} and lblOrderNo = '{billNo}' and showday >= '{dateTime.ToString("yyyy-MM-dd")}'";
|
||
//DataTable dataDayPlan = BaseImpl.GetDataTableResult(sqlValue);
|
||
//---------- 查询①:渲染表格排程” ----------
|
||
string sqlExcludePlan = "SELECT * FROM RD_worktimetab WHERE 1 = 1";
|
||
sqlExcludePlan += $" AND lblOrderNo = '{billNo}'";
|
||
sqlExcludePlan += $" AND showday >= '{dateTime:yyyy-MM-dd}'";
|
||
sqlExcludePlan += " AND billdocument_id NOT LIKE N'计划文件%'";
|
||
// 获取结果
|
||
DataTable dataNoPlanFile = BaseImpl.GetDataTableResult(sqlExcludePlan);
|
||
// ---------- 查询②:只包含“计划文件” ----------
|
||
string sqlIncludePlan = "SELECT billdocument_id FROM RD_worktimetab WHERE 1 = 1";
|
||
sqlIncludePlan += $" AND lblOrderNo = '{billNo}'";
|
||
sqlIncludePlan += $" AND showday >= '{dateTime:yyyy-MM-dd}'";
|
||
sqlIncludePlan += " AND billdocument_id LIKE N'计划文件%'";
|
||
// 获取结果
|
||
DataTable dataOnlyPlanFile = BaseImpl.GetDataTableResult(sqlIncludePlan);
|
||
MergeMainDataWithDayPlan(dataTable, dataNoPlanFile, dateTime);
|
||
//若存在缓存计划数据则渲染合计
|
||
if (dataOnlyPlanFile.Rows.Count > 0)
|
||
{
|
||
string jhrowtiemjson = (dataOnlyPlanFile.Rows[0]["billdocument_id"] + "").Replace("计划文件", "");
|
||
try
|
||
{
|
||
JObject rowObject = JsonConvert.DeserializeObject<JObject>(jhrowtiemjson);
|
||
JArray jArray = new JArray();
|
||
jArray.Add(rowObject);
|
||
DataRow jhrowitem = JsonConvert.DeserializeObject<DataTable>(JsonConvert.SerializeObject(jArray)).Rows[0];
|
||
//渲染计划合计
|
||
gcMain.AddHeadquarters(jhrowitem);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
//else
|
||
//{
|
||
// gcMain.AddHeadquarters(null);
|
||
//}
|
||
gcMain.RefreshHeaderColor();
|
||
this.gcMain.GridControl.DataSource = null;
|
||
this.gcMain.GridControl.DataSource = dataTable;
|
||
}
|
||
this.gcMain.GridControl.DataSourceChanged += OnGcMainDataSourceChanged;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 保存日计划变更数据(批量保存)。
|
||
/// 调用存储过程 usp_MergeDayPlanChanges,将所有变更记录一次性提交到数据库。
|
||
/// 通过 TVP 参数传递数据,同时捕获输出参数 @msg 和返回值。
|
||
/// </summary>
|
||
/// <param name="tvp">包含所有变更记录的 DataTable,必须与 dbo.DayPlanChangeType 定义一致</param>
|
||
/// <param name="message">输出提示信息,存储过程执行后的返回消息</param>
|
||
/// <returns>存储过程返回值,成功返回 1,失败返回 0</returns>
|
||
public int SaveDayPlanChanges(DataTable tvp, out string message)
|
||
{
|
||
// 创建输出参数 @msg
|
||
SqlParameter pMsg = new SqlParameter("@msg", SqlDbType.VarChar, 2000)
|
||
{
|
||
Direction = ParameterDirection.Output
|
||
};
|
||
// 创建返回值参数 @return
|
||
SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int)
|
||
{
|
||
Direction = ParameterDirection.ReturnValue
|
||
};
|
||
// 创建 TVP 参数,名称必须与存储过程参数一致
|
||
SqlParameter tvpParam = new SqlParameter("@DayPlanChanges", SqlDbType.Structured)
|
||
{
|
||
TypeName = "dbo.DayPlanChangeTVP",
|
||
Value = tvp
|
||
};
|
||
// 构造参数数组
|
||
SqlParameter[] parameters = new SqlParameter[] { tvpParam, pMsg, returnValue };
|
||
// 执行存储过程,此处调用 ExecuteNonQuery 即可,不需要返回数据集
|
||
// 请确保 DBUtil.ExecuteNonQuery 方法能够传递参数并执行存储过程
|
||
BaseImpl.ExecProcedure("usp_MergeDayPlanChanges2025", parameters);
|
||
// 获取输出参数 @msg 中的提示信息
|
||
message = pMsg.Value.ToString();
|
||
// 获取存储过程的返回值
|
||
int result = Convert.ToInt32(returnValue.Value);
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 计划明细与主数据合并:
|
||
/// 1) 按 <paramref name="startDate"/> 起算 7 天动态生成列;
|
||
/// 2) 把 dataDayPlan 中对应日期的 amount 值填入主表;
|
||
/// 3) 计算行级合计写入 “heji” 列。
|
||
/// </summary>
|
||
private DataTable MergeMainDataWithDayPlan(DataTable dataMain, DataTable dataDayPlan, DateTime startDate)
|
||
{
|
||
const string rightPrimaryKey = "billdocument_id"; // dataDayPlan 主键
|
||
const string dateField = "showday";
|
||
const string amountField = "amount";
|
||
string topPrimaryKey = BillModel.DetailUUIDKey; // dataMain 主键
|
||
|
||
int dayCount = 0;
|
||
BaseUserControl baseUserControl = ControlObj.FindControl("bom_rdm_tianshu");
|
||
if (baseUserControl != null)
|
||
{
|
||
int.TryParse(baseUserControl.EditText, out dayCount);
|
||
}
|
||
if (dayCount <= 0)
|
||
{
|
||
dayCount = 7;
|
||
}
|
||
DateTime endDate = startDate.AddDays(dayCount);
|
||
|
||
// ---------- 1. 预索引 dataDayPlan:billdocument_id -> List<DataRow> ----------
|
||
var dayPlanMap = new Dictionary<string, List<DataRow>>();
|
||
foreach (DataRow row in dataDayPlan.Rows)
|
||
{
|
||
string billId = row[rightPrimaryKey].ToString();
|
||
if (!dayPlanMap.TryGetValue(billId, out var list))
|
||
{
|
||
list = new List<DataRow>();
|
||
dayPlanMap[billId] = list;
|
||
}
|
||
list.Add(row);
|
||
}
|
||
|
||
// ---------- 2. 为主表添加日期列和合计列 ----------
|
||
for (DateTime d = startDate; d <= endDate; d = d.AddDays(1))
|
||
{
|
||
string colName = d.ToString("yyyy-MM-dd");
|
||
if (!dataMain.Columns.Contains(colName))
|
||
dataMain.Columns.Add(colName, typeof(decimal));
|
||
}
|
||
if (!dataMain.Columns.Contains("workingsum"))
|
||
dataMain.Columns.Add("workingsum", typeof(decimal));
|
||
|
||
// ---------- 3. 预构建填充映射:主键 -> (日期列名, 金额) ----------
|
||
var dataMap = new Dictionary<string, Dictionary<string, decimal>>();
|
||
foreach (DataRow mainRow in dataMain.Rows)
|
||
{
|
||
string key = mainRow[topPrimaryKey].ToString();
|
||
var inner = new Dictionary<string, decimal>();
|
||
dataMap[key] = inner;
|
||
|
||
if (dayPlanMap.TryGetValue(key, out var rows))
|
||
{
|
||
foreach (DataRow dayRow in rows)
|
||
{
|
||
if (dayRow[dateField] == DBNull.Value) continue;
|
||
|
||
DateTime d = Convert.ToDateTime(dayRow[dateField]);
|
||
if (d < startDate || d > endDate) continue;
|
||
|
||
string col = d.ToString("yyyy-MM-dd");
|
||
if (!dataMain.Columns.Contains(col)) continue;
|
||
|
||
if (decimal.TryParse(dayRow[amountField]?.ToString(), out decimal amt))
|
||
inner[col] = amt;
|
||
}
|
||
}
|
||
}
|
||
|
||
// ---------- 4. 一次性填充并计算行合计 ----------
|
||
foreach (DataRow mainRow in dataMain.Rows)
|
||
{
|
||
string key = mainRow[topPrimaryKey].ToString();
|
||
decimal rowSum = 0m;
|
||
|
||
if (dataMap.TryGetValue(key, out var inner))
|
||
{
|
||
foreach (var kv in inner)
|
||
{
|
||
mainRow[kv.Key] = kv.Value;
|
||
rowSum += kv.Value;
|
||
}
|
||
}
|
||
|
||
mainRow["workingsum"] = rowSum; // 行汇总
|
||
}
|
||
|
||
return dataMain;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 构建带日期的数据源
|
||
/// </summary>
|
||
/// <param name="focusedRow"></param>
|
||
/// <param name="dataDayPlan"></param>
|
||
/// <param name="startDate"></param>
|
||
/// <returns></returns>
|
||
private void UpdateRowWithDayPlan(DataRow focusedRow, DataTable dataDayPlan, DateTime startDate)
|
||
{
|
||
string rightPrimaryKey = "billdocument_id";
|
||
string dateField = "showday";
|
||
string amountField = "amount";
|
||
string topPrimaryKey = BillModel.DetailUUIDKey;
|
||
|
||
int dayCount = 0;
|
||
BaseUserControl baseUserControl = ControlObj.FindControl("bom_rdm_tianshu");
|
||
if (baseUserControl != null)
|
||
{
|
||
int.TryParse(baseUserControl.EditText, out dayCount);
|
||
}
|
||
if (dayCount <= 0)
|
||
{
|
||
dayCount = 7;
|
||
}
|
||
|
||
DateTime endDate = startDate.AddDays(dayCount); // 计算结束日期
|
||
// **1. 预索引 dataDayPlan 数据(billdocument_id -> 该 key 相关的所有行)**
|
||
Dictionary<string, List<DataRow>> dayPlanMap = new Dictionary<string, List<DataRow>>();
|
||
foreach (DataRow row in dataDayPlan.Rows)
|
||
{
|
||
string billId = row[rightPrimaryKey].ToString();
|
||
if (!dayPlanMap.ContainsKey(billId))
|
||
{
|
||
dayPlanMap[billId] = new List<DataRow>();
|
||
}
|
||
dayPlanMap[billId].Add(row);
|
||
}
|
||
// **2. 预构建主数据的列**
|
||
for (DateTime dt = startDate; dt <= endDate; dt = dt.AddDays(1))
|
||
{
|
||
string colName = dt.ToString("yyyy-MM-dd");
|
||
if (!focusedRow.Table.Columns.Contains(colName))
|
||
{
|
||
focusedRow.Table.Columns.Add(colName, typeof(decimal)); // 确保列存在
|
||
}
|
||
}
|
||
// **3. 预构建数据填充映射表**
|
||
Dictionary<string, Dictionary<string, decimal>> dataMap = new Dictionary<string, Dictionary<string, decimal>>();
|
||
string key = focusedRow[topPrimaryKey].ToString();
|
||
if (!dataMap.ContainsKey(key))
|
||
{
|
||
dataMap[key] = new Dictionary<string, decimal>();
|
||
}
|
||
// **查找 key 关联的时间数据**
|
||
if (dayPlanMap.ContainsKey(key))
|
||
{
|
||
foreach (DataRow dayRow in dayPlanMap[key])
|
||
{
|
||
if (dayRow[dateField] != DBNull.Value)
|
||
{
|
||
DateTime dayValue = Convert.ToDateTime(dayRow[dateField]);
|
||
string colName = dayValue.ToString("yyyy-MM-dd");
|
||
if (dayValue >= startDate && dayValue <= endDate && focusedRow.Table.Columns.Contains(colName))
|
||
{
|
||
decimal.TryParse(dayRow[amountField] + "", out decimal amountValue);
|
||
dataMap[key][colName] = amountValue;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
// **4. 一次性填充 DataTable(避免逐行赋值带来的性能问题)**
|
||
if (dataMap.ContainsKey(key))
|
||
{
|
||
foreach (var col in dataMap[key])
|
||
{
|
||
focusedRow[col.Key] = col.Value;
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:单据明细选中刷新附件明细(明细为树表格时)</para>
|
||
/// <para>创建人:曹屹峰</para>
|
||
/// <para>创建日期:2021-06-30 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
private void TreeListObj_MouseClick(object sender, MouseEventArgs e)
|
||
{
|
||
// 获取点击的节点
|
||
DevExpress.XtraTreeList.Nodes.TreeListNode hitNode = (this.gcMain as TreeGridControlEx).TreeListObj.CalcHitInfo(e.Location).Node;
|
||
// 获取点击的列
|
||
DevExpress.XtraTreeList.Columns.TreeListColumn hitColumn = (this.gcMain as TreeGridControlEx).TreeListObj.CalcHitInfo(e.Location).Column;
|
||
if (hitNode != null && hitColumn != null)
|
||
{
|
||
if (this.tb_buttom.TabControlObj.TabPages.Count > 1)
|
||
{
|
||
|
||
SetDetailGridDataSource();
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 切换下方附加模块页签时,刷新当前页签
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void TabControlObj_SelectedPageChanged(object sender, TabPageChangedEventArgs e)
|
||
{
|
||
if (this.tb_buttom.TabControlObj.TabPages.Count > 1)
|
||
{
|
||
SetDetailGridDataSource();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:获取底部多标签数据</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-12-19 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
public void SetDetailGridDataSource()
|
||
{
|
||
|
||
DataRow rowItem = this.gcMain.GridView.GetFocusedDataRow();
|
||
if (this.BillModel.DetailTreeTable)
|
||
{
|
||
rowItem = (this.gcMain as TreeGridControlEx).GetViewFocusedDataRow();
|
||
}
|
||
int i = 0;
|
||
foreach (XtraTabPage page in this.tb_buttom.TabControlObj.TabPages)
|
||
{
|
||
if (i == 0)
|
||
{
|
||
i++;
|
||
continue;
|
||
}
|
||
if (this.BillModel.RefreshSelectedDetail && page != tb_buttom.TabControlObj.SelectedTabPage)
|
||
{
|
||
continue;
|
||
}
|
||
if (rowItem != null && page != null)
|
||
{
|
||
this.SetTabPageDataSource(page, rowItem);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:设置表格数据</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-01-29 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="tabPage">The tab page.</param>
|
||
/// <param name="gridControl">The grid control.</param>
|
||
public void SetTabPageDataSource(XtraTabPage tabPage, DataRow rowItem)
|
||
{
|
||
|
||
GridDetailModel model = this.tb_buttom.GetGridDetailModel(tabPage);
|
||
if (rowItem != null && model != null)
|
||
{
|
||
if (tabPage.Tag is ModuleWebView)
|
||
{
|
||
// 加载网页
|
||
string url = ReplaceHelper.ReplaceRowParam(rowItem, ReplaceHelper.ReplaceUserInfo(model.DetailSql));
|
||
url = url.StartsWith("http") ? url : SystemInfo.Instance.OAUrl + url;
|
||
ModuleWebView webView = tabPage.Tag as ModuleWebView;
|
||
webView.Dock = DockStyle.Fill;
|
||
webView.Tag = model;
|
||
webView.Navigate(url);
|
||
}
|
||
else if (tabPage.Tag is FrmWebBrowser)
|
||
{
|
||
// 加载网页
|
||
string url = ReplaceHelper.ReplaceRowParam(rowItem, ReplaceHelper.ReplaceUserInfo(model.DetailSql));
|
||
url = url.StartsWith("http") ? url : SystemInfo.Instance.OAUrl + url;
|
||
FrmWebBrowser webView = tabPage.Tag as FrmWebBrowser;
|
||
webView.Dock = DockStyle.Fill;
|
||
webView.Tag = model;
|
||
webView.LoadUrl(url);
|
||
}
|
||
else if (tabPage.Tag is FrmMiniBlink)
|
||
{
|
||
// 加载网页
|
||
string url = ReplaceHelper.ReplaceRowParam(rowItem, ReplaceHelper.ReplaceUserInfo(model.DetailSql));
|
||
url = url.StartsWith("http") ? url : SystemInfo.Instance.OAUrl + url;
|
||
FrmMiniBlink webView = tabPage.Tag as FrmMiniBlink;
|
||
webView.Dock = DockStyle.Fill;
|
||
webView.Tag = model;
|
||
webView.LoadUrl(url);
|
||
}
|
||
else if (tabPage.Tag is TabMultipledetails)
|
||
{
|
||
TabMultipledetails tabMultipledetails = tabPage.Tag as TabMultipledetails;
|
||
tabMultipledetails.SetConditionValues(rowItem);
|
||
|
||
GridControlEx grdExMain = (tabMultipledetails.SplitMain.Panel1.Tag as GridControlEx);
|
||
GridDetailModel MainModel = grdExMain.Tag as GridDetailModel;
|
||
string searchMainSql = this.GetSearchSql(MainModel, rowItem);
|
||
DataTable firstTable = MainImpl.GetDataTableResult(searchMainSql);
|
||
grdExMain.LastSearchSql = searchMainSql;
|
||
grdExMain.SetGridViewDataSource(firstTable);
|
||
|
||
if (tabMultipledetails.SplitMain.Panel2.Tag is GridControlEx)
|
||
{
|
||
GridControlEx grdExAdditional = (tabMultipledetails.SplitMain.Panel2.Tag as GridControlEx);
|
||
GridDetailModel AdditionalModel = grdExAdditional.Tag as GridDetailModel;
|
||
string searchAddSql = this.GetSearchSql(AdditionalModel, rowItem);
|
||
if (!MainModel.IsUnioDetail)
|
||
{
|
||
grdExAdditional.LastSearchSql = searchAddSql;
|
||
grdExAdditional.SetGridViewDataSource(MainImpl.GetDataTableResult(searchAddSql));
|
||
}
|
||
//右侧是左侧的明细,左侧没有数据时。右侧赋空值(因为无法触发左侧行改变事件)
|
||
if (MainModel.IsUnioDetail && firstTable.Rows.Count == 0)
|
||
{
|
||
grdExAdditional.LastSearchSql = "";
|
||
grdExAdditional.SetGridViewDataSource(new DataTable());
|
||
}
|
||
}
|
||
else if (tabMultipledetails.SplitMain.Panel2.Tag is ChartControlEx)
|
||
{
|
||
ChartControlEx grdExAdditional = (tabMultipledetails.SplitMain.Panel2.Tag as ChartControlEx);
|
||
GridDetailModel AdditionalModel = grdExAdditional.Tag as GridDetailModel;
|
||
string searchAddSql = this.GetSearchSql(AdditionalModel, rowItem);
|
||
DataTable table = MainImpl.GetDataTableResult(searchAddSql);
|
||
grdExAdditional.CreateChart(table);
|
||
}
|
||
|
||
tabPage.Text = MainModel.DetailName + "(" + firstTable.Rows.Count + QuantitySuffix;
|
||
//tabPage.Text = MainModel.DetailName + "(" + firstTable.Rows.Count + "条)";
|
||
//tabPage.Appearance.Header.ForeColor = firstTable.Rows.Count > 0 ? Color.Red : Color.FromArgb(0, 0, 0);
|
||
}
|
||
else
|
||
{
|
||
string searchSql = this.GetSearchSql(model, rowItem);
|
||
if (tabPage.Tag is GridControlEx)
|
||
{
|
||
(tabPage.Tag as GridControlEx).LastSearchSql = searchSql;
|
||
}
|
||
this.tb_buttom.SetGridDataSource(tabPage, MainImpl.GetDataTableResult(searchSql));
|
||
if (tabPage.Tag is GridControlEx && (tabPage.Tag as GridControlEx).ParentControl != null)
|
||
(tabPage.Tag as GridControlEx).ParentControl.SetAllControlValue(rowItem);
|
||
//配置明细直接根据条件加载
|
||
if (model.SystemModel != null && 1 == model.SystemModel.isFirstLoad)
|
||
{
|
||
(tabPage.Tag as GridControlEx).ParentControl.SearchGrid();
|
||
GridControlEx gridControlEx = tabPage.Tag as GridControlEx;
|
||
|
||
if (gridControlEx.CustomGroupBandEx != null)
|
||
{
|
||
tabPage.Text = model.DetailName + "(" + gridControlEx.CustomGroupBandEx.DataRowCount() + QuantitySuffix;
|
||
}
|
||
else if (gridControlEx.CustomGroupTreeBandEx != null)
|
||
{
|
||
tabPage.Text = model.DetailName + "(" + gridControlEx.CustomGroupTreeBandEx.DataRowCount() + QuantitySuffix;
|
||
}
|
||
else
|
||
{
|
||
tabPage.Text = model.DetailName + "(" + (tabPage.Tag as GridControlEx).ParentControl.GridRowCount + QuantitySuffix;
|
||
}
|
||
//tabPage.Text = gridControlEx.CustomGroupBandEx != null ? model.DetailName + "(" + gridControlEx.CustomGroupBandEx.DataRowCount() + "条)" : model.DetailName + "(" + (tabPage.Tag as GridControlEx).ParentControl.GridRowCount + "条)";
|
||
//tabPage.Text = model.DetailName + "(" + (tabPage.Tag as GridControlEx).ParentControl.GridRowCount + "条)";
|
||
}
|
||
//附加信息根据主表明细选中行,判断配置的按钮条件
|
||
Object moduleObject = tabPage.Controls.Cast<Object>().FirstOrDefault();
|
||
ModuleGridEx moduleGridEx = null;
|
||
if (moduleObject is ModuleGridEx)
|
||
{
|
||
moduleGridEx = moduleObject as ModuleGridEx;
|
||
moduleGridEx.ParentButtonState(rowItem);
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:获取查询条件</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-22 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="model">The model.</param>
|
||
/// <param name="rowItem">The row item.</param>
|
||
/// <returns>System.String.</returns>
|
||
protected string GetSearchSql(GridDetailModel model, DataRow rowItem)
|
||
{
|
||
string fieldName = !string.IsNullOrEmpty(model.UnionParentField) && rowItem.Table.Columns.Contains(model.UnionParentField) ? model.UnionParentField : BillModel.PrimaryKey;
|
||
string sqlValue = model.IsReadOnly || model.IsChart ? model.DetailSql : model.SystemModel.MenuSql;
|
||
string unioValue = string.Empty;
|
||
unioValue = rowItem.Table.Columns.Contains(fieldName) ? rowItem[fieldName] + "" : string.Empty;
|
||
if (this.ControlObj != null && string.IsNullOrEmpty(unioValue))
|
||
{
|
||
unioValue = !string.IsNullOrEmpty(model.UnionParentField) && this.ControlObj.FindControl(model.UnionParentField) != null ? this.ControlObj.GetControlValue(model.UnionParentField) : unioValue;
|
||
}
|
||
sqlValue = ReplaceHelper.ReplaceRowParam(rowItem, sqlValue);
|
||
sqlValue = this.ControlObj.ReplaceControlValue(sqlValue);//后替换主表内容
|
||
if (ReplaceHelper.IsSelect(sqlValue) && !string.IsNullOrEmpty(model.UnionValue))
|
||
{
|
||
sqlValue = ReplaceHelper.ReplaceWhereCond(sqlValue) + string.Format(" and {0}='{1}'", model.UnionValue, unioValue);
|
||
}
|
||
if (!string.IsNullOrEmpty(model.UnionCond))
|
||
{
|
||
string UnionCond = ReplaceHelper.ReplaceRowParam(rowItem, model.UnionCond);
|
||
sqlValue += UnionCond;
|
||
}
|
||
return sqlValue;
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:单据来源选中行,加载明细</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2019-07-25 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="DevExpress.XtraTreeList.FocusedNodeChangedEventArgs"/> instance containing the event data.</param>
|
||
private void OnTreeListObjFocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
|
||
{
|
||
XtraTabPage tabPage = this.xtc_left_container.SelectedTabPage;
|
||
|
||
this.RefreshSourceDetail(tabPage.Tag as BillSourceUnionModel);
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:单据来源明细右键菜单执行后刷新数据</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-12-19 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
private void OnGridDetailRightMenuCallback(object sender, EventArgs e)
|
||
{
|
||
XtraTabPage tabPage = this.xtc_left_container.SelectedTabPage;
|
||
|
||
this.RefreshSourceDetail(tabPage.Tag as BillSourceUnionModel);
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 底部明细右键后刷新
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
///</summary>
|
||
private void OnButtomRightCallBack(object sender, EventArgs e)
|
||
{
|
||
DataRow rowItem = this.gcMain.GridView.GetFocusedDataRow();
|
||
XtraTabPage page = this.tb_buttom.TabControlObj.SelectedTabPage;
|
||
if (rowItem != null && page != null)
|
||
{
|
||
this.SetTabPageDataSource(page, rowItem);
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:来源双击加载明细</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-30 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
private void OnGridDetailDoubleClick(object sender, EventArgs e)
|
||
{
|
||
|
||
DataTable table = this.gcMain.GridControl.DataSource as DataTable;
|
||
XtraTabPage tabPage = this.xtc_left_container.SelectedTabPage;
|
||
BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel;
|
||
DataRow rowItem = unionModel.GridDetailControlObj.GridView.GetFocusedDataRow();
|
||
if (rowItem == null) return;
|
||
if (BillModel.IsSelectSourceColor && unionModel.GridDetailControlObj != null)
|
||
{
|
||
//选中行改变颜色
|
||
ColorHandles.Add(unionModel.GridDetailControlObj.GridView.GetFocusedDataSourceRowIndex());
|
||
unionModel.GridDetailControlObj.GridView.Invalidate();
|
||
}
|
||
//添加行到主表明细中
|
||
if (this.BillModel.DetailTreeTable)
|
||
{
|
||
if (this.CanAddTreeDetailRow())
|
||
{
|
||
string Pid = "0";//默认给空值,添加到最后(不添加到选中行的下层)
|
||
//添加行
|
||
this.AddMultiRowTreeGridControl(new DataRow[] { rowItem }, Pid);
|
||
if (!string.IsNullOrWhiteSpace(unionModel.AddDataSql) && !string.IsNullOrWhiteSpace(unionModel.AddDataCondition) && this.ValidateCond(unionModel.AddDataCondition, rowItem))
|
||
{
|
||
string addSql = ReplaceHelper.ReplaceRowParam(rowItem, ReplaceHelper.ReplaceUserInfo(unionModel.AddDataSql));
|
||
DataTable dataTable = MainImpl.GetDataTableResult(addSql);
|
||
DragAddTable(dataTable, (int.Parse((this.gcMain as TreeGridControlEx).GetNewNodesId()) - 1) + "");////上方的新增行的id默认是最大的
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (this.CanAddDetailRow())
|
||
{
|
||
if (!this.BillModel.IsFastDragAddDetail)
|
||
{
|
||
this.AddMultiRowToGridView(new DataRow[] { rowItem });
|
||
}
|
||
else
|
||
{
|
||
this.AddRowsToGridViewFast(new DataRow[] { rowItem });
|
||
}
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:来源明细的明细双击加载明细</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-30 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
private void OnGridDetailDetailDoubleClick(object sender, EventArgs e)
|
||
{
|
||
if (this.CanAddDetailRow())
|
||
{
|
||
DataTable table = this.gcMain.GridControl.DataSource as DataTable;
|
||
XtraTabPage tabPage = this.xtc_left_container.SelectedTabPage;
|
||
BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel;
|
||
DataRow rowItem = unionModel.GridDetailDetailControlObj.GridView.GetFocusedDataRow();
|
||
this.AddMultiRowToGridView(new DataRow[] { rowItem });
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:单据明细点击加载tab数据</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-04-26 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="RowCellClickEventArgs"/> instance containing the event data.</param>
|
||
private void OnGridViewDoubleClick(object sender, EventArgs e)
|
||
{
|
||
for (int i = 1; i < this.tb_buttom.TabControlObj.TabPages.Count; i++)
|
||
{
|
||
XtraTabPage tabPage = this.tb_buttom.TabControlObj.TabPages[i];
|
||
DataRow rowItem = this.gcMain.GridView.GetFocusedDataRow();
|
||
if (this.BillModel.DetailTreeTable)
|
||
{
|
||
rowItem = (this.gcMain as TreeGridControlEx).GetViewFocusedDataRow();
|
||
}
|
||
|
||
GridDetailModel model = this.tb_buttom.GetGridDetailModel(tabPage);
|
||
|
||
if (rowItem != null && tabPage != null)
|
||
{
|
||
if (tabPage.Tag is TabMultipledetails)
|
||
{
|
||
TabMultipledetails tabMultipledetails = tabPage.Tag as TabMultipledetails;
|
||
GridControlEx grdExMain = (tabMultipledetails.SplitMain.Panel1.Tag as GridControlEx);
|
||
GridControlEx grdExAdditional = (tabMultipledetails.SplitMain.Panel2.Tag as GridControlEx);
|
||
GridDetailModel MainModel = grdExMain.Tag as GridDetailModel;
|
||
GridDetailModel AdditionalModel = grdExAdditional.Tag as GridDetailModel;
|
||
string searchMainSql = this.GetSearchSql(MainModel, rowItem);
|
||
string searchAddSql = this.GetSearchSql(AdditionalModel, rowItem);
|
||
DataTable firstTable = MainImpl.GetDataTableResult(searchMainSql);
|
||
grdExMain.LastSearchSql = searchMainSql;
|
||
grdExAdditional.LastSearchSql = searchAddSql;
|
||
grdExMain.SetGridViewDataSource(firstTable);
|
||
if (!MainModel.IsUnioDetail) grdExAdditional.SetGridViewDataSource(MainImpl.GetDataTableResult(searchAddSql));
|
||
|
||
}
|
||
else
|
||
{
|
||
string searchSql = ReplaceHelper.ReplaceRowParam(rowItem, model.DetailSql);
|
||
this.tb_buttom.SetGridDataSource(tabPage, MainImpl.GetDataTableResult(searchSql));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:单据空行新增时初始化默认值</para>
|
||
/// <para>创建人:dl</para>
|
||
/// <para>创建日期:2019-01-29 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
private void OnGridViewInitNewRow(object sender, InitNewRowEventArgs e)
|
||
{
|
||
GridView view = sender as DevExpress.XtraGrid.Views.Grid.GridView;
|
||
DataTable gridTable = (this.gcMain.GridControl.DataSource as DataTable).TrimDeleteRows();
|
||
DataRow tmpRow = view.GetDataRow(e.RowHandle);
|
||
GridColumnCollection gridColumns = view.Columns;
|
||
//gridTable.Rows.Add(tmpRow);
|
||
int position = gridTable.Rows.Count;
|
||
foreach (GridColumn col in gridColumns)
|
||
{
|
||
GridColumnModel model = col.Tag as GridColumnModel;
|
||
if (model == null)
|
||
{
|
||
continue;
|
||
}
|
||
string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue);
|
||
|
||
if (model.DefaultValue.Contains("{#"))
|
||
{
|
||
fieldValue = this.ControlObj.ReplaceParentControlValue(model.DefaultValue);
|
||
if (!string.IsNullOrEmpty(fieldValue))
|
||
{
|
||
tmpRow[col.FieldName] = fieldValue;
|
||
view.SetFocusedRowCellValue(col, fieldValue);
|
||
}
|
||
}
|
||
else if (!string.IsNullOrEmpty(model.DefaultValue))
|
||
{
|
||
|
||
tmpRow[col.FieldName] = fieldValue;
|
||
view.SetFocusedRowCellValue(col, fieldValue);
|
||
|
||
if (model.DefaultValue.Contains("{ROW"))
|
||
{
|
||
if (position > 0)
|
||
{
|
||
|
||
fieldValue = ReplaceHelper.GetParamFields(model.DefaultValue)[0];
|
||
fieldValue = fieldValue.Replace("}", "").Replace("{", "");
|
||
fieldValue = fieldValue.Substring(fieldValue.IndexOf('_') + 1);
|
||
string topFieldValue = gridTable.Rows[position - 1][fieldValue] + "";
|
||
if (gridTable.Columns[model.FieldName].DataType == typeof(DateTime))
|
||
{
|
||
if (!string.IsNullOrEmpty(topFieldValue))
|
||
{
|
||
tmpRow[model.FieldName] = Convert.ToDateTime(topFieldValue);
|
||
view.SetFocusedRowCellValue(col, topFieldValue);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
tmpRow[model.FieldName] = topFieldValue;
|
||
view.SetFocusedRowCellValue(col, topFieldValue);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
tmpRow[model.FieldName] = fieldValue;
|
||
view.SetFocusedRowCellValue(col, fieldValue);
|
||
}
|
||
|
||
}
|
||
}
|
||
//设置序号
|
||
gridTable.OrderBy(this.BillModel.DetailOrderField, false);
|
||
//设置当前行序号
|
||
if (gridTable != null && gridTable.Rows.Count > 0 && !string.IsNullOrEmpty(this.BillModel.DetailOrderField) && gridTable.Columns.Contains(this.BillModel.DetailOrderField))
|
||
{
|
||
bool getMaxIndex = int.TryParse(gridTable.Rows.Cast<DataRow>().Max(n => n[this.BillModel.DetailOrderField]) + "", out int maxIndex);
|
||
if (getMaxIndex)
|
||
{
|
||
tmpRow[this.BillModel.DetailOrderField] = maxIndex + 1;
|
||
}
|
||
}
|
||
if (gridTable.Columns.Contains(this.BillModel.DetailOrderField) && gridTable.Rows.Count == 0)
|
||
{
|
||
tmpRow[this.BillModel.DetailOrderField] = 1;
|
||
}
|
||
//this.gcMain.GridView.UpdateCurrentRow();
|
||
//this.gcMain.GridView.ShowEditor();
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:右键菜单执行后刷新数据,刷新规则按照上一次查询条件刷新</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-02 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
private void OnGridViewRightCallBack(object sender, EventArgs e)
|
||
{
|
||
string billNo = this.lblOrderNo.Text.Trim();
|
||
this.SetBillStatus(BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, billNo)));
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:重绘单据水印</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-12-04 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="PaintEventArgs"/> instance containing the event data.</param>
|
||
private void OnLabelTitlePaint(object sender, PaintEventArgs e)
|
||
{
|
||
if (this._waterMark != null)
|
||
{
|
||
GraphicsText graphicsText = new GraphicsText();
|
||
graphicsText.Graphics = e.Graphics;
|
||
|
||
// 绘制围绕点旋转的文本
|
||
StringFormat format = new StringFormat();
|
||
format.Alignment = StringAlignment.Center;
|
||
format.LineAlignment = StringAlignment.Center;
|
||
|
||
// 绘制单据状态文本
|
||
if (!string.IsNullOrEmpty(this._waterMark.Text))
|
||
{
|
||
|
||
|
||
if (Business.Impl.LanguageTranslation.Translatable)
|
||
{
|
||
graphicsText.DrawString(this._waterMark.Text, new Font("宋体", 12, FontStyle.Bold), new SolidBrush(Color.Red), new PointF(50, 21), format, 0f);
|
||
// 测量文本实际尺寸(含字体和格式影响)
|
||
SizeF textSize = e.Graphics.MeasureString(this._waterMark.Text, new Font("宋体", 12, FontStyle.Bold), new SizeF(float.MaxValue, float.MaxValue), format);
|
||
int rectWidth = (int)textSize.Width + 10;
|
||
int rectHeight = (int)textSize.Height + 5;
|
||
// 文本中心点是(50,21),计算边框左上角坐标(确保边框围绕文本居中)
|
||
int rectX = 50 - rectWidth / 2;
|
||
int rectY = 21 - rectHeight / 2;
|
||
|
||
e.Graphics.DrawRectangle(new Pen(Color.Red, 2f), new Rectangle(rectX, rectY, rectWidth, 21));
|
||
}
|
||
else
|
||
{
|
||
graphicsText.DrawString(this._waterMark.Text, new Font("宋体", 12, FontStyle.Bold), new SolidBrush(Color.Red), new PointF(50, 21), format, -15f);
|
||
|
||
e.Graphics.TranslateTransform(0, 0);
|
||
e.Graphics.RotateTransform(-15f);
|
||
e.Graphics.DrawRectangle(new Pen(Color.Red, 2f), new Rectangle(14, 20, 55, 21));
|
||
}
|
||
|
||
}
|
||
|
||
// 绘制打印次数文本
|
||
e.Graphics.ResetTransform();
|
||
if (!string.IsNullOrEmpty(this._waterMark.Print))
|
||
{
|
||
|
||
|
||
if (Business.Impl.LanguageTranslation.Translatable)
|
||
{
|
||
graphicsText.DrawString(this._waterMark.Print, new Font("宋体", 11, FontStyle.Bold), new SolidBrush(Color.Red), new PointF((this.lbTitle.Width - 70), 21), format, 0f);
|
||
// 测量文本实际尺寸(含字体和格式影响)
|
||
SizeF textSize = e.Graphics.MeasureString(this._waterMark.Print, new Font("宋体", 11, FontStyle.Bold), new SizeF(float.MaxValue, float.MaxValue), format);
|
||
int rectWidth = (int)textSize.Width + 10;
|
||
int rectHeight = (int)textSize.Height + 5;
|
||
// 文本中心点是(this.lbTitle.Width - 70,21),计算边框左上角坐标(确保边框围绕文本居中)
|
||
int rectX = (this.lbTitle.Width - 70) - rectWidth / 2;
|
||
int rectY = 21 - rectHeight / 2;
|
||
|
||
e.Graphics.DrawRectangle(new Pen(Color.Red, 2f), new Rectangle(rectX, rectY, rectWidth, 21));
|
||
}
|
||
else
|
||
{
|
||
graphicsText.DrawString(this._waterMark.Print, new Font("宋体", 11, FontStyle.Bold), new SolidBrush(Color.Red), new PointF((this.lbTitle.Width - 70), 21), format, -15f);
|
||
e.Graphics.TranslateTransform(this.lbTitle.Width - 70, 21);
|
||
e.Graphics.RotateTransform(-15f);
|
||
e.Graphics.DrawRectangle(new Pen(Color.Red, 2f), new Rectangle(-35, -14, 70, 21));
|
||
}
|
||
|
||
}
|
||
|
||
// 绘制收款文本
|
||
e.Graphics.ResetTransform();
|
||
if (!string.IsNullOrEmpty(this._waterMark.Collect))
|
||
{
|
||
|
||
|
||
if (Business.Impl.LanguageTranslation.Translatable)
|
||
{
|
||
graphicsText.DrawString(this._waterMark.Collect, new Font("宋体", 12, FontStyle.Bold), new SolidBrush(Color.Red), new PointF((this.lbTitle.Width - 170), 21), format, 0f);
|
||
// 测量文本实际尺寸(含字体和格式影响)
|
||
SizeF textSize = e.Graphics.MeasureString(this._waterMark.Collect, new Font("宋体", 12, FontStyle.Bold), new SizeF(float.MaxValue, float.MaxValue), format);
|
||
int rectWidth = (int)textSize.Width + 10;
|
||
int rectHeight = (int)textSize.Height + 5;
|
||
// 文本中心点是(this.lbTitle.Width - 170,21),计算边框左上角坐标(确保边框围绕文本居中)
|
||
int rectX = (this.lbTitle.Width - 170) - rectWidth / 2;
|
||
int rectY = 21 - rectHeight / 2;
|
||
|
||
e.Graphics.DrawRectangle(new Pen(Color.Red, 2f), new Rectangle(rectX, rectY, rectWidth, 21));
|
||
}
|
||
else
|
||
{
|
||
graphicsText.DrawString(this._waterMark.Collect, new Font("宋体", 12, FontStyle.Bold), new SolidBrush(Color.Red), new PointF((this.lbTitle.Width - 170), 21), format, -15f);
|
||
|
||
e.Graphics.TranslateTransform(this.lbTitle.Width - 100, 21);
|
||
e.Graphics.RotateTransform(-15f);
|
||
e.Graphics.DrawRectangle(new Pen(Color.Red, 2f), new Rectangle(-100, -32, 55, 21));
|
||
}
|
||
|
||
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:单据来源拖动数据到单据明细表格后</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-12-05 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The e.</param>
|
||
private void OnDragDetailGridCompleted(object sender, GridDragGridArgs e)
|
||
{
|
||
if (this.CanAddDetailRow())
|
||
{
|
||
List<DataRow> dragRows = new List<DataRow>();
|
||
int[] rowHandles = e.SourceGridViewObj.GetSelectedRows();
|
||
foreach (int handle in rowHandles)
|
||
{
|
||
DataRow row = e.SourceGridViewObj.GetDataRow(handle);
|
||
dragRows.Add(row);
|
||
}
|
||
if (BillModel.IsSelectSourceColor)
|
||
{
|
||
//选中行改变颜色
|
||
foreach (int h in rowHandles)
|
||
{
|
||
ColorHandles.Add(h);
|
||
}
|
||
e.SourceGridViewObj.Invalidate();
|
||
}
|
||
|
||
if (dragRows != null && dragRows.Count > 0)
|
||
{
|
||
if (!this.BillModel.IsFastDragAddDetail)
|
||
{
|
||
this.AddMultiRowToGridView(dragRows.ToArray());
|
||
}
|
||
else
|
||
{
|
||
this.AddRowsToGridViewFast(dragRows.ToArray());
|
||
}
|
||
//拖拽后清除所有复选框
|
||
if (e.SourceGridViewObj != null && e.SourceGridViewObj.OptionsSelection.MultiSelectMode == GridMultiSelectMode.CheckBoxRowSelect)
|
||
{
|
||
e.SourceGridViewObj.ClearSelection();
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 来源明细为树表格推拽到主表明细表格后
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void OnTreeGridDetailGridCompleted(object sender, TreeGridDragGridArgs e)
|
||
{
|
||
DataRow[] dragRows = e.GridViewSelectRows;
|
||
if (dragRows != null && dragRows.Length > 0)
|
||
{
|
||
if (!this.BillModel.IsFastDragAddDetail)
|
||
{
|
||
this.AddMultiRowToGridView(dragRows);
|
||
}
|
||
else
|
||
{
|
||
this.AddRowsToGridViewFast(dragRows);
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:单据来源表格拖拽完成</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-03-21 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The e.</param>
|
||
private void OnDragMainGridCompleted(object sender, GridDragGridArgs e)
|
||
{
|
||
if (e.GridViewSelectRows == null || e.GridViewSelectRows.Length == 0) return;
|
||
|
||
try
|
||
{
|
||
bool isAgain = true;
|
||
if (this.BillModel.isWorkLogin)
|
||
{
|
||
if (!this.BillModel.SaveState && this.gcMain.DataRowCount() > 0)
|
||
{
|
||
DialogResult result = MessageUtil.Show(("数据未保存,是否确定新建单据?"), MessageBoxButtons.YesNo);
|
||
if (result == DialogResult.Yes)
|
||
{
|
||
this.SetBillStatus(null);
|
||
this.ControlObj.ResetControlValue(this.BillModel.ManuallyTriggerCorrelation, true);
|
||
}
|
||
else
|
||
{
|
||
isAgain = false;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
this.SetBillStatus(null);
|
||
this.ControlObj.ResetControlValue(this.BillModel.ManuallyTriggerCorrelation, true);
|
||
}
|
||
}
|
||
if (this.CanAddDetailRow() && isAgain)
|
||
{
|
||
if (this.BillModel.DisableDragPrompt || MessageUtil.Show(ResourceKeys.DragSelectRow, MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||
{
|
||
XtraTabPage tabPage = this.xtc_left_container.SelectedTabPage;
|
||
BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel;
|
||
int FocuseIndex = e.SourceGridViewObj.FocusedRowHandle;
|
||
int[] rows = e.SourceGridViewObj.GetSelectedRows();
|
||
List<DataRow> DragRows = new List<DataRow>();
|
||
int i = 0;
|
||
foreach (int rowIndex in rows)
|
||
{
|
||
// 拖动多行,所以明细数据改为动态查询
|
||
DataRow rowItem = e.SourceGridViewObj.GetDataRow(rowIndex);
|
||
this.RefreshSourceDetail(tabPage.Tag as BillSourceUnionModel);
|
||
DataTable details = BillImpl.GetDataTableResult(ReplaceHelper.ReplaceRowParam(rowItem, unionModel.ModelObj.DetailSql));
|
||
if (unionModel.ModelObj.sourceDetailType != "1" && unionModel.GridDetailControlObj.GridView != null && rowIndex == FocuseIndex)
|
||
{
|
||
if (SystemInfo.Instance.SourceFilteringMobile)
|
||
{
|
||
details = unionModel.GridDetailControlObj.GridView.GetGridViewFilteredAndSortedDataToDataTable();
|
||
}
|
||
else
|
||
{
|
||
details = unionModel.GridDetailControlObj.GridControl.DataSource as DataTable;
|
||
}
|
||
}
|
||
else if (unionModel.ModelObj.sourceDetailType == "1" && unionModel.TreeGridDetailControlObj.TreeListObj != null && rowIndex == FocuseIndex)
|
||
{
|
||
details = unionModel.TreeGridDetailControlObj.TreeListObj.DataSource as DataTable;
|
||
}
|
||
//details = GetGridViewFilteredAndSortedDataToDataTable(unionModel.GridDetailControlObj.GridView);
|
||
//DataTable details = unionModel.GridDetailControlObj.GridView.DataController.GetAllFilteredAndSortedRows().OfType<DataRow>().CopyToDataTable();
|
||
this.ControlObj.SetAllControlValue(rowItem, this.BillModel.isReplaceFixed);
|
||
|
||
if (this.BillModel.SourceMainPushPullHide)
|
||
{
|
||
DragRows.Add(rowItem);
|
||
}
|
||
|
||
|
||
|
||
if (unionModel.ModelObj.CadDragDetail)
|
||
{
|
||
this.AddMultiRowToGridView(details, unionModel);
|
||
|
||
if (BillModel.drgFinishHide == "1" && unionModel.GridDetailControlObj != null)
|
||
{
|
||
var detailRows = details.AsEnumerable().ToList();
|
||
foreach (var detailRow in detailRows)
|
||
{
|
||
if (unionModel.GridDetailControlObj.GridControl.DataSourceTable().Rows.IndexOf(detailRow) >= 0)
|
||
{
|
||
unionModel.GridDetailControlObj.GridControl.DataSourceTable().Rows.Remove(detailRow);
|
||
}
|
||
if (unionModel.GridDetailDetailControlObj != null && unionModel.GridDetailDetailControlObj.GridControl.DataSourceTable().Rows.IndexOf(detailRow) >= 0)
|
||
{
|
||
unionModel.GridDetailDetailControlObj.GridControl.DataSourceTable().Rows.Remove(detailRow);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
//单据为新增状态,根据最后一行的内容设置红蓝单据
|
||
if (!this.BillModel.SaveState && rows.Length - 1 == i && rowItem.Table.Columns.Contains(this.BillModel.RtagidKey) && this.BillModel.BillFlag != 0 && this.BillModel.BillFlag != 1)
|
||
{
|
||
if ("0".Equals(rowItem[this.BillModel.RtagidKey] + ""))
|
||
{
|
||
this.rdBlue.Checked = true;
|
||
this.OnBlueStateClick(null, null);
|
||
}
|
||
if ("1".Equals(rowItem[this.BillModel.RtagidKey] + ""))
|
||
{
|
||
this.rdRed.Checked = true;
|
||
this.OnRedStateClick(null, null);
|
||
}
|
||
}
|
||
i++;
|
||
}
|
||
if (unionModel.ModelObj.DragAndSave && rows.Length == i && i != 0)
|
||
{
|
||
this.OnBillSaveClick(null, null);
|
||
}
|
||
|
||
if (this.BillModel.SourceMainPushPullHide && DragRows.Count > 0)
|
||
{
|
||
foreach (DataRow item in DragRows)
|
||
{
|
||
if (e.SourceGridViewObj.GridControl.DataSourceTable().Rows.IndexOf(item) >= 0)
|
||
{
|
||
e.SourceGridViewObj.GridControl.DataSourceTable().Rows.Remove(item);
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Instance.WriteError(ex);
|
||
LogUtil.WriteError("单据来源表格拖拽完出错!", ex);
|
||
MessageUtil.Show(ResourceKeys.OperFault);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:新增单据</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-12-14 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
private void OnBillAddClick(object sender, EventArgs e)
|
||
{
|
||
if (!this.BillModel.SaveState && this.gcMain.DataRowCount() > 0)
|
||
{
|
||
DialogResult result = MessageUtil.Show(("数据未保存,是否确定新建单据?"), MessageBoxButtons.YesNo);
|
||
if (result == DialogResult.Yes)
|
||
{
|
||
this.SetBillStatus(null);
|
||
this.ControlObj.ResetControlValue(this.BillModel.ManuallyTriggerCorrelation, true);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
this.SetBillStatus(null);
|
||
this.ControlObj.ResetControlValue(this.BillModel.ManuallyTriggerCorrelation, true);
|
||
}
|
||
if (ScanCodeTextEdit != null) ScanCodeTextEdit.Focus();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 关闭时判断是否存在为保存新增单据
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public bool closeTheJudgment()
|
||
{
|
||
//if(this.ControlObj.VerifyUpdated())
|
||
if (!this.BillModel.SaveState && this.gcMain.DataRowCount() > 0)
|
||
{
|
||
return true;
|
||
}
|
||
return false;
|
||
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:删除明细记录</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-12-05 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
private void OnDeleteClick(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
//树表格删除
|
||
if (this.BillModel.DetailTreeTable)
|
||
{
|
||
string deleteCond = this.ControlObj.ReplaceParentControlValue(BillModel.DeleteDetailCond);
|
||
(this.gcMain as TreeGridControlEx).DeleteSelectedRows(deleteCond);
|
||
return;
|
||
}
|
||
|
||
|
||
|
||
int[] rows = this.gcMain.GridView.GetSelectedRows();
|
||
if (rows.Length < 1)
|
||
return;
|
||
|
||
DataTable dt = this.gcMain.GridView.GetGridViewFilteredAndSortedDataToDataTable();
|
||
|
||
|
||
if (string.IsNullOrEmpty(BillModel.DeleteDetailCond))
|
||
{
|
||
DialogResult result = MessageUtil.Show(string.Format(ResourceKeys.DeleteRows, rows.Length), MessageBoxButtons.YesNo);
|
||
if (result == DialogResult.Yes)
|
||
{
|
||
//保存删除的行和对应的行号
|
||
//撤销多次
|
||
Dictionary<int, DataRow> undo = new Dictionary<int, DataRow>();
|
||
for (int i = 0; i < rows.Length; i++)
|
||
{
|
||
DataRow rowItem = this.gcMain.GridView.GetDataRow(rows[i]);
|
||
DataRow dr = dt.NewRow();
|
||
dr.ItemArray = rowItem.ItemArray;
|
||
undo.Add(rows[i], dr);
|
||
}
|
||
ToWithdrawRows.Add(undo);
|
||
this.gcMain.GridView.Columns.ClearAllSort();
|
||
this.gcMain.GridView.DeleteSelectedRows();
|
||
this.gcMain.GridView.ClearSelection();
|
||
this.gcMain.GridView.SelectRow(this.gcMain.GridView.FocusedRowHandle);
|
||
this.gcMain.GridControl.DataSourceTable().OrderBy(this.BillModel.DetailOrderField);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
string successMsg = string.Empty, faultMsg = string.Empty;
|
||
string deleteCond = this.ControlObj.ReplaceParentControlValue(BillModel.DeleteDetailCond);
|
||
List<DataRow> deleteRows = new List<DataRow>();
|
||
List<int> faultInts = new List<int>();
|
||
//ToWithdrawRows.Clear();//清空上一次记录的删除行
|
||
Dictionary<int, DataRow> undo = new Dictionary<int, DataRow>();
|
||
|
||
foreach (int rowIndex in rows)
|
||
{
|
||
DataRow rowItem = this.gcMain.GridView.GetDataRow(rowIndex);
|
||
|
||
string deleteCond2 = ReplaceHelper.ReplaceRowParam(rowItem, deleteCond);
|
||
|
||
if (ReplaceHelper.EvalCond(deleteCond2))
|
||
{
|
||
deleteRows.Add(rowItem);
|
||
DataRow dr = dt.NewRow();
|
||
dr.ItemArray = rowItem.ItemArray;
|
||
undo.Add(rowIndex, dr);
|
||
|
||
}
|
||
else
|
||
{
|
||
faultInts.Add(rowIndex);
|
||
}
|
||
}
|
||
ToWithdrawRows.Add(undo);
|
||
DataTable table = this.gcMain.GridControl.DataSourceTable();
|
||
foreach (DataRow item in deleteRows)
|
||
{
|
||
table.Rows.Remove(item);
|
||
}
|
||
|
||
if (faultInts != null && faultInts.Count > 0)
|
||
{
|
||
MessageUtil.Show("发现如下:" + string.Join(",", faultInts.ToArray()) + "行不满足条件无法删除!");
|
||
}
|
||
else
|
||
{
|
||
MessageUtil.Show("删除成功!");
|
||
}
|
||
}
|
||
if (ScanCodeTextEdit != null) ScanCodeTextEdit.Focus();
|
||
return;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Instance.WriteError(ex);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:单据保存</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-12-07 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
private void OnBillSaveClick(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (this.BillSave())
|
||
{
|
||
ToWithdrawRows.Clear();
|
||
this.RefreshSelectedSource();
|
||
}
|
||
if (ScanCodeTextEdit != null) ScanCodeTextEdit.Focus();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageUtil.Show(ex);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:单据保存提交</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-12-07 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
private void OnBillApplyClick(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
DialogResult result = MessageUtil.Show(ResourceKeys.BillApply, MessageBoxButtons.YesNo);
|
||
if (result == DialogResult.Yes)
|
||
{
|
||
if (this.BillSave(0, false))
|
||
{
|
||
ToWithdrawRows.Clear();
|
||
this.BillApply("");
|
||
}
|
||
}
|
||
if (ScanCodeTextEdit != null) ScanCodeTextEdit.Focus();
|
||
return;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageUtil.Show(ex);
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:分割条移动保存位置</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-03-06 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
private void OnTopSplitterMoved(object sender, EventArgs e)
|
||
{
|
||
if (this._isInitFinish)// 是否为初始化创建
|
||
{
|
||
IniHelper.Write(string.Format("bill_width_{0}", this.SysModel.ModuleCode), this.ssc_main_top.SplitterPosition + "");
|
||
}
|
||
this.gcMain.gridControl.Refresh();
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:分割条移动保存位置</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-03-06 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
private void OnMainSplitterMoved(object sender, EventArgs e)
|
||
{
|
||
if (this._isInitFinish)
|
||
{
|
||
IniHelper.Write(string.Format("bill_height_{0}", this.SysModel.ModuleCode), this.ssc_main.SplitterPosition + "");
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:明细分割条移动保存位置</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-03-06 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
private void OnDetailsSplitterMoved(object sender, EventArgs e)
|
||
{
|
||
if (this._isInitFinish)
|
||
{
|
||
SplitContainerControl splitContainerControl = sender as SplitContainerControl;
|
||
IniHelper.Write(string.Format("bill_Details_Width_{0}", this.SysModel.ModuleCode), splitContainerControl.SplitterPosition + "");
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:单据来源查询之前处理</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-03-06 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The e.</param>
|
||
private void OnSearchBefore(object sender, SearchArgs e)
|
||
{
|
||
|
||
// 用户搜索时不加载右侧控件值,只有点击、人为选中行在加载右侧控件值.
|
||
this._isLoadRightControlValue = false;
|
||
XtraTabPage tabPage = this.xtc_left_container.SelectedTabPage;
|
||
BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel;
|
||
if (!unionModel.SearchObj.VerifyNull())
|
||
{
|
||
e.Continue = false;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:单据来源查询完成</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-03-06 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
/// <exception cref="System.NotImplementedException"></exception>
|
||
private void OnSearchAfterd(object sender, EventArgs e)
|
||
{
|
||
this._isLoadRightControlValue = true;
|
||
|
||
XtraTabPage tabPage = this.xtc_left_container.SelectedTabPage;
|
||
BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel;
|
||
if (unionModel.ModelObj.SourceType == 1)
|
||
{
|
||
if (unionModel.TreeViewObj != null && unionModel.SearchObj.MainGridEx != null)
|
||
{
|
||
string sql = ReplaceHelper.ReplaceUserInfo(unionModel.SearchObj.MainGridEx.LastSearchSql);
|
||
sql = this.ControlObj.ReplaceControlValue(sql);
|
||
|
||
//和上一次查询sql相同就不再次查询了
|
||
if (!unionModel.SearchObj.MainGridEx.LastSearchSql.Equals(sql))
|
||
{
|
||
unionModel.SearchObj.MainGridEx.SetGridViewDataSource(BaseImpl.GetDataTableResult(sql));
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (unionModel.GridControlObj != null)
|
||
{
|
||
|
||
string sql = ReplaceHelper.ReplaceUserInfo(unionModel.GridControlObj.LastSearchSql);
|
||
|
||
if (SubstringCount(sql, "#") > 1)
|
||
{
|
||
string fixedSql = sql.Substring(sql.IndexOf('#'), sql.LastIndexOf('#') + 1 - sql.IndexOf('#'));
|
||
string billMainCode = sql.Substring(sql.IndexOf('#'), sql.LastIndexOf('#') + 1 - sql.IndexOf('#')).Replace("#", "");
|
||
var paramList = ReplaceHelper.GetParamFields(billMainCode);
|
||
bool isCondReplace = true;
|
||
foreach (string item in paramList)
|
||
{
|
||
string field = item.Replace("{", "").Replace("}", "");
|
||
if (ControlObj.FindControl(field) != null)
|
||
{
|
||
string value = ControlObj.GetControlValue(field);
|
||
if (string.IsNullOrEmpty(value)) isCondReplace = false;
|
||
billMainCode = billMainCode.Replace(item, value);
|
||
}
|
||
}
|
||
if (!isCondReplace)
|
||
{
|
||
sql = sql.Replace(fixedSql, "1=1");
|
||
}
|
||
else
|
||
{
|
||
sql = sql.Replace(fixedSql, billMainCode);
|
||
|
||
}
|
||
}
|
||
int oldRowHandle = 0;
|
||
if (unionModel.GridControlObj.GridView != null)
|
||
{
|
||
oldRowHandle = unionModel.GridControlObj.GridView.FocusedRowHandle;
|
||
}
|
||
|
||
|
||
//替换主表中的参数
|
||
sql = this.ControlObj.ReplaceControlValue(sql);
|
||
//和上一次查询sql相同就不再次查询了
|
||
if (!unionModel.GridControlObj.LastSearchSql.Equals(sql))
|
||
{
|
||
unionModel.GridControlObj.gridControl.DataSource = BaseImpl.GetDataTableResult(sql);
|
||
unionModel.GridControlObj.GridView.SelectRowHandler(oldRowHandle);
|
||
}
|
||
|
||
//如果没有数据,显示 (0条)
|
||
//(unionModel.ModelObj.SourceType == 0 || this.IsBillShowCount) && unionModel.SearchObj.GridRowCount > 0
|
||
if (unionModel.ModelObj.SourceType == 0 || this.IsBillShowCount) tabPage.Text = unionModel.ModelObj.UserName + "(" + unionModel.SearchObj.GridRowCount + QuantitySuffix;
|
||
|
||
RefreshSourceDetail(unionModel);
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:判断字符串出现次数</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期: </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="str">The string.</param>
|
||
/// <param name="substring">The substring.</param>
|
||
/// <returns>System.Int32.</returns>
|
||
private static int SubstringCount(string str, string substring)
|
||
{
|
||
if (str.Contains(substring))
|
||
{
|
||
string strReplaced = str.Replace(substring, "");
|
||
return (str.Length - strReplaced.Length) / substring.Length;
|
||
}
|
||
|
||
return 0;
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:帮助文档</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2020-01-15 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
private void OnHelpClick(object sender, EventArgs e)
|
||
{
|
||
WebBrowserUtil.StartWebBrowser(this.SysModel.ModuleCode, this.BillModel.TypeName);
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:分配明细</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2020-01-15 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
private void OnBtnFPOldClick(object sender, EventArgs e)
|
||
{
|
||
this.gcMain.GridView.PostEditor();
|
||
FPOld();
|
||
}
|
||
private void OnBtnFPNewClick(object sender, EventArgs e)
|
||
{
|
||
this.gcMain.GridView.PostEditor();
|
||
FPNew();
|
||
}
|
||
/// <summary>
|
||
/// 新版分配
|
||
/// </summary>
|
||
private void FPNew(int rowHandle = 0)
|
||
{
|
||
try
|
||
{
|
||
this.gcMain.GridView.FocusedRowHandle = rowHandle;
|
||
DataTable table = this.gcMain.GridControl.DataSource as DataTable;
|
||
if (!table.Columns.Contains(guidField))
|
||
{
|
||
table.Columns.Add(guidField, typeof(string));
|
||
}
|
||
#region 创建分配界面
|
||
string[] args = { this.SysModel.FormText, this.SysModel.UserId, this.SysModel.UserName, this.SysModel.Privilege, this.SysModel.ModuleCode, this.SysModel.ModuleId + "", this.BillModel.PopupUnionCode, "1000" };
|
||
DynamicBaseSelectModel baseModel = new DynamicBaseSelectModel(args);
|
||
using (FrmBaseSelectBatch frmSelect = new FrmBaseSelectBatch(baseModel, this.ControlObj, this.gcMain))
|
||
{
|
||
frmSelect.Text = this.BillModel.TypeName;
|
||
frmSelect.InitControl();
|
||
frmSelect.OnAfterFPCallback += OnAfterFPCallback;
|
||
#region 初始化第一条数据
|
||
DataRow rowItem = this.gcMain.GridView.GetFocusedDataRow();
|
||
if (rowItem == null)
|
||
{
|
||
return;
|
||
}
|
||
rowItem[guidField] = Guid.NewGuid().ToString();
|
||
if (!string.IsNullOrEmpty(mRecordPrimaryField) && table.Columns.Contains(this.mRecordPrimaryField))
|
||
{
|
||
// 检查数据是否为分配后的行
|
||
if (!string.IsNullOrEmpty(rowItem[this.mRecordPrimaryField] + ""))
|
||
{
|
||
if (this.gcMain.GridView.FocusedRowHandle + 1 <= this.gcMain.GridView.RowCount - 1)
|
||
{
|
||
int focusedRowHandle = this.gcMain.GridView.FocusedRowHandle + 1;
|
||
this.gcMain.GridView.FocusedRowHandle = focusedRowHandle;
|
||
if (this.gcMain.GridView.FocusedRowHandle == focusedRowHandle)
|
||
{
|
||
FPNew(focusedRowHandle);
|
||
}
|
||
else
|
||
{
|
||
MessageUtil.Show("全部分配完毕");
|
||
}
|
||
}
|
||
return;
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(mRecordPrimaryField))
|
||
{
|
||
frmSelect.FpRows = table.Rows.Cast<DataRow>().Where(x => (rowItem[guidField] + "").Equals(x[guidField] + "")).ToArray();
|
||
if (frmSelect.FpRows != null && frmSelect.FpRows.Length > 0)
|
||
{
|
||
List<DataRow> rows = frmSelect.FpRows.ToList();
|
||
rows.Remove(rowItem);
|
||
frmSelect.FpRows = rows.ToArray();
|
||
}
|
||
if (table.Columns.Contains(mRecordPrimaryField))
|
||
{
|
||
frmSelect.FpOtherRows = table.Rows.Cast<DataRow>().Where(x => !(rowItem[guidField] + "").Equals(x[guidField] + "") && !string.IsNullOrEmpty(x[mRecordPrimaryField] + "")).ToArray();
|
||
}
|
||
}
|
||
frmSelect.InitData(rowItem);
|
||
frmSelect.OnBtnFPClick(null, null);
|
||
#endregion
|
||
//frmSelect.ShowDialog();
|
||
#endregion
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageUtil.Show(ex.Message);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 分配完成后回调
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void OnAfterFPCallback(object sender, EventArgs e)
|
||
{
|
||
WaitForm.ShowForm();
|
||
try
|
||
{
|
||
// 临时禁用新增行(空白行)
|
||
if (this.BillModel.DefaultAddEmptyRow) this.gcMain.GridView.OptionsView.NewItemRowPosition = NewItemRowPosition.None;
|
||
DataRow rowItem = this.gcMain.GridView.GetFocusedDataRow();
|
||
if (rowItem == null)
|
||
{
|
||
return;
|
||
}
|
||
DataTable table = this.gcMain.GridControl.DataSource as DataTable;
|
||
FrmBaseSelectBatch frmSelect = (FrmBaseSelectBatch)sender;
|
||
rowItem[guidField] = Guid.NewGuid().ToString();
|
||
if (!string.IsNullOrEmpty(mRecordPrimaryField) && table.Columns.Contains(this.mRecordPrimaryField))
|
||
{
|
||
// 检查数据是否为分配后的行
|
||
if (!string.IsNullOrEmpty(rowItem[this.mRecordPrimaryField] + ""))
|
||
{
|
||
if (this.gcMain.GridView.FocusedRowHandle + 1 <= this.gcMain.GridView.RowCount - 1)
|
||
{
|
||
this.gcMain.GridView.FocusedRowHandle += 1;
|
||
OnAfterFPCallback(sender, e);
|
||
}
|
||
return;
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(mRecordPrimaryField))
|
||
{
|
||
frmSelect.FpRows = table.Rows.Cast<DataRow>().Where(x => (rowItem[guidField] + "").Equals(x[guidField] + "")).ToArray();
|
||
if (frmSelect.FpRows != null && frmSelect.FpRows.Length > 0)
|
||
{
|
||
List<DataRow> rows = frmSelect.FpRows.ToList();
|
||
rows.Remove(rowItem);
|
||
frmSelect.FpRows = rows.ToArray();
|
||
}
|
||
if (table.Columns.Contains(mRecordPrimaryField))
|
||
{
|
||
frmSelect.FpOtherRows = table.Rows.Cast<DataRow>().Where(x => !(rowItem[guidField] + "").Equals(x[guidField] + "") && !string.IsNullOrEmpty(x[mRecordPrimaryField] + "")).ToArray();
|
||
}
|
||
}
|
||
frmSelect.InitData(rowItem);
|
||
bool success = frmSelect.FP();
|
||
if (success)
|
||
{
|
||
if (frmSelect.SelectedRows != null && frmSelect.SelectedRows.Length > 0)
|
||
{
|
||
// 增加标识列
|
||
if (!table.Columns.Contains(frmSelect.RecordPrimaryField))
|
||
{
|
||
this.mRecordPrimaryField = frmSelect.RecordPrimaryField;
|
||
table.Columns.Add(this.mRecordPrimaryField, typeof(String));
|
||
}
|
||
foreach (DataRow item in frmSelect.SelectedRows)
|
||
{
|
||
DataRow newRow = table.NewRow();
|
||
newRow.ItemArray = rowItem.ItemArray;
|
||
newRow[guidField] = rowItem[guidField];
|
||
DataColumn IsIdentCol = newRow.Table.Columns.Cast<DataColumn>().FirstOrDefault(x => x.ColumnName == BaseImpl.GetResult(string.Format("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.columns WHERE TABLE_NAME='{0}' AND COLUMNPROPERTY(OBJECT_ID('{0}'),COLUMN_NAME,'IsIdentity')=1", BillModel.DetailTable)) + "");
|
||
//自增长列分配按空值取
|
||
if (IsIdentCol != null)
|
||
{
|
||
if (IsIdentCol.DataType == typeof(Decimal) ||
|
||
IsIdentCol.DataType == typeof(Double) ||
|
||
IsIdentCol.DataType == typeof(Int16) ||
|
||
IsIdentCol.DataType == typeof(Int32) ||
|
||
IsIdentCol.DataType == typeof(Int64))
|
||
{
|
||
newRow[IsIdentCol.ColumnName] = 0;
|
||
}
|
||
}
|
||
foreach (DataColumn col in item.Table.Columns)
|
||
{
|
||
if (table.Columns.Contains(col.ColumnName))
|
||
{
|
||
//newRow[col.ColumnName] = item[col.ColumnName];
|
||
newRow[col.ColumnName] = item[col.ColumnName];
|
||
GridColumn column = this.gcMain.GridView.Columns[col.ColumnName];
|
||
if (column != null)
|
||
{
|
||
GridColumnModel model = column.Tag as GridColumnModel;
|
||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||
{
|
||
this.SetUnionValue(model, rowItem[column.FieldName] + "", newRow);
|
||
}
|
||
SetCalcValue(model, rowItem[column.FieldName] + "", newRow);
|
||
}
|
||
}
|
||
}
|
||
newRow[frmSelect.AmountField] = item[frmSelect.AmountField];
|
||
newRow[frmSelect.RecordPrimaryField] = item[frmSelect.RecordPrimaryField];
|
||
table.Rows.Add(newRow);
|
||
}
|
||
NumberMc = frmSelect.AmountField;
|
||
table.Rows.Remove(rowItem);
|
||
// 重排顺序
|
||
table.OrderBy(this.BillModel.DetailOrderField);
|
||
this.gcMain.GridView.UpdateCurrentRow();
|
||
this.gcMain.GridView.ShowEditor();
|
||
if (frmSelect.isNextOne)
|
||
{
|
||
int SourceRowIndex = this.gcMain.GridView.GetFocusedDataSourceRowIndex();
|
||
DataRow[] a = table.Rows.Cast<DataRow>().Where(x => string.IsNullOrEmpty(x[guidField].ToString())).ToArray();
|
||
if (a.Length != 0)
|
||
{
|
||
this.gcMain.GridView.FocusedRowHandle = SourceRowIndex;
|
||
OnAfterFPCallback(sender, e);
|
||
}
|
||
else
|
||
{
|
||
MessageUtil.Show("全部分配完毕");
|
||
// frmSelect.SelectRowItem = null;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (this.gcMain.GridView.FocusedRowHandle + 1 <= this.gcMain.GridView.RowCount - 1)
|
||
{
|
||
this.gcMain.GridView.FocusedRowHandle += 1;
|
||
OnAfterFPCallback(sender, e);
|
||
}
|
||
else
|
||
{
|
||
MessageUtil.Show("全部分配完毕");
|
||
}
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
throw;
|
||
}
|
||
finally
|
||
{
|
||
// 重新开启新增行(空白行)
|
||
if (this.BillModel.DefaultAddEmptyRow) this.gcMain.GridView.OptionsView.NewItemRowPosition = NewItemRowPosition.Bottom;
|
||
WaitForm.HideForm();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 老版分配
|
||
/// </summary>
|
||
private void FPOld()
|
||
{
|
||
try
|
||
{
|
||
DataRow rowItem = this.gcMain.GridView.GetFocusedDataRow();
|
||
if (rowItem == null)
|
||
{
|
||
MessageUtil.Show("请先选择一条明细在进行分配!");
|
||
return;
|
||
}
|
||
DataTable table = this.gcMain.GridControl.DataSource as DataTable;
|
||
if (!table.Columns.Contains(guidField))
|
||
{
|
||
table.Columns.Add(guidField, typeof(string));
|
||
}
|
||
rowItem[guidField] = Guid.NewGuid().ToString(); ;
|
||
if (!string.IsNullOrEmpty(mRecordPrimaryField) && table.Columns.Contains(this.mRecordPrimaryField))
|
||
{
|
||
// 检查数据是否为分配后的行
|
||
if (!string.IsNullOrEmpty(rowItem[this.mRecordPrimaryField] + "") && !this.BillModel.IgnoreAllocated)
|
||
{
|
||
MessageUtil.Show("该行数据为已分配后的数据,无需分配!");
|
||
return;
|
||
}
|
||
}
|
||
string[] args = { this.SysModel.FormText, this.SysModel.UserId, this.SysModel.UserName, this.SysModel.Privilege, this.SysModel.ModuleCode, this.SysModel.ModuleId + "", this.BillModel.PopupUnionCode, "1000" };
|
||
DynamicBaseSelectModel baseModel = new DynamicBaseSelectModel(args);
|
||
using (FrmBaseSelect frmSelect = new FrmBaseSelect(baseModel, this.ControlObj, this.gcMain))
|
||
{
|
||
//if (frmSelect.SelectRowItem == null)
|
||
//{
|
||
// frmSelect = new FrmBaseSelect(baseModel, this.ControlObj, this.gcMain);
|
||
//}
|
||
frmSelect.Text = this.BillModel.TypeName;
|
||
frmSelect.SelectRowItem = rowItem;
|
||
bool isNextOne = false;
|
||
if (!string.IsNullOrEmpty(mRecordPrimaryField))
|
||
{
|
||
frmSelect.FpRows = table.Rows.Cast<DataRow>().Where(x => (rowItem[guidField] + "").Equals(x[guidField] + "")).ToArray();
|
||
if (frmSelect.FpRows != null && frmSelect.FpRows.Length > 0)
|
||
{
|
||
List<DataRow> rows = frmSelect.FpRows.ToList();
|
||
rows.Remove(rowItem);
|
||
frmSelect.FpRows = rows.ToArray();
|
||
}
|
||
if (table.Columns.Contains(mRecordPrimaryField))
|
||
{
|
||
frmSelect.FpOtherRows = table.Rows.Cast<DataRow>().Where(x => !(rowItem[guidField] + "").Equals(x[guidField] + "") && !string.IsNullOrEmpty(x[mRecordPrimaryField] + "")).ToArray();
|
||
}
|
||
}
|
||
if (frmSelect.ShowDialog() == DialogResult.OK)
|
||
{
|
||
if (frmSelect.SelectedRows != null && frmSelect.SelectedRows.Length > 0)
|
||
{
|
||
//if (frmSelect.isNextOne)
|
||
//{
|
||
// isNextOne = true;
|
||
//}
|
||
//else
|
||
//{
|
||
// isNextOne = false;
|
||
//}
|
||
// 增加标识列
|
||
if (!table.Columns.Contains(frmSelect.RecordPrimaryField))
|
||
{
|
||
this.mRecordPrimaryField = frmSelect.RecordPrimaryField;
|
||
table.Columns.Add(this.mRecordPrimaryField, typeof(String));
|
||
}
|
||
|
||
foreach (DataRow item in frmSelect.SelectedRows)
|
||
{
|
||
DataRow newRow = table.NewRow();
|
||
newRow.ItemArray = rowItem.ItemArray;
|
||
newRow[guidField] = rowItem[guidField];
|
||
DataColumn IsIdentCol = newRow.Table.Columns.Cast<DataColumn>().FirstOrDefault(x => x.ColumnName == BaseImpl.GetResult(string.Format("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.columns WHERE TABLE_NAME='{0}' AND COLUMNPROPERTY(OBJECT_ID('{0}'),COLUMN_NAME,'IsIdentity')=1", BillModel.DetailTable)) + "");
|
||
//自增长列分配按空值取
|
||
if (IsIdentCol != null)
|
||
{
|
||
if (IsIdentCol.DataType == typeof(Decimal) ||
|
||
IsIdentCol.DataType == typeof(Double) ||
|
||
IsIdentCol.DataType == typeof(Int16) ||
|
||
IsIdentCol.DataType == typeof(Int32) ||
|
||
IsIdentCol.DataType == typeof(Int64))
|
||
{
|
||
newRow[IsIdentCol.ColumnName] = 0;
|
||
}
|
||
}
|
||
foreach (DataColumn col in item.Table.Columns)
|
||
{
|
||
if (table.Columns.Contains(col.ColumnName))
|
||
{
|
||
//newRow[col.ColumnName] = item[col.ColumnName];
|
||
newRow[col.ColumnName] = item[col.ColumnName];
|
||
GridColumn column = this.gcMain.GridView.Columns[col.ColumnName];
|
||
if (column != null)
|
||
{
|
||
GridColumnModel model = column.Tag as GridColumnModel;
|
||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||
{
|
||
this.SetUnionValue(model, rowItem[column.FieldName] + "", newRow);
|
||
}
|
||
SetCalcValue(model, rowItem[column.FieldName] + "", newRow);
|
||
}
|
||
}
|
||
}
|
||
newRow[frmSelect.AmountField] = item[frmSelect.AmountField];
|
||
newRow[frmSelect.RecordPrimaryField] = item[frmSelect.RecordPrimaryField];
|
||
table.Rows.Add(newRow);
|
||
}
|
||
NumberMc = frmSelect.AmountField;
|
||
//double syAmount = frmSelect.GetSyAmount();
|
||
//if (syAmount > 0)
|
||
//{
|
||
// rowItem[frmSelect.AmountField] = frmSelect.GetSyAmount();
|
||
//}
|
||
//else
|
||
//{
|
||
// table.Rows.Remove(rowItem);
|
||
//}
|
||
table.Rows.Remove(rowItem);
|
||
// 重排顺序
|
||
table.OrderBy(this.BillModel.DetailOrderField);
|
||
this.gcMain.GridView.UpdateCurrentRow();
|
||
this.gcMain.GridView.ShowEditor();
|
||
}
|
||
}
|
||
if (frmSelect.isNextOne)
|
||
{
|
||
int SourceRowIndex = this.gcMain.GridView.GetFocusedDataSourceRowIndex();
|
||
DataRow[] a = table.Rows.Cast<DataRow>().Where(x => string.IsNullOrEmpty(x[guidField].ToString())).ToArray();
|
||
if (a.Length != 0)
|
||
{
|
||
this.gcMain.GridView.FocusedRowHandle = SourceRowIndex;
|
||
OnBtnFPOldClick(null, null);
|
||
}
|
||
else
|
||
{
|
||
MessageUtil.Show("全部分配完毕");
|
||
// frmSelect.SelectRowItem = null;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageUtil.Show(ex);
|
||
}
|
||
}
|
||
private void cb_templete_QueryCloseUp(object sender, CancelEventArgs e)
|
||
{
|
||
this.SetTempSelect(true);
|
||
}
|
||
#endregion
|
||
|
||
#region 单据快速录入相关
|
||
/// <summary>
|
||
/// <para>说明:快速录入明细</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2019-08-05 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void InputGridView()
|
||
{
|
||
try
|
||
{
|
||
WaitForm.ShowForm();
|
||
|
||
string inputText = txt_input.Text.Trim();
|
||
ComboBoxEditModel editObj = cb_input.SelectedItem as ComboBoxEditModel;
|
||
|
||
if (string.IsNullOrWhiteSpace(inputText))
|
||
{
|
||
MessageUtil.Show(ResourceKeys.KeyWordNotNull);
|
||
return;
|
||
}
|
||
if (editObj != null)
|
||
{
|
||
|
||
DataTable table = BaseImpl.GetDataTableResult(this.ControlObj.ReplaceControlValue(ReplaceHelper.ReplaceSearchControlCond(editObj.SourceModel.CodeInputSql, inputText)));
|
||
if (table.Rows.Count == 0)
|
||
{
|
||
MessageUtil.Show(ResourceKeys.NotFoundKeyWord);
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
bool onlyPopup = false;
|
||
foreach (DataRow rowItem in table.Rows)
|
||
{
|
||
this.AddRowToGridView(rowItem);
|
||
this.AddRowToGridViewByBom(rowItem, editObj.UnionModel, ref onlyPopup);
|
||
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageUtil.Show(ex);
|
||
LogUtil.WriteError("单据快速录入明细出错!", ex);
|
||
}
|
||
finally
|
||
{
|
||
WaitForm.HideForm();
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:单据快速录入</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-04-19 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
private void OnInputClick(object sender, EventArgs e)
|
||
{
|
||
this.InputGridView();
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2019-08-05 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
|
||
private void OnInputKeyDown(object sender, KeyEventArgs e)
|
||
{
|
||
if (e.KeyCode == Keys.Enter)
|
||
{
|
||
this.InputGridView();
|
||
this.txt_input.EditValue = "";
|
||
this.txt_input.Focus();
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 单据模版录入相关
|
||
private void SetTempSelect(bool isTip)
|
||
{
|
||
ComboBoxEditModel model = this.cb_templete.SelectedItem as ComboBoxEditModel;
|
||
|
||
if (model != null)
|
||
{
|
||
bool isExec = true;
|
||
DataTable detailTable = gcMain.GridControl.DataSourceTable();
|
||
if (detailTable != null && detailTable.Rows.Count > 0 && isTip)
|
||
{
|
||
DialogResult result = XtraMessageBox.Show("确定要切换模版?\r\n注:切换模版会清空明细数据.", "系统提示", MessageBoxButtons.YesNo);
|
||
isExec = result == DialogResult.Yes;
|
||
}
|
||
if (isExec)
|
||
{
|
||
if (isExec)
|
||
{
|
||
string title = model.RowItem["rpname"] + "";
|
||
string brpId = model.RowItem["id"] + "";
|
||
|
||
// 设置标题
|
||
this.Parent.Text = title;
|
||
// 清空明细
|
||
detailTable.Clear();
|
||
|
||
// 设置主表固定字段
|
||
LabelTextEdit textEdit = this.ControlObj.FindControl("brpid") as LabelTextEdit;
|
||
if (textEdit == null)
|
||
{
|
||
MessageUtil.Show(ResourceKeys.NotFountBrpID);
|
||
return;
|
||
}
|
||
textEdit.EditText = brpId;
|
||
|
||
// 重新设置明细列
|
||
DataTable columns = BillImpl.GetBillDetailBrpColumns(brpId);
|
||
if (columns != null && columns.Rows.Count > 0)
|
||
gcMain.SetEditColumns(columns);
|
||
else
|
||
gcMain.GridView.Columns.Clear();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:初始化Brp模版</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-04-20 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void InitializeTemplete()
|
||
{
|
||
Dictionary<object, Hashtable> dataCaches = SysModel != null ? SysModel.DataCaches : null;
|
||
if (!dataCaches.GetValue(this, "BillBrp", out DataTable table))
|
||
{
|
||
table = BillImpl.GetBillBrp(this.SysModel.ModuleCode);
|
||
}
|
||
List<ComboBoxEditModel> tempModels = new List<ComboBoxEditModel>();
|
||
|
||
foreach (DataRow item in table.Rows)
|
||
{
|
||
ComboBoxEditModel editModel = new ComboBoxEditModel()
|
||
{
|
||
ValuemMeber = "id",
|
||
TextMember = "RpName",
|
||
RowItem = item
|
||
};
|
||
this.cb_templete.Properties.Items.Add(editModel);
|
||
tempModels.Add(editModel);
|
||
}
|
||
this.cb_templete.Tag = tempModels;
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:设置Brp模版</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-04-23 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void SetTempleteSelectedValue(string id)
|
||
{
|
||
List<ComboBoxEditModel> tempModels = this.cb_templete.Tag as List<ComboBoxEditModel>;
|
||
if (tempModels != null)
|
||
{
|
||
ComboBoxEditModel model = tempModels.Find(x => id.Equals(x.RowItem[x.ValuemMeber] + ""));
|
||
if (model == null)
|
||
gcMain.GridView.Columns.Clear();
|
||
else
|
||
{
|
||
this.cb_templete.SelectedItem = model;
|
||
this.SetTempSelect(false);
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:手动选择模版</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-04-23 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The source of the event.</param>
|
||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
||
private void OnTempleteClick(object sender, EventArgs e)
|
||
{
|
||
this._isSelectedTemplete = true;
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:单据选中/取消选中数据</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2020-05-12 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
/// <param name="e">The <see cref="RowCellClickEventArgs"/> instance containing the event data.</param>
|
||
private void OnGridViewIsCheckClick(object sender, RowCellClickEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
DataRow rowItem = (sender as GridView).GetFocusedDataRow();
|
||
if (rowItem != null && e.Column.FieldName == "_check")
|
||
{
|
||
rowItem["_check"] = "True".Equals(rowItem["_check"] + "") ? 0 : 1;
|
||
rowItem.AcceptChanges();
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
|
||
private void tb_buttom_Load(object sender, EventArgs e)
|
||
{
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 隐藏主表
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void OnMainTableHiding(object sender, EventArgs e)
|
||
{
|
||
if (this.pl_main_center_master.Dock == DockStyle.Top)
|
||
{
|
||
this.pl_main_center_master.Dock = DockStyle.None;
|
||
this.btnHiding.Text = "显示主表";
|
||
}
|
||
else
|
||
{
|
||
this.pl_main_center_master.Dock = DockStyle.Top;
|
||
this.btnHiding.Text = "隐藏主表";
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 刷新明细表
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void btnRefresh_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
WaitForm.ShowForm();
|
||
//主表明细
|
||
if (this.gcMain is TreeGridControlEx)
|
||
{
|
||
(this.gcMain as TreeGridControlEx).RefreshDataSource();
|
||
}
|
||
else
|
||
{
|
||
this.gcMain.RefreshDataSource();
|
||
}
|
||
|
||
//来源明细
|
||
foreach (XtraTabPage tabPage in this.xtc_left_container.TabPages)
|
||
{
|
||
BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel;
|
||
if (unionModel != null && unionModel.GridDetailControlObj != null)
|
||
{
|
||
unionModel.GridDetailControlObj.RefreshDataSource();
|
||
if (unionModel.GridDetailDetailControlObj != null) unionModel.GridDetailDetailControlObj.RefreshDataSource();
|
||
}
|
||
}
|
||
//附加信息
|
||
foreach (XtraTabPage tabPage in this.tb_buttom.TabControlObj.TabPages)
|
||
{
|
||
GridDetailModel model = this.tb_buttom.GetGridDetailModel(tabPage);
|
||
if (model != null)
|
||
{
|
||
if (tabPage.Tag is GridControlEx)
|
||
{
|
||
(tabPage.Tag as GridControlEx).RefreshDataSource();
|
||
}
|
||
}
|
||
else if (tabPage.Tag is TabMultipledetails)
|
||
{
|
||
TabMultipledetails tabMultipledetails = tabPage.Tag as TabMultipledetails;
|
||
(tabMultipledetails.SplitMain.Panel1.Tag as GridControlEx).RefreshDataSource();
|
||
(tabMultipledetails.SplitMain.Panel2.Tag as GridControlEx).RefreshDataSource();
|
||
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
WaitForm.HideForm();
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
#endregion
|
||
|
||
#region 计算贷方的值
|
||
/// <summary>
|
||
/// <para>说明:计算贷方的值</para>
|
||
/// <para>创建人:曹屹峰</para>
|
||
/// <para>创建日期:2022-01-19 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void OnGridControlKye(object sender, KeyEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (!e.KeyData.Equals(Keys.F1)) return;
|
||
GridColumn column = this.gcMain.GridView.FocusedColumn;
|
||
//if (!string.IsNullOrWhiteSpace(column.View.EditingValue + "")) return;
|
||
GridColumnModel model = column.Tag as GridColumnModel;
|
||
int[] rows = this.gcMain.GridView.GetSelectedRows();
|
||
if (model.FieldType == 115)
|
||
{
|
||
if (rows.Length != 1) return;
|
||
DataTable dataSource = this.gcMain.gridControl.DataSource as DataTable;//gridView.GetGridViewFilteredAndSortedDataToDataTable();
|
||
GridColumn debit = this.gcMain.GridView.Columns.FirstOrDefault(x => x.Caption.Equals("借方金额"));
|
||
GridColumn credit = this.gcMain.GridView.Columns.FirstOrDefault(x => x.Caption.Equals("贷方金额"));
|
||
double debitAmount = 0;//借方金额
|
||
double creditAmount = 0;//贷方金额
|
||
foreach (DataRow item in dataSource.Rows)
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(item[debit.FieldName].ToString())) debitAmount += double.Parse(item[debit.FieldName].ToString());
|
||
if (!string.IsNullOrWhiteSpace(item[credit.FieldName].ToString())) creditAmount += double.Parse(item[credit.FieldName].ToString());
|
||
}
|
||
//借方和贷方是否相等
|
||
double differenceAmount = debitAmount - creditAmount;
|
||
if (differenceAmount > 0 && column.FieldName.Equals(credit.FieldName))
|
||
{
|
||
dataSource.Rows[rows[0]][column.FieldName] = differenceAmount + double.Parse(dataSource.Rows[rows[0]][column.FieldName] + "");
|
||
this.gcMain.GridView.UpdateCurrentRow();
|
||
this.gcMain.GridView.ShowEditor();
|
||
}
|
||
if (differenceAmount < 0 && column.FieldName.Equals(debit.FieldName))
|
||
{
|
||
dataSource.Rows[rows[0]][column.FieldName] = differenceAmount * -1 + double.Parse(dataSource.Rows[rows[0]][column.FieldName] + "");
|
||
this.gcMain.GridView.UpdateCurrentRow();
|
||
this.gcMain.GridView.ShowEditor();
|
||
}
|
||
|
||
SendKeys.Send("{Esc}");
|
||
//e.Handled = true;
|
||
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageUtil.Show(ex.Message);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 重新计算右上角按钮坐标
|
||
/// </summary>
|
||
private void CalculateCoordinates()
|
||
{
|
||
List<SimpleButton> buttons = new List<SimpleButton>();//没有隐藏的按钮集合
|
||
|
||
//帮助文档按钮
|
||
if (SystemInfo.Instance.HideHelpDocument)
|
||
{
|
||
this.btnHelp.Visible = false;
|
||
}
|
||
else
|
||
{
|
||
buttons.Add(this.btnHelp);
|
||
}
|
||
//隐藏主表
|
||
if (this.BillModel.HiddenMasterTable)
|
||
{
|
||
this.btnHiding.Visible = true;
|
||
buttons.Add(this.btnHiding);
|
||
}
|
||
//刷新按钮
|
||
if (SystemInfo.Instance.HideTableRefresh)
|
||
{
|
||
this.btnRefresh.Visible = false;
|
||
}
|
||
else
|
||
{
|
||
buttons.Add(this.btnRefresh);
|
||
}
|
||
//分配按钮
|
||
buttons.Add(this.dbpFP);
|
||
|
||
|
||
//从最后开始计算
|
||
int x = this.dpbTools.Location.X;
|
||
//判断是否隐藏常用工具按钮,隐藏的话x为导出导入按钮的坐标
|
||
if (SystemInfo.Instance.HiddenTools)
|
||
{
|
||
this.dpbTools.Visible = false;
|
||
x = this.dpbImport.Location.X;
|
||
}
|
||
if (buttons.Count != 4)
|
||
{
|
||
foreach (SimpleButton item in buttons)
|
||
{
|
||
item.Location = new Point(x - 2 - item.Width, this.dpbTools.Location.Y);
|
||
x = x - 2 - item.Width;
|
||
}
|
||
}
|
||
|
||
//设置扫码控件
|
||
if (!string.IsNullOrWhiteSpace(this.BillModel.CodeExecuteSql) && !string.IsNullOrWhiteSpace(this.BillModel.CodeExecuteParameter))
|
||
{
|
||
this.pl_input.Controls.Clear();
|
||
this.pl_input.Visible = false;
|
||
|
||
LabelControl label = new LabelControl();
|
||
label.Font = new Font("宋体", 12F);
|
||
label.Text = "串号扫描";
|
||
label.Top = (pl_main_bottom.Height - label.Height) / 2;
|
||
label.Left = 10;
|
||
label.Parent = pl_main_bottom;
|
||
|
||
this.ScanCodeTextEdit = new TextEdit();
|
||
ScanCodeTextEdit.Height = this.pl_input.Height;
|
||
ScanCodeTextEdit.Width = this.pl_input.Width;
|
||
ScanCodeTextEdit.Properties.Appearance.Font = new Font("宋体", 10.5F);
|
||
ScanCodeTextEdit.Left = label.Width + 15;
|
||
ScanCodeTextEdit.Top = (pl_main_bottom.Height - ScanCodeTextEdit.Height) / 2;
|
||
ScanCodeTextEdit.BackColor = ColorTranslator.FromHtml("#FFC0CB");
|
||
ScanCodeTextEdit.KeyDown += Text_KeyDown;
|
||
ScanCodeTextEdit.Parent = pl_main_bottom;
|
||
|
||
}
|
||
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 来源明细是表格,推拽到主表树表格中
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void DragDetailGrid_OnDragComplete(object sender, GridDragTreeGridArgs e)
|
||
{
|
||
if (this.CanAddTreeDetailRow())
|
||
{
|
||
string Pid = "0";//必须父节点必须有默认值,不然如果新增后没有值的话,无法自动展开当前节点
|
||
if (e.SelectTreeNode != null)
|
||
{
|
||
Pid = e.SelectTreeNode[(this.gcMain as TreeGridControlEx).TreeListObj.KeyFieldName] + "";
|
||
|
||
DataRow SelectRow = (this.gcMain as TreeGridControlEx).GetViewSpecifyDataRow(e.SelectTreeNode);
|
||
if (!string.IsNullOrWhiteSpace(this.BillModel.TreeTableDragCondition) && !ReplaceHelper.EvalCond(ReplaceHelper.ReplaceRowParam(SelectRow, this.BillModel.TreeTableDragCondition)))
|
||
{
|
||
return;
|
||
}
|
||
}
|
||
XtraTabPage tabPage = this.xtc_left_container.SelectedTabPage;
|
||
BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel;
|
||
int oldRowHandle = this.gcMain.GridView.FocusedRowHandle;
|
||
//改变选中行颜色
|
||
int[] rowHandles = e.GridViewObj.GetSelectedRows();
|
||
if (BillModel.IsSelectSourceColor)
|
||
{
|
||
//选中行改变颜色
|
||
foreach (int h in rowHandles)
|
||
{
|
||
ColorHandles.Add(h);
|
||
}
|
||
e.GridViewObj.Invalidate();
|
||
}
|
||
//拖拽行
|
||
foreach (DataRow rowItem in e.GridViewSelectRows)
|
||
{
|
||
//添加拖拽行
|
||
this.AddMultiRowTreeGridControl(new DataRow[] { rowItem }, Pid);
|
||
if (!string.IsNullOrWhiteSpace(unionModel.AddDataSql) && !string.IsNullOrWhiteSpace(unionModel.AddDataCondition) && this.ValidateCond(unionModel.AddDataCondition, rowItem))
|
||
{
|
||
//添加拖拽行对应的数据源
|
||
string addSql = ReplaceHelper.ReplaceRowParam(e.GridViewSelectRows, ReplaceHelper.ReplaceUserInfo(unionModel.AddDataSql));
|
||
DataTable dataTable = MainImpl.GetDataTableResult(addSql);
|
||
DragAddTable(dataTable, (int.Parse((this.gcMain as TreeGridControlEx).GetNewNodesId()) - 1) + "");//上方的新增行的id默认是最大的
|
||
}
|
||
}
|
||
this.gcMain.GridView.SelectRowHandler(oldRowHandle);
|
||
|
||
if (e.SelectTreeNode != null)
|
||
{
|
||
e.SelectTreeNode.Expanded = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 拖拽后添加表格数据源
|
||
/// </summary>
|
||
/// <param name="dataTable">新增数据源</param>
|
||
/// <param name="Pid">父节点号</param>
|
||
public void DragAddTable(DataTable dataTable, string Pid)
|
||
{
|
||
try
|
||
{
|
||
if (dataTable == null || dataTable.Rows.Count < 1) return;
|
||
|
||
WaitForm.ShowForm(ResourceKeys.Handing);
|
||
//父节点名称
|
||
string ParentFieldName = (this.gcMain as TreeGridControlEx).TreeListObj.ParentFieldName;
|
||
//节点名称
|
||
string KeyFieldName = (this.gcMain as TreeGridControlEx).TreeListObj.KeyFieldName;
|
||
//主表明细结构
|
||
DataTable TreeTable = ((this.gcMain as TreeGridControlEx).TreeListObj.DataSource as DataTable).Clone();
|
||
//明细表数据
|
||
TreeListColumnCollection gridColumns = (this.gcMain as TreeGridControlEx).TreeListObj.Columns;
|
||
//可以添加的行节点id
|
||
List<string> nodeId = new List<string>();
|
||
|
||
//数据源的id和pid全部加上目标节点(加上后当前数据源就是目标节点的子节点数据源)
|
||
if (dataTable.Columns.Contains(ParentFieldName) && dataTable.Columns.Contains(KeyFieldName))
|
||
{
|
||
//当前树表格中最大的id号
|
||
int NodeId = int.Parse((this.gcMain as TreeGridControlEx).GetNewNodesId()) - 1;
|
||
//当前树表格中如果id为null,要赋值的id值(节点id不能为null)
|
||
int NewNodeId = int.Parse((this.gcMain as TreeGridControlEx).GetNewNodesId());
|
||
|
||
//根据当前的节点号,改变新增数据源中的节点号
|
||
foreach (DataRow rowItem in dataTable.Rows)
|
||
{
|
||
// 新增表格中的数据id全部加上最大id号,如果是空就默认去赋最大id+1的值
|
||
if (!string.IsNullOrWhiteSpace(rowItem[KeyFieldName] + ""))
|
||
{
|
||
rowItem[KeyFieldName] = int.Parse(rowItem[KeyFieldName] + "") + NodeId;
|
||
}
|
||
else
|
||
{
|
||
rowItem[KeyFieldName] = NewNodeId;
|
||
NewNodeId++;
|
||
}
|
||
|
||
//pid为0或者null的改成目标节点的节点号,有值的默认加上最大id值
|
||
if (string.IsNullOrWhiteSpace(rowItem[ParentFieldName] + "") || int.Parse(rowItem[ParentFieldName] + "") == 0)
|
||
{
|
||
rowItem[ParentFieldName] = Pid;
|
||
|
||
}
|
||
else if (int.Parse(rowItem[ParentFieldName] + "") > 0)
|
||
{
|
||
rowItem[ParentFieldName] = int.Parse(rowItem[ParentFieldName] + "") + NodeId;
|
||
}
|
||
|
||
DataRow newRow = TreeTable.NewRow();
|
||
newRow.BeginEdit();
|
||
// 赋值明细字段
|
||
foreach (TreeListColumn col in gridColumns)
|
||
{
|
||
try
|
||
{
|
||
GridColumnModel model = col.Tag as GridColumnModel;
|
||
if (dataTable.Columns.Contains(col.FieldName))
|
||
{
|
||
// 来源列中是否包含对应字段,包含则使用值
|
||
newRow[col.FieldName] = rowItem[col.FieldName];
|
||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||
{
|
||
this.SetUnionValue(model, rowItem[col.FieldName] + "", newRow);
|
||
}
|
||
SetCalcValue(model, rowItem[col.FieldName] + "", newRow);
|
||
}
|
||
else
|
||
{
|
||
// 未包含字段,则使用控件默认值.
|
||
if (col.FieldName.Contains("_Ls"))
|
||
{
|
||
string[] unioFielName = col.FieldName.Split('_');
|
||
string UnioValue = unioFielName[unioFielName.Length - 1];
|
||
DataColumn grid = dataTable.Columns.Cast<DataColumn>().FirstOrDefault(x => x.ColumnName.Split('_')[x.ColumnName.Split('_').Length - 1].Equals(UnioValue));
|
||
if (grid != null && !string.IsNullOrEmpty(model.UnionFields))
|
||
{
|
||
this.SetUnionValue(model, rowItem[col.FieldName] + "", newRow);
|
||
}
|
||
SetCalcValue(model, rowItem[col.FieldName] + "", newRow);
|
||
|
||
}
|
||
else
|
||
{
|
||
string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue);
|
||
|
||
if (model.DefaultValue.Contains("{#"))
|
||
{
|
||
fieldValue = this.ControlObj.ReplaceParentControlValue(model.DefaultValue);
|
||
if (!string.IsNullOrEmpty(fieldValue))
|
||
{
|
||
newRow[col.FieldName] = fieldValue;
|
||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||
{
|
||
this.SetUnionValue(model, fieldValue + "", newRow);
|
||
}
|
||
SetCalcValue(model, fieldValue + "", newRow);
|
||
|
||
//计算规则配置在结果字段上,所以无需验证当前操作控件
|
||
//this.gcMain.GridView.SetFocusedRowCellValue(col, fieldValue);
|
||
}
|
||
}
|
||
else if (!string.IsNullOrEmpty(model.DefaultValue))
|
||
{
|
||
newRow[col.FieldName] = fieldValue;
|
||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||
{
|
||
this.SetUnionValue(model, fieldValue + "", newRow);
|
||
}
|
||
SetCalcValue(model, fieldValue + "", newRow);
|
||
|
||
}
|
||
}
|
||
}
|
||
SetDisableColumn(model, newRow[col.FieldName] + "", newRow);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Instance.WriteError(ex);
|
||
}
|
||
}
|
||
|
||
newRow.EndEdit();
|
||
TreeTable.Rows.Add(newRow);
|
||
}
|
||
//(this.gcMain as TreeGridControlEx).SetGridViewDataSourceGenerateID(TreeTable);
|
||
//添加到主表明细中
|
||
while (TreeTable.Rows.Count != nodeId.Count)
|
||
{
|
||
foreach (DataRow item in TreeTable.Rows)
|
||
{
|
||
//是一级节点或者父节点已经添加了的数据,会添加到明细表中
|
||
if ((Pid.Equals(item[ParentFieldName] + "") || nodeId.Contains(item[ParentFieldName] + "")) && !nodeId.Contains(item[KeyFieldName] + ""))
|
||
{
|
||
nodeId.Add(item[KeyFieldName] + "");
|
||
//添加到主表明细中
|
||
this.AddMultiRowTreeGridControl(new DataRow[] { item }, item[ParentFieldName] + "");
|
||
}
|
||
}
|
||
}
|
||
//排序
|
||
(this.gcMain as TreeGridControlEx).DataSourceSorting();
|
||
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
WaitForm.HideForm();
|
||
}
|
||
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:添加多条数据到单据明细</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-30 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void AddMultiRowTreeGridControl(DataRow[] rowItems, string Pid)
|
||
{
|
||
this.isDragWrap = false;//用于设置拖拽时不允许扫码控件换行
|
||
XtraTabPage tabPage = this.xtc_left_container.SelectedTabPage;
|
||
BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel;
|
||
|
||
if (unionModel != null)
|
||
{
|
||
bool onlyOne = true;
|
||
|
||
foreach (DataRow rowItem in rowItems)
|
||
{
|
||
// 检查当前记录是否满足条件
|
||
if (ValidateDetailCond(rowItem, unionModel))
|
||
{
|
||
this.AddRowToTreeGridControl(rowItem, Pid);
|
||
if (!string.IsNullOrWhiteSpace(this.BillModel.ChangeColColor))
|
||
{
|
||
if (rowItem.Table.Columns.Contains(this.BillModel.ChangeColColor))
|
||
{
|
||
rowItem[this.BillModel.ChangeColColor] = "1";
|
||
}
|
||
}
|
||
if (BillModel.drgFinishHide == "1" && unionModel.GridDetailControlObj != null)
|
||
{
|
||
unionModel.GridDetailControlObj.GridControl.DataSourceTable().Rows.Remove(rowItem);
|
||
}
|
||
if (BillModel.DrgDetailAndSource && unionModel.GridControlObj != null)//移动明细主表数据到主表
|
||
{
|
||
try
|
||
{
|
||
int[] rows = unionModel.GridControlObj.GridView.GetSelectedRows();
|
||
foreach (int index in rows)
|
||
{
|
||
DataRow dataRow = unionModel.GridControlObj.GridView.GetDataRow(index);
|
||
this.ControlObj.SetAllControlValue(dataRow, true);
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (onlyOne)
|
||
{
|
||
onlyOne = false;
|
||
if (!string.IsNullOrEmpty(unionModel.ModelObj.DetailEnableMsg))
|
||
{
|
||
if (unionModel.ModelObj.DetailEnableMsg.StartsWith("select", StringComparison.OrdinalIgnoreCase) ||
|
||
unionModel.ModelObj.DetailEnableMsg.StartsWith("exec", StringComparison.OrdinalIgnoreCase))
|
||
{
|
||
MessageUtil.Show(BaseImpl.GetResult(unionModel.ModelObj.DetailEnableMsg) + "");
|
||
}
|
||
else
|
||
{
|
||
MessageUtil.Show(unionModel.ModelObj.DetailEnableMsg);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
this.isDragWrap = true;//用于设置拖拽时不允许扫码控件换行
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:添加行到单据明细中</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-30 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="rowItem">The row item.</param>
|
||
/// <param name="unionModel">The union model.</param>
|
||
private void AddRowToTreeGridControl(DataRow rowItem, string Pid)
|
||
{
|
||
TreeListColumnCollection gridColumns = (this.gcMain as TreeGridControlEx).TreeListObj.Columns;
|
||
DataTable gridTable = ((this.gcMain as TreeGridControlEx).TreeListObj.DataSource as DataTable).TrimDeleteRows();
|
||
if (!gridTable.Columns.Contains(ERPInfo.Instance.isAddRows))
|
||
{
|
||
gridTable.Columns.Add(ERPInfo.Instance.isAddRows, typeof(String));
|
||
}
|
||
string repeatProduct = (this.gcMain as TreeGridControlEx).TreeListObj.Columns["ProductId"] != null && rowItem.Table.Columns.Contains("ProductId") ? "ProductId" : this.BillModel.DetailPreFix + "ProductId";
|
||
AssociatedField = repeatProduct;
|
||
if ("1".Equals(this.BillModel.DetailDoubleClickTip) && rowItem.Table.Columns.Contains(repeatProduct))
|
||
{
|
||
// 需要提示编码重复
|
||
DataTable dt = (this.gcMain as TreeGridControlEx).TreeListObj.DataSource as DataTable;
|
||
if (dt != null && dt.Rows.Count > 0 && dt.Columns.Contains(repeatProduct))
|
||
{
|
||
DataRow[] drs = dt.Select(repeatProduct + "='" + rowItem[repeatProduct] + "'");
|
||
if (drs.Length >= 1)
|
||
{
|
||
DialogResult dialog = MessageUtil.Show(ResourceKeys.ProductIsRepet, MessageBoxButtons.YesNo);
|
||
if (dialog != DialogResult.Yes)
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
DataRow newRow = gridTable.NewRow();
|
||
//2024-1-29改成>=,之前为>导致选中第一行只会添加到最后一行(测试空白行没有影响)
|
||
int position = this.gcMain.GridView.FocusedRowHandle >= 0 ? gridTable.Rows.Count > 0 ? this.gcMain.GridView.FocusedRowHandle : 0 : gridTable.Rows.Count - 1;
|
||
|
||
|
||
|
||
(this.gcMain as TreeGridControlEx).TreeListObj.BeginUpdate();
|
||
GridView gridView = this.gcMain.GridView;
|
||
// 赋值明细字段
|
||
foreach (TreeListColumn col in gridColumns)
|
||
{
|
||
try
|
||
{
|
||
// 未包含字段,则使用控件默认值.
|
||
GridColumnModel model = col.Tag as GridColumnModel;
|
||
|
||
if (rowItem.Table.Columns.Contains(col.FieldName))
|
||
{
|
||
// 来源列中是否包含对应字段,包含则使用值
|
||
newRow[col.FieldName] = rowItem[col.FieldName];
|
||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||
{
|
||
this.SetUnionValue(model, rowItem[col.FieldName] + "", newRow);
|
||
}
|
||
SetCalcValue(model, rowItem[col.FieldName] + "", newRow);
|
||
}
|
||
else
|
||
{
|
||
|
||
if (col.FieldName.Contains("_Ls"))
|
||
{
|
||
string[] unioFielName = col.FieldName.Split('_');
|
||
string UnioValue = unioFielName[unioFielName.Length - 1];
|
||
DataColumn grid = rowItem.Table.Columns.Cast<DataColumn>().FirstOrDefault(x => x.ColumnName.Split('_')[x.ColumnName.Split('_').Length - 1].Equals(UnioValue));
|
||
if (grid != null && !string.IsNullOrEmpty(model.UnionFields))
|
||
{
|
||
this.SetUnionValue(model, rowItem[col.FieldName] + "", newRow);
|
||
}
|
||
SetCalcValue(model, rowItem[col.FieldName] + "", newRow);
|
||
}
|
||
else
|
||
{
|
||
string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue);
|
||
|
||
if (model.DefaultValue.Contains("{#"))
|
||
{
|
||
fieldValue = this.ControlObj.ReplaceParentControlValue(model.DefaultValue);
|
||
if (!string.IsNullOrEmpty(fieldValue))
|
||
{
|
||
newRow[col.FieldName] = fieldValue;
|
||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||
{
|
||
this.SetUnionValue(model, fieldValue + "", newRow);
|
||
}
|
||
SetCalcValue(model, fieldValue + "", newRow);
|
||
}
|
||
}
|
||
else if (!string.IsNullOrEmpty(model.DefaultValue))
|
||
{
|
||
newRow[col.FieldName] = fieldValue;
|
||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||
{
|
||
this.SetUnionValue(model, fieldValue + "", newRow);
|
||
}
|
||
SetCalcValue(model, fieldValue + "", newRow);
|
||
}
|
||
}
|
||
}
|
||
SetDisableColumn(model, newRow[col.FieldName] + "", newRow);
|
||
if (model.LimitLength > 0)
|
||
{
|
||
DataRow HandleRow = newRow;
|
||
int MaxInputLength = System.Text.Encoding.Default.GetBytes(newRow[col.FieldName] + "").Length;
|
||
if (model.LimitLength < MaxInputLength)
|
||
HandleRow.SetColumnError(HandleRow.Table.Columns[col.ColumnHandle], "当前输入文本超过设定长度!");//满足条件设置错误信息
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Instance.WriteError(ex);
|
||
}
|
||
}
|
||
(this.gcMain as TreeGridControlEx).TreeListObj.EndUpdate();
|
||
if (string.IsNullOrWhiteSpace(newRow[(this.gcMain as TreeGridControlEx).TreeListObj.KeyFieldName] + ""))
|
||
{
|
||
newRow[(this.gcMain as TreeGridControlEx).TreeListObj.KeyFieldName] = (this.gcMain as TreeGridControlEx).GetNewNodesId();//节点id为空,就默认给当前数据源最大id+1
|
||
}
|
||
|
||
if (!string.IsNullOrWhiteSpace(Pid))
|
||
{
|
||
newRow[(this.gcMain as TreeGridControlEx).TreeListObj.ParentFieldName] = Pid;//拖拽到目标节点的id
|
||
}
|
||
// 添加数据行
|
||
gridTable.Rows.Add(newRow);
|
||
|
||
|
||
if (!string.IsNullOrEmpty(NumberMc) && gridTable.Columns.Contains(mRecordPrimaryField))
|
||
{
|
||
DataRow[] rt = gridTable.Rows.Cast<DataRow>().Where(x => (newRow[BillModel.DetailPreFix + "ProductId"] + "").Equals(x[BillModel.DetailPreFix + "ProductId"] + "") && !string.IsNullOrEmpty(x[mRecordPrimaryField] + "")).ToArray();
|
||
foreach (DataRow item in rt)
|
||
{
|
||
if (newRow != null)
|
||
{
|
||
newRow[NumberMc] = Convert.ToDouble(newRow[NumberMc]) - Convert.ToDouble(item[NumberMc]);
|
||
}
|
||
//this.gcMain.OnGridViewCellValueChanged(this.gcMain, new CellValueChangedEventArgs(position + 1, this.gcMain.GridView.Columns[NumberMc], newRow[NumberMc] + ""));
|
||
//this.gcMain.GridView.UpdateCurrentRow();
|
||
//this.gcMain.GridView.ShowEditor();
|
||
if (Convert.ToDouble(newRow[NumberMc] + "") == 0.0)
|
||
{
|
||
gridTable.Rows.Remove(newRow);
|
||
MessageUtil.Show("数量已分配完毕!无需再进行拖拽!");
|
||
}
|
||
}
|
||
}
|
||
//gridTable.OrderBy(this.BillModel.DetailOrderField);
|
||
//设置排序列的值
|
||
(this.gcMain as TreeGridControlEx).DataSourceSorting();
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:添加多行到单据明细中</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-30 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="rowItem">The row item.</param>
|
||
/// <param name="unionModel">The union model.</param>
|
||
private void AddRowsToTreeGridControl(DataTable dataTable, BillSourceUnionModel unionModel)
|
||
{
|
||
WaitForm.ShowForm();
|
||
TreeListColumnCollection gridColumns = (this.gcMain as TreeGridControlEx).TreeListObj.Columns;
|
||
DataTable gridTable = ((this.gcMain as TreeGridControlEx).TreeListObj.DataSource as DataTable).TrimDeleteRows().Copy();
|
||
|
||
if (!gridTable.Columns.Contains(ERPInfo.Instance.isAddRows))
|
||
{
|
||
gridTable.Columns.Add(ERPInfo.Instance.isAddRows, typeof(String));
|
||
}
|
||
|
||
TreeListNode treeNode = (this.gcMain as TreeGridControlEx).TreeListObj.FocusedNode as TreeListNode;
|
||
int position = 0;
|
||
if (treeNode != null) position = treeNode.Id;
|
||
|
||
|
||
//bool isLastRow = this.gcMain.GridView.IsLastVisibleRow;
|
||
|
||
|
||
|
||
bool onlyOne = true;
|
||
foreach (DataRow rowItem in dataTable.Rows)
|
||
{
|
||
if (unionModel == null || ValidateDetailCond(rowItem, unionModel))
|
||
{
|
||
|
||
string repeatProduct = (this.gcMain as TreeGridControlEx).TreeListObj.Columns["ProductId"] != null && rowItem.Table.Columns.Contains("ProductId") ? "ProductId" : this.BillModel.DetailPreFix + "ProductId";
|
||
AssociatedField = repeatProduct;
|
||
|
||
if ("1".Equals(this.BillModel.DetailDoubleClickTip) && gridColumns[repeatProduct] != null && dataTable.Columns.Contains(repeatProduct))
|
||
{
|
||
//上面方法无法处理大小写,改成搜索的形式
|
||
DataTable dt = (this.gcMain as TreeGridControlEx).TreeListObj.DataSource as DataTable;
|
||
if (dt != null && dt.Rows.Count > 0 && dt.Columns.Contains(repeatProduct))
|
||
{
|
||
DataRow[] drs = dt.Select(repeatProduct + "='" + rowItem[repeatProduct] + "'");
|
||
if (drs.Length >= 1)
|
||
{
|
||
DialogResult dialog = MessageUtil.Show(ResourceKeys.ProductIsRepet, MessageBoxButtons.YesNo);
|
||
if (dialog != DialogResult.Yes)
|
||
return;
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
DataRow newRow = gridTable.NewRow();
|
||
newRow.BeginEdit();
|
||
// 赋值明细字段
|
||
foreach (TreeListColumn col in gridColumns)
|
||
{
|
||
try
|
||
{
|
||
GridColumnModel model = col.Tag as GridColumnModel;
|
||
if (dataTable.Columns.Contains(col.FieldName))
|
||
{
|
||
// 来源列中是否包含对应字段,包含则使用值
|
||
newRow[col.FieldName] = rowItem[col.FieldName];
|
||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||
{
|
||
this.SetUnionValue(model, rowItem[col.FieldName] + "", newRow);
|
||
}
|
||
SetCalcValue(model, rowItem[col.FieldName] + "", newRow);
|
||
}
|
||
else
|
||
{
|
||
// 未包含字段,则使用控件默认值.
|
||
if (col.FieldName.Contains("_Ls"))
|
||
{
|
||
string[] unioFielName = col.FieldName.Split('_');
|
||
string UnioValue = unioFielName[unioFielName.Length - 1];
|
||
DataColumn grid = dataTable.Columns.Cast<DataColumn>().FirstOrDefault(x => x.ColumnName.Split('_')[x.ColumnName.Split('_').Length - 1].Equals(UnioValue));
|
||
if (grid != null && !string.IsNullOrEmpty(model.UnionFields))
|
||
{
|
||
this.SetUnionValue(model, rowItem[col.FieldName] + "", newRow);
|
||
}
|
||
SetCalcValue(model, rowItem[col.FieldName] + "", newRow);
|
||
|
||
}
|
||
else
|
||
{
|
||
string fieldValue = BaseImpl.GetDefaultValue(model.DefaultValue);
|
||
|
||
if (model.DefaultValue.Contains("{#"))
|
||
{
|
||
fieldValue = this.ControlObj.ReplaceParentControlValue(model.DefaultValue);
|
||
if (!string.IsNullOrEmpty(fieldValue))
|
||
{
|
||
newRow[col.FieldName] = fieldValue;
|
||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||
{
|
||
this.SetUnionValue(model, fieldValue + "", newRow);
|
||
}
|
||
SetCalcValue(model, fieldValue + "", newRow);
|
||
|
||
//计算规则配置在结果字段上,所以无需验证当前操作控件
|
||
//this.gcMain.GridView.SetFocusedRowCellValue(col, fieldValue);
|
||
}
|
||
}
|
||
else if (!string.IsNullOrEmpty(model.DefaultValue))
|
||
{
|
||
newRow[col.FieldName] = fieldValue;
|
||
if (!string.IsNullOrEmpty(model.UnionFields))
|
||
{
|
||
this.SetUnionValue(model, fieldValue + "", newRow);
|
||
}
|
||
SetCalcValue(model, fieldValue + "", newRow);
|
||
|
||
}
|
||
}
|
||
}
|
||
SetDisableColumn(model, newRow[col.FieldName] + "", newRow);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Instance.WriteError(ex);
|
||
}
|
||
}
|
||
// newRow[(this.gcMain as TreeGridControlEx).TreeListObj.KeyFieldName] = (this.gcMain as TreeGridControlEx).GetNewNodesId();//节点id
|
||
newRow.EndEdit();
|
||
gridTable.Rows.Add(newRow);
|
||
|
||
position++;
|
||
|
||
if (!string.IsNullOrEmpty(NumberMc) && gridTable.Columns.Contains(mRecordPrimaryField))
|
||
{
|
||
DataRow[] rt = gridTable.Rows.Cast<DataRow>().Where(x => (newRow[BillModel.DetailPreFix + "ProductId"] + "").Equals(x[BillModel.DetailPreFix + "ProductId"] + "") && !string.IsNullOrEmpty(x[mRecordPrimaryField] + "")).ToArray();
|
||
foreach (DataRow item in rt)
|
||
{
|
||
if (newRow != null)
|
||
{
|
||
newRow[NumberMc] = Convert.ToDouble(newRow[NumberMc]) - Convert.ToDouble(item[NumberMc]);
|
||
}
|
||
//(this.gcMain as TreeGridControlEx).GcMain_CellValueChanged(this.gcMain as TreeGridControlEx, new CellValueChangedEventArgs(position, this.gcMain.GridView.Columns[NumberMc], newRow[NumberMc] + ""));
|
||
//this.gcMain.GridView.UpdateCurrentRow();
|
||
//this.gcMain.GridView.ShowEditor();
|
||
if (Convert.ToDouble(newRow[NumberMc] + "") == 0.0)
|
||
{
|
||
gridTable.Rows.Remove(newRow);
|
||
MessageUtil.Show("数量已分配完毕!无需再进行拖拽!");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (onlyOne)
|
||
{
|
||
onlyOne = false;
|
||
if (!string.IsNullOrEmpty(unionModel.ModelObj.DetailEnableMsg))
|
||
{
|
||
if (unionModel.ModelObj.DetailEnableMsg.StartsWith("select", StringComparison.OrdinalIgnoreCase) ||
|
||
unionModel.ModelObj.DetailEnableMsg.StartsWith("exec", StringComparison.OrdinalIgnoreCase))
|
||
{
|
||
MessageUtil.Show(BaseImpl.GetResult(unionModel.ModelObj.DetailEnableMsg) + "");
|
||
}
|
||
else
|
||
{
|
||
MessageUtil.Show(unionModel.ModelObj.DetailEnableMsg);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
(this.gcMain as TreeGridControlEx).SetGridViewDataSourceGenerateID(gridTable);
|
||
//this.gcMain.GridControl.DataSource = gridTable;
|
||
//if (position >= 0)
|
||
// this.gcMain.GridView.SelectRowHandler(position);
|
||
//else
|
||
// this.gcMain.GridView.SelectRowHandler(gridTable.Rows.Count - 1);
|
||
|
||
//gridTable.OrderBy(this.BillModel.DetailOrderField);
|
||
//this.gcMain.GridView.UpdateCurrentRow();
|
||
//this.gcMain.GridView.ShowEditor();
|
||
gridTable.OrderBy(this.BillModel.DetailOrderField);
|
||
(this.gcMain as TreeGridControlEx).DataSourceSorting();
|
||
WaitForm.HideForm();
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 来源拖拽到主表明细中
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void DragDetailGrid_OnDragMainGridCompleted(object sender, GridDragTreeGridArgs e)
|
||
{
|
||
if (e.GridViewSelectRows == null || e.GridViewSelectRows.Length == 0) return;
|
||
try
|
||
{
|
||
if (this.CanAddTreeDetailRow())
|
||
{
|
||
if (this.BillModel.DisableDragPrompt || MessageUtil.Show(ResourceKeys.DragSelectRow, MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||
{
|
||
XtraTabPage tabPage = this.xtc_left_container.SelectedTabPage;
|
||
BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel;
|
||
int FocuseIndex = e.GridViewObj.FocusedRowHandle;
|
||
int[] rows = e.GridViewObj.GetSelectedRows();
|
||
List<DataRow> DragRows = new List<DataRow>();
|
||
int i = 0;
|
||
foreach (int rowIndex in rows)
|
||
{
|
||
// 拖动多行,所以明细数据改为动态查询
|
||
DataRow rowItem = e.GridViewObj.GetDataRow(rowIndex);
|
||
this.RefreshSourceDetail(tabPage.Tag as BillSourceUnionModel);
|
||
DataTable details = BillImpl.GetDataTableResult(ReplaceHelper.ReplaceRowParam(rowItem, unionModel.ModelObj.DetailSql));
|
||
if (unionModel.ModelObj.sourceDetailType != "1" && unionModel.GridDetailControlObj.GridView != null && rowIndex == FocuseIndex)
|
||
{
|
||
if (SystemInfo.Instance.SourceFilteringMobile)
|
||
{
|
||
details = unionModel.GridDetailControlObj.GridView.GetGridViewFilteredAndSortedDataToDataTable();
|
||
}
|
||
else
|
||
{
|
||
details = unionModel.GridDetailControlObj.GridControl.DataSource as DataTable;
|
||
}
|
||
}
|
||
else if (unionModel.ModelObj.sourceDetailType == "1" && unionModel.TreeGridDetailControlObj.TreeListObj != null && rowIndex == FocuseIndex)
|
||
{
|
||
details = unionModel.TreeGridDetailControlObj.TreeListObj.DataSource as DataTable;
|
||
}
|
||
this.ControlObj.SetAllControlValue(rowItem, this.BillModel.isReplaceFixed);
|
||
|
||
if (this.BillModel.SourceMainPushPullHide)
|
||
{
|
||
DragRows.Add(rowItem);
|
||
}
|
||
|
||
|
||
if (unionModel.ModelObj.CadDragDetail)
|
||
{
|
||
//清空当前主单明细表数据
|
||
//((this.gcMain as TreeGridControlEx).TreeListObj.DataSource as DataTable).Clear();
|
||
(this.gcMain as TreeGridControlEx).TreeListObj.OptionsBehavior.Editable = true;
|
||
this.AddMultiRowToGridView(details, unionModel);
|
||
}
|
||
|
||
//单据为新增状态,根据最后一行的内容设置红蓝单据
|
||
if (!this.BillModel.SaveState && rows.Length - 1 == i && rowItem.Table.Columns.Contains(this.BillModel.RtagidKey) && this.BillModel.BillFlag != 0 && this.BillModel.BillFlag != 1)
|
||
{
|
||
if ("0".Equals(rowItem[this.BillModel.RtagidKey] + ""))
|
||
{
|
||
this.rdBlue.Checked = true;
|
||
this.OnBlueStateClick(null, null);
|
||
}
|
||
if ("1".Equals(rowItem[this.BillModel.RtagidKey] + ""))
|
||
{
|
||
this.rdRed.Checked = true;
|
||
this.OnRedStateClick(null, null);
|
||
}
|
||
}
|
||
i++;
|
||
}
|
||
if (unionModel.ModelObj.DragAndSave && rows.Length == i && i != 0)
|
||
{
|
||
this.OnBillSaveClick(null, null);
|
||
}
|
||
|
||
|
||
if (this.BillModel.SourceMainPushPullHide && DragRows.Count > 0)
|
||
{
|
||
foreach (DataRow item in DragRows)
|
||
{
|
||
if (e.GridViewObj.GridControl.DataSourceTable().Rows.IndexOf(item) >= 0)
|
||
{
|
||
e.GridViewObj.GridControl.DataSourceTable().Rows.Remove(item);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Instance.WriteError(ex);
|
||
LogUtil.WriteError("单据来源表格拖拽完出错!", ex);
|
||
MessageUtil.Show(ResourceKeys.OperFault);
|
||
}
|
||
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:是否允许添加明细</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-06-06 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <returns><c>true</c> if this instance [can add detail row]; otherwise, <c>false</c>.</returns>
|
||
private bool CanAddTreeDetailRow()
|
||
{
|
||
// 检测是否正在筛选数据
|
||
if (!string.IsNullOrEmpty((this.gcMain as TreeGridControlEx).TreeListObj.FindFilterText.Trim()) ||
|
||
!string.IsNullOrEmpty((this.gcMain as TreeGridControlEx).TreeListObj.FilterPanelText.Trim()))
|
||
{
|
||
if (MessageUtil.Show(ResourceKeys.GridViewSearching, MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||
{
|
||
(this.gcMain as TreeGridControlEx).TreeListObj.FindFilterText = "";
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
// 检测是否点击了排序表格
|
||
if ((this.gcMain as TreeGridControlEx).IsColumnSorted())
|
||
{
|
||
(this.gcMain as TreeGridControlEx).ClearAllSort();
|
||
}
|
||
// 检测是否为提交或者终审模块
|
||
string text = Business.Impl.LanguageTranslation.Translatable ? Business.Impl.LanguageTranslation.GetTranslatedText("已终审") : "已终审";
|
||
if (_waterMark.Text.Contains(text) && !this.BillModel.BillFinalReviewAdd)
|
||
{
|
||
MessageUtil.Show(ResourceKeys.AddBillDetailed);
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:检查可用条件</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-11-09 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="cond">The cond.</param>
|
||
/// <param name="dataRow">The data row.</param>
|
||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
|
||
private bool ValidateCond(string cond, DataRow dataRow)
|
||
{
|
||
bool result = false;
|
||
string condition = cond;
|
||
try
|
||
{
|
||
if (string.IsNullOrWhiteSpace(cond)) return true;//如果值是空格或者空行,默认正确
|
||
cond = ReplaceHelper.ReplaceRowParam(dataRow, cond);
|
||
if (cond.StartsWith("@") || cond.StartsWith("!"))
|
||
{
|
||
result = "1".Equals(BaseImpl.GetDefaultValue(cond));
|
||
}
|
||
else if (dataRow == null)
|
||
{
|
||
result = ReplaceHelper.EvalCond(cond);
|
||
}
|
||
else
|
||
{
|
||
result = ReplaceHelper.ReplaceRowParamCond(dataRow, cond);
|
||
}
|
||
return result;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
}
|
||
return result;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 页签里数据修改后刷新主表和主表明细
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void Tab_OnDetailSaveGridCallBack(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
this.SetBillStatus(BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, this.lblOrderNo.Text)));
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 扫码回车事件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void Text_KeyDown(object sender, KeyEventArgs e)
|
||
{
|
||
if (e.KeyCode == Keys.Enter)
|
||
{
|
||
TextEdit textEdit = sender as TextEdit;
|
||
string inputText = textEdit.Text;
|
||
if (!string.IsNullOrWhiteSpace(this.BillModel.CodeExecuteSql) && !string.IsNullOrWhiteSpace(this.BillModel.CodeExecuteParameter))
|
||
{
|
||
if (inputText.Length > 50)
|
||
{
|
||
MessageUtil.Show("扫码长度过长,请重新扫码");
|
||
return;
|
||
}
|
||
|
||
//获取选中行
|
||
DataRow MainRowItem = gcMain.GridView.GetFocusedDataRow();
|
||
if (MainRowItem == null)
|
||
{
|
||
MainRowItem = gcMain.GridControl.DataSourceTable().NewRow();
|
||
}
|
||
//获取红蓝单据
|
||
string DocumentColor = this.rdBlue.Checked ? "0" : this.rdRed.Checked ? "1" : "";
|
||
//数量,默认为1
|
||
int Quantity = 1;
|
||
/*
|
||
A:弹框输入数量
|
||
B;不弹框,默认数量为1
|
||
C:配置了扫码关联模块,根据数量sql结果。判断是否弹窗。数量默认为1
|
||
|
||
this.BillModel.ScanCodeFixedPrefix为条码前缀,扫码内容前缀和配置相同,默认为B
|
||
*/
|
||
string Type = string.Empty;
|
||
if (!string.IsNullOrWhiteSpace(this.BillModel.ScanCodeFixedPrefix) && inputText.StartsWith(this.BillModel.ScanCodeFixedPrefix))
|
||
{
|
||
Type = "B";
|
||
}
|
||
else
|
||
{
|
||
string Sql = string.Format("select line_str from wms_ScanCodeLinetab a where modid='{0}' and hl_tig='{1}'", this.SysModel.ModuleCode, DocumentColor);
|
||
Type = SqlHelper.ExecuteScalar(Sql) + "";
|
||
if (string.IsNullOrWhiteSpace(Type))
|
||
{
|
||
MessageUtil.Show("扫码配置错误,请联系朗速服务人员");
|
||
return;
|
||
}
|
||
}
|
||
switch (Type.ToUpper())
|
||
{
|
||
case "A":
|
||
|
||
FrmAdd frmAdd = new FrmAdd();
|
||
if (frmAdd.ShowDialog() == DialogResult.OK)
|
||
{
|
||
Quantity = frmAdd.Quantity;
|
||
}
|
||
else
|
||
{
|
||
textEdit.EditValue = "";
|
||
textEdit.Focus();
|
||
return;
|
||
}
|
||
this.ExecuteWcanningSQL(MainRowItem, Quantity + "", DocumentColor, inputText);
|
||
break;
|
||
case "B":
|
||
this.ExecuteWcanningSQL(MainRowItem, Quantity + "", DocumentColor, inputText);
|
||
break;
|
||
case "C":
|
||
if (!string.IsNullOrWhiteSpace(this.BillModel.ScanCodeModuleCode))
|
||
{
|
||
//根据传入的模块号获取模块信息
|
||
DataRow modelRow = MainImpl.GetSystemdllTab(this.BillModel.ScanCodeModuleCode);//获取模块信息
|
||
if (modelRow == null)
|
||
{
|
||
MessageUtil.Show("模块编号[" + this.BillModel.ScanCodeModuleCode + "],配置错误!\r\n该模块信息未找到!");
|
||
return;
|
||
}
|
||
if (modelRow.Table.Columns.Contains("countSql") && !string.IsNullOrWhiteSpace(modelRow["countSql"] + ""))
|
||
{
|
||
string sql = modelRow["countSql"] + "";
|
||
sql = ReplaceHelper.ReplaceUserInfo(sql);
|
||
sql = ReplaceHelper.ReplaceParamToValue(sql, "{value}", inputText);
|
||
string num = SqlHelper.ExecuteScalar(sql) + "";
|
||
num = this.IsNumberic(num) ? num : "0";
|
||
if (int.Parse(num) == 0)
|
||
{
|
||
MessageUtil.Show("未检测到扫码信息存在,请检查相应前序业务!");
|
||
}
|
||
else if (int.Parse(num) == 1)
|
||
{
|
||
this.ExecuteWcanningSQL(MainRowItem, Quantity + "", DocumentColor, inputText);
|
||
}
|
||
else if (int.Parse(num) > 1)
|
||
{
|
||
FrmScanCodeAssociation frmScanCodeAssociation = new FrmScanCodeAssociation(modelRow, inputText);
|
||
if (frmScanCodeAssociation.ShowDialog() == DialogResult.OK)
|
||
{
|
||
string Codes = frmScanCodeAssociation.StringCodes;
|
||
this.ExecuteWcanningSQL(MainRowItem, Quantity + "", DocumentColor, Codes);
|
||
}
|
||
else
|
||
{
|
||
textEdit.EditValue = "";
|
||
textEdit.Focus();
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
MessageUtil.Show("扫码配置错误");
|
||
return;
|
||
}
|
||
break;
|
||
|
||
}
|
||
}
|
||
|
||
|
||
//刷新单据管理(sourceType=2)
|
||
foreach (XtraTabPage tabPage in this.xtc_left_container.TabPages)
|
||
{
|
||
BillSourceUnionModel model = tabPage.Tag as BillSourceUnionModel;
|
||
if (model != null && model.GridControlObj != null && model.ModelObj.SourceType == 2)
|
||
{
|
||
this.RefreshSource(model);
|
||
}
|
||
}
|
||
//刷新下方配置的附件模块
|
||
this.OngcMainRowCellClick(null, null);
|
||
|
||
textEdit.EditValue = "";
|
||
textEdit.Focus();
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 执行扫码的存储过程
|
||
/// </summary>
|
||
/// <param name="MainRowItem">明细选中行</param>
|
||
///<param name="Quantity">数量</param>
|
||
///<param name="DocumentColor">红蓝单据字段</param>
|
||
///<param name="Codes">串码,多个用;隔开</param>
|
||
public void ExecuteWcanningSQL(DataRow MainRowItem, string Quantity, string DocumentColor, string Codes)
|
||
{
|
||
int j = 0;
|
||
foreach (string code in Codes.TrimEnd(';').Split(';'))
|
||
{
|
||
if (string.IsNullOrWhiteSpace(code)) continue;
|
||
List<string> Parameter = this.BillModel.CodeExecuteParameter.Split(',').ToList();
|
||
for (int i = 0; i < Parameter.Count; i++)
|
||
{
|
||
string item = Parameter[i];
|
||
if (item.Contains("{DocumentColor}"))
|
||
{
|
||
item = ReplaceHelper.ReplaceParamToValue(item, "{DocumentColor}", DocumentColor);
|
||
}
|
||
if (item.Contains("{amount}"))
|
||
{
|
||
item = Quantity + "";
|
||
}
|
||
//替换单据号
|
||
item = ReplaceHelper.ReplaceParamToValue(item, "{" + this.BillModel.PrimaryKey + "}", this.lblOrderNo.Text);
|
||
//替换选中行(没有就传空)
|
||
item = ReplaceHelper.ReplaceRowParam(MainRowItem, item);
|
||
//替换扫码内容
|
||
item = ReplaceHelper.ReplaceParamToValue(item, "{value}", code);
|
||
Parameter[i] = item;
|
||
}
|
||
|
||
|
||
List<string> procParams = ReplaceHelper.GetParamFields(this.BillModel.CodeExecuteSql);
|
||
List<SqlParameter> sqlParamList = new List<SqlParameter>();
|
||
string[] paramStr = procParams[0].Replace("{", "").Replace("}", "").Split(',');
|
||
SqlParameter pMsg = new SqlParameter("@msg", SqlDbType.VarChar, 2000);
|
||
|
||
for (int i = 0; i < paramStr.Length; i++)
|
||
{
|
||
string item = paramStr[i];
|
||
if (paramStr[i].Equals("@msg", StringComparison.OrdinalIgnoreCase))
|
||
{
|
||
pMsg.Direction = ParameterDirection.InputOutput;
|
||
pMsg.Value = Parameter.Count > i ? string.IsNullOrEmpty(Parameter[i]) ? "" : Parameter[i] : "";
|
||
sqlParamList.Add(pMsg);
|
||
}
|
||
else
|
||
{
|
||
string paramStr1 = paramStr[i];
|
||
SqlParameter param = new SqlParameter(string.Format("{0}", paramStr1), SqlDbType.VarChar);
|
||
param.Value = Parameter[i];
|
||
sqlParamList.Add(param);
|
||
}
|
||
}
|
||
SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int, 4);
|
||
returnValue.Direction = ParameterDirection.ReturnValue;
|
||
int result;
|
||
sqlParamList.Add(returnValue);
|
||
|
||
try
|
||
{
|
||
result = MainImpl.ExecProcedure(this.BillModel.CodeExecuteSql.Replace(procParams[0], "").Trim(), sqlParamList.ToArray());
|
||
}
|
||
catch (SqlException sex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(sex);
|
||
MessageUtil.Show(Message, sex.Message);
|
||
return;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
return;
|
||
}
|
||
int rValue = Convert.ToInt32(returnValue.Value);
|
||
string varchar = pMsg.Value + "";
|
||
switch (rValue)
|
||
{
|
||
case 1:
|
||
if (string.IsNullOrWhiteSpace(varchar))
|
||
{
|
||
//刷新当前单据
|
||
if (j == Codes.TrimEnd(';').Split(';').Length - 1)
|
||
{
|
||
this.SetBillStatus(BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, this.lblOrderNo.Text)));
|
||
}
|
||
|
||
}
|
||
else
|
||
{
|
||
//刷新返回的单据号
|
||
this.lblOrderNo.Text = varchar;
|
||
this.SetBillStatus(BillImpl.GetDataRowResult(string.Format("select * from {0} where {1}='{2}'", BillModel.MasterTable, BillModel.PrimaryKey, varchar)));
|
||
}
|
||
break;
|
||
case -1:
|
||
MessageUtil.Show(ResourceKeys.OperFault + "\n" + pMsg.Value);
|
||
break;
|
||
}
|
||
j++;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 判断是不是数值
|
||
/// </summary>
|
||
/// <param name="oText"></param>
|
||
/// <returns></returns>
|
||
private bool IsNumberic(string oText)
|
||
{
|
||
try
|
||
{
|
||
int var1 = Convert.ToInt32(oText);
|
||
return true;
|
||
}
|
||
catch
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 打开来源模块,并把选中的数据反写到主表明细中
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void OpenTheSourcePopup(object sender, EventArgs e)
|
||
{
|
||
string SourceId = sender + "";
|
||
if (string.IsNullOrWhiteSpace(SourceId)) return;
|
||
FrmDocumentSource frmSource = new FrmDocumentSource(SourceId);
|
||
frmSource.WindowState = FormWindowState.Maximized;
|
||
if (frmSource.ShowDialog() == DialogResult.OK)
|
||
{
|
||
this.gcMain.GridView.BeginUpdate();
|
||
foreach (DataRow rowItem in frmSource.DataRows)
|
||
{
|
||
this.AddRowToGridView(rowItem);
|
||
}
|
||
this.gcMain.GridView.EndUpdate();
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 所有粘贴完成后执行
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void OnAllAfterParseCallBack(object sender, EventArgs e)
|
||
{
|
||
DataTable gridTable = (this.gcMain.GridControl.DataSource as DataTable).TrimDeleteRows();
|
||
gridTable.OrderBy(this.BillModel.DetailOrderField);
|
||
this.gcMain.GridView.UpdateCurrentRow();
|
||
this.gcMain.GridView.ShowEditor();
|
||
}
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:设置图片事件</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-02-27 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
private void SetImageEvent(DataTable table)
|
||
{
|
||
if (table == null || table.Rows.Count == 0) return;
|
||
DataRow[] imageRows = table.Select("fieldTypeId=" + (int)ControlType.LabPicEx);
|
||
|
||
foreach (DataRow item in imageRows)
|
||
{
|
||
string fieldName = item["fieldName"] + "";
|
||
LabelImageEdit imageEdit = this.ControlObj.FindControl(fieldName) as LabelImageEdit;
|
||
if (imageEdit != null)
|
||
{
|
||
imageEdit.UploadEvent += new LabelImageEdit.UploadEventHander(OnImageUploadEvent);
|
||
imageEdit.DeleteEvent += new LabelImageEdit.DeleteEventHander(OnImageDeleteEvent);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// <para>说明:上传附件</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-02-27 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
protected void OnImageUploadEvent(object sender)
|
||
{
|
||
try
|
||
{
|
||
_imageEdit = sender as LabelImageEdit;
|
||
if (string.IsNullOrWhiteSpace(this.lblOrderNo.Text))
|
||
{
|
||
MessageUtil.Show(ResourceKeys.UnSaveData);
|
||
}
|
||
else
|
||
{
|
||
//string prefix = "001";
|
||
//string imagePath = _imageEdit.SaveImageToLocal(prefix);
|
||
OpenFileDialog openFileDialog = new OpenFileDialog();
|
||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||
{
|
||
WaitForm.ShowForm("上传中...");
|
||
if (!string.IsNullOrEmpty(openFileDialog.FileName))
|
||
{
|
||
Image image = null;
|
||
bool isImage = true;
|
||
try
|
||
{
|
||
image = Image.FromFile(openFileDialog.FileName);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
isImage = false;
|
||
}
|
||
if (image != null && isImage)
|
||
{
|
||
_imageEdit.TextEdit.Image = image;
|
||
}
|
||
else
|
||
{
|
||
_imageEdit.TextEdit.Image = global::Lskj.Control.Properties.Resources.file;
|
||
}
|
||
_imageEdit.CurrentImagePath = openFileDialog.FileName;
|
||
}
|
||
else
|
||
{
|
||
_imageEdit.CurrentImagePath = string.Empty;
|
||
}
|
||
string imagePath = _imageEdit.CurrentImagePath;
|
||
if (!string.IsNullOrEmpty(imagePath))
|
||
{
|
||
//string speciesNo = string.IsNullOrEmpty(lteSpeciesNo.TextEdit.Text) ? "01" : lteSpeciesNo.TextEdit.Text;
|
||
//int directotyId = AttachImpl.GetAttachDirectoryId(this.SysModel.MenuDirId + "", this.PrimaryValue);
|
||
//AttachHelper.UpLoadFile(this.Handle, directotyId + "", speciesNo, "001", imagePath);
|
||
bool isSuccess = UploadFile(imagePath);
|
||
if (!isSuccess)
|
||
{
|
||
_imageEdit.CurrentImagePath = string.Empty;
|
||
_imageEdit.TextEdit.Image = null;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
MessageUtil.Show("未选择上传文件");
|
||
}
|
||
WaitForm.HideForm();
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// 上传附件(新)
|
||
/// </summary>
|
||
private bool UploadFile(string filePath)
|
||
{
|
||
bool isUpload = true;
|
||
try
|
||
{
|
||
string token = "";
|
||
string loginUrl = $"{SystemInfo.Instance.OAUrl}/Api/SysUserAjaxApi.ashx";
|
||
HttpTools.setting("application/x-www-form-urlencoded", null, null, HttpTools.Encode.UTF8);
|
||
Dictionary<string, string> loginPmsDic = new Dictionary<string, string>();
|
||
loginPmsDic.Add("method", "Login");
|
||
loginPmsDic.Add("username", ERPInfo.Instance.UserName);
|
||
loginPmsDic.Add("password", ERPInfo.Instance.InPassWord);
|
||
HttpWebResponse loginResponse = HttpTools.Post(loginUrl, "", loginPmsDic, HttpTools.Method.POST, out CookieCollection loginCookie, out string loginResult);
|
||
if (loginResponse != null && !string.IsNullOrEmpty(loginResult))
|
||
{
|
||
JObject jObject = JsonConvert.DeserializeObject<JObject>(loginResult);
|
||
if (jObject.ContainsKey("success"))
|
||
{
|
||
if ((jObject["success"] + "").Equals("True"))
|
||
{
|
||
if (jObject.ContainsKey("token"))
|
||
{
|
||
token = jObject["token"] + "";
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(token))
|
||
{
|
||
byte[] fileBytes = ConvertFileToBytes(filePath);
|
||
string fileBase64Str = Convert.ToBase64String(fileBytes) + "";
|
||
string postUrl = "{0}Api/FileUploadApi.ashx?moduleId={1}&idValue={2}&folder={3}&totsize={4}&position={5}&filename={6}&method={7}";
|
||
Dictionary<string, string> headerDic = new Dictionary<string, string>();
|
||
headerDic.Add("Authorization", $"Bearer {token}");
|
||
postUrl = string.Format(postUrl, SystemInfo.Instance.OAUrl, this.SysModel.ModuleCode, this.lblOrderNo.Text, "UploadFilesTemp", fileBytes.Length, 0, System.Web.HttpUtility.UrlEncode($"{Guid.NewGuid()}_{Path.GetFileName(_imageEdit.CurrentImagePath)}"), "DoWebUpload");
|
||
HttpTools.setting("application/x-www-form-urlencoded", null, null);
|
||
HttpWebResponse webResponse = HttpTools.Post(postUrl, fileBase64Str, null, headerDic, HttpTools.Method.POST, out CookieCollection cookieCollection, out string result);
|
||
if (webResponse != null && !string.IsNullOrEmpty(result))
|
||
{
|
||
JObject jsonObject = (JObject)JsonConvert.DeserializeObject(result);
|
||
string isSuccess = jsonObject["success"] + "";
|
||
if (isSuccess.Equals("True", StringComparison.CurrentCultureIgnoreCase))
|
||
{
|
||
string fileId = jsonObject["other"] + "";
|
||
string webpath = jsonObject["data"]["WebRelPath"] + "";
|
||
BaseModuleImpl.UpdateRecord(this.BillModel.MasterTable, _imageEdit.Model.FieldName, webpath, this.BillModel.PrimaryKey, this.lblOrderNo.Text);
|
||
//string searchSql = @"update P_fm_FileTab set author='{2}',CreationTime='{3}' ,Uploader='{4}' ,UploadTime='{5}'
|
||
// where dllcoid = '{0}' and
|
||
// parentid = (select dirid from P_fm_DirectoryTab where
|
||
// ParentId = (select dirid from v_systemdlltab where DllCoid = '{0}') and PID = '{1}') and fileId='{6}' ";
|
||
//searchSql = string.Format(searchSql, this.Model.ModuleCode, this.leftTreeGridIdValue, dataRow["author"], fi.CreationTime, ERPInfo.Instance.UserName, dataRow["UploadTime"], fileId);
|
||
//SqlHelper.ExecuteNonQuery(searchSql);
|
||
}
|
||
else
|
||
{
|
||
if (jsonObject.ContainsKey("msg"))
|
||
{
|
||
string returnMsg = jsonObject["msg"] + "";
|
||
MessageUtil.Show(string.Format("上传失败,原因:{0}", returnMsg));
|
||
}
|
||
isUpload = false;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
MessageUtil.Show(string.Format("上传失败,原因:{0}", result));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
MessageUtil.Show(string.Format("验证失败,原因:{0}", loginResult));
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageUtil.Show(string.Format("上传失败,原因:{0}", ex.Message));
|
||
isUpload = false;
|
||
}
|
||
return isUpload;
|
||
}
|
||
/// <summary>
|
||
/// 附件转换byte[]
|
||
/// </summary>
|
||
/// <param name="filePath">附件路径</param>
|
||
/// <returns>二进制</returns>
|
||
private byte[] ConvertFileToBytes(string filePath)
|
||
{
|
||
byte[] bytContent = null;
|
||
System.IO.FileStream fs = null;
|
||
System.IO.BinaryReader br = null;
|
||
try
|
||
{
|
||
fs = new FileStream(filePath, System.IO.FileMode.Open, FileAccess.Read, FileShare.Read);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
throw;
|
||
}
|
||
if (fs != null)
|
||
br = new BinaryReader((Stream)fs);
|
||
if (br != null)
|
||
bytContent = br.ReadBytes((Int32)fs.Length);
|
||
if (fs != null)
|
||
fs.Dispose();
|
||
return bytContent;
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:删除附件</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2018-02-27 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="sender">The sender.</param>
|
||
protected void OnImageDeleteEvent(object sender)
|
||
{
|
||
try
|
||
{
|
||
LabelImageEdit imageEdit = sender as LabelImageEdit;
|
||
if (imageEdit != null)
|
||
{
|
||
int result = BaseModuleImpl.UpdateRecord(this.BillModel.MasterTable, imageEdit.Model.FieldName, "", this.BillModel.PrimaryKey, this.lblOrderNo.Text);
|
||
MessageUtil.Show(result > 0 ? ResourceKeys.OperSuccess : ResourceKeys.OperFault);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||
MessageUtil.Show(Message, ex.Message);
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 设置打印按钮条件
|
||
/// </summary>
|
||
/// <param name="dataRow"></param>
|
||
public bool SetPrintButton(DataRow rowItem)
|
||
{
|
||
try
|
||
{
|
||
bool result = false;
|
||
//判断打印按钮条件
|
||
if (!string.IsNullOrWhiteSpace(this.BillModel.PrintingConditions))
|
||
{
|
||
if (rowItem == null) return result;
|
||
|
||
string cond = ReplaceHelper.ReplaceRowParam(rowItem, this.BillModel.PrintingConditions);
|
||
if (cond.StartsWith("@") || cond.StartsWith("!"))
|
||
{
|
||
result = "1".Equals(BaseImpl.GetDefaultValue(cond));
|
||
}
|
||
else
|
||
{
|
||
result = ReplaceHelper.ReplaceRowParamCond(rowItem, cond);
|
||
}
|
||
return result;
|
||
}
|
||
else
|
||
{
|
||
return true;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 改变选中行的颜色
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void GridView_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e)
|
||
{
|
||
XtraTabPage tabPage = this.xtc_left_container.SelectedTabPage;
|
||
BillSourceUnionModel unionModel = tabPage.Tag as BillSourceUnionModel;
|
||
if (unionModel != null && unionModel.GridDetailControlObj.GridView != null)
|
||
{
|
||
int sourceIdx = unionModel.GridDetailControlObj.GridView.GetDataSourceRowIndex(e.RowHandle);
|
||
if (ColorHandles.Contains(sourceIdx))
|
||
e.Appearance.BackColor = ColorTranslator.FromHtml(this.BillModel.SelectSourceColor);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 清空记录的选中行
|
||
/// </summary>
|
||
/// <param name="gridview"></param>
|
||
public void ClearHighlightRows(GridView gridview)
|
||
{
|
||
if (this.BillModel.IsSelectSourceColor && ColorHandles.Count > 0)
|
||
{
|
||
ColorHandles.Clear();
|
||
gridview.Invalidate();
|
||
}
|
||
}
|
||
|
||
|
||
public bool VerificationCond()
|
||
{
|
||
|
||
DataTable detailTable = this.gcMain.GridControl.DataSourceTable().TrimDeleteRows();
|
||
|
||
foreach (DataRow CondItem in SaveCondTab.Rows)
|
||
{
|
||
string condition = CondItem["condition"] + "";
|
||
if (!string.IsNullOrWhiteSpace(condition))
|
||
{
|
||
|
||
if (detailTable != null && detailTable.Rows.Count > 0)
|
||
{
|
||
condition = this.ControlObj.ReplaceParentControlValue(condition);
|
||
foreach (DataRow item in detailTable.Rows)
|
||
{
|
||
if (!ValidateCond(condition, item))
|
||
{
|
||
MessageUtil.Show(string.IsNullOrWhiteSpace(CondItem["hintmsg"] + "") ? "条件验证失败" : CondItem["hintmsg"] + "");
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
List<string> conditionlist = ReplaceHelper.GetParamFields(condition);
|
||
foreach (string item in conditionlist)
|
||
{
|
||
if (!item.Contains("{#")) continue;//只有所有替换参数都包含了{#的(全部都是主表参数),才会去验证条件
|
||
}
|
||
condition = this.ControlObj.ReplaceParentControlValue(condition);
|
||
if (!ValidateCond(condition, null))
|
||
{
|
||
MessageUtil.Show(string.IsNullOrWhiteSpace(CondItem["hintmsg"] + "") ? "条件验证失败" : CondItem["hintmsg"] + "");
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
}
|
||
} |