// サブプロシージャ:DBからのDTHISTORYへの読み込み private void readDtHistory(ref DataTable dt) { dt.Clear(); string model = txtModel.Text; string process = txtProcess.Text; string inspect = txtInspect.Text; DateTime lotFrom = dtpLotFrom.Value; DateTime lotTo = dtpLotTo.Value; string line = txtLine.Text; string sql = "select inspect, lot, inspectdate, line, qc_user, " + "m1, m2, m3, m4, m5, x, r FROM tbl_measure_history " + "WHERE model = '" + model + "' AND " + "process = '" + process + "' AND " + "inspect = '" + inspect + "' AND " + "lot >= '" + lotFrom.ToString() + "' AND " + "lot <= '" + lotTo.ToString() + "' AND " + "line = '" + line + "' " + "order by lot, inspectdate"; System.Diagnostics.Debug.Print(sql); TfSQL tf = new TfSQL(); tf.sqlDataAdapterFillDatatable(sql, ref dt); }
// ロード時の処理(コンボボックスに、オートコンプリート機能の追加) private void Form5_Load(object sender, EventArgs e) { string sql = "select DISTINCT qcuser FROM qc_user ORDER BY qcuser"; TfSQL tf = new TfSQL(); tf.getComboBoxData(sql, ref cmbUserName); }
// サブプロシージャ:上限・下限、行セット・列セット、コマンド、の設定 private void setLimitSetAndCommand(ref DataTable dt) { dt.Clear(); string sql = "select upper, lower, clm_set, row_set, instrument from tbl_measure_item_2 " + "where model = '" + txtModel.Text + "' and " + "inspect = '" + txtInspect.Text + "'"; System.Diagnostics.Debug.Print(sql); TfSQL tf = new TfSQL(); tf.sqlDataAdapterFillDatatable(sql, ref dt); upp = (double)dt.Rows[0]["upper"]; txtUsl.Text = upp.ToString(); low = (double)dt.Rows[0]["lower"]; txtLsl.Text = low.ToString(); rowSet = (int)dt.Rows[0]["row_set"]; clmSet = (int)dt.Rows[0]["clm_set"]; if (dt.Rows[0]["instrument"].ToString() == "mmx") { command = xquery; } else if (dt.Rows[0]["instrument"].ToString() == "mmy") { command = yquery; } }
// ユーザーログイン時、パスワードとログイン状態の確認(2重ログインの防止) private void btnLogIn_Click(object sender, EventArgs e) { string sql = null; string user = null; string pass = null; bool login = false; user = cmbUserName.Text; if (user != null) { TfSQL tf = new TfSQL(); sql = "select pass FROM qc_user WHERE qcuser='******'"; pass = tf.sqlExecuteScalarString(sql); sql = "select loginstatus FROM qc_user WHERE qcuser='******'"; login = tf.sqlExecuteScalarBool(sql); if (pass == txtPassword.Text) { if (login) { DialogResult reply = MessageBox.Show("This user account is currently used by other user," + System.Environment.NewLine + "or the log out last time had a problem." + System.Environment.NewLine + "Do you log in with this account ?", "Notice", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (reply == DialogResult.No) { return; } } // ログイン状態をTRUEへ変更 sql = "UPDATE qc_user SET loginstatus=true WHERE qcuser='******'"; bool res = tf.sqlExecuteNonQuery(sql, false); // 子フォームForm1を表示し、デレゲートイベントを追加: frmItem f1 = new frmItem(); f1.RefreshEvent += delegate(object sndr, EventArgs excp) { // Form1を閉じる際、ログイン状態をFALSEへ変更し、当フォームForm5も閉じる sql = "UPDATE qc_user SET loginstatus=false WHERE qcuser='******'"; res = tf.sqlExecuteNonQuery(sql, false); this.Close(); }; f1.updateControls(user); f1.Show(); this.Visible = false; } else if (pass != txtPassword.Text) { MessageBox.Show("Password does not match", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
// 削除ボタン押下時の処理 private void btnDelete_Click(object sender, EventArgs e) { if (dtBuffer.Rows.Count <= 0) { return; } DialogResult result = MessageBox.Show("Do you really want to delete the selected row?", "Notice", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result == DialogResult.No) { MessageBox.Show("Delete process was canceled.", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2); } else if (result == DialogResult.Yes) { // データの削除 string sql = "delete from tbl_measure_history where " + "model='" + txtModel.Text + "' and " + "inspect='" + txtInspect.Text + "' and " + "lot ='" + dtBuffer.Rows[0]["lot"] + "' and " + "inspectdate ='" + dtBuffer.Rows[0]["inspectdate"] + "' and " + "line ='" + txtLine.Text + "'"; System.Diagnostics.Debug.Print(sql); TfSQL tf = new TfSQL(); int res = tf.sqlExecuteNonQueryInt(sql, false); // バックグラウンドでPQMテーブル内の削除 DataTable dtTemp = new DataTable(); dtTemp = dtBuffer.Copy(); deleteFromPqmTable(dtTemp); // 新規登録用バッファーテーブル、バッファーグリットビューを初期化する dtBuffer.Clear(); // 削除後テーブルの再読み込み readDtHistory(ref dtHistory); // HISTORYデータグリッドビューのマーキングをクリアする colorViewReset(ref dgvHistory); // グリットビューの更新 updateDataGripViews(dtBuffer, dtHistory, ref dgvBuffer, ref dgvHistory); // 編集モードフラグを下し、登録・修正ボタンを「登録」の表示にする editMode = false; btnRegister.Text = "Register"; dtpLotInput.Enabled = true; } }
// サブプロシージャ:型式コンボボックスへ候補を取り込む public void getComboListFromDB(ref ComboBox cmb) { string sql = "select model from tbl_model_dbplace order by model"; System.Diagnostics.Debug.Print(sql); TfSQL tf = new TfSQL(); tf.getComboBoxData(sql, ref cmb); if (cmbModel.Items.Count > 0) { cmbModel.SelectedIndex = 0; } }
// 既存測定値の修正 private void dgvHistory_CellContentClick(object sender, DataGridViewCellEventArgs e) { int curRow = int.Parse(e.RowIndex.ToString()); if (dgvHistory.Columns[e.ColumnIndex] == Open && curRow >= 0) { // 編集モードフラグを立て、登録・修正ボタンを「修正」の表示にする editMode = true; btnRegister.Text = "Update"; dtpLotInput.Enabled = false; // 新規登録用バッファーテーブル、バッファーグリットビューを初期化し、ボタンに対応する値を格納する dtBuffer.Clear(); string sql = "select inspect, lot, inspectdate, line, qc_user, " + "m1, m2, m3, m4, m5 FROM tbl_measure_history WHERE " + "model = '" + txtModel.Text + "' AND " + "inspect = '" + dgvHistory["inspect", curRow].Value.ToString() + "' AND " + "lot = '" + (DateTime)dgvHistory["lot", curRow].Value + "' AND " + "inspectdate = '" + (DateTime)dgvHistory["inspectdate", curRow].Value + "' AND " + "line = '" + dgvHistory["line", curRow].Value.ToString() + "' " + "order by qc_user"; System.Diagnostics.Debug.Print(sql); TfSQL tf = new TfSQL(); tf.sqlDataAdapterFillDatatable(sql, ref dtBuffer); // グリットビューの更新 updateDataGripViews(dtBuffer, dtHistory, ref dgvBuffer, ref dgvHistory); // 新規登録用グリットビュー(バッファテーブル)へ、ボタンを追加する if (dgvBuffer.Columns.Count <= 12) { addButtonsToDgvBuffer(dgvBuffer, edit1, edit2, edit3, edit4, edit5); } // 変更ターゲット行を表示する if (dgvHistory.Rows.Count >= 1) { dgvHistory.FirstDisplayedScrollingRowIndex = curRow; } // サブプロシージャ:編集中の行をマーキングする colorViewForEdit(ref dgvHistory, curRow); colorViewForEdit(ref dgvBuffer, 0); } }
// サブプロシージャ:参照すべき接続文字列を PQMテーブル名を特定する private string decideConnectionString(string model) { string sql = "select dbplace from tbl_model_dbplace where model='" + model + "'"; System.Diagnostics.Debug.Print(sql); TfSQL tf = new TfSQL(); string dbplace = tf.sqlExecuteScalarString(sql); if (dbplace == "HW2") { conStringPqmDb = conStringPqmDbP2; } else if (dbplace == "CAR") { conStringPqmDb = conStringPqmDbP4; } return(conStringPqmDb); }
// 測定値の取り込みが終わったら、データベースへ登録する private void btnRegister_Click(object sender, EventArgs e) { if (dtBuffer.Rows.Count <= 0) { return; } string model = txtModel.Text; string process = txtProcess.Text; string inspect = txtInspect.Text; DateTime lot = DateTime.Parse(dtBuffer.Rows[0]["lot"].ToString());; DateTime inspectdate = DateTime.Parse(dtBuffer.Rows[0]["inspectdate"].ToString());; string line = txtLine.Text; // ブァッファーテーブル内で、平均とレンジを計算する calculateAverageAndRangeInDataTable(ref dtBuffer); // IPQCDB 測定履歴テーブルに登録する TfSQL tf = new TfSQL(); bool res = tf.sqlMultipleInsert(model, process, inspect, lot, inspectdate, line, dtBuffer); if (res) { // バックグラウンドでPQMテーブルに登録する DataTable dtTemp = new DataTable(); dtTemp = dtBuffer.Copy(); registerMeasurementToPqmTable(dtTemp); // 登録済の状態を、当フォームに表示する dtBuffer.Clear(); readDtHistory(ref dtHistory); updateDataGripViews(dtBuffer, dtHistory, ref dgvBuffer, ref dgvHistory); // 編集モードフラグを立て、登録・修正ボタンを「登録」の表示に戻す editMode = false; btnRegister.Text = "Register"; dtpLotInput.Enabled = true; } }
// サブサブプロシージャ:グリットビュー右端にボタンを追加 private void addButtonsToDataGridView(DataGridView dgv) { dtLine.Clear(); string model = cmbModel.Text; string sql = "select line FROM tbl_model_line where model='" + model + "' order by line"; System.Diagnostics.Debug.Print(sql); TfSQL tf = new TfSQL(); tf.sqlDataAdapterFillDatatable(sql, ref dtLine); if (dtLine.Rows.Count == 0) { return; } if (line1 != null) { dgv.Columns.Remove(line1); line1 = null; } if (line2 != null) { dgv.Columns.Remove(line2); line2 = null; } if (line3 != null) { dgv.Columns.Remove(line3); line3 = null; } if (dtLine.Rows.Count >= 1) { line1 = new DataGridViewButtonColumn(); line1.Name = "line"; line1.Text = dtLine.Rows[0]["line"].ToString(); line1.UseColumnTextForButtonValue = true; line1.Width = 45; dgv.Columns.Add(line1); } if (dtLine.Rows.Count >= 2) { line2 = new DataGridViewButtonColumn(); line2.Name = "line"; line2.Text = dtLine.Rows[1]["line"].ToString(); line2.UseColumnTextForButtonValue = true; line2.Width = 45; dgv.Columns.Add(line2); } if (dtLine.Rows.Count >= 3) { line3 = new DataGridViewButtonColumn(); line3.Name = "line"; line3.Text = dtLine.Rows[2]["line"].ToString(); line3.UseColumnTextForButtonValue = true; line3.Width = 45; dgv.Columns.Add(line3); } }