Commit f62737b4 authored by tr's avatar tr

1、审核样例优化

parent fb3751ef
......@@ -28,31 +28,48 @@
/// </summary>
private void InitializeComponent()
{
this.panelAuditHome = new System.Windows.Forms.Panel();
this.NodeHome = new System.Windows.Forms.Panel();
this.label1 = new System.Windows.Forms.Label();
this.NodeHome.SuspendLayout();
this.SuspendLayout();
//
// panelAuditHome
// NodeHome
//
this.panelAuditHome.AutoScroll = true;
this.panelAuditHome.Dock = System.Windows.Forms.DockStyle.Fill;
this.panelAuditHome.Location = new System.Drawing.Point(0, 0);
this.panelAuditHome.Name = "panelAuditHome";
this.panelAuditHome.Size = new System.Drawing.Size(346, 312);
this.panelAuditHome.TabIndex = 0;
this.NodeHome.AutoScroll = true;
this.NodeHome.Controls.Add(this.label1);
this.NodeHome.Dock = System.Windows.Forms.DockStyle.Fill;
this.NodeHome.Location = new System.Drawing.Point(0, 0);
this.NodeHome.Name = "NodeHome";
this.NodeHome.Size = new System.Drawing.Size(346, 312);
this.NodeHome.TabIndex = 0;
//
// label1
//
this.label1.Dock = System.Windows.Forms.DockStyle.Fill;
this.label1.Font = new System.Drawing.Font("微软雅黑", 36F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label1.ForeColor = System.Drawing.SystemColors.ControlLight;
this.label1.Location = new System.Drawing.Point(0, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(346, 312);
this.label1.TabIndex = 0;
this.label1.Text = "审核控件";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// ucAudit
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.panelAuditHome);
this.Controls.Add(this.NodeHome);
this.Name = "ucAudit";
this.Size = new System.Drawing.Size(346, 312);
this.NodeHome.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Panel panelAuditHome;
private System.Windows.Forms.Panel NodeHome;
private System.Windows.Forms.Label label1;
}
}
......@@ -10,14 +10,21 @@ using System.Windows.Forms;
namespace Tools.MyCommon.controls
{
/// <summary>
/// 审核控件
/// </summary>
public partial class ucAudit : UserControl
{
/// <summary>
/// 构造函数:审核控件
/// </summary>
public ucAudit()
{
InitializeComponent();
}
private DataTable _dt = null;
/// <summary>
/// 数据源
/// </summary>
......@@ -42,25 +49,50 @@ namespace Tools.MyCommon.controls
/// </summary>
public void RefreshNode()
{
this.SetAuditActived();
this.SetNodeActived();
}
List<ucAuditNode> auditNodeList = null;
int previous = -1; //前一节点
int current = 0; //当前节点
bool isIniting = false;
/// <summary>
/// 节点列表
/// </summary>
List<ucAuditNode> NodeList = null;
/// <summary>
/// 前一节点
/// </summary>
int previous = -1;
/// <summary>
/// 当前节点
/// </summary>
int current = 0;
/// <summary>
/// 是否初始化中(并发控制)
/// </summary>
bool IsIniting = false;
/// <summary>
/// 节点总数
/// </summary>
private int NodeCount => this.NodeList == null ? 0 : this.NodeList.Count;
/// <summary>
/// 是否为空
/// </summary>
private bool IsNullOrEmpty => this.NodeList == null || this.NodeCount == 0;
/// <summary>
/// 初始化审批视图
/// </summary>
private void InitAuditView()
{
if (this.isIniting)
if (this.IsIniting)
return;
try
{
this.isIniting = true;
this.IsIniting = true;
//清除控件
this.panelAuditHome.Controls.Clear();
this.NodeHome.Controls.Clear();
//初始化审批节点列表
auditNodeList = new List<ucAuditNode>();
this.NodeList = new List<ucAuditNode>();
int index = 0;
foreach (DataRow dr in this.DataSource.Rows)
{
......@@ -69,8 +101,8 @@ namespace Tools.MyCommon.controls
node.Index = index;
node.AuditStateChanged += Audit_AuditStateChanged;
node.Location = new Point(0, index * 155);
node.Parent = this.panelAuditHome;
auditNodeList.Add(node);
node.Parent = this.NodeHome;
this.NodeList.Add(node);
index++;
}
......@@ -81,47 +113,69 @@ namespace Tools.MyCommon.controls
}
finally
{
this.isIniting = false;
this.IsIniting = false;
}
}
/// <summary>
/// 初始化审批激活状态
/// </summary>
private void InitAuditActived()
{
if (this.IsNullOrEmpty)
return;
//寻找第一个待审节点
int index = 0;
int total = this.auditNodeList.Count;
while (index < total && this.auditNodeList[index].AuditState != 0)
while (index < this.NodeCount && this.NodeList[index].AuditState != 0)
{
index++;
}
this.current = index >= total ? total - 1 : index;
//如果不存在待审节点,则指向最后一个节点
this.current = index >= this.NodeCount ? this.NodeCount - 1 : index;
this.previous = this.current - 1;
this.SetAuditActived();
//激活节点
this.SetNodeActived();
}
private void SetAuditActived()
/// <summary>
/// 激活节点
/// </summary>
private void SetNodeActived()
{
if (auditNodeList == null || auditNodeList.Count == 0)
if (this.IsNullOrEmpty)
return;
if (previous < 0) //到达边界时,分别处理
{
this.SetAuditActived(current, true);
this.SetNodeActived(current, true);
}
else
{
this.SetAuditActived(previous, auditNodeList[current].AuditState == 0); //下一节点待审核时,当前节点有效,即可以撤销
this.SetAuditActived(current, auditNodeList[previous].AuditState == 1); //上一节点审核通过后,当前节点有效,即可以审批
this.SetNodeActived(previous, this.NodeList[current].AuditState == 0); //下一节点待审核时,当前节点有效,即可以撤销
this.SetNodeActived(current, this.NodeList[previous].AuditState == 1); //上一节点审核通过后,当前节点有效,即可以审批
}
}
private void SetAuditActived(int index, bool IsActive)
/// <summary>
/// 激活指定节点
/// </summary>
/// <param name="index"></param>
/// <param name="IsActive"></param>
private void SetNodeActived(int index, bool IsActive)
{
if (auditNodeList == null || auditNodeList.Count == 0)
if (this.IsNullOrEmpty)
return;
if (index >= 0 && index < auditNodeList.Count)
if (index >= 0 && index < this.NodeCount)
{
auditNodeList[index].IsActive = IsActive;
this.NodeList[index].IsActive = IsActive;
}
}
/// <summary>
/// 事件:审核状态改变
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Audit_AuditStateChanged(object sender, EventArgs e)
{
ucAuditNode node = sender as ucAuditNode;
......@@ -129,13 +183,13 @@ namespace Tools.MyCommon.controls
bool IsDown = node.Index == current;
//上下偏移时,修改前序节点状态
int disposal = IsDown ? previous : current;
this.SetAuditActived(disposal, false);
this.SetNodeActived(disposal, false);
//移动当前指针位置
current += IsDown && current < auditNodeList.Count - 1 ? 1 : 0; //向下
current += IsDown && current < this.NodeCount - 1 ? 1 : 0; //向下
current += !IsDown && current > 0 ? -1 : 0; //向上
previous = current - 1; //前序指针永远等于:current-1
//激活当前节点和前序节点
this.SetAuditActived();
this.SetNodeActived();
}
}
}
......@@ -11,24 +11,31 @@ using Tools.MyUtils;
namespace Tools.MyCommon.controls
{
/// <summary>
/// 审核节点
/// </summary>
public partial class ucAuditNode : UserControl
{
/// <summary>
/// 审核状态改变事件
/// </summary>
public event EventHandler AuditStateChanged;
/// <summary>
/// 构造函数:审核节点
/// </summary>
public ucAuditNode()
{
InitializeComponent();
}
private bool _actived = false;
/// <summary>
/// 数据源
/// </summary>
public DataRow DataSource { get; set; } = null;
/// <summary>
/// (私有)是否激活
/// </summary>
private bool _actived = false;
/// <summary>
/// 是否激活
/// </summary>
public bool IsActive
......@@ -61,23 +68,29 @@ namespace Tools.MyCommon.controls
/// </summary>
private string WaitAuditUser => this.DataSource == null ? "" : $";{this.DataSource["WaitAuditUser"].ToString()};";
/// <summary>
/// 事件:控件加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ucAudit_Load(object sender, EventArgs e)
{
if (!this.DesignMode && this.DataSource != null)
{
this.SetEnabled();
this.lbAuditState.Text = this.GetAuditStateText();
this.lbAuditDateTime.Text = this.DataSource["AuditDateTime"].ToString();
this.lbWaitAuditUser.Text = this.DataSource["WaitAuditUser"].ToString();
this.lbAuditUser.Text = this.DataSource["AuditUser"].ToString();
this.tbAuditRemark.Text = this.DataSource["AuditRemark"].ToString();
//
//初始化界面
this.InitView();
//绑定事件
this.rbInit.CheckedChanged += RadioButton_CheckedChanged;
this.rbPass.CheckedChanged += RadioButton_CheckedChanged;
this.rbNoPass.CheckedChanged += RadioButton_CheckedChanged;
this.rbRevert.CheckedChanged += RadioButton_CheckedChanged;
}
}
/// <summary>
/// 事件:单选按钮选择
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void RadioButton_CheckedChanged(object sender, EventArgs e)
{
//只接收选中事件
......@@ -94,6 +107,32 @@ namespace Tools.MyCommon.controls
}
}
/// <summary>
/// 初始化界面
/// </summary>
private void InitView()
{
//设置有效性
this.SetEnabled();
//初始化信息
this.lbAuditState.Text = this.GetAuditStateText();
this.lbAuditDateTime.Text = this.DataSource["AuditDateTime"].ToString();
this.lbWaitAuditUser.Text = this.DataSource["WaitAuditUser"].ToString();
this.lbAuditUser.Text = this.DataSource["AuditUser"].ToString();
this.tbAuditRemark.Text = this.DataSource["AuditRemark"].ToString();
}
/// <summary>
/// 刷新界面
/// </summary>
public void RefreshView()
{
this.InitView();
}
/// <summary>
/// 获取审批状态
/// </summary>
/// <returns></returns>
private int GetAuditState()
{
if (this.rbPass.Checked)
......@@ -105,6 +144,10 @@ namespace Tools.MyCommon.controls
return 0;
}
/// <summary>
/// 获取审批状态文本
/// </summary>
/// <returns></returns>
private string GetAuditStateText()
{
string result = "";
......@@ -120,11 +163,17 @@ namespace Tools.MyCommon.controls
return result;
}
/// <summary>
/// 设置有效性
/// </summary>
private void SetEnabled()
{
this.Enabled = this.IsActive && this.WaitAuditUser.IndexOf($";{Utils.LoginUser};") >= 0;
this.tbAuditRemark.Enabled = this.Enabled && this.IsWaitAudit;
}
/// <summary>
/// 设置审批信息
/// </summary>
private void SetAuditInfo()
{
this.lbAuditState.Text = this.GetAuditStateText();
......
......@@ -18,12 +18,12 @@ namespace Tools.MyUtils
private static readonly int gab_width = 6; //标签间隔
private static readonly int init_x = 50; //起始坐标x
private static readonly int init_y = 50; //起始坐标y
//横坐标相对位置:因为单向绘制,这里只需考虑横坐标
//横坐标相对位置
private static readonly int arrow_width = label_width + gab_width - bitmap_width; //箭头长度
private static readonly int arrow_relative_x = bitmap_width; //箭头相对位置x
private static readonly int label_relative_x = label_width / 2 + bitmap_width / 2 + gab_width; //标签相对位置x
private static readonly int bitmap_relative_x = label_width + gab_width; //图片相对位置x
//纵坐标固定位置
//纵坐标固定位置(因为单向绘制,所以纵坐标都是固定的)
private static readonly int arrow_y = init_y + bitmap_width / 2; //箭头纵坐标绝对位置
private static readonly int label_y = init_y + bitmap_width; //标签纵坐标绝对位置
......@@ -135,7 +135,7 @@ namespace Tools.MyUtils
FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.LineLimit,
Trimming = StringTrimming.EllipsisPath
};
g.DrawRectangle(new Pen(Brushes.Red), rectangle);
//g.DrawRectangle(new Pen(Brushes.Red), rectangle);
g.DrawString(text, font, Brushes.Black, rectangle, format);
}
......
......@@ -50,7 +50,6 @@
this.tsbExit = new System.Windows.Forms.ToolStripButton();
this.tabPage3 = new System.Windows.Forms.TabPage();
this.panel2 = new System.Windows.Forms.Panel();
this.lbInfo = new System.Windows.Forms.Label();
this.cmbLoginUser = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.ucAudit1 = new Tools.MyCommon.controls.ucAudit();
......@@ -253,7 +252,6 @@
//
// panel2
//
this.panel2.Controls.Add(this.lbInfo);
this.panel2.Controls.Add(this.cmbLoginUser);
this.panel2.Controls.Add(this.label1);
this.panel2.Dock = System.Windows.Forms.DockStyle.Top;
......@@ -262,15 +260,6 @@
this.panel2.Size = new System.Drawing.Size(792, 35);
this.panel2.TabIndex = 1;
//
// lbInfo
//
this.lbInfo.AutoSize = true;
this.lbInfo.Location = new System.Drawing.Point(313, 12);
this.lbInfo.Name = "lbInfo";
this.lbInfo.Size = new System.Drawing.Size(41, 12);
this.lbInfo.TabIndex = 2;
this.lbInfo.Text = "label2";
//
// cmbLoginUser
//
this.cmbLoginUser.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
......@@ -348,7 +337,6 @@
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.ComboBox cmbLoginUser;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label lbInfo;
private MyCommon.controls.ucAudit ucAudit1;
}
}
\ No newline at end of file
......@@ -117,6 +117,18 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="Column1.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column2.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column3.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column1.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
......@@ -134,7 +146,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADW
CAAAAk1TRnQBSQFMAgEBAwEAAUgBAAFIAQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
CAAAAk1TRnQBSQFMAgEBAwEAAVABAAFQAQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment