テストで作ってみたが方向性変更のため未使用。複数のPCからバーコードを使い製作時間(工数)を登録するプログラム。
今後、時間のあるとき稼働時間算出の設定について変更できるようにしようかなと。
MySQLが必要なので、XAMPPを使うのが一番簡単で、XAMPPのシェルからMySQLにログインしたら、以下をコピペで実行。
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 |
CREATE DATABASE man_hours CHARSET=sjis; USE man_hours; CREATE TABLE items ( items_id int unsigned NOT NULL AUTO_INCREMENT, orders_id int DEFAULT NULL, suffix_no int DEFAULT NULL, PRIMARY KEY (items_id) ) DEFAULT CHARSET=sjis; CREATE TABLE orders ( orders_id int unsigned NOT NULL AUTO_INCREMENT, customer varchar(100) DEFAULT NULL, model varchar(100) DEFAULT NULL, serial_no varchar(100) DEFAULT NULL, quantity smallint unsigned DEFAULT NULL, notes varchar(100) DEFAULT NULL, visible varchar(2) DEFAULT NULL, PRIMARY KEY (orders_id) ) DEFAULT CHARSET=sjis; CREATE TABLE tasks_e ( tasks_id int unsigned NOT NULL AUTO_INCREMENT, items_id int DEFAULT NULL, workers_id int DEFAULT NULL, end_dt datetime DEFAULT NULL, PRIMARY KEY (tasks_id), UNIQUE KEY (items_id,workers_id) ) DEFAULT CHARSET=sjis; CREATE TABLE tasks_p ( tasks_id int unsigned NOT NULL AUTO_INCREMENT, items_id int DEFAULT NULL, workers_id int DEFAULT NULL, adjust varchar(10) DEFAULT NULL, PRIMARY KEY (tasks_id), UNIQUE KEY (items_id,workers_id) ) DEFAULT CHARSET=sjis; CREATE TABLE tasks_s ( tasks_id int unsigned NOT NULL AUTO_INCREMENT, items_id int DEFAULT NULL, workers_id int DEFAULT NULL, start_dt datetime DEFAULT NULL, PRIMARY KEY (tasks_id), UNIQUE KEY (items_id,workers_id) ) DEFAULT CHARSET=sjis; CREATE TABLE workers ( workers_id int unsigned NOT NULL AUTO_INCREMENT, worker_name varchar(100) DEFAULT NULL, work_type varchar(100) DEFAULT NULL, PRIMARY KEY (workers_id) ) DEFAULT CHARSET=sjis; |
起動後以下の画面が表示されるので、接続先はIPアドレス、DB名はman_hours、ユーザー、パスワードはMySQL作成時に指定したユーザー、パスワード。
Form1.cs
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 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace 製品工数管理 { public partial class Form1 : Form { public Form1() { Form9 f = new Form9(); f.ShowDialog(); Db.DbHost = f.DbHost; Db.DbName = f.DbName; Db.DbUser = f.DbUser; Db.DbPass = f.DbPass; InitializeComponent(); ImeMode = ImeMode.Off; Db d = new Db(); if (!d.DbState) { MessageBox.Show(d.DbStateMessage); foreach (Control c in Controls) { c.Enabled = false; } return; } } private void button1_Click(object sender, EventArgs e) { Form2 f = new Form2(); f.ShowDialog(); } private void button3_Click(object sender, EventArgs e) { Form3 f = new Form3(); f.ShowDialog(); } private void button2_Click(object sender, EventArgs e) { Form6 f = new Form6(); f.ShowDialog(); } private void button4_Click(object sender, EventArgs e) { Form7 f = new Form7(); f.ShowDialog(); } } } |
Form2.cs
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 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using ZXing; namespace 製品工数管理 { public partial class Form2 : Form { string default_query = "select orders_id,customer,model,serial_no,quantity,notes,visible,'表示' from orders where visible = '未'"; public Form2() { InitializeComponent(); ImeMode = ImeMode.Off; dataGridView1.AllowUserToAddRows = false; dataGridView1.ReadOnly = true; dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; dataGridView1.ColumnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.False; dataGridView1.DefaultCellStyle.Font = new Font("Meiryo UI", 11); Db d = new Db(); if (!d.DbState) { MessageBox.Show(d.DbStateMessage); return; } foreach(string s in d.LoadCustomer()) { comboBox2.Items.Add(s); } foreach (string s in d.LoadModel()) { comboBox3.Items.Add(s); } d.ExecuteReader(default_query, "", dataGridView1); } public void CreateBarcode(string code) { BarcodeWriter br = new BarcodeWriter(); br.Format = BarcodeFormat.CODE_128; br.Options.Height = 79; br.Options.Width = 151; br.Options.Margin = 10; br.Options.PureBarcode = false; Bitmap b = br.Write(code); pictureBox1.BackgroundImage = b; } private Boolean CheckTextBox() { if (comboBox2.Text == "" || comboBox3.Text == "" || textBox3.Text == "" || textBox4.Text == "") { MessageBox.Show("備考以外は入力必須です。"); return false; } try { int.Parse(textBox4.Text); } catch { MessageBox.Show("数量が正しくありません。"); return false; } comboBox2.Text = comboBox2.Text.Trim(); comboBox3.Text = comboBox3.Text.Trim(); textBox3.Text = textBox3.Text.Trim(); textBox6.Text = textBox6.Text.Trim(); comboBox2.Text = comboBox2.Text.Replace("\'", "’"); comboBox3.Text = comboBox3.Text.Replace("\'", "’"); textBox3.Text = textBox3.Text.Replace("\'", "’"); textBox6.Text = textBox6.Text.Replace("\'", "’"); comboBox2.Text = comboBox2.Text.Replace("\"", "”"); comboBox3.Text = comboBox3.Text.Replace("\"", "”"); textBox3.Text = textBox3.Text.Replace("\"", "”"); textBox6.Text = textBox6.Text.Replace("\"", "”"); return true; } private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { int r = e.RowIndex; int c = e.ColumnIndex; if (r == -1 || c == -1) return; textBox5.Text = dataGridView1.Rows[r].Cells[0].Value.ToString(); comboBox2.Text = dataGridView1.Rows[r].Cells[1].Value.ToString(); comboBox3.Text = dataGridView1.Rows[r].Cells[2].Value.ToString(); textBox3.Text = dataGridView1.Rows[r].Cells[3].Value.ToString(); textBox4.Text = dataGridView1.Rows[r].Cells[4].Value.ToString(); textBox6.Text = dataGridView1.Rows[r].Cells[5].Value.ToString(); comboBox1.Text = dataGridView1.Rows[r].Cells[6].Value.ToString(); CreateBarcode(textBox5.Text); if (c == 7) { Form4 f = new Form4(textBox5.Text, comboBox2.Text, comboBox3.Text, textBox3.Text, textBox4.Text, textBox6.Text); f.ShowDialog(); } } private void button1_Click(object sender, EventArgs e) { if (!CheckTextBox()) return; Db d = new Db(); if (!d.DbState) { MessageBox.Show(d.DbStateMessage); return; } string q1 = @"insert into orders (customer,model,serial_no,quantity,notes,visible) " + "values ('" + comboBox2.Text + "','" + comboBox3.Text + "','" + textBox3.Text + "'," + textBox4.Text + ",'" + textBox6.Text + "','未');"; string lastId = d.ExecuteNonReader(q1, ""); if(lastId == "") { MessageBox.Show("枝番登録に問題があります。オーダーを再登録してください。"); return; } else { string q2 = "insert into items (orders_id,suffix_no) values "; for (int i = 1; i <= int.Parse(textBox4.Text); i++) { q2 += "(" + lastId + "," + i.ToString() + ")"; if (i == int.Parse(textBox4.Text)) { q2 += ";"; } else { q2 += ","; } } d.ExecuteNonReader(q2, ""); } d.ExecuteReader(default_query, "", dataGridView1); button2.PerformClick(); MessageBox.Show("登録しました。"); } private void button2_Click(object sender, EventArgs e) { comboBox2.Text = ""; comboBox3.Text = ""; textBox3.Text = ""; textBox4.Text = ""; textBox5.Text = ""; textBox6.Text = ""; comboBox1.Text = "未"; pictureBox1.BackgroundImage = null; } private void button3_Click(object sender, EventArgs e)//更新 { if (textBox5.Text == "") { MessageBox.Show("変更対象を選択してください。"); return; } if (!CheckTextBox()) return; Db d = new Db(); if (!d.DbState) { MessageBox.Show(d.DbStateMessage); return; } //数量更新不可 if (!d.QuantityCheck("select quantity from orders where orders_id = " + textBox5.Text + ";", textBox4.Text)) { MessageBox.Show("数量は更新できません。"); return; } string q = "update orders set customer = '" + comboBox2.Text + "', model = '" + comboBox3.Text + "' , serial_no = '" + textBox3.Text + "' , quantity = " + textBox4.Text + " , notes = '" + textBox6.Text + "' , visible = '" + comboBox1.Text + "' where orders_id = " + textBox5.Text + ";"; d.ExecuteNonReader(q, ""); d.ExecuteReader(default_query, "", dataGridView1); button2.PerformClick(); MessageBox.Show("更新しました。"); } private void button4_Click(object sender, EventArgs e)//削除 { DialogResult yn = MessageBox.Show("本当に削除しますか?", "", MessageBoxButtons.YesNo); if (yn == DialogResult.No) return; if (textBox5.Text == "") { MessageBox.Show("削除対象を選択してください。"); return; } if (!CheckTextBox()) return; Db d = new Db(); if (!d.DbState) { MessageBox.Show(d.DbStateMessage); return; } string q = "delete from orders where orders_id = " + textBox5.Text + ";"; d.ExecuteNonReader(q, ""); q = "delete from items where orders_id = " + textBox5.Text + ";"; d.ExecuteNonReader(q, ""); d.ExecuteReader(default_query, "", dataGridView1); button2.PerformClick(); MessageBox.Show("削除しました。"); } private void checkBox1_CheckedChanged(object sender, EventArgs e) { Db d = new Db(); if (!d.DbState) { MessageBox.Show(d.DbStateMessage); return; } if (checkBox1.Checked) { default_query = "select orders_id,customer,model,serial_no,quantity,notes,visible,'表示' from orders where visible = '完'"; } else { default_query = "select orders_id,customer,model,serial_no,quantity,notes,visible,'表示' from orders where visible = '未'"; } d.ExecuteReader(default_query, "", dataGridView1); button2.PerformClick(); } } } |
Form3.cs
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 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using MySql.Data.MySqlClient; namespace 製品工数管理 { public partial class Form3 : Form { public Form3() { InitializeComponent(); ImeMode = ImeMode.Off; dataGridView1.AllowUserToAddRows = false; dataGridView1.ReadOnly = true; dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; dataGridView1.ColumnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.False; dataGridView1.DefaultCellStyle.Font = new Font("Meiryo UI", 11); Db d = new Db(); if (!d.DbState) { MessageBox.Show(d.DbStateMessage); return; } d.ExecuteReader("select * from workers;","",dataGridView1); } private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { int r = e.RowIndex; int c = e.ColumnIndex; if (r == -1 || c == -1) return; textBox1.Text = dataGridView1.Rows[r].Cells[0].Value.ToString(); textBox2.Text = dataGridView1.Rows[r].Cells[1].Value.ToString(); textBox3.Text = dataGridView1.Rows[r].Cells[2].Value.ToString(); } private void button4_Click(object sender, EventArgs e) { textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; } private void button2_Click(object sender, EventArgs e) { if (textBox1.Text == "") { MessageBox.Show("変更対象を選択してください。"); return; } if (!CheckTextBox()) return; Db d = new Db(); if (!d.DbState) { MessageBox.Show(d.DbStateMessage); return; } string q = @"update workers set worker_name = '" + textBox2.Text + "', work_type = '" + textBox3.Text + "' where workers_id = " + textBox1.Text + ";"; d.ExecuteNonReader(q, ""); d.ExecuteReader("select * from workers;", "", dataGridView1); button4.PerformClick(); MessageBox.Show("更新しました"); } private void button3_Click(object sender, EventArgs e) { DialogResult yn = MessageBox.Show("本当に削除しますか?","",MessageBoxButtons.YesNo); if (yn == DialogResult.No) return; if (textBox1.Text == "") { MessageBox.Show("削除対象を選択してください。"); return; } if (!CheckTextBox()) return; Db d = new Db(); if (!d.DbState) { MessageBox.Show(d.DbStateMessage); return; } string q = @"delete from workers where workers_id = " + textBox1.Text + ";"; d.ExecuteNonReader(q, ""); d.ExecuteReader("select * from workers;", "", dataGridView1); button4.PerformClick(); MessageBox.Show("削除しました。"); } private void button1_Click(object sender, EventArgs e) { if (!CheckTextBox()) return; Db d = new Db(); if (!d.DbState) { MessageBox.Show(d.DbStateMessage); return; } string q = @"insert into workers (worker_name,work_type) values ('" + textBox2.Text + "','" + textBox3.Text + "');"; d.ExecuteNonReader(q, ""); d.ExecuteReader("select * from workers;", "", dataGridView1); button4.PerformClick(); MessageBox.Show("登録しました。"); } private Boolean CheckTextBox() { if (textBox2.Text == "" || textBox3.Text == "") { MessageBox.Show("全て入力必須です。"); return false; } textBox2.Text = textBox2.Text.Trim(); textBox3.Text = textBox3.Text.Trim(); textBox2.Text = textBox2.Text.Replace("\'", "’"); textBox3.Text = textBox3.Text.Replace("\'", "’"); textBox2.Text = textBox2.Text.Replace("\"", "”"); textBox3.Text = textBox3.Text.Replace("\"", "”"); return true; } } } |
Form4.cs
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 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using ZXing; namespace 製品工数管理 { public partial class Form4 : Form { public Form4(string orders_id, string customer, string model, string serial_no, string quantity, string notes) { InitializeComponent(); ImeMode = ImeMode.Off; textBox5.Text = orders_id; textBox1.Text = customer; textBox2.Text = model; textBox3.Text = serial_no; textBox4.Text = quantity; textBox6.Text = notes; CreateBarcode(orders_id); } public void CreateBarcode(string code) { BarcodeWriter br = new BarcodeWriter(); br.Format = BarcodeFormat.CODE_128; br.Options.Height = 80; br.Options.Width = 245; br.Options.Margin = 10; br.Options.PureBarcode = false; Bitmap b = br.Write(code); pictureBox1.BackgroundImage = b; } public void PanelPrint() { System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument(); pd.PrintPage += new System.Drawing.Printing.PrintPageEventHandler((object sender, System.Drawing.Printing.PrintPageEventArgs e) => { Bitmap bmp = new Bitmap(panel1.Width, panel1.Height); panel1.DrawToBitmap(bmp, new Rectangle(0, 0, panel1.Width, panel1.Height)); e.Graphics.DrawImage(bmp, e.MarginBounds); e.HasMorePages = false; bmp.Dispose(); }); PrintDialog pdg = new PrintDialog(); pdg.Document = pd; if (pdg.ShowDialog() == DialogResult.OK) pd.Print(); } private void button1_Click(object sender, EventArgs e) { PanelPrint(); } private void button2_Click(object sender, EventArgs e) { SaveFileDialog sd = new SaveFileDialog(); sd.FileName = "orders.png"; sd.InitialDirectory = @"c:\"; sd.Title = "保存先を指定してください。"; if(sd.ShowDialog() == DialogResult.OK) { Bitmap bmp = new Bitmap(panel1.Width, panel1.Height); panel1.DrawToBitmap(bmp, new Rectangle(0, 0, panel1.Width, panel1.Height)); bmp.Save(sd.FileName); bmp.Dispose(); } } } } |
Form5.cs
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 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace 製品工数管理 { public partial class Form5 : Form { public Form5(string worker_name, string wokers_id, string orders_id) { InitializeComponent(); ImeMode = ImeMode.Off; timer1.Start(); dataGridView1.AllowUserToAddRows = false; dataGridView1.Columns[0].ReadOnly = true; dataGridView1.Columns[1].ReadOnly = true; dataGridView1.Columns[2].ReadOnly = true;//枝番 dataGridView1.Columns[3].ReadOnly = true;//開始 dataGridView1.Columns[4].ReadOnly = true;//終了 dataGridView1.Columns[5].ReadOnly = true;//調整 dataGridView1.Columns[6].ReadOnly = true;//稼働 dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView1.Columns[2].Width = 50; dataGridView1.Columns[3].Width = 200; dataGridView1.Columns[4].Width = 200; dataGridView1.Columns[5].Width = 110; dataGridView1.Columns[6].Width = 110; dataGridView1.Columns[7].Width = 50; dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; dataGridView1.ColumnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.False; dataGridView1.DefaultCellStyle.Font = new Font("Meiryo UI", 11); dataGridView1.Columns[3].DefaultCellStyle.Font = new Font("Meiryo UI", 16); dataGridView1.Columns[4].DefaultCellStyle.Font = new Font("Meiryo UI", 16); dataGridView1.Columns[5].DefaultCellStyle.Font = new Font("Meiryo UI", 16); dataGridView1.Columns[6].DefaultCellStyle.Font = new Font("Meiryo UI", 16); textBox7.Text = wokers_id; label10.Text = "" + worker_name + " さんの入力画面です。"; label10.Tag = worker_name; comboBox1.Items.AddRange(new string[]{ "00:15" , "00:30" , "01:00" , "02:00" , "04:00" , "08:00"}); comboBox1.Text = "00:15"; //作業中一覧から起動 if(orders_id != "") { textBox5.Text = orders_id; button1.PerformClick(); } } private void timer1_Tick(object sender, EventArgs e) { label7.Text = DateTime.Now.ToString("yyyy/MM/dd (dddd)"); label8.Text = DateTime.Now.ToString("HH:mm:ss"); } public string DefaultQuery() { return "select items.orders_id , items.items_id , items.suffix_no , " + "date_format(tasks_s.start_dt, '%y-%m-%d %H:%i') , " + "date_format(tasks_e.end_dt, '%y-%m-%d %H:%i') , " + "substring(tasks_p.adjust,1,length(tasks_p.adjust)-3) ,'','False' " + "from items left outer join tasks_s on items.items_id = tasks_s.items_id and tasks_s.workers_id = " + textBox7.Text + " " + "left outer join tasks_e on items.items_id = tasks_e.items_id and tasks_e.workers_id = " + textBox7.Text + " " + "left outer join tasks_p on items.items_id = tasks_p.items_id and tasks_p.workers_id = " + textBox7.Text + " " + "where items.orders_id = " + textBox5.Text + " order by items.items_id;"; //items.items_id は primary key。tasks_x.items_id と tasks_x.workers_id で 複合unique key。1対1のjoin。 } private void button1_Click(object sender, EventArgs e) { if (textBox5.Text == "") { MessageBox.Show("オーダーIDが入力されていません。"); return; } Db d = new Db(); if (!d.DbState) { MessageBox.Show(d.DbStateMessage); return; } List<TextBox> t = new List<TextBox>() { textBox1, textBox2, textBox3, textBox4, textBox6 }; if (!d.FormLoadExecuteReader("select customer,model,serial_no,quantity,notes from orders where orders_id = " + textBox5.Text + ";", t)) { MessageBox.Show("オーダーIDが存在しません。"); return; } d.ExecuteReader(DefaultQuery(), "", dataGridView1); SetWorkTime(); checkBox1.Checked = false; } private void SetWorkTime() { for (int r = 0; r < dataGridView1.Rows.Count; r++) { string s = dataGridView1.Rows[r].Cells[3].Value.ToString(); string e = dataGridView1.Rows[r].Cells[4].Value.ToString(); string a = dataGridView1.Rows[r].Cells[5].Value.ToString(); if (s != "" && e != "" && a != "") { dataGridView1.Rows[r].Cells[6].Value = Db.WorkTime(DateTime.Parse(s), DateTime.Parse(e), TimeSpan.Parse(a)); } if (s != "" && e != "" && a == "") { dataGridView1.Rows[r].Cells[6].Value = Db.WorkTime(DateTime.Parse(s), DateTime.Parse(e), new TimeSpan(0,0,0)); } if (s == "" || e == "") { dataGridView1.Rows[r].Cells[6].Value = "-"; } } } private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { int r = e.RowIndex; int c = e.ColumnIndex; if (c == 3 && r >= 0 && dataGridView1.Rows[r].Cells[c].Value.ToString() != "")//開始 { Db d = new Db(); if (!d.DbState) { MessageBox.Show(d.DbStateMessage); return; } Form10 f = new Form10(); f.ShowDialog(); if (f.getDatetime == "") { DialogResult yn = MessageBox.Show("削除しますか?(終了も削除されます)", "", MessageBoxButtons.YesNo); if (yn == DialogResult.No) return; string items_id = dataGridView1.Rows[r].Cells[1].Value.ToString(); string workers_id = textBox7.Text; d.ExecuteNonReader("delete from tasks_s where items_id = " + items_id + " and workers_id = " + workers_id + ";", ""); d.ExecuteNonReader("delete from tasks_e where items_id = " + items_id + " and workers_id = " + workers_id + ";", ""); d.ExecuteReader(DefaultQuery(), "", dataGridView1); SetWorkTime(); checkBox1.Checked = false; MessageBox.Show("削除しました。"); } else { string items_id = dataGridView1.Rows[r].Cells[1].Value.ToString(); string workers_id = textBox7.Text; d.ExecuteNonReader("update tasks_s set start_dt = '" + f.getDatetime + "' where items_id = " + items_id + " and workers_id = " + workers_id + ";", ""); d.ExecuteReader(DefaultQuery(), "", dataGridView1); SetWorkTime(); checkBox1.Checked = false; MessageBox.Show("更新しました。"); } } if (c == 4 && r >= 0 && dataGridView1.Rows[r].Cells[c].Value.ToString() != "")//終了 { Db d = new Db(); if (!d.DbState) { MessageBox.Show(d.DbStateMessage); return; } Form10 f = new Form10(); f.ShowDialog(); if (f.getDatetime == "") { DialogResult yn = MessageBox.Show("削除しますか?", "", MessageBoxButtons.YesNo); if (yn == DialogResult.No) return; string items_id = dataGridView1.Rows[r].Cells[1].Value.ToString(); string workers_id = textBox7.Text; d.ExecuteNonReader("delete from tasks_e where items_id = " + items_id + " and workers_id = " + workers_id + ";", ""); d.ExecuteReader(DefaultQuery(), "", dataGridView1); SetWorkTime(); checkBox1.Checked = false; MessageBox.Show("削除しました。"); } else { string items_id = dataGridView1.Rows[r].Cells[1].Value.ToString(); string workers_id = textBox7.Text; d.ExecuteNonReader("update tasks_e set end_dt = '" + f.getDatetime + "' where items_id = " + items_id + " and workers_id = " + workers_id + ";", ""); d.ExecuteReader(DefaultQuery(), "", dataGridView1); SetWorkTime(); checkBox1.Checked = false; MessageBox.Show("更新しました。"); } } if (c == 5 && r >= 0 && dataGridView1.Rows[r].Cells[c].Value.ToString() != "")//調整 { DialogResult yn = MessageBox.Show("削除しますか?", "", MessageBoxButtons.YesNo); if (yn == DialogResult.No) return; string items_id = dataGridView1.Rows[r].Cells[1].Value.ToString(); string workers_id = textBox7.Text; Db d = new Db(); if (!d.DbState) { MessageBox.Show(d.DbStateMessage); return; } d.ExecuteNonReader("delete from tasks_p where items_id = " + items_id + " and workers_id = " + workers_id + ";", ""); d.ExecuteReader(DefaultQuery(), "", dataGridView1); SetWorkTime(); checkBox1.Checked = false; MessageBox.Show("削除しました。"); } } private void OnOff(object sender, EventArgs e) { if (button2 == sender) InsertDatetime("開始", 3, "tasks_s", "start_dt"); if (button3 == sender) InsertDatetime("終了", 4, "tasks_e", "end_dt"); } public void InsertDatetime(string cap, int col_no, string tbl,string col_name) { if (dataGridView1.Rows.Count == 0) return; for (int r = 0; r < dataGridView1.Rows.Count; r++) { string check = dataGridView1.Rows[r].Cells[7].Value.ToString(); if (check == "True" && dataGridView1.Rows[r].Cells[col_no].Value.ToString() != "") { MessageBox.Show("既に" + cap + "時刻が登録されています。削除後に登録してください。"); return; } if (check == "True" && col_no == 4 && dataGridView1.Rows[r].Cells[3].Value.ToString() == "") { MessageBox.Show("作業開始の前に作業終了を登録できません。"); return; } } string query = "insert into " + tbl + " (items_id,workers_id," + col_name + ") values "; Boolean queryExists = false; for (int r = 0; r < dataGridView1.Rows.Count; r++) { string items_id = dataGridView1.Rows[r].Cells[1].Value.ToString(); string check = dataGridView1.Rows[r].Cells[7].Value.ToString(); if (check == "True" && dataGridView1.Rows[r].Cells[col_no].Value.ToString() == "") { query += "(" + items_id + "," + textBox7.Text + ",'" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "'),"; queryExists = true; } } if (queryExists) { query = query.Substring(0, query.Length - 1) + ";"; Db d = new Db(); if (!d.DbState) { MessageBox.Show(d.DbStateMessage); return; } d.ExecuteNonReader(query, ""); d.ExecuteReader(DefaultQuery(), "", dataGridView1); SetWorkTime(); checkBox1.Checked = false; MessageBox.Show("登録しました。"); } } private void UpDown(object sender, EventArgs e) { if (dataGridView1.Rows.Count == 0) return; Boolean f = false; for (int r = 0; r < dataGridView1.Rows.Count; r++) { if ("True" == dataGridView1.Rows[r].Cells[7].Value.ToString()) f = true; } if (f && (Button)sender == button4) PauseClick(TimeSpan.Parse("" + comboBox1.Text)); if (f && (Button)sender == button5) PauseClick(TimeSpan.Parse("-" + comboBox1.Text)); } public void PauseClick(TimeSpan t) { Db d = new Db(); if (!d.DbState) { MessageBox.Show(d.DbStateMessage); return; } for (int r = 0; r < dataGridView1.Rows.Count; r++) { string items_id = dataGridView1.Rows[r].Cells[1].Value.ToString(); string check = dataGridView1.Rows[r].Cells[7].Value.ToString(); if (check == "True") { string adjust_col = dataGridView1.Rows[r].Cells[5].Value.ToString(); TimeSpan ts ; if(adjust_col == "") { ts = t; } else { ts = t + TimeSpan.Parse(adjust_col); } string q = "delete from tasks_p where items_id = " + items_id + " and workers_id = " + textBox7.Text + ";"; d.ExecuteNonReader(q, ""); if (ts != TimeSpan.Zero) { q = "insert into tasks_p (items_id,workers_id,adjust) values (" + items_id + "," + textBox7.Text + ",'" + ts.ToString() + "');"; d.ExecuteNonReader(q, ""); } } } d.ExecuteReader(DefaultQuery(), "", dataGridView1); SetWorkTime(); checkBox1.Checked = false; MessageBox.Show("登録しました。"); } private void button6_Click(object sender, EventArgs e) { Form8 f = new Form8(textBox7.Text,label10.Tag.ToString()); f.ShowDialog(); if(f.ReturnOrders_id != "") { textBox5.Text = f.ReturnOrders_id; button1.PerformClick(); } } private void checkBox1_CheckedChanged(object sender, EventArgs e) { if (dataGridView1.Rows.Count == 0) return; for (int r = 0; r < dataGridView1.Rows.Count; r++) { dataGridView1.Rows[r].Cells[7].Value = checkBox1.Checked.ToString(); } } } } |
Form6.cs
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 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace 製品工数管理 { public partial class Form6 : Form { public Form6() { InitializeComponent(); ImeMode = ImeMode.Off; Db d = new Db(); if (!d.DbState) { MessageBox.Show(d.DbStateMessage); return; } string[][] workers = d.LoadWorkers(); int count = workers.Length; int pages = 1; tabControl1.ItemSize = new Size(1, 55); if(count <= 24) { tabControl1.TabPages.Add("1ページ"); } else if(count > 24 && count <= 48) { tabControl1.TabPages.Add("1ページ"); tabControl1.TabPages.Add("2ページ"); pages = 2; } else if (count > 48) { tabControl1.TabPages.Add("1ページ"); tabControl1.TabPages.Add("2ページ"); tabControl1.TabPages.Add("3ページ"); pages = 3; } int i = 0; for (int p = 0; p < pages; p++) { int x = 6; int y = 6; for (int r = 0; r < 6; r++) { for (int c = 0; c < 4; c++) { if (i == count) break; Button b = new Button(); b.Font = new Font("Meiryo UI", 16); b.Text = workers[i][1].ToString(); b.Tag = workers[i][0].ToString(); b.Size = new Size(206, 71); b.Location = new Point(y + c * (206 + 6), x + r * (71 + 6)); b.Click += new EventHandler(ClickWorker); tabControl1.TabPages[p].Controls.Add(b); i++; } } } } public void ClickWorker(object sender, EventArgs e) { Form5 f = new Form5(((Button)sender).Text, ((Button)sender).Tag.ToString(),""); f.ShowDialog(); } } } |
Form7.cs
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 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace 製品工数管理 { public partial class Form7 : Form { public Form7() { InitializeComponent(); ImeMode = ImeMode.Off; string[] col = new string[] { "オーダーID", "得意先", "型式", "工番", "枝番", "数量" , "名前" , "開始日時" , "終了日時" , "調整時間" , "稼働時間"}; for (int i = 0; i < col.Length; i++) { dataGridView1.Columns.Add(new DataGridViewTextBoxColumn()); dataGridView1.Columns[i].HeaderText = col[i]; } dataGridView1.AllowUserToAddRows = false; dataGridView1.ReadOnly = true; dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; dataGridView1.ColumnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.False; dataGridView1.DefaultCellStyle.Font = new Font("Meiryo UI", 11); DbLoad(); } public string QueryWhere() { string orders_id = textBox5.Text; string customer = comboBox2.Text; string model = comboBox1.Text; string serial_no = textBox6.Text; string worker_name = comboBox3.Text; string start_dt_1 = textBox1.Text; string start_dt_2 = textBox2.Text; string end_dt_1 = textBox3.Text; string end_dt_2 = textBox4.Text; string q = ""; if (orders_id != "") { q = "where items.orders_id like '%" + orders_id + "%' "; } if (customer != "") { if (q == "") { q = "where customer like '%" + customer + "%' "; } else { q += "and customer like '%" + customer + "%' "; } } if (model != "") { if (q == "") { q = "where model like '%" + model + "%' "; } else { q += "and model like '%" + model + "%' "; } } if (serial_no != "") { if (q == "") { q = "where serial_no like '%" + serial_no + "%' "; } else { q += "and serial_no like '%" + serial_no + "%' "; } } if (worker_name != "") { if (q == "") { q = "where worker_name like '%" + worker_name + "%' "; } else { q += "and worker_name like '%" + worker_name + "%' "; } } if (start_dt_1 != "" && start_dt_2 != "") { string f = DateTime.Parse(start_dt_1).ToString("yyyy-MM-dd"); string t = DateTime.Parse(start_dt_2).AddDays(1).ToString("yyyy-MM-dd"); if (q == "") { q = "where tasks_s.start_dt >= '" + f + "' and tasks_s.start_dt < '" + t + "' "; } else { q += "and tasks_s.start_dt >= '" + f + "' and tasks_s.start_dt < '" + t + "' "; } } if (start_dt_1 != "" && start_dt_2 == "") { string f = DateTime.Parse(start_dt_1).ToString("yyyy-MM-dd"); if (q == "") { q = "where tasks_s.start_dt >= '" + f + "' "; } else { q += "and tasks_s.start_dt >= '" + f + "' "; } } if (start_dt_1 == "" && start_dt_2 != "") { string t = DateTime.Parse(start_dt_2).AddDays(1).ToString("yyyy-MM-dd"); if (q == "") { q = "where tasks_s.start_dt < '" + t + "' "; } else { q += "and tasks_s.start_dt < '" + t + "' "; } } if (end_dt_1 != "" && end_dt_2 != "") { string f = DateTime.Parse(end_dt_1).ToString("yyyy-MM-dd"); string t = DateTime.Parse(end_dt_2).AddDays(1).ToString("yyyy-MM-dd"); if (q == "") { q = "where tasks_e.end_dt >= '" + f + "' and tasks_e.end_dt < '" + t + "' "; } else { q += "and tasks_e.end_dt >= '" + f + "' and tasks_e.end_dt < '" + t + "' "; } } if (end_dt_1 != "" && end_dt_2 == "") { string f = DateTime.Parse(end_dt_1).ToString("yyyy-MM-dd"); if (q == "") { q = "where tasks_e.end_dt >= '" + f + "' "; } else { q += "and tasks_e.end_dt >= '" + f + "' "; } } if (end_dt_1 == "" && end_dt_2 != "") { string t = DateTime.Parse(end_dt_2).AddDays(1).ToString("yyyy-MM-dd"); if (q == "") { q = "where tasks_e.end_dt < '" + t + "' "; } else { q += "and tasks_e.end_dt < '" + t + "' "; } } if (q == "") { q = "where visible = '" + comboBox4.Text + "' and tasks_s.tasks_id is not null "; } else { q += "and visible = '" + comboBox4.Text + "' and tasks_s.tasks_id is not null "; } return q; } private void DbLoad() { string start_dt_1 = textBox1.Text; string start_dt_2 = textBox2.Text; string end_dt_1 = textBox3.Text; string end_dt_2 = textBox4.Text; try { if (start_dt_1 != "") DateTime.Parse(start_dt_1); if (start_dt_2 != "") DateTime.Parse(start_dt_2); if (end_dt_1 != "") DateTime.Parse(end_dt_1); if (end_dt_2 != "") DateTime.Parse(end_dt_2); } catch { MessageBox.Show("日付が正しくありません。"); return; } string q = "select items.orders_id , orders.customer , orders.model , orders.serial_no , items.suffix_no , orders.quantity , workers.worker_name , " + "date_format(tasks_s.start_dt, '%y-%m-%d %H:%i') , " + "date_format(tasks_e.end_dt, '%y-%m-%d %H:%i') , " + "substring(tasks_p.adjust,1,length(tasks_p.adjust)-3) , '' " + "from items " + "left outer join tasks_s on items.items_id = tasks_s.items_id " + "left outer join tasks_e on items.items_id = tasks_e.items_id and tasks_s.workers_id = tasks_e.workers_id " + "left outer join tasks_p on items.items_id = tasks_p.items_id and tasks_s.workers_id = tasks_p.workers_id " + "left outer join workers on tasks_s.workers_id = workers.workers_id " + "left outer join orders on items.orders_id = orders.orders_id " + QueryWhere() + " order by items.orders_id , workers.worker_name , items.suffix_no;"; Db d = new Db(); if (!d.DbState) { MessageBox.Show(d.DbStateMessage); return; } comboBox2.Items.Clear(); comboBox1.Items.Clear(); comboBox3.Items.Clear(); foreach (string s in d.LoadCustomer()) { comboBox2.Items.Add(s); } foreach (string s in d.LoadModel()) { comboBox1.Items.Add(s); } foreach (string[] s in d.LoadWorkers()) { comboBox3.Items.Add(s[1]); } d.ExecuteReader(q,"",dataGridView1); SetWorkTime(); } private void SetWorkTime() { for (int r = 0; r < dataGridView1.Rows.Count; r++) { string s = dataGridView1.Rows[r].Cells[7].Value.ToString(); string e = dataGridView1.Rows[r].Cells[8].Value.ToString(); string a = dataGridView1.Rows[r].Cells[9].Value.ToString(); if (s != "" && e != "" && a != "") { dataGridView1.Rows[r].Cells[10].Value = Db.WorkTime(DateTime.Parse(s), DateTime.Parse(e), TimeSpan.Parse(a)); } if (s != "" && e != "" && a == "") { dataGridView1.Rows[r].Cells[10].Value = Db.WorkTime(DateTime.Parse(s), DateTime.Parse(e), new TimeSpan(0, 0, 0)); } if (s == "" || e == "") { dataGridView1.Rows[r].Cells[10].Value = "-"; } } } private void button1_Click(object sender, EventArgs e) { DbLoad(); } } } |
Form8.cs
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 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace 製品工数管理 { public partial class Form8 : Form { public string ReturnOrders_id = ""; public Form8(string workers_id,string worker_name) { InitializeComponent(); ImeMode = ImeMode.Off; string[] col = new string[] { "名前" , "オーダーID" , "得意先", "型式", "工番", "枝番", "数量", "開始日時" }; for (int i = 0; i < col.Length; i++) { dataGridView1.Columns.Add(new DataGridViewTextBoxColumn()); dataGridView1.Columns[i].HeaderText = col[i]; } dataGridView1.AllowUserToAddRows = false; dataGridView1.ReadOnly = true; dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; dataGridView1.ColumnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.False; dataGridView1.DefaultCellStyle.Font = new Font("Meiryo UI", 11); string q = "select '" + worker_name + "' , items.orders_id , orders.customer , orders.model , orders.serial_no , items.suffix_no , orders.quantity , " + "date_format(tasks_s.start_dt, '%y-%m-%d %H:%i') " + "from items " + "left outer join tasks_s on items.items_id = tasks_s.items_id and tasks_s.workers_id = " + workers_id + " " + "left outer join tasks_e on items.items_id = tasks_e.items_id and tasks_e.workers_id = " + workers_id + " " + "left outer join tasks_p on items.items_id = tasks_p.items_id and tasks_p.workers_id = " + workers_id + " " + "left outer join orders on items.orders_id = orders.orders_id " + "where tasks_s.start_dt is not null and tasks_e.end_dt is null and visible = '未';"; Db d = new Db(); if (!d.DbState) { MessageBox.Show(d.DbStateMessage); return; } d.ExecuteReader(q, "", dataGridView1); } private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { int r = e.RowIndex; int c = e.ColumnIndex; if (c == 1 && r >= 0 && dataGridView1.Rows[r].Cells[c].Value.ToString() != "") { ReturnOrders_id = dataGridView1.Rows[r].Cells[c].Value.ToString(); this.Close(); } } } } |
Form9.cs
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 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace 製品工数管理 { public partial class Form9 : Form { public string DbHost; public string DbName; public string DbUser; public string DbPass; public Form9() { InitializeComponent(); try { System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(string[])); using (System.IO.StreamReader sr = new System.IO.StreamReader(Application.StartupPath + @"\path.txt", new System.Text.UTF8Encoding(false))) { string[] s = (string[])xs.Deserialize(sr); textBox5.Text = s[0]; textBox1.Text = s[1]; textBox2.Text = s[2]; textBox3.Text = s[3]; sr.Close(); } } catch { } } private void Form9_FormClosing(object sender, FormClosingEventArgs e) { DbHost = textBox5.Text; DbName = textBox1.Text; DbUser = textBox2.Text; DbPass = textBox3.Text; try { System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(string[])); using (System.IO.StreamWriter sw = new System.IO.StreamWriter(Application.StartupPath + @"\path.txt", false, new System.Text.UTF8Encoding(false))) { xs.Serialize(sw, new string[] { DbHost , DbName, DbUser , DbPass}); sw.Close(); } } catch { } } } } |
Form10.cs
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 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace 製品工数管理 { public partial class Form10 : Form { public string getDatetime = ""; public Form10() { InitializeComponent(); ImeMode = ImeMode.Off; for (int i = DateTime.Now.AddYears(-2).Year; i <= DateTime.Now.AddYears(2).Year; i++ ) { comboBox1.Items.Add(i.ToString()); } comboBox1.Text = DateTime.Now.Year.ToString(); for (int i = 1; i <= 12; i++) { comboBox2.Items.Add(i.ToString("00")); } comboBox2.Text = DateTime.Now.Month.ToString(); for (int i = 1; i <= 31; i++) { comboBox3.Items.Add(i.ToString("00")); } comboBox3.Text = DateTime.Now.Day.ToString(); for (int i = 0; i <= 24; i++) { comboBox4.Items.Add(i.ToString("00")); } comboBox4.Text = "00"; comboBox5.Items.AddRange(new string[] { "00", "15", "30", "45" }); comboBox5.Text = "00"; } private void button1_Click(object sender, EventArgs e) { DateTime dt = new DateTime(); try { dt = DateTime.Parse(comboBox1.Text + "-" + comboBox2.Text + "-" + comboBox3.Text + " " + comboBox4.Text + ":" + comboBox5.Text + ":01"); } catch { MessageBox.Show("値が正しくありません。"); getDatetime = ""; return; } getDatetime = dt.ToString("yyyy-MM-dd HH:mm:ss"); this.Close(); } private void button2_Click(object sender, EventArgs e) { getDatetime = ""; this.Close(); } } } |
Db.cs
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 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using MySql.Data.MySqlClient; namespace 製品工数管理 { class Db { public static string DbHost; public static string DbName; public static string DbUser; public static string DbPass; public Boolean DbState = true; public string DbStateMessage = ""; string dsn = ""; public Db() { dsn = @"user=" + DbUser + ";password=" + DbPass + ";database=" + DbName + ";server=" + DbHost + ";charset=sjis"; MySqlConnection con = null; try { using (con = new MySqlConnection(dsn)) { con.Open(); } } catch(Exception e) { DbStateMessage = e.Message; DbState = false; return; } finally { con.Close(); } } public string[] LoadModel() { MySqlConnection con = null; try { using (con = new MySqlConnection(dsn)) { con.Open(); MySqlCommand cmd = new MySqlCommand("select distinct model from orders", con); using (MySqlDataReader dr = cmd.ExecuteReader()) { List<string> tmp = new List<string>(); while (dr.Read()) { tmp.Add(dr[0].ToString()); } return tmp.ToArray(); } } } catch { } finally { con.Close(); } return new string[] { }; } public string[] LoadCustomer() { MySqlConnection con = null; try { using (con = new MySqlConnection(dsn)) { con.Open(); MySqlCommand cmd = new MySqlCommand("select distinct customer from orders", con); using (MySqlDataReader dr = cmd.ExecuteReader()) { List<string> tmp = new List<string>(); while (dr.Read()) { tmp.Add(dr[0].ToString()); } return tmp.ToArray(); } } } catch { } finally { con.Close(); } return new string[] { }; } public string[][] LoadWorkers() { MySqlConnection con = null; try { using (con = new MySqlConnection(dsn)) { con.Open(); MySqlCommand cmd = new MySqlCommand("select workers_id , worker_name from workers", con); using (MySqlDataReader dr = cmd.ExecuteReader()) { List<string[]> tmp = new List<string[]>(); while (dr.Read()) { tmp.Add(new string[] { dr[0].ToString(), dr[1].ToString() }); } return tmp.ToArray(); } } } catch{} finally { con.Close(); } return new string[][] { }; } public string ExecuteNonReader(string q, string cap) { MySqlConnection con = null; try { using (con = new MySqlConnection(dsn)) { con.Open(); MySqlCommand cmd1 = new MySqlCommand(q,con); cmd1.ExecuteNonQuery(); MySqlCommand cmd2 = new MySqlCommand("select last_insert_id()",con); using (MySqlDataReader dr = cmd2.ExecuteReader()) { if (dr.Read() && dr[0].ToString() != "") return dr[0].ToString(); } } } catch { } finally { con.Close(); } return ""; } public void ExecuteReader(string q, string cap, DataGridView dgv) { dgv.Rows.Clear(); MySqlConnection con = null; try { using (con = new MySqlConnection(dsn)) { con.Open(); MySqlCommand cmd = new MySqlCommand(q, con); using (MySqlDataReader dr = cmd.ExecuteReader()) { while(dr.Read()) { List<string> tmp = new List<string>(); for (int c = 0; c < dgv.Columns.Count; c++) { tmp.Add(dr[c].ToString()); } dgv.Rows.Add(tmp.ToArray()); } } } } catch { } finally { con.Close(); } } public Boolean QuantityCheck(string q, string quantity) { MySqlConnection con = null; try { using (con = new MySqlConnection(dsn)) { con.Open(); MySqlCommand cmd = new MySqlCommand(q, con); using (MySqlDataReader dr = cmd.ExecuteReader()) { if(dr.Read() && dr[0].ToString() == quantity) return true; } } } catch { } finally { con.Close(); } return false; } public Boolean FormLoadExecuteReader(string q,List<TextBox> t) { MySqlConnection con = null; try { using (con = new MySqlConnection(dsn)) { con.Open(); MySqlCommand cmd = new MySqlCommand(q, con); using (MySqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { t[0].Text = dr[0].ToString(); t[1].Text = dr[1].ToString(); t[2].Text = dr[2].ToString(); t[3].Text = dr[3].ToString(); t[4].Text = dr[4].ToString(); return true; } } } } catch { } finally { con.Close(); } return false; } private static TimeSpan ActualWork(DateTime s, DateTime e) { //08:30 - 10:00 = 01:30 //10:15 - 12:00 = 01:45 = 03:15 //12:50 - 15:00 = 02:10 //15:15 - 17:20 = 02:05 = 04:15 = 07:30 int y = s.Year; int m = s.Month; int d = s.Day; DateTime start_dt = new DateTime(y, m, d, s.Hour, s.Minute, 00); DateTime end_dt = new DateTime(y, m, d, e.Hour, e.Minute, 00); DateTime dt = start_dt; TimeSpan ts = new TimeSpan(0, 0, 0); while (dt < end_dt) { ts += new TimeSpan(0, 1, 0); if (dt >= new DateTime(y, m, d, 10, 00, 00) && dt < new DateTime(y, m, d, 10, 15, 00)) ts -= new TimeSpan(0, 1, 0); if (dt >= new DateTime(y, m, d, 12, 00, 00) && dt < new DateTime(y, m, d, 12, 50, 00)) ts -= new TimeSpan(0, 1, 0); if (dt >= new DateTime(y, m, d, 15, 00, 00) && dt < new DateTime(y, m, d, 15, 15, 00)) ts -= new TimeSpan(0, 1, 0); if (dt >= new DateTime(y, m, d, 17, 20, 00) && dt < new DateTime(y, m, d, 17, 30, 00)) ts -= new TimeSpan(0, 1, 0); dt += new TimeSpan(0, 1, 0); } return ts; } public static string WorkTime(DateTime s, DateTime e, TimeSpan a) { if (s > e) return "-"; DateTime start_day = new DateTime(s.Year,s.Month,s.Day); DateTime end_day = new DateTime(e.Year, e.Month, e.Day); //開始と終了が同 if (start_day == end_day) { TimeSpan ts = ActualWork(s,e); return (ts + a).ToString().Substring(0, (ts + a).ToString().Length - 3); } else //開始と終了が別 { TimeSpan ts = new TimeSpan(0, 0, 0); int i = 0; while (start_day.AddDays(i) <= end_day) { DateTime t = start_day.AddDays(i); if (t == start_day && t != end_day)//開始 { ts += ActualWork(s, new DateTime(s.Year,s.Month,s.Day,17,20,00)); } if (t != start_day && t != end_day)//中間 { ts += ActualWork(new DateTime(t.Year, t.Month, t.Day, 8, 30, 00), new DateTime(t.Year, t.Month, t.Day, 17, 20, 00)); } if (t != start_day && t == end_day)//終了 { ts += ActualWork(new DateTime(e.Year, e.Month, e.Day, 8, 30, 00), e); } i++; } return (ts + a).ToString().Substring(0, (ts + a).ToString().Length - 3); } } } } |