Exemplo n.º 1
0
        // サブプロシージャ:データグリットビューの更新
        public void updateDataGridViews(ref DataTable dt, ref DataGridView dgv)
        {
            string   batchNo       = txtBatchNo.Text;
            string   modelNo       = cmbModelNo.Text;
            string   modelName     = txtModelName.Text;
            string   subAssyName   = cmbSubAssy.Text;
            DateTime batchDate     = dtpBatchDate.Value.Date;
            DateTime batchNextDate = dtpBatchDate.Value.Date.AddDays(1);
            string   shift         = cmbShift.Text;
            string   line          = cmbLine.Text;
            string   leader        = txtLeaderId.Text;
            string   leaderName    = txtLeaderName.Text;
            bool     b_batch       = chkBatch.Checked;
            bool     b_model       = chkModel.Checked;
            bool     b_subAssy     = chkSubAssy.Checked;
            bool     b_batchDate   = chkBatchDate.Checked;
            bool     b_shift       = chkShift.Checked;
            bool     b_line        = chkLine.Checked;
            bool     b_leader      = chkLeader.Checked;



            string sql1 = "select approve_by, check_by, batch_no, model_no, model_name, sub_assy_no, sub_assy_name, batch_date, " +
                          "shift, line, leader_id, leader_name, in_qty, out_qty, in_time, out_time, remark from t_batch_no where ";

            bool[] cr = { batchNo == String.Empty ? false : true,
                          modelNo == String.Empty ? false : true,
                          subAssyNo == String.Empty ? false : true,
                          true,
                          shift == String.Empty ? false : true,
                          line == String.Empty ? false : true,
                          leader == String.Empty ? false : true };

            bool[] ck = { b_batch,
                          b_model,
                          b_subAssy,
                          b_batchDate,
                          b_shift,
                          b_line,
                          b_leader };

            string sql2 = (!(cr[0] && ck[0]) ? String.Empty : "batch_no like '" + batchNo + "%' AND ") +
                          (!(cr[1] && ck[1]) ? String.Empty : "model_no = '" + modelNo + "' AND ") +
                          (!(cr[2] && ck[2]) ? String.Empty : "sub_assy_no = '" + subAssyNo + "' AND ") +
                          (!(cr[3] && ck[3]) ? String.Empty : "batch_date >= '" + batchDate + "' AND batch_date < '" + batchNextDate + "' AND ") +
                          (!(cr[4] && ck[4]) ? String.Empty : "shift = '" + shift + "' AND ") +
                          (!(cr[5] && ck[5]) ? String.Empty : "line = '" + line + "' AND ") +
                          (!(cr[6] && ck[6]) ? String.Empty : "leader_id = '" + leader + "' AND ");

            bool b_all = (cr[0] && ck[0]) || (cr[1] && ck[1]) || (cr[2] && ck[2]) || (cr[3] && ck[3]) || (cr[4] && ck[4]) ||
                         (cr[5] && ck[5]) || (cr[6] && ck[6]);

            System.Diagnostics.Debug.Print(b_all.ToString());
            System.Diagnostics.Debug.Print(cr[0].ToString() + " " + ck[0].ToString() + " " + cr[1].ToString() + " " + ck[1].ToString() + " " +
                                           cr[2].ToString() + " " + ck[2].ToString() + " " + cr[3].ToString() + " " + ck[3].ToString() + " " +
                                           cr[4].ToString() + " " + ck[4].ToString() + cr[5].ToString() + " " + ck[5].ToString() + " " + cr[6].ToString() + " " + ck[6].ToString());

            if (!b_all)
            {
                MessageBox.Show("Please select at least one check box and fill the criteria.", "Notice",
                                MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2);
                return;
            }

            string sql3 = sql1 + VBStrings.Left(sql2, sql2.Length - 5);

            System.Diagnostics.Debug.Print(sql3);

            dt.Clear();
            TfSQL tf = new TfSQL();

            tf.sqlDataAdapterFillDatatable(sql3, ref dt);

            // データグリットビューへDTAATABLEを格納
            dgv.DataSource          = dt;
            dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;

            //行ヘッダーに行番号を表示する
            for (int i = 0; i < dgv.Rows.Count; i++)
            {
                dgv.Rows[i].HeaderCell.Value = (i + 1).ToString();

                if (dgv.Rows[i].Cells[1].Value.ToString() != "")
                {
                    dgv.Rows[i].Cells[0].Value    = true;
                    dgv.Rows[i].Cells[0].ReadOnly = true;
                }
                else
                {
                    dgv.Rows[i].Cells[0].Value = false;
                }

                if (dgv.Rows[i].Cells[2].Value.ToString() == "")
                {
                    dgv.Rows[i].Cells[0].ReadOnly = true;
                }
            }
            //行ヘッダーの幅を自動調節する
            dgv.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders);

            // 一番下の行を表示する
            if (dgv.Rows.Count != 0)
            {
                dgv.FirstDisplayedScrollingRowIndex = dgv.Rows.Count - 1;
            }
        }