Chức năng chi tiết đơn hàng - code window form asp.net

Chức năng chi tiết đơn hàng - code window form asp.net

Chức năng chi tiết đơn hàng - code window form asp.net

Thiết kế trang quản lý dạng lưới

<div id="tool" runat="server"  style="width:1000px; height:55px; margin:auto; text-align:left;">
<p style="float:left; width:100px;"> &nbsp;
 <asp:HyperLink runat="server"CssClass="btn"  NavigateUrl="~/Admin/Oders_Detail.aspx?act=add">Tạo mới</asp:HyperLink>
</p><div style="float:right; width:800px;  padding-top:20px;"> Từ khóa cần tìm<asp:TextBox ID="txt_search" runat="server" Width="365px"></asp:TextBox>
            <asp:Button ID="btsearch" CssClass="btn" runat="server" Text="Tìm kiếm" OnClick="btsearch_Click" Width="85px" />
         &nbsp;&nbsp;&nbsp; </div></div>
 <asp:GridView ID="GridOders_Detail" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="ID" HorizontalAlign="Center" PageSize="5" Width="950px" OnPageIndexChanging="GridOders_Detail_PageIndexChanging" CellPadding="4" EnableViewState="False" ForeColor="#333333" GridLines="Horizontal" ShowFooter="True"> <AlternatingRowStyle BackColor="White" ForeColor="#2F867A" /> <Columns><asp:TemplateField HeaderStyle-Width="20"> <HeaderTemplate>  <asp:CheckBox ID="cbxSelectAll" runat="server" AutoPostBack="True" ClientIDMode="Static" OnCheckedChanged="cbxSelectAll_CheckedChanged" /><div class="table-header-top"></div></HeaderTemplate><ItemTemplate> <asp:CheckBox ID="cbxSelectOne" runat="server" AutoPostBack="True" ClientIDMode="AutoID" OnCheckedChanged="cbxSelectOne_CheckedChanged" ToolTip='<%# Eval("ID") %>' /></ItemTemplate><HeaderStyle Width="20px" /><FooterTemplate><asp:Button ID="btxoa"  CssClass="btn" OnClick="btxoa_Click" OnClientClick = "return confirm('Bạn có chắc muốn xóa ?');" runat="server" Text="Xóa chọn" /></FooterTemplate> </asp:TemplateField><asp:BoundField DataField="Oderid" HeaderText="Oderid" SortExpression="Oderid" >
                    <FooterStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                   <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                   <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                   </asp:BoundField><asp:BoundField DataField="ProductId" HeaderText="ProductId" SortExpression="ProductId" >
                    <FooterStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                   <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                   <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                   </asp:BoundField><asp:TemplateField HeaderText="RequiresShipping" SortExpression="RequiresShipping">
 <ItemTemplate>
 <asp:Image ID="Image_RequiresShipping" runat="server" ImageUrl='<%# (Eval("RequiresShipping").ToString()) =="True" ? "~/Admin/Images/icon_Hien.png" : "~/Admin/Images/icon_An.png" %>' title="Xanh có | Vàng không" /></ItemTemplate>
                        <FooterStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                  </asp:TemplateField><asp:BoundField DataField="KeyID" HeaderText="KeyID" SortExpression="KeyID" >
                    <FooterStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                   <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                   <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                   </asp:BoundField><asp:TemplateField HeaderText="Sửa"> <ItemTemplate><asp:HyperLink ID="hl_Sua" runat="server" ImageUrl="~/Admin/Images/icon_Sua.png" NavigateUrl='<%# "~/Admin/Oders_Detail.aspx?act=edit&ID="+Eval("ID") %>'></asp:HyperLink> </ItemTemplate>
                    <FooterStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Xóa">
                    <ItemTemplate>
                         <asp:HyperLink ID="hl_Sua1" runat="server"  OnClientClick = "return confirm('Bạn có chắc muốn xóa?');"   ImageUrl="~/Admin/Images/icon_Xoa.png" NavigateUrl='<%# "~/Admin/Oders_Detail.aspx?act=delete&ID="+Eval("ID") %>'></asp:HyperLink> </ItemTemplate></asp:TemplateField>  </Columns><EditRowStyle BackColor="#7C6F57" /><EmptyDataTemplate>Không có dữ liệu</EmptyDataTemplate> <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" BorderStyle="Dotted" Width="111px" /> <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" /><PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" /><RowStyle BackColor="#E3EAEB" /><SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" /> <SortedAscendingCellStyle BackColor="#F8FAFA" /><SortedAscendingHeaderStyle BackColor="#246B61" /><SortedDescendingCellStyle BackColor="#D4DFE1" /> <SortedDescendingHeaderStyle BackColor="#15524A" /></asp:GridView>

File .cs

namespace megastore{public partial class Oders_Detail {
protected global::System.Web.UI.WebControls.GridView GridOders_Detail;}
}

Main_oder.aspx

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace megastore
{
    public partial class Oders_Detail : System.Web.UI.Page
    {
        
	protected void Page_Load(object sender, EventArgs e)
	{
 		try 
		{
			load();
			if (!IsPostBack) 
			{
				
                    if (Request.QueryString["act"] == null)
                    {
                      // Mặc định là ẩn form nhập liệu
                        Panel_Design.Visible = false;
                        lbl_title.Text="Quản lý Oders_Detail";
                     // Hiện danh sách dạng lưới
                        Panel_view.Visible = true;
                    }
                    else if (Request.QueryString["act"] == "add")

                    {
                      // nếu lệnh = thêm thì hiên form nhập liệu
                        Panel_Design.Visible = true;
                        lbl_title.Text="Thêm mới Oders_Detail";
                        Panel_view.Visible = false;
                        tool.Visible = false;
                    }
                    else if (Request.QueryString["act"] == "edit")

                    {
                        Panel_Design.Visible = true;
                        Panel_view.Visible = false;
                        lbl_title.Text="Chỉnh sửa Oders_Detail";
                        tool.Visible = false;
                        load_edit();
                         //Load các thông tin đê cập nhật lên form
                    
                    }
				if(Request.QueryString["act"] == "delete" && Request.QueryString["ID"] != null)
				{
				 string ID = Request.QueryString["ID"]; 
				 string str = "DELETE FROM [Oders_Detail] WHERE ID="+ID+" ";
				 XLDL.thuchienlenh(str);
				 Response.Write("<script>alert('Đã xóa mã số : " + ID + " thành công!')</script>");
				 Response.Write("<script> location.href = 'Oders_Detail.aspx';</script>");
				}
			}
		}
		catch { } 
	}
	public void load()
	{
		GridOders_Detail.DataSource =XLDL.Docbang("select * from [Oders_Detail]  ORDER BY ID DESC");
		GridOders_Detail.DataBind();
		if (!IsPostBack) {
}
	}


	protected void GridOders_Detail_PageIndexChanging(object sender, GridViewPageEventArgs e)
	{ 
		try
		{
			 GridOders_Detail.PageIndex = e.NewPageIndex;
			 GridOders_Detail.DataSource = XLDL.Docbang("SELECT * FROM [Oders_Detail]   ORDER BY ID DESC");
			 GridOders_Detail.DataBind();
			}
		catch {   }
	}


	public void load_edit()
	{
			string str= "SELECT * FROM [Oders_Detail] WHERE [ID] = "+Request.QueryString["ID"]+" ";/*Load dữ liệu từ cơ sở dữ liệu lên form*/
			System.Data.DataTable dt = XLDL.Docbang(str);
			txtID.Text =dt.Rows[0]["ID"].ToString();
			txtOderid.Text =dt.Rows[0]["Oderid"].ToString();
			txtProductId.Text =dt.Rows[0]["ProductId"].ToString();
			txtQuantity.Text =dt.Rows[0]["Quantity"].ToString();
			CKE_VariantId.Text =dt.Rows[0]["VariantId"].ToString();
			CKE_VariantTitle.Text =dt.Rows[0]["VariantTitle"].ToString();
			CKE_Title.Text =dt.Rows[0]["Title"].ToString();
			chRequiresShipping.Checked =Boolean.Parse(dt.Rows[0]["RequiresShipping"].ToString());
			txtPrice.Text =dt.Rows[0]["Price"].ToString();
			txtDiscountedPrice.Text =dt.Rows[0]["DiscountedPrice"].ToString();
			txtGrams.Text =dt.Rows[0]["Grams"].ToString();
			CKE_AppliedDiscount.Text =dt.Rows[0]["AppliedDiscount"].ToString();
			txtKeyID.Text =dt.Rows[0]["KeyID"].ToString();

	}


	protected void btluu_Click(object sender, EventArgs e)
	{
		try
		{
			if (Request.QueryString["act"] == "add"){						   
                string sql= "INSERT INTO [Oders_Detail](ID,Oderid,ProductId,Quantity,VariantId,VariantTitle,Title,RequiresShipping,Price,DiscountedPrice,Grams,AppliedDiscount,KeyID) VALUES ("+Int32.Parse(txtID.Text) +",N'"+txtOderid.Text +"',N'"+txtProductId.Text +"',"+Int32.Parse(txtQuantity.Text) +",N'"+CKE_VariantId.Text +"',N'"+CKE_VariantTitle.Text +"',N'"+CKE_Title.Text +"',N'"+chRequiresShipping.Checked.ToString() +"',"+Double.Parse(txtPrice.Text) +","+Double.Parse(txtDiscountedPrice.Text) +","+Int32.Parse(txtGrams.Text) +",N'"+CKE_AppliedDiscount.Text +"',N'"+txtKeyID.Text +"')";
				XLDL.thuchienlenh(sql);
				Response.Write("<script> location.href ='Oders_Detail.aspx';</script>");
			}

			else
			 if (Request.QueryString["act"] == "edit" && Request.QueryString["ID"] != null)
				{
						   
                string sql= "UPDATE [Oders_Detail] SET [ID]="+Int32.Parse(txtID.Text)+",[Oderid]=N'"+txtOderid.Text+"',[ProductId]=N'"+txtProductId.Text+"',[Quantity]="+Int32.Parse(txtQuantity.Text)+",[VariantId]=N'"+CKE_VariantId.Text+"',[VariantTitle]=N'"+CKE_VariantTitle.Text+"',[Title]=N'"+CKE_Title.Text+"',[RequiresShipping]=N'"+chRequiresShipping.Checked.ToString()+"',[Price]="+Double.Parse(txtPrice.Text)+",[DiscountedPrice]="+Double.Parse(txtDiscountedPrice.Text)+",[Grams]="+Int32.Parse(txtGrams.Text)+",[AppliedDiscount]=N'"+CKE_AppliedDiscount.Text+"',[KeyID]=N'"+txtKeyID.Text+"' WHERE [ID]="+Int32.Parse(txtID.Text)+" ";
				string id = Request.QueryString["ID"];
				XLDL.thuchienlenh(sql);
				Response.Write("<script>alert('Đã cập nhật thành công!')</script>");
				Response.Write("<script> location.href ='Oders_Detail.aspx?act=edit&ID="+id+"';</script>");
				}
		} catch{	Response.Write("<script>alert('Xin lỗi hệ thống lưu thất bại!')</script>");}
	}
		protected void btsearch_Click(object sender, EventArgs e)
		{
 		try{
			GridOders_Detail.DataSource = XLDL.Docbang("SELECT * FROM [Oders_Detail] where Oderid LIKE '%"+txt_search.Text+"%' order by ID desc ");
			GridOders_Detail.DataBind();
			//Grid{0}.DataSource = XLDL.Search("Search_All",txt_search.Text)
			//Grid{0}.DataBind();
		}catch { } 
		}

		protected void cbxSelectOne_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox cbxSelectOne = (CheckBox)sender;
            if (!cbxSelectOne.Checked)
            {
                ((CheckBox)GridOders_Detail.HeaderRow.FindControl("cbxSelectAll")).Checked = false;
            }
            changestyle();
        }

        private void changeStyleSelectedRow(GridViewRow row, bool check)
        {
            if (check)
            {
                row.ApplyStyle(GridOders_Detail.SelectedRowStyle);
            }
            else
            {
                if (row.RowIndex % 2 == 0)
                {
                    row.ApplyStyle(GridOders_Detail.RowStyle);
                }
                else
                {
                    row.ApplyStyle(GridOders_Detail.AlternatingRowStyle);
                }
            }
        }
         // hàm thay đổi màu sắc hàng đã check
        private void changestyle()
        {
            int count = 0;
            foreach (GridViewRow row in GridOders_Detail.Rows)
            {
                CheckBox cbxSelectOne = (CheckBox)row.FindControl("cbxSelectOne");
                if (cbxSelectOne.Checked)
                {
                    count++;
                }
                changeStyleSelectedRow(row, cbxSelectOne.Checked);
            }
        
        }
         /*tự động check tất cả*/
        protected void cbxSelectAll_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox cbxSelectAll = (CheckBox)sender;
            if (cbxSelectAll.Checked)
            {
                foreach (GridViewRow row in GridOders_Detail.Rows)
                {
                    CheckBox cbxSelectOne = (CheckBox)row.FindControl("cbxSelectOne");
                    cbxSelectOne.Checked =true;
                }
            }
            else
            {
                foreach (GridViewRow row in GridOders_Detail.Rows)
                {
                    CheckBox cbxSelectOne = (CheckBox)row.FindControl("cbxSelectOne");
                    cbxSelectOne.Checked = false; ;
                }
            }
            changestyle();
        }
       
		protected void btxoa_Click(object sender, EventArgs e)
		{
			try
			{
				foreach (GridViewRow rows in GridOders_Detail.Rows)
				{
				CheckBox chk = (CheckBox)rows.FindControl("cbxSelectOne");
				if (chk.Checked)
				{
					CheckBox btnDel = (CheckBox)rows.FindControl("cbxSelectOne");
					if (btnDel.ToolTip.Trim()!=null)
					{
					XLDL.thuchienlenh("DELETE FROM [Oders_Detail] WHERE  ID=" + btnDel.ToolTip.Trim() + "");
					}
				}
				}
			Response.Write("<script> location.href ='Oders_Detail.aspx';</script>");
			}
			catch{}
		}

    }
}

 


Tags

admin

Hãy chia sẽ cảm nghĩ của bạn về bài viết trên nhé !

0 Nhận xét

  • Hãy trở thành người đầu tiên viết chia sẽ cảm nghĩ của mình bên dưới nhé!

Thêm Bình luận