private void BindGrid() { int organizecity = 0; if (int.TryParse(tr_OrganizeCity.SelectValue, out organizecity)) { DataTable dt = FNA_BudgetPercentFeeTypeBLL.GetList(organizecity, 0); DataTable dt_matrix = MatrixTable.Matrix(dt, new string[] { "区域ID", "区域名称", "区域级别" }, "FeeTypeName", "BudgetPercent", false, true); //dt_matrix.Columns.Add("机动费用", Type.GetType("System.Decimal"), "100-合计"); gv_List.DataSource = dt_matrix; gv_List.DataBind(); } }
private void BindGrid() { IList <FNA_BudgetPercentFeeType> list = FNA_BudgetPercentFeeTypeBLL.GetModelList("OrganizeCity=" + ViewState["OrganizeCity"].ToString()); Dictionary <string, Dictionary_Data> dic = DictionaryBLL.GetDicCollections("FNA_FeeType"); foreach (Dictionary_Data item in dic.Values) { if (list.FirstOrDefault(p => p.FeeType.ToString() == item.Code) == null) { FNA_BudgetPercentFeeType m = new FNA_BudgetPercentFeeType(); m.FeeType = int.Parse(item.Code); m.BudgetPercent = 0; list.Add(m); } } gv_List.BindGrid <FNA_BudgetPercentFeeType>(list); }
protected void bt_Save_Click(object sender, EventArgs e) { #region 验证所有百分比选项是否小于或等于100,小于100时,其余部分用作机动费用 decimal percent = 0; foreach (GridViewRow row in gv_List.Rows) { percent += decimal.Parse(((TextBox)row.FindControl("tbx_BudgetPercent")).Text); } if (percent > 100) { MessageBox.Show(this, "对不起,各费用类型设定的百分比总和不能大于100!"); return; } #endregion foreach (GridViewRow row in gv_List.Rows) { int id = (int)gv_List.DataKeys[row.RowIndex]["ID"]; if (id == 0) { FNA_BudgetPercentFeeTypeBLL bll = new FNA_BudgetPercentFeeTypeBLL(); bll.Model.OrganizeCity = (int)ViewState["OrganizeCity"]; bll.Model.FeeType = (int)gv_List.DataKeys[row.RowIndex]["FeeType"]; bll.Model.BudgetPercent = decimal.Parse(((TextBox)row.FindControl("tbx_BudgetPercent")).Text); bll.Model.ApproveFlag = 1; bll.Model.InsertStaff = (int)Session["UserID"]; bll.Add(); } else { FNA_BudgetPercentFeeTypeBLL bll = new FNA_BudgetPercentFeeTypeBLL(id); bll.Model.BudgetPercent = decimal.Parse(((TextBox)row.FindControl("tbx_BudgetPercent")).Text); bll.Model.UpdateStaff = (int)Session["UserID"]; bll.Update(); } } MessageBox.ShowAndRedirect(this, "保存成功!", "BudgetPercentList.aspx"); }