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

📄 wuzichushou.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 wuzichushou : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string myConnStr = "data source=.;database=物资管理系统;Trusted_Connection=SSPI";
        SqlConnection myConn = new SqlConnection(myConnStr);

        myConn.Open();

        string sql = "select 物资编号 from 物资信息表";
        SqlCommand myComm = new SqlCommand(sql, myConn);
        myComm = new SqlCommand(sql, myConn);
        SqlDataReader myReader = myComm.ExecuteReader();
        if (!IsPostBack)
        {
            while (myReader.Read())
                this.DropDownListwuzibianhao.Items.Add(myReader.GetValue(0).ToString());
        }
        myReader.Close();

        sql = "select 物资名称 from 物资信息表";
        myComm = new SqlCommand(sql, myConn);
        myReader = myComm.ExecuteReader();
        if (!IsPostBack)
        {
            while (myReader.Read())
                this.DropDownListwuzimingchen.Items.Add(myReader.GetValue(0).ToString());
        }
        myReader.Close();

        sql = "select  客户编号 from 客户信息表";
        myComm = new SqlCommand(sql, myConn);
        myReader = myComm.ExecuteReader();
        if (!IsPostBack)
        {
            while (myReader.Read())
                this.DropDownListkehubianhao.Items.Add(myReader.GetValue(0).ToString());
        }
        myReader.Close();

        sql = "select 客户名称 from 客户信息表";
        myComm = new SqlCommand(sql, myConn);
        myReader = myComm.ExecuteReader();
        if (!IsPostBack)
        {
            while (myReader.Read())
                this.DropDownListkehumingchen.Items.Add(myReader.GetValue(0).ToString());
        }
        myReader.Close();

        sql = "select 姓名 from 职工信息表 ";
        myComm = new SqlCommand(sql, myConn);
        myReader = myComm.ExecuteReader();
        if (!IsPostBack)
        {
            while (myReader.Read())
                this.DropDownListjingshouren.Items.Add(myReader.GetValue(0).ToString());
        }
        myReader.Close();
       

        sql = "select 单价 from 物资信息表";
        myComm = new SqlCommand(sql, myConn);
        myReader = myComm.ExecuteReader();
        if (!IsPostBack)
        {
            while (myReader.Read())
                this.DropDownListchushoujiage.Items.Add(myReader.GetValue(0).ToString());
        }
        myReader.Close();

        myConn.Close();
    } 
   protected void Buttoncfanhui_Click1(object sender, EventArgs e)
    {
     this.Response.Redirect("物资出库.aspx");
    }
    protected void Buttoncshuru_Click(object sender, EventArgs e)
    {
        string myConnStr = "data source=.;database=物资管理系统;Trusted_Connection=SSPI";
        SqlConnection myConn = new SqlConnection(myConnStr);
       /* if (this.TextBoxchushoudanbianhao.Text != "")
        {
            Response.Write("<script>alert('不用填写!');</script>");
        }
        else
        {*/
            string strcm = "select max(出售单编号) from 物资出售信息表 ";
            myConn.Open();
            SqlCommand cm = new SqlCommand(strcm, myConn);
            int maxnum = (int)cm.ExecuteScalar()+1;
            this.TextBoxchushoudanbianhao.Text = maxnum.ToString();
            myConn.Close();

            string strcd = "select 物资编号,单价 from 物资信息表 where 物资名称='" + this.DropDownListwuzimingchen.Text + "'";
            myConn.Open();
            SqlCommand cd = new SqlCommand(strcd, myConn);
           
            SqlDataReader rdr = cd.ExecuteReader();
           
            if (rdr.Read())
            {
                // TextBoxwuzishuliang.Text = Convert.ToString(rdr["物资数量"]);
                //TextBoxchushoushijian.Text = Convert.ToString(rdr["出售时间"]);
                DropDownListwuzibianhao.Text = Convert.ToString(rdr["物资编号"]);
                DropDownListchushoujiage.Text = Convert.ToString(rdr["单价"]);
            }
            myConn.Close();
        //}
       /*  if (this.TextBoxchushoudanbianhao.Text == "")
        {
            Response.Write("<script>alert('请填写出售单编号!');</script>");

        }*/
        //else 
        if (this.TextBoxchushoushijian.Text == "")
        {
            Response.Write("<script>alert('请输入出售时间!');</script>");
        }
        else if (this.TextBoxwuzishuliang.Text == "")
        {
            Response.Write("<script>alert('请输入物资数量!');</script>");
        }
        else
        {


           

            string strcmd = "select 物资数量 from 物资信息表 where 物资名称='" + this.DropDownListwuzimingchen.Text + "'";
            myConn.Open();
            SqlCommand cmd = new SqlCommand(strcmd, myConn);
            int num = (int)cmd.ExecuteScalar();
            myConn.Close();
          
            if (num != 0)
            {
                string sql
                    = "insert into 物资出售信息表(出售单编号,出售时间,物资编号,物资名称,客户编号,客户名称,经手人,物资数量,出售价格) values('"
                   + this.TextBoxchushoudanbianhao.Text + "','" 
                    +this.TextBoxchushoushijian.Text + "','" +
                    this.DropDownListwuzibianhao.Text + "','" +
                   this.DropDownListwuzimingchen.Text + "','" +
                this.DropDownListkehubianhao.Text + "','" +
              this.DropDownListkehumingchen.Text + "','" +
              this.DropDownListjingshouren.Text + "','" +
              this.TextBoxwuzishuliang.Text + "','" +
               this.DropDownListchushoujiage.Text+ "');";

                if (num < Convert.ToDouble(TextBoxwuzishuliang.Text))
                {
                    sql += "update  物资信息表 set 物资数量= 0 where 物资编号='" + this.DropDownListwuzibianhao.Text + "'";
                    SqlCommand myComm = new SqlCommand(sql, myConn);
                    myConn.Open();
                    myComm.ExecuteNonQuery();
                    myConn.Close();
                    this.Response.Write("<script language=javascript>alert('数量不够,领用不足!')</script>");
                }
                else
                {
                    sql += "update  物资信息表 set 物资数量=物资数量-" + this.TextBoxwuzishuliang.Text
                           + "where 物资名称='" + this.DropDownListwuzimingchen.Text + "'";
                    SqlCommand myCom = new SqlCommand(sql, myConn);
                    myConn.Open();
                    myCom.ExecuteNonQuery();
                    myConn.Close();
                    this.Response.Write("<script language=javascript>alert('出售单输入成功!')</script>");
                  
                }
                
            }
            else
            {
                this.Response.Write("<script language=javascript>alert('此物资已用完,请补充!')</script>");
                this.TextBoxchushoudanbianhao.Text = "";
                  this.TextBoxchushoushijian.Text = "";
                  this.DropDownListwuzibianhao.Text = "1";
                  this.DropDownListkehubianhao.Text = "1";
                  this.TextBoxwuzishuliang.Text = "";
            }
         

        }
    }
    protected void Buttoncshanchu_Click(object sender, EventArgs e)
    {
        string myConnStr = "data source=.;database=物资管理系统;Trusted_Connection=SSPI";
        SqlConnection myConn = new SqlConnection(myConnStr);
        if (TextBoxchushoudanbianhao.Text == "")
        {
            Response.Write("<script>alert('请填写出售单编号!');</script>");

        }
        else if (TextBoxwuzishuliang.Text == "")
        {
            Response.Write("<script>alert('物资数量为空项,请先进行查询!');</script>");
        }


        else
        {
            string strcmd = "select 物资数量 from 物资出售信息表 where 出售单编号='" + this.TextBoxchushoudanbianhao.Text + "'";
            myConn.Open();
            SqlCommand cmd = new SqlCommand(strcmd, myConn);
            int nl = Convert.ToInt32(cmd.ExecuteScalar());
            myConn.Close();

            if (nl == Convert.ToDouble(TextBoxwuzishuliang.Text))
            {
                string sql
                 = "delete from 物资出售信息表  where 出售单编号='" + this.TextBoxchushoudanbianhao.Text + "'";
                sql += "update 物资信息表 set 物资数量=物资数量+" + this.TextBoxwuzishuliang.Text
                   + "where 物资名称='" + this.DropDownListwuzimingchen.Text + "'";
                SqlCommand myComm = new SqlCommand(sql, myConn);
                myConn.Open();
                myComm.ExecuteNonQuery();
                myConn.Close();
                this.Response.Write("<script language=javascript>alert('出售单删除成功!')</script>");
                this.TextBoxchushoudanbianhao.Text = "";
                this.TextBoxchushoushijian.Text = "";
                this.DropDownListwuzibianhao.Text = "1";
                this.DropDownListkehubianhao.Text = "1";
               
                this.TextBoxwuzishuliang.Text = "";
            }
            else if (nl != Convert.ToDouble(TextBoxwuzishuliang.Text))
            {
                this.Response.Write("<script language=javascript>alert('物资数量不正确或出售单编号错误,请先进行查找!')</script>");
            }
        }
    }
    protected void Buttoncxiugai_Click(object sender, EventArgs e)
    {
        string myConnStr = "data source=.;database=物资管理系统;Trusted_Connection=SSPI";
        SqlConnection myConn = new SqlConnection(myConnStr);


        if (TextBoxchushoudanbianhao.Text == "")
        {
            Response.Write("<script>alert('请填写出售单编号!');</script>");

        }
        else if (TextBoxwuzishuliang.Text == "")
        {
            Response.Write("<script>alert('物资数量为空项,请先进行查找!');</script>");
        }
        else if (TextBoxchushoushijian.Text == "")
        {
            Response.Write("<script>alert('请填写出售时间!');</script>");

        }
        else
        {
            string strcmd = "select 物资数量 from  物资出售信息表 where 出售单编号='" + this.TextBoxchushoudanbianhao.Text + "'";
            myConn.Open();
            SqlCommand cmd = new SqlCommand(strcmd, myConn);
            int nu = Convert.ToInt32(cmd.ExecuteScalar());
            myConn.Close();

            if (nu == Convert.ToDouble(TextBoxwuzishuliang.Text))
            {
                string sql
                          = "update 物资出售信息表 set 物资数量='" + this.TextBoxwuzishuliang.Text
                          + "', 出售时间='" + this.TextBoxchushoushijian.Text
                        + "'  ,   物资编号='" + this.DropDownListwuzibianhao.Text
                         + "', 物资名称='" + this.DropDownListwuzimingchen.Text
                     + "',客户编号='" + this.DropDownListkehubianhao.Text
                    + "',客户名称='" + this.DropDownListkehumingchen.Text
                     + "',经手人='" + this.DropDownListjingshouren.Text
             + "' where 出售单编号='" + this.TextBoxchushoudanbianhao.Text + "'";
                SqlCommand myComm = new SqlCommand(sql, myConn);
                myConn.Open();
                myComm.ExecuteNonQuery();
                myConn.Close();
                this.Response.Write("<script language=javascript>alert('出售单修改成功!')</script>");
            }
            else 
            {
                this.Response.Write("<script language=javascript>alert('物资数量被修改或领用单编号错误,请先进行查找!')</script>");
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
         string myConnStr = "data source=.;database=物资管理系统;Trusted_Connection=SSPI";
        SqlConnection myConn = new SqlConnection(myConnStr);
        if (TextBoxchushoudanbianhao.Text == "")
        {
            Response.Write("<script>alert('请填写出售单编号!');</script>");

        }
        else
        {
            string strcmd = "select  出售时间,物资编号,物资名称,客户编号,客户名称,经手人,物资数量,出售价格 from 物资出售信息表 where 出售单编号='" + this.TextBoxchushoudanbianhao.Text + "'";
            myConn.Open();
            SqlCommand cmd = new SqlCommand(strcmd, myConn);
            SqlDataReader rdr = cmd.ExecuteReader();

            if (rdr.Read())
            {
                TextBoxwuzishuliang.Text = Convert.ToString(rdr["物资数量"]);
                TextBoxchushoushijian.Text = Convert.ToString(rdr["出售时间"]);
                DropDownListwuzibianhao.Text = Convert.ToString(rdr["物资编号"]);
                DropDownListwuzimingchen.Text = Convert.ToString(rdr["物资名称"]);
                DropDownListkehubianhao.Text = Convert.ToString(rdr["客户编号"]);
                DropDownListkehumingchen.Text = Convert.ToString(rdr["客户名称"]);
                DropDownListjingshouren.Text = Convert.ToString(rdr["经手人"]);
                DropDownListchushoujiage.Text = Convert.ToString(rdr["出售价格"]);
                this.Response.Write("<script language=javascript>alert('查找成功!')</script>");
            }
            else
            {
                this.Response.Write("<script language=javascript>alert('不存在该项,请重新核对领用单编号!')</script>");
            }
            myConn.Close();
             }
    }
 
  
}   
    

⌨️ 快捷键说明

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