private int NextPaymentMethodID() { // if (qds_PaymentMethod_Sp == null) { qds_PaymentMethod_Sp = new Qds_PaymentMethod_Sp(Properties.Settings.Default.WsirDbConnectionString); } List <Qds_PaymentMethod> qds_PaymentMethodList = qds_PaymentMethod_Sp.SelectAll(); if (qds_PaymentMethodList.Count < 1) { return(-1); } if (qds_PaymentMethodAvailableByDepot_Sp == null) { qds_PaymentMethodAvailableByDepot_Sp = new Qds_PaymentMethodAvailableByDepot_Sp(Properties.Settings.Default.WsirDbConnectionString); } foreach (Qds_PaymentMethod pm in qds_PaymentMethodList) { if (pm.PaymentMethodID == 0) { continue; } qds_PaymentMethodAvailableByDepot = qds_PaymentMethodAvailableByDepot_Sp.Select(depotID, pm.PaymentMethodID); if (qds_PaymentMethodAvailableByDepot == null) { return(pm.PaymentMethodID); } } return(-1); }
private void OK_Click(object sender, EventArgs e) { if (DataGridView1.Rows.Count < 1) { return; } int paymentMethodID = (int)DataGridView1.CurrentRow.Cells[1].Value; if (paymentMethodID == 0) { MessageBox.Show("Please select another method!"); return; } //Check that PaymentMethod is not assigned if change if (formerPaymentMethodID != paymentMethodID) { if (qds_PaymentMethodAvailableByDepot_Sp == null) { qds_PaymentMethodAvailableByDepot_Sp = new Qds_PaymentMethodAvailableByDepot_Sp(Properties.Settings.Default.WsirDbConnectionString); } qds_PaymentMethodAvailableByDepot = qds_PaymentMethodAvailableByDepot_Sp.Select(depotID, paymentMethodID); if (qds_PaymentMethodAvailableByDepot != null) { MessageBox.Show("Payment Method already assigned!"); return; } } //only on DepotDefault bool depotDefault = (bool)DataGridView1.CurrentRow.Cells[2].Value; if (depotDefault && (formerDepotDefault != depotDefault)) { using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.WsirDbConnectionString)) { try { string query = "UPDATE [Qds_PaymentMethodAvailableByDepot] WITH (ROWLOCK) " + "SET [DepotDefault] = 0 " + "WHERE [DepotID] = '" + depotID + "' "; using (SqlCommand command = new SqlCommand(query, connection)) { connection.Open(); command.ExecuteNonQuery(); } } catch { // } finally { connection.Close(); } } } if (OK.Text == "&Select") { try { int.TryParse(this.DataGridView1.CurrentRow.Cells[0].Value.ToString(), out fieldId); if (fieldId < 1) { throw new Exception(); } fieldName = DataGridView1.CurrentRow.Cells[1].Value.ToString().Trim(); } catch { MessageBox.Show("Please select a valid item."); return; } Close(); return; } BindingNavigatorSaveItem.PerformClick(); }