/*******************************************************************************
* Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:F_MST_0204.cs
* 2.功能描述:范围权限
* 编辑履历:
* 作者 日期 版本 修改内容
* 王鑫 2014/09/17 1.00 新建
*******************************************************************************/
using System;
using System.Data;
using System.Windows.Forms;
using Dongke.IBOSS.PRD.Basics.BaseControls;
using Dongke.IBOSS.PRD.Basics.BaseResources;
using Dongke.IBOSS.PRD.Basics.Library;
using Dongke.IBOSS.PRD.Client.CommonModule;
using Dongke.IBOSS.PRD.Client.Controls;
using Dongke.IBOSS.PRD.WCF.Proxys;
namespace Dongke.IBOSS.PRD.Client.SystemModule
{
public partial class F_MST_0207 : FormBase
{
#region 成员变量
// 传过来的用户ID
private int _userID;
// 页面的数据源
DataSet _userRightData;
// 是否是第一次加载页面
bool _isFirstLoad = true;
//查看工号权限
bool _viewUser = false; //默认是否选中
// 工号权限
bool _user = false; //默认是否选中
// 查看成型线
bool _viewGroutingLine = false;
// 操作成型线
bool _groutingLine = false;//
// 操作温湿度
bool _thermometer = false;
// 查看温湿度
bool _viewThermometer = false;
// 操作部门
bool _organization = false;
// 查看部门
bool _viewOrganization = false;
// 操作工序
bool _proceduce = false;
// 查看工序
bool _viewProceduce = false;
// 数据表的数据源
private DataTable _dtDataGird = null;
private string _userCodeValue;
private bool _ShowFlag = true;
private int? _purviewID = null;
private int? _purviewType = null;
#endregion
#region 构造函数
public F_MST_0207()
{
InitializeComponent();
}
public F_MST_0207(int userID)
{
InitializeComponent();
this._userID = userID;
// 设置标题
this.Text = FormTitles.F_MST_0204;
// 工具栏按钮文本赋值
this.btnSave.Text = ButtonText.BTN_SAVE;
this.btnCancel.Text = ButtonText.BTN_CLOSE;
}
public F_MST_0207(int userID, string userCode)
{
InitializeComponent();
this._userID = userID;
// 设置标题
this.Text = FormTitles.F_MST_0204;
// 工具栏按钮文本赋值
this.btnSave.Text = ButtonText.BTN_SAVE;
this.btnCancel.Text = ButtonText.BTN_CLOSE;
}
#endregion
#region 事件
///
/// 窗体加载事件
///
///
///
private void F_MST_0204_Load(object sender, EventArgs e)
{
try
{
// 保存按钮不可用
//this.btnSave.Enabled = false;
this._userRightData = (DataSet)DoAsync(new BaseAsyncMethod(this.GetUserRightData));
if (this._userRightData != null && this._userRightData.Tables.Count >= Constant.INT_IS_ZERO)
{
//加载用户列表
DataSet functionUsers = (DataSet)DoAsync(new BaseAsyncMethod(GetFunctionUsers));
//this.btnSave.Enabled = DataJudge.IsChange(this._userFunctionRightData);
//this.btnCancel.Enabled = true;
if (functionUsers != null)
{
this.dgvFunctionUsers.AutoGenerateColumns = false;
this.dgvFunctionUsers.DataSource = functionUsers.Tables[0];
//this.dgvFunctionUsers.Columns["UserCode"].ReadOnly = true;
this.dgvFunctionUsers.Columns["UserName1"].ReadOnly = true;
this.dgvFunctionUsers.Columns["OrganizationName1"].ReadOnly = true;
this._dtDataGird = functionUsers.Tables[0];
//
////DataView dv = functionUsers.Tables[0].DefaultView;
////dv.RowFilter = "FunctionCode='-100'";
////this.dgvFunctionUsers.DataSource = dv.ToTable();
}
//查看业务部门树的生成
this.InitOrganizationTreeView(this._userRightData.Tables[0], true);
this.tvwViewOrganization.ExpandAll();
// 操作业务部门树的生成
this.InitOrganizationTreeView(this._userRightData.Tables[1], false);
this.tvwOrganization.ExpandAll();
// 设置DataGridView属性
this.dgvViewUser.AutoGenerateColumns = false;
this.dgvViewUser.Columns[5].ReadOnly = true;
// 工号权限的绑定
this.dgvViewUser.DataSource = this._userRightData.Tables[2];
// 设置DataGridView属性
this.dgvUser.AutoGenerateColumns = false;
this.dgvUser.Columns[5].ReadOnly = true;
// 工号权限的绑定
this.dgvUser.DataSource = this._userRightData.Tables[3];
// 设置DataGridView属性
this.dgvViewGroutingLine.AutoGenerateColumns = false;
this.dgvViewGroutingLine.Columns[3].ReadOnly = true;
// 查看成型线权限的绑定
this.dgvViewGroutingLine.DataSource = this._userRightData.Tables[4];
// 设置DataGridView属性
this.dgvGroutingLine.AutoGenerateColumns = false;
this.dgvGroutingLine.Columns[3].ReadOnly = true;
// 操作成型线权限的绑定
this.dgvGroutingLine.DataSource = this._userRightData.Tables[5];
// 生成查看生产线及工序树
InitGroutingLineTreeView(this._userRightData.Tables[6], this._userRightData.Tables[8]);
this.tvwGroutinProductionLine.ExpandAll();
InitGroutingLineTreeCKView(this._userRightData.Tables[7], this._userRightData.Tables[9]);
this.tvwGroutinProductionLineCK.ExpandAll();
// 撤销工序范围 InitCancelTreeCKView
DataTable dtCopy = this._userRightData.Tables[6].Copy();
dtCopy.TableName = "newtable";
foreach (DataRow dr in dtCopy.Rows)
{
dr["purviewtype"] = -99;
}
dtCopy.AcceptChanges();
this._userRightData.Tables.Add(dtCopy);
InitCancelTreeCKView(dtCopy, this._userRightData.Tables[12]);
this.treeViewCancel.ExpandAll();
// 设置DataGridView属性
this.dgvViewThermometer.AutoGenerateColumns = false;
this.dgvViewThermometer.Columns[3].ReadOnly = true;
// 查看温湿计权限的绑定
this.dgvViewThermometer.DataSource = this._userRightData.Tables[10];
// 设置DataGridView属性
this.dgvThermometer.AutoGenerateColumns = false;
this.dgvThermometer.Columns[3].ReadOnly = true;
// 操作温湿计权限的绑定
this.dgvThermometer.DataSource = this._userRightData.Tables[11];
//
DataView dv = functionUsers.Tables[0].DefaultView;
dv.RowFilter = "Purviewid='-100'";
this.dgvFunctionUsers.DataSource = dv.ToTable();
}
this._isFirstLoad = false;
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 根据系统功能ID取得使用该功能的用户列表
///
///
private DataSet GetFunctionUsers()
{
try
{
return SystemModuleProxy.Service.GetFunctionUserPurviewList();
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 窗体关闭时事件
///
///
///
private void F_MST_0204_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
// 判断数据是否被修改过,修改过需要提示保存消息
//if (DataJudge.IsChange(this._userRightData))
//if (this.btnSave.Enabled)
if (DataJudge.IsChange(this._dtDataGird))
{
DialogResult result = MessageBox.Show(Messages.MSG_CMN_Q001, this.Text,
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
// 保存数据
btnSave_Click(sender, e);
}
else if (result == DialogResult.Cancel)
{
e.Cancel = true;
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 组织机构范围权限的子节点选择后,父节点自动选择
/// 父节点选择之后,子节点自动选择
/// 选择之后修改后台数据源
///
///
///
private void tvwViewOrganization_AfterCheck(object sender, TreeViewEventArgs e)
{
try
{
//int purviewID = Convert.ToInt32(e.Node.Tag);
//foreach (DataRow dataRow in _userRightData.Tables[0].Rows)
//{
// if (purviewID == Convert.ToInt32(dataRow["PurviewID"]))
// {
// dataRow["RightFlag"] = e.Node.Checked;
// break;
// }
//}
//if (!this._isFirstLoad)
//{
// // 保存按钮状态改变
// this.btnSave.Enabled = DataJudge.IsChange(this._userRightData);
//}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 窗体关闭
///
///
///
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
//保存按钮事件
private void btnSave_Click(object sender, EventArgs e)
{
try
{
this.btnSave.Enabled = false;
this.btnCancel.Enabled = false;
int returnAffectRows = (int)DoAsync(new BaseAsyncMethod(SaveUserRightInfo));
this.btnSave.Enabled = true;
this.btnCancel.Enabled = true;
if (returnAffectRows > Constant.INT_IS_ZERO)
{
this._dtDataGird.AcceptChanges();
// 提示信息
MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "修改用户范围权限", "保存"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
}
else
{
// 提示信息
MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "修改用户范围权限", "保存"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
catch (Exception ex)
{
this.btnSave.Enabled = true;
this.btnCancel.Enabled = true;
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 操作部门树结点改变
///
///
///
private void tvwOrganization_AfterCheck(object sender, TreeViewEventArgs e)
{
try
{
//int purviewID = Convert.ToInt32(e.Node.Tag);
//foreach (DataRow dataRow in _userRightData.Tables[1].Rows)
//{
// if (purviewID == Convert.ToInt32(dataRow["PurviewID"]))
// {
// dataRow["RightFlag"] = e.Node.Checked;
// break;
// }
//}
//if (!this._isFirstLoad)
//{
// // 保存按钮状态改变
// this.btnSave.Enabled = DataJudge.IsChange(this._userRightData);
//}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 操作业务部门树形全部收缩
///
///
///
private void btnOrganizationCollapse_Click(object sender, EventArgs e)
{
this.tvwOrganization.CollapseAll();
}
///
/// 操作员范围选择发生改变,保存按钮状态
///
///
///
private void dgvUser_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
//if (!this._isFirstLoad)
//{
// // 保存按钮状态改变
// this.btnSave.Enabled = DataJudge.IsChange(this._userRightData);
//}
}
//
/// 操作员范围选择发生改变,保存按钮状态
///
///
///
private void dgvUser_CellValueChanged_1(object sender, DataGridViewCellEventArgs e)
{
//if (!this._isFirstLoad)
//{
// // 保存按钮状态改变
// this.btnSave.Enabled = DataJudge.IsChange(this._userRightData);
//}
}
///
/// 生产线单元格值改变
///
///
///
private void dgvViewGroutingLine_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
//if (!this._isFirstLoad)
//{
// // 保存按钮状态改变
// this.btnSave.Enabled = DataJudge.IsChange(this._userRightData);
//}
}
///
/// 操作成型生产线单元格值改变
///
///
///
private void dgvGroutingLine_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
//if (!this._isFirstLoad)
//{
// // 保存按钮状态改变
// this.btnSave.Enabled = DataJudge.IsChange(this._userRightData);
//}
}
///
/// 查看生产线及工序范围权限选中改变事件
///
///
///
private void tvwGroutinProductionLine_AfterCheck(object sender, TreeViewEventArgs e)
{
try
{
//int purviewID = Convert.ToInt32(e.Node.Tag);
////起始为ProductionLine_为成型生产线,否则为工序
//foreach (DataRow dataRow in (e.Node.Name.StartsWith("ProductionLine_") ? _userRightData.Tables[6].Rows : _userRightData.Tables[8].Rows))
//{
// if (purviewID == Convert.ToInt32(dataRow["PurviewID"]))
// {
// dataRow["RightFlag"] = e.Node.Checked;
// break;
// }
// if (e.Node.Parent != null)
// {
// if (e.Node.Checked)
// e.Node.Parent.Checked = true;
// }
//}
//if (!this._isFirstLoad)
//{
// // 保存按钮状态改变
// this.btnSave.Enabled = DataJudge.IsChange(this._userRightData);
//}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 温湿计范围权限改变后
///
///
///
private void dgvThermometer_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
//if (!this._isFirstLoad)
//{
// // 保存按钮状态改变
// this.btnSave.Enabled = DataJudge.IsChange(this._userRightData);
//}
}
///
/// 操作工序范围选定值改变后
///
///
///
private void tvwGroutinProductionLineCK_AfterCheck(object sender, TreeViewEventArgs e)
{
}
///
/// 操作工序展开所有节点
///
///
///
private void btnCKOpen_Click(object sender, EventArgs e)
{
this.tvwGroutinProductionLineCK.ExpandAll();
}
///
/// 操作工序折叠所有节点
///
///
///
private void btnCKClose_Click(object sender, EventArgs e)
{
this.tvwGroutinProductionLineCK.CollapseAll();
}
#endregion
#region 私有方法
///
/// 加载查看工序树结点
///
///
///
private void InitCancelTreeCKView(DataTable GroutingLineTable, DataTable ProductionLineTable)
{
foreach (DataRow row in GroutingLineTable.Rows)
{
TreeNode sNode;
sNode = new TreeNode();
sNode.Text = '[' + row["ProductionLineCode"].ToString() + ']' + row["ProductionLinename"].ToString();
sNode.Name = "ProductionLine_" + row["ProductionLineCode"].ToString();
sNode.Tag = row["PurviewID"];
if (Convert.ToBoolean(row["RightFlag"]))
{
sNode.Checked = true;
}
// this.tvwGroutinProductionLineCK.Nodes.Add(sNode);
this.treeViewCancel.Nodes.Add(sNode);
InitCancelProcedureTreeView(sNode, ProductionLineTable);
}
}
///
/// 生成查看成工序树
///
///
///
private void InitCancelProcedureTreeView(TreeNode sNode, DataTable ProductionLineTable)
{
DataRow[] rows = ProductionLineTable.Select
("ProductionLineid=" + sNode.Tag.ToString());
foreach (DataRow row in rows)
{
TreeNode childNode;
childNode = sNode.Nodes.Add('[' + row["ProcedureCode"].ToString() + ']' + row["Procedurename"].ToString());
childNode.Name = "Procedure_" + row["ProcedureCode"].ToString();
childNode.Tag = row["PurviewID"];
if (Convert.ToBoolean(row["RightFlag"]))
{
childNode.Checked = true;
}
}
}
/// 获取员工档案数据集
///
///
private DataSet GetUserRightData()
{
return SystemModuleProxy.Service.GetUserRightData(-2);
}
///
/// 根据取得的数据,生成部门树
///
///
/// 是否是查看部门
private void InitOrganizationTreeView(DataTable treeTable, bool isViewOrganization)
{
try
{
TreeNode node = null;
DataRow[] organizationRows = treeTable.Select
("OrganizationCode LIKE '0%' AND LEN(OrganizationCode) = 3");
// 递归生成功能权限树
this.InitTreeView(treeTable, organizationRows, node, isViewOrganization);
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 递归创建部门树
///
///
///
///
private void InitTreeView(DataTable treeTable, DataRow[] rows, TreeNode node, bool isViewOrganization)
{
foreach (DataRow row in rows)
{
TreeNode sNode;
if (node == null)
{
sNode = new TreeNode();
sNode.Text = '[' + row["OrganizationCode"].ToString() + ']' + row["OrganizationName"].ToString();
sNode.Name = row["OrganizationCode"].ToString();
sNode.Tag = row["PurviewID"];
if (Convert.ToBoolean(row["RightFlag"]))
{
sNode.Checked = true;
}
if (isViewOrganization)
{
this.tvwViewOrganization.Nodes.Add(sNode);
}
else
{
this.tvwOrganization.Nodes.Add(sNode);
}
}
else
{
sNode = node.Nodes.Add('[' + row["OrganizationCode"].ToString() + ']' + row["OrganizationName"].ToString());
sNode.Name = row["OrganizationCode"].ToString();
sNode.Tag = row["PurviewID"];
if (Convert.ToBoolean(row["RightFlag"]))
{
sNode.Checked = true;
}
}
string filterExpression = "OrganizationCode LIKE '" + row["OrganizationCode"].ToString()
+ "%' AND LEN(OrganizationCode) = " + (row["OrganizationCode"].ToString().Length + 3);
DataRow[] subRows = treeTable.Select(filterExpression);
// 递归方法
InitTreeView(treeTable, subRows, sNode, isViewOrganization);
}
}
///
/// 将全部节点选择或者取消选中
///
///
///
private void CheckTreeview(TreeView treeView, bool flag)
{
TreeNodeCollection nodes = treeView.Nodes;
foreach (TreeNode node in nodes)
{
CheckSubNodes(node, flag);
}
}
///
/// 递归选中节点或者取消选中节点
///
///
///
private void CheckSubNodes(TreeNode treeNode, bool flag)
{
treeNode.Checked = flag;
foreach (TreeNode node in treeNode.Nodes)
{
CheckSubNodes(node, flag);
}
}
///
/// 生成查看成型线树
///
///
///
private void InitGroutingLineTreeView(DataTable GroutingLineTable, DataTable ProductionLineTable)
{
foreach (DataRow row in GroutingLineTable.Rows)
{
TreeNode sNode;
sNode = new TreeNode();
sNode.Text = '[' + row["ProductionLineCode"].ToString() + ']' + row["ProductionLinename"].ToString();
sNode.Name = "ProductionLine_" + row["ProductionLineCode"].ToString();
sNode.Tag = row["PurviewID"];
if (Convert.ToBoolean(row["RightFlag"]))
{
sNode.Checked = true;
}
this.tvwGroutinProductionLine.Nodes.Add(sNode);
InitGroutingProductionTreeView(sNode, ProductionLineTable);
}
}
///
/// 加载查看工序树结点
///
///
///
private void InitGroutingLineTreeCKView(DataTable GroutingLineTable, DataTable ProductionLineTable)
{
foreach (DataRow row in GroutingLineTable.Rows)
{
TreeNode sNode;
sNode = new TreeNode();
sNode.Text = '[' + row["ProductionLineCode"].ToString() + ']' + row["ProductionLinename"].ToString();
sNode.Name = "ProductionLine_" + row["ProductionLineCode"].ToString();
sNode.Tag = row["PurviewID"];
if (Convert.ToBoolean(row["RightFlag"]))
{
sNode.Checked = true;
}
this.tvwGroutinProductionLineCK.Nodes.Add(sNode);
InitGroutingProductionTreeView(sNode, ProductionLineTable);
}
}
///
/// 生成查看成工序树
///
///
///
private void InitGroutingProductionTreeView(TreeNode sNode, DataTable ProductionLineTable)
{
DataRow[] rows = ProductionLineTable.Select
("ProductionLineid=" + sNode.Tag.ToString());
foreach (DataRow row in rows)
{
TreeNode childNode;
childNode = sNode.Nodes.Add('[' + row["ProcedureCode"].ToString() + ']' + row["Procedurename"].ToString());
childNode.Name = "Procedure_" + row["ProcedureCode"].ToString();
childNode.Tag = row["PurviewID"];
if (Convert.ToBoolean(row["RightFlag"]))
{
childNode.Checked = true;
}
}
}
#endregion
///
/// 绑定原来数据只能删除不能编辑
///
private void BindReadOnly()
{
foreach (DataGridViewRow row in this.dgvFunctionUsers.Rows)
{
if (row.Cells["AddFlag"].Value != null)
{
row.Cells["UserCode1"].ReadOnly = true;
}
}
this.dgvFunctionUsers.IsSetInputColumnsColor = true;
}
///
/// 操作部门
///
///
///
private void tvwOrganization_AfterSelect(object sender, TreeViewEventArgs e)
{
try
{
//if (e.Node.Name == Constant.INT_IS_ONE.ToString() || e.Node.Name == Constant.INT_IS_ZERO.ToString())
//{
this._purviewID = Convert.ToInt32(e.Node.Tag);
this._purviewType = 2;
DataView dv = this._dtDataGird.DefaultView;
dv.RowFilter = "purviewID=" + this._purviewID + " and purviewType=" + this._purviewType;
this.dgvFunctionUsers.DataSource = dv.ToTable();
BindReadOnly();
//}
}
catch (Exception ex)
{
this.btnCancel.Enabled = true;
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
// 查看部门
private void tvwViewOrganization_AfterSelect(object sender, TreeViewEventArgs e)
{
try
{
//if (e.Node.Name == Constant.INT_IS_ONE.ToString() || e.Node.Name == Constant.INT_IS_ZERO.ToString())
//{
this._purviewID = Convert.ToInt32(e.Node.Tag);
this._purviewType = 1;
DataView dv = this._dtDataGird.DefaultView;
dv.RowFilter = "purviewID=" + this._purviewID + " and purviewType=" + this._purviewType;
this.dgvFunctionUsers.DataSource = dv.ToTable();
BindReadOnly();
//}
}
catch (Exception ex)
{
this.btnCancel.Enabled = true;
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 操作工序
///
///
///
private void tvwGroutinProductionLineCK_AfterSelect(object sender, TreeViewEventArgs e)
{
try
{
//if (e.Node.Name == Constant.INT_IS_ONE.ToString() || e.Node.Name == Constant.INT_IS_ZERO.ToString())
//{
this._purviewID = Convert.ToInt32(e.Node.Tag);
if (e.Node.Name.Contains("ProductionLine_"))
{
this._purviewType = 8;
}
else
{
this._purviewType = 10;
}
DataView dv = this._dtDataGird.DefaultView;
dv.RowFilter = "purviewID=" + this._purviewID + " and purviewType=" + this._purviewType;
this.dgvFunctionUsers.DataSource = dv.ToTable();
BindReadOnly();
//}
}
catch (Exception ex)
{
this.btnCancel.Enabled = true;
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 查看工序
///
///
///
private void tvwGroutinProductionLine_AfterSelect(object sender, TreeViewEventArgs e)
{
try
{
//if (e.Node.Name == Constant.INT_IS_ONE.ToString() || e.Node.Name == Constant.INT_IS_ZERO.ToString())
//{
this._purviewID = Convert.ToInt32(e.Node.Tag);
if (e.Node.Name.Contains("ProductionLine_"))
{
this._purviewType = 7;
}
else
{
this._purviewType = 9;
}
DataView dv = this._dtDataGird.DefaultView;
dv.RowFilter = "purviewID=" + this._purviewID + " and purviewType=" + this._purviewType;
this.dgvFunctionUsers.DataSource = dv.ToTable();
BindReadOnly();
//}
}
catch (Exception ex)
{
this.btnCancel.Enabled = true;
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 操作工号
///
///
///
private void dgvUser_SelectionChanged(object sender, EventArgs e)
{
try
{
if (this.dgvUser.CurrentCell != null)
{
this._purviewID = Convert.ToInt32(this.dgvUser.Rows[this.dgvUser.CurrentCell.RowIndex].Cells["dgUserID"].Value);
this._purviewType = 4;
DataView dv = this._dtDataGird.DefaultView;
dv.RowFilter = "purviewID=" + this._purviewID + " and purviewType=" + this._purviewType;
this.dgvFunctionUsers.DataSource = dv.ToTable();
BindReadOnly();
}
}
catch (Exception ex)
{
this.btnCancel.Enabled = true;
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 查看工号
///
///
///
private void dgvViewUser_SelectionChanged(object sender, EventArgs e)
{
try
{
if (this.dgvViewUser.CurrentCell != null)
{
this._purviewID = Convert.ToInt32(this.dgvViewUser.Rows[this.dgvViewUser.CurrentCell.RowIndex].Cells["dgvViewUserID"].Value);
this._purviewType = 3;
DataView dv = this._dtDataGird.DefaultView;
dv.RowFilter = "purviewID=" + this._purviewID + " and purviewType=" + this._purviewType;
this.dgvFunctionUsers.DataSource = dv.ToTable();
BindReadOnly();
}
}
catch (Exception ex)
{
this.btnCancel.Enabled = true;
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 操作成型线
///
///
///
private void dgvGroutingLine_SelectionChanged(object sender, EventArgs e)
{
try
{
if (this.dgvGroutingLine.CurrentCell != null)
{
this._purviewID = Convert.ToInt32(this.dgvGroutingLine.Rows[this.dgvGroutingLine.CurrentCell.RowIndex].Cells["dgGroutingLineID"].Value);
this._purviewType = 6;
DataView dv = this._dtDataGird.DefaultView;
dv.RowFilter = "purviewID=" + this._purviewID + " and purviewType=" + this._purviewType;
this.dgvFunctionUsers.DataSource = dv.ToTable();
BindReadOnly();
}
}
catch (Exception ex)
{
this.btnCancel.Enabled = true;
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 查看成型线
///
///
///
private void dgvViewGroutingLine_SelectionChanged(object sender, EventArgs e)
{
try
{
if (this.dgvViewGroutingLine.CurrentCell != null)
{
this._purviewID = Convert.ToInt32(this.dgvViewGroutingLine.Rows[this.dgvViewGroutingLine.CurrentCell.RowIndex].Cells["dgViewGroutingLineID"].Value);
this._purviewType = 5;
DataView dv = this._dtDataGird.DefaultView;
dv.RowFilter = "purviewID=" + this._purviewID + " and purviewType=" + this._purviewType;
this.dgvFunctionUsers.DataSource = dv.ToTable();
BindReadOnly();
}
}
catch (Exception ex)
{
this.btnCancel.Enabled = true;
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 操作温湿度
///
///
///
private void dgvThermometer_SelectionChanged(object sender, EventArgs e)
{
try
{
if (this.dgvThermometer.CurrentCell != null)
{
this._purviewID = Convert.ToInt32(this.dgvThermometer.Rows[this.dgvThermometer.CurrentCell.RowIndex].Cells["dgThermometerID"].Value);
this._purviewType = 12;
DataView dv = this._dtDataGird.DefaultView;
dv.RowFilter = "purviewID=" + this._purviewID + " and purviewType=" + this._purviewType;
this.dgvFunctionUsers.DataSource = dv.ToTable();
BindReadOnly();
}
}
catch (Exception ex)
{
this.btnCancel.Enabled = true;
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 查看温湿度
///
///
///
private void dgvViewThermometer_SelectionChanged(object sender, EventArgs e)
{
try
{
if (this.dgvViewThermometer.CurrentCell != null)
{
this._purviewID = Convert.ToInt32(this.dgvViewThermometer.Rows[this.dgvViewThermometer.CurrentCell.RowIndex].Cells["dgThermometerIDV"].Value);
this._purviewType = 11;
DataView dv = this._dtDataGird.DefaultView;
dv.RowFilter = "purviewID=" + this._purviewID + " and purviewType=" + this._purviewType;
this.dgvFunctionUsers.DataSource = dv.ToTable();
BindReadOnly();
}
}
catch (Exception ex)
{
this.btnCancel.Enabled = true;
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
private void dgvFunctionUsers_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
try
{
if (this.dgvFunctionUsers.Rows.Count <= 1)
{
return;
}
DataGridViewColumn columnItem = this.dgvFunctionUsers.Columns[e.ColumnIndex];
if ("UserCode1".Equals(columnItem.Name))
{
_userCodeValue = this.dgvFunctionUsers.Rows[e.RowIndex].Cells[columnItem.Name].Value + "";
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
private void dgvFunctionUsers_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
try
{
if (this.dgvFunctionUsers.Rows.Count <= 1 || !_ShowFlag)
{
return;
}
DataGridViewRow rowItem = this.dgvFunctionUsers.Rows[e.RowIndex];
DataGridViewColumn columnItem = this.dgvFunctionUsers.Columns[e.ColumnIndex];
string OrganizationName = this.dgvFunctionUsers.Rows[e.RowIndex].Cells["OrganizationName1"].Value.ToString();
// 用编号获取产品信息
if ("UserCode1".Equals(columnItem.Name))
{
_ShowFlag = false;
DataTable dtNew = FormUtility.BindUserRowDataSource_FunctionCode(this.dgvFunctionUsers,
e.RowIndex, columnItem.Name, _userCodeValue);
if (dtNew != null && dtNew.Rows.Count > 0)
{
foreach (DataRow r in dtNew.Rows)
{
DataRow[] isR = this._dtDataGird.Select("Purviewid='" + this._purviewID + "' and UserID=" + r["UserID"] + " and PURVIEWTYPE=" + this._purviewType);
if (isR.Length == 0)
{
DataRow drNew = this._dtDataGird.NewRow();
drNew["UserID"] = r["UserID"];
drNew["UserCode"] = r["UserCode"];
drNew["UserName"] = r["UserName"];
drNew["OrganizationName"] = r["OrganizationName"];
drNew["Purviewid"] = this._purviewID;
drNew["PURVIEWTYPE"] = this._purviewType;
drNew["AddFlag"] = 1;
this._dtDataGird.Rows.Add(drNew);
dgvFunctionUsers.Rows[e.RowIndex].Cells["UserCode1"].ReadOnly = true;
// BindReadOnly();
}
}
}
//this.btnSave.Enabled = DataJudge.IsChange(this._dtDataGird);
this.btnSave.Enabled = true;
//this.dgvFunctionUsers.Rows[e.RowIndex].Cells["FunctionCode"].Value = this._functionCode;
//this._dtDataGird.AcceptChanges();
// 设置可输入单元格的颜色
this.dgvFunctionUsers.IsSetInputColumnsColor = true;
}
_ShowFlag = true;
}
catch (Exception ex)
{
//_ShowFlag = true;
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 保存用户范围权限
///
/// 更新数据影响的行数
private object SaveUserRightInfo()
{
try
{
return SystemModuleProxy.Service.SaveUserRightList(this._dtDataGird);
}
catch (Exception ex)
{
throw ex;
}
}
private void dgvFunctionUsers_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
{
if (e.Row.Index != -1)
{
DataTable dt = this.dgvFunctionUsers.DataSource as DataTable;
string Purviewid = dt.Rows[e.Row.Index]["Purviewid"].ToString();
string PURVIEWTYPE = dt.Rows[e.Row.Index]["PURVIEWTYPE"].ToString();
string userID = dt.Rows[e.Row.Index]["userID"].ToString();
//DataGridViewRow rowItem = this.dgvFunctionUsers.Rows[e.Row.Index];
//string functionCode = rowItem.Cells["FunctionCode"].Value.ToString();
//string userID = this.dgvFunctionUsers.Rows[e.Row.Index].Cells["userID"].Value.ToString();
DataRow[] isR = this._dtDataGird.Select("Purviewid='" + Purviewid + "' and UserID=" + userID + " and PURVIEWTYPE=" + PURVIEWTYPE);
isR[0].Delete();
this.btnSave.Enabled = true;
}
}
///
/// Tab页选定项索引改变后
///
///
///
private void tctlRight_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
//查看工号
if (tctlRight.SelectedTab.Text == "查看工号范围")
{
dgvViewUser_SelectionChanged(sender, e);
tvwViewOrganization.SelectedNode = null;
tvwGroutinProductionLineCK.SelectedNode = null;
tvwGroutinProductionLine.SelectedNode = null;
tvwOrganization.SelectedNode = null;
}
else if (tctlRight.SelectedTab.Text == "操作工号范围")
{
dgvUser_SelectionChanged(sender, e);
tvwViewOrganization.SelectedNode = null;
tvwGroutinProductionLineCK.SelectedNode = null;
tvwGroutinProductionLine.SelectedNode = null;
tvwOrganization.SelectedNode = null;
}
else if (tctlRight.SelectedTab.Text == "查看成型线范围")
{
dgvViewGroutingLine_SelectionChanged(sender, e);
tvwViewOrganization.SelectedNode = null;
tvwGroutinProductionLineCK.SelectedNode = null;
tvwGroutinProductionLine.SelectedNode = null;
tvwOrganization.SelectedNode = null;
}
else if (tctlRight.SelectedTab.Text == "操作成型线范围")
{
dgvGroutingLine_SelectionChanged(sender, e);
tvwViewOrganization.SelectedNode = null;
tvwGroutinProductionLineCK.SelectedNode = null;
tvwGroutinProductionLine.SelectedNode = null;
tvwOrganization.SelectedNode = null;
}
else if (tctlRight.SelectedTab.Text == "查看温湿计范围")
{
dgvViewThermometer_SelectionChanged(sender, e);
tvwViewOrganization.SelectedNode = null;
tvwGroutinProductionLineCK.SelectedNode = null;
tvwGroutinProductionLine.SelectedNode = null;
tvwOrganization.SelectedNode = null;
}
else if (tctlRight.SelectedTab.Text == "操作温湿计范围")
{
dgvThermometer_SelectionChanged(sender, e);
tvwViewOrganization.SelectedNode = null;
tvwGroutinProductionLineCK.SelectedNode = null;
tvwGroutinProductionLine.SelectedNode = null;
tvwOrganization.SelectedNode = null;
}
else if (tctlRight.SelectedTab.Text == "操作部门范围")
{
tvwOrganization.SelectedNode = tvwOrganization.Nodes[0];
tvwViewOrganization.SelectedNode = null;
tvwGroutinProductionLineCK.SelectedNode = null;
tvwGroutinProductionLine.SelectedNode = null;
}
else if (tctlRight.SelectedTab.Text == "查看部门范围")
{
tvwViewOrganization.SelectedNode = tvwViewOrganization.Nodes[0];
tvwGroutinProductionLineCK.SelectedNode = null;
tvwGroutinProductionLine.SelectedNode = null;
tvwOrganization.SelectedNode = null;
}
else if (tctlRight.SelectedTab.Text == "操作工序范围")
{
tvwGroutinProductionLineCK.SelectedNode = tvwGroutinProductionLineCK.Nodes[0];
tvwViewOrganization.SelectedNode = null;
tvwGroutinProductionLine.SelectedNode = null;
tvwOrganization.SelectedNode = null;
}
else if (tctlRight.SelectedTab.Text == "查看工序范围")
{
tvwGroutinProductionLine.SelectedNode = tvwGroutinProductionLine.Nodes[0];
tvwViewOrganization.SelectedNode = null;
tvwGroutinProductionLineCK.SelectedNode = null;
tvwOrganization.SelectedNode = null;
}
}
catch (Exception ex)
{
throw ex;
}
}
private void dgvFunctionUsers_Sorted(object sender, EventArgs e)
{
BindReadOnly();
}
private void treeViewCancel_AfterSelect(object sender, TreeViewEventArgs e)
{
try
{
this._purviewID = Convert.ToInt32(e.Node.Tag);
if (!e.Node.Name.Contains("ProductionLine_"))
{
this._purviewType = 13;
DataView dv = this._dtDataGird.DefaultView;
dv.RowFilter = "purviewID=" + this._purviewID + " and purviewType=" + this._purviewType;
this.dgvFunctionUsers.DataSource = dv.ToTable();
BindReadOnly();
}
}
catch (Exception ex)
{
this.btnCancel.Enabled = true;
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
}
}