⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 totalview0508.aspx.cs

📁 用vs2005写的一个生产任务管理系统。数据的统计和综合查询是主要功能
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
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 RWSB.DatabaseOper;
using ZHENGYI ;

namespace RWSB.GeneralSearch
{
	/// <summary>
	/// 
	/// 
	/// </summary>
	public partial class totalview: RWSB.PageBase
	{
        DatabaseConnect Dbc = new DatabaseConnect();
		
		protected void Page_Load(object sender, System.EventArgs e)
		{
		
			// 在此处放置用户代码以初始化页面
			SetDivePage();
			/*if (Session["userid"]==null)
			{
				Response.Write ("<script>alert('超时,请重新登录');top.location.href='../userpass.aspx';</script>");
				return ;
			}*/
			if (!Page.IsPostBack )
			{
         
				//string str=" select departmentid from users where userid="+Session["userid"].ToString ();
				//object o=Dbc.GetObjectBySql (str);
				//ViewState["departmentid"]=o.ToString ();
				//dstSearch_Bind();
                fwdept_Bind();
                //avail_Bind();
				dataBind();
			}
		}

       /* protected void dg_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            dg.EditItemIndex = e.Item.ItemIndex;
            BindGridToSource();
        }

        protected void dg_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            dg.EditItemIndex = -1;
            BindGridToSource();
        }*/

        protected void dg_DeleteCommand(object source, DataGridCommandEventArgs e)
        {
            if(Session["UserGrade"].ToString().Trim() != "管理员")
			{
				Response.Write ("<script>alert('对不起,您不具有删除权限');</script>");
				return ;
			}

            string strconn = ConfigurationSettings.AppSettings["conn"];
            SqlConnection myconn = new SqlConnection(strconn);
            myconn.Open();
            
            string DeleteCmd = "DELETE FROM rwxx WHERE rwid = @uid";
            SqlCommand MyCommand = new SqlCommand(DeleteCmd, myconn);

            MyCommand.Parameters.Add(new SqlParameter("@uid", SqlDbType.Int, 4));
            MyCommand.Parameters["@uid"].Value = dg.DataKeys[e.Item.ItemIndex];

            try
            {

                MyCommand.ExecuteNonQuery();
                Response.Write("<script>alert('已删除纪录!');</script>");
                dg.EditItemIndex = -1;
            }
            catch (SqlException Exp)
            {
                
                 Response.Write("<script>alert('错误: 无法删除数据纪录!');</script>");
            }

            MyCommand.Connection.Close();
            BindGridToSource();


        }

      /*  protected void dg_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            string sqlstring = "select DocumentID,Title,RecordID,documentsn,isuse from document order by DocumentID asc ";
            string strconn = ConfigurationSettings.AppSettings["conn"];
            SqlConnection myconn = new SqlConnection(strconn);
            myconn.Open();
            // 建立 UPDATE 命令字符串
            string UpdateCmd = "UPDATE document SET isuse = @usestate  WHERE DocumentID = @uid";

            SqlCommand MyCommand = new SqlCommand(UpdateCmd, myconn);

            // 设定 UPDATE 命令字串中各个参数的数据类型与长度
            MyCommand.Parameters.Add(new SqlParameter("@uid", SqlDbType.Int, 4));
            MyCommand.Parameters.Add(new SqlParameter("@usestate", SqlDbType.Bit));
            

            // 取得主索引键之值
            MyCommand.Parameters["@uid"].Value = dg.DataKeys[e.Item.ItemIndex];

            
            int NumCols = e.Item.Cells.Count;

            // 略过第一栏与第二栏。
            for (int i = 3; i <= NumCols - 1; i++)
            {
               
                if (i == 4)
                {
                    CheckBox CkBox;
                    CkBox = (CheckBox)e.Item.FindControl("CKuse");
                
               
                    // 第四个字段将 True 转换成 1,
                    // 并将 False 转换成 0,
                    if (CkBox.Checked == true)
                        MyCommand.Parameters["@usestate"].Value = 1;
                    else
                        MyCommand.Parameters["@usestate"].Value = 0;
                }
                
            }
            try
            {
                
                MyCommand.ExecuteNonQuery();
                Response.Write("<script>alert('已更新数据纪录!');</script>");
                dg.EditItemIndex = -1;
            }
            catch (SqlException Exp)
            {
                if (Exp.Number == 2627)
                    Response.Write("<script>alert('错误: 具有相同主索引键的数据纪录已经存在!');</script>");
                else
                   Response.Write("<script>alert('错误: 无法更新数据纪录,请确定各字段是否都已正确输入!');</script>");
            }

            MyCommand.Connection.Close();
            BindGridToSource();
        }
        */

