📄 reckoning_open.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;
using LoginCheckClass;
/// <summary>
/// 2008年7月30日 谈鸿如 编写
/// 2008年7月30日 测试
/// 用来实现 商品进货、进货退货、商品销售、销售退货的结账功能
/// </summary>
public partial class 往来管理_Reckoning_open : System.Web.UI.Page
{
//页面加载时运行
protected void Page_Load(object sender, EventArgs e)
{
//调用LoginCheck类的check方法来判断用户是否登录
LoginCheck a = new LoginCheck();
a.check();
//调用前台javascript比较结款金额是否大于未结款金额
TextBox1.Attributes["onchange"] = "javascript:numvs();";
if (!IsPostBack)
{
try
{
using (SqlConnection connection = new SqlConnection(_connectString)) //建立连接
{
connection.Open(); //打开连接
using (SqlCommand command = new SqlCommand())
{
command.Connection = connection;
//读取在Reckoning页面中建立的Session["ReckoningID"]的值,用来确定页面读出tb_Reckoning表中的哪条信息
command.Parameters.Add("@id", SqlDbType.Int).Value = Convert.ToInt32(Session["ReckoningID"]);
/*查询出所选信息的未结款金额
此金额通过tb_stock表中的Nopayment字段减去tb_reckoning表中同一商品的Settlement字段总和得到*/
command.CommandText = "select (dbo.tb_Stock.Nopayment-(select isnull(sum(dbo.tb_Reckoning.Settlement),0) from dbo.tb_Reckoning where dbo.tb_Reckoning.Stockid=dbo.tb_Stock.id)) as nopayment from dbo.tb_Stock where id=@id";
command.ExecuteNonQuery();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Label4.Text = Convert.ToString(reader.GetInt32(0));
TextBox1.Text = Label4.Text;
}
}
}
}
//若查询失败,则抛出异常信息
catch (Exception ex1)
{
Response.Write(@"<script>alert('系统错误')</script>");
}
}
}
//点击结款按钮后调用以下代码
protected void Button1_Click(object sender, EventArgs e)
{
try
{
using (SqlConnection connection = new SqlConnection(_connectString)) //建立连接
{
connection.Open(); //打开连接
using(SqlCommand command=new SqlCommand())
{
command.Connection=connection;
command.CommandType=CommandType.Text;
//读取页面中所填的结款金额、经手人、结款时间并赋予变量中
command.Parameters.Add("@Settlement",SqlDbType.Int).Value=TextBox1.Text; //结款金额
command.Parameters.Add("@ManageMan",SqlDbType.VarChar,50).Value=TextBox2.Text; //经手人
command.Parameters.Add("@datetime", SqlDbType.DateTime).Value = Convert.ToDateTime(DaintyDate1.Text); //结款时间
command.Parameters.Add("@username",SqlDbType.VarChar,50).Value=Convert.ToString(Session["UserName"]); //当前登录用户名
command.Parameters.Add("@id",SqlDbType.Int).Value=Convert.ToInt32(Session["ReckoningID"]); //选择的id
command.Parameters.Add("@AddTime", SqlDbType.VarChar, 50).Value = DateTime.Now; //当前时间
//将以上信息添加到tb_reckoning表中
command.CommandText = "Insert into tb_Reckoning (StockID,Settlement,ManageMan,datetime,username,Addtime) values (@id,@Settlement,@ManageMan,@datetime,@username,@AddTime)";
command.ExecuteNonQuery();
//添加成功后给用户提出成功信息
Response.Write(@"<script>alert('支付成功');opener.location.reload();window.close();</script>");
}
}
}
//若插入失败,则抛出异常信息
catch (Exception ex)
{
Response.Write(@"<script>alert('系统错误');</script>");
}
}
//使用db_sellConnectionString连接字符串
private static readonly string _connectString = System.Configuration.ConfigurationManager.ConnectionStrings["db_sellConnectionString"].ConnectionString;
//点击关闭按钮时,关闭当前弹出窗口
protected void Button2_Click(object sender, EventArgs e)
{
Response.Write("<script>window.close()</script>");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -