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

📄 customerordermodify.aspx.cs

📁 PetShop实现的是一个网上购物的系统功能
💻 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.Diagnostics;
using PetShop.Components;

namespace PetShop.Web
{
	/// <summary>
	/// CustomerOrderEdit 的摘要说明。
	/// </summary>
	public partial class CustomerOrderEdit : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label lblDeliveryMethod;
		public bool UseDefaultValues=false;
	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			PetShop.Components.Order order=new PetShop.Components.Order();
			int orderid=Convert.ToInt32(Request.QueryString["strNM"]);
			string strMethodName=order.GetDeliveryMethodName(orderid);
			if (!Page.IsPostBack)
			{
				// 在此处放置用户代码以初始化页面
				string strdatetime=Request.QueryString["strDT"];
				string strnumber=Request.QueryString["strNM"];
				string strstotus=Request.QueryString["strTS"];
				this.lbldtime.Text=strdatetime;
				this.lblorderid.Text=strnumber;
				this.lblstatus.Text=strstotus;

               
                Hashtable ad = (Hashtable)Session["UserID"];
				Debug.Assert(ad!=null);
				this.lblacout.Text=ad["userID"].ToString();	

//				PetShop.Components.Order order=new PetShop.Components.Order();
//				int orderid=Convert.ToInt32(Request.QueryString["strNM"]);
//				string strMethodName=order.GetDeliveryMethodName(orderid);
				if (strMethodName=="Take away by yourself")
				{
					this.DropMethod.Items[0].Selected=true;
					this.lblcharge.Text=string.Format("{0:c}","0.0");
					this.lblshipping.Visible=false;
					this.shippingAddress.Visible=false;
					this.lblbilling.Visible=false;
					this.ControlAddress.Visible=false;
				}

				if(strMethodName=="Direct delivery")
				{
					this.DropMethod.Items[1].Selected=true;
					this.lblcharge.Text=string.Format("{0:c}","5.0");
				}

				if(strMethodName=="Express direct delivery")
				{
					this.DropMethod.Items[2].Selected=true;
				    this.lblcharge.Text=string.Format("{0:c}","10.0");
				}

                
				string Paymentid=order.GetPaymentType(orderid).ToString();
				if(Paymentid=="1")
				{
					this.Droptype.Items[0].Selected=true;
					this.lblchecknum.Visible=false;
					this.txtCheckNumber.Visible=false;
					this.Table1.Visible=true;
					this.txtCardNumber.Text="9999 9999 9999 9999";
					this.lblCreditCard.Visible=true;

				}
				else if(Paymentid=="2")
				{
					this.Droptype.Items[1].Selected=true;
					this.lblchecknum.Visible=true;
					this.txtCheckNumber.Visible=true;
					this.txtCheckNumber.Text="0123456789";
					this.Table1.Visible=false;
					this.lblCreditCard.Visible=false;
				}
				else if(Paymentid=="3")
				{
					this.Droptype.Items[2].Selected=true;
					//this.lblCreditCard.Visible=false;
					this.txtCheckNumber.Visible=false;
					this.lblchecknum.Visible=false;
					this.Table1.Visible=false;
					this.lblCreditCard.Visible=false;
				}

				string strPetStore=order.GetPetStore(orderid);
				if (strMethodName =="Take away by yourself")
				{
					this.lblStoreName.Visible = true;
					this.ddlStoreShops.Visible = true;
					if (strPetStore=="PetStore No.1")
					{
						this.ddlStoreShops.Items[0].Selected=true;
					}

					if (strPetStore=="PetStore No.2")
					{
						this.ddlStoreShops.Items[1].Selected=true;
					}
				}
				else
				{
					this.lblStoreName.Visible = false;
					this.ddlStoreShops.Visible = false;
				}

			//	PetShop.Components.Order order=new PetShop.Components.Order();
			//	order.DelALineItem(iOrderId,strItemID);
			//	this.DataGrid .Columns [4].FooterText =totalPrice;
				if(strMethodName=="Take away by yourself")
				{
					this.DataGrid.Columns[1].FooterText=string.Format("{0:c}","0.0");
				}
				if(strMethodName=="Direct delivery")
				{
					this.DataGrid.Columns[1].FooterText=string.Format("{0:c}","5.0");
				}
				else
				{
					this.DataGrid.Columns[1].FooterText=string.Format("{0:c}","10.0");
				}
				
				
				this.DataGrid.DataSource=order.GetLineItem(orderid);
				this.DataGrid.DataBind();
				
				decimal totalPrice=0M;
				for (int i=this.DataGrid.Items.Count-1;i>=0;i--)
				{
					decimal Price;
					DataGridItem dataItem1=this.DataGrid.Items[i];
					Price=decimal.Parse(dataItem1.Cells[4].Text);
					totalPrice+=Price;
				}
				this.DataGrid.Columns[3].FooterText=totalPrice.ToString();
			}
			
			
			
		
           
		}

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

		}
		#endregion

		

		protected void Droptype_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if(this.Droptype.SelectedItem.Value=="0")
			{
				this.lblchecknum.Visible=false;
				this.txtCheckNumber.Visible=false;
				this.Table1.Visible=true;
				this.lblCreditCard.Visible=true;
			}
			else if(this.Droptype.SelectedItem.Value=="1")
			{
				this.lblchecknum.Visible=true;
				this.txtCheckNumber.Visible=true;
				this.Table1.Visible=false;
				this.lblCreditCard.Visible=false;
			}
			else
			{
				this.lblchecknum.Visible=false;
				this.txtCheckNumber.Visible=false;
				this.Table1.Visible=false;
				this.lblCreditCard.Visible=false;
			}
		}

		protected void DropMethod_SelectedIndexChanged(object sender, System.EventArgs e)
		{
		    if(this.DropMethod.SelectedItem.Value=="0")
			{
				this.lblcharge.Text=string.Format("{0:c}","0.0");
				this.lblshipping.Visible=false;
				this.shippingAddress.Visible=false;
				this.lblbilling.Visible=false;
				this.ControlAddress.Visible=false;
			}
			else if(this.DropMethod.SelectedItem.Value=="1")
			{
				this.lblcharge.Text=string.Format("{0:c}","5.0");
				this.lblshipping.Visible=true;
				this.shippingAddress.Visible=true;
				this.lblbilling.Visible=true;
				this.ControlAddress.Visible=true;
			}
			else
			{
				this.lblcharge.Text=string.Format("{0:c}","10.0");
				this.lblbilling.Visible=true;
				this.lblshipping.Visible=true;
				this.ControlAddress.Visible=true;
			}
		}

		protected void Dropstore_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			
		}

		private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			int qty;
			for(int i=this.DataGrid.Items.Count-1;i>=0;i--)
			{
				DataGridItem dataItem=this.DataGrid.Items[i];
				TextBox qtyTextBox=(TextBox)dataItem.FindControl("txtQuantity");
				try
				{
					qty=Convert.ToInt32(qtyTextBox.Text);
					string strOrderID=Request.QueryString["strNM"];
					int iOrderId=int.Parse(strOrderID);
					string strItemID=dataItem.Cells[0].Text;
                    
					PetShop.Components.Order order=new PetShop.Components.Order();
					order.UpdateQtyInLineItem(qty,iOrderId,strItemID);
					this.DataGrid.DataSource=order.GetLineItem(iOrderId);
				}
				catch(Exception ex)
				{
					PetShop.Components.Error.Log(ex.ToString());
				}
			}
			this.DataGrid.DataBind();
		}

		protected void DataGrid_SelectedIndexChanged(object sender, System.EventArgs e)
		{
		
		}

		private void ImageButton2_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			int iMethodId=Convert.ToInt32(this.DropMethod.SelectedItem.Value.ToString()); 
			decimal decCharge=Convert.ToDecimal(this.lblcharge.Text);
			int iPaymentId=Convert.ToInt32(this.Droptype.SelectedItem.Value.ToString());
			string strStoreName=this.ddlStoreShops.SelectedItem.Value.ToString();
			int iOrderID=Convert.ToInt32(this.lblorderid.Text);
			
			Inc.ControlAddress shippingAddress;                                        
			shippingAddress = (Inc.ControlAddress)FindControl("shippingAddress");
			string strShipFirstName=null;
			string strShipLastName=null;
			string strShipAddr1=null;
			string strShipAddr2=null;
			string strShipCity=null;
			string strShipState=null;
			string strShipZip=null;
			string strShipCountry=null;
			if(iMethodId == 1)
			{
				strShipFirstName=" ";
				strShipLastName=" ";
				strShipAddr1=" ";
				strShipAddr2=" ";
				strShipCity=" ";
				strShipState=" ";
				strShipZip=" ";
				strShipCountry=" ";
			}
			else
			{
				 strShipFirstName=shippingAddress.GetFirstName;
				 strShipLastName=shippingAddress.GetLastName;
				 strShipAddr1=shippingAddress.GetAddr1;
				 strShipAddr2=shippingAddress.GetAddr2;
				 strShipCity=shippingAddress.GetCity;
				 strShipState=shippingAddress.GetState;
				 strShipZip=shippingAddress.GetZip;
				 strShipCountry=shippingAddress.GetCountry;
			}

			Inc.ControlAddress ControlAddress;                                        
			ControlAddress = (Inc.ControlAddress)FindControl("ControlAddress");
			string strBillFirstName=ControlAddress.GetFirstName;
			string strBillShipLastName=ControlAddress.GetLastName;
			string strBillShipAddr1=ControlAddress.GetAddr1;
			string strBillShipAddr2=ControlAddress.GetAddr2;
			string strBillShipCity=ControlAddress.GetCity;
			string strBillShipState=ControlAddress.GetState;
			string strBillShipZip=ControlAddress.GetZip;
			string strBillShipCountry=ControlAddress.GetCountry;

			string strCreditType=null;
			string strCreditNum=null;
			string strDate=null;
			if(iPaymentId == 2|| iPaymentId == 3)
			{
				strCreditType = " ";
				strCreditNum = " ";
				strDate = " ";
			}
			else
			{
				strCreditType=this.listCardType.SelectedItem.ToString();        
				strCreditNum=this.txtCardNumber.Text;
				strDate=this.listMonth.SelectedItem.ToString()+this.listYear.SelectedItem.ToString();
				//strCheckNumber=this.txtCheckNumber.Text;
			}
			//string strCheckNum=this.txtCheckNumber.Text;

			string strCheckNum = null;
			if(iPaymentId == 1|| iPaymentId == 3)
			{
				strCheckNum = " ";
			}
			else
			{
				strCheckNum=this.txtCheckNumber.Text;
			}


			decimal totalPrice=0M;
			for (int i=this.DataGrid.Items.Count-1;i>=0;i--)
			{
				decimal Price;
				DataGridItem dataItem=this.DataGrid.Items[i];
				Price=decimal.Parse(dataItem.Cells[4].Text);
				totalPrice+=Price;
			}
			
//			PetShop.Components.ShoppingCart cart = (PetShop.Components.ShoppingCart)Session["ShoppingCartSession"];
//			int qty;
//			for (int i=this.DataGrid.Items.Count-1; i>=0; i--) 
//			{
//				DataGridItem _item = this.DataGrid.Items[i];
//				TextBox qtyTextBox = (TextBox)_item.FindControl("txtQuantity");
//				try 
//				{
//					qty = Convert.ToInt32(qtyTextBox.Text);		
//					cart[(this.DataGrid.CurrentPageIndex * this.DataGrid.PageSize) + i].Qty = qty;
//					this.DataGrid.Columns[1].FooterText=qty.ToString("c");
//				}
//				catch 
//				{
//					// don't do anything, the qty will not be
//					// updated and will retain the old value
//				}
//			}


			PetShop.Components.Order order=new PetShop.Components.Order();
			order.UpdateOrder(iOrderID,strShipAddr1,strShipAddr2,strShipCity,strShipState,strShipZip,strShipCountry,
				strBillShipAddr1,strBillShipAddr2,strBillShipCity,strBillShipState,strBillShipZip,
				strBillShipCountry,"",totalPrice,strBillFirstName,strBillShipLastName,strShipFirstName,
				strShipLastName,strCreditNum,strDate,strCreditType,"",iPaymentId,iMethodId,decCharge,strCheckNum,
				strStoreName);      
		}

		private void DataGrid_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			if(e.CommandName=="Delete")
			{
				string strOrderID=Request.QueryString["strNM"];
				int iOrderId=Convert.ToInt32(strOrderID);
				string strItemID=e.Item.Cells[0].Text;

				PetShop.Components.Order order=new PetShop.Components.Order();
				order.DelALineItem(iOrderId,strItemID);
				this.DataGrid.DataSource=order.GetLineItem(iOrderId);
				this.DataGrid.DataBind();
			}
		}
		
	}
}

⌨️ 快捷键说明

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