test

来源:互联网 发布:一卡通乘客刷卡数据 编辑:程序博客网 时间:2024/04/27 22:41

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;
using Wuqi.Webdiyer;
using System.Reflection;
using System.IO;
using System.Runtime.InteropServices;
using System.Data.OracleClient;

namespace chem
{
 /// <summary>
 /// adm_corps 的摘要说明。
 /// </summary>
 public class adm_corps : System.Web.UI.Page
 {
  protected System.Web.UI.WebControls.Label L_corps;
  protected System.Web.UI.WebControls.DropDownList D_police;
 
  protected System.Web.UI.WebControls.DataGrid D_corpinfo;
  protected System.Web.UI.HtmlControls.HtmlForm frmMain;
  protected System.Web.UI.WebControls.LinkButton B_add;
  protected System.Web.UI.WebControls.DropDownList D_police1;

  protected Wuqi.Webdiyer.AspNetPager pager;

  protected string uid="";
  protected string bid="";
  protected System.Web.UI.WebControls.DropDownList D_corpkind;
  protected System.Web.UI.WebControls.TextBox T_corpquery;
  protected System.Web.UI.WebControls.ImageButton B_query;
  protected System.Web.UI.WebControls.LinkButton B_toexcel;
  protected System.Web.UI.WebControls.DataGrid dg;

  protected string ModuleName = "企业信息管理";

  private void Page_Load(object sender, System.EventArgs e)
  {
   if(!this.IsPostBack)
   { 
    if(!Common.MustLogin(ref bid,ref uid))    //验证登录
    {
     Common.CallBack("您还没有登录!请登录。",Common.loginUrl);
     return;
    }

    if ( !Common.ModuleCheck( ref bid,ref uid,ModuleName ) )
    {
     B_add.Visible = false;
     B_toexcel.Visible = false;
    }    
    Common.GetCorpKind(D_corpkind);     //绑定企业类型
    int page = 1;
    try
    {
     string id1 = Request.QueryString["id1"].ToString();
     Common.BindParentDrop(bid,D_police,true);      //绑定police下拉框   
     Common.DropDownList_Select(D_police,id1,0);
     string id2 = Request.QueryString["id2"].ToString();
     Common.BindSubDrop(bid,D_police,D_police1);      //绑定police1下拉框
     Common.DropDownList_Select(D_police1,id2,0);
     string kind = Request.QueryString["kind"].ToString();
     Common.DropDownList_Select(D_corpkind,kind,0);
     if(Request.QueryString.Count > 0)
     {
      page = Convert.ToInt32(Request.QueryString["page"]);
      if(page == 0)
       page = 1;
     }
    }
    catch
    {
     Common.BindParentDrop(bid,D_police,true);      //绑定police下拉框
     Common.BindSubDrop(bid,D_police,D_police1);      //绑定police1下拉框
    }
    DropChange(page);
   }
  }

  private void DropChange(int PageIndex)   //三个下拉框一起查询
  {
   bid=Request.Cookies["SunrayTechChem"].Values["BoroughID"].ToString();
   int tmpBid = Common.WhichBorough(bid);
   string sql="";
       
   if(tmpBid == 1)  //省厅的情况
   {    
    if(D_police1.Visible == true)     
     KindChange(bid,D_police1.SelectedValue,ref sql);          
    else
     KindChange(bid,D_police.SelectedValue,ref sql);                       
   }        
   else if(tmpBid == 2) //地区的情况   
    KindChange(bid,D_police.SelectedItem.Value,ref sql);   
   else    //县级情况
    KindChange(bid,"",ref sql);
   string headSql = "select CI.CorpName,CI.CorpID,CI.BoroughID,CI.CorpNo from Corp_Info CI ";
   string order="order by CI.BoroughID,CI.CorpNo";

   string CorpName = T_corpquery.Text.Trim();
   string strCorpSql = "";
   if( !CorpName.Equals( "" ) )
    strCorpSql = " and ( CorpName like '%"+CorpName+"%' or CorpID like '%" + CorpName + "') ";
   string strSql ="";

   //modified by zhengjo 2006-12-04
//   string countSql = "select Count(*) from Corp_Info CI ";
//   strSql = countSql+sql;
//   Common.SetPager(PageIndex,pager,strSql);
   strSql=headSql + sql + strCorpSql + order;
   Common.BindGrid( strSql , "Corp_Info" , D_corpinfo , pager , PageIndex );
//   Common.BindGrid(strSql,"Corp_Info",D_corpinfo,D_corpinfo.Columns.Count,pager.PageSize*(pager.CurrentPageIndex-1),pager.PageSize);   
  
   string s1="";
   string s2="";
   if(!Common.ModuleCheck(ref s1,ref s2, "企业信息管理"))
   {
    D_corpinfo.Columns[2].Visible = false;
    D_corpinfo.Columns[3].Visible = false;
    D_corpinfo.Columns[4].Visible = false;
   }     
  }

