private void tlbMenu_DeleteClick() { try { Cursor = Cursors.WaitCursor; if (XtraMessageBox.Show("Be sure to delete the record??", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { if (!ValidarIngreso()) { OccupationBE objE_Cargo = new OccupationBE(); objE_Cargo.IdOccupation = int.Parse(gvCargo.GetFocusedRowCellValue("IdOccupation").ToString()); objE_Cargo.Login = Parametros.strUsuarioLogin; objE_Cargo.Machine = WindowsIdentity.GetCurrent().Name.ToString(); objE_Cargo.IdCompany = Parametros.intEmpresaId; OccupationBL objBL_Cargo = new OccupationBL(); objBL_Cargo.Elimina(objE_Cargo); XtraMessageBox.Show("The record was successfully deleted.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); Cargar(); } } Cursor = Cursors.Default; } catch (Exception ex) { Cursor = Cursors.Default; XtraMessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnGrabar_Click(object sender, EventArgs e) { try { Cursor = Cursors.WaitCursor; if (!ValidarIngreso()) { OccupationBL objBL_Cargo = new OccupationBL(); OccupationBE objCargo = new OccupationBE(); objCargo.IdOccupation = IdOccupation; objCargo.NameOccupation = txtDescripcion.Text; objCargo.FlagState = true; objCargo.Login = Parametros.strUsuarioLogin; objCargo.Machine = WindowsIdentity.GetCurrent().Name.ToString(); objCargo.IdCompany = Parametros.intEmpresaId; if (pOperacion == Operacion.Nuevo) { objBL_Cargo.Inserta(objCargo); } else { objBL_Cargo.Actualiza(objCargo); } this.Close(); } } catch (Exception ex) { Cursor = Cursors.Default; XtraMessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
void ExportarExcel(string filename) { Excel._Application xlApp; Excel._Workbook xlLibro; Excel._Worksheet xlHoja; Excel.Sheets xlHojas; xlApp = new Excel.Application(); filename = Path.Combine(Directory.GetCurrentDirectory(), "Excel\\Occupation.xlsx"); xlLibro = xlApp.Workbooks.Open(filename, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); xlHojas = xlLibro.Sheets; xlHoja = (Excel._Worksheet)xlHojas[1]; Cursor.Current = Cursors.WaitCursor; try { int Row = 6; int Secuencia = 1; List <OccupationBE> lstOccupation = null; lstOccupation = new OccupationBL().ListaTodosActivo(Parametros.intEmpresaId); if (lstOccupation.Count > 0) { xlHoja.Shapes.AddPicture(Path.Combine(Directory.GetCurrentDirectory(), "Logo.jpg"), Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, 1, 1, 100, 60); foreach (var item in lstOccupation) { xlHoja.Cells[Row, 1] = item.IdOccupation; xlHoja.Cells[Row, 2] = item.NameOccupation; Row = Row + 1; Secuencia = Secuencia + 1; } } xlLibro.SaveAs("C:\\Excel\\Occupation.xlsx", Excel.XlFileFormat.xlWorkbookDefault, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Excel.XlSaveAsAccessMode.xlExclusive, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); xlLibro.Close(true, Missing.Value, Missing.Value); xlApp.Quit(); Cursor.Current = Cursors.Default; BSUtils.OpenExcel("C:\\Excel\\Occupation.xlsx"); //XtraMessageBox.Show("It was imported correctly \n The file was generated C:\\Excel\\Occupation.xlsx", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { xlLibro.Close(false, Missing.Value, Missing.Value); xlApp.Quit(); Cursor.Current = Cursors.Default; MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Warning); } }