private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { if (dataGridView1.CurrentCell.ColumnIndex == 10 && e.Control is ComboBox) { ComboBox comboBox = e.Control as ComboBox; comboBox.SelectedIndexChanged -= LastColumnComboSelectionChanged; comboBox.SelectedIndexChanged += LastColumnComboSelectionChanged; } if (dataGridView1.CurrentCell.ColumnIndex == 11) { var currentcell = dataGridView1.CurrentCellAddress; System.Windows.Forms.TextBox textBox = e.Control as System.Windows.Forms.TextBox; if (dataGridView1.Rows[currentcell.Y].Cells[11].ReadOnly == false) { string ID1 = ""; string num_date_invoice = dataGridView1.Rows[currentcell.Y].Cells[0].Value.ToString(); int i = 0; while (num_date_invoice[i] != ' ') { ID1 += num_date_invoice[i]; i++; } sum_for_pay r = new sum_for_pay(ID1, 2); r.StartPosition = FormStartPosition.CenterParent; r.ShowDialog(); LoadData("select * from table_billing order by num_of_bill desc"); } } e.CellStyle.ForeColor = Color.White; e.CellStyle.BackColor = Color.Gray; }
private void LastColumnComboSelectionChanged(object sender, EventArgs e) { var currentcell = dataGridView1.CurrentCellAddress; string num_date_invoice = dataGridView1.Rows[currentcell.Y].Cells[0].Value.ToString(); string previous_value = dataGridView1.Rows[currentcell.Y].Cells[10].Value.ToString(); int num; string ID1 = ""; int i = 0; while (num_date_invoice[i] != ' ') { ID1 += num_date_invoice[i]; i++; } OracleCommand cmd; string sum = ""; if (dataGridView1.Rows[currentcell.Y].Cells[currentcell.X].EditedFormattedValue.ToString() == "Выставлена") { num = 0; } else if (dataGridView1.Rows[currentcell.Y].Cells[currentcell.X].EditedFormattedValue.ToString() == "Часть оплаты") { num = 1; } else { //123 cmd = con.CreateCommand(); cmd.CommandText = $"select cost_deliv from table_billing where num_of_bill = {ID1}"; cmd.CommandType = CommandType.Text; OracleDataReader dr = cmd.ExecuteReader(); dr.Read(); sum = dr[0].ToString(); dr.Close(); num = 2; } if (num == 0 && previous_value != dataGridView1.Rows[currentcell.Y].Cells[currentcell.X].EditedFormattedValue.ToString()) { cmd = con.CreateCommand(); dataGridView1.Rows[currentcell.Y].Cells[11].ReadOnly = true; cmd.CommandText = $"UPDATE table_billing SET PROCESS = {num}, payment_amount = 0 where num_of_bill = {ID1}"; cmd.ExecuteNonQuery(); LoadData("select * from table_billing order by num_of_bill desc"); } else if (num == 1 && previous_value != dataGridView1.Rows[currentcell.Y].Cells[currentcell.X].EditedFormattedValue.ToString()) { sum_for_pay r = new sum_for_pay(ID1, 2); r.StartPosition = FormStartPosition.CenterParent; r.ShowDialog(); if (Data.yes == true) { cmd = con.CreateCommand(); dataGridView1.Rows[currentcell.Y].Cells[11].ReadOnly = false; cmd.CommandText = $"UPDATE table_billing SET PROCESS = {num} where num_of_bill = {ID1}"; cmd.ExecuteNonQuery(); LoadData("select * from table_billing order by num_of_bill desc"); } Data.yes = false; } else if (num == 2 && previous_value != dataGridView1.Rows[currentcell.Y].Cells[currentcell.X].EditedFormattedValue.ToString()) /////x = 10 { cmd = con.CreateCommand(); dataGridView1.Rows[currentcell.Y].Cells[11].ReadOnly = true; cmd.CommandText = $"UPDATE table_billing SET PROCESS = {num}, payment_amount = {sum} where num_of_bill = {ID1}"; cmd.ExecuteNonQuery(); LoadData("select * from table_billing order by num_of_bill desc"); } }
//1 private void LastColumnComboSelectionChanged(object sender, EventArgs e) { var DS = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator[0]; var currentcell = dataGridView_invoice.CurrentCellAddress; string num_date_invoice = dataGridView_invoice.Rows[currentcell.Y].Cells[0].Value.ToString(); string previous_value = dataGridView_invoice.Rows[currentcell.Y].Cells[10].Value.ToString(); int num; string ID1 = ""; int i = 0; while (num_date_invoice[i] != ' ') { ID1 += num_date_invoice[i]; i++; } OracleCommand cmd; string sum = ""; if (dataGridView_invoice.Rows[currentcell.Y].Cells[currentcell.X].EditedFormattedValue.ToString() == "Выставлена") { num = 0; } else if (dataGridView_invoice.Rows[currentcell.Y].Cells[currentcell.X].EditedFormattedValue.ToString() == "Часть оплаты") { num = 1; } else { //123 cmd = con.CreateCommand(); cmd.CommandText = $"select SUM_T from registration_of_invoice where ID = {ID1}"; cmd.CommandType = CommandType.Text; OracleDataReader dr = cmd.ExecuteReader(); dr.Read(); sum = dr[0].ToString().Replace(DS.ToString(), "."); dr.Close(); num = 2; } if (num == 0 && previous_value != dataGridView_invoice.Rows[currentcell.Y].Cells[currentcell.X].EditedFormattedValue.ToString()) { cmd = con.CreateCommand(); dataGridView_invoice.Rows[currentcell.Y].Cells[11].ReadOnly = true; cmd.CommandText = $"UPDATE REGISTRATION_OF_INVOICE SET PROCESS = {num}, SUM_PAID = 0 where id = {ID1}"; cmd.ExecuteNonQuery(); LoadData("select * from registration_of_invoice order by ID, num_of_ser"); } else if (num == 1 && previous_value != dataGridView_invoice.Rows[currentcell.Y].Cells[currentcell.X].EditedFormattedValue.ToString()) { sum_for_pay r = new sum_for_pay(ID1, 1); r.StartPosition = FormStartPosition.CenterParent; r.ShowDialog(); if (Data.yes == true) { cmd = con.CreateCommand(); dataGridView_invoice.Rows[currentcell.Y].Cells[11].ReadOnly = false; cmd.CommandText = $"UPDATE REGISTRATION_OF_INVOICE SET PROCESS = {num} where id = {ID1}"; cmd.ExecuteNonQuery(); LoadData("select * from registration_of_invoice order by ID, num_of_ser"); } Data.yes = false; } else if (num == 2 && previous_value != dataGridView_invoice.Rows[currentcell.Y].Cells[currentcell.X].EditedFormattedValue.ToString()) { cmd = con.CreateCommand(); dataGridView_invoice.Rows[currentcell.Y].Cells[11].ReadOnly = true; cmd.CommandText = $"UPDATE REGISTRATION_OF_INVOICE SET PROCESS = {num}, SUM_PAID = {sum} where id = {ID1}"; cmd.ExecuteNonQuery(); LoadData("select * from registration_of_invoice order by ID, num_of_ser"); } }