📄 ucdictypcdwh.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Qeb.Control;
using Sybase.DataWindow;
using Qeb.Support;
using Qeb.Support.Common;
using Qeb.DBProxy;
using Qeb.GY;
namespace Qeb.YK
{
public partial class UCDictYpCdWh : Qeb.GY.UCDictBase
{
public UCDictYpCdWh()
{
InitializeComponent();
}
private void UCDictYpCdWh_Load(object sender, EventArgs e)
{
//初始化数据窗口
this.dwYpCd.LibraryList = PBL.GyPbl;
this.dwYpCd.DataWindowObject = GyDataObjects.D_Yk_YpCdWh;
this.dwYpCd.InitUI();
try
{
dwYpCd.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 findCdmc(string cdmc, int editRow)
{
int findRow = dwYpCd.FindRow("cdmc='" + cdmc + "'", 1, this.dwYpCd.RowCount);
if (findRow == editRow)
{
if (editRow < dwYpCd.RowCount)
{
findRow = dwYpCd.FindRow("cdmc='" + cdmc + "'", editRow + 1, this.dwYpCd.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 根据产地ID或产地名称查找记录
public override void FindInDw(string value)
{
if (value == null)
value = "";
int findRow = dwYpCd.FindRow("cdid='" + value + "or cdmc like'" + value+"'", 1, dwYpCd.RowCount);
if (findRow > 0)
{
dwYpCd.ScrollToRow(findRow);
dwYpCd.SetRow(findRow);
}
}
#endregion
#region 数据完整性检查函数
private bool checkYpCdWh()
{
string colName = "";
string errorMsg = "";
int rowNum = 0;
int rowCount = 0;
DataBuffer buffer = DataBuffer.Primary;
find:
if (buffer == DataBuffer.Primary)
rowCount = dwYpCd.RowCount;
else
rowCount = dwYpCd.FilteredCount;
rowNum = 0;
do
{
rowNum = dwYpCd.FindNextModifiedRow(rowNum, buffer);
if (rowNum > 0)
{
colName = "cdid";
if (this.dwYpCd.IsItemNull(rowNum, colName))
{
errorMsg = "产地ID";
goto Error;
}
}
else
{
rowNum = rowCount;
}
}
while (rowNum < rowCount);
//处理过滤缓冲区
if (buffer == DataBuffer.Primary && dwYpCd.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.dwYpCd.ScrollToRow(rowNum);
this.dwYpCd.Focus();
this.dwYpCd.SetRow(rowNum);
this.dwYpCd.SetColumn(colName);
}
return false;
}
return true;
}
#endregion
#region 检索数据
private void RetrieveData()
{
try
{
DbProxyClient proxy = App.DbProxy;
proxy.Clear();
proxy.Retrieve(this.dwYpCd);
//---
DataWindowChild dwsf = dwYpCd.GetChild("sfid");
proxy.Clear();
proxy.AddRetrieveParam(":p_flid", GyDmDefine.DMFL_SF);
proxy.Retrieve(dwsf);
DataWindowChild dwcd = dwYpCd.GetChild("cdlbid");
proxy.Clear();
proxy.AddRetrieveParam(":p_flid", GyDmDefine.DMFL_CDLB);
proxy.Retrieve(dwcd);
dwYpCd.Refresh();
}
catch (Exception ex)
{
MessageBox.Show("检索数据出错:" + ex.Message, MsgTitle.Error);
}
finally
{
this.m_IsModified = false;
btnSave.Enabled = false;
}
}
#endregion
//
private void dwYpCd_EditChanged(object sender, EditChangedEventArgs e)
{
if (!this.m_IsModified)
{
this.m_IsModified = true;
this.btnSave.Enabled = true;
}
}
private void dwYpCd_ItemChanged(object sender, Sybase.DataWindow.ItemChangedEventArgs e)
{
switch (e.ColumnName)
{
//产地名称不可以为空
case "cdmc":
if(e.Data==null||e.Data=="")
{
MessageBox.Show("产地名称不允许为空,请输入!");
e.Action = ItemChangedAction.Reject;
}
else
{
//检查是否存在重复产地名称
try
{
if (this.findCdmc(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;
//产地类别ID不为空
case "cdlbid":
if (e.Data == null || e.Data == "")
{
MessageBox.Show("产地类别不允许为空,请输入!");
e.Action = ItemChangedAction.Reject;
}
break;
}
//输入码的生成
if (e.ColumnName == "cdmc")
{
if (e.Data == null || e.Data.Trim() == "")
{
e.Action = Sybase.DataWindow.ItemChangedAction.Reject;
dwYpCd.SetItemNull(e.RowNumber, "cdmc");
dwYpCd.SetItemNull(e.RowNumber, "srm1");
dwYpCd.SetItemNull(e.RowNumber, "srm2");
dwYpCd.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 == "")
{
dwYpCd.SetItemString(e.RowNumber, "srm1", srm1);
dwYpCd.SetItemString(e.RowNumber, "srm2", srm2);
dwYpCd.SetItemString(e.RowNumber, "srm3", srm3);
}
else
{
MessageBox.Show(errMsg, MsgTitle.Error);
}
}
}
private void dwYpCd_ItemError(object sender,ItemErrorEventArgs e)
{
e.Action = ItemErrorAction.RejectWithNoMessage;
}
#region buttons
//增加
private void btnAdd_Click(object sender, EventArgs e)
{
int row = dwYpCd.InsertRow(0);
dwYpCd.SetRow(row);
dwYpCd.SetItemDecimal(row, "zfbz", 0);
dwYpCd.ScrollToRow(row);
dwYpCd.Focus();
dwYpCd.SetColumn("cdid");
}
#region 作废
private void btnStop_Click(object sender, EventArgs e)
{
if (dwYpCd.CurrentRow > 0)
{
//停用的记录如果是新增的,直接删除
RowStatus status = dwYpCd.GetRowStatus(dwYpCd.CurrentRow, DataBuffer.Primary);
if (status == RowStatus.New || status == RowStatus.NewAndModified)
{
dwYpCd.DeleteRow(dwYpCd.CurrentRow);
return;
}
//产地ID
string cdId = "";
if (!dwYpCd.IsItemNull(dwYpCd.CurrentRow, "cdid"))
{
cdId = dwYpCd.GetItemString(dwYpCd.CurrentRow, "cdid");
}
//产地名称
string cdMc = "";
if (!dwYpCd.IsItemNull(dwYpCd.CurrentRow, "cdmc"))
{
cdMc = dwYpCd.GetItemString(dwYpCd.CurrentRow, "cdmc");
}
DialogResult result = MessageBox.Show(this, "产地ID为【" + cdId + "】和产地名称为【" + cdMc + "】的信息将要被作废,您确定要作废吗?", MsgTitle.Prompt, MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
if (result == DialogResult.OK)
{
dwYpCd.SetItemDecimal(dwYpCd.CurrentRow, "zfbz", 1);
this.m_IsModified = true;
this.btnSave.Enabled = true;
}
}
else
{
MessageBox.Show("请选择需要删除的用户再单击删除按钮!",MsgTitle.Prompt);
}
}
#endregion
//修改
private void btnModify_Click(object sender, EventArgs e)
{
try
{
dwYpCd.SetProperty("DataWindow.ReadOnly", "No");
}
catch (Exception ex)
{
MessageBox.Show("设置数据窗口只读属性发生异常:" + ex.Message);
return;
}
this.btnAdd.Enabled = true;
this.btnStop.Enabled = true;
}
//设置主键函数
private void SetPk()
{
DbProxyClient proxy = App.DbProxy;
string cdid = "";
int rowNum = 0;
int rowCount = dwYpCd.RowCount;
do
{
rowNum = dwYpCd.FindNextModifiedRow(rowNum, DataBuffer.Primary);
if (rowNum > 0)
{
if (dwYpCd.IsItemNull(rowNum, "cdid") || dwYpCd.GetItemString(rowNum, "cdid") == "")
{
try
{
cdid = Sequence.GetXhByName("SEQ_GY_YPCD_CDID");
if (string.IsNullOrEmpty(cdid))
{
MessageBox.Show("没有取到序列,返回值为空!", MsgTitle.Error);
return;
}
dwYpCd.SetItemString(rowNum, "cdid", cdid);
}
catch (Exception ex)
{
MessageBox.Show("取序列发生异常:" + ex.Message, MsgTitle.Error);
break;
}
}
}
else
{
rowNum = rowCount;
}
}
while (rowNum < rowCount);
}
//保存
private void btnSave_Click(object sender, EventArgs e)
{
dwYpCd.AcceptText();
///检验数据完整性
SetPk();
if (!this.checkYpCdWh())
return;
try
{
DbProxyClient proxy = App.DbProxy;
proxy.Clear();
proxy.AddDataWindow(this.dwYpCd);
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();
}
//关闭
private void btnClose_Click(object sender, EventArgs e)
{
this.ParentForm.Close();
}
#endregion
//作废标志修改可以保存
private void dwYpCd_Click(object sender, EventArgs e)
{
if(this.btnAdd.Enabled&&dwYpCd.ObjectUnderMouse.Band.Type==BandType.Detail)
{
if(dwYpCd.ObjectUnderMouse.Gob.Name=="zfbz")
{
if(!this.m_IsModified)
{
this.m_IsModified = true;
this.btnSave.Enabled =true;
}
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -