Пример #1
0
        public List <object> Deleta_Custo(decimal NUMERO_ORCAMENTO, decimal NUMERO_ITEM_ORCAMENTO, decimal NUMERO_CUSTO_VENDA, decimal ID_USUARIO)
        {
            try
            {
                using (Doran_ERP_Servicos_DadosDataContext ctx = new Doran_ERP_Servicos_DadosDataContext())
                {
                    var query = from linha in ctx.TB_CUSTO_ITEM_ORCAMENTO_VENDAs
                                where linha.NUMERO_ORCAMENTO == NUMERO_ORCAMENTO &&
                                linha.NUMERO_ITEM_ORCAMENTO == NUMERO_ITEM_ORCAMENTO &&
                                linha.NUMERO_CUSTO_VENDA == NUMERO_CUSTO_VENDA
                                select linha;

                    foreach (var item in query)
                    {
                        ctx.TB_CUSTO_ITEM_ORCAMENTO_VENDAs.DeleteOnSubmit(item);
                        Doran_Base.Auditoria_ERP_Servicos.Doran_Auditoria.Audita_Delete(ctx, item, ctx.TB_CUSTO_ITEM_ORCAMENTO_VENDAs.ToString(), ID_USUARIO);
                    }

                    ctx.SubmitChanges();
                }

                List <object> retorno = new List <object>();

                using (Doran_Comercial_Orcamentos item = new Doran_Comercial_Orcamentos(NUMERO_ORCAMENTO, ID_USUARIO))
                {
                    retorno = item.Recalcula_Custos(NUMERO_ITEM_ORCAMENTO);
                }

                return(retorno);
            }
            catch (Exception ex)
            {
                Doran_Base.Auditoria_ERP_Servicos.Doran_Exception.GravaErro(ex, ID_USUARIO);
                throw ex;
            }
        }
Пример #2
0
        public List <object> Salva_Custos(List <Dictionary <string, object> > LINHAS)
        {
            try
            {
                using (Doran_ERP_Servicos_DadosDataContext ctx = new Doran_ERP_Servicos_DadosDataContext())
                {
                    decimal NUMERO_ORCAMENTO      = 0;
                    decimal NUMERO_ITEM_ORCAMENTO = 0;

                    foreach (Dictionary <string, object> CUSTO in LINHAS)
                    {
                        NUMERO_ORCAMENTO      = Convert.ToDecimal(CUSTO["NUMERO_ORCAMENTO"]);
                        NUMERO_ITEM_ORCAMENTO = Convert.ToDecimal(CUSTO["NUMERO_ITEM_ORCAMENTO"]);

                        var query = (from linha in ctx.TB_CUSTO_ITEM_ORCAMENTO_VENDAs
                                     where linha.NUMERO_ORCAMENTO == Convert.ToDecimal(CUSTO["NUMERO_ORCAMENTO"]) &&
                                     linha.NUMERO_ITEM_ORCAMENTO == Convert.ToDecimal(CUSTO["NUMERO_ITEM_ORCAMENTO"]) &&
                                     linha.NUMERO_CUSTO_VENDA == Convert.ToDecimal(CUSTO["NUMERO_CUSTO_VENDA"])
                                     select linha).ToList();

                        if (query.Count() > 0)
                        {
                            foreach (var item in query)
                            {
                                string VALOR_CUSTO = CUSTO["CUSTO_ITEM_ORCAMENTO"].ToString().Replace(".", ",");

                                item.CUSTO_ITEM_ORCAMENTO = Convert.ToDecimal(VALOR_CUSTO);
                                item.PREVISAO_ENTREGA     = Convert.ToDateTime(CUSTO["PREVISAO_ENTREGA"]);
                                item.OBS_CUSTO_VENDA      = string.IsNullOrEmpty(CUSTO["OBS_CUSTO_VENDA"].ToString()) ? "" :
                                                            CUSTO["OBS_CUSTO_VENDA"].ToString();

                                if (string.IsNullOrEmpty(CUSTO["CODIGO_FORNECEDOR"].ToString()))
                                {
                                    CUSTO["CODIGO_FORNECEDOR"] = null;
                                }

                                item.CODIGO_FORNECEDOR = Convert.ToDecimal(CUSTO["CODIGO_FORNECEDOR"]);

                                item.CODIGO_FORNECEDOR = item.CODIGO_FORNECEDOR.HasValue ? item.CODIGO_FORNECEDOR : null;

                                Doran_Base.Auditoria_ERP_Servicos.Doran_Auditoria.Audita_Update(ctx, ctx.TB_CUSTO_ITEM_ORCAMENTO_VENDAs.GetModifiedMembers(item),
                                                                                                ctx.TB_CUSTO_ITEM_ORCAMENTO_VENDAs.ToString(), Convert.ToDecimal(CUSTO["ID_USUARIO"]));
                            }
                        }
                        else
                        {
                            System.Data.Linq.Table <TB_CUSTO_ITEM_ORCAMENTO_VENDA> Entidade = ctx.GetTable <TB_CUSTO_ITEM_ORCAMENTO_VENDA>();

                            TB_CUSTO_ITEM_ORCAMENTO_VENDA novo = new TB_CUSTO_ITEM_ORCAMENTO_VENDA();

                            string VALOR_CUSTO = CUSTO["CUSTO_ITEM_ORCAMENTO"].ToString().Replace(".", ",");

                            novo.NUMERO_ORCAMENTO      = Convert.ToDecimal(CUSTO["NUMERO_ORCAMENTO"]);
                            novo.NUMERO_ITEM_ORCAMENTO = Convert.ToDecimal(CUSTO["NUMERO_ITEM_ORCAMENTO"]);
                            novo.NUMERO_CUSTO_VENDA    = Convert.ToDecimal(CUSTO["NUMERO_CUSTO_VENDA"]);
                            novo.CUSTO_ITEM_ORCAMENTO  = Convert.ToDecimal(VALOR_CUSTO);
                            novo.PREVISAO_ENTREGA      = Convert.ToDateTime(CUSTO["PREVISAO_ENTREGA"]);
                            novo.OBS_CUSTO_VENDA       = string.IsNullOrEmpty(CUSTO["OBS_CUSTO_VENDA"].ToString()) ? "" :
                                                         CUSTO["OBS_CUSTO_VENDA"].ToString();

                            if (string.IsNullOrEmpty(CUSTO["CODIGO_FORNECEDOR"].ToString()))
                            {
                                CUSTO["CODIGO_FORNECEDOR"] = null;
                            }

                            novo.CODIGO_FORNECEDOR = Convert.ToDecimal(CUSTO["CODIGO_FORNECEDOR"]);

                            novo.CODIGO_FORNECEDOR = novo.CODIGO_FORNECEDOR.HasValue ? novo.CODIGO_FORNECEDOR : null;

                            Entidade.InsertOnSubmit(novo);

                            Doran_Base.Auditoria_ERP_Servicos.Doran_Auditoria.Audita_Insert(ctx, novo, Entidade.ToString(), Convert.ToDecimal(CUSTO["ID_USUARIO"]));
                        }
                    }

                    ctx.SubmitChanges();

                    List <object> retorno = new List <object>();

                    using (Doran_Comercial_Orcamentos item = new Doran_Comercial_Orcamentos(NUMERO_ORCAMENTO, Convert.ToDecimal(LINHAS[0]["ID_USUARIO"])))
                    {
                        retorno = item.Recalcula_Custos(NUMERO_ITEM_ORCAMENTO);
                    }

                    return(retorno);
                }
            }
            catch (Exception ex)
            {
                Doran_Base.Auditoria_ERP_Servicos.Doran_Exception.GravaErro(ex, Convert.ToDecimal(LINHAS[0]["ID_USUARIO"]));
                throw ex;
            }
        }