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 |
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.SQLite; namespace PersonalManager { public partial class Form1 : Form { private string connectionString = "Data Source=" + Application.StartupPath + @"\data.sqlite"; public Form1() { InitializeComponent(); button1.Click += (s, e) => { ExecuteNonQuery("create table if not exists employee(" + "id integer not null primary key autoincrement," + "name text" + ")"); ExecuteNonQuery("insert into employee (name) values ('taro')"); DataTable dt = ExecuteQuery("select * from employee"); List<Model> models = new List<Model>(); for (int r = 0; r < dt.Rows.Count; r++) { models.Add(new Model() { id = dt.Rows[r]["id"].ToString(), name = dt.Rows[r]["name"].ToString() }); } dataGridView1.DataSource = models; }; } private void ExecuteNonQuery(string commandText) { using (SQLiteConnection con = new SQLiteConnection(connectionString)) { con.Open(); using (SQLiteCommand cmd = new SQLiteCommand(con)) { try { cmd.CommandText = commandText; cmd.ExecuteNonQuery(); } catch (Exception e) { MessageBox.Show(e.Message); } } } } private void ExecuteNonQuery(List<string> commandTextList) { using (SQLiteConnection con = new SQLiteConnection(connectionString)) { con.Open(); using (SQLiteCommand cmd = new SQLiteCommand(con)) { cmd.Transaction = con.BeginTransaction(); try { foreach (string sql in commandTextList) { cmd.CommandText = sql; cmd.ExecuteNonQuery(); } cmd.Transaction.Commit(); } catch (Exception e) { MessageBox.Show(e.Message); cmd.Transaction.Rollback(); } } } } private DataTable ExecuteQuery(string commandText) { using (SQLiteConnection con = new SQLiteConnection(connectionString)) { try { con.Open(); using (SQLiteCommand cmd = new SQLiteCommand(con)) { cmd.CommandText = commandText; using (SQLiteDataReader reader = cmd.ExecuteReader()) { DataTable dt = new DataTable(); dt.Load(reader); return dt; } } } catch (Exception e) { MessageBox.Show(e.Message); return new DataTable(); } } } } class Model { public string id { get; set; } public string name { get; set; } } } |
CSSメモ
数年前の記事をベースに色々追加しているので内容が古い。
position
static:
位置指定できない(top/bottom/left/rightが使えない)static以外は基準となれる。
relative:
top/bottom/left/rightが使える。
abusolute:
祖先の左上基準。なければbodyの左上から。
fixed:
スクロールしても固定。
abusolute,fixedはfloat:noneになってしまう。
relativeはtop/bottom/left/rightとfloatを流用できるが、通常はstatic + floatとおぼえておく。
floatクリア
floatの親要素に以下。
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 |
/* 従来 */ .floatcontainer:after{ content: "."; display: block; height: 0; font-size:0; clear: both; visibility:hidden; } .floatcontainer{ display: inline-block; } * html .floatcontainer { height: 1%; } .floatcontainer{ display:block; } /* あるいは以下 */ .clearfix:after { content: ""; clear: both; display: block; } |
センタリング
margin: 0 auto
widthは必要。
margin相殺
marginは重なると相殺される。
大きい値が優先。
ネストして親と子が同じ方向にmarginがあった場合も
相殺される。(親にborderがあったりpaddingがあるとおきない。)
高さ100%
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
/* 従来 */ html, body{ height:100% } #container { min-height:100% height:100% /* min-heightに対応していないブラウザ用 */ } body > #container{ height: auto /* containerの要素全体の高さがbodyタグより大きくなった場合 */ } /* あるいは以下 */ html,body{ height:100% } #container{ height: auto; min-height:100%; } |
Chromeなどでキャッシュの影響で直ぐに反映されない場合、デベロッパーツールを表示し、リロードボタンの上で右クリックするとキャッシュをクリアできる。
作り方
上から、
<header><main><footer>
が基本。
<section>にabcのようなID/Class名を付けた場合、
その中の<div>などはabc-xxxのような形で統一する。
・1カラムの幅100%作り方
①<section>
width 100%
の中に
②<div id=”xxx-inner”>
max-width: 000px;
margin: 0 auto;
を入れる
②の中で調整する場合、
さらにその中に③<div>を入れる。
テキストの位置は、②か③の中で<h1~>や<p>として入れる。
①<section>が画像の場合、
background-image: url(‘1.jpg’);
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
height: 000px;
横並びにしたい場合、
<ul>の場合、
<ul>に
display: flex;
flex-wrap: wrap;
<li>に
display: block;
width: x%;
<div>の場合も同じ、
親<div>に
display: flex;
flex-wrap: wrap;
子<div>に
width: x%;
・余白調整
それぞれの<section>の上下にpaddingを入れる。
あとは上の要素からmargin-bottomで調整する。
・スマホの向きに合わせた文字サイズの自動調整をしない
1 2 3 |
body{ -webkit-text-size-adjust: 100%; } |
・フェードイン
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
body { animation: fadeIn 4s ease 0s 1 normal; -webkit-animation: fadeIn 4s ease 0s 1 normal; } @keyframes fadeIn { 0% {opacity: 0} 100% {opacity: 1} } @-webkit-keyframes fadeIn { 0% {opacity: 0} 100% {opacity: 1} } html { visibility: hidden; } html.wf-active, html.loading-delay { visibility: visible; } |
・iOSのinputリセット
1 2 3 4 5 6 7 8 9 10 11 12 |
input,select{ appearance: none; -moz-appearance: none; -webkit-appearance: none; } select { background-image: url(./arrow.svg); background-repeat: no-repeat; background-size: 12px 10px; background-position: right 10px center; } |
Vue.js 入門
jsというとフレームワークが色々あるので、今回はVue.jsを少しさわってみた。
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 |
//-------------------------------------------------------- //Vueインスタンス生成 var vm = new Vue({}) //-------------------------------------------------------- //拡張オプションを定義したコンストラクタ拡張からのVueインスタンス生成 var v = Vue.extend({}) var vm = new v() //-------------------------------------------------------- //Vueインスタンスプロパティのプロパティプロキシ var prop = {age: 99} var vm = new Vue({ data: prop }) console.log(vm.age); //00 vm.age = 98; console.log(prop.age); //98 //-------------------------------------------------------- //インスタンスメソッド$watch <div id="app"> <input type="text" v-model="age"> </div> <script> var vm = new Vue({ el: "#app", data:{ age: 20 } }) vm.$watch("age",function(){ alert(""); }); </script> //-------------------------------------------------------- //グローバルコンポーネント <div id="app"> <hello></hello> </div> <script> //グローバルコンポーネント Vue.component("Hello",{ template: "<p>Hello World</p>" }) //ルートインスタンス new Vue({ el:"#app" }) </script> //-------------------------------------------------------- //ローカルコンポーネント <div id="app"> <my-comp></my-comp> </div> <script> var tmp = Vue.extend({ template: "<p>Hello World</p>" }) new Vue({ el:"#app", components: { "my-comp": tmp } }) </script> //-------------------------------------------------------- //コンポーネントプロパティ <div id="app"> <child msg="hey"></child> </div> <script> //プロパティ宣言 Vue.component("child",{ props: ["msg"], template: "<span>{{ msg }}</span>" }) new Vue({ el:"#app" }) </script> //-------------------------------------------------------- //動的なコンポーネント <body> <div id="app"> <component v-bind:is="currentView"></component> </div> </body> <script> Vue.component("logincomp",{ template: '<p>hey</p>' }) new Vue({ el: "#app", data: { currentView: "logincomp" } }) </script> //-------------------------------------------------------- //動的なコンポーネント //複数の呼び出し方 <body> <div id="app"> <p>h or e or c</p> <input type="text" v-model="currentView"><br> <component v-bind:is="currentView"></component> </div> </body> <script> var tmp = Vue.extend({ template: "<p>e !!!</p>" }) new Vue({ el: "#app", data: { currentView: "h" }, components:{ //テンプレート定義方法 h: { template: "<p>h !!!</p>" }, e: tmp, c: { template: "#c"} } }) </script> <script type="text/x-template" id="c"> <p>c !!!</p> </script> |
適当に色々書いてみたもの。
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 |
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Test</title> <script src="vue.min.js"></script> <style> .rd{ background-color: red; } </style> </head> <body> <div id="box" v-bind:style="s" v-on:click="alert" v-bind:class="{ bk: isBk, rd: isRd }"> </div> <div id="app"> <input type="button" value="ClickMe!" v-on:click="SayHello"><br> <p>h or e or c を入力最初はeは空ボタンを押した後は値が入る</p> <input type="text" v-model="currentView"><br> <component v-bind:is="currentView"></component> <div id="tbl" v-bind:style="styleObject"> table </div> </div> </body> <script> var tbl = "<table>"; for(var r=1; r<=10; r++){ tbl += "<tr class='r" + r +"'>" for(var c=1; c<=5; c++){ tbl += "<td class='c" + c + "'>○</td>"; } tbl += "</tr>" } tbl += "</table>"; var e = document.getElementById("tbl"); e.innerHTML = tbl; </script> <script> new Vue({ el:"#box", methods:{ alert:function(){ this.isRd = true; //クラス変更する。 alert(""); } }, data:{ s:{ border: "3px solid black", width: "30px", height: "30px" }, isBk: false, isRd: false } }) new Vue({ el: "#tbl", data:{ styleObject:{ fontSize: "32px" } }, methods:{ bom: function(){ alert("") } } }) //メインインスタンスから呼ばれるコンポーネント定義 var tmp = Vue.extend({ props:["msg"], created: function(){ alert("created"); this.msg = "hello e !!! "; //ここでvar msg = "xxx"としてもテンプレートでは使えない。 }, template: "<p>{{ buff }}</p>" }) new Vue({ el: "#app", data: { currentView: "h" }, props:["buff"], //ここのbuffはtmp他のインスタンスからでも呼べる。 components:{ //テンプレート定義方法 h: { template: "<p>h !!!</p>" }, e: tmp, c: { template: "#c"} }, methods: { SayHello: function(){ buff = "hello Vue !"; alert(buff); } } }) </script> <script type="text/x-template" id="c"> <p>c !!!</p> </script> </html> |
json展開、axiosでpost
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 |
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>title</title> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <script src="https://unpkg.com/axios/dist/axios.min.js"></script> </head> <body> <div id="app"> <input type="button" v-on:click="fetchData" value="Get"> <input type="text" v-bind:value="status"> <input type="range" max="1" min="0" step="0.25" v-model="v"> <span>{{ v }}</span> <table> <tr v-for="i in js.data" v-bind:id="i.id"> <td>{{ i.name }}</td><td>{{ i.age }}</td><td>{{ i.addr }}</td> </tr> </table> </div> <script> let js = { "data":[ { "id": 1, "name": "taro", "age": 20, "addr": "tokyo", }, { "id": 2, "name": "jiro", "age": 30, "addr": "kanagawa", } ]}; new Vue({ el: '#app', data:{ status, v: 0, js, }, methods:{ fetchData(){ axios .get('https://api.coindesk.com/v1/bpi/currentprice.json') .then(response => { console.log(response) this.status = response.status }) } } }) </script> </body> </html> |
フロント開発環境色々
HTML/CSS/JSなどフロントは数年前にちょっと勉強しただけでだいぶ忘れてしまったので復習をする。
まずは環境構築から。
エディタ
使うエディタはVSCodeとした。補完が効くので助かる。
Vim拡張機能を入れてしばらく使ったがやめた。そのままでも不便がないぐらいのショーットカットがあるので、設定は少しだけ。
VSCode設定
ショートカット追加
{“key”: “ctrl+i”,”command”: “editor.action.jumpToBracket”}
ユーザー設定
minimapは1.10から
1 2 3 4 5 6 7 |
{ "php.validate.executablePath": "C:\\Users\\xxx\\Desktop\\xampp\\php\\php.exe", "editor.minimap.enabled": true, "editor.tabSize": 2, "editor.fontSize": 16, "workbench.iconTheme": "vs-seti" } |
VSCodeショートカット
Ctrl + Shift + L
選択中の箇所を同時編集(マルチカーソル)
Ctrl + i
対応括弧に移動。
Ctrl + /
コメントトグル
Ctrl + P
ファイル検索して開く
Alt + Up/Down
行を上下移動
Alt + Shift + Up/Down
行を上下コピー
Alt + Shift + ドラッグ
矩形選択
Alt + クリック
マルチカーソル
Ctrl + Shift + k
行の削除
Ctrl + Shift + \
対応する括弧
Ctrl + ]
行にインデントを追加
Ctrl + [
行のインデントを削除
sass(scss)
$で変数。#{}で変数展開。変数には型もある。
組み込みの関数もあり、自作もできる。
@function name($arg) {
@return returnValue
}
ループ処理
@for $i from 0 to 10 {
}
条件分岐
@if $arg == 0 {
}
などなど便利な機能がある。以下適当に記述してみたもの。
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 |
$mainColor: #991100; $subColor: #884400; @mixin mixBorder($color) { border: 1px $color solid; } .DivClass { background-color: $subColor; @include mixBorder($mainColor); } @for $i from 1 to 10 { @if $i % 2 == 0 { #tr-#{$i}{ color: black; border: #{$i}px solid black; } } @else if $i % 2 == 1 { #tr-#{$i}{ color: black; border: #{$i}px solid grey; } } } @each $var in taro,jiro,saburo { ##{$var}{color:black;} .name-#{$var}{color:black;} } #header { @extend .DivClass; } div { @extend .DivClass; } #container { width: 960px; height: 1200px; margin: 0 auto; } #header > ul > li { font-size: 25px; list-style: none; display: inline; a { text-decoration: none; } } |
VSCodeタスクでsass(scss)コンパイル
Rubyは入っているので、
gem install sass
とする。
バージョン確認。
sass -v
タスク作成は、
Ctrl + Shift + P
でパレットを開き、
Configure Task Runner
と入力し、othersを選ぶ。
そうすると、task.jsonができるので、
“version”: “0.1.0”,
“command”: “sass”,
“isShellCommand”: true,
“args”: [“test.scss”,”test.css”],
“showOutput”: “always”
のように記述する。
タスクランナーの実行は、
Ctrl + Shift + B
と入力する。
tasks.jsonはプロジェクトフォルダの中にある.vscodeの中にできる。
プロジェクトとは、サイドバーで開いているフォルダのこと。
タスクランナーで複数コマンドを渡したい場合
上記はscssコマンドだけだが、他にも色々したい場合。
ここではpowershell。(UTF-8で日本語入ると動かないので注意)
自動でサーバーに転送したい、chromeで開きたい等。
https://github.com/PowerShell/Win32-OpenSSH/releases
からWin版のSSHを落とし、フォルダの中から
ssh.exe, scp.exe
をコピーしておく。
鍵ファイルもコピーして、ps1と同じ場所に置く。
以下のようにすると、sassをコンパイルして、htmlとともにサーバーに転送し、そのURLを開く。
(Chromeのタブは増えてしまうが)
c.ps1
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 |
# $PSVersionTable # scssのコンパイル # scss style.scss style.css # Chromeで開く(ローカル) $file = "index3.html" $path = Split-Path $MyInvocation.MyCommand.Path -Parent Start-Process -FilePath "chrome" -ArgumentList $path"/"$file <# 拡張子で判断して複数同時にChromeで開く(ローカル) $path = Split-Path $MyInvocation.MyCommand.Path -Parent foreach($file in Get-ChildItem -Filter *.html -Path $path -Name){ Write-Host $path"/"$file; Start-Process -FilePath "chrome" -ArgumentList $path"/"$file } #> <# scpでサーバーへ転送 $url = "http://192.168.102.15:3000/" $usr = "okamura" $remoteHost = "192.168.102.15" $remotePath = "/home/okamura/www/" $key = "ThinkPad.key" $files = ( "index2.html", "vue.min.js" ) $localPath = Split-Path $MyInvocation.MyCommand.Path -Parent foreach($file in $files){ # Write-Host $usr"@"$ip":"$url ./scp.exe -P 2299 -i $key $localPath"/"$file $usr"@"$remoteHost":"$remotePath } Start-Process -FilePath "chrome" -ArgumentList $url"/"$files[0] #> # read-host |
tasks.json
1 2 3 4 5 6 7 8 9 |
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "0.1.0", "command": "start", "isShellCommand": true, "args": ["powershell","./c.ps1"], "showOutput": "always" } |
Emmet
VSCodeだと標準で入っている。
Tabキーで展開できる。
マークダウン
マークダウンを使う場合、
Ctrl+Shift+V
でプレビューできる。
Debugger for Chorme
拡張機能でChromeと検索すると出て来るのでインスト。
サイトバーのデバッグを開き、再生すると、launch.jsonができるので接続設定を記述する。
Chrome拡張機能 manifest.jsonメモ
manifest_version, name, versionは必須。
・manifest_version
2, 3を指定。
・name
任意の名前。
・version
任意のバージョン。
***
・content_scripts / background
・content_scripts
特定のページで動作。DOMを操作できる。
content_scripts > matches
スクリプトを動作させたいURL。
content_scripts > js
動作させるスクリプト。
・background
常にバックグラウンドで動いている。
v3からbackgroundはservice_workerを指定する。
background > scripts
バックグラウンドで動作するスクリプト。
background > persistent
persistent:falseにするとEvent-Pageとなり、必要になったら動く。
バックグラウンドは非推奨。
***
・browser_action / page_action
browser_action:全てのページでアイコン表示。
page_action:特定のページでアイコン表示。
v3からactionに統合される。
***
・id
IDを指定。
・description
説明。
・icons
アイコンを指定。
・short_name
短縮名。
・default_locale
デフォルト言語を指定。
***
・permissions
ChromeAPIを使う場合指定。
・permissions > contextMenus
右クリックメニューの拡張。
***
・commands
ショートカット定義。
・options_page
オプションページを使う場合指定。
・minimum_chrome_version
Chromeの最低バージョンを指定。
・homepage_url
ホームページを指定。
・author
作成者。
・override pages
新規タブ、ブックマークマネージャ、履歴の差し替え。
・omnibox
検索ボックスの拡張。
Chrome拡張機能 Google検索にfavicon
最新版あり。
即席で作ったけどかなり活躍していて、検索結果にfaviconがないと気持ち悪くなってしまった。
script.js
1 2 3 4 5 6 7 8 9 |
$(document).ready(function(){ $("h3.r > a").each(function(){ var url = $(this).attr('href'); domain = url.match(/^https?:\/\/([-0-9a-z.]+)/i); var fav = "//www.google.com/s2/favicons?domain=" + domain[1]; var img = "<img src='" + fav + "'>"; $(this).parent().prepend(img); }); }); |
manifest.json
1 2 3 4 5 6 7 8 9 10 11 |
{ "manifest_version": 2, "name": "Google検索にfavicon", "version": "0.0.1", "content_scripts":[ { "matches": ["https://www.google.co.jp/search?*"], "js": ["jquery-3.1.1.min.js","script.js"] } ] } |
検索結果の構造が変わった模様。
script.js
1 2 3 4 5 6 7 8 9 |
$(document).ready(function(){ $("a > h3").each(function(){ var url = $(this).parent().attr('href'); domain = url.match(/^https?:\/\/([-0-9a-z.]+)/i); var fav = "//www.google.com/s2/favicons?domain=" + domain[1]; var img = "<img src='" + fav + "'>"; $(this).prepend(img); }); }); |
jquery-3.1.1.min.js、manifest.json、script.jsの3つのまとめてフォルダに入れ、Chrome拡張へドラッグする。
PHP Javascript 工程管理
以前作っていた工程管理。お蔵入り版。
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 |
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <title>外注工程管理表</title> <link rel="stylesheet" href="cssreset-min.css"> <link rel="stylesheet" href="style.css"> <script src="jquery-1.11.2.min.js"></script> </head> <body> <?php session_start(); if(array_key_exists("s",$_GET) && $_GET["s"] != ""){ if(preg_match("/^[0-9]{8}$/", $_GET["s"])){ $start_day = substr($_GET["s"], 0, 4) . "-" . substr($_GET["s"], 4, 2) . "-" . substr($_GET["s"], 6, 2); }else{ $start_day = date("Y-m-d"); } }else{ $start_day = date("Y-m-d"); } if(array_key_exists("c",$_GET) && $_GET["c"] != ""){ if(preg_match("/^[0-9]+$/", $_GET["c"])){ $column = $_GET["c"]; }else{ $column = 14; } }else{ $column = 14; } include 'class.php'; $db = new Db(); include 'edit.php'; include 'save.php'; ?> <div class="frm"> <input type="button" value=" 新規登録 " id="save_btn"> <span class="<?php if(!array_key_exists("v", $_GET)){ echo 'down_btn"'; }else{ echo 'btn" id="default_btn"'; } ?>> 通常 </span> <span class="<?php if(array_key_exists("v", $_GET) && $_GET["v"] == "none_draw"){ echo 'down_btn"'; }else{ echo 'btn" id="none_draw_btn"'; } ?>> 未出図依頼 </span> <span class="<?php if(array_key_exists("v", $_GET) && $_GET["v"] == "none_sup"){ echo 'down_btn"'; }else{ echo 'btn" id="none_sup_btn"'; } ?>> 製作先未決定 </span> <span class="<?php if(array_key_exists("v", $_GET) && $_GET["v"] == "done"){ echo 'down_btn"'; }else{ echo 'btn" id="done_btn"'; } ?>> 出荷済 </span> <span class="<?php if(array_key_exists("v", $_GET) && $_GET["v"] == "hold"){ echo 'down_btn"'; }else{ echo 'btn" id="hold_btn"'; } ?>> 保留 </span> </div> <div id="start" class="frm"> 列数:<input type="text" value="<?php echo $column ?>" id="column_count"> 日付: <!-- 年 --> <select id="start_y"> <option><?php echo date("Y",strtotime(" $start_day - 2 year")); ?></option> <option><?php echo date("Y",strtotime(" $start_day - 1 year")); ?></option> <option selected ><?php echo date("Y",strtotime(" $start_day + 0 year")); ?></option> <option><?php echo date("Y",strtotime(" $start_day + 1 year")); ?></option> <option><?php echo date("Y",strtotime(" $start_day + 2 year")); ?></option> </select> <!-- 月 --> <select id="start_m"> <?php for($i=1; $i <= 12; $i++){ if((int)date("m",strtotime("$start_day")) == $i){ if($i < 10){ $i = "0" . $i; } echo '<option selected>', $i, '</option>'; }else{ if($i < 10){ $i = "0" . $i; } echo '<option>', $i, '</option>'; } } ?> </select> <!-- 日 --> <select id="start_d"> <?php for($i=1; $i <= 31; $i++){ if((int)date("d",strtotime("$start_day")) == $i){ if($i < 10){ $i = "0" . $i; } echo '<option selected>', $i, '</option>'; }else{ if($i < 10){ $i = "0" . $i; } echo '<option>', $i, '</option>'; } } ?> </select> <input type="button" value=" 更新 " id="start_position"> <input type="button" value=" 本日 " id="today_position"> </div> <?php include 'table.php'; ?> <script> $(document).on("change","#task_select",function(){ if($("#task_select option:selected").text() == "検査"){ $("#task_select_val").removeAttr("disabled"); }else{ $("#task_select_val").attr("disabled", "disabled"); } }); $(document).on("click","#input_task_cancel_btn", function(){ $("#input_task_add").remove(); }); $(document).on("click","#input_task_add_btn", function(){ var task = $("#task_select option:selected").text(); var task_val = $("#task_select_val").val(); var id = $(this).prev().children("input[name=id]").val(); var ymd = $(this).prev().children("input[name=ymd]").val(); $.ajax({ type: "POST", url: "add_task.php", acync: false, data: { task: task, task_val: task_val, id: id, ymd: ymd }, dataType: 'html', success: function(data){ if (data === "false"){ alert("エラーが発生しました。処理は中断されました。"); return; } $("#input_task_add").remove(); window.location.reload(); },error: function(){ alert("エラーが発生しました。処理は中断されました。"); return; } }); }); //ダイアログを表示 $(document).on("click", ".tbl_btn", function(){ if(document.getElementById("input_task_add") != null){ return; } var id = $(this).parent().parent().parent().parent().data("id"); var ymd = $(this).parent().data("date"); var top = $(this).position().top; var left = $(this).position().left; var html = '<form class="frm">'+ 'タスク:<select id="task_select"><option>出図日</option><option>支給品手配</option><option>検査</option><option>納期</option></select> '+ '<input type="text" id="task_select_val" disabled="disabled">'+ '<input type="hidden" name="id" value="' + id + '">'+ '<input type="hidden" name="ymd" value="' + ymd + '">'+ '</form>'+ '<input type="button" value=" 登録 " id="input_task_add_btn"> <input type="button" value=" 中止 "id="input_task_cancel_btn">'; var e = $("<div>", { id: "input_task_add", html: html }); $("body").append(e); $("#input_task_add").css({ "background-color": "white", "position": "absolute", "z-index": "999", "border":"2px solid #1253A4", "padding": "10px", "width": "265px", "top": top, "left": left }); }); $(document).on("click", "#default_btn", function(){ var y = $("#start_y option:selected").text(); var m = $("#start_m option:selected").text(); var d = $("#start_d option:selected").text(); var start_day = y + m + d; var count = $("#column_count").val(); window.location.href = "<?php echo $_SERVER['SCRIPT_NAME']; ?>" + "?s=" + start_day + "&c=" + count + ""; }); $(document).on("click", "#done_btn", function(){ var y = $("#start_y option:selected").text(); var m = $("#start_m option:selected").text(); var d = $("#start_d option:selected").text(); var start_day = y + m + d; var count = $("#column_count").val(); window.location.href = "<?php echo $_SERVER['SCRIPT_NAME']; ?>" + "?v=done&s=" + start_day + "&c=" + count + ""; }); $(document).on("click", "#none_draw_btn", function(){ var y = $("#start_y option:selected").text(); var m = $("#start_m option:selected").text(); var d = $("#start_d option:selected").text(); var start_day = y + m + d; var count = $("#column_count").val(); window.location.href = "<?php echo $_SERVER['SCRIPT_NAME']; ?>" + "?v=none_draw&s=" + start_day + "&c=" + count + ""; }); $(document).on("click", "#none_sup_btn", function(){ var y = $("#start_y option:selected").text(); var m = $("#start_m option:selected").text(); var d = $("#start_d option:selected").text(); var start_day = y + m + d; var count = $("#column_count").val(); window.location.href = "<?php echo $_SERVER['SCRIPT_NAME']; ?>" + "?v=none_sup&s=" + start_day + "&c=" + count + ""; }); $(document).on("click", "#hold_btn", function(){ var y = $("#start_y option:selected").text(); var m = $("#start_m option:selected").text(); var d = $("#start_d option:selected").text(); var start_day = y + m + d; var count = $("#column_count").val(); window.location.href = "<?php echo $_SERVER['SCRIPT_NAME']; ?>" + "?v=hold&s=" + start_day + "&c=" + count + ""; }); //更新 $(document).on("click", "#start_position", function(){ var y = $("#start_y option:selected").text(); var m = $("#start_m option:selected").text(); var d = $("#start_d option:selected").text(); var start_day = y + m + d; var count = $("#column_count").val(); window.location.href = "<?php echo $_SERVER['SCRIPT_NAME']; ?><?php if(array_key_exists("v",$_GET) && $_GET["v"] != ""){ echo "?v=", $_GET["v"], "&"; }else{ echo "?"; } ?>s=" + start_day + "&c=" + count + ""; }); //本日 $(document).on("click", "#today_position", function(){ var count = $("#column_count").val(); window.location.href = "<?php echo $_SERVER['SCRIPT_NAME']; ?><?php if(array_key_exists("v",$_GET) && $_GET["v"] != ""){ echo "?v=", $_GET["v"], "&"; }else{ echo "?"; } ?>s=" + <?php echo date("Ymd"); ?> + "&c=" + count + ""; }); $(document).on("click","#save_btn",function(){ $("#edit_div").css("display","none"); $("#save_div").css("display","block"); }); //中止 $(document).on("click","#save_cancel_btn",function(){ $("#save_div").css("display","none"); }); $(document).on("click","#edit_cancel_btn",function(){ $("#edit_div").css("display","none"); }); $(document).on("click",".edit_btn",function(){ $("#save_div").css("display","none"); var id = $(this).parent().parent().parent().parent().data("id"); var kokyaku = $(this).parent().parent().find(".val_2").children("p").text(); var katashiki = $(this).parent().parent().find(".val_3").children("p").text(); var kouban = $(this).parent().parent().find(".val_4").children("p").text(); var suryo = $(this).parent().parent().find(".val_5").children("p").text(); var seisakusaki = $(this).parent().parent().find(".val_6").children("p").text(); var tanka = $(this).parent().parent().find(".val_7").children("p").text(); $("#edit_div").css("display","block"); //表示させているのはdata-idではなくループカウンタ $("#update_id").text($(this).parent().parent().parent().find(".cap_1").children("p").text()); $("#edit_id").val(id); $("#edit_kokyaku").val(kokyaku); $("#edit_katashiki").val(katashiki); $("#edit_kouban").val(kouban); $("#edit_suryo").val(suryo); $("#edit_seisakusaki").val(seisakusaki); $("#edit_tanka").val(tanka.replace(/,/g,"")); }); //更新・削除・出荷 $(document).on("click","#edit_update_btn, #edit_delete_btn, #edit_hide_btn, #edit_hide_cancel_btn, #edit_hold_btn, #edit_hold_cancel_btn",function(){ var condition = $(this).attr("id"); var id = $("#edit_id").val(); var kokyaku = $("#edit_kokyaku").val(); var katashiki = $("#edit_katashiki").val(); var kouban = $("#edit_kouban").val(); var suryo = $("#edit_suryo").val(); var seisakusaki = $("#edit_seisakusaki").val(); var tanka = $("#edit_tanka").val(); var y = $("#edit_year option:selected").text(); var m = $("#edit_month option:selected").text(); $.ajax({ type: "POST", url: "edit_condition.php", acync: false, data: { condition: condition, id: id, kokyaku: kokyaku, katashiki: katashiki, kouban: kouban, suryo: suryo, seisakusaki: seisakusaki, tanka: tanka, y: y, m: m }, dataType: 'html', success: function(data){ if (data === "false"){ alert("エラーが発生しました。処理は中断されました。"); return; } $("#edit_div").css("display","none"); //window.location.href = "<?php echo $_SERVER['SCRIPT_NAME']; ?>" window.location.reload(); },error: function(){ alert("エラーが発生しました。処理は中断されました。"); return; } }); }); $(document).keydown(function(e){ if(e.keyCode == 27){ $("#edit_div").css("display","none"); $("#save_div").css("display","none"); $("#input_task_add").remove(); } }); </script> </body> </html> |
PHP Javascript 在庫管理
以前作っていた在庫管理。お蔵入り版。
1つのファイルにHTML,CSS,JS,PHPを全て書き込んでいた。
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 |
<!DOCTYPE html> <html lang="ja"> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <meta charset="UTF-8"> <title>受注参照</title> <style> body{ font-family: Meiryo, sans-serif; font-size: 12px; } #view_tb{ border-collapse: collapse; font-size: 12px; } #view_tb td, #view_tb th{ border: 1px dotted #ccc; white-space: nowrap; padding: 1px; } #view_tb tr:hover{ background-color: #eef; } #frm{ margin-bottom: 10px; background-color: #eef; } #bk{ display: none; } #sav_tb td{ text-align: right; } .yen{ text-align: right; } .lnk{ cursor: pointer; color: blue; } </style> </head> <body> <a href="?view=受注一覧&offset=0" id="bk">戻る</a> <div id="header"> <?php require_once('config.php'); require_once('functions.php'); // 登録 // if( $_GET['save'] == "登録"){ $n = date("Y-m-d"); echo <<< HTML <form method="POST"> <table id="sav_tb"> <tr><td>区分:</td><td><input type="text" value="新規" disabled></td></tr> <tr><td>型式:</td><td><input type="text"></td></tr> <tr><td>工番(数値):</td><td><input type="text" value=0></td></tr> <tr><td>数量(数値):</td><td><input type="text" value=0></td></tr> <tr><td>納期:</td><td><input type="text" value="$n"></td></tr> <tr><td>得意先:</td><td><input type="text"></td></tr> <tr><td>単価(数値):</td><td><input type="text" value="0"></td></tr> <tr><td>金額(数値):</td><td><input type="text" value="0" disabled></td></tr> <tr><td>本社備考1:</td><td><input type="text"></td></tr> <tr><td>本社備考2:</td><td><input type="text"></td></tr> <tr><td>納期確定:</td><td><input type="text"></td></tr> <tr><td>更新日:</td><td><input type="text" value="$n" disabled></td></tr> <tr><td>作成日:</td><td><input type="text" value="$n" disabled></td></tr> <tr> <td></td> <td><span class="lnk" id="sv">[登録]</span> <span class="lnk" id="abt">[中止]</span></td> </tr> </table> </div><!-- header --> </form> <script> $(function(){ // 登録 // $(document).on('click', '#sv', function(){ var kubun = $("#sav_tb tr:nth-child(1) input").val(); var katashiki = $("#sav_tb tr:nth-child(2) input").val(); var kouban = parseInt($("#sav_tb tr:nth-child(3) input").val()); var suryo = parseInt($("#sav_tb tr:nth-child(4) input").val()); var nouki = $("#sav_tb tr:nth-child(5) input").val(); var tokuisaki = $("#sav_tb tr:nth-child(6) input").val(); var tanka = parseInt($("#sav_tb tr:nth-child(7) input").val()); var kingaku = parseInt($("#sav_tb tr:nth-child(8) input").val()); var honsyabikou1 = $("#sav_tb tr:nth-child(9) input").val(); var honsyabikou2 = $("#sav_tb tr:nth-child(10) input").val(); var noukikakutei = $("#sav_tb tr:nth-child(11) input").val(); var koushinbi = $("#sav_tb tr:nth-child(12) input").val(); var sakuseibi = $("#sav_tb tr:nth-child(13) input").val(); // nouki // if (nouki != ""){ nouki = nouki.replace(/\//g,"-"); var d = new Date(nouki); var mth = d.getMonth() + 1; if( 1 <= mth && 12 >= mth && 10 > mth ){ mth = '0' + mth; }else if( 1 <= mth && 12 >= mth ){ mth = mth; }else{ alert("納期を確認してください(YYYY-MM-DD)"); return; } var day = d.getDate(); if( 1 <= day && 31 >= day && 10 > day ){ day = '0' + day; }else if( 1 <= day && 31 >= day ){ day = day; }else{ alert("納期を確認してください(YYYY-MM-DD)"); return; } nouki = d.getFullYear() + "-" + mth + "-" + day; $("#sav_tb tr:nth-child(5) input").val(nouki); } // suryo tanka // if((!isNaN(suryo)) && (!isNaN(tanka))){ kingaku = suryo * tanka; $("#sav_tb tr:nth-child(8) input").val(kingaku); }else{ alert("数量と単価を確認してください"); return; } // kouban // if(isNaN(kouban)){ alert("工番を確認してください"); return; } if(confirm('登録しますか?')){ $.post('_save.php',{ kubun: kubun, katashiki: katashiki, kouban: kouban, suryo: suryo, nouki: nouki, tokuisaki: tokuisaki, tanka: tanka, kingaku: kingaku, honsyabikou1: honsyabikou1, honsyabikou2: honsyabikou2, noukikakutei: noukikakutei, koushinbi: koushinbi, sakuseibi: sakuseibi },function(){ location.href="?view=受注一覧&offset=0"; }); } }); // 中止 // $(document).on('click', '#abt', function(){ location.href="?view=受注一覧&offset=0"; }); }); </script> </body> </html> HTML; exit; } // 受注一覧 在庫一覧 // if( $_GET['view'] == "在庫一覧" ){ echo $_GET['view']; $sql = "select * from order_tb where (入庫 is not null) and (出庫 is null)"; $cntsql = "select count(*) from order_tb where (入庫 is not null) and (出庫 is null)"; if (array_key_exists('型',$_GET)){ $sql = $sql . " and (型式 like '%" . $_GET['型'] . "%')"; $cntsql = $cntsql . " and (型式 like '%" . $_GET['型'] . "%')"; } if (array_key_exists('工',$_GET)){ $sql = $sql . " and (工番 like '%" . $_GET['工'] . "%')"; $cntsql = $cntsql . " and (工番 like '%" . $_GET['工'] . "%')"; } if (array_key_exists('納',$_GET) && $_GET['納'] != ""){ $sql = $sql . " and (納期 like '%" . date("Y-m-d", strtotime($_GET['納'])) . "%')"; $cntsql = $cntsql . " and (納期 like '%" . date("Y-m-d", strtotime($_GET['納'])) . "%')"; } if (array_key_exists('得',$_GET)){ $sql = $sql . " and (得意先 like '%" . $_GET['得'] . "%')"; $cntsql = $cntsql . " and (得意先 like '%" . $_GET['得'] . "%')"; } if (array_key_exists('本',$_GET)){ $sql = $sql . " and ((本社備考1 like '%" . $_GET['本'] . "%')"; $sql = $sql . " or (本社備考2 like '%" . $_GET['本'] . "%'))"; $cntsql = $cntsql . " and ((本社備考1 like '%" . $_GET['本'] . "%')"; $cntsql = $cntsql . " or (本社備考2 like '%" . $_GET['本'] . "%'))"; } if (array_key_exists('更',$_GET) && $_GET['更'] != ""){ $sql = $sql . " and (更新日 like '%" . date("Y-m-d", strtotime($_GET['更'])) . "%')"; $cntsql = $cntsql . " and (更新日 like '%" . date("Y-m-d", strtotime($_GET['更'])) . "%')"; } if (array_key_exists('作',$_GET) && $_GET['作'] != ""){ $sql = $sql . " and (作成日 like '%" . date("Y-m-d", strtotime($_GET['作'])) . "%')"; $cntsql = $cntsql . " and (作成日 like '%" . date("Y-m-d", strtotime($_GET['作'])) . "%')"; } $sql = $sql . " limit " . $_GET['offset'] . ",100;"; $cntsql = $cntsql . ";"; }elseif( $_GET['view'] == "受注一覧" ){ echo $_GET['view']; $sql = "select * from order_tb where (id is not null)"; $cntsql = "select count(*) from order_tb where (id is not null)"; if (array_key_exists('型',$_GET)){ $sql = $sql . " and (型式 like '%" . $_GET['型'] . "%')"; $cntsql = $cntsql . " and (型式 like '%" . $_GET['型'] . "%')"; } if (array_key_exists('工',$_GET)){ $sql = $sql . " and (工番 like '%" . $_GET['工'] . "%')"; $cntsql = $cntsql . " and (工番 like '%" . $_GET['工'] . "%')"; } if (array_key_exists('納',$_GET) && $_GET['納'] != ""){ $sql = $sql . " and (納期 like '%" . date("Y-m-d", strtotime($_GET['納'])) . "%')"; $cntsql = $cntsql . " and (納期 like '%" . date("Y-m-d", strtotime($_GET['納'])) . "%')"; } if (array_key_exists('得',$_GET)){ $sql = $sql . " and (得意先 like '%" . $_GET['得'] . "%')"; $cntsql = $cntsql . " and (得意先 like '%" . $_GET['得'] . "%')"; } if (array_key_exists('本',$_GET)){ $sql = $sql . " and ((本社備考1 like '%" . $_GET['本'] . "%')"; $sql = $sql . " or (本社備考2 like '%" . $_GET['本'] . "%'))"; $cntsql = $cntsql . " and ((本社備考1 like '%" . $_GET['本'] . "%')"; $cntsql = $cntsql . " or (本社備考2 like '%" . $_GET['本'] . "%'))"; } if (array_key_exists('更',$_GET) && $_GET['更'] != ""){ $sql = $sql . " and (更新日 like '%" . date("Y-m-d", strtotime($_GET['更'])) . "%')"; $cntsql = $cntsql . " and (更新日 like '%" . date("Y-m-d", strtotime($_GET['更'])) . "%')"; } if (array_key_exists('作',$_GET) && $_GET['作'] != ""){ $sql = $sql . " and (作成日 like '%" . date("Y-m-d", strtotime($_GET['作'])) . "%')"; $cntsql = $cntsql . " and (作成日 like '%" . date("Y-m-d", strtotime($_GET['作'])) . "%')"; } $sql = $sql . " limit " . $_GET['offset'] . ",100;"; $cntsql = $cntsql . ";"; }else{ echo <<< HTML <a href="?view=受注一覧&offset=0">受注一覧(入出庫管理)</a> </div><!--header--> </body> </html> HTML; exit; } $db = con(); $rows = array(); $s = $db->query($cntsql); if (array_key_exists('型',$_GET)){ echo "(検索結果)"; } $cnt = $s->fetchColumn(); echo " " .$cnt . "件取得しました"; foreach($db->query($sql) as $row){ array_push($rows, $row); } ?> <form method="GET" id="frm"> <input type="submit" value="受注一覧" name="view"> <input type="submit" value="在庫一覧" name="view"> <input type="hidden" value="0" name="offset"> <?php if($_GET['offset'] > 0 && array_key_exists('型', $_GET)): ?> <a href="?view=<?php echo $_GET['view']; ?>&offset=<?php echo $_GET['offset'] - 100; ?> &型=<?php echo $_GET['型']; ?> &工=<?php echo $_GET['工']; ?> &納=<?php echo $_GET['納']; ?> &得=<?php echo $_GET['得']; ?> &本=<?php echo $_GET['本']; ?> &更=<?php echo $_GET['更']; ?> &作=<?php echo $_GET['作']; ?> ">前へ</a> <?php elseif($_GET['offset'] > 0): ?> <a href="?view=<?php echo $_GET['view']; ?>&offset=<?php echo $_GET['offset'] - 100; ?>">前へ</a> <?php else: ?> 前へ <?php endif; ?> <?php if($_GET['offset'] + 100 < $cnt && array_key_exists('型', $_GET)): ?> <a href="?view=<?php echo $_GET['view']; ?>&offset=<?php echo $_GET['offset'] + 100; ?> &型=<?php echo $_GET['型']; ?> &工=<?php echo $_GET['工']; ?> &納=<?php echo $_GET['納']; ?> &得=<?php echo $_GET['得']; ?> &本=<?php echo $_GET['本']; ?> &更=<?php echo $_GET['更']; ?> &作=<?php echo $_GET['作']; ?> ">次へ</a> <?php elseif($_GET['offset'] + 100 < $cnt): ?> <a href="?view=<?php echo $_GET['view']; ?>&offset=<?php echo $_GET['offset'] + 100; ?>">次へ</a> <?php else: ?> 次へ <?php endif; ?> <?php if($_GET['offset'] < (($cnt-1) - (($cnt-1) % 100)) && array_key_exists('型', $_GET)): ?> <a href="?view=<?php echo $_GET['view']; ?>&offset=<?php echo ($cnt-1) - (($cnt-1) % 100); ?> &型=<?php echo $_GET['型']; ?> &工=<?php echo $_GET['工']; ?> &納=<?php echo $_GET['納']; ?> &得=<?php echo $_GET['得']; ?> &本=<?php echo $_GET['本']; ?> &更=<?php echo $_GET['更']; ?> &作=<?php echo $_GET['作']; ?> ">最後へ</a> <?php elseif($_GET['offset'] < (($cnt-1) - (($cnt-1) % 100))): ?> <a href="?view=<?php echo $_GET['view']; ?>&offset=<?php echo ($cnt-1) - (($cnt-1) % 100); ?>">最後へ</a> <?php else: ?> 最後へ <?php endif; ?> (<?php echo $_GET['offset'] + 1; ?>から<?php echo $_GET['offset'] + 100; ?>まで) </form> <form method="GET" id="frm"> <input type="submit" value="登録" name="save"> <input type="button" id="csv" value="書出"> </form> <form method="GET" id="frm"> 型:<input type="text" value="<?php echo $_GET['型']; ?>" size="8" name="型"> 工:<input type="text" value="<?php echo $_GET['工']; ?>" size="8" name="工"> 納:<input type="text" value="<?php echo $_GET['納']; ?>" size="8" name="納" id="n"> 得:<input type="text" value="<?php echo $_GET['得']; ?>" size="8" name="得"> 本:<input type="text" value="<?php echo $_GET['本']; ?>" size="8" name="本"> 更:<input type="text" value="<?php echo $_GET['更']; ?>" size="8" name="更"> 作:<input type="text" value="<?php echo $_GET['作']; ?>" size="8" name="作"> <input type="hidden" value="<?php echo $_GET['view']; ?>" name="view"> <input type="hidden" value="0" name="offset"> <input type="submit" value="取得">: </form> </div><!-- header --> <div id="view"> <table id="view_tb"> <tr> <th>区分</th> <th>型式</th> <th>工番</th> <th>数量</th> <th>納期</th> <th>得意先</th> <th>単価</th> <th>金額</th> <th>本社備考1</th> <th>本社備考2</th> <th>納期確定</th> <th>更新日</th> <th>作成日</th> <th>入庫</th> <th>出庫</th> <th>入庫</th> <th>出庫</th> <th>入消</th> <th>出消</th> <th></th> <th>分割</th> <th>回数</th> <th>削除</th> </tr> <?php for($i = 0, $total = 0; $i < count($rows); $i++ ): ?> <tr id="r_<?php echo $rows[$i][0]; ?>" data-id="<?php echo $rows[$i][0]; ?>"> <td><?php echo $rows[$i][2]; ?></td> <td><?php echo $rows[$i][4]; ?></td> <td><?php echo $rows[$i][5]; ?></td> <td><?php echo $rows[$i][9]; ?></td> <td><?php echo $rows[$i][10]; ?></td> <td><?php echo $rows[$i][15]; ?></td> <td class="lnk yen" id="plice"><?php echo $rows[$i][16]; ?></td> <td class="yen"><?php echo $rows[$i][17]; ?></td> <td><?php echo $rows[$i][18]; ?></td> <td><?php echo $rows[$i][19]; ?></td> <td><?php echo $rows[$i][20]; ?></td> <td><?php echo $rows[$i][22]; ?></td> <td><?php echo $rows[$i][23]; ?></td> <td><?php echo $rows[$i][24]; ?></td> <td><?php echo $rows[$i][25]; ?></td> <td class="lnk" id="rcv">[入庫]</td> <td class="lnk" id="shp">[出庫]</td> <td class="lnk" id="d_rcv">[入消]</td> <td class="lnk" id="d_shp">[出消]</td> <td><input id="inp" type="text" size="1"></td> <td class="lnk" id="sp">[分割]</td> <td><?php echo $rows[$i][26]; ?></td> <td class="lnk" id="del">[削除]</td> </tr> <?php $total = $total + $rows[$i][17]; ?> <?php endfor; ?> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="yen"><?php echo number_format($total); ?></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> </table> </div><!--view--> <script> $(function(){ // 削除 // $(document).on('click', '#del', function(){ if(confirm('削除しますか?')){ var id = $(this).parent().data('id'); $.post('_delete.php',{id: id},function(){ $('#r_' + id).fadeOut(300); location.reload(); }); } }); // 入庫 // $(document).on('click', '#rcv', function(){ if(confirm('入庫しますか?')){ var id = $(this).parent().data('id'); $.post('_rcv.php',{id: id},function(rs){ $('#r_' + id + " > td:nth-child(14)").text(rs); }); } }); // 出庫 // $(document).on('click', '#shp', function(){ if(confirm('出庫しますか?')){ var id = $(this).parent().data('id'); $.post('_shp.php',{id: id},function(rs){ $('#r_' + id + " > td:nth-child(15)").text(rs); }); } }); // 入消 // $(document).on('click', '#d_rcv', function(){ if(confirm('入庫を取消しますか?')){ var id = $(this).parent().data('id'); $.post('_d_rcv.php',{id: id},function(){ $('#r_' + id + " > td:nth-child(14)").text(""); }); } }); // 出消 // $(document).on('click', '#d_shp', function(){ if(confirm('出庫を取消しますか?')){ var id = $(this).parent().data('id'); $.post('_d_shp.php',{id: id},function(){ $('#r_' + id + " > td:nth-child(15)").text(""); }); } }); // 分割 // $(document).on('click', '#sp', function(){ var id = $(this).parent().data('id'); var num = parseInt($('#r_' + id + " > td:nth-child(4)").text()); var plice = parseInt($('#r_' + id + " > td:nth-child(7)").text()); var p_num = parseInt($('#r_' + id + ' input').val()); if(!isNaN(p_num) && num > p_num && p_num > 0){ if(confirm('受注数 ' + num + ' から ' + p_num + ' を別の行に複製します')){ num = num - p_num; $.post('_pull_num.php',{id: id, num: num, p_num: p_num, plice: plice},function(){ $('#r_' + id).fadeOut(300,function(){ location.reload(); }); }); } } }); // 単価 // $(document).on('click', '#plice',function(){ var id = $(this).parent().data('id'); var num = parseInt($('#r_' + id + " > td:nth-child(4)").text()); var plice = parseInt(prompt("単価を入力してください")); if(!isNaN(plice) && !isNaN(plice * num)){ $.post('_plice.php',{id: id, num: num, plice: plice},function(){ $('#r_' + id + " > td:nth-child(7)").text(plice); $('#r_' + id + " > td:nth-child(8)").text(plice * num); location.reload(); }); } }); // 書出 // var flg = true; $(document).on('click', '#csv',function(){ if(flg){ flg = false; $("#view_tb th:nth-child(n+16):nth-child(-n+21), td:nth-child(n+16):nth-child(-n+21)").remove(); $("#view_tb th:nth-last-child(1), td:nth-last-child(1)").remove(); $("#header").css("display","none"); $("#bk").css("display","inline"); } }); }); </script> </body> </html> |
C# VBA 在庫管理
以前作ったプログラムお蔵入り版
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 |
AccessVBA テーブル作成、他
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 |
Sub test() 'テーブル作成 -------------------------------------------------------- Set t = CurrentDb.CreateTableDef("ttest") Set f = t.CreateField("id", dbDate) t.Fields.Append f CurrentDb.TableDefs.Append t 'パススルークエリ作成 -------------------------------------------------------- 'SQLServerへ接続 queryName = "test" For i = 0 To CurrentDb.QueryDefs.Count - 1 If CurrentDb.QueryDefs(i).Name = queryName Then CurrentDb.QueryDefs.Delete queryName Next i Set t = CurrentDb.CreateQueryDef(queryName) With t .Connect = "ODBC; Driver=SQL Server; Server=ESPRIMO\SQLEXPRESS; Database=my_database" .ReturnsRecords = True .SQL = "SELECT * FROM tbl;" End With Set t = Nothing '更新系などのパススルークエリも作成できる -------------------------------------------------------- queryName = "test" For i = 0 To CurrentDb.QueryDefs.Count - 1 If CurrentDb.QueryDefs(i).Name = queryName Then CurrentDb.QueryDefs.Delete queryName Next i Set t = CurrentDb.CreateQueryDef(queryName) With t .Connect = "ODBC; Driver=SQL Server; Server=ESPRIMO\SQLEXPRESS;Database=my_database" .ReturnsRecords = False .SQL = "DELETE FROM tbl;" End With Set t = Nothing 'リンクテーブル(mdbへ接続) -------------------------------------------------------- Set t = CurrentDb.CreateTableDef("AccessLink") t.Connect = ";DATABASE=" & Application.CurrentProject.Path & "/tmp.mdb;" t.SourceTableName = "tbl" CurrentDb.TableDefs.Append t 'テーブル削除 -------------------------------------------------------- tableName = "test_tbl" For i = 0 To CurrentDb.TableDefs.Count - 1 If CurrentDb.TableDefs(i).Name = tableName Then CurrentDb.TableDefs.Delete tableName Exit For End If Next i 'クエリの実行 -------------------------------------------------------- 'new_tableを作成しold_tableのデータをnew_tableへ入れる。 CurrentDb.Execute "select * into new_table from old_table" 'new_tableにold_tableのデータを入れる。 CurrentDb.Execute "insert into new_table select * from old_table" End Sub |