private void SalvarServico()
        {
            try
            {
                Valid();

                ServicoBLL bll  = new ServicoBLL();
                int        id   = int.Parse(txNumBloco.Text);
                Servico    serv = (id == 0
                    ? new Servico()
                    : bll.Find(id));
                if (serv == null)
                {
                    serv = new Servico();
                }

                serv.Id       = id;
                serv.Data     = txData.SelectedDate.Value;
                serv.Cliente  = txCliente.Text;
                serv.Telefone = txTelefone.Text;
                serv.Obs      = txObs.Text;

                bll.Save(serv);

                txNumBloco.IsEnabled = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Atenção",
                                MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Ejemplo n.º 2
0
        private void btConfirmar_Click(object sender, RoutedEventArgs e)
        {
            Caixa          cx = new CaixaBLL().GetCaixaAberto();
            MovimentoCaixa mc = new MovimentoCaixa();

            mc.ServicoId      = ServicoId;
            mc.CaixaId        = cx.Id;
            mc.FormaPagamento = (int)comboBox.SelectedValue;
            mc.Valor          = decimal.Parse(txValorAdiantamento.Text);
            mc.Tipo           = (int)TipoMovCaixa.Entrada;
            mc.Obs            = $"Adiantamento de pagamento do serviço N° {ServicoId}";

            if (mc.FormaPagamento == -1)
            {
                MessageBox.Show("Selecione uma forma de pagamento",
                                "Atenção", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            MovimentoCaixaBLL bll = new MovimentoCaixaBLL();

            bll.Save(mc);

            if (FecharServico)
            {
                ServicoBLL servBLL = new ServicoBLL();
                var        serv    = servBLL.Find(ServicoId);
                serv.Finalizado = true;
                servBLL.Save(serv);

                List <MaterialServico> materiaisServ = serv.MaterialServico.ToList();

                foreach (MaterialServico m in materiaisServ)
                {
                    MaterialBLL matBll   = new MaterialBLL();
                    var         material = matBll.Find(m.MaterialId);
                    material.Estoque -= m.Quantidade;
                    matBll.Save(material);
                }
            }

            Confirmado = true;
            Close();
        }