📄 ucdictyqwh.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 UCDictYqWh : Qeb.GY.UCDictBase
{
public UCDictYqWh()
{
InitializeComponent();
}
private void UCDictYqWh_Load(object sender, EventArgs e)
{
this.LookUpPromptText = "请输入院区ID或院区名称";
//初始化数据窗口
this.dwYqXx.LibraryList = PBL.GyPbl;
this.dwYqXx.DataWindowObject = GyDataObjects.D_Gy_YqXx;
this.dwYqXx.InitUI();
try
{
dwYqXx.SetProperty("DataWindow.ReadOnly", "Yes");
}
catch(Exception ex)
{
MessageBox.Show("设置数据窗口只读属性发生异常:" + ex.Message);
}
this.RetrieveData();
}
#region 在数据窗口中查找记录
public override void FindInDw(string value)
{
if (value == null)
value = "";
int findRow = dwYqXx.FindRow("yqid='" + value + "' or yqmc='" + value + "'", 1, dwYqXx.RowCount);
if (findRow > 0)
{
dwYqXx.ScrollToRow(findRow);
dwYqXx.SetRow(findRow);
}
}
#endregion
#region 数据完整性检查
private bool CheckYqXx()
{
string colName = "";
string errorMsg = "";
int rowNum = 0;
int rowCount = 0;
DataBuffer buffer = DataBuffer.Primary;
find:
if (buffer == DataBuffer.Primary)
rowCount = dwYqXx.RowCount;
else
rowCount = dwYqXx.FilteredCount;
rowNum = 0;
do
{
rowNum = dwYqXx.FindNextModifiedRow(rowNum, buffer);
if (rowNum > 0)
{
colName = "Yqid";
if (this.dwYqXx.IsItemNull(rowNum, colName))
{
errorMsg = "院区ID";
break;
}
colName = "Yqmc";
if (this.dwYqXx.IsItemNull(rowNum, colName))
{
errorMsg = "院区名称";
break;
}
colName = "Pxxh";
if (this.dwYqXx.IsItemNull(rowNum, colName))
{
errorMsg = "排序序号";
break;
}
colName = "Tybz";
if (this.dwYqXx.IsItemNull(rowNum, colName))
{
errorMsg = "停用标志";
break;
}
}
else
{
rowNum = rowCount;
}
}
while (rowNum < rowCount);
//处理过滤缓冲区
if (buffer == DataBuffer.Primary && dwYqXx.FilteredCount > 0)
{
buffer = DataBuffer.Filter;
goto find;
}
if (errorMsg != "")
{
if (buffer == DataBuffer.Filter)
{
MessageBox.Show("数据输入不完整," + errorMsg + "没有输入,该记录已被过滤,重新设置过滤条件后可显示!", MsgTitle.Warning);
}
else
{
MessageBox.Show("数据输入不完整,第" + rowNum.ToString() + "行" + errorMsg + "没有输入!", MsgTitle.Warning);
this.dwYqXx.ScrollToRow(rowNum);
this.dwYqXx.Focus();
this.dwYqXx.SetRow(rowNum);
this.dwYqXx.SetColumn(colName);
}
return false;
}
return true;
}
#endregion
#region 增加
private void btnAdd_Click(object sender, EventArgs e)
{
int rowIndex = dwYqXx.InsertRow(0);
dwYqXx.SetRow(rowIndex);
dwYqXx.ScrollToRow(rowIndex);
dwYqXx.Focus();
dwYqXx.SetColumn("yqid");
}
#endregion
#region 删除
private void btnStop_Click(object sender, EventArgs e)
{
if (dwYqXx.CurrentRow > 0)
{
////停用的记录如果是新增的,直接删除
RowStatus status = dwYqXx.GetRowStatus(dwYqXx.CurrentRow, DataBuffer.Primary);
if (status == RowStatus.New || status == RowStatus.NewAndModified)
{
dwYqXx.DeleteRow(dwYqXx.CurrentRow);
return;
}
//院区ID
string yqid = "";
if (!dwYqXx.IsItemNull(dwYqXx.CurrentRow, "yqid"))
{
yqid = dwYqXx.GetItemString(dwYqXx.CurrentRow, "yqid");
}
//院区名称
string yqMc = "";
if (!dwYqXx.IsItemNull(dwYqXx.CurrentRow, "yqmc"))
{
yqMc = dwYqXx.GetItemString(dwYqXx.CurrentRow, "yqmc");
}
DialogResult result = MessageBox.Show(this, "院区ID为【" + yqid + "】院区名称为【" + yqMc + "】的记录只能停用,不能删除,您确定要停用吗?", MsgTitle.Prompt, MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
if (result == DialogResult.OK)
{
dwYqXx.SetItemDecimal(dwYqXx.CurrentRow, "TyBz", 1);
this.m_IsModified = true;
this.btnSave.Enabled = true;
}
}
else
{
MessageBox.Show("请选择需要删除的用户再单击删除按钮!", MsgTitle.Prompt);
}
}
#endregion
#region 保存
private void btnSave_Click(object sender, EventArgs e)
{
dwYqXx.AcceptText();
//检验数据完整性
if (!this.CheckYqXx())
return;
try
{
DbProxyClient proxy = App.DbProxy;
proxy.Clear();
proxy.AddDataWindow(this.dwYqXx);
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.Clear();
proxy.Retrieve(this.dwYqXx);
}
catch (Exception ex)
{
MessageBox.Show("检索数据出错:" + ex.Message, MsgTitle.Error);
}
finally
{
this.m_IsModified = false;
btnSave.Enabled = false;
}
this.dwYqXx.SetSort("pxxh");
this.dwYqXx.Sort();
}
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
{
dwYqXx.SetProperty("DataWindow.ReadOnly", "No");
}
catch (Exception ex)
{
MessageBox.Show("设置数据窗口只读属性发生异常:" + ex.Message);
return;
}
this.btnAdd.Enabled = true;
this.btnStop.Enabled = true;
}
private void dwYqXx_EditChanged(object sender, EditChangedEventArgs e)
{
if (!this.m_IsModified)
{
this.m_IsModified = true;
this.btnSave.Enabled = true;
}
}
private void btnPrint_Click(object sender, EventArgs e)
{
}
private void btnExport_Click(object sender, EventArgs e)
{
}
private void dwYqXx_ItemChanged(object sender, Sybase.DataWindow.ItemChangedEventArgs e)
{
switch (e.ColumnName)
{
case "yqid":
if (e.Data == null || e.Data == "")
{
MessageBox.Show("院区ID不允许为空,请输入!");
e.Action = ItemChangedAction.Reject;
}
break;
case "yqmc":
if (e.Data == null || e.Data == "")
{
MessageBox.Show("院区名称不允许为空,请输入!");
e.Action = ItemChangedAction.Reject;
}
break;
//case "pxxh":
// if (e.Data == null || e.Data == "")
// {
// MessageBox.Show("排序序号不允许为空,请输入!");
// e.Action = ItemChangedAction.Reject;
// }
// break;
//case "tybz":
// if (e.Data == null || e.Data == "")
// {
// MessageBox.Show("停用标志不允许为空,请输入!");
// e.Action = ItemChangedAction.Reject;
// }
// break;
}
}
private void dwYqXx_ItemError(object sender, ItemErrorEventArgs e)
{
e.Action = ItemErrorAction.RejectWithNoMessage;
}
private void dwYqXx_Click(object sender, EventArgs e)
{
if (this.btnAdd.Enabled && dwYqXx.ObjectUnderMouse.Band.Type == BandType.Detail)
{
if (dwYqXx.ObjectUnderMouse.Gob.Name == "tybz")
{
if (!this.m_IsModified)
{
this.m_IsModified = true;
this.btnSave.Enabled = true;
}
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -