<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CG_cgthd.aspx.cs" Inherits="Purchase_CG_cgth" EnableEventValidation="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<link href="../CSS/CSS.css" rel="stylesheet" type="text/css" />
<meta content="JavaScript" name="vs_defaultClientScript"/>
</head>
<body >
<script language="javascript" type="text/javascript">
function selectspxx()
{
strreturnval = window.showModalDialog('../Purchase/CG_cgthd_select.aspx','window','dialogWidth=500px;dialogHeigh=450px');
window.document.all("allvalue").value = strreturnval;
if((window.document.all("allvalue").value !="underfined")&&(window.document.all("allvalue").value !=""))
{
__doPostBack("IB_OK","");
}
else
return;
}
</script>
<form id="form1" runat="server">
<div>总金额<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"></asp:TextBox>
</div>
<div style=" float:right;">
<asp:ImageButton ID="IB_OK" runat="server" name="allvalue" οnclick="IB_OK_Click"
Visible="False" ValidationGroup="False" />
<input id="selectsp" type="button" value="选择商品" οnclick="selectspxx()" />
</div>
<div>
<asp:GridView ID="CG_cgthd" runat="server" AutoGenerateColumns="False"
Width="100%" AllowSorting="True"
onrowcancelingedit="CG_cgthd_RowCancelingEdit"
onrowdeleting="CG_cgthd_RowDeleting" onrowediting="CG_cgthd_RowEditing"
onrowupdating="CG_cgthd_RowUpdating" onsorting="CG_cgthd_Sorting"
DataKeyNames="shangpin_id" onrowdatabound="CG_cgthd_RowDataBound"
CellPadding="4" ForeColor="#333333" GridLines="None">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:BoundField DataField="shangpin_id" HeaderText="编号"
SortExpression="shangpin_id" ReadOnly="True" />
<asp:BoundField DataField="mingcheng" HeaderText="名称"
SortExpression="mingcheng" ReadOnly="True" />
<asp:BoundField DataField="shuliang" HeaderText="数量"
SortExpression="shuliang" />
<asp:BoundField DataField="danjia" HeaderText="单价" SortExpression="danjia" />
<asp:BoundField DataField="jine" HeaderText="金额" SortExpression="jine"
ReadOnly="True" DataFormatString="{0:c}" />
<asp:TemplateField HeaderText="编辑" ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LB_update" runat="server" CausesValidation="True"
CommandName="Update" Text="更新"></asp:LinkButton>
<asp:LinkButton ID="LB_cancel" runat="server" CausesValidation="False"
CommandName="Cancel" Text="取消"></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="LB_edit" runat="server" CausesValidation="False"
CommandName="Edit" Text="编辑"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="删除" ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LB_delete" runat="server" CausesValidation="False"
CommandName="Delete" Text="删除" OnClientClick="return confirm('请确认删除!')"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
<div><input id="allvalue" type="hidden" runat="server"/>
<asp:Button ID="Button1" runat="server" Text="提交数据" />
</div>
</div>
</form>
</body>
</html>
cs代码
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text.RegularExpressions;
using DAL.CGXX;
public partial class Purchase_CG_cgth : System.Web.UI.Page
{
private void Bind()
{
CG_cgthd cg = new CG_cgthd();
DataSet ds = cg.DataBind("V_CG_cgthd");
DataTable dt = ds.Tables[0];
if (dt.Rows.Count > 0)
{
CG_cgthd.DataSource = dt.DefaultView;
CG_cgthd.DataBind();
}
else
{
dt.Rows.Add(ds);
CG_cgthd.DataSource = dt.DefaultView;
CG_cgthd.DataBind();
int columnCount = CG_cgthd.Rows[0].Cells.Count;
CG_cgthd.Rows[0].Cells.Clear();
CG_cgthd.Rows[0].Cells.Add(new TableCell());
CG_cgthd.Rows[0].Cells[0].ColumnSpan = columnCount;
CG_cgthd.Rows[0].Cells[0].Text = "没有信息!";
}
ViewState["cgthd"] = ds;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind();
ViewState["sort"] = "ASC";
}
}
protected void CG_cgthd_RowDeleting(object sender, GridViewDeleteEventArgs e)
{//删除
string sid = CG_cgthd.DataKeys[e.RowIndex].Value.ToString();
DataSet ds = (DataSet)ViewState["cgthd"];
DataTable dt = ds.Tables["V_CG_cgthd"];
dt.PrimaryKey = new DataColumn[]
{
dt.Columns["shangpin_id"]
};
DataRow myrow = dt.Rows.Find(sid);
if (myrow != null)
{
myrow.Delete();
}
if (dt.Rows.Count > 0)
{
CG_cgthd.DataSource = ds;
CG_cgthd.DataBind();
}
else
{
dt.Rows.Add(ds);
CG_cgthd.DataSource = dt.DefaultView;
CG_cgthd.DataBind();
int columnCount = CG_cgthd.Rows[0].Cells.Count;
CG_cgthd.Rows[0].Cells.Clear();
CG_cgthd.Rows[0].Cells.Add(new TableCell());
CG_cgthd.Rows[0].Cells[0].ColumnSpan = columnCount;
CG_cgthd.Rows[0].Cells[0].Text = "没有信息!";
}
ViewState["cgthd"] = ds;
CG_cgthd cg = new CG_cgthd();
TextBox1.Text = (cg.DataTableCount(ds)).ToString();
}
protected void CG_cgthd_RowEditing(object sender, GridViewEditEventArgs e)
{//编辑
CG_cgthd.EditIndex = e.NewEditIndex;
DataSet ds = (DataSet)ViewState["cgthd"];
CG_cgthd.DataSource = ds;
CG_cgthd.DataBind();
CG_cgthd cg = new CG_cgthd();
TextBox1.Text = (cg.DataTableCount(ds)).ToString();
}
protected void CG_cgthd_Sorting(object sender, GridViewSortEventArgs e)
{//排序
DataSet ds = (DataSet)ViewState["cgthd"];
DAL.ComFunction cf = new DAL.ComFunction();
if (ViewState["sort"] == null)
{
ViewState["sort"] = "ASC";
}
else
{
if (ViewState["sort"].ToString() == "ASC")
{
ViewState["sort"] = "DESC";
}
else
{
ViewState["sort"] = "ASC";
}
}
cf.GridViewSort(ds.Tables[0],e.SortExpression.ToString(),ViewState["sort"].ToString());
CG_cgthd.DataSource = ds;
CG_cgthd.DataBind();
}
protected void CG_cgthd_RowUpdating(object sender, GridViewUpdateEventArgs e)
{//更新
string sid = CG_cgthd.DataKeys[e.RowIndex].Value.ToString();
string shuliang = ((TextBox)(CG_cgthd.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim();
string danjia = ((TextBox)(CG_cgthd.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim();
DataSet ds = (DataSet)ViewState["cgthd"];
DataTable dt = ds.Tables[0];
DataRow myrow = dt.Rows.Find(sid);
if (myrow != null)
{
myrow.BeginEdit();
myrow["shuliang"] = shuliang;
myrow["danjia"] = danjia;
myrow["jine"] = Convert.ToInt32(myrow["shuliang"]) * Convert.ToInt32(myrow["danjia"]);
myrow.EndEdit();
}
CG_cgthd.EditIndex = -1;
CG_cgthd.DataSource = ds;
CG_cgthd.DataBind();
ViewState["cgthd"] = ds;
CG_cgthd cg = new CG_cgthd();
TextBox1.Text = (cg.DataTableCount(ds)).ToString();
}
protected void CG_cgthd_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
DataSet ds = (DataSet)ViewState["cgthd"];
CG_cgthd.EditIndex = -1;
CG_cgthd.DataSource = ds;
CG_cgthd.DataBind();
}
protected void IB_OK_Click(object sender, ImageClickEventArgs e)
{
DataSet ds = (DataSet)ViewState["cgthd"];
DataTable dt = ds.Tables[0];
if (CG_cgthd.Rows[0].Cells[0].Text == "没有信息!")
{
dt.Clear();
}
string sid = allvalue.Value.ToString();
string[] splist = Regex.Split(sid, ",");
string sBH = splist[0].ToString();
string sMC = splist[1].ToString();
string sSL = splist[2].ToString();
string sJJ = splist[3].ToString();
if ((sBH == "") || (sMC == "") || (sJJ == "") || (sSL == ""))
{
if (CG_cgthd.Rows[0].Cells[0].Text == "没有信息!")
{
dt.Rows.Add(ds);
CG_cgthd.DataSource = dt.DefaultView;
CG_cgthd.DataBind();
int columnCount = CG_cgthd.Rows[0].Cells.Count;
CG_cgthd.Rows[0].Cells.Clear();
CG_cgthd.Rows[0].Cells.Add(new TableCell());
CG_cgthd.Rows[0].Cells[0].ColumnSpan = columnCount;
CG_cgthd.Rows[0].Cells[0].Text = "没有信息!";
}
return;
}
dt.PrimaryKey = new DataColumn[]
{
dt.Columns["shangpin_id"]
};
DataRow myrow = dt.Rows.Find(sBH);
if (myrow != null)
{//修改
myrow.BeginEdit();
myrow["shuliang"] = Convert.ToInt32(myrow["shuliang"]) + Convert.ToInt32(sSL);
myrow["jine"] = Convert.ToInt32(myrow["shuliang"]) * Convert.ToInt32(myrow["danjia"]);
myrow.EndEdit();
}
else
{//添加
DataRow newrow = dt.NewRow();
newrow["shangpin_id"] = sBH;
newrow["mingcheng"] = sMC;
newrow["shuliang"] = Convert.ToInt32(sSL);
newrow["danjia"] = Convert.ToSingle(sJJ);
newrow["jine"] = Convert.ToInt32(sSL) * Convert.ToSingle(sJJ);
dt.Rows.Add(newrow);
}
CG_cgthd.DataSource = ds;
CG_cgthd.DataBind();
ViewState["cgthd"] = ds;
CG_cgthd cg = new CG_cgthd();
TextBox1.Text = (cg.DataTableCount(ds)).ToString();
}
protected void CG_cgthd_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
}
}
}
采购退贷单选择项
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CG_cgthd_select.aspx.cs" Inherits="Purchase_CG_cgthd_select" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<link href="../CSS/CSS.css" rel="stylesheet" type="text/css" />
<base target="_self"/>
</head>
<body>
<script language="javascript" type="text/javascript">
function clickok()
{
window.document.all("Hide_return").value = document.all("tb_BH").value+","+document.all("tb_MC").value+","+document.all("tb_SL").value+","+document.all("tb_JJ").value;
returnall = document.getElementById("Hide_return").value;
window.returnValue=returnall;
window.close();
return true;
}
</script>
<form id="form1" runat="server">
<div style="text-align:left">『->商品信息列表』</div>
<div>
<asp:GridView ID="CG_select" runat="server" AutoGenerateColumns="False"
Width="100%" onselectedindexchanging="CG_select_SelectedIndexChanging"
onselectedindexchanged="CG_select_SelectedIndexChanged"
onrowdatabound="CG_select_RowDataBound" CellPadding="4"
ForeColor="#333333" GridLines="None" onrowcreated="CG_select_RowCreated">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:BoundField DataField="id" HeaderText="商品编号" SortExpression="id" />
<asp:BoundField DataField="mingcheng" HeaderText="商品名称"
SortExpression="mingcheng" />
<asp:BoundField DataField="leibie" HeaderText="商品类别" SortExpression="leibie" />
<asp:BoundField DataField="danwei" HeaderText="单价" SortExpression="danwei" />
<asp:BoundField DataField="jinjia" HeaderText="进价"
SortExpression="jinjia" />
<asp:CommandField HeaderText="选择" ShowSelectButton="True" />
</Columns>
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
</div>
<br />
<div style="line-height:24px;">
商品编号<asp:TextBox ID="tb_BH" runat="server" BorderStyle="Groove" Width="56px"></asp:TextBox>
商品名称<asp:TextBox ID="tb_MC" runat="server" BorderStyle="Groove" Width="69px"></asp:TextBox>
进价<asp:TextBox ID="tb_JJ" runat="server" BorderStyle="Groove" Width="50px"></asp:TextBox>
数量<asp:TextBox ID="tb_SL" runat="server" BorderStyle="Groove" Width="40px"></asp:TextBox>
</div>
<div></div>
<div>
<input id="Hide_return" type="hidden" />
<input id="Button1" type="button" value="确定" οnclick="clickok();" /></div>
</form>
</body>
</html>
*********************cs代码
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DAL;
public partial class Purchase_CG_cgthd_select : System.Web.UI.Page
{
private void Bind()
{
DAL.ComFunction cf = new DAL.ComFunction();
CG_select.DataSource = cf.DataBind("V_JB_spxx_xs");
CG_select.DataBind();
CG_select.DataKeyNames = new string[] { "id" };
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind();
}
}
protected void CG_select_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
}
protected void CG_select_SelectedIndexChanged(object sender, EventArgs e)
{
tb_BH.Text = CG_select.SelectedRow.Cells[0].Text.ToString();
tb_MC.Text = CG_select.SelectedRow.Cells[1].Text.ToString();
tb_JJ.Text = CG_select.SelectedRow.Cells[4].Text.ToString();
}
protected void CG_select_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
}
}
protected void CG_select_RowCreated(object sender, GridViewRowEventArgs e)
{
e.Row.Attributes.Add("onclick", "javascirpt:__doPostBack('CG_select','Select$" + e.Row.RowIndex + "')");
}
}