ホテル管理システム
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
using System;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.IO;
using HotelPms.Share.IO;
 
namespace HotelPms.Share.Windows.Tool
{
    public partial class DBLogin : Form
    {
        private string listFile = @"\LoginInfo.vic";
 
        private string userID = string.Empty;
        private string passWord = string.Empty;
        private string dataSource = string.Empty;
        private string catalog = string.Empty;
 
        /// <summary>ƒ†[ƒU[</summary>
        public string UseID
        {
            get { return userID; }
            set { userID = value; }
        }
 
        /// <summary>ƒpƒXƒ[ƒh</summary>
        public string PassWord
        {
            get { return passWord; }
            set { passWord = value; }
        }
 
        /// <summary>ƒf[ƒ^ƒx[ƒXŠÝ‚̃pƒ\ƒRƒ“–¼</summary>
        public string DataSource
        {
            get { return dataSource; }
            set { dataSource = value; }
        }
 
        /// <summary>ƒf[ƒ^ƒx[ƒX–¼</summary>
        public string Catalog
        {
            get { return catalog; }
            set { catalog = value; }
        }
 
        public DBLogin()
        {
            //SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
            //System.Data.DataTable table = instance.GetDataSources();
 
            InitializeComponent();
 
            // Display the contents of the table.
            //DisplayData(table);
        }
 
        private void Login_Shown(object sender, EventArgs e)
        {
            if (this.cmbSrcDataSource.Items.Count > 0)
            {
                this.cmbSrcDataSource.SelectedIndex = 0;
            }
 
            if (!File.Exists(Application.StartupPath + listFile)) { return; }
 
            listBox1.Items.Clear();
            using (StreamReader sr = new StreamReader(Application.StartupPath + listFile, Encoding.Default))
            {
                string line = string.Empty;
 
                while ((line = sr.ReadLine()) != null)
                {
                    listBox1.Items.Add(line);
                }
                sr.Close();
            }
 
        }
 
        private void DisplayData(System.Data.DataTable table)
        {
            foreach (System.Data.DataRow row in table.Rows)
            {
                this.cmbSrcDataSource.Items.Add(row["ServerName"].ToString());
            }
        }
 
        private void Save()
        {
            string line = cmbSrcDataSource.Text + "," + txtDstUser.Text + "," + txtDstPassword.Text + "," + txtDstCatalog.Text;
            if (!listBox1.Items.Contains(line))
            {
                listBox1.Items.Add(line);
            }
 
            StringBuilder fileInfo = new StringBuilder();
            foreach (string item in listBox1.Items)
            {
                fileInfo.Append(item + Environment.NewLine);
            }
            FileOperation.Delete(Application.StartupPath + listFile);
            File.WriteAllText(Application.StartupPath + listFile, fileInfo.ToString(), Encoding.Default);
        }
 
        private void btnLogin_Click(object sender, EventArgs e)
        {
            userID = txtDstUser.Text;
            passWord = txtDstPassword.Text;
            dataSource = cmbSrcDataSource.Text;
            catalog = txtDstCatalog.Text;
 
            Save();
 
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
 
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
 
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if(listBox1.SelectedIndex == -1) { return;}
            string[] items = listBox1.Items[listBox1.SelectedIndex].ToString().Split(new char[]{','});
 
            cmbSrcDataSource.Text = items[0];
            txtDstUser.Text = items[1];
            txtDstPassword.Text = items[2];
            txtDstCatalog.Text = items[3];
        }
 
        private void cmbSrcDataSource_DropDown(object sender, EventArgs e)
        {
            ComboBox obj = sender as ComboBox;
            if (obj.Items.Count == 0)
            {
                this.Cursor = System.Windows.Forms.Cursors.AppStarting;
 
                //SqlDataSourceEnumerator sqlServerList = System.Data.Sql.SqlDataSourceEnumerator.Instance;
                //using (DataTable dtServerList = sqlServerList.GetDataSources())
                //{
                //    foreach (DataRow dRow in dtServerList.Rows)
                //    {
                //        obj.Items.Add(dRow["ServerName"].ToString());
                //    }
                //}
                this.Cursor = System.Windows.Forms.Cursors.Default;
            }
        }
    }
}