  private void KindChange(string bid,string DropValue,ref string sql)
  { 
   int I_bid = Common.WhichBorough(bid);
   if(DropValue != "")      
   {
    I_bid = Common.WhichBorough(DropValue);
    bid = DropValue;
   }
   if(D_corpkind.SelectedValue != "")  
   {
    sql += "where CI.CorpID in (select distinct(CorpID) from Corp_Types where CorpType='"+D_corpkind.SelectedValue+"' and";
    if(I_bid == 1)
     sql += " SUBSTR(BoroughID,1,2)='"+bid.Substring(0,2)+"')";
    else if(I_bid == 2)
     sql += " SUBSTR(BoroughID,1,4)='"+bid.Substring(0,4)+"')";
    else
     sql += " BoroughID='"+bid+"')";
   }
   else
   {
    if(I_bid == 1)
     sql += " where SUBSTR(BoroughID,1,2)='"+bid.Substring(0,2)+"'";
    else if(I_bid == 2)
     sql += " where SUBSTR(BoroughID,1,4)='"+bid.Substring(0,4)+"'";
    else
     sql += " where BoroughID='"+bid+"'";
   }  
  }
  
  public void ChangePage(object src,PageChangedEventArgs e)
  {
   DropChange(e.NewPageIndex);   
  }
  public void D_police_SelectedIndexChanged(object sender,System.EventArgs e)
  {
   string bid = Request.Cookies["SunrayTechChem"].Values["BoroughID"].ToString();
   Common.BindSubDrop(bid,D_police,D_police1);
   DropChange(1); 
  }
 
  #region Web 窗体设计器生成的代码
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {   
   this.D_police.SelectedIndexChanged += new System.EventHandler(this.D_police_SelectedIndexChanged);
   this.D_police1.SelectedIndexChanged += new System.EventHandler(this.D_police1_SelectedIndexChanged);
   this.D_corpkind.SelectedIndexChanged += new System.EventHandler(this.D_corpkind_SelectedIndexChanged);
   this.B_add.Click += new System.EventHandler(this.B_add_Click);
   this.B_toexcel.Click += new System.EventHandler(this.B_toexcel_Click);
   this.B_query.Click += new System.Web.UI.ImageClickEventHandler(this.B_query_Click);
   this.D_corpinfo.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.D_corpinfo_EditCommand);
   this.D_corpinfo.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.D_corpinfo_DeleteCommand);
   this.dg.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dg_ItemDataBound);
   this.Load += new System.EventHandler(this.Page_Load);

  }
  #endregion

  private void D_corpinfo_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
  {
   string bid="";
   try
   {
    bid=Request.Cookies["SunrayTechChem"].Values["BoroughID"].ToString();
   }
   catch
   {
    Response.Redirect("login.aspx");
   }
   string deltype="delete from Corp_Types where CorpID='"+e.Item.Cells[0].Text.ToString().Trim()+"' and BoroughID=(select BoroughID from Corp_Info where CorpID='"+e.Item.Cells[0].Text.ToString().Trim()+"' and CorpName='"+e.Item.Cells[1].Text.ToString().Trim()+"')";
   Common.delete(deltype);
   string delsql="delete from Corp_Info where CorpID='"+e.Item.Cells[0].Text.ToString().Trim()+"' and CorpName='"+e.Item.Cells[1].Text.ToString().Trim()+"'";
   Common.delete(delsql);
   
   string gridsql="";
   try
   {
    if(bid==Common.Sboroughid)
    {
     gridsql="select * from Corp_Info where BoroughID='"+D_police.SelectedItem.Value+"'";
    }
    else
    {
     gridsql="select * from Corp_Info where BoroughID='"+bid+"'";
    }
   }
   catch
   {
    Response.Redirect("login.aspx");
   }
   Common.BindGrid(gridsql,"Corp_Info",D_corpinfo);
  }

  private void B_add_Click(object sender, System.EventArgs e)
  {
   string kind = "&kind="+D_corpkind.SelectedValue+"&page="+pager.CurrentPageIndex;
   if(D_police.Visible==true)
   {
    if(D_police1.Visible==true)
     Response.Redirect("adm_corps_add.aspx?id1="+D_police.SelectedItem.Value+"&id2="+D_police1.SelectedItem.Value+kind);
    else
     Response.Redirect("adm_corps_add.aspx?id1="+D_police.SelectedItem.Value+"&id2="+kind);
   }
   else
    Response.Redirect("adm_corps_add.aspx?id1=&id2="+kind);
  }

  private void D_corpinfo_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
  {
   string bid = Request.Cookies["SunrayTechChem"].Values["BoroughID"].ToString();
   if(D_police.Visible==true)
   {
    if(D_police1.Visible==true)
     Response.Redirect("adm_corps_modi.aspx?id1="+D_police.SelectedItem.Value+"&id2="+D_police1.SelectedItem.Value+"&kind="+D_corpkind.SelectedItem.Value+"&cid="+e.Item.Cells[1].Text.Trim()+"&page="+pager.CurrentPageIndex);
    else
     Response.Redirect("adm_corps_modi.aspx?id1="+D_police.SelectedItem.Value+"&id2=&kind="+D_corpkind.SelectedItem.Value+"&cid="+e.Item.Cells[1].Text.Trim()+"&page="+pager.CurrentPageIndex);
   }
   else
    Response.Redirect("adm_corps_modi.aspx?id1=&id2=&kind="+D_corpkind.SelectedItem.Value+"&cid="+e.Item.Cells[1].Text.Trim()+"&page="+pager.CurrentPageIndex);
  }

  private void D_corpkind_SelectedIndexChanged(object sender, System.EventArgs e)
  {
   DropChange(1);
  }

  private void D_police1_SelectedIndexChanged(object sender, System.EventArgs e)
  {
   DropChange(1);
  }

  private void B_query_Click(object sender, System.Web.UI.ImageClickEventArgs e)
  {
   //modified by zhengjo 2006-12-04
   DropChange( 1 );
//   string CorpName = T_corpquery.Text.Trim();
//   string CorpSql = "select CI.CorpName,CI.CorpID,CI.BoroughID,CI.CorpNo from Corp_Info CI where ";
//   CorpSql += Common.BoroughChange(D_police,D_police1);
//   if(D_corpkind.SelectedValue != "")
//    CorpSql += " CI.CorpID in (select distinct(CorpID) from Corp_Types where CorpType='"+D_corpkind.SelectedValue+"' and";
//   string orderSql = " CorpName like '%"+CorpName+"%' order by CorpNo";
//   CorpSql += orderSql;
//   Common.BindGrid(CorpSql,"Corp_Info",D_corpinfo,pager,1);
  }
  
  [DllImport("User32.dll", CharSet = CharSet.Auto)]

  public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int ID);

  private void B_toexcel_Click(object sender, System.EventArgs e)
  {
   //将企业信息搜索出来放入DataTable
   string CorpSql = "select CorpName 企业名称,CorpID 企业编号,CorpMan 企业法人,TelePhone 联系电话,Address 联系地址,PostCode 邮编,Password 同步密码,Fgld 分管领导,Phone1 分管领导电话,Operator 专管员,Phone2 专管员电话,Remark     备注 from Corp_Info where ";
   CorpSql += Common.RequestBidJudge(D_police.SelectedValue,D_police1.SelectedValue);
   if(D_corpkind.SelectedValue != "")
    CorpSql += " CorpID in (select distinct(CorpID) from Corp_Types where CorpType='"+D_corpkind.SelectedValue+"' and ";
   string orderSql = " order by CorpNo";
   CorpSql += orderSql;
   DataTable dt = Common.select(CorpSql,"Corp_Info");   
   
   string FileName = "企业信息列表[" + DateTime.Now.ToString("yyyyMMddHHmmss") +"]";

   int rowCount = dt.Rows.Count;
   int columnCount = dt.Columns.Count;
   
   dg.DataSource = dt.DefaultView;
   dg.DataBind(); 
   
   Response.Clear();
   Response.Buffer= true;
   Response.Charset="GB2312";
   Response.AddHeader("Content-Disposition", "attachment; filename="+System.Web.HttpUtility.UrlEncode(FileName)+".xls");
   Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");
   //设置输出流为简体中文
   Response.ContentType = "application/ms-excel";
   //设置输出文件类型为excel文件。
   this.EnableViewState = false;
   System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN",true);
   System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
   System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
   dg.RenderControl(oHtmlTextWriter);
   Response.Write(oStringWriter.ToString());
   Response.End();        
  }

  private void dg_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
  {
   if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
   {
    e.Item.Cells[0].Attributes.Add("style","vnd.ms-excel.numberformat:@");
    e.Item.Cells[1].Attributes.Add("style","vnd.ms-excel.numberformat:@");
    e.Item.Cells[3].Attributes.Add("style","vnd.ms-excel.numberformat:@");
    e.Item.Cells[5].Attributes.Add("style","vnd.ms-excel.numberformat:@");
    e.Item.Cells[6].Attributes.Add("style","vnd.ms-excel.numberformat:@");
    e.Item.Cells[8].Attributes.Add("style","vnd.ms-excel.numberformat:@");
    e.Item.Cells[10].Attributes.Add("style","vnd.ms-excel.numberformat:@");
   }
  }
 }
}
 

原创粉丝点击