private void frmRegStyleEdit_Load(object sender, EventArgs e) { BSUtils.LoaderLook(cboClient, new ClientBL().ListaTodosActivo(Parametros.intEmpresaId), "NameClient", "IdClient", true); cboClient.EditValue = IdClient; deRevenueDate.DateTime = DateTime.Now; BSUtils.LoaderLook(cboDivision, new ClientDepartmentBL().ListaTodosActivo(IdClient), "NameDivision", "IdClientDepartment", true); BSUtils.LoaderLook(cboMediaUnit, new MediaUnitBL().ListaTodosActivo(Parametros.intEmpresaId), "NameMediaUnit", "IdMediaUnit", true); cboMediaUnit.EditValue = 1; if (pOperacion == Operacion.Nuevo) { this.Text = "Style - New"; } else if (pOperacion == Operacion.Modificar) { this.Text = "Style - Update"; StyleBE objE_Style = new StyleBE(); objE_Style = new StyleBL().Selecciona(IdStyle); if (objE_Style != null) { cboClient.EditValue = objE_Style.IdClient; txtNameStyle.Text = objE_Style.NameStyle; deRevenueDate.DateTime = objE_Style.RevenueDate; txtDescription.Text = objE_Style.Description; txtItem.Text = objE_Style.Item; cboDivision.EditValue = objE_Style.IdClientDepartment; cboMediaUnit.EditValue = objE_Style.IdMediaUnit; } } txtNameStyle.Focus(); }
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\\Style.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 <StyleBE> lstStyle = null; lstStyle = new StyleBL().ListaTodosActivo(Parametros.intEmpresaId, IdClient, 0); if (lstStyle.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 lstStyle) { xlHoja.Cells[Row, 1] = item.IdStyle; xlHoja.Cells[Row, 2] = item.NameClient; xlHoja.Cells[Row, 3] = item.NameStyle; xlHoja.Cells[Row, 4] = item.Description; xlHoja.Cells[Row, 5] = BSUtils.GetDateFormat(item.RevenueDate); xlHoja.Cells[Row, 6] = item.MameDivision; xlHoja.Cells[Row, 7] = item.NameMediaUnit; xlHoja.Cells[Row, 8] = item.Situation; Row = Row + 1; Secuencia = Secuencia + 1; } } xlLibro.SaveAs("C:\\Excel\\Style.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; XtraMessageBox.Show("It was imported correctly \n The file was generated C:\\Excel\\Style.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); } }
private void btnGrabar_Click(object sender, EventArgs e) { try { Cursor = Cursors.WaitCursor; if (!ValidarIngreso()) { StyleBL objBL_Style = new StyleBL(); StyleBE objStyle = new StyleBE(); objStyle.IdStyle = IdStyle; objStyle.IdClient = IdClient; objStyle.NameStyle = txtNameStyle.Text; objStyle.RevenueDate = Convert.ToDateTime(deRevenueDate.EditValue); objStyle.Description = txtDescription.Text; objStyle.Item = txtItem.Text; objStyle.IdClientDepartment = Convert.ToInt32(cboDivision.EditValue); objStyle.IdMediaUnit = Convert.ToInt32(cboMediaUnit.EditValue); objStyle.FlagState = true; objStyle.Login = Parametros.strUsuarioLogin; objStyle.Machine = WindowsIdentity.GetCurrent().Name.ToString(); objStyle.IdCompany = Parametros.intEmpresaId; if (pOperacion == Operacion.Nuevo) { objBL_Style.Inserta(objStyle); } else { objBL_Style.Actualiza(objStyle); } this.Close(); } } catch (Exception ex) { Cursor = Cursors.Default; XtraMessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
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()) { for (int i = 0; i < gvStyle.SelectedRowsCount; i++) { int row = gvStyle.GetSelectedRows()[i]; StyleBE objE_Style = new StyleBE(); objE_Style.IdStyle = int.Parse(gvStyle.GetRowCellValue(row, "IdStyle").ToString()); objE_Style.Login = Parametros.strUsuarioLogin; objE_Style.Machine = WindowsIdentity.GetCurrent().Name.ToString(); objE_Style.IdCompany = Parametros.intEmpresaId; StyleBL objBL_Area = new StyleBL(); objBL_Area.Elimina(objE_Style); } 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 ImportarExcel() { if (strFleExcel == "") { return; } Excel._Application xlApp; Excel._Workbook xlLibro; Excel._Worksheet xlHoja; Excel.Sheets xlHojas; xlApp = new Excel.Application(); xlLibro = xlApp.Workbooks.Open(strFleExcel, 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]; int Secuencia = 2; int _row = 2; int _totRow = 2; try { List <StyleBE> lstStyle = new List <StyleBE>(); while (FuncionBase.IsNumeric((string)xlHoja.get_Range("A" + _row, Missing.Value).Text.ToString().Trim())) { //Declaracion de variables int IdCompany = 0; int intIdClient = 0; string strNameClient = ""; string strNameStyle = ""; DateTime RevenueDate = new DateTime(2010, 1, 1); string strDescription = ""; int intIdClientDepartment = 0; string strNameDivision = ""; int IdMediaUnit = 0; string strAbbreviate = ""; strNameClient = (string)xlHoja.get_Range("B" + _row, Missing.Value).Text.ToString().Trim(); ClientBE objE_Client = null; objE_Client = new ClientBL().SeleccionaDescripcion(Parametros.intEmpresaId, strNameClient); if (objE_Client != null) { intIdClient = objE_Client.IdClient; strNameStyle = (string)xlHoja.get_Range("C" + _row, Missing.Value).Text.ToString().Trim(); RevenueDate = Convert.ToDateTime(xlHoja.get_Range("D" + _row, Missing.Value).Text.ToString().Trim()); strDescription = (string)xlHoja.get_Range("E" + _row, Missing.Value).Text.ToString().Trim(); strNameDivision = (string)xlHoja.get_Range("F" + _row, Missing.Value).Text.ToString().Trim(); ClientDepartmentBE objE_ClientDepartment = null; objE_ClientDepartment = new ClientDepartmentBL().SeleccionaDescripcion(intIdClient, strNameDivision); if (objE_ClientDepartment != null) { intIdClientDepartment = objE_ClientDepartment.IdClientDepartment; } else { XtraMessageBox.Show("N° Secuencia : " + Secuencia.ToString() + "\n Division: " + strNameDivision, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); xlLibro.Close(false, Missing.Value, Missing.Value); xlApp.Quit(); this.Dispose(); this.Close(); } strAbbreviate = (string)xlHoja.get_Range("G" + _row, Missing.Value).Text.ToString().Trim(); MediaUnitBE objE_MediaUnit = null; objE_MediaUnit = new MediaUnitBL().SeleccionaAbreviatura(Parametros.intEmpresaId, strAbbreviate); if (objE_MediaUnit != null) { IdMediaUnit = objE_MediaUnit.IdMediaUnit; } else { XtraMessageBox.Show("N° Secuencia : " + Secuencia.ToString() + "\n Media Unit: " + strAbbreviate, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); xlLibro.Close(false, Missing.Value, Missing.Value); xlApp.Quit(); this.Dispose(); this.Close(); } StyleBE objE_Style = new StyleBE(); objE_Style.IdStyle = 0; objE_Style.IdCompany = Parametros.intEmpresaId; objE_Style.IdClient = intIdClient; objE_Style.NameStyle = strNameStyle; objE_Style.RevenueDate = RevenueDate; objE_Style.Description = strDescription; objE_Style.IdClientDepartment = intIdClientDepartment; objE_Style.IdMediaUnit = IdMediaUnit; objE_Style.FlagState = true; objE_Style.Login = Parametros.strUsuarioLogin; objE_Style.Machine = WindowsIdentity.GetCurrent().Name.ToString(); lstStyle.Add(objE_Style); } Application.DoEvents(); _row++; Secuencia++; } StyleBL objBL_Style = new StyleBL(); objBL_Style.InsertaMasivo(lstStyle); XtraMessageBox.Show("Los Datos se guardaron conrrectamente.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); xlLibro.Close(false, Missing.Value, Missing.Value); xlApp.Quit(); this.Close(); } catch (Exception ex) { xlApp.Quit(); XtraMessageBox.Show(ex.Message + "\n N° Secuencia : " + Secuencia.ToString(), ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } }