📄 nzadd.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_NZAdd : 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_NZAdd");
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("innernum", Type.GetType("System.Int32"));
DataColumn[] thekey ={ DTable.Columns["code"] };
DTable.PrimaryKey = thekey;
BindGrid1();
}
if (!IsPostBack)
{
DDate.Text = DateTime.Now.ToString("yyyy-MM-dd");
BindGrid();
BindGrid1();
}
}
#region 返回脚本字符串
public string getalertinfo(string str1)
{
string str;
str = "<script language='javascript'>alert('" + str1 + "')</script>";
return str.Trim();
}
#endregion
public void BindGrid()
{
string str1 = "";
string str2;
//SqlDataAdapter dtcmd = null;
//SqlDataReader dataR = null;
//DataTable dt = new DataTable();
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";
//dtcmd=new sqldataadapter(str2,cnn);
//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 = Socut.Data.ExecuteDataSet(str2, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize);
DataGrid1.DataBind();
}
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 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] = Convert.ToSingle(PriceStr);
DRow[5] = "1";
DTable.Rows.Add(DRow);
BindGrid1();
}
}
}
protected void Save_Click(object sender, EventArgs e)
{
DataRowCollection Drc;
Int32 theTag;
string theBookCode;
Int32 theInnerNum;
string UnitCode;
SqlDataReader DataR;
DateTime theDate;
string ModeStr = InnerMode.SelectedItem.Value;
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 inneroutsheet 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)
{
theBookCode = theRow[0].ToString();
theInnerNum = Convert.ToInt32(theRow[5]);
Sql = "insert into inneroutsheet(code,ddate,innermode,bookcode,innernum,memo) values('" +UnitCode.Trim()+"','" +theDate+"','" +ModeStr+"','" +theBookCode+ "'," +theInnerNum+ ",'" +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 = "";
}
}
}
protected void Grid_Cancel(object source, DataGridCommandEventArgs e)
{
this.DataGrid2.EditItemIndex = -1;
BindGrid1();
}
protected void Grid_Delete(object source, DataGridCommandEventArgs e)
{
string theNo = e.Item.Cells[0].Text;
DataRowCollection Drc = null;
DataRow Dr = null;
Drc = DTable.Rows;
if (Drc.Contains(theNo))
{
Dr = Drc.Find(Dr);
Drc.Remove(Dr);
BindGrid1();
}
}
protected void Grid_Edit(object source, DataGridCommandEventArgs e)
{
DataGrid2.EditItemIndex = e.Item.ItemIndex;
BindGrid1();
}
protected void Grid2_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
}
protected void Grid_Update(object source, DataGridCommandEventArgs e)
{
string InnerNumStr = ((TextBox)e.Item.Cells[5].Controls[0]).Text;
string theNum = e.Item.Cells[0].Text;
DataRowCollection Drc = null;
DataRow theRow;
if (VCUtilities.IsNumeric(InnerNumStr))
{
Drc = DTable.Rows;
if (Drc.Contains(theNum))
{
theRow = Drc.Find(theNum);
theRow[5] = Convert.ToInt32(InnerNumStr);
if (theRow.HasErrors)
DTable.RejectChanges();
else
DTable.GetChanges();
}
}
DataGrid2.EditItemIndex = -1;
BindGrid1();
}
protected void Grid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
BindGrid();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
BindGrid();
}
protected void Clear_Click(object sender, EventArgs e)
{
DTable.Rows.Clear();
BindGrid1();
}
protected void Query_Click(object sender, EventArgs e)
{
BindGrid();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -