protected void Button3_Click(object sender, EventArgs e) { var vacio = 0.0000; CultureInfo culture = new CultureInfo("en-US"); this.Calcular(); //Advertencia si el campo no se a calculado correctamente if (double.Parse(lblTotal2.Text) == vacio) { this.ClientScript.RegisterStartupScript(this.GetType(), "SweetAlert", "fallo()", true); this.Calcular(); } //Advertencia si hay campos vacios de dinero, hora y fecha. else if (string.IsNullOrWhiteSpace(txtDinero.Text) || string.IsNullOrWhiteSpace(txtHora.Text) || string.IsNullOrWhiteSpace(fechaEntrega.Text)) { this.ClientScript.RegisterStartupScript(this.GetType(), "SweetAlert", "vacio()", true); this.Calcular(); } //Advertencia si el dinero no es el suficiente para liquidar la cuenta else if (double.Parse(txtDinero.Text, culture) >= double.Parse(lblTotal2.Text, culture)) { this.ClientScript.RegisterStartupScript(this.GetType(), "SweetAlert", "fallo()", true); this.Calcular(); } else { DateTime fechact = DateTime.Now; ControllerCliente ctrlCli = new ControllerCliente(); var CanStock = 0; tblVenta ven = new tblVenta(); var ExStock = 0; //Si cae en que el cliente es mostrador significa que la venta //se esta realizando al momento y eso va a afectar en el descuento del inventario if ((Session["cliente"].ToString() == "MOSTRADOR")) { foreach (GridViewRow row in GridView1.Rows) { var existente = (from existe in contexto.tblStock where existe.fkProducto == int.Parse(row.Cells[1].Text) select existe).FirstOrDefault(); var cantidadExistente = (from existe in contexto.tblStock where existe.fkProducto == int.Parse(row.Cells[1].Text) select existe); //Si cae aqui significa que no hay un historial en stock if (existente == null) { CanStock++; } else { foreach (tblStock ord in cantidadExistente) { //Aqui se hace la resta de la catidad solicitada menos lo que esxita en stock var resta = ord.dblCantidad - int.Parse(((TextBox)row.Cells[3].FindControl("TextBox1")).Text); if (resta >= 0) { } else { ExStock++; } } } } //Alertas en caso de que haya caido en las validaciones anteriores if (CanStock > 0) { this.ClientScript.RegisterStartupScript(this.GetType(), "SweetAlert", "falloCantidad()", true); } //Alertas en caso de que haya caido en las validaciones anteriores else if (ExStock > 0) { this.ClientScript.RegisterStartupScript(this.GetType(), "SweetAlert", "alerta()", true); } else { ven.Fecha = fechact; ven.dblTotal = decimal.Parse(lblTotal2.Text, culture); //ven.dblSubTotal = decimal.Parse(lblSubTotal.Text); //ven.dblIGV = decimal.Parse(lblIGV.Text); ven.strEstado = "FINALIZADO"; ven.dblAbono = decimal.Parse(txtDinero.Text, culture);; ven.dblInteres = null; ven.strFechaEntega = fechaEntrega.Text; ven.strHoraEntega = txtHora.Text; ven.fkCliente = null; ctrlCli.InsertarVenta(ven); foreach (GridViewRow row in GridView1.Rows) { var cantidadExistente = (from existe in contexto.tblStock where existe.fkProducto == int.Parse(row.Cells[1].Text) select existe); foreach (tblStock ord in cantidadExistente) { var resta = ord.dblCantidad - int.Parse(((TextBox)row.Cells[3].FindControl("TextBox1")).Text); ControllerAlmacen ctrlAlm = new ControllerAlmacen(); tblMovimiento mov = new tblMovimiento(); mov.strTipo = "VENTA NUMERO " + ven.idVenta; mov.fecha = fechact; mov.dblValAnt = ord.dblCantidad; mov.dblValNvo = resta; mov.fkStock = ord.idStock; mov.fkEmpleado = Int32.Parse(Session["id"].ToString()); mov.strNumVen = ven.idVenta.ToString(); mov.strFactura = ""; ctrlAlm.InsertarMovimientoAlmacen(mov); ord.dblCantidad = resta; contexto.SubmitChanges(); } ControllerCliente ctrlClie = new ControllerCliente(); tblDetalleVenta detalle = new tblDetalleVenta(); detalle.Fecha = fechact; detalle.intCantidad = int.Parse(((TextBox)row.Cells[3].FindControl("TextBox1")).Text); detalle.fkProducto = int.Parse(row.Cells[1].Text); detalle.dblPrecio = decimal.Parse(((TextBox)row.Cells[4].FindControl("TextBox2")).Text, culture); detalle.fkVenta = ven.idVenta; detalle.fkEmpleado = int.Parse(Session["id"].ToString()); ctrlClie.InsertarDetalle(detalle); } Session["contado"] = null; this.ClientScript.RegisterStartupScript(this.GetType(), "SweetAlert", "exito()", true); } } else { ven.Fecha = fechact; ven.dblTotal = decimal.Parse(lblTotal2.Text); //ven.dblSubTotal = decimal.Parse(lblSubTotal.Text); //ven.dblIGV = decimal.Parse(lblIGV.Text); ven.strEstado = "PENDIENTE"; ven.dblAbono = decimal.Parse(txtDinero.Text, culture);; ven.dblInteres = null; ven.strFechaEntega = fechaEntrega.Text; ven.strHoraEntega = txtHora.Text; ven.fkCliente = int.Parse(Session["cliente"].ToString()); ctrlCli.InsertarVenta(ven); foreach (GridViewRow row in GridView1.Rows) { ControllerCliente ctrlClie = new ControllerCliente(); tblDetalleVenta detalle = new tblDetalleVenta(); detalle.Fecha = fechact; detalle.intCantidad = int.Parse(((TextBox)row.Cells[3].FindControl("TextBox1")).Text); detalle.fkProducto = int.Parse(row.Cells[1].Text); detalle.dblPrecio = decimal.Parse(((TextBox)row.Cells[4].FindControl("TextBox2")).Text, culture); detalle.fkVenta = ven.idVenta; detalle.fkEmpleado = int.Parse(Session["id"].ToString()); ctrlClie.InsertarDetalle(detalle); } Session["contado"] = null; this.ClientScript.RegisterStartupScript(this.GetType(), "SweetAlert", "exito()", true); } this.Limpiar(); } }
private void btnGrabar_Click(object sender, EventArgs e) { bool guardar = true; bool mostrarMensaje = false; string rpta = ""; foreach (Control control in controles) { if (string.IsNullOrWhiteSpace(control.Text)) { if (tipo_crecion == 1) { dxErrorProvider1.SetError(control, "Este campo no puede ser vacío"); mostrarMensaje = true; } else { mostrarMensaje = true; } } } if (dtTelefono.Rows.Count == 0) { mostrarMensaje = true; } if (mostrarMensaje) { MessageBox.Show("ALGUNOS CAMPOS REQUERIDOS NO ESTAN BIEN ESCRITOS O ESTAN VACIOS, POR FAVOR RECTIFIQUE", "CREACIÓN EN PROCESO"); guardar = false; } if (guardar) { if (tipo_crecion == 0) { MCliente objMCliente = new MCliente(); objMCliente.idEstadoCivil = lookUpEditEstadoCivil.ItemIndex > -1 ? Convert.ToInt32(lookUpEditEstadoCivil.EditValue) : 3; objMCliente.identificacion = txtDpi.Text; objMCliente.IdUsuario = Configuraciones.Configuraciones.idusuario; objMCliente.Nombres = txtNombres.Text; objMCliente.Apellidos = txtApellidos.Text; objMCliente.fechaNacimiento = Convert.ToDateTime(dateEditFechaNacimiento.EditValue); objMCliente.direccion = txtDireccion.Text; objMCliente.email = string.IsNullOrWhiteSpace(txtEmail.Text) == true ? "" : txtEmail.Text; objMCliente.empresaLabora = string.IsNullOrWhiteSpace(txtInstitucionLabora.Text) == true ? "" : txtInstitucionLabora.Text; objMCliente.cargo = string.IsNullOrWhiteSpace(txtCargoOcupa.Text) == true ? "" : txtCargoOcupa.Text; objMCliente.nit = txtNit.Text; objMCliente.manejaCuentaBanco = radioGroupUsaCuenta.SelectedIndex == 0 ? false : true; objMCliente.negocioPropio = radioGroupTieneNegocio.SelectedIndex == 0 ? false : true; objMCliente.tipoNegocio = radioGroupTieneNegocio.SelectedIndex == 0 ? "" : txtTipoNegocio.Text; objMCliente.tiempoNegocio = radioGroupTieneNegocio.SelectedIndex == 0 ? "" : txtTiempoNegocio.Text; objMCliente.cantidadHijos = Convert.ToInt32(spinEditCantidadHijos.EditValue); objMCliente.cantidadAportesFamilia = Convert.ToDouble(spinEditAportesFamilia.EditValue); objMCliente.casaPropia = radioGroupCasaPropia.SelectedIndex == 0 ? false : true; objMCliente.tiempoResidir = radioGroupCasaPropia.SelectedIndex == 0 ? "" : txtTiempoResidir.Text; objMCliente.trabajaPareja = radioGroupTrabajaPareja.SelectedIndex == 0 ? false : true; objMCliente.trabajoPareja = radioGroupTrabajaPareja.SelectedIndex == 0 ? "" : txtTrabajaPareja.Text; objMCliente.descripcion = string.IsNullOrWhiteSpace(txtDescripcion.Text) == true ? "" : txtDescripcion.Text; objMCliente.RazonSocial = string.IsNullOrWhiteSpace(txtRazonSocial.Text) == true ? "" : txtRazonSocial.Text; objMCliente.DireccionFiscal = string.IsNullOrWhiteSpace(txtDireccionFiscal.Text) == true ? "" : txtDireccionFiscal.Text; objMCliente.IdSubGrupo = lookUpEditSubGrupo.ItemIndex > -1 ? Convert.ToInt32(lookUpEditSubGrupo.EditValue) : 6; //objMCliente.ConObservaciones = dtTelefono.Rows.Count > 0 ? true : false; objMCliente.ConObservaciones = false; objMCliente.EsFiador = true; objMCliente.ConTelefonos = dtTelefono.Rows.Count > -1 ? true : false; List <MTelefonoCliente> Telefonos = new List <MTelefonoCliente>(); foreach (DataRow item in dtTelefono.Rows) { MTelefonoCliente telefono = new MTelefonoCliente(); telefono.Descripcion = item["descripcion"].ToString(); telefono.Telefono = item["telefono"].ToString(); telefono.Opcion = 1; telefono.IdTelefon = 0; Telefonos.Add(telefono); } rpta = ControllerCliente.GuardarCliente(objMCliente, Telefonos); if (rpta == "OK") { MessageBox.Show("EL CLIENTE SE CREO CORRECTAMENTE", "CREACIÓN EN PROCESO"); EsBotonOTecla = true; this.Close(); } else { MessageBox.Show("OCURRIO UN ERRO AL TRATAR DE CREAR EL CLIENTE, POR FAVOR CONSULTE A SU ADMINISTRADOR DE DATOS " + rpta, "ERROR AL CREAR"); } } else { MCliente objMCliente = new MCliente(); objMCliente.idCliente = id_cliente; objMCliente.idEstadoCivil = lookUpEditEstadoCivil.ItemIndex > -1 ? Convert.ToInt32(lookUpEditEstadoCivil.EditValue) : 3; objMCliente.identificacion = txtDpi.Text; objMCliente.IdUsuario = Configuraciones.Configuraciones.idusuario; objMCliente.Nombres = txtNombres.Text; objMCliente.Apellidos = txtApellidos.Text; objMCliente.fechaNacimiento = Convert.ToDateTime(dateEditFechaNacimiento.EditValue); objMCliente.direccion = txtDireccion.Text; objMCliente.email = string.IsNullOrWhiteSpace(txtEmail.Text) == true ? "" : txtEmail.Text; objMCliente.empresaLabora = string.IsNullOrWhiteSpace(txtInstitucionLabora.Text) == true ? "" : txtInstitucionLabora.Text; objMCliente.cargo = string.IsNullOrWhiteSpace(txtCargoOcupa.Text) == true ? "" : txtCargoOcupa.Text; objMCliente.nit = txtNit.Text; objMCliente.manejaCuentaBanco = radioGroupUsaCuenta.SelectedIndex == 0 ? false : true; objMCliente.negocioPropio = radioGroupTieneNegocio.SelectedIndex == 0 ? false : true; objMCliente.tipoNegocio = radioGroupTieneNegocio.SelectedIndex == 0 ? "" : txtTipoNegocio.Text; objMCliente.tiempoNegocio = radioGroupTieneNegocio.SelectedIndex == 0 ? "" : txtTiempoNegocio.Text; objMCliente.cantidadHijos = Convert.ToInt32(spinEditCantidadHijos.EditValue); objMCliente.cantidadAportesFamilia = Convert.ToDouble(spinEditAportesFamilia.EditValue); objMCliente.casaPropia = radioGroupCasaPropia.SelectedIndex == 0 ? false : true; objMCliente.tiempoResidir = radioGroupCasaPropia.SelectedIndex == 0 ? "" : txtTiempoResidir.Text; objMCliente.trabajaPareja = radioGroupTrabajaPareja.SelectedIndex == 0 ? false : true; objMCliente.trabajoPareja = radioGroupTrabajaPareja.SelectedIndex == 0 ? "" : txtTrabajaPareja.Text; objMCliente.descripcion = string.IsNullOrWhiteSpace(txtDescripcion.Text) == true ? "" : txtDescripcion.Text; objMCliente.RazonSocial = string.IsNullOrWhiteSpace(txtRazonSocial.Text) == true ? "" : txtRazonSocial.Text; objMCliente.DireccionFiscal = string.IsNullOrWhiteSpace(txtDireccionFiscal.Text) == true ? "" : txtDireccionFiscal.Text; objMCliente.IdSubGrupo = lookUpEditSubGrupo.ItemIndex > -1 ? Convert.ToInt32(lookUpEditSubGrupo.EditValue) : 6; //objMCliente.ConObservaciones = dtTelefono.Rows.Count > 0 ? true : false; objMCliente.ConObservaciones = false; objMCliente.EsFiador = true; objMCliente.ConTelefonos = dtTelefono.Rows.Count > -1 ? true : false; List <MTelefonoCliente> TelefonosEliminacion = new List <MTelefonoCliente>(); foreach (DataRow item in dtTelefonoEliminacion.Rows) { MTelefonoCliente telefono = new MTelefonoCliente(); telefono.IdTelefon = Convert.ToInt32(item["id_telefono"]); telefono.Descripcion = item["descripcion"].ToString(); telefono.Telefono = item["telefono"].ToString(); telefono.Opcion = 0; telefono.IdCliente = 0; TelefonosEliminacion.Add(telefono); } List <MTelefonoCliente> TelefonosInsercion = new List <MTelefonoCliente>(); foreach (DataRow item in dtTelefono.Rows) { MTelefonoCliente telefono = new MTelefonoCliente(); telefono.Descripcion = item["descripcion"].ToString(); telefono.Telefono = item["telefono"].ToString(); telefono.Opcion = 1; telefono.IdCliente = id_cliente; TelefonosInsercion.Add(telefono); } rpta = ControllerCliente.ActualizarCliente(objMCliente, TelefonosInsercion, TelefonosEliminacion); if (rpta == "OK") { MessageBox.Show("EL CLIENTE SE CREO CORRECTAMENTE", "CREACIÓN EN PROCESO"); EsBotonOTecla = true; this.Close(); } else { MessageBox.Show("OCURRIO UN ERRO AL TRATAR DE CREAR EL CLIENTE, POR FAVOR CONSULTE A SU ADMINISTRADOR DE DATOS " + rpta, "ERROR AL CREAR"); } } } }
//______________________________________________________________________________________________________________________ //______________________________________________________________________________________________________________________ private void FormClientes_Load(object sender, EventArgs e) { XtraTabControl1.ShowTabHeader = DevExpress.Utils.DefaultBoolean.False; mostrarEnComboboxLookUp(lookUpEditEstadoCivil, "descripcion", "id_estado_civil", ControllerCliente.MostrarEstadoCivil()); mostrarEnComboboxLookUp(lookUpEditGrupo, "descripcion", "id_grupo", ControllerCliente.MostrarGrupo()); CrearTablaTelefonos(); controles.Add(txtNombres); controles.Add(txtApellidos); controles.Add(txtDireccion); controles.Add(txtDescripcion); controles.Add(dateEditFechaNacimiento); controles.Add(tbtelefono); controles.Add(txtInstitucionLabora); controles.Add(txtCargoOcupa); controles.Add(txtRazonSocial); controles.Add(txtDireccionFiscal); controles.Add(txtNit); foreach (Control control in controles) { dxErrorProvider1.SetError(control, ""); if (string.IsNullOrWhiteSpace(control.Text)) { dxErrorProvider1.SetError(control, "Este campo no puede ser vacío"); } } if (tipo_crecion == 0) { btnGrabar.Text = "Grabar"; } else { btnGrabar.Text = "Actualizar"; dtTelefonoEliminacion = ControllerVentas.MostrarTelefonoDeCliente(id_cliente); dtTelefono = ControllerVentas.MostrarTelefonoDeCliente(id_cliente); mostrarEnComboboxLookUp(tbtelefono, "telefono", "id_telefono", dtTelefono); } }
private void lookUpEditGrupo_EditValueChanged(object sender, EventArgs e) { if (lookUpEditGrupo.ItemIndex > -1) { mostrarEnComboboxLookUp(lookUpEditSubGrupo, "descripcion", "id_cliente_subgrupo", ControllerCliente.MostrarSubGrupo(Convert.ToInt32(lookUpEditGrupo.EditValue))); } }