コード例 #1
0
        protected void btneditar_Click(object sender, EventArgs e)
        {
            TheGym k = new TheGym
            {
                NombreClienteEditar    = tbnombre.Text,
                ApellidoClienteEditar  = tbapellido.Text,
                DNIClienteEditar       = tbdni.Text,
                FechaClienteEditar     = tbfechanacimiento.Text,
                EmailClienteEditar     = tbemail.Text,
                TelefonoClienteEditar  = tbtelefono.Text,
                DomicilioClienteEditar = tbdomicilio.Text,
            };

            k.DNIEditar = DNIEdit;

            k.UpdateCliente();

            tbapellido.Text        = string.Empty;
            tbnombre.Text          = string.Empty;
            tbbuscar.Text          = string.Empty;
            tbemail.Text           = string.Empty;
            DNIEdit                = string.Empty;
            tbdni.Text             = string.Empty;
            tbfechanacimiento.Text = string.Empty;
            tbtelefono.Text        = string.Empty;
            tbdomicilio.Text       = string.Empty;

            DataTable aux = new DataTable();

            GridView1.DataSource = aux;
            GridView1.DataBind();
            GridView1.Dispose();
        }
コード例 #2
0
        protected void btneditar_Click(object sender, EventArgs e)
        {
            TheGym k = new TheGym
            {
                IdPlanBuscar     = id,
                NombrePlanEdit   = tbnombre.Text,
                PrecioPlanEdit   = tbprecio.Text,
                DuracionPlanEdit = tbduracion.Text
            };

            k.UpdatePlan();

            DataTable aux = new DataTable();

            GridView1.DataSource = aux;
            GridView1.DataBind();
            GridView1.Dispose();
            gvactividadesplanbusqueda.DataSource = aux;
            gvactividadesplanbusqueda.DataBind();
            gvactividadesplanbusqueda.Dispose();
            tbbuscar.Text       = string.Empty;
            tbduracion.Text     = string.Empty;
            tbnombre.Text       = string.Empty;
            tbprecio.Text       = string.Empty;
            tbduracion.ReadOnly = true;
            tbnombre.ReadOnly   = true;
            tbprecio.ReadOnly   = true;
            ddlactividad.ClearSelection();
            ddlDias.ClearSelection();
            ddlactividad.DataSource = aux;
            ddlactividad.DataBind();
        }
    protected void Button3_Click(object sender, EventArgs e)
    {
        GridView1.Dispose();
        GridView1.DataBind();

        khoi.Text = khoi.SelectedItem.Text;

        string ketnoi;

        ketnoi = "SELECT     SOBAODANH, HOTEN, NGAYSINH, DM1, DM2, DM3, DTC, KHOI FROM KQ where  ((KHOI=" + khoi.SelectedValue.ToString() + ") and (SOBAODANH=" + mssv.Text + "))";


        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);

        SqlCommand sql = new SqlCommand(ketnoi, con);

        DataSet        ds  = new DataSet();
        SqlDataAdapter sda = new SqlDataAdapter(sql);

        sda.Fill(ds, "KQ");
        DataTable dt = ds.Tables["KQ"];

        GridView1.DataSource = dt.DefaultView;
        GridView1.DataBind();
    }
コード例 #4
0
ファイル: UpdateForm.aspx.cs プロジェクト: zelld0m/CrudManual
        protected void _BtnUpdate_Click(object sender, EventArgs e)
        {
            _BtnSearch_Click(sender, e);   // Activate Button Search
            if (String.IsNullOrWhiteSpace(_Tb_ID.Text) || String.IsNullOrWhiteSpace(_Tb_Name.Text) || String.IsNullOrWhiteSpace(_Tb_AuthorityName.Text))
            {
                ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + "ID BOX IS EMPTY  " + "');", true);
            }

            else
            {
                _BtnSearch_Click(sender, e);  // using search for validation of records if Available
                if (GridView1.Rows.Count > 0 && GridView2.Rows.Count > 0)
                {
                    svc.UpdateDummy(Convert.ToInt32(_Tb_ID.Text), _Tb_Name.Text);
                    svc.UpdateAuthority(Convert.ToInt32(_Tb_ID.Text), Convert.ToInt32(DropDownList1.SelectedValue), _Tb_AuthorityName.Text);
                    ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + " UPDATE SUCCESSFUL " + "');", true);
                }
                else if (GridView1.Rows.Count == 0)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + " NO ID FOUND " + "');", true);
                }

                GridView1.Dispose();
                GridView2.Dispose();
            }
            ClearControls();
        }