        protected void BindGridToSource()
        {
            
        
            string con1 = "";
            string con2 = "";
            string con3 = "";
            string con4 = "";
            string con5 = "";
            string con6 = "";

            string btsearch = zynrDDL.SelectedItem.Text.Trim();
            //string whsearch = fwcode.Text.Trim().Replace("'", "''");
            string rqsearch = fwrq.Text.Trim().Replace("'", "''");

            string sqlstring = "select rwid,a.sbsj,xb,rwxz,zcqj,zyxm,wcsl,zycj,a.zycjorder,rwsn from rwxx  a ";

            if (dstSearch.SelectedItem.Text.Trim() != "")
            {
                con1 = " xb = '" + dstSearch.SelectedItem.Text.Trim() + "'  and ";
                
            }
            else
            {
                con1 = "";
            } 
               
     
            if (btsearch != "")
            { 
                con2 = " zyxm = '" + zynrDDL.SelectedItem.Text.Trim() + "'  and ";
            }
            else 
            {
                con2 = "";
            }


            if (rwxzDDL.SelectedItem.Text.Trim() != "")
             {
                 con3 = " rwxz = '" + rwxzDDL.SelectedItem.Text.Trim() + "'  and ";
             }
             else 
             {
                 con3 = "";
             }

            if (fwdept.SelectedItem.Text.Trim() !="")
            {
                con4 = " a.zycj = '" + fwdept.SelectedItem.Text.Trim() + "'  and ";
            }
            else 
            {
                con4 = "";
            }


            if (rqsearch != "")
            {
                con5 = " rwsn  like '%" + rqsearch + "%'  and ";
            }
            else 
            {
                con5 = "";
            }

            
            
                con6 = " status = 1 ";



                if (con1 == "" && con2 == "" && con3 == "" && con4 == "" && con5 == "" )
            {
                //sqlstring += " order by zycjorder asc";
                sqlstring += " ,(select zycjorder,max(rwid) row,sbsj from rwxx group by zycjorder,sbsj) b where (a.zycjorder= b.zycjorder and a.sbsj = b.sbsj) order by a.zycjorder asc,b.sbsj desc";
            }
            else 
            {
                sqlstring += "  where " + con1 + con2 + con3 + con4 + con5 + con6 ;
            }
            
             string strconn = ConfigurationSettings.AppSettings["conn"];
            SqlConnection myconn = new SqlConnection(strconn);
          try{
            
            myconn.Open();

            SqlDataAdapter mycmd = new SqlDataAdapter(sqlstring,myconn);
            DataSet ds = new DataSet();
            mycmd.Fill(ds, "rwxx");
            dg.DataSource = ds.Tables["rwxx"].DefaultView;
            dg.DataBind();
            }
           catch(Exception exception)
			{
                //Response.Write("<script>alert('查询任务时出错!');</script>");
                Response.Write(exception.Message);
                Response.End();
                myconn.Close();
                return;
			}
        }

		/*private void dstSearch_Bind()
		{
            string sqlstring = "select zypritype,zytypename from ZyPriType order by zypritype asc ";
            string strconn = ConfigurationSettings.AppSettings["conn"];
            SqlConnection myconn = new SqlConnection(strconn);
            myconn.Open();
            SqlCommand mycmd = new SqlCommand(sqlstring, myconn);
            SqlDataReader dr = mycmd.ExecuteReader();

            dstSearch.DataSource = dr;
            dstSearch.DataTextField = "zytypename";
            dstSearch.DataValueField = "zypritype";
            dstSearch.DataBind();
            myconn.Close();
       
		}*/

        private void fwdept_Bind()
        {
            string sqlstring = "select id,bmname,showorder from ExigenceDegree order by showorder asc ";
            string strconn = ConfigurationSettings.AppSettings["conn"];
            SqlConnection myconn = new SqlConnection(strconn);
            myconn.Open();
            SqlCommand mycmd = new SqlCommand(sqlstring, myconn);
            SqlDataReader dr = mycmd.ExecuteReader();

            fwdept.DataSource = dr;
            fwdept.DataTextField = "bmname";
            fwdept.DataValueField = "showorder";
            fwdept.DataBind();
            myconn.Close();

        }

       

       
		private void SetDivePage()
		{
			dg.AllowPaging =true; 
			dg.PageSize =10; 
			
			ZHENGYI.BindDataDelegate f =new ZHENGYI.BindDataDelegate (dataBind);//修改这个dataBind,让f 指向你的方法。 
			divepage.SetTarget(dg,f,15);
		}

		private void dataBind()
		{
			
            BindGridToSource();
		  
			
		}
		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.ImageButton1.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButton1_Click);
			this.dg.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dg_ItemDataBound);

		}
		#endregion

		private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			dataBind();
		}

		private void dg_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
		{
			if (e.Item .ItemType ==ListItemType.Item || e.Item .ItemType ==ListItemType.AlternatingItem )
			{
					
				if (e.Item .Cells[3].Text .Length >30 )
				{
					e.Item .Cells[3].Text ="<a href=\"#\" onclick=\"openwin('"+e.Item .Cells[0].Text + "')\" title=\""+ e.Item .Cells[3].Text +"\">"+e.Item.Cells [3].Text.Substring (0,30) +"...</a>";
                    
				}
				else
				{
					
                    e.Item.Cells[3].Text = "<a href=\"#\" onclick=\"openwin('" + e.Item.Cells[0].Text + "')\"  title=\"" + e.Item.Cells[3].Text + "\">" + e.Item.Cells[3].Text + "</a>"; 
				}

                if (e.Item.Cells[5].Text.Length > 40)
                {
                    e.Item.Cells[5].Text =  e.Item.Cells[5].Text.Substring(0, 40) + "...";

                }
                else
                {

                    e.Item.Cells[5].Text =  e.Item.Cells[5].Text ;
                }
			}
		}

        
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -