以前作ったプログラムお蔵入り版
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 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 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 |
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 System.Data.OleDb; namespace 全在庫管理 { public partial class Form1 : Form { DataTable dt; public Form1() { InitializeComponent(); dataGridView1.MultiSelect = false; dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView1.AllowUserToAddRows = false; dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; comboBox2.Enabled = false; textBox1.TextChanged += new EventHandler(init_view); textBox2.TextChanged += new EventHandler(init_view); textBox3.TextChanged += new EventHandler(init_view); textBox5.TextChanged += new EventHandler(init_view); contextMenuStrip1.Items.Add("更新"); contextMenuStrip1.Items.Add("出庫"); contextMenuStrip1.Items.Add("複写"); contextMenuStrip1.Items.Add("削除"); init(); } ~Form1() { dt.Dispose(); } private void init() { string q = @"select * from tbl where 出庫日 is null order by ID"; if (checkBox3.Checked) q = @"select * from tbl where 出庫日 is not null order by ID"; if (checkBox4.Checked) q = @"select * from tbl where 入庫日 = #" + DateTime.Now.ToString("yyyy/MM/dd") + "# order by ID"; if (checkBox5.Checked) q = @"select * from tbl where 出庫日 = #" + DateTime.Now.ToString("yyyy/MM/dd") + "# order by ID"; dt = Util.getDt(q); list_add(); } public void list_add() { comboBox1.Items.Clear(); comboBox2.Items.Clear(); using (DataView dv = new DataView(dt)) { using (DataTable tmp = dv.ToTable(true, new string[] { "仕入月" })) { DataRow[] dr = tmp.Select("仕入月 is not null"); for (int i = 0; i < dr.Length; i++) { comboBox1.Items.Add(DateTime.Parse(dr[i]["仕入月"].ToString()).ToString("yyyy年MM月")); comboBox2.Items.Add(DateTime.Parse(dr[i]["仕入月"].ToString()).ToString("yyyy年MM月")); } } } } private void Form1_Load(object sender, EventArgs e) { init_view(sender, e); } public void init_view(object sender, EventArgs e) { dataGridView1.Rows.Clear(); string tmp = ""; bool chk = false; if (textBox2.Text != "") { tmp = "工番 like '%" + textBox2.Text + "%'"; chk = true; } if (textBox1.Text != "") { if (chk) tmp = tmp + " and "; tmp = tmp + "製品名称 like '%" + textBox1.Text + "%'"; chk = true; } if (textBox3.Text != "") { if (chk) tmp = tmp + " and "; tmp = tmp + " 仕入先 like '%" + textBox3.Text + "%'"; chk = true; } if (textBox5.Text != "") { if (chk) tmp = tmp + " and "; tmp = tmp + " 区分 like '%" + textBox5.Text + "%'"; chk = true; } if (comboBox1.Text != "" && comboBox2.Enabled == false) { if (chk) tmp = tmp + " and "; tmp = tmp + " 仕入月 = #" + DateTime.Parse(comboBox1.Text).ToString("yyyy/MM/01") + "#"; } else if (comboBox1.Text != "" && comboBox2.Enabled == true && comboBox2.Text != "") { if (chk) tmp = tmp + " and "; tmp = tmp + " 仕入月 >= #" + DateTime.Parse(comboBox1.Text).ToString("yyyy/MM/01") + "# and 仕入月 <= #" + DateTime.Parse(comboBox2.Text).ToString("yyyy/MM/01") + "#"; } else if (comboBox1.Text != "" && comboBox2.Enabled == true && comboBox2.Text == "") { if (chk) tmp = tmp + " and "; tmp = tmp + " 仕入月 >= #" + DateTime.Parse(comboBox1.Text).ToString("yyyy/MM/01") + "#"; } else if (comboBox1.Text == "" && comboBox2.Enabled == true && comboBox2.Text != "") { if (chk) tmp = tmp + " and "; tmp = tmp + " 仕入月 <= #" + DateTime.Parse(comboBox2.Text).ToString("yyyy/MM/01") + "#"; } System.Diagnostics.Debug.Print(tmp.ToString()); DataRow[] dr = dt.Select(tmp, "ID"); decimal[,] rc = new decimal[6, 4]; for (int i = 0; i < dr.Length; i++) { decimal res00; decimal.TryParse(dr[i]["数量"].ToString(), out res00); decimal res01; decimal.TryParse(dr[i]["計上単価"].ToString(), out res01); DateTime res02; if (!DateTime.TryParse(dr[i]["仕入月"].ToString(), out res02)) res02 = new DateTime(1970, 1, 1); dataGridView1.Rows.Add( dr[i]["ID"].ToString(), dr[i]["工番"].ToString(), dr[i]["製品名称"].ToString(), dr[i]["仕入先"].ToString(), res00.ToString(), string.Format("{0:#,0}", res01), string.Format("{0:#,0}", (res00 * res01)), dr[i]["区分"].ToString(), res02.ToString("yyyy年MM月"), dr[i]["備考"].ToString() ); switch (dr[i]["区分"].ToString()) { case "内作材料①": if ((res00 * res01) >= 50000) { rc[1, 2] = rc[1, 2] + (res00 * res01); } else { rc[1, 3] = rc[1, 3] + (res00 * res01); } rc[1, 1] = rc[1, 1] + (res00 * res01); break; case "外作材料①": if ((res00 * res01) >= 50000) { rc[2, 2] = rc[2, 2] + (res00 * res01); } else { rc[2, 3] = rc[2, 3] + (res00 * res01); } rc[2, 1] = rc[2, 1] + (res00 * res01); break; case "内作製品": if ((res00 * res01) >= 50000) { rc[3, 2] = rc[3, 2] + (res00 * res01); } else { rc[3, 3] = rc[3, 3] + (res00 * res01); } rc[3, 1] = rc[3, 1] + (res00 * res01); break; case "外作製品": if ((res00 * res01) >= 50000) { rc[4, 2] = rc[4, 2] + (res00 * res01); } else { rc[4, 3] = rc[4, 3] + (res00 * res01); } rc[4, 1] = rc[4, 1] + (res00 * res01); break; default: if ((res00 * res01) >= 50000) { rc[5, 2] = rc[5, 2] + (res00 * res01); } else { rc[5, 3] = rc[5, 3] + (res00 * res01); } rc[5, 1] = rc[5, 1] + (res00 * res01); break; } } textBox4.Text = string.Format("{0:#,0}", rc[1, 1]); textBox8.Text = string.Format("{0:#,0}", rc[2, 1]); textBox11.Text = string.Format("{0:#,0}", rc[3, 1]); textBox14.Text = string.Format("{0:#,0}", rc[4, 1]); textBox17.Text = string.Format("{0:#,0}", rc[5, 1]); textBox20.Text = string.Format("{0:#,0}", rc[1, 1] + rc[2, 1] + rc[3, 1] + rc[4, 1] + rc[5, 1]); textBox6.Text = string.Format("{0:#,0}", rc[1, 2]); textBox9.Text = string.Format("{0:#,0}", rc[2, 2]); textBox12.Text = string.Format("{0:#,0}", rc[3, 2]); textBox15.Text = string.Format("{0:#,0}", rc[4, 2]); textBox18.Text = string.Format("{0:#,0}", rc[5, 2]); textBox21.Text = string.Format("{0:#,0}", rc[1, 2] + rc[2, 2] + rc[3, 2] + rc[4, 2] + rc[5, 2]); textBox7.Text = string.Format("{0:#,0}", rc[1, 3]); textBox10.Text = string.Format("{0:#,0}", rc[2, 3]); textBox13.Text = string.Format("{0:#,0}", rc[3, 3]); textBox16.Text = string.Format("{0:#,0}", rc[4, 3]); textBox19.Text = string.Format("{0:#,0}", rc[5, 3]); textBox22.Text = string.Format("{0:#,0}", rc[1, 3] + rc[2, 3] + rc[3, 3] + rc[4, 3] + rc[5, 3]); label16.Text = dr.Length.ToString() + "件取得しました"; } private void button1_Click(object sender, EventArgs e) { textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; textBox5.Text = ""; comboBox1.Text = ""; comboBox2.Text = ""; checkBox1.Checked = false; comboBox2.Enabled = false; textBox23.Text = ""; textBox24.Text = ""; textBox25.Text = ""; textBox26.Text = ""; textBox27.Text = ""; textBox28.Text = ""; textBox29.Text = ""; textBox30.Text = ""; init_view(sender, e); } private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) { if (e.Button == MouseButtons.Right) { dataGridView1.ClearSelection(); if (e.RowIndex >= 0 && e.ColumnIndex >= 0) dataGridView1.Rows[e.RowIndex].Selected = true; foreach (ToolStripMenuItem tsmi in contextMenuStrip1.Items) { if (tsmi.Text == "出庫取消") { contextMenuStrip1.Items.Remove(tsmi); break; } } if (checkBox3.Checked || checkBox5.Checked) contextMenuStrip1.Items.Add("出庫取消"); } } private string[] parse_num(string[] tmp) { string[] res = new string[3]; decimal out001; if (tmp[0] == "" || !decimal.TryParse(tmp[0], out out001)) { res[0] = "0"; } else { res[0] = out001.ToString(); } decimal out002; if (tmp[1] == "" || !decimal.TryParse(tmp[1], out out002)) { res[1] = "0"; } else { res[1] = out002.ToString(); } DateTime out003; if (tmp[2].Length == 6 && tmp[2].Substring(4, 1) != "/") { tmp[2] = tmp[2].Substring(0, 4) + "/" + tmp[2].Substring(4, 2) + "/1"; } else if (tmp[2].Length == 6 && tmp[2].Substring(4, 1) == "/") { tmp[2] = tmp[2].Substring(0, 4) + "/" + tmp[2].Substring(5, 1) + "/1"; } else if (tmp[2].Length == 7 && tmp[2].Substring(4, 1) == "/") { tmp[2] = tmp[2].Substring(0, 4) + "/" + tmp[2].Substring(5, 2) + "/1"; } if (tmp[2] == "" || !DateTime.TryParse(tmp[2], out out003)) { res[2] = "1970/01/01"; } else { res[2] = out003.ToString("yyyy/MM/01"); } return res; } private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { if (dataGridView1.Rows.Count == 0) return; set_selection(dataGridView1.SelectedRows[0].Index); string q = ""; switch (e.ClickedItem.Text.ToString()) { case "更新": if (dgvr.Cells[4].Value == null || dgvr.Cells[5].Value == null || dgvr.Cells[8].Value == null) { MessageBox.Show("数量、計上単価、仕入月が空白では処理できません。"); return; } string[] res = parse_num(new string[] { dgvr.Cells[4].Value.ToString(), dgvr.Cells[5].Value.ToString(), dgvr.Cells[8].Value.ToString() } ); q = @"update tbl set " + "工番='" + dgvr.Cells[1].Value.ToString() + "'," + "製品名称='" + dgvr.Cells[2].Value.ToString() + "'," + "仕入先='" + dgvr.Cells[3].Value.ToString() + "'," + "数量=" + res[0] + "," + "計上単価=" + res[1] + "," + "区分='" + dgvr.Cells[7].Value.ToString() + "'," + "仕入月=#" + res[2] + "#," + "備考='" + dgvr.Cells[9].Value.ToString() + "' " + "where ID = " + dgvr.Cells[0].Value.ToString() + ""; break; case "出庫": q = @"update tbl set " + "出庫日=#" + DateTime.Now.ToString("yyyy/MM/dd") + "# " + "where ID = " + dgvr.Cells[0].Value.ToString() + ""; break; case "出庫取消": q = @"update tbl set " + "出庫日=NULL " + "where ID = " + dgvr.Cells[0].Value.ToString() + ""; break; case "複写": q = @"insert into tbl select 工番,製品名称,仕入先,数量,計上単価,区分,仕入月,備考,出庫日,入庫日 from tbl " + "where ID = " + dgvr.Cells[0].Value.ToString() + ""; break; case "削除": q = @"delete from tbl " + "where ID = " + dgvr.Cells[0].Value.ToString() + ""; break; } Util.exeQry(q); init(); init_view(sender, e); init_selection(e.ClickedItem.Text.ToString()); MessageBox.Show(e.ClickedItem.Text.ToString() + "しました。"); } private void init_selection(string tmp) { if (dataGridView1.Rows.Count == 0) return; switch (tmp) { case "更新": case "出庫": case "削除": if (dgv_rows_count == dataGridView1.Rows.Count) { dataGridView1.Rows[dgv_selected].Selected = true; dataGridView1.FirstDisplayedScrollingRowIndex = dgv_view_index; } else { if (dgv_selected >= 1) dataGridView1.Rows[dgv_selected - 1].Selected = true; dataGridView1.FirstDisplayedScrollingRowIndex = dgv_view_index; } break; case "複写": case "新規": dataGridView1.Rows[dataGridView1.Rows.Count - 1].Selected = true; dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows.Count - 1; break; } } private DataGridViewRow dgvr; private int dgv_view_index; private int dgv_selected; private int dgv_rows_count; private void set_selection(int rows_index) { dgvr = dataGridView1.SelectedRows[0]; dgv_view_index = dataGridView1.FirstDisplayedScrollingRowIndex; dgv_selected = rows_index; dgv_rows_count = dataGridView1.Rows.Count; } private void comboBox1_TextChanged(object sender, EventArgs e) { DateTime out001; if (!DateTime.TryParse(comboBox1.Text, out out001)) comboBox1.Text = ""; init_view(sender, e); } private void comboBox2_TextChanged(object sender, EventArgs e) { DateTime out001; if (!DateTime.TryParse(comboBox2.Text, out out001)) comboBox2.Text = ""; init_view(sender, e); } private void checkBox1_CheckedChanged(object sender, EventArgs e) { if(checkBox1.Checked) { comboBox2.Enabled = true; } else { comboBox2.Text = ""; comboBox2.Enabled = false; } init_view(sender, e); } private void button2_Click(object sender, EventArgs e) { checkBox3.Checked = false; string[] res = parse_num(new string[] { textBox26.Text, textBox27.Text, textBox29.Text }); string q = @"insert into tbl (工番,製品名称,仕入先,数量,計上単価,区分,仕入月,備考,入庫日) values " + "('" + textBox23.Text + "','" + textBox24.Text + "','" + textBox25.Text + "'" + "," + res[0] + "," + res[1] + ",'" + textBox28.Text + "',#" + res[2] + "#,'" + textBox30.Text + "',#" + DateTime.Now.ToString("yyyy/MM/dd") + "#)"; Util.exeQry(q); init(); init_view(sender, e); init_selection("新規"); button1.PerformClick(); MessageBox.Show("新規登録しました。"); } private void btn5678_click(object sender, EventArgs e) { switch (((Button)sender).Text) { case "更新": contextMenuStrip1.Items[0].PerformClick(); break; case "出庫": contextMenuStrip1.Items[1].PerformClick(); break; case "複写": contextMenuStrip1.Items[2].PerformClick(); break; case "削除": contextMenuStrip1.Items[3].PerformClick(); break; } } private void btn34_click(object sender, EventArgs e) { DialogResult res = MessageBox.Show("表示されている行が" + ((Button)sender).Text + "されます。実行しますか?","",MessageBoxButtons.OKCancel); if (res == DialogResult.Cancel) return; for (int r = 0; r < dataGridView1.Rows.Count; r++) { string q = ""; if (((Button)sender).Text == "全て出庫") { q = @"update tbl set " + "出庫日=#" + DateTime.Now.ToString("yyyy/MM/dd") + "# " + "where ID = " + dataGridView1.Rows[r].Cells[0].Value.ToString() + ""; } else { q = @"delete from tbl " + "where ID = " + dataGridView1.Rows[r].Cells[0].Value.ToString() + ""; } Text = r + "件目処理中..."; Util.exeQry(q); } Text = "全在庫管理 v1.0"; init(); init_view(sender, e); button1.PerformClick(); MessageBox.Show(((Button)sender).Text + "しました。"); } private void checkBox3_CheckedChanged(object sender, EventArgs e) { if (checkBox3.Checked) { checkBox4.Checked = false; checkBox5.Checked = false; } init(); init_view(sender, e); button1.PerformClick(); } private void checkBox4_CheckedChanged(object sender, EventArgs e) { if (checkBox4.Checked) { checkBox3.Checked = false; checkBox5.Checked = false; } init(); init_view(sender, e); button1.PerformClick(); } private void checkBox5_CheckedChanged(object sender, EventArgs e) { if (checkBox5.Checked) { checkBox3.Checked = false; checkBox4.Checked = false; } init(); init_view(sender, e); button1.PerformClick(); } } } |
Util.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 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data; using System.Data.OleDb; using System.Windows.Forms; namespace 全在庫管理 { class Util { public static void exeQry(string q) { using (OleDbConnection con = new OleDbConnection(@"provider=microsoft.jet.oledb.4.0;data source=" + Application.StartupPath + @"\zen_zaiko.mdb")) { try { con.Open(); OleDbCommand cmd = new OleDbCommand(q, con); cmd.ExecuteNonQuery(); } finally { con.Close(); } } } public static DataTable getDt(string q) { DataTable dt; using (OleDbConnection con = new OleDbConnection(@"provider=microsoft.jet.oledb.4.0;data source=" + Application.StartupPath + @"\zen_zaiko.mdb")) { try { con.Open(); OleDbCommand cmd = new OleDbCommand(q, con); using (OleDbDataReader dr = cmd.ExecuteReader()) { dt = new DataTable(); dt.Load(dr); dr.Close(); } } finally { con.Close(); } } return dt; } } } |
アップロードVBA
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 |
Public frm_type As String Public frm_date As String Public frm_book As String Public frm_chk As Boolean Sub upload_zaiko() On Error GoTo ex frm_chk = False UserForm1.Show If frm_chk = False Then Exit Sub If frm_type = "" Then MsgBox "区分を選択してください。終了します。" Exit Sub End If If frm_date = "" Then MsgBox "仕入月を選択してください。終了します。" Exit Sub End If If frm_book = "" Then MsgBox "対象ブックを選択してください。終了します。" Exit Sub End If Application.ScreenUpdating = False Application.DisplayAlerts = False p = ThisWorkbook.Path & "\zen_zaiko.mdb" t = Selection(1).Row b = Selection(Selection.Count).Row Set con = CreateObject("adodb.connection") Set res = CreateObject("adodb.recordset") con.Open "provider=microsoft.jet.oledb.4.0;data source=" & p Dim buf(9) As String For r = t To b If frm_book = "仕入台帳" Then buf(1) = h(Cells(r, 10).Text, "str") '工番 buf(2) = h(Cells(r, 5).Text & " " & Cells(r, 6).Text & " " & Cells(r, 7).Text, "str") & "(" & h(Cells(r, 12).Text, "str") & ")" '製品名称/型式 buf(3) = h(Cells(r, 3).Text, "str") '仕入先 buf(4) = h(Cells(r, 15).Text, "int") '数量 buf(5) = h(Cells(r, 18).Text, "cur") '計上単価 buf(6) = frm_type '区分 buf(7) = Format(CDate(frm_date), "yyyy/MM/01") '仕入月 buf(8) = "" '備考 buf(9) = Format(Year(Date) & "/" & Month(Date) & "/" & Day(Date), "yyyy/MM/dd") '入庫日 ElseIf frm_book = "工程表" Then buf(1) = h(Cells(r, 3).Text, "str") '工番 buf(2) = h(Cells(r, 2).Text, "str") & "(" & h(Cells(r, 102).Text, "str") & ")" '製品名称/客先 buf(3) = h(ActiveSheet.Name, "str") '班 buf(4) = h(Cells(r, 5).Text, "int") '数量 buf(5) = h(Cells(r, 104).Text, "cur") '計上単価 buf(6) = frm_type '区分 buf(7) = Format(CDate(frm_date), "yyyy/MM/01") '仕入月 buf(8) = "" '備考 buf(9) = Format(Year(Date) & "/" & Month(Date) & "/" & Day(Date), "yyyy/MM/dd") '入庫日 End If q = "insert into tbl (工番,製品名称,仕入先,数量,計上単価,区分,仕入月,備考,入庫日) values (" & _ "'" & buf(1) & "'," & _ "'" & buf(2) & "'," & _ "'" & buf(3) & "'," & _ buf(4) & "," & _ buf(5) & "," & _ "'" & buf(6) & "'," & _ "'" & buf(7) & "'," & _ "'" & buf(8) & "'," & _ "'" & buf(9) & "')" con.Execute (q) Next r If con.State = 1 Then con.Close Set con = Nothing Application.ScreenUpdating = True Application.DisplayAlerts = True MsgBox "終了しました。" Exit Sub ex: If con.State = 1 Then con.Close Set con = Nothing Application.ScreenUpdating = True Application.DisplayAlerts = True MsgBox "エラーが発生しました。" End Sub Function h(str, chk) On Error GoTo ex If (chk = "int" Or chk = "cur") And str = "" Then h = 0 Exit Function End If If chk = "int" Then If IsNumeric(str) Then h = CInt(str) Exit Function Else h = 0 Exit Function End If End If If chk = "cur" Then If IsNumeric(str) Then h = CCur(str) Exit Function Else h = 0 Exit Function End If End If If chk = "str" And str <> "" Then str = Replace(str, ",", ",") str = Replace(str, "'", "’") '全角空白 str = Replace(str, " ", " ") '半角空白 str = Replace(str, " ", " ") str = Replace(str, " ", " ") str = Replace(str, " ", " ") h = str Exit Function ElseIf chk = "str" And str = "" Then h = "" Exit Function End If Exit Function ex: MsgBox "文字列の変換エラーが発生しました。" h = 0 End Function Sub auto_open() On Error Resume Next Application.CommandBars("cell").Controls("全在庫へアップロード").Delete With Application.CommandBars("cell").Controls.Add .Caption = "全在庫へアップロード" .OnAction = "upload_zaiko" End With End Sub Sub auto_close() On Error Resume Next Application.CommandBars("cell").Controls("全在庫へアップロード").Delete Application.CommandBars("cell").Controls("全在庫へアップロード").Delete End Sub |