示例#1
0
        private void populateFields(int pGetID = 0)
        {
            mdc = new ModelDataContext();
            try
            {
                if (pGetID > 0)
                {
                    Model.Matricula matricula = mdc.Matricula.First(matr => matr.idMatricula == pGetID);

                    tbCodigo.Text = pGetID.ToString();
                    DropDownList1.SelectedValue = matricula.idCurso.ToString();
                    DropDownList2.SelectedValue = matricula.idMateria.ToString();
                    DropDownList3.SelectedValue = matricula.idAluno.ToString();
                }
                else
                {
                    Response.Redirect("Matriculas.aspx");
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                mdc.Dispose();
            }
        }
        private void onDelete()
        {
            mdc = new ModelDataContext();

            try
            {
                Model.Matricula matricula = mdc.Matricula.First(matr => matr.idMatricula == int.Parse(tbCodigo.Text.Trim()));
                mdc.Matricula.DeleteOnSubmit(matricula);
                mdc.SubmitChanges();
                Response.Redirect("Matriculas.aspx");
            }
            catch (Exception)
            {
            }
            finally
            {
                mdc.Dispose();
            }
        }
示例#3
0
 private void onInsert()
 {
     try
     {
         using (ModelDataContext mdc = new ModelDataContext())
         {
             Model.Matricula matricula = new Model.Matricula()
             {
                 idCurso      = Convert.ToInt16(DropDownList1.SelectedValue.Trim()),
                 idMateria    = Convert.ToInt16(DropDownList2.SelectedValue.Trim()),
                 idAluno      = Convert.ToInt16(DropDownList3.SelectedValue.Trim()),
                 dataCadastro = DateTime.Parse(DateTime.Now.ToShortDateString())
             };
             mdc.Matricula.InsertOnSubmit(matricula);
             mdc.SubmitChanges();
             Response.Redirect("Matriculas.aspx");
         }
     }
     catch (Exception)
     {
     }
 }
示例#4
0
        private void onUpdate()
        {
            mdc = new ModelDataContext();
            try
            {
                {
                    Model.Matricula matricula = mdc.Matricula.First(matr => matr.idMatricula == int.Parse(tbCodigo.Text.Trim()));
                    matricula.idCurso         = Convert.ToInt16(DropDownList1.SelectedValue.Trim());
                    matricula.idMateria       = Convert.ToInt16(DropDownList2.SelectedValue.Trim());
                    matricula.idAluno         = Convert.ToInt16(DropDownList3.SelectedValue.Trim());
                    matricula.dataAtualizacao = DateTime.Parse(DateTime.Now.ToShortDateString());

                    mdc.SubmitChanges();
                    Response.Redirect("Matriculas.aspx");
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                mdc.Dispose();
            }
        }