コード例 #1
0
        public void Grava_Futuro_Abatimento_Cliente(decimal?VALOR, DataContext ctx)
        {
            System.Data.Linq.Table <TB_SALDO_CLIENTE_FORNECEDOR> Entidade = ctx.GetTable <TB_SALDO_CLIENTE_FORNECEDOR>();

            TB_SALDO_CLIENTE_FORNECEDOR novo = new TB_SALDO_CLIENTE_FORNECEDOR();

            if (CODIGO_CLIENTE == 0)
            {
                CODIGO_CLIENTE = BuscaCodigoCliente();
            }

            novo.CODIGO_CLIENTE        = CODIGO_CLIENTE;
            novo.CODIGO_FORNECEDOR     = 0;
            novo.NUMERO_SEQ_NF_SAIDA   = 0;
            novo.NUMERO_ITEM_NFS       = 0;
            novo.NUMERO_SEQ_NF_ENTRADA = NUMERO_SEQ_NF_ENTRADA;
            novo.NUMERO_ITEM_NFE       = NUMERO_ITEM_NF_ENTRADA;
            novo.DATA_LANCAMENTO       = DateTime.Now;
            novo.VALOR_LANCAMENTO      = VALOR;
            novo.SALDO_RESTANTE        = VALOR;

            Entidade.InsertOnSubmit(novo);

            Doran_Base.Auditoria_ERP_Servicos.Doran_Auditoria.Audita_Insert(ctx, novo, Entidade.ToString(), ID_USUARIO);
        }
コード例 #2
0
        //public static List<T> LinqCache<T>(this System.Data.Linq.Table<T> query) where T : class
        //{
        //    string tableName = query.Context.Mapping.GetTable(typeof(T)).TableName;
        //    //List<T> result = HttpContext.Current.Cache[tableName] as List<T>;
        //    List<T> result = ApplicationState.GetValue<List<T>>(tableName) as List<T>;

        //    if (result == null)
        //    {
        //        using (SqlConnection cn = new SqlConnection(query.Context.Connection.ConnectionString))
        //        {
        //            cn.Open();
        //            SqlCommand cmd = new SqlCommand(query.Context.GetCommand(query).CommandText, cn);
        //            cmd.Notification = null;
        //            cmd.NotificationAutoEnlist = true;
        //            SqlCacheDependencyAdmin.EnableNotifications(query.Context.Connection.ConnectionString);
        //            if (!SqlCacheDependencyAdmin.GetTablesEnabledForNotifications(query.Context.Connection.ConnectionString).Contains(tableName))
        //            {
        //                SqlCacheDependencyAdmin.EnableTableForNotifications(query.Context.Connection.ConnectionString, tableName);
        //            }

        //            SqlCacheDependency dependency = new SqlCacheDependency(cmd);
        //            //cmd.ExecuteNonQuery();

        //            //result = query.ToList();
        //            result = query.Context.Translate<T>(cmd.ExecuteReader()).ToList();

        //            //HttpContext.Current.Cache.Insert(tableName, result, dependency);
        //            ApplicationState.SetValue(tableName, result);
        //        }
        //    }
        //    return result;
        //}



        public static List <T> LinqCache <T>(this System.Data.Linq.Table <T> query) where T : class
        {
            try
            {
                string tableName = query.Context.Mapping.GetTable(typeof(T)).TableName;

                DateTime lastUsedCache = ApplicationState.GetValue <DateTime>(tableName + "CacheDate");

                List <T> result = null;

                if (lastUsedCache != null && lastUsedCache.AddSeconds(8) > DateTime.Now)
                {
                    result = ApplicationState.GetValue <List <T> >(tableName + "Cache") as List <T>;
                }


                if (result == null)
                {
                    using (SqlConnection cn = new SqlConnection(query.Context.Connection.ConnectionString))
                    {
                        cn.Open();
                        SqlCommand cmd = new SqlCommand(query.Context.GetCommand(query).CommandText, cn);
                        cmd.ExecuteNonQuery();

                        result = query.ToList();

                        ApplicationState.SetValue(tableName + "Cache", result);

                        // make sure we DO use the cache the next time
                        ApplicationState.SetValue(tableName + "CacheDate", DateTime.Now);
                    }
                }
                return(result);
            }
            catch (Exception ex)
            {
                throw new Exception("Error in caching systeem", ex);
            }
        }
