📄 add_sell.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 Add_Sell : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
HeardConfig();
if (!IsPostBack)
{
PersonInfo.Return_SessionPerson();//判断管理员是否登陆
IsPage_Bind();
}
}
#region 页面初始化必需的内容 附加脚本
public void HeardConfig()
{
Header.Title = "销售订单管理系统-进库登记";
HeaderTextInfo.GetHeader(this, "<script language='javascript' type='text/javascript' src='Computation.js'></script>");
}
#endregion
public void IsPage_Bind()
{
this.Label1.Text = QueryString.Get_SessionPerson;
SqlConnection strcon = new SqlConnection(ConfigurationManager.ConnectionStrings["SellOrder_ConnectionString"].ConnectionString);
strcon.Open();
SqlDataAdapter sda = new SqlDataAdapter("select * from Commodity order by id desc", strcon);
DataSet ds = new DataSet();
sda.Fill(ds, "tb_Commodity");
DataRowView rowview = ds.Tables["tb_Commodity"].DefaultView[0];
int CommodityIds = Convert.ToInt32(rowview["CompanyId"]);
this.CommodityId.DataSource = ds.Tables["tb_Commodity"];
this.CommodityId.DataValueField = "id";
this.CommodityId.DataTextField = "CommodityName";
this.CommodityId.DataBind();
SqlCommand scdc = new SqlCommand("select CompanyName from Company where id=" + CommodityIds + "", strcon);
this.CId.Text = Convert.ToString(scdc.ExecuteScalar());
this.CompanyId.Value = CommodityIds.ToString();
//显示客户
SqlDataAdapter sdac = new SqlDataAdapter("select * from Company where CompanyType='客户' order by id desc", strcon);
sdac.Fill(ds, "tb_Company");
this.ClientId.DataSource = ds.Tables["tb_Company"];
this.ClientId.DataValueField = "id";
this.ClientId.DataTextField = "CompanyName";
this.ClientId.DataBind();
//计算剩余商品数量
stockClass ss = new stockClass();
string Snum = Convert.ToString(ss.stock(Convert.ToInt32(rowview["id"])) - ss.sell(Convert.ToInt32(rowview["id"])));
Session["snum"] = Snum;
this.Number.Text = Snum;//保存剩余数量
this.StockDate.SelectedDate = DateTime.Now;
}
//当选择商品变动时内容变动时执行
protected void CommodityId_TextChanged(object sender, EventArgs e)
{
SqlConnection strcon = new SqlConnection(ConfigurationManager.ConnectionStrings["SellOrder_ConnectionString"].ConnectionString);
strcon.Open();
SqlDataAdapter sda = new SqlDataAdapter("select * from Commodity where id=" + this.CommodityId.SelectedValue + "", strcon);
DataSet ds = new DataSet();
sda.Fill(ds, "tb_Commodity");
DataRowView rowview = ds.Tables["tb_Commodity"].DefaultView[0];
string CommodityIds = Convert.ToString(rowview["CompanyId"]);
SqlCommand scdc = new SqlCommand("select CompanyName from Company where id=" + CommodityIds + "", strcon);
this.CId.Text = Convert.ToString(scdc.ExecuteScalar());
this.CompanyId.Value = CommodityIds;
stockClass ss = new stockClass();
Session["snum"] = ss.stock(Convert.ToInt32(rowview["id"])) - ss.sell(Convert.ToInt32(rowview["id"]));
this.Number.Text = Convert.ToString(ss.stock(Convert.ToInt32(rowview["id"])) - ss.sell(Convert.ToInt32(rowview["id"])));
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Convert.ToInt32(Session["snum"]) < Convert.ToInt32(this.Number.Text.Trim()))
{
Response.Write("<script>alert('没有更多的库存,请重新填写');history.back()</script>");//history.back()直接退回括号内可填写整数
Response.End();
}
string CommodityId = this.CommodityId.Text.ToString();
string CompanyId = this.CompanyId.Value.ToString();
int ClientId = Convert.ToInt32(this.ClientId.SelectedValue);
int Number = Math.Abs(Convert.ToInt32(this.Number.Text));//数量
decimal Pirce = Decimal.Round(Convert.ToDecimal(this.Pirce.Text.Trim()), 2);//单价,保留2位小数
string StockDate = this.StockDate.SelectedDate.ToShortDateString();
string SettlementType = this.SettlementType.Text.ToString();
decimal Payment = Decimal.Round(Convert.ToDecimal(this.Payment.Text.Trim()), 2);//应付金额,保留2位小数
decimal FactPayment = Decimal.Round(Convert.ToDecimal(this.FactPayment.Text.Trim()), 2);//实付金额,保留2位小数
decimal NotPayment = Decimal.Round(Convert.ToDecimal(this.NotPayment.Text.Trim()), 2);//未付金额,保留2位小数
string ManageMan = this.ManageMan.Text.ToString();
string Username = QueryString.Get_SessionPerson;
string AddTime = Convert.ToString(DateTime.Now);
string Type = "销售信息";
//计算输入的金额是否正确
if (Number * Pirce < Payment)
{
Response.Write("<script>alert('应付金额填写错误');history.back()</script>");
Response.End();
}
string CmdTxt = "insert into Stock (CommodityId,CompanyId,Number,Pirce,StockDate,SettlementType,Payment,FactPayment,NotPayment,ManageMan,Username,AddTime,Type,ClientId)values('" + CommodityId + "','" + CompanyId + "','" + Number + "','" + Pirce + "','" + StockDate + "','" + SettlementType + "','" + Payment + "','" + FactPayment + "','" + NotPayment + "','" + ManageMan + "','" + Username + "','" + AddTime + "','" + Type + "','" + ClientId + "')";
bool YesNo = new SqlDataBase().RunSql_Return_Bool(CmdTxt);//判断添加后返回结果,如果正确则返回的是1
if (YesNo)
{ JScript.AlertAndRedirect("添加成功!", "Add_Sell.aspx"); }
else
{ JScript.GoHistory("添加失败", -1); }
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -