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

📄 orderprint.aspx.cs

📁 在c#中调用rpt
💻 CS
字号:
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.IO;
using System.Diagnostics ;
using CounterManage.Components;
using CrystalDecisions.CrystalReports.Engine  ;
using CrystalDecisions.Shared ;

namespace netorder
{
	/// <summary>
	/// OrderPrint 的摘要说明。
	/// </summary>
	public class OrderPrint : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.Label Label3;
		protected System.Web.UI.WebControls.TextBox TextBox1;
		protected System.Web.UI.WebControls.TextBox TextBox2;
		protected System.Web.UI.WebControls.Label Label4;
		protected System.Web.UI.WebControls.TextBox TextBox3;
		protected System.Web.UI.WebControls.RadioButton RadioButton1;
		protected System.Web.UI.WebControls.RadioButton RadioButton2;
		protected System.Web.UI.WebControls.Label Label5;
		protected System.Web.UI.WebControls.TextBox TextBox4;
		protected System.Web.UI.WebControls.TextBox TextBox5;
		protected System.Web.UI.WebControls.Label Label6;
		protected System.Web.UI.WebControls.TextBox TextBox6;
		protected System.Web.UI.WebControls.Label Label7;
		protected System.Web.UI.WebControls.ListBox ListBox2;
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.Button Button2;
		protected System.Web.UI.WebControls.DataGrid DataGrid1;
		protected System.Web.UI.WebControls.Label Label1;
		private DataTable myTable,myTable1;
		private DataRow myRow,myRow1;
		protected System.Web.UI.WebControls.Label Label8;
		protected System.Web.UI.WebControls.RadioButton RadioButton3;
		protected System.Web.UI.WebControls.RadioButton RadioButton4;
		protected System.Web.UI.WebControls.RadioButton RadioButton5;
		protected System.Web.UI.WebControls.DataGrid DataGrid2;
		protected System.Web.UI.WebControls.Button Button3;
		protected System.Web.UI.WebControls.Label Label9;
		protected System.Web.UI.WebControls.TextBox Textbox7;
		protected System.Web.UI.WebControls.ListBox ListBox3;
		protected string strRes ;
		
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			string temp;
			string EndDate,BeginDate;
			temp = Session["UserId"].ToString().Trim();
			if(temp.Length == 0 )
			{
				Response.Redirect(@"Login.aspx");
				return;
			}
			if (!IsPostBack) 
			{
				SqlConnection thisConnection = new SqlConnection(Session["connStr"].ToString() );
				thisConnection.Open();

				String MdType = "",QueryTxt = "";
				MdType = Session["OrderType"].ToString().Trim();

				//付值店铺
				QueryTxt = " select NA from [SYSTEM] where IDCO = '001' and CO= '" + Session["WebShop"]  +"'";
				SqlDataAdapter thisAdapter =  new SqlDataAdapter(
					QueryTxt,thisConnection);

				DataSet ds  = new DataSet();
				thisAdapter.Fill(ds,"webshop");
               
				this.myTable = ds.Tables[0];
				for (int i = 0; i <myTable.Rows.Count; i++)
				{
					String shopna = "" ;
					myRow = myTable.Rows[i];
					shopna = myRow[0].ToString().Trim();
					this.TextBox1.Text = shopna;
					//this.DropDownList1.Items[i].Text = shopna;

				}
                
				//付值管理部
				String TXTwebshop;

				TXTwebshop = Session["Shop"].ToString().Trim();
				TXTwebshop = TXTwebshop.Substring(1,1);
				QueryTxt = " select NA from [SYSTEM] where IDCO = '002' and CO= '0" + TXTwebshop  +"'";
				SqlDataAdapter thisAdapter1 =  new SqlDataAdapter(
					QueryTxt,thisConnection);

				DataSet ds1  = new DataSet();
				thisAdapter1.Fill(ds1,"shop");
            
				this.myTable1 = ds1.Tables[0];
				for (int j = 0; j <myTable1.Rows.Count; j++)
				{
					String shopna = "" ;
					myRow1 = myTable1.Rows[j];
					shopna = myRow1[0].ToString().Trim().Substring(0,2) + "课";
					this.TextBox2.Text = shopna;
				}

				QueryTxt = "SELECT Convert(char(10),Getdate(),126)";
				thisAdapter =  new SqlDataAdapter(
					QueryTxt,thisConnection);
                
				ds = new DataSet();
				thisAdapter.Fill(ds,"BeginDate");
				this.myTable = ds.Tables[0];
				this.myRow  = this.myTable.Rows[0];
				BeginDate = this.myRow[0].ToString().Substring(0,8) + "01" ;
			
				EndDate = this.myRow[0].ToString().Trim() ;

				this.TextBox5.Text = BeginDate;
				this.TextBox6.Text = EndDate;
				
				QueryTxt = Refresh_list();

				 QueryTxt = GetSql(QueryTxt) + " Order by A.OrderNO";
				thisAdapter =  new SqlDataAdapter(
					QueryTxt,thisConnection);
				    
				ds = new DataSet();
				thisAdapter.Fill(ds,"MdCashOrderList");
	
				this.DataGrid1.DataSource = ds.Tables["MdCashOrderList"].DefaultView ;
				this.DataGrid1.DataBind();
				thisConnection.Close();
			}
			//付值订货单编号
		}

		private string Refresh_list()
		{
			string MdSql;
			
			MdSql = "SELECT A.OrderNO,A.StoCo,A.StoNA,A.ItCo,A.ItNA,A.STD,A.Sell,A.OrderQut,Convert(Dec(18,2),(A.Sell * A.OrderQut * A.OrdUN)) Amount, " +
					"       A.OrderDate,A.ReceiveDate,A.Cost,A.CreateDate, " +
					"       A.UpdateDate,A.PageNO,A.[LineNO],A.UserName,A.ITDECO,A.alertflag,A.OrdUN,A.PaymentNo, (case when A.Status = '0' then '基础' else '追加' end) StatusName," +
				    "       (case A.ConfirmFlag when '0' then '开单' " +
                    "                          when '1' then '课长确认' " +
				    "                          when '2' then '店铺部长确认' " +
				    "                          when '3' then '本部部长确认' " +
				    "                          when '4' then '勾对'  " +
				    "                          when '9' then '作废' " +
					"                          else '结束'  " +
				    "       end) flag " +
					"  FROM CashOrder A, " +
					"       userMaster B " +
					" WHERE A.UserId = B.UserID " +
					"   AND A.OrderQut > 0 ";


			return MdSql;
		}


		private string Refresh_sum()
		{
			string MdSql;

			MdSql = " SELECT A.ItCo,A.ItNA,A.STD,A.OrdUN,SUM(A.OrderQut) OrderQut,Convert(Dec(18,2),SUM(A.Sell * A.OrderQut * A.OrdUN)) SellAmount, " + 
					"        SUM(A.Cost * A.OrderQut * A.OrdUN) CostAmount " + 
					"   FROM CashOrder A, " + 
					"        userMaster B" + 
					"  WHERE A.UserId = B.UserID  " ;

			return MdSql ;
		}
		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.Button3.Click += new System.EventHandler(this.Button3_Click);
			this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged);
			this.Button2.Click += new System.EventHandler(this.Button2_Click);
			this.Button1.Click += new System.EventHandler(this.Button1_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void NAR(Object o)
		{
			
			try{System.Runtime.InteropServices.Marshal.ReleaseComObject(o);}
			catch{}
			finally{o = null;}
		}
		private void Button1_Click(object sender, System.EventArgs e)
		{
			string MdSql,GroupSql,tablename,Rptname;
			ReportDocument rpt ; 

			ModuleFun MFun = new ModuleFun(); 
			//初始化数据窗口,同时获取查询数据的基本SQL
			if(this.RadioButton1.Checked == true)  
			{
				this.DataGrid1.Visible = true;
				this.DataGrid2.Visible = false;
				MdSql = Refresh_list() ;
				GroupSql = "" ;
				tablename = "OrderList"; 
				Rptname = "OrderListRpt.rpt";
			}
			else
			{
				this.DataGrid1.Visible = false;
				this.DataGrid2.Visible = true;
				MdSql = Refresh_sum();
				GroupSql = "  GROUP BY  A.ItCo,A.ItNA,A.STD,A.OrdUN  HAVING SUM(A.OrderQut) > 0 " ;
				tablename = "OrderSum"; 
				Rptname = "OrderSumRpt.rpt";
			}
     
			//为拼SQL做准备
			MdSql = GetSql(MdSql);

			if (GroupSql != "")
			{
				MdSql = MdSql + GroupSql;
			}
			else
			{
				MdSql = MdSql  + " Order by A.OrderNO" ;
			}
			
			SqlConnection thisConn = new SqlConnection(Session["connStr"].ToString());
			thisConn.Open();

			SqlDataAdapter thisAdapter =  new SqlDataAdapter(MdSql,thisConn);
			DataSet ds = new DataSet();
			thisAdapter.Fill(ds,tablename);

			rpt =MFun.GetReportDocument(MFun.GetReportPath(this, Rptname), ds);


			this.Session["frmPreview_rpt"] = rpt;
			//dayin 
			strRes = MFun.GetOpenCheckStr();

		}

		private void Button2_Click(object sender, System.EventArgs e)
		{
			string MdSql,GroupSql;
			int Message;
			//初始化数据窗口,同时获取查询数据的基本SQL
			if(this.RadioButton1.Checked == true)  
			{
				this.DataGrid1.Visible = true;
				this.DataGrid2.Visible = false;
				MdSql = Refresh_list() ;
				GroupSql = "" ;
				Message = 1; 
			}
			else
			{
				this.DataGrid1.Visible = false;
				this.DataGrid2.Visible = true;
				MdSql = Refresh_sum();
				GroupSql = "  GROUP BY  A.ItCo,A.ItNA,A.STD,A.OrdUN  HAVING SUM(A.OrderQut) > 0 " ;
				Message = 2;
			}
     
			//为拼SQL做准备
			MdSql = GetSql(MdSql);

			if (GroupSql != "")
			{
				MdSql = MdSql + GroupSql;
			}
			else
			{
			   MdSql = MdSql  + " Order by A.OrderNO" ;
			}

			SqlConnection thisConnection = new SqlConnection(Session["connStr"].ToString() );
			thisConnection.Open();
			
			SqlDataAdapter thisAdapter2 =  new SqlDataAdapter(
				MdSql,thisConnection);
                
			DataSet ds2 = new DataSet();
			thisAdapter2.Fill(ds2,"ReportDsi");

			if(Message == 1 )
			{
				this.DataGrid1.DataSource = ds2.Tables["ReportDsi"].DefaultView ;
				this.DataGrid1.DataBind();
			}
			else
			{
				this.DataGrid2.DataSource = ds2.Tables["ReportDsi"].DefaultView ;
				this.DataGrid2.DataBind();
			}
			thisConnection.Close();

		}
		private string GetSql(string textSql)
		{
			string txtTemp,FiledTemp;
			//首先判断当前登入人员的身份,店铺人员只能看本店铺的订货信息,本部人员只能看到代开的订货信息。
			txtTemp = Session["Shop"].ToString().Trim();
			txtTemp = txtTemp.Substring(0,1);
			//textSql = textSql + " AND  Right(A.ITDECO,1) = '"+ Session["WebShop"].ToString().Trim().Substring(1,1) +"'";
			if(txtTemp == "1")
			{
				//说明是本部人员,则只要服务部相同就可以
				textSql = textSql + " AND A.ITDECO = '"+ Session["Shop"].ToString().Trim() +"' ";
			}
			else
			{
				//说明是店铺人员,不但服务部开头必须为0,还需要是同店铺的信息才能显示
				textSql = textSql + " AND (LEFT(A.ITDECO,1) = '0' AND A.StoCo = '"+ Session["WebShop"].ToString().Trim() +"')";
			}
			
			//输入的查询条件
			//订货单信息
			txtTemp = this.TextBox3.Text ;
			if (txtTemp != "")
			{
				//输入了订货单信息的查询条件
				textSql = textSql + " AND A.IndentNo = '"+ txtTemp +"'";
			}
            //申请单号信息
			txtTemp = this.Textbox7.Text ;
			if (txtTemp != "")
			{
				textSql = textSql + " AND A.PaymentNo = '"+ txtTemp +"'";
			}
			//厂商输入的为代码
			txtTemp = this.TextBox4.Text ;
			if(txtTemp != "")
			{
				//输入了厂商查询信息
				textSql = textSql + " AND ((case when isnull(A.CmpNA,'') = '' then A.CmpABBV else A.CmpNA end) = '"+ txtTemp +"' or (case when isnull(A.CmpNA,'') = '' then A.CmpCo else A.CmpNA end) = '"+ txtTemp +"')";
			}

			//时间条件
			//首先判断是那个字段要进行查询
			FiledTemp = "";
			if (this.RadioButton3.Checked ==true)
			{
				//制单日期
				FiledTemp = " Convert(char(10),A.CreateDate,126) ";
			}

			if(this.RadioButton4.Checked == true )
			{
				//订货日期
				FiledTemp = " Convert(char(10),A.OrderDate,126) ";
			}
			
			if(this.RadioButton5.Checked == true )
			{
				//确认日期
				FiledTemp = " Convert(char(10),A.ConfirmDate,126) ";
			}

			if(FiledTemp == "" )
			{
				return "";
			}

			txtTemp = this.TextBox5.Text ;
			if(txtTemp != "")
			{
				//起始时间
				textSql = textSql + " AND " +  FiledTemp + " >= '" + txtTemp + "' ";
			}
			
			txtTemp = this.TextBox6.Text ;
			if(txtTemp != "")
			{
				//结束时间
				textSql = textSql + " AND " + FiledTemp + " <= '" + txtTemp + "' ";
			}
			//状态条件
			txtTemp = this.ListBox2.SelectedValue  ;
			if(txtTemp != "-1" && txtTemp != "" ) textSql = textSql + " and A.ConfirmFlag = '"+ txtTemp + "'"  ;
			//金额差异条件
			txtTemp = this.ListBox3.SelectedValue ;

			if(txtTemp != "0" && txtTemp != "")
			{
				if(txtTemp == "1")
				{
					textSql = textSql + " and (IsNull(A.InvoiceNo,'') in (select InvoiceNo from InvoiceTable where IsNull(Invoice_Amount,0) <> IsNull(Finish_Amount,0))) "  ;
				}
				else
				{
					textSql = textSql + " and (IsNull(A.InvoiceNo,'') in (select InvoiceNo from InvoiceTable where IsNull(Invoice_Amount,0) = IsNull(Finish_Amount,0)))"  ;
				}
			}
			return textSql;
		}

		private void Button3_Click(object sender, System.EventArgs e)
		{
			Response.Redirect(@"main.aspx");
		}

		private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
		
		}



	}
}

⌨️ 快捷键说明

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