public bool actualizarDescuento(eDESCUENTO oeDESCUENTO) { using (SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["CadenaPrincipal"].ToString())) { string sp = "[pa_op_DESCUENTO_ActualizarDescuento]"; SqlCommand cmd = new SqlCommand(sp, cnn); cmd.CommandType = CommandType.StoredProcedure; cnn.Open(); cmd.Parameters.Add(new SqlParameter("@CAN_CODIGO", oeDESCUENTO.CAN_codigo)); //variable tipo:string cmd.Parameters.Add(new SqlParameter("@PRO_CODIGO", oeDESCUENTO.PRO_codigo)); //variable tipo:string cmd.Parameters.Add(new SqlParameter("@DSC_is_especial", oeDESCUENTO.DSC_is_especial)); //variable tipo:string cmd.Parameters.Add(new SqlParameter("@DSC_PORCENTAJE", oeDESCUENTO.DSC_porcentaje)); //variable tipo:double cmd.Parameters.Add(new SqlParameter("@DSC_ESP_PORCENTAJE", oeDESCUENTO.DSC_esp_porcentaje)); //variable tipo:double cmd.Parameters.Add(new SqlParameter("@DSC_FECHA_VENCIMIENTO", (object)oeDESCUENTO.DSC_fecha_vencimiento ?? DBNull.Value)); //variable tipo:DATETIME return(cmd.ExecuteNonQuery() > 0); } }
public override void Guardar() { if (tabDescuentos.SelectedTab == tabDescuentos.TabPages["Grupal"])//your specific tabname { eDESCUENTO oeDESCUENTO = new eDESCUENTO(); balDESCUENTO obalDESCUENTO = new balDESCUENTO(); int contadorInsertadosCorrectos = 0; int contadorInsertadosIncorrectos = 0; DateTime u; foreach (DataGridViewRow row in this.dgvDescuentoGrupal.Rows) { string CAN_codigo = this.cmbCanal.SelectedValue.ToString(); string PRO_codigo = row.Cells["PRO_codigo"].Value.ToString(); string DSC_is_especial = row.Cells["DSC_is_especial"].Value.ToString(); double porcentaje = row.Cells["DSC_porcentaje"].Value != null?Convert.ToDouble(row.Cells["DSC_porcentaje"].Value.ToString()) : 0; double esp_porcentaje = row.Cells["DSC_esp_porcentaje"].Value != null?Convert.ToDouble(row.Cells["DSC_esp_porcentaje"].Value.ToString()) : 0; DateTime?DSC_fecha_vencimiento = (row.Cells["DSC_fecha_vencimiento"].Value != null) ? DateTime.TryParse(row.Cells["DSC_fecha_vencimiento"].Value.ToString(), out u) ? Convert.ToDateTime(row.Cells["DSC_fecha_vencimiento"].Value.ToString()) : (DateTime?)null : null; oeDESCUENTO.CAN_codigo = CAN_codigo; oeDESCUENTO.PRO_codigo = PRO_codigo; oeDESCUENTO.DSC_is_especial = DSC_is_especial; oeDESCUENTO.DSC_porcentaje = porcentaje; oeDESCUENTO.DSC_esp_porcentaje = esp_porcentaje; oeDESCUENTO.DSC_fecha_vencimiento = DSC_fecha_vencimiento; if (balDESCUENTO.actualizarDescuento(oeDESCUENTO)) { contadorInsertadosCorrectos++; } else { contadorInsertadosIncorrectos++; } } mensaje("guardar", contadorInsertadosCorrectos, contadorInsertadosIncorrectos); //MessageBox.Show("Se actualizaron los " + contadorInsertadosCorrectos + " registros en la tabla de descuentos.", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information); mostrarDescuentosGrupales(); } else { eDESCUENTO_P oeDESCUENTOP = new eDESCUENTO_P(); balDESCUENTO_P obalDESCUENTOP = new balDESCUENTO_P(); int contadorInsertadosCorrectos = 0; int contadorInsertadosIncorrectos = 0; foreach (DataGridViewRow row in this.dgvDescuentoSocio.Rows) { int SOC_codigo = Convert.ToInt16(this.txtCodigoSocio.Text); string PRO_codigo = row.Cells["PRO_codigo2"].Value.ToString(); double porcentaje = row.Cells["DSC_porcentaje2"].Value != null?Convert.ToDouble(row.Cells["DSC_porcentaje2"].Value.ToString()) : 0; oeDESCUENTOP.SOC_codigo = SOC_codigo; oeDESCUENTOP.PRO_codigo = PRO_codigo; oeDESCUENTOP.DSC_porcentaje = porcentaje; if (obalDESCUENTOP.actualizarDescuentoP(oeDESCUENTOP)) { contadorInsertadosCorrectos++; } else { contadorInsertadosIncorrectos++; } } mensaje("guardar", contadorInsertadosCorrectos, contadorInsertadosIncorrectos); //MessageBox.Show("Se actualizaron los " + contadorInsertadosCorrectos + " registros en la tabla de descuentos.", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information); mostrarDescuentosSocio(); } }