⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ucdictfyxzwh.cs

📁 基于C/S的医疗卫生管理系统
💻 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 UCDictFyXzWh : Qeb.GY.UCDictBase
    {
        //检索数据
        private string m_RetrieveParam = "";
        public UCDictFyXzWh()
        {
            InitializeComponent();
        }

        private void UCDictFyXzWh_Load(object sender, EventArgs e)
        {
            //初始化数据窗口
            this.dwFyXz.LibraryList = PBL.GyPbl;
            this.dwFyXz.DataWindowObject = GyDataObjects.D_Gy_FyXzWh;
            this.dwFyXz.InitUI();
            try
            {
                dwFyXz.SetProperty("DataWindow.ReadOnly", "Yes");
            }
            catch (Exception ex)
            {
                MessageBox.Show("设置数据窗口只读属性发生异常:" + ex.Message);
            }

            //订阅消息         
            this.SubscribeEvent(MsgEventDefine.Dict_RefreshWithParam);

            this.UnSubscribeEvent(MsgEventDefine.FyLbWh_Saved);
        }
        #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 findFyxzid(string fyxzid, int editRow)
        {
            int findRow = dwFyXz.FindRow("fyxzid='" + fyxzid + "'", 1, this.dwFyXz.RowCount);
            if (findRow == editRow)
            {
                if (editRow < dwFyXz.RowCount)
                {
                    findRow = dwFyXz.FindRow("fyxzid='" + fyxzid + "'", editRow + 1, this.dwFyXz.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 != "UCDictFyXzWh")
                        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 = dwFyXz.FindRow("fyxzid='" + value + "or xzmc='"+value+"'", 1, dwFyXz.RowCount);
            if (findRow > 0)
            {
                dwFyXz.ScrollToRow(findRow);
                dwFyXz.SetRow(findRow);
            }
        }

        #region 数据完整性检查
        private bool checkFyxzWh()
        {
            string colName = "";
            string errorMsg = "";
            int rowNum = 0;
            int rowCount = 0;

            DataBuffer buffer = DataBuffer.Primary;
        find:
            if (buffer == DataBuffer.Primary)
                rowCount = dwFyXz.RowCount;
            else
                rowCount = dwFyXz.FilteredCount;

            rowNum = 0;
            do
            {

                rowNum = dwFyXz.FindNextModifiedRow(rowNum, buffer);
                if (rowNum > 0)
                {
                    colName = "fyxzid";
                    if (this.dwFyXz.IsItemNull(rowNum, colName))
                    {
                        errorMsg = "费用性质ID";
                        goto Error;
                    }

                }
                else
                {
                    rowNum = rowCount;
                }
            }
            while (rowNum < rowCount);
            //处理过滤缓冲区
            if (buffer == DataBuffer.Primary && dwFyXz.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.dwFyXz.ScrollToRow(rowNum);
                    this.dwFyXz.Focus();
                    this.dwFyXz.SetRow(rowNum);
                    this.dwFyXz.SetColumn(colName);
                }
                return false;
            }
            return true;
        }
        #endregion

        //检索数据
        #region 检索数据
        private void RetrieveData(string fylbId)
        {
            try
            {
                DbProxyClient proxy = App.DbProxy;
                proxy.Clear();
                proxy.AddRetrieveParam("p_fylbid", fylbId);
                proxy.Retrieve(this.dwFyXz);

                //检索子数据窗口 费用类别ID
                DataWindowChild dwc = dwFyXz.GetChild("fylbid");
                proxy.Clear();
                proxy.Retrieve(dwc);
            }
            catch (Exception ex)
            {
                MessageBox.Show("检索数据出错:" + ex.Message, MsgTitle.Error);
            }
            finally
            {
                this.m_IsModified = false;
                btnSave.Enabled = false;
            }

        }

        #endregion

        private void dwFyXz_EditChanged(object sender, EditChangedEventArgs e)
        {
            if (!this.m_IsModified)
            {
                this.m_IsModified = true;
                this.btnSave.Enabled = true;
            }
        }

        private void dwFyXz_ItemChanged(object sender, Sybase.DataWindow.ItemChangedEventArgs e)
        {
            switch (e.ColumnName)
            {
                case "fyxzid":
                    if (e.Data == null || e.Data == "")
                    {
                        MessageBox.Show("不允许为空,请输入!");
                        e.Action = ItemChangedAction.Reject;
                    }
                    else
                    {
                        //检查是否存在重复参数ID
                        try
                        {
                            if (this.findFyxzid(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 == "xzmc")
            {
                if (e.Data == null || e.Data.Trim() == "")
                {
                    e.Action = Sybase.DataWindow.ItemChangedAction.Reject;
                    dwFyXz.SetItemNull(e.RowNumber, "xzmc");
                    dwFyXz.SetItemNull(e.RowNumber, "srm1");
                    dwFyXz.SetItemNull(e.RowNumber, "srm2");
                    dwFyXz.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 == "")
                {
                    dwFyXz.SetItemString(e.RowNumber, "srm1", srm1);
                    dwFyXz.SetItemString(e.RowNumber, "srm2", srm2);
                    dwFyXz.SetItemString(e.RowNumber, "srm3", srm3);
                }
                else
                {
                    MessageBox.Show(errMsg, MsgTitle.Error);
                }
            }
        }

        private void dwFyXz_ItemError(object sender, ItemErrorEventArgs e)
        {
            e.Action = ItemErrorAction.RejectWithNoMessage;
        }

        
        #region buttons
        //增加
        private void btnAdd_Click(object sender, EventArgs e)
        {
            int row = dwFyXz.InsertRow(0);
            dwFyXz.SetRow(row);
            dwFyXz.SetItemString(row, "fylbid", m_RetrieveParam);
            dwFyXz.SetItemDecimal(row, "mzsybz", 0);
            dwFyXz.SetItemDecimal(row, "zysybz",0);
            dwFyXz.SetItemDecimal(row, "zfbz", 0);
            dwFyXz.ScrollToRow(row);
            dwFyXz.Focus();
            dwFyXz.SetColumn("fyxzid");
        }

        //删除
        private void btnStop_Click(object sender, EventArgs e)
        {
            if (dwFyXz.CurrentRow > 0)
            {
                //停用的记录如果是新增的,直接删除
                RowStatus status = dwFyXz.GetRowStatus(dwFyXz.CurrentRow, DataBuffer.Primary);
                if (status == RowStatus.New || status == RowStatus.NewAndModified)
                {
                    dwFyXz.DeleteRow(dwFyXz.CurrentRow);
                    return;
                }

                //费用性质ID
                string fyxzid = "";
                if (!dwFyXz.IsItemNull(dwFyXz.CurrentRow, "fyxzid"))
                {
                    fyxzid = dwFyXz.GetItemString(dwFyXz.CurrentRow, "fyxzid");
                }
                 
                //性质名称
                string xzmc = "";
                if (!dwFyXz.IsItemNull(dwFyXz.CurrentRow, "xzmc"))
                {
                    xzmc = dwFyXz.GetItemString(dwFyXz.CurrentRow, "xzmc");
                }
                DialogResult result = MessageBox.Show(this, "费用性质ID为【" + fyxzid + "】和性质名称为【" + xzmc + "】的信息将要被作废,您确定要作废吗?", MsgTitle.Prompt, MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (result == DialogResult.OK)
                {
                    dwFyXz.SetItemDecimal(dwFyXz.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
            {
                dwFyXz.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)
        {
            dwFyXz.AcceptText();

            ///检验数据完整性
            if (!this.checkFyxzWh())
                return;
            try
            {
                DbProxyClient proxy = App.DbProxy;
                proxy.Clear();
                proxy.AddDataWindow(this.dwFyXz);
                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 + -