예제 #1
0
        public Boolean ModificarDB(ct_cbtecble_Plantilla_Info Pla_I)
        {
            try
            {
                List <ct_cbtecble_Plantilla_det_Info> listadetalle = new List <ct_cbtecble_Plantilla_det_Info>();
                listadetalle = Pla_I.LstDet;
                using (EntitiesDBConta context = new EntitiesDBConta())
                {
                    var contact = context.ct_cbtecble_Plantilla.FirstOrDefault(v => v.IdEmpresa == Pla_I.IdEmpresa &&
                                                                               v.IdTipoCbte == Pla_I.IdTipoCbte && v.IdPlantilla == Pla_I.IdPlantilla);

                    if (contact != null)
                    {
                        contact.cb_Estado        = Pla_I.cb_Estado;
                        contact.IdPlantilla      = Pla_I.IdPlantilla;
                        contact.IdUsuarioUltModi = (Pla_I.IdUsuarioUltModi != "") ? Pla_I.IdUsuarioUltModi : Pla_I.IdUsuario;
                        contact.cb_Fecha         = Pla_I.cb_Fecha;
                        contact.cb_FechaUltModi  = Convert.ToDateTime(DateTime.Now.ToShortDateString());
                        contact.cb_Observacion   = Pla_I.cb_Observacion;
                        context.SaveChanges();


                        ct_cbtecble_Plantilla_det_Data _Pla_Det_Data = new ct_cbtecble_Plantilla_det_Data();

                        int count = 0;
                        if (_Pla_Det_Data.EliminarDB(Pla_I.IdEmpresa, Pla_I.IdTipoCbte, Pla_I.IdPlantilla))
                        {
                            ct_cbtecble_Plantilla_det_Data data = new ct_cbtecble_Plantilla_det_Data();
                            foreach (var reg in listadetalle)
                            {
                                reg.IdEmpresa   = Pla_I.IdEmpresa;
                                reg.IdTipoCbte  = Pla_I.IdTipoCbte;
                                reg.IdPlantilla = Pla_I.IdPlantilla;
                                //reg.secuencia = count++;
                                data.GrabarDB(reg);
                            }
                        }
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                string arreglo = ToString();
                tb_sis_Log_Error_Vzen_Data oDataLog      = new tb_sis_Log_Error_Vzen_Data();
                tb_sis_Log_Error_Vzen_Info Log_Error_sis = new tb_sis_Log_Error_Vzen_Info(ex.ToString(), "", arreglo, "",
                                                                                          "", "", "", "", DateTime.Now);
                oDataLog.Guardar_Log_Error(Log_Error_sis, ref mensaje);
                mensaje = ex.ToString();
                throw new Exception(ex.ToString());
            }
        }
예제 #2
0
        public Boolean GrabarDB(ct_cbtecble_Plantilla_Info Info, ref decimal ID, ref string msg)
        {
            try
            {
                int IdSecuencia = 0;
                ID = Get_IdPlantilla(Info.IdEmpresa);
                Info.IdPlantilla = ID;
                ct_Cbtecble_tipo_Data data = new ct_Cbtecble_tipo_Data();
                string codigo_CbteCble;

                if (data.Get_Codigo_x_CbtCble_tipo(Info.IdEmpresa, Info.IdTipoCbte, ref msg) == null)
                {
                    msg = "ID Tipo Comprobante no existe";
                    return(false);
                }

                using (EntitiesDBConta context = new EntitiesDBConta())
                {
                    EntitiesDBConta EDB = new EntitiesDBConta();

                    var Q = from tbCbteCble in EDB.ct_cbtecble_Plantilla
                            where tbCbteCble.IdEmpresa == Info.IdEmpresa &&
                            tbCbteCble.IdTipoCbte == Info.IdTipoCbte &&
                            tbCbteCble.IdPlantilla == Info.IdPlantilla
                            select tbCbteCble;

                    if (Q.ToList().Count == 0)
                    {
                        var address = new ct_cbtecble_Plantilla();

                        address.IdPlantilla      = ID;
                        address.IdEmpresa        = Info.IdEmpresa;
                        address.IdTipoCbte       = Info.IdTipoCbte;
                        address.cb_Fecha         = Info.cb_Fecha;
                        address.cb_Observacion   = Info.cb_Observacion;
                        address.cb_Estado        = Info.cb_Estado;
                        address.IdUsuario        = Info.IdUsuario;
                        address.IdUsuarioUltModi = Info.IdUsuario;
                        address.cb_FechaTransac  = Info.cb_FechaTransac;
                        address.cb_FechaUltModi  = Info.cb_FechaTransac;

                        context.ct_cbtecble_Plantilla.Add(address);
                        context.SaveChanges();

                        ct_cbtecble_Plantilla_det_Data PlaDet_Data = new ct_cbtecble_Plantilla_det_Data();
                        foreach (var item in Info.LstDet)
                        {
                            item.IdPlantilla = ID;
                            item.IdEmpresa   = Info.IdEmpresa;
                            item.IdPlantilla = Info.IdPlantilla;
                            item.IdTipoCbte  = Info.IdTipoCbte;
                            PlaDet_Data.GrabarDB(item);
                        }
                        msg = "Se ha procedido a generar el la Plantilla #: " + ID.ToString() + " para el tipo de comprobante #: " + Info.IdTipoCbte + " exitosamente.";
                    }
                    else
                    {
                        msg = "No se pudo guardar la Plantilla debido a que el id de Plantilla existe";
                        return(false);
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                string arreglo = ToString();
                tb_sis_Log_Error_Vzen_Data oDataLog      = new tb_sis_Log_Error_Vzen_Data();
                tb_sis_Log_Error_Vzen_Info Log_Error_sis = new tb_sis_Log_Error_Vzen_Info(ex.ToString(), "", arreglo, "",
                                                                                          "", "", "", "", DateTime.Now);
                oDataLog.Guardar_Log_Error(Log_Error_sis, ref mensaje);
                mensaje = ex.ToString();

                msg = "Mensaje de error: " + ex.Message;
                throw new Exception(ex.ToString());
            }
        }