Exemplo n.º 1
0
    public void sousuo()
    {
        string strXM           = txtXM.Text;
        string strDH           = txtDH.Text;
        linqKeHuDataContext kh = new linqKeHuDataContext();

        System.Linq.IQueryable <KeHu> query;
        //判断组合条件
        switch (drl1.SelectedValue)
        {
        case "和":
            query =
                from kehu in kh.KeHu
                where kehu.Kh_XingMing == txtXM.Text.Trim() && kehu.Kh_DianHua == txtDH.Text.Trim()
                select kehu;
            //把grvKH的数据源设置为查询结果query
            grvKH.DataSource = query;
            //把grvKH的索引设置为客户ID
            grvKH.DataKeyNames = new string[] { "Kh_id" };
            //grvKH重新绑定数据
            grvKH.DataBind();
            break;

        case "或":
            query =
                from kehu in kh.KeHu
                where kehu.Kh_XingMing == txtXM.Text.Trim() || kehu.Kh_DianHua == txtDH.Text.Trim()
                select kehu;
            grvKH.DataSource   = query;
            grvKH.DataKeyNames = new string[] { "Kh_id" };
            grvKH.DataBind();
            break;
        }
    }
Exemplo n.º 2
0
    protected void grvKH_SelectedIndexChanged(object sender, EventArgs e)
    {
        linqKeHuDataContext kh       = new linqKeHuDataContext();
        Table <KeHu>        kehulist = kh.GetTable <KeHu>();
        var query =
            from kehu in kehulist
            where kehu.Kh_Id == Convert.ToInt32(grvKH.DataKeys[grvKH.SelectedIndex].Value.ToString())
            select kehu;

        FormView1.DataSource = query;
        FormView1.DataBind();
        //dlvKeHu.DataSource = query;
        //dlvKeHu.DataBind();
    }
Exemplo n.º 3
0
    public void tianjia()
    {
        //各项信息填写完成后,把客户信息利用LINQ技术输入到KeHu表
        linqKeHuDataContext kh = new linqKeHuDataContext();
        KeHu newkh             = new KeHu();

        newkh.Kh_XingMing       = txtXM.Text;
        newkh.Kh_XingBie        = RadioButtonList1.SelectedValue;
        newkh.Kh_DianHua        = txtDH.Text;
        newkh.Kh_JingJiRenId    = Convert.ToInt32(Session["Yg_Id"].ToString());
        newkh.Kh_ShenFenZheng   = txtSF.Text;
        newkh.Kh_BeiZhu         = txtBZ.Text;
        newkh.Kh_TianJiaShiJian = DateTime.Now;
        //提交插入新客户请求
        kh.KeHu.InsertOnSubmit(newkh);
        //执行插入新客户
        kh.SubmitChanges();
        //提示插入新客户成功
        Response.Write("<Script language=javascript>");
        Response.Write("window.alert('添加客户成功!');");
        Response.Write("window.location='KeHuTJ.aspx");
        Response.Write("'</script>");
    }