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

📄 bookinfo.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;
using System.Data.SqlTypes;

public partial class ZDWH_Bookinfo : System.Web.UI.Page
{
    SqlDataAdapter dtcmd = new SqlDataAdapter();
    DataSet dset = new DataSet();
    SqlConnection conn=new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["connection"]);
    SqlCommand cmd=new SqlCommand();
    protected void Page_Load(object sender, EventArgs e)
    {
       AspNetPager1.RecordCount = Database.RunExecuteScalar("dt_bookinfo");
       if (Session["DispUser"] == null)
            {
                Session["DispUser"] = "";
                Session["logintime"] = "";
            }
            Page.RegisterStartupScript("", getSessionInfo(Session["DispUser"].ToString(), Session["logintime"].ToString()));
            string url = Request.RawUrl.ToString();
            if (Session["CurrUser"] == null)
                Response.Redirect("../Index.aspx?handle=" + url);

        if (!IsPostBack)
        {           
            SelPress.DataSource = CreateDataSource();
            SelPress.DataTextField = "fullname";
            SelPress.DataValueField = "Code";
            SelPress.DataBind();
            BindGrid();
            
        }
    }
    public ICollection CreateDataSource()
    {        
        dtcmd=new SqlDataAdapter("select * from pressinfosheet order by code",conn);
        dtcmd.Fill(dset);
        DataView dv=new DataView(dset.Tables[0]);
        conn.Close();
        return dv;
    }
    public string getSessionInfo(string DispUser, string LoginTime)
    {
        string _DisUser;
        _DisUser = "<script language='javascript'>window.status='登陆用户:" + DispUser;
        _DisUser += "  登陆时间:" + LoginTime + "'</script>";
        return _DisUser;
    }
    public void BindGrid()
    {
        SqlDataReader dataR = null;
        DataTable dt = new DataTable();
        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(storeamounta) as mskc,sum(storeamountz) as zdkc,sum(price*storeamounta) as msmy,sum(price*storeamountz) as zdmy from BookInfoSheet a,pressinfosheet b,bookstoresheeta c,bookstoresheetz d where a.presscode=b.code and a.code=c.bookcode and a.code=d.bookcode " + 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["zdkc"].ToString() + " 门市库存 " + dataR["mskc"].ToString() + " 总店码洋 " + dataR["zdmy"].ToString() + " 门市码洋 " + dataR["msmy"].ToString();
        }
        dataR.Close();
        str1 = "select a.*,abbrname,storeamounta,storeamountz from bookinfosheet a,pressinfosheet b,bookstoresheeta c,bookstoresheetz d where a.presscode=b.code and a.code=c.bookcode and a.code=d.bookcode " + str1 + " order by a.code";
        //dtcmd = new SqlDataAdapter(str1, conn);
        //dtcmd.Fill(dt);
        DataGrid1.DataSource = Socut.Data.ExecuteDataSet(str1, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize);
        DataGrid1.DataBind();
        
        #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();
    }
    protected void Save_Click(object sender, EventArgs e)
    {
        string BookName = name.Text;
        string isbnStr = ISBN.Text;
        string CbsStr = SelPress.SelectedItem.Value;
        float Price= Convert.ToSingle(bookprice.Text);
        string SelfCode = bookselfcode.Text;
        string YMStr = sourcecode.Text;
        string CBYear = cbyyear.Text;
        string Version = bc.Text;
        string Author = bookauthor.Text;
        string LocCode = locatecode.Text;
        string MeMoStr = memo.Text;
        string sql;
        SqlDataReader dataR;
        string BookCode;
        conn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["connection"]);
        conn.Open();
        sql = "select * from bookinfosheet where presscode='" +CbsStr + "'order by code desc";
        cmd = new SqlCommand(sql, conn);
        dataR = cmd.ExecuteReader();
        if (dataR.Read())
        {
            Int32 temp = Convert.ToInt32(dataR["code"].ToString().Substring(4)) + 1;
            BookCode = CbsStr.Trim() + temp.ToString("0000");           
        }
        else
        {
            BookCode = CbsStr.Trim() + "0001";           
        }
        dataR.Close();
        //保存图书基本信息
        sql = "insert into bookinfosheet(code,name,sourcecode,selfcode,isbn,yyear,version,author,price,presscode,loccode,memo) values('" +BookCode+ "','" +BookName+ "','" +YMStr+ "','" +SelfCode+ "','" +isbnStr+ "','" +CBYear+ "','" +Version+ "','" +Author+ "'," +Price+ ",'" +CbsStr+ "','" +LocCode+ "','" +MeMoStr+ "')";
        cmd = new SqlCommand(sql, conn);
        cmd.ExecuteNonQuery();
        sql = "insert into bookstoresheeta(bookcode) values('" + BookCode + "')";
        cmd = new SqlCommand(sql, conn);
        cmd.ExecuteNonQuery();
        sql = "insert into bookstoresheetz(bookcode) values('" + BookCode + "')";
        cmd = new SqlCommand(sql, conn);
        cmd.ExecuteNonQuery();
        conn.Close();
        BindGrid();
        name.Text="";
        ISBN.Text = "";
        bookprice.Text="";
        sourcecode.Text="";
        bookselfcode.Text="";
        cbyyear.Text="";
        bc.Text="";
        bookauthor.Text="";
        locatecode.Text="";
        memo.Text="";
        Page.RegisterStartupScript("",getalertinfo("数据保存成功!"));
    }
    public string getalertinfo(string str1)
    {
        string str;
        str = "<script language='javascript'>alert('" + str1 + "')</script>";
        return str.Trim();
    }
    protected void QueryBtn_Click(object sender, EventArgs e)
    {
        BindGrid();
    }
    protected void DataGrid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
    {
        DataGrid1.CurrentPageIndex = e.NewPageIndex;
        BindGrid();
    }
    protected void DataGrid1_EditCommand(object source, DataGridCommandEventArgs e)
    {
        //取消验证控件的验证功能,以免在单击编辑按钮时页面验证
        Requiredfieldvalidator1.Enabled = false;
        Requiredfieldvalidator2.Enabled = false;
        DataGrid1.EditItemIndex = e.Item.ItemIndex;
        BindGrid();
    }
    protected void DataGrid1_CancelCommand(object source, DataGridCommandEventArgs e)
    {
        //开启验证控件的验证功能
        Requiredfieldvalidator1.Enabled =true;
        Requiredfieldvalidator2.Enabled =true;
        DataGrid1.EditItemIndex =-1;
        BindGrid();
    }
    protected void DataGrid1_DeleteCommand(object source, DataGridCommandEventArgs e)
    {
        string codeStr = e.Item.Cells[0].Text;
        int zdku = Convert.ToInt32(e.Item.Cells[6].Text);
        int msku = Convert.ToInt32(e.Item.Cells[7].Text);
        string sql;
        if (zdku != 0 || msku != 0)
            Page.RegisterStartupScript("", getalertinfo("该书存在库存,无法删除!"));
        else
        {
            conn.Open();
            sql = sql = "delete from bookinfosheet where code='" + codeStr + "'";
            cmd = new SqlCommand(sql, conn);
            cmd.ExecuteNonQuery();
            conn.Close();
            BindGrid();
        }
    }
    protected void DataGrid1_UpdateCommand(object source, DataGridCommandEventArgs e)
    {
        string NameStr = ((TextBox)e.Item.Cells[1].Controls[0]).Text;
        float PriceStr = Convert.ToSingle(((TextBox)e.Item.Cells[3].Controls[0]).Text);
        string AuthorStr = ((TextBox)e.Item.Cells[4].Controls[0]).Text;
        string VersionStr = ((TextBox)e.Item.Cells[5].Controls[0]).Text;
        string CodeStr = e.Item.Cells[0].Text;
        string sql;
        sql = "update bookinfosheet set name='" +NameStr+ "',price=" +PriceStr+ ",author='" +AuthorStr+ "',version='" +VersionStr+ "' where code='" +CodeStr+ "'";
        conn.Open();
        cmd = new SqlCommand(sql, conn);
        cmd.ExecuteNonQuery();
        conn.Close();
        DataGrid1.EditItemIndex = -1;
        BindGrid();
        //开启验证控件的验证功能
        Requiredfieldvalidator1.Enabled = true;
        Requiredfieldvalidator2.Enabled = true;
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        BindGrid();
    }
}

⌨️ 快捷键说明

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