Files
lserp_cs_6.0/插件库/Lskj.PubAccraditation/FrmAccraditation.cs
T
2026-08-04 13:49:05 +08:00

4574 lines
225 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/***********************
* 说明:单据审批弹出模块
* 创建人:龚宇超
* 创建日期:2018-01-02
* 修改人:
* 修改日期:
* 修改备注:
* 版本:1.0.0.0
***********************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Lskj.Control;
using Lskj.Control.Model;
using Lskj.Util;
using Lskj.Data;
using Lskj.Model;
using Lskj.Business.Impl;
using DevExpress.XtraEditors;
using DevExpress.XtraTab;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Grid;
using Lskj.Business;
using DevExpress.XtraBars;
using System.Collections;
using Lskj.Core;
using System.Threading.Tasks;
using DevExpress.Utils;
using DevExpress.Data;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.IO;
namespace Lskj.PubAccraditation
{
/// <summary>
/// 单据审批弹出模块
/// </summary>
public partial class FrmAccraditation : BaseForm
{
public FrmAccraditation()
{
InitializeComponent();
}
#region 公有变量
/// <summary>
/// 单据结构明细
/// </summary>
public AccraditationModel AuditModelObj;
/// <summary>
/// 单据模型
/// </summary>
public BillAuditModel BillModelObj;
/// <summary>
/// 单据审批表模型
/// </summary>
public BillAuditCommonModel BillAuditComObj;
/// <summary>
/// 单据入口参数模型
/// </summary>
public DynamicPubAccraditionPopModel SysModel;
/// <summary>
/// 主表控件
/// </summary>
public MyControl ControlObj;
/// <summary>
/// 是否是Brp模块加载审核明细
/// </summary>
public bool isBrpAccrad = false;
#endregion
/// <summary>
/// 调用动态链接库默认传递参数
/// </summary>
public DynamicModel syModel { get; private set; }
/// <summary>
/// 关闭当前审核界面,刷新打开界面
/// </summary>
/// <param name="sender">The sender.</param>
public event RefreshThePage refreshThePage;
public delegate void RefreshThePage(string promptInformation, string id);
/// <summary>
/// 主表动态生成的日期列
/// </summary>
public List<GridColumn> DateColumnList = new List<GridColumn>();
/// <summary>
/// 主表动态生成的合计列
/// </summary>
public GridColumn SumGridColumn = new GridColumn();
#region 私有变量
/// <summary>
/// 数量名称
/// </summary>
public string NumberMc;
/// <summary>
/// 主键字段
/// </summary>
private string mRecordPrimaryField;
private string guidField = "xxxxx_guid";
/// <summary>
/// id(推送记录)
/// </summary>
private int _beforeId;
/// <summary>
/// 是否初始化完成
/// </summary>
private bool _isInitFinish;
/// <summary>
/// 意见
/// </summary>
private string _auditAdvice;
/// <summary>
/// 菜单模块名(推送记录)
/// </summary>
private string _beforeMenuName;
/// <summary>
/// 用户(推送记录)
/// </summary>
private string _beforeUsers;
/// <summary>
/// 单据类别值
/// </summary>
private string _mainBillTypeValue;
/// <summary>
/// 单据信息
/// </summary>
private DataRow _drBillInfoMsg;
/// <summary>
/// 明细数据
/// </summary>
private DataTable _dtSourceData;
/// <summary>
/// 单据类别
/// </summary>
private DataTable _dtBillType;
/// <summary>
/// 单据明细列表
/// </summary>
private DataTable _dtBillAttachList;
/// <summary>
/// 单据billInfo
/// </summary>
private DataTable _dtBillInfoFiled;
/// <summary>
/// 分单数据
/// </summary>
private DataTable _dtSpareSourceData;
/// <summary>
/// 审批流转模型
/// </summary>
private FlowTypeStepModel _flowTypeStepModel;
/// <summary>
/// 单据水印
/// </summary>
private WaterMark _waterMark;
/// <summary>
/// 获取隐藏的x轴距
/// </summary>
private ArrayList LocationX = new ArrayList();
/// <summary>
/// 是否执行了加载储存过程
/// </summary>
public bool ProcessExists = false;
// <summary>
/// 模块对应的权限表信息
/// </summary>
public DataTable AuthorityTable;
/// <summary>
/// 打印完成后添加数据用到的参数: 表名,列前缀,主键字段,主键值,模块编号,主打印Sql
/// </summary>
private List<string> _printSaveParams;
/// <summary>
/// 主打印Sql
/// </summary>
private string _mainPrintSql;
/// <summary>
/// 打印主sql中关联打印次数返回条件
/// </summary>
private string _printModeCond;
/// <summary>
/// 是否直接打印
/// </summary>
private bool _isExcPrint;
#endregion
/// <summary>
/// <para>说明:窗体加载时</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-02 </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>
protected override void OnLoad(EventArgs e)
{
WaitForm.ShowForm();
try
{
string results = @"IF EXISTS(SELECT * FROM SYSOBJECTS WHERE NAME ='p_Get_NewDesignPlatform_DocumentsReview' AND TYPE = 'P') begin select 1 end else Begin select 2 end";
if (SqlHelper.ConnectionType == ConnectionType.DmServer)
{
results = @"SELECT CASE WHEN EXISTS (
SELECT 1 FROM ALL_OBJECTS WHERE OBJECT_NAME = 'p_Get_NewDesignPlatform_DocumentsReview' AND OBJECT_TYPE = 'PROCEDURE')
THEN 1
ELSE 2
END AS result
FROM DUAL;";
}
results = BaseImpl.GetResult(results) + "";
if (results.Equals("1") && SystemInfo.Instance.isExecload)
{
System.Data.DataSet dsConfig = BillImpl.GetNewDesignPlatformDocumentsReview(SysModel, Lskj.Data.ResourceKeys.SettingTableName);
Lskj.Data.Caches.CacheSYSConfig.Instance().SetData(dsConfig);
ProcessExists = true;
}
this._isInitFinish = false;
this.splitMain.Visible = false;
this.InitializeSetting();
this.InitializeControl();
this.InitializeSplitterPosition();
if (SystemInfo.Instance.ReviewCommentsRequired)
{
label_auditPerson.ForeColor = string.IsNullOrEmpty(SystemInfo.Instance.ControlRequiredColor) ? Color.Blue : ColorTranslator.FromHtml(SystemInfo.Instance.ControlRequiredColor);
this.txtRemark.Text = "";
}
}
catch (Exception ex)
{
LogHelper.Instance.WriteError(ex, ResourceKeys.BaseModule);
LogUtil.WriteError("单据审批初始化出错!", ex);
//MessageUtil.Show(ex);
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
finally
{
Lskj.Control.Model.AutoSizeChange.ControllInitializeSize(this);
//2023-10-13 丁哥规定在明细的附加信息中配置双击参数(DBClickEvent),上方的AuditLoadDetailFlag失效
if (this.BillModelObj.DetailTreeTable)
{
(this.gridBillInfo as TreeGridControlEx).TreeListObj.FocusedNodeChanged += TreeListObj_FocusedNodeChanged;
(this.gridBillInfo as TreeGridControlEx).TreeListObj.DoubleClick += new EventHandler(gridView_DoubleClick);
}
else
{
this.gridBillInfo.GridView.FocusedRowObjectChanged += GridView_FocusedRowObjectChanged;//SelectionChanged事件会执行2次,故改成焦点行改变事件
this.gridBillInfo.GridView.DoubleClick += new EventHandler(gridView_DoubleClick);
}
WaitForm.HideForm();
this._isInitFinish = true;
this.splitMain.Visible = true;
InitButLocation();
}
}
#region 获取数据源缓存
/// <summary>
/// 获取数据源缓存
/// </summary>
/// <param name="cachesDic"></param>
public void GetDataCaches(Dictionary<object, Hashtable> cachesDic)
{
//全局数据
Task<DynamicModel> dynamicModelTask = cachesDic.AddTask(this, "DynamicModel", new Task<DynamicModel>(() =>
{
return SysModel;//动态链接库对象
}));
DynamicPubAccraditionPopModel dynamicModel = (DynamicPubAccraditionPopModel)dynamicModelTask.Result;
#region InitializeSetting
Task<DataRow> accraditationModelRowTask = cachesDic.AddTask(this, "AccraditationModelRow", new Task<DataRow>(() =>
{
return BillAuditImpl.GetBillFlowData(dynamicModel.ModuleCode, dynamicModel.StepCode);
}));
Task<AccraditationModel> accraditationModelTask = cachesDic.AddTask(this, "AccraditationModel", new Task<AccraditationModel>(() =>
{
return new AccraditationModel(accraditationModelRowTask.Result);
}));
Task<DataRow> billInfoTask = cachesDic.AddTask(this, "BillInfo", new Task<DataRow>(() =>
{
return BillImpl.GetBillInfo(dynamicModel.ModuleCode);//获取单个模块信息
}));
Task<BillAuditModel> billAuditModelTask = cachesDic.AddTask(this, "BillAuditModel", new Task<BillAuditModel>(() =>
{
BillAuditModel billAuditModel = new BillAuditModel(billInfoTask.Result);
Task<string> masterPreFixTask = cachesDic.AddTask(this, "MasterPreFix", new Task<string>(() =>
{
return BaseImpl.GetColumnPrefix(billAuditModel.MasterTable);
}));
Task<string> detailPreFixTask = cachesDic.AddTask(this, "DetailPreFix", new Task<string>(() =>
{
return BaseImpl.GetColumnPrefix(billAuditModel.DetailTable);// 明细表列前缀
}));
billAuditModel.MasterPreFix = masterPreFixTask.Result;
billAuditModel.DetailPreFix = detailPreFixTask.Result;
billAuditModel.DetailOrderField = detailPreFixTask.Result + "lsidx_id";// 单据来源id
return billAuditModel;
}));
Task<BillAuditCommonModel> billAuditCommonModelTask = cachesDic.AddTask(this, "BillAuditCommonModel", new Task<BillAuditCommonModel>(() =>
{
return new BillAuditCommonModel();
}));
Task<DataRow> menuConfigTabTask = cachesDic.AddTask(this, "MenuConfigTab", new Task<DataRow>(() =>
{
return BaseImpl.GetMenuConfigTab(dynamicModel.ModuleId); //获取菜单其他配置
}));
Task<int> fileCountTask = cachesDic.AddTask(this, "FileCount", new Task<int>(() =>
{
return AttachImpl.GetFileCount(billAuditModelTask.Result.DirId + "", dynamicModel.BillDocumentId);
}));
//记录推送用户
Task<DataRow> pushedOpersTask = cachesDic.AddTask(this, "PushedOpers", new Task<DataRow>(() =>
{
return BillAuditImpl.GetPushedOpers(dynamicModel.BillDocumentId, dynamicModel.StepCode);
}));
Task<DataTable> billInfoDataTask = cachesDic.AddTask(this, "BillInfoData", new Task<DataTable>(() =>
{
return BillAuditImpl.GetBillInfoData(dynamicModel.ModuleCode);
}));
#endregion
#region InitializeControl
Task<DataTable> readOnlyColumnsTask = cachesDic.AddTask(gridFlow, "ReadOnlyColumns", new Task<DataTable>(() =>
{
return BaseAuditImpl.GetFlowRecordColumn();
}));
string customColumKey = GridCustomColumnStruct.AuditPopupAttachGridView + billAuditModelTask.Result.FormKey;
cachesDic.AddTask(gridFlow, "DynamicModel", dynamicModelTask);
gridFlow.GetDataCaches(cachesDic, customColumKey);
Task<DataTable> gridViewDataSourceTask = cachesDic.AddTask(gridFlow, "GridViewDataSource", new Task<DataTable>(() =>
{
return BaseAuditImpl.GetFlowRecordData(billAuditCommonModelTask.Result.SystemTabFlowStep, dynamicModel.BillDocumentId, dynamicModel.ModuleCode);
}));
//BindTab
Task<List<GridDetailModel>> detailTask = cachesDic.AddTask(gridFlow, "Details", new Task<List<GridDetailModel>>(() =>
{
List<GridDetailModel> details = new List<GridDetailModel>();
DataTable table = BaseAuditImpl.GetAttachTabs(dynamicModel.ModuleCode, dynamicModel.StepCode);
foreach (DataRow item in table.Rows)
{
if (table.Columns.Contains("privilegeoper"))
{
string privilegeoper = item["privilegeoper"] + "";//配置的权限人员
if (string.IsNullOrWhiteSpace(privilegeoper) || privilegeoper.Split(',').Contains(ERPInfo.Instance.UserName))
{
GridDetailModel gridDetailModel = new GridDetailModel(item, null, GridCustomColumnStruct.AuditPopupBasicInfoGridView + item["formKey"] + "");
details.Add(gridDetailModel);
Task<DataTable> addGridColumnsTask = cachesDic.AddTask(gridDetailModel, "GridColumns", new Task<DataTable>(() =>
{
DataTable gridColumns = BaseAuditImpl.GetBottomBasicInformation(item["formKey"] + "");
gridDetailModel.GridColumns = gridColumns;
return gridColumns;
}));
}
}
else
{
GridDetailModel gridDetailModel = new GridDetailModel(item, null, GridCustomColumnStruct.AuditPopupBasicInfoGridView + item["formKey"] + "");
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;
}));
cachesDic.AddTask(tab_basicInfo, "DynamicModel", dynamicModelTask);
cachesDic.AddTask(tab_basicInfo, "Details", detailTask);
tab_basicInfo.GetDataCaches(cachesDic);
//BindBill
Task<DataTable> controlLocationTask = cachesDic.AddTask(this, "ControlLocation", new Task<DataTable>(() =>
{
return BaseModuleImpl.GetControlLocation(billAuditModelTask.Result.FormKey, dynamicModel.ModuleCode);
}));
Task<MyControl> controlObjTask = cachesDic.AddTask(this, "ControlObj", new Task<MyControl>(() =>
{
MyControl myControl = new MyControl();
myControl.Model = SysModel;
myControl.PrimaryValue = dynamicModel.BillDocumentId;
cachesDic.AddTask(myControl, "DynamicModel", dynamicModelTask);
cachesDic.AddTask(myControl, "ControlsTable", controlLocationTask);
myControl.GetControlDataCaches(cachesDic);
return myControl;
}));
Task<DataTable> detailColumnsTask = cachesDic.AddTask(gridBillInfo, "DetailColumns", new Task<DataTable>(() =>
{
return BillImpl.GetDetailColumns(dynamicModel.ModuleCode);
}));
string gridBillCustomColumKey = GridCustomColumnStruct.AuditPopupDetailGridView + billAuditModelTask.Result.FormKey;
cachesDic.AddTask(gridBillInfo, "DynamicModel", dynamicModelTask);
gridBillInfo.GetDataCaches(cachesDic, gridBillCustomColumKey);
Task<DataTable> baseGridRightMenusTask = cachesDic.AddTask(gridBillInfo, "BaseGridRightMenus", new Task<DataTable>(() =>
{
return BaseModuleImpl.GetBaseGridRightMenus(accraditationModelTask.Result.BillGridMenuFlag + dynamicModel.ModuleCode, ModuleType.BillAuditDetail);
}));
Task<DataTable> baseGridRowColorsTask = cachesDic.AddTask(gridBillInfo, "BaseGridRowColors", new Task<DataTable>(() =>
{
return BaseModuleImpl.GetBaseGridRowColors("BILLDETAIL_" + billAuditModelTask.Result.FormKey);
}));
//设置必填和修改字段
Task<DataRow> currentFlowRowDataTask = cachesDic.AddTask(this, "CurrentFlowRowData", new Task<DataRow>(() =>
{
DataRow currentFlowRowData = BaseAuditImpl.GetCurrentFlowRowData(billAuditModelTask.Result.MasterTable, billAuditModelTask.Result.PrimaryKey, dynamicModel.BillDocumentId);
if (currentFlowRowData != null)
{
string mainBillTypeValue = currentFlowRowData[billAuditModelTask.Result.BillType] + "";
if (!string.IsNullOrEmpty(mainBillTypeValue) && mainBillTypeValue != "0")
{
//SetButtonsStatus
Task<DataRow> billFlowStepTask = cachesDic.AddTask(this, "BillFlowStep", new Task<DataRow>(() =>
{
DataRow billFlowStep = BillAuditImpl.GetBillFlowStep(dynamicModel.ModuleCode, mainBillTypeValue, dynamicModel.StepCode);
if (billFlowStep != null)
{
Task<FlowTypeStepModel> flowTypeStepModelTask = cachesDic.AddTask(this, "FlowTypeStepModel", new Task<FlowTypeStepModel>(() =>
{
FlowTypeStepModel flowTypeStepModel = new FlowTypeStepModel(billFlowStep);
//LoadRemindRecord
if (flowTypeStepModel != null && !string.IsNullOrEmpty(flowTypeStepModel.RemindSelect))
{
Task<DataTable> remindinRecordTask = cachesDic.AddTask(gridRemind, "RemindinRecord", new Task<DataTable>(() =>
{
DataTable dt = BaseAuditImpl.GetRemindinRecord(billAuditCommonModelTask.Result.FlowStepTable, billAuditCommonModelTask.Result.ComfrimTable, dynamicModel.BillDocumentId, dynamicModel.ModuleCode);
if (dt != null && dt.Rows.Count > 0)
{
Task<DataTable> gridRemindReadOnlyColumnsTask = cachesDic.AddTask(gridRemind, "ReadOnlyColumns", new Task<DataTable>(() =>
{
return BaseAuditImpl.GetRemindColumn();
}));
cachesDic.AddTask(gridRemind, "DynamicModel", dynamicModelTask);
gridRemind.GetDataCaches(cachesDic);
}
return dt;
}));
}
return new FlowTypeStepModel(billFlowStep);
}));
string operUser = flowTypeStepModelTask.Result.OperUser;
Task<DataRow> operatorsTask = cachesDic.AddTask(this, "Operators", new Task<DataRow>(() =>
{
DataRow operators = BillAuditImpl.GetOperators(dynamicModel.ModuleCode, dynamicModel.BillDocumentId, dynamicModel.StepCode);
operUser = operators != null ? operators["operators"] + "" : operUser;
if (operUser.StartsWith("@"))
{
string sql = string.Format("select count(1) from p_employeetab where ({0}) and employeeid='{1}' ", ReplaceHelper.ReplaceRowParam(_drBillInfoMsg, ReplaceHelper.ReplaceUserInfo(operUser)).Replace("@", "").Replace("''", "'"), ERPInfo.Instance.UserId);
Task<string> numberTask = cachesDic.AddTask(this, "Number", new Task<string>(() =>
{
return BaseImpl.GetResult(sql) + "";
}));
}
return operators;
}));
Task<bool> billComfirmTask = cachesDic.AddTask(this, "BillComfirm", new Task<bool>(() =>
{
return BillAuditImpl.GetBillComfirm(this.SysModel.ConfirmId) < 0;
}));
//代理权限
Task<DataRow> agencyAuthorityTask = cachesDic.AddTask(this, "AgencyAuthority", new Task<DataRow>(() =>
{
return BillAuditImpl.GetAgencyAuthority(dynamicModel.ModuleCode);
}));
}
return billFlowStep;
}));
}
}
return currentFlowRowData;
}));
//LoadSignRecord
if (billAuditCommonModelTask.Result != null)
{
Task<DataTable> signRecordTask = cachesDic.AddTask(gridSign, "SignRecord", new Task<DataTable>(() =>
{
DataTable dt = BaseAuditImpl.GetSignRecord(billAuditCommonModelTask.Result.ComfrimTable, dynamicModel.BillDocumentId, dynamicModel.ModuleCode);
if (dt != null && dt.Rows.Count > 0)
{
Task<DataTable> gridSignReadOnlyColumnsTask = cachesDic.AddTask(gridSign, "ReadOnlyColumns", new Task<DataTable>(() =>
{
return BaseAuditImpl.GetSignRecordCoulumn();
}));
cachesDic.AddTask(gridSign, "DynamicModel", dynamicModelTask);
gridSign.GetDataCaches(cachesDic);
}
return dt;
}));
}
//InitCommonMenu
Task<DataTable> tableCommonTask = cachesDic.AddTask(this, "TableCommon", new Task<DataTable>(() =>
{
return BaseModuleImpl.GetBaseGridRightMenus(dynamicModel.ModuleCode, ModuleType.BillDetail);
}));
//InitOtherParms
Task<DataTable> checkSuggestionDataSourceTask = cachesDic.AddTask(this, "CheckSuggestionDataSource", new Task<DataTable>(() =>
{
return BaseImpl.GetDataTableResult(accraditationModelTask.Result.SuggestionSql);
}));
#endregion
}
#endregion
#region 初始化属性设置
/// <summary>
/// <para>说明:初始化属性设置</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-03 </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, "AccraditationModel", out this.AuditModelObj))
{
this.AuditModelObj = new AccraditationModel(BillAuditImpl.GetBillFlowData(this.SysModel.ModuleCode, this.SysModel.StepCode));
}
if (!dataCaches.GetValue(this, "BillInfo", out DataRow modelRow))
{
modelRow = BillImpl.GetBillInfo(this.SysModel.ModuleCode);//获取单个模块信息
}
if (modelRow == null)
{
throw new Exception("模块编号[" + this.SysModel.ModuleCode + "],配置错误!\r\n该模块信息未找到!");
}
if (!dataCaches.GetValue(this, "BillAuditModel", out this.BillModelObj))
{
this.BillModelObj = new BillAuditModel(modelRow);
this.BillModelObj.MasterPreFix = BaseImpl.GetColumnPrefix(this.BillModelObj.MasterTable);
this.BillModelObj.DetailPreFix = BaseImpl.GetColumnPrefix(this.BillModelObj.DetailTable);// 明细表列前缀
this.BillModelObj.DetailOrderField = this.BillModelObj.DetailPreFix + "lsidx_id";// 单据来源id
}
if (SystemInfo.Instance.IsNotBillDetailOrder)//禁用排序
{
this.BillModelObj.DetailOrderField = string.Empty;
}
if (!dataCaches.GetValue(this, "BillAuditCommonModel", out this.BillAuditComObj))
{
this.BillAuditComObj = new BillAuditCommonModel();
}
this.Text = this.SysModel.FormText + "—" + this.AuditModelObj.CurstepName + " " + string.Format(ResourceKeys.BillNoTitle, this.SysModel.BillDocumentId);
this.btnAccradit.Text = this.AuditModelObj.StepApplyText;
this.btnBack.Text = this.AuditModelObj.StepBackText;
this.btnClose.Text = this.AuditModelObj.StepCloseText;
this.btnSpare.Enabled = this.AuditModelObj.StepDivide > 0;
this.label_auditPerson.Text = this.label_managerAudit.LabelText = this.AuditModelObj.CurstepName;
this.label_managerAudit.EditText = this.SysModel.UserName;
this.pl_right_bottom.Tag = this.p_right_bottom.Tag = "NotChangeLocation";
if (!dataCaches.GetValue(this, "MenuConfigTab", out DataRow menuCondRow))
{
menuCondRow = BaseImpl.GetMenuConfigTab(this.SysModel.ModuleId); //获取菜单其他配置
}
if (!dataCaches.GetValue(this, "FileCount", out int fileCount))
{
fileCount = AttachImpl.GetFileCount(this.BillModelObj.DirId + "", this.SysModel.BillDocumentId);
}
this.btnAttach.Text += "(" + fileCount + ")";
if (menuCondRow != null)
{
if (menuCondRow["DllFileName"].Equals("Lskj.PubAccraditationBrp.dll")) this.isBrpAccrad = true;// 是否是Brp模式加载
}
if (this.BillModelObj.AutoMultiHeader == 1)
{
this.pl_detail.Controls.Clear();
this.gridBillInfo = new BandedGridControlEx();
this.gridBillInfo.Model = this.SysModel;
this.gridBillInfo.Dock = DockStyle.Fill;
this.pl_detail.Controls.Add(this.gridBillInfo);
}
//树表格
if (this.BillModelObj.DetailTreeTable)
{
this.pl_detail.Controls.Clear();
this.gridBillInfo = new TreeGridControlEx();
this.gridBillInfo.Dock = DockStyle.Fill;
this.pl_detail.Controls.Add(this.gridBillInfo);
(this.gridBillInfo as TreeGridControlEx).Expansion = this.BillModelObj.DetailTreeTableExpansion;
(this.gridBillInfo as TreeGridControlEx).AddRightButton();
//节点编号
(this.gridBillInfo as TreeGridControlEx).TreeListObj.KeyFieldName = "tap_id";
//父节点编号
(this.gridBillInfo as TreeGridControlEx).TreeListObj.ParentFieldName = "tap_pid";
(this.gridBillInfo as TreeGridControlEx).SortField = this.BillModelObj.DetailOrderField;
(this.gridBillInfo as TreeGridControlEx).InitializedragState();
}
//记录推送用户
this.GetPushOpers();
this.gridFlow.GridView.RowStyle += new RowStyleEventHandler(gridFlowInfo_RowStyle);
if (this.BillModelObj.DetailTreeTable)
{
(this.gridBillInfo as TreeGridControlEx).TreeListObj.Paint += new PaintEventHandler(gridBillInfo_Panint);
(this.gridBillInfo as TreeGridControlEx).TreeListObj.ShowingEditor += new CancelEventHandler(OnGridViewShowingEditor);
}
else
{
this.gridBillInfo.gridControl.Paint += new PaintEventHandler(gridBillInfo_Panint);
this.gridBillInfo.GridView.ShowingEditor += new CancelEventHandler(OnGridViewShowingEditor);
}
if (!dataCaches.GetValue(this, "BillInfoData", out this._dtBillInfoFiled))
{
this._dtBillInfoFiled = BillAuditImpl.GetBillInfoData(this.SysModel.ModuleCode);
}
}
#endregion
#region 表格是否可以编辑设置
/// <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
{
DataRow rowItem = this.gridBillInfo.GridView.GetDataRow(this.gridBillInfo.GridView.FocusedRowHandle);
if (this.BillModelObj.DetailTreeTable)
{
rowItem = (this.gridBillInfo as TreeGridControlEx).GetViewFocusedDataRow();
}
if (!string.IsNullOrWhiteSpace(BillModelObj.UpdateDetailCond))
{
string UpdateCond = this.ControlObj.ReplaceParentControlValue(BillModelObj.UpdateDetailCond);
UpdateCond = ReplaceHelper.ReplaceRowParam(rowItem, UpdateCond);
if (!ReplaceHelper.EvalCond(UpdateCond))
{
e.Cancel = true;//该行不可编辑
}
}
}
catch (Exception ex)
{
LogHelper.Instance.WriteError(ex);
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
#endregion
#region 流转表格设置行颜色
/// <summary>
/// <para>说明:流转表格行颜色区分</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-03 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void gridFlowInfo_RowStyle(object sender, RowStyleEventArgs e)
{
try
{
if (e.RowHandle > 0)
{
DataRow dr = this.gridFlow.GridView.GetDataRow(e.RowHandle);
if (dr["sh"].ToString() == "审") e.Appearance.ForeColor = Color.Blue;
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
#endregion
#region 初始化控件
/// <summary>
/// <para>说明:初始化控件</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-03 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void InitializeControl()
{
Dictionary<object, Hashtable> dataCaches = SysModel != null ? SysModel.DataCaches : null;
if (!dataCaches.GetValue(gridFlow, "ReadOnlyColumns", out DataTable dtReadOnlyColumns))
{
dtReadOnlyColumns = BaseAuditImpl.GetFlowRecordColumn();
}
if (!dataCaches.GetValue(gridFlow, "GridViewDataSource", out DataTable dtridViewDataSource))
{
dtridViewDataSource = BaseAuditImpl.GetFlowRecordData(this.BillAuditComObj.SystemTabFlowStep, this.SysModel.BillDocumentId, this.SysModel.ModuleCode);
}
this.gridFlow.Model = SysModel;
this.gridFlow.SetReadOnlyColumns(dtReadOnlyColumns, GridCustomColumnStruct.AuditPopupAttachGridView + this.BillModelObj.FormKey);
this.gridFlow.SetGridViewDataSource(dtridViewDataSource);
this.SetFormSize();
this.BindTab();
this.BindBill();
this.LoadRemindRecord();
this.LoadSignRecord();
this.InitCommonMenu();
this.InitOtherParms();
this.InitOkBtn();
}
#endregion
#region
/// <summary>
/// <para>说明:录所有按钮的位置</para>
/// <para>创建人:王一帆</para>
/// <para>创建日期:2020-11-25 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void InitButLocation()
{
LocationX.Clear();
int newlocationX = 0;
foreach (System.Windows.Forms.Control control in pl_bottom.Controls)
{
int x = control.Location.X;
bool isvisbel = control.Visible;
if (!control.Visible)
{
LocationX.Add(x);
}
}
foreach (System.Windows.Forms.Control control in pl_bottom.Controls)
{
int x = control.Location.X;
newlocationX = control.Location.X;
foreach (int b in LocationX)
{
if (x < b)
{
newlocationX += 73;
}
}
control.Location = new Point(newlocationX, control.Location.Y);
}
if (!btnRemindAccradit.Visible)
{
CheckSuggestion.Width = btnRemindAccradit.Location.X + btnRemindAccradit.Width - CheckSuggestion.Location.X;
}
if (!btnRemindBack.Visible)
{
label_managerAudit.Width = btnRemindBack.Location.X + btnRemindBack.Width - label_managerAudit.Location.X;
if (!btnBack.Visible)
{
label_managerAudit.Width = btnBack.Location.X + btnBack.Width - label_managerAudit.Location.X;
}
}
if (!btnClose.Visible)
{
label_date.Width = btnClose.Location.X + btnClose.Width - label_date.Location.X;
}
}
#endregion
#region 初始化常用菜单
/// <summary>
/// <para>说明:设置初始化常用菜单</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-08 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void InitCommonMenu()
{
Dictionary<object, Hashtable> dataCaches = SysModel != null ? SysModel.DataCaches : null;
if (!dataCaches.GetValue(this, "TableCommon", out DataTable tableCommon))
{
tableCommon = BaseModuleImpl.GetBaseGridRightMenus(this.SysModel.ModuleCode, ModuleType.BillDetail);
}
if (tableCommon == null && tableCommon.Rows.Count <= 0)
{
dpb_Tools.Enabled = false;
return;
}
foreach (DataRow item in tableCommon.Rows)
{
BarButtonItem itemCommon = new BarButtonItem();
itemCommon.Caption = item["menuname"] + "";
itemCommon.Tag = item;
itemCommon.ItemClick += new ItemClickEventHandler(itemCommon_ItemClick);
this.pMenu.AddItem(itemCommon);
}
}
#endregion
#region 常用工具
/// <summary>
/// <para>说明:常用工具点击</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-01-08 </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_ItemClick(object sender, ItemClickEventArgs e)
{
try
{
DataRow rowItem = e.Item.Tag as DataRow;
CommonMenu menu = new CommonMenu(this.SysModel, this.ControlObj);
menu.ApplyBefore += new CommonToolApplyEventHandler(OnMenuApplyBefore);
menu.Apply(rowItem);
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:执行前单独替换BilldocumentId</para>
/// <para>创建人:王一帆</para>
/// <para>创建日期:2020-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="e">The e.</param>
protected void OnMenuApplyBefore(ApplyArgs e)
{
try
{
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.BillModelObj.PrimaryKey.Equals(cond.Replace("{", "").Replace("}", "").ToLower(), StringComparison.OrdinalIgnoreCase) ? this.SysModel.BillDocumentId : cond;
item = item.Replace(cond, value); ;
}
paramList[i] = item;
}
e.MemuModel.ParamList = paramList.ToList();
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
#endregion
#region 设置窗体大小
/// <summary>
/// <para>说明:设置窗体大小</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-03 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void SetFormSize()
{
int panelWidth = this.BillModelObj.PanelWidth + this.gridFlow.Width;
this.Width = panelWidth < Screen.PrimaryScreen.WorkingArea.Width ? panelWidth : Screen.PrimaryScreen.WorkingArea.Width;
this.Left = (Screen.PrimaryScreen.WorkingArea.Width / 2) - (this.Width / 2);
this.Top = (Screen.PrimaryScreen.WorkingArea.Height / 2) - (this.Height / 2);
}
#endregion
#region 绑定选项卡
/// <summary>
/// <para>说明:绑定选项卡</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-03 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void BindTab()
{
Dictionary<object, Hashtable> dataCaches = SysModel != null ? SysModel.DataCaches : null;
this.tab_basicInfo.Model = this.SysModel;
this.tab_basicInfo.ParentGridEx = this.gridBillInfo;
if (this.BillModelObj.SaveRefresh)
{
this.tab_basicInfo.OnDetailSaveGridCallBack += Tab_basicInfo_OnDetailSaveGridCallBack;
}
if (!dataCaches.GetValue(tab_basicInfo, "Details", out List<GridDetailModel> details))
{
details = GetTabDetails();
}
this.tab_basicInfo.InitTabPages(details);
this.splitLeft.PanelVisibility = tab_basicInfo.TabControlObj.TabPages.Count == 0 ? SplitPanelVisibility.Panel1 : SplitPanelVisibility.Both;
this.tab_basicInfo.OnRightCallback += new EventHandler(AuditTab_OnRightCallback);
}
/// <summary>
/// <para>说明:获取选项卡数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-15 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <returns>List&lt;GridDetailModel&gt;.</returns>
private List<GridDetailModel> GetTabDetails()
{
List<GridDetailModel> details = new List<GridDetailModel>();
DataTable table = BaseAuditImpl.GetAttachTabs(this.SysModel.ModuleCode, this.SysModel.StepCode);
foreach (DataRow item in table.Rows)
{
if (table.Columns.Contains("privilegeoper"))
{
string privilegeoper = item["privilegeoper"] + "";//配置的权限人员
if (string.IsNullOrWhiteSpace(privilegeoper) || privilegeoper.Split(',').Contains(ERPInfo.Instance.UserName))
{
DataTable dtGridColumns = BaseAuditImpl.GetBottomBasicInformation(item["formKey"] + "");
details.Add(new GridDetailModel(item, dtGridColumns, GridCustomColumnStruct.AuditPopupBasicInfoGridView + item["formKey"] + ""));
}
}
else
{
DataTable dtGridColumns = BaseAuditImpl.GetBottomBasicInformation(item["formKey"] + "");
details.Add(new GridDetailModel(item, dtGridColumns, GridCustomColumnStruct.AuditPopupBasicInfoGridView + item["formKey"] + ""));
}
}
return details;
}
#endregion
#region 绑定审批单据
/// <summary>
/// <para>说明:单据管理</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-04 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void BindBill()
{
Dictionary<object, Hashtable> dataCaches = SysModel != null ? SysModel.DataCaches : null;
// 初始化表头
if (!dataCaches.GetValue(this, "ControlObj", out this.ControlObj))
{
this.ControlObj = new MyControl();
}
if (!dataCaches.GetValue(this, "ControlLocation", out DataTable dtControlLocation))
{
dtControlLocation = BaseModuleImpl.GetControlLocation(this.BillModelObj.FormKey, this.SysModel.ModuleCode);
}
this.ControlObj.PrimaryValue = this.SysModel.BillDocumentId;
this.ControlObj.isAuditMain = true;
this.ControlObj.InitControl(dtControlLocation, this.pl_left_top);
if (SystemInfo.Instance.AuditAutoScroll)
{
this.pl_left_top.AutoScroll = true;
}
this.ControlObj.OnDataSourceBindCallBack += new EventHandler(OnControlObjOnDataSourceBindCallBack);
this.ControlObj.OnDataFileRefrshCallBack += OnDataFileRefrshFile;
this.pl_left_top.Height = this.BillModelObj.ParentHeight - 36 > this.pl_left_top.Height ? this.pl_left_top.Height : this.BillModelObj.ParentHeight;
//初始明细数据
this.gridBillInfo.Model = this.SysModel;
this.gridBillInfo.ParentControl = this.ControlObj;
if (this.BillModelObj.DetailTreeTable)
{
(this.gridBillInfo as TreeGridControlEx).OnDataSourceBindCallBack += new EventHandler(OnGridBillInfoOnDataSourceBindCallBack);
}
else
{
this.gridBillInfo.OnDataSourceBindCallBack += new EventHandler(OnGridBillInfoOnDataSourceBindCallBack);
}
if (!dataCaches.GetValue(gridBillInfo, "DetailColumns", out DataTable dtDetailColumns))
{
dtDetailColumns = BillImpl.GetDetailColumns(this.SysModel.ModuleCode);
}
this.gridBillInfo.SetEditColumns(dtDetailColumns, GridCustomColumnStruct.AuditPopupDetailGridView + this.BillModelObj.FormKey);
if (!dataCaches.GetValue(gridBillInfo, "BaseGridRightMenus", out DataTable dtGridRightMenu))
{
dtGridRightMenu = BaseModuleImpl.GetBaseGridRightMenus(this.AuditModelObj.BillGridMenuFlag + this.SysModel.ModuleCode, ModuleType.BillAuditDetail);
}
if (this.BillModelObj.DetailTreeTable)
{
(this.gridBillInfo as TreeGridControlEx).SetGridRightMenus(dtGridRightMenu, this.SysModel, OnGridViewRightCallBack);
}
else
{
if (this.gridBillInfo is BandedGridControlEx)// 判断是不是多表头表格
{
//设置表格右键菜单
(this.gridBillInfo as BandedGridControlEx).SetGridRightMenus(dtGridRightMenu, this.SysModel, OnGridViewRightCallBack);
}
else
{
this.gridBillInfo.SetGridRightMenus(dtGridRightMenu, this.SysModel, OnGridViewRightCallBack);
}
}
if (!dataCaches.GetValue(gridBillInfo, "BaseGridRowColors", out DataTable dtBaseGridRowColors))
{
dtBaseGridRowColors = BaseModuleImpl.GetBaseGridRowColors("BILLDETAIL_" + this.BillModelObj.FormKey);
}
this.gridBillInfo.SetGridRowColors(dtBaseGridRowColors);
////修改字段
//if (!string.IsNullOrEmpty(this.AuditModelObj.DetailModifyFields) && this.AuditModelObj.DetailModifyFields != "-1")
//{
// gridBillInfo.GridView.OptionsBehavior.Editable = true;
// GridColumnCollection gc = this.gridBillInfo.GridView.Columns;
// this.AuditModelObj.DetailModifyFields = this.AuditModelObj.DetailModifyFields + ",";
// foreach (GridColumn item in gc)
// {
// GridColumnModel model = item.Tag as GridColumnModel;
// item.OptionsColumn.AllowEdit = this.AuditModelObj.DetailModifyFields.IndexOf(item.FieldName + ",", StringComparison.OrdinalIgnoreCase) != -1;
// item.OptionsColumn.ReadOnly = !item.OptionsColumn.AllowEdit;
// if (model.FieldType == ControlType.LabMemoEdit) item.OptionsColumn.AllowEdit = true;
// }
//}
////必填字段
//if (!string.IsNullOrEmpty(this.AuditModelObj.RequiredDetailFields) && this.AuditModelObj.RequiredDetailFields != "-1")
//{
// GridColumnCollection gc = this.gridBillInfo.GridView.Columns;
// string[] RequiredDetail = this.AuditModelObj.RequiredDetailFields.Split(',');
// Color RequiredForceColor = string.IsNullOrEmpty(SystemInfo.Instance.ControlRequiredColor) ? Color.Blue : ColorTranslator.FromHtml(SystemInfo.Instance.ControlRequiredColor);
// foreach (GridColumn item in gc)
// {
// GridColumnModel model = item.Tag as GridColumnModel;
// if (RequiredDetail.Contains(model.FieldName))
// {
// item.AppearanceHeader.Options.UseForeColor = true;
// item.AppearanceHeader.ForeColor = RequiredForceColor;
// }
// }
//}
this.AuthorityTable = PowerImpl.GetModuleAuthorityEnable(this.SysModel.ModuleCode);
if (this.AuditModelObj.DetailModifyFields != "-1")
{
this.gridBillInfo.SetReadOnlyAllColumn();
this.dbpFP.Enabled = false;
}
//设置必填和修改字段
this.gridBillInfo.SetFieldStatus(this.AuditModelObj.DetailModifyFields, this.AuditModelObj.RequiredDetailFields, this.AuthorityTable);
this.SetBillControl(this.AuditModelObj.BillModifyFields, this.AuditModelObj.RequiredFields);
this.InitPrint();
this.GetPrintOtherParam();
//加载分配
this.dbpFP.Click += new System.EventHandler(this.OnBtnFPOldClick);
BarButtonItem itemFPBatch = new BarButtonItem();
itemFPBatch.Caption = "批量分配";
itemFPBatch.ItemClick += new ItemClickEventHandler(OnBtnFPNewClick);
//分配
this.pmFP.AddItems(new BarItem[] { itemFPBatch });
this.dbpFP.Visible = !string.IsNullOrWhiteSpace(this.BillModelObj.PopupUnionCode);
}
/// <summary>
/// <para>说明:数据绑定完后刷新数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期: </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>
void OnGridBillInfoOnDataSourceBindCallBack(object sender, EventArgs e)
{
try
{
WaitForm.ShowForm("正在加载数据");
// 设置Brp模版
if (this.isBrpAccrad)
{
this.SetTempleteSelectedValue(this.ControlObj.GetControlValue("brpId"));
}
//this._dtSourceData = BillImpl.GetDataTableResult(ReplaceHelper.ReplaceParamToValue(this.BillModelObj.DetailSql, this.SysModel.BillDocumentId));
this._dtSourceData = BillImpl.GetDataTableResult(ReplaceHelper.ReplaceRowParam(_drBillInfoMsg, this.BillModelObj.DetailSql));
if (this.BillModelObj.DetailTreeTable)
{
if (this._dtSourceData.Columns.Contains(this.BillModelObj.DetailOrderField))
{
DataView dataView = this._dtSourceData.AsDataView();
dataView.Sort = this.BillModelObj.DetailOrderField;
this._dtSourceData = dataView.ToTable();
}
(this.gridBillInfo as TreeGridControlEx).SetGridViewDataSourceGenerateID(_dtSourceData);
}
else
{
this._dtSourceData.OrderBy(this.BillModelObj.DetailOrderField);
this.gridBillInfo.SetGridViewDataSource(_dtSourceData);
}
if (_dtSourceData != null) this._dtSpareSourceData = this._dtSourceData.Clone();
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
finally
{
WaitForm.HideForm();
}
}
/// <summary>
/// <para>说明:设置Brp模版加载明细</para>
/// <para>创建人:王一帆</para>
/// <para>创建日期:2021-03-02 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void SetTempleteSelectedValue(string id)
{
DataTable detailTable = this.BillModelObj.DetailTreeTable ? (this.gridBillInfo as TreeGridControlEx).GetGridViewDataSource() : gridBillInfo.GridControl.DataSourceTable();
string brpId = id;
// 清空明细
detailTable.Clear();
// 重新设置明细列
DataTable columns = BillImpl.GetBillDetailBrpColumns(brpId);
if (columns != null && columns.Rows.Count > 0)
{
gridBillInfo.SetEditColumns(columns);
}
else
{
gridBillInfo.GridView.Columns.Clear();
if (this.BillModelObj.DetailTreeTable) (this.gridBillInfo as TreeGridControlEx).TreeListObj.Columns.Clear();
}
}
/// <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>
void OnControlObjOnDataSourceBindCallBack(object sender, EventArgs e)
{
try
{
this.ControlObj.CanExecControl = false;
this.ControlObj.SetAllControlValue(this._drBillInfoMsg);
if(this.BillModelObj.HighlightChangeControl) this.ControlObj.ModifiedDefaultValueHighlight(this._drBillInfoMsg);
this.ControlObj.CanExecControl = true;
this.SetColor();
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <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();
OnGcMainDataSourceChanged(gridBillInfo.GridView, null);//手动刷新日期合计数据源
}
private void AddDataColumns()
{
foreach (GridColumn gridColumn in gridBillInfo.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)
{
gridBillInfo.GridView.Columns.Remove(item);
}
gridBillInfo.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.####}";
gridBillInfo.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;
gridBillInfo.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);
gridBillInfo.GridView.BeginUpdate();
try
{
for (int i = 0; i < DateColumnList.Count; i++)
{
GridColumn gridColumn = DateColumnList[i];
// 当前列对应的日期 = 起始日期加 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;
}
else
{
gridColumn.Visible = false;
}
}
}
finally
{
gridBillInfo.GridView.EndUpdate();
}
}
/// <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 = SysModel.BillDocumentId;
this.gridBillInfo.GridControl.DataSourceChanged -= OnGcMainDataSourceChanged;
DataTable dataTable = gridBillInfo.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];
//渲染计划合计
gridBillInfo.AddHeadquarters(jhrowitem);
}
catch (Exception)
{
}
}
this.gridBillInfo.GridControl.DataSource = null;
this.gridBillInfo.GridControl.DataSource = dataTable;
}
this.gridBillInfo.GridControl.DataSourceChanged += OnGcMainDataSourceChanged;
}
}
/// <summary>
/// 构建带日期的数据源
/// </summary>
/// <param name="dataMain"></param>
/// <param name="dataDayPlan"></param>
/// <param name="startDate"></param>
/// <returns></returns>
private DataTable MergeMainDataWithDayPlan(DataTable dataMain, DataTable dataDayPlan, DateTime startDate)
{
string rightPrimaryKey = "billdocument_id";
string dateField = "showday";
string amountField = "amount";
string topPrimaryKey = BillModelObj.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. 预索引 dataDayPlanbilldocument_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;
}
#endregion
#region 右键菜单执行后刷新
/// <summary>
/// <para>说明:右键菜单执行后刷新单据数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-03-19 </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>
protected void OnGridViewRightCallBack(object sender, EventArgs e)
{
try
{
// 刷新主表
this._drBillInfoMsg = BaseAuditImpl.GetCurrentFlowRowData(this.BillModelObj.MasterTable, this.BillModelObj.PrimaryKey, this.SysModel.BillDocumentId);
this.ControlObj.SetAllControlValue(this._drBillInfoMsg);
// 刷新明细表
//this._dtSourceData = BillImpl.GetDataTableResult(ReplaceHelper.ReplaceParamToValue(this.BillModelObj.DetailSql, this.SysModel.BillDocumentId));
this._dtSourceData = BillImpl.GetDataTableResult(ReplaceHelper.ReplaceRowParam(_drBillInfoMsg, this.BillModelObj.DetailSql));
this._dtSourceData.OrderBy(this.BillModelObj.DetailOrderField);
if (this.BillModelObj.DetailTreeTable)
{
(this.gridBillInfo as TreeGridControlEx).SetGridViewDataSourceGenerateID(_dtSourceData);
}
else
{
this.gridBillInfo.SetGridViewDataSource(_dtSourceData);
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:单据右键菜单执行后刷新Tab标签数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-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>
protected void AuditTab_OnRightCallback(object sender, EventArgs e)
{
try
{
GridDetailModel model = this.tab_basicInfo.GetFocusTabPageGridDetailModel();
DataRow dataRow = this.BillModelObj.DetailTreeTable ? (this.gridBillInfo as TreeGridControlEx).GetViewFocusedDataRow() : this.gridBillInfo.GridView.GetFocusedDataRow();
//string sqlValue = ReplaceHelper.ReplaceRowParam(dataRow, model.DetailSql);
//this.tab_basicInfo.SetGridDataSource(MainImpl.GetDataTableResult(sqlValue));
bool isDetailAttach = (model.IsReadOnly || model.IsChart);
string sqlValue = isDetailAttach ? ReplaceHelper.ReplaceRowParam(dataRow, model.DetailSql) : GetSearchSql(model);
sqlValue = ReplaceHelper.ReplaceRowParam(dataRow, sqlValue);
//this.tab_basicInfo.SetGridDataSource(tabPage, MainImpl.GetDataTableResult(sqlValue));
this.tab_basicInfo.SetGridDataSource(MainImpl.GetDataTableResult(sqlValue));
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
#endregion
#region 初始化打印
/// <summary>
/// <para>说明:创建打印</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-04 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void InitPrint()
{
string[] files = this.BillModelObj.PrintFile.Split('|');
for (int i = 0; i < files.Length; i++)
{
string fileName = files[i];
if (!string.IsNullOrWhiteSpace(fileName))
{
BarButtonItem itemPrint = new BarButtonItem();
itemPrint.Caption = fileName.Replace(".rmf", "").Replace(".frx", "");
itemPrint.Tag = files[i];
itemPrint.ItemClick += new ItemClickEventHandler(itemPrint_ItemClick);
pMprint.AddItem(itemPrint);
}
}
}
#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.BillModelObj.PrintSql) && this.BillModelObj.PrintSql.Contains("<<"))
{
string[] strs = this.BillModelObj.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"] + "";
string comprefix = BaseImpl.GetColumnPrefix(tableName);
string primaryKey = modetype == "1" ? BaseImpl.GetBasePrimaryKey(str[0]) : comprefix + "billdocument_id";
//表名,列前缀,主键字段,主键值,模块编号,主打印Sql
_printSaveParams = new List<string>() { tableName, comprefix, primaryKey, str[1], str[0], _mainPrintSql };
//判断是否直接打印 modetype 区别单据和基础档案模块
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>创建日期:2018-01-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>
protected void itemPrint_ItemClick(object sender, ItemClickEventArgs e)
{
try
{
string billNo = txt_billDocumentId.EditText;
string printPath = PubUtil.PrintFileAbsolutelyPath;
string printFile = e.Item.Tag + "";
if (!File.Exists(printPath))
{
MessageUtil.Show(ResourceKeys.NotFoundPrintFile);
return;
}
if (!string.IsNullOrEmpty(billNo))
{
DataRow masterRow = BillImpl.GetDataRowResult(ReplaceHelper.ReplaceParamToValue(this.BillModelObj.MasterSql, billNo));
if (masterRow == null)
{
MessageUtil.Show(ResourceKeys.DataNotFount);
return;
}
if (!ReplaceHelper.ReplaceRowParamCond(masterRow, this.BillModelObj.PrintCond))
{
MessageUtil.Show(ResourceKeys.DisSatisfyPrintCond);
return;
}
string tmpSql = ReplaceHelper.ReplaceRowParam(masterRow, this.BillModelObj.PrintSql);
string tmpSql1 = ReplaceHelper.ReplaceRowParam(masterRow, this.BillModelObj.PrintSql1);
string tmpSql2 = ReplaceHelper.ReplaceRowParam(masterRow, this.BillModelObj.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[BillModelObj.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.BillModelObj.PrintFileType, tmpSql2);
}
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <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]);
}
}
#endregion
#region 绘制水印
/// <summary>
/// <para>说明:绘制水印</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-05 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void gridBillInfo_Panint(object sender, PaintEventArgs e)
{
try
{
if (this.SysModel.StepOver != "1") return;
GraphicsText graphicsText = new GraphicsText();
graphicsText.Graphics = e.Graphics;
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
Pen pen = new Pen(Color.Red, 2f);
SolidBrush brush = new SolidBrush(Color.Red);
if (!string.IsNullOrEmpty(this._waterMark.Text))
{
int x = (this.gridBillInfo.Width - 90) / 2;
int y = (this.gridBillInfo.Height - 32) / 2;
graphicsText.DrawString(this._waterMark.Text, new Font("宋体", 20, FontStyle.Bold), brush, new PointF(x, y), format, -20f);
e.Graphics.TranslateTransform(x, y);
e.Graphics.RotateTransform(-20f);
if (Business.Impl.LanguageTranslation.Translatable)
{
// 1. 测量文本尺寸
SizeF textSize = e.Graphics.MeasureString(this._waterMark.Text, new Font("宋体", 20, FontStyle.Bold), new SizeF(float.MaxValue, float.MaxValue), format);
// 2. 计算边框矩形的尺寸和位置
int rectWidth = (int)textSize.Width + 10;
e.Graphics.DrawRectangle(pen, new Rectangle(-rectWidth / 2, -19, rectWidth, 32));
}
else
{
e.Graphics.DrawRectangle(pen, new Rectangle(-45, -19, 90, 32));
}
}
e.Graphics.ResetTransform();
if (!string.IsNullOrEmpty(this._waterMark.Print))
{
int x1 = (this.gridBillInfo.Width - 120) / 2;
int y1 = (this.gridBillInfo.Height - 90) / 2 + 100;
graphicsText.DrawString(this._waterMark.Print, new Font("宋体", 18, FontStyle.Bold), brush, new PointF(x1, y1), format, -20f);
e.Graphics.TranslateTransform(x1, y1);
e.Graphics.RotateTransform(-20f);
if (Business.Impl.LanguageTranslation.Translatable)
{
// 1. 测量文本尺寸
SizeF textSize = e.Graphics.MeasureString(this._waterMark.Print, new Font("宋体", 18, FontStyle.Bold), new SizeF(float.MaxValue, float.MaxValue), format);
// 2. 计算边框矩形的尺寸和位置
int rectWidth = (int)textSize.Width + 10;
e.Graphics.DrawRectangle(pen, new Rectangle(-rectWidth / 2, -19, rectWidth, 32));
}
else
{
e.Graphics.DrawRectangle(pen, new Rectangle(-60, -19, 120, 32));
}
}
e.Graphics.ResetTransform();
if (!string.IsNullOrEmpty(this._waterMark.Collect))
{
int x2 = (this.gridBillInfo.Width - 90) / 2;
int y2 = (this.gridBillInfo.Height - 90) / 2 - 40;
graphicsText.DrawString(this._waterMark.Collect, new Font("宋体", 20, FontStyle.Bold), brush, new PointF(x2, y2), format, -20f);
e.Graphics.TranslateTransform(x2, y2);
e.Graphics.RotateTransform(-20f);
if (Business.Impl.LanguageTranslation.Translatable)
{
// 1. 测量文本尺寸
SizeF textSize = e.Graphics.MeasureString(this._waterMark.Collect, new Font("宋体", 20, FontStyle.Bold), new SizeF(float.MaxValue, float.MaxValue), format);
// 2. 计算边框矩形的尺寸和位置
int rectWidth = (int)textSize.Width + 10;
e.Graphics.DrawRectangle(pen, new Rectangle(-rectWidth / 2, -19, rectWidth, 32));
}
else
{
e.Graphics.DrawRectangle(pen, new Rectangle(-45, -19, 90, 32));
}
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
#endregion
#region 审批单据管理
/// <summary>
/// <para>说明:单据管理</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-04 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void SetBillControl(string billFields, string RequiredFields)
{
Dictionary<object, Hashtable> dataCaches = SysModel != null ? SysModel.DataCaches : null;
if (!dataCaches.GetValue(this, "CurrentFlowRowData", out this._drBillInfoMsg))
{
this._drBillInfoMsg = BaseAuditImpl.GetCurrentFlowRowData(this.BillModelObj.MasterTable, this.BillModelObj.PrimaryKey, this.SysModel.BillDocumentId);
}
if (this._drBillInfoMsg == null)
{
MessageUtil.Show(ResourceKeys.NotFindAuditRecord);
return;
}
this._mainBillTypeValue = this._drBillInfoMsg[this.BillModelObj.BillType] + "";
if (string.IsNullOrEmpty(this._mainBillTypeValue) || this._mainBillTypeValue == "0")
{
MessageUtil.Show(ResourceKeys.NotSetFlowType);
return;
}
this._waterMark = new WaterMark(this.BillModelObj.MasterPreFix, this._drBillInfoMsg);
this.SetButtonsStatus();
if (this.AuditModelObj.BillModifyFields != "-1")
this.ControlObj.SetReadOnlyAllControl(true, false);
//改变控件状态 必填字段
if (!string.IsNullOrEmpty(RequiredFields) && RequiredFields != "-1")
{
foreach (DataRow dr in this._dtBillInfoFiled.Rows)
{
string fieldName = dr["fieldName"] + "";
this.ControlObj.SetRequiredControl(fieldName, RequiredFields.Split(',').Contains(fieldName), false);
}
}
//改变控件状态 操作字段
if (!string.IsNullOrEmpty(billFields) && billFields != "-1")
{
foreach (string item in billFields.Split(','))
{
BaseUserControl control = this.ControlObj.FindControl(item);
if (control == null) continue;
if (string.IsNullOrWhiteSpace(control.Model.PrivilegeOper))
{
//没有人员权限,转成可编辑
this.ControlObj.SetReadOnlyControl(item, false, false);
}
else
{
List<int> targetPrivTypeIds = new List<int>();
foreach (string permission in control.Model.PrivilegeOper.Split(','))
{
if (!string.IsNullOrWhiteSpace(permission)) targetPrivTypeIds.Add(int.Parse(permission));
}
//获取权限对应的人员名称
string userString = string.Join(",", AuthorityTable.AsEnumerable()
.Where(row => targetPrivTypeIds.Contains(row.Field<int>("privTypeId")))
.Select(row => row.Field<string>("userList"))
.Where(value => value != null)
.ToList());
//有权限的字段,转成可编辑
if (userString.Split(',').Contains(ERPInfo.Instance.UserName)) this.ControlObj.SetReadOnlyControl(item, false, false);
}
}
//foreach (DataRow dr in this._dtBillInfoFiled.Rows)
//{
// string fieldName = dr["fieldName"] + "";
// this.ControlObj.SetReadOnlyControl(fieldName, !billFields.Split(',').Contains(fieldName), true);
//}
}
}
#endregion
#region 设置按钮状态
/// <summary>
/// <para>说明:设置按钮状态</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-04 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void SetButtonsStatus()
{
Dictionary<object, Hashtable> dataCaches = SysModel != null ? SysModel.DataCaches : null;
if (!dataCaches.GetValue(this, "BillFlowStep", out DataRow dr))
{
dr = BillAuditImpl.GetBillFlowStep(this.SysModel.ModuleCode, this._mainBillTypeValue, this.SysModel.StepCode);
}
if (dr == null)
{
MessageUtil.Show(ResourceKeys.FlowStepConfigError);
return;
}
if (!dataCaches.GetValue(this, "FlowTypeStepModel", out this._flowTypeStepModel))
{
this._flowTypeStepModel = new FlowTypeStepModel(dr);
}
string operUser = this._flowTypeStepModel.OperUser;
if (!dataCaches.GetValue(this, "Operators", out DataRow drOper))
{
drOper = BillAuditImpl.GetOperators(this.SysModel.ModuleCode, this.SysModel.BillDocumentId, this.SysModel.StepCode);
}
this.btnAccradit.Visible = BillAuditImpl.GetBillComfirm(this.SysModel.ConfirmId) < 0;
operUser = drOper != null ? drOper["operators"] + "" : operUser;
if (operUser.StartsWith("@"))
{
if (!dataCaches.GetValue(this, "Number", out string number))
{
string sql = string.Format("select count(1) from p_employeetab where ({0}) and employeeid='{1}' ", ReplaceHelper.ReplaceRowParam(_drBillInfoMsg, ReplaceHelper.ReplaceUserInfo(operUser)).Replace("@", "").Replace("''", "'"), ERPInfo.Instance.UserId);
number = BaseImpl.GetResult(sql) + "";
}
this.btnSave.Enabled = this.btnClose.Enabled = this.btnBack.Enabled = this.btnAccradit.Enabled = int.Parse(string.IsNullOrWhiteSpace(number + "") ? "0" : number + "") > 0;
}
else
{
this.btnSave.Enabled = this.btnClose.Enabled = this.btnBack.Enabled = this.btnAccradit.Enabled = operUser.Contains(this.SysModel.UserName);
}
//代理权限
if (!dataCaches.GetValue(this, "AgencyAuthority", out DataRow agency))
{
agency = BillAuditImpl.GetAgencyAuthority(this.SysModel.ModuleCode);
}
if (agency != null)
{
string sourceuser = agency["sourceuser"] + "";
foreach (string item in sourceuser.Split(','))
{
if (operUser.Contains(item))
{
this.btnSave.Enabled = this.btnClose.Enabled = this.btnBack.Enabled = this.btnAccradit.Enabled = true;
break;
}
}
}
this.btnClose.Visible = this._flowTypeStepModel.StepClosed == 1;
this.btnRemindAccradit.Visible = this.btnRemindBack.Visible = this._flowTypeStepModel.RemindSelect == "1";
//终审
if (this.SysModel.StepOver == "1")
{
this.btnSave.Visible = this.btnClose.Visible = this.btnBack.Visible = this.txtRemark.Visible = this.pl_right_bottom.Visible = this.label_auditPerson.Visible = false;
this.p_right_bottom.Height = 60;
this.btnPrint.Parent = this.p_right_bottom;
this.btnPrint.Visible = true;
this.btnPrint.Left = 15;
this.btnPrint.Top = 20;
this.btnPrint.Height = 30;
this.btnPrint.Width = (this.p_right_bottom.Width - 55) / 2;
this.btnAttach.Parent = this.p_right_bottom;
this.btnAttach.Visible = true;
this.btnAttach.Left = this.btnPrint.Left + this.btnPrint.Width + 15;
this.btnAttach.Top = 20;
this.btnAttach.Height = 30;
this.btnAttach.Width = (this.p_right_bottom.Width - 55) / 2;
}
}
#endregion
#region 加载提醒记录
/// <summary>
/// <para>说明:加载提醒记录</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-08 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void LoadRemindRecord()
{
Dictionary<object, Hashtable> dataCaches = SysModel != null ? SysModel.DataCaches : null;
if (this._flowTypeStepModel != null && !string.IsNullOrEmpty(this._flowTypeStepModel.RemindSelect))
{
if (!dataCaches.GetValue(gridRemind, "RemindinRecord", out DataTable dt))
{
dt = BaseAuditImpl.GetRemindinRecord(this.BillAuditComObj.FlowStepTable, this.BillAuditComObj.ComfrimTable, this.SysModel.BillDocumentId, this.SysModel.ModuleCode);
}
if (dt != null && dt.Rows.Count > 0)
{
if (!dataCaches.GetValue(gridRemind, "ReadOnlyColumns", out DataTable dtReadOnlyColumns))
{
dtReadOnlyColumns = BaseAuditImpl.GetRemindColumn();
}
this.gridRemind.SetReadOnlyColumns(dtReadOnlyColumns);
this.gridRemind.SetGridViewDataSource(dt);
this.tabpage_remind.Text = this.tabpage_remind.Text + "(" + dt.Rows.Count + ")";
}
else
{
this.TabControl.TabPages.Remove(this.tabpage_remind);
}
}
}
#endregion
#region 加载会签记录
/// <summary>
/// <para>说明:加载会签记录</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-08</para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void LoadSignRecord()
{
Dictionary<object, Hashtable> dataCaches = SysModel != null ? SysModel.DataCaches : null;
if (this.BillAuditComObj == null) return;
if (!dataCaches.GetValue(gridSign, "SignRecord", out DataTable dt))
{
dt = BaseAuditImpl.GetSignRecord(this.BillAuditComObj.ComfrimTable, this.SysModel.BillDocumentId, this.SysModel.ModuleCode);
}
if (dt != null && dt.Rows.Count > 0)
{
if (!dataCaches.GetValue(gridSign, "ReadOnlyColumns", out DataTable dtReadOnlyColumns))
{
dtReadOnlyColumns = BaseAuditImpl.GetSignRecordCoulumn();
}
this.gridSign.SetReadOnlyColumns(dtReadOnlyColumns);
this.gridSign.SetGridViewDataSource(dt);
this.tabpage_sign.Text = this.tabpage_sign.Text + "(" + dt.Rows.Count + ")";
}
else
{
this.TabControl.TabPages.Remove(this.tabpage_sign);
}
}
#endregion
#region 加载其他属性
/// <summary>
/// <para>说明:加载其他属性</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-08</para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void InitOtherParms()
{
Dictionary<object, Hashtable> dataCaches = SysModel != null ? SysModel.DataCaches : null;
if (!dataCaches.GetValue(this, "CheckSuggestionDataSource", out DataTable dt))
{
dt = BaseImpl.GetDataTableResult(this.AuditModelObj.SuggestionSql);
}
this.CheckSuggestion.ValueField = this.CheckSuggestion.TextField = "Mix_apellation";
this.CheckSuggestion.SetDataSource(dt);
this.CheckSuggestion.TextEdit.SelectedIndex = 0;
this.CheckSuggestion.TextEdit.SelectedValueChanged += new EventHandler(CheckSuggestion_Click);
this.txt_billDocumentId.EditText = this.SysModel.BillDocumentId;
this.label_date.EditText = DateTime.Now.ToString();
if (!string.IsNullOrWhiteSpace(this.AuditModelObj.StepApplyContent))
{
this.txtRemark.Text = this.AuditModelObj.StepApplyContent;
}
}
#endregion
#region 是否为确认审核功能
/// <summary>
/// <para>说明:是否是确认审核</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-08</para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void InitOkBtn()
{
if (this.SysModel.ConfirmId == "1")
{
this.btnAccradit.Enabled = true;
this.btnRemindAccradit.Visible = this.btnRemindBack.Visible = this.btnSave.Visible = this.btnClose.Visible = this.btnSpare.Visible = this.btnBack.Visible = false;
this.btnAccradit.Text = "确认(&Y)";
this.btnAccradit.Text = "确认(&Y)";
this.label_auditPerson.Text = "确认意见";
this.label_date.EditText = "会签人";
this.txtRemark.Text = "确认";
}
}
#endregion
#region 常用意见
/// <summary>
/// <para>说明:常用意见下拉框事件</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-08</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 CheckSuggestion_Click(object sender, EventArgs e)
{
try
{
this.txtRemark.Text = this.CheckSuggestion.EditText;
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
#endregion
#region 表格双击事件
/// <summary>
/// <para>说明:双击表格</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-08</para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void gridView_DoubleClick(object sender, EventArgs e)
{
try
{
GridViewClick("2");
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
#endregion
#region 表格选中双击共用函数
/// <summary>
/// <para>说明:gridBillInfo点击事件共用函数</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-08</para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// <param name="frequency">1表示点击进入,2表示双击进入</param>
/// </summary>
private void GridViewClick(string frequency)
{
foreach (XtraTabPage tabPage in this.tab_basicInfo.TabControlObj.TabPages)
{
GridDetailModel model = this.tab_basicInfo.GetGridDetailModel(tabPage);
//是否为双击进入
if (model.DBClickEvent && !frequency.Equals("2")) return;
DataRow dataRow = this.BillModelObj.DetailTreeTable ? (this.gridBillInfo as TreeGridControlEx).GetViewFocusedDataRow() : this.gridBillInfo.GridView.GetFocusedDataRow();
//条件判断
if (!string.IsNullOrWhiteSpace(model.Enablecond) && !this.ValidateCond(model.Enablecond, dataRow))
{
//配置了条件,并且不满足条件
this.tab_basicInfo.SetGridDataSource(tabPage, new DataTable());
continue;
}
bool isDetailAttach = (model.IsReadOnly || model.IsChart);
if (tabPage.Tag is ModuleWebView)
{
// 加载网页
string url = ReplaceHelper.ReplaceRowParam(dataRow, 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(dataRow, 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(dataRow, 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 GridControlEx)
{
string sqlValue = isDetailAttach ? ReplaceHelper.ReplaceRowParam(dataRow, model.DetailSql) : GetSearchSql(model);
GridControlEx grdExMain = (tabPage.Tag as GridControlEx);
if (!isDetailAttach) grdExMain.LastSearchSql = sqlValue;
//this.tab_basicInfo.SetGridDataSource(tabPage, MainImpl.GetDataTableResult(sqlValue));
this.tab_basicInfo.SetGridDataSource(tabPage, sqlValue);
}
else if (tabPage.Tag is TabMultipledetails)
{
TabMultipledetails tabMultipledetails = tabPage.Tag as TabMultipledetails;
tabMultipledetails.SetConditionValues(dataRow);
GridControlEx grdExMain = (tabMultipledetails.SplitMain.Panel1.Tag as GridControlEx);
GridDetailModel MainModel = grdExMain.Tag as GridDetailModel;
string searchMainSql = isDetailAttach ? ReplaceHelper.ReplaceRowParam(dataRow, MainModel.DetailSql) : this.GetSearchSql(MainModel);
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 = isDetailAttach ? ReplaceHelper.ReplaceRowParam(dataRow, AdditionalModel.DetailSql) : this.GetSearchSql(AdditionalModel);
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);
DataTable table = MainImpl.GetDataTableResult(searchAddSql);
grdExAdditional.CreateChart(table);
}
}
else
{
string sqlValue = isDetailAttach ? ReplaceHelper.ReplaceRowParam(dataRow, model.DetailSql) : GetSearchSql(model);
this.tab_basicInfo.SetGridDataSource(tabPage, sqlValue);
}
}
}
#endregion
#region 获取查询条件
/// <summary>
/// <para>说明:获取查询条件</para>
/// <para>创建人:王一帆</para>
/// <para>创建日期:2021-01-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)
{
string fieldName = !string.IsNullOrEmpty(model.UnionParentField) ? model.UnionParentField : BaseImpl.GetBasePrimaryKey(model.UnionModule);
DataRow dr = this.BillModelObj.DetailTreeTable ? (this.gridBillInfo as TreeGridControlEx).GetViewFocusedDataRow() : this.gridBillInfo.GridView.GetFocusedDataRow();
fieldName = dr.Table.Columns.Contains(fieldName) ? dr[fieldName].ToString() : this.ControlObj.PrimaryValue;
string sqlValue = model.IsReadOnly || model.IsChart ? model.DetailSql : model.SystemModel.MenuSql;
if (ReplaceHelper.IsSelect(sqlValue) && !string.IsNullOrEmpty(model.UnionValue))
{
string[] sqlValues = sqlValue.Split(new string[] { "where " }, StringSplitOptions.None);
if (sqlValues.Length > 1)
{
string sql = string.Empty;
for (int i = 0; i < sqlValues.Length; i++)
{
if (i == sqlValues.Length - 2)
{
sql += sqlValues[i] + string.Format(" where {0}='{1}' and ", model.UnionValue, fieldName) + sqlValues[i + 1];
break;
}
sql += sqlValues[i] + " where ";
}
sqlValue = sql;
}
else
{
sqlValue = ReplaceHelper.ReplaceWhereCond(sqlValue) + string.Format(" and {0}='{1}'", model.UnionValue, fieldName);
}
}
if (!string.IsNullOrEmpty(model.UnionCond))
{
string UnionCond = ReplaceHelper.ReplaceRowParam(dr, model.UnionCond);
sqlValue += UnionCond;
}
return sqlValue;
}
#endregion
#region 表格选中改变事件
/// <summary>
/// <para>说明:gridBillInfo选中事件</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-08</para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void gridBillInfo_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e)
{
try
{
GridViewClick("1");
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:gridBillInfo焦点行改变事件</para>
/// <para>创建人:曹屹峰</para>
/// <para>创建日期:2023-10-13</para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void GridView_FocusedRowObjectChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventArgs e)
{
try
{
GridViewClick("1");
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
private void TreeListObj_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
{
try
{
GridViewClick("1");
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
#endregion
#region 关闭
/// <summary>
/// <para>说明:关闭</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-08</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 btnClose_Click(object sender, EventArgs e)
{
try
{
if (!string.IsNullOrEmpty(this.AuditModelObj.StepCloseTip) && MessageUtil.Show(this.AuditModelObj.StepCloseTip, MessageBoxButtons.YesNo) == DialogResult.Yes)
{
string nextSelectStepCode = string.Empty;
string nextSelectStepOper = string.Empty;
this._auditAdvice = txtRemark.Text;
//string result = BaseAuditImpl.Audit(out nextSelectStepCode, out nextSelectStepOper, this.SysModel, this.SysModel.StepCode, this.SysModel.BillDocumentId, "", "p_BillAudit", "Q", "0", this.txtRemark.Text, "", "", true, -1);
//string result = BaseAuditImpl.Audit(out nextSelectStepCode, out nextSelectStepOper, out string msgText, this.SysModel, this.SysModel.StepCode, this.SysModel.BillDocumentId, "", "p_BillAudit", "Q", "0", this.txtRemark.Text, "", "", true, -1);
string result = this.AuditMethod(out nextSelectStepCode, out nextSelectStepOper, out string msgText, this.SysModel, this.SysModel.StepCode, this.SysModel.BillDocumentId, "", "p_BillAudit", "Q", "0", this.txtRemark.Text, "", "", true, -1);
if ("1".Equals(result))
{
MessageUtil.Show(ResourceKeys.CloseSuccess);
this.DialogResult = DialogResult.OK;
}
else
{
if (!"9".Equals(result)) MessageUtil.Show(ResourceKeys.CloseFail + "\r\n" + msgText);
}
}
}
catch (Exception ex)
{
LogUtil.WriteError("关闭出错!", ex);
//MessageUtil.Show("关闭出错!" + ex);
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
#endregion
#region 返回审核
/// <summary>
/// <para>说明:返回审核</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-09</para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="row">The row.</param>
/// <returns>System.Int32.</returns>
private int ExecuteBackSelect(DataRow row)
{
if (row == null)
{
MessageUtil.Show(ResourceKeys.NoFindAntiauditBill);
return -9;
}
if (this.BillModelObj.BackSelected == "0") return -1;
if (this.SysModel.StepCode == "100")
{
FrmBackSelect frmBackSelNew = new FrmBackSelect();
//frmBackSelNew.FrmBackSelectEx.StepSelection.Hide();
frmBackSelNew.SysModel = this.SysModel;
frmBackSelNew.BillModelObj = this.BillModelObj;
frmBackSelNew.FrmBackSelectEx.LabelAdvice.EditText = this.CheckSuggestion.EditText;
frmBackSelNew.InitControlSpecial();
if (frmBackSelNew.ShowDialog() != DialogResult.OK) return -9;
this._auditAdvice = frmBackSelNew.ComfirmMsg;
return 0;
}
FrmBackSelect frmBackSel = new FrmBackSelect();
frmBackSel.SysModel = this.SysModel;
frmBackSel.BillModelObj = this.BillModelObj;
frmBackSel.FrmBackSelectEx.LabelAdvice.EditText = this.CheckSuggestion.EditText;
frmBackSel.InitControl();
if (frmBackSel.ShowDialog() != DialogResult.OK) return -9;
this._auditAdvice = frmBackSel.ComfirmMsg;
return frmBackSel.SelectStepCode;
}
#endregion
#region 审核事件
/// <summary>
/// <para>说明:提醒审核事件</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2020-08-20</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 btnRemindAccradit_Click(object sender, EventArgs e)
{
try
{
if (VerificationRequired()) return;
if (this.SysModel.ConfirmId == "1" || this.SysModel.StepOver == "1")
{
if (BillAuditImpl.ConfirmAudit(this.SysModel.UserId, this.txtRemark.Text, this.SysModel.ModuleCode, this.SysModel.BillDocumentId) > 0)
{
MessageUtil.Show(ResourceKeys.ConfirmSuccess);
//this.Close();
this.DialogResult = DialogResult.OK;
if (refreshThePage != null)
{
refreshThePage("", ERPInfo.Instance.PageControl.SelectedTabPage.Tag + "");
}
else
{
//上一次点开page 当前打开page删除后要选中的page
if (ERPInfo.Instance.PageControl != null)
{
string id = ERPInfo.Instance.PageControl.SelectedTabPage.Tag + "";
XtraTabPage beforePage = ERPInfo.Instance.ModuleForms[id].BeforePage;
if (beforePage != null)
{
//要删除的page
XtraTabPage removePage = new XtraTabPage();
ERPInfo.Instance.ModuleForms.Remove(id);
foreach (XtraTabPage tablepage in ERPInfo.Instance.PageControl.TabPages)
{
if (tablepage.Tag == null) continue;
if (tablepage.Tag.ToString().Equals(id)) removePage = tablepage;
if (tablepage == beforePage) ERPInfo.Instance.PageControl.SelectedTabPage = beforePage;
}
ERPInfo.Instance.PageControl.TabPages.Remove(removePage);
removePage.Dispose();
}
}
}
}
else
{
MessageUtil.Show(ResourceKeys.ConfirmFail);
}
}
else
{
bool isAudit = true;
string confirmOpers = string.Empty, remindOpers = string.Empty;
FrmRemindSelectForm formRemind = new FrmRemindSelectForm();
formRemind.FieldValue = this.SysModel.BillDocumentId;
formRemind.MenuCode = this.SysModel.ModuleCode;
isAudit = formRemind.ShowDialog() == DialogResult.Yes;
confirmOpers = formRemind.ConfirmOpers;
remindOpers = formRemind.RemindOpers;
string nextSelectStepCode = string.Empty;
string nextSelectStepOper = string.Empty;
if (isAudit)
{
if (this.ControlObj.isRequiredFields(this.AuditModelObj.RequiredFields))
{
if (this.BillModelObj.DetailTreeTable)
{
if (!(this.gridBillInfo as TreeGridControlEx).isRequiredFields(this.AuditModelObj.RequiredDetailFields)) return;
}
else
{
if (!this.gridBillInfo.GridControl.isRequiredFields(this.AuditModelObj.RequiredDetailFields, this.gridBillInfo.GridView)) return;
}
if (!SaveBillData(0, false)) return;
//string result = BaseAuditImpl.Audit(out nextSelectStepCode, out nextSelectStepOper, this.SysModel, this.SysModel.StepCode, this.SysModel.BillDocumentId, "", this.BillAuditComObj.ProcedureName, "F", this._flowTypeStepModel.RemindSelect, this.txtRemark.Text, remindOpers, confirmOpers);
//string result = BaseAuditImpl.Audit(out nextSelectStepCode, out nextSelectStepOper, out string msgText, this.SysModel, this.SysModel.StepCode, this.SysModel.BillDocumentId, "", this.BillAuditComObj.ProcedureName, "F", this._flowTypeStepModel.RemindSelect, this.txtRemark.Text, remindOpers, confirmOpers);
string result = this.AuditMethod(out nextSelectStepCode, out nextSelectStepOper, out string msgText, this.SysModel, this.SysModel.StepCode, this.SysModel.BillDocumentId, "", this.BillAuditComObj.ProcedureName, "F", this._flowTypeStepModel.RemindSelect, this.txtRemark.Text, remindOpers, confirmOpers);
if ("1".Equals(result))
{
PushHelper push = new PushHelper(this.SysModel.BillDocumentId, this.SysModel.StepCode, this.SysModel.ModuleCode, this._beforeUsers, this._beforeMenuName, this._beforeId);
push.Push_Bill_Oper_Message();
this.DialogResult = DialogResult.OK;
if (refreshThePage != null)
{
refreshThePage("审核成功", ERPInfo.Instance.PageControl.SelectedTabPage.Tag + "");
}
else
{
//上一次点开page 当前打开page删除后要选中的page
if (ERPInfo.Instance.PageControl != null)
{
string id = ERPInfo.Instance.PageControl.SelectedTabPage.Tag + "";
XtraTabPage beforePage = ERPInfo.Instance.ModuleForms[id].BeforePage;
if (beforePage != null)
{
//MessageUtil.Show("审核成功");
//要删除的page
XtraTabPage removePage = new XtraTabPage();
ERPInfo.Instance.ModuleForms.Remove(id);
foreach (XtraTabPage tablepage in ERPInfo.Instance.PageControl.TabPages)
{
if (tablepage.Tag == null) continue;
if (tablepage.Tag.ToString().Equals(id)) removePage = tablepage;
if (tablepage == beforePage) ERPInfo.Instance.PageControl.SelectedTabPage = beforePage;
}
ERPInfo.Instance.PageControl.TabPages.Remove(removePage);
removePage.Dispose();
}
}
}
}
else
{
if (!"9".Equals(result)) MessageUtil.Show(ResourceKeys.AuditFail + "\r\n" + msgText);
}
}
}
}
}
catch (Exception ex)
{
LogUtil.WriteError("提醒审核事件出错!", ex);
//MessageUtil.Show("提醒审核事件出错!" + ex);
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:审核事件</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-09</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 btnAccradit_Click(object sender, EventArgs e)
{
try
{
//下方页签保存
if (this.BillModelObj.ReviewSaveAdditional)
{
this.SaveAdditionalModules();
}
if (VerificationRequired()) return;
this.Info("点击审核按钮");
WaitForm.ShowForm(ResourceKeys.Handing);
if (this.SysModel.ConfirmId == "1")
{
if (BillAuditImpl.ConfirmAudit(this.SysModel.UserId, this.txtRemark.Text, this.SysModel.ModuleCode, this.SysModel.BillDocumentId) > 0)
{
MessageUtil.Show(ResourceKeys.ConfirmSuccess);
this.DialogResult = DialogResult.OK;
//this.Close();
if (refreshThePage != null)
{
refreshThePage("", ERPInfo.Instance.PageControl.SelectedTabPage.Tag + "");
}
else
{
//上一次点开page 当前打开page删除后要选中的page
if (ERPInfo.Instance.PageControl != null)
{
string id = ERPInfo.Instance.PageControl.SelectedTabPage.Tag + "";
XtraTabPage beforePage = ERPInfo.Instance.ModuleForms[id].BeforePage;
if (beforePage != null)
{
//要删除的page
XtraTabPage removePage = new XtraTabPage();
ERPInfo.Instance.ModuleForms.Remove(id);
foreach (XtraTabPage tablepage in ERPInfo.Instance.PageControl.TabPages)
{
if (tablepage.Tag == null) continue;
if (tablepage.Tag.ToString().Equals(id)) removePage = tablepage;
if (tablepage == beforePage) ERPInfo.Instance.PageControl.SelectedTabPage = beforePage;
}
ERPInfo.Instance.PageControl.TabPages.Remove(removePage);
removePage.Dispose();
}
}
}
}
else
{
MessageUtil.Show(ResourceKeys.ConfirmFail);
}
}
else
{
bool isAudit = true;
string confirmOpers = string.Empty, remindOpers = string.Empty;
string nextSelectStepCode = string.Empty;
string nextSelectStepOper = string.Empty;
if (isAudit)
{
if (SystemInfo.Instance.auditComfirmOpers.Split(',').Contains(ERPInfo.Instance.UserName) || "1".Equals(SystemInfo.Instance.auditComfirmOpers))
{
if (MessageUtil.Show(string.Format(ResourceKeys.ConfirmIsAudit), MessageBoxButtons.YesNo) == DialogResult.No)
{
return;
}
}
if (this.ControlObj.isRequiredFields(this.AuditModelObj.RequiredFields))
{
if (this.BillModelObj.DetailTreeTable)
{
if (!(this.gridBillInfo as TreeGridControlEx).isRequiredFields(this.AuditModelObj.RequiredDetailFields)) return;
}
else
{
if (!this.gridBillInfo.GridControl.isRequiredFields(this.AuditModelObj.RequiredDetailFields, this.gridBillInfo.GridView)) return;
}
if (!SaveBillData(0, false)) return;
string opinion = this.txtRemark.Text;//审核意见
if (this.CheckSuggestion.EditText.Equals("不同意"))
{
opinion = this.CheckSuggestion.EditText + "^" + opinion;
}
//审核前调用
if (ApiHelper.IsExecEventApi(Interface.Api.OperateEvent.BeforeModuleAuditStateChange, this.SysModel.ModuleCode, 0))
{
ApiHelper apiHelper = new ApiHelper(this.SysModel.ModuleCode, this.SysModel.BillDocumentId, this.BillModelObj.PrimaryKey, this.BillModelObj.MasterTable, 0);
apiHelper.OnEvent(Interface.Api.OperateEvent.BeforeModuleAuditStateChange, Interface.Api.ActionType.Audit);//审核
if (!apiHelper.apiHandler.GetApiSuccess(apiHelper.apiHandlerModels))
{
DialogResult dialogResult = MessageUtil.Show(ResourceKeys.AuditFail + "\r\n" + apiHelper.apiResutMsg);
return;
}
}
//string result = BaseAuditImpl.Audit(out nextSelectStepCode, out nextSelectStepOper,
//this.SysModel, this.SysModel.StepCode, this.SysModel.BillDocumentId, "", this.BillAuditComObj.ProcedureName, "F", this._flowTypeStepModel.RemindSelect, opinion, remindOpers, confirmOpers);
//string result = BaseAuditImpl.Audit(out nextSelectStepCode, out nextSelectStepOper, out string msgText, this.SysModel, this.SysModel.StepCode, this.SysModel.BillDocumentId, "", this.BillAuditComObj.ProcedureName, "F", this._flowTypeStepModel.RemindSelect, opinion, remindOpers, confirmOpers);
string result = this.AuditMethod(out nextSelectStepCode, out nextSelectStepOper, out string msgText, this.SysModel, this.SysModel.StepCode, this.SysModel.BillDocumentId, "", this.BillAuditComObj.ProcedureName, "F", this._flowTypeStepModel.RemindSelect, opinion, remindOpers, confirmOpers);
this.Info($"审核单号:{this.SysModel.BillDocumentId},审核结果返回:{result}");
WaitForm.HideForm();
if ("1".Equals(result))
{
//推送消息
PushHelper push = new PushHelper(this.SysModel.BillDocumentId, this.SysModel.StepCode, this.SysModel.ModuleCode, this._beforeUsers, this._beforeMenuName, this._beforeId);
push.Push_Bill_Oper_Message();
#region 审核成功后调用API
this.Info($"审核后执行接口:AfterModuleAuditStateChangeModuleCode:{this.SysModel.ModuleCode}");
if (ApiHelper.IsExecEventApi(Interface.Api.OperateEvent.AfterModuleAuditStateChange, this.SysModel.ModuleCode, 0))
{
ApiHelper apiHelper = new ApiHelper(this.SysModel.ModuleCode, this.SysModel.BillDocumentId, this.BillModelObj.PrimaryKey, this.BillModelObj.MasterTable, 0);
this.Info($"进入执行逻辑");
apiHelper.OnEvent(Interface.Api.OperateEvent.AfterModuleAuditStateChange, Interface.Api.ActionType.Audit);//审核
if (!apiHelper.apiHandler.GetApiSuccess(apiHelper.apiHandlerModels))
{
MessageUtil.Show(apiHelper.apiResutMsg);
}
}
#endregion
this.DialogResult = DialogResult.OK;
if (refreshThePage != null)
{
refreshThePage("审核成功", ERPInfo.Instance.PageControl.SelectedTabPage.Tag + "");
}
else
{
//上一次点开page 当前打开page删除后要选中的page
if (ERPInfo.Instance.PageControl != null)
{
string id = ERPInfo.Instance.PageControl.SelectedTabPage.Tag + "";
XtraTabPage beforePage = ERPInfo.Instance.ModuleForms[id].BeforePage;
if (beforePage != null)
{
//MessageUtil.Show("审核成功");
//要删除的page
XtraTabPage removePage = new XtraTabPage();
ERPInfo.Instance.ModuleForms.Remove(id);
foreach (XtraTabPage tablepage in ERPInfo.Instance.PageControl.TabPages)
{
if (tablepage.Tag == null) continue;
if (tablepage.Tag.ToString().Equals(id)) removePage = tablepage;
if (tablepage == beforePage) ERPInfo.Instance.PageControl.SelectedTabPage = beforePage;
}
ERPInfo.Instance.PageControl.TabPages.Remove(removePage);
removePage.Dispose();
}
}
}
}
else
{
if (!"9".Equals(result)) MessageUtil.Show(ResourceKeys.AuditFail + "\r\n" + msgText);
}
}
}
}
}
catch (Exception ex)
{
LogUtil.WriteError("审核事件出错!", ex);
MessageUtil.Show("审核事件出错!" + ex);
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
finally
{
WaitForm.HideForm();
}
}
#endregion
#region 分单
/// <summary>
/// <para>说明:分单</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-09</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 btnSpare_Click(object sender, EventArgs e)
{
try
{
FrmSpare spare = new FrmSpare();
spare.SysModel = this.SysModel;
spare.BillModel = this.BillModelObj;
spare.DtSource = this._dtSourceData;
spare.DetailSql = this.BillModelObj.DetailSql;
spare.DtNewSource = this._dtSpareSourceData;
DialogResult result = spare.ShowDialog();
this._dtSpareSourceData = spare.DtNewSource;
if (result == DialogResult.OK) checkBillSplite();
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
#endregion
#region 检查分单
/// <summary>
/// <para>说明:检查分单</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-09</para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <returns>System.Boolean.</returns>
private bool checkBillSplite()
{
bool createResult = false;
try
{
if (this._dtSourceData.Rows.Count > 0)
{
createSourceBillId();
//复制单据数据
createResult = createBill();
if (createResult)
{
if (this.BillModelObj.DetailTreeTable)
{
(this.gridBillInfo as TreeGridControlEx).SetGridViewDataSourceGenerateID(_dtSourceData);
}
else
{
this.gridBillInfo.SetGridViewDataSource(_dtSourceData);
}
}
}
}
catch (Exception ex)
{
//MessageUtil.Show(ex);
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
return createResult;
}
#endregion
#region 单据来源
/// <summary>
/// <para>说明:单据来源</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-09</para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void createSourceBillId()
{
try
{
BillAuditImpl.CreateSourceBillId(this.BillModelObj.MasterTable);
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
#endregion
#region 导出单据明细
private void btnExport_Click(object sender, EventArgs e)
{
try
{
this.gridBillInfo.GridControl.ToExcel(this.SysModel.FormText);
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
#endregion
#region 分配明细
private void OnBtnFPClick(object sender, EventArgs e)
{
try
{
this.gridBillInfo.GridControl.ToExcel(this.SysModel.FormText);
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
#endregion
#region 分单创建单据
/// <summary>
/// <para>说明:分单创建单据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-10</para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private bool createBill()
{
string defaultValue = SqlHelper.ExecuteScalar(string.Format("select defaultValue from p_systembillinfo where typecode = '{0}' and fieldName = '{1}'", this.SysModel.ModuleCode, this.BillModelObj.MasterPreFix + "billdocument_id")) + "";
if (!string.IsNullOrEmpty(defaultValue))
{
defaultValue = BaseImpl.GetDefaultValue(defaultValue);
}
string billNo = this.BillModelObj.NewVer == 1 || SystemInfo.Instance.SplitOrderNewVer ? BillImpl.GetBillNo(this.BillModelObj.BillSeq) : defaultValue;
//构造表头
string masterSql = this.GetBillHearder(billNo);
//构造明细"@billdocument_id@"
string detailSql = this.GetBillDetail(this.BillModelObj.NewVer == 1 ? billNo : billNo);
//分单处理
string msg = string.Empty;
string detailGuid = Guid.NewGuid().ToString();
//int returnValue = BillImpl.BillSave(masterSql, detailSql, BillModelObj.DetailTable, ref billNo, detailGuid, BillModelObj.BillSeq, BillModelObj.SaveState ? 2 : 1, 0, out msg, 0, this.BillModelObj.NewVer);
int returnValue = BillAuditImpl.SpliteBill(out msg, masterSql, detailSql, billNo, this.SysModel.ModuleCode, this.SysModel.BillDocumentId);
if (returnValue == 1)
{
MessageUtil.Show(ResourceKeys.SpliterBillSuccess);
//this._dtSourceData = BillImpl.GetDataTableResult(ReplaceHelper.ReplaceParamToValue(this.BillModelObj.DetailSql, this.SysModel.BillDocumentId));
this._dtSourceData = BillImpl.GetDataTableResult(ReplaceHelper.ReplaceRowParam(_drBillInfoMsg, this.BillModelObj.DetailSql));
this._dtSourceData.OrderBy(this.BillModelObj.DetailOrderField);
this._dtSpareSourceData.Clear();
return true;
}
else if (returnValue != 9)
{
MessageUtil.Show(string.Format(ResourceKeys.SpliterBillFail, returnValue, msg));
}
return false;
}
#endregion
#region 构造表头
/// <summary>
/// <para>说明:构造表头</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-09</para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private string GetBillHearder(string billNo)
{
StringBuilder fieldBuilder = new StringBuilder();
StringBuilder valueBuilder = new StringBuilder();
DataTable rowTab = SqlHelper.ExecuteDataTable(string.Format("select * from {0} where {1} = '{2}'", this.BillModelObj.MasterTable, this.BillModelObj.PrimaryKey, this.SysModel.BillDocumentId));
if (rowTab != null && rowTab.Rows.Count > 0)
{
DataRow row = rowTab.Rows[0];
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", this.BillModelObj.MasterTable)) + "";//自增长列
foreach (DataColumn column in row.Table.Columns)
{
if (column.ColumnName.Equals(autogrowcolumn) || column.ColumnName.Equals(this.BillModelObj.PrimaryKey, StringComparison.CurrentCultureIgnoreCase))
continue;
string fieldValue = row[column] + "";
fieldBuilder.Append(column.ColumnName + ",");
valueBuilder.AppendFormat("'{0}',", fieldValue);
}
}
//foreach (ControlModel model in this.ControlObj.ControlModels)
//{
// if (!model.IsSave ||
// model.FieldName.Equals(BillModelObj.PrimaryKey, StringComparison.OrdinalIgnoreCase) ||
// model.FieldType == ControlType.LabPic ||
// model.FieldType == ControlType.LabPicEx)
// continue;
// string fieldValue = this.ControlObj.GetControlValue(model);
// fieldBuilder.Append(model.FieldName + ",");
// valueBuilder.AppendFormat("'{0}',", fieldValue);
//}
fieldBuilder.Append(this.BillModelObj.PrimaryKey + ",");
valueBuilder.AppendFormat("'{0}',", billNo);
return string.Format(@"insert into {0} ({1})values({2})", this.BillModelObj.MasterTable, fieldBuilder.ToString().TrimEnd(','), valueBuilder.ToString().TrimEnd(','));
}
#endregion
#region 构造明细
/// <summary>
/// <para>说明:构造明细</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-09</para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="billNo">单据编号.</param>
private string GetBillDetail(string billNo)
{
string ids = string.Empty;
string detailPrefix = BaseImpl.GetColumnPrefix(this.BillModelObj.DetailTable);
string sourceId = detailPrefix + "id";
foreach (DataRow item in _dtSpareSourceData.Rows)
{
ids += item[sourceId] + ",";
}
return string.Format("update {0} set {1}Billdocument_id='{2}' where {4} in ({3})", this.BillModelObj.DetailTable, detailPrefix, billNo, ids.TrimEnd(','), sourceId);
}
#endregion
#region 返退
/// <summary>
/// <para>说明:提醒返回审核</para>
/// <para>创建人:王一帆</para>
/// <para>创建日期:2020-08-20</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 btnRemindReturn_Click(object sender, EventArgs e)
{
try
{
if (VerificationRequired()) return;
this._auditAdvice = txtRemark.Text;
int ret = ExecuteBackSelect(this._drBillInfoMsg);
if (ret == -9) return;
string nextSelectStepCode = string.Empty;
string nextSelectStepOper = string.Empty;
if (this.SysModel.StepOver == "1")
{
if (MessageUtil.Show(ResourceKeys.ConfimAuditFailAndReturnBill, MessageBoxButtons.YesNo) == DialogResult.Yes)
{
// string result = BaseAuditImpl.Audit(out nextSelectStepCode, out nextSelectStepOper,
//this.SysModel, this.SysModel.StepCode, this.SysModel.BillDocumentId, "", this.BillAuditComObj.ProcedureName, "R", this._flowTypeStepModel.RemindSelect, this._auditAdvice, "", "", true, ret, 0, true);
// string result = BaseAuditImpl.Audit(out nextSelectStepCode, out nextSelectStepOper, out string msgText,
//this.SysModel, this.SysModel.StepCode, this.SysModel.BillDocumentId, "", this.BillAuditComObj.ProcedureName, "R", this._flowTypeStepModel.RemindSelect, this._auditAdvice, "", "", true, ret, 0, true);
string result = this.AuditMethod(out nextSelectStepCode, out nextSelectStepOper, out string msgText,
this.SysModel, this.SysModel.StepCode, this.SysModel.BillDocumentId, "", this.BillAuditComObj.ProcedureName, "R", this._flowTypeStepModel.RemindSelect, this._auditAdvice, "", "", true, ret, 0, true);
if (result == "1")
{
MessageUtil.Show(ResourceKeys.ForcedSuccess);
PushHelper push = new PushHelper(this.SysModel.BillDocumentId, this.SysModel.StepCode, this.SysModel.ModuleCode, this._beforeUsers, this._beforeMenuName, this._beforeId);
push.Push_Bill_Oper_Message();
this.DialogResult = DialogResult.OK;
if (refreshThePage != null)
{
refreshThePage("", ERPInfo.Instance.PageControl.SelectedTabPage.Tag + "");
}
else
{
//上一次点开page 当前打开page删除后要选中的page
if (ERPInfo.Instance.PageControl != null)
{
string id = ERPInfo.Instance.PageControl.SelectedTabPage.Tag + "";
XtraTabPage beforePage = ERPInfo.Instance.ModuleForms[id].BeforePage;
if (beforePage != null)
{
//要删除的page
XtraTabPage removePage = new XtraTabPage();
ERPInfo.Instance.ModuleForms.Remove(id);
foreach (XtraTabPage tablepage in ERPInfo.Instance.PageControl.TabPages)
{
if (tablepage.Tag == null) continue;
if (tablepage.Tag.ToString().Equals(id)) removePage = tablepage;
if (tablepage == beforePage) ERPInfo.Instance.PageControl.SelectedTabPage = beforePage;
}
ERPInfo.Instance.PageControl.TabPages.Remove(removePage);
removePage.Dispose();
}
}
}
}
else
{
if (!"9".Equals(result)) MessageUtil.Show(string.Format(ResourceKeys.ForcedFail, msgText));
}
}
}
else
{
bool isAudit = true;
string confirmOpers = string.Empty, remindOpers = string.Empty;
FrmRemindSelectForm formRemind = new FrmRemindSelectForm();
formRemind.FieldValue = this.SysModel.BillDocumentId;
formRemind.MenuCode = this.SysModel.ModuleCode;
isAudit = formRemind.ShowDialog() == DialogResult.Yes;
confirmOpers = formRemind.ConfirmOpers;
remindOpers = formRemind.RemindOpers;
if (isAudit)
{
// string result = BaseAuditImpl.Audit(out nextSelectStepCode, out nextSelectStepOper,
//this.SysModel, this.SysModel.StepCode, this.SysModel.BillDocumentId, "", this.BillAuditComObj.ProcedureName, "R", this._flowTypeStepModel.RemindSelect, this._auditAdvice, remindOpers, confirmOpers, true, ret);
// string result = BaseAuditImpl.Audit(out nextSelectStepCode, out nextSelectStepOper, out string msgText,
//this.SysModel, this.SysModel.StepCode, this.SysModel.BillDocumentId, "", this.BillAuditComObj.ProcedureName, "R", this._flowTypeStepModel.RemindSelect, this._auditAdvice, remindOpers, confirmOpers, true, ret);
string result = this.AuditMethod(out nextSelectStepCode, out nextSelectStepOper, out string msgText,
this.SysModel, this.SysModel.StepCode, this.SysModel.BillDocumentId, "", this.BillAuditComObj.ProcedureName, "R", this._flowTypeStepModel.RemindSelect, this._auditAdvice, remindOpers, confirmOpers, true, ret);
if (result == "1")
{
MessageUtil.Show(ResourceKeys.ForcedSuccess);
PushHelper push = new PushHelper(this.SysModel.BillDocumentId, this.SysModel.StepCode, this.SysModel.ModuleCode, this._beforeUsers, this._beforeMenuName, this._beforeId);
push.Push_Bill_Oper_Message();
this.DialogResult = DialogResult.OK;
if (refreshThePage != null)
{
refreshThePage("", ERPInfo.Instance.PageControl.SelectedTabPage.Tag + "");
}
else
{
//上一次点开page 当前打开page删除后要选中的page
if (ERPInfo.Instance.PageControl != null)
{
string id = ERPInfo.Instance.PageControl.SelectedTabPage.Tag + "";
XtraTabPage beforePage = ERPInfo.Instance.ModuleForms[id].BeforePage;
if (beforePage != null)
{
//要删除的page
XtraTabPage removePage = new XtraTabPage();
ERPInfo.Instance.ModuleForms.Remove(id);
foreach (XtraTabPage tablepage in ERPInfo.Instance.PageControl.TabPages)
{
if (tablepage.Tag == null) continue;
if (tablepage.Tag.ToString().Equals(id)) removePage = tablepage;
if (tablepage == beforePage) ERPInfo.Instance.PageControl.SelectedTabPage = beforePage;
}
ERPInfo.Instance.PageControl.TabPages.Remove(removePage);
removePage.Dispose();
}
}
}
}
else
{
if (!"9".Equals(result)) MessageUtil.Show(string.Format(ResourceKeys.ForcedFail, msgText));
}
}
}
}
catch (Exception ex)
{
LogUtil.WriteError("提醒返回审核出错!", ex);
//MessageUtil.Show("提醒返回审核出错!" + ex);
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:返回审核</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-09</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 btnReturn_Click(object sender, EventArgs e)
{
try
{
if (!string.IsNullOrWhiteSpace(SystemInfo.Instance.AntiAuditUrl) && this.BillModelObj.NewVer == 1)
{
//string url = string.Format("/pages/app/app.html?stepcode=200&id=YQPS250610001&xtype=plugins.BaseAccraditation.AuditBackBox&username={0}&password={1}&dllcoid=", ERPInfo.Instance.UserName, "2383C0ADDCD699FB2CB45079ABB39E3CEF242D98");
string url = ReplaceHelper.ReplaceUserInfo(SystemInfo.Instance.AntiAuditUrl);
url = url.Replace("{stepcode}", this.SysModel.StepCode).Replace("{primaryvalue}", this.SysModel.BillDocumentId).Replace("{remark}", txtRemark.Text).Replace("&isbase=1", "");
string[] defaultArgs = string.Format(ModuleArgs.DefaultArgs, this.SysModel.FormText, this.SysModel.UserId, this.SysModel.UserName, this.SysModel.Privilege, this.SysModel.ModuleCode).Split('~');
string[] menuArgs = new string[] { "", "", url };
string[] args = defaultArgs.Concat(menuArgs).ToArray();
IForm form = FormHelper.LoadDllForm(ResourceDynamic.PubBrower, args);
form.SubForm.WindowState = FormWindowState.Normal;
DialogResult result = form.SubForm.ShowDialog();
if (result == DialogResult.OK)
{
this.DialogResult = DialogResult.OK;
if (refreshThePage != null)
{
refreshThePage("", ERPInfo.Instance.PageControl.SelectedTabPage.Tag + "");
}
else
{
//上一次点开page 当前打开page删除后要选中的page
if (ERPInfo.Instance.PageControl != null)
{
string id = ERPInfo.Instance.PageControl.SelectedTabPage.Tag + "";
XtraTabPage beforePage = ERPInfo.Instance.ModuleForms[id].BeforePage;
if (beforePage != null)
{
//要删除的page
XtraTabPage removePage = new XtraTabPage();
ERPInfo.Instance.ModuleForms.Remove(id);
foreach (XtraTabPage tablepage in ERPInfo.Instance.PageControl.TabPages)
{
if (tablepage.Tag == null) continue;
if (tablepage.Tag.ToString().Equals(id)) removePage = tablepage;
if (tablepage == beforePage) ERPInfo.Instance.PageControl.SelectedTabPage = beforePage;
}
ERPInfo.Instance.PageControl.TabPages.Remove(removePage);
removePage.Dispose();
}
}
}
}
return;
}
if (VerificationRequired()) return;
this._auditAdvice = txtRemark.Text;
int ret = ExecuteBackSelect(this._drBillInfoMsg);
if (ret == -9) return;
string nextSelectStepCode = string.Empty;
string nextSelectStepOper = string.Empty;
if (this.SysModel.StepOver == "1")
{
if (MessageUtil.Show(ResourceKeys.ConfimAuditFailAndReturnBill, MessageBoxButtons.YesNo) == DialogResult.Yes)
{
if (!SaveBillData(0, false)) return;
//反退前调用
if (ApiHelper.IsExecEventApi(Interface.Api.OperateEvent.BeforeModuleAuditStateChange, this.SysModel.ModuleCode, 0))
{
ApiHelper apiHelper = new ApiHelper(this.SysModel.ModuleCode, this.SysModel.BillDocumentId, this.BillModelObj.PrimaryKey, this.BillModelObj.MasterTable, 0);
apiHelper.OnEvent(Interface.Api.OperateEvent.BeforeModuleAuditStateChange, Interface.Api.ActionType.AuditBack);//审核
if (!apiHelper.apiHandler.GetApiSuccess(apiHelper.apiHandlerModels))
{
DialogResult dialogResult = MessageUtil.Show(ResourceKeys.ForcedFail + "\r\n" + apiHelper.apiResutMsg);
return;
}
}
//string result = BaseAuditImpl.Audit(out nextSelectStepCode, out nextSelectStepOper,
//this.SysModel, this.SysModel.StepCode, this.SysModel.BillDocumentId, "", this.BillAuditComObj.ProcedureName, "R", this._flowTypeStepModel.RemindSelect, this._auditAdvice, "", "", true, ret, 0, true);
//string result = BaseAuditImpl.Audit(out nextSelectStepCode, out nextSelectStepOper, out string msgText,
//this.SysModel, this.SysModel.StepCode, this.SysModel.BillDocumentId, "", this.BillAuditComObj.ProcedureName, "R", this._flowTypeStepModel.RemindSelect, this._auditAdvice, "", "", true, ret, 0, true);
string result = this.AuditMethod(out nextSelectStepCode, out nextSelectStepOper, out string msgText,
this.SysModel, this.SysModel.StepCode, this.SysModel.BillDocumentId, "", this.BillAuditComObj.ProcedureName, "R", this._flowTypeStepModel.RemindSelect, this._auditAdvice, "", "", true, ret, 0, true);
if (result == "1")
{
MessageUtil.Show(ResourceKeys.ForcedSuccess);
PushHelper push = new PushHelper(this.SysModel.BillDocumentId, this.SysModel.StepCode, this.SysModel.ModuleCode, this._beforeUsers, this._beforeMenuName, this._beforeId);
push.Push_Bill_Oper_Message();
//反退后调用
if (ApiHelper.IsExecEventApi(Interface.Api.OperateEvent.AfterModuleAuditStateChange, this.SysModel.ModuleCode, 0))
{
ApiHelper apiHelper = new ApiHelper(this.SysModel.ModuleCode, this.SysModel.BillDocumentId, this.BillModelObj.PrimaryKey, this.BillModelObj.MasterTable, 0);
apiHelper.OnEvent(Interface.Api.OperateEvent.AfterModuleAuditStateChange, Interface.Api.ActionType.AuditBack);
if (!apiHelper.apiHandler.GetApiSuccess(apiHelper.apiHandlerModels))
{
MessageUtil.Show(apiHelper.apiResutMsg);
}
}
this.DialogResult = DialogResult.OK;
if (refreshThePage != null)
{
refreshThePage("", ERPInfo.Instance.PageControl.SelectedTabPage.Tag + "");
}
else
{
//上一次点开page 当前打开page删除后要选中的page
if (ERPInfo.Instance.PageControl != null)
{
string id = ERPInfo.Instance.PageControl.SelectedTabPage.Tag + "";
XtraTabPage beforePage = ERPInfo.Instance.ModuleForms[id].BeforePage;
if (beforePage != null)
{
//要删除的page
XtraTabPage removePage = new XtraTabPage();
ERPInfo.Instance.ModuleForms.Remove(id);
foreach (XtraTabPage tablepage in ERPInfo.Instance.PageControl.TabPages)
{
if (tablepage.Tag == null) continue;
if (tablepage.Tag.ToString().Equals(id)) removePage = tablepage;
if (tablepage == beforePage) ERPInfo.Instance.PageControl.SelectedTabPage = beforePage;
}
ERPInfo.Instance.PageControl.TabPages.Remove(removePage);
removePage.Dispose();
}
}
}
}
else
{
if (!"9".Equals(result)) MessageUtil.Show(string.Format(ResourceKeys.ForcedFail, msgText));
}
}
}
else
{
if (SystemInfo.Instance.backAuditComfirmOpers.Split(',').Contains(ERPInfo.Instance.UserName) || "1".Equals(SystemInfo.Instance.backAuditComfirmOpers))
{
if (MessageUtil.Show(string.Format(ResourceKeys.ConfimAuditFailAndReturnBill), MessageBoxButtons.YesNo) == DialogResult.No)
{
return;
}
}
bool isAudit = true;
string confirmOpers = string.Empty, remindOpers = string.Empty;
if (isAudit)
{
// string result = BaseAuditImpl.Audit(out nextSelectStepCode, out nextSelectStepOper,
//this.SysModel, this.SysModel.StepCode, this.SysModel.BillDocumentId, "", this.BillAuditComObj.ProcedureName, "R", this._flowTypeStepModel.RemindSelect, this._auditAdvice, remindOpers, confirmOpers, true, ret);
// string result = BaseAuditImpl.Audit(out nextSelectStepCode, out nextSelectStepOper, out string msgText,
//this.SysModel, this.SysModel.StepCode, this.SysModel.BillDocumentId, "", this.BillAuditComObj.ProcedureName, "R", this._flowTypeStepModel.RemindSelect, this._auditAdvice, remindOpers, confirmOpers, true, ret);
//反退前调用
if (ApiHelper.IsExecEventApi(Interface.Api.OperateEvent.BeforeModuleAuditStateChange, this.SysModel.ModuleCode, 0))
{
ApiHelper apiHelper = new ApiHelper(this.SysModel.ModuleCode, this.SysModel.BillDocumentId, this.BillModelObj.PrimaryKey, this.BillModelObj.MasterTable, 0);
apiHelper.OnEvent(Interface.Api.OperateEvent.BeforeModuleAuditStateChange, Interface.Api.ActionType.AuditBack);//审核
if (!apiHelper.apiHandler.GetApiSuccess(apiHelper.apiHandlerModels))
{
DialogResult dialogResult = MessageUtil.Show(ResourceKeys.ForcedFail + "\r\n" + apiHelper.apiResutMsg);
return;
}
}
string result = this.AuditMethod(out nextSelectStepCode, out nextSelectStepOper, out string msgText,
this.SysModel, this.SysModel.StepCode, this.SysModel.BillDocumentId, "", this.BillAuditComObj.ProcedureName, "R", this._flowTypeStepModel.RemindSelect, this._auditAdvice, remindOpers, confirmOpers, true, ret);
if (result == "1")
{
MessageUtil.Show(ResourceKeys.ForcedSuccess);
PushHelper push = new PushHelper(this.SysModel.BillDocumentId, this.SysModel.StepCode, this.SysModel.ModuleCode, this._beforeUsers, this._beforeMenuName, this._beforeId);
push.Push_Bill_Oper_Message();
//反退后调用
if (ApiHelper.IsExecEventApi(Interface.Api.OperateEvent.AfterModuleAuditStateChange, this.SysModel.ModuleCode, 0))
{
ApiHelper apiHelper = new ApiHelper(this.SysModel.ModuleCode, this.SysModel.BillDocumentId, this.BillModelObj.PrimaryKey, this.BillModelObj.MasterTable, 0);
apiHelper.OnEvent(Interface.Api.OperateEvent.AfterModuleAuditStateChange, Interface.Api.ActionType.AuditBack);
if (!apiHelper.apiHandler.GetApiSuccess(apiHelper.apiHandlerModels))
{
MessageUtil.Show(apiHelper.apiResutMsg);
}
}
this.DialogResult = DialogResult.OK;
if (refreshThePage != null)
{
refreshThePage("", ERPInfo.Instance.PageControl.SelectedTabPage.Tag + "");
}
else
{
//上一次点开page 当前打开page删除后要选中的page
if (ERPInfo.Instance.PageControl != null)
{
string id = ERPInfo.Instance.PageControl.SelectedTabPage.Tag + "";
XtraTabPage beforePage = ERPInfo.Instance.ModuleForms[id].BeforePage;
if (beforePage != null)
{
//要删除的page
XtraTabPage removePage = new XtraTabPage();
ERPInfo.Instance.ModuleForms.Remove(id);
foreach (XtraTabPage tablepage in ERPInfo.Instance.PageControl.TabPages)
{
if (tablepage.Tag == null) continue;
if (tablepage.Tag.ToString().Equals(id)) removePage = tablepage;
if (tablepage == beforePage) ERPInfo.Instance.PageControl.SelectedTabPage = beforePage;
}
ERPInfo.Instance.PageControl.TabPages.Remove(removePage);
removePage.Dispose();
}
}
}
}
else
{
if (!"9".Equals(result)) MessageUtil.Show(string.Format(ResourceKeys.ForcedFail, msgText));
}
}
}
}
catch (Exception ex)
{
LogUtil.WriteError("返回审核出错!", ex);
MessageUtil.Show("返回审核出错!" + ex);
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
#endregion
#region 记录本次推送人员
/// <summary>
/// <para>说明:记录本次推送人员</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-09 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void GetPushOpers()
{
Dictionary<object, Hashtable> dataCaches = SysModel != null ? SysModel.DataCaches : null;
if (!dataCaches.GetValue(this, "PushedOpers", out DataRow beforeOpers))
{
beforeOpers = BillAuditImpl.GetPushedOpers(this.SysModel.BillDocumentId, this.SysModel.StepCode);
}
if (beforeOpers != null)
{
//记录本次操作信息
this._beforeMenuName = beforeOpers["menuname"] + "";
this._beforeUsers = beforeOpers["operators"] + "";
this._beforeId = Convert.ToInt32(beforeOpers["id"]);
}
}
#endregion
#region 保存单据
/// <summary>
/// <para>说明:保存单据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-10 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void btnSave_Click(object sender, EventArgs e)
{
try
{
SaveBillData();
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:保存单据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-10 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="confirmFlag">保存确认标记</param>
private bool SaveBillData(int confirmFlag = 0, bool showMsg = true)
{
bool save = false;
try
{
string HeaderError = string.Empty;//表头错误
string FormError = string.Empty;//表格内容错误
string SaveErrorMessage = string.Empty;//提示错误
string guid = Guid.NewGuid().ToString();
string masterSql = GetUpdateBillHeader(out HeaderError);
string detailSql = GetDetailRecord(guid, out FormError);
if (string.IsNullOrEmpty(detailSql) && !this.BillModelObj.SaveNullDetail)
{
MessageUtil.Show(ResourceKeys.BillDetailIsNotNull);
return false;
}
string tipMsg = string.Empty;
if (!this.ControlObj.VerifyNull()) return false;
SaveErrorMessage = HeaderError + FormError;
if (!string.IsNullOrEmpty(SaveErrorMessage))
{
MessageUtil.Show(SaveErrorMessage);
return false;
}
int result = BillImpl.BillSave(masterSql, detailSql, this.BillModelObj.DetailTable, ref this.SysModel.BillDocumentId, guid, this.BillModelObj.BillSeq, 2, confirmFlag, out tipMsg, 1, this.BillModelObj.NewVer);
switch (result)
{
case 1:
if (showMsg)
MessageUtil.Show(ResourceKeys.SaveSuccess);
save = true;
//记录主键修改信息
AuditChangeLog.SaveHeaderChangeLog(this._drBillInfoMsg,this.ControlObj, this.SysModel.BillDocumentId, this.SysModel.StepCode, ERPInfo.Instance.UserId);
#region 修改保存成功后调用API
if (ApiHelper.IsExecEventApi(Interface.Api.OperateEvent.AfterModuleDataChange, this.SysModel.ModuleCode, 0))
{
ApiHelper apiHelper = new ApiHelper(this.SysModel.ModuleCode, this.SysModel.BillDocumentId, this.BillModelObj.PrimaryKey, this.BillModelObj.MasterTable, 0);
apiHelper.OnEvent(Interface.Api.OperateEvent.AfterModuleDataChange, Interface.Api.ActionType.Update);//修改
if (!apiHelper.apiHandler.GetApiSuccess(apiHelper.apiHandlerModels))
{
MessageUtil.Show(apiHelper.apiResutMsg);
}
}
#endregion
break;
case 9:
if (MessageUtil.Show(tipMsg, MessageBoxButtons.YesNo) == DialogResult.Yes)
save = SaveBillData(1, showMsg);
break;
default:
MessageUtil.Show(string.Format(ResourceKeys.OperateFail, result, tipMsg));
break;
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
if (this.BillModelObj.SaveSuccessfullyRefresh && !save) return save;//保存成功才刷新
// 刷新主表
this._drBillInfoMsg = BaseAuditImpl.GetCurrentFlowRowData(this.BillModelObj.MasterTable, this.BillModelObj.PrimaryKey, this.SysModel.BillDocumentId);
this.ControlObj.CanExecControl = false;
this.ControlObj.SetAllControlValue(this._drBillInfoMsg);//刷新表头数据
this.ControlObj.CanExecControl = true;
// 刷新明细表
//this._dtSourceData = BillImpl.GetDataTableResult(ReplaceHelper.ReplaceParamToValue(this.BillModelObj.DetailSql, this.SysModel.BillDocumentId));
this._dtSourceData = BillImpl.GetDataTableResult(ReplaceHelper.ReplaceRowParam(_drBillInfoMsg, this.BillModelObj.DetailSql));
this._dtSourceData.OrderBy(this.BillModelObj.DetailOrderField);
if (this.BillModelObj.DetailTreeTable)
{
(this.gridBillInfo as TreeGridControlEx).SetGridViewDataSourceGenerateID(_dtSourceData);
}
else
{
this.gridBillInfo.SetGridViewDataSource(_dtSourceData);
}
return save;
}
#endregion
#region 修改表头
/// <summary>
/// <para>说明:获取修改表头</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-10 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <returns>System.String.</returns>
private string GetUpdateBillHeader(out string SaveErrorMessage)
{
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}'", this.BillModelObj.MasterTable));
string errorMessage = string.Empty;
foreach (ControlModel model in this.ControlObj.ControlModels)
{
if (!model.IsSave ||
model.FieldType == ControlType.LabPic ||
model.FieldType == ControlType.LabPicEx)
continue;
if (this.ControlObj.FindControl(model) != null)
{
string fieldValue = this.ControlObj.GetControlValue(model);
string newfieldValue = fieldValue;
if (fieldValue == "****") continue;
if (SystemInfo.Instance.IsSpecialAuditSave &&
this._drBillInfoMsg != null &&
this._drBillInfoMsg.Table != null &&
this._drBillInfoMsg.Table.Columns.Contains(model.FieldName) &&
AuditChangeLog.IsSameValue(this._drBillInfoMsg[model.FieldName] + "", fieldValue))
{
continue;
}
if ((model.FieldType == ControlType.LabDate ||
model.FieldType == ControlType.LabDate ||
model.FieldType == ControlType.LabDate ||
model.FieldType == ControlType.LabDate ||
model.FieldType == ControlType.LabDate) && string.IsNullOrEmpty(fieldValue))
{
fieldValue = "NULL";
}
else
{
fieldValue = "N'" + fieldValue + "'";
}
updateBuilder.AppendFormat("{0}={1},", model.FieldName, fieldValue);
errorMessage = errorMessage + DatabaseFormatJudgment.SaveOrModifyBalidation(DetailedProperties, model, newfieldValue);
}
}
SaveErrorMessage = errorMessage;
string updateFields = updateBuilder.ToString().TrimEnd(',');
if (string.IsNullOrEmpty(updateFields))
{
return string.Empty;
}
return string.Format("update {0} set {1} where {2}='{3}'", this.BillModelObj.MasterTable, updateFields, BillModelObj.PrimaryKey, this.SysModel.BillDocumentId);
}
#endregion
#region 获取明细
/// <summary>
/// <para>说明:获取明细</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-01-10 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <returns>System.String.</returns>
private string GetDetailRecord(string guid, out string SaveErrorMessage)
{
// 构造明细
StringBuilder detailBuilder = new StringBuilder();
DataTable DetailedProperties = BaseImpl.GetDataTableResult(string.Format("select COLUMN_NAME,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH from information_schema.columns where table_name = '{0}'", BillModelObj.DetailTable + "_temp"));//单据明细性表
string errorMessage = string.Empty;
DataTable detailTable = this.gridBillInfo.GridControl.DataSourceTable().TrimDeleteRows();
if (this.BillModelObj.DetailTreeTable)
{
detailTable = ((this.gridBillInfo as TreeGridControlEx).TreeListObj.DataSource as DataTable).TrimDeleteRows();
}
if (detailTable.Rows.Count > 0)
{
DataTable BillColumns = BaseImpl.GetDataTableResult(string.Format("select * from {0} where 1<>1", BillModelObj.DetailTable));
IEnumerable<DataColumn> detailColumns = BillColumns.Columns.Cast<DataColumn>();
DataTable BillTempColumns = BaseImpl.GetDataTableResult(string.Format("select * from {0} where 1<>1", BillModelObj.DetailTable + "_temp"));
foreach (DataRow dataRow in detailTable.Rows)
{
StringBuilder fields = new StringBuilder();
StringBuilder values = new StringBuilder();
string detailSql = @"insert into " + BillModelObj.DetailTable + "_temp" + "({0}) values({1})";
fields.Append("sysstr,");
values.Append("'" + guid + "',");
foreach (DataColumn item in detailTable.Columns)
{
var selectColumn = detailColumns.Where(n => n.ColumnName.Equals(item.ColumnName, StringComparison.OrdinalIgnoreCase));
if (selectColumn.Count() == 0)
{
continue;
}
fields.Append(item.ColumnName + ",");
string fieldValue = (dataRow[item] + "").Replace("'", "''");
if (!BillTempColumns.Columns.Contains(item.ColumnName))
{
string type = "varchar(50)";
if (item.DataType == typeof(DateTime))
{
type = "datetime";
}
BaseImpl.ExecSqlValue(string.Format("alter table {0} add {1} {2}", BillModelObj.DetailTable + "_temp", item.ColumnName, type));
}
if (!string.IsNullOrWhiteSpace(fieldValue))
{
values.Append(item.DataType == typeof(DateTime) ? "N'" + Convert.ToDateTime(fieldValue).ToString("yyyy-MM-dd HH:mm:ss") + "'," : "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(DetailedProperties, dataRow, item, fieldValue);
}
detailBuilder.AppendFormat(detailSql, fields.ToString().Trim(','), values.ToString().Trim(','));
}
}
SaveErrorMessage = errorMessage;
return detailBuilder.ToString();
}
#endregion
#region 附件管理
/// <summary>
/// <para>说明:附件管理</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-01-25 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <returns>System.String.</returns>
private void btnAttach_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrWhiteSpace(this.SysModel.BillDocumentId))
{
MessageUtil.Show(ResourceKeys.NotFoundBillNo);
}
else
{
string url = string.Format("pages/PhotoView.html?left=1&username={0}&password={1}&id={2}&dllcoid={4}&isview={3}", ERPInfo.Instance.UserName, ERPInfo.Instance.Password, this.SysModel.BillDocumentId, this.btnAccradit.Enabled ? "0" : "1", this.SysModel.ModuleCode);
// 固定传入参数(窗口标题、操作员ID、操作员名称、权限、模版编号)
string[] defaultArgs = string.Format(ModuleArgs.DefaultArgs, this.SysModel.FormText, this.SysModel.UserId, this.SysModel.UserName, this.SysModel.Privilege, this.SysModel.ModuleCode).Split('~');
string[] menuArgs = SystemInfo.Instance.BsAttachFlag.Equals("1") ? new string[] { "", "", url } : new string[] { this.SysModel.BillDocumentId, "0", this.BillModelObj.DirId + "", "", "", "", "", this.SysModel.StepOver };
string[] args = defaultArgs.Concat(menuArgs).ToArray();
IForm form = FormHelper.LoadDllForm(SystemInfo.Instance.BsAttachFlag.Equals("1") ? ResourceDynamic.PubBrower : ResourceDynamic.PhotoView, args);
form.SubForm.StartPosition = FormStartPosition.CenterScreen;
DialogResult result = form.SubForm.ShowDialog();
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
#endregion
#region 记载分割条位置
private void splitLeft_SplitterPositionChanged(object sender, EventArgs e)
{
if (this._isInitFinish)
{
IniHelper.Write(string.Format("base_spliterPositionLeft_{0}", this.SysModel.ModuleCode), this.splitLeft.SplitterPosition + "");
}
}
private void splitMain_SplitterPositionChanged(object sender, EventArgs e)
{
if (this._isInitFinish)
{
IniHelper.Write(string.Format("base_spliterPositionMain_{0}", this.SysModel.ModuleCode), this.splitMain.SplitterPosition + "");
}
}
#endregion
/// <summary>
/// <para>说明:初始化分割条位置</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-01-25 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void InitializeSplitterPosition()
{
try
{
string splitterMainPosition = IniHelper.Read(string.Format("base_spliterPositionMain_{0}", this.SysModel.ModuleCode));
if (!string.IsNullOrEmpty(splitterMainPosition)) this.splitMain.SplitterPosition = Convert.ToInt32(splitterMainPosition);
string splitterLeftPosition = IniHelper.Read(string.Format("base_spliterPositionLeft_{0}", this.SysModel.ModuleCode));
if (!string.IsNullOrEmpty(splitterLeftPosition)) this.splitLeft.SplitterPosition = Convert.ToInt32(splitterLeftPosition);
}
catch (Exception ex)
{
LogHelper.Instance.WriteError(ex);
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
private bool VerificationRequired()
{
bool results = false;
if (SystemInfo.Instance.ReviewCommentsRequired && string.IsNullOrWhiteSpace(this.txtRemark.Text))
{
MessageUtil.Show("请输入审核意见");
results = true;
}
return results;
}
/// <summary>
/// 页签里数据修改后刷新明细
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Tab_basicInfo_OnDetailSaveGridCallBack(object sender, EventArgs e)
{
// 刷新主表
this._drBillInfoMsg = BaseAuditImpl.GetCurrentFlowRowData(this.BillModelObj.MasterTable, this.BillModelObj.PrimaryKey, this.SysModel.BillDocumentId);
this.ControlObj.SetAllControlValue(this._drBillInfoMsg);
// 刷新明细表
//this._dtSourceData = BillImpl.GetDataTableResult(ReplaceHelper.ReplaceParamToValue(this.BillModelObj.DetailSql, this.SysModel.BillDocumentId));
this._dtSourceData = BillImpl.GetDataTableResult(ReplaceHelper.ReplaceRowParam(_drBillInfoMsg, this.BillModelObj.DetailSql));
this._dtSourceData.OrderBy(this.BillModelObj.DetailOrderField);
if (this.BillModelObj.DetailTreeTable)
{
(this.gridBillInfo as TreeGridControlEx).SetGridViewDataSourceGenerateID(_dtSourceData);
}
else
{
this.gridBillInfo.SetGridViewDataSource(_dtSourceData);
}
}
/// <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;
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;
}
/// <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.gridBillInfo.GridView.PostEditor();
FPOld();
}
private void OnBtnFPNewClick(object sender, EventArgs e)
{
this.gridBillInfo.GridView.PostEditor();
FPNew();
}
/// <summary>
/// 新版分配
/// </summary>
private void FPNew(int rowHandle = 0)
{
try
{
this.gridBillInfo.GridView.FocusedRowHandle = rowHandle;
DataTable table = this.gridBillInfo.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.BillModelObj.PopupUnionCode, "1000" };
DynamicBaseSelectModel baseModel = new DynamicBaseSelectModel(args);
using (FrmBaseSelectBatch frmSelect = new FrmBaseSelectBatch(baseModel, this.ControlObj, this.gridBillInfo))
{
frmSelect.Text = this.BillModelObj.TypeName;
frmSelect.InitControl();
frmSelect.OnAfterFPCallback += OnAfterFPCallback;
#region 初始化第一条数据
DataRow rowItem = this.gridBillInfo.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.gridBillInfo.GridView.FocusedRowHandle + 1 <= this.gridBillInfo.GridView.RowCount - 1)
{
int focusedRowHandle = this.gridBillInfo.GridView.FocusedRowHandle + 1;
this.gridBillInfo.GridView.FocusedRowHandle = focusedRowHandle;
if (this.gridBillInfo.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.BillModelObj.DefaultAddEmptyRow) this.gridBillInfo.GridView.OptionsView.NewItemRowPosition = NewItemRowPosition.None;
DataRow rowItem = this.gridBillInfo.GridView.GetFocusedDataRow();
if (rowItem == null)
{
return;
}
DataTable table = this.gridBillInfo.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.gridBillInfo.GridView.FocusedRowHandle + 1 <= this.gridBillInfo.GridView.RowCount - 1)
{
this.gridBillInfo.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", BillModelObj.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.gridBillInfo.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.BillModelObj.DetailOrderField);
this.gridBillInfo.GridView.UpdateCurrentRow();
this.gridBillInfo.GridView.ShowEditor();
if (frmSelect.isNextOne)
{
int SourceRowIndex = this.gridBillInfo.GridView.GetFocusedDataSourceRowIndex();
DataRow[] a = table.Rows.Cast<DataRow>().Where(x => string.IsNullOrEmpty(x[guidField].ToString())).ToArray();
if (a.Length != 0)
{
this.gridBillInfo.GridView.FocusedRowHandle = SourceRowIndex;
OnAfterFPCallback(sender, e);
}
else
{
MessageUtil.Show("全部分配完毕");
// frmSelect.SelectRowItem = null;
}
}
}
}
else
{
if (this.gridBillInfo.GridView.FocusedRowHandle + 1 <= this.gridBillInfo.GridView.RowCount - 1)
{
this.gridBillInfo.GridView.FocusedRowHandle += 1;
OnAfterFPCallback(sender, e);
}
else
{
MessageUtil.Show("全部分配完毕");
}
}
}
catch (Exception)
{
throw;
}
finally
{
// 重新开启新增行(空白行)
if (this.BillModelObj.DefaultAddEmptyRow) this.gridBillInfo.GridView.OptionsView.NewItemRowPosition = NewItemRowPosition.Bottom;
WaitForm.HideForm();
}
}
/// <summary>
/// 老版分配
/// </summary>
private void FPOld()
{
try
{
DataRow rowItem = this.gridBillInfo.GridView.GetFocusedDataRow();
if (rowItem == null)
{
MessageUtil.Show("请先选择一条明细在进行分配!");
return;
}
DataTable table = this.gridBillInfo.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] + ""))
{
MessageUtil.Show("该行数据为已分配后的数据,无需分配!");
return;
}
}
string[] args = { this.SysModel.FormText, this.SysModel.UserId, this.SysModel.UserName, this.SysModel.Privilege, this.SysModel.ModuleCode, this.SysModel.ModuleId + "", this.BillModelObj.PopupUnionCode, "1000" };
DynamicBaseSelectModel baseModel = new DynamicBaseSelectModel(args);
using (FrmBaseSelect frmSelect = new FrmBaseSelect(baseModel, this.ControlObj, this.gridBillInfo))
{
//if (frmSelect.SelectRowItem == null)
//{
// frmSelect = new FrmBaseSelect(baseModel, this.ControlObj, this.gcMain);
//}
frmSelect.Text = this.BillModelObj.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", BillModelObj.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.gridBillInfo.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.BillModelObj.DetailOrderField);
this.gridBillInfo.GridView.UpdateCurrentRow();
this.gridBillInfo.GridView.ShowEditor();
}
}
if (frmSelect.isNextOne)
{
int SourceRowIndex = this.gridBillInfo.GridView.GetFocusedDataSourceRowIndex();
DataRow[] a = table.Rows.Cast<DataRow>().Where(x => string.IsNullOrEmpty(x[guidField].ToString())).ToArray();
if (a.Length != 0)
{
this.gridBillInfo.GridView.FocusedRowHandle = SourceRowIndex;
OnBtnFPOldClick(null, null);
}
else
{
MessageUtil.Show("全部分配完毕");
// frmSelect.SelectRowItem = null;
}
}
}
}
catch (Exception ex)
{
MessageUtil.Show(ex);
}
}
/// <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.gridBillInfo.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>创建日期: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.gridBillInfo.gridControl.DataSourceTable();
if (rowItem != null && model != null)
{
List<GridColumnModel> calcModels = this.gridBillInfo.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>
/// 审核或反审
/// </summary>
public string AuditMethod(out string nextSelectStepCode,
out string nextSelectStepOper,
out string msgText,
DynamicModel sysModel,
string stepCode,
string billDocumentId,
string message,
string storedName,
string accractFlag,
string remindSelect,
string remarkText = "",
string remindOpers = "",
string confirmOpers = "",
bool ret = false,
int returnd = 0,
int selectConfirmFlag = 0,
bool IsStepOver = false,
int comfirm = 0
)
{
string result = BaseAuditImpl.Audit(out nextSelectStepCode, out nextSelectStepOper, out msgText, sysModel, stepCode, billDocumentId, message, storedName, accractFlag, remindSelect, remarkText, remindOpers, confirmOpers, ret, returnd, selectConfirmFlag, IsStepOver, comfirm);
if ("9".Equals(result))
{
// 继续执行保存
//if (string.IsNullOrWhiteSpace(msgText)) msgText = "失败";
if (MessageUtil.Show(msgText, MessageBoxButtons.YesNo) == DialogResult.Yes)
result = AuditMethod(out nextSelectStepCode, out nextSelectStepOper, out msgText, sysModel, stepCode, billDocumentId, message, storedName, accractFlag, remindSelect, remarkText, remindOpers, confirmOpers, ret, returnd, selectConfirmFlag, IsStepOver, 1);
}
return result;
}
/// <summary>
/// 保存所有附加模块
/// </summary>
/// <returns></returns>
public void SaveAdditionalModules()
{
try
{
foreach (XtraTabPage tabPage in this.tab_basicInfo.TabControlObj.TabPages)
{
GridDetailModel model = this.tab_basicInfo.GetGridDetailModel(tabPage);
Object moduleObject = tabPage.Controls.Cast<Object>().FirstOrDefault();
if (moduleObject is ModuleGridEx)
{
ModuleGridEx moduleGridEx = moduleObject as ModuleGridEx;
if (moduleGridEx.GridControlObj.IsDataNotSaved() && moduleGridEx.BtnSave.Visible && moduleGridEx.BtnSave.Enabled)
{
moduleGridEx.BtnSave.PerformClick();
}
}
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// 设置修改过的控件颜色
/// </summary>
public void SetColor()
{
List <string> FieldList = AuditChangeLog.GetChangeLogFields(this.SysModel.BillDocumentId);
foreach (string item in FieldList)
{
this.ControlObj.SetBackgroundColor(item);
}
}
}
}