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

📄 instorequery.aspx.cs

📁 本系统主要内容是围绕图书销售管理系统而展开讨论的
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class TSPX_InStoreQuery : System.Web.UI.Page
{
    SqlCommand cmd = null;
    SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["connection"]);
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGrid();
        }
    }
    public void BindGrid()
    {
        SqlDataReader dataR = null;
        DataTable dt = new DataTable();
        SqlDataAdapter dtcmd;
        string str1 = String.Empty;
        string str2 = String.Empty;
        if (query_content.Text != "")
            str1 = " and " + query_tj.SelectedItem.Value + " like '%" + query_content.Text + "%'";
        str2 = "select count(*) as nums,sum(instorenum) as instorenums,sum(instorenum*price) as summy,sum(instorenum*price*discount) as sumsy from instoresheet a,bookinfosheet b,providerinfosheet c,pressinfosheet d where a.providercode=c.code and a.bookcode=b.code and presscode=d.code " +str1;
        cmd = new SqlCommand(str2, conn);
        conn.Open();
        dataR = cmd.ExecuteReader();
        if (dataR.Read())
        {
            if (dataR["nums"].ToString() == "0")
                Msg.Text = "";
            else
                Msg.Text = "合计:记录数 " + dataR["nums"].ToString() + "  总入库数 " + dataR["instorenums"].ToString() + " 总码洋 " + dataR["summy"].ToString() + " 总实洋  " + dataR["sumsy"].ToString();
        }
        dataR.Close();
        str1 = "select a.code,ddate,c.abbrname as providername,bookcode,b.name as bookname,d.abbrname,author,price,instorenum,discount from instoresheet a,bookinfosheet b,providerinfosheet c,pressinfosheet d where a.providercode=c.code and a.bookcode=b.code and presscode=d.code " +str1+ "  order by a.code desc,bookcode";
        dtcmd = new SqlDataAdapter(str1, conn);
        dtcmd.Fill(dt);
        #region 用来判断当前删除是否为当前页的最后一条记录
        if ((this.DataGrid1.CurrentPageIndex == this.DataGrid1.PageCount - 1) && this.DataGrid1.Items.Count == 1)
        {
            if (this.DataGrid1.CurrentPageIndex - 1 > 1)
            {
                this.DataGrid1.CurrentPageIndex = this.DataGrid1.CurrentPageIndex - 1;
            }
            else
            {
                this.DataGrid1.CurrentPageIndex = 0;
            }
        }
        #endregion
        DataGrid1.DataSource = dt;
        DataGrid1.DataBind();
        conn.Close();
    }
    #region 返回脚本字符串
    public string getalertinfo(string str1)
    {
        string str;
        str = "<script language='javascript'>alert('" + str1 + "')</script>";
        return str.Trim();
    }
    #endregion
    protected void Query_Click(object sender, EventArgs e)
    {
        BindGrid();
    }
    protected void Grid1_Del(object source, DataGridCommandEventArgs e)
    {
        string codeStr = e.Item.Cells[0].Text;
        string sql;
        SqlDataReader dataR = null;
        string bookCodeStr = e.Item.Cells[3].Text;
        if (e.CommandName.ToString() == "delete")
        {
            conn.Open();
            sql = "delete from instoresheet where code='" + codeStr.Trim() + "' and bookcode='" + bookCodeStr.Trim() + "'";
            cmd = new SqlCommand(sql, conn);
            cmd.ExecuteNonQuery();
            conn.Close();
            BindGrid();
        }
        else
        {
            if (e.CommandName.ToString() == "deleteunit")
            {
                conn.Open();
                sql = "delete from instoresheet where code='" + codeStr + "'";
                cmd = new SqlCommand(sql, conn);
                cmd.ExecuteNonQuery();
                conn.Close();
                BindGrid();
            }
        }
    }
    protected void Grid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
    {
        this.DataGrid1.CurrentPageIndex = e.NewPageIndex;
        BindGrid();
    }
    protected void Grid1_Edit(object source, DataGridCommandEventArgs e)
    {
        this.DataGrid1.EditItemIndex = e.Item.ItemIndex;
        BindGrid();
    }
    protected void Grid1_Cancel(object source, DataGridCommandEventArgs e)
    {
        this.DataGrid1.EditItemIndex = -1;
        BindGrid();
    }
    protected void Grid1_Update(object source, DataGridCommandEventArgs e)
    {
        string BookCodeStr = e.Item.Cells[3].Text;
        string InNumStr = ((TextBox)e.Item.Cells[8].Controls[0]).Text;
        string DiscountStr = ((TextBox)e.Item.Cells[9].Controls[0]).Text;
        string CodeStr = e.Item.Cells[0].Text;
        float theDiscount;
        if (VCUtilities.IsNumeric(InNumStr))
        {
            theDiscount = 1;
            if (VCUtilities.IsSingle(DiscountStr))
            {
                if (Convert.ToSingle(DiscountStr) > 0 && Convert.ToSingle(DiscountStr) <= 1)
                {
                    theDiscount = Convert.ToSingle(DiscountStr);
                }
            }
            conn.Open();
            string sql = "update instoresheet set instorenum=" + Convert.ToInt32(InNumStr) + ",discount="+theDiscount+" where code='" + CodeStr + "' and bookcode='" + BookCodeStr + "'";
            cmd = new SqlCommand(sql, conn);
            cmd.ExecuteNonQuery();
            conn.Close();
        }
        DataGrid1.EditItemIndex = -1;
        BindGrid();
    }
    protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        switch (e.Item.ItemType)
        {
            case (ListItemType.Item):
            case (ListItemType.AlternatingItem):
                {
                    LinkButton btn = (LinkButton)e.Item.Cells[11].Controls[0];
                    LinkButton btn_All = (LinkButton)e.Item.Cells[12].Controls[0];
                    btn.Attributes.Add("OnClick", "return window.confirm('确定要删除该收订记录?')");
                    btn_All.Attributes.Add("OnClick", "return window.confirm('确定要删除该收订整单记录?')");
                    break;
                }
        }
    }
}

⌨️ 快捷键说明

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