📄 lsadd.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_LSAdd : System.Web.UI.Page
{
SqlCommand cmd = new SqlCommand();
public static DataTable DTable = new DataTable("SubTable");
SqlConnection conn=new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["connection"]);
protected void Page_Load(object sender, EventArgs e)
{
AspNetPager1.RecordCount=Database.RunExecuteScalar("dt_LSAdd");
if (DTable.Columns.Count == 0)
{
DTable.Columns.Add("code", Type.GetType("System.String"));
DTable.Columns.Add("name", Type.GetType("System.String"));
DTable.Columns.Add("cbs", Type.GetType("System.String"));
DTable.Columns.Add("author", Type.GetType("System.String"));
DTable.Columns.Add("price", Type.GetType("System.Single"));
DTable.Columns.Add("outnum", Type.GetType("System.Int32"));
DTable.Columns.Add("discount", Type.GetType("System.Single"));
DataColumn[] thekey ={ DTable.Columns["code"] };
DTable.PrimaryKey = thekey;
BindGrid1();
}
if (!IsPostBack)
{
DDate.Text = DateTime.Now.ToString("yyyy-MM-dd");
BindGrid();
BindGrid1();
}
}
public void BindGrid1()
{
#region 用来判断当前删除是否为当前页的最后一条记录
if ((this.DataGrid2.CurrentPageIndex == this.DataGrid2.PageCount - 1) && this.DataGrid2.Items.Count == 1)
{
if (this.DataGrid2.CurrentPageIndex - 1 > 1)
{
this.DataGrid2.CurrentPageIndex = this.DataGrid2.CurrentPageIndex - 1;
}
else
{
this.DataGrid2.CurrentPageIndex = 0;
}
}
#endregion
DataGrid2.DataSource = DTable;
DataGrid2.DataBind();
}
protected void Clear_Click(object sender, EventArgs e)
{
ys.Text = "";
DTable.Rows.Clear();
BindGrid1();
}
public void BindGrid()
{
string str1="";
string str2;
if (query_content.Text.Trim() != "")
str1 = " and " + query_tj.SelectedItem.Value + " like '%" + query_content.Text + "%'";
str2 = "select a.*,abbrname,storeamounta,storeamountz from bookinfosheet a,pressinfosheet b,bookstoresheeta c,bookstoresheetz d where a.presscode=b.code and a.code=c.bookcode and a.code=d.bookcode " + str1 + " order by a.code";
#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 =Socut.Data.ExecuteDataSet(str2, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize);
DataGrid1.DataBind();
}
protected void Query_Click(object sender, EventArgs e)
{
BindGrid();
}
#region 返回脚本字符串
public string getalertinfo(string str1)
{
string str;
str = "<script language='javascript'>alert('" + str1 + "')</script>";
return str.Trim();
}
#endregion
#region 添加至按钮代码
protected void AddToSub_Click(object source, DataGridCommandEventArgs e)
{
SqlDataReader dataR = null;
if ((e.CommandName.ToString() == "addtoout"))
{
string CodeStr = e.Item.Cells[0].Text;
string NameStr = e.Item.Cells[1].Text;
string CbStr = e.Item.Cells[2].Text;
string AuthorStr = e.Item.Cells[4].Text;
float PriceStr = Convert.ToSingle(e.Item.Cells[3].Text.Substring(1));
string Sql;
DataRow DRow = DTable.NewRow();
DataRowCollection Drc = null;
Drc = DTable.Rows;
if (Drc.Contains(CodeStr))
Page.RegisterStartupScript("", getalertinfo("该图书已在出库单中,无法再次添加!"));
else
{
DRow[0] = CodeStr.Trim();
DRow[1] = NameStr.Trim();
DRow[2] = CbStr.Trim();
DRow[3] = AuthorStr.Trim();
DRow[4] = PriceStr;
DRow[5] = 1;
DRow[6] = "1.00";
DTable.Rows.Add(DRow);
BindGrid1();
}
}
}
#endregion
protected void Grid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
BindGrid();
}
protected void Grid2_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
DataGrid2.CurrentPageIndex = e.NewPageIndex;
BindGrid1();
}
protected void Grid_Cancel(object source, DataGridCommandEventArgs e)
{
DataGrid2.EditItemIndex = -1;
BindGrid1();
}
protected void Grid_Delete(object source, DataGridCommandEventArgs e)
{
string theNo = e.Item.Cells[0].Text;
DataRowCollection Drc = DTable.Rows;
DataRow theRow;
if (Drc.Contains(theNo))
{
theRow = Drc.Find(theNo);
Drc.Remove(theRow);
BindGrid1();
}
}
protected void Grid_Edit(object source, DataGridCommandEventArgs e)
{
DataGrid2.EditItemIndex = e.Item.ItemIndex;
BindGrid1();
}
protected void Grid_Update(object source, DataGridCommandEventArgs e)
{
string OutNumStr = ((TextBox)e.Item.Cells[6].Controls[0]).Text;
string strdiscount = ((TextBox)e.Item.Cells[5].Controls[0]).Text;
string theNo = e.Item.Cells[0].Text;
DataRowCollection Drc;
DataRow theRow;
if (VCUtilities.IsNumeric(OutNumStr))
{
Drc = DTable.Rows;
if (Drc.Contains(theNo))
{
theRow = Drc.Find(theNo);
theRow[5] = Convert.ToInt32(OutNumStr);
if (strdiscount != null&&VCUtilities.IsSingle(strdiscount))
{
if (Convert.ToSingle(strdiscount) > 0 && Convert.ToSingle(strdiscount) <= 1)
{
theRow[6] = strdiscount;
}
else
theRow[6] = 1;
}
//else
// theRow[5] = 1;
if (theRow.HasErrors)
DTable.RejectChanges();
else
DTable.AcceptChanges();
}
}
DataGrid2.EditItemIndex = -1;
BindGrid1();
}
protected void tj_Click(object sender, EventArgs e)
{
DataRowCollection Drc;
float themoney=0;
int thenum;
float theprice;
float thediscount;
string UnitCode;
Drc = DTable.Rows;
if (Drc.Count > 0)
{
foreach (DataRow theRow in Drc)
{
if (theRow[5] != null)
{
if (Convert.ToInt32(theRow[5]) != 0)
{
if (theRow[6] == null)
thediscount = 1;
else
{
if (VCUtilities.IsSingle(theRow[6].ToString()))
thediscount = Convert.ToSingle(theRow[6]);
else
thediscount = 1;
}
thenum = Convert.ToInt32(theRow[5]);
theprice = Convert.ToSingle(theRow[4]);
themoney = themoney + thenum * theprice * thediscount;
}
}
}
if (themoney==0)
ys.Text = "";
else
ys.Text = themoney.ToString();
}
}
protected void Save_Click(object sender, EventArgs e)
{
DataRowCollection Drc;
Int32 theTag;
string theBookCode;
Int32 theoutNum;
string UnitCode;
float theDiscount;
SqlDataReader DataR;
DateTime theDate;
string strMemo = memo.Text.Trim();
string Sql;
if (!VCUtilities.IsDate(DDate.Text))
{
Page.RegisterStartupScript("", getalertinfo("错误的日期!"));
return;
}
theDate = Convert.ToDateTime(DDate.Text.ToString());
Drc = DTable.Rows;
if (Drc.Count == 0)
Page.RegisterStartupScript("", getalertinfo("没有添加数据,无法保存!"));
else
{
theTag = 0;
conn.Open();
UnitCode = DateTime.Now.ToString("yyMMdd");
Sql = "select * from outstoresheeta where left(code,6)='" +UnitCode.Trim() + "' order by code desc";
cmd = new SqlCommand(Sql, conn);
DataR = cmd.ExecuteReader();
if (DataR.Read())
{
Int32 temp = Convert.ToInt32(DataR["code"].ToString().Substring(6)) + 1;
UnitCode = UnitCode.Trim() + temp.ToString("000");
}
else
UnitCode = UnitCode.Trim() + "001";
DataR.Close();
foreach (DataRow theRow in Drc)
{
if (theRow[5] != null)
{
if (Convert.ToInt32(theRow[5]) != 0)
{
if (theRow[6] == null)
theDiscount = 1;
else
{
if (VCUtilities.IsSingle(theRow[6].ToString()))
theDiscount = Convert.ToSingle(theRow[6]);
else
theDiscount = 1;
}
theBookCode = theRow[0].ToString();
theoutNum = Convert.ToInt32(theRow[5]);
Sql = "insert into outstoresheeta(code,ddate,bookcode,outstorenum,outdiscount,agent,memo) values('" + UnitCode.Trim() + "','" + theDate + "','" + theBookCode + "'," + theoutNum + "," + theDiscount + ",'" + Session["username"] + "','" + strMemo + "')";
cmd = new SqlCommand(Sql, conn);
cmd.ExecuteNonQuery();
theTag = 1;
}
}
}
if (theTag != 1)
Page.RegisterStartupScript("", getalertinfo("没有添加出库数,无法保存!"));
else
{
Drc.Clear();
Page.RegisterStartupScript("", getalertinfo("数据保存成功!"));
BindGrid();
BindGrid1();
memo.Text = "";
ys.Text = "";
yb.Text = "";
ss.Text = "";
}
}
}
protected void js_Click(object sender, EventArgs e)
{
string ysStr = ys.Text;
float SngYs;
string ssStr = ss.Text;
float SngSS;
float SngYB;
#region 应收代码格式验证
if (ysStr == "")
SngYs = 0;
else
{
if(!VCUtilities.IsSingle(ysStr))
SngYs=0;
else
SngYs=Convert.ToSingle(ysStr);
}
#endregion
#region 实收代码格式验证
if (ssStr=="")
SngSS = 0;
else
{
if (!VCUtilities.IsSingle(ssStr))
SngSS = 0;
else
SngSS = Convert.ToSingle(ssStr);
}
#endregion
#region 应补代码计算
SngYB = SngSS - SngYs;
yb.Text = SngYB.ToString();
#endregion
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
BindGrid();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -