Exemplo n.º 1
0
        private void schedulerControl1_AppointmentDrop(object sender, AppointmentDragEventArgs e)
        {
            string createEventMsg = "Crear el evento a las {0} el dia {1}.";
            string moveEventMsg = "Mover el evento desde {0} el dia {1} a las {2} el dia {3}.";

            bool Crear = false;
            bool Mover = false;

            DateTime srcStart = e.SourceAppointment.Start;
            DateTime newStart = e.EditedAppointment.Start;

            string msg = (srcStart == DateTime.MinValue) ? String.Format(createEventMsg, newStart.ToShortTimeString(), newStart.ToShortDateString()) :
                String.Format(moveEventMsg, srcStart.ToShortTimeString(), srcStart.ToShortDateString(), newStart.ToShortTimeString(), newStart.ToShortDateString());

            if (msg.Contains("Crear"))
                Crear = true;

            if (msg.Contains("Mover"))
                Mover = true;

            clsVisita visita = new clsVisita();

            if (Mover) {
                if (!PermitirModificarVisita(e.SourceAppointment)) {
                    e.Allow = false;
                    e.Handled = true;
                    return;
                }
            }

            if (XtraMessageBox.Show(msg + "\r\nProceder?", "Mi Calendario", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) {
                e.Allow = false;
                e.Handled = true;
                return;
            }

            if (Convert.ToInt64(e.SourceAppointment.CustomFields["IdVisita"]) > 0) {
                if (Mover) {
                    visita =
                        LogicaNegocios.Calendarios.clsCalendarios.ObtenerVisitaPorId(
                            Convert.ToInt64(e.SourceAppointment.CustomFields["IdVisita"]));

                }

                //visita.Id = Convert.ToInt64(e.SourceAppointment.CustomFields["IdVisita"]);
                //visita.Asunto = e.SourceAppointment.Subject;
                //visita.Descripcion = e.SourceAppointment.Description;
                //visita.Ubicacion = e.SourceAppointment.Location;
                visita.FechaHoraComienzo = e.EditedAppointment.Start;
                visita.FechaHoraTermino = e.EditedAppointment.End;
            } else {
                visita.Id = Convert.ToInt64(e.SourceAppointment.CustomFields["IdVisita"]);
                visita.Asunto = e.SourceAppointment.Subject;
                visita.Descripcion = e.SourceAppointment.Description;
                visita.Ubicacion = e.SourceAppointment.Location;
                visita.FechaHoraComienzo = e.EditedAppointment.Start;
                visita.FechaHoraTermino = e.EditedAppointment.End;
            }

            if (Crear) {
                visita.Cliente = LogicaNegocios.Clientes.clsClientesMaster.ObtenerClienteMasterPorId(IdClienteDraw);
                visita.EstadoBD = Entidades.Enums.Enums.VisitaEstado.Incompleta;

                if (visita.Cliente.Tipo == Enums.TipoPersona.Cuenta) {
                    ResultadoTransaccion resCuenta = LogicaNegocios.Clientes.clsCuentas.ObtenerCuentaPorIdMaster(visita.Cliente.Id);
                    clsCuenta cuenta = new clsCuenta();
                    if (resCuenta.Estado == Enums.EstadoTransaccion.Aceptada)
                        cuenta = (clsCuenta)resCuenta.ObjetoTransaccion;

                    if (cuenta != null)
                        visita.Vendedor = cuenta.VendedorAsignado;
                } else if (visita.Cliente.Tipo == Enums.TipoPersona.Target) {
                    ResultadoTransaccion resCuenta =
                        LogicaNegocios.Clientes.clsTarget.ObtenerTargetPorIdMaster(visita.Cliente.Id);

                    clsTarget target = new clsTarget();
                    if (resCuenta.Estado == Enums.EstadoTransaccion.Aceptada)
                        target = (clsTarget)resCuenta.ObjetoTransaccion;

                    if (target != null)
                        visita.Vendedor = target.VendedorAsignado;
                }

                clsVisitaAsistente asistente = new clsVisitaAsistente();
                asistente.Usuario = Base.Usuario.UsuarioConectado.Usuario;
                asistente.TipoAsistente = Entidades.Enums.Enums.VisitaTipoAsistente.Usuario;
                visita.Asistentes.Add(asistente);

                clsParametrosInfo paraminfo = LogicaNegocios.Parametros.clsParametros.ListarParametrosPorTipo(Entidades.Enums.Enums.TipoParametro.ImportanciaVisita);
                visita.NivelImportancia = paraminfo.Items[0];  // Entidades.Enums.Enums.VisitaNivelImportancia.Baja;
            }

            //visita.Vendedor = Base.Usuario.UsuarioConectado.Usuario;

            visita.UsuarioOrganizador = Base.Usuario.UsuarioConectado.Usuario;
            Entidades.GlobalObject.ResultadoTransaccion res = LogicaNegocios.Calendarios.clsCalendarios.GuardarVisita(visita);

            if (res.Estado == Entidades.Enums.Enums.EstadoTransaccion.Aceptada) {

            } else {

                MessageBox.Show(res.Descripcion, "Calendario", MessageBoxButtons.OK, MessageBoxIcon.Error);
                e.Allow = false;
                e.Handled = true;
                return;
            }

            PopupClientes.Visible = false;

            //if(schedulerStorage1.Appointments.IsNewAppointment(e.EditedAppointment))
            //{
            //    schedulerStorage1.Appointments.Add(e.EditedAppointment);
            //}

            //SincronizarOutlook();
        }
Exemplo n.º 2
0
        private void gridView5_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            DevExpress.XtraGrid.Views.Base.ColumnView columna = sender as DevExpress.XtraGrid.Views.Base.ColumnView;
            string nomcliente = "";
            Int64 IdCliente = 0;
            clsCuenta cuenta = new clsCuenta();
            clsClienteMaster clienteselecccionado = new clsClienteMaster(false);

            if (e.Column.FieldName == "Cliente.NombreFantasia")
            {
                nomcliente = columna.EditingValue.ToString();

                //Console.WriteLine("nomCliente--->"+nomcliente);
                if (nomcliente.Trim() != "")
                {
                    ddlP1Cliente.SelectedIndex = 0;
                    for (int i = 0; i < ddlP1Cliente.Properties.Items.Count; i++)
                    {
                        if (ddlP1Cliente.Properties.Items[i].ToString().Trim() == nomcliente.Trim())
                        {
                            ddlP1Cliente.SelectedIndex = i;
                            break;
                        }
                    }
                    //Console.WriteLine("index seleccionado--->" + ddlP1Cliente.SelectedIndex);

                    if (ddlP1Cliente.SelectedIndex == 0)
                    {
                        clienteselecccionado = new clsClienteMaster(true)
                                                   {
                                                       NombreFantasia = columna.EditingValue.ToString(),
                                                       NombreCompañia = columna.EditingValue.ToString(),
                                                       Tipo = Enums.TipoPersona.CuentaPaperless,
                                                       EstadoCuenta = Enums.Estado.Habilitado
                                                   };
                        PaperlessAsignacionActual.DataUsuario1.Paso1HousesBL[e.RowHandle].TipoCliente = null;
                    }
                    else
                    {
                        clienteselecccionado = (clsClienteMaster)this.ddlP1Cliente.SelectedItem;
                        if (clienteselecccionado.Id != 0)
                        {
                            PaperlessTipoCliente ptc = new PaperlessTipoCliente();

                            var transaccion = LogicaNegocios.Clientes.clsCuentas.BuscarCuentaPorId(clienteselecccionado.Id);
                            if (transaccion != null)
                            {
                                cuenta = (clsCuenta)transaccion.ObjetoTransaccion;
                                if (cuenta != null && cuenta.ClienteMaster.ClienteMasterTipoCliente != null)
                                {
                                    if (cuenta.ClienteMaster.ClienteMasterTipoCliente.Count.Equals(0) ||
                                        cuenta.ClienteMaster.ClienteMasterTipoCliente.Count > 1)
                                    {
                                        PaperlessAsignacionActual.DataUsuario1.Paso1HousesBL[e.RowHandle].TipoCliente = null;
                                    }
                                    else
                                    {
                                        ptc.Nombre = cuenta.ClienteMaster.ClienteMasterTipoCliente[0].Nombre;
                                        ptc.Id = cuenta.ClienteMaster.ClienteMasterTipoCliente[0].Id;
                                        PaperlessAsignacionActual.DataUsuario1.Paso1HousesBL[e.RowHandle].TipoCliente = ptc;
                                    }
                                }
                                else
                                {
                                    PaperlessAsignacionActual.DataUsuario1.Paso1HousesBL[e.RowHandle].TipoCliente = null;
                                }

                            }
                        }
                        if (clienteselecccionado.NombreFantasia.Length.Equals(0))
                            clienteselecccionado.NombreFantasia = clienteselecccionado.NombreCompañia;
                    }

                }

                PaperlessAsignacionActual.DataUsuario1.Paso1HousesBL[e.RowHandle].Cliente = clienteselecccionado;
            }

            if (e.Column.FieldName == "TipoCliente.Nombre")
            {
                PaperlessAsignacionActual.DataUsuario1.Paso1HousesBL[e.RowHandle].TipoCliente =
                    (PaperlessTipoCliente)columna.EditingValue;
            }
        }
Exemplo n.º 3
0
        public static ResultadoTransaccion ObtenerCuentaPorIdMaster(Int64 IdMaster)
        {
            ResultadoTransaccion res = new ResultadoTransaccion();
            try
            {

                //Abrir Conexion
                //conn = BaseDatos.Conexion();
                conn = BaseDatos.NuevaConexion();

                //Registrar Cliente Master
                objParams = SqlHelperParameterCache.GetSpParameterSet(conn, "SP_C_CLIENTES_CUENTA_POR_ID_MASTER");
                objParams[0].Value = IdMaster;
                SqlCommand command = new SqlCommand("SP_C_CLIENTES_CUENTA_POR_ID_MASTER", conn);
                command.Parameters.AddRange(objParams);
                command.CommandType = CommandType.StoredProcedure;
                dreader = command.ExecuteReader();

                while (dreader.Read())
                {
                    clsCuenta cuenta = new clsCuenta();
                    cuenta.ClienteMaster.Id = Convert.ToInt64(dreader["IdMaster"]);
                    cuenta.ClienteMaster.NombreCompañia = dreader["NombreCompania"].ToString();
                    cuenta.ClienteMaster.NombreFantasia = dreader["NombreFantasia"].ToString();
                    cuenta.ClienteMaster.RUT = dreader["RUT"].ToString();
                    cuenta.ClienteMaster.Tipo = (Enums.TipoPersona)dreader["CodTipo"];
                    cuenta.ClienteMaster.FechaCreacion = (DateTime)dreader["FechaCreacionMaster"];
                    if (dreader["AutorizadoAduana"] is DBNull)
                        cuenta.AutorizadoAduana = false;
                    else
                        cuenta.AutorizadoAduana = (bool)dreader["AutorizadoAduana"];

                    if (dreader["IdDireccionInfo"] is DBNull)
                        cuenta.ClienteMaster.DireccionInfo = null;
                    else
                        cuenta.ClienteMaster.DireccionInfo =
                            clsDireccionADO.ListarDireccionesPorIdInfo(Convert.ToInt64(dreader["IdDireccionInfo"]));

                    cuenta.Id = Convert.ToInt64(dreader["IdCuenta"]);

                    if (!(dreader["IdVendedorAsignado"] is DBNull))
                        cuenta.VendedorAsignado =
                            Usuarios.clsUsuarioADO.ObtenerUsuarioPorId(Convert.ToInt16(dreader["IdVendedorAsignado"]));

                    //if (!(dreader["IdCustomerAsignado"] is DBNull))
                    //    cuenta.CustomerAsignado = Usuarios.clsUsuarioADO.ObtenerUsuarioPorId(Convert.ToInt16(dreader["IdCustomerAsignado"]));

                    cuenta.Telefono = dreader["Telefono"].ToString();
                    cuenta.CuentaSkype = dreader["CuentaSkype"].ToString();
                    cuenta.SitioWeb = dreader["SitioWeb"].ToString();
                    cuenta.Email = dreader["Email"].ToString();
                    cuenta.Estado = (Enums.Estado)dreader["IdEstado"];

                    if (!(dreader["IdZonaVentas"] is DBNull))
                        cuenta.ZonaVentas =
                            Parametros.clsParametrosDAO.BuscarParametroPorId(Convert.ToInt16(dreader["IdZonaVentas"]));

                    if (!(dreader["IdCategoriaCliente"] is DBNull))
                        cuenta.CategoriaCliente =
                            Parametros.clsParametrosDAO.BuscarParametroPorId(Convert.ToInt16(dreader["IdCategoriaCliente"]));

                    if (!(dreader["IdClasificacion"] is DBNull))
                        cuenta.Clasificacion = ObtenerClasificacionPorId(Convert.ToInt16(dreader["IdClasificacion"]));

                    cuenta.Observacion = dreader["Observacion"].ToString();

                    if (!(dreader["IdSectorEconomico"] is DBNull))
                        cuenta.SectorEconomico =
                            Parametros.clsParametrosDAO.BuscarParametroPorId(Convert.ToInt16(dreader["IdSectorEconomico"]));

                    if (!(dreader["IdMonedaVtaEst"] is DBNull))
                        cuenta.TipoMonedaVtaEstimada =
                            Parametros.clsParametrosDAO.BuscarMonedaPorId(Convert.ToInt16(dreader["IdMonedaVtaEst"]));

                    if (!(dreader["MontoVtaEst"] is DBNull))
                        cuenta.MontoVentaEstimada = (decimal)dreader["MontoVtaEst"];

                    if (!(dreader["NumEmpleados"] is DBNull))
                        cuenta.NumEmpleados = Convert.ToInt64(dreader["NumEmpleados"]);

                    if (!(dreader["IdUMMovimiento"] is DBNull))
                        cuenta.UMMovimientoEstimado =
                            Parametros.clsParametrosDAO.BuscarParametroPorId(Convert.ToInt16(dreader["IdUMMovimiento"]));

                    if (!(dreader["VolumenMovimiento"] is DBNull))
                        cuenta.MontoMovimientoEstimado = Convert.ToDecimal(dreader["VolumenMovimiento"]);

                    if (!(dreader["IdFormaContactoPref"] is DBNull))
                        cuenta.FormaContactoPreferida =
                            Parametros.clsParametrosDAO.BuscarParametroPorId(Convert.ToInt16(dreader["IdFormaContactoPref"]));

                    cuenta.PermiteTelOficina = (bool)dreader["PermiteTelOfi"];
                    cuenta.PermiteTelParticular = (bool)dreader["PermiteTelPart"];
                    cuenta.PermiteTelCelular = (bool)dreader["PermiteTelCel"];
                    cuenta.PermiteSkype = (bool)dreader["PermiteSkype"];
                    cuenta.PermiteEmail = (bool)dreader["PermiteEmail"];
                    cuenta.PermiteEmailMasivo = (bool)dreader["PermiteEmailMasivo"];

                    if (!(dreader["CodDiaPreferido"] is DBNull))
                        cuenta.DiaPreferido =
                            Parametros.clsParametrosDAO.BuscarParametroPorId(Convert.ToInt16(dreader["CodDiaPreferido"]));

                    if (!(dreader["CodJornadaPreferida"] is DBNull))
                        cuenta.JornadaPreferida =
                            Parametros.clsParametrosDAO.BuscarParametroPorId(Convert.ToInt16(dreader["CodJornadaPreferida"]));

                    cuenta.ClienteMaster.ProductosPreferidos =
                        clsClienteMasterADO.ObtenerProductosPreferidos(cuenta.ClienteMaster.Id);

                    cuenta.ClienteMaster.TiposRelaciones =
                        clsClienteMasterADO.ObtenerTiposRelacion(cuenta.ClienteMaster.Id);

                    res.Estado = Enums.EstadoTransaccion.Aceptada;
                    res.ObjetoTransaccion = cuenta;

                }
            }
            catch (Exception ex)
            {
                Log.EscribirLog(ex.Message);

                res.Estado = Enums.EstadoTransaccion.Rechazada;
                res.Descripcion = ex.Message;
                res.Accion = Enums.AccionTransaccion.Consultar;
            }
            finally
            {
                if(!dreader.IsClosed) dreader.Close();
                conn.Close();
            }

            return res;
        }
