📄 ucdictjswh.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Sybase.DataWindow;
using Qeb.Support;
using Qeb.Support.Common;
using Qeb.DBProxy;
namespace Qeb.GY
{
public partial class UCDictJsWh : Qeb.GY.UCDictBase
{
public UCDictJsWh()
{
InitializeComponent();
}
private void UCDictQxWh_Load(object sender, EventArgs e)
{
this.LookUpPromptText = "请输入角色ID或角色名称";
//初始化数据窗口
this.dwJsXx.LibraryList = PBL.GyPbl;
this.dwJsXx.DataWindowObject = GyDataObjects.D_Gy_JsXxWh;
this.dwJsXx.InitUI();
try
{
dwJsXx.SetProperty("DataWindow.ReadOnly", "Yes");
}
catch (Exception ex)
{
MessageBox.Show("设置数据窗口只读属性发生异常:" + ex.Message);
}
this.RetrieveData();
}
#region 根据角色ID、角色名称查找记录
public override void FindInDw(string value)
{
if (value == null)
value = "";
try
{
int findRow = dwJsXx.FindRow("jsid='" + value + "' or jsmc='" + value + "'", 1, dwJsXx.RowCount);
if (findRow > 0)
{
dwJsXx.ScrollToRow(findRow);
dwJsXx.SetRow(findRow);
}
}
catch(Exception ex)
{
MessageBox.Show("快速定位角色信息发生异常:" + ex.Message);
}
}
#endregion
#region 数据完整性检查
private bool CheckJsXx()
{
string colName = "";
string errorMsg = "";
int row = -1;
for (row = 1; row < this.dwJsXx.RowCount + 1; row++)
{
colName = "JsMc";
if (this.dwJsXx.IsItemNull(row, colName))
{
errorMsg = "角色名称";
break;
}
}
if (errorMsg != "")
{
MessageBox.Show("数据输入不完整,第" + row.ToString() + "行" + errorMsg + "没有输入!", MsgTitle.Warning);
this.dwJsXx.ScrollToRow(row);
this.dwJsXx.Focus();
this.dwJsXx.SetRow(row);
this.dwJsXx.SetColumn(colName);
return false;
}
return true;
}
#endregion
#region 增加
private void btnAdd_Click(object sender, EventArgs e)
{
int rowIndex = dwJsXx.InsertRow(0);
dwJsXx.SetItemDecimal(rowIndex, "pxxh", dwJsXx.GetRowIdFromRow(rowIndex));
dwJsXx.SetRow(rowIndex);
dwJsXx.ScrollToRow(rowIndex);
dwJsXx.Focus();
dwJsXx.SetColumn("JsMc");
}
#endregion
#region 删除
private void btnStop_Click(object sender, EventArgs e)
{
if (dwJsXx.CurrentRow >0)
{
//停用的记录如果是新增的,直接删除
RowStatus status = dwJsXx.GetRowStatus(dwJsXx.CurrentRow,DataBuffer.Primary);
if (status == RowStatus.New || status == RowStatus.NewAndModified)
{
dwJsXx.DeleteRow(dwJsXx.CurrentRow);
return;
}
//角色ID
string jsId = "";
if (!dwJsXx.IsItemNull(dwJsXx.CurrentRow, "JsId"))
{
jsId = dwJsXx.GetItemString(dwJsXx.CurrentRow, "JsId");
}
//角色名称
string jsMc = "";
if (!dwJsXx.IsItemNull(dwJsXx.CurrentRow,"jsmc"))
{
jsMc = dwJsXx.GetItemString(dwJsXx.CurrentRow, "jsmc");
}
DialogResult result = MessageBox.Show(this, "角色ID为【" + jsId + "】角色名称为【" + jsMc + "】的记录只能停用,不能删除,您确定要停用吗?", MsgTitle.Prompt, MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
if (result == DialogResult.OK)
{
dwJsXx.SetItemDecimal(dwJsXx.CurrentRow, "TyBz",1);
this.m_IsModified = true;
this.btnSave.Enabled = true;
}
}
else
{
MessageBox.Show("请选择需要删除的记录再单击删除按钮!",MsgTitle.Prompt);
}
}
#endregion
#region 保存
//设置主键
private void SetPk()
{
DbProxyClient proxy = App.DbProxy;
string jsid = "";
int rowNum = 0;
int rowCount = dwJsXx.RowCount;
do
{
rowNum = dwJsXx.FindNextModifiedRow(rowNum, DataBuffer.Primary);
if (rowNum > 0)
{
if (dwJsXx.IsItemNull(rowNum, "jsid") || dwJsXx.GetItemString(rowNum, "jsid") == "")
{
try
{
jsid = Sequence.GetXhByName("SEQ_GY_JSXX_JSID");
if (string.IsNullOrEmpty(jsid))
{
MessageBox.Show("没有取到序列,返回值为空!", MsgTitle.Error);
return;
}
dwJsXx.SetItemString(rowNum, "jsid", jsid);
}
catch (Exception ex)
{
MessageBox.Show("取序列发生异常:" + ex.Message, MsgTitle.Error);
break;
}
}
}
else
{
rowNum = rowCount;
}
}
while (rowNum < rowCount);
}
private void btnSave_Click(object sender, EventArgs e)
{
dwJsXx.AcceptText();
SetPk();
//检验数据完整性
if (!this.CheckJsXx())
return;
try
{
DbProxyClient proxy = App.DbProxy;
proxy.Clear();
proxy.AddDataWindow(this.dwJsXx);
proxy.Update();
this.m_IsModified = false;
btnSave.Enabled = false;
}
catch(Exception ex)
{
MessageBox.Show("保存角色信息发生异常:" + ex.Message,MsgTitle.Error);
}
}
#endregion
#region 关闭
private void btnClose_Click(object sender, EventArgs e)
{
this.ParentForm.Close();
}
#endregion
#region 检索数据
private void RetrieveData()
{
try
{
DbProxyClient proxy = App.DbProxy;
proxy.Retrieve(this.dwJsXx);
dwJsXx.SetSort("pxxh");
dwJsXx.Sort();
}
catch (Exception ex)
{
MessageBox.Show("检索数据发生异常:"+ex.Message,MsgTitle.Error);
}
finally
{
this.m_IsModified = false;
btnSave.Enabled = false;
}
}
private void btnRefresh_Click(object sender, EventArgs e)
{
if (this.m_IsModified )
{
DialogResult result = MessageBox.Show(this, "数据已修改,是否需要保存?", MsgTitle.Prompt, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
return;
}
}
this.RetrieveData();
}
#endregion
private void btnModify_Click(object sender, EventArgs e)
{
try
{
dwJsXx.SetProperty("DataWindow.ReadOnly", "No");
}
catch(Exception ex)
{
MessageBox.Show("设置数据窗口只读属性发生异常:"+ex.Message);
return;
}
this.btnAdd.Enabled = true;
this.btnStop.Enabled = true;
}
private void dwJsXx_EditChanged(object sender, EditChangedEventArgs e)
{
if (!this.m_IsModified)
{
this.m_IsModified = true;
this.btnSave.Enabled = true;
}
}
private int FindJsMc(string jsmc,int editRow)
{
int findRow = dwJsXx.FindRow("jsmc='" + jsmc + "'", 1, this.dwJsXx.RowCount);
if (findRow == editRow)
{
if (editRow < dwJsXx.RowCount)
findRow = dwJsXx.FindRow("jsmc='" + jsmc + "'", editRow+1, this.dwJsXx.RowCount);
}
return findRow;
}
private void dwJsXx_ItemChanged(object sender, Sybase.DataWindow.ItemChangedEventArgs e)
{
switch (e.ColumnName)
{
case "jsmc":
if (e.Data == null || e.Data == "")
{
MessageBox.Show("角色名称不允许为空,请输入!");
e.Action = ItemChangedAction.Reject;
}
else
{
try
{
if (this.FindJsMc(e.Data, e.RowNumber) >0)
{
MessageBox.Show("角色名称已存在,不允许重复!",MsgTitle.Prompt);
e.Action = ItemChangedAction.RejectAndAllowFocusChange;
}
}
catch(Exception ex)
{
MessageBox.Show("检查角色名称是否已存在是发生异常:"+ex.Message,MsgTitle.Error);
e.Action = ItemChangedAction.Reject;
}
}
break;
}
}
private void dwJsXx_ItemError(object sender, ItemErrorEventArgs e)
{
e.Action = ItemErrorAction.RejectWithNoMessage;
}
private void dwJsXx_Click(object sender, EventArgs e)
{
if (this.btnAdd.Enabled && dwJsXx.ObjectUnderMouse.Band.Type == BandType.Detail)
{
if (dwJsXx.ObjectUnderMouse.Gob.Name == "tybz")
{
if (!this.m_IsModified)
{
this.m_IsModified = true;
this.btnSave.Enabled = true;
}
}
}
}
private void btGaoJi_Click(object sender, EventArgs e)
{
showAdvancedDialog();
}
private void dwJsXx_DoubleClick(object sender, EventArgs e)
{
showAdvancedDialog();
}
private void showAdvancedDialog()
{
if (dwJsXx.CurrentRow == 0)
{
MessageBox.Show("请选择一个用户");
return;
}
if (this.m_IsModified)
{
MessageBox.Show("已有数据修改,请先保存");
return;
}
if (dwJsXx.IsItemNull(dwJsXx.CurrentRow, "jsid"))
return;
string jsMc = dwJsXx.GetItemString(dwJsXx.CurrentRow, "jsmc");
string jsId = dwJsXx.GetItemString(dwJsXx.CurrentRow, "jsid");
FJsYhWhGj fJsYhWhGj = new FJsYhWhGj();
fJsYhWhGj.SetJsMsg(jsMc, jsId);
fJsYhWhGj.ShowDialog(this);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -