private bool checkInputData(DataGridView dgv) { string checkStr; for (int i = 0; i < dgv.RowCount; i++) { if (dgv.Rows[i].Cells["Cost"].Value != null) { for (int j = 3; j < dgv.ColumnCount; j++) { if (j != 4) { checkStr = Convert.ToString(dgv.Rows[i].Cells[j].Value); if (checkStr == null || checkStr == "") { } else { if (!DHandling.IsDecimal(checkStr)) { DMessage.ValueErrMsg(); //dgv[j, i].Style.BackColor = Color.Red; dgv.CurrentCell = dgv[j, i]; return(false); } } } } } } return(true); }
private void calculateLine(DataGridViewRow dgvRow) { // Wakamatsu 20170307 //if (!(DHandling.IsDecimal(Convert.ToString(dgvRow.Cells["Quantity"].Value)))) return; //if (Convert.ToString(dgvRow.Cells["UnitPrice"].Value) == "") return; //decimal calcUnitPrice = toRegDecimal(Convert.ToString(dgvRow.Cells["UnitPrice"].Value)); //decimal calcQuantity = toRegDecimal(Convert.ToString(dgvRow.Cells["Quantity"].Value)); decimal calcQuantity = 0; decimal calcUnitPrice = 0; if ((DHandling.IsDecimal(Convert.ToString(dgvRow.Cells["Quantity"].Value)))) { calcQuantity = toRegDecimal(Convert.ToString(dgvRow.Cells["Quantity"].Value)); } if ((DHandling.IsDecimal(Convert.ToString(dgvRow.Cells["UnitPrice"].Value)))) { calcUnitPrice = toRegDecimal(Convert.ToString(dgvRow.Cells["UnitPrice"].Value)); } // Wakamatsu 20170307 decimal calcCost = calcUnitPrice * calcQuantity; dgvRow.Cells["Quantity"].Value = decPointFormat(calcQuantity); dgvRow.Cells["UnitPrice"].Value = decFormat(calcUnitPrice); dgvRow.Cells["Cost"].Value = decFormat(calcCost); calculateAmount(); }
private bool checkDecimalValue(string checkStr) { if (!String.IsNullOrEmpty(checkStr)) { if (!DHandling.IsDecimal(checkStr)) { DMessage.ValueErrMsg(); return(false); } } return(true); }
// Cellの内容に変化があったとき private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (iniPro) { return; // 初期化中 } DataGridView dgv = ( DataGridView )sender; string WorkString = ""; switch (e.ColumnIndex) { case 0: // 「削除」チェックボックス列 break; case 1: // 「No.」列 break; case 2: // 「原価コード」列 break; case 3: // 「注文番号」列 break; case 4: // 「原価内容」列 break; case 5: // 「業務番号」列 break; case 6: // 「業務名」列 break; case 7: // 「発注金額」列 if (Convert.ToString(dgv.Rows[e.RowIndex].Cells["OAmount"].Value) == "") { return; } WorkString = Convert.ToString(dgv.Rows[e.RowIndex].Cells["OAmount"].Value); if (!(DHandling.IsDecimal(WorkString))) { WorkString = "0"; } dgv.Rows[e.RowIndex].Cells["OAmount"].Value = decFormat(Convert.ToDecimal(WorkString)); calculateInvolvedItems(dgv.Rows[e.RowIndex]); break; case 8: // 「前月累計出来高」列 if (Convert.ToString(dgv.Rows[e.RowIndex].Cells["SAmount"].Value) == "") { return; } WorkString = Convert.ToString(dgv.Rows[e.RowIndex].Cells["SAmount"].Value); if (!(DHandling.IsDecimal(WorkString))) { WorkString = "0"; } dgv.Rows[e.RowIndex].Cells["SAmount"].Value = decFormat(Convert.ToDecimal(WorkString)); break; case 9: // 「今月出来高」列 if (Convert.ToString(dgv.Rows[e.RowIndex].Cells["Amount"].Value) == "") { return; } WorkString = Convert.ToString(dgv.Rows[e.RowIndex].Cells["Amount"].Value); if (!(DHandling.IsDecimal(WorkString))) { WorkString = "0"; } dgv.Rows[e.RowIndex].Cells["Amount"].Value = decFormat(Convert.ToDecimal(WorkString)); calculateInvolvedItems(dgv.Rows[e.RowIndex]); updateStat = true; break; case 10: // 「発注残額」列 break; case 11: // 「伝票番号」列 if (dgv.Rows[e.RowIndex].Cells["SlipNo"].Value == null || Convert.ToString(dgv.Rows[e.RowIndex].Cells["SlipNo"].Value) == "") { return; } WorkString = Convert.ToString(dgv.Rows[e.RowIndex].Cells["SlipNo"].Value); if (!(DHandling.IsNumeric(WorkString))) { WorkString = ""; } dgv.Rows[e.RowIndex].Cells["SlipNo"].Value = WorkString; break; default: break; } //updateStat = true; }