📄 ucdictfylbwh.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 UCDictFyLbWh: Qeb.GY.UCDictBase
{
public UCDictFyLbWh()
{
InitializeComponent();
}
private void UCDictFyLbWh_Load(object sender, EventArgs e)
{
//初始化数据窗口
this.dwFyLb.LibraryList = PBL.GyPbl;
this.dwFyLb.DataWindowObject = GyDataObjects.D_Gy_FyLbWh;
this.dwFyLb.InitUI();
try
{
dwFyLb.SetProperty("DataWindow.ReadOnly", "Yes");
}
catch (Exception ex)
{
MessageBox.Show("设置数据窗口只读属性发生异常:" + ex.Message);
}
this.RetrieveData();
}
#region 函数
private DialogResult needSave()
{
DialogResult result = DialogResult.No;
if (this.m_IsModified)
{
result = MessageBox.Show(this, "数据已修改,是否需要保存?", MsgTitle.Prompt, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
}
return result;
}
private int findFylbid(string fylbid, int editRow)
{
int findRow = dwFyLb.FindRow("fylbid='" + fylbid + "'", 1, this.dwFyLb.RowCount);
if (findRow == editRow)
{
if (editRow < dwFyLb.RowCount)
{
findRow = dwFyLb.FindRow("fylbid='" + fylbid + "'", editRow + 1, this.dwFyLb.RowCount);
}
}
return findRow;
}
private void SetEnabled(bool ok)
{
if (ok)
{
this.btnModify.Enabled = true;
}
else
{
this.btnModify.Enabled = false;
btnAdd.Enabled = false;
btnStop.Enabled = false;
btnSave.Enabled = false;
}
}
#endregion
//根据费用类别ID和类别名称查找记录
public override void FindInDw(string value)
{
if (value == null)
value = "";
int findRow = dwFyLb.FindRow("fllbid='" + value +"or lbmc='"+value+ "'", 1, dwFyLb.RowCount);
if (findRow > 0)
{
dwFyLb.ScrollToRow(findRow);
dwFyLb.SetRow(findRow);
}
}
#region 数据完整性检查
private bool checkFylbwh()
{
string colName = "";
string errorMsg = "";
int rowNum = 0;
int rowCount = 0;
DataBuffer buffer = DataBuffer.Primary;
find:
if (buffer == DataBuffer.Primary)
rowCount = dwFyLb.RowCount;
else
rowCount = dwFyLb.FilteredCount;
rowNum = 0;
do
{
rowNum = dwFyLb.FindNextModifiedRow(rowNum, buffer);
if (rowNum > 0)
{
colName = "fylbid";
if (this.dwFyLb.IsItemNull(rowNum, colName))
{
errorMsg = "费用类别ID";
goto Error;
}
}
else
{
rowNum = rowCount;
}
}
while (rowNum < rowCount);
//处理过滤缓冲区
if (buffer == DataBuffer.Primary && dwFyLb.FilteredCount > 0)
{
buffer = DataBuffer.Filter;
goto find;
}
Error:
if (errorMsg != "")
{
if (buffer == DataBuffer.Filter)
{
MessageBox.Show("数据输入不完整," + errorMsg + "没有输入,该记录已被过滤,重新设置过滤条件后可显示!", MsgTitle.Warning);
}
else
{
MessageBox.Show("数据输入不完整,第" + rowNum.ToString() + "行" + errorMsg + "没有输入!", MsgTitle.Warning);
this.dwFyLb.ScrollToRow(rowNum);
this.dwFyLb.Focus();
this.dwFyLb.SetRow(rowNum);
this.dwFyLb.SetColumn(colName);
}
return false;
}
return true;
}
#endregion
#region 检索数据
private void RetrieveData()
{
try
{
DbProxyClient proxy = App.DbProxy;
proxy.Clear();
proxy.Retrieve(this.dwFyLb);
}
catch (Exception ex)
{
MessageBox.Show("检索数据出错:" + ex.Message, MsgTitle.Error);
}
finally
{
this.m_IsModified = false;
btnSave.Enabled = false;
}
}
#endregion
private void dwFyLb_EditChanged(object sender, EditChangedEventArgs e)
{
if (!this.m_IsModified)
{
this.m_IsModified = true;
this.btnSave.Enabled = true;
}
}
private void dwFyLb_ItemChanged(object sender, Sybase.DataWindow.ItemChangedEventArgs e)
{
switch (e.ColumnName)
{
case "fylbid":
if (e.Data == null || e.Data == "")
{
MessageBox.Show("不允许为空,请输入!");
e.Action = ItemChangedAction.Reject;
}
else
{
//检查是否存在重复参数ID
try
{
if (this.findFylbid(e.Data, e.RowNumber) > 0)
{
MessageBox.Show("参数ID已存在,不允许重复!", MsgTitle.Prompt);
e.Action = ItemChangedAction.RejectAndAllowFocusChange;
}
}
catch (Exception ex)
{
MessageBox.Show("重复参数ID是否已存在是发生异常:" + ex.Message, MsgTitle.Error);
e.Action = ItemChangedAction.Reject;
}
}
break;
}
//输入码
if (e.ColumnName == "lbmc")
{
if (e.Data == null || e.Data.Trim() == "")
{
e.Action = Sybase.DataWindow.ItemChangedAction.Reject;
dwFyLb.SetItemNull(e.RowNumber, "lbmc");
dwFyLb.SetItemNull(e.RowNumber, "srm1");
dwFyLb.SetItemNull(e.RowNumber, "srm2");
dwFyLb.SetItemNull(e.RowNumber, "srm3");
}
string srm1 = "";
string srm2 = "";
string srm3 = "";
string errMsg = StringHelper.GetSrm(e.Data, true, ref srm1, ref srm2, ref srm3);
if (errMsg == "")
{
dwFyLb.SetItemString(e.RowNumber, "srm1", srm1);
dwFyLb.SetItemString(e.RowNumber, "srm2", srm2);
dwFyLb.SetItemString(e.RowNumber, "srm3", srm3);
}
else
{
MessageBox.Show(errMsg, MsgTitle.Error);
}
}
}
private void dwFyLb_ItemError(object sender, ItemErrorEventArgs e)
{
e.Action = ItemErrorAction.RejectWithNoMessage;
}
private void dwFyLb_Click(object sender, EventArgs e)
{
//作废标志修改后可保存
if (this.btnAdd.Enabled && dwFyLb.ObjectUnderMouse.Band.Type == BandType.Detail)
{
if (dwFyLb.ObjectUnderMouse.Gob.Name == "zfbz")
{
if (!this.m_IsModified)
{
this.m_IsModified = true;
this.btnSave.Enabled = true;
}
}
}
}
#region buttons 增加等...
//增加
private void btnAdd_Click(object sender, EventArgs e)
{
int row = dwFyLb.InsertRow(0);
dwFyLb.SetRow(row);
dwFyLb.SetItemDecimal(row, "zfbz", 0);
dwFyLb.ScrollToRow(row);
dwFyLb.Focus();
dwFyLb.SetColumn("fylbid");
}
//作废
private void btnStop_Click(object sender, EventArgs e)
{
if (dwFyLb.CurrentRow > 0)
{
//停用的记录如果是新增的,直接删除
RowStatus status = dwFyLb.GetRowStatus(dwFyLb.CurrentRow, DataBuffer.Primary);
if (status == RowStatus.New || status == RowStatus.NewAndModified)
{
dwFyLb.DeleteRow(dwFyLb.CurrentRow);
return;
}
//费用类别ID
string fylbid = "";
if (!dwFyLb.IsItemNull(dwFyLb.CurrentRow, "fylbid"))
{
fylbid = dwFyLb.GetItemString(dwFyLb.CurrentRow, "fylbid");
}
//类别名称
string lbmc = "";
if (!dwFyLb.IsItemNull(dwFyLb.CurrentRow, "lbmc"))
{
lbmc = dwFyLb.GetItemString(dwFyLb.CurrentRow, "lbmc");
}
DialogResult result = MessageBox.Show(this, "费用类别ID为【" + fylbid + "】和类别名称为【" + lbmc + "】的信息将要被作废,您确定要作废吗?", MsgTitle.Prompt, MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
if (result == DialogResult.OK)
{
dwFyLb.SetItemDecimal(dwFyLb.CurrentRow, "zfbz", 1);
this.m_IsModified = true;
this.btnSave.Enabled = true;
}
}
else
{
MessageBox.Show("请选择需要删除的费用类别再单击删除按钮!", MsgTitle.Prompt);
}
}
//修改
private void btnModify_Click(object sender, EventArgs e)
{
try
{
dwFyLb.SetProperty("DataWindow.ReadOnly", "No");
}
catch (Exception ex)
{
MessageBox.Show("设置数据窗口只读属性发生异常:" + ex.Message);
return;
}
this.btnAdd.Enabled = true;
this.btnStop.Enabled = true;
}
//保存
private void btnSave_Click(object sender, EventArgs e)
{
if (!dwFyLb.AcceptText())
return;
///检验数据完整性
if (!this.checkFylbwh())
return;
try
{
DbProxyClient proxy = App.DbProxy;
proxy.Clear();
proxy.AddDataWindow(this.dwFyLb);
proxy.Update();
this.m_IsModified = false;
btnSave.Enabled = false;
}
catch (Exception ex)
{
MessageBox.Show("保存参数发生异常:" + ex.Message, MsgTitle.Error);
return;
}
UIMessageManager.FireEvent(MsgEventDefine.FyLbWh_Saved,null);
}
//刷新
private void btnRefresh_Click(object sender, EventArgs e)
{
if (needSave() == DialogResult.Yes)
return;
this.RetrieveData();
}
//关闭
private void btnClose_Click(object sender, EventArgs e)
{
this.ParentForm.Close();
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -