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

📄 xsd.aspx.cs

📁 该程序是商品库存管理系统是B/s模式的 希望大家指教
💻 CS
字号:
using System;
using System.Data;
using System.Data.SqlClient;
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;

public partial class jhd : System.Web.UI.Page
{
    SqlConnection Conn;
   
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //设置数据库连接
            String strConn = ConfigurationManager.AppSettings["conn"];
            Conn = new SqlConnection(strConn);
            Conn.Open();
            //设置要执行的SQL命令
            //取出所有商品编号并设置到控件

            String sql = "select 商品编号,商品名称 from 商品库存 ";
            SqlCommand Comm = new SqlCommand(sql, Conn);
            SqlDataReader Reader = Comm.ExecuteReader();
            while (Reader.Read())
                this.DropDownList1.Items.Add(Reader.GetValue(0).ToString() + "-" + Reader.GetValue(1).ToString());
            Reader.Close();

            //设置要执行的SQL命令
            //取出所有往来单位编号并设置到控件
            sql = "select 往来单位编号,往来单位名称 from 往来单位 ";
            Comm = new SqlCommand(sql, Conn);
            Reader = Comm.ExecuteReader();
            while (Reader.Read())
                this.DropDownList2.Items.Add(Reader.GetValue(0).ToString() + "-" + Reader.GetValue(1).ToString());
            Reader.Close();

            //设置要执行的SQL命令
            //取出所有业务员编号并设置到控件
            sql = "select 业务员编号,姓名 from 业务员 ";
            Comm = new SqlCommand(sql, Conn);
            Reader = Comm.ExecuteReader();
            while (Reader.Read())
                this.DropDownList3.Items.Add(Reader.GetValue(0).ToString() + "-" + Reader.GetValue(1).ToString());
            Reader.Close();

            //初始化日期、数量        
            this.TextBox3.Text = "1";
            this.TextBox2.Text = DateTime.Today.ToShortDateString();

            //关闭数据库连接
            Conn.Close();
        }

    }


    protected void Button1_Click(object sender, EventArgs e)
    {

        //设置数据库连接
        String strConn = ConfigurationManager.AppSettings["conn"];
        Conn = new SqlConnection(strConn);
        Conn.Open();

        //设置要执行的SQL命令
        //取出当前增加的销售单的编号并设置到控件
        String sql = "select count(*) from 销售单 ";
        SqlCommand Comm = new SqlCommand(sql, Conn);

        int maxNum = Convert.ToInt32(Comm.ExecuteScalar()) + 1;
        this.TextBox1.Text = maxNum.ToString();

        //设置要执行的SQL命令
        //在表中加入销售单数据,并同时修改库存商品的库存数量
        String sl = this.TextBox3.Text;

        if (sl.Trim() == "")
        {
            sl = "0";
        }

        sql = "insert into 销售单 (销售单编号,日期,商品编号,往来单位编号,业务员编号,数量) values('"
            + this.TextBox1.Text + "',convert(smalldatetime,'" +
            this.TextBox2.Text + "',120),'" +
            this.DropDownList1.Text.Remove(this.DropDownList1.Text.IndexOf("-")) + "','" +
            this.DropDownList2.Text.Remove(this.DropDownList2.Text.IndexOf("-")) + "','" +
            this.DropDownList3.Text.Remove(this.DropDownList3.Text.IndexOf("-")) + "'," +
            sl + "); ";
        sql += "update 商品库存 set 数量=数量-" + sl
            + " where 商品编号='" + this.DropDownList1.Text.Remove(this.DropDownList1.Text.IndexOf("-")) + "'";

        Comm = new SqlCommand(sql, Conn);

        Comm.ExecuteNonQuery();
        Conn.Close();

        //提示用户操作成功
        this.Response.Write("<script language=javascript>alert('销售单输入成功!')</script>");

    }
}

⌨️ 快捷键说明

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