From 1a1c8e71fcd14858f595029f089b2d4a00202b32 Mon Sep 17 00:00:00 2001
From: ogi <Administrator@S-OGI-PC>
Date: Fri, 05 Dec 2025 09:24:16 +0900
Subject: [PATCH] プロジェクトファイルを追加。
---
HotelPms.Share.Windows/Tool/MstList.cs | 664 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 664 insertions(+), 0 deletions(-)
diff --git a/HotelPms.Share.Windows/Tool/MstList.cs b/HotelPms.Share.Windows/Tool/MstList.cs
new file mode 100644
index 0000000..7c85856
--- /dev/null
+++ b/HotelPms.Share.Windows/Tool/MstList.cs
@@ -0,0 +1,664 @@
+using HotelPms.Share.Data;
+using HotelPms.Share.Util;
+using HotelPms.Share.Windows.Util;
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Diagnostics;
+using System.Drawing;
+using System.Windows.Forms;
+
+
+namespace HotelPms.Share.Windows.Tool
+{
+ public partial class MstList : Form
+ {
+ /// ****************************** Description *******************************
+ /// ���V�X�e������
+ /// �@�\��Z���^�[�Ǘ��V�X�e��
+ /// ���T�v
+ /// �@�ꗗ�I�����
+ /// ������
+ /// �@20090126 vic �V�K�쐬
+ /// ****************************** Declarations ******************************
+
+ #region �����������@Declartions�@����������
+
+ [Flags]
+ public enum Style : int
+ {
+ None = 0x1,
+ HideBottom = 0x2,
+ HideReturnField = 0x4,
+ HideGridHeader = 0x8,
+ }
+
+
+ private bool isReturnRow = false;
+
+ public bool IsReturnRow
+ {
+ set { isReturnRow = value; }
+ }
+
+ private DataGridViewRow m_CurrentRow = null;
+
+
+ public object SelecetdItem
+ {
+ get
+ {
+ return m_CurrentRow;
+ }
+ }
+
+
+ /// <summary>
+ /// �������
+ /// </summary>
+ public enum SearchType
+ {
+ Custom = 0, //Sql�������[�U�[����w�肷��
+ DataTable, //.ShowDataTable��DataTable���w�肷��
+ }
+
+ private DataView DtView = new DataView();
+
+ // ���ʕϐ�
+ private int intReturnField_IndexNo; // ReturnField��Index
+ private string strSqlSelected; // Sql���̑I���i���ۂɎ��s����SQL��)
+ private string strSql = string.Empty;
+ private string strAddCondition = string.Empty;
+ private string strReturnField = "�R�[�h";
+ private string strSearchField = "����";
+ private string strReturnValue = string.Empty;
+ private List<int> colWidth = new List<int>();
+ private bool strVisibleBottom = true;
+ private bool strVisibleReturnField = true;
+ private bool visibleGridHeader = true;
+ private Style style = Style.None;
+
+ #endregion
+
+ #region �����������@Property�@����������
+
+ /// <summary>
+ /// OwnerControl
+ /// </summary>
+ public DBConnectItem DBConnectData { get; set; }
+
+ /// <summary>
+ /// OwnerControl
+ /// </summary>
+ public Control OwnerControl { get; set; }
+
+ /// <summary>
+ /// SelectType
+ /// </summary>
+ public SearchType SelectType { get; set; }
+
+ /// <summary>
+ /// ShowDataTable(�\������f�[�^�e�[�u�����w�肷��A�������A�f�t�H���g�̏ꍇ�R�[�h�A���̃J�������K�v)
+ /// </summary>
+ public DataTable DtTable { get; set; }
+
+ /// <summary>
+ /// Sql
+ /// </summary>
+ public string Sql
+ {
+ set { strSql = value; }
+ get { return strSql; }
+ }
+
+ /// <summary>
+ /// AddCondition
+ /// </summary>
+ public string AddCondition
+ {
+ set { strAddCondition = value; }
+ get { return strAddCondition; }
+ }
+
+ /// <summary>
+ /// ReturnField(�I�������Ƃ��ɕԂ��t�B�[���h��)
+ /// </summary>
+ public string ReturnField
+ {
+ set { strReturnField = value; }
+ get { return strReturnField; }
+ }
+
+ /// <summary>
+ /// SearchField
+ /// </summary>
+ public string SearchField
+ {
+ set { strSearchField = value; }
+ get { return strSearchField; }
+ }
+
+ public Style CurStyle
+ {
+ set { style = value; }
+ get { return style; }
+ }
+
+ /// <summary>
+ /// VisibleBottom
+ /// </summary>
+ public List<int> ColWidth
+ {
+ set { colWidth = value; }
+ get { return colWidth; }
+ }
+
+ /// <summary>
+ /// ReturnValue(�I����Ɏ擾�ł���l)
+ /// </summary>
+ public string ReturnValue
+ {
+ get { return strReturnValue; }
+ }
+
+ #endregion
+
+ #region �����������@Class Event�@����������
+
+ /// <summary>
+ /// MstList
+ /// </summary>
+ public MstList()
+ {
+ InitializeComponent();
+ }
+
+ private void SetLocation()
+ {
+ DataGridView grid = OwnerControl as DataGridView;
+ Form ownerForm = GeneralSub.GetOwnerForm(grid);
+ //�\���ʒu����
+ System.Drawing.Point location = new System.Drawing.Point(0, 0);
+ System.Drawing.Point baseLocation = GeneralSub.GetPopUpLocationEx(ownerForm, grid);
+ location.X = baseLocation.X;
+ location.Y = baseLocation.Y;
+ if (location.X + this.Width > Screen.PrimaryScreen.Bounds.Width)
+ {
+ location.X = baseLocation.X - (location.X + this.Width - Screen.PrimaryScreen.Bounds.Width + 2);
+ }
+ if (location.Y + this.Height > Screen.PrimaryScreen.Bounds.Height)
+ {
+ location.Y = baseLocation.Y - grid.Rows[grid.CurrentCell.RowIndex].Height - this.Height;
+ }
+ this.SetBounds(location.X, location.Y, this.Width, this.Height);
+ }
+
+ /// <summary>
+ /// MstList_Load
+ /// </summary>
+ private void MstList_Load(object sender, EventArgs e)
+ {
+ //�\�����C�A�E�g
+ if (OwnerControl != null)
+ {
+ if (OwnerControl is DataGridView)
+ {
+ SetLocation();
+ }
+ else
+ {
+ this.StartPosition = FormStartPosition.Manual;
+ Point p = this.OwnerControl.PointToScreen(new Point(0, 0));
+
+ int x = p.X;
+ int y = p.Y + OwnerControl.Height;
+
+ if (p.Y + OwnerControl.Height + this.Height > Screen.PrimaryScreen.Bounds.Height)
+ {
+ y = p.Y - this.Height;
+ }
+
+ if (p.X + this.Width > Screen.PrimaryScreen.Bounds.Width)
+ {
+ x = Screen.PrimaryScreen.Bounds.Width - this.Width;
+ }
+
+ this.Location = new Point(x, y);
+ }
+ }
+ //if (msSqlNet == null) { msSqlNet = EnvironmentSetting.DbAccess; }
+
+ if ((style & Style.HideBottom) == Style.HideBottom) { strVisibleBottom = false; }
+ if ((style & Style.HideGridHeader) == Style.HideGridHeader) { visibleGridHeader = false; }
+ if ((style & Style.HideReturnField) == Style.HideReturnField) { strVisibleReturnField = false; }
+
+ //DefaultDataTable�ݒ�
+ SetDefaultHeader();
+
+ //Sql���̑I��
+ GetData();
+ DtTable.TableName = "SelectTable";
+
+ // DataView��DataSet�̃e�[�u����A������
+ DtView.Table = DtTable;
+ DtView.RowFilter = "";
+
+ // �f�[�^��\��
+ this.DataGridView1.DataSource = DtView;
+
+ //�����̌����L�[�ƕ���{�^����\�����邩(�����l:True(�\��))
+ if (this.strVisibleBottom == false)
+ {
+ this.panel2.Visible = false; // �p�l���P�ʂŔ�\����
+ }
+
+ // DataGridView1�̐ݒ�
+ //this.DataGridView1.RowHeadersVisible = false; //�s�w�b�_�[���\��
+ //this.DataGridView1.AutoResizeColumns( "AllCells", true); // ����������
+
+
+ //ReturnField(�߂�l��Ԃ����ڗ�)��IndexNo���擾����B
+ intReturnField_IndexNo = -1;
+
+ if (strReturnField == string.Empty)
+ {
+ intReturnField_IndexNo = 0;
+ }
+ else
+ {
+ for (int i = 0; i < this.DataGridView1.Columns.Count; i++)
+ {
+ if (this.DataGridView1.Columns[i].HeaderText.ToString() == strReturnField.ToString())
+ {
+ intReturnField_IndexNo = i;
+ }
+ }
+ }
+
+ if (intReturnField_IndexNo == -1)
+ {
+ intReturnField_IndexNo = 0;
+ strReturnField = string.Empty;
+ strSearchField = string.Empty;
+ }
+
+ //ReturnField(�߂�l��Ԃ����ڗ�)���擾����B
+ if (this.strReturnField.Length == 0)
+ {
+ this.strReturnField = this.DtView.Table.Columns[intReturnField_IndexNo].ColumnName.ToString();
+ }
+
+ //SearchField(�����L�[�Ɋ֘A�����鍀�ڗ�)���擾����B
+ if (this.strSearchField.Length == 0)
+ {
+ this.strSearchField = this.DtView.Table.Columns[intReturnField_IndexNo + 1].ColumnName.ToString();
+ }
+
+ //VisibleReturnField = false�̏ꍇ�AReturnField���\���Ƃ���B
+ if ((strVisibleReturnField == false) && (intReturnField_IndexNo > -1))
+ {
+ this.DataGridView1.Columns[intReturnField_IndexNo].Visible = false;
+ }
+
+ if (DtTable.Rows.Count == 0)
+ {
+ MessageBox.Show("�Y���f�[�^������܂���B");
+ this.Close();
+ return;
+ }
+
+ this.DataGridView1.ColumnHeadersVisible = visibleGridHeader;
+
+ //�G���[����
+ if (!ValidateInput())
+ {
+ Debug.Assert(false, "�J���pError", "Select���s�K�AsearchField�����l�A������ȊO");
+
+ }
+
+ DataGridView1.EnableHeadersVisualStyles = false;
+ DataGridView1.ColumnHeadersHeight = 25;
+ foreach (DataGridViewColumn col in DataGridView1.Columns)
+ {
+ col.HeaderCell.Style.BackColor = System.Drawing.Color.FromArgb(50, 50, 100);
+ col.HeaderCell.Style.ForeColor = Color.White;
+ }
+
+ DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;//COMMENT:20080918 �ї� No1060
+ DataGridView1.AllowUserToResizeColumns = true;
+ if (colWidth == null || colWidth.Count == 0)
+ {
+ DataGridView1.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ return;
+ }
+ for (int i = 0; i < colWidth.Count; i++)
+ {
+ DataGridView1.Columns[i].Width = colWidth[i];
+ }
+ }
+
+ #region Esc�L�[�@����
+
+ protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
+ {
+ if (keyData == Keys.Escape)
+ {
+ //�e�X�g�p���b�Z�[�W
+ //MessageBox.Show("����{�^���N���b�N");
+
+ //�߂�l�Ƃ��Đݒ�(Empty�l)
+ strReturnValue = string.Empty;
+
+ //��ʂ����
+ this.Close();
+ }
+
+ return base.ProcessCmdKey(ref msg, keyData);
+ }
+
+ #endregion
+
+ #endregion
+
+ #region �����������@Control Event�@����������
+
+ /// <summary>
+ /// ����{�^���@�N���b�N�C�x���g
+ /// </summary>
+ private void btnClose_Click(object sender, EventArgs e)
+ {
+ //�e�X�g�p���b�Z�[�W
+ //MessageBox.Show("����{�^���N���b�N");
+
+ //�߂�l�Ƃ��Đݒ�(Empty�l)
+ strReturnValue = string.Empty;
+
+ //��ʂ����
+ this.Close();
+
+ }
+
+ /// <summary>
+ /// DataGridView1_CellMouseDoubleClick
+ /// </summary>
+ private void DataGridView1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
+ {
+ if (DataGridView1.RowCount > 0)
+ {
+
+ //�e�X�g�p���b�Z�[�W
+ //int iCol = intReturnField_IndexNo; //��(ReturnField�̗�Œ�)
+ //int iRow = this.DataGridView1.CurrentCell.RowIndex; //�s(�I���s)
+ //MessageBox.Show("��" + iCol.ToString() + ":�s" + iRow.ToString() + "��" + CellValue.ToString.ToString() + "���I������Ă��܂�");
+
+
+ // �A�N�e�B�u�ȃZ���̒l��߂�l�Ƃ��Đݒ�
+ if (!isReturnRow)
+ {
+ strReturnValue = this.DataGridView1[this.strReturnField.ToString(), this.DataGridView1.CurrentCell.RowIndex].Value.ToString(); //Cell�l
+ }
+ else
+ {
+ m_CurrentRow = this.DataGridView1.CurrentRow;
+ }
+
+ //��ʂ����
+ this.Close();
+
+ }
+ }
+
+ /// <summary>
+ /// DataGridView1_KeyDown
+ /// </summary>
+ private void DataGridView1_KeyDown(object sender, KeyEventArgs e)
+ {
+ if (e.KeyCode == Keys.Enter)
+ {
+ if (DataGridView1.RowCount > 0)
+ {
+
+ if (!isReturnRow)
+ {
+ strReturnValue = this.DataGridView1[this.strReturnField.ToString(), this.DataGridView1.CurrentCell.RowIndex].Value.ToString(); //Cell�l
+ }
+ else
+ {
+ m_CurrentRow = this.DataGridView1.CurrentRow;
+ }
+ //��ʂ����
+ this.Close();
+
+ }
+ }
+ else if (e.KeyCode == Keys.Tab)
+ {
+ e.Handled = true;
+
+ if (e.Shift == true)
+ {
+ this.btnClose.Focus();
+ }
+ else
+ {
+ this.txtSearch.Focus();
+ }
+ }
+ }
+
+ /// <summary>
+ /// txtSearch_KeyDown
+ /// </summary>
+ private void txtSearch_KeyDown(object sender, KeyEventArgs e)
+ {
+
+ //string strFilterSql;
+
+ //Enter�L�[���͂̏ꍇ
+ if (e.KeyCode == Keys.Enter)
+ {
+ //DataGridView1�փt�H�[�J�X�ړ�
+ this.DataGridView1.Focus();
+ }
+
+ }
+
+ /// <summary>
+ /// txtSearch_KeyDown
+ /// </summary>
+ private void txtSearch_TextChanged(object sender, EventArgs e)
+ {
+
+ string strFilterSql;
+
+ // �t�B���^�[������
+ if ((this.txtSearch.Text.ToString() == string.Empty) || (this.strSearchField.ToString() == string.Empty))
+ {
+ //�t�B���^��������(�S��\��)
+ strFilterSql = string.Empty;
+ }
+ else
+ {
+ //�t�B���^�����w��
+ strFilterSql = this.strSearchField.ToString() + " LIKE '%" + this.txtSearch.Text.ToString() + "%'";
+ }
+
+ //�e�X�g�p���b�Z�[�W
+ //MessageBox.Show("�t�B���^�[�F" + strFilterSql.ToString());
+
+ // �t�B���^�[�������w�肵��DataView�Ɋi�[
+ DtView.RowFilter = strFilterSql.ToString();
+
+ // �f�[�^��\��
+ this.DataGridView1.DataSource = DtView;
+
+ }
+
+ private void txtSearch_Enter(object sender, EventArgs e)
+ {
+ txtSearch.BackColor = Color.LightSteelBlue;
+ }
+
+ private void txtSearch_Leave(object sender, EventArgs e)
+ {
+ txtSearch.BackColor = Color.White;
+ }
+
+ #endregion
+
+ #region �����������@Private Function�@����������
+
+ /// <summary>
+ /// Default�̐ݒ�
+ /// </summary>
+ private void SetDefaultHeader()
+ {
+ if (SelectType != SearchType.DataTable)
+ {
+ DtTable.Columns.AddRange(new DataColumn[] { new DataColumn("�R�[�h"), new DataColumn("����") });
+ }
+ }
+
+ /// <summary>
+ /// ValidateInput
+ /// </summary>
+ private bool ValidateInput()
+ {
+ if (isReturnRow) { return true; }
+ if (DtTable.Rows.Count == 0)
+ return false;
+ if (
+ DtTable.Columns[this.strSearchField].DataType != typeof(string)
+ // && DtSet.Tables[0].Columns[this.strSearchField].DataType != typeof(int)
+ )
+ return false;
+ return true;
+ }
+
+ /// <summary>
+ /// SelectSql
+ /// </summary>
+ private void GetData()
+ {
+ strSqlSelected = string.Empty;
+
+ //Sql���̑I��
+ if (SelectType.Equals(SearchType.Custom))
+ { //�J�X�^���ݒ�
+
+ strSqlSelected = this.strSql.ToString() + " " + this.strAddCondition.ToString();
+ // �f�[�^���擾
+ using (MsSqlNet msSqlNet = new MsSqlNet(DBConnectData.HostName, DBConnectData.UserID, DBConnectData.Password, DBConnectData.DBName))
+ {
+ DtTable = msSqlNet.GetDataTable(this.strSqlSelected.ToString());
+ }
+ }
+ }
+
+
+ #region ------------ �Œ�f�[�^�̃e�[�u���f�[�^ -------------------
+
+ /// <summary>
+ /// Enum�ɂ��f�[�^�e�[�u�������
+ /// </summary>
+ public DataTable GetTypeData(Type enumType)
+ {
+ DataTable dt = new DataTable();
+ dt.Columns.AddRange(new DataColumn[] { new DataColumn("�R�[�h"), new DataColumn("����") });
+ DataRow row = null;
+ foreach (object item in Enum.GetValues(enumType))
+ {
+ row = dt.NewRow();
+ dt.Rows.Add(row);
+ row["�R�[�h"] = ((int)item).ToString();
+ row["����"] = item.ToString();
+ }
+ return dt;
+ }
+
+ #endregion
+
+ #endregion
+
+ #region �����������@Public Function�@����������
+
+ public static string GetTypeName(Type enumType,int code)
+ {
+ try
+ {
+ return CConvert.ToString(Enum.GetName(enumType, code));
+ }
+ catch
+ {
+ return string.Empty;
+ }
+ }
+
+ public static string ExecuteSql(Control owner, DBConnectItem dbItem, string sql)
+ {
+ return Execute(SearchType.Custom, owner, dbItem, Style.None, Size.Empty, string.Empty, string.Empty, string.Empty, null, sql, null);
+ }
+
+ public static string ExecuteTable(Control owner, DataTable data)
+ {
+ return Execute(SearchType.DataTable, owner, null, Style.None, Size.Empty, string.Empty, string.Empty, string.Empty, null, string.Empty, data);
+ }
+
+ /// <summary>
+ /// �ꗗ�\��
+ /// </summary>
+ /// <returns></returns>
+ public static string Execute(SearchType type, Control owner, DBConnectItem dbItem)
+ {
+ return Execute(type, owner, dbItem, Style.None, Size.Empty, string.Empty, string.Empty, string.Empty, null, string.Empty, null);
+ }
+
+ public static string Execute(SearchType type, Control owner, DBConnectItem dbItem, Style style)
+ {
+ return Execute(type, owner, dbItem, style, Size.Empty, string.Empty, string.Empty, string.Empty, null, string.Empty, null);
+ }
+
+ public static string Execute(SearchType type, Control owner, DBConnectItem dbItem, Style style, Size size)
+ {
+ return Execute(type, owner, dbItem, style, size, string.Empty, string.Empty, string.Empty, null, string.Empty, null);
+ }
+
+ public static string Execute(SearchType type, Control owner, DBConnectItem dbItem, Style style, Size size, string addCondition)
+ {
+ return Execute(type, owner, dbItem, style, size, addCondition, string.Empty, string.Empty, null, string.Empty, null);
+ }
+
+ public static string Execute(SearchType type, Control owner, DBConnectItem dbItem, Style style, Size size, string addCondition,
+ string returnField, string searchField, List<int> colWidth)
+ {
+ return Execute(type, owner, dbItem, style, size, addCondition, returnField, searchField, colWidth, string.Empty, null);
+ }
+
+ public static string Execute(SearchType type, Control owner, DBConnectItem dbItem, Style style, Size size, string addCondition,
+ string returnField, string searchField, List<int> colWidth, string sql, DataTable data)
+ {
+ string result = string.Empty;
+ MstList mstList = new MstList();
+ mstList.SelectType = type;
+ mstList.OwnerControl = owner;
+ mstList.DBConnectData = dbItem;
+ mstList.CurStyle = style;
+ if (!size.Equals(Size.Empty)) { mstList.Size = size; }
+ if (returnField.Length > 0) { mstList.ReturnField = returnField; }
+ if (searchField.Length > 0) { mstList.SearchField = searchField; }
+ if (colWidth != null) { mstList.ColWidth = colWidth; }
+ mstList.AddCondition = addCondition;
+ mstList.Sql = sql;
+ mstList.DtTable = data;
+ mstList.ShowDialog();
+ if (mstList.ReturnValue.Length > 0)
+ {
+ result = mstList.ReturnValue;
+ }
+ mstList.Dispose();
+ return result;
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
--
Gitblit v1.10.0