Exemple #1
0
        protected void ImgDelEmail_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                GridViewRow _gvrow = (GridViewRow)(sender as Control).Parent.Parent;
                _codigo  = GrdvEmails.DataKeys[_gvrow.RowIndex].Values["CodigoMATD"].ToString();
                _correos = GrdvEmails.DataKeys[_gvrow.RowIndex].Values["Email"].ToString();

                _dtbemail  = (DataTable)ViewState["Emails"];
                _resultado = _dtbemail.Select("CodigoMATD='" + _codigo + "'").FirstOrDefault();
                _resultado.Delete();
                _dtbdatos.AcceptChanges();
                GrdvEmails.DataSource = _dtbemail;
                GrdvEmails.DataBind();

                //_dts = new ConsultaDatosDAO().FunInsertAdicionales(4, int.Parse(_codigo),
                //    0, 0, "", "", "", "", "", "", "", "", "", "", "", "", "",
                //    "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
                //    Session["Conectar"].ToString());
            }
            catch (Exception ex)
            {
                Lblerror.Text = ex.ToString();
            }
        }
Exemple #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string ConnectionString = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;

            using (SqlConnection connection1 = new SqlConnection(ConnectionString))
            {
                SqlDataAdapter dataAdapter1 = new SqlDataAdapter("SELECT * FROM Students", connection1);
                DataSet        dataSet1     = new DataSet();

                dataAdapter1.Fill(dataSet1);     // Fill method, opens the connection, executes the command, fills the DataSet and then immediatly closes the connection. All in one.
                GridView1.DataSource = dataSet1; // this SqlDataSet is available with no active open connection to data source. Unlike the SqlDataReader, which needs active open connection to data source.
                GridView1.DataBind();
            }

            using (SqlConnection connection2 = new SqlConnection(ConnectionString))
            {
                SqlDataAdapter dataAdapter2 = new SqlDataAdapter("spGetStudentsAndEmails", connection2); // This stored procedure returns two datasets - Students and Emails.
                dataAdapter2.SelectCommand.CommandType = CommandType.StoredProcedure;

                DataSet dataSet2 = new DataSet();
                dataAdapter2.Fill(dataSet2); // Fill method, opens the connection, executes the command, fills the DataSet and then immediatly closes the connection. All in one.

                dataSet2.Tables[0].TableName = "Students";
                dataSet2.Tables[1].TableName = "Emails";

                GrdvStudents.DataSource = dataSet2.Tables["Students"]; //First DataSet.
                GrdvStudents.DataBind();
                GrdvEmails.DataSource = dataSet2.Tables["Emails"];     //Second DataSet
                GrdvEmails.DataBind();
            }
        }
Exemple #3
0
        protected void ChkEmail_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                DdlTipoMail.SelectedValue = "0";
                RdbEmail.SelectedValue    = "PER";
                TxtEmail.Text             = "";
                TxtObservaEmail.Text      = "";
                TrEmail1.Visible          = false;
                TrEmail2.Visible          = false;
                TrEmail3.Visible          = false;
                TrEmail4.Visible          = false;
                TrEmail5.Visible          = false;
                GrdvEmails.DataSource     = null;
                GrdvEmails.DataBind();

                if (ChkEmail.Checked)
                {
                    TrEmail1.Visible = true;
                    TrEmail2.Visible = true;
                    TrEmail3.Visible = true;
                    TrEmail4.Visible = true;

                    _dts = new ConsultaDatosDAO().FunConsultaDatos(234, 0, 0, 0, "TIPO CORREO", "CORREO",
                                                                   ViewState["NumeroDocumento"].ToString(), Session["Conectar"].ToString().ToString());
                    GrdvEmails.DataSource = _dts;
                    GrdvEmails.DataBind();
                    ViewState["Emails"] = _dts.Tables[0];

                    if (_dts.Tables[0].Rows.Count > 0)
                    {
                        TrEmail5.Visible = true;
                    }
                    else
                    {
                        TrEmail5.Visible = false;
                    }
                }
            }
            catch (Exception ex)
            {
                Lblerror.Text = ex.ToString();
            }
        }