コード例 #5
0
 protected void btnDownload_Click(object sender, EventArgs e)
 {
     GetData();
     exporttoexcel("Report.xls", GridView1);
     GridView1 = null;
     GridView1.Dispose();
 
 }
コード例 #6
0
        protected void Unnamed3_Click(object sender, EventArgs e)
        {
            adodatalayer ad1    = new adodatalayer();
            int          idno   = Convert.ToInt32(TextBox1.Text);
            var          update = ad1.DeleteStudent(idno);

            GridView1.DataSource = update;
            GridView1.Dispose();
        }
コード例 #7
0
        protected void btnCheckEmail_Click(object sender, EventArgs e)
        {
            try
            {
                int intRecords = 0;

                ArrayList u = new ArrayList();

                u = UserController.GetUsersByEmail(this.PortalId, txtEmail.Text.ToString(), 0, 1, ref intRecords);

                if (u.Count > 0)
                {
                    // lblErrorMessage.Text = "That e-mail address is already registered. Please login first.";
                    lblErrorMessage.Text = Localization.GetString("AlreadyRegisteredAccountMessage", this.LocalResourceFile);
                    PanelLogin.Visible   = true;

                    GridView1.Visible    = true;
                    GridView1.DataSource = u;
                    GridView1.DataBind();

                    txtUserName.Text             = GridView1.Rows[0].Cells[1].Text.ToString();
                    PanelPassword.Visible        = false;
                    btnCheckEmail.Visible        = false;
                    PanelRegisterAuction.Visible = false;

                    hiddenUserID.Value      = GridView1.Rows[0].Cells[0].Text.ToString();
                    lblInstructions.Visible = false;

                    GridView1.Visible = false;
                }
                else
                {
                    GridView1.Dispose();
                    GridView1.Visible            = false;
                    PanelLogin.Visible           = false;
                    PanelRegisterAuction.Visible = true;
                    btnRegister.Visible          = true;
                    PanelPassword.Visible        = true;
                    btnCheckEmail.Visible        = false;


                    reqFirstName.ValidationGroup   = "NewRegister";
                    reqLastName.ValidationGroup    = "NewRegister";
                    reqAddress.ValidationGroup     = "NewRegister";
                    reqCity.ValidationGroup        = "NewRegister";
                    reqPhoneNumber.ValidationGroup = "NewRegister";
                }

                pnlTerms.Visible = false;
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
コード例 #8
0
ファイル: stupdate.aspx.cs プロジェクト: swathisinisetti/C-
        protected void Button1_Click(object sender, EventArgs e)
        {
            Addlayer ad1   = new Addlayer();
            DateTime Doj   = DateTime.Parse(TextBox1.Text);
            string   Sname = TextBox2.Text;

            var up = ad1.update(Doj, Sname);

            GridView1.DataSource = up;
            GridView1.Dispose();
        }
コード例 #9
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            adodatalayer ad1    = new adodatalayer();
            int          idno   = Convert.ToInt32(TextBox1.Text);
            string       name   = (TextBox2.Text);
            string       course = (TextBox3.Text);
            string       date   = (TextBox4.Text);
            var          insert = ad1.InsertData(idno, name, course, date);

            GridView1.DataSource = insert;
            GridView1.Dispose();
        }
コード例 #10
0
        protected void ImageButton3_Click(object sender, ImageClickEventArgs e)
        {
            SqlConnection con = new SqlConnection("Data Source=ISENMURATI\\SQL2012;Initial Catalog=AirlineWeb;Integrated Security=True");
            DataTable     dt  = new DataTable();

            SqlDataAdapter objda = new SqlDataAdapter("SELECT * from Customers", con);

            objda.Fill(dt);
            GridView1.DataSource = dt;

            ExportToExcel("Report.xls", GridView1);
            GridView1 = null;
            GridView1.Dispose();
        }
コード例 #11
0
        protected void Button8_Click(object sender, EventArgs e)
        {
            string sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
                                       "Data Source=" + Server.MapPath("~/UpdateExcel/") + FileUpload1.FileName +
                                       ";Extended Properties=Excel 8.0;";
            OleDbConnection objConn = new OleDbConnection(sConnectionString);

            if (FileUpload1.HasFile)
            {
                try {
                    Directory.CreateDirectory(Server.MapPath("~/UpdateExcel/"));
                    FileUpload1.SaveAs(Server.MapPath("~/UpdateExcel/") + FileUpload1.FileName);
                    OleDbDataAdapter objAdapter1 = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", objConn);
                    if (objConn.State == ConnectionState.Closed)
                    {
                        objConn.Open();
                    }

                    DataSet objDataset1 = new DataSet();
                    objAdapter1.Fill(objDataset1, "XLData");
                    try {
                        GridView1.Dispose();
                        GridView1.DataSource = objDataset1.Tables[0]; //测试代码,用来测试是否能读出EXCEL上面的数据
                        GridView1.DataBind();
                        createbutton.Enabled = true;
                        //CheckText();
                    } catch (Exception ee) {
                        createbutton.Enabled = false;
                        Layer(@"layer.alert('请关闭本页面,删除C:\\DownExcel\\路径中的xls,重新把您的xls复制进去再试,记得格式转化成97-2003哦', {
                              icon: 2,title: false,
                              skin: 'layer-ext-moon' 
                            })", Page);
                    }
                } catch {
                    createbutton.Enabled = false;
                    Layer(@"layer.alert('上传失败!未知错误', {
                              icon: 5,title: false,
                              skin: 'layer-ext-moon' 
                            })", Page);
                }
            }
            else
            {
                createbutton.Enabled = false;
                Layer(@"layer.alert('您没有选择文件', {
                              icon: 0,title: false,
                              skin: 'layer-ext-moon' 
                            })", Page);
            }
        }
コード例 #12
0
        protected void btnTimkiem_Click(object sender, EventArgs e)
        {
            DataTable x = licht.LookLichTrinh(txtTimkiem.Text.Trim());

            if (x.Rows.Count <= 0)
            {
                Response.Write("<script>alert('Không có kết quả');</script>");
            }
            else
            {
                GridView1.Dispose();
                GridView1.DataSource = licht.LookLichTrinh(txtTimkiem.Text);
                GridView1.DataBind();
            }
        }
コード例 #13
0
        protected void btnEditar_Click(object sender, EventArgs e)
        {
            TheGym k = new TheGym
            {
                DNIEditar               = DNIEdit,
                NombreEmpleadoEdit      = TbNombre.Text,
                ApellidoEmpleadoEdit    = TbApellido.Text,
                DNIEmpleadoEdit         = TbDNI.Text,
                FechaNacEmpleadoEdit    = TbFechaNac.Text,
                EmailEmpleadoEdit       = TbEmail.Text,
                TelefonoEmpleadoEdit    = TbTelefono.Text,
                DomicilioEmpleadoEdit   = TbDomicilio.Text,
                TituloEmpleadoEdit      = TbTitulo.Text,
                ExperienciaEmpleadoEdit = TbExperiencia.Text,
                CargoEmpleadoEdit       = ddlCargo.SelectedValue
            };

            k.UpdateEmpleado();

            TbNombre.Text      = string.Empty;
            TbApellido.Text    = string.Empty;
            TbDNI.Text         = string.Empty;
            TbFechaNac.Text    = string.Empty;
            TbEmail.Text       = string.Empty;
            TbTelefono.Text    = string.Empty;
            TbDomicilio.Text   = string.Empty;
            TbTitulo.Text      = string.Empty;
            TbExperiencia.Text = string.Empty;
            ddlCargo.ClearSelection();
            ddlCargo.Enabled       = false;
            TbNombre.ReadOnly      = true;
            TbApellido.ReadOnly    = true;
            TbDNI.ReadOnly         = true;
            TbFechaNac.ReadOnly    = true;
            TbEmail.ReadOnly       = true;
            TbTelefono.ReadOnly    = true;
            TbDomicilio.ReadOnly   = true;
            TbTitulo.ReadOnly      = true;
            TbExperiencia.ReadOnly = true;

            DataTable aux = new DataTable();

            GridView1.DataSource = aux;
            GridView1.DataBind();
            GridView1.Dispose();
        }
