webform---组合查询&流水号生成

public partial class 组合查询 : System.Web.UI.Page
{
    private MyDBDataContext _Context = new MyDBDataContext();

    //绑定数据车辆系列
    private void FillBrand()
    {
        List<Brand> list = _Context.Brand.ToList();
        ddlBrand.DataSource = list;
        ddlBrand.DataTextField = "Brand_Name";
        ddlBrand.DataValueField = "Brand_Code";
        ddlBrand.DataBind();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            FillBrand();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        var query1 = _Context.Car.AsQueryable();//根据车名查
        var query2 = _Context.Car.AsQueryable();//根据系列查
        var query3 = _Context.Car.AsQueryable();//根据油耗查

        //根据填写情况完善以上三个查询条件
        if (txtName.Text.Trim().Length > 0)
        {
            query1 = query1.Where(p=>p.Name .Contains(txtName.Text));
        }
        if (ddlBrand.SelectedValue != "-1")
        {
            query2 = query2.Where(p=>p.Brand == ddlBrand.SelectedValue);
        }
        if (txtOil.Text.Trim().Length > 0)
        {
            query3 = query3.Where(p=>p.Oil == Convert.ToDecimal( txtOil.Text ));
        }

        //三个查询关系可用集合的交集来实现
        var query = query1.Intersect(query2).Intersect(query3);

        //数据绑定 显示
        Repeater1.DataSource = query;
        Repeater1.DataBind();
    }
}
//点击生成流水号按钮

    protected void Button2_Click(object sender, EventArgs e)
    {
        string prefix = "p" + DateTime.Now.ToString("yyyyMMdd");  //生成当天的流水号前缀
        //查当天的最大流水号(a.已经有流水号 b.没有流水号)
        int maxFlow = 0;
        var query = _Context.Info.Where(p => p.Code.StartsWith(prefix));  //模糊查询当天所有的流水号
        if (query.Count() > 0)  //已有流水号,则找最大流水号
        {
            query = query.OrderByDescending(p=>p.Code);  //按流水号降序排
            string maxCode = query.First().Code;  //获取最大流水号
            maxFlow = Convert.ToInt32(maxCode.Substring(maxCode.Length-3));  //截取并转换出现有的最大的流水号来
        }

        //组合生成新的流水号
        string flowCode = prefix + (maxFlow + 1).ToString("000");

        //显示在文本框中
        TextBox1.Text = flowCode;

    }
时间: 2024-10-26 06:28:33

webform---组合查询&流水号生成的相关文章

WebForm组合查询

封转类 using System; using System.Collections.Generic; using System.Linq; using System.Web; /// <summary> /// Car 的摘要说明 /// </summary> public class Car { public int ids{get;set;} public string code{get;set;} public string name{get;set;} public st

webform组合查询和分页

1.组合查询(1)数据访问类 //参数1:SQL语句 参数2:哈希表public List<Users> chas(string s,Hashtable has) { List<Users> List = new List<Users>(); Users u = null; com.CommandText = s; com.Parameters.Clear(); foreach(string aa in has.Keys) { com.Parameters.Add(aa

Webfrom 生成流水号 组合查询 Repeater中单选与复选控件的使用 JS实战应用

                                         Default.aspx 网页界面 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html> <html xmlns="http://www.

webform:分页组合查询

一个简单的分页组合查询页面 /// <summary> /// 查询方法 /// </summary> /// <param name="tsql">SQL语句</param> /// <param name="hh">哈希表</param> /// <returns></returns> public List<Goods> Select(string un

WebForm 分页与组合查询

1.封装实体类 2.写查询方法 //SubjectData类 public List<Subject> Select(string name) { List<Subject> list = new List<Subject>(); cmd.CommandText = "select *from Subject where SubjectName like @a "; cmd.Parameters.Clear(); cmd.Parameters.Add

webform(八)组合查询

组合查询就是根据条件取出某些数据并展示出来. 前台代码 <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>组合查询</title> &l

Webform(Linq高级查、分页、组合查询)

Linq高级查:字符串:模糊查(包含):con.car.Where(r => r.name.Contains(name)).ToList();以什么开头:con.car.Where(r => r.name.StartsWith(name)).ToList();以什么结尾:con.car.Where(r => r.name.EndsWith(name)).ToList(); 数值:个数:.Count()最大值:con.car.Max(r => r.price);最小值:con.car

Webform(分页与组合查询配合使用)

1.封装实体类 2.写查询方法 //SubjectData类 public List<Subject> Select(string name) { List<Subject> list = new List<Subject>(); cmd.CommandText = "select *from Subject where SubjectName like @a "; cmd.Parameters.Clear(); cmd.Parameters.Add

WebForm之Linq组合查询

组合查询 protected void Button1_Click(object sender, EventArgs e) { //默认查询所有,返回的是Table类型,转换成IQueryAble类型. var query1 = this._Contex.car.AsQueryable(); var query2 = this._Contex.car.AsQueryable(); var query3 = this._Contex.car.AsQueryable(); //进一步判断查询,根据输