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

📄 qdatawindow.cs

📁 基于C/S的医疗卫生管理系统
💻 CS
字号:
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Collections;
using System.Data;

using Sybase.DataWindow;
using Oracle.DataAccess.Client;

using Qeb.DBProxy;
using Qeb.Support.Common;

namespace Qeb.Control
{
    public partial class QDataWindow : DataWindowControl
    {
        public QDataWindow()
        {
            InitializeComponent();
        }

        public QDataWindow(IContainer container)
        {
            container.Add(this);
            InitializeComponent();
        }

        #region 变量 属性
        private ViewStyle m_ViewStyle = ViewStyle.Standard;
        [Description("控件样式"), Category("控件样式")]
        public ViewStyle ControlStyle
        {
            get { return m_ViewStyle; }
            set { m_ViewStyle = value; }
        }

        private bool m_HeaderSort = false;
        [Description("点击列头排序,不是GRID风格DataObject或DataObject为空的不能点列头排序"), Category("扩展属性")]
        public bool HeaderSort
        {
            get { return m_HeaderSort; }
            set { m_HeaderSort = value; }
        }
        private string m_SortType = "A";

        //private bool m_SelectedRowHighLighted = true;
        //[Description("当前行高亮显示"), Category("扩展属性")]
        //public bool SelectedRowHighLighted
        //{
        //    get { return m_SelectedRowHighLighted; }
        //    set { m_SelectedRowHighLighted = value; }
        //}

        private bool m_EnterToTab = false;
        [Description("回车转为Tab"), Category("扩展属性")]
        public bool EnterToTab
        {
            get { return m_EnterToTab; }
            set { m_EnterToTab = value; }
        }

        private Color m_CurrentRowColor = Color.FromArgb(200, 223, 251);
        private Color m_RowColor = Color.FromArgb(253, 248, 247);
        private Color m_EvenRowColor = Color.FromArgb(240, 245, 245); //248, 238, 236

        private Color m_BackColor = Color.FromArgb(253, 248, 247);
        //private Color m_HeaderBackColor = Color.FromArgb(240, 214, 209);
        private Color m_HeaderBackColor = Color.FromArgb(253, 248, 247);

        private Color m_ModifiedColBackColor = Color.FromArgb(244, 255, 244);
        private Color m_ReadonlyColBackColor = Color.FromArgb(226, 228, 226);

        #endregion

        public void InitUI()
        {
            if (string.IsNullOrEmpty(this.DataWindowObject))
                return;
            if (m_ViewStyle == ViewStyle.Standard)
            {
                try
                {

                    this.Modify("DataWindow.Color=" + ColorTranslator.ToWin32(m_BackColor));
                    this.Modify("DataWindow.Header.Color=" + ColorTranslator.ToWin32(m_HeaderBackColor));
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Trace.WriteLine(ex.ToString());
                }

                string rowColor = "";
                if (this.Style == DataWindowStyle.Grid || this.Style == DataWindowStyle.Label || this.Style == DataWindowStyle.Nup)
                {
                    rowColor = "DataWindow.Detail.Color=\"536870912~tif(getrow()=currentrow(),16506824, if(mod(getrow(),2)=1,16251133,16119280))\"";
                }
                else
                {
                    rowColor = "DataWindow.Detail.Color=\"536870912~t16119280\"";
                }

                try
                {
                    this.Modify(rowColor);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Trace.WriteLine(ex.ToString());
                }
            }
        }


        protected override void OnDataWindowCreated(DataWindowCreatedEventArgs e)
        {
            base.OnDataWindowCreated(e);
            InitUI();
        }

        protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
        {
            if (this.m_EnterToTab && msg.WParam.ToInt32() == (int)Keys.Enter)
            {
                SendKeys.Send("{Tab}");
                return true;
            }

            return base.ProcessCmdKey(ref msg, keyData);
        }

        #region Click
        protected override void OnClick(EventArgs e)
        {
            base.OnClick(e);

            #region 点击列头排序
            if (this.m_HeaderSort && this.Style == DataWindowStyle.Grid &&
                !string.IsNullOrEmpty(this.DataWindowObject))
            {
                GraphicObject graphicObject = this.ObjectUnderMouse.Gob;

                try
                {
                    if (graphicObject is GraphicObjectText && this.ObjectUnderMouse.Band.Type == BandType.Header && !graphicObject.Empty)
                    {
                        string sort = graphicObject.Name;
                        if (string.IsNullOrEmpty(sort))
                            return;

                        sort = sort.Substring(0, sort.Length - 2) + " " + m_SortType;
                        if (m_SortType == "A")
                            this.m_SortType = "D";
                        else
                            this.m_SortType = "A";

                        this.SetSort(sort);
                        this.Sort();
                        this.SelectRow(0, false);
                        if (this.RowCount > 0)
                        {
                            RowFocusChangedEventArgs ee = new RowFocusChangedEventArgs(this.CurrentRow);
                            this.OnRowFocusChanged(ee);
                        }
                    }
                }
                catch(Exception ex)
                {
                    MessageBox.Show("基类排序操作失败:"+ex.Message,"错误");
                }
            }
            #endregion

            if (this.DataWindowObject != "" && this.CurrentRow != this.ObjectUnderMouse.RowNumber && this.ObjectUnderMouse.RowNumber > 0)
            {
                this.SetRow(this.ObjectUnderMouse.RowNumber);
            }
        }
        #endregion

        protected override void OnRowFocusChanged(RowFocusChangedEventArgs e)
        {
            base.OnRowFocusChanged(e);
            this.Refresh();
            //if (m_SelectedRowHighLighted)
            //{
            //    this.SelectRow(0, false);
            //    if (e.RowNumber > 0)
            //    {
            //        this.SelectRow(e.RowNumber, true);
            //    }
            //}
        }

        public DataTable CovertToDataTable()
        {
            return DataControlHelper.CovertToDataTable(this);
        }

        public int FindRepeatValue(string expression, int exceptRow)
        {
            int findRow = this.FindRow(expression, 1, this.RowCount);
            if (exceptRow > 0 && findRow == exceptRow)
            {
                if (exceptRow < this.RowCount)
                    findRow = this.FindRow(expression, exceptRow + 1, this.RowCount);
                else
                    findRow = 0;
            }

            return findRow;
        }

        protected override void OnLostFocus(EventArgs e)
        {
            this.AcceptText();
            base.OnLostFocus(e);
        }

        #region 切换系统输入法
        /// <summary>
        /// 切换系统输入法
        /// </summary>
        /// <param name="hzSr">true 汉字输入 false 非汉字输入</param>
        public void SetIME(bool hzSr)
        {
            IntPtr hklCurrent;

            if (hzSr)
            {
                hklCurrent = Win32Api.GetKeyboardLayout(0);
                if (!Win32Api.ImmIsIME(hklCurrent))
                {
                    Win32Api.ImmSimulateHotKey(this.Handle, Win32Api.IME_THotKey_IME_NonIME_Toggle);
                }
            }
            else
            {
                hklCurrent = Win32Api.GetKeyboardLayout(0);
                if (Win32Api.ImmIsIME(hklCurrent))
                {
                    Win32Api.ImmSimulateHotKey(this.Handle, Win32Api.IME_THotKey_IME_NonIME_Toggle);
                }
            }
        }
        #endregion
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -