using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Collections.Generic;
namespace Sgcyc.GysPt
{
public class CbxLbx
{
private string arg;
private CheckBox cbx;
private ListBox lbx;
public string Arg
{
get { return this.arg; }
set { this.arg = value; }
}
public CheckBox Cbx
{
get { return this.cbx; }
set { this.cbx = value; }
}
public ListBox Lbx
{
get { return this.lbx; }
set { this.lbx = value; }
}
public void BindListBox(DataView view)
{
if (this.cbx.Checked)
{
this.lbx.DataSource = view;
this.lbx.DataTextField = this.arg;
this.lbx.DataBind();
if (this.arg == "mqjb")
foreach (ListItem item in this.lbx.Items)
{
switch (item.Text)
{
case "11":
item.Text = "油井";
break;
case "31":
item.Text = "水井";
break;
case "4S":
item.Text = "蒸汽驱";
break;
default:
break;
}
}
}
else
{
this.lbx.Items.Clear();
}
}
public CbxLbx(string arg, CheckBox cbx, ListBox lbx)
{
this.arg = arg;
this.cbx = cbx;
this.lbx = lbx;
}
}
public partial class GysCxXt : System.Web.UI.Page
{
private List<CbxLbx> clList = new List<CbxLbx>();
protected void Page_Load(object sender, EventArgs e)
{
this.clList.Add(new CbxLbx("mqjb", this.CheckBox1, this.ListBox1));
this.clList.Add(new CbxLbx("qkdy", this.CheckBox2, this.ListBox2));
this.clList.Add(new CbxLbx("km", this.CheckBox3, this.ListBox3));
this.clList.Add(new CbxLbx("jlzh", this.CheckBox4, this.ListBox4));
this.clList.Add(new CbxLbx("jh", this.CheckBox5, this.ListBox5));
foreach (CbxLbx cl in this.clList)
{
cl.Lbx.SelectedIndex = -1;
cl.Cbx.CheckedChanged += new EventHandler(Cbx_CheckedChanged);
cl.Lbx.SelectedIndexChanged += new EventHandler(Lbx_SelectedIndexChanged);
}
if (!IsPostBack)
{
ListBoxTimeSetup();
Sgcyc.DAL.DateAccess dataAccess
= new Sgcyc.DAL.DateAccess();
string command = "select jh,qkdy,km,jlzh,mqjb from daa01 where wstbz=0";
DataView view = dataAccess.GetDataviewByCommand(command);
SessionView = view;
}
}
void Lbx_SelectedIndexChanged(object sender, EventArgs e)
{
//throw new NotImplementedException();
foreach (CbxLbx cl in this.clList)
{
cl.BindListBox(this.SessionView);
}
}
void Cbx_CheckedChanged(object sender, EventArgs e)
{
//throw new NotImplementedException();
foreach (CbxLbx cl in this.clList)
{
DataTable dt = this.SessionView.Table;
string filter = string.Format(
"{0}={1}",
cl.Arg,
cl.Lbx.SelectedValue
);
DataRow[] rows = dt.Select(filter);
DataTable newTable = new DataTable();
newTable.Rows.Add(rows);
DataView newView = newTable.DefaultView;
cl.BindListBox(newView);
this.SessionView = newView;
}
}
public DataView SessionView
{
get { return this.Session["view"] as DataView; }
set { this.Session["view"] = value; }
}
private void ListBoxTimeSetup()
{
DateTime now = DateTime.Now;
int nowYear = now.Year;
int nowMonth = now.Month;
int nowDay = now.Day;
int beginYear = nowYear - 40;
ListItem item = null;
for (int year = beginYear; year <= nowYear; year++)
{
item = new ListItem(year.ToString());
this.lbxBeginYear.Items.Add(item);
this.lbxEndYear.Items.Add(item);
}
for (int month = 1; month <= 12; month++)
{
item = new ListItem(month.ToString());
this.lbxBeginMonth.Items.Add(item);
this.lbxEndMonth.Items.Add(item);
}
this.lbxEndMonth.SelectedValue = item.Text;
for (int day = 1; day <= 31; day++)
{
item = new ListItem(day.ToString());
this.lbxBeginDay.Items.Add(item);
this.lbxEndDay.Items.Add(item);
}
this.lbxEndDay.SelectedValue = item.Value;
}
}
}
