Пример #1
0
        private void Nr_NotaFiscal_Leave(object sender, EventArgs e)
        {
            string vColunas = "c.Tp_Movimento|=|'E';c.Nr_NotaFiscal|=|'" + Nr_NotaFiscal.Text.Trim() + "';c.st_registro|<>|'C'";

            if (cd_clifor.Text.Trim() != "")
            {
                vColunas += ";c.cd_clifor|=|'" + cd_clifor.Text.Trim() + "'";
            }
            DataRow linha = UtilPesquisa.EDIT_LEAVE(vColunas, new Componentes.EditDefault[] { Nr_NotaFiscal, Nr_LanctoFiscal, ID_NFItem },
                                                    new TCD_Lan_SaldoNotasOriginacao());

            if (linha != null)
            {
                VL_SubtotalNF.Value = Convert.ToDecimal(linha["VL_Subtotal"].ToString());
                decimal qtd    = Convert.ToDecimal(linha["QTD_Disponivel"].ToString());
                decimal vl     = Convert.ToDecimal(linha["VL_Disponivel"].ToString());
                decimal totqtd = 0;
                decimal totvl  = 0;
                QTD_NFCurrent = Convert.ToDecimal(linha["Quantidade"].ToString());
                TList_Lan_Originacao_x_Faturamento listaValidaTotalLancto = (BS_ItensNota.Current as TRegistro_LanFaturamento_Item).lOriginacao_x_Faturamento;

                //VERIFICAR SE EXISTE LANÇAMENTO BS ORIG
                if (listaValidaTotalLancto != null)
                {
                    totqtd = ((BS_ItensNota.Current as TRegistro_LanFaturamento_Item).Quantidade - Convert.ToDecimal(listaValidaTotalLancto.Sum(p => p.QTD_Origem)));
                    totvl  = ((BS_ItensNota.Current as TRegistro_LanFaturamento_Item).Vl_subtotal - Convert.ToDecimal(listaValidaTotalLancto.Sum(p => p.VL_Origem)));

                    //VERIFICA se jah existe um lançamento para esta nota fiscal
                    if (listaValidaTotalLancto.Count(p => (p.Nr_LanctoFiscal == Convert.ToDecimal(Nr_LanctoFiscal.Text)) && (p.ID_NFItem == Convert.ToDecimal(ID_NFItem.Text))) > 1)
                    {
                        Nr_LanctoFiscal.Text = "";
                        Nr_NotaFiscal.Text   = "";
                        ID_NFItem.Text       = "";
                        qtd    = 0;
                        vl     = 0;
                        totqtd = 0;
                        totvl  = 0;
                        MessageBox.Show("Atenção, já existe um lançamento para esta nota fiscal!");
                    }
                }


                //VERIRICA A QTD DE PRODUTO
                if (qtd > totqtd)
                {
                    qtd = totqtd;
                }

                //VERIRICA A QTD DE PRODUTO
                if (vl > totvl)
                {
                    vl = totvl;
                }

                Quantidade.Maximum = qtd;
                Quantidade.Value   = qtd;
                //Quantidade_Leave(this, e);
                VL_Subtotal.Maximum = vl;
                //VL_Subtotal.Value = vl;
                decimal valor = 0;
                if (QTD_NFCurrent > 0)
                {
                    valor = Math.Round(((Quantidade.Value) * (VL_SubtotalNF.Value / QTD_NFCurrent)), 2);
                }
                VL_Subtotal.Maximum = valor;
                VL_Subtotal.Value   = valor;
            }
            else
            {
                Nr_LanctoFiscal.Text = "";
                Nr_NotaFiscal.Text   = "";
                ID_NFItem.Text       = "";
                VL_SubtotalNF.Value  = 0;
                Quantidade.Value     = 0;
                Quantidade.Maximum   = 0;
                VL_Subtotal.Value    = 0;
                VL_Subtotal.Maximum  = 0;
            }
        }