457 lines
17 KiB
C#
457 lines
17 KiB
C#
using DevExpress.XtraBars;
|
||
using DevExpress.XtraBars.ToolbarForm;
|
||
using DevExpress.XtraEditors;
|
||
using DeviceRepair.Models;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.Linq;
|
||
using System.Windows.Forms;
|
||
using TsSFCDevice.Client.Biz.Base.Utils;
|
||
using TsSFCDevice.Client.Biz.Impl;
|
||
|
||
namespace TsSFCDevice.Client.Launch.CustomField
|
||
{
|
||
public partial class pageFieldCode : ToolbarForm
|
||
{
|
||
/// <summary>
|
||
/// 窗口标题
|
||
/// </summary>
|
||
public string Caption = "字段配置";
|
||
|
||
/// <summary>
|
||
/// 当前字段编码
|
||
/// </summary>
|
||
public string FieldCode = "";
|
||
|
||
/// <summary>
|
||
/// 筛选条件
|
||
/// </summary>
|
||
public string FilterString
|
||
{
|
||
get
|
||
{
|
||
return bar_txt_FilterString.EditValue + "";
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 基础权限
|
||
/// </summary>
|
||
public string BaseAuthCode = "";
|
||
public int BaseAuthNumber = 0;
|
||
|
||
List<FieldsInfo> CurrentDatas;
|
||
int m_SelectedCurrentRowIndex = 0;
|
||
FieldsInfo CurrentFieldInfo;
|
||
|
||
List<dynamic> _FieldsTypeCollect;
|
||
public List<dynamic> FieldsTypeCollect
|
||
{
|
||
get
|
||
{
|
||
if (_FieldsTypeCollect == null)
|
||
_FieldsTypeCollect = new List<dynamic>() {
|
||
new { TypeValue = "NVarChar", Name = "文本值" },
|
||
new { TypeValue = "double", Name = "数值" },
|
||
new { TypeValue = "decimal", Name = "货币" }
|
||
};
|
||
return _FieldsTypeCollect;
|
||
}
|
||
}
|
||
|
||
Dictionary<int, string> _UserMapping;
|
||
Dictionary<int, string> UserMapping
|
||
{
|
||
get
|
||
{
|
||
if (_UserMapping == null)
|
||
{
|
||
try
|
||
{
|
||
_UserMapping = Utility.SystemRuntimeInfo.CurrentUsersCaches?.ToList().ToDictionary(x => x.Id, x => x.UserName);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
XtraMessageBoxHelper.Error(ex.Message);
|
||
}
|
||
}
|
||
return _UserMapping;
|
||
}
|
||
}
|
||
|
||
public pageFieldCode() : this("", "", "字段配置")
|
||
{
|
||
|
||
}
|
||
|
||
public pageFieldCode(string Code, string baseAuthCode, string DisPlayTitle = "字段配置")
|
||
{
|
||
InitializeComponent();
|
||
|
||
FieldCode = Code;
|
||
BaseAuthCode = baseAuthCode.Substring(0, baseAuthCode.LastIndexOf('_'));
|
||
BaseAuthNumber = Convert.ToInt32(baseAuthCode.Substring(baseAuthCode.LastIndexOf('_') + 1));
|
||
Caption = $"字段配置 - {DisPlayTitle}";
|
||
this.Load += PageFieldCode_Load;
|
||
}
|
||
|
||
private void PageFieldCode_Load(object sender, EventArgs e)
|
||
{
|
||
Text = Caption;
|
||
|
||
GridViewInitialize(gridView1);
|
||
InitializeGridDatas();
|
||
|
||
gridView1.OptionsMenu.EnableColumnMenu = false;
|
||
|
||
gridView1.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.CheckBoxRowSelect;
|
||
gridView1.OptionsSelection.ShowCheckBoxSelectorInColumnHeader = DevExpress.Utils.DefaultBoolean.False;
|
||
gridView1.CustomDrawColumnHeader += GridView1_CustomDrawColumnHeader;
|
||
gridView1.RowCellClick += GridView1_RowCellClick;
|
||
gridView1.CustomDrawRowIndicator += GridView1_CustomDrawRowIndicator;
|
||
|
||
gridView1.RowStyle += (sd, ee) =>
|
||
{
|
||
DevExpress.XtraGrid.Views.Grid.GridView view = sd as DevExpress.XtraGrid.Views.Grid.GridView;
|
||
|
||
if (ee.RowHandle >= 0)
|
||
{
|
||
FieldsInfo item = view.GetRow(ee.RowHandle) as FieldsInfo;
|
||
if (!item.Status)
|
||
ee.Appearance.BackColor = Color.FromArgb(255, 126, 126);
|
||
}
|
||
};
|
||
|
||
if (((gridControl1.DataSource as IList<FieldsInfo>)?.Count ?? 0) > 0)
|
||
gridView1_FocusedRowChanged(gridView1, new DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs(-1, 0));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 自增长行号
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void GridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
|
||
{
|
||
if (e.Info.IsRowIndicator && e.RowHandle >= 0)
|
||
{
|
||
e.Info.DisplayText = (e.RowHandle + 1).ToString();
|
||
e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
|
||
e.Appearance.TextOptions.VAlignment = DevExpress.Utils.VertAlignment.Center;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 行选择模式,且全部只读
|
||
/// </summary>
|
||
/// <param name="view"></param>
|
||
void GridViewInitialize(DevExpress.XtraGrid.Views.Grid.GridView view)
|
||
{
|
||
// 关闭列头右键菜单
|
||
view.OptionsMenu.EnableColumnMenu = false;
|
||
|
||
view.OptionsBehavior.Editable = false;
|
||
view.OptionsBehavior.ReadOnly = true;
|
||
|
||
view.OptionsSelection.EnableAppearanceFocusedCell = false;
|
||
view.OptionsScrollAnnotations.ShowSelectedRows = DevExpress.Utils.DefaultBoolean.False;
|
||
|
||
foreach (DevExpress.XtraGrid.Columns.GridColumn item in view.Columns)
|
||
{
|
||
item.OptionsColumn.AllowEdit = false;
|
||
item.OptionsColumn.AllowGroup = DevExpress.Utils.DefaultBoolean.True;
|
||
item.OptionsColumn.AllowMerge = DevExpress.Utils.DefaultBoolean.False;
|
||
item.OptionsColumn.AllowShowHide = false;
|
||
}
|
||
}
|
||
|
||
private void GridView1_CustomDrawColumnHeader(object sender, DevExpress.XtraGrid.Views.Grid.ColumnHeaderCustomDrawEventArgs e)
|
||
{
|
||
if (e.Column != null && (e.Column.Caption == "Selection" || e.Column.FieldName == "DX$CheckboxSelectorColumn"))
|
||
{
|
||
e.Info.Caption = "选择";
|
||
e.Appearance.Font = new System.Drawing.Font("Tahoma", 12F);
|
||
}
|
||
}
|
||
|
||
private void GridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
|
||
{
|
||
if (e.Button == MouseButtons.Right)
|
||
{
|
||
e.Handled = true;
|
||
return;
|
||
}
|
||
|
||
if (e.Column.Caption == "Selection")
|
||
{
|
||
if (this.m_SelectedCurrentRowIndex == e.RowHandle && this.gridView1.IsRowSelected(e.RowHandle))
|
||
this.gridView1.UnselectRow(e.RowHandle);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 新增
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void barButtonItem3_ItemClick(object sender, ItemClickEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (!Utility.SystemRuntimeInfo.AuthValidate($"{BaseAuthCode}_{(BaseAuthNumber + 1)}"))
|
||
{
|
||
throw new Exception($"当前账号缺少此操作的权限");
|
||
}
|
||
|
||
pageFieldEdit view = new pageFieldEdit(FieldCode);
|
||
|
||
DialogResult Dr = view.ShowDialog(this);
|
||
if (Dr == DialogResult.OK)
|
||
{
|
||
InitializeGridDatas();
|
||
}
|
||
else if (Dr == DialogResult.Abort)
|
||
{
|
||
throw new Exception(view.ErrorMsg);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
XtraMessageBoxHelper.Error(ex.Message);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 数据加载
|
||
/// </summary>
|
||
void InitializeGridDatas()
|
||
{
|
||
try
|
||
{
|
||
splashScreenManager1.ShowWaitForm();
|
||
|
||
IList<FieldsInfo> CurrentDatas = CustomFieldRepository.Instance.GetDatas(new string[] { FieldCode }); //FieldsManager.Instance.GetQuery(FieldCode);
|
||
|
||
foreach (var item in CurrentDatas)
|
||
{
|
||
item.FieldTypeCaption = FieldsTypeCollect.FirstOrDefault(x => x.TypeValue == item.FieldType).Name;
|
||
item.StatusText = item.Status ? "启用" : "停用";
|
||
item.CreatorName = UserMapping[item.CreatBy];
|
||
if (item.ModifyBy.HasValue)
|
||
item.ModifierName = UserMapping[item.ModifyBy.Value];
|
||
}
|
||
|
||
var DataSource = CurrentDatas.Where(x => x.FieldText.Contains(FilterString)
|
||
|| x.FieldValue.Contains(FilterString)).ToList();
|
||
|
||
gridControl1.DataSource = DataSource;
|
||
// 设置行号列宽度
|
||
SizeF size = this.CreateGraphics().MeasureString(DataSource.Count.ToString(), this.Font);
|
||
gridView1.IndicatorWidth = Convert.ToInt32(size.Width) + 20;
|
||
|
||
gridView1.BestFitColumns();
|
||
gridView1.Columns[0].BestFit();
|
||
gridView1.Columns[1].BestFit();
|
||
gridView1.Columns[2].BestFit();
|
||
|
||
if ((DataSource?.Count ?? 0) > 0)
|
||
gridView1_FocusedRowChanged(gridView1, new DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs(-1, 0));
|
||
splashScreenManager1.TryCloseWait();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
splashScreenManager1.TryCloseWait();
|
||
XtraMessageBoxHelper.Error(ex.Message);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取选择的目标,并且更改状态按钮的图
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (e.FocusedRowHandle >= 0)
|
||
{
|
||
m_SelectedCurrentRowIndex = e.FocusedRowHandle;
|
||
CurrentFieldInfo = gridView1.GetRow(e.FocusedRowHandle) as FieldsInfo;
|
||
|
||
#region 修改选定状态
|
||
if (gridView1.SelectedRowsCount > 0)
|
||
{
|
||
for (int i = 0; i < this.gridView1.RowCount; i++)
|
||
{
|
||
if (this.gridView1.IsRowSelected(i) && e.FocusedRowHandle.ToString().Equals(i.ToString()) == false)
|
||
{
|
||
this.gridView1.UnselectRow(i);
|
||
}
|
||
}
|
||
}
|
||
|
||
this.gridView1.SelectRow(e.FocusedRowHandle);
|
||
#endregion
|
||
|
||
#region 修改按钮图片
|
||
if (CurrentFieldInfo != null && CurrentFieldInfo.Status)
|
||
{
|
||
bar_btn_StatusChange.Caption = "字段禁用";
|
||
bar_btn_StatusChange.ImageOptions.Image = Properties.Resources.LOCK;
|
||
}
|
||
else
|
||
{
|
||
bar_btn_StatusChange.Caption = "字段启用";
|
||
bar_btn_StatusChange.ImageOptions.Image = Properties.Resources.UNLOCK;
|
||
}
|
||
#endregion
|
||
}
|
||
else
|
||
{
|
||
CurrentFieldInfo = null;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
XtraMessageBoxHelper.Error(ex.Message);
|
||
}
|
||
}
|
||
|
||
#region 搜索
|
||
private void repositoryItemButtonEdit1_KeyDown(object sender, KeyEventArgs e)
|
||
{
|
||
if (e.KeyCode != Keys.Enter)
|
||
return;
|
||
|
||
gridControl1.DataSource = CurrentDatas.Where(x => x.FieldText.Contains(FilterString)
|
||
|| x.FieldValue.Contains(FilterString)).ToList();
|
||
gridView1.BestFitColumns();
|
||
}
|
||
|
||
private void bar_btn_Search_ItemClick(object sender, ItemClickEventArgs e)
|
||
{
|
||
InitializeGridDatas();
|
||
}
|
||
|
||
private void repositoryItemTextEdit4_KeyDown(object sender, KeyEventArgs e)
|
||
{
|
||
if (e.KeyCode != Keys.Enter)
|
||
return;
|
||
|
||
bar_btn_Search.PerformClick();
|
||
}
|
||
|
||
private void repositoryItemTextEdit4_KeyUp(object sender, KeyEventArgs e)
|
||
{
|
||
// FilterString = (sender as TextEdit).EditValue.ToString().Trim();
|
||
}
|
||
#endregion
|
||
|
||
#region 修改状态
|
||
/// <summary>
|
||
/// 修改状态
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void bar_btn_StatusChange_ItemClick(object sender, ItemClickEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (CurrentFieldInfo == null)
|
||
throw new Exception("请选择字段所在行!");
|
||
|
||
if (!Utility.SystemRuntimeInfo.AuthValidate($"{BaseAuthCode}_{(BaseAuthNumber + 3)}"))
|
||
{
|
||
throw new Exception($"当前账号缺少此操作的权限");
|
||
}
|
||
|
||
if (XtraMessageBoxHelper.AskYesNo($"<size=16>确认<b>{(CurrentFieldInfo.Status ? "<color=red>停用<color/>" : "<color=LimeGreen>启用<color/>")}<b/>字段{CurrentFieldInfo.FieldText} - {CurrentFieldInfo.FieldValue}?<size/>") == DialogResult.Yes)
|
||
{
|
||
XtraInputBoxArgs args = new XtraInputBoxArgs { Prompt = "原因录入:", Caption = $"请录入字段{(CurrentFieldInfo.Status ? "停用" : "启用")}原因", DefaultResponse = "" };
|
||
args.Buttons = new DialogResult[] { DialogResult.OK, DialogResult.Cancel };
|
||
args.DefaultButtonIndex = (int)DialogResult.Cancel;
|
||
|
||
// 声明默认返回值
|
||
DialogResult DiaResult = DialogResult.None;
|
||
args.Showing += (a, b) =>
|
||
{
|
||
//选中ok按钮,将返回值变量改变为ok。
|
||
b.Buttons[DialogResult.OK].Click += (c, d) => { DiaResult = DialogResult.OK; };
|
||
};
|
||
|
||
DiaResult = DialogResult.None;
|
||
// 显示对话框
|
||
var Description = XtraInputBox.Show(args);
|
||
string DescriptionValue = Description + "";
|
||
// 判断点击的按钮
|
||
if (DiaResult == DialogResult.None)
|
||
return;
|
||
|
||
if (string.IsNullOrWhiteSpace(DescriptionValue))
|
||
throw new Exception("原因不能为空,是否继续操作?");
|
||
|
||
if (DescriptionValue.Length >= 400)
|
||
throw new Exception("原因描述超出长度,最大长度为200!");
|
||
|
||
bool BeStatus = !CurrentFieldInfo.Status;
|
||
|
||
APIResponseData apiResponseData = CustomFieldRepository.Instance.Change_Field_Status(CurrentFieldInfo.AutoID, DescriptionValue, BeStatus);
|
||
if (!apiResponseData.IsSuccess)
|
||
throw new Exception(apiResponseData.Message);
|
||
|
||
InitializeGridDatas();
|
||
gridView1.RefreshData();
|
||
gridView1.FocusedRowHandle = m_SelectedCurrentRowIndex > 0 ? 0 : m_SelectedCurrentRowIndex + 1;
|
||
XtraMessageBoxHelper.Info("操作成功!");
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
XtraMessageBoxHelper.Error(ex.Message);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 修改
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void barButtonItem4_ItemClick(object sender, ItemClickEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (CurrentFieldInfo == null)
|
||
throw new Exception("请选择字段所在行!");
|
||
|
||
if (!Utility.SystemRuntimeInfo.AuthValidate($"{BaseAuthCode}_{(BaseAuthNumber + 2)}"))
|
||
{
|
||
throw new Exception($"当前账号缺少此操作的权限");
|
||
}
|
||
|
||
if (!CurrentFieldInfo.Status)
|
||
{
|
||
throw new Exception($"停用的数据不允许更改!");
|
||
}
|
||
|
||
pageFieldEdit view = new pageFieldEdit(FieldCode, CurrentFieldInfo);
|
||
|
||
DialogResult Dr = view.ShowDialog(this);
|
||
if (Dr == DialogResult.OK)
|
||
{
|
||
InitializeGridDatas();
|
||
}
|
||
else if (Dr == DialogResult.Abort)
|
||
{
|
||
throw new Exception(view.ErrorMsg);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
XtraMessageBoxHelper.Error(ex.Message);
|
||
}
|
||
}
|
||
}
|
||
} |