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

📄 buyaddform.aspx.cs

📁 基于w/s模式的资产管理系统,可以参考参考,忘了什么时候从网络下的,还可以
💻 CS
字号:
//文件名:BuyAddForm.aspx.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 BuyManage_BuyAddForm : System.Web.UI.Page
{
    private static DataTable MyGoodsTable = new DataTable();
    private static int MyID = 0; 
    protected void Page_Load(object sender, EventArgs e)
    {
        string MyForbidString = Session["MyForbid"].ToString();
        if (MyForbidString.IndexOf("C1") > 1)
        {
            Server.Transfer("~/SystemManage/AllErrorHelp.aspx");
        }     
      
        this.Button5.OnClientClick = "return confirm('请检查采购商品信息是否正确,一旦新增就无法修改,是否继续?')";
        this.Button3.OnClientClick = "return confirm('请检查采购入库单信息是否正确,一旦保存就无法修改,是否继续?')";    
    }   
    protected void Button1_Click(object sender, EventArgs e)
    {//新增入库单
        String MySQLConnectionString = ConfigurationManager.ConnectionStrings["MySaleDBConnectionString"].ConnectionString;
        SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
        MyConnection.Open();
        string MySQL = "Select * From 采购信息 Where 采购单号='" + this.TextBox1.Text + "'";
        SqlCommand MyCommand = new SqlCommand(MySQL, MyConnection);
        if(MyCommand.ExecuteScalar()!=null)
        {
            this.Page.RegisterStartupScript("msgOnlyAlert", "<script>alert('采购单号已经存在!')</script>");
            this.TextBox1.Text = "";
        }
        if (MyConnection.State == ConnectionState.Open)
        {
            MyConnection.Close();
        }
            //创建无连接的数据表
            DataColumn[] MyKey = new DataColumn[1];
            MyGoodsTable = new DataTable("商品采购明细表");
            DataColumn MyColumn = new DataColumn();
            MyColumn.DataType = System.Type.GetType("System.Int16");
            MyColumn.ColumnName = "自编号";
            MyGoodsTable.Columns.Add(MyColumn);
            MyKey[0] = MyColumn;
            MyGoodsTable.PrimaryKey = MyKey;
            MyGoodsTable.Columns.Add("商品编号", System.Type.GetType("System.String"));
            MyGoodsTable.Columns.Add("商品名称", System.Type.GetType("System.String"));
            MyGoodsTable.Columns.Add("规格型号", System.Type.GetType("System.String"));
            MyGoodsTable.Columns.Add("计量单位", System.Type.GetType("System.String"));
            MyGoodsTable.Columns.Add("商品单价", System.Type.GetType("System.Double"));
            MyGoodsTable.Columns.Add("采购数量", System.Type.GetType("System.Double"));
            MyGoodsTable.Columns.Add("采购金额", System.Type.GetType("System.Double"));
            MyGoodsTable.Columns.Add("生产日期", System.Type.GetType("System.String"));
            MyGoodsTable.Columns.Add("补充说明", System.Type.GetType("System.String"));
            this.GridView2.DataSource = MyGoodsTable;
        this.GridView2.DataBind();
        MyID = 0;
        this.TextBox2.Text = "0";
    }
    protected void Button3_Click(object sender, EventArgs e)
    {//保存入库单
        if (this.TextBox2.Text.Length<2)
            return;
        String MySQLConnectionString = ConfigurationManager.ConnectionStrings["MySaleDBConnectionString"].ConnectionString;
        string MySQL = "INSERT INTO 采购信息(采购单号,客户名称,应付金额,实付金额,支付方式,经办人员,入库日期,补充说明)VALUES('";
        MySQL += this.TextBox1.Text + "','";
        MySQL += this.DropDownList1.SelectedValue.ToString() + "','";
        MySQL += this.TextBox2.Text + "','";
        MySQL += this.TextBox3.Text + "','";
        MySQL += this.DropDownList2.SelectedValue.ToString()+ "','";
        MySQL += this.TextBox4.Text + "','";
        MySQL += this.TextBox5.Text + "','";
        MySQL += this.TextBox6.Text + "');";
        SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
        MyConnection.Open();
        SqlCommand MyCommand = MyConnection.CreateCommand();
        MyCommand.CommandText = MySQL;
        MyCommand.ExecuteNonQuery();
        foreach (DataRow MyRow in MyGoodsTable.Rows)
        {
            MySQL = "INSERT INTO 采购明细(采购单号,商品编号,商品名称,规格型号,计量单位,商品单价,采购数量,采购金额,生产日期,补充说明) VALUES('";
            MySQL += this.TextBox1.Text + "','";          
            MySQL += MyRow[1].ToString() + "','";
            MySQL += MyRow[2].ToString() + "','";
            MySQL += MyRow[3].ToString() + "','";
            MySQL += MyRow[4].ToString() + "','";
            MySQL += MyRow[5].ToString() + "','";
            MySQL += MyRow[6].ToString() + "','";
            MySQL += MyRow[7].ToString() + "','";
            MySQL += MyRow[8].ToString() + "','";            
            MySQL += MyRow[9].ToString() + "');";
            MySQL += "Update 商品信息 SET 累计采购量=累计采购量+" + MyRow[6].ToString() + " WHERE 商品编号='" + MyRow[1].ToString() + "';";
            MyCommand.CommandText = MySQL;
            MyCommand.ExecuteNonQuery();
        }
        if (MyConnection.State == ConnectionState.Open)
        {
            MyConnection.Close();
        }
        this.TextBox1.Text = "";
        MyGoodsTable.Rows.Clear();
        this.GridView2.DataSource = MyGoodsTable;
        this.GridView2.DataBind();
        MyID = 0;
        this.TextBox2.Text = "0";
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {//显示选择的商品信息
        if (this.TextBox1.Text.Length>1)
        {
            this.TextBox7.Text = this.GridView1.SelectedRow.Cells[1].Text.ToString();
            this.TextBox8.Text = this.GridView1.SelectedRow.Cells[2].Text.ToString();
            this.TextBox9.Text = this.GridView1.SelectedRow.Cells[3].Text.ToString();
            this.TextBox10.Text = this.GridView1.SelectedRow.Cells[4].Text.ToString();
            this.TextBox11.Text = this.GridView1.SelectedRow.Cells[5].Text.ToString();
        }
    }
    protected void TextBox12_TextChanged(object sender, EventArgs e)
    {//计算商品采购金额
        double  MyPrice = Convert.ToDouble(this.TextBox11.Text);
        double MyNumber = Convert.ToDouble(this.TextBox12.Text);
        double MyAmount = MyPrice * MyNumber;
        this.TextBox13.Text = MyAmount.ToString();       
    }
     protected void Button5_Click(object sender, EventArgs e)
    {//新增采购商品     
        if (this.TextBox13.Text.Length > 1)
        {
            MyID = MyID + 1;
            DataRow MyRow = MyGoodsTable.NewRow();
            MyRow[0] = MyID;
            MyRow["商品编号"] = this.TextBox7.Text;
            MyRow["商品名称"] = this.TextBox8.Text;
            MyRow["规格型号"] = this.TextBox9.Text;
            MyRow["计量单位"] = this.TextBox10.Text;
            MyRow["商品单价"] = this.TextBox11.Text;
            MyRow["采购数量"] = this.TextBox12.Text;
            MyRow["采购金额"] = this.TextBox13.Text;
            MyRow["生产日期"] = this.TextBox14.Text;
            MyRow["补充说明"] = this.TextBox15.Text;
            MyGoodsTable.Rows.Add(MyRow);
            this.GridView2.DataSource = MyGoodsTable;
            this.GridView2.DataBind();
            Double My应付金额 = Convert.ToDouble(this.TextBox2.Text);
            My应付金额 += Convert.ToDouble(this.TextBox13.Text);
            this.TextBox2.Text = My应付金额.ToString();
            this.TextBox13.Text = "";
        }
    }
    public String MyPrint采购单号
    {//设置要传递到打印页的数据
        get
        {
            return this.TextBox1.Text;
        }
    }
    public String MyPrint客户名称
    {//设置要传递到打印页的数据
        get
        {
            return this.DropDownList1.SelectedValue.ToString();
        }
    }
    public String MyPrint应付金额
    {//设置要传递到打印页的数据
        get
        {
            return this.TextBox2.Text;
        }
    }
    public String MyPrint实付金额
    {//设置要传递到打印页的数据
        get
        {
            return this.TextBox3.Text;
        }
    }
    public String MyPrint支付方式
    {//设置要传递到打印页的数据
        get
        {
            return this.DropDownList2.SelectedValue.ToString();
        }
    }
    public String MyPrint经办人员
    {//设置要传递到打印页的数据
        get
        {
            return this.TextBox4.Text;
        }
    }
    public String MyPrint入库日期
    {//设置要传递到打印页的数据
        get
        {
            return this.TextBox5.Text;
        }
    }
    public String MyPrint补充说明
    {//设置要传递到打印页的数据
        get
        {
            return this.TextBox6.Text;
        }
    }
    public DataTable  MyPrintDataTable
    {//设置要传递到打印页的数据
        get
        {
            return MyGoodsTable;
        }
    }    
    protected void Button2_Click(object sender, EventArgs e)
    {//打印商品采购入库单
        Server.Transfer("~/BuyManage/BuyAddPrint.aspx");
    }
}

⌨️ 快捷键说明

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