Exemple #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string ConnectionString = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;

            using (SqlConnection connection1 = new SqlConnection(ConnectionString))
            {
                connection1.Open();
                SqlCommand command1 = new SqlCommand("SELECT * FROM students", connection1);
                using (SqlDataReader rdr1 = command1.ExecuteReader()) //Note that new cannot be used to create a SqlDataReader object. ExecuteReader return object of SqlDataReader.
                {
                    DataTable table = new DataTable();
                    table.Columns.Add("ID");
                    table.Columns.Add("FirstName");
                    table.Columns.Add("LastName");
                    table.Columns.Add("FullName");

                    while (rdr1.Read())
                    {
                        DataRow dataRow = table.NewRow();

                        dataRow["ID"]        = rdr1["Id"];
                        dataRow["FirstName"] = rdr1["FirstName"];
                        dataRow["LastName"]  = rdr1["LastName"];
                        dataRow["FullName"]  = rdr1["FirstName"] + " " + rdr1["LastName"];
                        table.Rows.Add(dataRow);
                    }
                    GridView1.DataSource = table;
                    GridView1.DataBind();
                }

                SqlCommand command2 = new SqlCommand("SELECT * FROM students; SELECT * FROM Emails", connection1); // there are two SQL queries that return two seperate data sets.
                using (SqlDataReader rdr2 = command2.ExecuteReader())                                              // both data sets are pointed by a single DataReader object.
                {
                    GrdvStudents.DataSource = rdr2;                                                                //first result set displayed.
                    GrdvStudents.DataBind();

                    rdr2.NextResult();            //this will make the result move to the next result object.

                    GrdvEmails.DataSource = rdr2; //second result set displayed.
                    GrdvEmails.DataBind();
                }
            }
        }
        protected void BtnLoadData_Click(object sender, EventArgs e)
        {
            if (Cache["Data"] == null)
            {
                string ConnectionString = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
                using (SqlConnection connection2 = new SqlConnection(ConnectionString))
                {
                    SqlDataAdapter dataAdapter2 = new SqlDataAdapter("spGetStudentsAndEmails", connection2); // This stored procedure returns two datasets - Students and Emails.
                    dataAdapter2.SelectCommand.CommandType = CommandType.StoredProcedure;

                    DataSet dataSet2 = new DataSet();
                    dataAdapter2.Fill(dataSet2); // Fill method, opens the connection, executes the command, fills the DataSet and then immediatly closes the connection. All in one.

                    dataSet2.Tables[0].TableName = "Students";
                    dataSet2.Tables[1].TableName = "Emails";

                    Cache["Data"] = dataSet2;                              // Cache is a global object. You can label your DataSet in the Cashe using a name (eg "Data").
                                                                           // Every DataSet Stored in the Cache with a label is kept seperately and retrived with the help of label.

                    GrdvStudents.DataSource = dataSet2.Tables["Students"]; //First DataSet.
                    GrdvStudents.DataBind();
                    GrdvEmails.DataSource = dataSet2.Tables["Emails"];     //Second DataSet
                    GrdvEmails.DataBind();

                    LblMessage.Text = "Data Loaded from the Database";
                }
            }
            else
            {
                DataSet dataSet1 = (DataSet)Cache["Data"];             // DateSet retrived with the help of the label, should be typecasted to the object type of the data.
                GrdvStudents.DataSource = dataSet1.Tables["Students"]; //First DataSet.
                GrdvStudents.DataBind();
                GrdvEmails.DataSource = dataSet1.Tables["Emails"];     //Second DataSet
                GrdvEmails.DataBind();

                LblMessage.Text = "Data Loaded from the Cache";
            }
        }
Exemple #6
0
        protected void ImgAgregarMail_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                if (DdlTipoMail.SelectedValue == "0")
                {
                    new FuncionesDAO().FunShowJSMessage("Seleccione Tipo Mail..!", this);
                    return;
                }

                if (string.IsNullOrEmpty(TxtEmail.Text.Trim()))
                {
                    new FuncionesDAO().FunShowJSMessage("Ingrese Email..!", this);
                    return;
                }

                if (!new FuncionesDAO().Email_bien_escrito(TxtEmail.Text.Trim()))
                {
                    new FuncionesDAO().FunShowJSMessage("Email Incorrecto..!", this);
                    return;
                }

                _dtbdatos = (DataTable)ViewState["Emails"];

                if (ViewState["Emails"] != null)
                {
                    _resultado = _dtbdatos.Select("Email='" + TxtEmail.Text.ToLower() + "'").FirstOrDefault();

                    if (_resultado != null)
                    {
                        _lexiste = true;
                    }
                }

                if (_lexiste)
                {
                    new FuncionesDAO().FunShowJSMessage("Ya Existe Email Agregado..!", this);
                    return;
                }

                TrEmail5.Visible = true;
                //_dts = new ConsultaDatosDAO().FunInsertAdicionales(1, 0, 0, 0, "", ViewState["NumeroDocumento"].ToString(),
                //    "CORREO", DdlTipoMail.SelectedValue, RdbEmail.SelectedValue, TxtEmail.Text.Trim().ToLower(),
                //    "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
                //    "", "", Session["Conectar"].ToString());

                _dts = new ConsultaDatosDAO().FunConsultaDatos(234, 0, 0, 0, "TIPO CORREO", "CORREO",
                                                               ViewState["NumeroDocumento"].ToString(), Session["Conectar"].ToString().ToString());

                ViewState["Emails"]   = _dts.Tables[0];
                GrdvEmails.DataSource = _dts.Tables[0];
                GrdvEmails.DataBind();

                DdlTipoMail.SelectedValue = "0";
                TxtEmail.Text             = "";
                TxtObservaEmail.Text      = "";
            }
            catch (Exception ex)
            {
                Lblerror.Text = ex.ToString();
            }
        }