/*************************************************************
  * 商品検索/取引先検索の検索データを設定する
  *************************************************************/
 private void setSelectData(Const.SEARCH_TYPE type)
 {
     Form_Common_SelectData form = new Form_Common_SelectData(type);
     form.ShowDialog();
     if (form.DialogResult == DialogResult.OK)
     {
         string code = (string)form.dataGridView.SelectedRows[0].Cells[0].Value;
         string name = (string)form.dataGridView.SelectedRows[0].Cells[1].Value;
         string note = (string)form.dataGridView.SelectedRows[0].Cells[2].Value;
         string unit = (string)form.dataGridView.SelectedRows[0].Cells[3].Value;
         switch (type)
         {
             case Const.SEARCH_TYPE.Product:
                 productCode.Text = code;
                 productName.Text = name;
                 saleUnit.Text = unit;
                 break;
             case Const.SEARCH_TYPE.Supplier:
                 suppllierCode.Text = code;
                 suppllierName.Text = name;
                 break;
         }
     }
     form.Dispose();
 }
        /*************************************************************
         * データグリッドビューのテキストをワンクリックで編集可能とする
         *************************************************************/
        private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridView dgv = (DataGridView)sender;

            if (e.ColumnIndex > decimal.MinusOne && e.RowIndex > decimal.MinusOne)
            {
                if (dgv.Columns[e.ColumnIndex] is DataGridViewTextBoxColumn)
                {
                    SendKeys.Send("{F2}");
                }

                if (dgv.Columns[e.ColumnIndex] is DataGridViewButtonColumn)
                {

                    // 原料名検索
                    if (dgv.CurrentCell.OwningColumn.Name == "dgvMaterialCostBtn")
                    {
                        Form_Common_SelectData form = new Form_Common_SelectData(Const.SEARCH_TYPE.Material);
                        form.ShowDialog();
                        if (form.DialogResult == DialogResult.OK)
                        {
                            string code = (string)form.dataGridView.SelectedRows[0].Cells[0].Value;
                            if (DataTableSupport.containsKey((DataTable)dgvMaterialCostName.DataSource, code))
                            {
                                dgvMaterialCost.Rows[e.RowIndex].Cells["dgvMaterialCostName"].Value = code;
                                dgvMaterialCost.Rows[e.RowIndex].Cells["dgvMaterialCostPrice"].Value = DataTableSupport.getPrice((DataTable)dgvMaterialCostName.DataSource, code).ToString("N");

                                if (e.RowIndex == dgvMaterialCost.NewRowIndex)
                                {
                                    dgvMaterialCost.BeginEdit(false);
                                    dgvMaterialCost.CurrentCell = dgvMaterialCost[2, dgvMaterialCost.NewRowIndex];
                                    dgvMaterialCost.NotifyCurrentCellDirty(true);
                                }
                            }
                        }
                    }

                    // 包装資材費検索
                    if (dgv.CurrentCell.OwningColumn.Name == "dgvPackingBtn")
                    {
                        Form_Common_SelectData form = new Form_Common_SelectData(Const.SEARCH_TYPE.Packing);
                        form.ShowDialog();
                        if (form.DialogResult == DialogResult.OK)
                        {
                            string code = (string)form.dataGridView.SelectedRows[0].Cells[0].Value;
                            if (DataTableSupport.containsKey((DataTable)dgvPackingName.DataSource, code))
                            {
                                dgvPacking.Rows[e.RowIndex].Cells["dgvPackingName"].Value = code;
                                dgvPacking.Rows[e.RowIndex].Cells["dgvPackingCost"].Value = DataTableSupport.getPrice((DataTable)dgvPackingName.DataSource, code).ToString("N");

                                if (e.RowIndex == dgvPacking.NewRowIndex)
                                {
                                    dgvPacking.BeginEdit(false);
                                    dgvPacking.CurrentCell = dgvPacking[2, dgvPacking.NewRowIndex];
                                    dgvPacking.NotifyCurrentCellDirty(true);
                                }
                            }
                        }
                    }
                    calcAll();
                }
            }
        }
        /*************************************************************
         * データグリッドビューのクリック時のイベント処理
         *************************************************************/
        private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridView dgv = (DataGridView)sender;

            if (e.ColumnIndex > decimal.MinusOne && e.RowIndex > decimal.MinusOne)
            {
                // ブレンド割合のテキストボックス
                if (dgv.Columns[e.ColumnIndex] is DataGridViewTextBoxColumn)
                {
                    SendKeys.Send("{F2}");
                }

                // 商品検索の処理
                if (dgv.Columns[e.ColumnIndex] is DataGridViewButtonColumn)
                {
                    Form_Common_SelectData form = new Form_Common_SelectData(Const.SEARCH_TYPE.Product);
                    form.ShowDialog();
                    if (form.DialogResult == DialogResult.OK)
                    {
                        string code = (string)form.dataGridView.SelectedRows[0].Cells[0].Value;
                        setProductData(code, e.RowIndex);
                        setPackingFareData(code, suppllierCode.Text, e.RowIndex);

                        if (e.RowIndex == dgvProduct.NewRowIndex)
                        {
                            dgvProduct.BeginEdit(false);
                            dgvProduct.CurrentCell = dgvProduct[3, dgvProduct.NewRowIndex];
                            dgvProduct.NotifyCurrentCellDirty(true);
                        }
                    }
                    calcAll();
                }
            }
        }