ホテル管理システム
ogi
yesterday 1a1c8e71fcd14858f595029f089b2d4a00202b32
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
using customTypes;
using HotelPms.Data.Common;
using HotelPms.Data.Common.Interface.Access;
using HotelPms.DataAccessGrpc.Client;
using HotelPms.Share.Util;
using HotelPms.Share.Windows.Component;
using HotelPms.Share.Windows.Util;
using HotelPms.WinForm.Common;
using HotelPms.WinForm.Common.Interface;
using HotelPms.WinForm.Common.Util;
using System.Data;
 
namespace HotelPms.WinForm.Master
{
    public partial class Demo : MasterBase, IMasterCtrl
    {
        #region  ★★★★★ Declartions ★★★★★
 
        private IDemo? demoAccess;
 
        #endregion
 
        #region  ★★★★★ Property ★★★★★
        #endregion
 
        #region  ★★★★★ Class Event ★★★★★
 
        public Demo(IDemo access)
        {
            InitializeComponent();
            demoAccess = access;
            MasterCtrl = this;
            dgvData.Visible = false;
        }
 
        private void Form_Load(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            MasterCtrl.ShowData();
            System.Diagnostics.Debug.WriteLine(dgvData.Rows.Count);
            if (dgvData.Rows.Count == 0)
            {
                SetNewMode();
            }
            dgvData.Visible = true;
            Cursor = Cursors.Default;
        }
 
        #endregion
 
        #region  ★★★★★ Control Event ★★★★★
        #endregion
 
        #region  ★★★★★ Private Function ★★★★★
        #endregion
 
        #region  ★★★★★ Public  Function ★★★★★
 
        public bool Delete()
        {
            int orgIndex = dgvData.CurrentRow.Index;
            int pID = CConvert.ToInt(GetCellValue("ID"));
            if (MessageBox.Show(string.Format(DelMsg + Environment.NewLine + "ID = {0}", pID),
                Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.No) { return false; }
 
 
            //排他チェック
            if (demoAccess.GetUpdateID(pID) != CConvert.ToInt(GetCellValue("UpdateID")))
            {
                if (MessageBox.Show(LockMsg, this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    MasterCtrl.ShowData(pID);
                    m_ValueChangeListener.SetUpdateFormMode(UpdateFormMode.Normal);
                }
                return false;
            }
 
            Data.DataResult dataResult = demoAccess.Remove($"ID = {pID}");
            if (dataResult.ErrNo != 0)
            {
                MessageBox.Show("削除に失敗しました。" + Environment.NewLine + $"{dataResult.ErrNo}.{dataResult.ErrData}", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
 
            ShowData(orgIndex < dgvData.RowCount ? orgIndex : dgvData.RowCount - 1);
            if (dgvData.Rows.Count == 0) { SetNewMode(); }
            return true;
        }
 
        public bool IsCorrectEtc(object sender, bool isCheckAll, bool isShowErrMsg)
        {
            if (sender.Equals(txtID) && m_ValueChangeListener.CurUpdateMode == UpdateFormMode.Inputting)
            {
                if (demoAccess.Exists(CConvert.ToInt(txtID.Text)))
                {
                    MessageBox.Show(ExistsMsg, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtID.Focus();
                    return false;
                }
            }
 
            return true;
        }
 
        public bool Save()
        {
            if (m_ValueChangeListener.CurUpdateMode != UpdateFormMode.Inputting && m_ValueChangeListener.CurUpdateMode != UpdateFormMode.Edit) { return true; }
 
            //ソートがあるため、index正しくない
            int id = (dgvData.CurrentRow == null) ? 0 : CConvert.ToInt(GetCellValue("ID"));
            bool isNew = false;
            HotelPms.Data.Master.Demo item = null;
            UpdateFormMode orgMode = m_ValueChangeListener.CurUpdateMode;
            if (orgMode == UpdateFormMode.Edit) 
            { 
                item = demoAccess.GetItem(CConvert.ToInt(txtID.Text)); 
                
                //排他チェック
                if(item.UpdateID != CConvert.ToInt(GetCellValue("UpdateID")))
                {
                    if(MessageBox.Show(LockMsg, this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        MasterCtrl.ShowData(id);
                        m_ValueChangeListener.SetUpdateFormMode(UpdateFormMode.Normal);
                    }
                    return false;
                }
            }
            if (item == null)
            {
                item = new HotelPms.Data.Master.Demo();
                isNew = true;
            }
            item.ID = CConvert.ToInt(txtID.Text);
            item.Name = txtName.Text;
            item.FInt = CConvert.ToInt(txtFInt.Text);
            item.FTinyInt = CConvert.ToInt(txtFTinyInt.Text);
            item.FSmallInt = CConvert.ToInt(txtFSmallInt.Text);
            item.FBit = CConvert.ToBool(txtFBit.Text);
            item.FFloat = CConvert.ToFloat(txtFFloat.Text);
            item.FDecimal = CConvert.ToDecimal(txtFDecimal.Text);
            item.FDate = new Date(CConvert.ToDateInt(txtFDate.Text));
            item.UpdateDate = CConvert.ToTimestamp(CConvert.ToDateTime(txtUpdateDate.Text));
            item.UpdateID++;
            Data.DataResult dataResult = isNew ? demoAccess.Add(item) : demoAccess.Update(item);
 
            MasterCtrl.ShowData(id);
            if (orgMode == UpdateFormMode.Inputting) { SetNewMode(); }
            m_ValueChangeListener.SetUpdateFormMode(orgMode == UpdateFormMode.Edit ? UpdateFormMode.Normal : UpdateFormMode.New);
            return dataResult.ErrNo == 0;
        }
 
        public void SetDispName(CTextBox sender)
        {
            if (sender.Equals(txtFBit))
            {
                sender.MstNameCtrl.Text = CConvert.GetEnumDescription<EVisible>(CConvert.ToInt(sender.Text));
            }
        }
 
        public void ShowData()
        {
            ShowData(0);
        }
 
        private int FindRowIndex(int id)
        {
            for (int i = 0; i < m_Data.Rows.Count; i++)
            {
                if (id == CConvert.ToInt(m_Data.Rows[i]["ID"])) { return i; }
            }
            return 0;
        }
 
        public void ShowData(int id)
        {
            try
            {
                m_DisableSelectionChanged = true;
                DataTable orgData = m_Data;
                string where = string.Empty;
                if (txtSearchKey.Text.Trim().Length > 0)
                {
                    where += string.Format(" A.Name LIKE '%{0}%' ", txtSearchKey.Text);
                }
 
                m_Data = demoAccess.GetMasterGridData(where);  //同期実行
                dgvData.DataSource = m_Data;
                SetGridColNameDict();
                SetGridStyle();
                if (dgvData.Rows.Count > 0)
                {
                    SetCellFocus(FindRowIndex(id), 0, true);
                    ShowDetail();
                }
                if (orgData != null) { orgData.Dispose(); orgData = null; }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                m_DisableSelectionChanged = false;
            }
        }
 
        private void SetGridStyle()
        {
            DataGridViewColumn col = null;
            col = dgvData.Columns["ID"];
            col.HeaderText = "ID";
            col.Width = 100;
            col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            col = dgvData.Columns["Name"];
            col.HeaderText = "名称";
            col.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
            col.Width = 100;
            col = dgvData.Columns["FInt"];
            col.HeaderText = "FInt";
            col.Width = 100;
            col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
            col = dgvData.Columns["FTinyInt"];
            col.HeaderText = "FTinyInt";
            col.Width = 100;
            col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            col = dgvData.Columns["FSmallInt"];
            col.HeaderText = "FSmallInt";
            col.Width = 100;
            col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
            col = dgvData.Columns["FFloat"];
            col.HeaderText = "FFloat";
            col.Width = 100;
            col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
            col = dgvData.Columns["FBit"];
            col.HeaderText = "FBit";
            col.Width = 100;
            col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
            col = dgvData.Columns["FDecimal"];
            col.HeaderText = "FDecimal";
            col.Width = 100;
            col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
            col = dgvData.Columns["FDate"];
            col.HeaderText = "FDate";
            col.Width = 100;
            col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
 
            col = dgvData.Columns["UpdateDate"];
            col.Visible = false;
            col = dgvData.Columns["UpdateID"];
            col.Visible = false;
        }
 
        public void ShowDetail()
        {
            if (dgvData.CurrentRow == null) { return; }
            tbArray.DisbleValidating = true;
            int index = dgvData.CurrentRow.Index;
            txtName.Text = CConvert.ToString(GetCellValue("Name"));
            this.ActiveControl = txtName;
            tbArray.PerformEnter(txtName, null);
            txtID.Enabled = false;
            txtID.Text = GeneralSub.ToFormText(CConvert.ToInt(GetCellValue("ID")));
            txtFInt.Text = GeneralSub.ToFormText(CConvert.ToInt(GetCellValue("FInt")));
            txtFTinyInt.Text = GeneralSub.ToFormText(CConvert.ToInt(GetCellValue("FTinyInt")));
            txtFSmallInt.Text = GeneralSub.ToFormText(CConvert.ToInt(GetCellValue("FSmallInt")));
            txtFFloat.Text = CConvert.ToFloat(GetCellValue("FFloat")).ToString();
            txtFBit.Text = CConvert.ToBool(GetCellValue("FBit")) ? "1" : "0";
            SetDispName(txtFBit);
            txtFDecimal.Text = CConvert.ToDecimal(GetCellValue("FDecimal")).ToString();
            txtFDate.Text = CConvert.ToDateString(GetCellValue("FDate"));
            txtUpdateDate.Text = GetCellValue("UpdateDate").ToString();
 
            m_ValueChangeListener.SetUpdateFormMode(UpdateFormMode.Normal);
            tbArray.DisbleValidating = false;
        }
 
        public void ShowList(CTextBox sender)
        {
            DataTable data = null;
 
            if (sender.Equals(txtFBit)) { data = CConvert.GetEnumTypeList<EVisible>(); }
 
            if (data == null) { return; }
            string ret = HotelPms.Share.Windows.Tool.DataSelector.Execute(sender, data, new Size(250, 120), string.Empty, string.Empty, null, HotelPms.Share.Windows.Tool.DataSelector.Style.HideBottom);
            if (ret.Length == 0) { return; }
            sender.Text = ret;
            tbArray.PerformKeyDown(sender, new KeyEventArgs(Keys.Enter));
        }
 
 
        #endregion
    }
}