📄 kctest_ls.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 TSLS_kctest_ls : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["connection"]);
SqlCommand cmd = null;
protected void Page_Load(object sender, EventArgs e)
{
string str1;
if (!IsPostBack)
{
conn.Open();
str1 = "exec testkucuna";
cmd = new SqlCommand(str1, conn);
cmd.ExecuteNonQuery();
conn.Close();
BindGrid();
}
}
public void BindGrid()
{
SqlDataReader dataR = null;
DataTable dt = new DataTable();
SqlDataAdapter dtcmd;
string str1 = String.Empty;
string str2 = String.Empty;
if (query_content.Text != "")
str1 = " and " + query_tj.SelectedItem.Value + " like '%" + query_content.Text + "%'";
str2 = "select count(*) as nums,sum(storeamounta) as sumstore,sum(storeamounta*price) as summy,sum(storeamounttest) as sumstore1,sum(storeamounttest*price) as summy1 from bookinfosheet a,bookstoresheeta b,pressinfosheet c where a.code=b.bookcode and a.presscode=c.code " + str1;
cmd = new SqlCommand(str2, conn);
conn.Open();
dataR = cmd.ExecuteReader();
if (dataR.Read())
{
if (dataR["nums"].ToString() == "0")
Msg.Text = "";
else
Msg.Text = "合计:记录数 " +dataR["nums"].ToString()+ " 现有库存 " + dataR["sumstore"].ToString()+ " 现有码洋 " +dataR["summy"].ToString()+ " 应有库存 " + dataR["sumstore1"].ToString()+ " 应有码洋 " + dataR["summy1"].ToString();
}
dataR.Close();
str1 = "select bookcode,a.name as bookname,c.abbrname,author,price,storeamounta,storeamounttest,suminnerin,sumout,suminnerout from bookinfosheet a,bookstoresheeta b,pressinfosheet c where a.code=b.bookcode and a.presscode=c.code " + str1 + " order by bookcode";
dtcmd = new SqlDataAdapter(str1, conn);
dtcmd.Fill(dt);
#region 用来判断当前删除是否为当前页的最后一条记录
if ((this.DataGrid1.CurrentPageIndex == this.DataGrid1.PageCount - 1) && this.DataGrid1.Items.Count == 1)
{
if (this.DataGrid1.CurrentPageIndex - 1 > 1)
{
this.DataGrid1.CurrentPageIndex = this.DataGrid1.CurrentPageIndex - 1;
}
else
{
this.DataGrid1.CurrentPageIndex = 0;
}
}
#endregion
DataGrid1.DataSource = dt;
DataGrid1.DataBind();
conn.Close();
}
#region 返回脚本字符串
public string getalertinfo(string str1)
{
string str;
str = "<script language='javascript'>alert('" + str1 + "')</script>";
return str.Trim();
}
#endregion
protected void Update_Click(object sender, EventArgs e)
{
string str1;
conn.Open();
str1 = "update bookstoresheeta set storeamounta=storeamounttest where storeamounta<>storeamounttest";
cmd = new SqlCommand(str1, conn);
cmd.ExecuteNonQuery();
conn.Close();
BindGrid();
Page.RegisterStartupScript("", getalertinfo("数据更新成功!"));
}
protected void Test_Click(object sender, EventArgs e)
{
SqlDataAdapter dtcmd = null;
SqlDataReader dataR = null;
DataTable dt = new DataTable();
string str2 = String.Empty;
string str1 = String.Empty;
str1 = "select count(*) as nums from bookstoresheeta where storeamounta<>storeamounttest";
cmd=new SqlCommand(str1,conn);
conn.Open();
dataR = cmd.ExecuteReader();
if(dataR.Read())
{
if(dataR["nums"].ToString()=="0")
Page.RegisterStartupScript("",getalertinfo("门市库存无差错!"));
else
{
str1="门市库存中,有" +dataR["nums"].ToString()+ "种图书库存不正确!";
Page.RegisterStartupScript("",getalertinfo(str1));
}
}
dataR.Close();
str2 = "select count(*) as nums,sum(storeamounta) as sumstore,sum(storeamounta*price) as summy,sum(storeamounttest) as sumstore1,sum(storeamounttest*price) as summy1 from bookinfosheet a,bookstoresheeta b,pressinfosheet c where a.code=b.bookcode and a.presscode=c.code and storeamounta<>storeamounttest";
cmd = new SqlCommand(str2, conn);
dataR = cmd.ExecuteReader();
if (dataR.Read())
{
if (dataR["nums"].ToString() == "0")
Msg.Text = "";
else
Msg.Text = "合计:记录数 " + dataR["nums"].ToString() + " 现有库存 " + dataR["sumstore"].ToString() + " 现有码洋 " + dataR["summy"].ToString() + " 应有库存 " + dataR["sumstore1"].ToString() + " 应有码洋 " + dataR["summy1"].ToString();
}
dataR.Close();
str1 = "select bookcode,a.name as bookname,c.abbrname,author,price,storeamounta,storeamounttest,suminnerin,sumout,suminnerout from bookinfosheet a,bookstoresheeta b,pressinfosheet c where a.code=b.bookcode and a.presscode=c.code and storeamounta<>storeamounttest order by bookcode";
dtcmd = new SqlDataAdapter(str1, conn);
dtcmd.Fill(dt);
#region 用来判断当前删除是否为当前页的最后一条记录
if ((this.DataGrid1.CurrentPageIndex == this.DataGrid1.PageCount - 1) && this.DataGrid1.Items.Count == 1)
{
if (this.DataGrid1.CurrentPageIndex - 1 > 1)
{
this.DataGrid1.CurrentPageIndex = this.DataGrid1.CurrentPageIndex - 1;
}
else
{
this.DataGrid1.CurrentPageIndex = 0;
}
}
#endregion
DataGrid1.DataSource = dt;
DataGrid1.DataBind();
conn.Close();
}
protected void Query_Click(object sender, EventArgs e)
{
BindGrid();
}
protected void Grid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
BindGrid();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -