62,074
社区成员
发帖
与我相关
我的任务
分享
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333" ShowFooter="True" DataKeyNames="ID"
onrowcancelingedit="GridView1_RowCancelingEdit"
onrowdeleting="GridView1_RowDeleting" onrowediting="GridView1_RowEditing"
onrowupdating="GridView1_RowUpdating">
public partial class WorkSpace_FundsPlan : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Databind();
}
}
//数据绑定
private void Databind()
{
FundsPlanManager funsPlanManager = new FundsPlanManager();
UserInfo userInfo = (UserInfo)Session["UserInfo"];
if (userInfo != null)
{
IList<FundsPlan> fundsPlan = funsPlanManager.GetListByDepartId(userInfo.Department.DepartId);
GridView1.DataSource = fundsPlan;
GridView1.DataBind();
}
}
public string GetScript(string name)
{
return string.Format("return confirm(\"确定删除此资金使用计划[{0}]吗?\");", name);
}
protected void Button1_Click(object sender, EventArgs e)
{
FundsPlan fundsPlan = new FundsPlan();
fundsPlan.AddTime = DateTime.Now;
fundsPlan.Amount = Convert.ToDecimal(txtAmount.Text.Trim());
UserInfo user=(UserInfo)Session["UserInfo"];
fundsPlan.DepartId = user.Department.DepartId;
fundsPlan.Name = txtName.Text.Trim();
fundsPlan.Paid = Convert.ToDecimal(txtPaid.Text.Trim());
fundsPlan.Remarks = txtRemark.Text.Trim();
fundsPlan.UnPaid = Convert.ToDecimal(txtUnPaid.Text.Trim());
fundsPlan.UserId = user.UserId;
FundsPlanManager fundsPlangerManager = new FundsPlanManager();
int success=fundsPlangerManager.Add(fundsPlan);
if (success > 0)
{
Databind();
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
Databind();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string id = GridView1.DataKeys[e.RowIndex].Value.ToString();
FundsPlanManager funsPlanManager = new FundsPlanManager();
bool success=funsPlanManager.Delete(Convert.ToInt32(id));
if (success)
{
GridView1.EditIndex = -1;
Databind();
}
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
Databind();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
FundsPlan fundsPlan = new FundsPlan();
string id = GridView1.DataKeys[e.RowIndex].Value.ToString();
string name = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text.Trim();
decimal amount =Convert.ToDecimal(((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text.Trim());
decimal paid = Convert.ToDecimal(((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text.Trim());
decimal unpaid = Convert.ToDecimal(((TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text.Trim());
string remarks =((TextBox)GridView1.Rows[e.RowIndex].Cells[5].FindControl("txtEditRemarks")).Text.Trim();
DateTime addTime =Convert.ToDateTime(((Label)GridView1.Rows[e.RowIndex].Cells[6].FindControl("lblEditAddTime")).Text.Trim());
fundsPlan.PID = Int32.Parse(id);
fundsPlan.Name = name;
fundsPlan.Amount = amount;
fundsPlan.Paid = paid;
fundsPlan.UnPaid = unpaid;
fundsPlan.Remarks = remarks;
fundsPlan.AddTime = addTime;
FundsPlanManager m = new FundsPlanManager();
m.Update(fundsPlan);
GridView1.EditIndex = -1;
Databind();
}
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="PID" onrowcancelingedit="GridView1_RowCancelingEdit"
onrowdeleting="GridView1_RowDeleting" onrowediting="GridView1_RowEditing"
onrowupdating="GridView1_RowUpdating">
<Columns>
<asp:BoundField DataField="PID" HeaderText="ID" />
<asp:BoundField DataField="Name" HeaderText="付款用途" />
<asp:BoundField DataField="Amount" HeaderText="暂定额度" />
<asp:BoundField DataField="Paid" HeaderText="已付累计" />
<asp:BoundField DataField="UnPaid" HeaderText="未付" />
<asp:TemplateField HeaderText="说明">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Remarks") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtEditRemarks" runat="server" Height="65px"
Text='<%# Bind("Remarks") %>' TextMode="MultiLine" Width="233px"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="添加时间">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("AddTime") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblEditAddTime" runat="server" Text='<%# Bind("AddTime") %>'></asp:Label>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
<asp:CommandField SelectText="付款录入" ShowSelectButton="True" />
</Columns>
</asp:GridView>