Beispiel #1
0
        private void edit_bt_Click(object sender, EventArgs e)
        {
            int obra_id = Int32.Parse(obras_dataGridView1.CurrentRow.Cells[0].Value.ToString());

            data.connectToDB();
            ObraModel tmp = new ObraModel();

            //String sql = String.Format("SELECT * FROM proj_obras WHERE obra_id = '" + obra_id + "'");
            SqlCommand com = new SqlCommand("getObrasById", data.connection());

            com.CommandType = CommandType.StoredProcedure;
            com.Parameters.AddWithValue("@obra_id", obra_id);
            SqlDataReader reader;

            reader = com.ExecuteReader();
            while (reader.Read())
            {
                tmp.obra_id    = Int32.Parse(reader["obra_id"].ToString());
                tmp.data_ini   = DateTime.Parse(reader["data_ini"].ToString());
                tmp.data_fim   = DateTime.Parse(reader["data_fim"].ToString());
                tmp.orcamento  = Int32.Parse(reader["orcamento"].ToString());
                tmp.condominio = Decimal.Parse(reader["condominio"].ToString());
            }
            data.close();

            tmp.empresa = Decimal.Parse(obras_dataGridView1.CurrentRow.Cells[2].Value.ToString());

            AddObra o = new AddObra(tmp);

            o.ShowDialog(this);
        }
Beispiel #2
0
        private List <ObraModel> GetObras()
        {
            data.connectToDB();

            List <ObraModel> obras = new List <ObraModel>();

            String        sql = "SELECT * FROM proj_obras";
            SqlCommand    com = new SqlCommand(sql, data.connection());
            SqlDataReader reader;

            reader = com.ExecuteReader();
            while (reader.Read())
            {
                ObraModel tmp = new ObraModel();

                tmp.obra_id    = Int32.Parse(reader["obra_id"].ToString());
                tmp.data_ini   = DateTime.Parse(reader["data_ini"].ToString());
                tmp.data_fim   = DateTime.Parse(reader["data_fim"].ToString());
                tmp.orcamento  = Int32.Parse(reader["orcamento"].ToString());
                tmp.condominio = Decimal.Parse(reader["condominio"].ToString());

                obras.Add(tmp);
            }
            data.close();

            return(obras);
        }
Beispiel #3
0
        private void SaveObra(ObraModel o)
        {
            data.connectToDB();

            SqlCommand cmd = new SqlCommand("insertObra", data.connection());

            //cmd.CommandText = "INSERT proj_obras (obra_id, data_ini, data_fim, orcamento, condominio) Values(@obra_id, @data_ini, @data_fim, @orcamento, @condominio)";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Clear();
            cmd.Parameters.AddWithValue("@obra_id", o.obra_id);
            cmd.Parameters.AddWithValue("@data_ini", o.data_ini);
            cmd.Parameters.AddWithValue("@data_fim", o.data_fim);
            cmd.Parameters.AddWithValue("@orcamento", o.orcamento);
            cmd.Parameters.AddWithValue("@condominio", o.condominio);
            cmd.Parameters.AddWithValue("@empresa", o.empresa);
            cmd.Connection = data.connection();

            try
            {
                cmd.ExecuteNonQuery();
                MessageBox.Show("Entry Successful!");
            }
            catch (Exception ex)
            {
                //throw new Exception("Failed to insert in database. \n ERROR MESSAGE: \n" + ex.Message);
                //MessageBox.Show("Não foi possível guardar os dados! Verifique os campos inseridos!");
                MessageBox.Show(ex.Message);
            }
            finally
            {
                data.close();
            }
        }
Beispiel #4
0
        private void ok_bt_Click(object sender, EventArgs e)
        {
            ObraModel obra = new ObraModel();

            try
            {
                obra.obra_id    = Int32.Parse(id_textBox.Text);
                obra.data_ini   = DateTime.Parse(ini_dateTimePicker.Text.ToString());
                obra.data_fim   = DateTime.Parse(fim_dateTimePicker.Text.ToString());
                obra.orcamento  = Int32.Parse(orcamento_textBox.Text.ToString());
                obra.condominio = (condominio_comboBox.SelectedItem as CondominioView).value;
                obra.empresa    = (empresa_comboBox.SelectedItem as EmpresaView).value;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            if (adding)
            {
                SaveObra(obra);
            }
            else
            {
                UpdateObra(obra);
            }

            Obras parent = (Obras)Owner;

            parent.GetObrasByCondominio(obra.condominio);
            this.Close();
        }
Beispiel #5
0
        private void UpdateObra(ObraModel o)
        {
            data.connectToDB();

            //cmd.CommandText = "UPDATE proj_obras SET data_ini = @data_ini, "
            //                + "data_fim = @data_fim, orcamento = @orcamento, "
            //                + "condominio = @condominio WHERE obra_id = @obra_id";
            SqlCommand cmd = new SqlCommand("updateObra", data.connection());

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@obra_id", o.obra_id);
            cmd.Parameters.AddWithValue("@data_ini", o.data_ini);
            cmd.Parameters.AddWithValue("@data_fim", o.data_fim);
            cmd.Parameters.AddWithValue("@orcamento", o.orcamento);
            cmd.Parameters.AddWithValue("@condominio", o.condominio);
            cmd.Parameters.AddWithValue("empresa", o.empresa);
            cmd.Connection = data.connection();

            try
            {
                cmd.ExecuteNonQuery();
                MessageBox.Show("Update Successful!");
            }
            catch (Exception ex)
            {
                //throw new Exception("Failed to update in database. \n ERROR MESSAGE: \n" + ex.Message);
                MessageBox.Show("Não foi possível atualizar os dados! Verifique os campos inseridos!");
            }
            finally
            {
                data.close();
            }
        }
Beispiel #6
0
 public AddObra(ObraModel o)
 {
     InitializeComponent();
     adding = false;
     FillCondominioBox();
     FillEmpresaLisBox();
     FillObraInfo(o);
 }
        public async Task <IActionResult> Insert(ObraModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var obra = _mapper.Map <ObraDto>(model);
            await _obraRepositorio.Insertar(obra);

            return(Ok(model));
        }
Beispiel #8
0
 private void FillObraInfo(ObraModel o)
 {
     id_textBox.Text          = o.obra_id.ToString();
     id_textBox.ReadOnly      = true;
     ini_dateTimePicker.Text  = o.data_ini.ToString();
     fim_dateTimePicker.Text  = o.data_fim.ToString();
     orcamento_textBox.Text   = o.orcamento.ToString();
     condominio_comboBox.Text = getNomeCond(o.condominio);
     empresa_comboBox.Text    = getNomeEmpresa(o.empresa);
     empresa_comboBox.Enabled = false;
 }
        public async Task <IActionResult> Edit(long id, ObraModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var obra = _mapper.Map <ObraDto>(model);

            obra.Id = id;
            await _obraRepositorio.Modificar(obra);

            return(Ok(model));
        }