コード例 #14
0
ファイル: adonet4.cs プロジェクト: deepakpa829/Deepak
        protected void Button1_Click(object sender, EventArgs e)
        {
            ADOlayer ad    = new ADOlayer();
            int      Id    = Convert.ToInt32(Id1.Text);
            string   Sname = Sname1.Text;

            ad.UpdateRecord(Id, Sname);
            var t = ad.Getallrecords();

            GridView1.DataSource = t;
            GridView1.Dispose();

            ADOlayer ado    = new ADOlayer();
            var      stlist = ado.Getallrecords();

            GridView1.DataSource = stlist;
            GridView1.DataBind();
        }
コード例 #15
0
        protected void gvtodas_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            conexionbd obje = new conexionbd();
            DataSet    dt   = new DataSet();

            gvtodas.PageIndex = e.NewPageIndex;

            dt = obje.CargarSolicitudes("", "", "", 3);
            gvtodas.DataSource = dt;
            gvtodas.DataBind();
            GridView1.Dispose();
            Pnlpendientes.Dispose();
            Pnlpendientes.Visible = false;
            // GridView1.Visible = false;

            PnlTodas.Visible = true;
            //  gvtodas.Visible = true;
        }
コード例 #16
0
    //protected void Button1_Click(object sender, EventArgs e)
    //{



    //    string ketnoi;

    //    ketnoi = "select * from sinhvien where (mssv="+mssv.Text+")";

    //    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);

    //    SqlCommand sql = new SqlCommand(ketnoi, con);

    //    DataSet ds = new DataSet();
    //    SqlDataAdapter sda = new SqlDataAdapter(sql);
    //    sda.Fill(ds, "sinhvien");
    //    DataTable dt = ds.Tables["sinhvien"];
    //    GridView1.DataSource = dt.DefaultView;
    //    GridView1.DataBind();

    //}



    //private void checknumber()
    //{

    //    string Str = textBox1.Text.Trim();

    //    double Num;

    //    bool isNum = double.TryParse(Str, out Num);

    //    if (isNum)

    //        MessageBox.Show(Num.ToString());

    //    else

    //        MessageBox.Show("Invalid number");

    //}



    //protected void khoi_SelectedIndexChanged(object sender, EventArgs e)
    //{
    //    Button2.Text = "Tra cứu";
    //    Label myLabel1 = this.FindControl("label1") as Label;
    //    myLabel1.Text = "";
    //    if (khoi.SelectedIndex == 8)
    //    {


    //        Label myLabel = this.FindControl("label1") as Label;
    //        myLabel.Text = "Thí sinh tốt nghiệp 2014 nộp học bạ và chứng nhận TN tạm thời (photo công chứng).Thí sinh TN trước năm 2014 nộp học bạ và giấy xác nhận điểm thi TN môn văn ( photo công chứng). Thời hạn nộp trước 5/08/2014";
    //    }

    //    if (khoi.SelectedIndex == 10)
    //    {


    //        Label myLabel = this.FindControl("label1") as Label;
    //        myLabel.Text = "Thí sinh tốt nghiệp 2014 nộp học bạ và chứng nhận TN tạm thời (photo công chứng).Thí sinh TN trước năm 2014 nộp học bạ và giấy xác nhận điểm thi TN môn văn ( photo công chứng). Thời hạn nộp trước 5/08/2014";
    //    }
    //    if (khoi.SelectedIndex == 9)
    //    {


    //        Label myLabel = this.FindControl("label1") as Label;
    //        myLabel.Text = "Thí sinh tốt nghiệp 2014 nộp học bạ và chứng nhận TN tạm thời (photo công chứng).Thí sinh TN trước năm 2014 nộp học bạ và giấy xác nhận điểm thi TN môn văn ( photo công chứng). Thời hạn nộp trước 5/08/2014";
    //    }
    //    if (khoi.SelectedIndex == 6)
    //    {


    //        Label myLabel = this.FindControl("label1") as Label;
    //        myLabel.Text = "Thí sinh tốt nghiệp 2014 nộp học bạ và chứng nhận TN tạm thời (photo công chứng).Thí sinh TN trước năm 2014 nộp học bạ và giấy xác nhận điểm thi TN môn văn ( photo công chứng). Thời hạn nộp trước 5/08/2014";
    //    }
    //    if (khoi.SelectedIndex == 7)
    //    {


    //        Label myLabel = this.FindControl("label1") as Label;
    //        myLabel.Text = "Thí sinh tốt nghiệp 2014 nộp học bạ và chứng nhận TN tạm thời (photo công chứng).Thí sinh TN trước năm 2014 nộp học bạ và giấy xác nhận điểm thi TN môn văn ( photo công chứng). Thời hạn nộp trước 5/08/2014";
    //    }
    //}

    //private void checkhoso()
    //{
    //    Button2.Text = "Tra cứu";
    //    Label myLabel1 = this.FindControl("label1") as Label;
    //    myLabel1.Text = "";
    //    if (khoi.SelectedIndex == 8)
    //    {


    //        Label myLabel = this.FindControl("label1") as Label;
    //        myLabel.Text = "Thí sinh tốt nghiệp 2014 nộp học bạ và chứng nhận TN tạm thời (photo công chứng).Thí sinh TN trước năm 2014 nộp học bạ và giấy xác nhận điểm thi TN môn văn ( photo công chứng). Thời hạn nộp trước 5/08/2014";
    //    }

    //    if (khoi.SelectedIndex == 10)
    //    {


    //        Label myLabel = this.FindControl("label1") as Label;
    //        myLabel.Text = "Thí sinh tốt nghiệp 2014 nộp học bạ và chứng nhận TN tạm thời (photo công chứng).Thí sinh TN trước năm 2014 nộp học bạ và giấy xác nhận điểm thi TN môn văn ( photo công chứng). Thời hạn nộp trước 5/08/2014";
    //    }
    //    if (khoi.SelectedIndex == 9)
    //    {


    //        Label myLabel = this.FindControl("label1") as Label;
    //        myLabel.Text = "Thí sinh tốt nghiệp 2014 nộp học bạ và chứng nhận TN tạm thời (photo công chứng).Thí sinh TN trước năm 2014 nộp học bạ và giấy xác nhận điểm thi TN môn văn ( photo công chứng). Thời hạn nộp trước 5/08/2014";
    //    }
    //    if (khoi.SelectedIndex == 6)
    //    {


    //        Label myLabel = this.FindControl("label1") as Label;
    //        myLabel.Text = "Thí sinh tốt nghiệp 2014 nộp học bạ và chứng nhận TN tạm thời (photo công chứng).Thí sinh TN trước năm 2014 nộp học bạ và giấy xác nhận điểm thi TN môn văn ( photo công chứng). Thời hạn nộp trước 5/08/2014";
    //    }
    //    if (khoi.SelectedIndex == 7)
    //    {


    //        Label myLabel = this.FindControl("label1") as Label;
    //        myLabel.Text = "Thí sinh tốt nghiệp 2014 nộp học bạ và chứng nhận TN tạm thời (photo công chứng).Thí sinh TN trước năm 2014 nộp học bạ và giấy xác nhận điểm thi TN môn văn ( photo công chứng). Thời hạn nộp trước 5/08/2014";
    //    }
    //}
    protected void Button1_Click(object sender, EventArgs e)
    {
        GridView1.Dispose();
        GridView1.DataBind();

        //  khoi.Text = khoi.SelectedItem.Text;

        string ketnoi;

        ketnoi = "SELECT SOPHIEU, HOVATEN, PHAI, NGAYSINH,NGANH, MANGANH FROM  KQXT WHERE ((HOVATEN = N'" + mssv.Text + "') and (NGAYSINH= N'" + mssv0.Text + "'))";
        SqlConnection  con = new SqlConnection(ConfigurationManager.ConnectionStrings["TSConnectionString"].ConnectionString);
        SqlCommand     sql = new SqlCommand(ketnoi, con);
        DataSet        ds  = new DataSet();
        SqlDataAdapter sda = new SqlDataAdapter(sql);

        sda.Fill(ds, "KQXT");
        DataTable dt = ds.Tables["KQXT"];

        GridView1.DataSource = dt.DefaultView;
        GridView1.DataBind();
    }
コード例 #17
0
        public void ConsultarTodasSolicitudes()
        {
            solicitud  oSolicitud = new solicitud();
            conexionbd obje       = new conexionbd();
            DataSet    dt         = new DataSet();

            dt = obje.CargarSolicitudes("", "", "", 2);

            GridView1.DataSource = dt;
            GridView1.DataBind();
            int conteo = 0;

            conteo = oSolicitud.ContarPendientes();



            lbltareas.Text = "Tareas Pendientes: " + conteo;
            if (chktodas.Checked)
            {
                dt = obje.CargarSolicitudes("", "", "", 3);

                gvtodas.DataSource = dt;
                gvtodas.DataBind();
                GridView1.Dispose();
                Pnlpendientes.Dispose();
                Pnlpendientes.Visible = false;


                PnlTodas.Visible = true;

                lbltareas.Text = "Todas las tareas";
            }
            else
            {
                Pnlpendientes.Visible = true;

                PnlTodas.Visible = false;
            }
        }
 protected void Button2_Click(object sender, EventArgs e)
 {
     GridView1.Dispose();
     GridView1.DataBind();
 }
コード例 #19
0
ファイル: SendMail.aspx.cs プロジェクト: varathansp/TimeSheet
        protected void btnGo_Click(object sender, EventArgs e)
        {
            try
            {
                DateTime FromDate = Convert.ToDateTime(FrmDateCal.Text);
                DateTime ToDate   = Convert.ToDateTime(ToDateCal.Text);
                int      result   = DateTime.Compare(FromDate, ToDate);

                if (result < 0 || result == 0)
                {
                    con.ConnectionString = connection.ToString();
                    con.Open();
                    OleDbCommand cmd = new OleDbCommand();
                    cmd.Connection = con;
                    //String query = "SELECT NAME,SUM(HOURS) AS [TOTAL HOURS] FROM TIMESHEET WHERE cdate(format(DATE,'M/d/yyyy hh:mm:ss')) BETWEEN #" + FrmDateCal.Text + "# AND #" + ToDateCal.Text + "# GROUP BY NAME UNION ALL SELECT LOGIN.USERNAME as NAME,'0' as HOURS FROM LOGIN WHERE LOGIN.USERNAME NOT IN (SELECT TIMESHEET.NAME FROM TIMESHEET GROUP BY TIMESHEET.NAME)";
                    String query = "(select  l.username as NAME,sum(t.hours) as [HOURS] from login l left join (select ts.name as NAME,sum(ts.hours) as [HOURS] from timesheet ts where cdate(format(DATE,'M/d/yyyy hh:mm:ss')) BETWEEN #" + FrmDateCal.Text + "# AND #" + ToDateCal.Text + "# group by name) t on l.username=t.name group by username) ";

                    OleDbDataAdapter da = new OleDbDataAdapter(query, con);
                    DataTable        dt = new DataTable();
                    da.Fill(dt);
                    string hours = txtHours.Text;
                    if (dt.Rows.Count > 0)
                    {
                        GridView1.DataSource = dt;

                        GridView1.DataBind();
                        for (int i = 0; i < GridView1.Rows.Count; i++)
                        {
                            string value = GridView1.Rows[i].Cells[2].Text;
                            if (GridView1.Rows[i].Cells[2].Text == "&nbsp;")
                            {
                                GridView1.Rows[i].Cells[2].Text = "0";
                            }
                        }
                        GridView1.Visible = true;
                        GridView1.Dispose();
                        sendMail.Visible = true;

                        if (hours != "")
                        {
                            for (int i = 0; i < GridView1.Rows.Count; i++)
                            {
                                if (Convert.ToInt32(GridView1.Rows[i].Cells[2].Text) < Convert.ToInt32(hours))
                                {
                                    GridView1.Rows[i].Cells[2].BackColor = Color.Red;
                                }
                            }
                        }
                    }


                    else
                    {
                        lblError.Text = "No result found";
                    }
                }

                else
                {
                    lblError.Text     = "**FROM DATE should always be earlier than TO DATE**";
                    GridView1.Visible = false;
                }
                con.Close();
            }

            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }
コード例 #20
0
        protected void Button8_Click(object sender, EventArgs e)
        {
            Directory.CreateDirectory(Server.MapPath("~/UpdateExcel/"));
            string sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
                                       "Data Source=" + Server.MapPath("~/UpdateExcel/") + FileUpload1.FileName +
                                       ";Extended Properties=Excel 8.0;";
            OleDbConnection objConn = new OleDbConnection(sConnectionString);

            if (FileUpload1.HasFile)
            {
                try {
                    FileUpload1.SaveAs(Server.MapPath("~/UpdateExcel/") + FileUpload1.FileName);
                    //建立EXCEL的连接
                    if (objConn.State == ConnectionState.Closed)
                    {
                        objConn.Open();
                    }
                    OleDbCommand     objCmdSelect = new OleDbCommand("SELECT * FROM [Sheet1$]", objConn);
                    OleDbDataAdapter objAdapter1  = new OleDbDataAdapter();
                    objAdapter1.SelectCommand = objCmdSelect;

                    DataSet objDataset1 = new DataSet();
                    try {
                        objAdapter1.Fill(objDataset1, "XLData");
                        string temp = "";
                        for (int i = 0; i < objDataset1.Tables[0].Rows.Count; i++)  //删除空行
                        {
                            temp = objDataset1.Tables[0].Rows[i][0].ToString();
                            if (temp == null || temp == "" || temp == "&nbsp;" || temp == "null")
                            {
                                objDataset1.Tables[0].Rows[i].Delete();
                            }
                        }
                        GridView1.Dispose();
                        GridView1.DataSource = objDataset1.Tables[0].DefaultView; //测试代码,用来测试是否能读出EXCEL上面的数据
                        GridView1.DataBind();
                        CheckText();
                    } catch (Exception ee) {
                        try {
                            GridView1.Dispose();
                        } catch { }
                        Label1.Text = ("检查失败!可能是选错了表,或者表中信息错误,错误信息:" + ee.Message).Replace("'", "〞");
                        Layer(string.Format(@"layer.alert('{0}', {{
                              icon: 5,title: false,
                              shadeClose: true,skin: 'layer-ext-moon'  
                            }})", Label1.Text), Page);
                        Button1.CssClass = " layui-btn-disabled touming";
                        Button1.Enabled  = false;
                    }
                } catch (Exception ee) {
                    Label1.Text = ("检查失败!可能是不支持excel2007版本及以上,错误信息" + ee.Message).Replace("'", "〞");;
                    Layer(string.Format(@"layer.alert('{0}', {{
                              icon: 5,title: false,
                              shadeClose: true,skin: 'layer-ext-moon'  
                            }})", Label1.Text), Page);
                    Button1.CssClass = " layui-btn-disabled touming";
                    Button1.Enabled  = false;
                } finally {
                    if (objConn.State == ConnectionState.Open)
                    {
                        objConn.Close();
                    }
                }
            }
            else
            {
                Label1.Text = "您没有选择文件";
                Layer(@"layer.alert('您没有选择文件', {
                              icon: 0,title: false,
                              shadeClose: true,skin: 'layer-ext-moon'  
                            })", Page);
            }
        }