コード例 #3
0
        /// <summary>
        /// Calcula os impostos do item da nota fiscal (ICMS, Base ICMS, ICMS de Substituição, ICMS de Substituição e Total IPI,
        /// e grava na tabela TB_ITEM_NOTA_SAIDA
        /// </summary>
        /// <param name="dados">Objeto JSON com as informações das colunas da tabela</param>
        /// <returns>Retorna os totais da nota</returns>
        public Dictionary <string, object> Calcula_e_Grava_Item_Nota_Saida(Dictionary <string, object> dados)
        {
            using (Doran_ERP_Servicos_DadosDataContext ctx = new Doran_ERP_Servicos_DadosDataContext())
            {
                try
                {
                    ctx.Connection.Open();
                    ctx.Transaction = ctx.Connection.BeginTransaction(IsolationLevel.ReadUncommitted);

                    decimal CODIGO_CLIENTE = dados.ContainsKey("ID_CLIENTE") ?
                                             decimal.TryParse(dados["ID_CLIENTE"].ToString(), out CODIGO_CLIENTE) ?
                                             Convert.ToDecimal(dados["ID_CLIENTE"]) : 0
                                : 0;

                    if (!dados.ContainsKey("ID_PRODUTO"))
                    {
                        dados.Add("ID_PRODUTO", Busca_ID_PRODUTO(dados["CODIGO_PRODUTO_ITEM_NF"].ToString()));
                    }

                    decimal ALIQ_ISS = dados.ContainsKey("ALIQ_ISS_ITEM_NF") ? decimal.TryParse(dados["ALIQ_ISS_ITEM_NF"].ToString(), out ALIQ_ISS) ?
                                       Convert.ToDecimal(dados["ALIQ_ISS_ITEM_NF"]) : 0 :
                                       decimal.TryParse(dados["ALIQ_ISS"].ToString(), out ALIQ_ISS) ?
                                       Convert.ToDecimal(dados["ALIQ_ISS"]) : 0;

                    decimal VALOR_TOTAL_ITEM_NF = Convert.ToDecimal(dados["VALOR_TOTAL_ITEM_NF"]);

                    decimal VALOR_ISS_ITEM_NF = ALIQ_ISS > Convert.ToDecimal(0.00) ?
                                                Math.Round(VALOR_TOTAL_ITEM_NF * (ALIQ_ISS / 100), 2, MidpointRounding.ToEven) : 0;

                    decimal BASE_ISS_ITEM_NF = VALOR_TOTAL_ITEM_NF;

                    System.Data.Linq.Table <TB_ITEM_NOTA_SAIDA> Entidade = ctx.GetTable <TB_ITEM_NOTA_SAIDA>();

                    TB_ITEM_NOTA_SAIDA novo = new TB_ITEM_NOTA_SAIDA();

                    novo.NUMERO_ITEM_NF            = _NUMERO_SEQ;
                    novo.ID_PRODUTO_ITEM_NF        = Convert.ToDecimal(dados["ID_PRODUTO"]);
                    novo.CODIGO_PRODUTO_ITEM_NF    = dados["CODIGO_PRODUTO_ITEM_NF"].ToString();
                    novo.DESCRICAO_PRODUTO_ITEM_NF = dados["DESCRICAO_PRODUTO_ITEM_NF"].ToString();

                    novo.UNIDADE_MEDIDA_ITEM_NF = dados["UNIDADE_MEDIDA_ITEM_NF"].ToString();
                    novo.QTDE_ITEM_NF           = Convert.ToDecimal(dados["QTDE_ITEM_NF"]);
                    novo.VALOR_UNITARIO_ITEM_NF = Convert.ToDecimal(dados["VALOR_UNITARIO_ITEM_NF"]);

                    novo.VALOR_DESCONTO_ITEM_NF = dados.ContainsKey("VALOR_DESCONTO_ITEM_NF") ?
                                                  Convert.ToDecimal(dados["VALOR_DESCONTO_ITEM_NF"]) : 0;

                    novo.VALOR_TOTAL_ITEM_NF = VALOR_TOTAL_ITEM_NF;
                    novo.VALOR_ISS_ITEM_NF   = VALOR_ISS_ITEM_NF;
                    novo.ALIQ_ISS_ITEM_NF    = ALIQ_ISS;
                    novo.BASE_ISS_ITEM_NF    = BASE_ISS_ITEM_NF;

                    novo.NUMERO_PEDIDO_VENDA = dados.ContainsKey("NUMERO_PEDIDO_VENDA") ?
                                               Convert.ToDecimal(dados["NUMERO_PEDIDO_VENDA"]) : 0;

                    novo.NUMERO_ITEM_PEDIDO_VENDA = dados.ContainsKey("NUMERO_ITEM_PEDIDO_VENDA") ?
                                                    Convert.ToDecimal(dados["NUMERO_ITEM_PEDIDO_VENDA"]) : 0;

                    Entidade.InsertOnSubmit(novo);

                    Doran_Base.Auditoria_ERP_Servicos.Doran_Auditoria.Audita_Insert(ctx, novo, Entidade.ToString(), ID_USUARIO);

                    ctx.SubmitChanges();

                    Dictionary <string, decimal> linha1 = new Dictionary <string, decimal>();

                    linha1.Add("TOTAL_SERVICOS_NF", VALOR_TOTAL_ITEM_NF);
                    linha1.Add("TOTAL_ISS_NF", VALOR_ISS_ITEM_NF);
                    linha1.Add("BASE_ISS_NF", BASE_ISS_ITEM_NF);

                    ctx.Transaction.Commit();

                    return(Calcula_e_Grava_Totais_Nota_Saida(linha1, true));
                }
                catch
                {
                    ctx.Transaction.Rollback();
                    throw;
                }
            }
        }
コード例 #4
0
 public static int Delete <TEntity>(this System.Data.Linq.Table <TEntity> source, System.Linq.Expressions.Expression <Func <TEntity, bool> > predicate) where TEntity : class
 {
     System.Data.Linq.DataContext dc = source.Context;
     System.Data.Common.DbCommand c  = dc.GetCommand(source.Where(predicate));
     return(Delete(c));
 }
コード例 #5
0
 public static TEntity SelectByPrimaryKey <TEntity>(this System.Data.Linq.Table <TEntity> source, TEntity PrimaryKey) where TEntity : class
 {
     return(null);
 }
コード例 #6
0
 public static void DeleteByPrimaryKey <TEntity>(this System.Data.Linq.Table <TEntity> source, TEntity PrimaryKey) where TEntity : class
 {
 }
コード例 #7
0
 public static void UpdateByPrimaryKey <TEntity>(this System.Data.Linq.Table <TEntity> source, TEntity PrimaryKey, object NewValues) where TEntity : class
 {
 }
コード例 #8
0
 public static void Update <TEntity>(this System.Data.Linq.Table <TEntity> source, System.Linq.Expressions.Expression <Func <TEntity, int, bool> > predicate, object NewValues) where TEntity : class
 {
 }
コード例 #9
0
        public Dictionary <string, object> Calcula_e_Grava_Item_Nota_Entrada(Dictionary <string, object> dados)
        {
            string str_conn = ConfigurationManager.ConnectionStrings["Doran_Servicos_ORM.Properties.Settings.Doran_ERP_ServicosConnectionString"].ConnectionString;

            using (Doran_ERP_Servicos_DadosDataContext ctx1 = new Doran_ERP_Servicos_DadosDataContext())
            {
                string CODIGO_CFOP    = dados["CODIGO_CFOP_ITEM_NFE"].ToString();
                string CLAS_FISCAL_NF = dados["CODIGO_CF_ITEM_NFE"].ToString();


                decimal VALOR_TOTAL_ITEM_NFE = Convert.ToDecimal(dados["VALOR_TOTAL_ITEM_NFE"]);
                decimal VALOR_IPI_ITEM_NFE   = Math.Round(VALOR_TOTAL_ITEM_NFE * (Convert.ToDecimal(dados["ALIQ_IPI_ITEM_NFE"]) / 100), 2);

                decimal ALIQ_ICMS_ITEM_NFE = Convert.ToDecimal(dados["ALIQ_ICMS_ITEM_NFE"]);
                decimal BASE_ICMS_ITEM_NFE = dados.ContainsKey("BASE_ICMS_ITEM_NFE") ?
                                             Convert.ToDecimal(dados["BASE_ICMS_ITEM_NFE"]) :
                                             Convert.ToDecimal(dados["VALOR_TOTAL_ITEM_NFE"]);

                decimal VALOR_ICMS_ITEM_NFE = Math.Round(BASE_ICMS_ITEM_NFE * (ALIQ_ICMS_ITEM_NFE / 100), 2);

                decimal BASE_ICMS_SUBS_ITEM_NFE  = Convert.ToDecimal(dados["BASE_ICMS_SUBS_ITEM_NFE"]);
                decimal VALOR_ICMS_SUBS_ITEM_NFE = Convert.ToDecimal(dados["VALOR_ICMS_SUBS_ITEM_NFE"]);

                try
                {
                    ctx1.Connection.ConnectionString = str_conn;
                    ctx1.Connection.Open();
                    ctx1.Transaction = ctx1.Connection.BeginTransaction(IsolationLevel.ReadUncommitted);

                    decimal ID_PRODUTO = 0;

                    if (!dados.ContainsKey("ID_PRODUTO"))
                    {
                        var query = (from linha1 in ctx1.TB_PRODUTOs
                                     where linha1.CODIGO_PRODUTO == dados["CODIGO_PRODUTO_ITEM_NFE"].ToString()
                                     select new
                        {
                            linha1.ID_PRODUTO
                        }).ToList();

                        foreach (var item in query)
                        {
                            ID_PRODUTO = item.ID_PRODUTO;
                        }
                    }
                    else
                    {
                        if (!decimal.TryParse(dados["ID_PRODUTO"].ToString(), out ID_PRODUTO))
                        {
                            throw new Exception("ID de produto inv&aacute;lido");
                        }

                        ID_PRODUTO = Convert.ToDecimal(dados["ID_PRODUTO"]);
                    }

                    var existeProduto = (from linha1 in ctx1.TB_PRODUTOs
                                         where linha1.ID_PRODUTO == ID_PRODUTO
                                         select linha1).Any();

                    if (!existeProduto)
                    {
                        throw new Exception("C&oacute;digo de produto n&atilde;o cadastrado");
                    }

                    System.Data.Linq.Table <TB_ITEM_NOTA_ENTRADA> Entidade = ctx1.GetTable <TB_ITEM_NOTA_ENTRADA>();

                    TB_ITEM_NOTA_ENTRADA novo = new TB_ITEM_NOTA_ENTRADA();

                    novo.NUMERO_SEQ_NFE             = _NUMERO_SEQ;
                    novo.ID_PRODUTO_ITEM_NFE        = ID_PRODUTO;
                    novo.CODIGO_PRODUTO_ITEM_NFE    = dados["CODIGO_PRODUTO_ITEM_NFE"].ToString().Trim();
                    novo.DESCRICAO_PRODUTO_ITEM_NFE = dados["DESCRICAO_PRODUTO_ITEM_NFE"].ToString().Trim();
                    novo.CODIGO_CF_ITEM_NFE         = dados["CODIGO_CF_ITEM_NFE"].ToString();
                    novo.CODIGO_ST_ITEM_NFE         = dados["CODIGO_ST_ITEM_NFE"].ToString();
                    novo.CODIGO_CFOP_ITEM_NFE       = dados["CODIGO_CFOP_ITEM_NFE"].ToString();
                    novo.QTDE_ITEM_NFE            = Convert.ToDecimal(dados["QTDE_ITEM_NFE"]);
                    novo.VALOR_UNITARIO_ITEM_NFE  = Convert.ToDecimal(dados["VALOR_UNITARIO_ITEM_NFE"]);
                    novo.VALOR_TOTAL_ITEM_NFE     = VALOR_TOTAL_ITEM_NFE;
                    novo.ALIQ_ICMS_ITEM_NFE       = ALIQ_ICMS_ITEM_NFE;
                    novo.VALOR_ICMS_ITEM_NFE      = VALOR_ICMS_ITEM_NFE;
                    novo.BASE_ICMS_ITEM_NFE       = BASE_ICMS_ITEM_NFE;
                    novo.ALIQ_IPI_ITEM_NFE        = Convert.ToDecimal(dados["ALIQ_IPI_ITEM_NFE"]);
                    novo.VALOR_IPI_ITEM_NFE       = VALOR_IPI_ITEM_NFE;
                    novo.BASE_ICMS_SUBS_ITEM_NFE  = BASE_ICMS_SUBS_ITEM_NFE;
                    novo.VALOR_ICMS_SUBS_ITEM_NFE = VALOR_ICMS_SUBS_ITEM_NFE;
                    novo.PERC_IVA_ITEM_NFE        = Convert.ToDecimal(dados["PERC_IVA_ITEM_NFE"]);
                    novo.DATA_CHEGADA_ITEM_NFE    = DateTime.Now;
                    novo.NUMERO_LOTE_ITEM_NFE     = dados["NUMERO_LOTE_ITEM_NFE"].ToString();

                    novo.NUMERO_PEDIDO_COMPRA       = dados.ContainsKey("NUMERO_PEDIDO_COMPRA") ? Convert.ToDecimal(dados["NUMERO_PEDIDO_COMPRA"]) : 0;
                    novo.NUMERO_ITEM_COMPRA         = dados.ContainsKey("NUMERO_ITEM_COMPRA") ? Convert.ToDecimal(dados["NUMERO_ITEM_COMPRA"]) : 0;
                    novo.SALDO_ITEM_NFE             = Convert.ToDecimal(dados["QTDE_ITEM_NFE"]);
                    novo.ABATIMENTO_CONCEDIDO       = dados.ContainsKey("ABATIMENTO_CONCEDIDO") ? Convert.ToDecimal(dados["ABATIMENTO_CONCEDIDO"]) : 0;
                    novo.ALIQ_ICMS_SAIDA_ICMS_ST    = dados.ContainsKey("ALIQ_ICMS_SAIDA_ICMS_ST") ? Convert.ToDecimal(dados["ALIQ_ICMS_SAIDA_ICMS_ST"]) : 0;
                    novo.PERCENTUAL_IPI_A_RECUPERAR = dados.ContainsKey("PERCENTUAL_IPI_A_RECUPERAR") ? Convert.ToDecimal(dados["PERCENTUAL_IPI_A_RECUPERAR"]) : 0;

                    Entidade.InsertOnSubmit(novo);

                    Doran_Base.Auditoria_ERP_Servicos.Doran_Auditoria.Audita_Insert(ctx1, novo, Entidade.ToString(), ID_USUARIO);

                    ctx1.SubmitChanges();

                    var CFOP_DEVOLUCAO = (from linha1 in ctx1.TB_CFOPs
                                          where linha1.CODIGO_CFOP == novo.CODIGO_CFOP_ITEM_NFE
                                          select linha1.OPERACAO_DEVOLUCAO).ToList().First();

                    if (novo.ABATIMENTO_CONCEDIDO == 1 && CFOP_DEVOLUCAO == 1)
                    {
                        using (Doran_Saldo_Cliente_Fornecedor abatimento_cliente = new Doran_Saldo_Cliente_Fornecedor(Convert.ToDecimal(dados["ID_USUARIO"])))
                        {
                            abatimento_cliente.NUMERO_SEQ_NF_ENTRADA  = novo.NUMERO_SEQ_NFE;
                            abatimento_cliente.NUMERO_ITEM_NF_ENTRADA = novo.NUMERO_SEQ_ITEM_NFE;
                            abatimento_cliente.Grava_Futuro_Abatimento_Cliente(novo.VALOR_TOTAL_ITEM_NFE, ctx1);
                        }
                    }

                    Dictionary <string, decimal> linha = new Dictionary <string, decimal>();

                    linha.Add("TOTAL_PRODUTOS_NFE", VALOR_TOTAL_ITEM_NFE);
                    linha.Add("TOTAL_IPI_NFE", VALOR_IPI_ITEM_NFE);
                    linha.Add("BASE_ICMS_NFE", BASE_ICMS_ITEM_NFE);
                    linha.Add("VALOR_ICMS_NFE", VALOR_ICMS_ITEM_NFE);
                    linha.Add("BASE_ICMS_SUBS_NFE", BASE_ICMS_SUBS_ITEM_NFE);
                    linha.Add("VALOR_ICMS_SUBS_NFE", VALOR_ICMS_SUBS_ITEM_NFE);

                    Dictionary <string, object> retorno = Calcula_e_Grava_Totais_Nota_Entrada(ctx1, linha, true);

                    ctx1.Transaction.Commit();

                    return(retorno);
                }
                catch
                {
                    ctx1.Transaction.Rollback();
                    throw;
                }
            }
        }
コード例 #10
0
 public Repository(DataContext dataContext)
 {
     DataTable = dataContext.GetTable <T>();
 }