Exemplo n.º 4
0
        private void CargarVendedorClienteSeleccionado()
        {
            if (ClienteMaster == null) return;

            ResultadoTransaccion res = new ResultadoTransaccion();
            clsUsuario vendedor = null;

            if (ClienteMaster.Tipo == Enums.TipoPersona.Cuenta)
            {
                clsCuenta cuenta = new clsCuenta();
                res = LogicaNegocios.Clientes.clsCuentas.ObtenerCuentaPorIdMaster(ClienteMaster.Id);
                if (res.Estado == Enums.EstadoTransaccion.Aceptada)
                {
                    cuenta = (clsCuenta)res.ObjetoTransaccion;
                    vendedor = cuenta.VendedorAsignado;
                }

            }
            if (ClienteMaster.Tipo == Enums.TipoPersona.Target)
            {
                clsTarget target = new clsTarget();
                res = LogicaNegocios.Clientes.clsTarget.ObtenerTargetPorIdMaster(ClienteMaster.Id);
                if (res.Estado == Enums.EstadoTransaccion.Aceptada)
                {
                    target = (clsTarget)res.ObjetoTransaccion;
                    vendedor = target.VendedorAsignado;
                }

                //clsTargetAccount taccount = new clsTargetAccount();
                //res = LogicaNegocios.Clientes.clsTargetAccount.ObtenerTargetAccountPorIdMaster(ClienteMaster.Id);
                //if (res.Estado == Enums.EstadoTransaccion.Aceptada)
                //{
                //    taccount = (clsTargetAccount)res.ObjetoTransaccion;
                //    //vendedor = taccount.VendedorAsignado;
                //}

            }

            txtVendedor.Text = "";
            cboVendedor.SelectedIndex = 0;

            if (vendedor != null)
            {
                txtVendedor.Text = vendedor.NombreCompleto;
                cboVendedor.SelectedItem = vendedor;
            }
        }
Exemplo n.º 5
0
        public static ResultadoTransaccion ActualizarCuenta(clsCuenta cuenta)
        {
            resTransaccion = new ResultadoTransaccion();
            try
            {
                //Abrir Conexion
                conn = BaseDatos.Conexion();

                //Crear Transaccion
                transaction = conn.BeginTransaction();

                //Registrar Direcciones
                resTransaccion = clsDireccionADO.GuardarDirecciones(cuenta.ClienteMaster.DireccionInfo, conn, transaction);
                if (resTransaccion.Estado == Enums.EstadoTransaccion.Rechazada)
                    throw new Exception(resTransaccion.Descripcion);

                cuenta.ClienteMaster.DireccionInfo = (clsDireccionInfo)resTransaccion.ObjetoTransaccion;

                //Actualizar Master
                resTransaccion = clsClienteMasterADO.ActualizarClienteMaster(cuenta.ClienteMaster, conn, transaction);
                if (resTransaccion.Estado == Enums.EstadoTransaccion.Rechazada)
                    throw new Exception(resTransaccion.Descripcion);

                //Actualizar Cuenta
                objParams = SqlHelperParameterCache.GetSpParameterSet(conn, "SP_A_CLIENTES_MASTER");
                objParams[0].Value = cuenta.Id;
                objParams[1].Value = cuenta.ClienteMaster.Id;

                if (cuenta.VendedorAsignado != null)
                    objParams[2].Value = cuenta.VendedorAsignado.Id;
                else
                    objParams[2].Value = -1;

                //if (cuenta.CustomerAsignado != null)
                //    objParams[3].Value = cuenta.CustomerAsignado.Id;
                //else
                //    objParams[3].Value = -1;

                objParams[3].Value = cuenta.Telefono;
                objParams[4].Value = cuenta.CuentaSkype;
                objParams[5].Value = cuenta.SitioWeb;
                objParams[6].Value = cuenta.Email;
                objParams[7].Value = cuenta.Estado;

                if (cuenta.ZonaVentas != null)
                    objParams[8].Value = cuenta.ZonaVentas.Id;
                else
                    objParams[8].Value = -1;

                if (cuenta.CategoriaCliente != null)
                    objParams[9].Value = cuenta.CategoriaCliente.Id;
                else
                    objParams[9].Value = -1;

                objParams[10].Value = cuenta.Observacion;

                if (cuenta.SectorEconomico != null)
                    objParams[11].Value = cuenta.SectorEconomico.Id;
                else
                    objParams[11].Value = -1;

                if (cuenta.TipoMonedaVtaEstimada != null)
                    objParams[12].Value = cuenta.TipoMonedaVtaEstimada.Id;
                else
                    objParams[12].Value = -1;

                objParams[13].Value = cuenta.MontoVentaEstimada;
                objParams[14].Value = cuenta.NumEmpleados;

                if (cuenta.UMMovimientoEstimado != null)
                    objParams[15].Value = cuenta.UMMovimientoEstimado.Id;
                else
                    objParams[15].Value = -1;

                objParams[16].Value = cuenta.MontoMovimientoEstimado;

                if (cuenta.FormaContactoPreferida != null)
                    objParams[17].Value = cuenta.FormaContactoPreferida.Id;
                else
                    objParams[17].Value = -1;

                objParams[18].Value = cuenta.PermiteTelOficina;
                objParams[19].Value = cuenta.PermiteTelParticular;
                objParams[20].Value = cuenta.PermiteTelCelular;
                objParams[21].Value = cuenta.PermiteSkype;
                objParams[22].Value = cuenta.PermiteEmail;
                objParams[23].Value = cuenta.PermiteEmailMasivo;
                if (cuenta.DiaPreferido == null)
                    objParams[24].Value = -1;
                else
                    objParams[24].Value = cuenta.DiaPreferido.Id;

                if (cuenta.JornadaPreferida == null)
                    objParams[25].Value = -1;
                else
                    objParams[25].Value = cuenta.JornadaPreferida.Id;

                objParams[26].Value = cuenta.AutorizadoAduana;

                if (cuenta.Clasificacion == null)
                    objParams[27].Value = -1;
                else
                    objParams[27].Value = cuenta.Clasificacion.Id;

                objParams[28].Value = cuenta.TipoReciboAperturaEmbarcador;

                SqlCommand command2 = new SqlCommand("SP_A_CLIENTES_MASTER", conn, transaction);
                command2.Parameters.AddRange(objParams);
                command2.CommandType = CommandType.StoredProcedure;
                command2.ExecuteNonQuery();

                //Productos preferidos

                foreach (var producto in cuenta.ClienteMaster.ProductosPreferidos)
                {
                    if (producto.IsNew && !producto.IsDeleted)
                        clsClienteMasterADO.AsignarTipoProducto(producto, cuenta.ClienteMaster.Id, transaction, conn);
                    else if (!producto.IsNew && !producto.IsDeleted)
                        clsClienteMasterADO.ActualizarTipoProducto(producto, transaction, conn);
                    else if (producto.IsDeleted)
                        clsClienteMasterADO.BorrarProductosPorId(producto.Id,transaction,conn);
                }

                //resTransaccion = clsClienteMasterADO.BorrarProductos(cuenta.ClienteMaster.Id, transaction, conn);
                //if (resTransaccion.Estado == Enums.EstadoTransaccion.Aceptada)
                //{
                //    foreach (var producto in cuenta.ClienteMaster.ProductosPreferidos)
                //    {
                //        clsClienteMasterADO.AsignarTipoProducto(producto, cuenta.ClienteMaster.Id, transaction, conn);
                //    }
                //}
                //else
                //    throw new Exception(resTransaccion.Descripcion);

                //Tipos Relacion
                resTransaccion = clsClienteMasterADO.BorrarTipoRelacion(cuenta.ClienteMaster.Id, transaction, conn);
                if (resTransaccion.Estado == Enums.EstadoTransaccion.Aceptada)
                {
                    foreach (var relacion in cuenta.ClienteMaster.TiposRelaciones)
                    {
                        clsClienteMasterADO.AsignarTipoRelacion(relacion, cuenta.ClienteMaster.Id, transaction, conn);
                    }
                }
                else
                    throw new Exception(resTransaccion.Descripcion);

                //Condiciones comerciales
                //resTransaccion = clsCondicionComercialDAO.GuardaCondicionComercialCliente(cuenta.ClienteMaster, conn,
                                                                                       //   transaction);
                //if(resTransaccion.Estado == Enums.EstadoTransaccion.Rechazada)
                //    throw new Exception(resTransaccion.Descripcion);

                //Ejecutar transaccion
                transaction.Commit();

                resTransaccion.Estado = Enums.EstadoTransaccion.Aceptada;
                resTransaccion.Descripcion = "Se actualizo Cuenta con Id " + cuenta.Id.ToString();

                //Registrar Actividad
                LogActividadUsuarios log = new LogActividadUsuarios(cuenta.GetType().ToString(), cuenta.Id, Enums.TipoActividadUsuario.Edito, Base.Usuario.UsuarioConectado.Usuario);
                LogActividades.clsLogActividadUsuariosADO.GuardaActividad(log);

            }
            catch (Exception ex)
            {
                transaction.Rollback();
                Log.EscribirLog(ex.Message);

                resTransaccion.Estado = Enums.EstadoTransaccion.Rechazada;
                resTransaccion.Descripcion = ex.Message;
            }
            finally
            {
                conn.Close();
                resTransaccion.Accion = Enums.AccionTransaccion.Actualizar;
                resTransaccion.ObjetoTransaccion = cuenta;
            }

            return resTransaccion;
        }
Exemplo n.º 6
0
        public static IList<clsCuenta> ListarCuentas(string nombre, Int64 vendedor, Int64 customer, int idEstado)
        {
            IList<clsCuenta> listTarget = new List<clsCuenta>();
            clsCuenta cuenta;

            try
            {
                //Abrir Conexion
                conn = BaseDatos.Conexion();

                //Registrar Cliente Master
                objParams = SqlHelperParameterCache.GetSpParameterSet(conn, "SP_L_CLIENTES_CUENTAS");
                objParams[0].Value = nombre;
                objParams[1].Value = vendedor;
                objParams[2].Value = customer;
                objParams[3].Value = idEstado;
                SqlCommand command = new SqlCommand("SP_L_CLIENTES_CUENTAS", conn);
                command.Parameters.AddRange(objParams);
                command.CommandType = CommandType.StoredProcedure;
                dreader = command.ExecuteReader();

                while (dreader.Read())
                {
                    cuenta = new clsCuenta();
                    cuenta.ClienteMaster.Id = Convert.ToInt64(dreader[0]);
                    cuenta.Id = Convert.ToInt64(dreader[1]);
                    cuenta.ClienteMaster.NombreCompañia = dreader[2].ToString();
                    cuenta.ClienteMaster.RUT = dreader[3].ToString();

                    if (dreader[4] is DBNull)
                        cuenta.VendedorAsignado = null;
                    else
                        cuenta.VendedorAsignado = new clsUsuario(dreader[4].ToString(), dreader[5].ToString(), dreader[6].ToString());

                    //if (dreader[7] is DBNull)
                    //    cuenta.CustomerAsignado = null;
                    //else
                    //    cuenta.CustomerAsignado = new clsUsuario(dreader[7].ToString(), dreader[8].ToString(), dreader[9].ToString());

                    cuenta.Telefono = dreader[7].ToString();
                    cuenta.CuentaSkype = dreader[8].ToString();
                    cuenta.SitioWeb = dreader[9].ToString();
                    cuenta.Email = dreader[10].ToString();
                    cuenta.Estado = (Enums.Estado)Convert.ToInt16(dreader[11]);
                    cuenta.ClienteMaster.NombreFantasia = dreader[12].ToString();
                    listTarget.Add(cuenta);
                }
            }
            catch (Exception ex)
            {
                Log.EscribirLog(ex.Message);

            }
            finally
            {
                conn.Close();
            }

            return listTarget;
        }
Exemplo n.º 7
0
        public static ResultadoTransaccion GuardarCuenta(clsCuenta cuenta)
        {
            resTransaccion = new ResultadoTransaccion();
            Int64 idMaster = 0;
            Int64 idCuenta = 0;
            try
            {
                //Abrir Conexion
                conn = BaseDatos.Conexion();

                //Crear Transaccion
                transaction = conn.BeginTransaction();

                //Registrar Direcciones
                resTransaccion = clsDireccionADO.GuardarDirecciones(cuenta.ClienteMaster.DireccionInfo, conn, transaction);
                if (resTransaccion.Estado == Enums.EstadoTransaccion.Rechazada)
                {
                    throw new Exception(resTransaccion.Descripcion);
                }
                cuenta.ClienteMaster.DireccionInfo = (clsDireccionInfo)resTransaccion.ObjetoTransaccion;

                //Registrar Cliente Master
                resTransaccion = clsClienteMasterADO.GuardarClienteMaster(cuenta.ClienteMaster, conn,
                                                                                          transaction);
                if (resTransaccion.Estado == Enums.EstadoTransaccion.Rechazada)
                    throw new Exception(resTransaccion.Descripcion);

                idMaster = (Int64)resTransaccion.ObjetoTransaccion;

                //Registrar Cuenta
                objParams = SqlHelperParameterCache.GetSpParameterSet(conn, "SP_N_CLIENTES_CUENTA");
                objParams[0].Value = idMaster;

                if (cuenta.VendedorAsignado != null)
                    objParams[1].Value = cuenta.VendedorAsignado.Id;
                else
                    objParams[1].Value = -1;

                //if (cuenta.CustomerAsignado != null)
                //    objParams[2].Value = cuenta.CustomerAsignado.Id;
                //else
                //    objParams[2].Value = -1;

                objParams[2].Value = cuenta.Telefono;
                objParams[3].Value = cuenta.CuentaSkype;
                objParams[4].Value = cuenta.SitioWeb;
                objParams[5].Value = cuenta.Email;
                objParams[6].Value = cuenta.Estado;

                if (cuenta.ZonaVentas == null)
                    objParams[7].Value = -1;
                else
                    objParams[7].Value = cuenta.ZonaVentas.Id;

                if (cuenta.CategoriaCliente == null)
                    objParams[8].Value = -1;
                else
                    objParams[8].Value = cuenta.CategoriaCliente.Id;

                objParams[9].Value = cuenta.Observacion;

                if (cuenta.SectorEconomico != null)
                    objParams[10].Value = cuenta.SectorEconomico.Id;
                else
                    objParams[10].Value = -1;

                if (cuenta.TipoMonedaVtaEstimada != null)
                    objParams[11].Value = cuenta.TipoMonedaVtaEstimada.Id;
                else
                    objParams[11].Value = -1;

                objParams[12].Value = cuenta.MontoVentaEstimada;
                objParams[13].Value = cuenta.NumEmpleados;

                if (cuenta.UMMovimientoEstimado != null)
                    objParams[14].Value = cuenta.UMMovimientoEstimado.Id;
                else
                    objParams[14].Value = -1;

                objParams[15].Value = cuenta.MontoMovimientoEstimado;

                if (cuenta.FormaContactoPreferida != null)
                    objParams[16].Value = cuenta.FormaContactoPreferida.Id;
                else
                    objParams[16].Value = -1;

                objParams[17].Value = cuenta.PermiteTelOficina;
                objParams[18].Value = cuenta.PermiteTelParticular;
                objParams[19].Value = cuenta.PermiteTelCelular;
                objParams[20].Value = cuenta.PermiteSkype;
                objParams[21].Value = cuenta.PermiteEmail;
                objParams[22].Value = cuenta.PermiteEmailMasivo;
                if (cuenta.DiaPreferido == null)
                    objParams[23].Value = -1;
                else
                    objParams[23].Value = cuenta.DiaPreferido.Id;

                if (cuenta.JornadaPreferida == null)
                    objParams[24].Value = -1;
                else
                    objParams[24].Value = cuenta.JornadaPreferida.Id;

                objParams[25].Value = cuenta.AutorizadoAduana;

                if (cuenta.Clasificacion == null)
                    objParams[26].Value = -1;
                else
                    objParams[26].Value = cuenta.Clasificacion.Id;

                SqlCommand command2 = new SqlCommand("SP_N_CLIENTES_CUENTA", conn);
                command2.Transaction = transaction;
                command2.Parameters.AddRange(objParams);
                command2.CommandType = CommandType.StoredProcedure;
                idCuenta = Convert.ToInt64(command2.ExecuteScalar());
                cuenta.Id = idCuenta;
                if (idMaster > 0)
                {
                    //Productos preferidos
                    //clsClienteMasterADO.BorrarProductos(idTarget, transaction,conn);
                    foreach (var producto in cuenta.ClienteMaster.ProductosPreferidos)
                    {
                        clsClienteMasterADO.AsignarTipoProducto(producto, idMaster, transaction, conn);
                    }

                    //Tipos Relacion
                    //clsClienteMasterADO.BorrarTipoRelacion(idMaster, transaction, conn);
                    foreach (var relacion in cuenta.ClienteMaster.TiposRelaciones)
                    {
                        clsClienteMasterADO.AsignarTipoRelacion(relacion, idMaster, transaction, conn);
                    }
                }

                //Ejecutar transaccion
                transaction.Commit();

                resTransaccion.Estado = Enums.EstadoTransaccion.Aceptada;
                resTransaccion.Descripcion = "Se Creo Cuenta con Id " + idMaster.ToString();

                //Registrar Actividad
                LogActividadUsuarios log = new LogActividadUsuarios(cuenta.GetType().ToString(), cuenta.Id, Enums.TipoActividadUsuario.Creo, Base.Usuario.UsuarioConectado.Usuario);
                LogActividades.clsLogActividadUsuariosADO.GuardaActividad(log);

            }
            catch (Exception ex)
            {
                transaction.Rollback();
                Log.EscribirLog(ex.Message);

                resTransaccion.Estado = Enums.EstadoTransaccion.Rechazada;
                resTransaccion.Descripcion = ex.Message;
                resTransaccion.ArchivoError = "clsCuentaADO";
                resTransaccion.MetodoError = MethodBase.GetCurrentMethod().Name;

            }
            finally
            {
                conn.Close();
                resTransaccion.Accion = Enums.AccionTransaccion.Insertar;
                cuenta.Id = idCuenta;
                cuenta.ClienteMaster.Id = idMaster;
                resTransaccion.ObjetoTransaccion = cuenta;
            }

            return resTransaccion;
        }
Exemplo n.º 8
0
        public static ResultadoTransaccion EliminarCuenta(clsCuenta cuenta)
        {
            ResultadoTransaccion resTransaccion = new ResultadoTransaccion();
            try
            {
                transaction = BaseDatos.Conexion().BeginTransaction();

                //Eliminar Direcciones
                if (cuenta.ClienteMaster.DireccionInfo != null)
                {
                    foreach (var direccion in cuenta.ClienteMaster.DireccionInfo.Items)
                    {
                        resTransaccion = new ResultadoTransaccion();
                        resTransaccion = clsDireccionADO.EliminarDireccion(direccion, transaction);

                        if (resTransaccion.Estado == Enums.EstadoTransaccion.Rechazada)
                            throw new Exception(resTransaccion.Descripcion);
                    }

                    resTransaccion = new ResultadoTransaccion();
                    resTransaccion = clsDireccionADO.EliminarDireccionInfo(cuenta.ClienteMaster.DireccionInfo.IdInfo,
                                                                           transaction);
                    if (resTransaccion.Estado == Enums.EstadoTransaccion.Rechazada)
                        throw new Exception(resTransaccion.Descripcion);

                }

                //Eliminar Tipos de Relacion
                resTransaccion = new ResultadoTransaccion();
                resTransaccion = clsClienteMasterADO.BorrarTipoRelacion(cuenta.ClienteMaster.Id, transaction, conn);
                if (resTransaccion.Estado == Enums.EstadoTransaccion.Rechazada)
                    throw new Exception(resTransaccion.Descripcion);

                //Eliminar Tipos de Carga
                resTransaccion = new ResultadoTransaccion();
                resTransaccion = clsClienteMasterADO.BorrarProductos(cuenta.ClienteMaster.Id, transaction, conn);
                if (resTransaccion.Estado == Enums.EstadoTransaccion.Rechazada)
                    throw new Exception(resTransaccion.Descripcion);

                //Eliminar Cliente Master
                resTransaccion = new ResultadoTransaccion();
                resTransaccion = clsClienteMasterADO.EliminarClienteMaster(cuenta.ClienteMaster, transaction);
                if (resTransaccion.Estado == Enums.EstadoTransaccion.Rechazada)
                    throw new Exception(resTransaccion.Descripcion);

                //Eliminar Contactos
                IList<clsContacto> listContactos = new List<clsContacto>();
                listContactos = clsClienteMasterADO.ListarContactos(cuenta.ClienteMaster);
                foreach (var contacto in listContactos)
                {
                    resTransaccion = new ResultadoTransaccion();
                    resTransaccion = clsContactoADO.EliminarContacto(contacto, transaction);
                    if (resTransaccion.Estado == Enums.EstadoTransaccion.Rechazada)
                        throw new Exception(resTransaccion.Descripcion);
                }

                //Eliminar Cuenta
                objParams = SqlHelperParameterCache.GetSpParameterSet(BaseDatos.Conexion(), "SP_E_CLIENTES_CUENTA");
                objParams[0].Value = cuenta.Id;

                SqlCommand command = new SqlCommand("SP_E_CLIENTES_CUENTA", BaseDatos.Conexion());
                command.Parameters.AddRange(objParams);
                command.CommandType = CommandType.StoredProcedure;
                command.Transaction = transaction;
                command.ExecuteNonQuery();
                resTransaccion.Estado = Enums.EstadoTransaccion.Aceptada;

                transaction.Commit();

                //Registrar Actividad
                LogActividadUsuarios log = new LogActividadUsuarios(cuenta.GetType().ToString(), cuenta.Id, Enums.TipoActividadUsuario.Elimino, Base.Usuario.UsuarioConectado.Usuario);
                LogActividades.clsLogActividadUsuariosADO.GuardaActividad(log);

            }
            catch (Exception ex)
            {
                transaction.Rollback();
                resTransaccion.Estado = Enums.EstadoTransaccion.Rechazada;
                resTransaccion.Descripcion = ex.Message;
                Log.EscribirLog(ex.Message);
            }
            finally
            {
                BaseDatos.CerrarConexion();
            }
            return resTransaccion;
        }
Exemplo n.º 9
0
        public static ResultadoTransaccion CambiaEstado(clsCuenta cuenta)
        {
            ResultadoTransaccion resTransaccion = new ResultadoTransaccion();
            try
            {
                objParams = SqlHelperParameterCache.GetSpParameterSet(BaseDatos.Conexion(), "SP_A_CLIENTES_CUENTA_CAMBIA_ESTADO");
                objParams[0].Value = cuenta.Id;
                objParams[1].Value = (Int16)cuenta.Estado;

                SqlCommand command = new SqlCommand("SP_A_CLIENTES_CUENTA_CAMBIA_ESTADO", BaseDatos.Conexion());
                command.Parameters.AddRange(objParams);
                command.CommandType = CommandType.StoredProcedure;
                command.ExecuteNonQuery();
                resTransaccion.Estado = Enums.EstadoTransaccion.Aceptada;

            }
            catch (Exception ex)
            {
                resTransaccion.Estado = Enums.EstadoTransaccion.Rechazada;
                resTransaccion.Descripcion = ex.Message;
                Log.EscribirLog(ex.Message);
            }
            finally
            {
                BaseDatos.CerrarConexion();
            }
            return resTransaccion;
        }
Exemplo n.º 10
0
 private PaperlessTipoCliente ObtieneTipodeCliente(PaperlessUsuario1HousesBL house)
 {
     clsCuenta cuenta = new clsCuenta();
     PaperlessTipoCliente ptc = new PaperlessTipoCliente();
     if (house.Cliente != null) {
         var transaccion = LogicaNegocios.Clientes.clsCuentas.BuscarCuentaPorId(house.Cliente.Id);
         if (transaccion != null) {
             cuenta = (clsCuenta)transaccion.ObjetoTransaccion;
             if (cuenta != null && cuenta.ClienteMaster.ClienteMasterTipoCliente != null) {
                 if (cuenta.ClienteMaster.ClienteMasterTipoCliente.Count.Equals(0) ||
                     cuenta.ClienteMaster.ClienteMasterTipoCliente.Count > 1) {
                     house.TipoCliente = null;
                 } else {
                     ptc.Nombre = cuenta.ClienteMaster.ClienteMasterTipoCliente[0].Nombre;
                     ptc.Id = cuenta.ClienteMaster.ClienteMasterTipoCliente[0].Id;
                     house.TipoCliente = ptc;
                 }
             }
         }
     }
     return house.TipoCliente;
 }
Exemplo n.º 11
0
        private void BuscaCuentaPorId(Int64 IdCuenta)
        {
            clsCuenta cuenta = new clsCuenta();
                ResultadoTransaccion transaccion =
                    LogicaNegocios.Clientes.clsCuentas.BuscarCuentaPorId(IdCuenta);

                if (transaccion.Estado == Enums.EstadoTransaccion.Rechazada)
                {
                    this.CuentaActual = null;
                    //MessageBox.Show("No se pudo cargar la Cuenta", "Cuentas", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                cuenta = (clsCuenta)transaccion.ObjetoTransaccion;

                this.CuentaActual = cuenta;
        }