//********************************************************** //* PROCEDIMIENTO PARA LLENAR COMBOBOX //********************************************************** public static void LlenarComboBox(ComboBox comboBox, String dataSource, String valueMember, String displayMember, String whereMember, String orderMember) { SqlConnection conn = Procedimientos.abrirConexion(); DataSet dataSet = new DataSet(); SqlDataAdapter dataAdapter = new SqlDataAdapter(String.Format("SELECT {0} 'Value',{1} AS 'Display' FROM {2} {3} {4}", valueMember, displayMember, dataSource, String.IsNullOrEmpty(whereMember) ? "" : "WHERE " + whereMember, String.IsNullOrEmpty(orderMember) ? "" : "ORDER BY " + orderMember), conn); dataAdapter.Fill(dataSet, dataSource); DataRow row = dataSet.Tables[0].NewRow(); dataSet.Tables[0].Rows.InsertAt(row, 0); comboBox.DataSource = dataSet.Tables[0].DefaultView; comboBox.ValueMember = "Value"; comboBox.DisplayMember = "Display"; comboBox.DropDownStyle = ComboBoxStyle.DropDownList; comboBox.Text = "(Seleccione una Opcion)"; }
//********************************************************** //* PROCEDIMIENTO PARA LLENAR COMBOBOX FROM STORE //********************************************************** public static void LlenarComboBoxDesdeProcedure(ComboBox comboBox, String dataSource, String valueMember, String displayMember, String whereMember, String orderMember) { SqlConnection conn = Procedimientos.abrirConexion(); DataSet dataSet = new DataSet(); SqlDataAdapter dataAdapter = new SqlDataAdapter("EXEC " + dataSource, conn); dataAdapter.Fill(dataSet, dataSource); DataRow row = dataSet.Tables[0].NewRow(); dataSet.Tables[0].Rows.InsertAt(row, 0); comboBox.DataSource = dataSet.Tables[0].DefaultView; comboBox.ValueMember = valueMember; comboBox.DisplayMember = displayMember; comboBox.DropDownStyle = ComboBoxStyle.DropDownList; comboBox.Text = "(Seleccione una Opcion)"; }
//************************************************************************* //* PROCEDIMIENTO PARA VALIDAR SI UN REGISTRO YA SE ENCUENTRA EN LA BD //**************************************************************************** public static Boolean esUnico(String nombreTabla, String nombreCampo, String nombreTextBox) { SqlConnection conn = Procedimientos.abrirConexion(); SqlCommand comm = new SqlCommand(string.Format("SELECT COUNT(*) FROM {0} WHERE {1} = '{2}'", nombreTabla, nombreCampo, nombreTextBox), conn); comm.Parameters.AddWithValue("@nombreTextBox", nombreTextBox); Int32 count = (Int32)comm.ExecuteScalar(); if (count == 0) { return(true); } else { return(false); } }
private void FormMenu_Load(object sender, EventArgs e) { MdiClient ctlMDI; foreach (Control ctl in this.Controls) { try { ctlMDI = (MdiClient)ctl; ctlMDI.BackColor = this.BackColor; } catch (InvalidCastException exc) { // Catch and ignore the error if casting failed. } } ToolStripMenuItem menuItem = new ToolStripMenuItem("&Menu"); Procedimientos.obtenerOpcionesMenu(opcionesMenu, usuario.Id_Rol); foreach (KeyValuePair <int, OpcionMenu> kvp in opcionesMenu) { ToolStripMenuItem subItem = new ToolStripMenuItem(kvp.Value.DescripcionFuncionalidad, null, opcionMenu_Click); subItem.Tag = kvp.Value.DescripcionFuncionalidad; menuItem.DropDownItems.Add(subItem); } ToolStripMenuItem subItemSalir = new ToolStripMenuItem("Salir", null, opcionMenuSalir_Click); subItemSalir.Tag = "Salir"; menuItem.DropDownItems.Add(subItemSalir); menuStrip.Items.Add(menuItem); this.Controls.Add(menuStrip); }