📄 ucdictcswh.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 UCDictCsWh : Qeb.GY.UCDictBase
{
//检索数据
private string m_RetrieveParam = "";
public UCDictCsWh()
{
InitializeComponent();
}
private void UCDictCsWh_Load(object sender, EventArgs e)
{
//初始化数据窗口
this.dwGyCs.LibraryList = PBL.GyPbl;
this.dwGyCs.DataWindowObject = GyDataObjects.D_Gy_GyCs;
this.dwGyCs.InitUI();
try
{
dwGyCs.SetProperty("DataWindow.ReadOnly", "Yes");
}
catch (Exception ex)
{
MessageBox.Show("设置数据窗口只读属性发生异常:" + ex.Message);
}
//订阅消息
this.SubscribeEvent(MsgEventDefine.Dict_RefreshWithParam);
}
#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 findCsid(string csid, int editRow)
{
int findRow = dwGyCs.FindRow("csid='" + csid + "'", 1, this.dwGyCs.RowCount);
if (findRow == editRow)
{
if (editRow < dwGyCs.RowCount)
{
findRow = dwGyCs.FindRow("csid='" + csid + "'", editRow + 1, this.dwGyCs.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
#region 消息处理
//消息处理
protected override void ProcessUIMessage(string messageId, UIMessageEventArgs e)
{
if (messageId == MsgEventDefine.Dict_RefreshWithParam)
{
FDictBase.TagInfo tagInfo;
try
{
tagInfo = (FDictBase.TagInfo)e.Values;
if (tagInfo.ControlName != "UCDictCsWh")
return;
}
catch (Exception ex)
{
MessageBox.Show("处理刷新数据消息发生异常(转换参数出错):" + ex.Message, MsgTitle.Error);
return;
}
if (m_RetrieveParam != tagInfo.RefreshParam)
{
//检查是否需要保存
if (needSave() == DialogResult.Yes)
return;
m_RetrieveParam = tagInfo.RefreshParam;
this.RetrieveData(tagInfo.RefreshParam);
//如果是所有根目录,不允许修改
if (m_RetrieveParam == "*")
SetEnabled(false);
else
SetEnabled(true);
}
}
}
#endregion
//根据参数ID或参数名称查找记录
public override void FindInDw(string value)
{
if (value == null)
value = "";
int findRow = dwGyCs.FindRow("csid like'" + value +"'or csmc like'"+value+ "'", 1, dwGyCs.RowCount);
if (findRow > 0)
{
dwGyCs.ScrollToRow(findRow);
dwGyCs.SetRow(findRow);
}
}
#region 数据完整性检查
private bool checkCsWh()
{
string colName = "";
string errorMsg = "";
int rowNum = 0;
int rowCount = 0;
DataBuffer buffer = DataBuffer.Primary;
find:
if (buffer == DataBuffer.Primary)
rowCount = dwGyCs.RowCount;
else
rowCount = dwGyCs.FilteredCount;
rowNum = 0;
do
{
rowNum = dwGyCs.FindNextModifiedRow(rowNum, buffer);
if (rowNum > 0)
{
colName = "csid";
if (this.dwGyCs.IsItemNull(rowNum, colName))
{
errorMsg = "参数ID";
goto Error;
}
}
else
{
rowNum=rowCount;
}
}
while (rowNum < rowCount);
//处理过滤缓冲区
if (buffer == DataBuffer.Primary && dwGyCs.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.dwGyCs.ScrollToRow(rowNum);
this.dwGyCs.Focus();
this.dwGyCs.SetRow(rowNum);
this.dwGyCs.SetColumn(colName);
}
return false;
}
return true;
}
#endregion
//检索数据
#region 检索数据
private void RetrieveData(string yyId)
{
try
{
DbProxyClient proxy = App.DbProxy;
proxy.Clear();
proxy.AddRetrieveParam("p_yyid", yyId);
proxy.Retrieve(this.dwGyCs);
//数据窗口
DataWindowChild dwc = dwGyCs.GetChild("yyid");
proxy.Clear();
proxy.Retrieve(dwc);
int row = dwc.InsertRow(0);
dwc.SetItemString(row, "yyid", "0000");
dwc.SetItemString(row, "yymc", "{公用参数}");
}
catch (Exception ex)
{
MessageBox.Show("检索数据出错:" + ex.Message, MsgTitle.Error);
}
finally
{
this.m_IsModified = false;
btnSave.Enabled = false;
}
}
#endregion
private void dwGyCs_EditChanged(object sender, EditChangedEventArgs e)
{
if(!this.m_IsModified)
{
this.m_IsModified = true;
this.btnSave.Enabled = true;
}
}
private void dwGyCs_ItemChanged(object sender, Sybase.DataWindow.ItemChangedEventArgs e)
{
switch(e.ColumnName)
{
case "csid":
if (e.Data == null || e.Data == "")
{
MessageBox.Show("不允许为空,请输入!");
e.Action = ItemChangedAction.Reject;
}
else
{
//检查是否存在重复参数ID
try
{
if (this.findCsid(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;
}
}
private void dwGyCs_ItemError(object sender, ItemErrorEventArgs e)
{
e.Action = ItemErrorAction.RejectWithNoMessage;
}
private void dwGyCs_Click(object sender, EventArgs e)
{
if (this.btnAdd.Enabled && dwGyCs.ObjectUnderMouse.Band.Type == BandType.Detail)
{
if (dwGyCs.ObjectUnderMouse.Gob.Name == "jzfs")
{
if (!this.m_IsModified)
{
this.m_IsModified = true;
this.btnSave.Enabled = true;
}
}
}
}
#region buttons
//增加等...
private void btnAdd_Click(object sender, EventArgs e)
{
int row = dwGyCs.InsertRow(0);
dwGyCs.SetRow(row);
dwGyCs.SetItemString(row, "yyid", m_RetrieveParam);
dwGyCs.SetItemDecimal(row, "xtbz", 0);
dwGyCs.SetItemDecimal(row, "jzfs", 1);
dwGyCs.ScrollToRow(row);
dwGyCs.Focus();
dwGyCs.SetColumn("csid");
}
private void btnStop_Click(object sender, EventArgs e)
{
int rowNum = this.dwGyCs.CurrentRow;
if (rowNum > 0)
{
if (dwGyCs.GetItemString(dwGyCs.CurrentRow, "xtbz")=="1")
{
this.m_IsModified =false;
this.btnSave.Enabled = false;
}
else
if (dwGyCs.CurrentRow > 0)
{
//停用的记录如果是新增的,直接删除
RowStatus status = dwGyCs.GetRowStatus(dwGyCs.CurrentRow, DataBuffer.Primary);
if (status == RowStatus.New || status == RowStatus.NewAndModified)
{
dwGyCs.DeleteRow(dwGyCs.CurrentRow);
return;
}
//参数ID
string csid = "";
if (!dwGyCs.IsItemNull(dwGyCs.CurrentRow, "csid"))
{
csid = dwGyCs.GetItemString(dwGyCs.CurrentRow, "csid");
}
DialogResult result = MessageBox.Show(this, "参数ID为【" + csid + "】的信息将要被删除,您确定吗?", MsgTitle.Prompt, MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
if (result == DialogResult.OK)
{
this.dwGyCs.DeleteRow(0);
this.m_IsModified = true;
this.btnSave.Enabled = true;
}
}
else
{
MessageBox.Show("请选择需要删除的参数再单击删除按钮!", MsgTitle.Prompt);
}
//{
//this.dwGyCs.DeleteRow(0);
//this.m_IsModified = true;
//this.btnSave.Enabled = true;
//}
}
}
private void btnModify_Click(object sender, EventArgs e)
{
try
{
dwGyCs.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)
{
dwGyCs.AcceptText();
///检验数据完整性
if (!this.checkCsWh())
return;
try
{
DbProxyClient proxy = App.DbProxy;
proxy.Clear();
proxy.AddDataWindow(this.dwGyCs);
proxy.Update();
this.m_IsModified = false;
btnSave.Enabled = false;
}
catch (Exception ex)
{
MessageBox.Show("保存参数发生异常:" + ex.Message, MsgTitle.Error);
}
}
private void btnRefresh_Click(object sender, EventArgs e)
{
if (needSave() == DialogResult.Yes)
return;
this.RetrieveData(m_RetrieveParam);
}
private void btnClose_Click(object sender, EventArgs e)
{
this.ParentForm.Close();
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -