using ComponentFactory.Krypton.Toolkit;
using NXWMS.Client.Code.Extends;
using NXWMS.Client.Model.AppModels.Condition.Rule;
using NXWMS.Client.Model.AppModels.Result;
using NXWMS.Client.Model.AppModels.Result.Rule;
using NXWMS.Client.Model.CoreModels;
using NXWMS.Client.String.Enums;
using NXWMS.Commons;
using NXWMS.Services;
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;
namespace NXWMS.Forms.Rule
{
public partial class frmPrintTemplate : Form
{
///
/// 客户端字段排序列表
///
private List _clientFieldOrderList;
///
/// 界面最后执行操作
///
private EnumOperation _LastOperation;
private int _pageSize;
private int _pageIndex;
private int _totalCount;
public frmPrintTemplate()
{
InitializeComponent();
InitData();
InitControl();
}
private int _selectIndex;
private int _selectId;
private string _selectNo;
///
/// 主键Key
///
private string _PrimaryKey = "PRINT_TEMPLATE_ID";
///
/// 主键编码
///
private string _PrimaryNo = "PRINT_TEMPLATE_CODE";
///
/// 选择行主键列表
///
private List _CheckRowIdList = new List();
///
/// 数据初始化
///
private void InitData()
{
_clientFieldOrderList = new List();
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "PRINT_TEMPLATE_CODE", FieldDesc = "打印模版编码" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "PRINT_TEMPLATE_NAME", FieldDesc = "打印模版名称" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "PrintModeName", FieldDesc = "打印方式" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "IsShowLogoName", FieldDesc = "是否显示公司Logo标识" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "IsPrintHeaderName", FieldDesc = "是否打印表头" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "IsShowWatermarkName", FieldDesc = "是否添加水印" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "PrintNumber", FieldDesc = "打印数量" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "SourceTypeName", FieldDesc = "数据源类型" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "SourceName", FieldDesc = "数据源名称" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "SourceContent", FieldDesc = "数据源内容" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "SourceCode", FieldDesc = "数据源编码" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UsedFlagName", FieldDesc = "使用标识" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CreateName", FieldDesc = "创建人" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CREATE_TIME", FieldDesc = "创建时间" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UpdateName", FieldDesc = "更新人" });
_clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UPDATE_TIME", FieldDesc = "更新时间" });
}
///
/// 控件初始化
///
private void InitControl()
{
CheckForIllegalCrossThreadCalls = false;
dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), false);
groupOperation.MouseDown += new MouseEventHandler(this.groupOperation_MouseDown);
groupOperation.MouseMove += new MouseEventHandler(this.groupOperation_MouseMove);
dataGridView.CellDoubleClick += new DataGridViewCellEventHandler(this.dataGridView_CellDoubleClick);
var fieldList = new List().Add(new FieldValue { Code = "", Name = "全部" });
cmbSearchTemplateMode.DataSource = fieldList.GetFieldValueIdList();
cmbSearchTemplateMode.DisplayMember = "Name";
cmbSearchTemplateMode.ValueMember = "Id";
cmbPrintMode.DataSource = new List().GetFieldValueIdList();
cmbPrintMode.DisplayMember = "Name";
cmbPrintMode.ValueMember = "Id";
cmbSourceType.DataSource = new List().GetFieldValueIdList();
cmbSourceType.DisplayMember = "Name";
cmbSourceType.ValueMember = "Id";
_pageIndex = 1;
_pageSize = 20;
}
private Point mouse_offset;
private void groupOperation_MouseDown(object sender, MouseEventArgs e)
{
mouse_offset = new Point(-e.X, -e.Y);
}
private void groupOperation_MouseMove(object sender, MouseEventArgs e)
{
((Control)sender).Cursor = Cursors.Arrow;
if (e.Button == MouseButtons.Left)
{
Point mousePos = MousePosition;
mousePos.Offset(mouse_offset.X, mouse_offset.Y);
((Control)sender).Location = ((Control)sender).Parent.PointToClient(mousePos);
Application.DoEvents();
}
}
private void btnSearch_Click(object sender, EventArgs e)
{
_pageIndex = 1;
var loadfrm = new frmLoading();
loadfrm.Show();
var message = loadfrm.EventCalExec(LoadSearch, this.pageTool.PageIndex, this.pageTool.PageSize);
pageTool.DataCount = _totalCount;
if (!string.IsNullOrWhiteSpace(message))
{
KryptonMessageBox.Show($"查询失败!\r\n{message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private string LoadSearch(int pageIndex, int pageSize)
{
var result = RuleServices.printTemplateService.GetList(new PrintTemplateSearchCondition
{
OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
PrintMode = cmbSearchTemplateMode.SelectedValue.GetObjectToInt(),
IsUsed = chkSearchUse.Checked,
TemplateCode = txtSearchTemplateCode.Text,
SourceName = txtSearchSourceName.Text,
TemplateName = txtSearchTemplateName.Text,
PageIndex = pageIndex,
PageSize = pageSize
});
if (result.Status == OperateStatus.Success)
{
_totalCount = result.Data.TotalCount;
_pageIndex = pageIndex;
_pageSize = pageSize;
if (result.Data.RowData.Any())
{
dataGridView.Columns.Clear();
dataGridView.DataSource = result.Data.RowData.ToList();
dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList));
}
else
{
if (dataGridView.DataSource != null)
{
dataGridView.DataSource = new List();
}
dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), false);
}
return string.Empty;
}
else
{
return result.Message;
}
}
private void btnSearchExport_Click(object sender, EventArgs e)
{
this.dataGridView.DataGridViewExport($"{AppConfig.CurrentMenu.FirstOrDefault().MenuName}列表" + DateTime.Now.ToString("yyyyMMddHH"));
}
private void btnAdd_Click(object sender, EventArgs e)
{
if (!groupOperation.Visible)
{
tableLayoutPanelInput.SetGroupControlsEmpty(dataGridView);
richDescibe.Text = "";
_LastOperation = EnumOperation.Add;
txtTemplateCode.Enabled = true;
numPrintNumber.Value = 1;
chkUse.Checked = true;
groupOperation.Visible = true;
groupOperation.Focus();
}
}
private void SelectInit()
{
if (dataGridView.SelectedRows.Count > 0)
{
_selectIndex = dataGridView.SelectedRows[0].Index;
if (_selectIndex >= 0)
{
_selectId = Convert.ToInt32(dataGridView.Rows[_selectIndex].Cells[_PrimaryKey].Value);
_selectNo = dataGridView.Rows[_selectIndex].Cells[_PrimaryNo].Value.ToString();
}
}
else
{
_selectIndex = -1;
}
_CheckRowIdList = new List();
foreach (DataGridViewRow item in dataGridView.Rows)
{
if (item.Cells["#SELECTED"].Value.GetObjectToInt() == 1)
{
_CheckRowIdList.Add(item.Cells[_PrimaryKey].Value.ToString());
}
}
}
private void btnEdit_Click(object sender, EventArgs e)
{
if (!groupOperation.Visible)
{
SelectInit();
if (_selectIndex >= 0)
{
_LastOperation = EnumOperation.Edit;
richDescibe.Text = dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value == null ? "" :
dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value.ToString();
groupOperation.Visible = true;
tableLayoutPanelInput.SetGroupControls(dataGridView, dataGridView.Rows[_selectIndex]);
txtTemplateCode.Enabled = false;
groupOperation.Visible = true;
groupOperation.Focus();
}
}
}
private void btnRemove_Click(object sender, EventArgs e)
{
SelectInit();
if (_CheckRowIdList.Count == 0)
{
return;
}
if (KryptonMessageBox.Show($"确认删除选中数据?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
var editResult = RuleServices.printTemplateService.Deleted(new PrintTemplateCondition
{
OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
TemplateIds = string.Join(",", _CheckRowIdList),
});
if (editResult.Status == OperateStatus.Success)
{
KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
btnSearch_Click(null, null);
}
else
{
KryptonMessageBox.Show($"操作失败!\r\n{editResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
private void btnSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(txtTemplateCode.Text))
{
KryptonMessageBox.Show($"请输入模版编码。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (string.IsNullOrWhiteSpace(txtTemplateName.Text))
{
KryptonMessageBox.Show($"请输入模版名称。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (string.IsNullOrWhiteSpace(cmbPrintMode.Text))
{
KryptonMessageBox.Show($"请选择打印方式。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (string.IsNullOrWhiteSpace(cmbSourceType.Text))
{
KryptonMessageBox.Show($"请选择数据源类型。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
switch (_LastOperation)
{
case EnumOperation.Add:
var addResult = RuleServices.printTemplateService.Add(new PrintTemplateCondition
{
OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
IsUsed = chkUse.Checked,
Describe = richDescibe.Text,
IsShowLogo = chkShowLogoFlag.Checked,
IsShowWatermark = chkShowWatermark.Checked,
PrintMode = cmbPrintMode.SelectedValue.GetObjectToInt().Value,
PrintNumber = numPrintNumber.Value.GetObjectToInt(),
SourceCode = txtSourceCode.Text,
SourceContent = txtSourceContent.Text,
SourceName = txtSourceName.Text,
SourceType = cmbSourceType.SelectedValue.GetObjectToInt().Value,
TemplateCode = txtTemplateCode.Text,
TemplateName = txtTemplateName.Text,
});
if (addResult.Status == OperateStatus.Success)
{
KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
InitControl();
groupOperation.Visible = false;
btnSearch_Click(null, null);
dataGridView.ClearSelection();
}
else
{
KryptonMessageBox.Show($"操作失败!\r\n{addResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
break;
case EnumOperation.Edit:
var editResult = RuleServices.printTemplateService.Edit(new PrintTemplateCondition
{
OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
IsUsed = chkUse.Checked,
Describe = richDescibe.Text,
IsShowLogo = chkShowLogoFlag.Checked,
IsShowWatermark = chkShowWatermark.Checked,
PrintMode = cmbPrintMode.SelectedValue.GetObjectToInt().Value,
PrintNumber = numPrintNumber.Value.GetObjectToInt(),
SourceCode = txtSourceCode.Text,
SourceContent = txtSourceContent.Text,
SourceName = txtSourceName.Text,
SourceType = cmbSourceType.SelectedValue.GetObjectToInt().Value,
TemplateCode = txtTemplateCode.Text,
TemplateName = txtTemplateName.Text,
TemplateId = _selectId,
});
if (editResult.Status == OperateStatus.Success)
{
KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
InitControl();
groupOperation.Visible = false;
btnSearch_Click(null, null);
dataGridView.ClearSelection();
}
else
{
KryptonMessageBox.Show($"操作失败!\r\n{editResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
break;
}
}
private void btnExit_Click(object sender, EventArgs e)
{
if (KryptonMessageBox.Show($"确认退出 {_LastOperation.Display()}数据操作?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
groupOperation.Visible = false;
}
else
{
groupOperation.Visible = true;
groupOperation.Focus();
}
}
private void dataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
SelectInit();
if (_selectIndex >= 0)
{
_LastOperation = EnumOperation.Edit;
txtTemplateCode.Enabled = false;
tableLayoutPanelInput.SetGroupControls(dataGridView, dataGridView.Rows[_selectIndex]);
richDescibe.Text = dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value == null ? "" :
dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value.ToString();
groupOperation.Visible = true;
groupOperation.Focus();
}
}
private void btnSearchImport_Click(object sender, EventArgs e)
{
var from = new frmTempImportData(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name);
from.ShowDialog();
}
}
}