コード例 #1
0
        public int SalvarServicoPeca(ServicoPeca servicoPeca)
        {
            _SGMContext.ServicoPeca.Add(servicoPeca);
            _SGMContext.SaveChanges();

            return(servicoPeca.Id);
        }
コード例 #2
0
        private void BtnAdicionarPeca_Click(object sender, EventArgs e)
        {
            bool apagaDadosTemporario = true;

            if (txtClienteId.Text == "")
            {
                MessageBox.Show("Você precisa primeiro incluir um cliente acima!", "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                FrmConsultaPeca consultaPeca = FormResolve.Resolve <FrmConsultaPeca>();
                consultaPeca.ShowDialog();

                if (consultaPeca.codigo != 0)
                {
                    ServicoPeca servicoPeca = new ServicoPeca()
                    {
                        ServicoId = Convert.ToInt32(txtServicoId.Text),
                        PecaId    = consultaPeca.codigo
                    };

                    var Id = _servicoApplication.SalvarServicoPeca(servicoPeca);

                    var servicoPecaSalvo = _servicoApplication.GetServicoPecaByServicoId(Convert.ToInt32(txtServicoId.Text));

                    IList <PesquisaPecaServicoDataSource> peca = new List <PesquisaPecaServicoDataSource>();

                    foreach (var item in servicoPecaSalvo)
                    {
                        var mao = _pecaApplication.GetPecaByPecaId(item.PecaId);
                        peca.Add(new PesquisaPecaServicoDataSource
                        {
                            PecaId        = mao.PecaId,
                            Peca          = mao.Descricao,
                            Valor         = mao.Valor,
                            ServicoPecaId = Id
                        });
                    }

                    dgvPeca.DataSource            = peca;
                    dgvPeca.Columns[0].HeaderText = "Código";
                    dgvPeca.Columns[0].Width      = 50;
                    dgvPeca.Columns[1].HeaderText = "Peça";
                    dgvPeca.Columns[1].Width      = 330;
                    dgvPeca.Columns[2].HeaderText = "Valor Integral";
                    dgvPeca.Columns[2].Width      = 70;
                    dgvPeca.Columns[2].DefaultCellStyle.Format    = "C2";
                    dgvPeca.Columns[2].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                    dgvPeca.Columns[3].HeaderText = "ServicoPecaId";
                    dgvPeca.Columns[3].Width      = 20;
                    dgvPeca.Columns[3].Visible    = false;
                }

                CalcularServico(apagaDadosTemporario);
            }
        }
コード例 #3
0
        private void DgvPeca_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                int pecaId             = Convert.ToInt32(dgvPeca.Rows[e.RowIndex].Cells[0].Value);
                int servicoMaodeObraId = Convert.ToInt32(dgvPeca.Rows[e.RowIndex].Cells[3].Value);

                DialogResult res = MessageBox.Show("Deseja realmente EXCLUIR este item?", "Pergunta", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (res.ToString() == "Yes")
                {
                    ServicoPeca servicoPeca = new ServicoPeca()
                    {
                        Id        = servicoMaodeObraId,
                        ServicoId = Convert.ToInt32(txtServicoId.Text),
                        PecaId    = pecaId
                    };

                    _servicoApplication.DeletarServicoPeca(servicoPeca);

                    var servicoPecaSalvo = _servicoApplication.GetServicoPecaByServicoId(Convert.ToInt32(txtServicoId.Text));

                    IList <PesquisaPecaServicoDataSource> peca = new List <PesquisaPecaServicoDataSource>();

                    foreach (var item in servicoPecaSalvo)
                    {
                        var pec = _pecaApplication.GetPecaByPecaId(item.PecaId);
                        peca.Add(new PesquisaPecaServicoDataSource
                        {
                            PecaId        = pec.PecaId,
                            Peca          = pec.Descricao,
                            Valor         = pec.Valor,
                            ServicoPecaId = item.Id
                        });
                    }

                    dgvMaodeObra.DataSource            = peca;
                    dgvMaodeObra.Columns[0].HeaderText = "Código";
                    dgvMaodeObra.Columns[0].Width      = 50;
                    dgvMaodeObra.Columns[1].HeaderText = "Mão de Obra";
                    dgvMaodeObra.Columns[1].Width      = 330;
                    dgvMaodeObra.Columns[2].HeaderText = "Valor";
                    dgvMaodeObra.Columns[2].Width      = 70;
                    dgvMaodeObra.Columns[2].DefaultCellStyle.Format    = "C2";
                    dgvMaodeObra.Columns[2].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                    dgvMaodeObra.Columns[3].HeaderText = "OrcamentoMaoDeObraId";
                    dgvMaodeObra.Columns[3].Width      = 20;
                    dgvMaodeObra.Columns[3].Visible    = false;
                }

                CalcularServico();
            }
        }
コード例 #4
0
        public int SalvarServicoPeca(ServicoPeca servicoPeca)
        {
            using (var client = new HttpClient())
            {
                var content = new StringContent(JsonConvert.SerializeObject(servicoPeca), Encoding.UTF8, "application/json");
                var result = client.PostAsync($"{_sGMConfiguration.SGMWebApiUrl}SGM/servico/peca", content).Result;
                if (!result.IsSuccessStatusCode)
                {
                    throw new ApplicationException($"Problema ao SALVAR serviço-pecas. ServicoId: {servicoPeca.ServicoId}");
                }

                var response = result.Content.ReadAsStringAsync();

                return Convert.ToInt32(response.Result);
            }
        }
コード例 #5
0
        public void DeletarServicoPeca(ServicoPeca servicoPeca)
        {
            using (var client = new HttpClient())
            {
                var request = new HttpRequestMessage
                {
                    Method = HttpMethod.Delete,
                    RequestUri = new Uri($"{_sGMConfiguration.SGMWebApiUrl}SGM/servico/peca"),
                    Content = new StringContent(JsonConvert.SerializeObject(servicoPeca), Encoding.UTF8, "application/json")
                };

                var result = client.SendAsync(request);
                if (!result.Result.IsSuccessStatusCode)
                {
                    throw new ApplicationException($"Problema ao DELETAR serviço-peca. ServicoId: {servicoPeca.ServicoId}");
                }
            }
        }
コード例 #6
0
 public void DeletarServicoPeca(ServicoPeca servicoPeca)
 {
     _servicoCommand.DeletarServicoPeca(servicoPeca);
 }
コード例 #7
0
 public int SalvarServicoPeca(ServicoPeca servicoPeca)
 {
     return(_servicoCommand.SalvarServicoPeca(servicoPeca));
 }
コード例 #8
0
 public void DeletarServicoPeca(ServicoPeca servicoPeca)
 {
     _SGMContext.ServicoPeca.Remove(servicoPeca);
     _SGMContext.SaveChanges();
 }